ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TKLayoutBarrel_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TKLayoutBarrel_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 #include "DD4hep/DetFactoryHelper.h"
11 
12 using namespace std;
13 using namespace dd4hep;
14 
20 static Ref_t create_element(Detector& lcdd, xml_h xml, SensitiveDetector sens) {
21  xml_det_t x_det = xml;
22  string det_name = x_det.nameStr();
23  // Make DetElement
24  DetElement cylinderVolume(det_name, x_det.id());
25  // add Extension to Detlement for the RecoGeometry
26  Acts::ActsExtension* detvolume = new Acts::ActsExtension();
27  detvolume->addType("barrel", "detector");
28  cylinderVolume.addExtension<Acts::ActsExtension>(detvolume);
29  // make Volume
30  dd4hep::xml::Dimension x_det_dim(x_det.dimensions());
31  Tube tube_shape(x_det_dim.rmin(), x_det_dim.rmax(), x_det_dim.dz());
32  Volume tube_vol(det_name, tube_shape,
33  lcdd.air()); // air at the moment change later
34  tube_vol.setVisAttributes(lcdd, x_det_dim.visStr());
35  // go trough possible layers
36  size_t layer_num = 0;
37  for (xml_coll_t j(xml, _U(layer)); j; ++j) {
38  xml_comp_t x_layer = j;
39  double l_rmin = x_layer.inner_r();
40  double l_rmax = x_layer.outer_r();
41  double l_length = x_layer.z();
42  // Create Volume and DetElement for Layer
43  string layer_name = det_name + _toString((int)layer_num, "layer%d");
44  Volume layer_vol(layer_name, Tube(l_rmin, l_rmax, l_length),
45  lcdd.material(x_layer.materialStr()));
46  DetElement lay_det(cylinderVolume, layer_name, layer_num);
47  // Visualization
48  layer_vol.setVisAttributes(lcdd, x_layer.visStr());
49  // go trough possible modules
50  if (x_layer.hasChild(_U(module))) {
51  xml_comp_t x_module = x_layer.child(_U(module));
52  int repeat = x_module.repeat();
53  double deltaphi = 2. * M_PI / repeat;
54  // slices in z
55  xml_comp_t x_slice = x_layer.child(_U(slice));
56  int zrepeat = x_slice.repeat();
57  double dz = x_slice.z();
58  double dr = x_slice.dr();
59  double offsetrz = x_slice.dz();
60  size_t module_num = 0;
61  // Creat the module volume
62  Volume mod_vol(
63  "module",
64  Box(x_module.length(), x_module.width(), x_module.thickness()),
65  lcdd.material(x_module.materialStr()));
66  // Place the Modules in z
67  for (int k = -zrepeat; k <= zrepeat; k++) {
68  double r = (l_rmax + l_rmin) * 0.5;
69  string zname = _toString((int)k, "z%d");
70  if (k % 2 == 0)
71  r -= offsetrz;
72  // Place the modules in phi
73  for (int i = 0; i < repeat; ++i) {
74  double radius = r;
75  if (i % 2 == 0)
76  radius -= dr;
77  // Visualization
78  mod_vol.setVisAttributes(lcdd, x_module.visStr());
79  double phi = deltaphi / dd4hep::rad * i;
80  string module_name = zname + _toString((int)i, "module%d");
81  Position trans(radius * cos(phi), radius * sin(phi), k * dz);
82  // Create the module DetElement
83  DetElement mod_det(lay_det, module_name, module_num);
84  // Create and attach the extension for DD4Hep/Acts conversion
85  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
86  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
87  // Set Sensitive Volmes sensitive
88  if (x_module.isSensitive()) {
89  mod_vol.setSensitiveDetector(sens);
90  }
91  // Place Module Box Volumes in layer
92  PlacedVolume placedmodule = layer_vol.placeVolume(
93  mod_vol,
94  Transform3D(RotationX(-0.5 * M_PI) * RotationZ(-0.5 * M_PI) *
95  RotationX(phi - 0.5 * M_PI),
96  trans));
97  placedmodule.addPhysVolID("module", module_num);
98  // assign module DetElement to the placed module volume
99  mod_det.setPlacement(placedmodule);
100  ++module_num;
101  }
102  }
103  }
104  // set granularity of layer material mapping and where material should be
105  // mapped
106  // hand over modules to ACTS
107  Acts::ActsExtension* detlayer = new Acts::ActsExtension();
108  detlayer->addType("sensitive cylinder", "layer");
109  lay_det.addExtension<Acts::ActsExtension>(detlayer);
110  // Place layer volume
111  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
112  placedLayer.addPhysVolID("layer", layer_num);
113  // Assign layer DetElement to layer volume
114  lay_det.setPlacement(placedLayer);
115  ++layer_num;
116  }
117  // Place Volume
118  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
119  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
120  placedTube.addPhysVolID("system", cylinderVolume.id());
121  cylinderVolume.setPlacement(placedTube);
122 
123  return cylinderVolume;
124 }
125 
126 DECLARE_DETELEMENT(ACTS_TKLayoutBarrel, create_element)