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 int& topologyMode, const BTLValues& btl, const ETLValues& etl);
73 
74  int getMTDTopologyMode() const { return mtdTopologyMode_; }
75 
76  unsigned int side(const DetId &id) const;
77  unsigned int layer(const DetId &id) const;
78  unsigned int module(const DetId &id) const;
79  unsigned int tray(const DetId& id) const;
80  unsigned int ring(const DetId& id) const;
81 
82  //module
83  unsigned int btlModule(const DetId &id) const {
84  return ((id.rawId()>>btlVals_.moduleStartBit_)& btlVals_.moduleMask_);
85  }
86  unsigned int etlModule(const DetId &id) const {
87  return int((id.rawId()>>btlVals_.moduleStartBit_) & btlVals_.moduleMask_);
88  }
89 
90  //tray
91  unsigned int btlTray(const DetId &id) const {
92  return ((id.rawId()>>btlVals_.trayStartBit_) & btlVals_.trayMask_) ;
93  }
94 
95  // ring id
96  unsigned int etlRing(const DetId &id) const {
97  return ((id.rawId()>>etlVals_.ringStartBit_) & etlVals_.ringMask_) ;
98  }
99 
100  // layer numbers
101  unsigned int btlLayer(const DetId &id) const {
102  return int((id.rawId()>>btlVals_.layerStartBit_) & btlVals_.layerMask_);
103  }
104  unsigned int etlLayer(const DetId &id) const {
105  return int((id.rawId()>>etlVals_.layerStartBit_) & etlVals_.layerMask_);
106  }
107 
108  //side
109  unsigned int btlSide(const DetId &id) const {
110  return ((id.rawId()>>btlVals_.sideStartBit_)&btlVals_.sideMask_);
111  }
112 
113  unsigned int etlSide(const DetId &id) const {
114  return ((id.rawId()>>etlVals_.sideStartBit_)&etlVals_.sideMask_);
115  }
116 
117  // which disc is this ring on the forward or backward one?
118  unsigned int etlDisc(const DetId &id) const {
119  return int((id.rawId()>>etlVals_.ringStartBit_) & etlVals_.ringMask_)%2;
120  }
121 
122  //old constructors, now return DetId
123  DetId btlDetId(uint32_t side,
124  uint32_t layer,
125  uint32_t tray,
126  uint32_t module) const {
127  //uply
129  uint32_t rawid=id.rawId();
135  return DetId(rawid);
136  }
137 
138  DetId etlDetId(uint32_t side,
139  uint32_t layer,
140  uint32_t ring,
141  uint32_t module) const {
143  uint32_t rawid=id.rawId();
149  return DetId(rawid);
150  }
151 
152  std::pair<DetId, SameLayerComparator> btlDetIdLayerComparator(uint32_t side, uint32_t layer) const {
153  return std::make_pair(btlDetId(side, layer, 1,1), SameLayerComparator(this));
154  }
155 
156  std::pair<DetId, SameLayerComparator> etlDetIdDiskComparator(uint32_t side, uint32_t layer) const {
157  return std::make_pair(etlDetId(side, layer, 1,1), SameLayerComparator(this));
158  }
159 
160  std::string print(DetId detid) const;
161 
162  int getMTDLayerNumber(const DetId &id)const;
163 
164  // Extract the raw bit value for a given field type.
165  // E.g. getField(id, PBLadder) == pxbLadder(id)
166  unsigned int getField(const DetId &id, DetIdFields idx) const {
167  return ((id.rawId()>>bits_per_field[idx].startBit)&bits_per_field[idx].mask);
168  }
169  // checks whether a given field can be extracted from a given DetId.
170  // This boils down to checking whether it is the correct subdetector.
171  bool hasField(const DetId &id, DetIdFields idx) const {
172  return id.subdetId() == bits_per_field[idx].subdet;
173  }
174 
175  private:
176 
177  const int mtdTopologyMode_;
178 
181 
183  unsigned int startBit;
184  unsigned int mask;
185  int subdet;
186  };
188 };
189 
190 #endif
191 
unsigned int ringMask_
Definition: MTDTopology.h:39
const BitmaskAndSubdet bits_per_field[DETID_FIELDS_MAX]
Definition: MTDTopology.h:187
bool operator()(uint32_t i1, uint32_t i2) const
Definition: MTDTopology.h:64
MTDTopology(const int &topologyMode, const BTLValues &btl, const ETLValues &etl)
Definition: MTDTopology.cc:11
unsigned int btlTray(const DetId &id) const
Definition: MTDTopology.h:91
const MTDTopology * topo_
Definition: MTDTopology.h:68
std::string print(DetId detid) const
Definition: MTDTopology.cc:96
unsigned int module(const DetId &id) const
Definition: MTDTopology.cc:55
unsigned int sideStartBit_
Definition: MTDTopology.h:22
unsigned int layer(const DetId &id) const
Definition: MTDTopology.cc:42
unsigned int sideStartBit_
Definition: MTDTopology.h:33
unsigned int btlSide(const DetId &id) const
Definition: MTDTopology.h:109
int getMTDTopologyMode() const
Definition: MTDTopology.h:74
unsigned int etlDisc(const DetId &id) const
Definition: MTDTopology.h:118
unsigned int moduleMask_
Definition: MTDTopology.h:29
const ETLValues etlVals_
Definition: MTDTopology.h:180
unsigned int moduleStartBit_
Definition: MTDTopology.h:25
unsigned int btlModule(const DetId &id) const
Definition: MTDTopology.h:83
std::pair< DetId, SameLayerComparator > etlDetIdDiskComparator(uint32_t side, uint32_t layer) const
Definition: MTDTopology.h:156
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:171
unsigned int btlLayer(const DetId &id) const
Definition: MTDTopology.h:101
DetId btlDetId(uint32_t side, uint32_t layer, uint32_t tray, uint32_t module) const
Definition: MTDTopology.h:123
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:29
unsigned int sideMask_
Definition: MTDTopology.h:26
unsigned int tray(const DetId &id) const
Definition: MTDTopology.cc:68
unsigned int etlSide(const DetId &id) const
Definition: MTDTopology.h:113
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
unsigned int moduleMask_
Definition: MTDTopology.h:40
unsigned int getField(const DetId &id, DetIdFields idx) const
Definition: MTDTopology.h:166
unsigned int layerStartBit_
Definition: MTDTopology.h:23
unsigned int ring(const DetId &id) const
Definition: MTDTopology.cc:81
unsigned int etlModule(const DetId &id) const
Definition: MTDTopology.h:86
DetId etlDetId(uint32_t side, uint32_t layer, uint32_t ring, uint32_t module) const
Definition: MTDTopology.h:138
int getMTDLayerNumber(const DetId &id) const
Definition: MTDTopology.cc:135
std::pair< DetId, SameLayerComparator > btlDetIdLayerComparator(uint32_t side, uint32_t layer) const
Definition: MTDTopology.h:152
unsigned int sideMask_
Definition: MTDTopology.h:37
unsigned int etlRing(const DetId &id) const
Definition: MTDTopology.h:96
unsigned int layerMask_
Definition: MTDTopology.h:27
unsigned int layerMask_
Definition: MTDTopology.h:38
unsigned int etlLayer(const DetId &id) const
Definition: MTDTopology.h:104
const BTLValues btlVals_
Definition: MTDTopology.h:179
const int mtdTopologyMode_
Definition: MTDTopology.h:177
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39