ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimpleLayeredCylinder_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file SimpleLayeredCylinder_geo.cpp
1 // This file is part of the Acts project.
2 //
3 // Copyright (C) 2017 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 
10 #include "DD4hep/DetFactoryHelper.h"
11 #include "XML/XMLElements.h"
12 
13 namespace det {
14 
27 static dd4hep::Ref_t createSimpleLayeredCylinder(
28  dd4hep::Detector& lcdd, dd4hep::xml::Handle_t xmlElement,
29  dd4hep::SensitiveDetector sensDet) {
30  dd4hep::xml::DetElement xmlDet =
31  static_cast<dd4hep::xml::DetElement>(xmlElement);
32  std::string name = xmlDet.nameStr();
33  dd4hep::DetElement detElement(name, xmlDet.id());
34  // add Extension to Detlement for the RecoGeometry
35  Acts::ActsExtension* detvolume = new Acts::ActsExtension();
36  detvolume->addType("barrel", "detector");
37  detElement.addExtension<Acts::ActsExtension>(detvolume);
38  // Create volume
39  dd4hep::Volume experimentalHall = lcdd.pickMotherVolume(detElement);
40  xml_comp_t dimensions(xmlDet.dimensions());
41  dd4hep::Tube envelope(dimensions.rmin(), dimensions.rmax(), dimensions.dz());
42  dd4hep::Volume envVolume(name, envelope,
43  lcdd.material(dimensions.materialStr()));
44 
45  // Create layer cylinders with their respective material, etc
46  size_t layerIdx = 0;
47  // loop through layers
48  for (xml_coll_t layerIt(xmlDet, _U(layer)); layerIt; ++layerIt) {
49  xml_comp_t layerDet = layerIt;
50  dd4hep::Tube layerShape(layerDet.rmin(), layerDet.rmax(), layerDet.dz());
51  std::string layerName = dd4hep::xml::_toString(layerIdx, "layer%d");
52  dd4hep::Volume layerVolume(layerName, layerShape, lcdd.air());
53  // Create layer detector element
54  dd4hep::DetElement lay_det(detElement, layerName, layerIdx);
55  // @todo use material string again layer.attr<std::string>("material"))
56 
57  // envVolume.placeVolume(layerVolume,
58  // dd4hep::Transform3D(dd4hep::RotationZ(0.),
59  // transLayer));
60  if (layerDet.hasAttr(_U(vis))) {
61  layerVolume.setVisAttributes(lcdd, layerDet.visStr());
62  }
63  if (layerDet.hasAttr(_U(sensitive))) {
64  layerVolume.setSensitiveDetector(sensDet);
65  }
66  // Set Acts Extension
67  Acts::ActsExtension* detlayer = new Acts::ActsExtension();
68  detlayer->addType("passive cylinder", "layer");
69  lay_det.addExtension<Acts::ActsExtension>(detlayer);
70 
71  // place the layer into the mother volume with a possible translation
72  dd4hep::Position transLayer(0., 0., layerDet.z_offset());
73  dd4hep::PlacedVolume placedLayerVolume =
74  envVolume.placeVolume(layerVolume, transLayer);
75  // set volume ID
76  placedLayerVolume.addPhysVolID("layer", layerIdx);
77  lay_det.setPlacement(placedLayerVolume);
78  layerIdx++;
79  }
80 
81  dd4hep::Position trans(0., 0., dimensions.z_offset());
82  dd4hep::PlacedVolume envPhys = experimentalHall.placeVolume(
83  envVolume, dd4hep::Transform3D(dd4hep::RotationZ(0.), trans));
84  envPhys.addPhysVolID("system", detElement.id());
85  detElement.setPlacement(envPhys);
86  detElement.setVisAttributes(lcdd, xmlDet.visStr(), envVolume);
87 
88  return detElement;
89 }
90 } // namespace det
91 
92 DECLARE_DETELEMENT(SimpleLayeredCylinder, det::createSimpleLayeredCylinder)