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  // set index
160  const_cast<GeomDet *>(p)->setGdetIndex(theDets.size());
161  theDets.push_back(p); // add to vector
162  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
163  DetId id(p->geographicalId());
164  switch(id.subdetId()){
166  thePXBDets.push_back(p);
167  break;
169  thePXFDets.push_back(p);
170  break;
172  theTIBDets.push_back(p);
173  break;
175  theTIDDets.push_back(p);
176  break;
178  theTOBDets.push_back(p);
179  break;
181  theTECDets.push_back(p);
182  break;
183  default:
184  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
185  }
186 
187 
188 }
189 
191  theDetIds.push_back(p);
192 }
193 
194 
197 {
198  return thePXBDets;
199 }
200 
203 {
204  return thePXFDets;
205 }
206 
209 {
210  return theTIBDets;
211 }
212 
215 {
216  return theTIDDets;
217 }
218 
221 {
222  return theTOBDets;
223 }
224 
227 {
228  return theTECDets;
229 }
230 
231 const TrackerGeomDet *
233 {
234  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
235  if (p != theMapUnit.end())
236  return static_cast<const TrackerGeomDet *>(p->second);
237  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDetUnit associated";
238  return nullptr;
239 }
240 
241 const TrackerGeomDet*
243 {
244  mapIdToDet::const_iterator p=theMap.find(s.rawId());
245  if (p != theMap.end())
246  return static_cast<const TrackerGeomDet *>(p->second);
247  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDet associated";
248  return nullptr;
249 }
250 
253  if(subdet>=1 && subdet<=6) {
254  return theSubDetTypeMap[subdet-1];
255  } else {
256  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
257  }
258 }
259 
260 unsigned int
262  if(subdet>=1 && subdet<=6) {
263  return theNumberOfLayers[subdet-1];
264  } else {
265  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
266  }
267 }
268 
269 bool
271  for(unsigned int i=1;i<7;++i) {
272  if(subdet == geomDetSubDetector(i)) return true;
273  }
274  return false;
275 }
276 
278 
279  std::string temp = gd->name();
280  std::string name = temp.substr(temp.find(":")+1);
281  DetId detid = gd->geographicalId();
282  float thickness = gd->bounds()->thickness();
283  std::string nameTag;
285  if (theDetTypetList.size() == 0) {
286  theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
287  } else {
288  auto & t = (*(theDetTypetList.end()-1));
289  if (std::get<1>(t) != mtype) theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
290  else {
291  if ( detid > std::get<0>(t) ) std::get<0>(t) = detid;
292  }
293  }
294 }
295 
297  for (auto iVal : theDetTypetList) {
298  DetId detid_max = std::get<0>(iVal);
299  TrackerGeometry::ModuleType mtype = std::get<1>(iVal);
300  if (detid.rawId() <= detid_max.rawId()) return mtype;
301  }
303 }
305  for (auto iVal : theDetTypetList) {
306  DetId detid_max = std::get<0>(iVal);
307  if (detid.rawId() <= detid_max.rawId())
308  return std::get<2>(iVal);
309  }
310  return -1.0;
311 }
312 
314  if ( name.find("PixelBarrel") != std::string::npos) return ModuleType::Ph1PXB;
315  else if (name.find("PixelForward") != std::string::npos) return ModuleType::Ph1PXF;
316  else if ( name.find("TIB") != std::string::npos) {
317  if ( name.find("0") != std::string::npos) return ModuleType::IB1;
318  else return ModuleType::IB2;
319  } else if ( name.find("TOB") != std::string::npos) {
320  if ( name.find("0") != std::string::npos) return ModuleType::OB1;
321  else return ModuleType::OB2;
322  } else if ( name.find("TID") != std::string::npos) {
323  if ( name.find("0") != std::string::npos) return ModuleType::W1A;
324  else if ( name.find("1") != std::string::npos) return ModuleType::W2A;
325  else if ( name.find("2") != std::string::npos) return ModuleType::W3A;
326  } else if ( name.find("TEC") != std::string::npos) {
327  if ( name.find("0") != std::string::npos) return ModuleType::W1B;
328  else if ( name.find("1") != std::string::npos) return ModuleType::W2B;
329  else if ( name.find("2") != std::string::npos) return ModuleType::W3B;
330  else if ( name.find("3") != std::string::npos) return ModuleType::W4;
331  else if ( name.find("4") != std::string::npos) return ModuleType::W5;
332  else if ( name.find("5") != std::string::npos) return ModuleType::W6;
333  else if ( name.find("6") != std::string::npos) return ModuleType::W7;
334  } else if ( name.find("BModule") != std::string::npos || name.find("EModule") != std::string::npos ) {
335  if (name.find("PSMacroPixel") != std::string::npos) return ModuleType::Ph2PSP;
336  else if (name.find("PSStrip") != std::string::npos) return ModuleType::Ph2PSS;
337  else if (name.find("2S") != std::string::npos) return ModuleType::Ph2SS;
338  }
339  return ModuleType::UNKNOWN;
340 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
const TrackerGeomDet * idToDetUnit(DetId) const
Return the pointer to the GeomDetUnit corresponding to a given DetId.
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
void addDetUnit(GeomDetUnit const *p)
mapIdToDetUnit theMapUnit
const DetContainer & detsTEC() const
DetTypeContainer theDetTypes
virtual ~TrackerGeometry()
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
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
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
std::vector< GeomDet const * > DetContainer
float getDetectorThickness(DetId) const
const DetContainer & detsTID() const
std::vector< std::tuple< DetId, TrackerGeometry::ModuleType, float > > theDetTypetList
const TrackerGeomDet * idToDet(DetId) const