CMS 3D CMS Logo

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