EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Endcap_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Endcap_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 
11 
12 #include "DD4hep/DetFactoryHelper.h"
13 
14 using namespace std;
15 using namespace dd4hep;
16 
23 static Ref_t create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
24  xml_det_t x_det = xml;
25  string det_name = x_det.nameStr();
26  // Make DetElement
27  DetElement cylinderVolume(det_name, x_det.id());
28  // add Extension to Detlement for the RecoGeometry
29  Acts::ActsExtension* detvolume = new Acts::ActsExtension();
30  cylinderVolume.addExtension<Acts::ActsExtension>(detvolume);
31  // make Volume
32  dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
33  Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
34  Volume tube_vol(det_name, tube_shape,
35  lcdd.air()); // air at the moment change later
36  tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
37  // go trough possible layers
38  size_t layer_num = 0;
39  // if it is the positive or negative endcap
40  for (xml_coll_t j(xml, _U(layer)); j; ++j) {
41  xml_comp_t x_layer = j;
42  double l_rmin = x_layer.inner_r();
43  double l_rmax = x_layer.outer_r();
44  double l_length = x_layer.dz();
45  // Create Volume and DetElement for Layer
46  string layer_name = det_name + _toString((int)layer_num, "layer%d");
47  Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
48  lcdd.material(x_layer.materialStr()));
49  DetElement lay_det(cylinderVolume, layer_name, layer_num);
50  // Visualization
51  layer_vol.setVisAttributes(lcdd, x_layer.visStr());
52  int module_num_num = 0;
53  // go trough possible modules
54  if (x_layer.hasChild(_U(module))) {
55  for (xml_coll_t i(x_layer, _U(module)); i; i++) {
56  xml_comp_t x_module = i;
57  int repeat = x_module.repeat();
58  double deltaphi = 2. * M_PI / repeat;
59  double radius = x_module.radius();
60  double slicedz = x_module.dz();
61 
62  size_t module_num = 0;
63 
64  // Create the module volume
65  Volume mod_vol(
66  "module",
67  Trapezoid(x_module.x1(), x_module.x2(), x_module.thickness(),
68  x_module.thickness(), x_module.length()),
69  lcdd.material(x_module.materialStr()));
70  mod_vol.setVisAttributes(lcdd, x_module.visStr());
71 
72  // create the Acts::DigitizationModule (needed to do geometric
73  // digitization) for all modules which have digitization module
74  auto digiModule =
76  x_module.x1(), x_module.x2(), x_module.length(),
77  x_module.thickness(), sens.readout().segmentation());
78 
79  // the sensitive placed components to be used later to create the
80  // DetElements
81  std::vector<PlacedVolume> sensComponents;
82  // the possible digitization module
83  std::shared_ptr<const Acts::DigitizationModule> digiComponent = nullptr;
84  // go through possible components
85  int comp_num = 0;
86  for (xml_coll_t comp(x_module, _U(module_component)); comp; comp++) {
87  xml_comp_t x_comp = comp;
88  // create the component volume
89  string comp_name =
90  _toString((int)comp_num, "component%d") + x_comp.materialStr();
91  Volume comp_vol(
92  comp_name,
93  Trapezoid(x_comp.x1(), x_comp.x2(), x_comp.thickness(),
94  x_comp.thickness(), x_comp.length()),
95  lcdd.material(x_comp.materialStr()));
96  comp_vol.setVisAttributes(lcdd, x_comp.visStr());
97 
98  // create the Acts::DigitizationModule (needed to do geometric
99  // digitization) for all modules which have the sdigitization
100  // compoenent
101  digiComponent =
103  x_comp.x1(), x_comp.x2(), x_comp.length(), x_comp.thickness(),
104  sens.readout().segmentation());
105 
106  // Set Sensitive Volumes sensitive
107  if (x_comp.isSensitive())
108  comp_vol.setSensitiveDetector(sens);
109 
110  // place component in module
111  Position translation(0., x_comp.z(), 0.);
112  PlacedVolume placed_comp = mod_vol.placeVolume(comp_vol, translation);
113  if (x_comp.isSensitive())
114  sensComponents.push_back(placed_comp);
115  placed_comp.addPhysVolID("component", module_num);
116  ++comp_num;
117  }
118 
119  // Place the Modules
120  for (int k = 0; k < repeat; k++) {
121  string zname = _toString((int)k, "z%d");
122 
123  double phi = deltaphi / dd4hep::rad * k;
124  string module_name =
125  zname + _toString((int)(repeat * module_num_num + module_num),
126  "module%d");
127  Position trans(radius * cos(phi), radius * sin(phi), slicedz);
128  // Create the module DetElement
129  DetElement mod_det(lay_det, module_name,
130  repeat * module_num_num + module_num);
131  // Set Sensitive Volumes sensitive
132  if (x_module.isSensitive()) {
133  mod_vol.setSensitiveDetector(sens);
134  // Create and attach the extension for DD4Hep/Acts conversion
135  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
136  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
137  }
138 
139  int scomp_num = 0;
140  for (auto& sensComp : sensComponents) {
141  // Create DetElement
142  DetElement comp_det(mod_det, "component", scomp_num);
143  // Create and attach the extension
144  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
145  comp_det.addExtension<Acts::ActsExtension>(moduleExtension);
146  comp_det.setPlacement(sensComp);
147  scomp_num++;
148  }
149  Rotation3D rotation1(1., 0., 0., 0., 1., 0., 0., 0., 1.);
150  // Place Module Box Volumes in layer
151  Transform3D transf1(RotationX(0.5 * M_PI) *
152  RotationY(phi + 0.5 * M_PI) *
153  RotationZ(0.1 * M_PI),
154  trans);
155  PlacedVolume placedmodule =
156  layer_vol.placeVolume(mod_vol, rotation1 * transf1);
157  placedmodule.addPhysVolID("module",
158  repeat * module_num_num + module_num);
159  // assign module DetElement to the placed module volume
160  mod_det.setPlacement(placedmodule);
161  ++module_num;
162  }
163  ++module_num_num;
164  }
165  }
166 
167  // Place the layer with appropriate Acts::Extension
168  // Configure the ACTS extension
169  Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
170  layerExtension->addType("sensitive disk", "layer");
171  lay_det.addExtension<Acts::ActsExtension>(layerExtension);
172 
173  // Placed Layer Volume
174  Position layer_pos(0., 0., x_layer.z());
175  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol, layer_pos);
176  placedLayer.addPhysVolID("layer", layer_num);
177  lay_det.setPlacement(placedLayer);
178  ++layer_num;
179  }
180  // Place Volume
181  // if it is the negative endcap the normal vector needs to point into the
182  // outside
183  Position endcap_translation(0., 0., x_det_dim.z());
184  Rotation3D rotation(1., 0., 0., 0., 1., 0., 0., 0., 1.);
185  if (x_det_dim.z() < 0.) {
186  rotation.SetComponents(1., 0., 0., 0., -1., 0., 0., 0., -1.);
187  }
188  Transform3D endcap_transform(rotation, endcap_translation);
189  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
190  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol, endcap_transform);
191  placedTube.addPhysVolID("system", cylinderVolume.id());
192  cylinderVolume.setPlacement(placedTube);
193 
194  return cylinderVolume;
195 }
196 
197 DECLARE_DETELEMENT(ACTS_Endcap, create_element)