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