47 double TS4TS5ChargeThreshold,
48 double TS3TS4ChargeThreshold,
49 double TS3TS4UpperChargeThreshold,
50 double TS5TS6ChargeThreshold,
51 double TS5TS6UpperChargeThreshold,
52 double R45PlusOneRange,
53 double R45MinusOneRange,
54 unsigned int TrianglePeakTS,
55 const std::vector<double>& LinearThreshold,
56 const std::vector<double>& LinearCut,
57 const std::vector<double>& RMS8MaxThreshold,
58 const std::vector<double>& RMS8MaxCut,
59 const std::vector<double>& LeftSlopeThreshold,
60 const std::vector<double>& LeftSlopeCut,
61 const std::vector<double>& RightSlopeThreshold,
62 const std::vector<double>& RightSlopeCut,
63 const std::vector<double>& RightSlopeSmallThreshold,
64 const std::vector<double>& RightSlopeSmallCut,
70 bool TriangleIgnoreSlow)
91 mLambdaLinearCut.push_back(std::pair<double, double>(LinearThreshold[
i], LinearCut[i]));
95 mLambdaRMS8MaxCut.push_back(std::pair<double, double>(RMS8MaxThreshold[i], RMS8MaxCut[i]));
99 mLeftSlopeCut.push_back(std::pair<double, double>(LeftSlopeThreshold[i], LeftSlopeCut[i]));
103 mRightSlopeCut.push_back(std::pair<double, double>(RightSlopeThreshold[i], RightSlopeCut[i]));
107 mRightSlopeSmallCut.push_back(std::pair<double, double>(RightSlopeSmallThreshold[i], RightSlopeSmallCut[i]));
111 mTS4TS5UpperCut.push_back(std::pair<double, double>(TS4TS5UpperThreshold[i], TS4TS5UpperCut[i]));
115 mTS4TS5LowerCut.push_back(std::pair<double, double>(TS4TS5LowerThreshold[i], TS4TS5LowerCut[i]));
149 if(abseta == 28 || abseta == 29)
return;
157 double TotalCharge = 0;
159 for(
int i = 0;
i < digi.
size(); ++
i)
169 double NominalChi2 = 0;
190 double TS4Left = 1000;
191 double TS4Right = 1000;
199 if(TS4Left > 1000 || TS4Left < -1000)
201 if(TS4Right > 1000 || TS4Right < -1000)
269 std::vector<double> PulseShape;
274 PulseShape.reserve(350);
275 for(
int i = 0;
i < 200;
i++)
276 PulseShape.push_back(HPDShape.
at(
i));
277 PulseShape.insert(PulseShape.begin(), 150, 0);
282 for(
unsigned int i = 1;
i < PulseShape.size();
i++)
302 int DigiSize = Charge.size();
305 double MinimumRightChi2 = 1000000;
306 double Numerator = 0;
307 double Denominator = 0;
321 double BestSlope = 0;
322 if (Denominator!=0) BestSlope = Numerator / Denominator;
351 for(
int i = iTS;
i < DigiSize;
i++)
352 Chi2 += Charge[
i] * Charge[
i];
354 if(Chi2 < MinimumRightChi2)
356 MinimumRightChi2 = Chi2;
362 double MinimumLeftChi2 = 1000000;
375 double BestSlope = 0;
376 if (Denominator!=0) BestSlope = Numerator / Denominator;
397 for(
int i = 0;
i < iTS;
i++)
398 Chi2 += Charge[
i] * Charge[
i];
403 if(MinimumLeftChi2 > Chi2)
405 MinimumLeftChi2 = Chi2;
410 result.
Chi2 = MinimumLeftChi2 + MinimumRightChi2;
424 int DigiSize = Charge.size();
426 double MinimumChi2 = 100000;
444 for(
int j = 0;
j < DigiSize;
j++)
453 SumF2 += F * F / ErrorTemp;
454 SumTF += F * Charge[
j] / ErrorTemp;
455 SumT2 += fabs(Charge[
j]);
469 double Chi2 = SumT2 - SumTF * SumTF / SumF2;
471 if(Chi2 < MinimumChi2)
476 if(MinimumChi2 < 1
e-5)
492 double OverallMinimumChi2 = 1000000;
494 int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
499 for(
int k = 0;
k < 6;
k++)
501 double SingleMinimumChi2 = 1000000;
509 if(Chi2 < SingleMinimumChi2)
511 SingleMinimumChi2 = Chi2;
520 if(Chi2 < SingleMinimumChi2)
521 SingleMinimumChi2 = Chi2;
525 if(SingleMinimumChi2 < OverallMinimumChi2)
526 OverallMinimumChi2 = SingleMinimumChi2;
529 return OverallMinimumChi2;
544 int DigiSize = Charge.size();
552 f1_.resize(DigiSize);
553 f2_.resize(DigiSize);
555 for(
int j = 0;
j < DigiSize;
j++)
571 for(
int j = 0;
j < DigiSize;
j++)
579 int OffsetTemp = Offset +
j * 25 + Distance;
585 if(OffsetTemp + 25 >= (
int)cipSize)
586 C1 = CumulativeIdealPulse[cipSize-1];
588 if( OffsetTemp >= -25)
589 C1 = CumulativeIdealPulse[OffsetTemp+25];
590 if(OffsetTemp >= (
int)cipSize)
591 C2 = CumulativeIdealPulse[cipSize-1];
594 C2 = CumulativeIdealPulse[OffsetTemp];
600 SumTF1 +=
f1_[
j] * Charge[
j] * errors_[
j];
601 SumTF2 +=
f2_[
j] * Charge[
j] * errors_[
j];
606 if (fabs(SumF1F2*SumF1F2-SumF1F1*SumF2F2)>1
e-5)
608 Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
609 Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
613 for(
int j = 0;
j < DigiSize;
j++)
615 double Residual = Height *
f1_[
j] + Height2 *
f2_[
j] - Charge[
j];
616 Chi2 += Residual * Residual *
errors_[
j];
637 int DigiSize = Charge.size();
639 if (DigiSize<=2)
return 1
e-5;
641 std::vector<double> TempCharge = Charge;
644 sort(TempCharge.begin(), TempCharge.end());
648 for(
int i = 0;
i < DigiSize - 2;
i++)
650 Total = Total + TempCharge[
i];
651 Total2 = Total2 + TempCharge[
i] * TempCharge[
i];
660 double RMS =
sqrt(Total2 - Total * Total / (DigiSize - 2));
662 double RMS8Max = RMS / TempCharge[DigiSize-1];
666 return RMS / TempCharge[DigiSize-1];
679 int DigiSize = Charge.size();
681 double SumTS2OverTi = 0;
682 double SumTSOverTi = 0;
683 double SumOverTi = 0;
688 for(
int i = 0;
i < DigiSize;
i++)
694 SumTS2OverTi += 1.*
i *
i / Error2;
695 SumTSOverTi += 1.*
i / Error2;
696 SumOverTi += 1. / Error2;
697 SumTiTS += Charge[
i] *
i / Error2;
698 SumTi += Charge[
i] / Error2;
701 double CM1 = SumTS2OverTi;
702 double CM2 = SumTSOverTi;
703 double CD1 = SumTSOverTi;
704 double CD2 = SumOverTi;
709 double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
710 double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
714 for(
int i = 0;
i < DigiSize;
i++)
716 double Deviation = Slope *
i + Intercept - Charge[
i];
717 double Error2 = Charge[
i];
720 Chi2 += Deviation * Deviation / Error2;
732 std::vector<std::pair<double, double> > &Cuts,
747 if(Charge <= Cuts[0].
first)
750 int IndexLargerThanCharge = -1;
751 for(
int i = 1;
i < (int)Cuts.size();
i++)
753 if(Cuts[
i].first > Charge)
755 IndexLargerThanCharge =
i;
760 double limit = 1000000;
762 if(IndexLargerThanCharge == -1)
763 limit = Cuts[Cuts.size()-1].second;
766 double C1 = Cuts[IndexLargerThanCharge].first;
767 double C2 = Cuts[IndexLargerThanCharge-1].first;
768 double L1 = Cuts[IndexLargerThanCharge].second;
769 double L2 = Cuts[IndexLargerThanCharge-1].second;
771 limit = (Charge - C1) / (C2 - C1) * (L2 - L1) + L1;
774 if(Side > 0 && Discriminant > limit)
776 if(Side < 0 && Discriminant < limit)
std::vector< double > f1_
double mMinimumChargeThreshold
std::vector< std::pair< double, double > > mLambdaLinearCut
float at(double time) const
double mTS5TS6UpperChargeThreshold
std::vector< double > f2_
int size() const
total number of samples in the digi
double mTS3TS4ChargeThreshold
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
tuple TS4TS5UpperThreshold
TriangleFitResult PerformTriangleFit(const std::vector< double > &Charge)
tuple TS4TS5LowerThreshold
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
double mTS3TS4UpperChargeThreshold
int capid() const
get the Capacitor id
const HcalQIESample & sample(int i) const
access a sample
double mTS5TS6ChargeThreshold
const Shape & hbShape() const
virtual void adc2fC(const HBHEDataFrame &df, CaloSamples &lf) const =0
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