CMS 3D CMS Logo

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