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