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 
12 #include "DD4hep/DetFactoryHelper.h"
13 
14 using namespace std;
15 using namespace dd4hep;
16 
22 static Ref_t create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
23  xml_det_t x_det = xml;
24  string det_name = x_det.nameStr();
25  // Make DetElement
26  DetElement cylinderVolume(det_name, x_det.id());
27  // Add Extension to DetElement for the RecoGeometry
28  Acts::ActsExtension* barrelExtension = new Acts::ActsExtension();
29  barrelExtension->addType("barrel", "detector");
30  cylinderVolume.addExtension<Acts::ActsExtension>(barrelExtension);
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 
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.z();
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  // go trough possible modules
53  if (x_layer.hasChild(_U(module))) {
54  xml_comp_t x_module = x_layer.child(_U(module));
55  int repeat = x_module.repeat();
56  double deltaphi = 2. * M_PI / repeat;
57  // slices in z
58  xml_comp_t x_slice = x_layer.child(_U(slice));
59  int zrepeat = x_slice.repeat();
60  double dz = x_slice.z();
61  double dr = x_slice.dr();
62  // Create the module volume
63  Volume mod_vol(
64  "module",
65  Box(x_module.width(), x_module.length(), x_module.thickness()),
66  lcdd.material(x_module.materialStr()));
67 
68  // create the Acts::DigitizationModule (needed to do geometric
69  // digitization) for all modules which have the same segmentation
70  auto digiModule =
72  x_module.length(), x_module.width(), x_module.thickness(),
73  sens.readout().segmentation());
74 
75  // Visualization
76  mod_vol.setVisAttributes(lcdd, x_module.visStr());
77  size_t module_num = 0;
78  // Place the Modules in z
79  for (int k = -zrepeat; k <= zrepeat; k++) {
80  double r = (l_rmax + l_rmin) * 0.5;
81  string zname = _toString((int)k, "z%d");
82  if (k % 2 == 0)
83  r += dr;
84  // Place the modules in phi
85  for (int i = 0; i < repeat; ++i) {
86  double phi = deltaphi / dd4hep::rad * i;
87  string module_name = zname + _toString((int)i, "module%d");
88  Position trans(r * cos(phi), r * sin(phi), k * dz);
89  // Create the module DetElement
90  DetElement mod_det(lay_det, module_name, module_num);
91  // Set Sensitive Volmes sensitive
92  if (x_module.isSensitive()) {
93  mod_vol.setSensitiveDetector(sens);
94  // Create and attach the extension for DD4Hep/Acts conversion
95  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
96  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
97  }
98  // Place Module Box Volumes in layer
99  PlacedVolume placedmodule = layer_vol.placeVolume(
100  mod_vol,
101  Transform3D(RotationX(0.5 * M_PI) * RotationY(phi - 0.6 * M_PI),
102  trans));
103  placedmodule.addPhysVolID("module", module_num);
104  // assign module DetElement to the placed module volume
105  mod_det.setPlacement(placedmodule);
106  ++module_num;
107  }
108  }
109  }
110 
111  // Place the layer with appropriate Acts::Extension
112  // Configure the ACTS extension
113  Acts::ActsExtension* layerExtension = new Acts::ActsExtension();
114  layerExtension->addType("active cylinder", "layer");
115  layerExtension->addType("axes", "definitions", "YxZ");
116  lay_det.addExtension<Acts::ActsExtension>(layerExtension);
117  // Place layer volume
118  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
119  placedLayer.addPhysVolID("layer", layer_num);
120  // Assign layer DetElement to layer volume
121  lay_det.setPlacement(placedLayer);
122  ++layer_num;
123  }
124  // Place Volume
125  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
126  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
127  placedTube.addPhysVolID("system", cylinderVolume.id());
128  cylinderVolume.setPlacement(placedTube);
129 
130  return cylinderVolume;
131 }
132 
133 DECLARE_DETELEMENT(ACTS_Barrel, create_element)