CMS 3D CMS Logo

DTGeometryParsFromDD.cc
Go to the documentation of this file.
1 
29 #include <iostream>
30 #include <algorithm>
31 #include <string>
32 
33 using namespace geant_units;
34 using namespace geant_units::operators;
35 
36 //#define EDM_ML_DEBUG
37 
39 
41 
42 // DD
44  const MuonGeometryConstants& muonConstants,
45  RecoIdealGeometry& rig) {
46 #ifdef EDM_ML_DEBUG
47  edm::LogVerbatim("DTGeometry") << "DTGeometryParsFromDD::build";
48 #endif
49 
50  std::string attribute = "MuStructure";
51  std::string value = "MuonBarrelDT";
52 
53  // Asking only for the Muon DTs
55  DDFilteredView fview(*cview, filter);
56  buildGeometry(fview, muonConstants, rig);
57 #ifdef EDM_ML_DEBUG
58  edm::LogVerbatim("DTGeometry") << "RecoIdealGeometry " << rig.size();
59 #endif
60 }
61 
62 // DD4hep
63 
65  const MuonGeometryConstants& muonConstants,
66  RecoIdealGeometry& rgeo) {
67  const std::string attribute = "MuStructure";
68  const std::string value = "MuonBarrelDT";
69  const cms::DDFilter filter(attribute, value);
70  cms::DDFilteredView fview(*cview, filter);
71  buildGeometry(fview, muonConstants, rgeo);
72 }
73 
74 // DD
76  const MuonGeometryConstants& muonConstants,
77  RecoIdealGeometry& rig) const {
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DDD ";
80 #endif
81  bool doChamber = fv.firstChild();
82 
83  // Loop on chambers
84  while (doChamber) {
85  DDValue val("Type");
88  if (DDfetch(&params, val))
89  type = val.strings()[0];
90  // FIXME
91  val = DDValue("FEPos");
92  std::string FEPos;
93  if (DDfetch(&params, val))
94  FEPos = val.strings()[0];
95  insertChamber(fv, type, muonConstants, rig);
96 
97  // Loop on SLs
98  bool doSL = fv.firstChild();
99  while (doSL) {
100  insertSuperLayer(fv, type, muonConstants, rig);
101 
102  bool doL = fv.firstChild();
103  // Loop on SLs
104  while (doL) {
105  insertLayer(fv, type, muonConstants, rig);
106 
107  // fv.parent();
108  doL = fv.nextSibling(); // go to next layer
109  } // layers
110 
111  fv.parent();
112  doSL = fv.nextSibling(); // go to next SL
113  } // sls
114 
115  fv.parent();
116  doChamber = fv.nextSibling(); // go to next chamber
117  } // chambers
118 }
119 
121  const std::string& type,
122  const MuonGeometryConstants& muonConstants,
123  RecoIdealGeometry& rig) const {
124  MuonGeometryNumbering mdddnum(muonConstants);
125  DTNumberingScheme dtnum(muonConstants);
126  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
127  DTChamberId detId(rawid);
128 #ifdef EDM_ML_DEBUG
129  edm::LogVerbatim("DTGeometry") << "inserting Chamber " << detId;
130 #endif
131 
132  // Chamber specific parameter (size)
133  std::vector<double> par;
134  par.emplace_back(DTChamberTag);
135  std::vector<double> size = extractParameters(fv);
136  par.insert(par.end(), size.begin(), size.end());
137 #ifdef EDM_ML_DEBUG
138  edm::LogVerbatim("DTGeometryParsFromDD")
139  << "(1) DDD, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
140 #endif
141  // width is along local X
143  // length is along local Y
144  // thickness is long local Z
145 
146  PosRotPair posRot(plane(fv));
147  rig.insert(rawid, posRot.first, posRot.second, par);
148 }
149 
151  const std::string& type,
152  const MuonGeometryConstants& muonConstants,
153  RecoIdealGeometry& rig) const {
154  MuonGeometryNumbering mdddnum(muonConstants);
155  DTNumberingScheme dtnum(muonConstants);
156  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
157  DTSuperLayerId slId(rawid);
158 #ifdef EDM_ML_DEBUG
159  edm::LogVerbatim("DTGeometry") << "inserting SuperLayer " << slId;
160 #endif
161 
162  // Slayer specific parameter (size)
163  std::vector<double> par;
164  par.emplace_back(DTSuperLayerTag);
165  std::vector<double> size = extractParameters(fv);
166  par.insert(par.end(), size.begin(), size.end());
167 #ifdef EDM_ML_DEBUG
168  edm::LogVerbatim("DTGeometryParsFromDD")
169  << "(2) DDD, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
170 #endif
171  // Ok this is the slayer position...
172  PosRotPair posRot(plane(fv));
173  rig.insert(slId, posRot.first, posRot.second, par);
174 }
175 
177  const std::string& type,
178  const MuonGeometryConstants& muonConstants,
179  RecoIdealGeometry& rig) const {
180  MuonGeometryNumbering mdddnum(muonConstants);
181  DTNumberingScheme dtnum(muonConstants);
182  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
183  DTLayerId layId(rawid);
184 #ifdef EDM_ML_DEBUG
185  edm::LogVerbatim("DTGeometry") << "inserting Layer " << layId;
186 #endif
187  // Layer specific parameter (size)
188  std::vector<double> par;
189  par.emplace_back(DTLayerTag);
190  std::vector<double> size = extractParameters(fv);
191  par.insert(par.end(), size.begin(), size.end());
192 
193  // Loop on wires
194  bool doWire = fv.firstChild();
195  int WCounter = 0;
196  int firstWire = fv.copyno();
197  //float wireLength = par[1]/cm;
198  while (doWire) {
199  WCounter++;
200  doWire = fv.nextSibling(); // next wire
201  }
202  std::vector<double> sensSize = extractParameters(fv);
203  //int lastWire=fv.copyno();
204  par.emplace_back(firstWire);
205  par.emplace_back(WCounter);
206  par.emplace_back(sensSize[1]);
207  fv.parent();
208 
209  PosRotPair posRot(plane(fv));
210 
211 #ifdef EDM_ML_DEBUG
212  edm::LogVerbatim("DTGeometryParsFromDD")
213  << "(3) DDD, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
214  << par[4] << " " << par[5] << " " << par[6];
215 #endif
216  rig.insert(layId, posRot.first, posRot.second, par);
217 }
218 
220  std::vector<double> par;
221  if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
223  DDSolid A = bs.solidA();
224  while (A.shape() != DDSolidShape::ddbox) {
226  A = bs.solidA();
227  }
228  par = A.parameters();
229  } else {
230  par = fv.logicalPart().solid().parameters();
231  }
232  return par;
233 }
234 
236  // extract the position
237  const DDTranslation& trans(fv.translation());
238 
239  std::vector<double> gtran(3);
240  gtran[0] = convertMmToCm(trans.x());
241  gtran[1] = convertMmToCm(trans.y());
242  gtran[2] = convertMmToCm(trans.z());
243 
244 #ifdef EDM_ML_DEBUG
245  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DDD, Position "
246  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
247 #endif
248  // now the rotation
249  // 'active' and 'passive' rotations are inverse to each other
250  const DDRotationMatrix& rotation = fv.rotation(); //REMOVED .Inverse();
251  DD3Vector x, y, z;
252  rotation.GetComponents(x, y, z);
253 
254  std::vector<double> grmat(9);
255  grmat[0] = x.X();
256  grmat[1] = x.Y();
257  grmat[2] = x.Z();
258 
259  grmat[3] = y.X();
260  grmat[4] = y.Y();
261  grmat[5] = y.Z();
262 
263  grmat[6] = z.X();
264  grmat[7] = z.Y();
265  grmat[8] = z.Z();
266 
267  return std::pair<std::vector<double>, std::vector<double> >(gtran, grmat);
268 }
269 
270 // DD4hep
271 
273  const MuonGeometryConstants& muonConstants,
274  RecoIdealGeometry& rig) const {
275 #ifdef EDM_ML_DEBUG
276  edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DD4hep ";
277 #endif
278  bool doChamber = fv.firstChild();
279 
280  while (doChamber) {
281  insertChamber(fv, muonConstants, rig);
282 
283  bool doSL = fv.nextSibling();
284  while (doSL) {
285  insertSuperLayer(fv, muonConstants, rig);
286 
287  fv.down();
288  bool doLayers = fv.sibling();
289  while (doLayers) {
290  insertLayer(fv, muonConstants, rig);
291 
292  doLayers = fv.sibling();
293  }
294 
295  doSL = fv.nextSibling();
296  }
297 
298  fv.parent();
299  doChamber = fv.firstChild();
300  }
301 }
302 
304  const Double_t* tr = fv.trans();
305 
306  std::vector<double> gtran(3);
307 
308  gtran[0] = tr[0] / dd4hep::cm;
309  gtran[1] = tr[1] / dd4hep::cm;
310  gtran[2] = tr[2] / dd4hep::cm;
311 
312 #ifdef EDM_ML_DEBUG
313  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DD4hep, Position "
314  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
315 #endif
317  DD3Vector x, y, z;
318  rotation.GetComponents(x, y, z);
319 
320  std::vector<double> grmat(9);
321 
322  grmat[0] = x.X();
323  grmat[1] = x.Y();
324  grmat[2] = x.Z();
325 
326  grmat[3] = y.X();
327  grmat[4] = y.Y();
328  grmat[5] = y.Z();
329 
330  grmat[6] = z.X();
331  grmat[7] = z.Y();
332  grmat[8] = z.Z();
333 
334  return std::pair<std::vector<double>, std::vector<double> >(gtran, grmat);
335 }
336 
338  const MuonGeometryConstants& muonConstants,
339  RecoIdealGeometry& rig) const {
340  MuonGeometryNumbering mdddnum(muonConstants);
341  DTNumberingScheme dtnum(muonConstants);
342  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
343  DTChamberId detId(rawid);
344 
345  std::vector<double> par_temp = fv.parameters();
346  std::vector<double> par(4);
347  par[0] = DTChamberTag; //DTChamberTag is the ID of a Chamber
348  par[1] = par_temp[0] / dd4hep::mm;
349  par[2] = par_temp[1] / dd4hep::mm;
350  par[3] = par_temp[2] / dd4hep::mm;
351 
352 #ifdef EDM_ML_DEBUG
353  edm::LogVerbatim("DTGeometryParsFromDD")
354  << "(1) DD4hep, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
355 #endif
356  PosRotPair posRot(plane(fv));
357  rig.insert(rawid, posRot.first, posRot.second, par);
358 }
359 
361  const MuonGeometryConstants& muonConstants,
362  RecoIdealGeometry& rig) const {
363  MuonGeometryNumbering mdddnum(muonConstants);
364  DTNumberingScheme dtnum(muonConstants);
365  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
366  DTSuperLayerId slId(rawid);
367 
368  std::vector<double> par_temp = fv.parameters();
369  std::vector<double> par(4);
370  par[0] = DTSuperLayerTag; //DTSuperLayerTag is the ID of a SuperLayer
371  par[1] = par_temp[0] / dd4hep::mm;
372  par[2] = par_temp[1] / dd4hep::mm;
373  par[3] = par_temp[2] / dd4hep::mm;
374 
375 #ifdef EDM_ML_DEBUG
376  edm::LogVerbatim("DTGeometryParsFromDD")
377  << "(2) DD4hep, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
378 #endif
379  PosRotPair posRot(plane(fv));
380  rig.insert(slId, posRot.first, posRot.second, par);
381 }
382 
384  const MuonGeometryConstants& muonConstants,
385  RecoIdealGeometry& rig) const {
386  MuonGeometryNumbering mdddnum(muonConstants);
387  DTNumberingScheme dtnum(muonConstants);
388  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
389  DTLayerId layId(rawid);
390 
391  std::vector<double> par_temp = fv.parameters();
392  std::vector<double> par(4);
393  par[0] = DTLayerTag; //DTLayerTag is the ID of a Layer
394  par[1] = par_temp[0] / dd4hep::mm;
395  par[2] = par_temp[1] / dd4hep::mm;
396  par[3] = par_temp[2] / dd4hep::mm;
397 
398  fv.down();
399  bool doWire = fv.sibling();
400  int firstWire = fv.volume()->GetNumber();
401  auto const& wpar = fv.parameters();
402  float wireLength = wpar[1] / dd4hep::mm;
403 
404  int WCounter = 0;
405  while (doWire) {
406  doWire = fv.checkChild();
407  WCounter++;
408  }
409 
410  par.emplace_back(firstWire);
411  par.emplace_back(WCounter);
412  par.emplace_back(wireLength);
413 
414  fv.up();
415 
416  PosRotPair posRot(plane(fv));
417 
418 #ifdef EDM_ML_DEBUG
419  edm::LogVerbatim("DTGeometryParsFromDD")
420  << "(3) DD4hep, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
421  << par[4] << " " << par[5] << " " << par[6];
422 #endif
423  rig.insert(layId, posRot.first, posRot.second, par);
424 }
Log< level::Info, true > LogVerbatim
void up()
set current node to the parent node in the filtered tree
bool parent()
set the current node to the parent node ...
void build(const DDCompactView *cview, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rig)
bool nextSibling()
set the current node to the next sibling ...
bool insert(DetId id, const std::vector< double > &trans, const std::vector< double > &rot, const std::vector< double > &pars)
PosRotPair plane(const DDFilteredView &fv) const
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:125
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool sibling()
set the current node to the next sub sibling
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
void down()
set current node to the child node in the filtered tree
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
virtual ~DTGeometryParsFromDD()
Destructor.
const Double_t * trans() const
The absolute translation of the current node.
void buildGeometry(DDFilteredView &fv, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rig) const
int baseNumberToUnitNumber(const MuonBaseNumber &num) const override
std::vector< std::pair< unsigned int, DDValue > > DDsvalues_type
Definition: DDsvalues.h:12
bool nextSibling()
set the current node to the next sibling
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const ExpandedNodes & history()
The numbering history of the current node.
int getDetId(const MuonBaseNumber &num) const
std::vector< double > extractParameters(DDFilteredView &fv) const
get parameter also for boolean solid.
Definition: value.py:1
bool parent()
set the current node to the parent node ...
bool firstChild()
set the current node to the first child
DDSolidShape shape(void) const
The type of the solid.
Definition: DDSolid.cc:123
void insertLayer(DDFilteredView &fv, const std::string &type, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rig) const
create the layer
DTGeometryParsFromDD()
Constructor.
DDsvalues_type mergedSpecifics() const
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
void insertChamber(DDFilteredView &fv, const std::string &type, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rig) const
create the chamber
constexpr NumType convertMmToCm(NumType millimeters)
Definition: angle_units.h:44
int copyno() const
Copy number associated with the current node.
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
std::pair< std::vector< double >, std::vector< double > > PosRotPair
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
const RotationMatrix rotation() const
const PlacedVolume volume() const
The physical volume of the current node.
void insertSuperLayer(DDFilteredView &fv, const std::string &type, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rig) const
create the SL
bool firstChild()
set the current node to the first child ...
float x
Definition: APVGainStruct.h:7
const DDTranslation & translation() const
The absolute translation of the current node.
bool checkChild()
count the number of children matching selection
const std::vector< double > parameters() const
extract shape parameters
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history) const