CMS 3D CMS Logo

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 {
20  geometricDetToGeomDet(GeometricDet::GDEnumType gdenum) {
21  // provide a map between the GeometricDet enumerators and the GeomDet enumerators of the possible tracker subdetectors
23  if(gdenum == GeometricDet::GDEnumType::PixelEndCap) return GeomDetEnumerators::SubDetector::PixelEndcap;
28  if(gdenum == GeometricDet::GDEnumType::PixelPhase1Barrel) return GeomDetEnumerators::SubDetector::P1PXB;
29  if(gdenum == GeometricDet::GDEnumType::PixelPhase1EndCap) return GeomDetEnumerators::SubDetector::P1PXEC;
30  if(gdenum == GeometricDet::GDEnumType::PixelPhase2Barrel) return GeomDetEnumerators::SubDetector::P2PXB;
31  if(gdenum == GeometricDet::GDEnumType::PixelPhase2EndCap) return GeomDetEnumerators::SubDetector::P2PXEC;
32  if(gdenum == GeometricDet::GDEnumType::OTPhase2Barrel) return GeomDetEnumerators::SubDetector::P2OTB;
33  if(gdenum == GeometricDet::GDEnumType::OTPhase2EndCap) return GeomDetEnumerators::SubDetector::P2OTEC;
35  }
36 
37  class DetIdComparator {
38  public:
39  bool operator()(GeometricDet const* gd1, GeometricDet const * gd2) const {
40  uint32_t det1 = gd1->geographicalId();
41  uint32_t det2 = gd2->geographicalId();
42  return det1 < det2;
43  }
44  };
45 }
46 
48  : theTrackerDet(gd)
49 {
50  for(unsigned int i=0;i<6;++i) {
52  theNumberOfLayers[i] = 0;
53  }
55 
56  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
57  for(unsigned int i=0;i<subdetgd.size();++i) {
58  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
59  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]= geometricDetToGeomDet(subdetgd[i]->type());
60  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->components().size();
61  LogTrace("BuildingSubDetTypeMap") << "subdet " << i
62  << " Geometric Det type " << subdetgd[i]->type()
63  << " Geom Det type " << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]
64  << " detid " << subdetgd[i]->geographicalId()
65  << " subdetid " << subdetgd[i]->geographicalId().subdetId()
66  << " number of layers " << subdetgd[i]->components().size();
67  }
68  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
69  for(unsigned int i=1;i<7;++i) {
70  LogTrace("SubDetTypeMapContent") << " detid subdet "<< i << " Geom Det type " << geomDetSubDetector(i);
71  }
72  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
73  for(unsigned int i=1;i<7;++i) {
74  LogTrace("NumberOfLayers") << " detid subdet "<< i << " number of layers " << numberOfLayers(i);
75  }
76  std::vector<const GeometricDet*> deepcomp;
77  gd->deepComponents(deepcomp);
78 
79  sort(deepcomp.begin(), deepcomp.end(), DetIdComparator());
80 
81  LogDebug("ThicknessAndType") << " Total Number of Detectors " << deepcomp.size() ;
82  LogDebug("ThicknessAndType") << "Dump of sensors names and bounds";
83  for(auto det : deepcomp) {
84  fillTestMap(det);
85  LogDebug("ThicknessAndType") << det->geographicalId() << " " << det->name().fullname() << " " << det->bounds()->thickness();
86  }
87  LogDebug("DetTypeList") << " Content of DetTypetList : size " << theDetTypetList.size();
88  for (auto iVal : theDetTypetList) {
89  LogDebug("DetTypeList") << " DetId " << std::get<0>(iVal)
90  << " Type " << static_cast<std::underlying_type<TrackerGeometry::ModuleType>::type>(std::get<1>(iVal))
91  << " Thickness " << std::get<2>(iVal);
92  }
93 }
94 
96  for (auto d : theDets) delete const_cast<GeomDet*>(d);
97  for (auto d : theDetTypes) delete const_cast<GeomDetType*>(d);
98 }
99 
101  theDetTypes.shrink_to_fit(); // owns the DetTypes
102  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
103  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
104  theDetUnitIds.shrink_to_fit();
105  theDetIds.shrink_to_fit();
106 
107  thePXBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
108  thePXFDets.shrink_to_fit(); // not owned: they're also in 'theDets'
109  theTIBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
110  theTIDDets.shrink_to_fit(); // not owned: they're also in 'theDets'
111  theTOBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
112  theTECDets.shrink_to_fit(); // not owned: they're also in 'theDets'
113 }
114 
116  theDetTypes.emplace_back(p); // add to vector
117 }
118 
120  // set index
121  const_cast<GeomDet *>(p)->setIndex(theDetUnits.size());
122  theDetUnits.emplace_back(p); // add to vector
123  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(),p));
124 }
125 
127  theDetUnitIds.emplace_back(p);
128 }
129 
131  // set index
132  const_cast<GeomDet *>(p)->setGdetIndex(theDets.size());
133  theDets.emplace_back(p); // add to vector
134  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
135  DetId id(p->geographicalId());
136  switch(id.subdetId()){
138  thePXBDets.emplace_back(p);
139  break;
141  thePXFDets.emplace_back(p);
142  break;
144  theTIBDets.emplace_back(p);
145  break;
147  theTIDDets.emplace_back(p);
148  break;
150  theTOBDets.emplace_back(p);
151  break;
153  theTECDets.emplace_back(p);
154  break;
155  default:
156  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
157  }
158 }
159 
161  theDetIds.emplace_back(p);
162 }
163 
164 
167 {
168  return thePXBDets;
169 }
170 
173 {
174  return thePXFDets;
175 }
176 
179 {
180  return theTIBDets;
181 }
182 
185 {
186  return theTIDDets;
187 }
188 
191 {
192  return theTOBDets;
193 }
194 
197 {
198  return theTECDets;
199 }
200 
201 const TrackerGeomDet *
203 {
204  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
205  if (p != theMapUnit.end()) {
206  return static_cast<const TrackerGeomDet *>(p->second);
207  } else {
208  throw cms::Exception("WrongTrackerSubDet") << "Invalid DetID: no GeomDetUnit associated with raw ID "
209  << s.rawId() << " of subdet ID " << s.subdetId();
210  }
211 }
212 
213 const TrackerGeomDet*
215 {
216  mapIdToDet::const_iterator p=theMap.find(s.rawId());
217  if (p != theMap.end()) {
218  return static_cast<const TrackerGeomDet *>(p->second);
219  } else {
220  throw cms::Exception("WrongTrackerSubDet") << "Invalid DetID: no GeomDetUnit associated with raw ID "
221  << s.rawId() << " of subdet ID " << s.subdetId();
222  }
223 }
224 
227  if(subdet>=1 && subdet<=6) {
228  return theSubDetTypeMap[subdet-1];
229  } else {
230  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
231  }
232 }
233 
234 unsigned int
236  if(subdet>=1 && subdet<=6) {
237  return theNumberOfLayers[subdet-1];
238  } else {
239  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
240  }
241 }
242 
243 bool
245  for(unsigned int i=1;i<7;++i) {
246  if(subdet == geomDetSubDetector(i)) return true;
247  }
248  return false;
249 }
250 
252 
253  std::string temp = gd->name();
254  std::string name = temp.substr(temp.find(":")+1);
255  DetId detid = gd->geographicalId();
256  float thickness = gd->bounds()->thickness();
257  std::string nameTag;
259  if (theDetTypetList.empty()) {
260  theDetTypetList.emplace_back(detid, mtype, thickness);
261  } else {
262  auto & t = (*(theDetTypetList.end()-1));
263  if (std::get<1>(t) != mtype) theDetTypetList.emplace_back(detid, mtype, thickness);
264  else {
265  if ( detid > std::get<0>(t) ) std::get<0>(t) = detid;
266  }
267  }
268 }
269 
271  for (auto iVal : theDetTypetList) {
272  DetId detid_max = std::get<0>(iVal);
273  TrackerGeometry::ModuleType mtype = std::get<1>(iVal);
274  if (detid.rawId() <= detid_max.rawId()) return mtype;
275  }
277 }
278 
280  for (auto iVal : theDetTypetList) {
281  DetId detid_max = std::get<0>(iVal);
282  if (detid.rawId() <= detid_max.rawId())
283  return std::get<2>(iVal);
284  }
285  return -1.0;
286 }
287 
289  if ( name.find("Pixel") != std::string::npos ){
290  if ( name.find("BarrelActive") != std::string::npos) return ModuleType::Ph1PXB;
291  else if ( name.find("ForwardSensor") != std::string::npos) return ModuleType::Ph1PXF;
292  else if ( name.find("BModule") != std::string::npos && name.find("InnerPixelActive") != std::string::npos ) return ModuleType::Ph2PXB;
293  else if ( name.find("EModule") != std::string::npos && name.find("InnerPixelActive") != std::string::npos ) return ModuleType::Ph2PXF;
294  } else if ( name.find("TIB") != std::string::npos) {
295  if ( name.find("0") != std::string::npos) return ModuleType::IB1;
296  else return ModuleType::IB2;
297  } else if ( name.find("TOB") != std::string::npos) {
298  if ( name.find("0") != std::string::npos) return ModuleType::OB1;
299  else return ModuleType::OB2;
300  } else if ( name.find("TID") != std::string::npos) {
301  if ( name.find("0") != std::string::npos) return ModuleType::W1A;
302  else if ( name.find("1") != std::string::npos) return ModuleType::W2A;
303  else if ( name.find("2") != std::string::npos) return ModuleType::W3A;
304  } else if ( name.find("TEC") != std::string::npos) {
305  if ( name.find("0") != std::string::npos) return ModuleType::W1B;
306  else if ( name.find("1") != std::string::npos) return ModuleType::W2B;
307  else if ( name.find("2") != std::string::npos) return ModuleType::W3B;
308  else if ( name.find("3") != std::string::npos) return ModuleType::W4;
309  else if ( name.find("4") != std::string::npos) return ModuleType::W5;
310  else if ( name.find("5") != std::string::npos) return ModuleType::W6;
311  else if ( name.find("6") != std::string::npos) return ModuleType::W7;
312  }
313  if ( name.find("BModule") != std::string::npos || name.find("EModule") != std::string::npos ) {
314  if (name.find("PSMacroPixel") != std::string::npos) return ModuleType::Ph2PSP;
315  else if (name.find("PSStrip") != std::string::npos) return ModuleType::Ph2PSS;
316  else if (name.find("2S") != std::string::npos) return ModuleType::Ph2SS;
317  }
318  return ModuleType::UNKNOWN;
319 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
void addDet(GeomDet const *p)
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
unsigned int theNumberOfLayers[6]
TrackerGeometry(GeometricDet const *gd=0)
void fillTestMap(const GeometricDet *gd)
DetIdContainer theDetIds
DetIdContainer theDetUnitIds
GeomDetEnumerators::SubDetector theSubDetTypeMap[6]
DetContainer theTECDets
DetContainer theDets
unsigned int numberOfLayers(int subdet) const
ConstGeometricDetContainer & components()
Definition: GeometricDet.h:176
void addDetId(DetId p)
DDName const & name() const
Definition: GeometricDet.h:146
bool isThere(GeomDetEnumerators::SubDetector subdet) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
mapIdToDetUnit theMapUnit
const DetContainer & detsTEC() const
DetTypeContainer theDetTypes
void addType(GeomDetType const *p)
const DetContainer & detsPXB() const
std::unique_ptr< Bounds > bounds() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
void addDetUnit(GeomDet const *p)
ModuleType getDetectorType(DetId) const
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:38
#define LogTrace(id)
~TrackerGeometry() override
DetContainer theTIDDets
const DetContainer & detsTIB() const
ModuleType moduleType(const std::string &name) const
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:36
Definition: DetId.h:18
DetContainer thePXBDets
DetContainer thePXFDets
DetId geographicalId() const
Definition: GeometricDet.h:212
void addDetUnitId(DetId p)
DetContainer theTIBDets
ConstGeometricDetContainer deepComponents() const
std::vector< const GeomDet * > DetContainer
DetContainer theTOBDets
const DetContainer & detsPXF() const
const TrackerGeomDet * idToDet(DetId) const override
const DetContainer & detsTOB() const
DetContainer theDetUnits
float getDetectorThickness(DetId) const
const DetContainer & detsTID() const
std::vector< std::tuple< DetId, TrackerGeometry::ModuleType, float > > theDetTypetList