EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TKLayoutEndcap_geo.cpp
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TKLayoutEndcap_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 
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 Detlement for the RecoGeometry
28  Acts::ActsExtension* detvolume = new Acts::ActsExtension();
29  detvolume->addType("endcap", "detector");
30  cylinderVolume.addExtension<Acts::ActsExtension>(detvolume);
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  int module_num_num = 0;
39  size_t layer_num = 0;
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.dz();
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  for (xml_coll_t i(x_layer, _U(module)); i; i++) {
55  xml_comp_t x_module = i;
56  int repeat = x_module.repeat();
57  double deltaphi = 2. * M_PI / repeat;
58  double radius = x_module.radius();
59  // Create the module volume
60  Volume mod_vol(
61  "module",
62  Trapezoid(x_module.x1(), x_module.x2(), x_module.thickness(),
63  x_module.thickness(), x_module.length()),
64  lcdd.material(x_module.materialStr()));
65  size_t module_num = 0;
66  // Place the Modules
67  for (int k = 0; k < repeat; k++) {
68  double slicedz = x_module.dz();
69  if (k % 2 == 0)
70  slicedz -= 10. * x_module.thickness();
71  string zname = _toString((int)k, "z%d");
72  // Visualization
73  mod_vol.setVisAttributes(lcdd, x_module.visStr());
74  double phi = deltaphi / dd4hep::rad * k;
75  string module_name =
76  zname + _toString((int)(repeat * module_num_num + module_num),
77  "module%d");
78  Position trans(radius * cos(phi), radius * sin(phi), slicedz);
79  // Create the module DetElement
80  DetElement mod_det(lay_det, module_name,
81  repeat * module_num_num + module_num);
82  // Create and attach the extension for DD4Hep/Acts conversion
83  Acts::ActsExtension* moduleExtension = new Acts::ActsExtension();
84  mod_det.addExtension<Acts::ActsExtension>(moduleExtension);
85  // Set Sensitive Volmes sensitive
86  if (x_module.isSensitive()) {
87  mod_vol.setSensitiveDetector(sens);
88  }
89  // Place Module Box Volumes in layer
90  PlacedVolume placedmodule = layer_vol.placeVolume(
91  mod_vol,
92  Transform3D(RotationX(0.5 * M_PI) * RotationY(phi + 0.5 * M_PI),
93  trans));
94  placedmodule.addPhysVolID("module",
95  repeat * module_num_num + module_num);
96  // assign module DetElement to the placed module volume
97  mod_det.setPlacement(placedmodule);
98  ++module_num;
99  }
100  ++module_num_num;
101  }
102  }
103  // set granularity of layer material mapping and where material should be
104  // mapped
105  // hand over modules to ACTS
106  Acts::ActsExtension* detlayer = new Acts::ActsExtension();
107  detlayer->addType("axes", "definitions", "XZy");
108  detlayer->addType("sensitive disk", "layer");
109  lay_det.addExtension<Acts::ActsExtension>(detlayer);
110  double layerZpos = x_layer.z();
111  // Placed Layer Volume
112  Position layer_pos(0., 0., layerZpos);
113  PlacedVolume placedLayer = tube_vol.placeVolume(layer_vol, layer_pos);
114  placedLayer.addPhysVolID("layer", layer_num);
115  lay_det.setPlacement(placedLayer);
116  ++layer_num;
117  }
118 
119  // if it is the negative endcap the normal vector needs to point into the
120  // Place Volume
121  Position endcap_translation(0., 0., x_det_dim.z());
122  Rotation3D rotation(1., 0., 0., 0., 1., 0., 0., 0., 1.);
123  if (x_det_dim.z() < 0.) {
124  rotation.SetComponents(1., 0., 0., 0., 1., 0., 0., 0., -1.);
125  }
126  Transform3D endcap_transform(rotation, endcap_translation);
127  Volume mother_vol = lcdd.pickMotherVolume(cylinderVolume);
128  PlacedVolume placedTube = mother_vol.placeVolume(tube_vol, endcap_transform);
129  placedTube.addPhysVolID("system", cylinderVolume.id());
130  cylinderVolume.setPlacement(placedTube);
131 
132  return cylinderVolume;
133 }
134 
135 DECLARE_DETELEMENT(ACTS_TKLayoutEndcap, create_element)