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