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