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  DDValue val(attribute, value, 0.0);
40  // Asking only for the MuonGEM's
42  filter.setCriteria(val, // name & value of a variable
44  DDLogOp::AND,
45  true, // compare strings otherwise doubles
46  true // use merged-specifics or simple-specifics
47  );
48  DDFilteredView fview(*cview);
49  fview.addFilter(filter);
50 
51  return this->buildGeometry(fview, muonConstants);
52 }
53 
55 {
56  LogDebug("GEMGeometryBuilderFromDDD") <<"Building the geometry service";
58  LogDebug("GEMGeometryBuilderFromDDD") << "About to run through the GEM structure\n"
59  <<" First logical part "
60  <<fv.logicalPart().name().name();
61 
62 
63 
64  bool doSuper = fv.firstChild();
65  LogDebug("GEMGeometryBuilderFromDDD") << "doSuperChamber = " << doSuper;
66  // loop over superchambers
67  while (doSuper){
68 
69  // getting chamber id from eta partitions
70  fv.firstChild();fv.firstChild();
71  MuonDDDNumbering mdddnumCh(muonConstants);
72  GEMNumberingScheme gemNumCh(muonConstants);
73  int rawidCh = gemNumCh.baseNumberToUnitNumber(mdddnumCh.geoHistoryToBaseNumber(fv.geoHistory()));
74  GEMDetId detIdCh = GEMDetId(rawidCh);
75  // back to chambers
76  fv.parent();fv.parent();
77 
78  // currently there is no superchamber in the geometry
79  // only 2 chambers are present separated by a gap.
80  // making superchamber out of the first chamber layer including the gap between chambers
81  if (detIdCh.layer() == 1){// only make superChambers when doing layer 1
82  GEMSuperChamber *gemSuperChamber = buildSuperChamber(fv, detIdCh);
83  geometry->add(gemSuperChamber);
84  }
85  GEMChamber *gemChamber = buildChamber(fv, detIdCh);
86 
87  // loop over chambers
88  // only 1 chamber
89  bool doChambers = fv.firstChild();
90  while (doChambers){
91 
92  // loop over GEMEtaPartitions
93  bool doEtaPart = fv.firstChild();
94  while (doEtaPart){
95 
96  MuonDDDNumbering mdddnum(muonConstants);
97  GEMNumberingScheme gemNum(muonConstants);
98  int rawid = gemNum.baseNumberToUnitNumber(mdddnum.geoHistoryToBaseNumber(fv.geoHistory()));
99  GEMDetId detId = GEMDetId(rawid);
100 
101  GEMEtaPartition *etaPart = buildEtaPartition(fv, detId);
102  gemChamber->add(etaPart);
103  geometry->add(etaPart);
104  doEtaPart = fv.nextSibling();
105  }
106  fv.parent();
107 
108  geometry->add(gemChamber);
109 
110  doChambers = fv.nextSibling();
111  }
112  fv.parent();
113 
114  doSuper = fv.nextSibling();
115  }
116 
117  auto& superChambers(geometry->superChambers());
118  // construct the regions, stations and rings.
119  for (int re = -1; re <= 1; re = re+2) {
120  GEMRegion* region = new GEMRegion(re);
121  for (int st=1; st<=GEMDetId::maxStationId; ++st) {
122  GEMStation* station = new GEMStation(re, st);
123  std::string sign( re==-1 ? "-" : "");
124  std::string name("GE" + sign + std::to_string(st) + "/1");
125  station->setName(name);
126  for (int ri=1; ri<=1; ++ri) {
127  GEMRing* ring = new GEMRing(re, st, ri);
128  for (unsigned sch=0; sch<superChambers.size(); ++sch){
129  GEMSuperChamber* superChamber = const_cast<GEMSuperChamber*>(superChambers.at(sch));
130  const GEMDetId detId(superChamber->id());
131  if (detId.region() != re || detId.station() != st || detId.ring() != ri) continue;
132 
133  auto ch1 = geometry->chamber(GEMDetId(detId.region(),detId.ring(),detId.station(),1,detId.chamber(),0));
134  auto ch2 = geometry->chamber(GEMDetId(detId.region(),detId.ring(),detId.station(),2,detId.chamber(),0));
135  superChamber->add(const_cast<GEMChamber*>(ch1));
136  superChamber->add(const_cast<GEMChamber*>(ch2));
137 
138  ring->add(superChamber);
139  LogDebug("GEMGeometryBuilderFromDDD") << "Adding super chamber " << detId << " to ring: "
140  << "re " << re << " st " << st << " ri " << ri << std::endl;
141  }
142  LogDebug("GEMGeometryBuilderFromDDD") << "Adding ring " << ri << " to station " << "re " << re << " st " << st << std::endl;
143  station->add(const_cast<GEMRing*>(ring));
144  geometry->add(const_cast<GEMRing*>(ring));
145  }
146  LogDebug("GEMGeometryBuilderFromDDD") << "Adding station " << st << " to region " << re << std::endl;
147  region->add(const_cast<GEMStation*>(station));
148  geometry->add(const_cast<GEMStation*>(station));
149  }
150  LogDebug("GEMGeometryBuilderFromDDD") << "Adding region " << re << " to the geometry " << std::endl;
151  geometry->add(const_cast<GEMRegion*>(region));
152  }
153 
154  return geometry;
155 }
156 
158  LogDebug("GEMGeometryBuilderFromDDD") << "buildSuperChamber "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
159 
161  std::vector<double> dpar = solid.solidA().parameters();
162 
163  double dy = dpar[0]/cm;//length is along local Y
164  double dz = dpar[3]/cm;// thickness is long local Z
165  double dx1= dpar[4]/cm;// bottom width is along local X
166  double dx2= dpar[8]/cm;// top width is along local X
167  dpar = solid.solidB().parameters();
168  dz += dpar[3]/cm;// chamber thickness
169  dz *=2; // 2 chambers in superchamber
170  dz += 2.105;// gap between chambers
171 
172  bool isOdd = detId.chamber()%2;
173  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(dx1,dx2,dy,dz), isOdd ));
174  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< dx1 << " " << dx2 << " " << dy << " " << dz <<std::endl;
175 
176  GEMSuperChamber* superChamber = new GEMSuperChamber(detId.superChamberId(), surf);
177  return superChamber;
178 }
179 
181  LogDebug("GEMGeometryBuilderFromDDD") << "buildChamber "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
182 
184  std::vector<double> dpar = solid.solidA().parameters();
185 
186  double dy = dpar[0]/cm;//length is along local Y
187  double dz = dpar[3]/cm;// thickness is long local Z
188  double dx1= dpar[4]/cm;// bottom width is along local X
189  double dx2= dpar[8]/cm;// top width is along local X
190  dpar = solid.solidB().parameters();
191  dz += dpar[3]/cm;// chamber thickness
192 
193  bool isOdd = detId.chamber()%2;
194  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(dx1,dx2,dy,dz), isOdd ));
195  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< dx1 << " " << dx2 << " " << dy << " " << dz <<std::endl;
196 
197  GEMChamber* chamber = new GEMChamber(detId.chamberId(), surf);
198  return chamber;
199 }
200 
202  LogDebug("GEMGeometryBuilderFromDDD") << "buildEtaPartition "<<fv.logicalPart().name().name() <<" "<< detId <<std::endl;
203 
204  // EtaPartition specific parameter (nstrips and npads)
205  DDValue numbOfStrips("nStrips");
206  DDValue numbOfPads("nPads");
207  std::vector<const DDsvalues_type* > specs(fv.specifics());
208  std::vector<const DDsvalues_type* >::iterator is = specs.begin();
209  double nStrips = 0., nPads = 0.;
210  for (;is != specs.end(); is++){
211  if (DDfetch( *is, numbOfStrips)) nStrips = numbOfStrips.doubles()[0];
212  if (DDfetch( *is, numbOfPads)) nPads = numbOfPads.doubles()[0];
213  }
214  LogDebug("GEMGeometryBuilderFromDDD")
215  << ((nStrips == 0. ) ? ("No nStrips found!!") : ("Number of strips: " + boost::lexical_cast<std::string>(nStrips)));
216  LogDebug("GEMGeometryBuilderFromDDD")
217  << ((nPads == 0. ) ? ("No nPads found!!") : ("Number of pads: " + boost::lexical_cast<std::string>(nPads)));
218 
219  // EtaPartition specific parameter (size)
220  std::vector<double> dpar = fv.logicalPart().solid().parameters();
221 
222  double be = dpar[4]/cm; // half bottom edge
223  double te = dpar[8]/cm; // half top edge
224  double ap = dpar[0]/cm; // half apothem
225  double ti = 0.4/cm; // half thickness
226 
227  std::vector<float> pars;
228  pars.push_back(be);
229  pars.push_back(te);
230  pars.push_back(ap);
231  pars.push_back(nStrips);
232  pars.push_back(nPads);
233 
234  bool isOdd = detId.chamber()%2;
235  RCPBoundPlane surf(boundPlane(fv, new TrapezoidalPlaneBounds(be, te, ap, ti), isOdd ));
236  std::string name = fv.logicalPart().name().name();
238 
239  LogDebug("GEMGeometryBuilderFromDDD") << "size "<< be << " " << te << " " << ap << " " << ti <<std::endl;
240  GEMEtaPartition* etaPartition = new GEMEtaPartition(detId, surf, e_p_specs);
241  return etaPartition;
242 }
243 
246  Bounds* bounds, bool isOddChamber) const {
247  // extract the position
248  const DDTranslation & trans(fv.translation());
249  const Surface::PositionType posResult(float(trans.x()/cm),
250  float(trans.y()/cm),
251  float(trans.z()/cm));
252 
253  // now the rotation
254  // DDRotationMatrix tmp = fv.rotation();
255  // === DDD uses 'active' rotations - see CLHEP user guide ===
256  // ORCA uses 'passive' rotation.
257  // 'active' and 'passive' rotations are inverse to each other
258  // DDRotationMatrix tmp = fv.rotation();
259  DDRotationMatrix rotation = fv.rotation();//REMOVED .Inverse();
260  DD3Vector x, y, z;
261  rotation.GetComponents(x,y,z);
262  // LogDebug("GEMGeometryBuilderFromDDD") << "translation: "<< fv.translation() << std::endl;
263  // LogDebug("GEMGeometryBuilderFromDDD") << "rotation : "<< fv.rotation() << std::endl;
264  // LogDebug("GEMGeometryBuilderFromDDD") << "INVERSE rotation manually: \n"
265  // << x.X() << ", " << x.Y() << ", " << x.Z() << std::endl
266  // << y.X() << ", " << y.Y() << ", " << y.Z() << std::endl
267  // << z.X() << ", " << z.Y() << ", " << z.Z() << std::endl;
268 
269  Surface::RotationType rotResult(float(x.X()),float(x.Y()),float(x.Z()),
270  float(y.X()),float(y.Y()),float(y.Z()),
271  float(z.X()),float(z.Y()),float(z.Z()));
272 
273  //Change of axes for the forward
274  Basic3DVector<float> newX(1.,0.,0.);
275  Basic3DVector<float> newY(0.,0.,1.);
276  Basic3DVector<float> newZ(0.,1.,0.);
277  // Odd chambers are inverted in gem.xml
278  if (isOddChamber) newY *= -1;
279 
280  rotResult.rotateAxes(newX, newY, newZ);
281 
282  return RCPBoundPlane( new BoundPlane( posResult, rotResult, bounds));
283 }
#define LogDebug(id)
const std::vector< double > & parameters(void) const
Give the parameters of the solid.
Definition: DDSolid.cc:157
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:137
GEMGeometry * buildGeometry(DDFilteredView &fview, const MuonDDDConstants &muonConstants)
const N & name() const
Definition: DDBase.h:78
void addFilter(const DDFilter &, DDLogOp op=DDLogOp::AND)
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:80
void add(GEMRing *ring)
Add ring to the station which takes ownership.
Definition: GEMStation.cc:26
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:557
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:75
Definition: value.py:1
virtual int baseNumberToUnitNumber(const MuonBaseNumber &)
DDSolid solidA(void) const
Definition: DDSolid.cc:552
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.
const std::string & name() const
Returns the name.
Definition: DDName.cc:90
void setCriteria(const DDValue &nameVal, DDCompOp, DDLogOp l=DDLogOp::AND, bool asString=true, bool merged=true)
Definition: DDFilter.cc:253
The DDGenericFilter is a runtime-parametrized Filter looking on DDSpecifcs.
Definition: DDFilter.h:33