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 
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* detvolume = new Acts::ActsExtension();
28  detvolume->addType("barrel", "detector");
29  cylinderVolume.addExtension<Acts::ActsExtension>(detvolume);
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  for (xml_coll_t j(xml, _U(layer)); j; ++j) {
39  xml_comp_t x_layer = j;
40  double l_rmin = x_layer.inner_r();
41  double l_rmax = x_layer.outer_r();
42  double l_length = x_layer.z();
43  // Create Volume and DetElement 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, l_length),
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  // go trough possible modules
51  if (x_layer.hasChild(_U(module))) {
52  xml_comp_t x_module = x_layer.child(_U(module));
53  int repeat = x_module.repeat();
54  double deltaphi = 2. * M_PI / repeat;
55  // slices in z
56  xml_comp_t x_slice = x_layer.child(_U(slice));
57  int zrepeat = x_slice.repeat();
58  double dz = x_slice.z();
59  double dr = x_slice.dr();
60  double offsetrz = x_slice.dz();
61  size_t module_num = 0;
62  // Creat the module volume
63  Volume mod_vol(
64  "module",
65  Box(x_module.length(), x_module.width(), x_module.thickness()),
66  lcdd.material(x_module.materialStr()));
67  // Place the Modules in z
68  for (int k = -zrepeat; k <= zrepeat; k++) {
69  double r = (l_rmax + l_rmin) * 0.5;
70  string zname = _toString((int)k, "z%d");
71  if (k % 2 == 0)
72  r -= offsetrz;
73  // Place the modules in phi
74  for (int i = 0; i < repeat; ++i) {
75  double radius = r;
76  if (i % 2 == 0)
77  radius -= dr;
78  // Visualization
79  mod_vol.setVisAttributes(lcdd, x_module.visStr());
80  double phi = deltaphi / dd4hep::rad * i;
81  string module_name = zname + _toString((int)i, "module%d");
82  Position trans(radius * cos(phi), radius * sin(phi), k * dz);
83  // Create the module DetElement
84  DetElement mod_det(lay_det, module_name, module_num);
85  // Create and attach the extension for DD4Hep/Acts conversion
86  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
87  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
88  // Set Sensitive Volmes sensitive
89  if (x_module.isSensitive()) {
90  mod_vol.setSensitiveDetector(sens);
91  }
92  // Place Module Box Volumes in layer
93  PlacedVolume placedmodule = layer_vol.placeVolume(
94  mod_vol,
95  Transform3D(RotationX(-0.5 * M_PI) * RotationZ(-0.5 * M_PI) *
96  RotationX(phi - 0.5 * M_PI),
97  trans));
98  placedmodule.addPhysVolID("module", module_num);
99  // assign module DetElement to the placed module volume
100  mod_det.setPlacement(placedmodule);
101  ++module_num;
102  }
103  }
104  }
105  // set granularity of layer material mapping and where material should be
106  // mapped
107  // hand over modules to ACTS
108  Acts::ActsExtension* detlayer = new Acts::ActsExtension();
109  detlayer->addType("sensitive cylinder", "layer");
110  lay_det.addExtension<Acts::ActsExtension>(detlayer);
111  // Place layer volume
112  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol);
113  placedLayer.addPhysVolID("layer", layer_num);
114  // Assign layer DetElement to layer volume
115  lay_det.setPlacement(placedLayer);
116  ++layer_num;
117  }
118  // Place Volume
119  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
120  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol);
121  placedTube.addPhysVolID("system", cylinderVolume.id());
122  cylinderVolume.setPlacement(placedTube);
123 
124  return cylinderVolume;
125 }
126 
127 DECLARE_DETELEMENT(ACTS_TKLayoutBarrel, create_element)