CMS 3D CMS Logo

HcalHFStatusBitFromRecHits.cc
Go to the documentation of this file.
4 
5 #include <algorithm> // for "max"
6 #include <cmath>
7 #include <iostream>
8 
10 {
11  // use simple values in default constructor
14  long_thresholdET_ = 0.5; // default energy requirement
15  short_thresholdET_ = 0.5;
18 }
19 
20 HcalHFStatusBitFromRecHits::HcalHFStatusBitFromRecHits(double shortR, double shortET, double shortE,
21  double longR, double longET, double longE)
22 {
23  long_HFlongshortratio_ = longR;
24  short_HFlongshortratio_ = shortR;
25  long_thresholdET_ = longET;
26  short_thresholdET_ = shortET;
27  long_thresholdEnergy_ = longE;
28  short_thresholdEnergy_ = shortE;
29 }
30 
32 
34  HcalChannelQuality* myqual,
35  const HcalSeverityLevelComputer* mySeverity)
36 {
37  // Compares energies from long & short fibers
38  int status;
39  float en, en2;
40  int ieta, iphi, depth;
41  float ratio; // ratio of (L-S)/(L+S) energy magnitudes
42  double coshEta;
43 
44  // Is there a faster way to do this than a double loop?
45  for (HFRecHitCollection::iterator iHF=rec.begin(); iHF!=rec.end();++iHF)
46  {
47  // skip cells that have already been tagged -- shouldn't happen in current algorithm
48  //if (iHF->flagField(HcalCaloFlagLabels::HFLongShort, HcalCaloFlagLabels::HFLongShort+1)) continue;
49 
50  ieta =iHF->id().ieta(); // int between 29-41
51  // eta = average value between cell eta bounds
52  std::pair<double,double> etas = myqual->topo()->etaRange(HcalForward,abs(ieta));
53  double eta1 = etas.first;
54  double eta2 = etas.second;
55  coshEta=fabs(cosh(0.5*(eta1+eta2)));
56 
57  status=0; // status bit for rechit
58 
59  en2=-999; // dummy starting value for partner energy
60  depth=iHF->id().depth();
61  en=iHF->energy(); // energy of current rechit
62 
63  if (depth==1) // check long fiber
64  {
65  if (en<1.2) continue; // never flag long rechits < 1.2 GeV
66  if (long_thresholdEnergy_>0. && en<long_thresholdEnergy_) continue;
67  if (long_thresholdET_>0. && en<long_thresholdET_*coshEta) continue;
68  }
69 
70  else if (depth==2) // check short fiber
71  {
72  if (en<1.8) continue; // never flag short rechits < 1.8 GeV
73  if (short_thresholdEnergy_>0. && en<short_thresholdEnergy_) continue;
74  if (short_thresholdET_>0. && en<short_thresholdET_*coshEta) continue;
75  }
76 
77  iphi =iHF->id().iphi();
78 
79  // Check for cells whose partners have been excluded from the rechit collections
80  // Such cells will not get flagged (since we can't make an L vs. S comparison)
81 
82  HcalDetId partner(HcalForward, ieta, iphi, 3-depth); // if depth=1, 3-depth =2, and vice versa
83  DetId detpartner=DetId(partner);
84  const HcalChannelStatus* partnerstatus=myqual->getValues(detpartner.rawId());
85  if (mySeverity->dropChannel(partnerstatus->getValue() ) ) continue; // partner was dropped; don't set flag
86 
87  // inner loop will find 'partner' channel (same ieta, iphi, different depth)
88  for (HFRecHitCollection::iterator iHF2=rec.begin(); iHF2!=rec.end();++iHF2)
89  {
90  if (iHF2->id().ieta()!=ieta) continue; // require ieta match
91  if (iHF2->id().iphi()!=iphi) continue; // require iphi match
92  if (iHF2->id().depth()==depth) continue; // require short/long combo
93 
94  en2=iHF2->energy();
95 
96  /*
97  We used to use absolute values of energies for ratios, but I don't think we want to do this any more.
98  For example, for a threshold of 0.995, if en=50 and en2=0, the flag would be set.
99  But if en=50 and en2<-0.125, the threshold would not be set if using the absolute values.
100  I don't think we want to have a range of en2 below which the flag is not set.
101  This does mean that we need to be careful not to set the en energy threshold too low,
102  so as to not falsely flag fluctuations (en=2, en2=-0.01, for example), but we should never be setting our
103  thresholds that low.
104  */
105 
106  ratio = (en - en2)/(en + en2);
107 
108  if (depth==1 && ratio>long_HFlongshortratio_)
109  status=1;
110  else if (depth==2 && ratio>short_HFlongshortratio_)
111  status=1;
112  break; // once partner channel found, break out of loop
113  } // inner loop
114 
115  // Consider the case where only one depth present
116  if (en2==-999) // outer rechit has already passed energy, ET thresholds above; no partner cell means this looks like isolated energy in one channel -- flag it!
117  status=1;
118 
119  // flag rechit as potential PMT window hit
120  if (status==1)
121  iHF->setFlagField(status,HcalCaloFlagLabels::HFLongShort, 1);
122  } // outer loop
123  return;
124 } // void HcalHFStatusBitFromRecHits::hfSetFlagFromRecHits(...)
const Item * getValues(DetId fId, bool throwOnFail=true) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:44
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
bool dropChannel(const uint32_t &mystatus) const
std::vector< HFRecHit >::iterator iterator
const_iterator end() const
Definition: DetId.h:18
std::pair< double, double > etaRange(HcalSubdetector subdet, int ieta) const
void hfSetFlagFromRecHits(HFRecHitCollection &rec, HcalChannelQuality *myqual, const HcalSeverityLevelComputer *mySeverity)
uint32_t getValue() const
const_iterator begin() const
const HcalTopology * topo() const