CMS 3D CMS Logo

GEMGeometryBuilderFromDDD.cc
Go to the documentation of this file.
1 
9 
13 
17 
19 
21 
22 #include "CLHEP/Units/GlobalSystemOfUnits.h"
23 
24 #include <iostream>
25 #include <algorithm>
26 #include <boost/lexical_cast.hpp>
27 
29 { }
30 
32 { }
33 
35 {
36  std::string attribute = "MuStructure"; // "ReadOutName"; // could come from .orcarc
37  std::string value = "MuonEndCapGEM"; // "MuonGEMHits"; // could come from .orcarc
38 
39 
40  // Asking only for the MuonGEM's
41  DDSpecificsMatchesValueFilter filter{DDValue(attribute, value, 0.0)};
42  DDFilteredView fview(*cview,filter);
43 
44  return this->buildGeometry(fview, muonConstants);
45 }
46 
48 {
49  LogDebug("GEMGeometryBuilderFromDDD") <<"Building the geometry service";
51  LogDebug("GEMGeometryBuilderFromDDD") << "About to run through the GEM structure\n"
52  <<" First logical part "
53  <<fv.logicalPart().name().name();
54 
55 
56 
57  bool doSuper = fv.firstChild();
58  LogDebug("GEMGeometryBuilderFromDDD") << "doSuperChamber = " << doSuper;
59  // loop over superchambers
60  while (doSuper){
61 
62  // getting chamber id from eta partitions
63  fv.firstChild();fv.firstChild();
64  MuonDDDNumbering mdddnumCh(muonConstants);
65  GEMNumberingScheme gemNumCh(muonConstants);
66  int rawidCh = gemNumCh.baseNumberToUnitNumber(mdddnumCh.geoHistoryToBaseNumber(fv.geoHistory()));
67  GEMDetId detIdCh = GEMDetId(rawidCh);
68  // back to chambers
69  fv.parent();fv.parent();
70 
71  // currently there is no superchamber in the geometry
72  // only 2 chambers are present separated by a gap.
73  // making superchamber out of the first chamber layer including the gap between chambers
74  if (detIdCh.layer() == 1){// only make superChambers when doing layer 1
75  GEMSuperChamber *gemSuperChamber = buildSuperChamber(fv, detIdCh);
76  geometry->add(gemSuperChamber);
77  }
78  GEMChamber *gemChamber = buildChamber(fv, detIdCh);
79 
80  // loop over chambers
81  // only 1 chamber
82  bool doChambers = fv.firstChild();
83  while (doChambers){
84 
85  // loop over GEMEtaPartitions
86  bool doEtaPart = fv.firstChild();
87  while (doEtaPart){
88 
89  MuonDDDNumbering mdddnum(muonConstants);
90  GEMNumberingScheme gemNum(muonConstants);
91  int rawid = gemNum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
92  GEMDetId detId = GEMDetId(rawid);
93 
94  GEMEtaPartition *etaPart = buildEtaPartition(fv, detId);
95  gemChamber->add(etaPart);
96  geometry->add(etaPart);
97  doEtaPart = fv.nextSibling();
98  }
99  fv.parent();
100 
101  geometry->add(gemChamber);
102 
103  doChambers = fv.nextSibling();
104  }
105  fv.parent();
106 
107  doSuper = fv.nextSibling();
108  }
109 
110  auto& superChambers(geometry->superChambers());
111  // construct the regions, stations and rings.
112  for (int re = -1; re <= 1; re = re+2) {
113  GEMRegion* region = new GEMRegion(re);
114  for (int st=1; st<=GEMDetId::maxStationId; ++st) {
115  GEMStation* station = new GEMStation(re, st);
116  std::string sign( re==-1 ? "-" : "");
117  std::string name("GE" + sign + std::to_string(st) + "/1");
118  station->setName(name);
119  for (int ri=1; ri<=1; ++ri) {
120  GEMRing* ring = new GEMRing(re, st, ri);
121  for (auto sch : superChambers){
122  GEMSuperChamber* superChamber = const_cast<GEMSuperChamber*>(sch);
123  const GEMDetId detId(superChamber->id());
124  if (detId.region() != re || detId.station() != st || detId.ring() != ri) continue;
125 
126  auto ch1 = geometry->chamber(GEMDetId(detId.region(),detId.ring(),detId.station(),1,detId.chamber(),0));
127  auto ch2 = geometry->chamber(GEMDetId(detId.region(),detId.ring(),detId.station(),2,detId.chamber(),0));
128  superChamber->add(const_cast<GEMChamber*>(ch1));
129  superChamber->add(const_cast<GEMChamber*>(ch2));
130 
131  ring->add(superChamber);
132  LogDebug("GEMGeometryBuilderFromDDD") << "Adding super chamber " << detId << " to ring: "
133  << "re " << re << " st " << st << " ri " << ri << std::endl;
134  }
135  LogDebug("GEMGeometryBuilderFromDDD") << "Adding ring " << ri << " to station " << "re " << re << " st " << st << std::endl;
136  station->add(const_cast<GEMRing*>(ring));
137  geometry->add(const_cast<GEMRing*>(ring));
138  }
139  LogDebug("GEMGeometryBuilderFromDDD") << "Adding station " << st << " to region " << re << std::endl;
140  region->add(const_cast<GEMStation*>(station));
141  geometry->add(const_cast<GEMStation*>(station));
142  }
143  LogDebug("GEMGeometryBuilderFromDDD") << "Adding region " << re << " to the geometry " << std::endl;
144  geometry->add(const_cast<GEMRegion*>(region));
145  }
146 
147  return geometry;
148 }
149 
151  LogDebug("GEMGeometryBuilderFromDDD") << "buildSuperChamber "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
152 
154  std::vector<double> dpar = solid.solidA().parameters();
155 
156  double dy = dpar[0]/cm;//length is along local Y
157  double dz = dpar[3]/cm;// thickness is long local Z
158  double dx1= dpar[4]/cm;// bottom width is along local X
159  double dx2= dpar[8]/cm;// top width is along local X
160  dpar = solid.solidB().parameters();
161  dz += dpar[3]/cm;// chamber thickness
162  dz *=2; // 2 chambers in superchamber
163  dz += 2.105;// gap between chambers
164 
165  bool isOdd = detId.chamber()%2;
166  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(dx1,dx2,dy,dz), isOdd ));
167  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< dx1 << " " << dx2 << " " << dy << " " << dz <<std::endl;
168 
169  GEMSuperChamber* superChamber = new GEMSuperChamber(detId.superChamberId(), surf);
170  return superChamber;
171 }
172 
174  LogDebug("GEMGeometryBuilderFromDDD") << "buildChamber "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
175 
177  std::vector<double> dpar = solid.solidA().parameters();
178 
179  double dy = dpar[0]/cm;//length is along local Y
180  double dz = dpar[3]/cm;// thickness is long local Z
181  double dx1= dpar[4]/cm;// bottom width is along local X
182  double dx2= dpar[8]/cm;// top width is along local X
183  dpar = solid.solidB().parameters();
184  dz += dpar[3]/cm;// chamber thickness
185 
186  bool isOdd = detId.chamber()%2;
187  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(dx1,dx2,dy,dz), isOdd ));
188  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< dx1 << " " << dx2 << " " << dy << " " << dz <<std::endl;
189 
190  GEMChamber* chamber = new GEMChamber(detId.chamberId(), surf);
191  return chamber;
192 }
193 
195  LogDebug("GEMGeometryBuilderFromDDD") << "buildEtaPartition "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
196 
197  // EtaPartition specific parameter (nstrips and npads)
198  DDValue numbOfStrips("nStrips");
199  DDValue numbOfPads("nPads");
200  std::vector<const DDsvalues_type* > specs(fv.specifics());
201  std::vector<const DDsvalues_type* >::iterator is = specs.begin();
202  double nStrips = 0., nPads = 0.;
203  for (;is != specs.end(); is++){
204  if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
205  if (DDfetch( *is, numbOfPads)) nPads = numbOfPads.doubles()[0];
206  }
207  LogDebug("GEMGeometryBuilderFromDDD")
208  << ((nStrips == 0. ) ? ("No nStrips found!!") : ("Number of strips: " + boost::lexical_cast<std::string>(nStrips)));
209  LogDebug("GEMGeometryBuilderFromDDD")
210  << ((nPads == 0. ) ? ("No nPads found!!") : ("Number of pads: " + boost::lexical_cast<std::string>(nPads)));
211 
212  // EtaPartition specific parameter (size)
213  std::vector<double> dpar = fv.logicalPart().solid().parameters();
214 
215  double be = dpar[4]/cm; // half bottom edge
216  double te = dpar[8]/cm; // half top edge
217  double ap = dpar[0]/cm; // half apothem
218  double ti = 0.4/cm; // half thickness
219 
220  std::vector<float> pars;
221  pars.emplace_back(be);
222  pars.emplace_back(te);
223  pars.emplace_back(ap);
224  pars.emplace_back(nStrips);
225  pars.emplace_back(nPads);
226 
227  bool isOdd = detId.chamber()%2;
228  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(be, te, ap, ti), isOdd ));
229  std::string name = fv.logicalPart().name().name();
231 
232  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< be << " " << te << " " << ap << " " << ti <<std::endl;
233  GEMEtaPartition* etaPartition = new GEMEtaPartition(detId, surf, e_p_specs);
234  return etaPartition;
235 }
236 
239  Bounds* bounds, bool isOddChamber) const {
240  // extract the position
241  const DDTranslation & trans(fv.translation());
242  const Surface::PositionType posResult(float(trans.x()/cm),
243  float(trans.y()/cm),
244  float(trans.z()/cm));
245 
246  // now the rotation
247  // DDRotationMatrix tmp = fv.rotation();
248  // === DDD uses 'active' rotations - see CLHEP user guide ===
249  // ORCA uses 'passive' rotation.
250  // 'active' and 'passive' rotations are inverse to each other
251  // DDRotationMatrix tmp = fv.rotation();
252  const DDRotationMatrix& rotation = fv.rotation();//REMOVED .Inverse();
253  DD3Vector x, y, z;
254  rotation.GetComponents(x,y,z);
255  // LogDebug("GEMGeometryBuilderFromDDD") << "translation: "<< fv.translation() << std::endl;
256  // LogDebug("GEMGeometryBuilderFromDDD") << "rotation : "<< fv.rotation() << std::endl;
257  // LogDebug("GEMGeometryBuilderFromDDD") << "INVERSE rotation manually: \n"
258  // << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
259  // << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
260  // << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
261 
262  Surface::RotationType rotResult(float(x.X()),float(x.Y()),float(x.Z()),
263  float(y.X()),float(y.Y()),float(y.Z()),
264  float(z.X()),float(z.Y()),float(z.Z()));
265 
266  //Change of axes for the forward
267  Basic3DVector<float> newX(1.,0.,0.);
268  Basic3DVector<float> newY(0.,0.,1.);
269  Basic3DVector<float> newZ(0.,1.,0.);
270  // Odd chambers are inverted in gem.xml
271  if (isOddChamber) newY *= -1;
272 
273  rotResult.rotateAxes(newX, newY, newZ);
274 
275  return RCPBoundPlane( new BoundPlane( posResult, rotResult, bounds));
276 }
#define LogDebug(id)
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 ...
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
GEMGeometry * buildGeometry(DDFilteredView &fview, const MuonDDDConstants &muonConstants)
const N & name() const
Definition: DDBase.h:78
bool nextSibling()
set the current node to the next sibling ...
const DDRotationMatrix & rotation() const
The absolute rotation of the current node.
void add(GEMChamber *ch)
Add chamber to the super chamber which takes ownership.
Plane BoundPlane
Definition: Plane.h:95
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: GEMDetId.h:74
const DDSolid & solid(void) const
Returns a reference object of the solid being the shape of this LogicalPart.
GEMDetId superChamberId() const
Return the corresponding superChamberId.
Definition: GEMDetId.h:90
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.
bool DDfetch(const DDsvalues_type *, DDValue &)
helper for retrieving DDValues from DDsvalues_type *.
Definition: DDsvalues.cc:81
void add(GEMRing *ring)
Add ring to the station which takes ownership.
Definition: GEMStation.cc:28
void add(GEMSuperChamber *ch)
Add super chamber to the ring which takes ownership.
Definition: GEMRing.cc:22
ReferenceCountingPointer< BoundPlane > RCPBoundPlane
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
DDSolid solidB(void) const
Definition: DDSolid.cc:668
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:85
GEMSuperChamber * buildSuperChamber(DDFilteredView &fv, GEMDetId detId) const
GEMGeometry * build(const DDCompactView *cview, const MuonDDDConstants &muonConstants)
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DD3Vector
A DD Translation is currently implemented with Root Vector3D.
Definition: DDTranslation.h:6
int layer() const
Layer id: each station have two layers of chambers: layer 1 is the inner chamber and layer 2 is the o...
Definition: GEMDetId.h:69
RCPBoundPlane boundPlane(const DDFilteredView &fv, Bounds *bounds, bool isOddChamber) const
void add(GEMEtaPartition *roll)
Add EtaPartition to the chamber which takes ownership.
Definition: GEMChamber.cc:27
static const int maxStationId
Definition: GEMDetId.h:101
void setName(std::string name)
Set the station name.
Definition: GEMStation.cc:77
Definition: value.py:1
DDSolid solidA(void) const
Definition: DDSolid.cc:662
const std::vector< const GEMSuperChamber * > & superChambers() const
Return a vector of all GEM super chambers.
Definition: GEMGeometry.cc:55
void add(GEMRegion *region)
Add a GEMRegion to the Geometry.
Definition: GEMGeometry.cc:104
GEMChamber * buildChamber(DDFilteredView &fv, GEMDetId detId) const
GEMEtaPartition * buildEtaPartition(DDFilteredView &fv, GEMDetId detId) const
const GEMChamber * chamber(GEMDetId id) const
Definition: GEMGeometry.cc:95
GEMDetId id() const
Return the GEMDetId of this super chamber.
ESHandle< TrackerGeometry > geometry
bool firstChild()
set the current node to the first child ...
void add(GEMStation *st)
Add station to the region which takes ownership.
Definition: GEMRegion.cc:25
Definition: Bounds.h:22
const DDTranslation & translation() const
The absolute translation of the current node.
std::vector< const DDsvalues_type * > specifics() const
MuonBaseNumber geoHistoryToBaseNumber(const DDGeoHistory &history)
ROOT::Math::Rotation3D DDRotationMatrix
A DDRotationMatrix is currently implemented with a ROOT Rotation3D.
int baseNumberToUnitNumber(const MuonBaseNumber &) override
const std::string & name() const
Returns the name.
Definition: DDName.cc:90