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 {
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 }
GeomDetEnumerators::SubDetector
SubDetector
Definition: GeomDetEnumerators.h:10
MTDGeometry::getDetectorThickness
float getDetectorThickness(DetId) const
Definition: MTDGeometry.cc:233
BTLDetId.h
mps_fire.i
i
Definition: mps_fire.py:355
MTDGeometry::addType
void addType(GeomDetType const *p)
Definition: MTDGeometry.cc:126
MessageLogger.h
GeomDet
Definition: GeomDet.h:27
MTDGeometry::ModuleType::UNKNOWN
MTDGeometry::numberOfLayers
unsigned int numberOfLayers(int subdet) const
Definition: MTDGeometry.cc:187
GeomDetEnumerators::invalidDet
Definition: GeomDetEnumerators.h:31
MTDGeometry::theNumberOfLayers
unsigned int theNumberOfLayers[2]
Definition: MTDGeometry.h:86
MTDGeometry::addDetUnit
void addDetUnit(GeomDet const *p)
Definition: MTDGeometry.cc:130
AlCaHLTBitMon_ParallelJobs.p
p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
MTDGeometry::addDetId
void addDetId(DetId p)
Definition: MTDGeometry.cc:157
MTDGeometry::theDets
DetContainer theDets
Definition: MTDGeometry.h:76
edm::LogInfo
Definition: MessageLogger.h:254
MTDGeometry.h
TrackerGeomDet
Definition: TrackerGeomDet.h:6
GeomDetType.h
GeomDetType
Definition: GeomDetType.h:9
cms::cuda::assert
assert(be >=bs)
GeometricTimingDet::ConstGeometricTimingDetContainer
std::vector< GeometricTimingDet const * > ConstGeometricTimingDetContainer
Definition: GeometricTimingDet.h:31
hcal_dqm_sourceclient-live_cfg.debugstr
debugstr
Definition: hcal_dqm_sourceclient-live_cfg.py:18
GeometricTimingDet::name
std::string const & name() const
Definition: GeometricTimingDet.h:105
MTDGeometry::theDetUnits
DetContainer theDetUnits
Definition: MTDGeometry.h:73
MTDGeometry::theDetUnitIds
DetIdContainer theDetUnitIds
Definition: MTDGeometry.h:77
MTDGeometry::moduleType
ModuleType moduleType(const std::string &name) const
Definition: MTDGeometry.cc:242
ETLDetId.h
GeometricTimingDet::bounds
std::unique_ptr< Bounds > bounds() const
Definition: GeometricTimingDet.cc:257
groupFilesInBlocks.temp
list temp
Definition: groupFilesInBlocks.py:142
MTDGeometry::idToDetUnit
const MTDGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
Definition: MTDGeometry.cc:163
MTDGeometry::isThere
bool isThere(GeomDetEnumerators::SubDetector subdet) const
Definition: MTDGeometry.cc:195
MTDGeometry::ModuleType::BTL
MTDGeometry::detsETL
const DetContainer & detsETL() const
Definition: MTDGeometry.cc:161
DetId
Definition: DetId.h:17
MTDGeometry::geomDetSubDetector
const GeomDetEnumerators::SubDetector geomDetSubDetector(int subdet) const
Definition: MTDGeometry.cc:179
MTDGeometry::theMapUnit
mapIdToDetUnit theMapUnit
Definition: MTDGeometry.h:79
alignCSCRings.s
s
Definition: alignCSCRings.py:92
MTDGeometry::idToDet
const MTDGeomDet * idToDet(DetId) const override
Definition: MTDGeometry.cc:171
MTDGeometry::MTDGeometry
MTDGeometry(GeometricTimingDet const *gd=nullptr)
Definition: MTDGeometry.cc:42
GeometricTimingDet::GTDEnumType
GTDEnumType
Definition: GeometricTimingDet.h:50
Calorimetry_cff.thickness
thickness
Definition: Calorimetry_cff.py:114
GeomDetEnumerators::TimingBarrel
Definition: GeomDetEnumerators.h:29
OrderedSet.t
t
Definition: OrderedSet.py:90
MTDGeometry::getDetectorType
ModuleType getDetectorType(DetId) const
Definition: MTDGeometry.cc:223
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
MTDGeometry::theMap
mapIdToDet theMap
Definition: MTDGeometry.h:80
MTDDetId::mtdSubDetector
int mtdSubDetector() const
Definition: MTDDetId.h:56
MTDGeometry::finalize
void finalize()
Definition: MTDGeometry.cc:115
MTDGeometry::ModuleType::ETL
edm::LogError
Definition: MessageLogger.h:183
MTDGeometry::theDetIds
DetIdContainer theDetIds
Definition: MTDGeometry.h:78
MTDDetId.h
TrackingGeometry::DetContainer
std::vector< const GeomDet * > DetContainer
Definition: TrackingGeometry.h:29
GeometricTimingDet::components
ConstGeometricTimingDetContainer & components()
Definition: GeometricTimingDet.h:120
MTDGeometry::fillTestMap
void fillTestMap(const GeometricTimingDet *gd)
Definition: MTDGeometry.cc:203
GeometricTimingDet
Definition: GeometricTimingDet.h:28
edm::LogInfo::log
LogInfo & log(F &&iF)
Definition: MessageLogger.h:282
GeometricTimingDet::geographicalId
DetId geographicalId() const
Definition: GeometricTimingDet.h:135
GeomDetEnumerators::TimingEndcap
Definition: GeomDetEnumerators.h:30
MTDGeometry::addDet
void addDet(GeomDet const *p)
Definition: MTDGeometry.cc:139
MTDGeometry::theETLDets
DetContainer theETLDets
Definition: MTDGeometry.h:83
GeomDet.h
MTDDetId::BTL
Definition: MTDDetId.h:27
type
type
Definition: HCALResponse.h:21
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
GeometricTimingDet.h
DetId.h
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
MTDDetId::ETL
Definition: MTDDetId.h:27
MTDDetId
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
Exception
Definition: hltDiff.cc:246
MTDGeometry::addDetUnitId
void addDetUnitId(DetId p)
Definition: MTDGeometry.cc:137
Skims_PA_cff.name
name
Definition: Skims_PA_cff.py:17
MTDGeometry::theSubDetTypeMap
GeomDetEnumerators::SubDetector theSubDetTypeMap[2]
Definition: MTDGeometry.h:85
Exception.h
GeometricTimingDet::deepComponents
ConstGeometricTimingDetContainer deepComponents() const
Definition: GeometricTimingDet.cc:197
MTDGeometry::~MTDGeometry
~MTDGeometry() override
Definition: MTDGeometry.cc:108
ztail.d
d
Definition: ztail.py:151
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:671
MTDGeometry::ModuleType
ModuleType
Definition: MTDGeometry.h:18
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
MTDGeometry::theBTLDets
DetContainer theBTLDets
Definition: MTDGeometry.h:82
MTDGeometry::theDetTypetList
std::vector< std::tuple< DetId, MTDGeometry::ModuleType, float > > theDetTypetList
Definition: MTDGeometry.h:87
MTDGeometry::theDetTypes
DetTypeContainer theDetTypes
Definition: MTDGeometry.h:72
MTDGeometry::detsBTL
const DetContainer & detsBTL() const
Definition: MTDGeometry.cc:159