CMS 3D CMS Logo

TrackerGeomBuilderFromGeometricDet.cc
Go to the documentation of this file.
20 
21 #include <cfloat>
22 #include <cassert>
23 using std::string;
24 using std::vector;
25 
26 namespace {
27  void verifyDUinTG(TrackerGeometry const& tg) {
28  int off = 0;
29  int end = 0;
30  for (int i = 1; i != 7; i++) {
31  auto det = GeomDetEnumerators::tkDetEnum[i];
32  off = tg.offsetDU(det);
33  end = tg.endsetDU(det);
34  assert(end >= off); // allow empty subdetectors. Needed for upgrade
35  for (int j = off; j != end; ++j) {
36  assert(tg.detUnits()[j]->geographicalId().subdetId() == i);
37  assert(GeomDetEnumerators::subDetGeom[tg.detUnits()[j]->subDetector()] == det);
38  assert(tg.detUnits()[j]->index() == j);
39  }
40  }
41  }
42 } // namespace
43 
45  const PTrackerParameters& ptp,
46  const TrackerTopology* tTopo) {
47  if (ptp.vpars.size() != 6) {
48  throw cms::Exception("TrackerGeomBuilderFromGeometricDet")
49  << "Tracker parameters block from XMLs called vPars is expected to have 6 entries, but has " << ptp.vpars.size()
50  << " entrie(s).";
51  }
52 
53  const int BIG_PIX_PER_ROC_X = ptp.vpars[2];
54  const int BIG_PIX_PER_ROC_Y = ptp.vpars[3];
55 
56  thePixelDetTypeMap.clear();
57  theStripDetTypeMap.clear();
58 
60  std::vector<const GeometricDet*> comp;
61  gd->deepComponents(comp);
62 
63  if (tTopo)
64  theTopo = tTopo;
65 
66  //define a vector which associate to the detid subdetector index -1 (from 0 to 5) the GeometridDet enumerator to be able to know which type of subdetector it is
67 
68  std::vector<GeometricDet::GDEnumType> gdsubdetmap(
69  6, GeometricDet::unknown); // hardcoded "6" should not be a surprise...
71 
72  LogDebug("SubDetectorGeometricDetType") << "GeometriDet enumerator values of the subdetectors";
73  for (unsigned int i = 0; i < subdetgd.size(); ++i) {
74  assert(subdetgd[i]->geographicalId().subdetId() > 0 && subdetgd[i]->geographicalId().subdetId() < 7);
75  gdsubdetmap[subdetgd[i]->geographicalId().subdetId() - 1] = subdetgd[i]->type();
76  LogTrace("SubDetectorGeometricDetType")
77  << "subdet " << i << " type " << subdetgd[i]->type() << " detid " << subdetgd[i]->geographicalId().rawId()
78  << " subdetid " << subdetgd[i]->geographicalId().subdetId();
79  }
80 
81  std::vector<const GeometricDet*> dets[6];
82  std::vector<const GeometricDet*>& pixB = dets[0];
83  pixB.reserve(comp.size());
84  std::vector<const GeometricDet*>& pixF = dets[1];
85  pixF.reserve(comp.size());
86  std::vector<const GeometricDet*>& tib = dets[2];
87  tib.reserve(comp.size());
88  std::vector<const GeometricDet*>& tid = dets[3];
89  tid.reserve(comp.size());
90  std::vector<const GeometricDet*>& tob = dets[4];
91  tob.reserve(comp.size());
92  std::vector<const GeometricDet*>& tec = dets[5];
93  tec.reserve(comp.size());
94 
95  for (auto& i : comp)
96  dets[i->geographicalId().subdetId() - 1].emplace_back(i);
97 
98  //loop on all the six elements of dets and firstly check if they are from pixel-like detector and call buildPixel, then loop again and check if they are strip and call buildSilicon. "unknown" can be filled either way but the vector of GeometricDet must be empty !!
99  // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
100 
101  // now building the Pixel-like subdetectors
102  for (unsigned int i = 0; i < 6; ++i) {
103  if (gdsubdetmap[i] == GeometricDet::PixelBarrel)
104  buildPixel(
105  dets[i], tracker, GeomDetEnumerators::SubDetector::PixelBarrel, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
106  if (gdsubdetmap[i] == GeometricDet::PixelPhase1Barrel)
107  buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P1PXB, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
108  // Phase2 case
109  if (gdsubdetmap[i] == GeometricDet::PixelPhase2Barrel)
110  buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2PXB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
111  //
112  if (gdsubdetmap[i] == GeometricDet::PixelEndCap)
113  buildPixel(
114  dets[i], tracker, GeomDetEnumerators::SubDetector::PixelEndcap, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
115  if (gdsubdetmap[i] == GeometricDet::PixelPhase1EndCap)
116  buildPixel(
117  dets[i], tracker, GeomDetEnumerators::SubDetector::P1PXEC, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
118  if (gdsubdetmap[i] == GeometricDet::PixelPhase2EndCap)
119  buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2PXEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
120  if (gdsubdetmap[i] == GeometricDet::OTPhase2Barrel)
121  buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2OTB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
122  if (gdsubdetmap[i] == GeometricDet::OTPhase2EndCap)
123  buildPixel(dets[i], tracker, GeomDetEnumerators::SubDetector::P2OTEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
124  }
125  //now building Strips
126  for (unsigned int i = 0; i < 6; ++i) {
127  if (gdsubdetmap[i] == GeometricDet::TIB)
129  if (gdsubdetmap[i] == GeometricDet::TID)
131  if (gdsubdetmap[i] == GeometricDet::TOB)
133  if (gdsubdetmap[i] == GeometricDet::TEC)
135  }
136  // and finally the "empty" subdetectors (maybe it is not needed)
137  for (unsigned int i = 0; i < 6; ++i) {
138  if (gdsubdetmap[i] == GeometricDet::unknown) {
139  if (!dets[i].empty())
140  throw cms::Exception("NotEmptyUnknownSubDet")
141  << "Subdetector " << i + 1 << " is unknown but it is not empty: " << dets[i].size();
142  buildSilicon(
143  dets[i], tracker, GeomDetEnumerators::tkDetEnum[i + 1], "barrel"); // "barrel" is used but it is irrelevant
144  }
145  }
146  buildGeomDet(tracker); //"GeomDet"
147 
148  verifyDUinTG(*tracker);
149 
150  return tracker;
151 }
152 
154  std::vector<const GeometricDet*> const& gdv,
157  bool upgradeGeometry,
158  int BIG_PIX_PER_ROC_X, // in x direction, rows. BIG_PIX_PER_ROC_X = 0 for SLHC
159  int BIG_PIX_PER_ROC_Y) // in y direction, cols. BIG_PIX_PER_ROC_Y = 0 for SLHC
160 {
161  LogDebug("BuildingGeomDetUnits") << " Pixel type. Size of vector: " << gdv.size()
162  << " GeomDetType subdetector: " << det
163  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
164  << " big pix per ROC x: " << BIG_PIX_PER_ROC_X << " y: " << BIG_PIX_PER_ROC_Y
165  << " is upgrade: " << upgradeGeometry;
166 
167  tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
168 
169  for (auto const& i : gdv) {
170  std::string const& detName = i->name();
171  if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
172  std::unique_ptr<const Bounds> bounds(i->bounds());
174  upgradeGeometry,
175  (int)i->pixROCRows(),
176  (int)i->pixROCCols(),
177  BIG_PIX_PER_ROC_X,
178  BIG_PIX_PER_ROC_Y,
179  (int)i->pixROCx(),
180  (int)i->pixROCy());
181 
182  thePixelDetTypeMap[detName] = new PixelGeomDetType(t, detName, det);
183  tracker->addType(thePixelDetTypeMap[detName]);
184  }
185 
187  GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane), thePixelDetTypeMap[detName], i->geographicalId());
188 
189  tracker->addDetUnit(temp);
190  tracker->addDetUnitId(i->geographicalId());
191  }
192  tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
193 }
194 
195 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const& gdv,
198  const std::string& part) {
199  LogDebug("BuildingGeomDetUnits") << " Strip type. Size of vector: " << gdv.size()
200  << " GeomDetType subdetector: " << det
201  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det] << " part "
202  << part;
203 
204  tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
205 
206  for (auto const& i : gdv) {
207  std::string const& detName = i->name();
208  if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
209  std::unique_ptr<const Bounds> bounds(i->bounds());
210  StripTopology* t = StripTopologyBuilder().build(bounds.get(), i->siliconAPVNum(), part);
211  theStripDetTypeMap[detName] = new StripGeomDetType(t, detName, det, i->stereo());
212  tracker->addType(theStripDetTypeMap[detName]);
213  }
214 
215  double scale = (theTopo->partnerDetId(i->geographicalId())) ? 0.5 : 1.0;
216 
218  GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName], i->geographicalId());
219 
220  tracker->addDetUnit(temp);
221  tracker->addDetUnitId(i->geographicalId());
222  }
223  tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
224 }
225 
227  PlaneBuilderForGluedDet gluedplaneBuilder;
228  auto const& gdu = tracker->detUnits();
229  auto const& gduId = tracker->detUnitIds();
230 
231  for (u_int32_t i = 0; i < gdu.size(); i++) {
232  tracker->addDet(gdu[i]);
233  tracker->addDetId(gduId[i]);
234  string gduTypeName = gdu[i]->type().name();
235 
236  //this step is time consuming >> TO FIX with a MAP?
237  if ((gduTypeName.find("Ster") != std::string::npos || gduTypeName.find("Lower") != std::string::npos ||
238  gduTypeName.find("One") != std::string::npos) &&
239  (theTopo->glued(gduId[i]) != 0 || theTopo->stack(gduId[i]) != 0 || theTopo->doubleSensor(gduId[i]))) {
240  int partner_pos = -1;
241  for (u_int32_t jj = 0; jj < gduId.size(); jj++) {
242  if (theTopo->partnerDetId(gduId[i]) == gduId[jj]) {
243  partner_pos = jj;
244  break;
245  }
246  }
247  if (partner_pos == -1) {
248  throw cms::Exception("Configuration") << "Module Type is Stereo or Lower but no partner detector found \n"
249  << "There is a problem on Tracker geometry configuration\n";
250  }
251 
252  const GeomDetUnit* dus = gdu[i];
253  const GeomDetUnit* dum = gdu[partner_pos];
254  std::vector<const GeomDetUnit*> composed(2);
255  composed[0] = dum;
256  composed[1] = dus;
257  DetId composedDetId;
258  if (gduTypeName.find("Ster") != std::string::npos) {
259  PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
260  composedDetId = theTopo->glued(gduId[i]);
261  GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane), dum, dus, composedDetId);
262  tracker->addDet((GeomDet*)gluedDet);
263  tracker->addDetId(composedDetId);
264 
265  } else if (gduTypeName.find("Lower") != std::string::npos) {
266  //The plane is *not* built in the middle, but on the Lower surface
267  Plane* plane = new Plane(dus->surface());
268  composedDetId = theTopo->stack(gduId[i]);
269  StackGeomDet* stackDet = new StackGeomDet(&(*plane), dus, dum, composedDetId);
270  tracker->addDet((GeomDet*)stackDet);
271  tracker->addDetId(composedDetId);
272  } else if (gduTypeName.find("One") != std::string::npos) {
273  //The plane is *not* built in the middle, but on the First surface
274  Plane* plane = new Plane(dus->surface());
275  composedDetId = theTopo->doubleSensor(gduId[i]);
276  DoubleSensGeomDet* doubleSensDet = new DoubleSensGeomDet(&(*plane), dus, dum, composedDetId);
277  tracker->addDet((GeomDet*)doubleSensDet);
278  tracker->addDetId(composedDetId);
279  }
280  }
281  }
282 }
283 
285  const GeometricDet* gd, double scale) const {
286  PlaneBuilderFromGeometricDet planeBuilder;
287  PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
288  //
289  // set medium properties (if defined)
290  //
291  plane->setMediumProperties(MediumProperties(gd->radLength() * scale, gd->xi() * scale));
292 
293  return plane;
294 }
std::vector< int > vpars
PlaneBuilderFromGeometricDet::ResultType buildPlaneWithMaterial(const GeometricDet *gd, double scaleFactor=1.) const
PixelTopology * build(const Bounds *bounds, bool upgradeGeometry, int ROWS_PER_ROC, int COLS_PER_ROC, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y, int ROCS_X, int ROCS_Y)
constexpr SubDetector subDetGeom[21]
std::map< std::string, const PixelGeomDetType * > thePixelDetTypeMap
unsigned int offsetDU(SubDetector sid) const
std::map< std::string, const StripGeomDetType * > theStripDetTypeMap
ResultType plane(const GeometricDet *gd) const
TrackerGeometry * build(const GeometricDet *gd, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
assert(be >=bs)
Definition: Plane.h:16
#define LogTrace(id)
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:154
uint32_t doubleSensor(const DetId &id) const
ResultType plane(const std::vector< const GeomDetUnit *> &dets) const
uint32_t stack(const DetId &id) const
unsigned int endsetDU(SubDetector sid) const
DetId partnerDetId(const DetId &id) const
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:34
double xi() const
Definition: GeometricDet.h:130
uint32_t glued(const DetId &id) const
Definition: DetId.h:17
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
double radLength() const
Definition: GeometricDet.h:129
part
Definition: HCALResponse.h:20
ConstGeometricDetContainer deepComponents() const
void buildSilicon(std::vector< const GeometricDet *> const &, TrackerGeometry *, GeomDetType::SubDetector det, const std::string &part)
void buildPixel(std::vector< const GeometricDet *> const &, TrackerGeometry *, GeomDetType::SubDetector det, bool upgradeGeometry, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y)
constexpr SubDetector tkDetEnum[8]
StripTopology * build(const Bounds *, double, const std::string &)
#define LogDebug(id)