DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
SiTrackerEndcap2_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 <map>
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 vacuum = description.vacuum();
28  int det_id = x_det.id();
29  string det_name = x_det.nameStr();
30  bool reflect = x_det.reflect(false);
31  DetElement sdet (det_name,det_id);
32  Assembly assembly (det_name);
33  //Volume assembly (det_name,Box(10000,10000,10000),vacuum);
34  Volume motherVol = description.pickMotherVolume(sdet);
35  int m_id=0, c_id=0, n_sensor=0;
36  map<string,Volume> modules;
37  map<string, Placements> sensitives;
38  PlacedVolume pv;
39 
40  assembly.setVisAttributes(description.invisible());
41  sens.setType("tracker");
42 
43  for(xml_coll_t mi(x_det,_U(module)); mi; ++mi, ++m_id) {
44  xml_comp_t x_mod = mi;
45  string m_nam = x_mod.nameStr();
46  xml_comp_t trd = x_mod.trd();
47  double posY;
48  double x1 = trd.x1();
49  double x2 = trd.x2();
50  double z = trd.z();
51  double y1, y2, total_thickness=0.;
52  xml_coll_t ci(x_mod,_U(module_component));
53  for(ci.reset(), total_thickness=0.0; ci; ++ci)
54  total_thickness += xml_comp_t(ci).thickness();
55 
56  y1 = y2 = total_thickness / 2;
57  Volume m_volume(m_nam, Trapezoid(x1, x2, y1, y2, z), vacuum);
58  m_volume.setVisAttributes(description.visAttributes(x_mod.visStr()));
59 
60  for(ci.reset(), n_sensor=1, c_id=0, posY=-y1; ci; ++ci, ++c_id) {
61  xml_comp_t c = ci;
62  double c_thick = c.thickness();
63  Material c_mat = description.material(c.materialStr());
64  string c_name = _toString(c_id,"component%d");
65  Volume c_vol(c_name, Trapezoid(x1,x2,c_thick/2e0,c_thick/2e0,z), c_mat);
66 
67  c_vol.setVisAttributes(description.visAttributes(c.visStr()));
68  pv = m_volume.placeVolume(c_vol,Position(0,posY+c_thick/2,0));
69  if ( c.isSensitive() ) {
70  sdet.check(n_sensor > 2,"SiTrackerEndcap2::fromCompact: "+c_name+" Max of 2 modules allowed!");
71  pv.addPhysVolID("sensor",n_sensor);
72  c_vol.setSensitiveDetector(sens);
73  sensitives[m_nam].push_back(pv);
74  ++n_sensor;
75  }
76  posY += c_thick;
77  }
78  modules[m_nam] = m_volume;
79  }
80 
81  for(xml_coll_t li(x_det,_U(layer)); li; ++li) {
82  xml_comp_t x_layer(li);
83  int l_id = x_layer.id();
84  int mod_num = 1;
85  for(xml_coll_t ri(x_layer,_U(ring)); ri; ++ri) {
86  xml_comp_t x_ring = ri;
87  double r = x_ring.r();
88  double phi0 = x_ring.phi0(0);
89  double zstart = x_ring.zstart();
90  double dz = x_ring.dz(0);
91  int nmodules = x_ring.nmodules();
92  string m_nam = x_ring.moduleStr();
93  Volume m_vol = modules[m_nam];
94  double iphi = 2*M_PI/nmodules;
95  double phi = phi0;
96  Placements& sensVols = sensitives[m_nam];
97 
98  for(int k=0; k<nmodules; ++k) {
99  string m_base = _toString(l_id,"layer%d") + _toString(mod_num,"_module%d");
100  double x = -r*std::cos(phi);
101  double y = -r*std::sin(phi);
102  DetElement module(sdet,m_base+"_pos",det_id);
103  pv = assembly.placeVolume(m_vol,Transform3D(RotationZYX(0,-M_PI/2-phi,-M_PI/2),Position(x,y,zstart+dz)));
104  pv.addPhysVolID("barrel",1).addPhysVolID("layer", l_id).addPhysVolID("module",mod_num);
105  module.setPlacement(pv);
106  for(size_t ic=0; ic<sensVols.size(); ++ic) {
107  PlacedVolume sens_pv = sensVols[ic];
108  DetElement comp_elt(module,sens_pv.volume().name(),mod_num);
109  comp_elt.setPlacement(sens_pv);
110  }
111 
112  if ( reflect ) {
113  pv = assembly.placeVolume(m_vol,Transform3D(RotationZYX(M_PI,-M_PI/2-phi,-M_PI/2),Position(x,y,-zstart-dz)));
114  pv.addPhysVolID("barrel",2).addPhysVolID("layer",l_id).addPhysVolID("module",mod_num);
115  DetElement r_module(sdet,m_base+"_neg",det_id);
116  r_module.setPlacement(pv);
117  for(size_t ic=0; ic<sensVols.size(); ++ic) {
118  PlacedVolume sens_pv = sensVols[ic];
119  DetElement comp_elt(r_module,sens_pv.volume().name(),mod_num);
120  comp_elt.setPlacement(sens_pv);
121  }
122  }
123  dz = -dz;
124  phi += iphi;
125  ++mod_num;
126  }
127  }
128  }
129  pv = motherVol.placeVolume(assembly);
130  pv.addPhysVolID("system",det_id);
131  sdet.setPlacement(pv);
132  return sdet;
133 }
134 
135 DECLARE_DETELEMENT(DD4hep_SiTrackerEndcap2,create_detector)
136 
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::Detector::vacuum
virtual Material vacuum() const =0
Return handle to material describing vacuum.
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< NamedObject >
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::Trapezoid
Trd2 Trapezoid
Shortcut name definition.
Definition: Shapes.h:1215
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::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
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::SensitiveDetector::setType
SensitiveDetector & setType(const std::string &typ)
Set detector type (structure, tracker, calorimeter, etc.).
Definition: DetElement.cpp:403