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 
15 
19 
23 
27 
30 //---------------------------------------------------------------------------
32 {
33  //
34  // Argumentless constructor; should not be used
35  //
36  // If arguments not properly specified for the constructor, I don't think
37  // we'd trust the flagging algorithm.
38  // Set the minimum charge threshold large enough so that nothing will be flagged.
39  //
40 
41  mMinimumChargeThreshold = 99999999;
42  mTS4TS5ChargeThreshold = 99999999;
43  mFirst = 4;
44  mLast = 6;
47 }
48 //---------------------------------------------------------------------------
49 HBHENegativeFlagSetter::HBHENegativeFlagSetter(double minimumChargeThreshold,
50  double tS4TS5ChargeThreshold, int first, int last,
51  std::vector<double> threshold, std::vector<double> cut)
52 {
53  //
54  // The constructor that should be used
55  //
56  // Copies various thresholds and limits and parameters to the class for future use.
57  //
58 
59  mMinimumChargeThreshold = minimumChargeThreshold;
60  mTS4TS5ChargeThreshold = tS4TS5ChargeThreshold;
61  mFirst = first;
62  mLast = last;
63 
64  if (mFirst < 2 || mLast < mFirst)
65  throw cms::Exception("Invalid mFirst, mLast specification");
66 
69 
70  for(int i = 0; i < (int)std::min(threshold.size(), cut.size()); i++)
71  mCut.push_back(std::pair<double, double>(threshold[i], cut[i]));
72  std::sort(mCut.begin(), mCut.end());
73 }
74 //---------------------------------------------------------------------------
76 {
77  // Dummy destructor - there's nothing to destruct by hand here
78 }
79 //---------------------------------------------------------------------------
81  const HBHEDataFrame &digi,
82  const HcalCoder &coder,
83  const HcalCalibrations &calib)
84 {
85  //
86  // Decide if a digi/pulse is good or bad using negative energy discriminants
87  //
88  // SetPulseShapeFlags determines the total charge in the digi.
89  // If the charge is above the minimum threshold, the code then
90  // runs the flag-setting algorithms to determine whether the
91  // flags should be set.
92  //
93 
94  const OOTPileupCorrData* corrObj = dynamic_cast<OOTPileupCorrData*>(hbhePileupCorr_.get());
95  if (corrObj)
96  {
98  coder.adc2fC(digi,cs);
99  const int nRead = cs.size();
100 
101  double ts[CaloSamples::MAXSAMPLES];
102  for (int i=0; i < nRead; i++)
103  {
104  const int capid = digi[i].capid();
105  ts[i] = cs[i] - calib.pedestal(capid);
106  }
107 
108  double ChargeInWindow = 0.0;
109  for(int i = mFirst; i <= mLast && i < CaloSamples::MAXSAMPLES; i++)
110  ChargeInWindow += ts[i];
111  if(ChargeInWindow < mMinimumChargeThreshold)
112  return;
113 
114  const OOTPileupCorrDataFcn& fcn = corrObj->getCorrectionByID(hbhe.id());
115  const PiecewiseScalingPolynomial& a1 = fcn.getA1();
116  const PiecewiseScalingPolynomial& a2 = fcn.getA2();
117 
118  bool passes = true;
119  for (int i = mFirst; i <= mLast && passes; i++)
120  {
121  const double ecorr = ts[i] - a1(ts[i-1]) - a2(ts[i-2]);
122  passes = checkPassFilter(ChargeInWindow, ecorr, mCut, -1);
123  }
124  if (!passes)
126  }
127 }
128 //---------------------------------------------------------------------------
129 void HBHENegativeFlagSetter::setHBHEPileupCorrection(boost::shared_ptr<AbsOOTPileupCorrection> corr)
130 {
132 }
133 //---------------------------------------------------------------------------
134 void HBHENegativeFlagSetter::setBXInfo(const BunchXParameter *info, unsigned length)
135 {
137  mLengthBunchCrossingInfo = length;
138 }
139 //---------------------------------------------------------------------------
141  double discriminant,
142  std::vector<std::pair<double, double> > &cuts,
143  int side)
144 {
145  //
146  // Checks whether Discriminant value passes Cuts for the specified Charge. True if pulse is good.
147  //
148  // The "Cuts" pairs are assumed to be sorted in terms of size from small to large,
149  // where each "pair" = (Charge, Discriminant)
150  // "Side" is either positive or negative, which determines whether to discard the pulse if discriminant
151  // is greater or smaller than the cut value
152  //
153 
154  if(cuts.size() == 0) // safety check that there are some cuts defined
155  return true;
156 
157  if(charge <= cuts[0].first) // too small to cut on
158  return true;
159 
160  int indexLargerThanCharge = -1; // find the range it is falling in
161  for(int i = 1; i < (int)cuts.size(); i++)
162  {
163  if(cuts[i].first > charge)
164  {
165  indexLargerThanCharge = i;
166  break;
167  }
168  }
169 
170  double limit = 1000000;
171 
172  if(indexLargerThanCharge == -1) // if charge is greater than the last entry, assume flat line
173  limit = cuts[cuts.size()-1].second;
174  else // otherwise, do a linear interpolation to find the cut position
175  {
176  double C1 = cuts[indexLargerThanCharge].first;
177  double C2 = cuts[indexLargerThanCharge-1].first;
178  double L1 = cuts[indexLargerThanCharge].second;
179  double L2 = cuts[indexLargerThanCharge-1].second;
180 
181  limit = (charge - C1) / (C2 - C1) * (L2 - L1) + L1;
182  }
183 
184  if(side > 0 && discriminant > limit)
185  return false;
186  if(side < 0 && discriminant < limit)
187  return false;
188 
189  return true;
190 }
191 //---------------------------------------------------------------------------
192 
193 
int i
Definition: DBlmapReader.cc:9
const PiecewiseScalingPolynomial & getA1() const
static const TGPicture * info(bool iBackgroundIsBlack)
auto_ptr< ClusterSequence > cs
void setBXInfo(const BunchXParameter *info, unsigned length)
static const int MAXSAMPLES
Definition: CaloSamples.h:73
HcalDetId id() const
get the id
Definition: HBHERecHit.h:23
const PiecewiseScalingPolynomial & getA2() const
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
T min(T a, T b)
Definition: MathUtil.h:58
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
void fcn(int &, double *, double &, double *, int)
boost::shared_ptr< AbsOOTPileupCorrection > hbhePileupCorr_
const OOTPileupCorrDataFcn & getCorrectionByID(const HcalDetId &id) const
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