CMS 3D CMS Logo

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