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  int ChamCounter = 0;
85  while (doChamber) {
86  ChamCounter++;
87  DDValue val("Type");
90  if (DDfetch(&params, val))
91  type = val.strings()[0];
92  // FIXME
93  val = DDValue("FEPos");
94  std::string FEPos;
95  if (DDfetch(&params, val))
96  FEPos = val.strings()[0];
97  insertChamber(fv, type, muonConstants, rig);
98 
99  // Loop on SLs
100  bool doSL = fv.firstChild();
101  int SLCounter = 0;
102  while (doSL) {
103  SLCounter++;
104  insertSuperLayer(fv, type, muonConstants, rig);
105 
106  bool doL = fv.firstChild();
107  int LCounter = 0;
108  // Loop on SLs
109  while (doL) {
110  LCounter++;
111  insertLayer(fv, type, muonConstants, rig);
112 
113  // fv.parent();
114  doL = fv.nextSibling(); // go to next layer
115  } // layers
116 
117  fv.parent();
118  doSL = fv.nextSibling(); // go to next SL
119  } // sls
120 
121  fv.parent();
122  doChamber = fv.nextSibling(); // go to next chamber
123  } // chambers
124 }
125 
127  const std::string& type,
128  const MuonGeometryConstants& muonConstants,
129  RecoIdealGeometry& rig) const {
130  MuonGeometryNumbering mdddnum(muonConstants);
131  DTNumberingScheme dtnum(muonConstants);
132  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
133  DTChamberId detId(rawid);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("DTGeometry") << "inserting Chamber " << detId;
136 #endif
137 
138  // Chamber specific parameter (size)
139  std::vector<double> par;
140  par.emplace_back(DTChamberTag);
141  std::vector<double> size = extractParameters(fv);
142  par.insert(par.end(), size.begin(), size.end());
143 #ifdef EDM_ML_DEBUG
144  edm::LogVerbatim("DTGeometryParsFromDD")
145  << "(1) DDD, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
146 #endif
147  // width is along local X
149  // length is along local Y
150  // thickness is long local Z
151 
152  PosRotPair posRot(plane(fv));
153  rig.insert(rawid, posRot.first, posRot.second, par);
154 }
155 
157  const std::string& type,
158  const MuonGeometryConstants& muonConstants,
159  RecoIdealGeometry& rig) const {
160  MuonGeometryNumbering mdddnum(muonConstants);
161  DTNumberingScheme dtnum(muonConstants);
162  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
163  DTSuperLayerId slId(rawid);
164 #ifdef EDM_ML_DEBUG
165  edm::LogVerbatim("DTGeometry") << "inserting SuperLayer " << slId;
166 #endif
167 
168  // Slayer specific parameter (size)
169  std::vector<double> par;
170  par.emplace_back(DTSuperLayerTag);
171  std::vector<double> size = extractParameters(fv);
172  par.insert(par.end(), size.begin(), size.end());
173 #ifdef EDM_ML_DEBUG
174  edm::LogVerbatim("DTGeometryParsFromDD")
175  << "(2) DDD, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
176 #endif
177  // Ok this is the slayer position...
178  PosRotPair posRot(plane(fv));
179  rig.insert(slId, posRot.first, posRot.second, par);
180 }
181 
183  const std::string& type,
184  const MuonGeometryConstants& muonConstants,
185  RecoIdealGeometry& rig) const {
186  MuonGeometryNumbering mdddnum(muonConstants);
187  DTNumberingScheme dtnum(muonConstants);
188  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
189  DTLayerId layId(rawid);
190 #ifdef EDM_ML_DEBUG
191  edm::LogVerbatim("DTGeometry") << "inserting Layer " << layId;
192 #endif
193  // Layer specific parameter (size)
194  std::vector<double> par;
195  par.emplace_back(DTLayerTag);
196  std::vector<double> size = extractParameters(fv);
197  par.insert(par.end(), size.begin(), size.end());
198 
199  // Loop on wires
200  bool doWire = fv.firstChild();
201  int WCounter = 0;
202  int firstWire = fv.copyno();
203  //float wireLength = par[1]/cm;
204  while (doWire) {
205  WCounter++;
206  doWire = fv.nextSibling(); // next wire
207  }
208  std::vector<double> sensSize = extractParameters(fv);
209  //int lastWire=fv.copyno();
210  par.emplace_back(firstWire);
211  par.emplace_back(WCounter);
212  par.emplace_back(sensSize[1]);
213  fv.parent();
214 
215  PosRotPair posRot(plane(fv));
216 
217 #ifdef EDM_ML_DEBUG
218  edm::LogVerbatim("DTGeometryParsFromDD")
219  << "(3) DDD, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
220  << par[4] << " " << par[5] << " " << par[6];
221 #endif
222  rig.insert(layId, posRot.first, posRot.second, par);
223 }
224 
226  std::vector<double> par;
227  if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
229  DDSolid A = bs.solidA();
230  while (A.shape() != DDSolidShape::ddbox) {
232  A = bs.solidA();
233  }
234  par = A.parameters();
235  } else {
236  par = fv.logicalPart().solid().parameters();
237  }
238  return par;
239 }
240 
242  // extract the position
243  const DDTranslation& trans(fv.translation());
244 
245  std::vector<double> gtran(3);
246  gtran[0] = convertMmToCm(trans.x());
247  gtran[1] = convertMmToCm(trans.y());
248  gtran[2] = convertMmToCm(trans.z());
249 
250 #ifdef EDM_ML_DEBUG
251  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DDD, Position "
252  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
253 #endif
254  // now the rotation
255  // 'active' and 'passive' rotations are inverse to each other
256  const DDRotationMatrix& rotation = fv.rotation(); //REMOVED .Inverse();
257  DD3Vector x, y, z;
258  rotation.GetComponents(x, y, z);
259 
260  std::vector<double> grmat(9);
261  grmat[0] = x.X();
262  grmat[1] = x.Y();
263  grmat[2] = x.Z();
264 
265  grmat[3] = y.X();
266  grmat[4] = y.Y();
267  grmat[5] = y.Z();
268 
269  grmat[6] = z.X();
270  grmat[7] = z.Y();
271  grmat[8] = z.Z();
272 
273  return std::pair<std::vector<double>, std::vector<double> >(gtran, grmat);
274 }
275 
276 // DD4hep
277 
279  const MuonGeometryConstants& muonConstants,
280  RecoIdealGeometry& rig) const {
281 #ifdef EDM_ML_DEBUG
282  edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DD4hep ";
283 #endif
284  bool doChamber = fv.firstChild();
285 
286  while (doChamber) {
287  insertChamber(fv, muonConstants, rig);
288 
289  bool doSL = fv.nextSibling();
290  while (doSL) {
291  insertSuperLayer(fv, muonConstants, rig);
292 
293  fv.down();
294  bool doLayers = fv.sibling();
295  while (doLayers) {
296  insertLayer(fv, muonConstants, rig);
297 
298  doLayers = fv.sibling();
299  }
300 
301  doSL = fv.nextSibling();
302  }
303 
304  fv.parent();
305  doChamber = fv.firstChild();
306  }
307 }
308 
310  const Double_t* tr = fv.trans();
311 
312  std::vector<double> gtran(3);
313 
314  gtran[0] = tr[0] / dd4hep::cm;
315  gtran[1] = tr[1] / dd4hep::cm;
316  gtran[2] = tr[2] / dd4hep::cm;
317 
318 #ifdef EDM_ML_DEBUG
319  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DD4hep, Position "
320  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
321 #endif
323  DD3Vector x, y, z;
324  rotation.GetComponents(x, y, z);
325 
326  std::vector<double> grmat(9);
327 
328  grmat[0] = x.X();
329  grmat[1] = x.Y();
330  grmat[2] = x.Z();
331 
332  grmat[3] = y.X();
333  grmat[4] = y.Y();
334  grmat[5] = y.Z();
335 
336  grmat[6] = z.X();
337  grmat[7] = z.Y();
338  grmat[8] = z.Z();
339 
340  return std::pair<std::vector<double>, std::vector<double> >(gtran, grmat);
341 }
342 
344  const MuonGeometryConstants& muonConstants,
345  RecoIdealGeometry& rig) const {
346  MuonGeometryNumbering mdddnum(muonConstants);
347  DTNumberingScheme dtnum(muonConstants);
348  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
349  DTChamberId detId(rawid);
350 
351  std::vector<double> par_temp = fv.parameters();
352  std::vector<double> par(4);
353  par[0] = DTChamberTag; //DTChamberTag is the ID of a Chamber
354  par[1] = par_temp[0] / dd4hep::mm;
355  par[2] = par_temp[1] / dd4hep::mm;
356  par[3] = par_temp[2] / dd4hep::mm;
357 
358 #ifdef EDM_ML_DEBUG
359  edm::LogVerbatim("DTGeometryParsFromDD")
360  << "(1) DD4hep, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
361 #endif
362  PosRotPair posRot(plane(fv));
363  rig.insert(rawid, posRot.first, posRot.second, par);
364 }
365 
367  const MuonGeometryConstants& muonConstants,
368  RecoIdealGeometry& rig) const {
369  MuonGeometryNumbering mdddnum(muonConstants);
370  DTNumberingScheme dtnum(muonConstants);
371  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
372  DTSuperLayerId slId(rawid);
373 
374  std::vector<double> par_temp = fv.parameters();
375  std::vector<double> par(4);
376  par[0] = DTSuperLayerTag; //DTSuperLayerTag is the ID of a SuperLayer
377  par[1] = par_temp[0] / dd4hep::mm;
378  par[2] = par_temp[1] / dd4hep::mm;
379  par[3] = par_temp[2] / dd4hep::mm;
380 
381 #ifdef EDM_ML_DEBUG
382  edm::LogVerbatim("DTGeometryParsFromDD")
383  << "(2) DD4hep, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
384 #endif
385  PosRotPair posRot(plane(fv));
386  rig.insert(slId, posRot.first, posRot.second, par);
387 }
388 
390  const MuonGeometryConstants& muonConstants,
391  RecoIdealGeometry& rig) const {
392  MuonGeometryNumbering mdddnum(muonConstants);
393  DTNumberingScheme dtnum(muonConstants);
394  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
395  DTLayerId layId(rawid);
396 
397  std::vector<double> par_temp = fv.parameters();
398  std::vector<double> par(4);
399  par[0] = DTLayerTag; //DTLayerTag is the ID of a Layer
400  par[1] = par_temp[0] / dd4hep::mm;
401  par[2] = par_temp[1] / dd4hep::mm;
402  par[3] = par_temp[2] / dd4hep::mm;
403 
404  fv.down();
405  bool doWire = fv.sibling();
406  int firstWire = fv.volume()->GetNumber();
407  auto const& wpar = fv.parameters();
408  float wireLength = wpar[1] / dd4hep::mm;
409 
410  int WCounter = 0;
411  while (doWire) {
412  doWire = fv.checkChild();
413  WCounter++;
414  }
415 
416  par.emplace_back(firstWire);
417  par.emplace_back(WCounter);
418  par.emplace_back(wireLength);
419 
420  fv.up();
421 
422  PosRotPair posRot(plane(fv));
423 
424 #ifdef EDM_ML_DEBUG
425  edm::LogVerbatim("DTGeometryParsFromDD")
426  << "(3) DD4hep, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
427  << par[4] << " " << par[5] << " " << par[6];
428 #endif
429  rig.insert(layId, posRot.first, posRot.second, par);
430 }
size
Write out results.
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