Belle II Software  release-08-01-10
TOPTemplateFitter.h
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * *
5  * See git log for contributors and copyright holders. *
6  * This file is licensed under LGPL-3.0, see LICENSE.md. *
7  **************************************************************************/
8 
9 #pragma once
10 
11 #include <top/dataobjects/TOPRawWaveform.h>
12 #include <top/dbobjects/TOPSampleTimes.h>
13 
14 #include <vector>
15 
16 namespace Belle2 {
22  namespace TOP {
23 
24  using Point = std::pair<double, double>;
25 
31 
32  public:
33 
39  double amplitude = 100.;
40  double risingEdge = 32.;
41  };
42 
46  struct FitResult {
47  double amplitude = 0;
48  double amplitudeError = 0;
49  double backgroundOffset = 0;
50  double backgroundOffsetError = 0;
51  double risingEdge = 0;
56  void clear()
57  {
58  amplitude = 0;
59  amplitudeError = 0;
60  backgroundOffset = 0;
62  risingEdge = 0;
63  }
64  };
65 
70  double S1 = 0;
71  double Sx = 0;
72  double Sxx = 0;
73  double Sy = 0;
74  double Sxy = 0;
75  double Syy = 0;
80  void clear()
81  {
82  S1 = 0;
83  Sx = 0;
84  Sxx = 0;
85  Sy = 0;
86  Sxy = 0;
87  Syy = 0;
88  }
89  };
90 
98  const TOPSampleTimes& sampleTimes,
99  const double averageRMS);
104 
109  double getChisq() const {return m_chisq;}
110 
115  const std::vector<double>& getChisqVector() const {return m_chisq_vec;}
116 
121  const FitResult& getFitResult() const {return m_result;}
122 
128 
134 
140 
145  static bool getUseParabola() {return s_useParabola;}
146 
151  static void setTemplateParameters(const TemplateParameters& params);
152 
157  static void setTemplateSamples(int nSamples);
158 
163  static void setTemplateResolution(int resolution);
164 
169  static void setUseParabola(bool use) {s_useParabola = use;}
170 
174  static void InitializeTemplateFit();
175 
181  void performTemplateFit(const double risingEdgeStart,
182  const double fitRange);
183 
184  private:
185 
194  void PerformTemplateFitMinimize(const std::vector<short>& samples, const std::vector<short>& pedestals,
195  const std::vector<float>& timingCorrection, const double risingEdgeCFD,
196  const double fitRange);
197 
204  double ComputeMinimizedParametersAndChisq(const MinimizationSums& sums, FitResult& result);
205 
213  void CalculateParabolaVertex(const Point& p1, const Point& p2, const Point& p3,
214  Point& vertex);
215 
218  const double m_averageRMS;
223  static std::vector<double> s_templateSamples;
224  static int s_fineOffsetRange;
226  static bool s_useParabola;
228  //fit results
230  double m_chisq = 0;
231  std::vector<double> m_chisq_vec;
233  };
234 
235  }
237 }
Class to store raw data waveforms.
Calibration constants of a singe ASIC channel: time axis (sample times)
Class to perform template fit on TOP waveform data Minimzation method is described here http://wwwa1....
static int s_fineOffsetRange
range for offset between template and signal
static void InitializeTemplateFit()
Intializes the template fit using default values.
static TemplateParameters & getTemplateParameters()
Returns the template parameters.
static TemplateParameters s_templateParameters
parameters used for the template calculation
std::vector< double > m_chisq_vec
all computed chi square values from template fit
static void setUseParabola(bool use)
Enable Usage of parabola improvement.
const TOPRawWaveform m_wf
raw sampled waveforms
double getChisq() const
Returns fit chi square.
void PerformTemplateFitMinimize(const std::vector< short > &samples, const std::vector< short > &pedestals, const std::vector< float > &timingCorrection, const double risingEdgeCFD, const double fitRange)
performs the template fit
void performTemplateFit(const double risingEdgeStart, const double fitRange)
Prepares data and performs the template fit in sample space.
static bool s_templateReInitialize
flag showing that the template samples have to be recomputed
const double m_averageRMS
average RMS of waveform samples, no database for this
const FitResult & getFitResult() const
Returns fitted values with errors.
static int s_templateResolution
resolution of template with respect to normal sample spacing
void CalculateParabolaVertex(const Point &p1, const Point &p2, const Point &p3, Point &vertex)
Calculate vertex coordinates of parabola given three data points.
static void setTemplateParameters(const TemplateParameters &params)
Sets the template parameters.
double m_chisq
chi square value from template fit
static void setTemplateSamples(int nSamples)
Set the total number of template samples.
FitResult m_result
fit result from template fit
const TOPSampleTimes m_sampleTimes
provides timing correction
TOPTemplateFitter(const TOPRawWaveform &wf, const TOPSampleTimes &sampleTimes, const double averageRMS)
full constructor
const std::vector< double > & getChisqVector() const
Returns calculated chisq values.
double ComputeMinimizedParametersAndChisq(const MinimizationSums &sums, FitResult &result)
Compute the minimized parameters and chi square value.
static std::vector< double > s_templateSamples
precomputed template samples
static int getTemplateResolution()
Returns the template resolution.
~TOPTemplateFitter()
default destructor
static bool s_useParabola
try improving fit by making use of parabolic shape of chisq values
static void setTemplateResolution(int resolution)
Set the template resolution.
static int getTemplateSamples()
Returns the total number of template samples.
static int s_totalTemplateSamples
number of samples used for template
static bool getUseParabola()
Returns useParabola.
Abstract base class for different kinds of events.
structure holding values from template fit
double amplitudeError
fitted amplitude error
void clear()
set the fit result variables to zero
double backgroundOffsetError
fitted background offset error
double backgroundOffset
fitted background offset
Variables used during template fit minimization.
double Sxy
sum of signal sample *template*weight
double Syy
sum of signal sample * signal sample * weight
double Sxx
sum of template*template*weight
void clear()
set sums used during template fit to initial values
double Sy
sum of signal sample * weight
Parameters of the template function.
double amplitude
amplitude of template function
double risingEdge
rising edge position of template in samples