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