test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
TrackerGeometry.cc
Go to the documentation of this file.
1 #include <typeinfo>
2 
7 
12 
13 #include <algorithm>
14 #include <iostream>
15 #include <map>
16 
17 
19 
20 namespace {
22 geometricDetToGeomDet(GeometricDet::GDEnumType gdenum) {
23  // provide a map between the GeometricDet enumerators and the GeomDet enumerators of the possible tracker subdetectors
25  if(gdenum == GeometricDet::GDEnumType::PixelEndCap) return GeomDetEnumerators::SubDetector::PixelEndcap;
30  if(gdenum == GeometricDet::GDEnumType::PixelPhase1Barrel) return GeomDetEnumerators::SubDetector::P1PXB;
31  if(gdenum == GeometricDet::GDEnumType::PixelPhase1EndCap) return GeomDetEnumerators::SubDetector::P1PXEC;
32  if(gdenum == GeometricDet::GDEnumType::PixelPhase2EndCap) return GeomDetEnumerators::SubDetector::P2PXEC;
33  if(gdenum == GeometricDet::GDEnumType::OTPhase2Barrel) return GeomDetEnumerators::SubDetector::P2OTB;
34  if(gdenum == GeometricDet::GDEnumType::OTPhase2EndCap) return GeomDetEnumerators::SubDetector::P2OTEC;
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 }
47 
49  UNKNOWN,
50  PXB,
51  PXF,
52  IB1,
53  IB2,
54  OB1,
55  OB2,
56  W1A,
57  W2A,
58  W3A,
59  W1B,
60  W2B,
61  W3B,
62  W4,
63  W5,
64  W6,
65  W7,
66  Ph1PXB,
67  Ph1PXF,
68  Ph2PXB,
69  Ph2PXF,
70  Ph2PSP,
71  Ph2PSS,
72  Ph2SS
73 };
74 
75 
76 TrackerGeometry::TrackerGeometry(GeometricDet const* gd) : theTrackerDet(gd)
77 {
78  for(unsigned int i=0;i<6;++i) {
80  theNumberOfLayers[i] = 0;
81  }
83 
84  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
85  for(unsigned int i=0;i<subdetgd.size();++i) {
86  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
87  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]= geometricDetToGeomDet(subdetgd[i]->type());
88  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->components().size();
89  LogTrace("BuildingSubDetTypeMap") << "subdet " << i
90  << " Geometric Det type " << subdetgd[i]->type()
91  << " Geom Det type " << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]
92  << " detid " << subdetgd[i]->geographicalId()
93  << " subdetid " << subdetgd[i]->geographicalId().subdetId()
94  << " number of layers " << subdetgd[i]->components().size();
95  }
96  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
97  for(unsigned int i=1;i<7;++i) {
98  LogTrace("SubDetTypeMapContent") << " detid subdet "<< i << " Geom Det type " << geomDetSubDetector(i);
99  }
100  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
101  for(unsigned int i=1;i<7;++i) {
102  LogTrace("NumberOfLayers") << " detid subdet "<< i << " number of layers " << numberOfLayers(i);
103  }
104  std::vector<const GeometricDet*> deepcomp;
105  gd->deepComponents(deepcomp);
106 
107  sort(deepcomp.begin(), deepcomp.end(), DetIdComparator());
108 
109  LogDebug("ThicknessAndType") << " Total Number of Detectors " << deepcomp.size() ;
110  LogDebug("ThicknessAndType") << "Dump of sensors names and bounds";
111  for(auto det : deepcomp) {
112  fillTestMap(det);
113  LogDebug("ThicknessAndType") << det->geographicalId() << " " << det->name().fullname() << " " << det->bounds()->thickness();
114  }
115  LogDebug("DetTypeList") << " Content of DetTypetList : size " << theDetTypetList.size();
116  for (auto iVal : theDetTypetList) {
117  LogDebug("DetTypeList") << " DetId " << std::get<0>(iVal) << " Type " << std::get<1>(iVal)<< " Thickness " << std::get<2>(iVal);
118  }
119 }
120 
121 
123  for (auto d : theDets) delete const_cast<GeomDet*>(d);
124  for (auto d : theDetTypes) delete const_cast<GeomDetType*>(d);
125 }
126 
128  theDetTypes.shrink_to_fit(); // owns the DetTypes
129  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
130  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
131  theDetUnitIds.shrink_to_fit();
132  theDetIds.shrink_to_fit();
133 
134  thePXBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
135  thePXFDets.shrink_to_fit(); // not owned: they're also in 'theDets'
136  theTIBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
137  theTIDDets.shrink_to_fit(); // not owned: they're also in 'theDets'
138  theTOBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
139  theTECDets.shrink_to_fit(); // not owned: they're also in 'theDets'
140 }
141 
142 
144  theDetTypes.push_back(p); // add to vector
145 }
146 
148  // set index
149  const_cast<GeomDetUnit *>(p)->setIndex(theDetUnits.size());
150  theDetUnits.push_back(p); // add to vector
151  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(),p));
152 }
153 
155  theDetUnitIds.push_back(p);
156 }
157 
159  theDets.push_back(p); // add to vector
160  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
161  DetId id(p->geographicalId());
162  switch(id.subdetId()){
164  thePXBDets.push_back(p);
165  break;
167  thePXFDets.push_back(p);
168  break;
170  theTIBDets.push_back(p);
171  break;
173  theTIDDets.push_back(p);
174  break;
176  theTOBDets.push_back(p);
177  break;
179  theTECDets.push_back(p);
180  break;
181  default:
182  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
183  }
184 
185 
186 }
187 
189  theDetIds.push_back(p);
190 }
191 
194 {
195  return theDetUnits;
196 }
197 
200 {
201  return theDets;
202 }
203 
206 {
207  return thePXBDets;
208 }
209 
212 {
213  return thePXFDets;
214 }
215 
218 {
219  return theTIBDets;
220 }
221 
224 {
225  return theTIDDets;
226 }
227 
230 {
231  return theTOBDets;
232 }
233 
236 {
237  return theTECDets;
238 }
239 
240 const TrackerGeomDet *
242 {
243  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
244  if (p != theMapUnit.end())
245  return static_cast<const TrackerGeomDet *>(p->second);
246  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDetUnit associated";
247  return nullptr;
248 }
249 
250 const TrackerGeomDet*
252 {
253  mapIdToDet::const_iterator p=theMap.find(s.rawId());
254  if (p != theMap.end())
255  return static_cast<const TrackerGeomDet *>(p->second);
256  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDet associated";
257  return nullptr;
258 }
259 
262  if(subdet>=1 && subdet<=6) {
263  return theSubDetTypeMap[subdet-1];
264  } else {
265  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
266  }
267 }
268 
269 unsigned int
271  if(subdet>=1 && subdet<=6) {
272  return theNumberOfLayers[subdet-1];
273  } else {
274  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
275  }
276 }
277 
278 bool
280  for(unsigned int i=1;i<7;++i) {
281  if(subdet == geomDetSubDetector(i)) return true;
282  }
283  return false;
284 }
285 
288 {
289  return theDetTypes;
290 }
291 
292 
295 {
296  return theDetUnitIds;
297 }
298 
301 {
302  return theDetIds;
303 }
305 
306  std::string temp = gd->name();
307  std::string name = temp.substr(temp.find(":")+1);
308  DetId detid = gd->geographicalId();
309  float thickness = gd->bounds()->thickness();
310  std::string nameTag;
312  if (theDetTypetList.size() == 0) {
313  theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
314  } else {
315  auto & t = (*(theDetTypetList.end()-1));
316  if (std::get<1>(t) != mtype) theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
317  else {
318  if ( detid > std::get<0>(t) ) std::get<0>(t) = detid;
319  }
320  }
321 }
322 
324  for (auto iVal : theDetTypetList) {
325  DetId detid_max = std::get<0>(iVal);
326  TrackerGeometry::ModuleType mtype = std::get<1>(iVal);
327  if (detid.rawId() <= detid_max.rawId()) return mtype;
328  }
330 }
332  for (auto iVal : theDetTypetList) {
333  DetId detid_max = std::get<0>(iVal);
334  if (detid.rawId() <= detid_max.rawId())
335  return std::get<2>(iVal);
336  }
337  return -1.0;
338 }
339 
341  if ( name.find("PixelBarrel") != std::string::npos) return ModuleType::Ph1PXB;
342  else if (name.find("PixelForward") != std::string::npos) return ModuleType::Ph1PXF;
343  else if ( name.find("TIB") != std::string::npos) {
344  if ( name.find("0") != std::string::npos) return ModuleType::IB1;
345  else return ModuleType::IB2;
346  } else if ( name.find("TOB") != std::string::npos) {
347  if ( name.find("0") != std::string::npos) return ModuleType::OB1;
348  else return ModuleType::OB2;
349  } else if ( name.find("TID") != std::string::npos) {
350  if ( name.find("0") != std::string::npos) return ModuleType::W1A;
351  else if ( name.find("1") != std::string::npos) return ModuleType::W2A;
352  else if ( name.find("2") != std::string::npos) return ModuleType::W3A;
353  } else if ( name.find("TEC") != std::string::npos) {
354  if ( name.find("0") != std::string::npos) return ModuleType::W1B;
355  else if ( name.find("1") != std::string::npos) return ModuleType::W2B;
356  else if ( name.find("2") != std::string::npos) return ModuleType::W3B;
357  else if ( name.find("3") != std::string::npos) return ModuleType::W4;
358  else if ( name.find("4") != std::string::npos) return ModuleType::W5;
359  else if ( name.find("5") != std::string::npos) return ModuleType::W6;
360  else if ( name.find("6") != std::string::npos) return ModuleType::W7;
361  } else if ( name.find("BModule") != std::string::npos || name.find("EModule") != std::string::npos ) {
362  if (name.find("PSMacroPixel") != std::string::npos) return ModuleType::Ph2PSP;
363  else if (name.find("PSStrip") != std::string::npos) return ModuleType::Ph2PSS;
364  else if (name.find("2S") != std::string::npos) return ModuleType::Ph2SS;
365  }
366  return ModuleType::UNKNOWN;
367 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
virtual const TrackerGeomDet * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
std::vector< GeomDetType const * > DetTypeContainer
int i
Definition: DBlmapReader.cc:9
void addDet(GeomDet const *p)
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
mapIdToDet theMap
assert(m_qm.get())
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:174
void addDetId(DetId p)
DetUnitContainer theDetUnits
DDName const & name() const
Definition: GeometricDet.h:144
bool isThere(GeomDetEnumerators::SubDetector subdet) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
tuple d
Definition: ztail.py:151
virtual const DetUnitContainer & detUnits() const
Returm a vector of all GeomDetUnit.
void addDetUnit(GeomDetUnit const *p)
virtual const DetIdContainer & detIds() const
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
mapIdToDetUnit theMapUnit
const DetContainer & detsTEC() const
DetTypeContainer theDetTypes
virtual ~TrackerGeometry()
void addType(GeomDetType const *p)
virtual const DetTypeContainer & detTypes() const
Return a vector of all det types.
const DetContainer & detsPXB() const
std::unique_ptr< Bounds > bounds() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
ModuleType getDetectorType(DetId) const
#define LogTrace(id)
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:210
void addDetUnitId(DetId p)
DetContainer theTIBDets
ConstGeometricDetContainer deepComponents() const
DetContainer theTOBDets
virtual const DetIdContainer & detUnitIds() const
Returm a vector of all GeomDetUnit DetIds.
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
std::vector< GeomDet const * > DetContainer
std::vector< GeomDetUnit const * > DetUnitContainer
virtual const DetContainer & dets() const
Returm a vector of all GeomDet (including all GeomDetUnits)
float getDetectorThickness(DetId) const
const DetContainer & detsTID() const
std::vector< std::tuple< DetId, TrackerGeometry::ModuleType, float > > theDetTypetList
virtual const TrackerGeomDet * idToDet(DetId) const
std::vector< DetId > DetIdContainer