CMS 3D CMS Logo

DTGeometryBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: DetectorDescription/DTGeometryBuilder
4 // Class: DTGeometryBuilder
5 //
14 //
15 // Original Author: Ianna Osborne
16 // Created: Wed, 16 Jan 2019 10:19:37 GMT
17 // Modified by Sergio Lo Meo (sergio.lo.meo@cern.ch) Mon, 31 August 2020
18 //
19 //
40 #include "DTGeometryBuilder.h"
41 #include "DD4hep/Detector.h"
43 
44 #include <memory>
45 #include <string>
46 #include <string_view>
47 
48 using namespace edm;
49 using namespace std;
50 using namespace cms;
51 
52 void DTGeometryBuilder::buildGeometry(DDFilteredView& fview, DTGeometry& geom, const MuonGeometryConstants& num) const {
53  edm::LogVerbatim("DTGeometryBuilder") << "(0) DTGeometryBuilder - DD4hep ";
54 
55  bool doChamber = fview.firstChild();
56 
57  while (doChamber) {
58  DTChamber* chamber = buildChamber(fview, num);
59 
60  bool doSL = fview.nextSibling();
61  while (doSL) {
62  DTSuperLayer* sl = buildSuperLayer(fview, chamber, num);
63 
64  fview.down();
65  bool doLayers = fview.sibling();
66  while (doLayers) {
67  DTLayer* l = buildLayer(fview, sl, num);
68  geom.add(l);
69 
70  doLayers = fview.sibling();
71  }
72 
73  geom.add(sl);
74  doSL = fview.nextSibling();
75  }
76  geom.add(chamber);
77 
78  fview.parent();
79  doChamber = fview.firstChild();
80  }
81 }
82 
83 DTGeometryBuilder::RCPPlane DTGeometryBuilder::plane(const DDFilteredView& fview, Bounds* bounds) const {
84  const Double_t* tr = fview.trans();
85  const Double_t* rot = fview.rot();
86 
87  return RCPPlane(
88  new Plane(Surface::PositionType(tr[0] / dd4hep::cm, tr[1] / dd4hep::cm, tr[2] / dd4hep::cm),
89  Surface::RotationType(rot[0], rot[3], rot[6], rot[1], rot[4], rot[7], rot[2], rot[5], rot[8]),
90  bounds));
91 }
92 
93 DTChamber* DTGeometryBuilder::buildChamber(DDFilteredView& fview, const MuonGeometryConstants& muonConstants) const {
94  MuonGeometryNumbering mdddnum(muonConstants);
95  DTNumberingScheme dtnum(muonConstants);
96  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
97 
98  DTChamberId detId(rawid);
99  auto const& par = fview.parameters();
100 
101  edm::LogVerbatim("DTGeometryBuilder") << "(1) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
102  << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
103 
104  RCPPlane surf(
105  plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
106 
107  DTChamber* chamber = new DTChamber(detId, surf);
108 
109  return chamber;
110 }
111 
112 DTSuperLayer* DTGeometryBuilder::buildSuperLayer(DDFilteredView& fview,
114  const MuonGeometryConstants& muonConstants) const {
115  MuonGeometryNumbering mdddnum(muonConstants);
116  DTNumberingScheme dtnum(muonConstants);
117  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
118 
119  DTSuperLayerId slId(rawid);
120 
121  auto const& par = fview.parameters();
122 
123  edm::LogVerbatim("DTGeometryBuilder") << "(2) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
124  << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
125 
126  RCPPlane surf(
127  plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
128 
129  DTSuperLayer* slayer = new DTSuperLayer(slId, surf, chamber);
130 
131  chamber->add(slayer);
132 
133  return slayer;
134 }
135 
136 DTLayer* DTGeometryBuilder::buildLayer(DDFilteredView& fview,
137  DTSuperLayer* sl,
138  const MuonGeometryConstants& muonConstants) const {
139  MuonGeometryNumbering mdddnum(muonConstants);
140  DTNumberingScheme dtnum(muonConstants);
141  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fview.history()));
142 
143  DTLayerId layId(rawid);
144 
145  auto const& par = fview.parameters();
146 
147  edm::LogVerbatim("DTGeometryBuilder") << "(3) detId: " << rawid << " par[0]: " << par[0] / dd4hep::cm
148  << " par[1]: " << par[1] / dd4hep::cm << " par[2]: " << par[2] / dd4hep::cm;
149 
150  RCPPlane surf(
151  plane(fview, new RectangularPlaneBounds(par[0] / dd4hep::cm, par[1] / dd4hep::cm, par[2] / dd4hep::cm)));
152 
153  fview.down();
154  bool doWire = fview.sibling();
155  int firstWire = fview.volume()->GetNumber();
156  auto const& wpar = fview.parameters();
157  float wireLength = wpar[1] / dd4hep::cm;
158 
159  edm::LogVerbatim("DTGeometryBuilder") << "(4) detId: " << rawid << " wpar[1]: " << wpar[1] / dd4hep::cm
160  << " firstWire: " << firstWire;
161 
162  int WCounter = 0;
163  while (doWire) {
164  doWire = fview.checkChild();
165  WCounter++;
166  }
167  fview.up();
168 
169  DTTopology topology(firstWire, WCounter, wireLength);
170 
171  DTLayerType layerType;
172 
173  DTLayer* layer = new DTLayer(layId, surf, topology, layerType, sl);
174 
175  sl->add(layer);
176  return layer;
177 }
178 
180  const DDDetector* det,
181  const MuonGeometryConstants& num,
182  const dd4hep::SpecParRefs& refs) {
183  Volume top = det->worldVolume();
184  DDFilteredView fview(det, top);
185  fview.mergedSpecifics(refs);
186  buildGeometry(fview, geom, num);
187 }
Log< level::Info, true > LogVerbatim
void up()
set current node to the parent node in the filtered tree
void mergedSpecifics(DDSpecParRefs const &)
User specific data.
const Double_t * rot() const
The absolute rotation of the current node.
void add(DTLayer *l)
Add layer to the SL which owns it.
Definition: DTSuperLayer.cc:47
bool sibling()
set the current node to the next sub sibling
Definition: Plane.h:16
void down()
set current node to the child node in the filtered tree
const Double_t * trans() const
The absolute translation of the current node.
int baseNumberToUnitNumber(const MuonBaseNumber &num) const override
bool nextSibling()
set the current node to the next sibling
const ExpandedNodes & history()
The numbering history of the current node.
bool parent()
set the current node to the parent node ...
bool firstChild()
set the current node to the first child
dd4hep::Volume Volume
Namespace of DDCMS conversion namespace.
dd4hep::Volume worldVolume() const
Handle to the world volume containing everything.
Definition: DDDetector.cc:67
HLT enums.
const PlacedVolume volume() const
The physical volume of the current node.
Definition: Bounds.h:18
bool checkChild()
count the number of children matching selection
const std::vector< double > parameters() const
extract shape parameters
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history) const