DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
EcalBarrel_geo.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 //
14 // Specialized generic detector constructor
15 //
16 //==========================================================================
18 #include "XML/Layering.h"
19 
20 using namespace std;
21 using namespace dd4hep;
22 using namespace dd4hep::detail;
23 
24 static Ref_t create_detector(Detector& description, xml_h e, SensitiveDetector sens) {
25  static double tolerance = 0e0;
26  Layering layering (e);
27  xml_det_t x_det = e;
28  Material air = description.air();
29  int det_id = x_det.id();
30  string det_name = x_det.nameStr();
31  xml_comp_t x_staves = x_det.staves();
32  xml_comp_t x_dim = x_det.dimensions();
33  int nsides = x_dim.numsides();
34  double inner_r = x_dim.rmin();
35  double dphi = (2*M_PI/nsides);
36  double hphi = dphi/2;
37  double mod_z = layering.totalThickness();
38  double outer_r = inner_r + mod_z;
39  double totThick = mod_z;
40  DetElement sdet (det_name,det_id);
41  Volume motherVol = description.pickMotherVolume(sdet);
42  PolyhedraRegular hedra (nsides,inner_r,inner_r+totThick+tolerance*2e0,x_dim.z());
43  Volume envelope (det_name,hedra,air);
44  PlacedVolume env_phv = motherVol.placeVolume(envelope,RotationZYX(0,0,M_PI/nsides));
45 
46  env_phv.addPhysVolID("system",det_id);
47  env_phv.addPhysVolID("barrel",0);
48  sdet.setPlacement(env_phv);
49 
50  DetElement stave_det("stave0",det_id);
51  double dx = 0.0; //mod_z / std::sin(dphi); // dx per layer
52 
53  // Compute the top and bottom face measurements.
54  double trd_x2 = (2 * std::tan(hphi) * outer_r - dx)/2 - tolerance;
55  double trd_x1 = (2 * std::tan(hphi) * inner_r + dx)/2 - tolerance;
56  double trd_y1 = x_dim.z()/2 - tolerance;
57  double trd_y2 = trd_y1;
58  double trd_z = mod_z/2 - tolerance;
59 
60  // Create the trapezoid for the stave.
61  Trapezoid trd(trd_x1, // Outer side, i.e. the "short" X side.
62  trd_x2, // Inner side, i.e. the "long" X side.
63  trd_y1, // Corresponds to subdetector (or module) Z.
64  trd_y2, //
65  trd_z); // Thickness, in Y for top stave, when rotated.
66 
67  Volume mod_vol("stave",trd,air);
68 
69  sens.setType("calorimeter");
70  { // ===== buildBarrelStave(description, sens, module_volume) =====
71  // Parameters for computing the layer X dimension:
72  double stave_z = trd_y1;
73  double tan_hphi = std::tan(hphi);
74  double l_dim_x = trd_x1; // Starting X dimension for the layer.
75  double l_pos_z = -(layering.totalThickness() / 2);
76 
77  // Loop over the sets of layer elements in the detector.
78  int l_num = 1;
79  for(xml_coll_t li(x_det,_U(layer)); li; ++li) {
80  xml_comp_t x_layer = li;
81  int repeat = x_layer.repeat();
82  // Loop over number of repeats for this layer.
83  for (int j=0; j<repeat; j++) {
84  string l_name = _toString(l_num,"layer%d");
85  double l_thickness = layering.layer(l_num-1)->thickness(); // Layer's thickness.
86 
87  Position l_pos(0,0,l_pos_z+l_thickness/2); // Position of the layer.
88  Box l_box(l_dim_x-tolerance,stave_z-tolerance,l_thickness / 2-tolerance);
89  Volume l_vol(l_name,l_box,air);
90  DetElement layer(stave_det, l_name, det_id);
91 
92  // Loop over the sublayers or slices for this layer.
93  int s_num = 1;
94  double s_pos_z = -(l_thickness / 2);
95  for(xml_coll_t si(x_layer,_U(slice)); si; ++si) {
96  xml_comp_t x_slice = si;
97  string s_name = _toString(s_num,"slice%d");
98  double s_thick = x_slice.thickness();
99  Box s_box(l_dim_x-tolerance,stave_z-tolerance,s_thick / 2-tolerance);
100  Volume s_vol(s_name,s_box,description.material(x_slice.materialStr()));
101  DetElement slice(layer,s_name,det_id);
102 
103  if ( x_slice.isSensitive() ) {
104  s_vol.setSensitiveDetector(sens);
105  }
106  slice.setAttributes(description,s_vol,x_slice.regionStr(),x_slice.limitsStr(),x_slice.visStr());
107 
108  // Slice placement.
109  PlacedVolume slice_phv = l_vol.placeVolume(s_vol,Position(0,0,s_pos_z+s_thick/2));
110  slice_phv.addPhysVolID("slice", s_num);
111  slice.setPlacement(slice_phv);
112  // Increment Z position of slice.
113  s_pos_z += s_thick;
114 
115  // Increment slice number.
116  ++s_num;
117  }
118 
119  // Set region, limitset, and vis of layer.
120  layer.setAttributes(description,l_vol,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr());
121 
122  PlacedVolume layer_phv = mod_vol.placeVolume(l_vol,l_pos);
123  layer_phv.addPhysVolID("layer", l_num);
124  layer.setPlacement(layer_phv);
125  // Increment to next layer Z position.
126  double xcut = l_thickness * tan_hphi;
127  l_dim_x += xcut;
128  l_pos_z += l_thickness;
129  ++l_num;
130  }
131  }
132  }
133 
134  // Set stave visualization.
135  if ( x_staves ) {
136  mod_vol.setVisAttributes(description.visAttributes(x_staves.visStr()));
137  }
138  // Phi start for a stave.
139  double phi = M_PI / nsides;
140  double mod_x_off = dx / 2; // Stave X offset, derived from the dx.
141  double mod_y_off = inner_r + mod_z/2; // Stave Y offset
142 
143  // Create nsides staves.
144  for (int i = 0; i < nsides; i++, phi -= dphi) { // i is module number
145  // Compute the stave position
146  double m_pos_x = mod_x_off * std::cos(phi) - mod_y_off * std::sin(phi);
147  double m_pos_y = mod_x_off * std::sin(phi) + mod_y_off * std::cos(phi);
148  Transform3D tr(RotationZYX(0,phi,M_PI*0.5),Translation3D(-m_pos_x,-m_pos_y,0));
149  PlacedVolume pv = envelope.placeVolume(mod_vol,tr);
150  pv.addPhysVolID("system",det_id);
151  pv.addPhysVolID("barrel",0);
152  pv.addPhysVolID("module",i+1);
153  DetElement sd = i==0 ? stave_det : stave_det.clone(_toString(i,"stave%d"));
154  sd.setPlacement(pv);
155  sdet.add(sd);
156  }
157 
158  // Set envelope volume attributes.
159  envelope.setAttributes(description,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
160  return sdet;
161 }
162 
163 DECLARE_DETELEMENT(DD4hep_EcalBarrel,create_detector)
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
dd4hep::PolyhedraRegular
Class describing a regular polyhedron shape.
Definition: Shapes.h:1493
dd4hep::SensitiveDetector
Handle class to hold the information of a sensitive detector.
Definition: DetElement.h:44
DECLARE_DETELEMENT
#define DECLARE_DETELEMENT(name, func)
Definition: Factories.h:339
M_PI
#define M_PI
Definition: Handle.h:33
dd4hep::PlacedVolume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:173
dd4hep::DetElement::clone
DetElement clone(int flag) const
Clone (Deep copy) the DetElement structure.
Definition: DetElement.cpp:274
dd4hep::PlacedVolume::addPhysVolID
PlacedVolume & addPhysVolID(const std::string &name, int value)
Add identifier.
Definition: Volumes.cpp:485
dd4hep::Handle
Handle: a templated class like a shared pointer, which allows specialized access to tgeometry objects...
Definition: Handle.h:84
dd4hep::_toString
std::string _toString(bool value)
String conversions: boolean value to string.
Definition: Handle.cpp:332
dd4hep::Detector::pickMotherVolume
virtual Volume pickMotherVolume(const DetElement &sd) const =0
Access mother volume by detector element.
dd4hep::DetElement::add
DetElement & add(DetElement sub_element)
Add new child to the detector structure.
Definition: DetElement.cpp:258
dd4hep::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::Volume::placeVolume
PlacedVolume placeVolume(const Volume &volume) const
Place daughter volume. The position and rotation are the identity.
Definition: Volumes.cpp:830
xml_comp_t
dd4hep::xml::Component xml_comp_t
Definition: XML.h:33
dd4hep::Trd2
Class describing a Trd2 shape.
Definition: Shapes.h:1163
dd4hep::Material
Handle class describing a material.
Definition: Objects.h:272
dd4hep::Translation3D
ROOT::Math::Translation3D Translation3D
Definition: Objects.h:119
dd4hep::Detector::material
virtual Material material(const std::string &name) const =0
Retrieve a matrial by its name from the detector description.
dd4hep::DetElement
Handle class describing a detector element.
Definition: DetElement.h:188
dd4hep::Detector::air
virtual Material air() const =0
Return handle to material describing air.
dd4hep::Volume
Handle class holding a placed volume (also called physical volume)
Definition: Volumes.h:378
dd4hep::detail
DD4hep internal namespace.
Definition: Alignments.h:32
dd4hep::DetElement::setAttributes
DetElement & setAttributes(const Detector &description, const Volume &volume, const std::string &region, const std::string &limits, const std::string &vis)
Set all attributes in one go.
Definition: DetElement.cpp:380
xml_det_t
dd4hep::xml::DetElement xml_det_t
Definition: XML.h:32
_U
#define _U(a)
Definition: Tags.h:23
Layering.h
dd4hep::DetElement::setPlacement
DetElement & setPlacement(const PlacedVolume &volume)
Set the physical volumes of the detector element.
Definition: DetElement.cpp:330
dd4hep::Detector::visAttributes
virtual const HandleMap & visAttributes() const =0
Accessor to the map of visualisation attributes.
dd4hep::Transform3D
ROOT::Math::Transform3D Transform3D
Definition: Objects.h:117
dd4hep::Layering
Class to convert a layering object from the compact notation.
Definition: Layering.h:116
dd4hep::Position
ROOT::Math::XYZVector Position
Definition: Objects.h:81
DetFactoryHelper.h
dd4hep::Box
Class describing a box shape.
Definition: Shapes.h:294
std
Definition: Plugins.h:30
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::Detector
The main interface to the dd4hep detector description package.
Definition: Detector.h:90
dd4hep::RotationZYX
ROOT::Math::RotationZYX RotationZYX
Definition: Objects.h:105
dd4hep::SensitiveDetector::setType
SensitiveDetector & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: DetElement.cpp:403