CMS 3D CMS Logo

HcalZDCDetId.h
Go to the documentation of this file.
1 #ifndef DataFormats_HcalDetId_HcalZDCDetId_h_included
2 #define DataFormats_HcalDetId_HcalZDCDetId_h_included 1
3 
4 #include <ostream>
7 
24 class HcalZDCDetId : public DetId {
25 public:
26  static constexpr uint32_t kZDCChannelMask1 = 0xF;
27  static constexpr uint32_t kZDCChannelMask2 = 0x3F;
28  static constexpr uint32_t kZDCSectionMask = 0x3;
29  static constexpr uint32_t kZDCSectionOffset = 4;
30  static constexpr uint32_t kZDCZsideMask = 0x40;
31  static constexpr uint32_t kZDCRPDMask = 0x80;
32  static constexpr uint32_t kZDCnewFormat = 0x100;
33  enum Section { Unknown = 0, EM = 1, HAD = 2, LUM = 3, RPD = 4 };
34 
35  static constexpr int32_t SubdetectorId = 2;
36 
37  static constexpr int32_t kDepEM = 5;
38  static constexpr int32_t kDepHAD = 4;
39  static constexpr int32_t kDepLUM = 2;
40  static constexpr int32_t kDepRPD = 16;
41  static constexpr int32_t kDepRun1 = (kDepEM + kDepHAD + kDepLUM);
42  static constexpr int32_t kDepTot = (kDepRun1 + kDepRPD);
43  static constexpr int32_t kDepRun3 = kDepTot;
44 
48  constexpr HcalZDCDetId(uint32_t rawid) : DetId(rawid) {}
50  constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel) {
51  id_ = packHcalZDCDetId(section, true_for_positive_eta, channel);
52  }
55  if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
56  throw cms::Exception("Invalid DetId")
57  << "Cannot initialize ZDCDetId from " << std::hex << gen.rawId() << std::dec;
58  }
59  id_ = newForm(gen.rawId());
60  }
63  if (!gen.null() && (gen.det() != Calo || gen.subdetId() != SubdetectorId)) {
64  throw cms::Exception("Invalid DetId") << "Cannot assign ZDCDetId from " << std::hex << gen.rawId() << std::dec;
65  }
66  id_ = newForm(gen.rawId());
67  return *this;
68  }
70  constexpr bool operator==(DetId gen) const {
71  if (gen.rawId() == id_) {
72  return true;
73  } else {
74  uint32_t id1 = newForm(gen.rawId());
75  uint32_t id2 = newForm(id_);
76  return (id1 == id2);
77  }
78  }
79  constexpr bool operator!=(DetId gen) const {
80  if (gen.rawId() != id_) {
81  return true;
82  } else {
83  uint32_t id1 = newForm(gen.rawId());
84  uint32_t id2 = newForm(id_);
85  return (id1 != id2);
86  }
87  }
88 
90  constexpr int32_t zside() const { return ((id_ & kZDCZsideMask) ? (1) : (-1)); }
93  uint32_t id = newForm(id_);
94  if (id & kZDCRPDMask)
95  return RPD;
96  else
97  return (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
98  }
100  constexpr int32_t depth() const {
101  const int se(section());
102  if (se == EM)
103  return 1;
104  else if (se == HAD)
105  return (channel() + 2);
106  else if (se == RPD)
107  return 2;
108  else
109  return channel();
110  }
112  constexpr int32_t channel() const {
113  const int32_t se(section());
114  uint32_t id = newForm(id_);
115  if (se == RPD)
116  return (1 + (id & kZDCChannelMask2));
117  else
118  return (id & kZDCChannelMask1);
119  }
120 
121  constexpr static bool newFormat(const uint32_t& di) { return (di & kZDCnewFormat); }
122  constexpr static uint32_t newForm(const uint32_t& di) {
123  uint32_t id(di);
124  if (!newFormat(id)) {
125  Section se(Unknown);
126  bool zside(true);
127  int32_t channel(0);
128  unpackHcalZDCDetId(id, se, zside, channel);
129  id = packHcalZDCDetId(se, zside, channel);
130  }
131  return id;
132  }
133 
134  constexpr uint32_t denseIndex() const {
135  const int32_t se(section());
136  uint32_t di =
137  (channel() - 1 +
138  (se == RPD ? 2 * kDepRun1 + (zside() < 0 ? 0 : kDepRPD)
139  : ((zside() < 0 ? 0 : kDepRun1) + (se == HAD ? kDepEM : (se == LUM ? kDepEM + kDepHAD : 0)))));
140  return di;
141  }
142 
143  constexpr static bool validDenseIndex(const uint32_t& di) { return (di < kSizeForDenseIndexing); }
144 
146  if (validDenseIndex(di)) {
147  bool lz(false);
148  uint32_t dp(0);
149  Section se(Unknown);
150  if (di >= 2 * kDepRun1) {
151  lz = (di >= (kDepRun1 + kDepTot));
152  se = RPD;
153  dp = 1 + ((di - 2 * kDepRun1) % kDepRPD);
154  } else {
155  lz = (di >= kDepRun1);
156  uint32_t in = (di % kDepRun1);
157  se = (in < kDepEM ? EM : (in < kDepEM + kDepHAD ? HAD : LUM));
158  dp = (se == EM ? in + 1 : (se == HAD ? in - kDepEM + 1 : in - kDepEM - kDepHAD + 1));
159  }
160  return HcalZDCDetId(se, lz, dp);
161  } else {
162  return HcalZDCDetId();
163  }
164  }
165 
166  constexpr static bool validDetId(Section se, int32_t dp) {
167  bool flag = (dp >= 1 && (((se == EM) && (dp <= kDepEM)) || ((se == HAD) && (dp <= kDepHAD)) ||
168  ((se == LUM) && (dp <= kDepLUM)) || ((se == RPD) && (dp <= kDepRPD))));
169  return flag;
170  }
171 
172 private:
173  constexpr static uint32_t packHcalZDCDetId(const Section& se, const bool& zside, const int32_t& channel) {
174  uint32_t id = DetId(DetId::Calo, SubdetectorId);
175  id |= kZDCnewFormat;
176  if (se == RPD) {
177  id |= kZDCRPDMask;
178  id |= ((channel - 1) & kZDCChannelMask2);
179  } else {
180  id |= (se & kZDCSectionMask) << kZDCSectionOffset;
181  id |= (channel & kZDCChannelMask1);
182  }
183  if (zside)
184  id |= kZDCZsideMask;
185  return id;
186  }
187 
188  constexpr static void unpackHcalZDCDetId(const uint32_t& id, Section& se, bool& zside, int32_t& channel) {
189  if (id & kZDCnewFormat) {
190  se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
191  channel = (se == RPD) ? (1 + (id & kZDCChannelMask2)) : (id & kZDCChannelMask1);
192  zside = (id & kZDCZsideMask);
193  } else {
194  se = (id & kZDCRPDMask) ? RPD : (Section)((id >> kZDCSectionOffset) & kZDCSectionMask);
195  channel = (se == RPD) ? (1 + (id & kZDCChannelMask1)) : (id & kZDCChannelMask1);
196  zside = (id & kZDCZsideMask);
197  }
198  }
199 
200 public:
204 };
205 
206 std::ostream& operator<<(std::ostream&, const HcalZDCDetId& id);
207 
208 #endif // DataFormats_HcalDetId_HcalZDCDetId_h_included
static constexpr int32_t kDepTot
Definition: HcalZDCDetId.h:42
std::ostream & operator<<(std::ostream &, const HcalZDCDetId &id)
Definition: HcalZDCDetId.cc:3
static constexpr HcalZDCDetId detIdFromDenseIndex(uint32_t di)
Definition: HcalZDCDetId.h:145
constexpr uint32_t denseIndex() const
Definition: HcalZDCDetId.h:134
static constexpr int32_t kDepRun3
Definition: HcalZDCDetId.h:43
static constexpr uint32_t kZDCChannelMask2
Definition: HcalZDCDetId.h:27
static constexpr int32_t kSizeForDenseIndexingRun1
Definition: HcalZDCDetId.h:201
constexpr int32_t depth() const
get the depth (1 for EM, channel + 1 for HAD, 2 for RPD, not sure yet for LUM, leave as default) ...
Definition: HcalZDCDetId.h:100
static constexpr uint32_t packHcalZDCDetId(const Section &se, const bool &zside, const int32_t &channel)
Definition: HcalZDCDetId.h:173
static constexpr uint32_t kZDCRPDMask
Definition: HcalZDCDetId.h:31
static constexpr int32_t kDepHAD
Definition: HcalZDCDetId.h:38
static constexpr uint32_t newForm(const uint32_t &di)
Definition: HcalZDCDetId.h:122
static constexpr int32_t kDepEM
Definition: HcalZDCDetId.h:37
constexpr HcalZDCDetId()
Definition: HcalZDCDetId.h:46
static constexpr uint32_t kZDCnewFormat
Definition: HcalZDCDetId.h:32
static constexpr uint32_t kZDCZsideMask
Definition: HcalZDCDetId.h:30
constexpr HcalZDCDetId(const DetId &gen)
Definition: HcalZDCDetId.h:54
static constexpr uint32_t kZDCSectionMask
Definition: HcalZDCDetId.h:28
constexpr HcalZDCDetId(uint32_t rawid)
Definition: HcalZDCDetId.h:48
static constexpr bool validDetId(Section se, int32_t dp)
Definition: HcalZDCDetId.h:166
constexpr bool operator!=(DetId gen) const
Definition: HcalZDCDetId.h:79
static constexpr void unpackHcalZDCDetId(const uint32_t &id, Section &se, bool &zside, int32_t &channel)
Definition: HcalZDCDetId.h:188
Definition: DetId.h:17
static constexpr int32_t kSizeForDenseIndexing
Definition: HcalZDCDetId.h:203
static constexpr uint32_t kZDCChannelMask1
Definition: HcalZDCDetId.h:26
uint32_t id_
Definition: DetId.h:69
static constexpr int32_t kDepLUM
Definition: HcalZDCDetId.h:39
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:92
static constexpr int32_t kDepRun1
Definition: HcalZDCDetId.h:41
constexpr HcalZDCDetId(Section section, bool true_for_positive_eta, int32_t channel)
Definition: HcalZDCDetId.h:50
static constexpr bool validDenseIndex(const uint32_t &di)
Definition: HcalZDCDetId.h:143
constexpr HcalZDCDetId & operator=(const DetId &gen)
Definition: HcalZDCDetId.h:62
constexpr bool operator==(DetId gen) const
Definition: HcalZDCDetId.h:70
static constexpr int32_t kDepRPD
Definition: HcalZDCDetId.h:40
static constexpr int32_t SubdetectorId
Definition: HcalZDCDetId.h:35
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:112
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
static constexpr bool newFormat(const uint32_t &di)
Definition: HcalZDCDetId.h:121
static constexpr uint32_t kZDCSectionOffset
Definition: HcalZDCDetId.h:29
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:38
static constexpr int32_t kSizeForDenseIndexingRun3
Definition: HcalZDCDetId.h:202