CMS 3D CMS Logo

MTDGeometry.cc
Go to the documentation of this file.
1 #include <typeinfo>
2 
8 
12 
15 
16 #include <algorithm>
17 #include <iostream>
18 #include <map>
19 
20 namespace {
22  geometricDetToGeomDet(GeometricTimingDet::GTDEnumType gdenum) {
23  // provide a map between the GeometricTimingDet enumerators and the GeomDet enumerators of the possible tracker subdetectors
24  if(gdenum == GeometricTimingDet::GTDEnumType::BTL ) return GeomDetEnumerators::SubDetector::TimingBarrel;
25  if(gdenum == GeometricTimingDet::GTDEnumType::ETL ) return GeomDetEnumerators::SubDetector::TimingEndcap;
27  }
28 
29  class DetIdComparator {
30  public:
31  bool operator()(GeometricTimingDet const* gd1, GeometricTimingDet const * gd2) const {
32  uint32_t det1 = gd1->geographicalId();
33  uint32_t det2 = gd2->geographicalId();
34  return det1 < det2;
35  }
36  };
37 }
38 
40  : theTrackerDet(gd)
41 {
42  for(unsigned int i=0;i<2;++i) {
44  theNumberOfLayers[i] = 0;
45  }
47 
48  LogDebug("BuildingSubDetTypeMap")
49  << "GeometricTimingDet and GeomDetEnumerators enumerator values of the subdetectors" << std::endl;
50  for(unsigned int i=0;i<subdetgd.size();++i) {
51  MTDDetId mtdid(subdetgd[i]->geographicalId());
52  assert(mtdid.mtdSubDetector()>0 && mtdid.mtdSubDetector()<3);
53  theSubDetTypeMap[mtdid.mtdSubDetector()-1] = geometricDetToGeomDet(subdetgd[i]->type());
54  theNumberOfLayers[mtdid.mtdSubDetector()-1]= subdetgd[i]->components().size();
55  LogTrace("BuildingSubDetTypeMap").log( [&](auto & debugstr) {
56  debugstr << "subdet " << i
57  << " Geometric Det type " << subdetgd[i]->type()
58  << " Geom Det type " << theSubDetTypeMap[mtdid.mtdSubDetector()-1]
59  << " detid " << std::hex << subdetgd[i]->geographicalId().rawId() << std::dec
60  << " subdetid " << mtdid.mtdSubDetector()
61  << " number of layers " << subdetgd[i]->components().size()
62  << std::endl;
63  });
64  }
65  LogDebug("SubDetTypeMapContent").log( [&](auto & debugstr) {
66  debugstr << "Content of theSubDetTypeMap" << std::endl;
67  for(unsigned int i=1;i<=2;++i) {
68  debugstr << " detid subdet "<< i
69  << " Geom Det type "<< geomDetSubDetector(i) << std::endl;
70  }
71  });
72  LogDebug("NumberOfLayers").log( [&](auto & debugstr) {
73  debugstr << "Content of theNumberOfLayers" << std::endl;
74  for(unsigned int i=1;i<=2;++i) {
75  debugstr << " detid subdet "<< i
76  << " number of layers " << numberOfLayers(i) << std::endl;
77  }
78  });
79  std::vector<const GeometricTimingDet*> deepcomp;
80  gd->deepComponents(deepcomp);
81 
82  sort(deepcomp.begin(), deepcomp.end(), DetIdComparator());
83 
84  LogDebug("ThicknessAndType")
85  << " Total Number of Detectors " << deepcomp.size() << std::endl;
86  LogDebug("ThicknessAndType")
87  << "Dump of sensors names and bounds" << std::endl;
88  LogDebug("ThicknessAndType").log( [&](auto & debugstr) {
89  for(auto det : deepcomp) {
90  fillTestMap(det);
91  debugstr << std::hex << det->geographicalId().rawId() << std::dec
92  << " " << det->name().fullname() << " "
93  << det->bounds()->thickness();
94  }
95  });
96  LogDebug("DetTypeList").log( [&](auto & debugstr) {
97  debugstr << " Content of DetTypetList : size " << theDetTypetList.size() << std::endl;
98  for (auto iVal : theDetTypetList) {
99  debugstr
100  << " DetId " << std::get<0>(iVal).rawId()
101  << " Type " << static_cast<std::underlying_type<MTDGeometry::ModuleType>::type>(std::get<1>(iVal))
102  << " Thickness " << std::get<2>(iVal) << std::endl;
103  }
104  });
105 }
106 
108  for (auto d : theDets) delete const_cast<GeomDet*>(d);
109  for (auto d : theDetTypes) delete const_cast<GeomDetType*>(d);
110 }
111 
113  theDetTypes.shrink_to_fit(); // owns the DetTypes
114  theDetUnits.shrink_to_fit(); // they're all also into 'theDets', so we assume 'theDets' owns them
115  theDets.shrink_to_fit(); // owns *ONLY* the GeomDet * corresponding to GluedDets.
116  theDetUnitIds.shrink_to_fit();
117  theDetIds.shrink_to_fit();
118 
119  theBTLDets.shrink_to_fit(); // not owned: they're also in 'theDets'
120  theETLDets.shrink_to_fit(); // not owned: they're also in 'theDets'
121 }
122 
124  theDetTypes.emplace_back(p); // add to vector
125 }
126 
128  // set index
129  const_cast<GeomDet *>(p)->setIndex(theDetUnits.size());
130  theDetUnits.emplace_back(p); // add to vector
131  theMapUnit.emplace(p->geographicalId().rawId(),p);
132 }
133 
135  theDetUnitIds.emplace_back(p);
136 }
137 
139  // set index
140  const_cast<GeomDet *>(p)->setGdetIndex(theDets.size());
141  theDets.emplace_back(p); // add to vector
142  theMap.insert(std::make_pair(p->geographicalId().rawId(),p));
143  MTDDetId id(p->geographicalId());
144  switch(id.mtdSubDetector()){
145  case MTDDetId::BTL:
146  theBTLDets.emplace_back(p);
147  break;
148  case MTDDetId::ETL:
149  theETLDets.emplace_back(p);
150  break;
151  default:
152  edm::LogError("MTDGeometry")<<"ERROR - I was expecting a MTD Subdetector, I got a "<<id.mtdSubDetector();
153  }
154 }
155 
157  theDetIds.emplace_back(p);
158 }
159 
160 
163 {
164  return theBTLDets;
165 }
166 
169 {
170  return theETLDets;
171 }
172 
173 const MTDGeomDet *
175 {
176  mapIdToDetUnit::const_iterator p=theMapUnit.find(s.rawId());
177  if (p != theMapUnit.end()) {
178  return static_cast<const MTDGeomDet *>(p->second);
179  }
180  return nullptr;
181 }
182 
183 const MTDGeomDet*
185 {
186  mapIdToDet::const_iterator p=theMap.find(s.rawId());
187  if (p != theMap.end()) {
188  return static_cast<const MTDGeomDet *>(p->second);
189  }
190  return nullptr;
191 }
192 
195  if(subdet>=1 && subdet<=2) {
196  return theSubDetTypeMap[subdet-1];
197  } else {
198  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
199  }
200 }
201 
202 unsigned int
203 MTDGeometry::numberOfLayers(int subdet) const {
204  if(subdet>=1 && subdet<=2) {
205  return theNumberOfLayers[subdet-1];
206  } else {
207  throw cms::Exception("WrongTrackerSubDet") << "Subdetector " << subdet;
208  }
209 }
210 
211 bool
213  for(unsigned int i=1;i<=2;++i) {
214  if(subdet == geomDetSubDetector(i)) return true;
215  }
216  return false;
217 }
218 
220 
221  std::string temp = gd->name().fullname();
222  std::string name = temp.substr(temp.find(":")+1);
223  DetId detid = gd->geographicalId();
224  float thickness = gd->bounds()->thickness();
225  std::string nameTag;
226  MTDGeometry::ModuleType mtype = moduleType(name);
227  if (theDetTypetList.empty()) {
228  theDetTypetList.emplace_back(detid, mtype, thickness);
229  } else {
230  auto & t = (*(theDetTypetList.end()-1));
231  if (std::get<1>(t) != mtype) theDetTypetList.emplace_back(detid, mtype, thickness);
232  else {
233  if ( detid > std::get<0>(t) ) std::get<0>(t) = detid;
234  }
235  }
236 }
237 
239  for (auto iVal : theDetTypetList) {
240  DetId detid_max = std::get<0>(iVal);
241  MTDGeometry::ModuleType mtype = std::get<1>(iVal);
242  if (detid.rawId() <= detid_max.rawId()) return mtype;
243  }
245 }
246 
248  for (auto iVal : theDetTypetList) {
249  DetId detid_max = std::get<0>(iVal);
250  if (detid.rawId() <= detid_max.rawId())
251  return std::get<2>(iVal);
252  }
253  return -1.0;
254 }
255 
257  if ( name.find("Timing") != std::string::npos ){
258  if ( name.find("BModule") != std::string::npos ) return ModuleType::BTL;
259  else if ( name.find("EModule") != std::string::npos ) return ModuleType::ETL;
260  }
261  return ModuleType::UNKNOWN;
262 }
#define LogDebug(id)
type
Definition: HCALResponse.h:21
MTDGeometry(GeometricTimingDet const *gd=0)
Definition: MTDGeometry.cc:39
DetIdContainer theDetUnitIds
Definition: MTDGeometry.h:80
DetContainer theBTLDets
Definition: MTDGeometry.h:85
DetTypeContainer theDetTypes
Definition: MTDGeometry.h:75
const DetContainer & detsETL() const
Definition: MTDGeometry.cc:168
DetContainer theDetUnits
Definition: MTDGeometry.h:76
DetId geographicalId() const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:50
void addType(GeomDetType const *p)
Definition: MTDGeometry.cc:123
unsigned int theNumberOfLayers[2]
Definition: MTDGeometry.h:89
void addDetId(DetId p)
Definition: MTDGeometry.cc:156
DetContainer theDets
Definition: MTDGeometry.h:79
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
mapIdToDet theMap
Definition: MTDGeometry.h:83
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:184
ConstGeometricTimingDetContainer & components()
DetIdContainer theDetIds
Definition: MTDGeometry.h:81
ModuleType moduleType(const std::string &name) const
Definition: MTDGeometry.cc:256
std::unique_ptr< Bounds > bounds() const
void finalize()
Definition: MTDGeometry.cc:112
ConstGeometricTimingDetContainer deepComponents() const
const std::string fullname() const
Definition: DDName.h:43
mapIdToDetUnit theMapUnit
Definition: MTDGeometry.h:82
bool isThere(GeomDetEnumerators::SubDetector subdet) const
Definition: MTDGeometry.cc:212
unsigned int numberOfLayers(int subdet) const
Definition: MTDGeometry.cc:203
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:79
#define LogTrace(id)
const DetContainer & detsBTL() const
Definition: MTDGeometry.cc:162
Definition: DetId.h:18
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
Definition: MTDGeometry.cc:194
DDName const & name() const
void addDet(GeomDet const *p)
Definition: MTDGeometry.cc:138
void addDetUnitId(DetId p)
Definition: MTDGeometry.cc:134
void fillTestMap(const GeometricTimingDet *gd)
Definition: MTDGeometry.cc:219
GeomDetEnumerators::SubDetector theSubDetTypeMap[2]
Definition: MTDGeometry.h:88
std::vector< const GeomDet * > DetContainer
~MTDGeometry() override
Definition: MTDGeometry.cc:107
int mtdSubDetector() const
Definition: MTDDetId.h:58
float getDetectorThickness(DetId) const
Definition: MTDGeometry.cc:247
DetContainer theETLDets
Definition: MTDGeometry.h:86
ModuleType getDetectorType(DetId) const
Definition: MTDGeometry.cc:238
std::vector< std::tuple< DetId, MTDGeometry::ModuleType, float > > theDetTypetList
Definition: MTDGeometry.h:90
std::vector< GeometricTimingDet const * > ConstGeometricTimingDetContainer
void addDetUnit(GeomDet const *p)
Definition: MTDGeometry.cc:127
const MTDGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: MTDGeometry.cc:174