38 double TS4TS5ChargeThreshold,
39 unsigned int TrianglePeakTS,
40 const std::vector<double>& LinearThreshold,
41 const std::vector<double>& LinearCut,
42 const std::vector<double>& RMS8MaxThreshold,
43 const std::vector<double>& RMS8MaxCut,
44 const std::vector<double>& LeftSlopeThreshold,
45 const std::vector<double>& LeftSlopeCut,
46 const std::vector<double>& RightSlopeThreshold,
47 const std::vector<double>& RightSlopeCut,
48 const std::vector<double>& RightSlopeSmallThreshold,
49 const std::vector<double>& RightSlopeSmallCut,
55 bool TriangleIgnoreSlow)
70 mLambdaLinearCut.push_back(std::pair<double, double>(LinearThreshold[
i], LinearCut[i]));
74 mLambdaRMS8MaxCut.push_back(std::pair<double, double>(RMS8MaxThreshold[i], RMS8MaxCut[i]));
78 mLeftSlopeCut.push_back(std::pair<double, double>(LeftSlopeThreshold[i], LeftSlopeCut[i]));
82 mRightSlopeCut.push_back(std::pair<double, double>(RightSlopeThreshold[i], RightSlopeCut[i]));
86 mRightSlopeSmallCut.push_back(std::pair<double, double>(RightSlopeSmallThreshold[i], RightSlopeSmallCut[i]));
90 mTS4TS5UpperCut.push_back(std::pair<double, double>(TS4TS5UpperThreshold[i], TS4TS5UpperCut[i]));
94 mTS4TS5LowerCut.push_back(std::pair<double, double>(TS4TS5LowerThreshold[i], TS4TS5LowerCut[i]));
128 if(abseta == 28 || abseta == 29)
return;
136 double TotalCharge = 0;
138 for(
int i = 0;
i < digi.
size(); ++
i)
148 double NominalChi2 = 0;
169 double TS4Left = 1000;
170 double TS4Right = 1000;
178 if(TS4Left > 1000 || TS4Left < -1000)
180 if(TS4Right > 1000 || TS4Right < -1000)
222 std::vector<double> PulseShape;
227 PulseShape.reserve(350);
228 for(
int i = 0;
i < 200;
i++)
229 PulseShape.push_back(HPDShape.
at(
i));
230 PulseShape.insert(PulseShape.begin(), 150, 0);
235 for(
unsigned int i = 1;
i < PulseShape.size();
i++)
255 int DigiSize = Charge.size();
258 double MinimumRightChi2 = 1000000;
259 double Numerator = 0;
260 double Denominator = 0;
274 double BestSlope = 0;
275 if (Denominator!=0) BestSlope = Numerator / Denominator;
304 for(
int i = iTS;
i < DigiSize;
i++)
305 Chi2 += Charge[
i] * Charge[
i];
307 if(Chi2 < MinimumRightChi2)
309 MinimumRightChi2 = Chi2;
315 double MinimumLeftChi2 = 1000000;
328 double BestSlope = 0;
329 if (Denominator!=0) BestSlope = Numerator / Denominator;
350 for(
int i = 0;
i < iTS;
i++)
351 Chi2 += Charge[
i] * Charge[
i];
356 if(MinimumLeftChi2 > Chi2)
358 MinimumLeftChi2 = Chi2;
363 result.
Chi2 = MinimumLeftChi2 + MinimumRightChi2;
377 int DigiSize = Charge.size();
379 double MinimumChi2 = 100000;
397 for(
int j = 0;
j < DigiSize;
j++)
406 SumF2 += F * F / ErrorTemp;
407 SumTF += F * Charge[
j] / ErrorTemp;
408 SumT2 += fabs(Charge[
j]);
422 double Chi2 = SumT2 - SumTF * SumTF / SumF2;
424 if(Chi2 < MinimumChi2)
429 if(MinimumChi2 < 1
e-5)
445 double OverallMinimumChi2 = 1000000;
447 int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
452 for(
int k = 0;
k < 6;
k++)
454 double SingleMinimumChi2 = 1000000;
462 if(Chi2 < SingleMinimumChi2)
464 SingleMinimumChi2 = Chi2;
473 if(Chi2 < SingleMinimumChi2)
474 SingleMinimumChi2 = Chi2;
478 if(SingleMinimumChi2 < OverallMinimumChi2)
479 OverallMinimumChi2 = SingleMinimumChi2;
482 return OverallMinimumChi2;
497 int DigiSize = Charge.size();
505 f1_.resize(DigiSize);
506 f2_.resize(DigiSize);
508 for(
int j = 0;
j < DigiSize;
j++)
524 for(
int j = 0;
j < DigiSize;
j++)
532 int OffsetTemp = Offset +
j * 25 + Distance;
538 if(OffsetTemp + 25 >= (
int)cipSize)
539 C1 = CumulativeIdealPulse[cipSize-1];
541 if( OffsetTemp >= -25)
542 C1 = CumulativeIdealPulse[OffsetTemp+25];
543 if(OffsetTemp >= (
int)cipSize)
544 C2 = CumulativeIdealPulse[cipSize-1];
547 C2 = CumulativeIdealPulse[OffsetTemp];
553 SumTF1 +=
f1_[
j] * Charge[
j] * errors_[
j];
554 SumTF2 +=
f2_[
j] * Charge[
j] * errors_[
j];
559 if (fabs(SumF1F2*SumF1F2-SumF1F1*SumF2F2)>1
e-5)
561 Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
562 Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
566 for(
int j = 0;
j < DigiSize;
j++)
568 double Residual = Height *
f1_[
j] + Height2 *
f2_[
j] - Charge[
j];
569 Chi2 += Residual * Residual *
errors_[
j];
590 int DigiSize = Charge.size();
592 if (DigiSize<=2)
return 1
e-5;
594 std::vector<double> TempCharge = Charge;
597 sort(TempCharge.begin(), TempCharge.end());
601 for(
int i = 0;
i < DigiSize - 2;
i++)
603 Total = Total + TempCharge[
i];
604 Total2 = Total2 + TempCharge[
i] * TempCharge[
i];
613 double RMS =
sqrt(Total2 - Total * Total / (DigiSize - 2));
615 double RMS8Max = RMS / TempCharge[DigiSize-1];
619 return RMS / TempCharge[DigiSize-1];
632 int DigiSize = Charge.size();
634 double SumTS2OverTi = 0;
635 double SumTSOverTi = 0;
636 double SumOverTi = 0;
641 for(
int i = 0;
i < DigiSize;
i++)
647 SumTS2OverTi += 1.*
i *
i / Error2;
648 SumTSOverTi += 1.*
i / Error2;
649 SumOverTi += 1. / Error2;
650 SumTiTS += Charge[
i] *
i / Error2;
651 SumTi += Charge[
i] / Error2;
654 double CM1 = SumTS2OverTi;
655 double CM2 = SumTSOverTi;
656 double CD1 = SumTSOverTi;
657 double CD2 = SumOverTi;
662 double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
663 double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
667 for(
int i = 0;
i < DigiSize;
i++)
669 double Deviation = Slope *
i + Intercept - Charge[
i];
670 double Error2 = Charge[
i];
673 Chi2 += Deviation * Deviation / Error2;
685 std::vector<std::pair<double, double> > &Cuts,
700 if(Charge <= Cuts[0].
first)
703 int IndexLargerThanCharge = -1;
704 for(
int i = 1;
i < (int)Cuts.size();
i++)
706 if(Cuts[
i].first > Charge)
708 IndexLargerThanCharge =
i;
713 double limit = 1000000;
715 if(IndexLargerThanCharge == -1)
716 limit = Cuts[Cuts.size()-1].second;
719 double C1 = Cuts[IndexLargerThanCharge].first;
720 double C2 = Cuts[IndexLargerThanCharge-1].first;
721 double L1 = Cuts[IndexLargerThanCharge].second;
722 double L2 = Cuts[IndexLargerThanCharge-1].second;
724 limit = (Charge - C1) / (C2 - C1) * (L2 - L1) + L1;
727 if(Side > 0 && Discriminant > limit)
729 if(Side < 0 && Discriminant < limit)
std::vector< double > f1_
double mMinimumChargeThreshold
std::vector< std::pair< double, double > > mLambdaLinearCut
float at(double time) const
std::vector< double > f2_
int size() const
total number of samples in the digi
HcalDetId id() const
get the id
void setFlagField(uint32_t value, int base, int width=1)
double pedestal(int fCapId) const
get pedestal for capid=0..3
double CalculateRMS8Max(const std::vector< double > &Charge)
std::vector< std::pair< double, double > > mTS4TS5LowerCut
double PerformNominalFit(const std::vector< double > &Charge)
double DualNominalFitSingleTry(const std::vector< double > &Charge, int Offset, int Distance, bool newCharges=true)
double PerformDualNominalFit(const std::vector< double > &Charge)
~HBHEPulseShapeFlagSetter()
double PerformLinearFit(const std::vector< double > &Charge)
std::vector< std::pair< double, double > > mLeftSlopeCut
TriangleFitResult PerformTriangleFit(const std::vector< double > &Charge)
MVATrainerComputer * calib
double mTS4TS5ChargeThreshold
HBHEPulseShapeFlagSetter()
std::vector< std::pair< double, double > > mRightSlopeCut
bool CheckPassFilter(double Charge, double Discriminant, std::vector< std::pair< double, double > > &Cuts, int Side)
int ietaAbs() const
get the absolute value of the cell ieta
std::vector< double > mCharge
std::vector< std::pair< double, double > > mRightSlopeSmallCut
int capid() const
get the Capacitor id
const HcalQIESample & sample(int i) const
access a sample
tuple TS4TS5LowerThreshold
const Shape & hbShape() const
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
tuple TS4TS5UpperThreshold
void SetPulseShapeFlags(HBHERecHit &hbhe, const HBHEDataFrame &digi, const HcalCoder &coder, const HcalCalibrations &calib)
std::vector< double > errors_
std::vector< double > CumulativeIdealPulse
std::vector< std::pair< double, double > > mLambdaRMS8MaxCut
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
std::vector< std::pair< double, double > > mTS4TS5UpperCut