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 std;
34 using namespace geant_units;
35 using namespace geant_units::operators;
36 
38 
40 
41 // DD
43  const MuonGeometryConstants& muonConstants,
44  RecoIdealGeometry& rig) {
45  // cout << "DTGeometryParsFromDD::build" << endl;
46  // static const string t0 = "DTGeometryParsFromDD::build";
47  // TimeMe timer(t0,true);
48 
49  std::string attribute = "MuStructure";
50  std::string value = "MuonBarrelDT";
51 
52  // Asking only for the Muon DTs
54  DDFilteredView fview(*cview, filter);
55  buildGeometry(fview, muonConstants, rig);
56  //cout << "RecoIdealGeometry " << rig.size() << endl;
57 }
58 
59 // DD4hep
60 
62  const MuonGeometryConstants& muonConstants,
63  RecoIdealGeometry& rgeo) {
64  const std::string attribute = "MuStructure";
65  const std::string value = "MuonBarrelDT";
66  const cms::DDFilter filter(attribute, value);
67  cms::DDFilteredView fview(*cview, filter);
68  buildGeometry(fview, muonConstants, rgeo);
69 }
70 
71 // DD
73  const MuonGeometryConstants& muonConstants,
74  RecoIdealGeometry& rig) const {
75  // static const string t0 = "DTGeometryParsFromDD::buildGeometry";
76  // TimeMe timer(t0,true);
77 
78  edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DDD ";
79 
80  bool doChamber = fv.firstChild();
81 
82  // Loop on chambers
83  int ChamCounter = 0;
84  while (doChamber) {
85  ChamCounter++;
86  DDValue val("Type");
88  string type;
89  if (DDfetch(&params, val))
90  type = val.strings()[0];
91  // FIXME
92  val = DDValue("FEPos");
93  string FEPos;
94  if (DDfetch(&params, val))
95  FEPos = val.strings()[0];
96  insertChamber(fv, type, muonConstants, rig);
97 
98  // Loop on SLs
99  bool doSL = fv.firstChild();
100  int SLCounter = 0;
101  while (doSL) {
102  SLCounter++;
103  insertSuperLayer(fv, type, muonConstants, rig);
104 
105  bool doL = fv.firstChild();
106  int LCounter = 0;
107  // Loop on SLs
108  while (doL) {
109  LCounter++;
110  insertLayer(fv, type, muonConstants, rig);
111 
112  // fv.parent();
113  doL = fv.nextSibling(); // go to next layer
114  } // layers
115 
116  fv.parent();
117  doSL = fv.nextSibling(); // go to next SL
118  } // sls
119 
120  fv.parent();
121  doChamber = fv.nextSibling(); // go to next chamber
122  } // chambers
123 }
124 
126  const string& type,
127  const MuonGeometryConstants& muonConstants,
128  RecoIdealGeometry& rig) const {
129  MuonGeometryNumbering mdddnum(muonConstants);
130  DTNumberingScheme dtnum(muonConstants);
131  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
132  DTChamberId detId(rawid);
133  //cout << "inserting Chamber " << detId << endl;
134 
135  // Chamber specific parameter (size)
136  vector<double> par;
137  par.emplace_back(DTChamberTag);
138  vector<double> size = extractParameters(fv);
139  par.insert(par.end(), size.begin(), size.end());
140  edm::LogVerbatim("DTGeometryParsFromDD")
141  << "(1) DDD, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
143  // width is along local X
144  // length is along local Y
145  // thickness is long local Z
146 
147  PosRotPair posRot(plane(fv));
148  rig.insert(rawid, posRot.first, posRot.second, par);
149 }
150 
152  const std::string& type,
153  const MuonGeometryConstants& muonConstants,
154  RecoIdealGeometry& rig) const {
155  MuonGeometryNumbering mdddnum(muonConstants);
156  DTNumberingScheme dtnum(muonConstants);
157  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
158  DTSuperLayerId slId(rawid);
159  //cout << "inserting SuperLayer " << slId << endl;
160 
161  // Slayer specific parameter (size)
162  vector<double> par;
163  par.emplace_back(DTSuperLayerTag);
164  vector<double> size = extractParameters(fv);
165  par.insert(par.end(), size.begin(), size.end());
166  edm::LogVerbatim("DTGeometryParsFromDD")
167  << "(2) DDD, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
168  // Ok this is the slayer position...
169  PosRotPair posRot(plane(fv));
170  rig.insert(slId, posRot.first, posRot.second, par);
171 }
172 
174  const std::string& type,
175  const MuonGeometryConstants& muonConstants,
176  RecoIdealGeometry& rig) const {
177  MuonGeometryNumbering mdddnum(muonConstants);
178  DTNumberingScheme dtnum(muonConstants);
179  int rawid = dtnum.getDetId(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
180  DTLayerId layId(rawid);
181  //cout << "inserting Layer " << layId << endl;
182 
183  // Layer specific parameter (size)
184  vector<double> par;
185  par.emplace_back(DTLayerTag);
186  vector<double> size = extractParameters(fv);
187  par.insert(par.end(), size.begin(), size.end());
188 
189  // Loop on wires
190  bool doWire = fv.firstChild();
191  int WCounter = 0;
192  int firstWire = fv.copyno();
193  //float wireLength = par[1]/cm;
194  while (doWire) {
195  WCounter++;
196  doWire = fv.nextSibling(); // next wire
197  }
198  vector<double> sensSize = extractParameters(fv);
199  //int lastWire=fv.copyno();
200  par.emplace_back(firstWire);
201  par.emplace_back(WCounter);
202  par.emplace_back(sensSize[1]);
203  fv.parent();
204 
205  PosRotPair posRot(plane(fv));
206 
207  edm::LogVerbatim("DTGeometryParsFromDD")
208  << "(3) DDD, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
209  << par[4] << " " << par[5] << " " << par[6];
210  rig.insert(layId, posRot.first, posRot.second, par);
211 }
212 
214  vector<double> par;
215  if (fv.logicalPart().solid().shape() != DDSolidShape::ddbox) {
217  DDSolid A = bs.solidA();
218  while (A.shape() != DDSolidShape::ddbox) {
220  A = bs.solidA();
221  }
222  par = A.parameters();
223  } else {
224  par = fv.logicalPart().solid().parameters();
225  }
226  return par;
227 }
228 
230  // extract the position
231  const DDTranslation& trans(fv.translation());
232 
233  std::vector<double> gtran(3);
234  gtran[0] = convertMmToCm(trans.x());
235  gtran[1] = convertMmToCm(trans.y());
236  gtran[2] = convertMmToCm(trans.z());
237 
238  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DDD, Position "
239  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
240  // now the rotation
241  // 'active' and 'passive' rotations are inverse to each other
242  const DDRotationMatrix& rotation = fv.rotation(); //REMOVED .Inverse();
243  DD3Vector x, y, z;
244  rotation.GetComponents(x, y, z);
245 
246  std::vector<double> grmat(9);
247  grmat[0] = x.X();
248  grmat[1] = x.Y();
249  grmat[2] = x.Z();
250 
251  grmat[3] = y.X();
252  grmat[4] = y.Y();
253  grmat[5] = y.Z();
254 
255  grmat[6] = z.X();
256  grmat[7] = z.Y();
257  grmat[8] = z.Z();
258 
259  return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
260 }
261 
262 // DD4hep
263 
265  const MuonGeometryConstants& muonConstants,
266  RecoIdealGeometry& rig) const {
267  edm::LogVerbatim("DTGeometryParsFromDD") << "(0) DTGeometryParsFromDD - DD4hep ";
268 
269  bool doChamber = fv.firstChild();
270 
271  while (doChamber) {
272  insertChamber(fv, muonConstants, rig);
273 
274  bool doSL = fv.nextSibling();
275  while (doSL) {
276  insertSuperLayer(fv, muonConstants, rig);
277 
278  fv.down();
279  bool doLayers = fv.sibling();
280  while (doLayers) {
281  insertLayer(fv, muonConstants, rig);
282 
283  doLayers = fv.sibling();
284  }
285 
286  doSL = fv.nextSibling();
287  }
288 
289  fv.parent();
290  doChamber = fv.firstChild();
291  }
292 }
293 
295  const Double_t* tr = fv.trans();
296 
297  std::vector<double> gtran(3);
298 
299  gtran[0] = tr[0] / dd4hep::cm;
300  gtran[1] = tr[1] / dd4hep::cm;
301  gtran[2] = tr[2] / dd4hep::cm;
302 
303  edm::LogVerbatim("DTGeometryParsFromDD") << "(4) DD4hep, Position "
304  << " " << gtran[0] << " " << gtran[1] << " " << gtran[2];
305 
307  DD3Vector x, y, z;
308  rotation.GetComponents(x, y, z);
309 
310  std::vector<double> grmat(9);
311 
312  grmat[0] = x.X();
313  grmat[1] = x.Y();
314  grmat[2] = x.Z();
315 
316  grmat[3] = y.X();
317  grmat[4] = y.Y();
318  grmat[5] = y.Z();
319 
320  grmat[6] = z.X();
321  grmat[7] = z.Y();
322  grmat[8] = z.Z();
323 
324  return pair<std::vector<double>, std::vector<double> >(gtran, grmat);
325 }
326 
328  const MuonGeometryConstants& muonConstants,
329  RecoIdealGeometry& rig) const {
330  MuonGeometryNumbering mdddnum(muonConstants);
331  DTNumberingScheme dtnum(muonConstants);
332  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
333  DTChamberId detId(rawid);
334 
335  vector<double> par_temp = fv.parameters();
336  vector<double> par(4);
337  par[0] = DTChamberTag; //DTChamberTag is the ID of a Chamber
338  par[1] = par_temp[0] / dd4hep::mm;
339  par[2] = par_temp[1] / dd4hep::mm;
340  par[3] = par_temp[2] / dd4hep::mm;
341 
342  edm::LogVerbatim("DTGeometryParsFromDD")
343  << "(1) DD4hep, Chamber DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
344  PosRotPair posRot(plane(fv));
345  rig.insert(rawid, posRot.first, posRot.second, par);
346 }
347 
349  const MuonGeometryConstants& muonConstants,
350  RecoIdealGeometry& rig) const {
351  MuonGeometryNumbering mdddnum(muonConstants);
352  DTNumberingScheme dtnum(muonConstants);
353  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
354  DTSuperLayerId slId(rawid);
355 
356  vector<double> par_temp = fv.parameters();
357  vector<double> par(4);
358  par[0] = DTSuperLayerTag; //DTSuperLayerTag is the ID of a SuperLayer
359  par[1] = par_temp[0] / dd4hep::mm;
360  par[2] = par_temp[1] / dd4hep::mm;
361  par[3] = par_temp[2] / dd4hep::mm;
362 
363  edm::LogVerbatim("DTGeometryParsFromDD")
364  << "(2) DD4hep, Super Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3];
365  PosRotPair posRot(plane(fv));
366  rig.insert(slId, posRot.first, posRot.second, par);
367 }
368 
370  const MuonGeometryConstants& muonConstants,
371  RecoIdealGeometry& rig) const {
372  MuonGeometryNumbering mdddnum(muonConstants);
373  DTNumberingScheme dtnum(muonConstants);
374  int rawid = dtnum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.history()));
375  DTLayerId layId(rawid);
376 
377  vector<double> par_temp = fv.parameters();
378  vector<double> par(4);
379  par[0] = DTLayerTag; //DTLayerTag is the ID of a Layer
380  par[1] = par_temp[0] / dd4hep::mm;
381  par[2] = par_temp[1] / dd4hep::mm;
382  par[3] = par_temp[2] / dd4hep::mm;
383 
384  fv.down();
385  bool doWire = fv.sibling();
386  int firstWire = fv.volume()->GetNumber();
387  auto const& wpar = fv.parameters();
388  float wireLength = wpar[1] / dd4hep::mm;
389 
390  int WCounter = 0;
391  while (doWire) {
392  doWire = fv.checkChild();
393  WCounter++;
394  }
395 
396  par.emplace_back(firstWire);
397  par.emplace_back(WCounter);
398  par.emplace_back(wireLength);
399 
400  fv.up();
401 
402  PosRotPair posRot(plane(fv));
403 
404  edm::LogVerbatim("DTGeometryParsFromDD")
405  << "(3) DD4hep, Layer DetID " << rawid << " " << par[0] << " " << par[1] << " " << par[2] << " " << par[3] << " "
406  << par[4] << " " << par[5] << " " << par[6];
407  rig.insert(layId, posRot.first, posRot.second, par);
408 }
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 ...
std::vector< double > extractParameters(DDFilteredView &fv) const
get parameter also for boolean solid.
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
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