DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
SiTrackerBarrel_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 "DD4hep/Printout.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  typedef vector<PlacedVolume> Placements;
26  xml_det_t x_det = e;
27  Material air = description.air();
28  int det_id = x_det.id();
29  string det_name = x_det.nameStr();
30  DetElement sdet (det_name,det_id);
31  Assembly assembly (det_name);
32  map<string, Volume> volumes;
33  map<string, Placements> sensitives;
34  PlacedVolume pv;
35 
36  sens.setType("tracker");
37  for(xml_coll_t mi(x_det,_U(module)); mi; ++mi) {
38  xml_comp_t x_mod = mi;
39  xml_comp_t m_env = x_mod.child(_U(module_envelope));
40  string m_nam = x_mod.nameStr();
41  Volume m_vol(m_nam,Box(m_env.width()/2,m_env.length()/2,m_env.thickness()/2),air);
42  int ncomponents = 0, sensor_number = 1;
43 
44  if ( volumes.find(m_nam) != volumes.end() ) {
45  printout(ERROR,"SiTrackerBarrel","Logics error in building modules.");
46  throw runtime_error("Logics error in building modules.");
47  }
48  volumes[m_nam] = m_vol;
49  m_vol.setVisAttributes(description.visAttributes(x_mod.visStr()));
50  for(xml_coll_t ci(x_mod,_U(module_component)); ci; ++ci, ++ncomponents) {
51  xml_comp_t x_comp = ci;
52  xml_comp_t x_pos = x_comp.position(false);
53  xml_comp_t x_rot = x_comp.rotation(false);
54  string c_nam = _toString(ncomponents,"component%d");
55  Box c_box(x_comp.width()/2,x_comp.length()/2,x_comp.thickness()/2);
56  Volume c_vol(c_nam,c_box,description.material(x_comp.materialStr()));
57 
58  if ( x_pos && x_rot ) {
59  Position c_pos(x_pos.x(0),x_pos.y(0),x_pos.z(0));
60  RotationZYX c_rot(x_rot.z(0),x_rot.y(0),x_rot.x(0));
61  pv = m_vol.placeVolume(c_vol, Transform3D(c_rot,c_pos));
62  }
63  else if ( x_rot ) {
64  pv = m_vol.placeVolume(c_vol,RotationZYX(x_rot.z(0),x_rot.y(0),x_rot.x(0)));
65  }
66  else if ( x_pos ) {
67  pv = m_vol.placeVolume(c_vol,Position(x_pos.x(0),x_pos.y(0),x_pos.z(0)));
68  }
69  else {
70  pv = m_vol.placeVolume(c_vol);
71  }
72  c_vol.setRegion(description, x_comp.regionStr());
73  c_vol.setLimitSet(description, x_comp.limitsStr());
74  c_vol.setVisAttributes(description, x_comp.visStr());
75  if ( x_comp.isSensitive() ) {
76  pv.addPhysVolID(_U(sensor),sensor_number++);
77  c_vol.setSensitiveDetector(sens);
78  sensitives[m_nam].push_back(pv);
79  }
80  }
81  }
82  for(xml_coll_t li(x_det,_U(layer)); li; ++li) {
83  xml_comp_t x_layer = li;
84  xml_comp_t x_barrel = x_layer.child(_U(barrel_envelope));
85  xml_comp_t x_layout = x_layer.child(_U(rphi_layout));
86  xml_comp_t z_layout = x_layer.child(_U(z_layout)); // Get the <z_layout> element.
87  int lay_id = x_layer.id();
88  string m_nam = x_layer.moduleStr();
89  string lay_nam = _toString(x_layer.id(),"layer%d");
90  Tube lay_tub (x_barrel.inner_r(),x_barrel.outer_r(),x_barrel.z_length()/2);
91  Volume lay_vol (lay_nam,lay_tub,air); // Create the layer envelope volume.
92  double phi0 = x_layout.phi0(); // Starting phi of first module.
93  double phi_tilt = x_layout.phi_tilt(); // Phi tilt of a module.
94  double rc = x_layout.rc(); // Radius of the module center.
95  int nphi = x_layout.nphi(); // Number of modules in phi.
96  double rphi_dr = x_layout.dr(); // The delta radius of every other module.
97  double phi_incr = (M_PI * 2) / nphi; // Phi increment for one module.
98  double phic = phi0; // Phi of the module center.
99  double z0 = z_layout.z0(); // Z position of first module in phi.
100  double nz = z_layout.nz(); // Number of modules to place in z.
101  double z_dr = z_layout.dr(); // Radial displacement parameter, of every other module.
102  Volume m_env = volumes[m_nam];
103  DetElement lay_elt(sdet,_toString(x_layer.id(),"layer%d"),lay_id);
104  Placements& sensVols = sensitives[m_nam];
105 
106  // Z increment for module placement along Z axis.
107  // Adjust for z0 at center of module rather than
108  // the end of cylindrical envelope.
109  double z_incr = nz > 1 ? (2.0 * z0) / (nz - 1) : 0.0;
110  // Starting z for module placement along Z axis.
111  double module_z = -z0;
112  int module = 1;
113 
114  // Loop over the number of modules in phi.
115  for (int ii = 0; ii < nphi; ii++) {
116  double dx = z_dr * std::cos(phic + phi_tilt); // Delta x of module position.
117  double dy = z_dr * std::sin(phic + phi_tilt); // Delta y of module position.
118  double x = rc * std::cos(phic); // Basic x module position.
119  double y = rc * std::sin(phic); // Basic y module position.
120 
121  // Loop over the number of modules in z.
122  for (int j = 0; j < nz; j++) {
123  string module_name = _toString(module,"module%d");
124  DetElement mod_elt(lay_elt,module_name,module);
125  // Module PhysicalVolume.
126  // Transform3D tr(RotationZYX(0,-((M_PI/2)-phic-phi_tilt),M_PI/2),Position(x,y,module_z));
127  //NOTE (Nikiforos, 26/08 Rotations needed to be fixed so that component1 (silicon) is on the outside
128  Transform3D tr(RotationZYX(0,((M_PI/2)-phic-phi_tilt),-M_PI/2),Position(x,y,module_z));
129 
130  pv = lay_vol.placeVolume(m_env,tr);
131  pv.addPhysVolID("module", module);
132  mod_elt.setPlacement(pv);
133  for(size_t ic=0; ic<sensVols.size(); ++ic) {
134  PlacedVolume sens_pv = sensVols[ic];
135  DetElement comp_elt(mod_elt,sens_pv.volume().name(),module);
136  comp_elt.setPlacement(sens_pv);
137  }
138 
140  module++;
141  // Adjust the x and y coordinates of the module.
142  x += dx;
143  y += dy;
144  // Flip sign of x and y adjustments.
145  dx *= -1;
146  dy *= -1;
147  // Add z increment to get next z placement pos.
148  module_z += z_incr;
149  }
150  phic += phi_incr; // Increment the phi placement of module.
151  rc += rphi_dr; // Increment the center radius according to dr parameter.
152  rphi_dr *= -1; // Flip sign of dr parameter.
153  module_z = -z0; // Reset the Z placement parameter for module.
154  }
155  // Create the PhysicalVolume for the layer.
156  pv = assembly.placeVolume(lay_vol); // Place layer in mother
157  pv.addPhysVolID("layer", lay_id); // Set the layer ID.
158  lay_elt.setAttributes(description,lay_vol,x_layer.regionStr(),x_layer.limitsStr(),x_layer.visStr());
159  lay_elt.setPlacement(pv);
160  }
161  sdet.setAttributes(description,assembly,x_det.regionStr(),x_det.limitsStr(),x_det.visStr());
162  assembly.setVisAttributes(description.invisible());
163  pv = description.pickMotherVolume(sdet).placeVolume(assembly);
164  pv.addPhysVolID("system", det_id); // Set the subdetector system ID.
165  pv.addPhysVolID("barrel", 0); // Flag this as a barrel subdetector.
166  sdet.setPlacement(pv);
167  return sdet;
168 }
169 
170 DECLARE_DETELEMENT(DD4hep_SiTrackerBarrel,create_detector)
171 
dd4hep::xml::Collection_t
Class to support the access to collections of XmlNodes (or XmlElements)
Definition: XMLElements.h:636
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::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::xml::Handle_t
Class to easily access the properties of single XmlElements.
Definition: XMLElements.h:380
dd4hep::Handle::name
const char * name() const
Access the object name (or "" if not supported by the object)
dd4hep::Assembly
Implementation class extending the ROOT assembly volumes (TGeoVolumeAssembly)
Definition: Volumes.h:762
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::Material
Handle class describing a material.
Definition: Objects.h:272
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
xml_det_t
dd4hep::xml::DetElement xml_det_t
Definition: XML.h:32
_U
#define _U(a)
Definition: Tags.h:23
dd4hep::Detector::invisible
virtual VisAttr invisible() const =0
Return handle to "invisible" visualization attributes.
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::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::PlacedVolume::volume
Volume volume() const
Logical volume of this placement.
Definition: Volumes.cpp:452
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::Tube
Class describing a tube shape of a section of a tube.
Definition: Shapes.h:628
Printout.h
dd4hep::SensitiveDetector::setType
SensitiveDetector & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: DetElement.cpp:403