EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IBLSimpleBarrel_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file IBLSimpleBarrel_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 
13 using namespace std;
14 using namespace dd4hep;
15 
21 static Ref_t create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
22  xml_det_t x_det = xml;
23  string det_name = x_det.nameStr();
24  // Make DetElement
25  DetElement cylinderVolume(det_name, x_det.id());
26  // add Extension to Detlement for the RecoGeometry
27  Acts::ActsExtension* barrelExtension = new Acts::ActsExtension();
28  barrelExtension->addType("barrel", "detector");
29  cylinderVolume.addExtension<Acts::ActsExtension>(barrelExtension);
30  // make Volume
31  dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
32  Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
33  Volume tube_vol(det_name, tube_shape,
34  lcdd.air()); // air at the moment change later
35  tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
36  // go trough possible layers
37  size_t layer_num = 0;
38 
39  for (xml_coll_t j(xml, _U(layer)); j; ++j) {
40  xml_comp_t x_layer = j;
41  double l_rmin = x_layer.inner_r();
42  double l_rmax = x_layer.outer_r();
43  // Create Volume for Layer
44  string layer_name = det_name + _toString((int)layer_num, "layer%d");
45  Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, x_layer.z()),
46  lcdd.material(x_layer.materialStr()));
47  DetElement lay_det(cylinderVolume, layer_name, layer_num);
48  // Visualization
49  layer_vol.setVisAttributes(lcdd, x_layer.visStr());
50 
51  // go trough possible modules
52  if (x_layer.hasChild(_U(module))) {
53  xml_comp_t x_module = x_layer.child(_U(module));
54  int repeat = x_module.repeat();
55  double deltaphi = 2. * M_PI / repeat;
56  // slices in z
57  xml_comp_t x_slice = x_layer.child(_U(slice));
58  int zrepeat = x_slice.repeat();
59  double dz = x_slice.z();
60  double dr = x_slice.dr();
61 
62  // Place the Modules in z
63  size_t module_num = 0;
64  // create the module volume and its corresponing component volumes first
65  Volume mod_vol(
66  "module",
67  Box(x_module.length(), x_module.width(), x_module.thickness()),
68  lcdd.material(x_module.materialStr()));
69  // Visualization
70  mod_vol.setVisAttributes(lcdd, x_module.visStr());
71  // the sensitive placed components to be used later to create the
72  // DetElements
73  std::vector<PlacedVolume> sensComponents;
74  int comp_num = 0;
75  // go through module components
76  for (xml_coll_t comp(x_module, _U(module_component)); comp; ++comp) {
77  string component_name = _toString((int)comp_num, "component%d");
78  xml_comp_t x_component = comp;
79  Volume comp_vol(component_name,
80  Box(x_component.length(), x_component.width(),
81  x_component.thickness()),
82  lcdd.material(x_component.materialStr()));
83  comp_vol.setVisAttributes(lcdd, x_component.visStr());
84 
85  // make sensitive components sensitive
86  if (x_component.isSensitive())
87  comp_vol.setSensitiveDetector(sens);
88 
89  // Place Component in Module
90  Position trans(x_component.x(), 0., x_component.z());
91  PlacedVolume placedcomponent = mod_vol.placeVolume(comp_vol, trans);
92  placedcomponent.addPhysVolID("component", comp_num);
93  if (x_component.isSensitive())
94  sensComponents.push_back(placedcomponent);
95  comp_num++;
96  }
97  // add possible trapezoidal shape with hole for cooling pipe
98  if (x_module.hasChild(_U(subtraction))) {
99  xml_comp_t x_sub = x_module.child(_U(subtraction));
100  xml_comp_t x_trd = x_sub.child(_U(trd));
101  xml_comp_t x_tubs = x_sub.child(_U(tubs));
102  string component_name = _toString((int)comp_num, "component%d");
103  // create the two shapes first
104  Trapezoid trap_shape(x_trd.x1(), x_trd.x2(), x_trd.length(),
105  x_trd.length(), x_trd.thickness());
106  Tube tubs_shape(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz());
107  // create the subtraction
108  Volume sub_vol("subtraction_components",
109  SubtractionSolid(trap_shape, tubs_shape,
110  Transform3D(RotationX(0.5 * M_PI))),
111  lcdd.material(x_sub.materialStr()));
112  sub_vol.setVisAttributes(lcdd, x_sub.visStr());
113  // Place the volume in the module
114  PlacedVolume placedSub = mod_vol.placeVolume(
115  sub_vol, Transform3D(RotationZ(0.5 * M_PI) * RotationY(M_PI),
116  Position(0., 0., x_sub.z())));
117  placedSub.addPhysVolID("component", comp_num);
118  comp_num++;
119  }
120  // add posibble cooling pipe
121  if (x_module.hasChild(_U(tubs))) {
122  xml_comp_t x_tubs = x_module.child(_U(tubs));
123  string component_name = _toString((int)comp_num, "component%d");
124  Volume pipe_vol("CoolingPipe",
125  Tube(x_tubs.rmin(), x_tubs.rmax(), x_tubs.dz()),
126  lcdd.material(x_tubs.materialStr()));
127  pipe_vol.setVisAttributes(lcdd, x_tubs.visStr());
128  // Place the cooling pipe into the module
129  PlacedVolume placedPipe = mod_vol.placeVolume(
130  pipe_vol, Transform3D(RotationX(0.5 * M_PI) * RotationY(0.5 * M_PI),
131  Position(0., 0., x_tubs.z())));
132  placedPipe.addPhysVolID("component", comp_num);
133  comp_num++;
134  }
135  // Now place the module
136  for (int k = -zrepeat; k <= zrepeat; k++) {
137  double r = (l_rmax + l_rmin) * 0.5;
138  if (k % 2 == 0)
139  r += dr;
140  // Place the modules in phi
141  for (int i = 0; i < repeat; ++i) {
142  double phi = deltaphi / dd4hep::rad * i;
143  string module_name =
144  layer_name + _toString((int)module_num, "module%d");
145  Position trans(r * cos(phi), r * sin(phi), k * dz);
146  // create detector element
147  DetElement mod_det(lay_det, module_name, module_num);
148  // Set Sensitive Volumes sensitive
149  if (x_module.isSensitive()) {
150  mod_vol.setSensitiveDetector(sens);
151  }
152  int sens_comp_num = 0;
153  for (auto& sensComp : sensComponents) {
154  DetElement component_det(mod_det, "component", sens_comp_num);
155  component_det.setPlacement(sensComp);
156  sens_comp_num++;
157  }
158  // Place Module Box Volumes in layer
159  PlacedVolume placedmodule = layer_vol.placeVolume(
160  mod_vol,
161  Transform3D(RotationX(-0.5 * M_PI) * RotationZ(-0.5 * M_PI) *
162  RotationX(phi - 0.6 * M_PI),
163  trans));
164  placedmodule.addPhysVolID("module", module_num);
165  // assign module DetElement to the placed module volume
166  mod_det.setPlacement(placedmodule);
167  ++module_num;
168  }
169  }
170  }
171 
172  if (x_layer.hasChild(_U(tubs))) {
173  xml_comp_t x_support = x_layer.child(_U(tubs));
174  double srmin = l_rmin + x_support.offset();
175  double srmax = srmin + x_support.thickness();
176  // create the volume of the support structure
177  Volume support_vol("SupportStructure", Tube(srmin, srmax, x_support.dz()),
178  lcdd.material(x_support.materialStr()));
179  support_vol.setVisAttributes(lcdd, x_support.visStr());
180  // place the support structure
181  PlacedVolume placedSupport = layer_vol.placeVolume(support_vol);
182  placedSupport.addPhysVolID("support", 1);
183  }
184 
185  // set granularity of layer material mapping and where material should be
186  // mapped hand over modules to ACTS
187 
188  Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
189  layerExtension->addType("sensitive cylinder", "layer");
190  lay_det.addExtension<Acts::ActsExtension>(layerExtension);
191  // Place layer volume
192  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
193  placedLayer.addPhysVolID("layer", layer_num);
194  // Assign layer DetElement to layer volume
195  lay_det.setPlacement(placedLayer);
196  ++layer_num;
197  }
198  // Place Volume
199  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
200  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
201  placedTube.addPhysVolID("system", cylinderVolume.id());
202  cylinderVolume.setPlacement(placedTube);
203 
204  return cylinderVolume;
205 }
206 
207 DECLARE_DETELEMENT(ACTS_IBLSimpleBarrel, create_element)