CMS 3D CMS Logo

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