CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HBHENegativeFlag.cc
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 #include <string>
3 #include <vector>
4 #include <iostream>
5 #include <algorithm>
6 #include <fstream>
7 #include <cmath>
8 
9 //---------------------------------------------------------------------------
12 
14 
18 
22 
27 //---------------------------------------------------------------------------
29 {
30  //
31  // Argumentless constructor; should not be used
32  //
33  // If arguments not properly specified for the constructor, I don't think
34  // we'd trust the flagging algorithm.
35  // Set the minimum charge threshold large enough so that nothing will be flagged.
36  //
37 
38  mMinimumChargeThreshold = 99999999;
39  mTS4TS5ChargeThreshold = 99999999;
40  mFirst = 4;
41  mLast = 6;
44 }
45 //---------------------------------------------------------------------------
46 HBHENegativeFlagSetter::HBHENegativeFlagSetter(double minimumChargeThreshold,
47  double tS4TS5ChargeThreshold, int first, int last,
48  std::vector<double> threshold, std::vector<double> cut)
49 {
50  //
51  // The constructor that should be used
52  //
53  // Copies various thresholds and limits and parameters to the class for future use.
54  //
55 
56  mMinimumChargeThreshold = minimumChargeThreshold;
57  mTS4TS5ChargeThreshold = tS4TS5ChargeThreshold;
58  mFirst = first;
59  mLast = last;
60 
61  if(mLast < mFirst) // sanity protection
63 
66 
67  for(int i = 0; i < (int)std::min(threshold.size(), cut.size()); i++)
68  mCut.push_back(std::pair<double, double>(threshold[i], cut[i]));
69  std::sort(mCut.begin(), mCut.end());
70 }
71 //---------------------------------------------------------------------------
73 {
74  // Dummy destructor - there's nothing to destruct by hand here
75 }
76 //---------------------------------------------------------------------------
78  const HBHEDataFrame &digi,
79  const HcalCoder &coder,
80  const HcalCalibrations &calib)
81 {
82  //
83  // Decide if a digi/pulse is good or bad using negative energy discriminants
84  //
85  // SetPulseShapeFlags determines the total charge in the digi.
86  // If the charge is above the minimum threshold, the code then
87  // runs the flag-setting algorithms to determine whether the
88  // flags should be set.
89  //
90 
91  if(hbhePileupCorr_)
92  {
94  coder.adc2fC(digi,cs);
95  const int nRead = cs.size();
96 
97  double inputCharge[CaloSamples::MAXSAMPLES];
98  double gains[CaloSamples::MAXSAMPLES];
99  double CorrectedEnergy[CaloSamples::MAXSAMPLES];
100 
101  for(int i = 0; i < nRead; i++)
102  {
103  const int capid = digi[i].capid();
104  inputCharge[i] = cs[i] - calib.pedestal(capid);
105  gains[i] = calib.respcorrgain(capid);
106  }
107 
108  double ChargeInWindow = 0;
109  for(int i = mFirst; i <= mLast && i < CaloSamples::MAXSAMPLES; i++)
110  ChargeInWindow = ChargeInWindow + inputCharge[i];
111  if(ChargeInWindow < mMinimumChargeThreshold)
112  return;
113 
114  const bool UseGain = hbhePileupCorr_->inputIsEnergy();
115  if(UseGain == true)
116  for(int i = 0; i < nRead; i++)
117  inputCharge[i] = inputCharge[i] * gains[i];
118 
119  bool pulseShapeCorrApplied = false;
120  bool leakCorrApplied = false;
121  bool readjustTiming = false;
122 
123  int n = std::min(mLast + 1, CaloSamples::MAXSAMPLES) - mFirst;
124 
125  hbhePileupCorr_->apply(digi.id(), inputCharge, nRead,
127  CorrectedEnergy, CaloSamples::MAXSAMPLES,
128  &pulseShapeCorrApplied, &leakCorrApplied,
129  &readjustTiming);
130 
131  for(int i = mFirst; i <= mLast; i++)
132  {
133  bool decision = checkPassFilter(ChargeInWindow, CorrectedEnergy[i], mCut, -1);
134  if(decision == false)
136  }
137  }
138 }
139 //---------------------------------------------------------------------------
140 void HBHENegativeFlagSetter::setHBHEPileupCorrection(boost::shared_ptr<AbsOOTPileupCorrection> corr)
141 {
143 }
144 //---------------------------------------------------------------------------
145 void HBHENegativeFlagSetter::setBXInfo(const BunchXParameter *info, unsigned length)
146 {
148  mLengthBunchCrossingInfo = length;
149 }
150 //---------------------------------------------------------------------------
152  double discriminant,
153  std::vector<std::pair<double, double> > &cuts,
154  int side)
155 {
156  //
157  // Checks whether Discriminant value passes Cuts for the specified Charge. True if pulse is good.
158  //
159  // The "Cuts" pairs are assumed to be sorted in terms of size from small to large,
160  // where each "pair" = (Charge, Discriminant)
161  // "Side" is either positive or negative, which determines whether to discard the pulse if discriminant
162  // is greater or smaller than the cut value
163  //
164 
165  if(cuts.size() == 0) // safety check that there are some cuts defined
166  return true;
167 
168  if(charge <= cuts[0].first) // too small to cut on
169  return true;
170 
171  int indexLargerThanCharge = -1; // find the range it is falling in
172  for(int i = 1; i < (int)cuts.size(); i++)
173  {
174  if(cuts[i].first > charge)
175  {
176  indexLargerThanCharge = i;
177  break;
178  }
179  }
180 
181  double limit = 1000000;
182 
183  if(indexLargerThanCharge == -1) // if charge is greater than the last entry, assume flat line
184  limit = cuts[cuts.size()-1].second;
185  else // otherwise, do a linear interpolation to find the cut position
186  {
187  double C1 = cuts[indexLargerThanCharge].first;
188  double C2 = cuts[indexLargerThanCharge-1].first;
189  double L1 = cuts[indexLargerThanCharge].second;
190  double L2 = cuts[indexLargerThanCharge-1].second;
191 
192  limit = (charge - C1) / (C2 - C1) * (L2 - L1) + L1;
193  }
194 
195  if(side > 0 && discriminant > limit)
196  return false;
197  if(side < 0 && discriminant < limit)
198  return false;
199 
200  return true;
201 }
202 //---------------------------------------------------------------------------
203 
204 
int i
Definition: DBlmapReader.cc:9
static const TGPicture * info(bool iBackgroundIsBlack)
double respcorrgain(int fCapId) const
get response corrected gain for capid=0..3
auto_ptr< ClusterSequence > cs
void setBXInfo(const BunchXParameter *info, unsigned length)
static const int MAXSAMPLES
Definition: CaloSamples.h:73
void setFlagField(uint32_t value, int base, int width=1)
Definition: CaloRecHit.cc:20
#define NULL
Definition: scimark2.h:8
double pedestal(int fCapId) const
get pedestal for capid=0..3
MVATrainerComputer * calib
Definition: MVATrainer.cc:64
std::vector< std::pair< double, double > > mCut
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T min(T a, T b)
Definition: MathUtil.h:58
bool first
Definition: L1TdeRCT.cc:75
JetCorrectorParameters corr
Definition: classes.h:5
bool checkPassFilter(double charge, double discriminant, std::vector< std::pair< double, double > > &cuts, int side)
void setHBHEPileupCorrection(boost::shared_ptr< AbsOOTPileupCorrection > corr)
int size() const
get the size
Definition: CaloSamples.h:24
boost::shared_ptr< AbsOOTPileupCorrection > hbhePileupCorr_
void setPulseShapeFlags(HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
const BunchXParameter * mBunchCrossingInfo
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
const HcalDetId & id() const
Definition: HBHEDataFrame.h:22