CMS 3D CMS Logo

GEMDetId.h
Go to the documentation of this file.
1 #ifndef DataFormats_MuonDetId_GEMDetId_h
2 #define DataFormats_MuonDetId_GEMDetId_h
3 
13 
14 #include <iosfwd>
15 #include <iostream>
16 
17 class GEMDetId : public DetId {
18 public:
19  static constexpr int32_t minRegionId = -1;
20  static constexpr int32_t maxRegionId = 1;
21  static constexpr int32_t minRingId = 1;
22  static constexpr int32_t maxRingId = 3;
23  static constexpr int32_t minStationId0 = 0;
24  static constexpr int32_t minStationId = 1;
25  // in the detId there is space to go up to 5 stations. Only 3 implemented now (0,1,2)
26  static constexpr int32_t maxStationId = 2;
27  static constexpr int32_t minChamberId = 0;
28  static constexpr int32_t maxChamberId = 36;
29  static constexpr int32_t minLayerId = 0; // LayerId = 0 is superChamber
30  static constexpr int32_t maxLayerId0 = 6;
31  static constexpr int32_t maxLayerId = 2; // GE1/GE2 has 2 layers
32  static constexpr int32_t minRollId = 0;
33  static constexpr int32_t maxRollId = 15;
34 
35 private:
36  static constexpr uint32_t RegionNumBits = 2;
37  static constexpr uint32_t RegionStartBit = 0;
38  static constexpr uint32_t RegionMask = 0x3;
39  static constexpr uint32_t RingNumBits = 3;
40  static constexpr uint32_t RingStartBit = RegionStartBit + RegionNumBits;
41  static constexpr uint32_t RingMask = 0x7;
42  static constexpr uint32_t StationNumBits = 3;
43  static constexpr uint32_t StationStartBit = RingStartBit + RingNumBits;
44  static constexpr uint32_t StationMask = 0x7;
45  static constexpr uint32_t ChamberNumBits = 6;
46  static constexpr uint32_t ChamberStartBit = StationStartBit + StationNumBits;
47  static constexpr uint32_t ChamberStartBitM = RegionStartBit + RegionNumBits;
48  static constexpr uint32_t ChamberMask = 0x3F;
49  static constexpr uint32_t LayerNumBits = 5;
50  static constexpr uint32_t LayerNumBitsP = 2;
51  static constexpr uint32_t LayerStartBit = ChamberStartBit + ChamberNumBits;
52  static constexpr uint32_t LayerStartBitM = ChamberStartBitM + ChamberNumBits;
53  static constexpr uint32_t LayerMask = 0x1F;
54  static constexpr uint32_t LayerMaskP = 0x3;
55  static constexpr uint32_t RollNumBits = 5;
56  static constexpr uint32_t RollStartBit = LayerStartBit + LayerNumBits;
57  static constexpr uint32_t RollStartBitP = LayerStartBit + LayerNumBitsP;
58  static constexpr uint32_t RollStartBitM = LayerStartBitM + LayerNumBits;
59  static constexpr uint32_t RollMask = 0x1F;
60  static constexpr uint32_t FormatNumBits = 1;
61  static constexpr uint32_t FormatStartBit = RollStartBit + RollNumBits;
62  static constexpr uint32_t FormatMask = 0x1;
63  static constexpr uint32_t kGEMIdFormat = 0x1000000;
64  static constexpr uint32_t kMuonIdMask = 0xF0000000;
65  static constexpr uint32_t chamberIdMask = ~(RollMask << RollStartBit);
66  static constexpr uint32_t superChamberIdMask = chamberIdMask + ~(LayerMask << LayerStartBit);
67 
68 public:
73  constexpr GEMDetId(uint32_t id) : DetId(id) {
75  throw cms::Exception("InvalidDetId")
76  << "GEMDetId ctor: det: " << det() << " subdet: " << subdetId() << " is not a valid GEM id\n";
77 
78  if (v11Format())
79  id_ = v12Form(id);
80  }
84  throw cms::Exception("InvalidDetId")
85  << "GEMDetId ctor: det: " << det() << " subdet: " << subdetId() << " is not a valid GEM id\n";
86  if (v11Format())
87  id_ = v12Form(id.rawId());
88  }
90  constexpr GEMDetId(int region, int ring, int station, int layer, int chamber, int roll)
92  if (region < minRegionId || region > maxRegionId || ring < minRingId || ring > maxRingId ||
93  station < minStationId0 || station > maxStationId || layer < minLayerId || layer > maxLayerId0 ||
94  chamber < minChamberId || chamber > maxChamberId || roll < minRollId || roll > maxRollId)
95  throw cms::Exception("InvalidDetId")
96  << "GEMDetId ctor: Invalid parameters: region " << region << " ring " << ring << " station " << station
97  << " layer " << layer << " chamber " << chamber << " roll " << roll << std::endl;
98 
99  int regionInBits = region - minRegionId;
100  int ringInBits = ring - minRingId;
101  int stationInBits = station - minStationId0;
102  int layerInBits = layer - minLayerId;
103  int chamberInBits = chamber - (minChamberId + 1);
104  int rollInBits = roll;
105 
106  id_ |= ((regionInBits & RegionMask) << RegionStartBit | (ringInBits & RingMask) << RingStartBit |
107  (stationInBits & StationMask) << StationStartBit | (layerInBits & LayerMask) << LayerStartBit |
108  (chamberInBits & ChamberMask) << ChamberStartBit | (rollInBits & RollMask) << RollStartBit | kGEMIdFormat);
109  }
110 
113  if (!gen.null()) {
114  int subdet = gen.subdetId();
115  if (gen.det() != Muon || (subdet != MuonSubdetId::GEM && subdet != MuonSubdetId::ME0))
116  throw cms::Exception("InvalidDetId")
117  << "GEMDetId ctor: Cannot assign GEMDetID from " << std::hex << gen.rawId() << std::dec;
118  if (v11Format())
119  id_ = v12Form(gen.rawId());
120  else
121  id_ = gen.rawId();
122  } else {
123  id_ = gen.rawId();
124  }
125  return (*this);
126  }
127 
129  constexpr bool operator==(const GEMDetId& gen) const {
130  uint32_t rawid = gen.rawId();
131  if (rawid == id_)
132  return true;
133  int reg(0), ri(0), stn(-1), lay(0), chamb(0), rol(0);
134  unpackId(rawid, reg, ri, stn, lay, chamb, rol);
135  return (((id_ & kMuonIdMask) == (rawid & kMuonIdMask)) && (reg == region()) && (ri == ring()) &&
136  (stn == station()) && (lay == layer()) && (chamb == chamber()) && (rol == roll()));
137  }
138  constexpr bool operator!=(const GEMDetId& gen) const {
139  uint32_t rawid = gen.rawId();
140  if (rawid == id_)
141  return false;
142  int reg(0), ri(0), stn(-1), lay(0), chamb(0), rol(0);
143  unpackId(rawid, reg, ri, stn, lay, chamb, rol);
144  return (((id_ & kMuonIdMask) != (rawid & kMuonIdMask)) || (reg != region()) || (ri != ring()) ||
145  (stn != station()) || (lay != layer()) || (chamb != chamber()) || (rol != roll()));
146  }
147 
149  constexpr bool operator<(const GEMDetId& r) const {
150  if (r.station() == this->station()) {
151  if (this->layer() == r.layer()) {
152  return this->rawId() < r.rawId();
153  } else {
154  return (this->layer() < r.layer());
155  }
156  } else {
157  return this->station() < r.station();
158  }
159  }
160 
162  constexpr bool v11Format() const { return ((id_ & kGEMIdFormat) == 0); }
163 
165  constexpr int region() const { return (static_cast<int>((id_ >> RegionStartBit) & RegionMask) + minRegionId); }
166 
170  constexpr int ring() const { return (static_cast<int>((id_ >> RingStartBit) & RingMask) + minRingId); }
171 
173  constexpr int station() const { return (static_cast<int>((id_ >> StationStartBit) & StationMask) + minStationId0); }
174 
177  constexpr int chamber() const {
178  return (static_cast<int>((id_ >> ChamberStartBit) & ChamberMask) + (minChamberId + 1));
179  }
180 
184  constexpr int layer() const { return (static_cast<int>((id_ >> LayerStartBit) & LayerMask) + minLayerId); }
185 
188  constexpr int roll() const {
189  return (static_cast<int>((id_ >> RollStartBit) & RollMask)); // value 0 is used as wild card
190  }
191 
193  constexpr GEMDetId chamberId() const { return GEMDetId(id_ & chamberIdMask); }
194 
196  constexpr GEMDetId superChamberId() const { return GEMDetId(id_ & superChamberIdMask); }
197 
199  constexpr GEMDetId layerId() const { return GEMDetId(id_ & chamberIdMask); }
200 
202  constexpr int nlayers() const {
203  return ((station() == 0) ? maxLayerId0 : ((station() > maxStationId) ? 0 : maxLayerId));
204  }
205 
206  constexpr uint32_t v12Form() const { return v12Form(id_); }
207 
208  constexpr static uint32_t v12Form(const uint32_t& inpid) {
209  uint32_t rawid(inpid);
210  if ((rawid & kGEMIdFormat) == 0) {
211  int region(0), ring(0), station(-1), layer(0), chamber(0), roll(0);
212  unpackId(rawid, region, ring, station, layer, chamber, roll);
213  int regionInBits = region - minRegionId;
214  int ringInBits = ring - minRingId;
215  int stationInBits = station - minStationId0;
216  int layerInBits = layer - minLayerId;
217  int chamberInBits = chamber - (minChamberId + 1);
218  int rollInBits = roll;
219  rawid = (((DetId::Muon & DetId::kDetMask) << DetId::kDetOffset) |
221  ((regionInBits & RegionMask) << RegionStartBit) | ((ringInBits & RingMask) << RingStartBit) |
222  ((stationInBits & StationMask) << StationStartBit) | ((layerInBits & LayerMask) << LayerStartBit) |
223  ((chamberInBits & ChamberMask) << ChamberStartBit) | ((rollInBits & RollMask) << RollStartBit) |
224  kGEMIdFormat);
225  }
226  return rawid;
227  }
228 
229 private:
230  constexpr void v12FromV11(const uint32_t& rawid) { id_ = v12Form(rawid); }
231 
232  constexpr static void unpackId(
233  const uint32_t& rawid, int& region, int& ring, int& station, int& layer, int& chamber, int& roll) {
234  if (((rawid >> DetId::kDetOffset) & DetId::kDetMask) == DetId::Muon) {
235  int subdet = ((rawid >> DetId::kSubdetOffset) & DetId::kSubdetMask);
236  if (subdet == MuonSubdetId::GEM) {
237  region = static_cast<int>(((rawid >> RegionStartBit) & RegionMask) + minRegionId);
238  ring = (static_cast<int>((rawid >> RingStartBit) & RingMask) + minRingId);
239  chamber = (static_cast<int>((rawid >> ChamberStartBit) & ChamberMask) + (minChamberId + 1));
240  if ((rawid & kGEMIdFormat) == 0) {
241  station = (static_cast<int>((rawid >> StationStartBit) & StationMask) + minStationId);
242  layer = (static_cast<int>((rawid >> LayerStartBit) & LayerMaskP) + minLayerId);
243  roll = (static_cast<int>((rawid >> RollStartBitP) & RollMask));
244  } else {
245  station = (static_cast<int>((rawid >> StationStartBit) & StationMask) + minStationId0);
246  layer = (static_cast<int>((rawid >> LayerStartBit) & LayerMask) + minLayerId);
247  roll = (static_cast<int>((rawid >> RollStartBit) & RollMask));
248  }
249  } else if (subdet == MuonSubdetId::ME0) {
250  region = static_cast<int>(((rawid >> RegionStartBit) & RegionMask) + minRegionId);
251  ring = 1;
252  station = 0;
253  chamber = (static_cast<int>((rawid >> ChamberStartBitM) & ChamberMask) + (minChamberId));
254  layer = (static_cast<int>((rawid >> LayerStartBitM) & LayerMask) + minLayerId);
255  roll = (static_cast<int>((rawid >> RollStartBitM) & RollMask));
256  }
257  }
258  }
259 
260 }; // GEMDetId
261 
262 std::ostream& operator<<(std::ostream& os, const GEMDetId& id);
263 
264 #endif
static uint32_t RollStartBitM
Definition: GEMDetId.h:58
std::ostream & operator<<(std::ostream &os, const GEMDetId &id)
Definition: GEMDetId.cc:7
static int32_t maxRollId
Definition: GEMDetId.h:33
static constexpr int GEM
Definition: MuonSubdetId.h:14
static uint32_t StationNumBits
Definition: GEMDetId.h:42
bool operator==(const GEMDetId &gen) const
Definition: GEMDetId.h:129
static uint32_t LayerStartBitM
Definition: GEMDetId.h:52
static uint32_t RollMask
Definition: GEMDetId.h:59
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
static uint32_t RollStartBit
Definition: GEMDetId.h:56
static int32_t maxLayerId0
Definition: GEMDetId.h:30
static uint32_t ChamberStartBitM
Definition: GEMDetId.h:47
static uint32_t LayerStartBit
Definition: GEMDetId.h:51
int roll() const
Definition: GEMDetId.h:188
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int ring() const
Definition: GEMDetId.h:170
static int32_t maxStationId
Definition: GEMDetId.h:26
static int32_t minRegionId
Definition: GEMDetId.h:19
static uint32_t StationStartBit
Definition: GEMDetId.h:43
GEMDetId()
Definition: GEMDetId.h:70
static const int kSubdetOffset
Definition: DetId.h:22
int chamber() const
Definition: GEMDetId.h:177
static uint32_t RollNumBits
Definition: GEMDetId.h:55
static uint32_t chamberIdMask
Definition: GEMDetId.h:65
GEMDetId superChamberId() const
Definition: GEMDetId.h:196
bool operator!=(const GEMDetId &gen) const
Definition: GEMDetId.h:138
static uint32_t LayerNumBitsP
Definition: GEMDetId.h:50
static uint32_t StationMask
Definition: GEMDetId.h:44
static uint32_t RegionNumBits
Definition: GEMDetId.h:36
static int32_t minStationId0
Definition: GEMDetId.h:23
GEMDetId chamberId() const
Definition: GEMDetId.h:193
bool operator<(const GEMDetId &r) const
Definition: GEMDetId.h:149
static uint32_t FormatMask
Definition: GEMDetId.h:62
static uint32_t LayerNumBits
Definition: GEMDetId.h:49
static const int kSubdetMask
Definition: DetId.h:20
Definition: Muon.py:1
static uint32_t RingStartBit
Definition: GEMDetId.h:40
static uint32_t RegionStartBit
Definition: GEMDetId.h:37
GEMDetId(int region, int ring, int station, int layer, int chamber, int roll)
Construct from fully qualified identifier.
Definition: GEMDetId.h:90
static uint32_t RegionMask
Definition: GEMDetId.h:38
static uint32_t kGEMIdFormat
Definition: GEMDetId.h:63
int layer() const
Definition: GEMDetId.h:184
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int station() const
Definition: GEMDetId.h:173
static int32_t maxChamberId
Definition: GEMDetId.h:28
static uint32_t RingMask
Definition: GEMDetId.h:41
static constexpr int ME0
Definition: MuonSubdetId.h:15
GEMDetId & operator=(const DetId &gen)
Definition: GEMDetId.h:112
uint32_t v12Form() const
Definition: GEMDetId.h:206
std::bitset< maskSIZE > RollMask
Definition: RPCRollMask.h:7
int region() const
Definition: GEMDetId.h:165
static uint32_t FormatNumBits
Definition: GEMDetId.h:60
static uint32_t kMuonIdMask
Definition: GEMDetId.h:64
static int32_t maxLayerId
Definition: GEMDetId.h:31
Definition: DetId.h:17
static int32_t minRollId
Definition: GEMDetId.h:32
static uint32_t ChamberNumBits
Definition: GEMDetId.h:45
static int32_t minRingId
Definition: GEMDetId.h:21
static uint32_t LayerMaskP
Definition: GEMDetId.h:54
bool v11Format() const
Definition: GEMDetId.h:162
static const int kDetMask
Definition: DetId.h:19
uint32_t id_
Definition: DetId.h:69
static uint32_t LayerMask
Definition: GEMDetId.h:53
static int32_t maxRegionId
Definition: GEMDetId.h:20
static int32_t maxRingId
Definition: GEMDetId.h:22
static const int kDetOffset
Definition: DetId.h:21
static uint32_t superChamberIdMask
Definition: GEMDetId.h:66
static int32_t minStationId
Definition: GEMDetId.h:24
static uint32_t ChamberStartBit
Definition: GEMDetId.h:46
void v12FromV11(const uint32_t &rawid)
Definition: GEMDetId.h:230
GEMDetId(DetId id)
Definition: GEMDetId.h:82
int nlayers() const
Definition: GEMDetId.h:202
static void unpackId(const uint32_t &rawid, int &region, int &ring, int &station, int &layer, int &chamber, int &roll)
Definition: GEMDetId.h:232
static int32_t minLayerId
Definition: GEMDetId.h:29
GEMDetId layerId() const
Definition: GEMDetId.h:199
static uint32_t ChamberMask
Definition: GEMDetId.h:48
static uint32_t RollStartBitP
Definition: GEMDetId.h:57
static uint32_t RingNumBits
Definition: GEMDetId.h:39
static int32_t minChamberId
Definition: GEMDetId.h:27
static uint32_t FormatStartBit
Definition: GEMDetId.h:61
static uint32_t v12Form(const uint32_t &inpid)
Definition: GEMDetId.h:208
GEMDetId(uint32_t id)
Definition: GEMDetId.h:73
#define constexpr
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46