CMS 3D CMS Logo

ME0GeometryBuilderFromDDD.cc
Go to the documentation of this file.
4 
8 
12 
14 
16 
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 
19 #include <algorithm>
20 #include <iostream>
21 #include <string>
22 
24 
26 
28  std::string attribute = "MuStructure";
29  std::string value = "MuonEndCapME0";
30 
31  // Asking only for the MuonME0's
32  DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
33  DDFilteredView fview(*cview, filter);
34 
35  return this->buildGeometry(fview, muonConstants);
36 }
37 
40 
41  LogTrace("ME0GeometryBuilderFromDDD") << "Building the geometry service";
42  LogTrace("ME0GeometryBuilderFromDDD") << "About to run through the ME0 structure\n"
43  << "Top level logical part: " << fv.logicalPart().name().name();
44 
45 // ==========================================
46 // === Test to understand the structure ===
47 // ==========================================
48 #ifdef EDM_ML_DEBUG
49  bool testChambers = fv.firstChild();
50  LogTrace("ME0GeometryBuilderFromDDD") << "doChamber = fv.firstChild() = " << testChambers;
51  // ----------------------------------------------------------------------------------------------------------------------------------------------
52  while (testChambers) {
53  // to etapartitions
54  LogTrace("ME0GeometryBuilderFromDDD")
55  << "to layer " << fv.firstChild(); // commented out in case only looping over sensitive volumes
56  LogTrace("ME0GeometryBuilderFromDDD")
57  << "to etapt " << fv.firstChild(); // commented out in case only looping over sensitive volumes
58  MuonDDDNumbering mdddnum(muonConstants);
59  ME0NumberingScheme me0Num(muonConstants);
60  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
61  ME0DetId detId = ME0DetId(rawId);
62  ME0DetId detIdCh = detId.chamberId();
63  // back to chambers
64  LogTrace("ME0GeometryBuilderFromDDD")
65  << "back to layer " << fv.parent(); // commented out in case only looping over sensitive volumes
66  LogTrace("ME0GeometryBuilderFromDDD")
67  << "back to chamb " << fv.parent(); // commented out in case only looping over sensitive volumes
68  // ok lets get started ...
69  LogTrace("ME0GeometryBuilderFromDDD")
70  << "In DoChambers Loop :: ME0DetId " << detId << " = " << detId.rawId() << " (which belongs to ME0Chamber "
71  << detIdCh << " = " << detIdCh.rawId() << ")";
72  LogTrace("ME0GeometryBuilderFromDDD") << "Second level logical part: " << fv.logicalPart().name().name();
74  std::vector<double> dpar2 = solid2.parameters();
75  std::stringstream parameters2;
76  for (unsigned int i = 0; i < dpar2.size(); ++i) {
77  parameters2 << " dpar[" << i << "]=" << dpar2[i] / 10 << "cm ";
78  }
79  LogTrace("ME0GeometryBuilderFromDDD")
80  << "Second level parameters: vector with size = " << dpar2.size() << " and elements " << parameters2.str();
81 
82  bool doLayers = fv.firstChild();
83  // --------------------------------------------------------------------------------------------------------------------------------------------
84  LogTrace("ME0GeometryBuilderFromDDD") << "doLayer = fv.firstChild() = " << doLayers;
85  while (doLayers) {
86  // to etapartitions
87  LogTrace("ME0GeometryBuilderFromDDD")
88  << "to etapt " << fv.firstChild(); // commented out in case only looping over sensitive volumes
89  MuonDDDNumbering mdddnum(muonConstants);
90  ME0NumberingScheme me0Num(muonConstants);
91  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
92  ME0DetId detId = ME0DetId(rawId);
93  ME0DetId detIdLa = detId.layerId();
94  // back to layers
95  LogTrace("ME0GeometryBuilderFromDDD")
96  << "back to layer " << fv.parent(); // commented out in case only looping over sensitive volumes
97  LogTrace("ME0GeometryBuilderFromDDD")
98  << "In DoLayers Loop :: ME0DetId " << detId << " = " << detId.rawId() << " (which belongs to ME0Layer "
99  << detIdLa << " = " << detIdLa.rawId() << ")";
100  LogTrace("ME0GeometryBuilderFromDDD") << "Third level logical part: " << fv.logicalPart().name().name();
101  DDBooleanSolid solid3 = (DDBooleanSolid)(fv.logicalPart().solid());
102  std::vector<double> dpar3 = solid3.parameters();
103  std::stringstream parameters3;
104  for (unsigned int i = 0; i < dpar3.size(); ++i) {
105  parameters3 << " dpar[" << i << "]=" << dpar3[i] / 10 << "cm ";
106  }
107  LogTrace("ME0GeometryBuilderFromDDD")
108  << "Third level parameters: vector with size = " << dpar3.size() << " and elements " << parameters3.str();
109  bool doEtaParts = fv.firstChild();
110  // --------------------------------------------------------------------------------------------------------------------------------------------
111  LogTrace("ME0GeometryBuilderFromDDD") << "doEtaPart = fv.firstChild() = " << doEtaParts;
112  while (doEtaParts) {
113  LogTrace("ME0GeometryBuilderFromDDD") << "In DoEtaParts Loop :: ME0DetId " << detId << " = " << detId.rawId();
114  LogTrace("ME0GeometryBuilderFromDDD") << "Fourth level logical part: " << fv.logicalPart().name().name();
115  DDBooleanSolid solid4 = (DDBooleanSolid)(fv.logicalPart().solid());
116  std::vector<double> dpar4 = solid4.parameters();
117  std::stringstream parameters4;
118  for (unsigned int i = 0; i < dpar4.size(); ++i) {
119  parameters4 << " dpar[" << i << "]=" << dpar4[i] / 10 << "cm ";
120  }
121  LogTrace("ME0GeometryBuilderFromDDD")
122  << "Fourth level parameters: vector with size = " << dpar4.size() << " and elements " << parameters4.str();
123  // --------------------------------------------------------------------------------------------------------------------------------------------
124  doEtaParts = fv.nextSibling();
125  LogTrace("ME0GeometryBuilderFromDDD") << "doEtaPart = fv.nextSibling() = " << doEtaParts;
126  }
127  fv.parent(); // commented out in case only looping over sensitive volumes
128  LogTrace("ME0GeometryBuilderFromDDD")
129  << "went back to parent :: name = " << fv.logicalPart().name().name() << " will now ask for nextSibling";
130  doLayers = fv.nextSibling();
131  LogTrace("ME0GeometryBuilderFromDDD") << "doLayer = fv.nextSibling() = " << doLayers;
132  }
133  fv.parent(); // commented out in case only looping over sensitive volumes
134  LogTrace("ME0GeometryBuilderFromDDD")
135  << "went back to parent :: name = " << fv.logicalPart().name().name() << " will now ask for nextSibling";
136  testChambers = fv.nextSibling();
137  LogTrace("ME0GeometryBuilderFromDDD") << "doChamber = fv.nextSibling() = " << testChambers;
138  }
139  fv.parent();
140 #endif
141 
142  // ==========================================
143  // === Here the Real ME0 Geometry Builder ===
144  // ==========================================
145  bool doChambers = fv.firstChild();
146  while (doChambers) {
147  // to etapartitions and back again to pick up DetId
148  fv.firstChild();
149  fv.firstChild();
150  MuonDDDNumbering mdddnum(muonConstants);
151  ME0NumberingScheme me0Num(muonConstants);
152  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
153  ME0DetId detId = ME0DetId(rawId);
154  ME0DetId detIdCh = detId.chamberId();
155  fv.parent();
156  fv.parent();
157 
158  // build chamber
159  ME0Chamber* me0Chamber = buildChamber(fv, detIdCh);
160  geometry->add(me0Chamber);
161 
162  // loop over layers of the chamber
163  bool doLayers = fv.firstChild();
164  while (doLayers) {
165  // to etapartitions and back again to pick up DetId
166  fv.firstChild();
167  MuonDDDNumbering mdddnum(muonConstants);
168  ME0NumberingScheme me0Num(muonConstants);
169  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
170  ME0DetId detId = ME0DetId(rawId);
171  ME0DetId detIdLa = detId.layerId();
172  fv.parent();
173 
174  // build layer
175  ME0Layer* me0Layer = buildLayer(fv, detIdLa);
176  me0Chamber->add(me0Layer);
177  geometry->add(me0Layer);
178 
179  // loop over etapartitions of the layer
180  bool doEtaParts = fv.firstChild();
181  while (doEtaParts) {
182  // pick up DetId
183  MuonDDDNumbering mdddnum(muonConstants);
184  ME0NumberingScheme me0Num(muonConstants);
185  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
186  ME0DetId detId = ME0DetId(rawId);
187 
188  // build etapartition
189  ME0EtaPartition* etaPart = buildEtaPartition(fv, detId);
190  me0Layer->add(etaPart);
191  geometry->add(etaPart);
192 
193  doEtaParts = fv.nextSibling();
194  }
195  fv.parent();
196  doLayers = fv.nextSibling();
197  }
198  fv.parent();
199  doChambers = fv.nextSibling();
200  }
201 
202  return geometry;
203 }
204 
206  LogTrace("ME0GeometryBuilderFromDDD") << "buildChamber " << fv.logicalPart().name().name() << " " << detId
207  << std::endl;
208 
210  // std::vector<double> dpar = solid.solidA().parameters();
211  std::vector<double> dpar = solid.parameters();
212  double L = dpar[0] / cm; // length is along local Y
213  double T = dpar[3] / cm; // thickness is long local Z
214  double b = dpar[4] / cm; // bottom width is along local X
215  double B = dpar[8] / cm; // top width is along local X
216  // hardcoded :: double b = 21.9859, B = 52.7261, L = 87.1678, T = 12.9;
217 
218 #ifdef EDM_ML_DEBUG
219  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = " << fv.logicalPart().name().name() << std::endl;
220  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = " << dpar.size() << std::endl;
221  for (unsigned int i = 0; i < dpar.size(); ++i) {
222  LogTrace("ME0GeometryBuilderFromDDD") << " dpar [" << i << "] = " << dpar[i] / 10 << " cm " << std::endl;
223  }
224  LogTrace("ME0GeometryBuilderFromDDD") << "size b: " << b << "cm, B: " << B << "cm, L: " << L << "cm, T: " << T
225  << "cm " << std::endl;
226 #endif
227 
228  bool isOdd = false; // detId.chamber()%2;
229  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b, B, L, T), isOdd));
230  ME0Chamber* chamber = new ME0Chamber(detId.chamberId(), surf);
231  return chamber;
232 }
233 
235  LogTrace("ME0GeometryBuilderFromDDD") << "buildLayer " << fv.logicalPart().name().name() << " " << detId << std::endl;
236 
238  // std::vector<double> dpar = solid.solidA().parameters();
239  std::vector<double> dpar = solid.parameters();
240  double L = dpar[0] / cm; // length is along local Y
241  double t = dpar[3] / cm; // thickness is long local Z
242  double b = dpar[4] / cm; // bottom width is along local X
243  double B = dpar[8] / cm; // top width is along local X
244  // dpar = solid.solidB().parameters();
245  // dz += dpar[3]/cm; // layer thickness --- to be checked !!! layer thickness should be same as eta part thickness
246  // hardcoded :: double b = 21.9859, B = 52.7261, L = 87.1678, t = 0.4;
247 
248 #ifdef EDM_ML_DEBUG
249  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = " << fv.logicalPart().name().name() << std::endl;
250  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = " << dpar.size() << std::endl;
251  for (unsigned int i = 0; i < dpar.size(); ++i) {
252  LogTrace("ME0GeometryBuilderFromDDD") << " dpar [" << i << "] = " << dpar[i] / 10 << " cm " << std::endl;
253  }
254  LogTrace("ME0GeometryBuilderFromDDD") << "size b: " << b << "cm, B: " << B << "cm, L: " << L << "cm, t: " << t
255  << "cm " << std::endl;
256 #endif
257 
258  bool isOdd = false; // detId.chamber()%2;
259  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b, B, L, t), isOdd));
260  ME0Layer* layer = new ME0Layer(detId.layerId(), surf);
261  return layer;
262 }
263 
265  LogTrace("ME0GeometryBuilderFromDDD") << "buildEtaPartition " << fv.logicalPart().name().name() << " " << detId
266  << std::endl;
267 
268  // EtaPartition specific parameter (nstrips and npads)
269  DDValue numbOfStrips("nStrips");
270  DDValue numbOfPads("nPads");
271  std::vector<const DDsvalues_type*> specs(fv.specifics());
272  std::vector<const DDsvalues_type*>::iterator is = specs.begin();
273  double nStrips = 0., nPads = 0.;
274  for (; is != specs.end(); is++) {
275  if (DDfetch(*is, numbOfStrips))
276  nStrips = numbOfStrips.doubles()[0];
277  if (DDfetch(*is, numbOfPads))
278  nPads = numbOfPads.doubles()[0];
279  }
280  LogTrace("ME0GeometryBuilderFromDDD") << ((nStrips == 0.) ? ("No nStrips found!!")
281  : ("Number of strips: " + std::to_string(nStrips)));
282  LogTrace("ME0GeometryBuilderFromDDD") << ((nPads == 0.) ? ("No nPads found!!")
283  : ("Number of pads: " + std::to_string(nPads)));
284 
285  // EtaPartition specific parameter (size)
286  std::vector<double> dpar = fv.logicalPart().solid().parameters();
287  double b = dpar[4] / cm; // half bottom edge
288  double B = dpar[8] / cm; // half top edge
289  double L = dpar[0] / cm; // half apothem
290  double t = dpar[3] / cm; // half thickness
291 
292 #ifdef EDM_ML_DEBUG
293  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = " << fv.logicalPart().name().name() << std::endl;
294  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = " << dpar.size() << std::endl;
295  for (unsigned int i = 0; i < dpar.size(); ++i) {
296  LogTrace("ME0GeometryBuilderFromDDD") << " dpar [" << i << "] = " << dpar[i] / 10 << " cm " << std::endl;
297  }
298  LogTrace("ME0GeometryBuilderFromDDD") << "size b: " << b << "cm, B: " << B << "cm, L: " << L << "cm, t: " << t
299  << "cm " << std::endl;
300 #endif
301 
302  std::vector<float> pars;
303  pars.emplace_back(b);
304  pars.emplace_back(B);
305  pars.emplace_back(L);
306  pars.emplace_back(nStrips);
307  pars.emplace_back(nPads);
308 
309  bool isOdd =
310  false; // detId.chamber()%2; // this gives the opportunity (in future) to change the face of the chamber (electronics facing IP or electronics away from IP)
311  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b, B, L, t), isOdd));
312  std::string name = fv.logicalPart().name().name();
314 
315  ME0EtaPartition* etaPartition = new ME0EtaPartition(detId, surf, e_p_specs);
316  return etaPartition;
317 }
318 
320  Bounds* bounds,
321  bool isOddChamber) const {
322  // extract the position
323  const DDTranslation& trans(fv.translation());
324  const Surface::PositionType posResult(float(trans.x() / cm), float(trans.y() / cm), float(trans.z() / cm));
325 
326  // now the rotation
327  // DDRotationMatrix tmp = fv.rotation();
328  // === DDD uses 'active' rotations - see CLHEP user guide ===
329  // ORCA uses 'passive' rotation.
330  // 'active' and 'passive' rotations are inverse to each other
331  // DDRotationMatrix tmp = fv.rotation();
332  const DDRotationMatrix& rotation = fv.rotation(); //REMOVED .Inverse();
333  DD3Vector x, y, z;
334  rotation.GetComponents(x, y, z);
335  // LogTrace("GEMGeometryBuilderFromDDD") << "translation: "<< fv.translation() << std::endl;
336  // LogTrace("GEMGeometryBuilderFromDDD") << "rotation : "<< fv.rotation() << std::endl;
337  // LogTrace("GEMGeometryBuilderFromDDD") << "INVERSE rotation manually: \n"
338  // << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
339  // << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
340  // << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
341 
342  Surface::RotationType rotResult(float(x.X()),
343  float(x.Y()),
344  float(x.Z()),
345  float(y.X()),
346  float(y.Y()),
347  float(y.Z()),
348  float(z.X()),
349  float(z.Y()),
350  float(z.Z()));
351 
352  //Change of axes for the forward
353  Basic3DVector<float> newX(1., 0., 0.);
354  Basic3DVector<float> newY(0., 0., 1.);
355  Basic3DVector<float> newZ(0., 1., 0.);
356  newY *= -1;
357 
358  rotResult.rotateAxes(newX, newY, newZ);
359 
360  return ME0BoundPlane(new BoundPlane(posResult, rotResult, bounds));
361 }
ReferenceCountingPointer< BoundPlane > ME0BoundPlane
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:121
bool parent()
set the current node to the parent node ...
ME0DetId layerId() const
Return the corresponding LayerId (mask eta partition)
Definition: ME0DetId.h:55
const DDLogicalPart & logicalPart() const
The logical-part of the current node in the filtered-view.
const std::vector< double > & doubles() const
a reference to the double-valued values stored in the given instance of DDValue
Definition: DDValue.cc:111
ME0Geometry * build(const DDCompactView *cview, const MuonDDDConstants &muonConstants)
const N & name() const
Definition: DDBase.h:59
ME0DetId chamberId() const
Return the corresponding ChamberId (mask layers)
Definition: ME0DetId.h:53
bool nextSibling()
set the current node to the next sibling ...
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
ME0Chamber * buildChamber(DDFilteredView &fv, ME0DetId detId) const
Plane BoundPlane
Definition: Plane.h:94
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
const DDGeoHistory & geoHistory() const
The list of ancestors up to the root-node of the current node.
void add(ME0Layer *layer)
Add Layer to the chamber which takes ownership.
Definition: ME0Chamber.cc:16
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:79
nStrips
1.2 is to make the matching window safely the two nearest strips 0.35 is the size of an ME0 chamber i...
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
int baseNumberToUnitNumber(const MuonBaseNumber &) override
ME0BoundPlane boundPlane(const DDFilteredView &fv, Bounds *bounds, bool isOddChamber) const
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
ME0Geometry * buildGeometry(DDFilteredView &fview, const MuonDDDConstants &muonConstants)
void add(const ME0EtaPartition *roll)
Add EtaPartition to the layer which takes ownership.
Definition: ME0Layer.cc:15
Definition: value.py:1
static const std::string B
#define LogTrace(id)
double b
Definition: hdecay.h:118
void add(ME0EtaPartition *etaPartition)
Add a ME0 etaPartition to the Geometry.
Definition: ME0Geometry.cc:47
ESHandle< TrackerGeometry > geometry
bool firstChild()
set the current node to the first child ...
Definition: Bounds.h:20
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
ME0EtaPartition * buildEtaPartition(DDFilteredView &fv, ME0DetId detId) const
long double T
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history)
const std::string & name() const
Returns the name.
Definition: DDName.cc:40
ME0Layer * buildLayer(DDFilteredView &fv, ME0DetId detId) const