CMS 3D CMS Logo

TrackerGeomBuilderFromGeometricDet.cc
Go to the documentation of this file.
22 
23 #include <cfloat>
24 #include <cassert>
25 using std::string;
26 using std::vector;
27 
28 namespace {
29  void verifyDUinTG(TrackerGeometry const& tg) {
30  int off = 0;
31  int end = 0;
32  for (int i = 1; i != 7; i++) {
33  auto det = GeomDetEnumerators::tkDetEnum[i];
34  off = tg.offsetDU(det);
35  end = tg.endsetDU(det);
36  assert(end >= off); // allow empty subdetectors. Needed for upgrade
37  for (int j = off; j != end; ++j) {
38  assert(tg.detUnits()[j]->geographicalId().subdetId() == i);
39  assert(GeomDetEnumerators::subDetGeom[tg.detUnits()[j]->subDetector()] == det);
40  assert(tg.detUnits()[j]->index() == j);
41  }
42  }
43  }
44 } // namespace
45 
48  const PTrackerParameters& ptp,
49  const TrackerTopology* tTopo) {
50  if (ptp.vpars.size() != 6) {
51  throw cms::Exception("TrackerGeomBuilderFromGeometricDet")
52  << "Tracker parameters block from XMLs called vPars is expected to have 6 entries, but has " << ptp.vpars.size()
53  << " entrie(s).";
54  }
55 
56  // phase-0, phase-1; BIG_PIX_PER_ROC from trackerParameters.xml
57  // phase-2: BIG_PIX_PER_ROC from pixelStructureTopology.xml (redefined later in buildPixel() )
58  const int BIG_PIX_PER_ROC_X = ptp.vpars[2];
59  const int BIG_PIX_PER_ROC_Y = ptp.vpars[3];
60 
61  thePixelDetTypeMap.clear();
62  theStripDetTypeMap.clear();
63 
65  std::vector<const GeometricDet*> comp;
66  gd->deepComponents(comp);
67 
68  if (tTopo)
69  theTopo = tTopo;
70 
71  //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
72 
73  std::vector<GeometricDet::GDEnumType> gdsubdetmap(
74  6, GeometricDet::unknown); // hardcoded "6" should not be a surprise...
76 
77  LogDebug("SubDetectorGeometricDetType") << "GeometriDet enumerator values of the subdetectors";
78  for (unsigned int i = 0; i < subdetgd.size(); ++i) {
79  assert(subdetgd[i]->geographicalId().subdetId() > 0 && subdetgd[i]->geographicalId().subdetId() < 7);
80  gdsubdetmap[subdetgd[i]->geographicalId().subdetId() - 1] = subdetgd[i]->type();
81  LogTrace("SubDetectorGeometricDetType")
82  << "subdet " << i << " type " << subdetgd[i]->type() << " detid " << subdetgd[i]->geographicalId().rawId()
83  << " subdetid " << subdetgd[i]->geographicalId().subdetId();
84  }
85 
86  std::vector<const GeometricDet*> dets[6];
87  std::vector<const GeometricDet*>& pixB = dets[0];
88  pixB.reserve(comp.size());
89  std::vector<const GeometricDet*>& pixF = dets[1];
90  pixF.reserve(comp.size());
91  std::vector<const GeometricDet*>& tib = dets[2];
92  tib.reserve(comp.size());
93  std::vector<const GeometricDet*>& tid = dets[3];
94  tid.reserve(comp.size());
95  std::vector<const GeometricDet*>& tob = dets[4];
96  tob.reserve(comp.size());
97  std::vector<const GeometricDet*>& tec = dets[5];
98  tec.reserve(comp.size());
99 
100  for (auto& i : comp)
101  dets[i->geographicalId().subdetId() - 1].emplace_back(i);
102 
103  //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 !!
104  // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
105 
106  // now building the Pixel-like subdetectors
107  for (unsigned int i = 0; i < 6; ++i) {
108  if (gdsubdetmap[i] == GeometricDet::PixelBarrel)
109  buildPixel(
110  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::PixelBarrel, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
111  if (gdsubdetmap[i] == GeometricDet::PixelPhase1Barrel)
112  buildPixel(
113  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P1PXB, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
114  if (gdsubdetmap[i] == GeometricDet::PixelEndCap)
115  buildPixel(
116  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::PixelEndcap, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
117  if (gdsubdetmap[i] == GeometricDet::PixelPhase1EndCap)
118  buildPixel(
119  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P1PXEC, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
120  // Phase2 case
121  if (gdsubdetmap[i] == GeometricDet::PixelPhase2Barrel)
123  if (gdsubdetmap[i] == GeometricDet::PixelPhase2EndCap)
125  if (gdsubdetmap[i] == GeometricDet::OTPhase2Barrel)
127  if (gdsubdetmap[i] == GeometricDet::OTPhase2EndCap)
129  }
130  //now building Strips
131  for (unsigned int i = 0; i < 6; ++i) {
132  if (gdsubdetmap[i] == GeometricDet::TIB)
134  if (gdsubdetmap[i] == GeometricDet::TID)
136  if (gdsubdetmap[i] == GeometricDet::TOB)
138  if (gdsubdetmap[i] == GeometricDet::TEC)
140  }
141  // and finally the "empty" subdetectors (maybe it is not needed)
142  for (unsigned int i = 0; i < 6; ++i) {
143  if (gdsubdetmap[i] == GeometricDet::unknown) {
144  if (!dets[i].empty())
145  throw cms::Exception("NotEmptyUnknownSubDet")
146  << "Subdetector " << i + 1 << " is unknown but it is not empty: " << dets[i].size();
147  buildSilicon(
148  dets[i], tracker, GeomDetEnumerators::tkDetEnum[i + 1], "barrel"); // "barrel" is used but it is irrelevant
149  }
150  }
151  buildGeomDet(tracker); //"GeomDet"
152 
153  verifyDUinTG(*tracker);
154 
155  return tracker;
156 }
157 
158 void TrackerGeomBuilderFromGeometricDet::buildPixel(std::vector<const GeometricDet*> const& gdv,
159  const PTrackerAdditionalParametersPerDet* const& ptitp,
162  int BIG_PIX_PER_ROC_X, // in x direction, rows.
163  int BIG_PIX_PER_ROC_Y) // in y direction, cols.
164 {
165  LogDebug("BuildingGeomDetUnits") << " Pixel type. Size of vector: " << gdv.size()
166  << " GeomDetType subdetector: " << det
167  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
168  << " big pix per ROC x: " << BIG_PIX_PER_ROC_X << " y: " << BIG_PIX_PER_ROC_Y;
169 
170  tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
171 
172  for (auto const& i : gdv) {
173  std::string const& detName = i->name();
174  if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
175  std::unique_ptr<const Bounds> bounds(i->bounds());
177  (int)i->pixROCRows(),
178  (int)i->pixROCCols(),
179  BIG_PIX_PER_ROC_X,
180  BIG_PIX_PER_ROC_Y,
181  (int)i->pixROCx(),
182  (int)i->pixROCy());
183 
184  thePixelDetTypeMap[detName] = new PixelGeomDetType(t, detName, det);
185  tracker->addType(thePixelDetTypeMap[detName]);
186  }
187 
189  GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane), thePixelDetTypeMap[detName], i->geographicalId());
190 
191  tracker->addDetUnit(temp);
192  tracker->addDetUnitId(i->geographicalId());
193  }
194  tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
195 }
196 
197 void TrackerGeomBuilderFromGeometricDet::buildPixelPhase2(std::vector<const GeometricDet*> const& gdv,
198  const PTrackerAdditionalParametersPerDet* const& ptitp,
201  LogDebug("BuildingGeomDetUnits") << " Phase2 Pixel type. Size of vector: " << gdv.size()
202  << " GeomDetType subdetector: " << det
203  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det];
204 
205  tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
206 
207  for (auto const& i : gdv) {
208  std::string const& detName = i->name();
209  if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
210  std::unique_ptr<const Bounds> bounds(i->bounds());
211  int BIG_PIX_PER_ROC_X = i->bigPixelsx(); // in x direction, rows
212  int BIG_PIX_PER_ROC_Y = i->bigPixelsy(); // in y direction, cols
213  float BIG_PIX_PITCH_X = i->bigPixelsPitchx(); // in x direction, rows
214  float BIG_PIX_PITCH_Y = i->bigPixelsPitchy(); // in y direction, cols
216  (int)i->pixROCRows(),
217  (int)i->pixROCCols(),
218  BIG_PIX_PER_ROC_X,
219  BIG_PIX_PER_ROC_Y,
220  BIG_PIX_PITCH_X,
221  BIG_PIX_PITCH_Y,
222  (int)i->pixROCx(),
223  (int)i->pixROCy());
224 
225  thePixelDetTypeMap[detName] = new PixelGeomDetType(t, detName, det);
226  tracker->addType(thePixelDetTypeMap[detName]);
227  }
228 
230  GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane), thePixelDetTypeMap[detName], i->geographicalId());
231 
232  tracker->addDetUnit(temp);
233  tracker->addDetUnitId(i->geographicalId());
234  }
235  tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
236 }
237 
238 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const& gdv,
241  const std::string& part) {
242  LogDebug("BuildingGeomDetUnits") << " Strip type. Size of vector: " << gdv.size()
243  << " GeomDetType subdetector: " << det
244  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det] << " part "
245  << part;
246 
247  tracker->setOffsetDU(GeomDetEnumerators::subDetGeom[det]);
248 
249  for (auto const& i : gdv) {
250  std::string const& detName = i->name();
251  if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
252  std::unique_ptr<const Bounds> bounds(i->bounds());
253  StripTopology* t = StripTopologyBuilder().build(bounds.get(), i->siliconAPVNum(), part);
254  theStripDetTypeMap[detName] = new StripGeomDetType(t, detName, det, i->stereo());
255  tracker->addType(theStripDetTypeMap[detName]);
256  }
257 
258  double scale = (theTopo->partnerDetId(i->geographicalId())) ? 0.5 : 1.0;
259 
261  GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName], i->geographicalId());
262 
263  tracker->addDetUnit(temp);
264  tracker->addDetUnitId(i->geographicalId());
265  }
266  tracker->setEndsetDU(GeomDetEnumerators::subDetGeom[det]);
267 }
268 
270  PlaneBuilderForGluedDet gluedplaneBuilder;
271  auto const& gdu = tracker->detUnits();
272  auto const& gduId = tracker->detUnitIds();
273 
274  for (u_int32_t i = 0; i < gdu.size(); i++) {
275  tracker->addDet(gdu[i]);
276  tracker->addDetId(gduId[i]);
277  string gduTypeName = gdu[i]->type().name();
278 
279  //this step is time consuming >> TO FIX with a MAP?
280  if ((gduTypeName.find("Ster") != std::string::npos || gduTypeName.find("Lower") != std::string::npos ||
281  gduTypeName.find("One") != std::string::npos) &&
282  (theTopo->glued(gduId[i]) != 0 || theTopo->stack(gduId[i]) != 0 || theTopo->doubleSensor(gduId[i]))) {
283  int partner_pos = -1;
284  for (u_int32_t jj = 0; jj < gduId.size(); jj++) {
285  if (theTopo->partnerDetId(gduId[i]) == gduId[jj]) {
286  partner_pos = jj;
287  break;
288  }
289  }
290  if (partner_pos == -1) {
291  throw cms::Exception("Configuration") << "Module Type is Stereo or Lower but no partner detector found \n"
292  << "There is a problem on Tracker geometry configuration\n";
293  }
294 
295  const GeomDetUnit* dus = gdu[i];
296  const GeomDetUnit* dum = gdu[partner_pos];
297  std::vector<const GeomDetUnit*> composed(2);
298  composed[0] = dum;
299  composed[1] = dus;
300  DetId composedDetId;
301  if (gduTypeName.find("Ster") != std::string::npos) {
302  PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
303  composedDetId = theTopo->glued(gduId[i]);
304  GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane), dum, dus, composedDetId);
305  tracker->addDet((GeomDet*)gluedDet);
306  tracker->addDetId(composedDetId);
307 
308  } else if (gduTypeName.find("Lower") != std::string::npos) {
309  //The plane is *not* built in the middle, but on the Lower surface
310  Plane* plane = new Plane(dus->surface());
311  composedDetId = theTopo->stack(gduId[i]);
312  StackGeomDet* stackDet = new StackGeomDet(&(*plane), dus, dum, composedDetId);
313  tracker->addDet((GeomDet*)stackDet);
314  tracker->addDetId(composedDetId);
315  } else if (gduTypeName.find("One") != std::string::npos) {
316  //The plane is *not* built in the middle, but on the First surface
317  Plane* plane = new Plane(dus->surface());
318  composedDetId = theTopo->doubleSensor(gduId[i]);
319  DoubleSensGeomDet* doubleSensDet = new DoubleSensGeomDet(&(*plane), dus, dum, composedDetId);
320  tracker->addDet((GeomDet*)doubleSensDet);
321  tracker->addDetId(composedDetId);
322  }
323  }
324  }
325 }
326 
328  const GeometricDet* gd, double scale) const {
329  PlaneBuilderFromGeometricDet planeBuilder;
330  PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
331  //
332  // set medium properties (if defined)
333  //
334  plane->setMediumProperties(MediumProperties(gd->radLength() * scale, gd->xi() * scale));
335 
336  return plane;
337 }
std::vector< int > vpars
void buildPixel(std::vector< const GeometricDet *> const &, const PTrackerAdditionalParametersPerDet *const &, TrackerGeometry *, GeomDetType::SubDetector det, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y)
PlaneBuilderFromGeometricDet::ResultType buildPlaneWithMaterial(const GeometricDet *gd, double scaleFactor=1.) const
void buildPixelPhase2(std::vector< const GeometricDet *> const &, const PTrackerAdditionalParametersPerDet *const &, TrackerGeometry *, GeomDetType::SubDetector det)
constexpr SubDetector subDetGeom[21]
TrackerGeometry * build(const GeometricDet *gd, const PTrackerAdditionalParametersPerDet *ptitp, const PTrackerParameters &ptp, const TrackerTopology *tTopo)
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
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:158
uint32_t doubleSensor(const DetId &id) const
ResultType plane(const std::vector< const GeomDetUnit *> &dets) const
PixelTopology * build(const Bounds *bounds, 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)
PixelTopology * build(const Bounds *bounds, int ROWS_PER_ROC, int COLS_PER_ROC, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y, float BIG_PIX_PITCH_X, float BIG_PIX_PITCH_Y, int ROCS_X, int ROCS_Y)
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)
constexpr SubDetector tkDetEnum[8]
StripTopology * build(const Bounds *, double, const std::string &)
#define LogDebug(id)