CMS 3D CMS Logo

HcalTopology.cc
Go to the documentation of this file.
2 #include <cmath>
3 #include <iostream>
4 #include <cassert>
5 #include <algorithm>
9 
10 using namespace geant_units;
11 using namespace geant_units::operators;
12 
13 static const int IPHI_MAX = 72;
14 
15 //#define EDM_ML_DEBUG
16 
17 HcalTopology::HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePosition)
18  : hcons_(hcons),
19  mergePosition_(mergePosition),
20  excludeHB_(false),
21  excludeHE_(false),
22  excludeHO_(false),
23  excludeHF_(false),
24  firstHBRing_(1),
25  firstHERing_(999),
26  lastHERing_(0),
27  firstHFRing_(29),
28  lastHFRing_(41),
29  firstHORing_(1),
30  lastHORing_(15),
31  firstHEDoublePhiRing_(999),
32  firstHEQuadPhiRing_(999),
33  firstHFQuadPhiRing_(40),
34  firstHETripleDepthRing_(999),
35  singlePhiBins_(IPHI_MAX),
36  doublePhiBins_(36),
37  maxPhiHE_(IPHI_MAX) {
47  if (hcons_->getNPhi(1) > maxPhiHE_)
48  maxPhiHE_ = hcons_->getNPhi(1);
49  for (auto& i : etaBinsHE_) {
50  if (firstHERing_ > i.ieta)
51  firstHERing_ = i.ieta;
52  if (lastHERing_ < i.ieta)
53  lastHERing_ = i.ieta;
54  int unit = static_cast<int>((i.dphi / 5.0_deg) + 0.01);
55  if (unit == 2 && firstHEDoublePhiRing_ > i.ieta)
56  firstHEDoublePhiRing_ = i.ieta;
57  if (unit == 4 && firstHEQuadPhiRing_ > i.ieta)
58  firstHEQuadPhiRing_ = i.ieta;
59  if (i.layer.size() > 2 && firstHETripleDepthRing_ > i.ieta)
61  }
62  if (firstHERing_ > lastHERing_) {
64  } else {
66  }
68  topoVersion_ = 0; //DL
69  HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
70  HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
71  HOSize_ = kHOSizePreLS1; // ieta * iphi * 2
72  HFSize_ = kHFSizePreLS1; // ieta * iphi * depth * 2
74  numberOfShapes_ = 87;
75  } else if (mode_ == HcalTopologyMode::SLHC) { // need to know more eventually
76  topoVersion_ = 10;
79  HOSize_ = (lastHORing_ - firstHORing_ + 1) * IPHI_MAX * 2; // ieta * iphi * 2
80  HFSize_ = (lastHFRing_ - firstHFRing_ + 1) * IPHI_MAX * maxDepthHF_ * 2; // ieta * iphi * depth * 2
82  numberOfShapes_ = (maxPhiHE_ > 72) ? 1200 : 500;
83  }
87  } else {
89  }
90 
91 #ifdef EDM_ML_DEBUG
92  edm::LogVerbatim("HCalGeom") << "Topo sizes " << HBSize_ << ":" << HESize_ << ":" << HOSize_ << ":" << HFSize_ << ":"
93  << HTSize_ << ":" << CALIBSize_ << " for mode " << mode_ << ":" << triggerMode_;
94 #endif
95 
96  //The transition between HE/HF in eta
101  phioff = hcons_->getPhiOffs();
102  std::pair<int, int> ietaHF = hcons_->getEtaRange(2);
105  if (etaBinsHE_.size() > 1) {
106  double eta = etaBinsHE_[etaBinsHE_.size() - 1].etaMax;
107  for (unsigned int i = 1; i < etaTableHF.size(); ++i) {
108  if (eta < etaTableHF[i]) {
109  etaHE2HF_ = ietaHF.first + i - 1;
110  break;
111  }
112  }
113  eta = etaTableHF[0];
114  for (auto& i : etaBinsHE_) {
115  if (eta < i.etaMax) {
116  etaHF2HE_ = i.ieta;
117  break;
118  }
119  }
120  }
121  const double fiveDegInRad = 5.0_deg;
122  for (double k : dPhiTable) {
123  int units = (int)(k / fiveDegInRad + 0.5);
124  unitPhi.emplace_back(units);
125  }
126  for (double k : dPhiTableHF) {
127  int units = (int)(k / fiveDegInRad + 0.5);
128  unitPhiHF.emplace_back(units);
129  }
130  int nEta = hcons_->getNEta();
131  for (int ring = 1; ring <= nEta; ++ring) {
132  std::vector<int> segmentation = hcons_->getDepth(ring - 1, false);
133  setDepthSegmentation(ring, segmentation, false);
134 #ifdef EDM_ML_DEBUG
135  edm::LogVerbatim("HCalGeom") << "Set segmentation for ring " << ring << " with " << segmentation.size()
136  << " elements:";
137  for (unsigned int k = 0; k < segmentation.size(); ++k)
138  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << segmentation[k];
139 #endif
140  segmentation = hcons_->getDepth(ring - 1, true);
141  setDepthSegmentation(ring, segmentation, true);
142 #ifdef EDM_ML_DEBUG
143  edm::LogVerbatim("HCalGeom") << "Set Plan-1 segmentation for ring " << ring << " with " << segmentation.size()
144  << " elements:";
145  for (unsigned int k = 0; k < segmentation.size(); ++k)
146  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << segmentation[k];
147 #endif
148  }
149 
150 #ifdef EDM_ML_DEBUG
151  edm::LogVerbatim("HCalGeom") << "Constants in HcalTopology " << firstHBRing_ << ":" << lastHBRing_ << " "
152  << firstHERing_ << ":" << lastHERing_ << ":" << firstHEDoublePhiRing_ << ":"
153  << firstHEQuadPhiRing_ << ":" << firstHETripleDepthRing_ << " " << firstHFRing_ << ":"
154  << lastHFRing_ << ":" << firstHFQuadPhiRing_ << " " << firstHORing_ << ":" << lastHORing_
155  << " " << maxDepthHB_ << ":" << maxDepthHE_ << " " << nEtaHB_ << ":" << nEtaHE_ << " "
156  << etaHE2HF_ << ":" << etaHF2HE_ << " " << maxPhiHE_;
157 #endif
158 }
159 
161  int maxDepthHB,
162  int maxDepthHE,
164  : hcons_(nullptr),
165  mergePosition_(false),
166  excludeHB_(false),
167  excludeHE_(false),
168  excludeHO_(false),
169  excludeHF_(false),
170  mode_(mode),
171  triggerMode_(tmode),
172  firstHBRing_(1),
173  lastHBRing_(16),
174  firstHERing_(16),
175  lastHERing_(29),
176  firstHFRing_(29),
177  lastHFRing_(41),
178  firstHORing_(1),
179  lastHORing_(15),
180  firstHEDoublePhiRing_((mode == HcalTopologyMode::H2 || mode == HcalTopologyMode::H2HE) ? (22) : (21)),
181  firstHEQuadPhiRing_(999),
182  firstHFQuadPhiRing_(40),
183  firstHETripleDepthRing_((mode == HcalTopologyMode::H2 || mode == HcalTopologyMode::H2HE) ? (24) : (27)),
184  singlePhiBins_(IPHI_MAX),
185  doublePhiBins_(36),
186  maxDepthHB_(maxDepthHB),
187  maxDepthHE_(maxDepthHE),
188  maxDepthHF_(2),
189  etaHE2HF_(30),
190  etaHF2HE_(29),
191  maxPhiHE_(IPHI_MAX),
192  HBSize_(kHBSizePreLS1),
193  HESize_(kHESizePreLS1),
194  HOSize_(kHOSizePreLS1),
195  HFSize_(kHFSizePreLS1),
196  HTSize_(kHTSizePreLS1),
197  CALIBSize_(kCALIBSizePreLS1),
198  numberOfShapes_(
199  ((mode == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::Run4))
200  ? 500
201  : 87) {
202  if (mode_ == HcalTopologyMode::LHC) {
203  topoVersion_ = 0; //DL
204  HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
205  HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
206  HOSize_ = kHOSizePreLS1; // ieta * iphi * 2
207  HFSize_ = kHFSizePreLS1; // phi * eta * depth * pm
208  } else if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::Run3) ||
209  (mode_ == HcalTopologyMode::Run4)) { // need to know more eventually
210  HBSize_ = maxDepthHB * 16 * IPHI_MAX * 2;
211  HESize_ = maxDepthHE * (29 - 16 + 1) * maxPhiHE_ * 2;
212  HOSize_ = 15 * IPHI_MAX * 2; // ieta * iphi * 2
213  HFSize_ = IPHI_MAX * 13 * maxDepthHF_ * 2; // phi * eta * depth * pm
215  topoVersion_ = 10;
216  }
217  nEtaHB_ = (lastHBRing_ - firstHBRing_ + 1);
218  nEtaHE_ = (lastHERing_ - firstHERing_ + 1);
221  } else {
223  }
224 
225  edm::LogWarning("HCalGeom") << "This is an incomplete constructor of HcalTopology - be warned that many "
226  << "functionalities will not be there - revert from this - get from EventSetup";
227 }
228 
229 bool HcalTopology::valid(const DetId& id) const {
230  assert(id.det() == DetId::Hcal);
231  return validHcal(id);
232 }
233 
234 bool HcalTopology::validHcal(const HcalDetId& id) const {
235  // check the raw rules
236  return validRaw(id) && !isExcluded(id);
237 }
238 
239 bool HcalTopology::validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const {
240  return validHcal(HcalDetId(subdet, ieta, iphi, depth));
241 }
242 
244  if (id.iphi() < 1 || id.iphi() > IPHI_MAX || id.ieta() == 0)
245  return false;
246  if (id.depth() != 0)
247  return false;
248  if (maxDepthHE_ == 0) {
249  if (id.ietaAbs() > lastHBRing_ && id.ietaAbs() < firstHFRing_)
250  return false;
251  }
252  // Version 2 TPs should be for HBHE when using 1TS filter scheme
253  if (id.version() == 0 or id.version() == 2) {
254  if (id.ietaAbs() > 28) {
256  return false;
258  return false;
259  if ((id.iphi() % 4) != 1)
260  return false;
261  if (id.ietaAbs() > 32)
262  return false;
263  }
264  } else if (id.version() == 1) {
266  return false;
267  if (id.ietaAbs() < 30 || id.ietaAbs() > 41)
268  return false;
269  if (id.ietaAbs() > 29 && ((id.iphi() % 2) == 0))
270  return false;
271  if (id.ietaAbs() > 39 && ((id.iphi() % 4) != 3))
272  return false;
273  } else if (id.version() > 2) {
274  // only versions 0, 1, and 2 are supported
275  return false;
276  }
277 
278  return true;
279 }
280 
281 bool HcalTopology::validCalib(const HcalCalibDetId& tid) const {
282  bool ok(false);
284  HcalSubdetector subdet = tid.hcalSubdet();
285  int ieta = tid.ieta();
286  int chan = tid.cboxChannel();
287  unsigned int iphi = static_cast<unsigned int>(tid.iphi());
288  if (subdet == HcalBarrel) {
291  (iphi >= minPhi_) && (iphi <= maxPhi_))
292  ok = true;
293  } else if (subdet == HcalEndcap) {
296  (chan == chanCalibHE2_)) &&
297  (iphi >= minPhi_) && (iphi <= maxPhi_))
298  ok = true;
299  } else if (subdet == HcalForward) {
302  (chan == chanCalibHF2_)) &&
303  (iphi >= minPhi_) && (iphi <= maxPhi_))
304  ok = true;
305  } else if (subdet == HcalOuter) {
308  (chan == chanCalibHOs_)) &&
309  (iphi >= minPhi_) && (iphi <= maxPhi_))
310  ok = true;
311  }
312  } else if (tid.calibFlavor() == HcalCalibDetId::HOCrosstalk) {
313  int ieta = std::abs(tid.ieta());
314  unsigned int iphi = static_cast<unsigned int>(tid.iphi());
316  (iphi >= minPhi_) && (iphi <= maxPhi_))
317  ok = true;
318  } else if (tid.calibFlavor() == HcalCalibDetId::HBX) {
319  int ieta = std::abs(tid.ieta());
320  unsigned int iphi = static_cast<unsigned int>(tid.iphi());
321  if ((ieta == etaCalibHBX_) && (iphi >= minPhi_) && (iphi <= maxPhi_))
322  ok = true;
323  } else if (tid.calibFlavor() == HcalCalibDetId::HEX) {
324  int ieta = std::abs(tid.ieta());
325  unsigned int iphi = static_cast<unsigned int>(tid.iphi());
327  (iphi >= minPhi_) && (iphi <= maxPhi_))
328  ok = true;
329  } else if ((tid.calibFlavor() == HcalCalibDetId::uMNqie) || (tid.calibFlavor() == HcalCalibDetId::LASERMON) ||
331  ok = true;
332  }
333  return ok;
334 }
335 
336 bool HcalTopology::validHcal(const HcalDetId& id, const unsigned int flag) const {
337  /* original logic show here because condensed form below is rather terse
338  // check the raw rules
339  bool ok = validHcal(id);
340  if (flag == 0) { // This is all what is needed
341  } else if (flag == 1) { // See if it is in the to be merged list and merged list
342  if (hcons_->isPlan1MergedId(id)) ok = true;
343  else if (hcons_->isPlan1ToBeMergedId(id)) ok = false;
344  } else if (!ok) {
345  ok = hcons_->isPlan1MergedId(id);
346  }
347  return ok;
348  */
349  return (flag > 0 and hcons_->isPlan1MergedId(id)) or
350  ((flag != 1 or !hcons_->isPlan1ToBeMergedId(id)) and validHcal(id));
351 }
352 
353 bool HcalTopology::isExcluded(const HcalDetId& id) const {
354  bool exed = false;
355  // first, check the full detector exclusions... (fast)
356  switch (id.subdet()) {
357  case (HcalBarrel):
358  exed = excludeHB_;
359  break;
360  case (HcalEndcap):
361  exed = excludeHE_;
362  break;
363  case (HcalOuter):
364  exed = excludeHO_;
365  break;
366  case (HcalForward):
367  exed = excludeHF_;
368  break;
369  default:
370  exed = false;
371  }
372  // next, check the list (slower)
373  if (!exed && !exclusionList_.empty()) {
374  std::vector<HcalDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
375  if (i != exclusionList_.end() && *i == id)
376  exed = true;
377  }
378  return exed;
379 }
380 
382  std::vector<HcalDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
383  if (i == exclusionList_.end() || *i != id) {
384  exclusionList_.insert(i, id);
385  }
386 }
387 
389  switch (subdet) {
390  case (HcalBarrel):
391  excludeHB_ = true;
392  break;
393  case (HcalEndcap):
394  excludeHE_ = true;
395  break;
396  case (HcalOuter):
397  excludeHO_ = true;
398  break;
399  case (HcalForward):
400  excludeHF_ = true;
401  break;
402  default:
403  break;
404  }
405 }
406 
407 std::vector<DetId> HcalTopology::east(const DetId& id) const {
408  std::vector<DetId> vNeighborsDetId;
409  HcalDetId neighbors[2];
410  for (int i = 0; i < decIEta(HcalDetId(id), neighbors); i++) {
411  if (neighbors[i].oldFormat())
412  neighbors[i].changeForm();
413  vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
414  }
415  return vNeighborsDetId;
416 }
417 
418 std::vector<DetId> HcalTopology::west(const DetId& id) const {
419  std::vector<DetId> vNeighborsDetId;
420  HcalDetId neighbors[2];
421  for (int i = 0; i < incIEta(HcalDetId(id), neighbors); i++) {
422  if (neighbors[i].oldFormat())
423  neighbors[i].changeForm();
424  vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
425  }
426  return vNeighborsDetId;
427 }
428 
429 std::vector<DetId> HcalTopology::north(const DetId& id) const {
430  std::vector<DetId> vNeighborsDetId;
431  HcalDetId neighbor;
432  if (incIPhi(HcalDetId(id), neighbor)) {
433  if (neighbor.oldFormat())
434  neighbor.changeForm();
435  vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
436  }
437  return vNeighborsDetId;
438 }
439 
440 std::vector<DetId> HcalTopology::south(const DetId& id) const {
441  std::vector<DetId> vNeighborsDetId;
442  HcalDetId neighbor;
443  if (decIPhi(HcalDetId(id), neighbor)) {
444  if (neighbor.oldFormat())
445  neighbor.changeForm();
446  vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
447  }
448  return vNeighborsDetId;
449 }
450 
451 std::vector<DetId> HcalTopology::up(const DetId& id) const {
452  HcalDetId neighbor = id;
453  std::vector<DetId> vNeighborsDetId;
454  if (incrementDepth(neighbor)) {
455  if (neighbor.oldFormat())
456  neighbor.changeForm();
457  vNeighborsDetId.emplace_back(neighbor);
458  }
459  return vNeighborsDetId;
460 }
461 
462 std::vector<DetId> HcalTopology::down(const DetId& id) const {
463  HcalDetId neighbor = id;
464  std::vector<DetId> vNeighborsDetId;
465  if (decrementDepth(neighbor)) {
466  if (neighbor.oldFormat())
467  neighbor.changeForm();
468  vNeighborsDetId.emplace_back(neighbor);
469  }
470  return vNeighborsDetId;
471 }
472 
473 int HcalTopology::exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi1, int iphi2, int depth1, int depth2) {
474  bool exed = false;
475  // first, check the full detector exclusions... (fast)
476  switch (subdet) {
477  case (HcalBarrel):
478  exed = excludeHB_;
479  break;
480  case (HcalEndcap):
481  exed = excludeHE_;
482  break;
483  case (HcalOuter):
484  exed = excludeHO_;
485  break;
486  case (HcalForward):
487  exed = excludeHF_;
488  break;
489  default:
490  exed = false;
491  }
492  if (exed)
493  return 0; // if the whole detector is excluded...
494 
495  int ieta_l = std::min(ieta1, ieta2);
496  int ieta_h = std::max(ieta1, ieta2);
497  int iphi_l = std::min(iphi1, iphi2);
498  int iphi_h = std::max(iphi1, iphi2);
499  int depth_l = std::min(depth1, depth2);
500  int depth_h = std::max(depth1, depth2);
501 
502  int n = 0;
503  for (int ieta = ieta_l; ieta <= ieta_h; ieta++)
504  for (int iphi = iphi_l; iphi <= iphi_h; iphi++)
505  for (int depth = depth_l; depth <= depth_h; depth++) {
506  HcalDetId id(subdet, ieta, iphi, depth);
507  if (validRaw(id)) { // use 'validRaw' to include check validity in "uncut" detector
508  exclude(id);
509  n++;
510  }
511  }
512  return n;
513 }
514 
542  const HcalSubdetector sd(id.subdet());
543  const int ie(id.ietaAbs());
544  const int ip(id.iphi());
545  const int dp(id.depth());
546 
547  return ((ip >= 1) && (ip <= IPHI_MAX) && (dp >= 1) && (ie >= 1) &&
548  (((sd == HcalBarrel) && (((ie <= 14) && (dp == 1)) || (((ie == 15) || (ie == 16)) && (dp <= 2)))) ||
549  ((sd == HcalEndcap) &&
550  (((ie == firstHERing()) && (dp == 3)) || ((ie == 17) && (dp == 1)) ||
551  ((ie >= 18) && (ie <= 20) && (dp <= 2)) || ((ie >= 21) && (ie <= 26) && (dp <= 2) && (ip % 2 == 1)) ||
552  ((ie >= 27) && (ie <= 28) && (dp <= 3) && (ip % 2 == 1)) || ((ie == 29) && (dp <= 2) && (ip % 2 == 1)))) ||
553  ((sd == HcalOuter) && (ie <= 15) && (dp == 4)) ||
554  ((sd == HcalForward) && (dp <= 2) &&
555  (((ie >= firstHFRing()) && (ie < firstHFQuadPhiRing()) && (ip % 2 == 1)) ||
556  ((ie >= firstHFQuadPhiRing()) && (ie <= lastHFRing()) && (ip % 4 == 3))))));
557 }
558 
560 bool HcalTopology::validRaw(const HcalDetId& id) const {
561  bool ok = true;
562  int ieta = id.ieta();
563  int aieta = id.ietaAbs();
564  int depth = id.depth();
565  int iphi = id.iphi();
566  int zside = id.zside();
567  HcalSubdetector subdet = id.subdet();
568  int maxPhi = (subdet == HcalEndcap) ? maxPhiHE_ : IPHI_MAX;
569  if ((ieta == 0 || iphi <= 0 || iphi > maxPhi) || aieta > maxEta_)
570  ok = false; // outer limits
571 
572  if (ok) {
573  if (subdet == HcalBarrel) {
576  if ((aieta > lastHBRing()) || (depth > hcons_->getMaxDepth(0, aieta, iphi, zside)) ||
577  (depth < hcons_->getMinDepth(0, aieta, iphi, zside)))
578  ok = false;
579  } else {
580  if (aieta > lastHBRing() || depth > 2 || (aieta <= 14 && depth > 1))
581  ok = false;
582  }
583  } else if (subdet == HcalEndcap) {
586  if ((depth > hcons_->getMaxDepth(1, aieta, iphi, zside)) ||
587  (depth < hcons_->getMinDepth(1, aieta, iphi, zside)) || (aieta < firstHERing()) || (aieta > lastHERing())) {
588  ok = false;
589  } else {
590  for (const auto& i : etaBinsHE_) {
591  if (aieta == i.ieta) {
592  if (aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0)
593  ok = false;
594  if (aieta >= firstHEQuadPhiRing() && (iphi % 4) != 3)
595  ok = false;
596  if (aieta + 1 == hcons_->getNoff(1)) {
597  if (depth < 1)
598  ok = false;
599  } else {
600  if (depth < i.depthStart)
601  ok = false;
602  }
603  break;
604  }
605  }
606  }
607  } else {
608  if (depth > hcons_->getMaxDepth(1, aieta, iphi, zside) || aieta < firstHERing() || aieta > lastHERing() ||
609  (aieta == firstHERing() && depth != hcons_->getDepthEta16(2, iphi, zside)) ||
610  (aieta == 17 && depth != 1 && mode_ != HcalTopologyMode::H2) || // special case at H2
611  (((aieta >= 17 && aieta < firstHETripleDepthRing()) || aieta == lastHERing()) && depth > 2) ||
612  (aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0))
613  ok = false;
614  }
615  } else if (subdet == HcalOuter) {
616  if (aieta > lastHORing() || iphi > IPHI_MAX || depth != 4)
617  ok = false;
618  } else if (subdet == HcalForward) {
619  if (aieta < firstHFRing() || aieta > lastHFRing() || ((iphi % 2) == 0) ||
620  (depth > hcons_->maxHFDepth(ieta, iphi)) || (aieta >= firstHFQuadPhiRing() && ((iphi + 1) % 4) != 0))
621  ok = false;
622  } else if (subdet == HcalTriggerTower) {
624  } else if (subdet == HcalOther) {
626  } else {
627  ok = false;
628  }
629  }
630  return ok;
631 }
632 
633 bool HcalTopology::incIPhi(const HcalDetId& id, HcalDetId& neighbor) const {
634  bool ok = valid(id);
635  if (ok) {
636  switch (id.subdet()) {
637  case (HcalBarrel):
638  case (HcalOuter):
639  if (id.iphi() == IPHI_MAX)
640  neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
641  else
642  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 1, id.depth());
643  break;
644  case (HcalEndcap):
645  if (id.ietaAbs() >= firstHEQuadPhiRing()) {
646  if (id.iphi() == IPHI_MAX - 1)
647  neighbor = HcalDetId(id.subdet(), id.ieta(), 3, id.depth());
648  else
649  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 4, id.depth());
650  } else if (id.ietaAbs() >= firstHEDoublePhiRing()) {
651  if (id.iphi() == IPHI_MAX - 1)
652  neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
653  else
654  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 2, id.depth());
655  } else {
656  if (id.iphi() == maxPhiHE_)
657  neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
658  else
659  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 1, id.depth());
660  }
661  break;
662  case (HcalForward):
663  if (id.ietaAbs() >= firstHFQuadPhiRing()) {
664  if (id.iphi() == IPHI_MAX - 1)
665  neighbor = HcalDetId(id.subdet(), id.ieta(), 3, id.depth());
666  else
667  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 4, id.depth());
668  } else {
669  if (id.iphi() == IPHI_MAX - 1)
670  neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
671  else
672  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 2, id.depth());
673  }
674  if (!validRaw(neighbor))
675  ok = false;
676  break;
677  default:
678  ok = false;
679  }
680  }
681  return ok;
682 }
683 
685 bool HcalTopology::decIPhi(const HcalDetId& id, HcalDetId& neighbor) const {
686  bool ok = valid(id);
687  if (ok) {
688  switch (id.subdet()) {
689  case (HcalBarrel):
690  case (HcalOuter):
691  if (id.iphi() == 1)
692  neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX, id.depth());
693  else
694  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 1, id.depth());
695  break;
696  case (HcalEndcap):
697  if (id.ietaAbs() >= firstHEQuadPhiRing()) {
698  if (id.iphi() == 3)
699  neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
700  else
701  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 4, id.depth());
702  } else if (id.ietaAbs() >= firstHEDoublePhiRing()) {
703  if (id.iphi() == 1)
704  neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
705  else
706  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 2, id.depth());
707  } else {
708  if (id.iphi() == 1)
709  neighbor = HcalDetId(id.subdet(), id.ieta(), maxPhiHE_, id.depth());
710  else
711  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 1, id.depth());
712  }
713  break;
714  case (HcalForward):
715  if (id.ietaAbs() >= firstHFQuadPhiRing()) {
716  if (id.iphi() == 3)
717  neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
718  else
719  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 4, id.depth());
720  } else {
721  if (id.iphi() == 1)
722  neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
723  else
724  neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 2, id.depth());
725  }
726  if (!validRaw(neighbor))
727  ok = false;
728  break;
729  default:
730  ok = false;
731  }
732  }
733  return ok;
734 }
735 
736 int HcalTopology::incIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
737  if (id.zside() == 1)
738  return incAIEta(id, neighbors);
739  else
740  return decAIEta(id, neighbors);
741 }
742 
743 int HcalTopology::decIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
744  if (id.zside() == 1)
745  return decAIEta(id, neighbors);
746  else
747  return incAIEta(id, neighbors);
748 }
749 
751 int HcalTopology::incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
752  int n = 1;
753  int aieta = id.ietaAbs();
754 
755  if (aieta == firstHEDoublePhiRing() - 1 && (id.iphi() % 2) == 0)
756  neighbors[0] = HcalDetId(id.subdet(), (aieta + 1) * id.zside(), id.iphi() - 1, id.depth());
757  else if (aieta == firstHFQuadPhiRing() - 1 && ((id.iphi() + 1) % 4) != 0)
758  neighbors[0] =
759  HcalDetId(id.subdet(), (aieta + 1) * id.zside(), ((id.iphi() == 1) ? (71) : (id.iphi() - 2)), id.depth());
760  else if (aieta == firstHEQuadPhiRing() - 1 && ((id.iphi() + 1) % 4) != 0)
761  neighbors[0] =
762  HcalDetId(id.subdet(), (aieta + 1) * id.zside(), ((id.iphi() == 1) ? (71) : (id.iphi() - 2)), id.depth());
763  else if (aieta == lastHBRing() && id.subdet() == HcalBarrel)
764  neighbors[0] = HcalDetId(HcalEndcap, (aieta + 1) * id.zside(), id.iphi(), 1);
765  else if (aieta == lastHERing() && id.subdet() == HcalEndcap)
766  neighbors[0] = HcalDetId(HcalForward, etaHE2HF_ * id.zside(), id.iphi(), 1);
767  else
768  neighbors[0] = HcalDetId(id.subdet(), (aieta + 1) * id.zside(), id.iphi(), id.depth());
769 
770  if (!valid(neighbors[0]))
771  n = 0;
772  return n;
773 }
774 
776 int HcalTopology::decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
777  int n = 1;
778  int aieta = id.ietaAbs();
779 
780  if (aieta == firstHEDoublePhiRing()) {
781  n = 2;
782  neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
783  neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 1, id.depth());
784  } else if (aieta == firstHFQuadPhiRing()) {
785  n = 2;
786  neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
787  if (id.iphi() == IPHI_MAX - 1)
788  neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), 1, id.depth());
789  else
790  neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 2, id.depth());
791  } else if (aieta == firstHEQuadPhiRing()) {
792  n = 2;
793  neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
794  if (id.iphi() == IPHI_MAX - 1)
795  neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), 1, id.depth());
796  else
797  neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 2, id.depth());
798  } else if (aieta == 1) {
799  neighbors[0] = HcalDetId(id.subdet(), -aieta * id.zside(), id.iphi(), id.depth());
800  } else if (aieta == firstHERing() && id.subdet() == HcalEndcap) {
801  neighbors[0] = HcalDetId(HcalBarrel, (aieta - 1) * id.zside(), id.iphi(), 1);
802  } else if (aieta == firstHFRing() && id.subdet() == HcalForward) {
803  neighbors[0] = HcalDetId(HcalEndcap, etaHF2HE_ * id.zside(), id.iphi(), 1);
804  } else
805  neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
806 
807  if (!valid(neighbors[0]) && n == 2) {
808  if (!valid(neighbors[1]))
809  n = 0;
810  else {
811  n = 1;
812  neighbors[0] = neighbors[1];
813  }
814  }
815  if (n == 2 && !valid(neighbors[1]))
816  n = 1;
817  if (n == 1 && !valid(neighbors[0]))
818  n = 0;
819 
820  return n;
821 }
822 
824  HcalSubdetector subdet, int etaRing, int iphi, int zside, int& nDepthBins, int& startingBin) const {
825  if (subdet == HcalBarrel) {
828  startingBin = hcons_->getMinDepth(0, etaRing, iphi, zside);
829  if (etaRing == lastHBRing()) {
830  nDepthBins = hcons_->getDepthEta16(1, iphi, zside) - startingBin + 1;
831  } else {
832  nDepthBins = hcons_->getMaxDepth(0, etaRing, iphi, zside) - startingBin + 1;
833  }
834  } else {
835  if (etaRing <= 14) {
836  nDepthBins = 1;
837  startingBin = 1;
838  } else {
839  nDepthBins = 2;
840  startingBin = 1;
841  }
842  }
843  } else if (subdet == HcalEndcap) {
846  if (etaRing == firstHERing()) {
847  startingBin = hcons_->getDepthEta16(2, iphi, zside);
848  } else {
849  startingBin = hcons_->getMinDepth(1, etaRing, iphi, zside);
850  }
851  nDepthBins = hcons_->getMaxDepth(1, etaRing, iphi, zside) - startingBin + 1;
852  } else {
853  if (etaRing == firstHERing()) {
854  nDepthBins = 1;
855  startingBin = 3;
856  } else if (etaRing == 17) {
857  nDepthBins = 1;
858  startingBin = 1;
859  } else if (etaRing == lastHERing()) {
860  nDepthBins = 2;
861  startingBin = 1;
862  } else {
863  nDepthBins = (etaRing >= firstHETripleDepthRing()) ? 3 : 2;
864  startingBin = 1;
865  }
866  }
867  } else if (subdet == HcalForward) {
868  nDepthBins = maxDepthHF_;
869  startingBin = 1;
870  } else if (subdet == HcalOuter) {
871  nDepthBins = 1;
872  startingBin = 4;
873  } else {
874  edm::LogWarning("HCalGeom") << "Bad HCAL subdetector " << subdet;
875  }
876 }
877 
879  HcalSubdetector subdet = detId.subdet();
880  int ieta = detId.ieta();
881  int etaRing = detId.ietaAbs();
882  int depth = detId.depth();
883  int iphi = detId.iphi();
884  int zside = detId.zside();
885  int nDepthBins(0), startingBin(0);
886  depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
887 
888  // see if the new depth bin exists
889  ++depth;
890  if (depth >= (startingBin + nDepthBins)) {
891  // handle on a case-by-case basis
892  if (subdet == HcalBarrel && etaRing < lastHORing()) {
893  // HO
894  subdet = HcalOuter;
895  depth = 4;
896  } else if (subdet == HcalBarrel && etaRing == lastHBRing()) {
897  // overlap
898  subdet = HcalEndcap;
902  } else if ((subdet == HcalEndcap) && (etaRing == lastHERing() - 1) && (mode_ != HcalTopologyMode::SLHC) &&
904  // guard ring HF29 is behind HE 28
905  subdet = HcalForward;
906  (ieta > 0) ? ++ieta : --ieta;
907  depth = 1;
908  } else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && (mode_ != HcalTopologyMode::SLHC) &&
910  // split cells go to bigger granularity. Ring 29 -> 28
911  (ieta > 0) ? --ieta : ++ieta;
912  } else {
913  // no more chances
914  detId = HcalDetId();
915  return false;
916  }
917  }
918  detId = HcalDetId(subdet, ieta, iphi, depth);
919  return validRaw(detId);
920 }
921 
923  HcalSubdetector subdet = detId.subdet();
924  int ieta = detId.ieta();
925  int etaRing = detId.ietaAbs();
926  int depth = detId.depth();
927  int iphi = detId.iphi();
928  int zside = detId.zside();
929  int nDepthBins, startingBin;
930  depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
931 
932  // see if the new depth bin exists
933  --depth;
934  if ((subdet == HcalOuter) || (subdet == HcalEndcap && etaRing == firstHERing())) {
935  subdet = HcalBarrel;
936  for (int i = 0; i < nEtaHB_; ++i) {
937  if (etaRing == etaBinsHB_[i].ieta) {
938  depth = etaBinsHB_[i].depthStart + etaBinsHB_[i].layer.size() - 1;
939  break;
940  }
941  }
942  } else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && (depth == hcons_->getDepthEta29(iphi, zside, 0)) &&
945  (ieta > 0) ? --ieta : ++ieta;
946  } else if (depth <= 0) {
947  if (subdet == HcalForward && etaRing == firstHFRing()) {
948  // overlap
949  subdet = HcalEndcap;
950  etaRing = etaHF2HE_;
951  ieta = (ieta > 0) ? etaRing : -etaRing;
952  for (const auto& i : etaBinsHE_) {
953  if (etaRing == i.ieta) {
954  depth = i.depthStart + i.layer.size() - 1;
955  break;
956  }
957  }
958  } else {
959  // no more chances
960  detId = HcalDetId();
961  return false;
962  }
963  }
964  detId = HcalDetId(subdet, ieta, detId.iphi(), depth);
965  return validRaw(detId);
966 }
967 
968 int HcalTopology::nPhiBins(int etaRing) const {
969  int lastPhiBin = singlePhiBins_;
971  lastPhiBin = doublePhiBins_ / 2;
972  else if (etaRing >= firstHEDoublePhiRing())
973  lastPhiBin = doublePhiBins_;
974  if (hcons_ && etaRing >= hcons_->getEtaRange(1).first && etaRing <= hcons_->getEtaRange(1).second) {
975  return nPhiBins(HcalBarrel, etaRing);
976  }
977  return lastPhiBin;
978 }
979 
980 int HcalTopology::nPhiBins(HcalSubdetector bc, int etaRing) const {
981  double phiTableVal;
982  if (bc == HcalForward) {
983  phiTableVal = dPhiTableHF[etaRing - firstHFRing_];
984  } else {
985  phiTableVal = dPhiTable[etaRing - firstHBRing_];
986  }
987  int lastPhiBin = 0;
988  if (phiTableVal != 0.0)
989  lastPhiBin = static_cast<int>((2._pi / phiTableVal) + 0.001);
990  return lastPhiBin;
991 }
992 
994  int maxd1 = std::max(maxDepthHB_, maxDepthHE_);
995  int maxd2 = std::max(maxDepthHF_, minMaxDepth_);
996  return std::max(maxd1, maxd2);
997 }
998 
1000  if (bc == HcalBarrel)
1001  return maxDepthHB_;
1002  else if (bc == HcalEndcap)
1003  return maxDepthHE_;
1004  else if (bc == HcalForward)
1005  return maxDepthHF_;
1006  else
1007  return 4;
1008 }
1009 
1010 int HcalTopology::etaRing(HcalSubdetector bc, double abseta) const {
1011  int etaring = firstHBRing_;
1012  if (bc == HcalForward) {
1013  etaring = firstHFRing_;
1014  for (unsigned int k = 0; k < etaTableHF.size() - 1; ++k) {
1015  if (abseta < etaTableHF[k + 1]) {
1016  etaring += k;
1017  break;
1018  }
1019  }
1020  } else {
1021  for (unsigned int k = 0; k < etaTable.size() - 1; ++k) {
1022  if (abseta < etaTable[k + 1]) {
1023  etaring += k;
1024  break;
1025  }
1026  }
1027  if (abseta >= etaTable[etaTable.size() - 1])
1028  etaring = lastHERing_;
1029  }
1030  return etaring;
1031 }
1032 
1033 int HcalTopology::phiBin(HcalSubdetector bc, int etaring, double phi) const {
1034  //put phi in correct range (0->2pi)
1035  int index(0);
1036  if (bc == HcalBarrel) {
1037  index = (etaring - firstHBRing_);
1038  phi -= phioff[0];
1039  } else if (bc == HcalEndcap) {
1040  index = (etaring - firstHBRing_);
1041  phi -= phioff[1];
1042  } else if (bc == HcalForward) {
1043  index = (etaring - firstHFRing_);
1044  if (index < static_cast<int>(dPhiTableHF.size())) {
1045  if (index >= 0 && unitPhiHF[index] > 2)
1046  phi -= phioff[4];
1047  else
1048  phi -= phioff[2];
1049  }
1050  }
1051  if (index < 0)
1052  index = 0;
1053  if (phi < 0.0)
1054  phi += 2._pi;
1055  else if (phi > 2._pi)
1056  phi -= 2._pi;
1057  int phibin(1), unit(1);
1058  if (bc == HcalForward) {
1059  if (index < (int)(dPhiTableHF.size())) {
1060  unit = unitPhiHF[index];
1061  phibin = static_cast<int>(phi / dPhiTableHF[index]) + 1;
1062  }
1063  } else {
1064  if (index < (int)(dPhiTable.size())) {
1065  phibin = static_cast<int>(phi / dPhiTable[index]) + 1;
1066  unit = unitPhi[index];
1067  }
1068  }
1069  int iphi(phibin);
1070  if (unit == 2)
1071  iphi = (phibin - 1) * 2 + 1;
1072  else if (unit == 4)
1073  iphi = (phibin - 1) * 4 + 3;
1074  return iphi;
1075 }
1076 
1077 void HcalTopology::getDepthSegmentation(const unsigned ring, std::vector<int>& readoutDepths, const bool one) const {
1078  // if it doesn't exist, return the first entry with a lower index. So if we only
1079  // have entries for 1 and 17, any input from 1-16 should return the entry for ring 1
1080  SegmentationMap::const_iterator pos;
1081  if (!one) {
1082  pos = depthSegmentation_.upper_bound(ring);
1083  if (pos == depthSegmentation_.begin()) {
1084  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
1085  }
1086  } else {
1087  pos = depthSegmentationOne_.upper_bound(ring);
1088  if (pos == depthSegmentationOne_.begin()) {
1089  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
1090  }
1091  }
1092  --pos;
1093  // pos now refers to the last element with key <= ring.
1094  readoutDepths = pos->second;
1095 }
1096 
1097 void HcalTopology::setDepthSegmentation(const unsigned ring, const std::vector<int>& readoutDepths, const bool one) {
1098  if (one) {
1099  depthSegmentationOne_[ring] = readoutDepths;
1100  } else {
1101  depthSegmentation_[ring] = readoutDepths;
1102  }
1103 }
1104 
1105 std::pair<int, int> HcalTopology::segmentBoundaries(const unsigned ring, const unsigned depth, const bool one) const {
1106  std::vector<int> readoutDepths;
1107  getDepthSegmentation(ring, readoutDepths, one);
1108  int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
1109  int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
1110  return std::pair<int, int>(d1, d2);
1111 }
1112 
1114  double eta(0);
1115  switch (subdet) {
1116  case (HcalBarrel):
1117  if (lastHBRing_ < (int)(etaTable.size()))
1119  break;
1120  case (HcalEndcap):
1121  if (lastHERing_ < (int)(etaTable.size()) && nEtaHE_ > 0)
1123  break;
1124  case (HcalOuter):
1125  if (lastHORing_ < (int)(etaTable.size()))
1127  break;
1128  case (HcalForward):
1129  if (!etaTableHF.empty())
1130  eta = etaTableHF[etaTableHF.size() - 1];
1131  break;
1132  default:
1133  eta = 0;
1134  }
1135  return eta;
1136 }
1137 std::pair<double, double> HcalTopology::etaRange(HcalSubdetector subdet, int keta) const {
1138  int ieta = (keta > 0) ? keta : -keta;
1139  if (subdet == HcalForward) {
1140  if (ieta >= firstHFRing_) {
1141  unsigned int ii = (unsigned int)(ieta - firstHFRing_);
1142  if (ii + 1 < etaTableHF.size())
1143  return std::pair<double, double>(etaTableHF[ii], etaTableHF[ii + 1]);
1144  }
1145  } else {
1146  int ietal = (mode_ == HcalTopologyMode::LHC && ieta == lastHERing_ - 1) ? (ieta + 1) : ieta;
1147  if ((ietal < (int)(etaTable.size())) && (ieta > 0))
1148  return std::pair<double, double>(etaTable[ieta - 1], etaTable[ietal]);
1149  }
1150  return std::pair<double, double>(0, 0);
1151 }
1152 
1153 unsigned int HcalTopology::detId2denseIdPreLS1(const DetId& id) const {
1154  HcalDetId hid(id);
1155  const HcalSubdetector sd(hid.subdet());
1156  const int ip(hid.iphi());
1157  const int ie(hid.ietaAbs());
1158  const int dp(hid.depth());
1159  const int zn(hid.zside() < 0 ? 1 : 0);
1160  unsigned int retval =
1161  ((sd == HcalBarrel)
1162  ? (ip - 1) * 18 + dp - 1 + ie - (ie < 16 ? 1 : 0) + zn * kHBhalf
1163  : ((sd == HcalEndcap)
1164  ? 2 * kHBhalf + (ip - 1) * 8 + (ip / 2) * 20 +
1165  ((ie == 16 || ie == 17)
1166  ? ie - 16
1167  : ((ie >= 18 && ie <= 20)
1168  ? 2 + 2 * (ie - 18) + dp - 1
1169  : ((ie >= 21 && ie <= 26)
1170  ? 8 + 2 * (ie - 21) + dp - 1
1171  : ((ie >= 27 && ie <= 28) ? 20 + 3 * (ie - 27) + dp - 1
1172  : 26 + 2 * (ie - 29) + dp - 1)))) +
1173  zn * kHEhalf
1174  : ((sd == HcalOuter)
1175  ? 2 * kHBhalf + 2 * kHEhalf + (ip - 1) * 15 + (ie - 1) + zn * kHOhalf
1176  : ((sd == HcalForward) ? 2 * kHBhalf + 2 * kHEhalf + 2 * kHOhalf + ((ip - 1) / 4) * 4 +
1177  ((ip - 1) / 2) * 22 + 2 * (ie - 29) + (dp - 1) + zn * kHFhalf
1178  : 0xFFFFFFFFu))));
1179  return retval;
1180 }
1181 
1182 unsigned int HcalTopology::detId2denseIdHB(const DetId& id) const {
1183  HcalDetId hid(id);
1184  const int ip(hid.iphi());
1185  const int ie(hid.ietaAbs());
1186  const int dp(hid.depth());
1187  const int zn(hid.zside() < 0 ? 1 : 0);
1188  unsigned int retval = 0xFFFFFFFFu;
1189  if (topoVersion_ == 0) {
1190  retval = (ip - 1) * 18 + dp - 1 + ie - (ie < 16 ? 1 : 0) + zn * kHBhalf;
1191  } else if (topoVersion_ == 10) {
1192  retval = (dp - 1) + maxDepthHB_ * (ip - 1);
1193  if (hid.ieta() > 0)
1194  retval += maxDepthHB_ * IPHI_MAX * (hid.ieta() - firstHBRing());
1195  else
1196  retval += maxDepthHB_ * IPHI_MAX * (hid.ieta() + lastHBRing() + nEtaHB_);
1197  }
1198  return retval;
1199 }
1200 
1201 unsigned int HcalTopology::detId2denseIdHE(const DetId& id) const {
1202  HcalDetId hid(id);
1203  const int ip(hid.iphi());
1204  const int ie(hid.ietaAbs());
1205  const int dp(hid.depth());
1206  const int zn(hid.zside() < 0 ? 1 : 0);
1207  unsigned int retval = 0xFFFFFFFFu;
1208  if (topoVersion_ == 0) {
1209  retval = (ip - 1) * 8 + (ip / 2) * 20 +
1210  ((ie == 16 || ie == 17)
1211  ? ie - 16
1212  : ((ie >= 18 && ie <= 20)
1213  ? 2 + 2 * (ie - 18) + dp - 1
1214  : ((ie >= 21 && ie <= 26) ? 8 + 2 * (ie - 21) + dp - 1
1215  : ((ie >= 27 && ie <= 28) ? 20 + 3 * (ie - 27) + dp - 1
1216  : 26 + 2 * (ie - 29) + dp - 1)))) +
1217  zn * kHEhalf;
1218  } else if (topoVersion_ == 10) {
1219  retval = (dp - 1) + maxDepthHE_ * (ip - 1);
1220  if (hid.ieta() > 0)
1221  retval += maxDepthHE_ * maxPhiHE_ * (hid.ieta() - firstHERing());
1222  else
1223  retval += maxDepthHE_ * maxPhiHE_ * (hid.ieta() + lastHERing() + nEtaHE_);
1224  }
1225  return retval;
1226 }
1227 
1228 unsigned int HcalTopology::detId2denseIdHO(const DetId& id) const {
1229  HcalDetId hid(id);
1230  const int ip(hid.iphi());
1231  const int ie(hid.ietaAbs());
1232  const int zn(hid.zside() < 0 ? 1 : 0);
1233 
1234  unsigned int retval = 0xFFFFFFFFu;
1235  if (topoVersion_ == 0) {
1236  retval = (ip - 1) * 15 + (ie - 1) + zn * kHOhalf;
1237  } else if (topoVersion_ == 10) {
1238  if (hid.ieta() > 0)
1239  retval = (ip - 1) + IPHI_MAX * (hid.ieta() - 1);
1240  else
1241  retval = (ip - 1) + IPHI_MAX * (30 + hid.ieta());
1242  }
1243  return retval;
1244 }
1245 
1246 unsigned int HcalTopology::detId2denseIdHF(const DetId& id) const {
1247  HcalDetId hid(id);
1248  const int ip(hid.iphi());
1249  const int ie(hid.ietaAbs());
1250  const int dp(hid.depth());
1251  const int zn(hid.zside() < 0 ? 1 : 0);
1252 
1253  unsigned int retval = 0xFFFFFFFFu;
1254  if (topoVersion_ == 0) {
1255  retval = ((ip - 1) / 4) * 4 + ((ip - 1) / 2) * 22 + 2 * (ie - 29) + (dp - 1) + zn * kHFhalf;
1256  } else if (topoVersion_ == 10) {
1257  retval = dp - 1 + 2 * (ip - 1);
1258  if (hid.ieta() > 0)
1259  retval += maxDepthHF_ * IPHI_MAX * (hid.ieta() - 29);
1260  else
1261  retval += maxDepthHF_ * IPHI_MAX * ((41 + 13) + hid.ieta());
1262  }
1263  return retval;
1264 }
1265 
1266 unsigned int HcalTopology::detId2denseIdHT(const DetId& id) const {
1267  HcalTrigTowerDetId tid(id);
1268  int zside = tid.zside();
1269  unsigned int ietaAbs = tid.ietaAbs();
1270  unsigned int iphi = tid.iphi();
1271  unsigned int ivers = tid.version();
1272 
1273  unsigned int index;
1274  if (ivers == 0) {
1275  if ((iphi - 1) % 4 == 0)
1276  index = (iphi - 1) * 32 + (ietaAbs - 1) - (12 * ((iphi - 1) / 4));
1277  else
1278  index = (iphi - 1) * 28 + (ietaAbs - 1) + (4 * (((iphi - 1) / 4) + 1));
1279  if (zside == -1)
1280  index += kHThalf;
1281  } else {
1282  index = kHTSizePreLS1;
1283  if (zside == -1)
1284  index += ((kHTSizePhase1 - kHTSizePreLS1) / 2);
1285  index += (36 * (ietaAbs - 30) + ((iphi - 1) / 2));
1286  }
1287 
1288  return index;
1289 }
1290 
1291 unsigned int HcalTopology::detId2denseIdCALIB(const DetId& id) const {
1292  HcalCalibDetId tid(id);
1293  int channel = tid.cboxChannel();
1294  int ieta = tid.ieta();
1295  int iphi = tid.iphi();
1296  int zside = tid.zside();
1297  unsigned int index = 0xFFFFFFFFu;
1298 
1300  HcalSubdetector subDet = tid.hcalSubdet();
1301 
1302  if (subDet == HcalBarrel) {
1303 #ifdef EDM_ML_DEBUG
1304  edm::LogVerbatim("HCalGeom") << "CALIB_HB: dphi = 4 (18 phi values), 3 channel types (0,1,2), eta = -1 or 1\n "
1305  " total of 18*3*2=108 channels";
1306 #endif
1308  auto kndx = std::find(chanCalibHB_, chanCalibHB_ + nchanCalibHB_, channel);
1309  if (indx != etaCalibHB_ + nEtaCalibHB_ && kndx != chanCalibHB_ + nchanCalibHB_) {
1310  int keta = static_cast<int>(indx - etaCalibHB_);
1311  int kchn = static_cast<int>(kndx - chanCalibHB_);
1312  index = ((iphi + 1) / mPhiCalibHB_ - 1) + kPhiCalibHB_ * kchn + keta * kchanCalibHB_ + kOffCalibHB_;
1313  }
1314  } else if (subDet == HcalEndcap) {
1315 #ifdef EDM_ML_DEBUG
1316  edm::LogVerbatim("HCalGeom") << "CALIB_HE: dphi = 4 (18 phi values), 7 channel types (0,1,2,3,4,5,6), eta = "
1317  "-1/+1\n total of 18*7*2=252 channels if (channel > 2) channel -= 1";
1318 #endif
1320  if (indx != etaCalibHE_ + nEtaCalibHE_) {
1321  int keta = static_cast<int>(indx - etaCalibHE_);
1322  auto kndx = std::find(chanCalibHE1_, chanCalibHE1_ + nchanCalibHE1_, channel);
1323  if (kndx != chanCalibHE1_ + nchanCalibHE1_) {
1324  int kchn = static_cast<int>(kndx - chanCalibHE1_);
1325  index = ((iphi + 1) / mPhiCalibHE_ - 1) + kPhiCalibHE_ * kchn + keta * kchanCalibHE1_ + kOffCalibHE1_;
1326  } else if (channel == chanCalibHE2_) {
1327  index = ((iphi + 1) / mPhiCalibHE_ - 1) + keta * kchanCalibHE2_ + kOffCalibHE2_;
1328  }
1329  }
1330  } else if (subDet == HcalForward) {
1331 #ifdef EDM_ML_DEBUG
1332  edm::LogVerbatim("HCalGeom")
1333  << "CALIB_HF: dphi = 18 (4 phi values), 3 channel types (0,1,8), eta = -1 or +1\n or iphi = 1; "
1334  "channel = 9, eta = -1 or +1 total channels 4*3*2=24 + 2";
1335 #endif
1337  if (indx != etaCalibHF_ + nEtaCalibHF_) {
1338  int keta = static_cast<int>(indx - etaCalibHF_);
1339  auto kndx = std::find(chanCalibHF1_, chanCalibHF1_ + nchanCalibHF1_, channel);
1340  if (kndx != chanCalibHF1_ + nchanCalibHF1_) {
1341  int kchn = static_cast<int>(kndx - chanCalibHF1_);
1342  index = ((iphi - 1) / mPhiCalibHF1_) + kPhiCalibHF1_ * kchn + keta * kchanCalibHF1_ + kOffCalibHF1_;
1343  } else if (channel == chanCalibHF2_) {
1344  index = keta * kchanCalibHF2_ + kOffCalibHF2_;
1345  }
1346  }
1347  } else if (subDet == HcalOuter) {
1348 #ifdef EDM_ML_DEBUG
1349  edm::LogVerbatim("HCalGeom") << "CALIB_HO: ";
1350 #endif
1352  if (indx != etaCalibHO_ + nEtaCalibHO_) {
1353  int keta = static_cast<int>(indx - etaCalibHO_);
1354  auto kndx = std::find(chanCalibHO_, chanCalibHO_ + nchanCalibHO_, channel);
1355  //there are 5 special calib crosstalk channels, one in each ring
1356  if (channel == chanCalibHOs_) {
1357  index = keta + kOffCalibHO2_;
1358  } else if (kndx != chanCalibHO_ + nchanCalibHO_) {
1359  //for HOM/HOP dphi = 6 (12 phi values), 2 channel types (0,1), eta = -2,-1 or 1,2
1360  //for HO0/YB0 dphi = 12 (6 phi values), 2 channel types (0,1), eta = 0
1361  int kchn = static_cast<int>(kndx - chanCalibHO_);
1362  int kphi = (ieta == 0) ? ((iphi + 1) / mPhiCalibHO0_ - 1) : ((iphi + 1) / mPhiCalibHO1_ - 1);
1363  if (ieta < 0) {
1364  index = kphi + kPhiCalibHO2_ * kchn + kPhiCalibHO1_ * keta + kOffCalibHO1_;
1365  } else if (ieta > 0) {
1366  index = kphi + kPhiCalibHO2_ * kchn + kPhiCalibHO1_ * (keta - 1) + kPhiCalibHO0_ + kOffCalibHO1_;
1367  } else {
1368  index = kphi + kPhiCalibHO2_ * kchn + kPhiCalibHO1_ * keta + kOffCalibHO1_;
1369  }
1370  }
1371  }
1372  } else {
1373  edm::LogWarning("HGCalGeom") << "HCAL Det Id not valid!";
1374  }
1375  } else if (tid.calibFlavor() == HcalCalibDetId::HOCrosstalk) {
1376 #ifdef EDM_ML_DEBUG
1377  edm::LogVerbatim("HCalGeom") << "HX: for YB0/HO0 phi is grouped in 6 groups of 6 with dphi=2 but the transitions "
1378  "are 1 or 3 in such a way that the %36 operation yeilds unique values for every "
1379  "iphi\n ieta = 0 for HO2M/HO1M ieta=2 for HO1P/HO2P; /ieta = 1 YB0/HO0";
1380 #endif
1381  int kphi = ((std::abs(ieta) == etaCalibHOX_[0]) ? ((iphi % 2 == 0) ? (iphi / 2 - 1) : (iphi - 1) / 2) : (iphi - 1));
1382  if (std::abs(ieta) == etaCalibHOX_[0]) {
1383  index = kphi + (((zside + 1) * nPhiCalibHOX_[0]) / 2) + nPhiCalibHOX_[1] + kOffCalibHOX_;
1384  } else if (std::abs(ieta) == etaCalibHOX_[1]) {
1385  index = kphi + ((zside + 1) * nPhiCalibHOX_[1]) + kOffCalibHOX_;
1386  }
1387  } else if (tid.calibFlavor() == HcalCalibDetId::HBX) {
1388  if (std::abs(ieta) == etaCalibHBX_) {
1389  index = kOffCalibHBX_ + (iphi - 1) + (zside + 1) * kPhiCalibHBX_ / 2;
1390  }
1391  } else if (tid.calibFlavor() == HcalCalibDetId::HEX) {
1392  if (std::abs(ieta) == etaCalibHEX_[0]) {
1393  index = kOffCalibHEX_ + (iphi - 1) / mPhiCalibHEX_ + (zside + 1) * kPhiCalibHEX_ / 2;
1394  } else if (std::abs(ieta) == etaCalibHEX_[1]) {
1395  index = kOffCalibHEX_ + (iphi - 1) / mPhiCalibHEX_ + (zside + 1) * kPhiCalibHEX_ / 2 + 2 * kPhiCalibHEX_;
1396  }
1397  }
1398 #ifdef EDM_ML_DEBUG
1399  edm::LogVerbatim("HCalGeom") << " " << ieta << " " << zside << " " << iphi << " " << index;
1400 #endif
1401  return index;
1402 }
1403 
1404 HcalCalibDetId HcalTopology::denseId2detIdCALIB(const unsigned int& hid) const {
1406  unsigned int hid0(hid);
1407  if (hid0 < kOffCalibHOX_) {
1408  HcalSubdetector subdet(HcalEmpty);
1409  int ieta(0), iphi(0), ichan(0), ctype(0);
1410  if (hid0 < kOffCalibHE1_) {
1411  int id0 = static_cast<int>(hid0);
1412  subdet = HcalBarrel;
1413  iphi = hid0 % kPhiCalibHB_;
1414  int keta = (hid0 < kchanCalibHB_) ? 0 : 1;
1415  ieta = etaCalibHB_[keta];
1416  ichan = (id0 - iphi - keta * kchanCalibHB_) / kPhiCalibHB_;
1417  iphi = mPhiCalibHB_ * (iphi + 1) - 1;
1418  ctype = chanCalibHB_[ichan];
1419  } else if (hid0 < kOffCalibHF1_) {
1420  hid0 -= kOffCalibHE1_;
1421  int id0 = static_cast<int>(hid0);
1422  subdet = HcalEndcap;
1423  iphi = hid0 % kPhiCalibHE_;
1424  int keta = (hid0 < kchanCalibHE1_) ? 0 : 1;
1425  ieta = etaCalibHE_[keta];
1426  ichan = (id0 - iphi - keta * kchanCalibHE1_) / kPhiCalibHE_;
1427  iphi = mPhiCalibHE_ * (iphi + 1) - 1;
1428  ctype = chanCalibHE1_[ichan];
1429  } else if (hid0 < kOffCalibHO1_) {
1430  hid0 -= kOffCalibHF1_;
1431  int id0 = static_cast<int>(hid0);
1432  subdet = HcalForward;
1433  iphi = hid0 % kPhiCalibHF1_;
1434  int keta = (hid0 < kchanCalibHF1_) ? 0 : 1;
1435  ieta = etaCalibHF_[keta];
1436  ichan = (id0 - iphi - keta * kchanCalibHF1_) / kPhiCalibHF1_;
1437  iphi = mPhiCalibHF1_ * iphi + 1;
1438  ctype = chanCalibHF1_[ichan];
1439  } else if (hid0 < kOffCalibHO2_) {
1440  hid0 -= kOffCalibHO1_;
1441  int id0 = static_cast<int>(hid0);
1442  subdet = HcalOuter;
1443  unsigned int kphi = hid0 % kPhiCalibHO2_;
1444  if (kphi < 2 * kPhiCalibHO1_) {
1445  ieta = (kphi >= kPhiCalibHO1_) ? etaCalibHO_[1] : etaCalibHO_[0];
1446  iphi = kphi % kPhiCalibHO1_;
1447  ichan = (id0 - iphi - (ieta + 2) * kPhiCalibHO1_) / kPhiCalibHO2_;
1448  iphi = (iphi + 1) * mPhiCalibHO1_ - 1;
1449  } else if (kphi < (2 * kPhiCalibHO1_ + kPhiCalibHO0_)) {
1450  ieta = etaCalibHO_[2];
1451  iphi = kphi % kPhiCalibHO0_;
1452  ichan = (id0 - iphi - (ieta + 2) * kPhiCalibHO1_) / kPhiCalibHO2_;
1453  iphi = (iphi + 1) * mPhiCalibHO0_ - 1;
1454  } else {
1455  ieta = (kphi >= 3 * kPhiCalibHO1_ + kPhiCalibHO0_) ? etaCalibHO_[4] : etaCalibHO_[3];
1456  iphi = kphi % kPhiCalibHO1_;
1457  ichan = (id0 - iphi - (ieta + 1) * kPhiCalibHO1_ - kPhiCalibHO0_) / kPhiCalibHO2_;
1458  iphi = (iphi + 1) * mPhiCalibHO1_ - 1;
1459  }
1460  ctype = chanCalibHO_[ichan];
1461  } else if (hid0 < kOffCalibHE2_) {
1462  hid0 -= kOffCalibHO2_;
1463  subdet = HcalOuter;
1464  iphi = phiCalibHO_[hid0];
1465  ctype = static_cast<int>(chanCalibHOs_);
1466  ieta = etaCalibHO_[hid0];
1467  } else if (hid0 < kOffCalibHF2_) {
1468  hid0 -= kOffCalibHE2_;
1469  subdet = HcalEndcap;
1470  iphi = hid0 % kPhiCalibHE_;
1471  int keta = (hid0 < kchanCalibHE2_) ? 0 : 1;
1472  ieta = etaCalibHE_[keta];
1473  iphi = mPhiCalibHE_ * (iphi + 1) - 1;
1474  ctype = chanCalibHE2_;
1475  } else {
1476  hid0 -= kOffCalibHF2_;
1477  subdet = HcalForward;
1478  int keta = (hid0 < kchanCalibHF2_) ? 0 : 1;
1479  ieta = etaCalibHF_[keta];
1480  iphi = phiCalibHF2_;
1481  ctype = chanCalibHF2_;
1482  }
1483  id = HcalCalibDetId(subdet, ieta, iphi, ctype);
1484 #ifdef EDM_ML_DEBUG
1485  edm::LogVerbatim("HCalGeom") << "CalibrationBox: " << hid << " o/p " << ieta << ":" << iphi << ":" << ichan << ":"
1486  << ctype << " " << id;
1487 #endif
1488  } else if (hid < kOffCalibHBX_) {
1489  hid0 -= kOffCalibHOX_;
1490  int iphi, ieta;
1491  if (hid0 < nPhiCalibHOX_[1]) {
1492  iphi = static_cast<int>(hid0) + 1;
1493  ieta = -etaCalibHOX_[1];
1494  } else if (hid0 < (nPhiCalibHOX_[1] + nPhiCalibHOX_[0])) {
1495  hid0 -= nPhiCalibHOX_[1];
1496  iphi = ((hid0 + phiCalibHOX1_) % phiCalibHOX2_ < phiCalibHOX3_) ? 2 * hid0 + 1 : 2 * hid0 + 2;
1497  ieta = -etaCalibHOX_[0];
1498  } else if (hid0 < (nPhiCalibHOX_[1] + 2 * nPhiCalibHOX_[0])) {
1499  hid0 -= (nPhiCalibHOX_[1] + nPhiCalibHOX_[0]);
1500  iphi = ((hid0 + phiCalibHOX1_) % phiCalibHOX2_ < phiCalibHOX3_) ? 2 * hid0 + 1 : 2 * hid0 + 2;
1501  ieta = etaCalibHOX_[0];
1502  } else {
1503  hid0 -= (nPhiCalibHOX_[1] + 2 * nPhiCalibHOX_[0]);
1504  iphi = static_cast<int>(hid0) + 1;
1505  ieta = etaCalibHOX_[1];
1506  }
1508 #ifdef EDM_ML_DEBUG
1509  edm::LogVerbatim("HCalGeom") << "HOCrossTalk: " << hid << ":" << hid0 << " o/p " << ieta << ":" << iphi << " "
1510  << id;
1511 #endif
1512  } else if (hid < kOffCalibHEX_) {
1513  hid0 -= kOffCalibHBX_;
1514  int ieta = (hid0 >= kPhiCalibHBX_) ? etaCalibHBX_ : -etaCalibHBX_;
1515  int iphi = (hid0 % kPhiCalibHBX_) + 1;
1517 #ifdef EDM_ML_DEBUG
1518  edm::LogVerbatim("HCalGeom") << "HBX: " << hid << ":" << hid0 << " o/p " << ieta << ":" << iphi << " " << id;
1519 #endif
1520  } else if (hid < kOffCalibHFX_) {
1521  hid0 -= kOffCalibHEX_;
1522  int iphi = 2 * (hid0 % kPhiCalibHEX_) + 1;
1523  int ieta = ((hid0 < kPhiCalibHEX_)
1524  ? -etaCalibHEX_[0]
1525  : ((hid0 < 2 * kPhiCalibHEX_) ? etaCalibHEX_[0]
1526  : ((hid0 < 3 * kPhiCalibHEX_) ? -etaCalibHEX_[1] : etaCalibHEX_[1])));
1528 #ifdef EDM_ML_DEBUG
1529  edm::LogVerbatim("HCalGeom") << "HEX: " << hid << ":" << hid0 << " o/p " << ieta << ":" << iphi << " " << id;
1530 #endif
1531  }
1532  return id;
1533 }
1534 
1535 unsigned int HcalTopology::detId2denseId(const DetId& id) const {
1536  unsigned int retval(0);
1537  if (topoVersion_ == 0) { // pre-LS1
1538  retval = detId2denseIdPreLS1(id);
1539  } else if (topoVersion_ == 10) {
1540  HcalDetId hid(id);
1541  if (hid.subdet() == HcalBarrel) {
1542  retval = (hid.depth() - 1) + maxDepthHB_ * (hid.iphi() - 1);
1543  if (hid.ieta() > 0)
1544  retval += maxDepthHB_ * IPHI_MAX * (hid.ieta() - firstHBRing());
1545  else
1546  retval += maxDepthHB_ * IPHI_MAX * (hid.ieta() + lastHBRing() + nEtaHB_);
1547  } else if (hid.subdet() == HcalEndcap) {
1548  retval = HBSize_;
1549  retval += (hid.depth() - 1) + maxDepthHE_ * (hid.iphi() - 1);
1550  if (hid.ieta() > 0)
1551  retval += maxDepthHE_ * maxPhiHE_ * (hid.ieta() - firstHERing());
1552  else
1553  retval += maxDepthHE_ * maxPhiHE_ * (hid.ieta() + lastHERing() + nEtaHE_);
1554  } else if (hid.subdet() == HcalOuter) {
1555  retval = HBSize_ + HESize_;
1556  if (hid.ieta() > 0)
1557  retval += (hid.iphi() - 1) + IPHI_MAX * (hid.ieta() - 1);
1558  else
1559  retval += (hid.iphi() - 1) + IPHI_MAX * (30 + hid.ieta());
1560  } else if (hid.subdet() == HcalForward) {
1561  retval = HBSize_ + HESize_ + HOSize_;
1562  retval += (hid.depth() - 1) + maxDepthHF_ * (hid.iphi() - 1);
1563  if (hid.ieta() > 0)
1564  retval += maxDepthHF_ * IPHI_MAX * (hid.ieta() - 29);
1565  else
1566  retval += maxDepthHF_ * IPHI_MAX * ((41 + 13) + hid.ieta());
1567  } else {
1568  retval = 0xFFFFFFFu;
1569  }
1570  }
1571 #ifdef EDM_ML_DEBUG
1572  edm::LogVerbatim("HcalGeom") << "DetId2Dense " << topoVersion_ << " ID " << std::hex << id.rawId() << std::dec
1573  << " | " << HcalDetId(id) << " : " << std::hex << retval << std::dec;
1574 #endif
1575  return retval;
1576 }
1577 
1578 DetId HcalTopology::denseId2detId(unsigned int denseid) const {
1580  int ie(0);
1581  int ip(0);
1582  int dp(0);
1583  int in(denseid);
1584  int iz(1);
1585  if (topoVersion_ == 0) { //DL// pre-LS1
1586  if (denseid < kSizeForDenseIndexingPreLS1) {
1587  if (in > 2 * (kHBhalf + kHEhalf + kHOhalf) - 1) { // HF
1588  sd = HcalForward;
1589  in -= 2 * (kHBhalf + kHEhalf + kHOhalf);
1590  iz = (in < kHFhalf ? 1 : -1);
1591  in %= kHFhalf;
1592  ip = 4 * (in / 48);
1593  in %= 48;
1594  ip += 1 + (in > 21 ? 2 : 0);
1595  if (3 == ip % 4)
1596  in -= 22;
1597  ie = 29 + in / 2;
1598  dp = 1 + in % 2;
1599  } else if (in > 2 * (kHBhalf + kHEhalf) - 1) { // HO
1600  sd = HcalOuter;
1601  in -= 2 * (kHBhalf + kHEhalf);
1602  iz = (in < kHOhalf ? 1 : -1);
1603  in %= kHOhalf;
1604  dp = 4;
1605  ip = 1 + in / 15;
1606  ie = 1 + (in - 15 * (ip - 1));
1607  } else if (in > 2 * kHBhalf - 1) { // Endcap
1608  sd = HcalEndcap;
1609  in -= 2 * kHBhalf;
1610  iz = (in < kHEhalf ? 1 : -1);
1611  in %= kHEhalf;
1612  ip = 2 * (in / 36);
1613  in %= 36;
1614  ip += 1 + in / 28;
1615  if (0 == ip % 2)
1616  in %= 28;
1617  ie = 15 + (in < 2 ? 1 + in : 2 + (in < 20 ? 1 + (in - 2) / 2 : 9 + (in < 26 ? 1 + (in - 20) / 3 : 3)));
1618  dp = (in < 1
1619  ? 3
1620  : (in < 2 ? 1 : (in < 20 ? 1 + (in - 2) % 2 : (in < 26 ? 1 + (in - 20) % 3 : (1 + (in - 26) % 2)))));
1621  } else { // barrel
1622  iz = (in < kHBhalf ? 1 : -1);
1623  in %= kHBhalf;
1624  ip = in / 18 + 1;
1625  in %= 18;
1626  if (in < 14) {
1627  dp = 1;
1628  ie = in + 1;
1629  } else {
1630  in %= 14;
1631  dp = 1 + in % 2;
1632  ie = 15 + in / 2;
1633  }
1634  }
1635  }
1636  } else if (topoVersion_ == 10) {
1637  if (denseid < ncells()) {
1638  if (denseid >= (HBSize_ + HESize_ + HOSize_)) {
1639  sd = HcalForward;
1640  in -= (HBSize_ + HESize_ + HOSize_);
1641  dp = (in % maxDepthHF_) + 1;
1642  ip = (in - dp + 1) % (maxDepthHF_ * IPHI_MAX);
1643  ip = (ip / maxDepthHF_) + 1;
1644  ie = (in - dp + 1 - maxDepthHF_ * (ip - 1)) / (IPHI_MAX * maxDepthHF_);
1645  if (ie > 12) {
1646  ie = 54 - ie;
1647  iz = -1;
1648  } else {
1649  ie += 29;
1650  iz = 1;
1651  }
1652  } else if (denseid >= (HBSize_ + HESize_)) {
1653  sd = HcalOuter;
1654  in -= (HBSize_ + HESize_);
1655  dp = 4;
1656  ip = (in % IPHI_MAX) + 1;
1657  ie = (in - ip + 1) / IPHI_MAX;
1658  if (ie > 14) {
1659  ie = 30 - ie;
1660  iz = -1;
1661  } else {
1662  ie += 1;
1663  iz = 1;
1664  }
1665  } else if (denseid >= (HBSize_)) {
1666  sd = HcalEndcap;
1667  in -= (HBSize_);
1668  dp = (in % maxDepthHE_) + 1;
1669  ip = (in - dp + 1) % (maxDepthHE_ * maxPhiHE_);
1670  ip = (ip / maxDepthHE_) + 1;
1671  ie = (in - dp + 1 - maxDepthHE_ * (ip - 1)) / (maxPhiHE_ * maxDepthHE_);
1672  if (ie >= nEtaHE_) {
1673  ie = lastHERing() + nEtaHE_ - ie;
1674  iz = -1;
1675  } else {
1676  ie = firstHERing() + ie;
1677  iz = 1;
1678  }
1679  } else {
1680  sd = HcalBarrel;
1681  dp = (in % maxDepthHB_) + 1;
1682  ip = (in - dp + 1) % (maxDepthHB_ * IPHI_MAX);
1683  ip = (ip / maxDepthHB_) + 1;
1684  ie = (in - dp + 1 - maxDepthHB_ * (ip - 1)) / (IPHI_MAX * maxDepthHB_);
1685  if (ie >= nEtaHB_) {
1686  ie = lastHBRing() + nEtaHB_ - ie;
1687  iz = -1;
1688  } else {
1689  ie = firstHBRing() + ie;
1690  iz = 1;
1691  }
1692  }
1693  }
1694  }
1695  HcalDetId hid(sd, iz * int(ie), ip, dp);
1696 #ifdef EDM_ML_DEBUG
1697  edm::LogVerbatim("HcalGeom") << "Dens2Det " << topoVersion_ << " i/p " << std::hex << denseid << " : " << hid.rawId()
1698  << std::dec << " | " << hid;
1699 #endif
1700  return hid;
1701 }
1702 
1703 unsigned int HcalTopology::ncells() const { return HBSize_ + HESize_ + HOSize_ + HFSize_; }
1704 
static constexpr int minMaxDepth_
Definition: HcalTopology.h:238
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
static constexpr int chanCalibHF2_
Definition: HcalTopology.h:279
Log< level::Info, true > LogVerbatim
bool validHT(const HcalTrigTowerDetId &id) const
int cboxChannel() const
get the calibration box channel (if relevant)
std::vector< int > unitPhiHF
Definition: HcalTopology.h:218
static constexpr unsigned int kchanCalibHE1_
Definition: HcalTopology.h:252
static constexpr int etaCalibHE_[nEtaCalibHE_]
Definition: HcalTopology.h:251
std::pair< int, int > getEtaRange(const int &i) const
static constexpr unsigned int kchanCalibHF1_
Definition: HcalTopology.h:259
static constexpr unsigned int kPhiCalibHBX_
Definition: HcalTopology.h:292
constexpr bool oldFormat() const
Definition: HcalDetId.h:139
const std::vector< double > & getPhiOffs() const
static constexpr int etaCalibHBX_
Definition: HcalTopology.h:291
static constexpr unsigned int kOffCalibHFX_
Definition: HcalTopology.h:299
unsigned int numberOfShapes_
Definition: HcalTopology.h:214
unsigned int detId2denseIdPreLS1(const DetId &id) const
std::vector< double > dPhiTableHF
Definition: HcalTopology.h:216
void excludeSubdetector(HcalSubdetector subdet)
bool decrementDepth(HcalDetId &id) const
int getDepthEta16(const int &det, const int &iphi, const int &zside) const
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHB_
Definition: HcalTopology.h:198
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
int topoVersion() const override
return a version which identifies the given topology
void getDepthSegmentation(const unsigned ring, std::vector< int > &readoutDepths, const bool flag=false) const
std::vector< int > unitPhi
Definition: HcalTopology.h:218
static constexpr unsigned int kchanCalibHE2_
Definition: HcalTopology.h:276
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
int getNPhi(const int &type) const
bool valid(const DetId &id) const override
std::vector< DetId > south(const DetId &id) const override
unsigned int detId2denseIdHF(const DetId &id) const
return a linear packed id from HF
void exclude(const HcalDetId &id)
HcalTopologyMode::TriggerMode triggerMode_
Definition: HcalTopology.h:191
int maxDepthHE() const
Definition: HcalTopology.h:140
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
static constexpr unsigned int kchanCalibHF2_
Definition: HcalTopology.h:280
std::pair< int, int > segmentBoundaries(const unsigned ring, const unsigned depth, const bool flag=false) const
static constexpr unsigned int kOffCalibHE1_
Definition: HcalTopology.h:247
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
static constexpr unsigned int nEtaCalibHO_
Definition: HcalTopology.h:262
unsigned int HESize_
Definition: HcalTopology.h:209
int incIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
int lastHORing() const
Definition: HcalTopology.h:99
unsigned int HTSize_
Definition: HcalTopology.h:212
static constexpr int kHFSizePreLS1
Definition: HcalTopology.h:234
static constexpr int kHBhalf
Definition: HcalTopology.h:227
static constexpr unsigned int kPhiCalibHO0_
Definition: HcalTopology.h:268
int zside(DetId const &)
bool incIPhi(const HcalDetId &id, HcalDetId &neighbor) const
static constexpr int phiCalibHO_[nEtaCalibHO_]
Definition: HcalTopology.h:266
static constexpr int etaCalibHO_[nEtaCalibHO_]
Definition: HcalTopology.h:265
HcalCalibDetId denseId2detIdCALIB(const unsigned int &id) const
return a Calib DetId from linear packed id
static constexpr unsigned int nEtaCalibHF_
Definition: HcalTopology.h:255
static constexpr int kHTSizePreLS1
Definition: HcalTopology.h:235
static constexpr unsigned int nchanCalibHO_
Definition: HcalTopology.h:262
int ieta() const
static constexpr int etaCalibHB_[nEtaCalibHB_]
Definition: HcalTopology.h:244
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
assert(be >=bs)
int maxDepthHB() const
Definition: HcalTopology.h:139
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHE_
Definition: HcalTopology.h:198
static constexpr unsigned int nPhiCalibHOX_[nEtaCalibHOX_]
Definition: HcalTopology.h:286
bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const
std::vector< HcalEtaBin > getEtaBins(const int &itype) const
int firstHETripleDepthRing() const
Definition: HcalTopology.h:104
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
static constexpr int kCALIBSizePreLS1
Definition: HcalTopology.h:237
static constexpr int kHThalf
Definition: HcalTopology.h:227
static constexpr int chanCalibHE2_
Definition: HcalTopology.h:275
static constexpr unsigned int nEtaCalibHB_
Definition: HcalTopology.h:241
int iphi() const
get the tower iphi
int etaRing(HcalSubdetector subdet, double eta) const
eta and phi index from eta, phi values
static constexpr int phiCalibHOX3_
Definition: HcalTopology.h:288
static constexpr unsigned int kPhiCalibHB_
Definition: HcalTopology.h:242
static constexpr unsigned int nEtaCalibHE_
Definition: HcalTopology.h:248
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
U second(std::pair< T, U > const &p)
static constexpr unsigned int maxPhi_
Definition: HcalTopology.h:239
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id)
std::vector< DetId > up(const DetId &id) const override
int firstHBRing() const
Definition: HcalTopology.h:91
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
static constexpr int phiCalibHOX2_
Definition: HcalTopology.h:288
constexpr void changeForm()
Definition: HcalDetId.h:198
int decIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
unsigned int CALIBSize_
Definition: HcalTopology.h:213
static constexpr unsigned int nchanCalibHB_
Definition: HcalTopology.h:241
unsigned int detId2denseIdCALIB(const DetId &id) const
return a linear packed id from CALIB
unsigned int HFSize_
Definition: HcalTopology.h:211
static constexpr int phiCalibHOX1_
Definition: HcalTopology.h:288
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
bool decIPhi(const HcalDetId &id, HcalDetId &neighbor) const
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:103
static constexpr unsigned int kOffCalibHEX_
Definition: HcalTopology.h:294
constexpr int ieta() const
get the cell ieta
Definition: HcalDetId.h:155
int lastHBRing() const
Definition: HcalTopology.h:92
int iphi() const
get the low-edge iphi (if relevant)
HcalTopologyMode::Mode mode_
Definition: HcalTopology.h:190
The Signals That Services Can Subscribe To This is based on ActivityRegistry and is current per Services can connect to the signals distributed by the ActivityRegistry in order to monitor the activity of the application Each possible callback has some defined which we here list in angle e< void, edm::EventID const &, edm::Timestamp const & > We also list in braces which AR_WATCH_USING_METHOD_ is used for those or
Definition: Activities.doc:12
HcalTopology(const HcalDDDRecConstants *hcons, const bool mergePosition=false)
Definition: HcalTopology.cc:17
static constexpr unsigned int mPhiCalibHEX_
Definition: HcalTopology.h:295
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
static constexpr int kHOhalf
Definition: HcalTopology.h:227
int maxDepth(void) const
static constexpr int chanCalibHE1_[nchanCalibHE1_]
Definition: HcalTopology.h:250
HcalSubdetector
Definition: HcalAssistant.h:31
unsigned int HBSize_
Definition: HcalTopology.h:208
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
const std::vector< double > & getEtaTable() const
static constexpr int kHESizePreLS1
Definition: HcalTopology.h:232
static constexpr int kHBSizePreLS1
Definition: HcalTopology.h:231
DetId denseId2detId(unsigned int) const override
return a linear packed id
static constexpr int etaCalibHEX_[nEtaCalibHEX_]
Definition: HcalTopology.h:296
static constexpr int kHOSizePreLS1
Definition: HcalTopology.h:233
static constexpr int kHEhalf
Definition: HcalTopology.h:227
static constexpr unsigned int kPhiCalibHO2_
Definition: HcalTopology.h:270
std::vector< double > etaTableHF
Definition: HcalTopology.h:216
SegmentationMap depthSegmentation_
Definition: HcalTopology.h:224
static constexpr unsigned int kPhiCalibHO1_
Definition: HcalTopology.h:269
SegmentationMap depthSegmentationOne_
Definition: HcalTopology.h:225
bool validRaw(const HcalDetId &id) const
static constexpr unsigned int mPhiCalibHE_
Definition: HcalTopology.h:249
unsigned int HOSize_
Definition: HcalTopology.h:210
bool validDetIdPreLS1(const HcalDetId &id) const
int getMaxDepth(const int &type) const
int zside() const
get the sign of ieta (+/-1)
std::vector< DetId > east(const DetId &id) const override
std::vector< double > etaTable
Definition: HcalTopology.h:216
int incAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
static constexpr unsigned int kOffCalibHB_
Definition: HcalTopology.h:240
Basic3DVector unit() const
static constexpr unsigned int nchanCalibHF1_
Definition: HcalTopology.h:255
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
static constexpr int kHTSizePhase1
Definition: HcalTopology.h:236
std::vector< DetId > down(const DetId &id) const override
const std::vector< double > & getEtaTableHF() const
static constexpr int chanCalibHO_[nchanCalibHO_]
Definition: HcalTopology.h:264
static constexpr unsigned int nchanCalibHE1_
Definition: HcalTopology.h:248
static constexpr unsigned int mPhiCalibHO1_
Definition: HcalTopology.h:267
ii
Definition: cuy.py:589
static constexpr unsigned int kOffCalibHOX_
Definition: HcalTopology.h:282
static constexpr unsigned int kPhiCalibHF1_
Definition: HcalTopology.h:256
int firstHEQuadPhiRing() const
Definition: HcalTopology.h:102
bool isPlan1ToBeMergedId(const HcalDetId &id) const
int firstHEQuadPhiRing_
Definition: HcalTopology.h:201
bool validCalib(const HcalCalibDetId &id) const
Definition: DetId.h:17
static constexpr int etaCalibHOX_[nEtaCalibHOX_]
Definition: HcalTopology.h:284
std::vector< double > phioff
Definition: HcalTopology.h:217
static constexpr int chanCalibHOs_
Definition: HcalTopology.h:263
void depthBinInformation(HcalSubdetector subdet, int etaRing, int iphi, int zside, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
static constexpr unsigned int kOffCalibHF1_
Definition: HcalTopology.h:254
static constexpr unsigned int nEtaCalibHOX_
Definition: HcalTopology.h:283
static constexpr int chanCalibHF1_[nchanCalibHF1_]
Definition: HcalTopology.h:257
static constexpr int kHFhalf
Definition: HcalTopology.h:227
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static constexpr unsigned int kOffCalibHE2_
Definition: HcalTopology.h:274
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:101
int maxHFDepth(int ieta, int iphi) const
static constexpr unsigned int kOffCalibHBX_
Definition: HcalTopology.h:289
static constexpr int chanCalibHB_[nchanCalibHB_]
Definition: HcalTopology.h:243
CalibDetType calibFlavor() const
get the flavor of this calibration detid
int ietaAbs() const
get the absolute value of the tower ieta
chan
lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") lumi.SetBorderSize( 0 ) lumi...
std::vector< DetId > north(const DetId &id) const override
bool validHcal(const HcalDetId &id) const
static constexpr unsigned int mPhiCalibHO0_
Definition: HcalTopology.h:267
std::vector< double > dPhiTable
Definition: HcalTopology.h:216
static constexpr unsigned int kOffCalibHO2_
Definition: HcalTopology.h:272
TString units(TString variable, Char_t axis)
int getNoff(const int &i) const
static constexpr unsigned int minPhi_
Definition: HcalTopology.h:239
int firstHETripleDepthRing_
Definition: HcalTopology.h:202
static constexpr int kSizeForDenseIndexingPreLS1
Definition: HcalTopology.h:230
int lastHERing() const
Definition: HcalTopology.h:94
bool isPlan1MergedId(const HcalDetId &id) const
static constexpr int etaCalibHF_[nEtaCalibHF_]
Definition: HcalTopology.h:258
int zside() const
get the z-side of the tower (1/-1)
std::vector< HcalDetId > exclusionList_
Definition: HcalTopology.h:187
const std::vector< double > & getPhiTable() const
bool incrementDepth(HcalDetId &id) const
int lastHFRing() const
Definition: HcalTopology.h:97
static constexpr unsigned int kPhiCalibHE_
Definition: HcalTopology.h:249
static constexpr unsigned int mPhiCalibHB_
Definition: HcalTopology.h:242
const std::vector< double > & getPhiTableHF() const
static constexpr unsigned int kchanCalibHB_
Definition: HcalTopology.h:245
int phiBin(HcalSubdetector subdet, int etaRing, double phi) const
std::vector< DetId > west(const DetId &id) const override
void setDepthSegmentation(const unsigned ring, const std::vector< int > &readoutDepths, const bool flag)
Log< level::Warning, false > LogWarning
static constexpr int phiCalibHF2_
Definition: HcalTopology.h:279
int version() const
get the version code for the trigger tower
static constexpr unsigned int kOffCalibHO1_
Definition: HcalTopology.h:261
static constexpr unsigned int nEtaCalibHEX_
Definition: HcalTopology.h:295
static constexpr float d1
static constexpr unsigned int kPhiCalibHEX_
Definition: HcalTopology.h:297
int getDepthEta29(const int &iphi, const int &zside, const int &type) const
std::vector< int > getDepth(const int &det, const int &phi, const int &zside, const unsigned int &eta) const
double etaMax(HcalSubdetector subdet) const
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
static constexpr unsigned int mPhiCalibHF1_
Definition: HcalTopology.h:256
unsigned int detId2denseIdHT(const DetId &id) const
return a linear packed id from HT
int firstHFRing() const
Definition: HcalTopology.h:96
int nPhiBins(int etaRing) const
how many phi segments in this ring
int firstHEDoublePhiRing_
Definition: HcalTopology.h:201
const HcalDDDRecConstants * hcons_
Definition: HcalTopology.h:185
static const int IPHI_MAX
Definition: HcalTopology.cc:13
static constexpr unsigned int kOffCalibHF2_
Definition: HcalTopology.h:278
int firstHFQuadPhiRing_
Definition: HcalTopology.h:201
int firstHERing() const
Definition: HcalTopology.h:93
bool isExcluded(const HcalDetId &id) const
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164