CMS 3D CMS Logo

RPCGeometryBuilderFromCondDB.cc
Go to the documentation of this file.
1 
8 
12 
16 
20 
22 
23 #include "CLHEP/Units/GlobalSystemOfUnits.h"
24 
25 #include <iostream>
26 #include <algorithm>
27 
29  theComp11Flag(comp11)
30 { }
31 
33 { }
34 
36 {
37  const std::vector<DetId>& detids(rgeo.detIds());
39 
40  for (unsigned int id=0; id<detids.size(); ++id){
41  RPCDetId rpcid(detids[id]);
42  RPCDetId chid(rpcid.region(),rpcid.ring(),rpcid.station(),
43  rpcid.sector(),rpcid.layer(),rpcid.subsector(),0);
44 
45  const auto tranStart = rgeo.tranStart(id);
46  const auto shapeStart = rgeo.shapeStart(id);
47  const auto rotStart = rgeo.rotStart(id);
48  const std::string& name = *rgeo.strStart(id);
49 
50  Surface::PositionType pos(*(tranStart)/cm,*(tranStart+1)/cm, *(tranStart+2)/cm);
51  // CLHEP way
52  Surface::RotationType rot(*(rotStart+0),*(rotStart+1),*(rotStart+2),
53  *(rotStart+3),*(rotStart+4),*(rotStart+5),
54  *(rotStart+6),*(rotStart+7),*(rotStart+8));
55 
56  RPCRollSpecs* rollspecs= nullptr;
57  Bounds* bounds = nullptr;
58 
59  // if (dpar.size()==4){
60  if ( rgeo.shapeEnd(id) - shapeStart == 4 ) {
61  const float width = *(shapeStart+0)/cm;
62  const float length = *(shapeStart+1)/cm;
63  const float thickness = *(shapeStart+2)/cm;
64  const float nstrip = *(shapeStart+3);
65  //RectangularPlaneBounds*
66  bounds = new RectangularPlaneBounds(width,length,thickness);
67  const std::vector<float> pars = {width, length, nstrip};
68 
69  if (!theComp11Flag) {
70  //Correction of the orientation to get the REAL geometry.
71  //Change of axes for the +z part only.
72  //Including the 0 whell
73  if ( *(tranStart+2) > -1500.) { //tran[2] >-1500. ){
74  Basic3DVector<float> newX(-1.,0.,0.);
75  Basic3DVector<float> newY(0.,-1.,0.);
76  Basic3DVector<float> newZ(0.,0.,1.);
77  rot.rotateAxes (newX, newY,newZ);
78  }
79  }
80 
81  rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCBarrel,name,pars);
82 
83  }
84  else {
85  const float be = *(shapeStart+0)/cm;
86  const float te = *(shapeStart+1)/cm;
87  const float ap = *(shapeStart+2)/cm;
88  const float ti = *(shapeStart+3)/cm;
89  const float nstrip = *(shapeStart+4);
90  // TrapezoidalPlaneBounds*
91  bounds = new TrapezoidalPlaneBounds(be,te,ap,ti);
92  const std::vector<float> pars = {be /*b/2*/, te /*B/2*/, ap /*h/2*/, nstrip};
93 
94  rollspecs = new RPCRollSpecs(GeomDetEnumerators::RPCEndcap,name,pars);
95 
96  //Change of axes for the forward
97  Basic3DVector<float> newX(1.,0.,0.);
98  Basic3DVector<float> newY(0.,0.,1.);
99  // if (tran[2] > 0. )
100  newY *= -1;
101  Basic3DVector<float> newZ(0.,1.,0.);
102  rot.rotateAxes (newX, newY,newZ);
103  }
104 
105  BoundPlane* bp = new BoundPlane(pos,rot,bounds);
107  RPCRoll* r = new RPCRoll(rpcid,surf,rollspecs);
108  geometry->add(r);
109 
110  auto rls = chids.find(chid);
111  if ( rls == chids.end() ) rls = chids.insert(std::make_pair(chid, std::list<RPCRoll*>())).first;
112  rls->second.emplace_back(r);
113  }
114 
115  // Create the RPCChambers and store them on the Geometry
116  for (auto & ich : chids) {
117  const RPCDetId& chid = ich.first;
118  const auto& rls = ich.second;
119 
120  // compute the overall boundplane.
121  BoundPlane* bp=nullptr;
122  if ( !rls.empty() ) {
123  // First set the baseline plane to calculate relative poisions
124  const auto& refSurf = (*rls.begin())->surface();
125  if ( chid.region() == 0 ) {
126  float corners[6] = {0,0,0,0,0,0};
127  for ( auto rl : rls ) {
128  const double h2 = rl->surface().bounds().length()/2;
129  const double w2 = rl->surface().bounds().width()/2;
130  const auto x1y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-w2,-h2,0)));
131  const auto x2y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+w2,+h2,0)));
132  corners[0] = std::min(corners[0], x1y1AtRef.x());
133  corners[1] = std::min(corners[1], x1y1AtRef.y());
134  corners[2] = std::max(corners[2], x2y2AtRef.x());
135  corners[3] = std::max(corners[3], x2y2AtRef.y());
136 
137  corners[4] = std::min(corners[4], x1y1AtRef.z());
138  corners[5] = std::max(corners[5], x1y1AtRef.z());
139  }
140  const LocalPoint lpOfCentre((corners[0]+corners[2])/2, (corners[1]+corners[3])/2, 0);
141  const auto gpOfCentre = refSurf.toGlobal(lpOfCentre);
142  auto bounds = new RectangularPlaneBounds((corners[2]-corners[0])/2, (corners[3]-corners[1])/2, (corners[5]-corners[4])+0.5);
143  bp = new BoundPlane(gpOfCentre, refSurf.rotation(), bounds);
144  }
145  else {
146  float cornersLo[3] = {0,0,0}, cornersHi[3] = {0,0,0};
147  float cornersZ[2] = {0,0};
148  for ( auto rl : rls ) {
149  const double h2 = rl->surface().bounds().length()/2;
150  const double w2 = rl->surface().bounds().width()/2;
151  const auto& topo = dynamic_cast<const TrapezoidalStripTopology&>(rl->specificTopology());
152  const double r = topo.radius();
153  const double wAtLo = w2/r*(r-h2); // tan(theta/2) = (w/2)/r = x/(r-h/2)
154  const double wAtHi = w2/r*(r+h2);
155 
156  const auto x1y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-wAtLo, -h2, 0)));
157  const auto x2y1AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+wAtLo, -h2, 0)));
158  const auto x1y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(-wAtHi, +h2, 0)));
159  const auto x2y2AtRef = refSurf.toLocal(rl->toGlobal(LocalPoint(+wAtHi, +h2, 0)));
160 
161  cornersLo[0] = std::min(cornersLo[0], x1y1AtRef.x());
162  cornersLo[1] = std::max(cornersLo[1], x2y1AtRef.x());
163  cornersLo[2] = std::min(cornersLo[2], x1y1AtRef.y());
164 
165  cornersHi[0] = std::min(cornersHi[0], x1y2AtRef.x());
166  cornersHi[1] = std::max(cornersHi[1], x2y2AtRef.x());
167  cornersHi[2] = std::max(cornersHi[2], x1y2AtRef.y());
168 
169  cornersZ[0] = std::min(cornersZ[0], x1y1AtRef.z());
170  cornersZ[1] = std::max(cornersZ[1], x1y1AtRef.z());
171  }
172  const LocalPoint lpOfCentre((cornersHi[0]+cornersHi[1])/2, (cornersLo[2]+cornersHi[2])/2, 0);
173  const auto gpOfCentre = refSurf.toGlobal(lpOfCentre);
174  auto bounds = new TrapezoidalPlaneBounds((cornersLo[1]-cornersLo[0])/2, (cornersHi[1]-cornersHi[0])/2, (cornersHi[2]-cornersLo[2])/2, (cornersZ[1]-cornersZ[0])+0.5);
175  bp = new BoundPlane(gpOfCentre, refSurf.rotation(), bounds);
176  }
177  }
178 
180  // Create the chamber
181  RPCChamber* ch = new RPCChamber (chid, surf);
182  // Add the rolls to rhe chamber
183  for(auto rl : rls ) ch->add(rl);
184  // Add the chamber to the geometry
185  geometry->add(ch);
186 
187  }
188  return geometry;
189 }
190 
void add(RPCRoll *rl)
Add Roll to the chamber which takes ownership.
Definition: RPCChamber.cc:48
virtual float length() const =0
RPCGeometry * build(const RecoIdealGeometry &rgeo)
common ppss p3p6s2 common epss epspn46 common const1 w2
Definition: inclppp.h:1
std::map< RPCDetId, std::list< RPCRoll * > > chids
Plane BoundPlane
Definition: Plane.h:95
std::vector< double >::const_iterator rotStart(size_t ind) const
const Bounds & bounds() const
Definition: Surface.h:120
TkRotation & rotateAxes(const Basic3DVector< T > &newX, const Basic3DVector< T > &newY, const Basic3DVector< T > &newZ)
std::vector< std::string >::const_iterator strStart(size_t ind) const
int ring() const
Definition: RPCDetId.h:72
std::vector< double >::const_iterator tranStart(size_t ind) const
T min(T a, T b)
Definition: MathUtil.h:58
const std::vector< DetId > & detIds() const
int layer() const
Definition: RPCDetId.h:108
int sector() const
Sector id: the group of chambers at same phi (and increasing r)
Definition: RPCDetId.h:102
std::vector< double >::const_iterator shapeEnd(size_t ind) const
ESHandle< TrackerGeometry > geometry
int subsector() const
SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel...
Definition: RPCDetId.h:114
std::vector< double >::const_iterator shapeStart(size_t ind) const
Definition: Bounds.h:22
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96