CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
46  const PTrackerParameters& ptp,
47  const TrackerTopology* tTopo) {
48  if (ptp.vpars.size() != 6) {
49  throw cms::Exception("TrackerGeomBuilderFromGeometricDet")
50  << "Tracker parameters block from XMLs called vPars is expected to have 6 entries, but has " << ptp.vpars.size()
51  << " entrie(s).";
52  }
53 
54  const int BIG_PIX_PER_ROC_X = ptp.vpars[2];
55  const int BIG_PIX_PER_ROC_Y = ptp.vpars[3];
56 
57  thePixelDetTypeMap.clear();
58  theStripDetTypeMap.clear();
59 
60  TrackerGeometry* tracker = new TrackerGeometry(gd);
61  std::vector<const GeometricDet*> comp;
62  gd->deepComponents(comp);
63 
64  if (tTopo)
65  theTopo = tTopo;
66 
67  //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
68 
69  std::vector<GeometricDet::GDEnumType> gdsubdetmap(
70  6, GeometricDet::unknown); // hardcoded "6" should not be a surprise...
72 
73  LogDebug("SubDetectorGeometricDetType") << "GeometriDet enumerator values of the subdetectors";
74  for (unsigned int i = 0; i < subdetgd.size(); ++i) {
75  assert(subdetgd[i]->geographicalId().subdetId() > 0 && subdetgd[i]->geographicalId().subdetId() < 7);
76  gdsubdetmap[subdetgd[i]->geographicalId().subdetId() - 1] = subdetgd[i]->type();
77  LogTrace("SubDetectorGeometricDetType")
78  << "subdet " << i << " type " << subdetgd[i]->type() << " detid " << subdetgd[i]->geographicalId().rawId()
79  << " subdetid " << subdetgd[i]->geographicalId().subdetId();
80  }
81 
82  std::vector<const GeometricDet*> dets[6];
83  std::vector<const GeometricDet*>& pixB = dets[0];
84  pixB.reserve(comp.size());
85  std::vector<const GeometricDet*>& pixF = dets[1];
86  pixF.reserve(comp.size());
87  std::vector<const GeometricDet*>& tib = dets[2];
88  tib.reserve(comp.size());
89  std::vector<const GeometricDet*>& tid = dets[3];
90  tid.reserve(comp.size());
91  std::vector<const GeometricDet*>& tob = dets[4];
92  tob.reserve(comp.size());
93  std::vector<const GeometricDet*>& tec = dets[5];
94  tec.reserve(comp.size());
95 
96  for (auto& i : comp)
97  dets[i->geographicalId().subdetId() - 1].emplace_back(i);
98 
99  //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 !!
100  // this order is VERY IMPORTANT!!!!! For the moment I (AndreaV) understand that some pieces of code rely on pixel-like being before strip-like
101 
102  // now building the Pixel-like subdetectors
103  for (unsigned int i = 0; i < 6; ++i) {
104  if (gdsubdetmap[i] == GeometricDet::PixelBarrel)
105  buildPixel(dets[i],
106  ptitpx,
107  tracker,
109  false,
110  BIG_PIX_PER_ROC_X,
111  BIG_PIX_PER_ROC_Y);
112  if (gdsubdetmap[i] == GeometricDet::PixelPhase1Barrel)
113  buildPixel(
114  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P1PXB, false, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
115  // Phase2 case
116  if (gdsubdetmap[i] == GeometricDet::PixelPhase2Barrel)
117  buildPixel(
118  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P2PXB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
119  //
120  if (gdsubdetmap[i] == GeometricDet::PixelEndCap)
121  buildPixel(dets[i],
122  ptitpx,
123  tracker,
125  false,
126  BIG_PIX_PER_ROC_X,
127  BIG_PIX_PER_ROC_Y);
128  if (gdsubdetmap[i] == GeometricDet::PixelPhase1EndCap)
129  buildPixel(dets[i],
130  ptitpx,
131  tracker,
133  false,
134  BIG_PIX_PER_ROC_X,
135  BIG_PIX_PER_ROC_Y);
136  if (gdsubdetmap[i] == GeometricDet::PixelPhase2EndCap)
137  buildPixel(
138  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P2PXEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
139  if (gdsubdetmap[i] == GeometricDet::OTPhase2Barrel)
140  buildPixel(
141  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P2OTB, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
142  if (gdsubdetmap[i] == GeometricDet::OTPhase2EndCap)
143  buildPixel(
144  dets[i], ptitpx, tracker, GeomDetEnumerators::SubDetector::P2OTEC, true, BIG_PIX_PER_ROC_X, BIG_PIX_PER_ROC_Y);
145  }
146  //now building Strips
147  for (unsigned int i = 0; i < 6; ++i) {
148  if (gdsubdetmap[i] == GeometricDet::TIB)
149  buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TIB, "barrel");
150  if (gdsubdetmap[i] == GeometricDet::TID)
151  buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TID, "endcap");
152  if (gdsubdetmap[i] == GeometricDet::TOB)
153  buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TOB, "barrel");
154  if (gdsubdetmap[i] == GeometricDet::TEC)
155  buildSilicon(dets[i], tracker, GeomDetEnumerators::SubDetector::TEC, "endcap");
156  }
157  // and finally the "empty" subdetectors (maybe it is not needed)
158  for (unsigned int i = 0; i < 6; ++i) {
159  if (gdsubdetmap[i] == GeometricDet::unknown) {
160  if (!dets[i].empty())
161  throw cms::Exception("NotEmptyUnknownSubDet")
162  << "Subdetector " << i + 1 << " is unknown but it is not empty: " << dets[i].size();
163  buildSilicon(
164  dets[i], tracker, GeomDetEnumerators::tkDetEnum[i + 1], "barrel"); // "barrel" is used but it is irrelevant
165  }
166  }
167  buildGeomDet(tracker); //"GeomDet"
168 
169  verifyDUinTG(*tracker);
170 
171  return tracker;
172 }
173 
175  std::vector<const GeometricDet*> const& gdv,
176  const PTrackerAdditionalParametersPerDet* const& ptitp,
177  TrackerGeometry* tracker,
179  bool upgradeGeometry,
180  int BIG_PIX_PER_ROC_X, // in x direction, rows. BIG_PIX_PER_ROC_X = 0 for SLHC
181  int BIG_PIX_PER_ROC_Y) // in y direction, cols. BIG_PIX_PER_ROC_Y = 0 for SLHC
182 {
183  LogDebug("BuildingGeomDetUnits") << " Pixel type. Size of vector: " << gdv.size()
184  << " GeomDetType subdetector: " << det
185  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det]
186  << " big pix per ROC x: " << BIG_PIX_PER_ROC_X << " y: " << BIG_PIX_PER_ROC_Y
187  << " is upgrade: " << upgradeGeometry;
188 
190 
191  std::map<DetId, bool> brickedness_map;
192 
193  std::vector<bool> brickedParams = ptitp->getAllBricked();
194  std::vector<int> geographicalIdParams = ptitp->getAllGeographicalIds();
195 
196  for (unsigned int i = 0; i < geographicalIdParams.size(); i++) {
197  brickedness_map[geographicalIdParams.at(i)] = brickedParams.at(i);
198  }
199 
200  for (auto const& i : gdv) {
201  std::string const& detName = i->name();
202  if (thePixelDetTypeMap.find(detName) == thePixelDetTypeMap.end()) {
203  std::unique_ptr<const Bounds> bounds(i->bounds());
204  PixelTopology* t = PixelTopologyBuilder().build(bounds.get(),
205  upgradeGeometry,
206  brickedness_map[i->geographicalId()],
207  (int)i->pixROCRows(),
208  (int)i->pixROCCols(),
209  BIG_PIX_PER_ROC_X,
210  BIG_PIX_PER_ROC_Y,
211  (int)i->pixROCx(),
212  (int)i->pixROCy());
213 
214  thePixelDetTypeMap[detName] = new PixelGeomDetType(t, detName, det);
215  tracker->addType(thePixelDetTypeMap[detName]);
216  }
217 
219  GeomDetUnit* temp = new PixelGeomDetUnit(&(*plane), thePixelDetTypeMap[detName], i->geographicalId());
220 
221  tracker->addDetUnit(temp);
222  tracker->addDetUnitId(i->geographicalId());
223  }
225 }
226 
227 void TrackerGeomBuilderFromGeometricDet::buildSilicon(std::vector<const GeometricDet*> const& gdv,
228  TrackerGeometry* tracker,
230  const std::string& part) {
231  LogDebug("BuildingGeomDetUnits") << " Strip type. Size of vector: " << gdv.size()
232  << " GeomDetType subdetector: " << det
233  << " logical subdetector: " << GeomDetEnumerators::subDetGeom[det] << " part "
234  << part;
235 
237 
238  for (auto const& i : gdv) {
239  std::string const& detName = i->name();
240  if (theStripDetTypeMap.find(detName) == theStripDetTypeMap.end()) {
241  std::unique_ptr<const Bounds> bounds(i->bounds());
242  StripTopology* t = StripTopologyBuilder().build(bounds.get(), i->siliconAPVNum(), part);
243  theStripDetTypeMap[detName] = new StripGeomDetType(t, detName, det, i->stereo());
244  tracker->addType(theStripDetTypeMap[detName]);
245  }
246 
247  double scale = (theTopo->partnerDetId(i->geographicalId())) ? 0.5 : 1.0;
248 
250  GeomDetUnit* temp = new StripGeomDetUnit(&(*plane), theStripDetTypeMap[detName], i->geographicalId());
251 
252  tracker->addDetUnit(temp);
253  tracker->addDetUnitId(i->geographicalId());
254  }
256 }
257 
259  PlaneBuilderForGluedDet gluedplaneBuilder;
260  auto const& gdu = tracker->detUnits();
261  auto const& gduId = tracker->detUnitIds();
262 
263  for (u_int32_t i = 0; i < gdu.size(); i++) {
264  tracker->addDet(gdu[i]);
265  tracker->addDetId(gduId[i]);
266  string gduTypeName = gdu[i]->type().name();
267 
268  //this step is time consuming >> TO FIX with a MAP?
269  if ((gduTypeName.find("Ster") != std::string::npos || gduTypeName.find("Lower") != std::string::npos) &&
270  (theTopo->glued(gduId[i]) != 0 || theTopo->stack(gduId[i]) != 0)) {
271  int partner_pos = -1;
272  for (u_int32_t jj = 0; jj < gduId.size(); jj++) {
273  if (theTopo->partnerDetId(gduId[i]) == gduId[jj]) {
274  partner_pos = jj;
275  break;
276  }
277  }
278  if (partner_pos == -1) {
279  throw cms::Exception("Configuration") << "Module Type is Stereo or Lower but no partner detector found \n"
280  << "There is a problem on Tracker geometry configuration\n";
281  }
282 
283  const GeomDetUnit* dus = gdu[i];
284  const GeomDetUnit* dum = gdu[partner_pos];
285  std::vector<const GeomDetUnit*> composed(2);
286  composed[0] = dum;
287  composed[1] = dus;
288  DetId composedDetId;
289  if (gduTypeName.find("Ster") != std::string::npos) {
290  PlaneBuilderForGluedDet::ResultType plane = gluedplaneBuilder.plane(composed);
291  composedDetId = theTopo->glued(gduId[i]);
292  GluedGeomDet* gluedDet = new GluedGeomDet(&(*plane), dum, dus, composedDetId);
293  tracker->addDet((GeomDet*)gluedDet);
294  tracker->addDetId(composedDetId);
295 
296  } else if (gduTypeName.find("Lower") != std::string::npos) {
297  //The plane is *not* built in the middle, but on the Lower surface
298  Plane* plane = new Plane(dus->surface());
299  composedDetId = theTopo->stack(gduId[i]);
300  StackGeomDet* stackDet = new StackGeomDet(&(*plane), dus, dum, composedDetId);
301  tracker->addDet((GeomDet*)stackDet);
302  tracker->addDetId(composedDetId);
303  }
304  }
305  }
306 }
307 
309  const GeometricDet* gd, double scale) const {
310  PlaneBuilderFromGeometricDet planeBuilder;
311  PlaneBuilderFromGeometricDet::ResultType plane = planeBuilder.plane(gd);
312  //
313  // set medium properties (if defined)
314  //
315  plane->setMediumProperties(MediumProperties(gd->radLength() * scale, gd->xi() * scale));
316 
317  return plane;
318 }
std::vector< int > vpars
double radLength() const
Definition: GeometricDet.h:128
void addDet(GeomDet const *p)
void setEndsetDU(SubDetector sid)
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
void buildPixel(std::vector< const GeometricDet * > const &, const PTrackerAdditionalParametersPerDet *const &, TrackerGeometry *, GeomDetType::SubDetector det, bool upgradeGeometry, int BIG_PIX_PER_ROC_X, int BIG_PIX_PER_ROC_Y)
std::map< std::string, const StripGeomDetType * > theStripDetTypeMap
const DetContainer & detUnits() const override
Returm a vector of all GeomDet.
assert(be >=bs)
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
Definition: Plane.h:16
ResultType plane(const std::vector< const GeomDetUnit * > &dets) const
#define LogTrace(id)
DetId partnerDetId(const DetId &id) const
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:152
void addDetId(DetId p)
unsigned int endsetDU(SubDetector sid) const
void setOffsetDU(SubDetector sid)
void buildSilicon(std::vector< const GeometricDet * > const &, TrackerGeometry *, GeomDetType::SubDetector det, const std::string &part)
PlaneBuilderFromGeometricDet::ResultType buildPlaneWithMaterial(const GeometricDet *gd, double scaleFactor=1.) const
void addType(GeomDetType const *p)
unsigned int offsetDU(SubDetector sid) const
PixelTopology * build(const Bounds *bounds, bool upgradeGeometry, bool isBricked, 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)
ResultType plane(const GeometricDet *gd) const
void addDetUnit(GeomDet const *p)
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:34
Definition: DetId.h:17
double xi() const
Definition: GeometricDet.h:129
uint32_t stack(const DetId &id) const
part
Definition: HCALResponse.h:20
void addDetUnitId(DetId p)
ConstGeometricDetContainer deepComponents() const
string end
Definition: dataset.py:937
uint32_t glued(const DetId &id) const
const DetIdContainer & detUnitIds() const override
Returm a vector of all GeomDetUnit DetIds.
constexpr SubDetector tkDetEnum[8]
StripTopology * build(const Bounds *, double, const std::string &)
#define LogDebug(id)