CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
HcalHFStatusBitFromDigis.cc
Go to the documentation of this file.
3 
4 #include <algorithm> // for "max"
5 #include <cmath>
6 #include <iostream>
7 
9  // use simple values in default constructor
10  minthreshold_ = 40; // minimum energy threshold (in GeV)
11 
12  firstSample_ =
13  1; // these are the firstSample, samplesToAdd value of Igor's algorithm -- not necessarily the same as the reco first, toadd values (which are supplied individually for each hit)
14  samplesToAdd_ = 3;
15  expectedPeak_ = 2;
16 
17  // Based on Igor V's algorithm:
18  //TS4/(TS3+TS4+TS5+TS6) > 0.93 - exp(-0.38275-0.012667*E)
19  coef_.push_back(0.93);
20  coef_.push_back(-0.38275);
21  coef_.push_back(-0.012667);
22  // Minimum energy of 10 GeV required
24  HFlongwindowMinTime_.clear();
25  HFlongwindowMinTime_.push_back(-10);
26  HFlongwindowMaxTime_.clear();
27  HFlongwindowMaxTime_.push_back(8);
29  HFshortwindowMinTime_.clear();
30  HFshortwindowMinTime_.push_back(-10);
31  HFshortwindowMaxTime_.clear();
32  HFshortwindowMaxTime_.push_back(8);
33 }
34 
36  const edm::ParameterSet& HFTimeInWindowParams) {
37  // Specify parameters used in forming the HFDigiTime flag
38  firstSample_ = HFDigiTimeParams.getParameter<int>("HFdigiflagFirstSample");
39  samplesToAdd_ = HFDigiTimeParams.getParameter<int>("HFdigiflagSamplesToAdd");
40  expectedPeak_ = HFDigiTimeParams.getParameter<int>("HFdigiflagExpectedPeak");
41  minthreshold_ = HFDigiTimeParams.getParameter<double>("HFdigiflagMinEthreshold");
42  coef_ = HFDigiTimeParams.getParameter<std::vector<double> >("HFdigiflagCoef");
43 
44  // Specify parameters used in forming HFInTimeWindow flag
45  HFlongwindowMinTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMinWindowTime");
46  HFlongwindowMaxTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hflongMaxWindowTime");
47  HFlongwindowEthresh_ = HFTimeInWindowParams.getParameter<double>("hflongEthresh");
48  HFshortwindowMinTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMinWindowTime");
49  HFshortwindowMaxTime_ = HFTimeInWindowParams.getParameter<std::vector<double> >("hfshortMaxWindowTime");
50  HFshortwindowEthresh_ = HFTimeInWindowParams.getParameter<double>("hfshortEthresh");
51 }
52 
54 
56  int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, const std::vector<double>& coef) {
57  // Resets values based on values in database.
60  expectedPeak_ = expectedPeak;
61  minthreshold_ = minthreshold;
62  coef_ = coef;
63 }
64 
66  // This resets the time samples used in the HF flag. These samples are not necessarily the same
67  // as the flags used by the energy reconstruction
70  expectedPeak_ = expectedPeak;
71 } // void HcalHFStatusBitFromDigis
72 
74  const HFDataFrame& digi,
75  const HcalCoder& coder,
76  const HcalCalibrations& calib) {
77  // The following 3 values are computed by Igor's algorithm
78  //only in the window [firstSample_, firstSample_ + samplesToAdd_),
79  //which may not be the same as the default reco window.
80 
81  double totalCharge = 0;
82  double peakCharge = 0;
83  double RecomputedEnergy = 0;
84 
85  CaloSamples tool;
86  coder.adc2fC(digi, tool);
87 
88  // Compute quantities needed for HFDigiTime, Fraction2TS FLAGS
89  for (int i = 0; i < digi.size(); ++i) {
90  int capid = digi.sample(i).capid();
91  double value = tool[i] - calib.pedestal(capid);
92 
93  // Sum all charge within flagging window, find charge in expected peak time slice
94  if (i >= firstSample_ && i < firstSample_ + samplesToAdd_) {
95  totalCharge += value;
96  RecomputedEnergy += value * calib.respcorrgain(capid);
97  if (i == expectedPeak_)
98  peakCharge = value;
99  }
100  } // for (int i=0;i<digi.size();++i)
101 
102  // FLAG: HcalCaloLabels::HFDigiTime
103  // Igor's algorithm: compare charge in peak to total charge in window
104  if (RecomputedEnergy >= minthreshold_) // don't set noise flags for cells below a given threshold
105  {
106  // Calculate allowed minimum value of (TS4/TS3+4+5+6):
107  double cutoff = 0; // no arguments specified; no cutoff applied
108  if (!coef_.empty())
109  cutoff = coef_[0];
110  // default cutoff takes the form:
111  // cutoff = coef_[0] - exp(coef_[1]+coef_[2]*E+coef_[3]*E^2+...)
112  double powRE = 1;
113  double expo_arg = 0;
114  for (unsigned int zz = 1; zz < coef_.size(); ++zz) {
115  expo_arg += coef_[zz] * powRE;
116  powRE *= RecomputedEnergy;
117  }
118  cutoff -= exp(expo_arg);
119 
120  if (peakCharge / totalCharge < cutoff)
122  }
123 
124  // FLAG: HcalCaloLabels:: HFInTimeWindow
125  // Timing algorithm
126  if (hf.id().depth() == 1) {
127  if (hf.energy() >= HFlongwindowEthresh_) {
128  float mult = 1. / hf.energy();
129  float enPow = 1.;
130  float mintime = 0;
131  float maxtime = 0;
132  for (unsigned int i = 0; i < HFlongwindowMinTime_.size(); ++i) {
133  mintime += HFlongwindowMinTime_[i] * enPow;
134  maxtime += HFlongwindowMaxTime_[i] * enPow;
135  enPow *= mult;
136  }
137  if (hf.time() < mintime || hf.time() > maxtime)
139  }
140  } else if (hf.id().depth() == 2) {
141  if (hf.energy() >= HFshortwindowEthresh_) {
142  float mult = 1. / hf.energy();
143  float enPow = 1.;
144  float mintime = 0;
145  float maxtime = 0;
146  for (unsigned int i = 0; i < HFshortwindowMinTime_.size(); ++i) {
147  mintime += HFshortwindowMinTime_[i] * enPow;
148  maxtime += HFshortwindowMaxTime_[i] * enPow;
149  enPow *= mult;
150  }
151  if (hf.time() < mintime || hf.time() > maxtime)
153  }
154  }
155 
156  return;
157 }
constexpr float energy() const
Definition: CaloRecHit.h:29
std::vector< double > HFlongwindowMaxTime_
std::vector< double > HFshortwindowMinTime_
void hfSetFlagFromDigi(HFRecHit &hf, const HFDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
Exp< T >::type exp(const T &t)
Definition: Exp.h:22
void resetParamsFromDB(int firstSample, int samplesToAdd, int expectedPeak, double minthreshold, const std::vector< double > &coef)
constexpr void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.h:36
void resetFlagTimeSamples(int firstSample, int samplesToAdd, int expectedPeak)
constexpr int size() const
total number of samples in the digi
Definition: HFDataFrame.h:27
constexpr float time() const
Definition: CaloRecHit.h:31
std::vector< double > HFlongwindowMinTime_
constexpr double pedestal(int fCapId) const
get pedestal for capid=0..3
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
constexpr int capid() const
get the Capacitor id
Definition: HcalQIESample.h:47
std::vector< double > HFshortwindowMaxTime_
constexpr HcalDetId id() const
Definition: HFRecHit.h:26
constexpr int depth() const
get the tower depth
Definition: HcalDetId.h:164
constexpr HcalQIESample const & sample(int i) const
access a sample
Definition: HFDataFrame.h:40
constexpr double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3