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