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  // in 2021 we have 1 demonstrator chamber in 2024 we have 3 chambers.
80  // Need to account for both
81  doSuper = (nGE21 < 4 && fvGE2.nextSibling());
82  } else {
83  edm::LogError("GEMGeometryParsFromDD") << "Failed to find next child volume. Cannot determine presence of GE 2/1";
84  }
85  }
86  bool demonstratorGeometry = nGE21 % 2 == 1;
87 
88 #ifdef EDM_ML_DEBUG
89  edm::LogVerbatim("Geometry") << "Found " << nGE21 << " GE2/1 chambers. Demonstrator geometry on? "
90  << demonstratorGeometry;
91 #endif
92 
93  doSuper = fv.firstChild();
94 
95  LogDebug("GEMGeometryParsFromDD") << "doSuperChamber = " << doSuper;
96  // loop over superchambers
97  while (doSuper) {
98  // getting chamber id from eta partitions
99  fv.firstChild();
100  doSuper = fv.firstChild();
101  if (doSuper) {
102  GEMDetId detIdCh =
103  GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
104  // back to chambers
105  fv.parent();
106  fv.parent();
107 
108  // currently there is no superchamber in the geometry
109  // only 2 chambers are present separated by a gap.
110  // making superchamber out of the first chamber layer including the gap between chambers
111 
112  // In Run 3 we also have a single GE2/1 chamber at layer 2. We
113  // make sure the superchamber gets built but also we build on the
114  // first layer for the other stations so the superchamber is in
115  // the right position there.
116  if ((detIdCh.layer() == 1) || (detIdCh.layer() == 2 and detIdCh.station() == 2 and demonstratorGeometry)) {
117  buildSuperChamber(fv, detIdCh, rgeo);
118  }
119  buildChamber(fv, detIdCh, rgeo);
120 
121  // loop over chambers
122  // only 1 chamber
123  bool doChambers = fv.firstChild();
124  while (doChambers) {
125  // loop over GEMEtaPartitions
126  bool doEtaPart = fv.firstChild();
127  while (doEtaPart) {
128  GEMDetId detId =
129  GEMDetId(gemNumbering.baseNumberToUnitNumber(muonDDDNumbering.geoHistoryToBaseNumber(fv.geoHistory())));
130  buildEtaPartition(fv, detId, rgeo);
131 
132  doEtaPart = fv.nextSibling();
133  }
134  fv.parent();
135  doChambers = fv.nextSibling();
136  }
137  fv.parent();
138  doSuper = fv.nextSibling();
139  } else {
140  edm::LogError("GEMGeometryParsFromDD") << "Failed to find next child volume. Cannot build GEM chambers.";
141  }
142  }
143 }
144 
146  LogDebug("GEMGeometryParsFromDD") << "buildSuperChamber " << fv.logicalPart().name().name() << " " << detId
147  << std::endl;
148 
150  std::vector<double> dpar = solid.solidA().parameters();
151 
152  GEMDetId gemid = detId.superChamberId();
153 
154  double dy = dpar[0]; //length is along local Y
155  double dz = dpar[3]; // thickness is long local Z
156  double dx1 = dpar[4]; // bottom width is along local X
157  double dx2 = dpar[8]; // top width is along local X
158  dpar = solid.solidB().parameters();
159 
160  dz += dpar[3]; // chamber thickness
161  dz *= 2; // 2 chambers in superchamber
162  dz += 2.105; // gap between chambers
163 
164  std::vector<double> pars{dx1, dx2, dy, dz};
165  std::vector<double> vtra = getTranslation(fv);
166  std::vector<double> vrot = getRotation(fv);
167 
168  LogDebug("GEMGeometryParsFromDD") << "dimension dx1 " << dx1 << ", dx2 " << dx2 << ", dy " << dy << ", dz " << dz;
169  edm::LogVerbatim("GEMGeometryParsFromDD")
170  << "(3) DDD, SuperChamber DetID " << gemid.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
171  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
172  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
173 }
174 
176  LogDebug("GEMGeometryParsFromDD") << "buildChamber " << fv.logicalPart().name().name() << " " << detId << std::endl;
177 
179  std::vector<double> dpar = solid.solidA().parameters();
180 
181  double dy = dpar[0]; //length is along local Y
182  double dz = dpar[3]; // thickness is long local Z
183  double dx1 = dpar[4]; // bottom width is along local X
184  double dx2 = dpar[8]; // top width is along local X
185  dpar = solid.solidB().parameters();
186  dz += dpar[3]; // chamber thickness
187 
188  GEMDetId gemid = detId.chamberId();
189 
190  std::vector<double> pars{dx1, dx2, dy, dz};
191  std::vector<double> vtra = getTranslation(fv);
192  std::vector<double> vrot = getRotation(fv);
193 
194  LogDebug("GEMGeometryParsFromDD") << "dimension dx1 " << dx1 << ", dx2 " << dx2 << ", dy " << dy << ", dz " << dz;
195  edm::LogVerbatim("GEMGeometryParsFromDD")
196  << "(4) DDD, Chamber DetID " << gemid.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
197  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
198  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
199 }
200 
202  LogDebug("GEMGeometryParsFromDD") << "buildEtaPartition " << fv.logicalPart().name().name() << " " << detId
203  << std::endl;
204 
205  // EtaPartition specific parameter (nstrips and npads)
206  DDValue numbOfStrips("nStrips");
207  DDValue numbOfPads("nPads");
208  DDValue delPhi("dPhi");
209  const std::vector<const DDsvalues_type*>& specs = fv.specifics();
210  double nStrips = 0., nPads = 0., dPhi = 0.;
211  for (auto const& is : specs) {
212  if (DDfetch(is, numbOfStrips))
213  nStrips = numbOfStrips.doubles()[0];
214  if (DDfetch(is, numbOfPads))
215  nPads = numbOfPads.doubles()[0];
216  if (DDfetch(is, delPhi))
217  dPhi = delPhi.doubles()[0];
218  }
219  LogDebug("GEMGeometryParsFromDD") << ((nStrips == 0.) ? ("No nStrips found!!")
220  : ("Number of strips: " + std::to_string(nStrips)));
221  LogDebug("GEMGeometryParsFromDD") << ((nPads == 0.) ? ("No nPads found!!")
222  : ("Number of pads: " + std::to_string(nPads)));
223 
224  // EtaPartition specific parameter (size)
225  std::vector<double> dpar = fv.logicalPart().solid().parameters();
226 
227  double dy = dpar[0]; //length is along local Y
228  double dz = dpar[3]; //0.4;// thickness is long local Z
229  double dx1 = dpar[4]; // bottom width is along local X
230  double dx2 = dpar[8]; // top width is along local X
231 
232  std::vector<double> pars{dx1, dx2, dy, dz, nStrips, nPads, dPhi};
233  std::vector<double> vtra = getTranslation(fv);
234  std::vector<double> vrot = getRotation(fv);
235 
236  LogDebug("GEMGeometryParsFromDD") << " dx1 " << dx1 << " dx2 " << dx2 << " dy " << dy << " dz " << dz << " nStrips "
237  << nStrips << " nPads " << nPads << " dPhi " << dPhi;
238 
239  edm::LogVerbatim("GEMGeometryParsFromDD")
240  << "(5) DDD, Eta Partion DetID " << detId.rawId() << " Name " << fv.logicalPart().name().name() << " dx1 " << dx1
241  << " dx2 " << dx2 << " dy " << dy << " dz " << dz << " nStrips " << nStrips << " nPads " << nPads << " dPhi "
242  << dPhi;
243  rgeo.insert(detId.rawId(), vtra, vrot, pars, {fv.logicalPart().name().name()});
244 }
245 
247  const DDTranslation& tran = fv.translation();
248  edm::LogVerbatim("GEMGeometryParsFromDD")
249  << "(1) DDD, tran vector " << tran.x() << " " << tran.y() << " " << tran.z();
250  return {tran.x(), tran.y(), tran.z()};
251 }
252 
254  const DDRotationMatrix& rota = fv.rotation(); //.Inverse();
255  DD3Vector x, y, z;
256  rota.GetComponents(x, y, z);
257  edm::LogVerbatim("GEMGeometryParsFromDD")
258  << "(2) DDD, rot matrix " << x.X() << " " << x.Y() << " " << x.Z() << " " << y.X() << " " << y.Y() << " "
259  << y.Z() << " " << z.X() << " " << z.Y() << " " << z.Z();
260  return {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
261 }
262 
263 // DD4hep
264 
266  const MuonGeometryConstants& muonConstants,
267  RecoIdealGeometry& rgeo) {
268  std::string attribute = "MuStructure";
269  std::string value = "MuonEndCapGEM";
270 
271  const cms::DDFilter filter(attribute, value);
272  cms::DDFilteredView fv(*cview, filter);
273 
274  this->buildGeometry(fv, muonConstants, rgeo);
275 }
276 
278  const MuonGeometryConstants& muonConstants,
279  RecoIdealGeometry& rgeo) {
280  edm::LogVerbatim("GEMGeometryParsFromDD") << "(0) GEMGeometryParsFromDD - DD4hep ";
281 
282  MuonGeometryNumbering mdddnum(muonConstants);
283  GEMNumberingScheme gemNum(muonConstants);
284  static constexpr uint32_t levelChamb = 7;
285  int chamb(0), region(0);
286  int theLevelPart = muonConstants.getValue("level");
287  int theRingLevel = muonConstants.getValue("mg_ring") / theLevelPart;
288  int theSectorLevel = muonConstants.getValue("mg_sector") / theLevelPart;
289 
290  // Check for the demonstrator geometry (only 1 chamber of GE2/1)
291  auto start = fv.copyNos();
292  int nGE21 = 0;
293  while (nGE21 < 2 && fv.firstChild()) {
294  const auto& history = fv.history();
297  if (fv.level() == levelChamb && detId.station() == 2) {
298  nGE21++;
299  }
300  }
301  bool demonstratorGeometry = nGE21 % 2 == 1;
302 #ifdef EDM_ML_DEBUG
303  edm::LogVerbatim("Geometry") << "Found " << nGE21 << " GE2/1 chambers. Demonstrator geometry on? "
304  << demonstratorGeometry;
305 #endif
306 
307  fv.goTo(start);
308  while (fv.firstChild()) {
309  const auto& history = fv.history();
312 
313  if (detId.station() == GEMDetId::minStationId0) {
314  if (num.getLevels() == theRingLevel) {
315  if (detId.region() != region) {
316  region = detId.region();
317  chamb = 0;
318  }
319  ++chamb;
320  detId = GEMDetId(detId.region(), detId.ring(), detId.station(), detId.layer(), chamb, 0);
321  buildSuperChamber(fv, detId, rgeo);
322  } else if (num.getLevels() == theSectorLevel) {
323  buildChamber(fv, detId, rgeo);
324  } else {
325  buildEtaPartition(fv, detId, rgeo);
326  }
327  } else {
328  if (fv.level() == levelChamb) {
329  if ((detId.layer() == 1) || (detId.layer() == 2 and detId.station() == 2 and demonstratorGeometry)) {
330  buildSuperChamber(fv, detId, rgeo);
331  }
332  buildChamber(fv, detId, rgeo);
333  } else if (num.getLevels() > theSectorLevel) {
334  buildEtaPartition(fv, detId, rgeo);
335  }
336  }
337  }
338 }
339 
341  cms::DDSolid solid(fv.solid());
342  auto solidA = solid.solidA();
343  std::vector<double> dpar = solidA.dimensions();
344 
345  double dy = dpar[3] / dd4hep::mm; //length is along local Y
346  double dz = dpar[2] / dd4hep::mm; // thickness is long local Z
347  double dx1 = dpar[0] / dd4hep::mm; // bottom width is along local X
348  double dx2 = dpar[1] / dd4hep::mm; // top width is along loc
349 
350  auto solidB = solid.solidB();
351  dpar = solidB.dimensions();
352  const int nch = 2;
353  const double chgap = 2.105;
354 
355  GEMDetId gemid = detId.superChamberId();
356  std::string_view name = fv.name();
357 
358  dz += (dpar[2] / dd4hep::mm); // chamber thickness
359  dz *= nch; // 2 chambers in superchamber
360  dz += chgap; // gap between chambers
361 
362  std::vector<double> pars{dx1, dx2, dy, dz};
363  std::vector<double> vtra = getTranslation(fv);
364  std::vector<double> vrot = getRotation(fv);
365 
366  edm::LogVerbatim("GEMGeometryParsFromDD")
367  << "(3) DD4hep, SuperChamber DetID " << gemid.rawId() << " Name " << std::string(name) << " dx1 " << dx1
368  << " dx2 " << dx2 << " dy " << dy << " dz " << dz;
369  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {std::string(name)});
370 }
371 
373  cms::DDSolid solid(fv.solid());
374  auto solidA = solid.solidA();
375  std::vector<double> dpar = solidA.dimensions();
376 
377  double dy = dpar[3] / dd4hep::mm; //length is along local Y
378  double dz = dpar[2] / dd4hep::mm; // thickness is long local Z
379  double dx1 = dpar[0] / dd4hep::mm; // bottom width is along local X
380  double dx2 = dpar[1] / dd4hep::mm; // top width is along local X
381 
382  auto solidB = solid.solidB();
383  dpar = solidB.dimensions();
384 
385  dz += (dpar[2] / dd4hep::mm); // chamber thickness
386 
387  GEMDetId gemid = detId.chamberId();
388  std::string_view name = fv.name();
389 
390  std::vector<double> pars{dx1, dx2, dy, dz};
391  std::vector<double> vtra = getTranslation(fv);
392  std::vector<double> vrot = getRotation(fv);
393 
394  edm::LogVerbatim("GEMGeometryParsFromDD")
395  << "(4) DD4hep, Chamber DetID " << gemid.rawId() << " Name " << std::string(name) << " dx1 " << dx1 << " dx2 "
396  << dx2 << " dy " << dy << " dz " << dz;
397  rgeo.insert(gemid.rawId(), vtra, vrot, pars, {std::string(name)});
398 }
399 
401  auto nStrips = fv.get<double>("nStrips");
402  auto nPads = fv.get<double>("nPads");
403  auto dPhi = fv.get<double>("dPhi");
404 
405  std::vector<double> dpar = fv.parameters();
406  std::string_view name = fv.name();
407 
408  double dx1 = dpar[0] / dd4hep::mm;
409  double dx2 = dpar[1] / dd4hep::mm;
410  double dy = dpar[3] / dd4hep::mm;
411  double dz = dpar[2] / dd4hep::mm;
412 
413  std::vector<double> pars{dx1, dx2, dy, dz, nStrips, nPads, dPhi};
414  std::vector<double> vtra = getTranslation(fv);
415  std::vector<double> vrot = getRotation(fv);
416 
417  edm::LogVerbatim("GEMGeometryParsFromDD")
418  << "(5) DD4hep, Eta Partion DetID " << detId.rawId() << " Name " << std::string(name) << " dx1 " << dx1 << " dx2 "
419  << dx2 << " dy " << dy << " dz " << dz << " nStrips " << nStrips << " nPads " << nPads << " dPhi " << dPhi;
420  rgeo.insert(detId.rawId(), vtra, vrot, pars, {std::string(name)});
421 }
422 
424  std::vector<double> tran(3);
425  tran[0] = static_cast<double>(fv.translation().X()) / dd4hep::mm;
426  tran[1] = static_cast<double>(fv.translation().Y()) / dd4hep::mm;
427  tran[2] = static_cast<double>(fv.translation().Z()) / dd4hep::mm;
428 
429  edm::LogVerbatim("GEMGeometryParsFromDD")
430  << "(1) DD4hep, tran vector " << tran[0] << " " << tran[1] << " " << tran[2];
431  return {tran[0], tran[1], tran[2]};
432 }
433 
435  DDRotationMatrix rota;
436  fv.rot(rota);
437  DD3Vector x, y, z;
438  rota.GetComponents(x, y, z);
439  const std::vector<double> rot = {x.X(), x.Y(), x.Z(), y.X(), y.Y(), y.Z(), z.X(), z.Y(), z.Z()};
440  edm::LogVerbatim("GEMGeometryParsFromDD")
441  << "(2) DD4hep, rot matrix " << rot[0] << " " << rot[1] << " " << rot[2] << " " << rot[3] << " " << rot[4]
442  << " " << rot[5] << " " << rot[6] << " " << rot[7] << " " << rot[8];
443  return {rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]};
444 }
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:58
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