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 
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::PixelPhase2EndCap) return GeomDetEnumerators::SubDetector::P2PXEC;
31  if(gdenum == GeometricDet::GDEnumType::OTPhase2Barrel) return GeomDetEnumerators::SubDetector::P2OTB;
32  if(gdenum == GeometricDet::GDEnumType::OTPhase2EndCap) return GeomDetEnumerators::SubDetector::P2OTEC;
34 }
35 class DetIdComparator {
36 public:
37  bool operator()(GeometricDet const* gd1, GeometricDet const * gd2) const {
38  uint32_t det1 = gd1->geographicalId();
39  uint32_t det2 = gd2->geographicalId();
40  return det1 < det2;
41  }
42 
43 };
44 }
45 
46 
47 TrackerGeometry::TrackerGeometry(GeometricDet const* gd) : theTrackerDet(gd)
48 {
49  for(unsigned int i=0;i<6;++i) {
51  theNumberOfLayers[i] = 0;
52  }
54 
55  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
56  for(unsigned int i=0;i<subdetgd.size();++i) {
57  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
58  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]= geometricDetToGeomDet(subdetgd[i]->type());
59  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->components().size();
60  LogTrace("BuildingSubDetTypeMap") << "subdet " << i
61  << " Geometric Det type " << subdetgd[i]->type()
62  << " Geom Det type " << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]
63  << " detid " << subdetgd[i]->geographicalId()
64  << " subdetid " << subdetgd[i]->geographicalId().subdetId()
65  << " number of layers " << subdetgd[i]->components().size();
66  }
67  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
68  for(unsigned int i=1;i<7;++i) {
69  LogTrace("SubDetTypeMapContent") << " detid subdet "<< i << " Geom Det type " << geomDetSubDetector(i);
70  }
71  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
72  for(unsigned int i=1;i<7;++i) {
73  LogTrace("NumberOfLayers") << " detid subdet "<< i << " number of layers " << numberOfLayers(i);
74  }
75  std::vector<const GeometricDet*> deepcomp;
76  gd->deepComponents(deepcomp);
77 
78  sort(deepcomp.begin(), deepcomp.end(), DetIdComparator());
79 
80  LogDebug("ThicknessAndType") << " Total Number of Detectors " << deepcomp.size() ;
81  LogDebug("ThicknessAndType") << "Dump of sensors names and bounds";
82  for(auto det : deepcomp) {
83  fillTestMap(det);
84  LogDebug("ThicknessAndType") << det->geographicalId() << " " << det->name().fullname() << " " << det->bounds()->thickness();
85  }
86  LogDebug("DetTypeList") << " Content of DetTypetList : size " << theDetTypetList.size();
87  for (auto iVal : theDetTypetList) {
88  LogDebug("DetTypeList") << " DetId " << std::get<0>(iVal)
89  << " Type " << static_cast<std::underlying_type<TrackerGeometry::ModuleType>::type>(std::get<1>(iVal))
90  << " Thickness " << std::get<2>(iVal);
91  }
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 
115 
117  theDetTypes.push_back(p); // add to vector
118 }
119 
121  // set index
122  const_cast<GeomDetUnit *>(p)->setIndex(theDetUnits.size());
123  theDetUnits.push_back(p); // add to vector
124  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(),p));
125 }
126 
128  theDetUnitIds.push_back(p);
129 }
130 
132  // set index
133  const_cast<GeomDet *>(p)->setGdetIndex(theDets.size());
134  theDets.push_back(p); // add to vector
135  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
136  DetId id(p->geographicalId());
137  switch(id.subdetId()){
139  thePXBDets.push_back(p);
140  break;
142  thePXFDets.push_back(p);
143  break;
145  theTIBDets.push_back(p);
146  break;
148  theTIDDets.push_back(p);
149  break;
151  theTOBDets.push_back(p);
152  break;
154  theTECDets.push_back(p);
155  break;
156  default:
157  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
158  }
159 
160 
161 }
162 
164  theDetIds.push_back(p);
165 }
166 
167 
170 {
171  return thePXBDets;
172 }
173 
176 {
177  return thePXFDets;
178 }
179 
182 {
183  return theTIBDets;
184 }
185 
188 {
189  return theTIDDets;
190 }
191 
194 {
195  return theTOBDets;
196 }
197 
200 {
201  return theTECDets;
202 }
203 
204 const TrackerGeomDet *
206 {
207  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
208  if (p != theMapUnit.end())
209  return static_cast<const TrackerGeomDet *>(p->second);
210  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDetUnit associated";
211  return nullptr;
212 }
213 
214 const TrackerGeomDet*
216 {
217  mapIdToDet::const_iterator p=theMap.find(s.rawId());
218  if (p != theMap.end())
219  return static_cast<const TrackerGeomDet *>(p->second);
220  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDet associated";
221  return nullptr;
222 }
223 
226  if(subdet>=1 && subdet<=6) {
227  return theSubDetTypeMap[subdet-1];
228  } else {
229  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
230  }
231 }
232 
233 unsigned int
235  if(subdet>=1 && subdet<=6) {
236  return theNumberOfLayers[subdet-1];
237  } else {
238  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
239  }
240 }
241 
242 bool
244  for(unsigned int i=1;i<7;++i) {
245  if(subdet == geomDetSubDetector(i)) return true;
246  }
247  return false;
248 }
249 
251 
252  std::string temp = gd->name();
253  std::string name = temp.substr(temp.find(":")+1);
254  DetId detid = gd->geographicalId();
255  float thickness = gd->bounds()->thickness();
256  std::string nameTag;
258  if (theDetTypetList.size() == 0) {
259  theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
260  } else {
261  auto & t = (*(theDetTypetList.end()-1));
262  if (std::get<1>(t) != mtype) theDetTypetList.push_back({std::make_tuple(detid, mtype, thickness)});
263  else {
264  if ( detid > std::get<0>(t) ) std::get<0>(t) = detid;
265  }
266  }
267 }
268 
270  for (auto iVal : theDetTypetList) {
271  DetId detid_max = std::get<0>(iVal);
272  TrackerGeometry::ModuleType mtype = std::get<1>(iVal);
273  if (detid.rawId() <= detid_max.rawId()) return mtype;
274  }
276 }
278  for (auto iVal : theDetTypetList) {
279  DetId detid_max = std::get<0>(iVal);
280  if (detid.rawId() <= detid_max.rawId())
281  return std::get<2>(iVal);
282  }
283  return -1.0;
284 }
285 
287  if ( name.find("Pixel") != std::string::npos ){
288  if ( name.find("BarrelActive") != std::string::npos) return ModuleType::Ph1PXB;
289  else if ( name.find("ForwardSensor") != std::string::npos) return ModuleType::Ph1PXF;
290  else if ( name.find("BModule") != std::string::npos && name.find("InnerPixelActive") != std::string::npos ) return ModuleType::Ph2PXB;
291  else if ( name.find("EModule") != std::string::npos && name.find("InnerPixelActive") != std::string::npos ) return ModuleType::Ph2PXF;
292  } else if ( name.find("TIB") != std::string::npos) {
293  if ( name.find("0") != std::string::npos) return ModuleType::IB1;
294  else return ModuleType::IB2;
295  } else if ( name.find("TOB") != std::string::npos) {
296  if ( name.find("0") != std::string::npos) return ModuleType::OB1;
297  else return ModuleType::OB2;
298  } else if ( name.find("TID") != std::string::npos) {
299  if ( name.find("0") != std::string::npos) return ModuleType::W1A;
300  else if ( name.find("1") != std::string::npos) return ModuleType::W2A;
301  else if ( name.find("2") != std::string::npos) return ModuleType::W3A;
302  } else if ( name.find("TEC") != std::string::npos) {
303  if ( name.find("0") != std::string::npos) return ModuleType::W1B;
304  else if ( name.find("1") != std::string::npos) return ModuleType::W2B;
305  else if ( name.find("2") != std::string::npos) return ModuleType::W3B;
306  else if ( name.find("3") != std::string::npos) return ModuleType::W4;
307  else if ( name.find("4") != std::string::npos) return ModuleType::W5;
308  else if ( name.find("5") != std::string::npos) return ModuleType::W6;
309  else if ( name.find("6") != std::string::npos) return ModuleType::W7;
310  }
311  if ( name.find("BModule") != std::string::npos || name.find("EModule") != std::string::npos ) {
312  if (name.find("PSMacroPixel") != std::string::npos) return ModuleType::Ph2PSP;
313  else if (name.find("PSStrip") != std::string::npos) return ModuleType::Ph2PSS;
314  else if (name.find("2S") != std::string::npos) return ModuleType::Ph2SS;
315  }
316  return ModuleType::UNKNOWN;
317 }
#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
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:175
void addDetId(DetId p)
DetUnitContainer theDetUnits
DDName const & name() const
Definition: GeometricDet.h:145
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:211
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