CMS 3D CMS Logo

GEMGeometryBuilderFromCondDB.cc
Go to the documentation of this file.
1 
8 
11 
12 #include "CLHEP/Units/GlobalSystemOfUnits.h"
13 
14 #include <algorithm>
15 
17 { }
18 
20 { }
21 
22 void
23 GEMGeometryBuilderFromCondDB::build(const std::shared_ptr<GEMGeometry>& theGeometry,
24  const RecoIdealGeometry& rgeo )
25 {
26  const std::vector<DetId>& detids( rgeo.detIds());
27  std::unordered_map<uint32_t, GEMSuperChamber*> superChambers;
28  std::unordered_map<uint32_t, GEMChamber*> chambers;
29  std::unordered_map<uint32_t, GEMEtaPartition*> partitions;
30 
31  for( unsigned int id = 0; id < detids.size(); ++id ){
32  GEMDetId gemid( detids[id] );
33  LogDebug("GEMGeometryBuilderFromDDD") <<"GEMGeometryBuilderFromDDD adding " << gemid << std::endl;
34  if (gemid.roll() == 0){
35  if (gemid.layer() == 0){
36  GEMSuperChamber* gsc = buildSuperChamber( rgeo, id, gemid );
37  superChambers.emplace(gemid.rawId(), gsc);
38  }
39  else {
40  GEMChamber* gch = buildChamber( rgeo, id, gemid );
41  chambers.emplace(gemid.rawId(), gch);
42  }
43  }
44  else {
45  GEMEtaPartition* gep = buildEtaPartition( rgeo, id, gemid );
46  partitions.emplace(gemid.rawId(), gep);
47  }
48  }
49 
51  // TEMP - for backward compatability with old geometry
52  // no superchambers or chambers in old geometry, using etpartitions
53  if (superChambers.empty()){
54  for( unsigned int id = 0; id < detids.size(); ++id ){
55  GEMDetId gemid( detids[id] );
56  if (gemid.roll() == 1){
57  GEMChamber* gch = buildChamber( rgeo, id, gemid.chamberId() );
58  chambers.emplace(gemid.chamberId().rawId(), gch);
59  if (gemid.layer() == 1){
60  GEMSuperChamber* gsc = buildSuperChamber( rgeo, id, gemid.superChamberId());
61  superChambers.emplace(gemid.superChamberId().rawId(), gsc);
62  }
63  }
64  }
65  }
67 
68  // construct the regions, stations and rings.
69  for (int re = -1; re <= 1; re = re+2){
70  GEMRegion* region = new GEMRegion(re);
71 
72  for (int st=0; st<=GEMDetId::maxStationId; ++st){
73  GEMStation* station = new GEMStation(re, st);
74  std::string sign( re==-1 ? "-" : "");
75  std::string name("GE" + sign + std::to_string(st) + "/1");
76  station->setName(name);
77 
78  for (int ri=1; ri<=1; ++ri) {
79  GEMRing* ring = new GEMRing(re, st, ri);
80 
81  for (auto sch : superChambers){
82  auto superChamber = sch.second;
83  const GEMDetId scId(superChamber->id());
84  if (scId.region() != re || scId.station() != st || scId.ring() != ri) continue;
85  int ch = scId.chamber();
86 
87  for (int ly=1; ly<=GEMDetId::maxLayerId; ++ly) {
88  const GEMDetId chId(re,ri,st,ly,ch,0);
89  auto chamberIt = chambers.find(chId.rawId());
90  if (chamberIt == chambers.end()) continue;
91  auto chamber = chamberIt->second;
92 
93  for (int roll=1; roll<=GEMDetId::maxRollId; ++roll) {
94  const GEMDetId rollId(re,ri,st,ly,ch,roll);
95  auto gepIt = partitions.find(rollId.rawId());
96  if (gepIt == partitions.end()) continue;
97  auto gep = gepIt->second;
98 
99  chamber->add(gep);
100  theGeometry->add(gep);
101  }
102 
103  superChamber->add(chamber);
104  theGeometry->add(chamber);
105  }
106 
107  LogDebug("GEMGeometryBuilderFromDDD") << "Adding super chamber " << scId << " to ring: " << std::endl;
108  ring->add(superChamber);
109  theGeometry->add(superChamber);
110  } // end superChambers
111 
112  if (ring->nSuperChambers()){
113  LogDebug("GEMGeometryBuilderFromDDD") << "Adding ring " << ri << " to station " << "re " << re << " st " << st << std::endl;
114  station->add(ring);
115  theGeometry->add(ring);
116  }
117  else {
118  delete ring;
119  }
120  }// end ring
121 
122  if (station->nRings()){
123  LogDebug("GEMGeometryBuilderFromDDD") << "Adding station " << st << " to region " << re << std::endl;
124  region->add(station);
125  theGeometry->add(station);
126  }
127  else {
128  delete station;
129  }
130  }// end station
131 
132  LogDebug("GEMGeometryBuilderFromDDD") << "Adding region " << re << " to the geometry " << std::endl;
133  theGeometry->add(region);
134  }
135 
136 }
137 
139 {
140  LogDebug("GEMGeometryBuilderFromCondDB") << "buildSuperChamber "<< detId <<std::endl;
141 
142  RCPBoundPlane surf(boundPlane(rgeo, gid, detId ));
143 
144  GEMSuperChamber* superChamber = new GEMSuperChamber(detId, surf);
145  return superChamber;
146 }
147 
149 {
150  LogDebug("GEMGeometryBuilderFromCondDB") << "buildChamber "<< detId <<std::endl;
151 
152  RCPBoundPlane surf(boundPlane(rgeo, gid, detId ));
153 
154  GEMChamber* chamber = new GEMChamber(detId, surf);
155  return chamber;
156 }
157 
159 {
160  std::vector<std::string>::const_iterator strStart = rgeo.strStart( gid );
161  std::string name = *( strStart );
162  LogDebug("GEMGeometryBuilderFromCondDB") << "buildEtaPartition "<< name<<" "<< detId <<std::endl;
163 
164  std::vector<double>::const_iterator shapeStart = rgeo.shapeStart( gid );
165  float be = *(shapeStart+0)/cm;
166  float te = *(shapeStart+1)/cm;
167  float ap = *(shapeStart+2)/cm;
168  float ti = *(shapeStart+3)/cm;
169  float nstrip = *(shapeStart+4);
170  float npad = *(shapeStart+5);
171 
172  std::vector<float> pars;
173  pars.emplace_back(be);
174  pars.emplace_back(te);
175  pars.emplace_back(ap);
176  pars.emplace_back(nstrip);
177  pars.emplace_back(npad);
178 
179  RCPBoundPlane surf(boundPlane(rgeo, gid, detId ));
181 
182  LogDebug("GEMGeometryBuilderFromCondDB") << "size "<< be << " " << te << " " << ap << " " << ti <<std::endl;
183  GEMEtaPartition* etaPartition = new GEMEtaPartition(detId, surf, e_p_specs);
184  return etaPartition;
185 }
186 
188 GEMGeometryBuilderFromCondDB::boundPlane(const RecoIdealGeometry& rgeo, unsigned int gid, GEMDetId detId) const
189 {
190  std::vector<double>::const_iterator shapeStart = rgeo.shapeStart( gid );
191  float be = *(shapeStart+0)/cm;
192  float te = *(shapeStart+1)/cm;
193  float ap = *(shapeStart+2)/cm;
194  float ti = *(shapeStart+3)/cm;
195  Bounds* bounds = new TrapezoidalPlaneBounds( be, te, ap, ti );
196 
197  std::vector<double>::const_iterator tranStart = rgeo.tranStart( gid );
198  Surface::PositionType posResult(*(tranStart)/cm, *(tranStart+1)/cm, *(tranStart+2)/cm );
199 
200  std::vector<double>::const_iterator rotStart = rgeo.rotStart( gid );
201  Surface::RotationType rotResult(*(rotStart+0), *(rotStart+1), *(rotStart+2),
202  *(rotStart+3), *(rotStart+4), *(rotStart+5),
203  *(rotStart+6), *(rotStart+7), *(rotStart+8));
204 
205  //Change of axes for the forward
206  Basic3DVector<float> newX(1.,0.,0.);
207  Basic3DVector<float> newY(0.,0.,1.);
208  Basic3DVector<float> newZ(0.,1.,0.);
209  // Odd chambers are inverted in gem.xml
210  bool isOdd = detId.chamber()%2;
211  // all me0 chambers are inverted
212  if (detId.station() == 0) isOdd = true;
213  if (isOdd) newY *= -1;
214 
215  rotResult.rotateAxes(newX, newY, newZ);
216 
217  return RCPBoundPlane( new BoundPlane( posResult, rotResult, bounds));
218 }
#define LogDebug(id)
void build(const std::shared_ptr< GEMGeometry > &theGeometry, const RecoIdealGeometry &rgeo)
int nSuperChambers() const
Return numbers of chambers.
Definition: GEMRing.cc:57
Plane BoundPlane
Definition: Plane.h:95
std::vector< double >::const_iterator rotStart(size_t ind) const
int roll() const
Definition: GEMDetId.h:80
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
static const int maxRollId
Definition: GEMDetId.h:111
GEMSuperChamber * buildSuperChamber(const RecoIdealGeometry &rgeo, unsigned int gid, GEMDetId detId) const
int chamber() const
Chamber id: it identifies a chamber in a ring it goes from 1 to 36.
Definition: GEMDetId.h:74
GEMDetId superChamberId() const
Return the corresponding superChamberId.
Definition: GEMDetId.h:90
ReferenceCountingPointer< BoundPlane > RCPBoundPlane
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
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
static const int maxLayerId
Definition: GEMDetId.h:108
std::vector< std::string >::const_iterator strStart(size_t ind) const
GEMDetId chamberId() const
Return the corresponding ChamberId.
Definition: GEMDetId.h:85
GEMEtaPartition * buildEtaPartition(const RecoIdealGeometry &rgeo, unsigned int gid, GEMDetId detId) const
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
int station() const
Station id : the station is the pair of chambers at same disk.
Definition: GEMDetId.h:64
std::vector< double >::const_iterator tranStart(size_t ind) const
static const int maxStationId
Definition: GEMDetId.h:101
void setName(std::string name)
Set the station name.
Definition: GEMStation.cc:77
GEMChamber * buildChamber(const RecoIdealGeometry &rgeo, unsigned int gid, GEMDetId detId) const
const std::vector< DetId > & detIds() const
RCPBoundPlane boundPlane(const RecoIdealGeometry &rgeo, unsigned int gid, GEMDetId detId) const
std::vector< double >::const_iterator shapeStart(size_t ind) const
int nRings() const
Return numbers of rings for this station.
Definition: GEMStation.cc:73
void add(GEMStation *st)
Add station to the region which takes ownership.
Definition: GEMRegion.cc:25
Definition: Bounds.h:22
static char chambers[264][20]
Definition: ReadPGInfo.cc:243