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