Belle II Software  release-08-01-10
NNWaveFitTool Class Reference

The class holds arrays of bins and bin centers, and a wave generator object containing information on the waveform function. More...

#include <NNWaveFitTool.h>

Collaboration diagram for NNWaveFitTool:

Public Member Functions

 NNWaveFitTool (const nnFitterBins &bins, const nnFitterBinData &binCenters, const WaveGenerator &wave)
 Constructor takes arrays of signals and bin probabilities. More...
 
const nnFitterBinsgetBins () const
 Get edges of time shift bins. More...
 
const nnFitterBinDatagetBinCenters () const
 Get mean bin time shifts. More...
 
void shiftInTime (nnFitterBinData &p, double timeShift)
 Shift the probability array in time. More...
 
void multiply (nnFitterBinData &p, const nnFitterBinData &p1)
 Multiply probabilities. More...
 
std::shared_ptr< nnFitterBinDatapFromInterval (double left, double right)
 Convert a uniform distribution to time-shift-like pdf. More...
 
std::tuple< double, double > getTimeShift (const nnFitterBinData &p)
 Return std::tuple containing time shift and its error. More...
 
std::tuple< double, double, double > getAmplitudeChi2 (const apvSamples &samples, double timeShift, double tau)
 Return std::tuple with signal amplitude, its error, and chi2 of the fit. More...
 
double pLessThan (nnFitterBinData p1, nnFitterBinData p2)
 Return the probability X < Y, where X and Y are random variables with binned pdfs p1 and p2. More...
 

Protected Member Functions

void normalize (nnFitterBinData &p)
 Normalize the probability distribution. More...
 

Private Attributes

const nnFitterBinsm_bins
 Edges of bins.
 
const nnFitterBinDatam_binCenters
 Centers of bins.
 
nnFitterBinData m_altBinData
 Bin data array for re-use.
 
apvSamples m_altSamples
 Array of 6 apv samples for re-use.
 
WaveGenerator m_waveGenerator
 APV signal generator.
 

Detailed Description

The class holds arrays of bins and bin centers, and a wave generator object containing information on the waveform function.

It can compute probability distribution updates in clustering, or the parameters of waveform fit, such as the time shift, amplitude and their errors, and it can do compatibility tests.

Definition at line 91 of file NNWaveFitTool.h.

Constructor & Destructor Documentation

◆ NNWaveFitTool()

NNWaveFitTool ( const nnFitterBins bins,
const nnFitterBinData binCenters,
const WaveGenerator wave 
)
inline

Constructor takes arrays of signals and bin probabilities.

Parameters
binsPointer to array of time bin edges
binCentersPointer to array of mean bin times
waveWave generator to generate waveform samples.

Definition at line 98 of file NNWaveFitTool.h.

Member Function Documentation

◆ getAmplitudeChi2()

tuple< double, double, double > getAmplitudeChi2 ( const apvSamples samples,
double  timeShift,
double  tau 
)

Return std::tuple with signal amplitude, its error, and chi2 of the fit.

The amplitude is calculated using linear regression through origin, its error as the error of the regression coefficient.

Parameters
samplesarray of 6 samples to fit
timeShiftfitted time shift
tauwidth of the waveform
Returns
std::tuple of amplitude, its error, and chi2

Definition at line 27 of file NNWaveFitTool.cc.

29 {
30  // Amplitude
31  auto tw = m_waveGenerator(timeShift, tau);
32  double waveNorm = inner_product(
33  tw.begin(), tw.end(), tw.begin(), 0.0);
34  double amplitude = 0.0;
35  double amplitudeError = 100.0;
36  if (waveNorm > 0.0) {
37  amplitude = inner_product(samples.begin(), samples.end(),
38  tw.begin(), 0.0) / waveNorm;
39  amplitudeError = 1.0 / sqrt(waveNorm);
40  }
41  // Chi2
42  transform(samples.begin(), samples.end(), tw.begin(), m_altSamples.begin(),
43  [amplitude](double s, double w)->double { return s - w* amplitude;});
44  size_t ndf = accumulate(samples.begin(), samples.end(), size_t(0),
45  [](size_t sum, double x)->size_t { return ((x > 3) ? sum + 1 : sum); }
46  ) - 2;
47  double chi2 = sqrt(1.0 / ndf * inner_product(m_altSamples.begin(), m_altSamples.end(),
48  m_altSamples.begin(), 0.0));
49  return make_tuple(amplitude, amplitudeError, chi2);
50 }
apvSamples m_altSamples
Array of 6 apv samples for re-use.
WaveGenerator m_waveGenerator
APV signal generator.
double sqrt(double a)
sqrt for double
Definition: beamHelpers.h:28

◆ getBinCenters()

const nnFitterBinData& getBinCenters ( ) const
inline

Get mean bin time shifts.

Returns
pointer to array of bin time shifts

Definition at line 115 of file NNWaveFitTool.h.

◆ getBins()

const nnFitterBins& getBins ( ) const
inline

Get edges of time shift bins.

Returns
pointer to array of bin edges

Definition at line 110 of file NNWaveFitTool.h.

◆ getTimeShift()

tuple< double, double > getTimeShift ( const nnFitterBinData p)

Return std::tuple containing time shift and its error.

Parameters
parray of bin probabilities
Returns
std::tuple of timeShift, timeShiftError

Definition at line 16 of file NNWaveFitTool.cc.

◆ multiply()

void multiply ( nnFitterBinData p,
const nnFitterBinData p1 
)
inline

Multiply probabilities.

Modify first probability distribution by multiplying it with the second.

Definition at line 129 of file NNWaveFitTool.h.

◆ normalize()

void normalize ( nnFitterBinData p)
inlineprotected

Normalize the probability distribution.

After shifting, multiplications or other ooperations on probabilities, we need to restore the normalization and re-build the list used for calculation of EmpiricalDistributionFunction. If probabilities vanish over all bins, return uniform distribution.

Definition at line 178 of file NNWaveFitTool.h.

◆ pFromInterval()

shared_ptr< nnFitterBinData > pFromInterval ( double  left,
double  right 
)

Convert a uniform distribution to time-shift-like pdf.

Parameters
leftLeft edge of the interval
rightRight edge of the interval
Returns
pointer to binned pdf representing the uniform distribution between left and right.

Definition at line 66 of file NNWaveFitTool.cc.

◆ pLessThan()

double pLessThan ( nnFitterBinData  p1,
nnFitterBinData  p2 
)

Return the probability X < Y, where X and Y are random variables with binned pdfs p1 and p2.

Parameters
p1binned pdf for X
p2binned pdf for Y

Definition at line 78 of file NNWaveFitTool.cc.

◆ shiftInTime()

void shiftInTime ( nnFitterBinData p,
double  timeShift 
)

Shift the probability array in time.

The method works by linearly interpolating the EmpiricalDistributionFunction to calculate values for a shifted set of bins.

Parameters
pthe probability array to be modified.
timeShiftthe size of the shift.

Definition at line 52 of file NNWaveFitTool.cc.


The documentation for this class was generated from the following files: