42 bool setLegacyFlags) {
118 std::vector<double> PulseShape;
123 PulseShape.reserve(350);
124 for (
int i = 0;
i < 200;
i++)
125 PulseShape.push_back(HPDShape.
at(
i));
126 PulseShape.insert(PulseShape.begin(), 150, 0);
131 for (
unsigned int i = 1;
i < PulseShape.size();
i++)
150 int DigiSize =
Charge.size();
153 double MinimumRightChi2 = 1000000;
154 double Numerator = 0;
155 double Denominator = 0;
168 double BestSlope = 0;
169 if (Denominator != 0)
170 BestSlope = Numerator / Denominator;
175 if (iTS != DigiSize) {
196 for (
int i = iTS;
i < DigiSize;
i++)
199 if (
Chi2 < MinimumRightChi2) {
200 MinimumRightChi2 =
Chi2;
201 result.RightSlope = BestSlope;
206 double MinimumLeftChi2 = 1000000;
218 double BestSlope = 0;
219 if (Denominator != 0)
220 BestSlope = Numerator / Denominator;
238 for (
int i = 0;
i < iTS;
i++)
244 if (MinimumLeftChi2 >
Chi2) {
245 MinimumLeftChi2 =
Chi2;
246 result.LeftSlope = BestSlope;
250 result.Chi2 = MinimumLeftChi2 + MinimumRightChi2;
263 int DigiSize =
Charge.size();
265 double MinimumChi2 = 100000;
281 double ErrorTemp = 0;
282 for (
int j = 0;
j < DigiSize;
j++) {
290 SumF2 +=
F *
F / ErrorTemp;
306 double Chi2 = SumT2 - SumTF * SumTF / SumF2;
308 if (
Chi2 < MinimumChi2)
313 if (MinimumChi2 < 1
e-5)
328 double OverallMinimumChi2 = 1000000;
330 int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
335 for (
int k = 0;
k < 6;
k++) {
336 double SingleMinimumChi2 = 1000000;
343 if (
Chi2 < SingleMinimumChi2) {
344 SingleMinimumChi2 =
Chi2;
352 if (
Chi2 < SingleMinimumChi2)
353 SingleMinimumChi2 =
Chi2;
357 if (SingleMinimumChi2 < OverallMinimumChi2)
358 OverallMinimumChi2 = SingleMinimumChi2;
361 return OverallMinimumChi2;
378 int DigiSize =
Charge.size();
386 f1_.resize(DigiSize);
387 f2_.resize(DigiSize);
389 for (
int j = 0;
j < DigiSize;
j++) {
404 for (
int j = 0;
j < DigiSize;
j++) {
411 int OffsetTemp = Offset +
j * 25 + Distance;
416 if (OffsetTemp + 25 >= (
int)cipSize)
418 else if (OffsetTemp >= -25)
420 if (OffsetTemp >= (
int)cipSize)
422 else if (OffsetTemp >= 0)
435 if (fabs(SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2) > 1
e-5) {
436 Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
437 Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
441 for (
int j = 0;
j < DigiSize;
j++) {
463 int DigiSize =
Charge.size();
468 std::vector<double> TempCharge =
Charge;
471 sort(TempCharge.begin(), TempCharge.end());
475 for (
int i = 0;
i < DigiSize - 2;
i++) {
477 Total2 = Total2 + TempCharge[
i] * TempCharge[
i];
488 double RMS8Max =
RMS / TempCharge[DigiSize - 1];
504 int DigiSize =
Charge.size();
506 double SumTS2OverTi = 0;
507 double SumTSOverTi = 0;
508 double SumOverTi = 0;
513 for (
int i = 0;
i < DigiSize;
i++) {
518 SumTS2OverTi += 1. *
i *
i / Error2;
519 SumTSOverTi += 1. *
i / Error2;
520 SumOverTi += 1. / Error2;
525 double CM1 = SumTS2OverTi;
526 double CM2 = SumTSOverTi;
527 double CD1 = SumTSOverTi;
528 double CD2 = SumOverTi;
533 double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
534 double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
538 for (
int i = 0;
i < DigiSize;
i++) {
572 int IndexLargerThanCharge = -1;
573 for (
int i = 1;
i < (
int)Cuts.size();
i++) {
575 IndexLargerThanCharge =
i;
580 double limit = 1000000;
582 if (IndexLargerThanCharge == -1)
583 limit = Cuts[Cuts.size() - 1].second;
586 double C1 = Cuts[IndexLargerThanCharge].first;
587 double C2 = Cuts[IndexLargerThanCharge - 1].first;
588 double L1 = Cuts[IndexLargerThanCharge].second;
589 double L2 = Cuts[IndexLargerThanCharge - 1].second;
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)
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
TS3TS4UpperChargeThreshold
std::vector< std::pair< double, double > > mRightSlopeCut
bool CheckPassFilter(double Charge, double Discriminant, std::vector< std::pair< double, double > > &Cuts, int Side)
std::vector< double > mCharge
const Shape & hbShape() const
std::vector< std::pair< double, double > > mRightSlopeSmallCut
double mTS3TS4UpperChargeThreshold
TS5TS6UpperChargeThreshold
double mTS5TS6ChargeThreshold
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
float at(double time) const