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 = 16;
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:
70  constexpr GEMDetId() : DetId(DetId::Muon, MuonSubdetId::GEM) {}
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  }
82  constexpr GEMDetId(DetId id) : DetId(id) {
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 
112  constexpr GEMDetId& operator=(const DetId& gen) {
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);
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
MuonSubdetId::GEM
static constexpr int GEM
Definition: MuonSubdetId.h:14
GEMDetId::RegionStartBit
static constexpr uint32_t RegionStartBit
Definition: GEMDetId.h:37
GEMDetId::v11Format
constexpr bool v11Format() const
Definition: GEMDetId.h:162
RollMask
std::bitset< maskSIZE > RollMask
Definition: RPCRollMask.h:7
GEMDetId::operator==
constexpr bool operator==(const GEMDetId &gen) const
Definition: GEMDetId.h:129
GEMDetId::ring
constexpr int ring() const
Definition: GEMDetId.h:170
GEMDetId::layer
constexpr int layer() const
Definition: GEMDetId.h:184
GEMDetId::RingMask
static constexpr uint32_t RingMask
Definition: GEMDetId.h:41
GEMDetId::region
constexpr int region() const
Definition: GEMDetId.h:165
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
operator<<
std::ostream & operator<<(std::ostream &os, const GEMDetId &id)
Definition: GEMDetId.cc:7
GEMDetId::LayerMask
static constexpr uint32_t LayerMask
Definition: GEMDetId.h:53
GEMDetId::superChamberId
constexpr GEMDetId superChamberId() const
Definition: GEMDetId.h:196
GEMDetId::maxStationId
static constexpr int32_t maxStationId
Definition: GEMDetId.h:26
GEMDetId::ChamberMask
static constexpr uint32_t ChamberMask
Definition: GEMDetId.h:48
GEMDetId::minChamberId
static constexpr int32_t minChamberId
Definition: GEMDetId.h:27
GEMDetId::StationStartBit
static constexpr uint32_t StationStartBit
Definition: GEMDetId.h:43
GEMDetId::LayerNumBits
static constexpr uint32_t LayerNumBits
Definition: GEMDetId.h:49
GEMDetId::RegionMask
static constexpr uint32_t RegionMask
Definition: GEMDetId.h:38
GEMDetId::minLayerId
static constexpr int32_t minLayerId
Definition: GEMDetId.h:29
GEMDetId::RollStartBitM
static constexpr uint32_t RollStartBitM
Definition: GEMDetId.h:58
GEMDetId::FormatNumBits
static constexpr uint32_t FormatNumBits
Definition: GEMDetId.h:60
GEMDetId::operator<
constexpr bool operator<(const GEMDetId &r) const
Definition: GEMDetId.h:149
GEMDetId::nlayers
constexpr int nlayers() const
Definition: GEMDetId.h:202
DetId::kSubdetMask
static const int kSubdetMask
Definition: DetId.h:20
GEMDetId::GEMDetId
constexpr GEMDetId(DetId id)
Definition: GEMDetId.h:82
Muon
Definition: Muon.py:1
GEMDetId::v12FromV11
constexpr void v12FromV11(const uint32_t &rawid)
Definition: GEMDetId.h:230
GEMDetId::v12Form
constexpr uint32_t v12Form() const
Definition: GEMDetId.h:206
GEMDetId::FormatMask
static constexpr uint32_t FormatMask
Definition: GEMDetId.h:62
GEMDetId::RingStartBit
static constexpr uint32_t RingStartBit
Definition: GEMDetId.h:40
GEMDetId::maxRollId
static constexpr int32_t maxRollId
Definition: GEMDetId.h:33
GEMDetId::LayerStartBit
static constexpr uint32_t LayerStartBit
Definition: GEMDetId.h:51
DetId::kSubdetOffset
static const int kSubdetOffset
Definition: DetId.h:22
DetId
Definition: DetId.h:17
GEMDetId::layerId
constexpr GEMDetId layerId() const
Definition: GEMDetId.h:199
GEMDetId::StationNumBits
static constexpr uint32_t StationNumBits
Definition: GEMDetId.h:42
GEMDetId::GEMDetId
constexpr GEMDetId()
Definition: GEMDetId.h:70
GEMDetId::ChamberNumBits
static constexpr uint32_t ChamberNumBits
Definition: GEMDetId.h:45
GEMDetId::minStationId0
static constexpr int32_t minStationId0
Definition: GEMDetId.h:23
GEMDetId::maxRingId
static constexpr int32_t maxRingId
Definition: GEMDetId.h:22
GEMDetId::maxChamberId
static constexpr int32_t maxChamberId
Definition: GEMDetId.h:28
GEMDetId::minRingId
static constexpr int32_t minRingId
Definition: GEMDetId.h:21
GEMDetId::RegionNumBits
static constexpr uint32_t RegionNumBits
Definition: GEMDetId.h:36
gen
Definition: PythiaDecays.h:13
GEMDetId::GEMDetId
constexpr GEMDetId(int region, int ring, int station, int layer, int chamber, int roll)
Construct from fully qualified identifier.
Definition: GEMDetId.h:90
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
GEMDetId::RollStartBitP
static constexpr uint32_t RollStartBitP
Definition: GEMDetId.h:57
GEMDetId::chamberIdMask
static constexpr uint32_t chamberIdMask
Definition: GEMDetId.h:65
GEMDetId::chamber
constexpr int chamber() const
Definition: GEMDetId.h:177
GEMDetId::maxLayerId0
static constexpr int32_t maxLayerId0
Definition: GEMDetId.h:30
DetId::kDetMask
static const int kDetMask
Definition: DetId.h:19
GEMDetId::kMuonIdMask
static constexpr uint32_t kMuonIdMask
Definition: GEMDetId.h:64
DetId::id_
uint32_t id_
Definition: DetId.h:69
GEMDetId::roll
constexpr int roll() const
Definition: GEMDetId.h:188
GEMDetId
Definition: GEMDetId.h:17
GEMDetId::LayerMaskP
static constexpr uint32_t LayerMaskP
Definition: GEMDetId.h:54
GEMDetId::superChamberIdMask
static constexpr uint32_t superChamberIdMask
Definition: GEMDetId.h:66
GEMDetId::ChamberStartBit
static constexpr uint32_t ChamberStartBit
Definition: GEMDetId.h:46
GEMDetId::minRegionId
static constexpr int32_t minRegionId
Definition: GEMDetId.h:19
GEMDetId::LayerStartBitM
static constexpr uint32_t LayerStartBitM
Definition: GEMDetId.h:52
MuonSubdetId::ME0
static constexpr int ME0
Definition: MuonSubdetId.h:15
GEMDetId::RollNumBits
static constexpr uint32_t RollNumBits
Definition: GEMDetId.h:55
GEMDetId::unpackId
constexpr static void unpackId(const uint32_t &rawid, int &region, int &ring, int &station, int &layer, int &chamber, int &roll)
Definition: GEMDetId.h:232
MuonSubdetId.h
GEMDetId::maxRegionId
static constexpr int32_t maxRegionId
Definition: GEMDetId.h:20
alignCSCRings.r
r
Definition: alignCSCRings.py:93
GEMDetId::FormatStartBit
static constexpr uint32_t FormatStartBit
Definition: GEMDetId.h:61
DetId::kDetOffset
static const int kDetOffset
Definition: DetId.h:21
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
DetId.h
GEMDetId::RollMask
static constexpr uint32_t RollMask
Definition: GEMDetId.h:59
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:31
GEMDetId::ChamberStartBitM
static constexpr uint32_t ChamberStartBitM
Definition: GEMDetId.h:47
GEMDetId::maxLayerId
static constexpr int32_t maxLayerId
Definition: GEMDetId.h:31
GEMDetId::chamberId
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:193
Exception
Definition: hltDiff.cc:246
GEMDetId::StationMask
static constexpr uint32_t StationMask
Definition: GEMDetId.h:44
GEMDetId::v12Form
constexpr static uint32_t v12Form(const uint32_t &inpid)
Definition: GEMDetId.h:208
GEMDetId::RollStartBit
static constexpr uint32_t RollStartBit
Definition: GEMDetId.h:56
GEMDetId::operator=
constexpr GEMDetId & operator=(const DetId &gen)
Definition: GEMDetId.h:112
GeomDetEnumerators::GEM
Definition: GeomDetEnumerators.h:21
GEMDetId::kGEMIdFormat
static constexpr uint32_t kGEMIdFormat
Definition: GEMDetId.h:63
GEMDetId::minRollId
static constexpr int32_t minRollId
Definition: GEMDetId.h:32
Exception.h
GEMDetId::RingNumBits
static constexpr uint32_t RingNumBits
Definition: GEMDetId.h:39
GEMDetId::LayerNumBitsP
static constexpr uint32_t LayerNumBitsP
Definition: GEMDetId.h:50
GEMDetId::station
constexpr int station() const
Definition: GEMDetId.h:173
GEMDetId::minStationId
static constexpr int32_t minStationId
Definition: GEMDetId.h:24
DetId::Muon
Definition: DetId.h:26
GEMDetId::GEMDetId
constexpr GEMDetId(uint32_t id)
Definition: GEMDetId.h:73
MuonSubdetId
Definition: MuonSubdetId.h:9
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
GEMDetId::operator!=
constexpr bool operator!=(const GEMDetId &gen) const
Definition: GEMDetId.h:138