CMS 3D CMS Logo

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