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>
11 #include "CLHEP/Units/GlobalPhysicalConstants.h"
12 
13 static const int IPHI_MAX=72;
14 
15 //#define EDM_ML_DEBUG
16 
18  const bool mergePosition) :
19  hcons_(hcons), mergePosition_(mergePosition),
20  excludeHB_(false), excludeHE_(false), excludeHO_(false), excludeHF_(false),
21  firstHBRing_(1),
22  firstHERing_(999), lastHERing_(0),
23  firstHFRing_(29), lastHFRing_(41),
24  firstHORing_(1), lastHORing_(15),
25  firstHEDoublePhiRing_(999), firstHEQuadPhiRing_(999),
26  firstHFQuadPhiRing_(40), firstHETripleDepthRing_(999),
27  singlePhiBins_(IPHI_MAX), doublePhiBins_(36), maxPhiHE_(IPHI_MAX) {
28 
39  for (auto & i : etaBinsHE_) {
40  if (firstHERing_ > i.ieta) firstHERing_ = i.ieta;
41  if (lastHERing_ < i.ieta) lastHERing_ = i.ieta;
42  int unit = (int)((i.dphi+0.01)/(5.0*CLHEP::deg));
43  if (unit == 2 && firstHEDoublePhiRing_ > i.ieta)
44  firstHEDoublePhiRing_ = i.ieta;
45  if (unit == 4 && firstHEQuadPhiRing_ > i.ieta)
46  firstHEQuadPhiRing_ = i.ieta;
47  if (i.layer.size() > 2 && firstHETripleDepthRing_ > i.ieta)
49  }
52  topoVersion_=0; //DL
53  HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
54  HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
55  HOSize_ = kHOSizePreLS1; // ieta * iphi * 2
56  HFSize_ = kHFSizePreLS1; // ieta * iphi * depth * 2
57  numberOfShapes_ = 87;
58  } else if (mode_==HcalTopologyMode::SLHC) { // need to know more eventually
59  topoVersion_=10;
60  HBSize_ = nEtaHB_*IPHI_MAX*maxDepthHB_*2;
62  HOSize_ = (lastHORing_-firstHORing_+1)*IPHI_MAX*2; // ieta * iphi * 2
63  HFSize_ = (lastHFRing_-firstHFRing_+1)*IPHI_MAX*maxDepthHF_*2; // ieta * iphi * depth * 2
64  numberOfShapes_ = (maxPhiHE_ > 72) ? 1200 : 500;
65  }
69  } else {
71  }
72 
73 #ifdef EDM_ML_DEBUG
74  std::cout << "Topo sizes " << HBSize_ << ":" << HESize_ << ":" << HOSize_
75  << ":" << HFSize_ << ":" << HTSize_ << " for mode " << mode_
76  << ":" << triggerMode_ << std::endl;
77 #endif
78 
79  //The transition between HE/HF in eta
85  std::pair<int,int> ietaHF = hcons_->getEtaRange(2);
86  double eta = etaBinsHE_[etaBinsHE_.size()-1].etaMax;
88  for (unsigned int i=1; i<etaTableHF.size(); ++i) {
89  if (eta < etaTableHF[i]) {
90  etaHE2HF_ = ietaHF.first + i - 1;
91  break;
92  }
93  }
94  eta = etaTableHF[0];
96  for (auto & i : etaBinsHE_) {
97  if (eta < i.etaMax) {
98  etaHF2HE_ = i.ieta;
99  break;
100  }
101  }
102  const double fiveDegInRad = 2*M_PI/72;
103  for (double k : dPhiTable) {
104  int units = (int)(k/fiveDegInRad+0.5);
105  unitPhi.emplace_back(units);
106  }
107  for (double k : dPhiTableHF) {
108  int units = (int)(k/fiveDegInRad+0.5);
109  unitPhiHF.emplace_back(units);
110  }
111  int nEta = hcons_->getNEta();
112  for (int ring=1; ring<=nEta; ++ring) {
113  std::vector<int> segmentation = hcons_->getDepth(ring-1,false);
114  setDepthSegmentation(ring,segmentation,false);
115 #ifdef EDM_ML_DEBUG
116  std::cout << "Set segmentation for ring " << ring << " with "
117  << segmentation.size() << " elements:";
118  for (unsigned int k=0; k<segmentation.size(); ++k)
119  std::cout << " " << segmentation[k];
120  std::cout << std::endl;
121 #endif
122  segmentation = hcons_->getDepth(ring-1,true);
123  setDepthSegmentation(ring,segmentation,true);
124 #ifdef EDM_ML_DEBUG
125  std::cout << "Set Plan-1 segmentation for ring " << ring << " with "
126  << segmentation.size() << " elements:";
127  for (unsigned int k=0; k<segmentation.size(); ++k)
128  std::cout << " " << segmentation[k];
129  std::cout << std::endl;
130 #endif
131  }
132 
133 #ifdef EDM_ML_DEBUG
134  std::cout << "Constants in HcalTopology " << firstHBRing_ << ":"
135  << lastHBRing_ << " " << firstHERing_ << ":" << lastHERing_ << ":"
136  << firstHEDoublePhiRing_ << ":" << firstHEQuadPhiRing_ << ":"
137  << firstHETripleDepthRing_ << " " << firstHFRing_ << ":"
138  << lastHFRing_ << ":" << firstHFQuadPhiRing_ << " " << firstHORing_
139  << ":" << lastHORing_ << " " << maxDepthHB_ << ":" << maxDepthHE_
140  << " " << nEtaHB_ << ":" << nEtaHE_ << " " << etaHE2HF_ << ":"
141  << etaHF2HE_ << " " << maxPhiHE_ << std::endl;
142 #endif
143 }
144 
148  mode_(mode), triggerMode_(tmode),
149  firstHBRing_(1), lastHBRing_(16),
150  firstHERing_(16), lastHERing_(29),
151  firstHFRing_(29), lastHFRing_(41),
152  firstHORing_(1), lastHORing_(15),
153  firstHEDoublePhiRing_((mode==HcalTopologyMode::H2 || mode==HcalTopologyMode::H2HE)?(22):(21)),
155  firstHETripleDepthRing_((mode==HcalTopologyMode::H2 || mode==HcalTopologyMode::H2HE)?(24):(27)),
157  maxDepthHB_(maxDepthHB), maxDepthHE_(maxDepthHE), maxDepthHF_(2),
164  numberOfShapes_(( mode==HcalTopologyMode::SLHC ) ? 500 : 87 ) {
165 
167  topoVersion_=0; //DL
168  HBSize_= kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
169  HESize_= kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
170  HOSize_= kHOSizePreLS1; // ieta * iphi * 2
171  HFSize_= kHFSizePreLS1; // phi * eta * depth * pm
172  } else if (mode_==HcalTopologyMode::SLHC) { // need to know more eventually
173  HBSize_= maxDepthHB*16*IPHI_MAX*2;
174  HESize_= maxDepthHE*(29-16+1)*maxPhiHE_*2;
175  HOSize_= 15*IPHI_MAX*2; // ieta * iphi * 2
176  HFSize_= IPHI_MAX*13*maxDepthHF_*2; // phi * eta * depth * pm
177  topoVersion_=10;
178  }
183  } else {
185  }
186 
187  edm::LogWarning("CaloTopology") << "This is an incomplete constructor of HcalTopology - be warned that many functionalities will not be there - revert from this - get from EventSetup";
188 }
189 
190 bool HcalTopology::valid(const DetId& id) const {
191  assert(id.det()==DetId::Hcal);
192  return validHcal(id);
193 }
194 
195 bool HcalTopology::validHcal(const HcalDetId& id) const {
196  // check the raw rules
197  bool ok=validRaw(id);
198 
199  ok=ok && !isExcluded(id);
200 
201  return ok;
202 }
203 
204 bool HcalTopology::validDetId(HcalSubdetector subdet, int ieta, int iphi,
205  int depth) const {
206  HcalDetId id(subdet,ieta,iphi,depth);
207  return validHcal(id);
208 }
209 
211 
212  if (id.iphi()<1 || id.iphi()>IPHI_MAX || id.ieta()==0) return false;
213  if (id.depth() != 0) return false;
214  if (id.version()==0) {
215  if (id.ietaAbs() > 28) {
218  if ((id.iphi() % 4) != 1) return false;
219  if (id.ietaAbs() > 32) return false;
220  }
221  } else {
223  if (id.ietaAbs()<30 || id.ietaAbs()>41) return false;
224  if (id.ietaAbs()>29 && ((id.iphi()%2)==0)) return false;
225  if (id.ietaAbs()>39 && ((id.iphi()%4)!=3)) return false;
226  }
227  return true;
228 }
229 
230 bool HcalTopology::validHcal(const HcalDetId& id, const unsigned int flag) const {
231  // check the raw rules
232  bool ok = validHcal(id);
233  if (flag == 0) { // This is all what is needed
234  } else if (flag == 1) { // See if it is in the to be merged list and merged list
235  if (hcons_->isPlan1MergedId(id)) ok = true;
236  else if (hcons_->isPlan1ToBeMergedId(id)) ok = false;
237  } else if (!ok) {
238  ok = hcons_->isPlan1MergedId(id);
239  }
240  return ok;
241 }
242 
243 bool HcalTopology::isExcluded(const HcalDetId& id) const {
244  bool exed=false;
245  // first, check the full detector exclusions... (fast)
246  switch (id.subdet()) {
247  case(HcalBarrel): exed=excludeHB_; break;
248  case(HcalEndcap): exed=excludeHE_; break;
249  case(HcalOuter): exed=excludeHO_; break;
250  case(HcalForward): exed=excludeHF_; break;
251  default: exed=false;
252  }
253  // next, check the list (slower)
254  if (!exed && !exclusionList_.empty()) {
255  std::vector<HcalDetId>::const_iterator i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
256  if (i!=exclusionList_.end() && *i==id) exed=true;
257  }
258  return exed;
259 }
260 
262  std::vector<HcalDetId>::iterator i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
263  if (i==exclusionList_.end() || *i!=id) {
264  exclusionList_.insert(i,id);
265  }
266 }
267 
269  switch (subdet) {
270  case(HcalBarrel): excludeHB_=true; break;
271  case(HcalEndcap): excludeHE_=true; break;
272  case(HcalOuter): excludeHO_=true; break;
273  case(HcalForward): excludeHF_=true; break;
274  default: break;
275  }
276 }
277 
278 std::vector<DetId> HcalTopology::east(const DetId& id) const {
279  std::vector<DetId> vNeighborsDetId;
280  HcalDetId neighbors[2];
281  for (int i=0;i<decIEta(HcalDetId(id),neighbors);i++) {
282  if (neighbors[i].oldFormat()) neighbors[i].changeForm();
283  vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
284  }
285  return vNeighborsDetId;
286 }
287 
288 std::vector<DetId> HcalTopology::west(const DetId& id) const {
289  std::vector<DetId> vNeighborsDetId;
290  HcalDetId neighbors[2];
291  for (int i=0;i<incIEta(HcalDetId(id),neighbors);i++) {
292  if (neighbors[i].oldFormat()) neighbors[i].changeForm();
293  vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
294  }
295  return vNeighborsDetId;
296 }
297 
298 std::vector<DetId> HcalTopology::north(const DetId& id) const {
299  std::vector<DetId> vNeighborsDetId;
300  HcalDetId neighbor;
301  if (incIPhi(HcalDetId(id),neighbor)) {
302  if (neighbor.oldFormat()) neighbor.changeForm();
303  vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
304  }
305  return vNeighborsDetId;
306 }
307 
308 std::vector<DetId> HcalTopology::south(const DetId& id) const {
309  std::vector<DetId> vNeighborsDetId;
310  HcalDetId neighbor;
311  if (decIPhi(HcalDetId(id),neighbor)) {
312  if (neighbor.oldFormat()) neighbor.changeForm();
313  vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
314  }
315  return vNeighborsDetId;
316 }
317 
318 std::vector<DetId> HcalTopology::up(const DetId& id) const {
319  HcalDetId neighbor = id;
320  std::vector<DetId> vNeighborsDetId;
321  if (incrementDepth(neighbor)) {
322  if (neighbor.oldFormat()) neighbor.changeForm();
323  vNeighborsDetId.emplace_back(neighbor);
324  }
325  return vNeighborsDetId;
326 }
327 
328 std::vector<DetId> HcalTopology::down(const DetId& id) const {
329  HcalDetId neighbor = id;
330  std::vector<DetId> vNeighborsDetId;
331  if (decrementDepth(neighbor)) {
332  if (neighbor.oldFormat()) neighbor.changeForm();
333  vNeighborsDetId.emplace_back(neighbor);
334  }
335  return vNeighborsDetId;
336 }
337 
338 int HcalTopology::exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi1, int iphi2, int depth1, int depth2) {
339 
340  bool exed=false;
341  // first, check the full detector exclusions... (fast)
342  switch (subdet) {
343  case(HcalBarrel): exed=excludeHB_; break;
344  case(HcalEndcap): exed=excludeHE_; break;
345  case(HcalOuter): exed=excludeHO_; break;
346  case(HcalForward): exed=excludeHF_; break;
347  default: exed=false;
348  }
349  if (exed) return 0; // if the whole detector is excluded...
350 
351  int ieta_l=std::min(ieta1,ieta2);
352  int ieta_h=std::max(ieta1,ieta2);
353  int iphi_l=std::min(iphi1,iphi2);
354  int iphi_h=std::max(iphi1,iphi2);
355  int depth_l=std::min(depth1,depth2);
356  int depth_h=std::max(depth1,depth2);
357 
358  int n=0;
359  for (int ieta=ieta_l; ieta<=ieta_h; ieta++)
360  for (int iphi=iphi_l; iphi<=iphi_h; iphi++)
361  for (int depth=depth_l; depth<=depth_h; depth++) {
362  HcalDetId id(subdet,ieta,iphi,depth);
363  if (validRaw(id)) { // use 'validRaw' to include check validity in "uncut" detector
364  exclude(id);
365  n++;
366  }
367  }
368  return n;
369 }
370 
398  const HcalSubdetector sd (id.subdet());
399  const int ie (id.ietaAbs());
400  const int ip (id.iphi());
401  const int dp (id.depth());
402 
403  return ( ( ip >= 1 ) &&
404  ( ip <= IPHI_MAX ) &&
405  ( dp >= 1 ) &&
406  ( ie >= 1 ) &&
407  ( ( ( sd == HcalBarrel ) &&
408  ( ( ( ie <= 14 ) &&
409  ( dp == 1 ) ) ||
410  ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
411  ( dp <= 2 ) ) ) ) ||
412  ( ( sd == HcalEndcap ) &&
413  ( ( ( ie == firstHERing() ) &&
414  ( dp == 3 ) ) ||
415  ( ( ie == 17 ) &&
416  ( dp == 1 ) ) ||
417  ( ( ie >= 18 ) &&
418  ( ie <= 20 ) &&
419  ( dp <= 2 ) ) ||
420  ( ( ie >= 21 ) &&
421  ( ie <= 26 ) &&
422  ( dp <= 2 ) &&
423  ( ip%2 == 1 ) ) ||
424  ( ( ie >= 27 ) &&
425  ( ie <= 28 ) &&
426  ( dp <= 3 ) &&
427  ( ip%2 == 1 ) ) ||
428  ( ( ie == 29 ) &&
429  ( dp <= 2 ) &&
430  ( ip%2 == 1 ) ) ) ) ||
431  ( ( sd == HcalOuter ) &&
432  ( ie <= 15 ) &&
433  ( dp == 4 ) ) ||
434  ( ( sd == HcalForward ) &&
435  ( dp <= 2 ) &&
436  ( ( ( ie >= firstHFRing() ) &&
437  ( ie < firstHFQuadPhiRing() ) &&
438  ( ip%2 == 1 ) ) ||
439  ( ( ie >= firstHFQuadPhiRing() ) &&
440  ( ie <= lastHFRing() ) &&
441  ( ip%4 == 3 ) ) ) ) ) ) ;
442 }
443 
445 bool HcalTopology::validRaw(const HcalDetId& id) const {
446  bool ok=true;
447  int ieta=id.ieta();
448  int aieta=id.ietaAbs();
449  int depth=id.depth();
450  int iphi=id.iphi();
451  int zside=id.zside();
452  HcalSubdetector subdet=id.subdet();
453  int maxPhi = (subdet==HcalEndcap) ? maxPhiHE_ : IPHI_MAX;
454  if ((ieta==0 || iphi<=0 || iphi>maxPhi) || aieta>maxEta_) ok = false; // outer limits
455 
456  if (ok) {
457  if (subdet==HcalBarrel) {
459  if ((aieta>lastHBRing()) ||
460  (depth>hcons_->getMaxDepth(0,aieta,iphi,zside)) ||
461  (depth<hcons_->getMinDepth(0,aieta,iphi,zside))) ok=false;
462  } else {
463  if (aieta>lastHBRing() || depth>2 || (aieta<=14 && depth>1)) ok=false;
464  }
465  } else if (subdet==HcalEndcap) {
467  if ((depth>hcons_->getMaxDepth(1,aieta,iphi,zside)) ||
468  (depth<hcons_->getMinDepth(1,aieta,iphi,zside)) ||
469  (aieta<firstHERing()) || (aieta>lastHERing())) {
470  ok = false;
471  } else {
472  for (const auto & i : etaBinsHE_) {
473  if (aieta == i.ieta) {
474  if (aieta >= firstHEDoublePhiRing() && (iphi%2)==0) ok=false;
475  if (aieta >= firstHEQuadPhiRing() && (iphi%4)!=3) ok=false;
476  if (aieta+1 == hcons_->getNoff(1)) {
477  if (depth < 1) ok = false;
478  } else {
479  if (depth < i.depthStart) ok = false;
480  }
481  break;
482  }
483  }
484  }
485  } else {
486  if (depth>hcons_->getMaxDepth(1,aieta,iphi,zside) ||
487  aieta<firstHERing() || aieta>lastHERing() ||
488  (aieta==firstHERing() && depth!=hcons_->getDepthEta16(2,iphi,zside)) ||
489  (aieta==17 && depth!=1 && mode_!=HcalTopologyMode::H2) || // special case at H2
490  (((aieta>=17 && aieta<firstHETripleDepthRing()) ||
491  aieta==lastHERing()) && depth>2) ||
492  (aieta>=firstHEDoublePhiRing() && (iphi%2)==0)) ok=false;
493  }
494  } else if (subdet==HcalOuter) {
495  if (aieta>lastHORing() || iphi>IPHI_MAX || depth!=4) ok=false;
496  } else if (subdet==HcalForward) {
497  if (aieta<firstHFRing() || aieta>lastHFRing() || ((iphi%2)==0) ||
498  (depth>hcons_->maxHFDepth(ieta,iphi)) ||
499  (aieta>=firstHFQuadPhiRing() && ((iphi+1)%4)!=0)) ok=false;
500  } else if (subdet==HcalTriggerTower) {
501  ok=validHT(HcalTrigTowerDetId(id.rawId()));
502  } else {
503  ok=false;
504  }
505  }
506  return ok;
507 }
508 
509 bool HcalTopology::incIPhi(const HcalDetId& id, HcalDetId &neighbor) const {
510  bool ok=valid(id);
511  if (ok) {
512  switch (id.subdet()) {
513  case (HcalBarrel):
514  case (HcalOuter):
515  if (id.iphi()==IPHI_MAX) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
516  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+1,id.depth());
517  break;
518  case (HcalEndcap):
519  if (id.ietaAbs()>=firstHEQuadPhiRing()) {
520  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),3,id.depth());
521  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+4,id.depth());
522  } else if (id.ietaAbs()>=firstHEDoublePhiRing()) {
523  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
524  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+2,id.depth());
525  } else {
526  if (id.iphi()==maxPhiHE_) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
527  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+1,id.depth());
528  }
529  break;
530  case (HcalForward):
531  if (id.ietaAbs()>=firstHFQuadPhiRing()) {
532  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),3,id.depth());
533  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+4,id.depth());
534  } else {
535  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
536  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+2,id.depth());
537  }
538  if (!validRaw(neighbor)) ok = false;
539  break;
540  default: ok=false;
541  }
542  }
543  return ok;
544 }
545 
547 bool HcalTopology::decIPhi(const HcalDetId& id, HcalDetId &neighbor) const {
548  bool ok=valid(id);
549  if (ok) {
550  switch (id.subdet()) {
551  case (HcalBarrel):
552  case (HcalOuter):
553  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX,id.depth());
554  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-1,id.depth());
555  break;
556  case (HcalEndcap):
557  if (id.ietaAbs()>=firstHEQuadPhiRing()) {
558  if (id.iphi()==3) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
559  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-4,id.depth());
560  } else if (id.ietaAbs()>=firstHEDoublePhiRing()) {
561  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
562  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-2,id.depth());
563  } else {
564  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),maxPhiHE_,id.depth());
565  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-1,id.depth());
566  }
567  break;
568  case (HcalForward):
569  if (id.ietaAbs()>=firstHFQuadPhiRing()) {
570  if (id.iphi()==3) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
571  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-4,id.depth());
572  } else {
573  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
574  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-2,id.depth());
575  }
576  if (!validRaw(neighbor)) ok = false;
577  break;
578  default: ok=false;
579  }
580  }
581  return ok;
582 }
583 
584 int HcalTopology::incIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
585  if (id.zside()==1) return incAIEta(id,neighbors);
586  else return decAIEta(id,neighbors);
587 }
588 
589 int HcalTopology::decIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
590  if (id.zside()==1) return decAIEta(id,neighbors);
591  else return incAIEta(id,neighbors);
592 }
593 
595 int HcalTopology::incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
596  int n=1;
597  int aieta=id.ietaAbs();
598 
599  if (aieta==firstHEDoublePhiRing()-1 && (id.iphi()%2)==0)
600  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),id.iphi()-1,id.depth());
601  else if (aieta==firstHFQuadPhiRing()-1 && ((id.iphi()+1)%4)!=0)
602  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),((id.iphi()==1)?(71):(id.iphi()-2)),id.depth());
603  else if (aieta==firstHEQuadPhiRing()-1 && ((id.iphi()+1)%4)!=0)
604  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),((id.iphi()==1)?(71):(id.iphi()-2)),id.depth());
605  else if (aieta==lastHBRing())
606  neighbors[0]=HcalDetId(HcalEndcap,(aieta+1)*id.zside(),id.iphi(),1);
607  else if (aieta==lastHERing())
608  neighbors[0]=HcalDetId(HcalForward,etaHE2HF_*id.zside(),id.iphi(),1);
609  else
610  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),id.iphi(),id.depth());
611 
612  if (!valid(neighbors[0])) n=0;
613  return n;
614 }
615 
617 int HcalTopology::decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
618  int n=1;
619  int aieta=id.ietaAbs();
620 
621  if (aieta==firstHEDoublePhiRing()) {
622  n=2;
623  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
624  neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi()+1,id.depth());
625  } else if (aieta==firstHFQuadPhiRing()) {
626  n=2;
627  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
628  if (id.iphi()==IPHI_MAX-1) neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),1,id.depth());
629  else neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi()+2,id.depth());
630  } else if (aieta==firstHEQuadPhiRing()) {
631  n=2;
632  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
633  if (id.iphi()==IPHI_MAX-1) neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),1,id.depth());
634  else neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi()+2,id.depth());
635  } else if (aieta==1) {
636  neighbors[0]=HcalDetId(id.subdet(),-aieta*id.zside(),id.iphi(),id.depth());
637  } else if (aieta==firstHERing()) {
638  neighbors[0]=HcalDetId(HcalBarrel,(aieta-1)*id.zside(),id.iphi(),1);
639  } else if (aieta==firstHFRing()) {
640  neighbors[0]=HcalDetId(HcalEndcap,etaHF2HE_*id.zside(),id.iphi(),1);
641  } else
642  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
643 
644  if (!valid(neighbors[0]) && n==2) {
645  if (!valid(neighbors[1])) n=0;
646  else {
647  n=1;
648  neighbors[0]=neighbors[1];
649  }
650  }
651  if (n==2 && !valid(neighbors[1])) n=1;
652  if (n==1 && !valid(neighbors[0])) n=0;
653 
654  return n;
655 }
656 
657 
659  int iphi, int zside, int & nDepthBins,
660  int & startingBin) const {
661 
662  if(subdet == HcalBarrel) {
664  startingBin = hcons_->getMinDepth(0,etaRing,iphi,zside);
665  if (etaRing==lastHBRing()) {
666  nDepthBins = hcons_->getDepthEta16(1,iphi,zside)-startingBin+1;
667  } else {
668  nDepthBins = hcons_->getMaxDepth(0,etaRing,iphi,zside)-startingBin+1;
669  }
670  } else {
671  if (etaRing<=14) {
672  nDepthBins = 1;
673  startingBin = 1;
674  } else {
675  nDepthBins = 2;
676  startingBin = 1;
677  }
678  }
679  } else if(subdet == HcalEndcap) {
681  if (etaRing==firstHERing()) {
682  startingBin = hcons_->getDepthEta16(2,iphi,zside);
683  } else {
684  startingBin = hcons_->getMinDepth(1,etaRing,iphi,zside);
685  }
686  nDepthBins = hcons_->getMaxDepth(1,etaRing,iphi,zside)-startingBin+1;
687  } else {
688  if (etaRing==firstHERing()) {
689  nDepthBins = 1;
690  startingBin = 3;
691  } else if (etaRing==17) {
692  nDepthBins = 1;
693  startingBin = 1;
694  } else if (etaRing==lastHERing()) {
695  nDepthBins = 2;
696  startingBin = 1;
697  } else {
698  nDepthBins = (etaRing >= firstHETripleDepthRing()) ? 3 : 2;
699  startingBin = 1;
700  }
701  }
702  } else if(subdet == HcalForward) {
703  nDepthBins = maxDepthHF_;
704  startingBin = 1;
705  } else if(subdet == HcalOuter) {
706  nDepthBins = 1;
707  startingBin = 4;
708  } else {
709  std::cerr << "Bad HCAL subdetector " << subdet << std::endl;
710  }
711 }
712 
714 
715  HcalSubdetector subdet = detId.subdet();
716  int ieta = detId.ieta();
717  int etaRing = detId.ietaAbs();
718  int depth = detId.depth();
719  int iphi = detId.iphi();
720  int zside = detId.zside();
721  int nDepthBins, startingBin;
722  depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
723 
724  // see if the new depth bin exists
725  ++depth;
726  if (depth >= (startingBin+nDepthBins)) {
727  // handle on a case-by-case basis
728  if (subdet == HcalBarrel && etaRing < lastHORing()) {
729  // HO
730  subdet = HcalOuter;
731  depth = 4;
732  } else if (subdet == HcalBarrel && etaRing == lastHBRing()) {
733  // overlap
734  subdet = HcalEndcap;
736  depth = hcons_->getDepthEta16(2,iphi,zside);
737  } else if (subdet == HcalEndcap && etaRing == lastHERing()-1 &&
739  // guard ring HF29 is behind HE 28
740  subdet = HcalForward;
741  (ieta > 0) ? ++ieta : --ieta;
742  depth = 1;
743  } else if (subdet == HcalEndcap && etaRing == lastHERing() &&
745  // split cells go to bigger granularity. Ring 29 -> 28
746  (ieta > 0) ? --ieta : ++ieta;
747  } else {
748  // no more chances
749  detId = HcalDetId();
750  return false;
751  }
752  }
753  detId = HcalDetId(subdet, ieta, iphi, depth);
754  return validRaw(detId);
755 }
756 
758  HcalSubdetector subdet = detId.subdet();
759  int ieta = detId.ieta();
760  int etaRing = detId.ietaAbs();
761  int depth = detId.depth();
762  int iphi = detId.iphi();
763  int zside = detId.zside();
764  int nDepthBins, startingBin;
765  depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
766 
767  // see if the new depth bin exists
768  --depth;
769  if ((subdet == HcalOuter) ||
770  (subdet == HcalEndcap && etaRing == firstHERing())) {
771  subdet = HcalBarrel;
772  for (int i=0; i<nEtaHB_; ++i) {
773  if (etaRing == etaBinsHB_[i].ieta) {
774  depth = etaBinsHB_[i].depthStart+etaBinsHB_[i].layer.size()-1;
775  break;
776  }
777  }
778  } else if (subdet == HcalEndcap && etaRing == lastHERing() &&
779  depth == hcons_->getDepthEta29(iphi,zside,0) &&
781  (ieta > 0) ? --ieta : ++ieta;
782  } else if (depth <= 0) {
783  if (subdet == HcalForward && etaRing == firstHFRing()) {
784  // overlap
785  subdet = HcalEndcap;
786  etaRing= etaHF2HE_;
787  ieta = (ieta > 0) ? etaRing : -etaRing;
788  for (const auto & i : etaBinsHE_) {
789  if (etaRing == i.ieta) {
790  depth = i.depthStart+i.layer.size()-1;
791  break;
792  }
793  }
794  } else {
795  // no more chances
796  detId = HcalDetId();
797  return false;
798  }
799  }
800  detId = HcalDetId(subdet, ieta, detId.iphi(), depth);
801  return validRaw(detId);
802 }
803 
805  int lastPhiBin=singlePhiBins_;
806  if (etaRing>= firstHFQuadPhiRing()) lastPhiBin=doublePhiBins_/2;
807  else if (etaRing>= firstHEQuadPhiRing()) lastPhiBin=doublePhiBins_/2;
808  else if (etaRing>= firstHEDoublePhiRing()) lastPhiBin=doublePhiBins_;
809  if (hcons_) {
810  if (etaRing>=hcons_->getEtaRange(1).first &&
811  etaRing<=hcons_->getEtaRange(1).second)
812  lastPhiBin = (int)((2*M_PI+0.001)/dPhiTable[etaRing-firstHBRing_]);
813  }
814  return lastPhiBin;
815 }
816 
818  static const double twopi = M_PI+M_PI;
819  int lastPhiBin;
820  if (bc == HcalForward) {
821  lastPhiBin = (int)((twopi+0.001)/dPhiTableHF[etaRing-firstHFRing_]);
822  } else {
823  lastPhiBin = (int)((twopi+0.001)/dPhiTable[etaRing-firstHBRing_]);
824  }
825  return lastPhiBin;
826 }
827 
829  if (bc == HcalBarrel) return maxDepthHB_;
830  else if (bc == HcalEndcap) return maxDepthHE_;
831  else if (bc == HcalForward) return maxDepthHF_;
832  else return 4;
833 }
834 
835 int HcalTopology::etaRing(HcalSubdetector bc, double abseta) const {
836  int etaring = firstHBRing_;
837  if (bc == HcalForward) {
838  etaring = firstHFRing_;
839  for (unsigned int k=0; k<etaTableHF.size()-1; ++k) {
840  if (abseta < etaTableHF[k+1]) {
841  etaring += k;
842  break;
843  }
844  }
845  } else {
846  for (unsigned int k=0; k<etaTable.size()-1; ++k) {
847  if (abseta < etaTable[k+1]) {
848  etaring += k;
849  break;
850  }
851  }
852  if (abseta >= etaTable[etaTable.size()-1]) etaring = lastHERing_;
853  }
854  return etaring;
855 }
856 
857 int HcalTopology::phiBin(HcalSubdetector bc, int etaring, double phi) const {
858  static const double twopi = M_PI+M_PI;
859  //put phi in correct range (0->2pi)
860  int index(0);
861  if (bc == HcalBarrel) {
862  index = (etaring-firstHBRing_);
863  phi -= phioff[0];
864  } else if (bc == HcalEndcap) {
865  index = (etaring-firstHBRing_);
866  phi -= phioff[1];
867  } else if (bc == HcalForward) {
868  index = (etaring-firstHFRing_);
869  if (index < (int)(dPhiTableHF.size())) {
870  if (unitPhiHF[index] > 2) phi -= phioff[4];
871  else phi -= phioff[2];
872  }
873  }
874  if (phi<0.0) phi += twopi;
875  if (phi>twopi) phi -= twopi;
876  int phibin(1), unit(1);
877  if (bc == HcalForward) {
878  if (index < (int)(dPhiTableHF.size())) {
879  unit = unitPhiHF[index];
880  phibin = static_cast<int>(phi/dPhiTableHF[index])+1;
881  }
882  } else {
883  if (index < (int)(dPhiTable.size())) {
884  phibin = static_cast<int>(phi/dPhiTable[index])+1;
885  unit = unitPhi[index];
886  }
887  }
888  int iphi(phibin);
889  if (unit == 2) iphi = (phibin-1)*2+1;
890  else if (unit == 4) iphi = (phibin-1)*4+3;
891  return iphi;
892 }
893 
895  std::vector<int> & readoutDepths,
896  const bool one) const {
897  // if it doesn't exist, return the first entry with a lower index. So if we only
898  // have entries for 1 and 17, any input from 1-16 should return the entry for ring 1
899  SegmentationMap::const_iterator pos;
900  if (!one) {
901  pos = depthSegmentation_.upper_bound(ring);
902  if (pos == depthSegmentation_.begin()) {
903  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
904  }
905  } else {
906  pos = depthSegmentationOne_.upper_bound(ring);
907  if (pos == depthSegmentationOne_.begin()) {
908  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
909  }
910  }
911  --pos;
912  // pos now refers to the last element with key <= ring.
913  readoutDepths = pos->second;
914 }
915 
917  const std::vector<int> & readoutDepths,
918  const bool one) {
919  if (one) {
920  depthSegmentationOne_[ring] = readoutDepths;
921  } else {
922  depthSegmentation_[ring] = readoutDepths;
923  }
924 }
925 
926 std::pair<int, int> HcalTopology::segmentBoundaries(const unsigned ring,
927  const unsigned depth,
928  const bool one) const {
929  std::vector<int> readoutDepths;
930  getDepthSegmentation(ring, readoutDepths, one);
931  int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
932  int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
933  return std::pair<int, int>(d1, d2);
934 }
935 
936 double HcalTopology::etaMax(HcalSubdetector subdet) const {
937  double eta(0);
938  switch (subdet) {
939  case(HcalBarrel):
940  if (lastHBRing_ < (int)(etaTable.size())) eta=etaTable[lastHBRing_];
941  break;
942  case(HcalEndcap):
943  if (lastHERing_ < (int)(etaTable.size()) && nEtaHE_ > 0) eta=etaTable[lastHERing_];
944  break;
945  case(HcalOuter):
946  if (lastHORing_ < (int)(etaTable.size())) eta=etaTable[lastHORing_];
947  break;
948  case(HcalForward):
949  if (!etaTableHF.empty()) eta=etaTableHF[etaTableHF.size()-1];
950  break;
951  default: eta=0;
952  }
953  return eta;
954 }
955 std::pair<double,double> HcalTopology::etaRange(HcalSubdetector subdet,
956  int keta) const {
957  int ieta = (keta > 0) ? keta : -keta;
958  if (subdet == HcalForward) {
959  if (ieta >= firstHFRing_) {
960  unsigned int ii = (unsigned int)(ieta-firstHFRing_);
961  if (ii+1 < etaTableHF.size())
962  return std::pair<double,double>(etaTableHF[ii],etaTableHF[ii+1]);
963  }
964  } else {
965  int ietal = (mode_==HcalTopologyMode::LHC && ieta == lastHERing_-1) ? (ieta+1) : ieta;
966  if ((ietal < (int)(etaTable.size())) && (ieta > 0))
967  return std::pair<double,double>(etaTable[ieta-1],etaTable[ietal]);
968  }
969  return std::pair<double,double>(0,0);
970 }
971 
972 unsigned int HcalTopology::detId2denseIdPreLS1 (const DetId& id) const {
973 
974  HcalDetId hid(id);
975  const HcalSubdetector sd (hid.subdet() ) ;
976  const int ip (hid.iphi() ) ;
977  const int ie (hid.ietaAbs() ) ;
978  const int dp (hid.depth() ) ;
979  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
980  unsigned int retval = ( ( sd == HcalBarrel ) ?
981  ( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf :
982  ( ( sd == HcalEndcap ) ?
983  2*kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
984  ( ( ie==16 || ie==17 ) ? ie - 16 :
985  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
986  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
987  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
988  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf :
989  ( ( sd == HcalOuter ) ?
990  2*kHBhalf + 2*kHEhalf + ( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf :
991  ( ( sd == HcalForward ) ?
992  2*kHBhalf + 2*kHEhalf + 2*kHOhalf +
993  ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
994  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
995  return retval;
996 }
997 
998 
999 unsigned int HcalTopology::detId2denseIdHB(const DetId& id) const {
1000  HcalDetId hid(id);
1001  const int ip (hid.iphi() ) ;
1002  const int ie (hid.ietaAbs() ) ;
1003  const int dp (hid.depth() ) ;
1004  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
1005  unsigned int retval = 0xFFFFFFFFu;
1006  if (topoVersion_==0) {
1007  retval=( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf;
1008  } else if (topoVersion_==10) {
1009  retval=(dp-1)+maxDepthHB_*(ip-1);
1010  if (hid.ieta()>0) retval+=maxDepthHB_*IPHI_MAX*(hid.ieta()-firstHBRing());
1011  else retval+=maxDepthHB_*IPHI_MAX*(hid.ieta()+lastHBRing()+nEtaHB_);
1012  }
1013  return retval;
1014 }
1015 
1016 unsigned int HcalTopology::detId2denseIdHE(const DetId& id) const {
1017  HcalDetId hid(id);
1018  const int ip (hid.iphi() ) ;
1019  const int ie (hid.ietaAbs() ) ;
1020  const int dp (hid.depth() ) ;
1021  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
1022  unsigned int retval = 0xFFFFFFFFu;
1023  if (topoVersion_==0) {
1024  retval=( ip - 1 )*8 + ( ip/2 )*20 +
1025  ( ( ie==16 || ie==17 ) ? ie - 16 :
1026  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
1027  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
1028  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
1029  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf;
1030  } else if (topoVersion_==10) {
1031  retval=(dp-1)+maxDepthHE_*(ip-1);
1032  if (hid.ieta()>0) retval+=maxDepthHE_*maxPhiHE_*(hid.ieta()-firstHERing());
1033  else retval+=maxDepthHE_*maxPhiHE_*(hid.ieta()+lastHERing()+nEtaHE_);
1034  }
1035  return retval;
1036 }
1037 
1038 unsigned int HcalTopology::detId2denseIdHO(const DetId& id) const {
1039  HcalDetId hid(id);
1040  const int ip (hid.iphi() ) ;
1041  const int ie (hid.ietaAbs() ) ;
1042  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
1043 
1044  unsigned int retval = 0xFFFFFFFFu;
1045  if (topoVersion_==0) {
1046  retval=( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf;
1047  } else if (topoVersion_==10) {
1048  if (hid.ieta()>0) retval=(ip-1)+IPHI_MAX*(hid.ieta()-1);
1049  else retval=(ip-1)+IPHI_MAX*(30+hid.ieta());
1050  }
1051  return retval;
1052 }
1053 
1054 unsigned int HcalTopology::detId2denseIdHF(const DetId& id) const {
1055  HcalDetId hid(id);
1056  const int ip (hid.iphi() ) ;
1057  const int ie (hid.ietaAbs() ) ;
1058  const int dp (hid.depth() ) ;
1059  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
1060 
1061  unsigned int retval = 0xFFFFFFFFu;
1062  if (topoVersion_==0) {
1063  retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
1064  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf;
1065  } else if (topoVersion_==10) {
1066  retval=dp-1+2*(ip-1);
1067  if (hid.ieta()>0) retval+=maxDepthHF_*IPHI_MAX*(hid.ieta()-29);
1068  else retval+=maxDepthHF_*IPHI_MAX*((41+13)+hid.ieta());
1069  }
1070  return retval;
1071 }
1072 
1073 unsigned int HcalTopology::detId2denseIdHT(const DetId& id) const {
1074  HcalTrigTowerDetId tid(id);
1075  int zside = tid.zside();
1076  unsigned int ietaAbs = tid.ietaAbs();
1077  unsigned int iphi = tid.iphi();
1078  unsigned int ivers = tid.version();
1079 
1080  unsigned int index;
1081  if (ivers == 0) {
1082  if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
1083  else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
1084  if (zside == -1) index += kHThalf;
1085  } else {
1086  index = kHTSizePreLS1;
1087  if (zside == -1) index += ((kHTSizePhase1-kHTSizePreLS1)/2);
1088  index += (36 * (ietaAbs - 30) + ((iphi - 1)/2));
1089  }
1090 
1091  return index;
1092 }
1093 
1094 unsigned int HcalTopology::detId2denseIdCALIB(const DetId& id) const {
1095  HcalCalibDetId tid(id);
1096  int channel = tid.cboxChannel();
1097  int ieta = tid.ieta();
1098  int iphi = tid.iphi();
1099  int zside = tid.zside();
1100  unsigned int index=0xFFFFFFFFu;
1101 
1103 
1104  HcalSubdetector subDet = tid.hcalSubdet();
1105 
1106  if (subDet==HcalBarrel) {
1107  //std::cout<<"CALIB_HB: ";
1108  //dphi = 4 (18 phi values), 3 channel types (0,1,2), eta = -1 or 1
1109  //total of 18*3*2=108 channels
1110  index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
1111  } else if (subDet==HcalEndcap) {
1112  //std::cout<<"CALIB_HE: ";
1113  //dphi = 4 (18 phi values), 6 channel types (0,1,3,4,5,6), eta = -1 or 1
1114  //total of 18*6*2=216 channels
1115  if (channel>2) channel-=1;
1116  index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
1117  } else if (subDet==HcalForward) {
1118  //std::cout<<"CALIB_HF: ";
1119  //dphi = 18 (4 phi values), 3 channel types (0,1,8), eta = -1 or 1
1120  if (channel==8) channel = 2;
1121  //total channels 4*3*2=24
1122  index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
1123  } else if (subDet==HcalOuter) {
1124  //std::cout<<"CALIB_HO: ";
1125  //there are 5 special calib crosstalk channels, one in each ring
1126  if (channel==7) {
1127  index = (ieta+2) + 420;
1128  //for HOM/HOP dphi = 6 (12 phi values), 2 channel types (0,1), eta = -2,-1 or 1,2
1129  //for HO0/YB0 dphi = 12 (6 phi values), 2 channel types (0,1), eta = 0
1130  } else{
1131  if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
1132  else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
1133  else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
1134  }
1135  } else {
1136  edm::LogWarning("CaloTopology") << "HCAL Det Id not valid!";
1137  index = 0;
1138  }
1139 
1140  } else if (tid.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
1141  //std::cout<<"HX: ";
1142  //for YB0/HO0 phi is grouped in 6 groups of 6 with dphi=2 but the transitions are 1 or 3
1143  // in such a way that the %36 operation yeilds unique values for every iphi
1144  if (abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425; //ieta = 1 YB0/HO0;
1145  else index = (iphi-1) + (36*(zside+1)*2) + 425; //ieta = 0 for HO2M/HO1M ieta=2 for HO1P/HO2P;
1146  }
1147  //std::cout << " " << ieta << " " << zside << " " << iphi << " " << depth << " " << index << std::endl;
1148  return index;
1149 }
1150 
1151 
1152 unsigned int HcalTopology::detId2denseId(const DetId& id) const {
1153  unsigned int retval(0);
1154  if (topoVersion_==0) { // pre-LS1
1155  retval = detId2denseIdPreLS1(id);
1156  } else if (topoVersion_==10) {
1157  HcalDetId hid(id);
1158  if (hid.subdet()==HcalBarrel) {
1159  retval = (hid.depth()-1)+maxDepthHB_*(hid.iphi()-1);
1160  if (hid.ieta()>0) retval+=maxDepthHB_*IPHI_MAX*(hid.ieta()-firstHBRing());
1161  else retval+=maxDepthHB_*IPHI_MAX*(hid.ieta()+lastHBRing()+nEtaHB_);
1162  } else if (hid.subdet()==HcalEndcap) {
1163  retval = HBSize_;
1164  retval+= (hid.depth()-1)+maxDepthHE_*(hid.iphi()-1);
1165  if (hid.ieta()>0) retval+=maxDepthHE_*maxPhiHE_*(hid.ieta()-firstHERing());
1166  else retval+=maxDepthHE_*maxPhiHE_*(hid.ieta()+lastHERing()+nEtaHE_);
1167  } else if (hid.subdet()==HcalOuter) {
1168  retval = HBSize_+HESize_;
1169  if (hid.ieta()>0) retval+=(hid.iphi()-1)+IPHI_MAX*(hid.ieta()-1);
1170  else retval+=(hid.iphi()-1)+IPHI_MAX*(30+hid.ieta());
1171  } else if (hid.subdet()==HcalForward) {
1172  retval = HBSize_+HESize_+HOSize_;
1173  retval+= (hid.depth()-1)+maxDepthHF_*(hid.iphi()-1);
1174  if (hid.ieta()>0) retval+=maxDepthHF_*IPHI_MAX*(hid.ieta()-29);
1175  else retval+=maxDepthHF_*IPHI_MAX*((41+13)+hid.ieta());
1176  } else {
1177  return 0xFFFFFFFu;
1178  }
1179  }
1180 #ifdef EDM_ML_DEBUG
1181  std::cout << "DetId2Dense " << topoVersion_ << " ID " << std::hex
1182  << id.rawId() << std::dec << " | " << HcalDetId(id) << " : "
1183  << std::hex << retval << std::dec << std::endl;
1184 #endif
1185  return retval;
1186 }
1187 
1188 DetId HcalTopology::denseId2detId(unsigned int denseid) const {
1189 
1191  int ie ( 0 ) ;
1192  int ip ( 0 ) ;
1193  int dp ( 0 ) ;
1194  int in ( denseid ) ;
1195  int iz ( 1 ) ;
1196  if (topoVersion_==0) { //DL// pre-LS1
1197  if (denseid < kSizeForDenseIndexingPreLS1) {
1198  if ( in > 2*( kHBhalf + kHEhalf + kHOhalf ) - 1 ) { // HF
1199  sd = HcalForward ;
1200  in -= 2*( kHBhalf + kHEhalf + kHOhalf ) ;
1201  iz = ( in<kHFhalf ? 1 : -1 ) ;
1202  in %= kHFhalf ;
1203  ip = 4*( in/48 ) ;
1204  in %= 48 ;
1205  ip += 1 + ( in>21 ? 2 : 0 ) ;
1206  if( 3 == ip%4 ) in -= 22 ;
1207  ie = 29 + in/2 ;
1208  dp = 1 + in%2 ;
1209  } else if ( in > 2*( kHBhalf + kHEhalf ) - 1 ) { // HO
1210  sd = HcalOuter ;
1211  in -= 2*( kHBhalf + kHEhalf ) ;
1212  iz = ( in<kHOhalf ? 1 : -1 ) ;
1213  in %= kHOhalf ;
1214  dp = 4 ;
1215  ip = 1 + in/15 ;
1216  ie = 1 + ( in - 15*( ip - 1 ) ) ;
1217  } else if ( in > 2*kHBhalf - 1 ) { // Endcap
1218  sd = HcalEndcap ;
1219  in -= 2*kHBhalf ;
1220  iz = ( in<kHEhalf ? 1 : -1 ) ;
1221  in %= kHEhalf ;
1222  ip = 2*( in/36 ) ;
1223  in %= 36 ;
1224  ip += 1 + in/28 ;
1225  if( 0 == ip%2 ) in %= 28 ;
1226  ie = 15 + ( in<2 ? 1 + in : 2 +
1227  ( in<20 ? 1 + ( in - 2 )/2 : 9 +
1228  ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
1229  dp = ( in<1 ? 3 :
1230  ( in<2 ? 1 :
1231  ( in<20 ? 1 + ( in - 2 )%2 :
1232  ( in<26 ? 1 + ( in - 20 )%3 :
1233  ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
1234  } else { // barrel
1235  iz = ( in<kHBhalf ? 1 : -1 ) ;
1236  in %= kHBhalf ;
1237  ip = in/18 + 1 ;
1238  in %= 18 ;
1239  if ( in < 14 ) {
1240  dp = 1 ;
1241  ie = in + 1 ;
1242  } else {
1243  in %= 14 ;
1244  dp = 1 + in%2 ;
1245  ie = 15 + in/2 ;
1246  }
1247  }
1248  }
1249  } else if (topoVersion_==10) {
1250  if (denseid < ncells()) {
1251  if (denseid >= (HBSize_+HESize_+HOSize_)) {
1252  sd = HcalForward ;
1253  in -= (HBSize_+HESize_+HOSize_);
1254  dp = (in%maxDepthHF_) + 1;
1255  ip = (in - dp + 1)%(maxDepthHF_*IPHI_MAX);
1256  ip = (ip/maxDepthHF_) + 1;
1257  ie = (in - dp + 1 - maxDepthHF_*(ip -1))/(IPHI_MAX*maxDepthHF_);
1258  if (ie > 12) {ie = 54 -ie; iz = -1;}
1259  else {ie += 29; iz = 1;}
1260  } else if (denseid >= (HBSize_+HESize_)) {
1261  sd = HcalOuter ;
1262  in -= (HBSize_+HESize_);
1263  dp = 4;
1264  ip = (in%IPHI_MAX) + 1;
1265  ie = (in - ip + 1)/IPHI_MAX;
1266  if (ie > 14) {ie = 30 -ie; iz = -1;}
1267  else {ie += 1; iz = 1;}
1268  } else if (denseid >= (HBSize_)) {
1269  sd = HcalEndcap ;
1270  in -= (HBSize_);
1271  dp = (in%maxDepthHE_)+1;
1272  ip = (in - dp + 1)%(maxDepthHE_*maxPhiHE_);
1273  ip = (ip/maxDepthHE_) + 1;
1274  ie = (in - dp + 1 - maxDepthHE_*(ip-1))/(maxPhiHE_*maxDepthHE_);
1275  if (ie >= nEtaHE_) {ie = lastHERing()+nEtaHE_ - ie; iz = -1;}
1276  else {ie = firstHERing() + ie; iz = 1;}
1277  } else {
1278  sd = HcalBarrel ;
1279  dp = (in%maxDepthHB_)+1;
1280  ip = (in - dp + 1)%(maxDepthHB_*IPHI_MAX);
1281  ip = (ip/maxDepthHB_) + 1;
1282  ie = (in - dp + 1 - maxDepthHB_*(ip-1))/(IPHI_MAX*maxDepthHB_);
1283  if (ie >= nEtaHB_) {ie = lastHBRing()+nEtaHB_ - ie; iz = -1;}
1284  else {ie = firstHBRing() + ie; iz = 1;}
1285  }
1286  }
1287  }
1288  HcalDetId hid(sd, iz*int(ie), ip, dp);
1289 #ifdef EDM_ML_DEBUG
1290  std::cout << "Dens2Det " << topoVersion_ << " i/p " << std::hex << denseid
1291  << " : " << hid.rawId() << std::dec << " | " << hid << std::endl;
1292 #endif
1293  return hid;
1294 }
1295 
1296 unsigned int HcalTopology::ncells() const {
1297  return HBSize_+HESize_+HOSize_+HFSize_;
1298 }
1299 
1301  return topoVersion_;
1302 }
DetId denseId2detId(unsigned int) const override
return a linear packed id
int firstHFRing() const
Definition: HcalTopology.h:91
std::vector< int > getDepth(const int &det, const int &phi, const int &zside, const unsigned int &eta) const
std::vector< int > unitPhiHF
Definition: HcalTopology.h:218
int zside() const
get the z-side of the tower (1/-1)
void getDepthSegmentation(const unsigned ring, std::vector< int > &readoutDepths, const bool flag=false) const
int topoVersion() const override
return a version which identifies the given topology
int decIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
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)
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHB_
Definition: HcalTopology.h:198
int phiBin(HcalSubdetector subdet, int etaRing, double phi) const
std::vector< int > unitPhi
Definition: HcalTopology.h:218
bool valid(const DetId &id) const override
CalibDetType calibFlavor() const
get the flavor of this calibration detid
std::vector< DetId > up(const DetId &id) const override
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
int maxDepthHE() const
Definition: HcalTopology.h:140
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.cc:114
bool validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const
unsigned int detId2denseIdHT(const DetId &id) const
return a linear packed id from HT
unsigned int detId2denseIdHF(const DetId &id) const
return a linear packed id from HF
void exclude(const HcalDetId &id)
const std::vector< double > & getEtaTableHF() const
HcalTopologyMode::TriggerMode triggerMode_
Definition: HcalTopology.h:191
int nPhiBins(int etaRing) const
how many phi segments in this ring
int firstHBRing() const
Definition: HcalTopology.h:87
int incIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
bool decrementDepth(HcalDetId &id) const
unsigned int HESize_
Definition: HcalTopology.h:209
int lastHBRing() const
Definition: HcalTopology.h:88
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
unsigned int HTSize_
Definition: HcalTopology.h:212
bool decIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool validHcal(const HcalDetId &id) const
#define nullptr
std::vector< HcalDDDRecConstants::HcalEtaBin > etaBinsHE_
Definition: HcalTopology.h:198
int ieta() const
get the rbx name (if relevant)
const std::vector< double > & getPhiOffs() const
std::pair< int, int > getEtaRange(const int &i) const
HcalTopologyMode::Mode mode() const
Definition: HcalTopology.h:31
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
bool isExcluded(const HcalDetId &id) const
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
std::vector< HcalEtaBin > getEtaBins(const int &itype) const
int depth() const
get the tower depth
Definition: HcalDetId.cc:129
std::pair< int, int > segmentBoundaries(const unsigned ring, const unsigned depth, const bool flag=false) const
unsigned int HFSize_
Definition: HcalTopology.h:211
bool incIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool isPlan1MergedId(const HcalDetId &id) const
bool validRaw(const HcalDetId &id) const
std::vector< DetId > south(const DetId &id) const override
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
int maxDepth(HcalSubdetector subdet) const
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
HcalTopologyMode::Mode mode_
Definition: HcalTopology.h:190
HcalTopology(const HcalDDDRecConstants *hcons, const bool mergePosition=false)
Definition: HcalTopology.cc:17
int etaRing(HcalSubdetector subdet, double eta) const
eta and phi index from eta, phi values
int firstHETripleDepthRing() const
Definition: HcalTopology.h:99
int ieta() const
get the cell ieta
Definition: HcalDetId.h:56
int lastHFRing() const
Definition: HcalTopology.h:92
int getDepthEta16(const int &det, const int &iphi, const int &zside) const
HcalSubdetector
Definition: HcalAssistant.h:31
unsigned int HBSize_
Definition: HcalTopology.h:208
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int getDepthEta29(const int &iphi, const int &zside, const int &type) const
std::vector< double > etaTableHF
Definition: HcalTopology.h:216
T min(T a, T b)
Definition: MathUtil.h:58
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:96
SegmentationMap depthSegmentation_
Definition: HcalTopology.h:224
SegmentationMap depthSegmentationOne_
Definition: HcalTopology.h:225
unsigned int HOSize_
Definition: HcalTopology.h:210
std::vector< double > etaTable
Definition: HcalTopology.h:216
bool oldFormat() const
Definition: HcalDetId.h:50
ii
Definition: cuy.py:588
#define M_PI
int k[5][pyjets_maxn]
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.cc:119
int iphi() const
get the low-edge iphi (if relevant)
bool validDetIdPreLS1(const HcalDetId &id) const
int firstHEQuadPhiRing_
Definition: HcalTopology.h:201
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:124
Definition: DetId.h:18
bool incrementDepth(HcalDetId &id) const
bool mergePosition_
Definition: HcalTopology.h:186
int zside() const
get the sign of ieta (+/-1)
std::vector< double > phioff
Definition: HcalTopology.h:217
const std::vector< double > & getPhiTable() const
int getNoff(const int &i) const
auto dp
Definition: deltaR.h:22
double sd
int version() const
get the version code for the trigger tower
int getMaxDepth(const int &type) const
int firstHERing() const
Definition: HcalTopology.h:89
const std::vector< double > & getEtaTable() const
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:98
int maxDepthHB() const
Definition: HcalTopology.h:139
std::vector< double > dPhiTable
Definition: HcalTopology.h:216
std::vector< DetId > west(const DetId &id) const override
int cboxChannel() const
get the calibration box channel (if relevant)
std::vector< DetId > north(const DetId &id) const override
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
TString units(TString variable, Char_t axis)
const std::vector< double > & getPhiTableHF() const
std::vector< DetId > down(const DetId &id) const override
int firstHETripleDepthRing_
Definition: HcalTopology.h:202
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
std::vector< HcalDetId > exclusionList_
Definition: HcalTopology.h:187
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
bool isPlan1ToBeMergedId(const HcalDetId &id) const
int firstHEQuadPhiRing() const
Definition: HcalTopology.h:97
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
void changeForm()
Definition: HcalDetId.cc:159
void setDepthSegmentation(const unsigned ring, const std::vector< int > &readoutDepths, const bool flag)
int maxHFDepth(int ieta, int iphi) const
int incAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
unsigned int detId2denseIdCALIB(const DetId &id) const
return a linear packed id from CALIB
int lastHORing() const
Definition: HcalTopology.h:94
int ietaAbs() const
get the absolute value of the tower ieta
int iphi() const
get the tower iphi
std::vector< DetId > east(const DetId &id) const override
double etaMax(HcalSubdetector subdet) const
int lastHERing() const
Definition: HcalTopology.h:90
int firstHEDoublePhiRing_
Definition: HcalTopology.h:201
const HcalDDDRecConstants * hcons_
Definition: HcalTopology.h:185
static const int IPHI_MAX
Definition: HcalTopology.cc:13
int firstHFQuadPhiRing_
Definition: HcalTopology.h:201
int getNPhi(const int &type) const
bool validHT(const HcalTrigTowerDetId &id) const