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>
10 
11 static const int IPHI_MAX=72;
12 
14  excludeHB_(false),
15  excludeHE_(false),
16  excludeHO_(false),
17  excludeHF_(false),
18  mode_(mode),
19  triggerMode_(tmode),
20  firstHBRing_(1),
21  lastHBRing_(16),
22  firstHERing_(16),
23  lastHERing_(29),
24  firstHFRing_(29),
25  lastHFRing_(41),
26  firstHORing_(1),
27  lastHORing_(15),
28  firstHEDoublePhiRing_((mode==HcalTopologyMode::H2 || mode==HcalTopologyMode::H2HE)?(22):(21)),
29  firstHFQuadPhiRing_(40),
30  firstHETripleDepthRing_((mode==HcalTopologyMode::H2 || mode==HcalTopologyMode::H2HE)?(24):(27)),
31  singlePhiBins_(72),
32  doublePhiBins_(36),
33  maxDepthHB_(maxDepthHB),
34  maxDepthHE_(maxDepthHE),
35  HBSize_(kHBSizePreLS1),
36  HESize_(kHESizePreLS1),
37  HOSize_(kHOSizePreLS1),
38  HFSize_(kHFSizePreLS1),
39  numberOfShapes_(( mode==HcalTopologyMode::SLHC ) ? 500 : 87 ) {
40 
42  topoVersion_=0; //DL
43  HBSize_= kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
44  HESize_= kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
45  HOSize_= kHOSizePreLS1; // ieta * iphi * 2
46  HFSize_= kHFSizePreLS1; // phi * eta * depth * pm
47  } else if (mode_==HcalTopologyMode::SLHC) { // need to know more eventually
48  HBSize_= maxDepthHB*16*72*2;
49  HESize_= maxDepthHE*(29-16+1)*72*2;
50  HOSize_= 15*72*2; // ieta * iphi * 2
51  HFSize_= 72*13*2*2; // phi * eta * depth * pm
52 
53  topoVersion_=10;
54  }
55 
56 }
57 
58 bool HcalTopology::valid(const DetId& id) const {
59  assert(id.det()==DetId::Hcal);
60  return validHcal(id);
61 }
62 
63 bool HcalTopology::validHcal(const HcalDetId& id) const {
64  // check the raw rules
65  bool ok=validRaw(id);
66 
67  ok=ok && !isExcluded(id);
68 
69  return ok;
70 }
71 
72 bool HcalTopology::isExcluded(const HcalDetId& id) const {
73  bool exed=false;
74  // first, check the full detector exclusions... (fast)
75  switch (id.subdet()) {
76  case(HcalBarrel): exed=excludeHB_; break;
77  case(HcalEndcap): exed=excludeHE_; break;
78  case(HcalOuter): exed=excludeHO_; break;
79  case(HcalForward): exed=excludeHF_; break;
80  default: exed=false;
81  }
82  // next, check the list (slower)
83  if (!exed && !exclusionList_.empty()) {
84  std::vector<HcalDetId>::const_iterator i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
85  if (i!=exclusionList_.end() && *i==id) exed=true;
86  }
87  return exed;
88 }
89 
91  std::vector<HcalDetId>::iterator i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
92  if (i==exclusionList_.end() || *i!=id) {
93  exclusionList_.insert(i,id);
94  }
95 }
96 
98  switch (subdet) {
99  case(HcalBarrel): excludeHB_=true; break;
100  case(HcalEndcap): excludeHE_=true; break;
101  case(HcalOuter): excludeHO_=true; break;
102  case(HcalForward): excludeHF_=true; break;
103  default: break;
104  }
105 }
106 
107 std::vector<DetId> HcalTopology::east(const DetId& id) const {
108  std::vector<DetId> vNeighborsDetId;
109  HcalDetId neighbors[2];
110  for (int i=0;i<decIEta(HcalDetId(id),neighbors);i++)
111  vNeighborsDetId.push_back(DetId(neighbors[i].rawId()));
112  return vNeighborsDetId;
113 }
114 
115 std::vector<DetId> HcalTopology::west(const DetId& id) const {
116  std::vector<DetId> vNeighborsDetId;
117  HcalDetId neighbors[2];
118  for (int i=0;i<incIEta(HcalDetId(id),neighbors);i++)
119  vNeighborsDetId.push_back(DetId(neighbors[i].rawId()));
120  return vNeighborsDetId;
121 }
122 
123 std::vector<DetId> HcalTopology::north(const DetId& id) const {
124  std::vector<DetId> vNeighborsDetId;
125  HcalDetId neighbor;
126  if (incIPhi(HcalDetId(id),neighbor))
127  vNeighborsDetId.push_back(DetId(neighbor.rawId()));
128  return vNeighborsDetId;
129 }
130 
131 std::vector<DetId> HcalTopology::south(const DetId& id) const {
132  std::vector<DetId> vNeighborsDetId;
133  HcalDetId neighbor;
134  if (decIPhi(HcalDetId(id),neighbor))
135  vNeighborsDetId.push_back(DetId(neighbor.rawId()));
136  return vNeighborsDetId;
137 }
138 
139 std::vector<DetId> HcalTopology::up(const DetId& id) const {
140  HcalDetId neighbor = id;
141  std::vector<DetId> vNeighborsDetId;
142  if(incrementDepth(neighbor)) {
143  vNeighborsDetId.push_back(neighbor);
144  }
145  return vNeighborsDetId;
146 }
147 
148 std::vector<DetId> HcalTopology::down(const DetId& id) const {
149  HcalDetId neighbor = id;
150  std::vector<DetId> vNeighborsDetId;
151  if (decrementDepth(neighbor)) {
152  vNeighborsDetId.push_back(neighbor);
153  }
154  return vNeighborsDetId;
155 }
156 
157 int HcalTopology::exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi1, int iphi2, int depth1, int depth2) {
158 
159  bool exed=false;
160  // first, check the full detector exclusions... (fast)
161  switch (subdet) {
162  case(HcalBarrel): exed=excludeHB_; break;
163  case(HcalEndcap): exed=excludeHE_; break;
164  case(HcalOuter): exed=excludeHO_; break;
165  case(HcalForward): exed=excludeHF_; break;
166  default: exed=false;
167  }
168  if (exed) return 0; // if the whole detector is excluded...
169 
170  int ieta_l=std::min(ieta1,ieta2);
171  int ieta_h=std::max(ieta1,ieta2);
172  int iphi_l=std::min(iphi1,iphi2);
173  int iphi_h=std::max(iphi1,iphi2);
174  int depth_l=std::min(depth1,depth2);
175  int depth_h=std::max(depth1,depth2);
176 
177  int n=0;
178  for (int ieta=ieta_l; ieta<=ieta_h; ieta++)
179  for (int iphi=iphi_l; iphi<=iphi_h; iphi++)
180  for (int depth=depth_l; depth<=depth_h; depth++) {
181  HcalDetId id(subdet,ieta,iphi,depth);
182  if (validRaw(id)) { // use 'validRaw' to include check validity in "uncut" detector
183  exclude(id);
184  n++;
185  }
186  }
187  return n;
188 }
189 
217  const HcalSubdetector sd (id.subdet());
218  const int ie (id.ietaAbs());
219  const int ip (id.iphi());
220  const int dp (id.depth());
221 
222  return ( ( ip >= 1 ) &&
223  ( ip <= IPHI_MAX ) &&
224  ( dp >= 1 ) &&
225  ( ie >= 1 ) &&
226  ( ( ( sd == HcalBarrel ) &&
227  ( ( ( ie <= 14 ) &&
228  ( dp == 1 ) ) ||
229  ( ( ( ie == 15 ) || ( ie == 16 ) ) &&
230  ( dp <= 2 ) ) ) ) ||
231  ( ( sd == HcalEndcap ) &&
232  ( ( ( ie == firstHERing() ) &&
233  ( dp == 3 ) ) ||
234  ( ( ie == 17 ) &&
235  ( dp == 1 ) ) ||
236  ( ( ie >= 18 ) &&
237  ( ie <= 20 ) &&
238  ( dp <= 2 ) ) ||
239  ( ( ie >= 21 ) &&
240  ( ie <= 26 ) &&
241  ( dp <= 2 ) &&
242  ( ip%2 == 1 ) ) ||
243  ( ( ie >= 27 ) &&
244  ( ie <= 28 ) &&
245  ( dp <= 3 ) &&
246  ( ip%2 == 1 ) ) ||
247  ( ( ie == 29 ) &&
248  ( dp <= 2 ) &&
249  ( ip%2 == 1 ) ) ) ) ||
250  ( ( sd == HcalOuter ) &&
251  ( ie <= 15 ) &&
252  ( dp == 4 ) ) ||
253  ( ( sd == HcalForward ) &&
254  ( dp <= 2 ) &&
255  ( ( ( ie >= firstHFRing() ) &&
256  ( ie < firstHFQuadPhiRing() ) &&
257  ( ip%2 == 1 ) ) ||
258  ( ( ie >= firstHFQuadPhiRing() ) &&
259  ( ie <= lastHFRing() ) &&
260  ( ip%4 == 3 ) ) ) ) ) ) ;
261 }
262 
264 bool HcalTopology::validRaw(const HcalDetId& id) const {
265  bool ok=true;
266  int ieta=id.ieta();
267  int aieta=id.ietaAbs();
268  int depth=id.depth();
269  int iphi=id.iphi();
270  if ((ieta==0 || iphi<=0 || iphi>IPHI_MAX) || aieta>lastHFRing()) return false; // outer limits
271 
272  if (ok) {
273  HcalSubdetector subdet=id.subdet();
274  if (subdet==HcalBarrel) {
276  if ((aieta>lastHBRing() || depth>maxDepthHB_ || (aieta==lastHBRing() && depth > 2))) ok=false;
277  } else {
278  if (aieta>lastHBRing() || depth>2 || (aieta<=14 && depth>1)) ok=false;
279  }
280  } else if (subdet==HcalEndcap) {
282  if (depth>maxDepthHE_ || aieta<firstHERing() || aieta>lastHERing() || (aieta==firstHERing() && depth<3) || (aieta>=firstHEDoublePhiRing() && (iphi%2)==0)) ok=false;
283  } else {
284  if (depth>3 || aieta<firstHERing() || aieta>lastHERing() || (aieta==firstHERing() && depth!=3) || (aieta==17 && depth!=1 && mode_!=HcalTopologyMode::H2) || // special case at H2
285  (((aieta>=17 && aieta<firstHETripleDepthRing()) || aieta==lastHERing()) && depth>2) ||
286  (aieta>=firstHEDoublePhiRing() && (iphi%2)==0)) ok=false;
287  }
288  } else if (subdet==HcalOuter) {
289  if (aieta>lastHORing() || iphi>IPHI_MAX || depth!=4) ok=false;
290  } else if (subdet==HcalForward) {
291  if (aieta<firstHFRing() || aieta>lastHFRing() || ((iphi%2)==0) || (depth>2) || (aieta>=firstHFQuadPhiRing() && ((iphi+1)%4)!=0)) ok=false;
292  } else {
293  ok=false;
294  }
295  }
296  return ok;
297 }
298 
299 
300 bool HcalTopology::incIPhi(const HcalDetId& id, HcalDetId &neighbor) const {
301  bool ok=valid(id);
302  if (ok) {
303  switch (id.subdet()) {
304  case (HcalBarrel):
305  case (HcalOuter):
306  if (id.iphi()==IPHI_MAX) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
307  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+1,id.depth());
308  break;
309  case (HcalEndcap):
310  if (id.ietaAbs()>=firstHEDoublePhiRing()) {
311  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
312  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+2,id.depth());
313  } else {
314  if (id.iphi()==IPHI_MAX) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
315  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+1,id.depth());
316  }
317  break;
318  case (HcalForward):
319  if (id.ietaAbs()>=firstHFQuadPhiRing()) {
320  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),3,id.depth());
321  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+4,id.depth());
322  } else {
323  if (id.iphi()==IPHI_MAX-1) neighbor=HcalDetId(id.subdet(),id.ieta(),1,id.depth());
324  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()+2,id.depth());
325  }
326  break;
327  default: ok=false;
328  }
329  }
330  return ok;
331 }
332 
334 bool HcalTopology::decIPhi(const HcalDetId& id, HcalDetId &neighbor) const {
335  bool ok=valid(id);
336  if (ok) {
337  switch (id.subdet()) {
338  case (HcalBarrel):
339  case (HcalOuter):
340  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX,id.depth());
341  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-1,id.depth());
342  break;
343  case (HcalEndcap):
344  if (id.ietaAbs()>=firstHEDoublePhiRing()) {
345  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
346  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-2,id.depth());
347  } else {
348  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX,id.depth());
349  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-1,id.depth());
350  }
351  break;
352  case (HcalForward):
353  if (id.ietaAbs()>=firstHFQuadPhiRing()) {
354  if (id.iphi()==3) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
355  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-4,id.depth());
356  } else {
357  if (id.iphi()==1) neighbor=HcalDetId(id.subdet(),id.ieta(),IPHI_MAX-1,id.depth());
358  else neighbor=HcalDetId(id.subdet(),id.ieta(),id.iphi()-2,id.depth());
359  }
360  break;
361  default: ok=false;
362  }
363  }
364  return ok;
365 }
366 
367 int HcalTopology::incIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
368  if (id.zside()==1) return incAIEta(id,neighbors);
369  else return decAIEta(id,neighbors);
370 }
371 
372 int HcalTopology::decIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
373  if (id.zside()==1) return decAIEta(id,neighbors);
374  else return incAIEta(id,neighbors);
375 }
376 
378 int HcalTopology::incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
379  int n=1;
380  int aieta=id.ietaAbs();
381 
382  if (aieta==firstHEDoublePhiRing()-1 && (id.iphi()%2)==0)
383  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),id.iphi()-1,id.depth());
384  else if (aieta==firstHFQuadPhiRing()-1 && ((id.iphi()+1)%4)!=0)
385  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),((id.iphi()==1)?(71):(id.iphi()-2)),id.depth());
386  else if (aieta==lastHBRing())
387  neighbors[0]=HcalDetId(HcalEndcap,(aieta+1)*id.zside(),id.iphi(),1);
388  else if (aieta==lastHERing())
389  neighbors[0]=HcalDetId(HcalForward,(aieta+1)*id.zside(),id.iphi(),1);
390  else
391  neighbors[0]=HcalDetId(id.subdet(),(aieta+1)*id.zside(),id.iphi(),id.depth());
392 
393  if (!valid(neighbors[0])) n=0;
394  return n;
395 }
396 
398 int HcalTopology::decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
399  int n=1;
400  int aieta=id.ietaAbs();
401 
402  if (aieta==firstHEDoublePhiRing()) {
403  n=2;
404  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
405  neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi()+1,id.depth());
406  } else if (aieta==firstHFQuadPhiRing()) {
407  n=2;
408  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
409  if (id.iphi()==IPHI_MAX-1) neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),1,id.depth());
410  else neighbors[1]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi()+2,id.depth());
411  } else if (aieta==1) {
412  neighbors[0]=HcalDetId(id.subdet(),-aieta*id.zside(),id.iphi(),id.depth());
413  } else if (aieta==lastHBRing()+1) {
414  neighbors[0]=HcalDetId(HcalBarrel,(aieta-1)*id.zside(),id.iphi(),id.depth());
415  } else if (aieta==lastHERing()+1) {
416  neighbors[0]=HcalDetId(HcalEndcap,(aieta-1)*id.zside(),id.iphi(),id.depth());
417  } else
418  neighbors[0]=HcalDetId(id.subdet(),(aieta-1)*id.zside(),id.iphi(),id.depth());
419 
420  if (!valid(neighbors[0]) && n==2) {
421  if (!valid(neighbors[1])) n=0;
422  else {
423  n=1;
424  neighbors[0]=neighbors[1];
425  }
426  }
427  if (n==2 && !valid(neighbors[1])) n=1;
428  if (n==1 && !valid(neighbors[0])) n=0;
429 
430  return n;
431 }
432 
433 
435  int & nDepthBins, int & startingBin) const {
436 
437  if(subdet == HcalBarrel) {
439  startingBin = 1;
440  if (etaRing==lastHBRing()) {
441  nDepthBins = 2;
442  } else {
443  nDepthBins = maxDepthHB_;
444  }
445  } else {
446  if (etaRing<=14) {
447  nDepthBins = 1;
448  startingBin = 1;
449  } else {
450  nDepthBins = 2;
451  startingBin = 1;
452  }
453  }
454  } else if(subdet == HcalEndcap) {
456  if (etaRing==firstHERing()) {
457  nDepthBins = maxDepthHE_ - 2;
458  startingBin = 3;
459  } else {
460  nDepthBins = maxDepthHE_;
461  startingBin = 1;
462  }
463  } else {
464  if (etaRing==firstHERing()) {
465  nDepthBins = 1;
466  startingBin = 3;
467  } else if (etaRing==17) {
468  nDepthBins = 1;
469  startingBin = 1;
470  } else if (etaRing==lastHERing()) {
471  nDepthBins = 2;
472  startingBin = 1;
473  } else {
474  nDepthBins = (etaRing >= firstHETripleDepthRing()) ? 3 : 2;
475  startingBin = 1;
476  }
477  }
478  } else if(subdet == HcalForward) {
479  nDepthBins = 2;
480  startingBin = 1;
481  } else if(subdet == HcalOuter) {
482  nDepthBins = 1;
483  startingBin = 4;
484  } else {
485  std::cerr << "Bad HCAL subdetector " << subdet << std::endl;
486  }
487 }
488 
489 
491 {
492  HcalSubdetector subdet = detId.subdet();
493  int ieta = detId.ieta();
494  int etaRing = detId.ietaAbs();
495  int depth = detId.depth();
496  int nDepthBins, startingBin;
497  depthBinInformation(subdet, etaRing, nDepthBins, startingBin);
498 
499  // see if the new depth bin exists
500  ++depth;
501  if(depth > nDepthBins) {
502  // handle on a case-by-case basis
503  if(subdet == HcalBarrel && etaRing < lastHORing()) {
504  // HO
505  subdet = HcalOuter;
506  depth = 4;
507  } else if(subdet == HcalBarrel && etaRing == lastHBRing()) {
508  // overlap
509  subdet = HcalEndcap;
510  } else if(subdet == HcalEndcap && etaRing == lastHERing()-1) {
511  // guard ring HF29 is behind HE 28
512  subdet = HcalForward;
513  (ieta > 0) ? ++ieta : --ieta;
514  depth = 1;
515  } else if(subdet == HcalEndcap && etaRing == lastHERing()) {
516  // split cells go to bigger granularity. Ring 29 -> 28
517  (ieta > 0) ? --ieta : ++ieta;
518  } else {
519  // no more chances
520  detId = HcalDetId();
521  return false;
522  }
523  }
524  detId = HcalDetId(subdet, ieta, detId.iphi(), depth);
525  return validRaw(detId);
526 }
527 
529  HcalSubdetector subdet = detId.subdet();
530  int ieta = detId.ieta();
531  int etaRing = detId.ietaAbs();
532  int depth = detId.depth();
533  int nDepthBins, startingBin;
534  depthBinInformation(subdet, etaRing, nDepthBins, startingBin);
535 
536  // see if the new depth bin exists
537  --depth;
538  if (subdet == HcalOuter) {
539  subdet = HcalBarrel;
541  depth = maxDepthHB_;
542  } else {
543  depth = (etaRing<=14) ? 1 : 2;
544  }
545  } else if (subdet == HcalEndcap && etaRing == firstHERing()) {
546  subdet = HcalBarrel;
547  depth = 2;
548  } else if (subdet == HcalEndcap && etaRing == lastHERing() && depth == 2 &&
550  (ieta > 0) ? --ieta : ++ieta;
551  } else if (depth <= 0) {
552  if (subdet == HcalForward && etaRing == firstHFRing()) {
553  // overlap
554  subdet = HcalEndcap;
555  etaRing= lastHERing()-1;
556  ieta = (ieta > 0) ? etaRing : -etaRing;
557  } else {
558  // no more chances
559  detId = HcalDetId();
560  return false;
561  }
562  }
563  detId = HcalDetId(subdet, ieta, detId.iphi(), depth);
564  return validRaw(detId);
565 }
566 
567 int HcalTopology::nPhiBins(int etaRing) const {
568  int lastPhiBin=singlePhiBins_;
569  if (etaRing>= firstHFQuadPhiRing()) lastPhiBin=doublePhiBins_/2;
570  else if (etaRing>= firstHEDoublePhiRing()) lastPhiBin=doublePhiBins_;
571  return lastPhiBin;
572 }
573 
574 void HcalTopology::getDepthSegmentation(unsigned ring, std::vector<int> & readoutDepths) const
575 {
576  // if it doesn't exist, return the first entry with a lower index. So if we only
577  // have entries for 1 and 17, any input from 1-16 should return the entry for ring 1
578  SegmentationMap::const_iterator pos = depthSegmentation_.upper_bound(ring);
579  if(pos == depthSegmentation_.begin()) {
580  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
581  }
582  --pos;
583  // pos now refers to the last element with key <= ring.
584  readoutDepths = pos->second;
585 }
586 
587 void HcalTopology::setDepthSegmentation(unsigned ring, const std::vector<int> & readoutDepths)
588 {
589  depthSegmentation_[ring] = readoutDepths;
590 }
591 
592 std::pair<int, int> HcalTopology::segmentBoundaries(unsigned ring, unsigned depth) const {
593  std::vector<int> readoutDepths;
594  getDepthSegmentation(ring, readoutDepths);
595  int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
596  int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
597  return std::pair<int, int>(d1, d2);
598 }
599 
600 unsigned int HcalTopology::detId2denseIdPreLS1 (const DetId& id) const {
601 
602  HcalDetId hid(id);
603  const HcalSubdetector sd (hid.subdet() ) ;
604  const int ip (hid.iphi() ) ;
605  const int ie (hid.ietaAbs() ) ;
606  const int dp (hid.depth() ) ;
607  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
608  unsigned int retval = ( ( sd == HcalBarrel ) ?
609  ( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf :
610  ( ( sd == HcalEndcap ) ?
611  2*kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
612  ( ( ie==16 || ie==17 ) ? ie - 16 :
613  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
614  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
615  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
616  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf :
617  ( ( sd == HcalOuter ) ?
618  2*kHBhalf + 2*kHEhalf + ( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf :
619  ( ( sd == HcalForward ) ?
620  2*kHBhalf + 2*kHEhalf + 2*kHOhalf +
621  ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
622  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
623  return retval;
624 }
625 
626 
627 unsigned int HcalTopology::detId2denseIdHB(const DetId& id) const {
628  HcalDetId hid(id);
629  const int ip (hid.iphi() ) ;
630  const int ie (hid.ietaAbs() ) ;
631  const int dp (hid.depth() ) ;
632  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
633  unsigned int retval = 0xFFFFFFFFu;
634  if (topoVersion_==0) {
635  retval=( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf;
636  } else if (topoVersion_==10) {
637  retval=dp-1 + maxDepthHB_*(ip-1)+maxDepthHB_*72*(hid.ieta()-1+33*zn);
638  }
639  return retval;
640 }
641 
642 unsigned int HcalTopology::detId2denseIdHE(const DetId& id) const {
643  HcalDetId hid(id);
644  const int ip (hid.iphi() ) ;
645  const int ie (hid.ietaAbs() ) ;
646  const int dp (hid.depth() ) ;
647  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
648  unsigned int retval = 0xFFFFFFFFu;
649  if (topoVersion_==0) {
650  retval=( ip - 1 )*8 + ( ip/2 )*20 +
651  ( ( ie==16 || ie==17 ) ? ie - 16 :
652  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
653  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
654  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
655  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf;
656  } else if (topoVersion_==10) {
657  retval=(dp-1)+maxDepthHE_*(ip-1)+maxDepthHE_*72*(hid.ieta()-16+zn*(14+29+16));
658  }
659  return retval;
660 }
661 
662 unsigned int HcalTopology::detId2denseIdHO(const DetId& id) const {
663  HcalDetId hid(id);
664  const int ip (hid.iphi() ) ;
665  const int ie (hid.ietaAbs() ) ;
666  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
667 
668  unsigned int retval = 0xFFFFFFFFu;
669  if (topoVersion_==0) {
670  retval=( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf;
671  } else if (topoVersion_==10) {
672  retval=( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf;
673  }
674  return retval;
675 }
676 
677 unsigned int HcalTopology::detId2denseIdHF(const DetId& id) const {
678  HcalDetId hid(id);
679  const int ip (hid.iphi() ) ;
680  const int ie (hid.ietaAbs() ) ;
681  const int dp (hid.depth() ) ;
682  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
683 
684  unsigned int retval = 0xFFFFFFFFu;
685  if (topoVersion_==0) {
686  retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
687  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf;
688  } else if (topoVersion_==10) {
689  retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
690  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf;
691  }
692  return retval;
693 }
694 
695 unsigned int HcalTopology::detId2denseIdHT(const DetId& id) const {
696  HcalTrigTowerDetId tid(id);
697  int zside = tid.zside();
698  unsigned int ietaAbs = tid.ietaAbs();
699  unsigned int iphi = tid.iphi();
700 
701  unsigned int index;
702  if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
703  else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
704 
705  if (zside == -1) index += kHThalf;
706 
707  return index;
708 }
709 
710 unsigned int HcalTopology::detId2denseIdCALIB(const DetId& id) const {
711  HcalCalibDetId tid(id);
712  int channel = tid.cboxChannel();
713  int ieta = tid.ieta();
714  int iphi = tid.iphi();
715  int zside = tid.zside();
716  unsigned int index=0xFFFFFFFFu;
717 
719 
720  HcalSubdetector subDet = tid.hcalSubdet();
721 
722  if (subDet==HcalBarrel) {
723  //std::cout<<"CALIB_HB: ";
724  //dphi = 4 (18 phi values), 3 channel types (0,1,2), eta = -1 or 1
725  //total of 18*3*2=108 channels
726  index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
727  } else if (subDet==HcalEndcap) {
728  //std::cout<<"CALIB_HE: ";
729  //dphi = 4 (18 phi values), 6 channel types (0,1,3,4,5,6), eta = -1 or 1
730  //total of 18*6*2=216 channels
731  if (channel>2) channel-=1;
732  index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
733  } else if (subDet==HcalForward) {
734  //std::cout<<"CALIB_HF: ";
735  //dphi = 18 (4 phi values), 3 channel types (0,1,8), eta = -1 or 1
736  if (channel==8) channel = 2;
737  //total channels 4*3*2=24
738  index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
739  } else if (subDet==HcalOuter) {
740  //std::cout<<"CALIB_HO: ";
741  //there are 5 special calib crosstalk channels, one in each ring
742  if (channel==7) {
743  channel = 2;
744  index = (ieta+2) + 420;
745  //for HOM/HOP dphi = 6 (12 phi values), 2 channel types (0,1), eta = -2,-1 or 1,2
746  //for HO0/YB0 dphi = 12 (6 phi values), 2 channel types (0,1), eta = 0
747  } else{
748  if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
749  else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
750  else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
751  }
752  } else {
753  std::cout << "HCAL Det Id not valid!" << std::endl;
754  index = 0;
755  }
756 
757  } else if (tid.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
758  //std::cout<<"HX: ";
759  //for YB0/HO0 phi is grouped in 6 groups of 6 with dphi=2 but the transitions are 1 or 3
760  // in such a way that the %36 operation yeilds unique values for every iphi
761  if (abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425; //ieta = 1 YB0/HO0;
762  else index = (iphi-1) + (36*(zside+1)*2) + 425; //ieta = 0 for HO2M/HO1M ieta=2 for HO1P/HO2P;
763  }
764  //std::cout << " " << ieta << " " << zside << " " << iphi << " " << depth << " " << index << std::endl;
765  return index;
766 }
767 
768 
769 unsigned int HcalTopology::detId2denseId(const DetId& id) const {
770  unsigned int retval(0);
771  if (topoVersion_==0) { // pre-LS1
772  retval = detId2denseIdPreLS1(id);
773  } else if (topoVersion_==10) {
774  HcalDetId hid(id);
775  if (hid.subdet()==HcalBarrel) {
776  retval=(hid.depth()-1)+maxDepthHB_*(hid.iphi()-1);
777  if (hid.ieta()>0) {
778  retval+=maxDepthHB_*72*(hid.ieta()-1);
779  } else {
780  retval+=maxDepthHB_*72*(32+hid.ieta());
781  }
782  } else if (hid.subdet()==HcalEndcap) {
783  retval=HBSize_;
784  retval+=(hid.depth()-1)+maxDepthHE_*(hid.iphi()-1);
785  if (hid.ieta()>0) {
786  retval+=maxDepthHE_*72*(hid.ieta()-16);
787  } else {
788  retval+=maxDepthHE_*72*((14+29)+hid.ieta());
789  }
790  } else if (hid.subdet()==HcalOuter) {
791  retval=HBSize_+HESize_;
792  if (hid.ieta()>0) retval+=(hid.iphi()-1)+72*(hid.ieta()-1);
793  else retval+=(hid.iphi()-1)+72*(30+hid.ieta());
794  } else if (hid.subdet()==HcalForward) {
795  retval=HBSize_+HESize_+HOSize_;
796  retval+=hid.depth()-1+2*(hid.iphi()-1);
797  if (hid.ieta()>0) retval+=2*72*(hid.ieta()-29);
798  else retval+=2*72*((41+13)+hid.ieta());
799  } else {
800  return 0xFFFFFFFu;
801  }
802  }
803  return retval;
804 }
805 
806 DetId HcalTopology::denseId2detId(unsigned int denseid) const {
807 
809  int ie ( 0 ) ;
810  int ip ( 0 ) ;
811  int dp ( 0 ) ;
812  int in ( denseid ) ;
813  int iz ( 1 ) ;
814  if (topoVersion_==0) { //DL// pre-LS1
815  if (denseid < kSizeForDenseIndexingPreLS1) {
816  if ( in > 2*( kHBhalf + kHEhalf + kHOhalf ) - 1 ) { // HF
817  sd = HcalForward ;
818  in -= 2*( kHBhalf + kHEhalf + kHOhalf ) ;
819  iz = ( in<kHFhalf ? 1 : -1 ) ;
820  in %= kHFhalf ;
821  ip = 4*( in/48 ) ;
822  in %= 48 ;
823  ip += 1 + ( in>21 ? 2 : 0 ) ;
824  if( 3 == ip%4 ) in -= 22 ;
825  ie = 29 + in/2 ;
826  dp = 1 + in%2 ;
827  } else if ( in > 2*( kHBhalf + kHEhalf ) - 1 ) { // HO
828  sd = HcalOuter ;
829  in -= 2*( kHBhalf + kHEhalf ) ;
830  iz = ( in<kHOhalf ? 1 : -1 ) ;
831  in %= kHOhalf ;
832  dp = 4 ;
833  ip = 1 + in/15 ;
834  ie = 1 + ( in - 15*( ip - 1 ) ) ;
835  } else if ( in > 2*kHBhalf - 1 ) { // Endcap
836  sd = HcalEndcap ;
837  in -= 2*kHBhalf ;
838  iz = ( in<kHEhalf ? 1 : -1 ) ;
839  in %= kHEhalf ;
840  ip = 2*( in/36 ) ;
841  in %= 36 ;
842  ip += 1 + in/28 ;
843  if( 0 == ip%2 ) in %= 28 ;
844  ie = 15 + ( in<2 ? 1 + in : 2 +
845  ( in<20 ? 1 + ( in - 2 )/2 : 9 +
846  ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
847  dp = ( in<1 ? 3 :
848  ( in<2 ? 1 :
849  ( in<20 ? 1 + ( in - 2 )%2 :
850  ( in<26 ? 1 + ( in - 20 )%3 :
851  ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
852  } else { // barrel
853  iz = ( in<kHBhalf ? 1 : -1 ) ;
854  in %= kHBhalf ;
855  ip = in/18 + 1 ;
856  in %= 18 ;
857  if ( in < 14 ) {
858  dp = 1 ;
859  ie = in + 1 ;
860  } else {
861  in %= 14 ;
862  dp = 1 + in%2 ;
863  ie = 15 + in/2 ;
864  }
865  }
866  }
867  } else if (topoVersion_==10) {
868  if (denseid < ncells()) {
869  if (denseid >= (HBSize_+HESize_+HOSize_)) {
870  sd = HcalForward ;
871  in -= (HBSize_+HESize_+HOSize_);
872  dp = (in%2) + 1;
873  ip = (in - dp + 1)%144;
874  ip = (ip/2) + 1;
875  ie = (in - dp + 1 - 2*(ip -1))/144;
876  if (ie > 12) {ie = 54 -ie; iz = -1;}
877  else {ie += 29; iz = 1;}
878  } else if (denseid >= (HBSize_+HESize_)) {
879  sd = HcalOuter ;
880  in -= (HBSize_+HESize_);
881  dp = 4;
882  ip = (in%72) + 1;
883  ie = (in - ip + 1)/72;
884  if (ie > 14) {ie = 30 -ie; iz = -1;}
885  else {ie += 1; iz = 1;}
886  } else if (denseid >= (HBSize_)) {
887  sd = HcalEndcap ;
888  in -= (HBSize_);
889  dp = (in%maxDepthHE_)+1;
890  ip = (in - dp + 1)%(maxDepthHE_*72);
891  ip = (ip/maxDepthHE_) + 1;
892  ie = (in - dp + 1 - maxDepthHE_*(ip-1))/(72*maxDepthHE_);
893  if (ie > 13) {ie = 43 - ie; iz = -1;}
894  else {ie += 16; iz = 1;}
895  } else {
896  sd = HcalBarrel ;
897  dp = (in%maxDepthHB_)+1;
898  ip = (in - dp + 1)%(maxDepthHB_*72);
899  ip = (ip/maxDepthHB_) + 1;
900  ie = (in - dp + 1 - maxDepthHB_*(ip-1))/(72*maxDepthHB_);
901  if (ie > 15) {ie = 32 - ie; iz = -1;}
902  else {ie += 1; iz = 1;}
903  }
904  }
905  }
906  return HcalDetId( sd, iz*int(ie), ip, dp );
907 }
908 
909 unsigned int HcalTopology::ncells() const {
911 }
912 
914  return topoVersion_;
915 }
int firstHFRing() const
Definition: HcalTopology.h:83
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 detId2denseIdPreLS1(const DetId &id) const
virtual unsigned int detId2denseId(const DetId &id) const
return a linear packed id
void excludeSubdetector(HcalSubdetector subdet)
Definition: HcalTopology.cc:97
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:45
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
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)
Definition: HcalTopology.cc:90
int nPhiBins(int etaRing) const
how many phi segments in this ring
int incIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
bool decrementDepth(HcalDetId &id) const
unsigned int HESize_
Definition: HcalTopology.h:172
int lastHBRing() const
Definition: HcalTopology.h:80
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
int zside(DetId const &)
bool decIPhi(const HcalDetId &id, HcalDetId &neighbor) const
bool validHcal(const HcalDetId &id) const
Definition: HcalTopology.cc:63
int ieta() const
get the rbx name (if relevant)
virtual int topoVersion() const
return a version which identifies the given topology
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
bool isExcluded(const HcalDetId &id) const
Definition: HcalTopology.cc:72
int depth() const
get the tower depth
Definition: HcalDetId.h:55
unsigned int HFSize_
Definition: HcalTopology.h:174
bool incIPhi(const HcalDetId &id, HcalDetId &neighbor) const
HcalTopology(HcalTopologyMode::Mode mode, int maxDepthHB, int maxDepthHE, HcalTopologyMode::TriggerMode tmode=HcalTopologyMode::tm_LHC_PreLS1)
Definition: HcalTopology.cc:13
bool validRaw(const HcalDetId &id) const
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
const int maxDepthHE_
Definition: HcalTopology.h:169
HcalTopologyMode::Mode mode_
Definition: HcalTopology.h:150
void setDepthSegmentation(unsigned ring, const std::vector< int > &readoutDepths)
int firstHETripleDepthRing() const
Definition: HcalTopology.h:90
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
int lastHFRing() const
Definition: HcalTopology.h:84
HcalSubdetector
Definition: HcalAssistant.h:31
unsigned int HBSize_
Definition: HcalTopology.h:171
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
T min(T a, T b)
Definition: MathUtil.h:58
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:88
SegmentationMap depthSegmentation_
Definition: HcalTopology.h:183
unsigned int HOSize_
Definition: HcalTopology.h:173
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 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)
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:81
virtual bool valid(const DetId &id) const
Definition: HcalTopology.cc:58
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:89
virtual std::vector< DetId > up(const DetId &id) const
int cboxChannel() const
get the calibration box channel (if relevant)
unsigned int detId2denseIdHO(const DetId &id) const
return a linear packed id from HO
const int maxDepthHB_
Definition: HcalTopology.h:168
const int singlePhiBins_
Definition: HcalTopology.h:166
const int doublePhiBins_
Definition: HcalTopology.h:167
std::vector< HcalDetId > exclusionList_
Definition: HcalTopology.h:147
unsigned int detId2denseIdHE(const DetId &id) const
return a linear packed id from HE
tuple cout
Definition: gather_cfg.py:121
HcalSubdetector hcalSubdet() const
get the HcalSubdetector (if relevant)
virtual std::vector< DetId > east(const DetId &id) const
volatile std::atomic< bool > shutdown_flag false
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:86
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)
int lastHERing() const
Definition: HcalTopology.h:82
static const int IPHI_MAX
Definition: HcalTopology.cc:11