CMS 3D CMS Logo

CmsMTDDetIdBuilder.cc
Go to the documentation of this file.
6 
7 #include <iostream>
8 #include <fstream>
9 #include <sstream>
10 #include <string>
11 #include <bitset>
12 
13 CmsMTDDetIdBuilder::CmsMTDDetIdBuilder(std::vector<int> detidShifts) : m_detidshifts() {
14  if (detidShifts.size() != nSubDet * maxLevels)
15  edm::LogError("WrongConfiguration") << "Wrong configuration of TrackerGeometricTimingDetESModule. Vector of "
16  << detidShifts.size() << " elements provided";
17  else {
18  for (unsigned int i = 0; i < nSubDet * maxLevels; ++i) {
19  m_detidshifts[i] = detidShifts[i];
20  }
21  }
22 }
23 
25  LogDebug("BuildingTrackerDetId") << "Starting to build MTD DetIds";
26 
28  mtd->setGeographicalID(t);
29  iterate(mtd, 0, mtd->geographicalID().rawId());
30 
31  return mtd;
32 }
33 
35  std::bitset<32> binary_ID(ID);
36 
37  // SubDetector (useful to know fron now on, valid only after level 0, where SubDetector is assigned)
38  uint32_t mask = (7 << 25);
39  uint32_t iSubDet = ID & mask;
40  iSubDet = iSubDet >> 25;
41  //
42 
43  LogTrace("BuildingTrackerDetId") << std::string(2 * level, '-') << "+" << ID << " " << iSubDet << " " << level;
44 
45  switch (level) {
46  // level 0: special case because it is used to assign the proper detid bits based on the endcap-like subdetector position: +z or -z
47  case 0: {
48  for (uint32_t i = 0; i < (in)->components().size(); i++) {
49  GeometricTimingDet* component = in->component(i);
50  uint32_t iSubDet = component->geographicalID().rawId();
51  uint32_t temp = ID;
52  temp |= (iSubDet << 25);
53  component->setGeographicalID(temp);
54 
55  if (iSubDet > 0 && iSubDet <= nSubDet && m_detidshifts[level * nSubDet + iSubDet - 1] >= 0) {
56  if (m_detidshifts[level * nSubDet + iSubDet - 1] + 2 < 25)
57  temp |= (0 << (m_detidshifts[level * nSubDet + iSubDet - 1] + 2));
58  bool negside = component->translation().z() < 0.;
59  if (std::abs(component->translation().z()) < 1.)
60  negside = component->components().front()->translation().z() <
61  0.; // needed for subdet like TID which are NOT translated
62  LogTrace("BuildingTrackerDetId")
63  << "Is negative endcap? " << negside << ", because z translation is " << component->translation().z()
64  << " and component z translation is " << component->components().front()->translation().z();
65  if (negside) {
66  temp |= (1 << m_detidshifts[level * nSubDet + iSubDet - 1]);
67  } else {
68  temp |= (2 << m_detidshifts[level * nSubDet + iSubDet - 1]);
69  }
70  }
71  component->setGeographicalID(DetId(temp));
72 
73  // next level
74  iterate(component, level + 1, ((in)->components())[i]->geographicalID().rawId());
75  }
76  break;
77  }
78  // level 1 to 5
79  default: {
80  for (uint32_t i = 0; i < (in)->components().size(); i++) {
81  auto component = in->component(i);
82  uint32_t temp = ID;
83 
84  if (level < maxLevels) {
85  if (iSubDet > 0 && iSubDet <= nSubDet && m_detidshifts[level * nSubDet + iSubDet - 1] >= 0) {
86  temp |= (component->geographicalID().rawId() << m_detidshifts[level * nSubDet + iSubDet - 1]);
87  }
88  component->setGeographicalID(temp);
89  // next level
90  iterate(component, level + 1, ((in)->components())[i]->geographicalID().rawId());
91  }
92  }
93 
94  break;
95  }
96  // level switch ends
97  }
98 
99  return;
100 }
#define LogDebug(id)
CmsMTDDetIdBuilder(std::vector< int > detidShifts)
uint32_t ID
Definition: Definitions.h:24
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
ConstGeometricTimingDetContainer & components()
void iterate(GeometricTimingDet *det, int level, unsigned int ID)
GeometricTimingDet * buildId(GeometricTimingDet *det)
GeometricTimingDet * component(size_t index)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
static const int maxLevels
void setGeographicalID(DetId id)
#define LogTrace(id)
Definition: DetId.h:17
DetId geographicalID() const
static const unsigned int nSubDet
std::array< int, nSubDet *maxLevels > m_detidshifts
Translation const & translation() const