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  //A.N.
142  // incrementDepth(neighbor);
143  std::vector<DetId> vNeighborsDetId;
144  if(incrementDepth(neighbor))
145  {
146  vNeighborsDetId.push_back(neighbor);
147  }
148  return vNeighborsDetId;
149 }
150 
151 std::vector<DetId> HcalTopology::down(const DetId& id) const {
152  std::cout << "HcalTopology::down() not yet implemented" << std::endl;
153  std::vector<DetId> vNeighborsDetId;
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  //A.N.
526  // assert(validRaw(detId));
527  return validRaw(detId);
528  //A.N. return true;
529 }
530 
531 
532 int HcalTopology::nPhiBins(int etaRing) const {
533  int lastPhiBin=singlePhiBins_;
534  if (etaRing>= firstHFQuadPhiRing()) lastPhiBin=doublePhiBins_/2;
535  else if (etaRing>= firstHEDoublePhiRing()) lastPhiBin=doublePhiBins_;
536  return lastPhiBin;
537 }
538 
539 void HcalTopology::getDepthSegmentation(unsigned ring, std::vector<int> & readoutDepths) const
540 {
541  // if it doesn't exist, return the first entry with a lower index. So if we only
542  // have entries for 1 and 17, any input from 1-16 should return the entry for ring 1
543  SegmentationMap::const_iterator pos = depthSegmentation_.upper_bound(ring);
544  if(pos == depthSegmentation_.begin()) {
545  throw cms::Exception("HcalTopology") << "No depth segmentation found for ring" << ring;
546  }
547  --pos;
548  // pos now refers to the last element with key <= ring.
549  readoutDepths = pos->second;
550 }
551 
552 void HcalTopology::setDepthSegmentation(unsigned ring, const std::vector<int> & readoutDepths)
553 {
554  depthSegmentation_[ring] = readoutDepths;
555 }
556 
557 std::pair<int, int> HcalTopology::segmentBoundaries(unsigned ring, unsigned depth) const {
558  std::vector<int> readoutDepths;
559  getDepthSegmentation(ring, readoutDepths);
560  int d1 = std::lower_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
561  int d2 = std::upper_bound(readoutDepths.begin(), readoutDepths.end(), depth) - readoutDepths.begin();
562  return std::pair<int, int>(d1, d2);
563 }
564 
565 unsigned int HcalTopology::detId2denseIdPreLS1 (const DetId& id) const {
566 
567  HcalDetId hid(id);
568  const HcalSubdetector sd (hid.subdet() ) ;
569  const int ip (hid.iphi() ) ;
570  const int ie (hid.ietaAbs() ) ;
571  const int dp (hid.depth() ) ;
572  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
573  unsigned int retval = ( ( sd == HcalBarrel ) ?
574  ( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf :
575  ( ( sd == HcalEndcap ) ?
576  2*kHBhalf + ( ip - 1 )*8 + ( ip/2 )*20 +
577  ( ( ie==16 || ie==17 ) ? ie - 16 :
578  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
579  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
580  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
581  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf :
582  ( ( sd == HcalOuter ) ?
583  2*kHBhalf + 2*kHEhalf + ( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf :
584  ( ( sd == HcalForward ) ?
585  2*kHBhalf + 2*kHEhalf + 2*kHOhalf +
586  ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
587  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf : 0xFFFFFFFFu ) ) ) ) ;
588  return retval;
589 }
590 
591 
592 unsigned int HcalTopology::detId2denseIdHB(const DetId& id) const {
593  HcalDetId hid(id);
594  const int ip (hid.iphi() ) ;
595  const int ie (hid.ietaAbs() ) ;
596  const int dp (hid.depth() ) ;
597  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
598  unsigned int retval = 0xFFFFFFFFu;
599  if (topoVersion_==0) {
600  retval=( ip - 1 )*18 + dp - 1 + ie - ( ie<16 ? 1 : 0 ) + zn*kHBhalf;
601  } else if (topoVersion_==10) {
602  retval=dp-1 + maxDepthHB_*(ip-1)+maxDepthHB_*72*(hid.ieta()-1+33*zn);
603  }
604  return retval;
605 }
606 
607 unsigned int HcalTopology::detId2denseIdHE(const DetId& id) const {
608  HcalDetId hid(id);
609  const int ip (hid.iphi() ) ;
610  const int ie (hid.ietaAbs() ) ;
611  const int dp (hid.depth() ) ;
612  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
613  unsigned int retval = 0xFFFFFFFFu;
614  if (topoVersion_==0) {
615  retval=( ip - 1 )*8 + ( ip/2 )*20 +
616  ( ( ie==16 || ie==17 ) ? ie - 16 :
617  ( ( ie>=18 && ie<=20 ) ? 2 + 2*( ie - 18 ) + dp - 1 :
618  ( ( ie>=21 && ie<=26 ) ? 8 + 2*( ie - 21 ) + dp - 1 :
619  ( ( ie>=27 && ie<=28 ) ? 20 + 3*( ie - 27 ) + dp - 1 :
620  26 + 2*( ie - 29 ) + dp - 1 ) ) ) ) + zn*kHEhalf;
621  } else if (topoVersion_==10) {
622  retval=(dp-1)+maxDepthHE_*(ip-1)+maxDepthHE_*72*(hid.ieta()-16+zn*(14+29+16));
623  }
624  return retval;
625 }
626 
627 unsigned int HcalTopology::detId2denseIdHO(const DetId& id) const {
628  HcalDetId hid(id);
629  const int ip (hid.iphi() ) ;
630  const int ie (hid.ietaAbs() ) ;
631  const int zn (hid.zside() < 0 ? 1 : 0 ) ;
632 
633  unsigned int retval = 0xFFFFFFFFu;
634  if (topoVersion_==0) {
635  retval=( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf;
636  } else if (topoVersion_==10) {
637  retval=( ip - 1 )*15 + ( ie - 1 ) + zn*kHOhalf;
638  }
639  return retval;
640 }
641 
642 unsigned int HcalTopology::detId2denseIdHF(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 
649  unsigned int retval = 0xFFFFFFFFu;
650  if (topoVersion_==0) {
651  retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
652  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf;
653  } else if (topoVersion_==10) {
654  retval = ( ( ip - 1 )/4 )*4 + ( ( ip - 1 )/2 )*22 +
655  2*( ie - 29 ) + ( dp - 1 ) + zn*kHFhalf;
656  }
657  return retval;
658 }
659 
660 unsigned int HcalTopology::detId2denseIdHT(const DetId& id) const {
661  HcalTrigTowerDetId tid(id);
662  int zside = tid.zside();
663  unsigned int ietaAbs = tid.ietaAbs();
664  unsigned int iphi = tid.iphi();
665 
666  unsigned int index;
667  if ((iphi-1)%4==0) index = (iphi-1)*32 + (ietaAbs-1) - (12*((iphi-1)/4));
668  else index = (iphi-1)*28 + (ietaAbs-1) + (4*(((iphi-1)/4)+1));
669 
670  if (zside == -1) index += kHThalf;
671 
672  return index;
673 }
674 
675 unsigned int HcalTopology::detId2denseIdCALIB(const DetId& id) const {
676  HcalCalibDetId tid(id);
677  int channel = tid.cboxChannel();
678  int ieta = tid.ieta();
679  int iphi = tid.iphi();
680  int zside = tid.zside();
681  unsigned int index=0xFFFFFFFFu;
682 
684 
685  HcalSubdetector subDet = tid.hcalSubdet();
686 
687  if (subDet==HcalBarrel) {
688  //std::cout<<"CALIB_HB: ";
689  //dphi = 4 (18 phi values), 3 channel types (0,1,2), eta = -1 or 1
690  //total of 18*3*2=108 channels
691  index = ((iphi+1)/4-1) + 18*channel + 27*(ieta+1);
692  } else if (subDet==HcalEndcap) {
693  //std::cout<<"CALIB_HE: ";
694  //dphi = 4 (18 phi values), 6 channel types (0,1,3,4,5,6), eta = -1 or 1
695  //total of 18*6*2=216 channels
696  if (channel>2) channel-=1;
697  index = ((iphi+1)/4-1) + 18*channel + 54*(ieta+1) + 108;
698  } else if (subDet==HcalForward) {
699  //std::cout<<"CALIB_HF: ";
700  //dphi = 18 (4 phi values), 3 channel types (0,1,8), eta = -1 or 1
701  if (channel==8) channel = 2;
702  //total channels 4*3*2=24
703  index = (iphi-1)/18 + 4*channel + 6*(ieta+1) + 324;
704  } else if (subDet==HcalOuter) {
705  //std::cout<<"CALIB_HO: ";
706  //there are 5 special calib crosstalk channels, one in each ring
707  if (channel==7) {
708  channel = 2;
709  index = (ieta+2) + 420;
710  //for HOM/HOP dphi = 6 (12 phi values), 2 channel types (0,1), eta = -2,-1 or 1,2
711  //for HO0/YB0 dphi = 12 (6 phi values), 2 channel types (0,1), eta = 0
712  } else{
713  if (ieta<0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 348;
714  else if (ieta>0) index = ((iphi+1)/12-1) + 36*channel + 6*(ieta+2) + 6 + 348;
715  else index = ((iphi+1)/6-1) + 36*channel + 6*(ieta+2) + 348;
716  }
717  } else {
718  std::cout << "HCAL Det Id not valid!" << std::endl;
719  index = 0;
720  }
721 
722  } else if (tid.calibFlavor()==HcalCalibDetId::HOCrosstalk) {
723  //std::cout<<"HX: ";
724  //for YB0/HO0 phi is grouped in 6 groups of 6 with dphi=2 but the transitions are 1 or 3
725  // in such a way that the %36 operation yeilds unique values for every iphi
726  if (abs(ieta)==4) index = ((iphi-1)%36) + (((zside+1)*36)/2) + 72 + 425; //ieta = 1 YB0/HO0;
727  else index = (iphi-1) + (36*(zside+1)*2) + 425; //ieta = 0 for HO2M/HO1M ieta=2 for HO1P/HO2P;
728  }
729  //std::cout << " " << ieta << " " << zside << " " << iphi << " " << depth << " " << index << std::endl;
730  return index;
731 }
732 
733 
734 unsigned int HcalTopology::detId2denseId(const DetId& id) const {
735  unsigned int retval(0);
736  if (topoVersion_==0) { // pre-LS1
737  retval = detId2denseIdPreLS1(id);
738  } else if (topoVersion_==10) {
739  HcalDetId hid(id);
740  if (hid.subdet()==HcalBarrel) {
741  retval=(hid.depth()-1)+maxDepthHB_*(hid.iphi()-1);
742  if (hid.ieta()>0) {
743  retval+=maxDepthHB_*72*(hid.ieta()-1);
744  } else {
745  retval+=maxDepthHB_*72*(32+hid.ieta());
746  }
747  } else if (hid.subdet()==HcalEndcap) {
748  retval=HBSize_;
749  retval+=(hid.depth()-1)+maxDepthHE_*(hid.iphi()-1);
750  if (hid.ieta()>0) {
751  retval+=maxDepthHE_*72*(hid.ieta()-16);
752  } else {
753  retval+=maxDepthHE_*72*((14+29)+hid.ieta());
754  }
755  } else if (hid.subdet()==HcalOuter) {
756  retval=HBSize_+HESize_;
757  if (hid.ieta()>0) retval+=(hid.iphi()-1)+72*(hid.ieta()-1);
758  else retval+=(hid.iphi()-1)+72*(30+hid.ieta());
759  } else if (hid.subdet()==HcalForward) {
760  retval=HBSize_+HESize_+HOSize_;
761  retval+=hid.depth()-1+2*(hid.iphi()-1);
762  if (hid.ieta()>0) retval+=2*72*(hid.ieta()-29);
763  else retval+=2*72*((41+13)+hid.ieta());
764  } else {
765  return 0xFFFFFFFu;
766  }
767  }
768  return retval;
769 }
770 
771 DetId HcalTopology::denseId2detId(unsigned int denseid) const {
772 
774  int ie ( 0 ) ;
775  int ip ( 0 ) ;
776  int dp ( 0 ) ;
777  int in ( denseid ) ;
778  int iz ( 1 ) ;
779  if (topoVersion_==0) { //DL// pre-LS1
780  if (denseid < kSizeForDenseIndexingPreLS1) {
781  if ( in > 2*( kHBhalf + kHEhalf + kHOhalf ) - 1 ) { // HF
782  sd = HcalForward ;
783  in -= 2*( kHBhalf + kHEhalf + kHOhalf ) ;
784  iz = ( in<kHFhalf ? 1 : -1 ) ;
785  in %= kHFhalf ;
786  ip = 4*( in/48 ) ;
787  in %= 48 ;
788  ip += 1 + ( in>21 ? 2 : 0 ) ;
789  if( 3 == ip%4 ) in -= 22 ;
790  ie = 29 + in/2 ;
791  dp = 1 + in%2 ;
792  } else if ( in > 2*( kHBhalf + kHEhalf ) - 1 ) { // HO
793  sd = HcalOuter ;
794  in -= 2*( kHBhalf + kHEhalf ) ;
795  iz = ( in<kHOhalf ? 1 : -1 ) ;
796  in %= kHOhalf ;
797  dp = 4 ;
798  ip = 1 + in/15 ;
799  ie = 1 + ( in - 15*( ip - 1 ) ) ;
800  } else if ( in > 2*kHBhalf - 1 ) { // Endcap
801  sd = HcalEndcap ;
802  in -= 2*kHBhalf ;
803  iz = ( in<kHEhalf ? 1 : -1 ) ;
804  in %= kHEhalf ;
805  ip = 2*( in/36 ) ;
806  in %= 36 ;
807  ip += 1 + in/28 ;
808  if( 0 == ip%2 ) in %= 28 ;
809  ie = 15 + ( in<2 ? 1 + in : 2 +
810  ( in<20 ? 1 + ( in - 2 )/2 : 9 +
811  ( in<26 ? 1 + ( in - 20 )/3 : 3 ) ) ) ;
812  dp = ( in<1 ? 3 :
813  ( in<2 ? 1 :
814  ( in<20 ? 1 + ( in - 2 )%2 :
815  ( in<26 ? 1 + ( in - 20 )%3 :
816  ( 1 + ( in - 26 )%2 ) ) ) ) ) ;
817  } else { // barrel
818  iz = ( in<kHBhalf ? 1 : -1 ) ;
819  in %= kHBhalf ;
820  ip = in/18 + 1 ;
821  in %= 18 ;
822  if ( in < 14 ) {
823  dp = 1 ;
824  ie = in + 1 ;
825  } else {
826  in %= 14 ;
827  dp = 1 + in%2 ;
828  ie = 15 + in/2 ;
829  }
830  }
831  }
832  } else if (topoVersion_==10) {
833  if (denseid < ncells()) {
834  if (denseid >= (HBSize_+HESize_+HOSize_)) {
835  sd = HcalForward ;
836  in -= (HBSize_+HESize_+HOSize_);
837  dp = (in%2) + 1;
838  ip = (in - dp + 1)%144;
839  ip = (ip/2) + 1;
840  ie = (in - dp + 1 - 2*(ip -1))/144;
841  if (ie > 12) {ie = 54 -ie; iz = -1;}
842  else {ie += 29; iz = 1;}
843  } else if (denseid >= (HBSize_+HESize_)) {
844  sd = HcalOuter ;
845  in -= (HBSize_+HESize_);
846  dp = 4;
847  ip = (in%72) + 1;
848  ie = (in - ip + 1)/72;
849  if (ie > 14) {ie = 30 -ie; iz = -1;}
850  else {ie += 1; iz = 1;}
851  } else if (denseid >= (HBSize_)) {
852  sd = HcalEndcap ;
853  in -= (HBSize_);
854  dp = (in%maxDepthHE_)+1;
855  ip = (in - dp + 1)%(maxDepthHE_*72);
856  ip = (ip/maxDepthHE_) + 1;
857  ie = (in - dp + 1 - maxDepthHE_*(ip-1))/(72*maxDepthHE_);
858  if (ie > 13) {ie = 43 - ie; iz = -1;}
859  else {ie += 16; iz = 1;}
860  } else {
861  sd = HcalBarrel ;
862  dp = (in%maxDepthHB_)+1;
863  ip = (in - dp + 1)%(maxDepthHB_*72);
864  ip = (ip/maxDepthHB_) + 1;
865  ie = (in - dp + 1 - maxDepthHB_*(ip-1))/(72*maxDepthHB_);
866  if (ie > 15) {ie = 32 - ie; iz = -1;}
867  else {ie += 1; iz = 1;}
868  }
869  }
870  }
871  return HcalDetId( sd, iz*int(ie), ip, dp );
872 }
873 
874 unsigned int HcalTopology::ncells() const {
876 }
877 
879  return topoVersion_;
880 }
int firstHFRing() const
Definition: HcalTopology.h:81
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:30
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:32
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
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
unsigned int HESize_
Definition: HcalTopology.h:170
int lastHBRing() const
Definition: HcalTopology.h:78
unsigned int detId2denseIdHB(const DetId &id) const
return a linear packed id from HB
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:40
unsigned int HFSize_
Definition: HcalTopology.h:172
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
const T & max(const T &a, const T &b)
int decAIEta(const HcalDetId &id, HcalDetId neighbors[2]) const
const int maxDepthHE_
Definition: HcalTopology.h:167
HcalTopologyMode::Mode mode_
Definition: HcalTopology.h:148
void setDepthSegmentation(unsigned ring, const std::vector< int > &readoutDepths)
int firstHETripleDepthRing() const
Definition: HcalTopology.h:88
int ieta() const
get the cell ieta
Definition: HcalDetId.h:36
int lastHFRing() const
Definition: HcalTopology.h:82
HcalSubdetector
Definition: HcalAssistant.h:31
unsigned int HBSize_
Definition: HcalTopology.h:169
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
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:86
SegmentationMap depthSegmentation_
Definition: HcalTopology.h:181
unsigned int HOSize_
Definition: HcalTopology.h:171
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:34
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:38
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
auto dp
Definition: deltaR.h:24
double sd
int firstHERing() const
Definition: HcalTopology.h:79
virtual bool valid(const DetId &id) const
Definition: HcalTopology.cc:58
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:87
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:166
const int singlePhiBins_
Definition: HcalTopology.h:164
const int doublePhiBins_
Definition: HcalTopology.h:165
std::vector< HcalDetId > exclusionList_
Definition: HcalTopology.h:145
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:84
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:80
static const int IPHI_MAX
Definition: HcalTopology.cc:11