CMS 3D CMS Logo

GEMGeometryParsFromDD.cc
Go to the documentation of this file.
1 /* Implementation of the GEMGeometryParsFromDD Class
2  * Build the GEMGeometry from the DDD and DD4hep description
3  *
4  * DD4hep part added to the original old file (DD version) made by M. Maggi (INFN Bari)
5  * Author: Sergio Lo Meo (sergio.lo.meo@cern.ch)
6  * Created: Mon, 15 Feb 2021
7  *
8  */
11 
16 
21 
23 
27 
28 #include <iostream>
29 #include <algorithm>
30 
32 
34 
35 // DDD
36 
38  const MuonGeometryConstants& muonConstants,
39  RecoIdealGeometry& rgeo) {
40  std::string attribute = "MuStructure";
41  std::string value = "MuonEndCapGEM";
42 
43  // Asking only for the MuonGEM's
45  DDFilteredView fv(*cview, filter);
46  DDFilteredView fv2(*cview, filter);
47 
48  this->buildGeometry(fv, fv2, muonConstants, rgeo);
49 }
50 
52  DDFilteredView& fvGE2,
53  const MuonGeometryConstants& muonConstants,
54  RecoIdealGeometry& rgeo) {
55  LogDebug("GEMGeometryParsFromDD") << "Building the geometry service";
56  LogDebug("GEMGeometryParsFromDD") << "About to run through the GEM structure\n"
57  << " First logical part " << fv.logicalPart().name().name();
58 
59  edm::LogVerbatim("GEMGeometryParsFromDD") << "(0) GEMGeometryParsFromDD - DDD ";
60  MuonGeometryNumbering muonDDDNumbering(muonConstants);
61  GEMNumberingScheme gemNumbering(muonConstants);
62 
63  // Check for the demonstrator geometry (only 1 chamber of GE2/1)
64  int nGE21 = 0;
65  bool doSuper = fvGE2.firstChild();
66  while (doSuper) {
67  // getting chamber id from eta partitions
68  fvGE2.firstChild();
69  doSuper = fvGE2.firstChild();
70  if (doSuper) {
71  int rawidCh = gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fvGE2.geoHistory()));
72  GEMDetId detIdCh = GEMDetId(rawidCh);
73  if (detIdCh.station() == 2)
74  nGE21++;
75 
76  // back to chambers
77  fvGE2.parent();
78  fvGE2.parent();
79  doSuper = (nGE21 < 2 && fvGE2.nextSibling());
80  } else {
81  edm::LogError("GEMGeometryParsFromDD") << "Failed to find next child volume. Cannot determine presence of GE 2/1";
82  }
83  }
84  bool demonstratorGeometry = nGE21 == 1;
85 
86 #ifdef EDM_ML_DEBUG
87  edm::LogVerbatim("Geometry") << "Found " << nGE21 << " GE2/1 chambers. Demonstrator geometry on? "
88  << demonstratorGeometry;
89 #endif
90 
91  doSuper = fv.firstChild();
92 
93  LogDebug("GEMGeometryParsFromDD") << "doSuperChamber = " << doSuper;
94  // loop over superchambers
95  while (doSuper) {
96  // getting chamber id from eta partitions
97  fv.firstChild();
98  doSuper = fv.firstChild();
99  if (doSuper) {
100  GEMDetId detIdCh =
101  GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
102  // back to chambers
103  fv.parent();
104  fv.parent();
105 
106  // currently there is no superchamber in the geometry
107  // only 2 chambers are present separated by a gap.
108  // making superchamber out of the first chamber layer including the gap between chambers
109 
110  // In Run 3 we also have a single GE2/1 chamber at layer 2. We
111  // make sure the superchamber gets built but also we build on the
112  // first layer for the other stations so the superchamber is in
113  // the right position there.
114  if ((detIdCh.layer() == 1) || (detIdCh.layer() == 2 and detIdCh.station() == 2 and demonstratorGeometry)) {
115  buildSuperChamber(fv, detIdCh, rgeo);
116  }
117  buildChamber(fv, detIdCh, rgeo);
118 
119  // loop over chambers
120  // only 1 chamber
121  bool doChambers = fv.firstChild();
122  while (doChambers) {
123  // loop over GEMEtaPartitions
124  bool doEtaPart = fv.firstChild();
125  while (doEtaPart) {
126  GEMDetId detId =
127  GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
128  buildEtaPartition(fv, detId, rgeo);
129 
130  doEtaPart = fv.nextSibling();
131  }
132  fv.parent();
133  doChambers = fv.nextSibling();
134  }
135  fv.parent();
136  doSuper = fv.nextSibling();
137  } else {
138  edm::LogError("GEMGeometryParsFromDD") << "Failed to find next child volume. Cannot build GEM chambers.";
139  }
140  }
141 }
142 
144  LogDebug("GEMGeometryParsFromDD") << "buildSuperChamber " << fv.logicalPart().name().name() << " " << detId
145  << std::endl;
146 
148  std::vector<double> dpar = solid.solidA().parameters();
149 
150  GEMDetId gemid = detId.superChamberId();
151 
152  double dy = dpar[0]; //length is along local Y
153  double dz = dpar[3]; // thickness is long local Z
154  double dx1 = dpar[4]; // bottom width is along local X
155  double dx2 = dpar[8]; // top width is along local X
156  dpar = solid.solidB().parameters();
157 
158  dz += dpar[3]; // chamber thickness
159  dz *= 2; // 2 chambers in superchamber
160  dz += 2.105; // gap between chambers
161 
162  std::vector<double> pars{dx1, dx2, dy, dz};
163  std::vector<double> vtra = getTranslation(fv);
164  std::vector<double> vrot = getRotation(fv);
165 
166  LogDebug("GEMGeometryParsFromDD") << "dimension dx1 " << dx1 << ", dx2 " << dx2 << ", dy " << dy << ", dz " << dz;
167  edm::LogVerbatim("GEMGeometryParsFromDD")
168  << "(3) DDD, SuperChamber DetID " << gemid.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
169  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
170  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
171 }
172 
174  LogDebug("GEMGeometryParsFromDD") << "buildChamber " << fv.logicalPart().name().name() << " " << detId << std::endl;
175 
177  std::vector<double> dpar = solid.solidA().parameters();
178 
179  double dy = dpar[0]; //length is along local Y
180  double dz = dpar[3]; // thickness is long local Z
181  double dx1 = dpar[4]; // bottom width is along local X
182  double dx2 = dpar[8]; // top width is along local X
183  dpar = solid.solidB().parameters();
184  dz += dpar[3]; // chamber thickness
185 
186  GEMDetId gemid = detId.chamberId();
187 
188  std::vector<double> pars{dx1, dx2, dy, dz};
189  std::vector<double> vtra = getTranslation(fv);
190  std::vector<double> vrot = getRotation(fv);
191 
192  LogDebug("GEMGeometryParsFromDD") << "dimension dx1 " << dx1 << ", dx2 " << dx2 << ", dy " << dy << ", dz " << dz;
193  edm::LogVerbatim("GEMGeometryParsFromDD")
194  << "(4) DDD, Chamber DetID " << gemid.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
195  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
196  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
197 }
198 
200  LogDebug("GEMGeometryParsFromDD") << "buildEtaPartition " << fv.logicalPart().name().name() << " " << detId
201  << std::endl;
202 
203  // EtaPartition specific parameter (nstrips and npads)
204  DDValue numbOfStrips("nStrips");
205  DDValue numbOfPads("nPads");
206  DDValue delPhi("dPhi");
207  const std::vector<const DDsvalues_type*>& specs = fv.specifics();
208  double nStrips = 0., nPads = 0., dPhi = 0.;
209  for (auto const& is : specs) {
210  if (DDfetch(is, numbOfStrips))
211  nStrips = numbOfStrips.doubles()[0];
212  if (DDfetch(is, numbOfPads))
213  nPads = numbOfPads.doubles()[0];
214  if (DDfetch(is, delPhi))
215  dPhi = delPhi.doubles()[0];
216  }
217  LogDebug("GEMGeometryParsFromDD") << ((nStrips == 0.) ? ("No nStrips found!!")
218  : ("Number of strips: " + std::to_string(nStrips)));
219  LogDebug("GEMGeometryParsFromDD") << ((nPads == 0.) ? ("No nPads found!!")
220  : ("Number of pads: " + std::to_string(nPads)));
221 
222  // EtaPartition specific parameter (size)
223  std::vector<double> dpar = fv.logicalPart().solid().parameters();
224 
225  double dy = dpar[0]; //length is along local Y
226  double dz = dpar[3]; //0.4;// thickness is long local Z
227  double dx1 = dpar[4]; // bottom width is along local X
228  double dx2 = dpar[8]; // top width is along local X
229 
230  std::vector<double> pars{dx1, dx2, dy, dz, nStrips, nPads, dPhi};
231  std::vector<double> vtra = getTranslation(fv);
232  std::vector<double> vrot = getRotation(fv);
233 
234  LogDebug("GEMGeometryParsFromDD") << " dx1 " << dx1 << " dx2 " << dx2 << " dy " << dy << " dz " << dz << " nStrips "
235  << nStrips << " nPads " << nPads << " dPhi " << dPhi;
236 
237  edm::LogVerbatim("GEMGeometryParsFromDD")
238  << "(5) DDD, Eta Partion DetID " << detId.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
239  << " dx2 " << dx2 << " dy " << dy << " dz " << dz << " nStrips " << nStrips << " nPads " << nPads << " dPhi "
240  << dPhi;
241  rgeo.insert(detId.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
242 }
243 
245  const DDTranslation& tran = fv.translation();
246  edm::LogVerbatim("GEMGeometryParsFromDD")
247  << "(1) DDD, tran vector " << tran.x() << " " << tran.y() << " " << tran.z();
248  return {tran.x(), tran.y(), tran.z()};
249 }
250 
252  const DDRotationMatrix& rota = fv.rotation(); //.Inverse();
253  DD3Vector x, y, z;
254  rota.GetComponents(x, y, z);
255  edm::LogVerbatim("GEMGeometryParsFromDD")
256  << "(2) DDD, rot matrix " << x.X() << " " << x.Y() << " " << x.Z() << " " << y.X() << " " << y.Y() << " "
257  << y.Z() << " " << z.X() << " " << z.Y() << " " << z.Z();
258  return {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
259 }
260 
261 // DD4hep
262 
264  const MuonGeometryConstants& muonConstants,
265  RecoIdealGeometry& rgeo) {
266  std::string attribute = "MuStructure";
267  std::string value = "MuonEndCapGEM";
268 
269  const cms::DDFilter filter(attribute, value);
270  cms::DDFilteredView fv(*cview, filter);
271 
272  this->buildGeometry(fv, muonConstants, rgeo);
273 }
274 
276  const MuonGeometryConstants& muonConstants,
277  RecoIdealGeometry& rgeo) {
278  edm::LogVerbatim("GEMGeometryParsFromDD") << "(0) GEMGeometryParsFromDD - DD4hep ";
279 
280  MuonGeometryNumbering mdddnum(muonConstants);
281  GEMNumberingScheme gemNum(muonConstants);
282  static constexpr uint32_t levelChamb = 7;
283  int chamb(0), region(0);
284  int theLevelPart = muonConstants.getValue("level");
285  int theRingLevel = muonConstants.getValue("mg_ring") / theLevelPart;
286  int theSectorLevel = muonConstants.getValue("mg_sector") / theLevelPart;
287 
288  // Check for the demonstrator geometry (only 1 chamber of GE2/1)
289  auto start = fv.copyNos();
290  int nGE21 = 0;
291  while (nGE21 < 2 && fv.firstChild()) {
292  const auto& history = fv.history();
293  MuonBaseNumber num(mdddnum.geoHistoryToBaseNumber(history));
295  if (fv.level() == levelChamb && detId.station() == 2) {
296  nGE21++;
297  }
298  }
299  bool demonstratorGeometry = nGE21 == 1;
300 #ifdef EDM_ML_DEBUG
301  edm::LogVerbatim("Geometry") << "Found " << nGE21 << " GE2/1 chambers. Demonstrator geometry on? "
302  << demonstratorGeometry;
303 #endif
304 
305  fv.goTo(start);
306  while (fv.firstChild()) {
307  const auto& history = fv.history();
308  MuonBaseNumber num(mdddnum.geoHistoryToBaseNumber(history));
310 
311  if (detId.station() == GEMDetId::minStationId0) {
312  if (num.getLevels() == theRingLevel) {
313  if (detId.region() != region) {
314  region = detId.region();
315  chamb = 0;
316  }
317  ++chamb;
318  detId = GEMDetId(detId.region(), detId.ring(), detId.station(), detId.layer(), chamb, 0);
319  buildSuperChamber(fv, detId, rgeo);
320  } else if (num.getLevels() == theSectorLevel) {
321  buildChamber(fv, detId, rgeo);
322  } else {
323  buildEtaPartition(fv, detId, rgeo);
324  }
325  } else {
326  if (fv.level() == levelChamb) {
327  if ((detId.layer() == 1) || (detId.layer() == 2 and detId.station() == 2 and demonstratorGeometry)) {
328  buildSuperChamber(fv, detId, rgeo);
329  }
330  buildChamber(fv, detId, rgeo);
331  } else if (num.getLevels() > theSectorLevel) {
332  buildEtaPartition(fv, detId, rgeo);
333  }
334  }
335  }
336 }
337 
339  cms::DDSolid solid(fv.solid());
340  auto solidA = solid.solidA();
341  std::vector<double> dpar = solidA.dimensions();
342 
343  double dy = dpar[3] / dd4hep::mm; //length is along local Y
344  double dz = dpar[2] / dd4hep::mm; // thickness is long local Z
345  double dx1 = dpar[0] / dd4hep::mm; // bottom width is along local X
346  double dx2 = dpar[1] / dd4hep::mm; // top width is along loc
347 
348  auto solidB = solid.solidB();
349  dpar = solidB.dimensions();
350  const int nch = 2;
351  const double chgap = 2.105;
352 
353  GEMDetId gemid = detId.superChamberId();
354  std::string_view name = fv.name();
355 
356  dz += (dpar[2] / dd4hep::mm); // chamber thickness
357  dz *= nch; // 2 chambers in superchamber
358  dz += chgap; // gap between chambers
359 
360  std::vector<double> pars{dx1, dx2, dy, dz};
361  std::vector<double> vtra = getTranslation(fv);
362  std::vector<double> vrot = getRotation(fv);
363 
364  edm::LogVerbatim("GEMGeometryParsFromDD")
365  << "(3) DD4hep, SuperChamber DetID " << gemid.rawId() << " Name " << std::string(name) << " dx1 " << dx1
366  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
367  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {std::string(name)});
368 }
369 
371  cms::DDSolid solid(fv.solid());
372  auto solidA = solid.solidA();
373  std::vector<double> dpar = solidA.dimensions();
374 
375  double dy = dpar[3] / dd4hep::mm; //length is along local Y
376  double dz = dpar[2] / dd4hep::mm; // thickness is long local Z
377  double dx1 = dpar[0] / dd4hep::mm; // bottom width is along local X
378  double dx2 = dpar[1] / dd4hep::mm; // top width is along local X
379 
380  auto solidB = solid.solidB();
381  dpar = solidB.dimensions();
382 
383  dz += (dpar[2] / dd4hep::mm); // chamber thickness
384 
385  GEMDetId gemid = detId.chamberId();
386  std::string_view name = fv.name();
387 
388  std::vector<double> pars{dx1, dx2, dy, dz};
389  std::vector<double> vtra = getTranslation(fv);
390  std::vector<double> vrot = getRotation(fv);
391 
392  edm::LogVerbatim("GEMGeometryParsFromDD")
393  << "(4) DD4hep, Chamber DetID " << gemid.rawId() << " Name " << std::string(name) << " dx1 " << dx1 << " dx2 "
394  << dx2 << " dy " << dy << " dz " << dz;
395  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {std::string(name)});
396 }
397 
399  auto nStrips = fv.get<double>("nStrips");
400  auto nPads = fv.get<double>("nPads");
401  auto dPhi = fv.get<double>("dPhi");
402 
403  std::vector<double> dpar = fv.parameters();
404  std::string_view name = fv.name();
405 
406  double dx1 = dpar[0] / dd4hep::mm;
407  double dx2 = dpar[1] / dd4hep::mm;
408  double dy = dpar[3] / dd4hep::mm;
409  double dz = dpar[2] / dd4hep::mm;
410 
411  std::vector<double> pars{dx1, dx2, dy, dz, nStrips, nPads, dPhi};
412  std::vector<double> vtra = getTranslation(fv);
413  std::vector<double> vrot = getRotation(fv);
414 
415  edm::LogVerbatim("GEMGeometryParsFromDD")
416  << "(5) DD4hep, Eta Partion DetID " << detId.rawId() << " Name " << std::string(name) << " dx1 " << dx1 << " dx2 "
417  << dx2 << " dy " << dy << " dz " << dz << " nStrips " << nStrips << " nPads " << nPads << " dPhi " << dPhi;
418  rgeo.insert(detId.rawId(), vtra, vrot, pars, {std::string(name)});
419 }
420 
422  std::vector<double> tran(3);
423  tran[0] = static_cast<double>(fv.translation().X()) / dd4hep::mm;
424  tran[1] = static_cast<double>(fv.translation().Y()) / dd4hep::mm;
425  tran[2] = static_cast<double>(fv.translation().Z()) / dd4hep::mm;
426 
427  edm::LogVerbatim("GEMGeometryParsFromDD")
428  << "(1) DD4hep, tran vector " << tran[0] << " " << tran[1] << " " << tran[2];
429  return {tran[0], tran[1], tran[2]};
430 }
431 
433  DDRotationMatrix rota;
434  fv.rot(rota);
435  DD3Vector x, y, z;
436  rota.GetComponents(x, y, z);
437  const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
438  edm::LogVerbatim("GEMGeometryParsFromDD")
439  << "(2) DD4hep, rot matrix " << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << " " << rot[4]
440  << " " << rot[5] << " " << rot[6] << " " << rot[7] << " " << rot[8];
441  return {rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]};
442 }
Definition: start.py:1
int getValue(const std::string &name) const
Log< level::Info, true > LogVerbatim
DDSolid solidA(void) const
Definition: DDSolid.cc:470
bool parent()
set the current node to the parent node ...
constexpr int station() const
Definition: GEMDetId.h:179
const std::vector< int > copyNos() const
The list of the volume copy numbers.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
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)
const Double_t * rot() const
The absolute rotation of the current node.
bool goTo(const nav_type &)
transversed the DDFilteredView according
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:125
Log< level::Error, false > LogError
constexpr int layer() const
Definition: GEMDetId.h:190
dd4hep::Solid solidA() const
void buildEtaPartition(DDFilteredView &fv, GEMDetId detId, RecoIdealGeometry &rgeo)
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
static std::string to_string(const XMLCh *ch)
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
std::vector< double > getRotation(DDFilteredView &fv)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
std::string_view name() const
static double delPhi(const double phi1, const double phi2)
const std::string & name() const
Returns the name.
Definition: DDName.cc:41
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const ExpandedNodes & history()
The numbering history of the current node.
static constexpr int32_t minStationId0
Definition: GEMDetId.h:24
void buildChamber(DDFilteredView &fv, GEMDetId detId, RecoIdealGeometry &rgeo)
const int level() const
get Iterator level
void buildGeometry(DDFilteredView &fview, DDFilteredView &fview2, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rgeo)
Definition: value.py:1
DDSolid solidB(void) const
Definition: DDSolid.cc:472
bool firstChild()
set the current node to the first child
const N & name() const
Definition: DDBase.h:59
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
T get(const std::string &)
extract attribute value
std::vector< const DDsvalues_type * > specifics() const
std::vector< double > getTranslation(DDFilteredView &fv)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
dd4hep::Solid solid() const
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
void buildSuperChamber(DDFilteredView &fv, GEMDetId detId, RecoIdealGeometry &rgeo)
bool firstChild()
set the current node to the first child ...
int baseNumberToUnitNumber(const MuonBaseNumber &) const override
const DDTranslation & translation() const
The absolute translation of the current node.
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
void build(const DDCompactView *cview, const MuonGeometryConstants &muonConstants, RecoIdealGeometry &rgeo)
#define LogDebug(id)
const Translation translation() const