CMS 3D CMS Logo

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