CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TrackerGeometry.cc
Go to the documentation of this file.
1 #include <typeinfo>
2 
8 
13 
14 #include <algorithm>
15 #include <iostream>
16 #include <map>
17 
18 namespace {
19  GeomDetEnumerators::SubDetector geometricDetToGeomDet(GeometricDet::GDEnumType gdenum) {
20  // provide a map between the GeometricDet enumerators and the GeomDet enumerators of the possible tracker subdetectors
23  if (gdenum == GeometricDet::GDEnumType::PixelEndCap)
25  if (gdenum == GeometricDet::GDEnumType::TIB)
27  if (gdenum == GeometricDet::GDEnumType::TID)
29  if (gdenum == GeometricDet::GDEnumType::TOB)
31  if (gdenum == GeometricDet::GDEnumType::TEC)
33  if (gdenum == GeometricDet::GDEnumType::PixelPhase1Barrel)
35  if (gdenum == GeometricDet::GDEnumType::PixelPhase1EndCap)
37  if (gdenum == GeometricDet::GDEnumType::PixelPhase2Barrel)
39  if (gdenum == GeometricDet::GDEnumType::PixelPhase2EndCap)
41  if (gdenum == GeometricDet::GDEnumType::OTPhase2Barrel)
43  if (gdenum == GeometricDet::GDEnumType::OTPhase2EndCap)
46  }
47 
48  class DetIdComparator {
49  public:
50  bool operator()(GeometricDet const* gd1, GeometricDet const* gd2) const {
51  uint32_t det1 = gd1->geographicalId();
52  uint32_t det2 = gd2->geographicalId();
53  return det1 < det2;
54  }
55  };
56 } // namespace
57 
58 TrackerGeometry::TrackerGeometry(GeometricDet const* gd) : theTrackerDet(gd) {
59  for (unsigned int i = 0; i < 6; ++i) {
61  theNumberOfLayers[i] = 0;
62  }
64 
65  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
66  for (unsigned int i = 0; i < subdetgd.size(); ++i) {
67  assert(subdetgd[i]->geographicalId().subdetId() > 0 && subdetgd[i]->geographicalId().subdetId() < 7);
68  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId() - 1] = geometricDetToGeomDet(subdetgd[i]->type());
69  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId() - 1] = subdetgd[i]->components().size();
70  LogTrace("BuildingSubDetTypeMap") << "subdet " << i << " Geometric Det type " << subdetgd[i]->type()
71  << " Geom Det type "
72  << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId() - 1] << " detid "
73  << subdetgd[i]->geographicalId() << " subdetid "
74  << subdetgd[i]->geographicalId().subdetId() << " number of layers "
75  << subdetgd[i]->components().size();
76  }
77  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
78  for (unsigned int i = 1; i < 7; ++i) {
79  LogTrace("SubDetTypeMapContent") << " detid subdet " << i << " Geom Det type " << geomDetSubDetector(i);
80  }
81  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
82  for (unsigned int i = 1; i < 7; ++i) {
83  LogTrace("NumberOfLayers") << " detid subdet " << i << " number of layers " << numberOfLayers(i);
84  }
85  std::vector<const GeometricDet*> deepcomp;
86  gd->deepComponents(deepcomp);
87 
88  sort(deepcomp.begin(), deepcomp.end(), DetIdComparator());
89 
90  LogDebug("ThicknessAndType") << " Total Number of Detectors " << deepcomp.size();
91  LogDebug("ThicknessAndType") << "Dump of sensors names and bounds";
92  for (auto det : deepcomp) {
93  fillTestMap(det);
94  LogDebug("ThicknessAndType") << det->geographicalId() << " " << det->name() << " " << det->bounds()->thickness();
95  }
96  LogDebug("DetTypeList") << " Content of DetTypetList : size " << theDetTypetList.size();
97  for (const auto& iVal : theDetTypetList) {
98  LogDebug("DetTypeList") << " DetId " << std::get<0>(iVal) << " Type "
99  << static_cast<std::underlying_type<TrackerGeometry::ModuleType>::type>(std::get<1>(iVal))
100  << " Thickness " << std::get<2>(iVal);
101  }
102 }
103 
105  for (auto d : theDets)
106  delete const_cast<GeomDet*>(d);
107  for (auto d : theDetTypes)
108  delete const_cast<GeomDetType*>(d);
109 }
110 
112  theDetTypes.shrink_to_fit(); // owns the DetTypes
113  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
114  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
115  theDetUnitIds.shrink_to_fit();
116  theDetIds.shrink_to_fit();
117 
118  thePXBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
119  thePXFDets.shrink_to_fit(); // not owned: they're also in 'theDets'
120  theTIBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
121  theTIDDets.shrink_to_fit(); // not owned: they're also in 'theDets'
122  theTOBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
123  theTECDets.shrink_to_fit(); // not owned: they're also in 'theDets'
124 }
125 
127  theDetTypes.emplace_back(p); // add to vector
128 }
129 
131  // set index
132  const_cast<GeomDet*>(p)->setIndex(theDetUnits.size());
133  theDetUnits.emplace_back(p); // add to vector
134  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(), p));
135 }
136 
138 
140  // set index
141  const_cast<GeomDet*>(p)->setGdetIndex(theDets.size());
142  theDets.emplace_back(p); // add to vector
143  theMap.insert(std::make_pair(p->geographicalId().rawId(), p));
144  DetId id(p->geographicalId());
145  switch (id.subdetId()) {
147  thePXBDets.emplace_back(p);
148  break;
150  thePXFDets.emplace_back(p);
151  break;
153  theTIBDets.emplace_back(p);
154  break;
156  theTIDDets.emplace_back(p);
157  break;
159  theTOBDets.emplace_back(p);
160  break;
162  theTECDets.emplace_back(p);
163  break;
164  default:
165  edm::LogError("TrackerGeometry") << "ERROR - I was expecting a Tracker Subdetector, I got a " << id.subdetId();
166  }
167 }
168 
169 void TrackerGeometry::addDetId(DetId p) { theDetIds.emplace_back(p); }
170 
172 
174 
176 
178 
180 
182 
184  mapIdToDetUnit::const_iterator p = theMapUnit.find(s.rawId());
185  if (p != theMapUnit.end()) {
186  return static_cast<const TrackerGeomDet*>(p->second);
187  } else {
188  throw cms::Exception("WrongTrackerSubDet")
189  << "Invalid DetID: no GeomDetUnit associated with raw ID " << s.rawId() << " of subdet ID " << s.subdetId();
190  }
191 }
192 
194  mapIdToDet::const_iterator p = theMap.find(s.rawId());
195  if (p != theMap.end()) {
196  return static_cast<const TrackerGeomDet*>(p->second);
197  } else {
198  throw cms::Exception("WrongTrackerSubDet")
199  << "Invalid DetID: no GeomDetUnit associated with raw ID " << s.rawId() << " of subdet ID " << s.subdetId();
200  }
201 }
202 
204  if (subdet >= 1 && subdet <= 6) {
205  return theSubDetTypeMap[subdet - 1];
206  } else {
207  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
208  }
209 }
210 
211 unsigned int TrackerGeometry::numberOfLayers(int subdet) const {
212  if (subdet >= 1 && subdet <= 6) {
213  return theNumberOfLayers[subdet - 1];
214  } else {
215  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
216  }
217 }
218 
220  for (unsigned int i = 1; i < 7; ++i) {
221  if (subdet == geomDetSubDetector(i))
222  return true;
223  }
224  return false;
225 }
226 
228  const std::string& temp = gd->name();
229  std::string name = temp.substr(temp.find(':') + 1);
230  DetId detid = gd->geographicalId();
231  float thickness = gd->bounds()->thickness();
232  std::string nameTag;
234  if (theDetTypetList.empty()) {
235  theDetTypetList.emplace_back(detid, mtype, thickness);
236  } else {
237  auto& t = (*(theDetTypetList.end() - 1));
238  if (std::get<1>(t) != mtype)
239  theDetTypetList.emplace_back(detid, mtype, thickness);
240  else {
241  if (detid > std::get<0>(t))
242  std::get<0>(t) = detid;
243  }
244  }
245 }
246 
248  for (const auto& iVal : theDetTypetList) {
249  DetId detid_max = std::get<0>(iVal);
250  if (detid.rawId() <= detid_max.rawId())
251  return std::get<1>(iVal);
252  }
254 }
255 
257  for (const auto& iVal : theDetTypetList) {
258  DetId detid_max = std::get<0>(iVal);
259  if (detid.rawId() <= detid_max.rawId())
260  return std::get<2>(iVal);
261  }
262  return -1.0;
263 }
264 
266  // IT
267  if (name.find("Pixel") != std::string::npos) {
268  // Phase 1
269  if (name.find("BarrelActive") != std::string::npos)
270  return ModuleType::Ph1PXB;
271  else if (name.find("ForwardSensor") != std::string::npos)
272  return ModuleType::Ph1PXF;
273 
274  // Phase 2
275  // barrel
276  else if (name.find("BModule") != std::string::npos) {
277  if (name.find("InnerPixelActive") != std::string::npos) {
278  return ModuleType::Ph2PXB;
279  } else if (name.find("InnerPixel3DActive") != std::string::npos) {
280  return ModuleType::Ph2PXB3D;
281  }
282  }
283  // forward
284  else if (name.find("EModule") != std::string::npos) {
285  if (name.find("InnerPixelActive") != std::string::npos) {
286  return ModuleType::Ph2PXF;
287  } else if (name.find("InnerPixel3DActive") != std::string::npos) {
288  return ModuleType::Ph2PXF3D;
289  }
290  }
291  }
292 
293  // TIB
294  else if (name.find("TIB") != std::string::npos) {
295  if (name.find('0') != std::string::npos)
296  return ModuleType::IB1;
297  else
298  return ModuleType::IB2;
299  }
300 
301  // TOB
302  else if (name.find("TOB") != std::string::npos) {
303  if (name.find('0') != std::string::npos)
304  return ModuleType::OB1;
305  else
306  return ModuleType::OB2;
307  }
308 
309  // TID
310  else if (name.find("TID") != std::string::npos) {
311  if (name.find('0') != std::string::npos)
312  return ModuleType::W1A;
313  else if (name.find('1') != std::string::npos)
314  return ModuleType::W2A;
315  else if (name.find('2') != std::string::npos)
316  return ModuleType::W3A;
317  }
318 
319  // TEC
320  else if (name.find("TEC") != std::string::npos) {
321  if (name.find('0') != std::string::npos)
322  return ModuleType::W1B;
323  else if (name.find('1') != std::string::npos)
324  return ModuleType::W2B;
325  else if (name.find('2') != std::string::npos)
326  return ModuleType::W3B;
327  else if (name.find('3') != std::string::npos)
328  return ModuleType::W4;
329  else if (name.find('4') != std::string::npos)
330  return ModuleType::W5;
331  else if (name.find('5') != std::string::npos)
332  return ModuleType::W6;
333  else if (name.find('6') != std::string::npos)
334  return ModuleType::W7;
335  }
336 
337  // Phase 2 OT
338  if (name.find("BModule") != std::string::npos || name.find("EModule") != std::string::npos) {
339  if (name.find("PSMacroPixel") != std::string::npos)
340  return ModuleType::Ph2PSP;
341  else if (name.find("PSStrip") != std::string::npos)
342  return ModuleType::Ph2PSS;
343  else if (name.find("2S") != std::string::npos)
344  return ModuleType::Ph2SS;
345  }
346 
347  return ModuleType::UNKNOWN;
348 }
static constexpr auto TEC
void addDet(GeomDet const *p)
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
uint16_t *__restrict__ id
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
unsigned int theNumberOfLayers[6]
void fillTestMap(const GeometricDet *gd)
Log< level::Error, false > LogError
DetIdContainer theDetIds
DetIdContainer theDetUnitIds
assert(be >=bs)
GeomDetEnumerators::SubDetector theSubDetTypeMap[6]
DetContainer theTECDets
DetContainer theDets
#define LogTrace(id)
unsigned int numberOfLayers(int subdet) const
TrackerGeometry(GeometricDet const *gd=nullptr)
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:152
void addDetId(DetId p)
bool isThere(GeomDetEnumerators::SubDetector subdet) const
tuple d
Definition: ztail.py:151
std::vector< const GeomDet * > DetContainer
mapIdToDetUnit theMapUnit
const DetContainer & detsTEC() const
DetTypeContainer theDetTypes
void addType(GeomDetType const *p)
const DetContainer & detsPXB() const
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
std::unique_ptr< Bounds > bounds() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
std::vector< std::tuple< DetId, TrackerGeometry::ModuleType, float > > theDetTypetList
void addDetUnit(GeomDet const *p)
static constexpr auto TOB
ModuleType getDetectorType(DetId) const
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:34
const TrackerGeomDet * idToDet(DetId) const override
~TrackerGeometry() override
DetContainer theTIDDets
const DetContainer & detsTIB() const
ModuleType moduleType(const std::string &name) const
const DetId & geographicalId() const
Definition: GeometricDet.h:98
Definition: DetId.h:17
static constexpr auto TIB
DetContainer thePXBDets
DetContainer thePXFDets
void addDetUnitId(DetId p)
DetContainer theTIBDets
ConstGeometricDetContainer deepComponents() const
DetContainer theTOBDets
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
DetContainer theDetUnits
const std::string & name() const
Definition: GeometricDet.h:92
static constexpr auto TID
float getDetectorThickness(DetId) const
const DetContainer & detsTID() const
#define LogDebug(id)