CMS 3D CMS Logo

MTDTopology.h
Go to the documentation of this file.
1 #ifndef MTDTOPOLOGY_H
2 #define MTDTOPOLOGY_H
3 
7 
8 #include <vector>
9 #include <string>
10 
11 //knower of all things tracker geometry
12 //flexible replacement for PXBDetId and friends
13 //to implement
14 // endcap pixel
15 
16 
17 class MTDTopology {
18 
19  public:
20 
21  struct BTLValues {
22  unsigned int sideStartBit_;
23  unsigned int layerStartBit_;
24  unsigned int trayStartBit_;
25  unsigned int moduleStartBit_;
26  unsigned int sideMask_;
27  unsigned int layerMask_;
28  unsigned int trayMask_;
29  unsigned int moduleMask_;
30  };
31 
32  struct ETLValues {
33  unsigned int sideStartBit_;
34  unsigned int layerStartBit_;
35  unsigned int ringStartBit_;
36  unsigned int moduleStartBit_;
37  unsigned int sideMask_;
38  unsigned int layerMask_;
39  unsigned int ringMask_;
40  unsigned int moduleMask_;
41  };
42 
43  enum DetIdFields {
46  /* TODO: this can be extended for all subdetectors */
48  };
49 
51  public:
52  explicit SameLayerComparator(const MTDTopology *topo): topo_(topo) {}
53 
54  bool operator()(DetId i1, DetId i2) const {
55  if(i1.det() == i2.det() &&
56  i1.subdetId() == i2.subdetId() &&
57  topo_->side(i1) == topo_->side(i2) &&
58  topo_->layer(i1) == topo_->layer(i2)) {
59  return false;
60  }
61  return i1 < i2;
62  }
63 
64  bool operator()(uint32_t i1, uint32_t i2) const {
65  return operator()(DetId(i1), DetId(i2));
66  }
67  private:
69  };
70 
71 
72  MTDTopology( const BTLValues& btl, const ETLValues& etl);
73 
74  unsigned int side(const DetId &id) const;
75  unsigned int layer(const DetId &id) const;
76  unsigned int module(const DetId &id) const;
77  unsigned int tray(const DetId& id) const;
78  unsigned int ring(const DetId& id) const;
79 
80  //module
81  unsigned int btlModule(const DetId &id) const {
82  return ((id.rawId()>>btlVals_.moduleStartBit_)& btlVals_.moduleMask_);
83  }
84  unsigned int etlModule(const DetId &id) const {
85  return int((id.rawId()>>btlVals_.moduleStartBit_) & btlVals_.moduleMask_);
86  }
87 
88  //tray
89  unsigned int btlTray(const DetId &id) const {
90  return ((id.rawId()>>btlVals_.trayStartBit_) & btlVals_.trayMask_) ;
91  }
92 
93  // ring id
94  unsigned int etlRing(const DetId &id) const {
95  return ((id.rawId()>>etlVals_.ringStartBit_) & etlVals_.ringMask_) ;
96  }
97 
98  // layer numbers
99  unsigned int btlLayer(const DetId &id) const {
100  return int((id.rawId()>>btlVals_.layerStartBit_) & btlVals_.layerMask_);
101  }
102  unsigned int etlLayer(const DetId &id) const {
103  return int((id.rawId()>>etlVals_.layerStartBit_) & etlVals_.layerMask_);
104  }
105 
106  //side
107  unsigned int btlSide(const DetId &id) const {
108  return ((id.rawId()>>btlVals_.sideStartBit_)&btlVals_.sideMask_);
109  }
110 
111  unsigned int etlSide(const DetId &id) const {
112  return ((id.rawId()>>etlVals_.sideStartBit_)&etlVals_.sideMask_);
113  }
114 
115  // which disc is this ring on the forward or backward one?
116  unsigned int etlDisc(const DetId &id) const {
117  return int((id.rawId()>>etlVals_.ringStartBit_) & etlVals_.ringMask_)%2;
118  }
119 
120  //old constructors, now return DetId
121  DetId btlDetId(uint32_t side,
122  uint32_t layer,
123  uint32_t tray,
124  uint32_t module) const {
125  //uply
127  uint32_t rawid=id.rawId();
133  return DetId(rawid);
134  }
135 
136  DetId etlDetId(uint32_t side,
137  uint32_t layer,
138  uint32_t ring,
139  uint32_t module) const {
141  uint32_t rawid=id.rawId();
147  return DetId(rawid);
148  }
149 
150  std::pair<DetId, SameLayerComparator> btlDetIdLayerComparator(uint32_t side, uint32_t layer) const {
151  return std::make_pair(btlDetId(side, layer, 1,1), SameLayerComparator(this));
152  }
153 
154  std::pair<DetId, SameLayerComparator> etlDetIdDiskComparator(uint32_t side, uint32_t layer) const {
155  return std::make_pair(etlDetId(side, layer, 1,1), SameLayerComparator(this));
156  }
157 
158  std::string print(DetId detid) const;
159 
160  int getMTDLayerNumber(const DetId &id)const;
161 
162  // Extract the raw bit value for a given field type.
163  // E.g. getField(id, PBLadder) == pxbLadder(id)
164  unsigned int getField(const DetId &id, DetIdFields idx) const {
165  return ((id.rawId()>>bits_per_field[idx].startBit)&bits_per_field[idx].mask);
166  }
167  // checks whether a given field can be extracted from a given DetId.
168  // This boils down to checking whether it is the correct subdetector.
169  bool hasField(const DetId &id, DetIdFields idx) const {
170  return id.subdetId() == bits_per_field[idx].subdet;
171  }
172 
173  private:
174 
177 
179  unsigned int startBit;
180  unsigned int mask;
181  int subdet;
182  };
184 };
185 
186 #endif
187 
unsigned int ringMask_
Definition: MTDTopology.h:39
const BitmaskAndSubdet bits_per_field[DETID_FIELDS_MAX]
Definition: MTDTopology.h:183
bool operator()(uint32_t i1, uint32_t i2) const
Definition: MTDTopology.h:64
unsigned int btlTray(const DetId &id) const
Definition: MTDTopology.h:89
const MTDTopology * topo_
Definition: MTDTopology.h:68
std::string print(DetId detid) const
Definition: MTDTopology.cc:95
unsigned int module(const DetId &id) const
Definition: MTDTopology.cc:54
unsigned int sideStartBit_
Definition: MTDTopology.h:22
unsigned int layer(const DetId &id) const
Definition: MTDTopology.cc:41
unsigned int sideStartBit_
Definition: MTDTopology.h:33
unsigned int btlSide(const DetId &id) const
Definition: MTDTopology.h:107
unsigned int etlDisc(const DetId &id) const
Definition: MTDTopology.h:116
unsigned int moduleMask_
Definition: MTDTopology.h:29
const ETLValues etlVals_
Definition: MTDTopology.h:176
unsigned int moduleStartBit_
Definition: MTDTopology.h:25
unsigned int btlModule(const DetId &id) const
Definition: MTDTopology.h:81
std::pair< DetId, SameLayerComparator > etlDetIdDiskComparator(uint32_t side, uint32_t layer) const
Definition: MTDTopology.h:154
unsigned int layerStartBit_
Definition: MTDTopology.h:34
static const uint32_t kMTDsubdOffset
Definition: MTDDetId.h:31
unsigned int trayMask_
Definition: MTDTopology.h:28
bool hasField(const DetId &id, DetIdFields idx) const
Definition: MTDTopology.h:169
unsigned int btlLayer(const DetId &id) const
Definition: MTDTopology.h:99
DetId btlDetId(uint32_t side, uint32_t layer, uint32_t tray, uint32_t module) const
Definition: MTDTopology.h:121
unsigned int moduleStartBit_
Definition: MTDTopology.h:36
SameLayerComparator(const MTDTopology *topo)
Definition: MTDTopology.h:52
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
unsigned int side(const DetId &id) const
Definition: MTDTopology.cc:28
unsigned int sideMask_
Definition: MTDTopology.h:26
unsigned int tray(const DetId &id) const
Definition: MTDTopology.cc:67
unsigned int etlSide(const DetId &id) const
Definition: MTDTopology.h:111
Definition: DetId.h:18
unsigned int trayStartBit_
Definition: MTDTopology.h:24
bool operator()(DetId i1, DetId i2) const
Definition: MTDTopology.h:54
unsigned int ringStartBit_
Definition: MTDTopology.h:35
MTDTopology(const BTLValues &btl, const ETLValues &etl)
Definition: MTDTopology.cc:11
unsigned int moduleMask_
Definition: MTDTopology.h:40
unsigned int getField(const DetId &id, DetIdFields idx) const
Definition: MTDTopology.h:164
unsigned int layerStartBit_
Definition: MTDTopology.h:23
unsigned int ring(const DetId &id) const
Definition: MTDTopology.cc:80
unsigned int etlModule(const DetId &id) const
Definition: MTDTopology.h:84
DetId etlDetId(uint32_t side, uint32_t layer, uint32_t ring, uint32_t module) const
Definition: MTDTopology.h:136
int getMTDLayerNumber(const DetId &id) const
Definition: MTDTopology.cc:134
std::pair< DetId, SameLayerComparator > btlDetIdLayerComparator(uint32_t side, uint32_t layer) const
Definition: MTDTopology.h:150
unsigned int sideMask_
Definition: MTDTopology.h:37
unsigned int etlRing(const DetId &id) const
Definition: MTDTopology.h:94
unsigned int layerMask_
Definition: MTDTopology.h:27
unsigned int layerMask_
Definition: MTDTopology.h:38
unsigned int etlLayer(const DetId &id) const
Definition: MTDTopology.h:102
const BTLValues btlVals_
Definition: MTDTopology.h:175
Definition: vlib.h:208
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39