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