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