CMS 3D CMS Logo

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