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