CMS 3D CMS Logo

ME0GeometryBuilderFromDDD10EtaPart.cc
Go to the documentation of this file.
4 
8 
12 
14 
16 
17 #include "CLHEP/Units/GlobalSystemOfUnits.h"
18 
19 #include <iostream>
20 #include <algorithm>
21 #include <boost/lexical_cast.hpp>
22 
24 { }
25 
27 { }
28 
29 
31 {
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 
43 
45 {
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 "<<detId<<" = "<<detId.rawId()<<" (which belongs to ME0Chamber "<<detIdCh<<" = "<<detIdCh.rawId()<<")";
75  LogTrace("ME0GeometryBuilderFromDDD") << "Second level logical part: " << fv.logicalPart().name().name();
77  std::vector<double> dpar2 = solid2.parameters();
78  std::stringstream parameters2;
79  for(unsigned int i=0; i<dpar2.size(); ++i) {
80  parameters2 << " dpar["<<i<<"]="<< dpar2[i]/10 << "cm ";
81  }
82  LogTrace("ME0GeometryBuilderFromDDD") << "Second level parameters: vector with size = "<<dpar2.size()<<" and elements "<<parameters2.str();
83  // from GEM
84  // DDBooleanSolid solid = (DDBooleanSolid)(fv.logicalPart().solid());
85  // std::vector<double> dpar = solid.solidA().parameters();
86  /*
87  if(solid2.solidA()) {
88  std::vector<double> dpar2a = solid2.solidA().parameters();
89  std::stringstream parameters2a;
90  for(unsigned int i=0; i<dpar2a.size(); ++i) {
91  parameters2a << " dpara["<<i<<"]="<< dpar2a[i]/10 << "cm ";
92  }
93  LogTrace("ME0GeometryBuilderFromDDD") << "Second level parameters: vector with size = "<<dpar2a.size()<<" and elements "<<parameters2.str();
94  }
95  if(solid2.solidB()) {
96  std::vector<double> dpar2b = solid2.solidB().parameters();
97  std::stringstream parameters2b;
98  for(unsigned int i=0; i<dpar2b.size(); ++i) {
99  parameters2b << " dparb["<<i<<"]="<< dpar2b[i]/10 << "cm ";
100  }
101  LogTrace("ME0GeometryBuilderFromDDD") << "Second level parameters: vector with size = "<<dpar2b.size()<<" and elements "<<parameters2.str();
102  }
103  */
104  bool doLayers = fv.firstChild();
105  // --------------------------------------------------------------------------------------------------------------------------------------------
106  LogTrace("ME0GeometryBuilderFromDDD") << "doLayer = fv.firstChild() = " << doLayers;
107  while (doLayers) {
108  // to etapartitions
109  LogTrace("ME0GeometryBuilderFromDDD")<<"to etapt "<<fv.firstChild(); // commented out in case only looping over sensitive volumes
110  MuonDDDNumbering mdddnum(muonConstants);
111  ME0NumberingScheme me0Num(muonConstants);
112  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
113  ME0DetId detId = ME0DetId(rawId);
114  ME0DetId detIdLa = detId.layerId();
115  // back to layers
116  LogTrace("ME0GeometryBuilderFromDDD")<<"back to layer "<<fv.parent(); // commented out in case only looping over sensitive volumes
117  LogTrace("ME0GeometryBuilderFromDDD") << "In DoLayers Loop :: ME0DetId "<<detId<<" = "<<detId.rawId()<<" (which belongs to ME0Layer "<<detIdLa<<" = "<<detIdLa.rawId()<<")";
118  LogTrace("ME0GeometryBuilderFromDDD") << "Third level logical part: " << fv.logicalPart().name().name();
119  DDBooleanSolid solid3 = (DDBooleanSolid)(fv.logicalPart().solid());
120  std::vector<double> dpar3 = solid3.parameters();
121  std::stringstream parameters3;
122  for(unsigned int i=0; i<dpar3.size(); ++i) {
123  parameters3 << " dpar["<<i<<"]="<< dpar3[i]/10 << "cm ";
124  }
125  LogTrace("ME0GeometryBuilderFromDDD") << "Third level parameters: vector with size = "<<dpar3.size()<<" and elements "<<parameters3.str();
126  bool doEtaParts = fv.firstChild();
127  // --------------------------------------------------------------------------------------------------------------------------------------------
128  LogTrace("ME0GeometryBuilderFromDDD") << "doEtaPart = fv.firstChild() = " << doEtaParts;
129  while (doEtaParts) {
130  LogTrace("ME0GeometryBuilderFromDDD") << "In DoEtaParts Loop :: ME0DetId "<<detId<<" = "<<detId.rawId();
131  LogTrace("ME0GeometryBuilderFromDDD") << "Fourth level logical part: " << fv.logicalPart().name().name();
132  DDBooleanSolid solid4 = (DDBooleanSolid)(fv.logicalPart().solid());
133  std::vector<double> dpar4 = solid4.parameters();
134  std::stringstream parameters4;
135  for(unsigned int i=0; i<dpar4.size(); ++i) {
136  parameters4 << " dpar["<<i<<"]="<< dpar4[i]/10 << "cm ";
137  }
138  LogTrace("ME0GeometryBuilderFromDDD") << "Fourth level parameters: vector with size = "<<dpar4.size()<<" and elements "<<parameters4.str();
139  // --------------------------------------------------------------------------------------------------------------------------------------------
140  doEtaParts = fv.nextSibling();
141  LogTrace("ME0GeometryBuilderFromDDD") << "doEtaPart = fv.nextSibling() = " << doEtaParts;
142  }
143  fv.parent(); // commented out in case only looping over sensitive volumes
144  LogTrace("ME0GeometryBuilderFromDDD") << "went back to parent :: name = "<<fv.logicalPart().name().name()<<" will now ask for nextSibling";
145  doLayers = fv.nextSibling();
146  LogTrace("ME0GeometryBuilderFromDDD") << "doLayer = fv.nextSibling() = " << doLayers;
147  }
148  fv.parent(); // commented out in case only looping over sensitive volumes
149  LogTrace("ME0GeometryBuilderFromDDD") << "went back to parent :: name = "<<fv.logicalPart().name().name()<<" will now ask for nextSibling";
150  testChambers = fv.nextSibling();
151  LogTrace("ME0GeometryBuilderFromDDD") << "doChamber = fv.nextSibling() = " << testChambers;
152  }
153  fv.parent();
154  #endif
155 
156 
157  // ==========================================
158  // === Here the Real ME0 Geometry Builder ===
159  // ==========================================
160  bool doChambers = fv.firstChild();
161  while (doChambers) {
162  // to etapartitions and back again to pick up DetId
163  fv.firstChild();
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 detIdCh = detId.chamberId();
170  fv.parent();
171  fv.parent();
172 
173  // build chamber
174  ME0Chamber *me0Chamber = buildChamber(fv, detIdCh);
175  geometry->add(me0Chamber);
176 
177  // loop over layers of the chamber
178  bool doLayers = fv.firstChild();
179  while (doLayers) {
180  // to etapartitions and back again to pick up DetId
181  fv.firstChild();
182  MuonDDDNumbering mdddnum(muonConstants);
183  ME0NumberingScheme me0Num(muonConstants);
184  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
185  ME0DetId detId = ME0DetId(rawId);
186  ME0DetId detIdLa = detId.layerId();
187  fv.parent();
188 
189  // build layer
190  ME0Layer *me0Layer = buildLayer(fv, detIdLa);
191  me0Chamber->add(me0Layer);
192  geometry->add(me0Layer);
193 
194 
195  // loop over etapartitions of the layer
196  bool doEtaParts = fv.firstChild();
197  while (doEtaParts) {
198  // pick up DetId
199  MuonDDDNumbering mdddnum(muonConstants);
200  ME0NumberingScheme me0Num(muonConstants);
201  int rawId = me0Num.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
202  ME0DetId detId = ME0DetId(rawId);
203 
204  // build etapartition
205  ME0EtaPartition *etaPart = buildEtaPartition(fv, detId);
206  me0Layer->add(etaPart);
207  geometry->add(etaPart);
208 
209  doEtaParts = fv.nextSibling();
210  }
211  fv.parent();
212  doLayers = fv.nextSibling();
213  }
214  fv.parent();
215  doChambers = fv.nextSibling();
216  }
217 
218  return geometry;
219 }
220 
222  LogTrace("ME0GeometryBuilderFromDDD") << "buildChamber "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
223 
225  // std::vector<double> dpar = solid.solidA().parameters();
226  std::vector<double> dpar = solid.parameters();
227  double L = dpar[0]/cm;// length is along local Y
228  double T = dpar[3]/cm;// thickness is long local Z
229  double b = dpar[4]/cm;// bottom width is along local X
230  double B = dpar[8]/cm;// top width is along local X
231  // hardcoded :: double b = 21.9859, B = 52.7261, L = 87.1678, T = 12.9;
232 
233  #ifdef EDM_ML_DEBUG
234  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = "<<fv.logicalPart().name().name()<<std::endl;
235  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = "<<dpar.size()<<std::endl;
236  for(unsigned int i=0; i<dpar.size(); ++i) {
237  LogTrace("ME0GeometryBuilderFromDDD") << " dpar ["<<i<<"] = "<< dpar[i]/10 << " cm "<<std::endl;
238  }
239  LogTrace("ME0GeometryBuilderFromDDD") << "size b: "<< b << "cm, B: " << B << "cm, L: " << L << "cm, T: " << T <<"cm "<<std::endl;
240  #endif
241 
242  bool isOdd = false; // detId.chamber()%2;
243  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b,B,L,T), isOdd ));
244  ME0Chamber* chamber = new ME0Chamber(detId.chamberId(), surf);
245  return chamber;
246 }
247 
249  LogTrace("ME0GeometryBuilderFromDDD") << "buildLayer "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
250 
252  // std::vector<double> dpar = solid.solidA().parameters();
253  std::vector<double> dpar = solid.parameters();
254  double L = dpar[0]/cm;// length is along local Y
255  double t = dpar[3]/cm;// thickness is long local Z
256  double b = dpar[4]/cm;// bottom width is along local X
257  double B = dpar[8]/cm;// top width is along local X
258  // dpar = solid.solidB().parameters();
259  // dz += dpar[3]/cm; // layer thickness --- to be checked !!! layer thickness should be same as eta part thickness
260  // hardcoded :: double b = 21.9859, B = 52.7261, L = 87.1678, t = 0.4;
261 
262  #ifdef EDM_ML_DEBUG
263  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = "<<fv.logicalPart().name().name()<<std::endl;
264  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = "<<dpar.size()<<std::endl;
265  for(unsigned int i=0; i<dpar.size(); ++i) {
266  LogTrace("ME0GeometryBuilderFromDDD") << " dpar ["<<i<<"] = "<< dpar[i]/10 << " cm "<<std::endl;
267  }
268  LogTrace("ME0GeometryBuilderFromDDD") << "size b: "<< b << "cm, B: " << B << "cm, L: " << L << "cm, t: " << t <<"cm "<<std::endl;
269  #endif
270 
271  bool isOdd = false; // detId.chamber()%2;
272  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b,B,L,t), isOdd ));
273  ME0Layer* layer = new ME0Layer(detId.layerId(), surf);
274  return layer;
275 }
276 
278  LogTrace("ME0GeometryBuilderFromDDD") << "buildEtaPartition "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
279 
280  // EtaPartition specific parameter (nstrips and npads)
281  DDValue numbOfStrips("nStrips");
282  DDValue numbOfPads("nPads");
283  std::vector<const DDsvalues_type* > specs(fv.specifics());
284  std::vector<const DDsvalues_type* >::iterator is = specs.begin();
285  double nStrips = 0., nPads = 0.;
286  for (;is != specs.end(); is++){
287  if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
288  if (DDfetch( *is, numbOfPads)) nPads = numbOfPads.doubles()[0];
289  }
290  LogTrace("ME0GeometryBuilderFromDDD")
291  << ((nStrips == 0. ) ? ("No nStrips found!!") : ("Number of strips: " + boost::lexical_cast<std::string>(nStrips)));
292  LogTrace("ME0GeometryBuilderFromDDD")
293  << ((nPads == 0. ) ? ("No nPads found!!") : ("Number of pads: " + boost::lexical_cast<std::string>(nPads)));
294 
295  // EtaPartition specific parameter (size)
296  std::vector<double> dpar = fv.logicalPart().solid().parameters();
297  double b = dpar[4]/cm; // half bottom edge
298  double B = dpar[8]/cm; // half top edge
299  double L = dpar[0]/cm; // half apothem
300  double t = dpar[3]/cm; // half thickness
301 
302  #ifdef EDM_ML_DEBUG
303  LogTrace("ME0GeometryBuilderFromDDD") << " name of logical part = "<<fv.logicalPart().name().name()<<std::endl;
304  LogTrace("ME0GeometryBuilderFromDDD") << " dpar is vector with size = "<<dpar.size()<<std::endl;
305  for(unsigned int i=0; i<dpar.size(); ++i) {
306  LogTrace("ME0GeometryBuilderFromDDD") << " dpar ["<<i<<"] = "<< dpar[i]/10 << " cm "<<std::endl;
307  }
308  LogTrace("ME0GeometryBuilderFromDDD") << "size b: "<< b << "cm, B: " << B << "cm, L: " << L << "cm, t: " << t <<"cm "<<std::endl;
309  #endif
310 
311  std::vector<float> pars;
312  pars.emplace_back(b);
313  pars.emplace_back(B);
314  pars.emplace_back(L);
315  pars.emplace_back(nStrips);
316  pars.emplace_back(nPads);
317 
318  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)
319  ME0BoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(b, B, L, t), isOdd ));
320  std::string name = fv.logicalPart().name().name();
322 
323  ME0EtaPartition* etaPartition = new ME0EtaPartition(detId, surf, e_p_specs);
324  return etaPartition;
325 }
326 
329  Bounds* bounds, bool isOddChamber) const {
330  // extract the position
331  const DDTranslation & trans(fv.translation());
332  const Surface::PositionType posResult(float(trans.x()/cm),
333  float(trans.y()/cm),
334  float(trans.z()/cm));
335 
336  // now the rotation
337  // DDRotationMatrix tmp = fv.rotation();
338  // === DDD uses 'active' rotations - see CLHEP user guide ===
339  // ORCA uses 'passive' rotation.
340  // 'active' and 'passive' rotations are inverse to each other
341  // DDRotationMatrix tmp = fv.rotation();
342  const DDRotationMatrix& rotation = fv.rotation();//REMOVED .Inverse();
343  DD3Vector x, y, z;
344  rotation.GetComponents(x,y,z);
345  // LogTrace("GEMGeometryBuilderFromDDD") << "translation: "<< fv.translation() << std::endl;
346  // LogTrace("GEMGeometryBuilderFromDDD") << "rotation : "<< fv.rotation() << std::endl;
347  // LogTrace("GEMGeometryBuilderFromDDD") << "INVERSE rotation manually: \n"
348  // << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
349  // << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
350  // << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
351 
352  Surface::RotationType rotResult(float(x.X()),float(x.Y()),float(x.Z()),
353  float(y.X()),float(y.Y()),float(y.Z()),
354  float(z.X()),float(z.Y()),float(z.Z()));
355 
356  //Change of axes for the forward
357  Basic3DVector<float> newX(1.,0.,0.);
358  Basic3DVector<float> newY(0.,0.,1.);
359  Basic3DVector<float> newZ(0.,1.,0.);
360  newY *= -1;
361 
362  rotResult.rotateAxes(newX, newY, newZ);
363 
364  return ME0BoundPlane( new BoundPlane( posResult, rotResult, bounds));
365 }
366 
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:150
bool parent()
set the current node to the parent node ...
ME0DetId layerId() const
Return the corresponding LayerId (mask eta partition)
Definition: ME0DetId.h:71
ME0Chamber * buildChamber(DDFilteredView &fv, ME0DetId detId) const
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 * buildGeometry(DDFilteredView &fview, const MuonDDDConstants &muonConstants)
const N & name() const
Definition: DDBase.h:78
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.
Plane BoundPlane
Definition: Plane.h:95
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
type of data representation of DDCompactView
Definition: DDCompactView.h:90
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
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
int baseNumberToUnitNumber(const MuonBaseNumber &) override
ReferenceCountingPointer< BoundPlane > ME0BoundPlane
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
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)
ME0EtaPartition * buildEtaPartition(DDFilteredView &fv, ME0DetId detId) const
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 ...
ME0Geometry * build(const DDCompactView *cview, const MuonDDDConstants &muonConstants)
ME0Layer * buildLayer(DDFilteredView &fv, ME0DetId detId) const
Definition: Bounds.h:22
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
long double T
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90