 |
Belle II Software
release-05-01-25
|
11 #include <top/utilities/TOPTemplateFitter.h>
12 #include <top/geometry/TOPGeometryPar.h>
13 #include <framework/logging/Logger.h>
18 using namespace Belle2::TOP;
32 const double averageRMS)
33 : m_wf(wf), m_sampleTimes(sampleTimes), m_averageRMS(averageRMS)
65 B2FATAL(
"rising edge of template function invalid!");
70 const auto& tdc = geo->getNominalTDC();
71 const double dt = tdc.getSampleWidth();
81 const double fitRange)
100 int minidx = std::distance(std::begin(
m_chisq_vec), it);
101 if (minidx > 0 && minidx < (
int)
m_chisq_vec.size() - 1) {
112 double denom = (p1.first - p2.first) * (p1.first - p3.first) * (p2.first - p3.first);
113 double a = (p3.first * (p2.second - p1.second) + p2.first * (p1.second - p3.second) + p1.first *
114 (p3.second - p2.second)) / denom;
115 double b = (p3.first * p3.first * (p1.second - p2.second) + p2.first * p2.first * (p3.second - p1.second)
116 + p1.first * p1.first * (p2.second - p3.second)) / denom;
117 double c = (p2.first * p3.first * (p2.first - p3.first) * p1.second + p3.first * p1.first * (p3.first - p1.first) * p2.second
118 + p1.first * p2.first * (p1.first - p2.first) * p3.second) / denom;
120 vertex.first = -b / (2 * a);
121 vertex.second = c - b * b / (4 * a);
125 const std::vector<float>& timingCorrection,
const double risingEdgeCFD,
const double fitRange)
127 if (samples.size() != pedestals.size() || samples.size() != timingCorrection.size()) {
128 B2FATAL(
"Size of sample, pedestal and timing correction vectors has to be equal!");
139 for (
int signalSampleIndex = risingEdgeCFD - fitRange; signalSampleIndex < risingEdgeCFD + fitRange; ++signalSampleIndex) {
140 if (signalSampleIndex < 0 || signalSampleIndex > (
int)samples.size() - 1)
continue;
141 int templateIndex = signalSampleIndex *
s_templateResolution - totalTemplateOffset + timingCorrection[signalSampleIndex];
142 if (templateIndex < 0 || templateIndex > (
int)
s_templateSamples.size() - 1)
continue;
143 double weight = 1. / (pedestals[signalSampleIndex] * pedestals[signalSampleIndex]);
145 double Sy = weight * samples[signalSampleIndex];
151 sums.
Syy += Sy * samples[signalSampleIndex];
169 const double determinant = sums.
S1 * sums.
Sxx - sums.
Sx * sums.
Sx;
170 result.amplitude = (-sums.
Sx * sums.
Sy + sums.
S1 * sums.
Sxy) / determinant;
171 result.backgroundOffset = (sums.
Sxx * sums.
Sy - sums.
Sx * sums.
Sxy) / determinant;
172 result.amplitudeError = sums.
S1 / determinant;
173 result.backgroundOffsetError = sums.
Sxx / determinant;
174 return sums.
Syy - result.backgroundOffset * sums.
Sy - result.amplitude * sums.
Sxy;
void clear()
set sums used during template fit to initial values
double Sx
sum of template*weight
double risingEdge
fitted rising edge
TOPTemplateFitter(const TOPRawWaveform &wf, const TOPSampleTimes &sampleTimes, const double averageRMS)
full constructor
static std::vector< double > s_templateSamples
precomputed template samples
void performTemplateFit(const double risingEdgeStart, const double fitRange)
Prepares data and performs the template fit in sample space.
double ComputeMinimizedParametersAndChisq(const MinimizationSums &sums, FitResult &result)
Compute the minimized parameters and chi square value.
static int s_totalTemplateSamples
number of samples used for template
static void setTemplateSamples(int nSamples)
Set the total number of template samples.
double risingEdge
rising edge position of template in samples
Variables used during template fit minimization.
double amplitudeError
fitted amplitude error
double amplitude
amplitude of template function
const TOPSignalShape & getSignalShape() const
Returns single photon signal shape.
double Syy
sum of signal sample * signal sample * weight
void CalculateParabolaVertex(const Point &p1, const Point &p2, const Point &p3, Point &vertex)
Calculate vertex coordinates of parabola given three data points.
double Sxy
sum of signal sample *template*weight
double Sxx
sum of template*template*weight
double S1
sum of sample weights
const TOPRawWaveform m_wf
raw sampled waveforms
structure holding values from template fit
static int s_templateResolution
resolution of template with respect to normal sample spacing
static TOPGeometryPar * Instance()
Static method to obtain the pointer to its instance.
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
static void InitializeTemplateFit()
Intializes the template fit using default values.
Calibration constants of a singe ASIC channel: time axis (sample times)
Abstract base class for different kinds of events.
const double m_averageRMS
average RMS of waveform samples, no database for this
double amplitude
fitted amplitude
static void setTemplateParameters(const TemplateParameters ¶ms)
Sets the template parameters.
static bool s_useParabola
try improving fit by making use of parabolic shape of chisq values
static TemplateParameters s_templateParameters
parameters used for the template calculation
static int s_fineOffsetRange
range for offset between template and signal
FitResult m_result
fit result from template fit
Parameters of the template function.
static void setTemplateResolution(int resolution)
Set the template resolution.
const TOPGeometry * getGeometry() const
Returns pointer to geometry object using Basf2 units.
static bool s_templateReInitialize
flag showing that the template samples have to be recomputed
double Sy
sum of signal sample * weight
std::vector< double > m_chisq_vec
all computed chi square values from template fit
double m_chisq
chi square value from template fit