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 TrackerGeometry::TrackerGeometry(GeometricDet const* gd) : theTrackerDet(gd)
18 {
19  for(unsigned int i=0;i<6;++i) {
21  theNumberOfLayers[i] = 0;
22  }
24 
25  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
26  for(unsigned int i=0;i<subdetgd.size();++i) {
27  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
28  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]= geometricDetToGeomDet(subdetgd[i]->type());
29  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->components().size();
30  LogTrace("BuildingSubDetTypeMap") << "subdet " << i
31  << " Geometric Det type " << subdetgd[i]->type()
32  << " Geom Det type " << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]
33  << " detid " << subdetgd[i]->geographicalId()
34  << " subdetid " << subdetgd[i]->geographicalId().subdetId()
35  << " number of layers " << subdetgd[i]->components().size();
36  }
37  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
38  for(unsigned int i=1;i<7;++i) {
39  LogTrace("SubDetTypeMapContent") << " detid subdet "<< i << " Geom Det type " << geomDetSubDetector(i);
40  }
41  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
42  for(unsigned int i=1;i<7;++i) {
43  LogTrace("NumberOfLayers") << " detid subdet "<< i << " number of layers " << numberOfLayers(i);
44  }
45 
46 }
47 
48 
50  for (auto d : theDets) delete const_cast<GeomDet*>(d);
51  for (auto d : theDetTypes) delete const_cast<GeomDetType*>(d);
52 }
53 
55  theDetTypes.shrink_to_fit(); // owns the DetTypes
56  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
57  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
58  theDetUnitIds.shrink_to_fit();
59  theDetIds.shrink_to_fit();
60 
61  thePXBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
62  thePXFDets.shrink_to_fit(); // not owned: they're also in 'theDets'
63  theTIBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
64  theTIDDets.shrink_to_fit(); // not owned: they're also in 'theDets'
65  theTOBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
66  theTECDets.shrink_to_fit(); // not owned: they're also in 'theDets'
67 }
68 
69 
71  theDetTypes.push_back(p); // add to vector
72 }
73 
75  // set index
76  const_cast<GeomDetUnit *>(p)->setIndex(theDetUnits.size());
77  theDetUnits.push_back(p); // add to vector
78  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(),p));
79 }
80 
82  theDetUnitIds.push_back(p);
83 }
84 
86  theDets.push_back(p); // add to vector
87  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
88  DetId id(p->geographicalId());
89  switch(id.subdetId()){
91  thePXBDets.push_back(p);
92  break;
94  thePXFDets.push_back(p);
95  break;
97  theTIBDets.push_back(p);
98  break;
100  theTIDDets.push_back(p);
101  break;
103  theTOBDets.push_back(p);
104  break;
106  theTECDets.push_back(p);
107  break;
108  default:
109  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
110  }
111 
112 
113 }
114 
116  theDetIds.push_back(p);
117 }
118 
121 {
122  return theDetUnits;
123 }
124 
127 {
128  return theDets;
129 }
130 
133 {
134  return thePXBDets;
135 }
136 
139 {
140  return thePXFDets;
141 }
142 
145 {
146  return theTIBDets;
147 }
148 
151 {
152  return theTIDDets;
153 }
154 
157 {
158  return theTOBDets;
159 }
160 
163 {
164  return theTECDets;
165 }
166 
167 const TrackerGeomDet *
169 {
170  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
171  if (p != theMapUnit.end())
172  return static_cast<const TrackerGeomDet *>(p->second);
173  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDetUnit associated";
174  return nullptr;
175 }
176 
177 const TrackerGeomDet*
179 {
180  mapIdToDet::const_iterator p=theMap.find(s.rawId());
181  if (p != theMap.end())
182  return static_cast<const TrackerGeomDet *>(p->second);
183  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDet associated";
184  return nullptr;
185 }
186 
189  if(subdet>=1 && subdet<=6) {
190  return theSubDetTypeMap[subdet-1];
191  } else {
192  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
193  }
194 }
195 
196 unsigned int
198  if(subdet>=1 && subdet<=6) {
199  return theNumberOfLayers[subdet-1];
200  } else {
201  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
202  }
203 }
204 
205 bool
207  for(unsigned int i=1;i<7;++i) {
208  if(subdet == geomDetSubDetector(i)) return true;
209  }
210  return false;
211 }
212 
215 {
216  return theDetTypes;
217 }
218 
219 
222 {
223  return theDetUnitIds;
224 }
225 
228 {
229  return theDetIds;
230 }
231 
234  // provide a map between the GeometricDet enumerators and the GeomDet enumerators of the possible tracker subdetectors
236  if(gdenum == GeometricDet::GDEnumType::PixelEndCap) return GeomDetEnumerators::SubDetector::PixelEndcap;
241  if(gdenum == GeometricDet::GDEnumType::PixelPhase1Barrel) return GeomDetEnumerators::SubDetector::P1PXB;
242  if(gdenum == GeometricDet::GDEnumType::PixelPhase1EndCap) return GeomDetEnumerators::SubDetector::P1PXEC;
243  if(gdenum == GeometricDet::GDEnumType::PixelPhase2EndCap) return GeomDetEnumerators::SubDetector::P2PXEC;
244  if(gdenum == GeometricDet::GDEnumType::OTPhase2Barrel) return GeomDetEnumerators::SubDetector::P2OTB;
245  if(gdenum == GeometricDet::GDEnumType::OTPhase2EndCap) return GeomDetEnumerators::SubDetector::P2OTEC;
247 }
#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)
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
bool isThere(GeomDetEnumerators::SubDetector subdet) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
static const GeomDetEnumerators::SubDetector geometricDetToGeomDet(GeometricDet::GDEnumType gdenum)
#define LogTrace(id)
DetContainer theTIDDets
const DetContainer & detsTIB() const
std::vector< GeometricDet const * > ConstGeometricDetContainer
Definition: GeometricDet.h:36
Definition: DetId.h:18
DetContainer thePXBDets
DetContainer thePXFDets
void addDetUnitId(DetId p)
DetContainer theTIBDets
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)
const DetContainer & detsTID() const
virtual const TrackerGeomDet * idToDet(DetId) const
std::vector< DetId > DetIdContainer