65 mLambdaLinearCut.push_back(std::pair<double, double>(LinearThreshold[
i], LinearCut[i]));
69 mLambdaRMS8MaxCut.push_back(std::pair<double, double>(RMS8MaxThreshold[i], RMS8MaxCut[i]));
73 mLeftSlopeCut.push_back(std::pair<double, double>(LeftSlopeThreshold[i], LeftSlopeCut[i]));
77 mRightSlopeCut.push_back(std::pair<double, double>(RightSlopeThreshold[i], RightSlopeCut[i]));
81 mRightSlopeSmallCut.push_back(std::pair<double, double>(RightSlopeSmallThreshold[i], RightSlopeSmallCut[i]));
85 mTS4TS5UpperCut.push_back(std::pair<double, double>(TS4TS5UpperThreshold[i], TS4TS5UpperCut[i]));
89 mTS4TS5LowerCut.push_back(std::pair<double, double>(TS4TS5LowerThreshold[i], TS4TS5LowerCut[i]));
123 std::vector<double> PulseShape;
128 PulseShape.reserve(350);
129 for(
int i = 0;
i < 200;
i++)
130 PulseShape.push_back(HPDShape.
at(
i));
131 PulseShape.insert(PulseShape.begin(), 150, 0);
136 for(
unsigned int i = 1;
i < PulseShape.size();
i++)
156 int DigiSize = Charge.size();
159 double MinimumRightChi2 = 1000000;
160 double Numerator = 0;
161 double Denominator = 0;
175 double BestSlope = 0;
176 if (Denominator!=0) BestSlope = Numerator / Denominator;
205 for(
int i = iTS;
i < DigiSize;
i++)
206 Chi2 += Charge[
i] * Charge[
i];
208 if(Chi2 < MinimumRightChi2)
210 MinimumRightChi2 =
Chi2;
216 double MinimumLeftChi2 = 1000000;
229 double BestSlope = 0;
230 if (Denominator!=0) BestSlope = Numerator / Denominator;
251 for(
int i = 0;
i < iTS;
i++)
252 Chi2 += Charge[
i] * Charge[
i];
257 if(MinimumLeftChi2 > Chi2)
259 MinimumLeftChi2 =
Chi2;
264 result.
Chi2 = MinimumLeftChi2 + MinimumRightChi2;
278 int DigiSize = Charge.size();
280 double MinimumChi2 = 100000;
298 for(
int j = 0;
j < DigiSize;
j++)
307 SumF2 += F * F / ErrorTemp;
308 SumTF += F * Charge[
j] / ErrorTemp;
309 SumT2 += fabs(Charge[
j]);
323 double Chi2 = SumT2 - SumTF * SumTF / SumF2;
325 if(Chi2 < MinimumChi2)
330 if(MinimumChi2 < 1
e-5)
346 double OverallMinimumChi2 = 1000000;
348 int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
353 for(
int k = 0;
k < 6;
k++)
355 double SingleMinimumChi2 = 1000000;
363 if(Chi2 < SingleMinimumChi2)
365 SingleMinimumChi2 =
Chi2;
374 if(Chi2 < SingleMinimumChi2)
375 SingleMinimumChi2 =
Chi2;
379 if(SingleMinimumChi2 < OverallMinimumChi2)
380 OverallMinimumChi2 = SingleMinimumChi2;
383 return OverallMinimumChi2;
398 int DigiSize = Charge.size();
406 f1_.resize(DigiSize);
407 f2_.resize(DigiSize);
409 for(
int j = 0;
j < DigiSize;
j++)
425 for(
int j = 0;
j < DigiSize;
j++)
433 int OffsetTemp = Offset +
j * 25 + Distance;
439 if(OffsetTemp + 25 >= (
int)cipSize)
440 C1 = CumulativeIdealPulse[cipSize-1];
442 if( OffsetTemp >= -25)
443 C1 = CumulativeIdealPulse[OffsetTemp+25];
444 if(OffsetTemp >= (
int)cipSize)
445 C2 = CumulativeIdealPulse[cipSize-1];
448 C2 = CumulativeIdealPulse[OffsetTemp];
454 SumTF1 +=
f1_[
j] * Charge[
j] * errors_[
j];
455 SumTF2 +=
f2_[
j] * Charge[
j] * errors_[
j];
460 if (fabs(SumF1F2*SumF1F2-SumF1F1*SumF2F2)>1
e-5)
462 Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
463 Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
467 for(
int j = 0;
j < DigiSize;
j++)
469 double Residual = Height *
f1_[
j] + Height2 *
f2_[
j] - Charge[
j];
470 Chi2 += Residual * Residual *
errors_[
j];
491 int DigiSize = Charge.size();
493 if (DigiSize<=2)
return 1
e-5;
495 std::vector<double> TempCharge = Charge;
498 sort(TempCharge.begin(), TempCharge.end());
502 for(
int i = 0;
i < DigiSize - 2;
i++)
504 Total = Total + TempCharge[
i];
505 Total2 = Total2 + TempCharge[
i] * TempCharge[
i];
514 double RMS =
sqrt(Total2 - Total * Total / (DigiSize - 2));
516 double RMS8Max = RMS / TempCharge[DigiSize-1];
533 int DigiSize = Charge.size();
535 double SumTS2OverTi = 0;
536 double SumTSOverTi = 0;
537 double SumOverTi = 0;
542 for(
int i = 0;
i < DigiSize;
i++)
548 SumTS2OverTi += 1.*
i *
i / Error2;
549 SumTSOverTi += 1.*
i / Error2;
550 SumOverTi += 1. / Error2;
551 SumTiTS += Charge[
i] *
i / Error2;
552 SumTi += Charge[
i] / Error2;
555 double CM1 = SumTS2OverTi;
556 double CM2 = SumTSOverTi;
557 double CD1 = SumTSOverTi;
558 double CD2 = SumOverTi;
563 double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
564 double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
568 for(
int i = 0;
i < DigiSize;
i++)
570 double Deviation = Slope *
i + Intercept - Charge[
i];
571 double Error2 = Charge[
i];
574 Chi2 += Deviation * Deviation / Error2;
586 std::vector<std::pair<double, double> > &Cuts,
601 if(Charge <= Cuts[0].
first)
604 int IndexLargerThanCharge = -1;
605 for(
int i = 1;
i < (
int)Cuts.size();
i++)
607 if(Cuts[
i].first > Charge)
609 IndexLargerThanCharge =
i;
614 double limit = 1000000;
616 if(IndexLargerThanCharge == -1)
617 limit = Cuts[Cuts.size()-1].second;
620 double C1 = Cuts[IndexLargerThanCharge].first;
621 double C2 = Cuts[IndexLargerThanCharge-1].first;
622 double L1 = Cuts[IndexLargerThanCharge].second;
623 double L2 = Cuts[IndexLargerThanCharge-1].second;
625 limit = (Charge - C1) / (C2 - C1) * (L2 - L1) + L1;
628 if(Side > 0 && Discriminant > limit)
630 if(Side < 0 && Discriminant < limit)
std::vector< double > f1_
double mMinimumChargeThreshold
std::vector< std::pair< double, double > > mLambdaLinearCut
HBHEPulseShapeFlagSetter(double MinimumChargeThreshold, double TS4TS5ChargeThreshold, double TS3TS4ChargeThreshold, double TS3TS4UpperChargeThreshold, double TS5TS6ChargeThreshold, double TS5TS6UpperChargeThreshold, double R45PlusOneRange, double R45MinusOneRange, unsigned int TrianglePeakTS, const std::vector< double > &LinearThreshold, const std::vector< double > &LinearCut, const std::vector< double > &RMS8MaxThreshold, const std::vector< double > &RMS8MaxCut, const std::vector< double > &LeftSlopeThreshold, const std::vector< double > &LeftSlopeCut, const std::vector< double > &RightSlopeThreshold, const std::vector< double > &RightSlopeCut, const std::vector< double > &RightSlopeSmallThreshold, const std::vector< double > &RightSlopeSmallCut, const std::vector< double > &TS4TS5UpperThreshold, const std::vector< double > &TS4TS5UpperCut, const std::vector< double > &TS4TS5LowerThreshold, const std::vector< double > &TS4TS5LowerCut, bool UseDualFit, bool TriangleIgnoreSlow, bool setLegacyFlags=true)
float at(double time) const
double mTS5TS6UpperChargeThreshold
std::vector< double > f2_
double mTS3TS4ChargeThreshold
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)
double mTS4TS5ChargeThreshold
std::vector< std::pair< double, double > > mRightSlopeCut
bool CheckPassFilter(double Charge, double Discriminant, std::vector< std::pair< double, double > > &Cuts, int Side)
TS5TS6UpperChargeThreshold
std::vector< double > mCharge
std::vector< std::pair< double, double > > mRightSlopeSmallCut
double mTS3TS4UpperChargeThreshold
double mTS5TS6ChargeThreshold
const Shape & hbShape() const
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
TS3TS4UpperChargeThreshold