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 
38 
39 
40 }
41 
42 
43 TrackerGeometry::TrackerGeometry(GeometricDet const* gd) : theTrackerDet(gd)
44 {
45  for(unsigned int i=0;i<6;++i) {
47  theNumberOfLayers[i] = 0;
48  }
50 
51  LogDebug("BuildingSubDetTypeMap") << "GeometriDet and GeomDetEnumerators enumerator values of the subdetectors";
52  for(unsigned int i=0;i<subdetgd.size();++i) {
53  assert(subdetgd[i]->geographicalId().subdetId()>0 && subdetgd[i]->geographicalId().subdetId()<7);
54  theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]= geometricDetToGeomDet(subdetgd[i]->type());
55  theNumberOfLayers[subdetgd[i]->geographicalId().subdetId()-1]= subdetgd[i]->components().size();
56  LogTrace("BuildingSubDetTypeMap") << "subdet " << i
57  << " Geometric Det type " << subdetgd[i]->type()
58  << " Geom Det type " << theSubDetTypeMap[subdetgd[i]->geographicalId().subdetId()-1]
59  << " detid " << subdetgd[i]->geographicalId()
60  << " subdetid " << subdetgd[i]->geographicalId().subdetId()
61  << " number of layers " << subdetgd[i]->components().size();
62  }
63  LogDebug("SubDetTypeMapContent") << "Content of theSubDetTypeMap";
64  for(unsigned int i=1;i<7;++i) {
65  LogTrace("SubDetTypeMapContent") << " detid subdet "<< i << " Geom Det type " << geomDetSubDetector(i);
66  }
67  LogDebug("NumberOfLayers") << "Content of theNumberOfLayers";
68  for(unsigned int i=1;i<7;++i) {
69  LogTrace("NumberOfLayers") << " detid subdet "<< i << " number of layers " << numberOfLayers(i);
70  }
71 
72 }
73 
74 
76  for (auto d : theDets) delete const_cast<GeomDet*>(d);
77  for (auto d : theDetTypes) delete const_cast<GeomDetType*>(d);
78 }
79 
81  theDetTypes.shrink_to_fit(); // owns the DetTypes
82  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
83  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
84  theDetUnitIds.shrink_to_fit();
85  theDetIds.shrink_to_fit();
86 
87  thePXBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
88  thePXFDets.shrink_to_fit(); // not owned: they're also in 'theDets'
89  theTIBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
90  theTIDDets.shrink_to_fit(); // not owned: they're also in 'theDets'
91  theTOBDets.shrink_to_fit(); // not owned: they're also in 'theDets'
92  theTECDets.shrink_to_fit(); // not owned: they're also in 'theDets'
93 }
94 
95 
97  theDetTypes.push_back(p); // add to vector
98 }
99 
101  // set index
102  const_cast<GeomDetUnit *>(p)->setIndex(theDetUnits.size());
103  theDetUnits.push_back(p); // add to vector
104  theMapUnit.insert(std::make_pair(p->geographicalId().rawId(),p));
105 }
106 
108  theDetUnitIds.push_back(p);
109 }
110 
112  theDets.push_back(p); // add to vector
113  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
114  DetId id(p->geographicalId());
115  switch(id.subdetId()){
117  thePXBDets.push_back(p);
118  break;
120  thePXFDets.push_back(p);
121  break;
123  theTIBDets.push_back(p);
124  break;
126  theTIDDets.push_back(p);
127  break;
129  theTOBDets.push_back(p);
130  break;
132  theTECDets.push_back(p);
133  break;
134  default:
135  edm::LogError("TrackerGeometry")<<"ERROR - I was expecting a Tracker Subdetector, I got a "<<id.subdetId();
136  }
137 
138 
139 }
140 
142  theDetIds.push_back(p);
143 }
144 
147 {
148  return theDetUnits;
149 }
150 
153 {
154  return theDets;
155 }
156 
159 {
160  return thePXBDets;
161 }
162 
165 {
166  return thePXFDets;
167 }
168 
171 {
172  return theTIBDets;
173 }
174 
177 {
178  return theTIDDets;
179 }
180 
183 {
184  return theTOBDets;
185 }
186 
189 {
190  return theTECDets;
191 }
192 
193 const TrackerGeomDet *
195 {
196  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
197  if (p != theMapUnit.end())
198  return static_cast<const TrackerGeomDet *>(p->second);
199  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDetUnit associated";
200  return nullptr;
201 }
202 
203 const TrackerGeomDet*
205 {
206  mapIdToDet::const_iterator p=theMap.find(s.rawId());
207  if (p != theMap.end())
208  return static_cast<const TrackerGeomDet *>(p->second);
209  edm::LogError("TrackerGeometry")<<"Invalid DetID: no GeomDet associated";
210  return nullptr;
211 }
212 
215  if(subdet>=1 && subdet<=6) {
216  return theSubDetTypeMap[subdet-1];
217  } else {
218  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
219  }
220 }
221 
222 unsigned int
224  if(subdet>=1 && subdet<=6) {
225  return theNumberOfLayers[subdet-1];
226  } else {
227  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
228  }
229 }
230 
231 bool
233  for(unsigned int i=1;i<7;++i) {
234  if(subdet == geomDetSubDetector(i)) return true;
235  }
236  return false;
237 }
238 
241 {
242  return theDetTypes;
243 }
244 
245 
248 {
249  return theDetUnitIds;
250 }
251 
254 {
255  return theDetIds;
256 }
#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
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
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:77
#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