EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Calorimeter_barrel.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Calorimeter_barrel.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2020 CERN for the benefit of the Acts project
4 //
5 // This Source Code Form is subject to the terms of the Mozilla Public
6 // License, v. 2.0. If a copy of the MPL was not distributed with this
7 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 
11 
12 #include "DD4hep/DetFactoryHelper.h"
13 
14 using namespace std;
15 using namespace dd4hep;
16 
17 static Ref_t create_element(Detector& oddd, xml_h xml, SensitiveDetector) {
18  xml_det_t x_det = xml;
19  string detName = x_det.nameStr();
20 
21  // Make DetElement
22  DetElement CaloBarrel(detName, x_det.id());
23 
24  // add Extension to DetElement for the RecoGeometry
25  Acts::ActsExtension* barrelExtension = new Acts::ActsExtension();
26  barrelExtension->addType("barrel", "detector");
27  CaloBarrel.addExtension<Acts::ActsExtension>(barrelExtension);
28 
29  // Make Volume
30  dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
31  Tube barrelShape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
32  Volume barrelVolume(detName, barrelShape, oddd.air());
33  barrelVolume.setVisAttributes(oddd, x_det.visStr());
34 
35  // Create the tubes with their respective material, etc
36  size_t VolIdx = 0;
37  // loop through layers
38  for (xml_coll_t tubIt(x_det, _U(tubs)); tubIt; ++tubIt) {
39  xml_comp_t VolDet = tubIt;
40  dd4hep::Tube VolShape(VolDet.rmin(), VolDet.rmax(), VolDet.dz());
41  std::string VolName = dd4hep::xml::_toString(VolDet.nameStr());
42  dd4hep::Volume Volume(VolName, VolShape,
43  oddd.material(VolDet.materialStr()));
44  // Create volume detector element
45  dd4hep::DetElement vol_det(CaloBarrel, VolName, VolIdx);
46 
47  if (VolDet.hasAttr(_U(vis))) {
48  Volume.setVisAttributes(oddd, VolDet.visStr());
49  }
50 
51  // Set Acts Extension
52  Acts::ActsExtension* detVolume = new Acts::ActsExtension();
53  detVolume->addType("passive cylinder", "volume");
54  vol_det.addExtension<Acts::ActsExtension>(detVolume);
55 
56  // place the layer into the mother volume with a possible translation
57  dd4hep::Position transvol(0., 0., 0.);
58  dd4hep::PlacedVolume placedVolume =
59  barrelVolume.placeVolume(Volume, transvol);
60  // set volume ID
61  placedVolume.addPhysVolID(VolName, VolIdx);
62  vol_det.setPlacement(placedVolume);
63  VolIdx++;
64  }
65 
66  // Place it in the mother
67  Volume motherVolume = oddd.pickMotherVolume(CaloBarrel);
68  PlacedVolume placedTube = motherVolume.placeVolume(barrelVolume);
69  placedTube.addPhysVolID(detName, CaloBarrel.id());
70  CaloBarrel.setPlacement(placedTube);
71 
72  // And return the element for further parsing
73  return CaloBarrel;
74 }
75 
76 DECLARE_DETELEMENT(Calorimeter, create_element)