CMS 3D CMS Logo

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