ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Barrel_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file Barrel_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 #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 DetElement 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  double l_length = x_layer.z();
44  // Create Volume and DetElement for Layer
45  string layer_name = det_name + _toString((int)layer_num, "layer%d");
46  Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
47  lcdd.material(x_layer.materialStr()));
48  DetElement lay_det(cylinderVolume, layer_name, layer_num);
49  // Visualization
50  layer_vol.setVisAttributes(lcdd, x_layer.visStr());
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  // Create the module volume
62  Volume mod_vol(
63  "module",
64  Box(x_module.width(), x_module.length(), x_module.thickness()),
65  lcdd.material(x_module.materialStr()));
66 
67  // create the Acts::DigitizationModule (needed to do geometric
68  // digitization) for all modules which have the same segmentation
70  x_module.length(), x_module.width(), x_module.thickness(),
71  sens.readout().segmentation());
72 
73  // Visualization
74  mod_vol.setVisAttributes(lcdd, x_module.visStr());
75  size_t module_num = 0;
76  // Place the Modules in z
77  for (int k = -zrepeat; k <= zrepeat; k++) {
78  double r = (l_rmax + l_rmin) * 0.5;
79  string zname = _toString((int)k, "z%d");
80  if (k % 2 == 0)
81  r += dr;
82  // Place the modules in phi
83  for (int i = 0; i < repeat; ++i) {
84  double phi = deltaphi / dd4hep::rad * i;
85  string module_name = zname + _toString((int)i, "module%d");
86  Position trans(r * cos(phi), r * sin(phi), k * dz);
87  // Create the module DetElement
88  DetElement mod_det(lay_det, module_name, module_num);
89  // Set Sensitive Volmes sensitive
90  if (x_module.isSensitive()) {
91  mod_vol.setSensitiveDetector(sens);
92  // Create and attach the extension for DD4Hep/Acts conversion
93  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
94  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
95  }
96  // Place Module Box Volumes in layer
97  PlacedVolume placedmodule = layer_vol.placeVolume(
98  mod_vol,
99  Transform3D(RotationX(0.5 * M_PI) * RotationY(phi - 0.6 * M_PI),
100  trans));
101  placedmodule.addPhysVolID("module", module_num);
102  // assign module DetElement to the placed module volume
103  mod_det.setPlacement(placedmodule);
104  ++module_num;
105  }
106  }
107  }
108 
109  // Place the layer with appropriate Acts::Extension
110  // Configure the ACTS extension
111  Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
112  layerExtension->addType("active cylinder", "layer");
113  layerExtension->addType("axes", "definitions", "YxZ");
114  lay_det.addExtension<Acts::ActsExtension>(layerExtension);
115  // Place layer volume
116  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
117  placedLayer.addPhysVolID("layer", layer_num);
118  // Assign layer DetElement to layer volume
119  lay_det.setPlacement(placedLayer);
120  ++layer_num;
121  }
122  // Place Volume
123  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
124  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
125  placedTube.addPhysVolID("system", cylinderVolume.id());
126  cylinderVolume.setPlacement(placedTube);
127 
128  return cylinderVolume;
129 }
130 
131 DECLARE_DETELEMENT(ACTS_Barrel, create_element)