CMS 3D CMS Logo

ZdcTopology.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <iostream>
6 #include <algorithm>
7 
9  : hcons_(hcons),
10  excludeEM_(false),
11  excludeHAD_(false),
12  excludeLUM_(false),
13  excludeRPD_(false),
14  excludeZP_(false),
15  excludeZN_(false),
16  firstEMModule_(1),
17  lastEMModule_(HcalZDCDetId::kDepEM),
18  firstHADModule_(1),
19  lastHADModule_(HcalZDCDetId::kDepHAD),
20  firstLUMModule_(1),
21  lastLUMModule_(HcalZDCDetId::kDepLUM),
22  firstRPDModule_(1),
23  lastRPDModule_(HcalZDCDetId::kDepRPD) {
26  edm::LogVerbatim("ForwardGeom") << "ZdcTopology : Mode " << mode_ << ":" << HcalTopologyMode::Mode::Run3
27  << " ExcludeRPD " << excludeRPD_;
28 }
29 
30 bool ZdcTopology::valid(const HcalZDCDetId& id) const {
31  // check the raw rules
32  bool ok = validRaw(id);
33  ok = ok && !isExcluded(id);
34  return ok;
35 }
36 
37 bool ZdcTopology::isExcluded(const HcalZDCDetId& id) const {
38  bool exed = false;
39 
40  // check for section exclutions
41  switch (id.section()) {
42  case (HcalZDCDetId::EM):
43  exed = excludeEM_;
44  break;
45  case (HcalZDCDetId::HAD):
46  exed = excludeHAD_;
47  break;
48  case (HcalZDCDetId::LUM):
49  exed = excludeLUM_;
50  break;
51  case (HcalZDCDetId::RPD):
52  exed = excludeRPD_;
53  break;
54  default:
55  exed = false;
56  }
57 
58  // check the entire list
59  if (!exed && !exclusionList_.empty()) {
60  std::vector<HcalZDCDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
61  if (i != exclusionList_.end() && *i == id)
62  exed = true;
63  }
64  return exed;
65 }
66 
68  std::vector<HcalZDCDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
69  if (i == exclusionList_.end() || *i != id) {
70  exclusionList_.insert(i, id);
71  }
72 }
73 
75  switch (zside) {
76  case (1):
77  excludeZP_ = true;
78  break;
79  case (-1):
80  excludeZN_ = true;
81  break;
82  default:
83  break;
84  }
85 }
86 
88  switch (zside) {
89  case (1):
90  excludeZP_ = true;
91  break;
92  case (-1):
93  excludeZN_ = true;
94  break;
95  default:
96  break;
97  }
98  switch (section) {
99  case (HcalZDCDetId::EM):
100  excludeEM_ = true;
101  break;
102  case (HcalZDCDetId::HAD):
103  excludeHAD_ = true;
104  break;
105  case (HcalZDCDetId::LUM):
106  excludeLUM_ = true;
107  break;
108  case (HcalZDCDetId::RPD):
109  excludeRPD_ = true;
110  break;
111  default:
112  break;
113  }
114 }
115 
117  bool exed = false;
118  switch (zside) {
119  case (1):
120  exed = excludeZP_;
121  break;
122  case (-1):
123  exed = excludeZN_;
124  break;
125  default:
126  exed = false;
127  }
128  if (exed)
129  return 0;
130 
131  switch (section) {
132  case (HcalZDCDetId::EM):
133  exed = excludeEM_;
134  break;
135  case (HcalZDCDetId::HAD):
136  exed = excludeHAD_;
137  break;
138  case (HcalZDCDetId::LUM):
139  exed = excludeLUM_;
140  break;
141  case (HcalZDCDetId::RPD):
142  exed = excludeRPD_;
143  break;
144  default:
145  exed = false;
146  }
147  if (exed)
148  return 0;
149 
150  bool isPositive = false;
151  if (zside == 1)
152  isPositive = true;
153 
154  int n = 0;
155  for (int ich = ich1; ich < ich2; ich++) {
156  HcalZDCDetId id(section, isPositive, ich);
157  if (validRaw(id))
158  exclude(id);
159  n++;
160  }
161  return n;
162 }
163 
164 bool ZdcTopology::validRaw(const HcalZDCDetId& id) const {
165  bool ok = true;
166  if (abs(id.zside()) != 1)
167  ok = false;
168  else if (id.channel() <= 0)
169  ok = false;
170  //else if (!(id.section() == HcalZDCDetId::EM || id.section() == HcalZDCDetId::HAD || id.section() == HcalZDCDetId::LUM))
171  else if (!(id.section() == HcalZDCDetId::EM || id.section() == HcalZDCDetId::HAD ||
173  ok = false;
174  else if (id.section() == HcalZDCDetId::EM && id.channel() > HcalZDCDetId::kDepEM)
175  ok = false;
176  else if (id.section() == HcalZDCDetId::HAD && id.channel() > HcalZDCDetId::kDepHAD)
177  ok = false;
178  else if (id.section() == HcalZDCDetId::LUM && id.channel() > HcalZDCDetId::kDepLUM)
179  ok = false;
180  else if (id.section() == HcalZDCDetId::RPD && id.channel() > HcalZDCDetId::kDepRPD)
181  ok = false;
182  return ok;
183 }
184 
185 std::vector<DetId> ZdcTopology::transverse(const DetId& id) const {
186  std::vector<DetId> vNeighborsDetId;
187  HcalZDCDetId zdcId = HcalZDCDetId(id);
188  HcalZDCDetId zdcDetId;
189  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::EM) {
190  bool isPositive = false;
191  if (zdcId.zside() == 1)
192  isPositive = true;
193  if (zdcId.channel() == 1) {
194  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
195  vNeighborsDetId.emplace_back(zdcDetId.rawId());
196  return vNeighborsDetId;
197  }
198  if (zdcId.channel() == HcalZDCDetId::kDepEM) {
199  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
200  vNeighborsDetId.emplace_back(zdcDetId.rawId());
201  return vNeighborsDetId;
202  }
203  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
204  vNeighborsDetId.emplace_back(zdcDetId.rawId());
205  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
206  vNeighborsDetId.emplace_back(zdcDetId.rawId());
207  }
208  return vNeighborsDetId;
209 }
210 
211 std::vector<DetId> ZdcTopology::longitudinal(const DetId& id) const {
212  std::vector<DetId> vNeighborsDetId;
213  HcalZDCDetId zdcId = HcalZDCDetId(id);
214  HcalZDCDetId zdcDetId;
215  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::HAD) {
216  bool isPositive = false;
217  if (zdcId.zside() == 1)
218  isPositive = true;
219  if (zdcId.channel() == 1) {
220  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
221  vNeighborsDetId.emplace_back(zdcDetId.rawId());
222  return vNeighborsDetId;
223  }
224  if (zdcId.channel() == HcalZDCDetId::kDepHAD) {
225  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
226  vNeighborsDetId.emplace_back(zdcDetId.rawId());
227  return vNeighborsDetId;
228  }
229  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
230  vNeighborsDetId.emplace_back(zdcDetId.rawId());
231  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
232  vNeighborsDetId.emplace_back(zdcDetId.rawId());
233  }
234  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::LUM) {
235  bool isPositive = false;
236  if (zdcId.zside() == 1)
237  isPositive = true;
238  if (zdcId.channel() == 1) {
239  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
240  vNeighborsDetId.emplace_back(zdcDetId.rawId());
241  return vNeighborsDetId;
242  }
243  if (zdcId.channel() == HcalZDCDetId::kDepLUM) {
244  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
245  vNeighborsDetId.emplace_back(zdcDetId.rawId());
246  return vNeighborsDetId;
247  }
248  }
249  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::RPD) {
250  bool isPositive = false;
251  if (zdcId.zside() == 1)
252  isPositive = true;
253  if (zdcId.channel() == 1) {
254  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
255  vNeighborsDetId.emplace_back(zdcDetId.rawId());
256  return vNeighborsDetId;
257  }
258  if (zdcId.channel() == HcalZDCDetId::kDepRPD) {
259  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
260  vNeighborsDetId.emplace_back(zdcDetId.rawId());
261  return vNeighborsDetId;
262  }
263  }
264  return vNeighborsDetId;
265 }
266 
267 std::vector<DetId> ZdcTopology::east(const DetId& /*id*/) const {
268  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::east() not yet implemented";
269  std::vector<DetId> vNeighborsDetId;
270  return vNeighborsDetId;
271 }
272 
273 std::vector<DetId> ZdcTopology::west(const DetId& /*id*/) const {
274  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::west() not yet implemented";
275  std::vector<DetId> vNeighborsDetId;
276  return vNeighborsDetId;
277 }
278 
279 std::vector<DetId> ZdcTopology::north(const DetId& /*id*/) const {
280  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::north() not yet implemented";
281  std::vector<DetId> vNeighborsDetId;
282  return vNeighborsDetId;
283 }
284 std::vector<DetId> ZdcTopology::south(const DetId& /*id*/) const {
285  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::south() not yet implemented";
286  std::vector<DetId> vNeighborsDetId;
287  return vNeighborsDetId;
288 }
289 std::vector<DetId> ZdcTopology::up(const DetId& /*id*/) const {
290  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::up() not yet implemented";
291  std::vector<DetId> vNeighborsDetId;
292  return vNeighborsDetId;
293 }
294 std::vector<DetId> ZdcTopology::down(const DetId& /*id*/) const {
295  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::down() not yet implemented";
296  std::vector<DetId> vNeighborsDetId;
297  return vNeighborsDetId;
298 }
299 
301  int ncells = 0;
302  switch (section) {
303  case (HcalZDCDetId::EM):
305  break;
306  case (HcalZDCDetId::HAD):
308  break;
309  case (HcalZDCDetId::LUM):
311  break;
312  case (HcalZDCDetId::RPD):
314  break;
315  case (HcalZDCDetId::Unknown):
316  ncells = 0;
317  break;
318  }
319  return ncells;
320 }
321 
323  int firstCell = 0;
324  switch (section) {
325  case (HcalZDCDetId::EM):
327  break;
328  case (HcalZDCDetId::HAD):
330  break;
331  case (HcalZDCDetId::LUM):
333  break;
334  case (HcalZDCDetId::RPD):
336  break;
337  case (HcalZDCDetId::Unknown):
338  firstCell = 0;
339  break;
340  }
341  return firstCell;
342 }
343 
345  int lastCell = 0;
346  switch (section) {
347  case (HcalZDCDetId::EM):
349  break;
350  case (HcalZDCDetId::HAD):
352  break;
353  case (HcalZDCDetId::LUM):
355  break;
356  case (HcalZDCDetId::RPD):
358  break;
359  case (HcalZDCDetId::Unknown):
360  lastCell = 0;
361  break;
362  }
363  return lastCell;
364 }
365 
369 }
370 
371 DetId ZdcTopology::denseId2detId(uint32_t di) const {
372  if (validDenseIndex(di)) {
373  bool lz(false);
374  uint32_t dp(0);
376  if (di >= 2 * HcalZDCDetId::kDepRun1) {
378  se = HcalZDCDetId::RPD;
379  dp = 1 + ((di - 2 * HcalZDCDetId::kDepRun1) % HcalZDCDetId::kDepRPD);
380  } else {
381  lz = (di >= HcalZDCDetId::kDepRun1);
382  uint32_t in = (di % HcalZDCDetId::kDepRun1);
383  se = (in < HcalZDCDetId::kDepEM
386  dp = (se == HcalZDCDetId::EM ? in + 1
387  : (se == HcalZDCDetId::HAD ? in - HcalZDCDetId::kDepEM + 1
389  }
390  return static_cast<DetId>(HcalZDCDetId(se, lz, dp));
391  }
392  return DetId();
393 }
394 
395 uint32_t ZdcTopology::detId2DenseIndex(const DetId& id) const {
396  HcalZDCDetId detId(id);
397  const int32_t se(detId.section());
398  uint32_t di = (detId.channel() - 1 +
399  (se == HcalZDCDetId::RPD
400  ? 2 * HcalZDCDetId::kDepRun1 + (detId.zside() < 0 ? 0 : HcalZDCDetId::kDepRPD)
401  : ((detId.zside() < 0 ? 0 : HcalZDCDetId::kDepRun1) +
402  (se == HcalZDCDetId::HAD
405  return di;
406 }
int firstEMModule_
Definition: ZdcTopology.h:83
Log< level::Info, true > LogVerbatim
std::vector< DetId > down(const DetId &id) const override
Definition: ZdcTopology.cc:294
bool excludeEM_
Definition: ZdcTopology.h:81
void exclude(const HcalZDCDetId &id)
Definition: ZdcTopology.cc:67
int lastLUMModule_
Definition: ZdcTopology.h:83
uint32_t kSizeForDenseIndexing() const
Definition: ZdcTopology.cc:366
static constexpr int32_t kDepTot
Definition: HcalZDCDetId.h:42
bool excludeRPD_
Definition: ZdcTopology.h:81
bool excludeHAD_
Definition: ZdcTopology.h:81
int zside(DetId const &)
ZdcTopology(const HcalDDDRecConstants *hcons)
Definition: ZdcTopology.cc:8
static constexpr int32_t kSizeForDenseIndexingRun1
Definition: HcalZDCDetId.h:201
std::vector< DetId > up(const DetId &id) const override
Definition: ZdcTopology.cc:289
const HcalDDDRecConstants * hcons_
Definition: ZdcTopology.h:76
HcalTopologyMode::Mode mode_
Definition: ZdcTopology.h:77
std::vector< DetId > north(const DetId &id) const override
Definition: ZdcTopology.cc:279
int firstRPDModule_
Definition: ZdcTopology.h:83
static constexpr int32_t kDepHAD
Definition: HcalZDCDetId.h:38
bool excludeZN_
Definition: ZdcTopology.h:81
static constexpr int32_t kDepEM
Definition: HcalZDCDetId.h:37
uint32_t detId2DenseIndex(const DetId &id) const
Definition: ZdcTopology.cc:395
std::vector< DetId > south(const DetId &id) const override
Definition: ZdcTopology.cc:284
int firstHADModule_
Definition: ZdcTopology.h:83
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DetId denseId2detId(uint32_t di) const override
Definition: ZdcTopology.cc:371
virtual std::vector< DetId > transverse(const DetId &id) const
Definition: ZdcTopology.cc:185
std::vector< HcalZDCDetId > exclusionList_
Definition: ZdcTopology.h:79
bool excludeLUM_
Definition: ZdcTopology.h:81
int lastRPDModule_
Definition: ZdcTopology.h:83
virtual bool valid(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:30
int firstCell(HcalZDCDetId::Section section) const
Definition: ZdcTopology.cc:322
std::vector< DetId > east(const DetId &id) const override
Definition: ZdcTopology.cc:267
Definition: DetId.h:17
std::vector< DetId > west(const DetId &id) const override
Definition: ZdcTopology.cc:273
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual unsigned int ncells() const
return a count of valid cells (for dense indexing use)
int lastCell(HcalZDCDetId::Section section) const
Definition: ZdcTopology.cc:344
static constexpr int32_t kDepLUM
Definition: HcalZDCDetId.h:39
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:92
bool validRaw(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:164
static constexpr int32_t kDepRun1
Definition: HcalZDCDetId.h:41
bool validDenseIndex(uint32_t din) const
Definition: ZdcTopology.h:57
bool excludeZP_
Definition: ZdcTopology.h:81
static constexpr int32_t kDepRPD
Definition: HcalZDCDetId.h:40
int lastEMModule_
Definition: ZdcTopology.h:83
bool isExcluded(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:37
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:112
int firstLUMModule_
Definition: ZdcTopology.h:83
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
static constexpr int32_t kSizeForDenseIndexingRun3
Definition: HcalZDCDetId.h:202
virtual std::vector< DetId > longitudinal(const DetId &id) const
Definition: ZdcTopology.cc:211
int lastHADModule_
Definition: ZdcTopology.h:83