CMS 3D CMS Logo

HBHEPulseShapeFlag.cc
Go to the documentation of this file.
1 //---------------------------------------------------------------------------
2 #include <iostream>
3 #include <algorithm>
4 #include <fstream>
5 #include <cmath>
6 
7 //---------------------------------------------------------------------------
9 
11 
15 
16 //---------------------------------------------------------------------------
19  double TS4TS5ChargeThreshold,
20  double TS3TS4ChargeThreshold,
22  double TS5TS6ChargeThreshold,
24  double R45PlusOneRange,
25  double R45MinusOneRange,
26  unsigned int TrianglePeakTS,
27  const std::vector<double>& LinearThreshold,
28  const std::vector<double>& LinearCut,
29  const std::vector<double>& RMS8MaxThreshold,
30  const std::vector<double>& RMS8MaxCut,
31  const std::vector<double>& LeftSlopeThreshold,
32  const std::vector<double>& LeftSlopeCut,
33  const std::vector<double>& RightSlopeThreshold,
34  const std::vector<double>& RightSlopeCut,
35  const std::vector<double>& RightSlopeSmallThreshold,
36  const std::vector<double>& RightSlopeSmallCut,
37  const std::vector<double>& TS4TS5LowerThreshold,
38  const std::vector<double>& TS4TS5LowerCut,
39  const std::vector<double>& TS4TS5UpperThreshold,
40  const std::vector<double>& TS4TS5UpperCut,
41  bool UseDualFit,
42  bool TriangleIgnoreSlow,
43  bool setLegacyFlags)
44 {
45  //
46  // The constructor that should be used
47  //
48  // Copies various thresholds and limits and parameters to the class for future use.
49  // Also calls the Initialize() function
50  //
51 
62  mSetLegacyFlags = setLegacyFlags;
63 
64  for(std::vector<double>::size_type i = 0; i < LinearThreshold.size() && i < LinearCut.size(); i++)
65  mLambdaLinearCut.push_back(std::pair<double, double>(LinearThreshold[i], LinearCut[i]));
66  sort(mLambdaLinearCut.begin(), mLambdaLinearCut.end());
67 
68  for(std::vector<double>::size_type i = 0; i < RMS8MaxThreshold.size() && i < RMS8MaxCut.size(); i++)
69  mLambdaRMS8MaxCut.push_back(std::pair<double, double>(RMS8MaxThreshold[i], RMS8MaxCut[i]));
71 
72  for(std::vector<double>::size_type i = 0; i < LeftSlopeThreshold.size() && i < LeftSlopeCut.size(); i++)
73  mLeftSlopeCut.push_back(std::pair<double, double>(LeftSlopeThreshold[i], LeftSlopeCut[i]));
74  sort(mLeftSlopeCut.begin(), mLeftSlopeCut.end());
75 
76  for(std::vector<double>::size_type i = 0; i < RightSlopeThreshold.size() && i < RightSlopeCut.size(); i++)
77  mRightSlopeCut.push_back(std::pair<double, double>(RightSlopeThreshold[i], RightSlopeCut[i]));
78  sort(mRightSlopeCut.begin(), mRightSlopeCut.end());
79 
80  for(std::vector<double>::size_type i = 0; i < RightSlopeSmallThreshold.size() && i < RightSlopeSmallCut.size(); i++)
81  mRightSlopeSmallCut.push_back(std::pair<double, double>(RightSlopeSmallThreshold[i], RightSlopeSmallCut[i]));
83 
84  for(std::vector<double>::size_type i = 0; i < TS4TS5UpperThreshold.size() && i < TS4TS5UpperCut.size(); i++)
85  mTS4TS5UpperCut.push_back(std::pair<double, double>(TS4TS5UpperThreshold[i], TS4TS5UpperCut[i]));
86  sort(mTS4TS5UpperCut.begin(), mTS4TS5UpperCut.end());
87 
88  for(std::vector<double>::size_type i = 0; i < TS4TS5LowerThreshold.size() && i < TS4TS5LowerCut.size(); i++)
89  mTS4TS5LowerCut.push_back(std::pair<double, double>(TS4TS5LowerThreshold[i], TS4TS5LowerCut[i]));
90  sort(mTS4TS5LowerCut.begin(), mTS4TS5LowerCut.end());
91 
93 
94  Initialize();
95 }
96 //---------------------------------------------------------------------------
98 {
99  // Dummy destructor - there's nothing to destruct by hand here
100 }
101 //---------------------------------------------------------------------------
103 {
104  // Dummy function in case something needs to be cleaned....but none right now
105 }
106 //---------------------------------------------------------------------------
108 {
109  //
110  // Initialization: whatever preprocess is needed
111  //
112  // 1. Get the ideal pulse shape from CMSSW
113  //
114  // Since the HcalPulseShapes class stores the ideal pulse shape in terms of 256 numbers,
115  // each representing 1ns integral of the ideal pulse, here I'm taking out the vector
116  // by calling at() function.
117  //
118  // A cumulative distribution is formed and stored to save some time doing integration to TS later on
119  //
120  // 2. Reserve space for vector
121  //
122 
123  std::vector<double> PulseShape;
124 
125  HcalPulseShapes Shapes;
126  const HcalPulseShapes::Shape& HPDShape = Shapes.hbShape();
127 
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); // Safety margin of a lot of zeros in the beginning
132 
133  CumulativeIdealPulse.reserve(350);
134  CumulativeIdealPulse.clear();
135  CumulativeIdealPulse.push_back(0);
136  for(unsigned int i = 1; i < PulseShape.size(); i++)
137  CumulativeIdealPulse.push_back(CumulativeIdealPulse[i-1] + PulseShape[i]);
138 
139  // reserve space for vector
140  mCharge.reserve(10);
141 }
142 //---------------------------------------------------------------------------
144 {
145  //
146  // Perform a "triangle fit", and extract the slopes
147  //
148  // Left-hand side and right-hand side are not correlated to each other - do them separately
149  //
150 
152  result.Chi2 = 0;
153  result.LeftSlope = 0;
154  result.RightSlope = 0;
155 
156  int DigiSize = Charge.size();
157 
158  // right side, starting from TS4
159  double MinimumRightChi2 = 1000000;
160  double Numerator = 0;
161  double Denominator = 0;
162 
163  for(int iTS = mTrianglePeakTS + 2; iTS <= DigiSize; iTS++) // the place where first TS center in flat line
164  {
165  // fit a straight line to the triangle part
166  Numerator = 0;
167  Denominator = 0;
168 
169  for(int i = mTrianglePeakTS + 1; i < iTS; i++)
170  {
171  Numerator += (i - mTrianglePeakTS) * (Charge[i] - Charge[mTrianglePeakTS]);
172  Denominator += (i - mTrianglePeakTS) * (i - mTrianglePeakTS);
173  }
174 
175  double BestSlope = 0;
176  if (Denominator!=0) BestSlope = Numerator / Denominator;
177  if(BestSlope > 0)
178  BestSlope = 0;
179 
180  // check if the slope is reasonable
181  if(iTS != DigiSize)
182  {
183  // iTS starts at mTrianglePeak+2; denominator never zero
184  if(BestSlope > -1 * Charge[mTrianglePeakTS] / (iTS - mTrianglePeakTS))
185  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - mTrianglePeakTS);
186  if(BestSlope < -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS))
187  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS);
188  }
189  else
190  {
191  // iTS starts at mTrianglePeak+2; denominator never zero
192  if(BestSlope < -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS))
193  BestSlope = -1 * Charge[mTrianglePeakTS] / (iTS - 1 - mTrianglePeakTS);
194  }
195 
196  // calculate partial chi2
197 
198  // The shape I'm fitting is more like a tent than a triangle.
199  // After the end of triangle edge assume a flat line
200 
201  double Chi2 = 0;
202  for(int i = mTrianglePeakTS + 1; i < iTS; i++)
203  Chi2 += (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope)
204  * (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope);
205  for(int i = iTS; i < DigiSize; i++) // Assumes fit line = 0 for iTS > fit
206  Chi2 += Charge[i] * Charge[i];
207 
208  if(Chi2 < MinimumRightChi2)
209  {
210  MinimumRightChi2 = Chi2;
211  result.RightSlope = BestSlope;
212  }
213  } // end of right-hand side loop
214 
215  // left side
216  double MinimumLeftChi2 = 1000000;
217 
218  for(int iTS = 0; iTS < (int)mTrianglePeakTS; iTS++) // the first time after linear fit ends
219  {
220  // fit a straight line to the triangle part
221  Numerator = 0;
222  Denominator = 0;
223  for(int i = iTS; i < (int)mTrianglePeakTS; i++)
224  {
225  Numerator = Numerator + (i - mTrianglePeakTS) * (Charge[i] - Charge[mTrianglePeakTS]);
226  Denominator = Denominator + (i - mTrianglePeakTS) * (i - mTrianglePeakTS);
227  }
228 
229  double BestSlope = 0;
230  if (Denominator!=0) BestSlope = Numerator / Denominator;
231  if (BestSlope < 0)
232  BestSlope = 0;
233 
234  // check slope
235  if(iTS != 0)
236  {
237  // iTS must be >0 and < mTrianglePeakTS; slope never 0
238  if(BestSlope > Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS))
239  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS);
240  if(BestSlope < Charge[mTrianglePeakTS] / (mTrianglePeakTS + 1 - iTS))
241  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS + 1 - iTS);
242  }
243  else
244  {
245  if(BestSlope > Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS))
246  BestSlope = Charge[mTrianglePeakTS] / (mTrianglePeakTS - iTS);
247  }
248 
249  // calculate minimum chi2
250  double Chi2 = 0;
251  for(int i = 0; i < iTS; i++)
252  Chi2 += Charge[i] * Charge[i];
253  for(int i = iTS; i < (int)mTrianglePeakTS; i++)
254  Chi2 += (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope)
255  * (Charge[mTrianglePeakTS] - Charge[i] + (i - mTrianglePeakTS) * BestSlope);
256 
257  if(MinimumLeftChi2 > Chi2)
258  {
259  MinimumLeftChi2 = Chi2;
260  result.LeftSlope = BestSlope;
261  }
262  } // end of left-hand side loop
263 
264  result.Chi2 = MinimumLeftChi2 + MinimumRightChi2;
265 
266  return result;
267 }
268 //---------------------------------------------------------------------------
269 double HBHEPulseShapeFlagSetter::PerformNominalFit(const std::vector<double> &Charge)
270 {
271  //
272  // Performs a fit to the ideal pulse shape. Returns best chi2
273  //
274  // A scan over different timing offset (for the ideal pulse) is carried out,
275  // and for each offset setting a one-parameter fit is performed
276  //
277 
278  int DigiSize = Charge.size();
279 
280  double MinimumChi2 = 100000;
281 
282  double F = 0;
283 
284  double SumF2 = 0;
285  double SumTF = 0;
286  double SumT2 = 0;
287 
288  for(int i = 0; i + 250 < (int)CumulativeIdealPulse.size(); i++)
289  {
291  continue;
292 
293  SumF2 = 0;
294  SumTF = 0;
295  SumT2 = 0;
296 
297  double ErrorTemp=0;
298  for(int j = 0; j < DigiSize; j++)
299  {
300  // get ideal pulse component for this time slice....
301  F = CumulativeIdealPulse[i+j*25+25] - CumulativeIdealPulse[i+j*25];
302 
303  ErrorTemp=Charge[j];
304  if (ErrorTemp<1) // protection against small charges
305  ErrorTemp=1;
306  // ...and increment various summations
307  SumF2 += F * F / ErrorTemp;
308  SumTF += F * Charge[j] / ErrorTemp;
309  SumT2 += fabs(Charge[j]);
310  }
311 
312  /*
313  chi2= sum((Charge[j]-aF)^2/|Charge[j]|
314  ( |Charge[j]| = assumed sigma^2 for Charge[j]; a bit wonky for Charge[j]<1 )
315  chi2 = sum(|Charge[j]|) - 2*sum(aF*Charge[j]/|Charge[j]|) +sum( a^2*F^2/|Charge[j]|)
316  chi2 minimimized when d(chi2)/da = 0:
317  a = sum(F*Charge[j])/sum(F^2)
318  ...
319  chi2= sum(|Q[j]|) - sum(Q[j]/|Q[j]|*F)*sum(Q[j]/|Q[j]|*F)/sum(F^2/|Q[j]|), where Q = Charge
320  chi2 = SumT2 - SumTF*SumTF/SumF2
321  */
322 
323  double Chi2 = SumT2 - SumTF * SumTF / SumF2;
324 
325  if(Chi2 < MinimumChi2)
326  MinimumChi2 = Chi2;
327  }
328 
329  // safety protection in case of perfect fit - don't want the log(...) to explode
330  if(MinimumChi2 < 1e-5)
331  MinimumChi2 = 1e-5;
332 
333  return MinimumChi2;
334 }
335 //---------------------------------------------------------------------------
336 double HBHEPulseShapeFlagSetter::PerformDualNominalFit(const std::vector<double> &Charge)
337 {
338  //
339  // Perform dual nominal fit and returns the chi2
340  //
341  // In this function we do a scan over possible "distance" (number of time slices between two components)
342  // and overall offset for the two components; first coarse, then finer
343  // All the fitting is done in the DualNominalFitSingleTry function
344  //
345 
346  double OverallMinimumChi2 = 1000000;
347 
348  int AvailableDistance[] = {-100, -75, -50, 50, 75, 100};
349 
350  // loop over possible pulse distances between two components
351  bool isFirst=true;
352 
353  for(int k = 0; k < 6; k++)
354  {
355  double SingleMinimumChi2 = 1000000;
356  int MinOffset = 0;
357 
358  // scan coarsely through different offsets and find the minimum
359  for(int i = 0; i + 250 < (int)CumulativeIdealPulse.size(); i += 10)
360  {
361  double Chi2 = DualNominalFitSingleTry(Charge, i, AvailableDistance[k],isFirst);
362  isFirst=false;
363  if(Chi2 < SingleMinimumChi2)
364  {
365  SingleMinimumChi2 = Chi2;
366  MinOffset = i;
367  }
368  }
369 
370  // around the minimum, scan finer for better a better minimum
371  for(int i = MinOffset - 15; i + 250 < (int)CumulativeIdealPulse.size() && i < MinOffset + 15; i++)
372  {
373  double Chi2 = DualNominalFitSingleTry(Charge, i, AvailableDistance[k],false);
374  if(Chi2 < SingleMinimumChi2)
375  SingleMinimumChi2 = Chi2;
376  }
377 
378  // update overall minimum chi2
379  if(SingleMinimumChi2 < OverallMinimumChi2)
380  OverallMinimumChi2 = SingleMinimumChi2;
381  }
382 
383  return OverallMinimumChi2;
384 }
385 //---------------------------------------------------------------------------
386 double HBHEPulseShapeFlagSetter::DualNominalFitSingleTry(const std::vector<double> &Charge, int Offset, int Distance, bool newCharges)
387 {
388  //
389  // Does a fit to dual signal pulse hypothesis given offset and distance of the two target pulses
390  //
391  // The only parameters to fit here are the two pulse heights of in-time and out-of-time components
392  // since offset is given
393  // The calculation here is based from writing down the Chi2 formula and minimize against the two parameters,
394  // ie., Chi2 = Sum{((T[i] - a1 * F1[i] - a2 * F2[i]) / (Sigma[i]))^2}, where T[i] is the input pulse shape,
395  // and F1[i], F2[i] are the two ideal pulse components
396  //
397 
398  int DigiSize = Charge.size();
399 
400  if(Offset < 0 || Offset + 250 >= (int)CumulativeIdealPulse.size())
401  return 1000000;
402  if(CumulativeIdealPulse[Offset+250] - CumulativeIdealPulse[Offset] < 1e-5)
403  return 1000000;
404 
405  if ( newCharges) {
406  f1_.resize(DigiSize);
407  f2_.resize(DigiSize);
408  errors_.resize(DigiSize);
409  for(int j = 0; j < DigiSize; j++)
410  {
411  errors_[j] = Charge[j];
412  if(errors_[j] < 1)
413  errors_[j] = 1;
414  errors_[j]=1.0/errors_[j];
415  }
416  }
417 
418  double SumF1F1 = 0;
419  double SumF1F2 = 0;
420  double SumF2F2 = 0;
421  double SumTF1 = 0;
422  double SumTF2 = 0;
423 
424  unsigned int cipSize=CumulativeIdealPulse.size();
425  for(int j = 0; j < DigiSize; j++)
426  {
427  // this is the TS value for in-time component - no problem we can do a subtraction directly
428  f1_[j] = CumulativeIdealPulse[Offset+j*25+25] - CumulativeIdealPulse[Offset+j*25];
429 
430  // However for the out-of-time component the index might go out-of-bound.
431  // Let's protect against this.
432 
433  int OffsetTemp = Offset + j * 25 + Distance;
434 
435  double C1 = 0; // lower-indexed value in the cumulative pulse shape
436  double C2 = 0; // higher-indexed value in the cumulative pulse shape
437 
438 
439  if(OffsetTemp + 25 >= (int)cipSize)
440  C1 = CumulativeIdealPulse[cipSize-1];
441  else
442  if( OffsetTemp >= -25)
443  C1 = CumulativeIdealPulse[OffsetTemp+25];
444  if(OffsetTemp >= (int)cipSize)
445  C2 = CumulativeIdealPulse[cipSize-1];
446  else
447  if( OffsetTemp >= 0)
448  C2 = CumulativeIdealPulse[OffsetTemp];
449  f2_[j] = C1 - C2;
450 
451  SumF1F1 += f1_[j] * f1_[j] * errors_[j];
452  SumF1F2 += f1_[j] * f2_[j] * errors_[j];
453  SumF2F2 += f2_[j] * f2_[j] * errors_[j];
454  SumTF1 += f1_[j] * Charge[j] * errors_[j];
455  SumTF2 += f2_[j] * Charge[j] * errors_[j];
456  }
457 
458  double Height = 0;
459  double Height2 = 0;
460  if (fabs(SumF1F2*SumF1F2-SumF1F1*SumF2F2)>1e-5)
461  {
462  Height = (SumF1F2 * SumTF2 - SumF2F2 * SumTF1) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
463  Height2 = (SumF1F2 * SumTF1 - SumF1F1 * SumTF2) / (SumF1F2 * SumF1F2 - SumF1F1 * SumF2F2);
464  }
465 
466  double Chi2 = 0;
467  for(int j = 0; j < DigiSize; j++)
468  {
469  double Residual = Height * f1_[j] + Height2 * f2_[j] - Charge[j];
470  Chi2 += Residual * Residual *errors_[j];
471  }
472 
473  // Safety protection in case of zero
474  if(Chi2 < 1e-5)
475  Chi2 = 1e-5;
476 
477  return Chi2;
478 }
479 //---------------------------------------------------------------------------
480 double HBHEPulseShapeFlagSetter::CalculateRMS8Max(const std::vector<double> &Charge)
481 {
482  //
483  // CalculateRMS8Max
484  //
485  // returns "RMS" divided by the largest charge in the time slices
486  // "RMS" is calculated using all but the two largest time slices.
487  // The "RMS" is not quite the actual RMS (see note below), but the value is only
488  // used for determining max values, and is not quoted as the actual RMS anywhere.
489  //
490 
491  int DigiSize = Charge.size();
492 
493  if (DigiSize<=2) return 1e-5; // default statement when DigiSize is too small for useful RMS calculation
494  // Copy Charge vector again, since we are passing references around
495  std::vector<double> TempCharge = Charge;
496 
497  // Sort TempCharge vector from smallest to largest charge
498  sort(TempCharge.begin(), TempCharge.end());
499 
500  double Total = 0;
501  double Total2 = 0;
502  for(int i = 0; i < DigiSize - 2; i++)
503  {
504  Total = Total + TempCharge[i];
505  Total2 = Total2 + TempCharge[i] * TempCharge[i];
506  }
507 
508  // This isn't quite the RMS (both Total2 and Total*Total need to be
509  // divided by an extra (DigiSize-2) within the sqrt to get the RMS.)
510  // We're only using this value for relative comparisons, though; we
511  // aren't explicitly interpreting it as the RMS. It might be nice
512  // to either change the calculation or rename the variable in the future, though.
513 
514  double RMS = sqrt(Total2 - Total * Total / (DigiSize - 2));
515 
516  double RMS8Max = RMS / TempCharge[DigiSize-1];
517  if(RMS8Max < 1e-5) // protection against zero
518  RMS8Max = 1e-5;
519 
520  return RMS8Max;
521 }
522 //---------------------------------------------------------------------------
523 double HBHEPulseShapeFlagSetter::PerformLinearFit(const std::vector<double> &Charge)
524 {
525  //
526  // Performs a straight-line fit over all time slices, and returns the chi2 value
527  //
528  // The calculation here is based from writing down the formula for chi2 and minimize
529  // with respect to the parameters in the fit, ie., slope and intercept of the straight line
530  // By doing two differentiation, we will get two equations, and the best parameters are determined by these
531  //
532 
533  int DigiSize = Charge.size();
534 
535  double SumTS2OverTi = 0;
536  double SumTSOverTi = 0;
537  double SumOverTi = 0;
538  double SumTiTS = 0;
539  double SumTi = 0;
540 
541  double Error2 = 0;
542  for(int i = 0; i < DigiSize; i++)
543  {
544  Error2 = Charge[i];
545  if(Charge[i] < 1)
546  Error2 = 1;
547 
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;
553  }
554 
555  double CM1 = SumTS2OverTi; // Coefficient in front of slope in equation 1
556  double CM2 = SumTSOverTi; // Coefficient in front of slope in equation 2
557  double CD1 = SumTSOverTi; // Coefficient in front of intercept in equation 1
558  double CD2 = SumOverTi; // Coefficient in front of intercept in equation 2
559  double C1 = SumTiTS; // Constant coefficient in equation 1
560  double C2 = SumTi; // Constant coefficient in equation 2
561 
562  // Denominators always non-zero by construction
563  double Slope = (C1 * CD2 - C2 * CD1) / (CM1 * CD2 - CM2 * CD1);
564  double Intercept = (C1 * CM2 - C2 * CM1) / (CD1 * CM2 - CD2 * CM1);
565 
566  // now that the best parameters are found, calculate chi2 from those
567  double Chi2 = 0;
568  for(int i = 0; i < DigiSize; i++)
569  {
570  double Deviation = Slope * i + Intercept - Charge[i];
571  double Error2 = Charge[i];
572  if(Charge[i] < 1)
573  Error2 = 1;
574  Chi2 += Deviation * Deviation / Error2;
575  }
576 
577  // safety protection in case of perfect fit
578  if(Chi2 < 1e-5)
579  Chi2 = 1e-5;
580 
581  return Chi2;
582 }
583 //---------------------------------------------------------------------------
585  double Discriminant,
586  std::vector<std::pair<double, double> > &Cuts,
587  int Side)
588 {
589  //
590  // Checks whether Discriminant value passes Cuts for the specified Charge. True if pulse is good.
591  //
592  // The "Cuts" pairs are assumed to be sorted in terms of size from small to large,
593  // where each "pair" = (Charge, Discriminant)
594  // "Side" is either positive or negative, which determines whether to discard the pulse if discriminant
595  // is greater or smaller than the cut value
596  //
597 
598  if(Cuts.empty()) // safety check that there are some cuts defined
599  return true;
600 
601  if(Charge <= Cuts[0].first) // too small to cut on
602  return true;
603 
604  int IndexLargerThanCharge = -1; // find the range it is falling in
605  for(int i = 1; i < (int)Cuts.size(); i++)
606  {
607  if(Cuts[i].first > Charge)
608  {
609  IndexLargerThanCharge = i;
610  break;
611  }
612  }
613 
614  double limit = 1000000;
615 
616  if(IndexLargerThanCharge == -1) // if charge is greater than the last entry, assume flat line
617  limit = Cuts[Cuts.size()-1].second;
618  else // otherwise, do a linear interpolation to find the cut position
619  {
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;
624 
625  limit = (Charge - C1) / (C2 - C1) * (L2 - L1) + L1;
626  }
627 
628  if(Side > 0 && Discriminant > limit)
629  return false;
630  if(Side < 0 && Discriminant < limit)
631  return false;
632 
633  return true;
634 }
635 //---------------------------------------------------------------------------
636 
637 
std::vector< double > f1_
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
std::vector< double > f2_
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)
uint16_t size_type
double PerformLinearFit(const std::vector< double > &Charge)
std::vector< std::pair< double, double > > mLeftSlopeCut
TriangleFitResult PerformTriangleFit(const std::vector< double > &Charge)
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< std::pair< double, double > > mRightSlopeCut
bool CheckPassFilter(double Charge, double Discriminant, std::vector< std::pair< double, double > > &Cuts, int Side)
isFirst
Definition: cuy.py:419
int k[5][pyjets_maxn]
std::vector< double > mCharge
std::vector< std::pair< double, double > > mRightSlopeSmallCut
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)
Definition: blowfish.cc:281
Definition: Chi2.h:15
std::vector< std::pair< double, double > > mTS4TS5UpperCut