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;
35  static constexpr int32_t minRollId = minEtaPartitionId;
36  static constexpr int32_t maxRollId = maxEtaPartitionId;
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;
43  static constexpr uint32_t RingStartBit = RegionStartBit + RegionNumBits;
44  static constexpr uint32_t RingMask = 0x7;
45  static constexpr uint32_t StationNumBits = 3;
46  static constexpr uint32_t StationStartBit = RingStartBit + RingNumBits;
47  static constexpr uint32_t StationMask = 0x7;
48  static constexpr uint32_t ChamberNumBits = 6;
49  static constexpr uint32_t ChamberStartBit = StationStartBit + StationNumBits;
50  static constexpr uint32_t ChamberStartBitM = RegionStartBit + RegionNumBits;
51  static constexpr uint32_t ChamberMask = 0x3F;
52  static constexpr uint32_t LayerNumBits = 5;
53  static constexpr uint32_t LayerNumBitsP = 2;
54  static constexpr uint32_t LayerStartBit = ChamberStartBit + ChamberNumBits;
55  static constexpr uint32_t LayerStartBitM = ChamberStartBitM + ChamberNumBits;
56  static constexpr uint32_t LayerMask = 0x1F;
57  static constexpr uint32_t LayerMaskP = 0x3;
58  static constexpr uint32_t EtaPartitionNumBits = 5;
59  static constexpr uint32_t EtaPartitionStartBit = LayerStartBit + LayerNumBits;
60  static constexpr uint32_t EtaPartitionStartBitP = LayerStartBit + LayerNumBitsP;
61  static constexpr uint32_t EtaPartitionStartBitM = LayerStartBitM + LayerNumBits;
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:
70  static constexpr uint32_t chamberIdMask = ~(EtaPartitionMask << EtaPartitionStartBit);
71  static constexpr uint32_t superChamberIdMask = chamberIdMask + ~(LayerMask << LayerStartBit);
72 
73 public:
75  constexpr GEMDetId() : DetId(DetId::Muon, MuonSubdetId::GEM) {}
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  }
87  constexpr GEMDetId(DetId id) : DetId(id) {
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 
118  constexpr GEMDetId& operator=(const DetId& gen) {
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 
204  constexpr GEMDetId chamberId() const { return GEMDetId(id_ & chamberIdMask); }
205 
207  constexpr GEMDetId superChamberId() const { return GEMDetId(id_ & superChamberIdMask); }
208 
210  constexpr GEMDetId layerId() const { return GEMDetId(id_ & chamberIdMask); }
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
MuonSubdetId::GEM
static constexpr int GEM
Definition: MuonSubdetId.h:14
GEMDetId::RegionStartBit
static constexpr uint32_t RegionStartBit
Definition: GEMDetId.h:40
GEMDetId::v11Format
constexpr bool v11Format() const
Definition: GEMDetId.h:168
GEMDetId::operator==
constexpr bool operator==(const GEMDetId &gen) const
Definition: GEMDetId.h:135
GEMDetId::isGE21
bool isGE21() const
Definition: GEMDetId.cc:11
GEMDetId::EtaPartitionNumBits
static constexpr uint32_t EtaPartitionNumBits
Definition: GEMDetId.h:58
GEMDetId::ring
constexpr int ring() const
Definition: GEMDetId.h:176
GEMDetId::layer
constexpr int layer() const
Definition: GEMDetId.h:190
GEMDetId::RingMask
static constexpr uint32_t RingMask
Definition: GEMDetId.h:44
GEMDetId::region
constexpr int region() const
Definition: GEMDetId.h:171
GEMDetId::subsystem
GEMSubDetId::Station subsystem() const
Definition: GEMDetId.cc:7
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:15
GEMDetId::EtaPartitionStartBitP
static constexpr uint32_t EtaPartitionStartBitP
Definition: GEMDetId.h:60
GEMDetId::EtaPartitionMask
static constexpr uint32_t EtaPartitionMask
Definition: GEMDetId.h:62
GEMDetId::LayerMask
static constexpr uint32_t LayerMask
Definition: GEMDetId.h:56
GEMDetId::superChamberId
constexpr GEMDetId superChamberId() const
Definition: GEMDetId.h:207
GEMDetId::maxStationId
static constexpr int32_t maxStationId
Definition: GEMDetId.h:27
GEMDetId::ChamberMask
static constexpr uint32_t ChamberMask
Definition: GEMDetId.h:51
GEMDetId::minChamberId
static constexpr int32_t minChamberId
Definition: GEMDetId.h:28
GEMDetId::StationStartBit
static constexpr uint32_t StationStartBit
Definition: GEMDetId.h:46
GEMDetId::LayerNumBits
static constexpr uint32_t LayerNumBits
Definition: GEMDetId.h:52
GEMDetId::RegionMask
static constexpr uint32_t RegionMask
Definition: GEMDetId.h:41
GEMDetId::minLayerId
static constexpr int32_t minLayerId
Definition: GEMDetId.h:30
GEMDetId::FormatNumBits
static constexpr uint32_t FormatNumBits
Definition: GEMDetId.h:63
GEMDetId::operator<
constexpr bool operator<(const GEMDetId &r) const
Definition: GEMDetId.h:155
GEMDetId::nlayers
constexpr int nlayers() const
Definition: GEMDetId.h:213
DetId::kSubdetMask
static const int kSubdetMask
Definition: DetId.h:20
GEMDetId::GEMDetId
constexpr GEMDetId(DetId id)
Definition: GEMDetId.h:87
Muon
Definition: Muon.py:1
GEMDetId::EtaPartitionStartBitM
static constexpr uint32_t EtaPartitionStartBitM
Definition: GEMDetId.h:61
GEMDetId::v12FromV11
constexpr void v12FromV11(const uint32_t &rawid)
Definition: GEMDetId.h:247
GEMDetId::v12Form
constexpr uint32_t v12Form() const
Definition: GEMDetId.h:217
GEMDetId::FormatMask
static constexpr uint32_t FormatMask
Definition: GEMDetId.h:65
GEMDetId::RingStartBit
static constexpr uint32_t RingStartBit
Definition: GEMDetId.h:43
GEMDetId::maxRollId
static constexpr int32_t maxRollId
Definition: GEMDetId.h:36
GEMDetId::LayerStartBit
static constexpr uint32_t LayerStartBit
Definition: GEMDetId.h:54
DetId::kSubdetOffset
static const int kSubdetOffset
Definition: DetId.h:22
DetId
Definition: DetId.h:17
GEMDetId::layerId
constexpr GEMDetId layerId() const
Definition: GEMDetId.h:210
GEMDetId::StationNumBits
static constexpr uint32_t StationNumBits
Definition: GEMDetId.h:45
GEMSubDetId.h
GEMDetId::GEMDetId
constexpr GEMDetId()
Definition: GEMDetId.h:75
GEMDetId::ChamberNumBits
static constexpr uint32_t ChamberNumBits
Definition: GEMDetId.h:48
GEMDetId::minStationId0
static constexpr int32_t minStationId0
Definition: GEMDetId.h:24
GEMDetId::maxRingId
static constexpr int32_t maxRingId
Definition: GEMDetId.h:23
GEMDetId::maxChamberId
static constexpr int32_t maxChamberId
Definition: GEMDetId.h:29
GEMDetId::minRingId
static constexpr int32_t minRingId
Definition: GEMDetId.h:22
GEMDetId::maxEtaPartitionId
static constexpr int32_t maxEtaPartitionId
Definition: GEMDetId.h:34
GEMDetId::isME0
bool isME0() const
Definition: GEMDetId.cc:13
GEMDetId::RegionNumBits
static constexpr uint32_t RegionNumBits
Definition: GEMDetId.h:39
gen
Definition: PythiaDecays.h:13
GEMDetId::GEMDetId
constexpr GEMDetId(int region, int ring, int station, int layer, int chamber, int ieta)
Construct from fully qualified identifier.
Definition: GEMDetId.h:95
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::chamberIdMask
static constexpr uint32_t chamberIdMask
Definition: GEMDetId.h:70
GEMSubDetId::Station
Station
Definition: GEMSubDetId.h:12
GEMDetId::chamber
constexpr int chamber() const
Definition: GEMDetId.h:183
l1t::mtf7::GEM
GEM Data Record : block->header().getID() = 7.
Definition: Block.h:21
GEMDetId::maxLayerId0
static constexpr int32_t maxLayerId0
Definition: GEMDetId.h:31
DetId::kDetMask
static const int kDetMask
Definition: DetId.h:19
GEMDetId::kMuonIdMask
static constexpr uint32_t kMuonIdMask
Definition: GEMDetId.h:67
DetId::id_
uint32_t id_
Definition: DetId.h:69
EtaPartitionMask
std::bitset< maskSIZE > EtaPartitionMask
Definition: GEMEtaPartitionMask.h:8
GEMDetId::roll
constexpr int roll() const
Definition: GEMDetId.h:194
GEMDetId
Definition: GEMDetId.h:18
GEMDetId::LayerMaskP
static constexpr uint32_t LayerMaskP
Definition: GEMDetId.h:57
GEMDetId::superChamberIdMask
static constexpr uint32_t superChamberIdMask
Definition: GEMDetId.h:71
GEMDetId::ChamberStartBit
static constexpr uint32_t ChamberStartBit
Definition: GEMDetId.h:49
GEMDetId::minRegionId
static constexpr int32_t minRegionId
Definition: GEMDetId.h:20
GEMDetId::LayerStartBitM
static constexpr uint32_t LayerStartBitM
Definition: GEMDetId.h:55
MuonSubdetId::ME0
static constexpr int ME0
Definition: MuonSubdetId.h:15
GEMDetId::unpackId
constexpr static void unpackId(const uint32_t &rawid, int &region, int &ring, int &station, int &layer, int &chamber, int &ieta)
Definition: GEMDetId.h:249
MuonSubdetId.h
GEMDetId::maxRegionId
static constexpr int32_t maxRegionId
Definition: GEMDetId.h:21
alignCSCRings.r
r
Definition: alignCSCRings.py:93
GEMDetId::FormatStartBit
static constexpr uint32_t FormatStartBit
Definition: GEMDetId.h:64
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
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
GEMDetId::ChamberStartBitM
static constexpr uint32_t ChamberStartBitM
Definition: GEMDetId.h:50
GEMDetId::maxLayerId
static constexpr int32_t maxLayerId
Definition: GEMDetId.h:32
GEMDetId::chamberId
constexpr GEMDetId chamberId() const
Definition: GEMDetId.h:204
Exception
Definition: hltDiff.cc:245
GEMDetId::StationMask
static constexpr uint32_t StationMask
Definition: GEMDetId.h:47
GEMDetId::v12Form
constexpr static uint32_t v12Form(const uint32_t &inpid)
Definition: GEMDetId.h:219
GEMDetId::isGE11
bool isGE11() const
Definition: GEMDetId.cc:9
GEMDetId::operator=
constexpr GEMDetId & operator=(const DetId &gen)
Definition: GEMDetId.h:118
GEMDetId::kGEMIdFormat
static constexpr uint32_t kGEMIdFormat
Definition: GEMDetId.h:66
GEMDetId::minEtaPartitionId
static constexpr int32_t minEtaPartitionId
Definition: GEMDetId.h:33
GEMDetId::minRollId
static constexpr int32_t minRollId
Definition: GEMDetId.h:35
Exception.h
GEMDetId::RingNumBits
static constexpr uint32_t RingNumBits
Definition: GEMDetId.h:42
GEMDetId::LayerNumBitsP
static constexpr uint32_t LayerNumBitsP
Definition: GEMDetId.h:53
GEMDetId::station
constexpr int station() const
Definition: GEMDetId.h:179
GEMDetId::minStationId
static constexpr int32_t minStationId
Definition: GEMDetId.h:25
DetId::Muon
Definition: DetId.h:26
GEMDetId::GEMDetId
constexpr GEMDetId(uint32_t id)
Definition: GEMDetId.h:78
GEMDetId::ieta
constexpr int ieta() const
Definition: GEMDetId.h:199
MuonSubdetId
Definition: MuonSubdetId.h:9
GEMDetId::EtaPartitionStartBit
static constexpr uint32_t EtaPartitionStartBit
Definition: GEMDetId.h:59
TauDecayModes.dec
dec
Definition: TauDecayModes.py:142
GEMDetId::operator!=
constexpr bool operator!=(const GEMDetId &gen) const
Definition: GEMDetId.h:144