LArSoft  v07_13_02
Liquid Argon Software toolkit - http://larsoft.org/
lar::util::LinearFit< T > Class Template Referenceabstract

Performs a linear regression of data. More...

#include "SimpleFits.h"

Inheritance diagram for lar::util::LinearFit< T >:
lar::util::details::SimplePolyFitterBase< T, 1U > lar::util::details::SimpleFitterInterface< T, D+1 > lar::util::details::SimplePolyFitterDataBase< T, D >

Public Types

using FitParameters_t = std::array< Data_t, NParams >
 type of set of fit parameters More...
 
using FitMatrix_t = std::array< Data_t, sqr(NParams)>
 
using Data_t = typename Base_t::Data_t
 type of the data More...
 
using MatrixOps = FastMatrixOperations< Data_t, NParams >
 
using Measurement_t = typename Collector_t::Measurement_t
 type of measurement without uncertainty More...
 
using MeasurementAndUncertainty_t = typename Collector_t::MeasurementAndUncertainty_t
 type of measurement with uncertainty More...
 

Public Member Functions

Data_t Intercept () const
 Returns the intercept of the fit. More...
 
Data_t Slope () const
 Returns the slope of the fit. More...
 
Data_t InterceptError () const
 Returns the error on intercept of the fit. More...
 
Data_t SlopeError () const
 Returns the error in slope of the fit. More...
 
Data_t InterceptSlopeCovariance () const
 Returns the covariance between intercept and slope of the fit. More...
 
virtual Data_t ChiSquare () const override
 Returns the $ \chi^{2} $ of the fit. More...
 
virtual bool isValid () const override
 Returns if the fit has valid results. More...
 
bool FillResults (FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
 Fills the specified parameters. More...
 
bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const override
 Fills the specified parameters. More...
 
bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors) const override
 Fills the specified parameters. More...
 
virtual bool FillResults (FitParameters_t &params, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const =0
 Fills the specified parameters. More...
 
virtual bool FillResults (FitParameters_t &params, FitParameters_t &paramerrors, FitMatrix_t &Xmat, Data_t &det, FitMatrix_t &Smat) const =0
 Fills the specified parameters. More...
 
virtual Data_t Evaluate (Data_t x) const override
 Evaluates the fitted function at the specified point. More...
 
virtual Data_t Evaluate (Data_t x) const =0
 Evaluates the fitted function at the specified point. More...
 
Data_t operator() (Data_t x) const
 Evaluates the fitted function; alias of Evaluate() More...
 
void clear ()
 Clears all the statistics. More...
 
template<typename Stream >
void PrintStats (Stream &out) const
 Prints the collected statistics into a stream. More...
 
Fitting
virtual FitParameters_t FitParameters () const override
 Computes and returns all the parameters of the fit result. More...
 
virtual FitParameters_t FitParameterErrors () const override
 Computes and returns all the parameter errors of the fit result. More...
 
virtual FitMatrix_t FitParameterCovariance () const override
 Computes and returns all the covariance matrix of the fit result. More...
 
virtual Data_t FitParameter (unsigned int n) const override
 Returns the parameter n of the fit result. More...
 
virtual Data_t FitParameterError (unsigned int n) const override
 Returns the error on parameter n of the fit result. More...
 
virtual int NDF () const override
 Returns the degrees of freedom in the determination of the fit. More...
 
Add elements
See also
FitDataCollector
bool add (Data_t x, Data_t y, Data_t sy=Data_t(1.0))
 
bool add (Measurement_t value, Data_t sy=Data_t(1.0))
 
bool add (MeasurementAndUncertainty_t value)
 
template<typename Iter >
void add_without_uncertainty (Iter begin, Iter end)
 
template<typename Iter , typename Pred >
void add_without_uncertainty (Iter begin, Iter end, Pred extractor)
 
template<typename Cont , typename Pred >
void add_without_uncertainty (Cont cont, Pred extractor)
 
template<typename Cont >
void add_without_uncertainty (Cont cont)
 
template<typename VIter , typename UIter , typename VPred , typename UPred = identity>
unsigned int add_with_uncertainty (VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
 
template<typename Iter >
unsigned int add_with_uncertainty (Iter begin, Iter end)
 
template<typename Cont >
unsigned int add_with_uncertainty (Cont cont)
 
Statistic retrieval
See also
FitDataCollector
int N () const
 
Data_t AverageUncertainty () const
 

Static Public Member Functions

static FitParameters_t ExtractParameterErrors (FitMatrix_t const &Smat)
 Extracts parameter errors from diagonal of the covarriance matrix. More...
 
static constexpr Data_t sqr (Data_t v)
 Returns the square of the specified data value. More...
 
template<typename V >
static constexpr V sqr (V const &v)
 Returns the square of the specified value. More...
 
static constexpr Data_t cube (Data_t v)
 Returns the cube of the specified data value. More...
 

Static Public Attributes

static constexpr unsigned int Degree
 Degree of the fit. More...
 
static constexpr unsigned int NParams
 Number of parameters in the fit. More...
 

Protected Member Functions

virtual FitParameters_t FitParameterErrors (FitMatrix_t const &Smat) const
 Computes and returns all the parameter errors of the fit result. More...
 
virtual FitMatrix_t MakeMatrixX () const
 Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } ) More...
 
virtual FitParameters_t MakeMatrixY () const
 Fills and returns the matrix (vector) of x^n y sum coefficients. More...
 
virtual Data_t Determinant (FitMatrix_t const &mat) const
 Computes the determinant of a matrix. More...
 
virtual FitMatrix_t InvertMatrix (FitMatrix_t const &mat, Data_t det) const
 Computes the inverse of a matrix (using provided determinant) More...
 
virtual FitMatrix_t InvertMatrix (FitMatrix_t const &mat) const
 Computes the inverse of a matrix. More...
 
virtual FitParameters_t MatrixProduct (FitMatrix_t const &mat, FitParameters_t const &vec) const
 Computes the product of a FitMatrix_t and a FitParameters_t. More...
 
Data_t XN (unsigned int n) const
 Returns the weighted sum of x^n. More...
 
Data_t XNY (unsigned int n) const
 Returns the weighted sum of x^n y. More...
 
Data_t I () const
 Aliases. More...
 
Data_t X () const
 Aliases. More...
 
Data_t X2 () const
 Aliases. More...
 
Data_t Y () const
 Aliases. More...
 
Data_t XY () const
 Aliases. More...
 
Data_t Y2 () const
 Aliases. More...
 
virtual FitParameters_t FitParameters (FitMatrix_t const &Xmat) const
 Returns the fitted parameters using the provided information. More...
 
virtual FitParameters_t FitParameters (FitMatrix_t const &Smat, Data_t) const
 Returns the fitted parameters using the provided information. More...
 
virtual Data_t Param (unsigned int n, FitMatrix_t const &Xmat) const
 Computes a single fit parameter using the given information. More...
 
virtual Data_t Param (unsigned int n, FitMatrix_t const &Xmat, Data_t detXmat) const
 Computes a single fit parameter using the given information. More...
 

Protected Attributes

Collector_t stats
 statistics collected from fit data input More...
 

Private Types

using Base_t = details::SimplePolyFitterBase< T, 1U >
 

Detailed Description

template<typename T>
class lar::util::LinearFit< T >

Performs a linear regression of data.


Template Parameters
Ttype of the quantities
Wtype of the weight (as T by default)

The linear regression connects measurements $ ( y_{i} \pm \sigma_{y,i} ) $ with a parameter $ ( x_{i} ) $ not affected by uncertainty. The returned parameters describe a straight line $ y = a x + b $ obtained by minimization of $ \chi^{2} = \sum_{i} \frac{ \left(y_{i} - a x_{i} - b \right)^{2} }{ \sigma^{2}_{y,i} }$

This saves having to link to ROOT for the simplest cases.

This simple linear fitter does not store any result: each time a result is requested, it is computed anew. In particular that is true also for ChiSquare(), that requires the full parameters set and therefore reruns the full fit (FitParameters()) and for the covariance matrix of the parameters.

Definition at line 849 of file SimpleFits.h.

Member Typedef Documentation

template<typename T>
using lar::util::LinearFit< T >::Base_t = details::SimplePolyFitterBase<T, 1U>
private

Definition at line 850 of file SimpleFits.h.

template<typename T>
using lar::util::details::SimplePolyFitterBase< T, D >::Data_t = typename Base_t::Data_t

type of the data

Definition at line 653 of file SimpleFits.h.

template<typename T>
using lar::util::LinearFit< T >::FitMatrix_t = std::array<Data_t, sqr(NParams)>

Definition at line 867 of file SimpleFits.h.

template<typename T>
using lar::util::LinearFit< T >::FitParameters_t = std::array<Data_t, NParams>

type of set of fit parameters

Definition at line 866 of file SimpleFits.h.

using lar::util::details::SimpleFitterInterface< T, N >::MatrixOps = FastMatrixOperations<Data_t, NParams>
inherited

Definition at line 466 of file SimpleFits.h.

template<typename T , unsigned int D>
using lar::util::details::SimplePolyFitterDataBase< T, D >::Measurement_t = typename Collector_t::Measurement_t
inherited

type of measurement without uncertainty

Definition at line 354 of file SimpleFits.h.

template<typename T , unsigned int D>
using lar::util::details::SimplePolyFitterDataBase< T, D >::MeasurementAndUncertainty_t = typename Collector_t::MeasurementAndUncertainty_t
inherited

type of measurement with uncertainty

Definition at line 358 of file SimpleFits.h.

Member Function Documentation

template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterDataBase< T, D >::add ( Data_t  x,
Data_t  y,
Data_t  sy = Data_t(1.0) 
)
inlineinherited

Definition at line 366 of file SimpleFits.h.

Referenced by cluster::ClusterParamsAlg::IntegrateFitCharge().

367  { return stats.add(x, y, sy); }
Float_t x
Definition: compare.C:6
Float_t y
Definition: compare.C:6
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
Adds one entry with specified x, y and uncertainty.
Definition: SimpleFits.h:1446
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterDataBase< T, D >::add ( Measurement_t  value,
Data_t  sy = Data_t(1.0) 
)
inlineinherited

Definition at line 369 of file SimpleFits.h.

370  { return stats.add(value, sy); }
std::string value(boost::any const &)
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
Adds one entry with specified x, y and uncertainty.
Definition: SimpleFits.h:1446
template<typename T , unsigned int D>
bool lar::util::details::SimplePolyFitterDataBase< T, D >::add ( MeasurementAndUncertainty_t  value)
inlineinherited

Definition at line 372 of file SimpleFits.h.

373  { return stats.add(value); }
std::string value(boost::any const &)
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
bool add(Data_t x, Data_t y, Data_t sy=Data_t(1.0))
Adds one entry with specified x, y and uncertainty.
Definition: SimpleFits.h:1446
template<typename T , unsigned int D>
template<typename VIter , typename UIter , typename VPred , typename UPred = identity>
unsigned int lar::util::details::SimplePolyFitterDataBase< T, D >::add_with_uncertainty ( VIter  begin_value,
VIter  end_value,
UIter  begin_uncertainty,
VPred  value_extractor,
UPred  uncertainty_extractor = UPred() 
)
inlineinherited

Definition at line 397 of file SimpleFits.h.

403  {
405  begin_value, end_value, begin_uncertainty,
406  value_extractor, uncertainty_extractor);
407  }
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
Adds measurements with uncertainties from a sequence.
Definition: SimpleFits.h:1477
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Iter >
unsigned int lar::util::details::SimplePolyFitterDataBase< T, D >::add_with_uncertainty ( Iter  begin,
Iter  end 
)
inlineinherited

Definition at line 411 of file SimpleFits.h.

412  { return stats.add_with_uncertainty(begin, end); }
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
Adds measurements with uncertainties from a sequence.
Definition: SimpleFits.h:1477
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Cont >
unsigned int lar::util::details::SimplePolyFitterDataBase< T, D >::add_with_uncertainty ( Cont  cont)
inlineinherited

Definition at line 415 of file SimpleFits.h.

416  { return stats.add_with_uncertainty(cont); }
unsigned int add_with_uncertainty(VIter begin_value, VIter end_value, UIter begin_uncertainty, VPred value_extractor, UPred uncertainty_extractor=UPred())
Adds measurements with uncertainties from a sequence.
Definition: SimpleFits.h:1477
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Iter >
void lar::util::details::SimplePolyFitterDataBase< T, D >::add_without_uncertainty ( Iter  begin,
Iter  end 
)
inlineinherited

Definition at line 377 of file SimpleFits.h.

void add_without_uncertainty(Iter begin, Iter end)
Adds measurements from a sequence, with no uncertainty.
Definition: SimpleFits.h:135
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Iter , typename Pred >
void lar::util::details::SimplePolyFitterDataBase< T, D >::add_without_uncertainty ( Iter  begin,
Iter  end,
Pred  extractor 
)
inlineinherited

Definition at line 381 of file SimpleFits.h.

382  { stats.add_without_uncertainty(begin, end, extractor); }
void add_without_uncertainty(Iter begin, Iter end)
Adds measurements from a sequence, with no uncertainty.
Definition: SimpleFits.h:135
std::vector< evd::details::RawDigitInfo_t >::const_iterator begin(RawDigitCacheDataClass const &cache)
std::vector< evd::details::RawDigitInfo_t >::const_iterator end(RawDigitCacheDataClass const &cache)
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Cont , typename Pred >
void lar::util::details::SimplePolyFitterDataBase< T, D >::add_without_uncertainty ( Cont  cont,
Pred  extractor 
)
inlineinherited

Definition at line 385 of file SimpleFits.h.

386  { stats.add_without_uncertainty(cont, extractor); }
void add_without_uncertainty(Iter begin, Iter end)
Adds measurements from a sequence, with no uncertainty.
Definition: SimpleFits.h:135
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
template<typename Cont >
void lar::util::details::SimplePolyFitterDataBase< T, D >::add_without_uncertainty ( Cont  cont)
inlineinherited

Definition at line 389 of file SimpleFits.h.

390  { stats.add_without_uncertainty(cont); }
void add_without_uncertainty(Iter begin, Iter end)
Adds measurements from a sequence, with no uncertainty.
Definition: SimpleFits.h:135
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
Data_t lar::util::details::SimplePolyFitterDataBase< T, D >::AverageUncertainty ( ) const
inlineinherited

Definition at line 429 of file SimpleFits.h.

429 { return stats.AverageUncertainty(); }
Data_t AverageUncertainty() const
Returns an average of the uncertainties.
Definition: SimpleFits.h:277
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T >
auto lar::util::LinearFit< T >::ChiSquare ( ) const
overridevirtual

Returns the $ \chi^{2} $ of the fit.

Returns
the $ \chi^{2} $ of the fit (not divided by NDF())

Reimplemented from lar::util::details::SimplePolyFitterBase< T, 1U >.

Definition at line 1756 of file SimpleFits.h.

References lar::util::details::FitDataCollector< T, D >::sqr(), X2, Y, and lar::util::details::FitDataCollector< T, D >::Y2().

1757 {
1758  FitParameters_t fit_params = this->FitParameters();
1759  const Data_t b = fit_params[0];
1760  const Data_t a = fit_params[1];
1761  return Y2() + sqr(a) * X2() + sqr(b) * I()
1762  + Data_t(2) * (a * b * X2() - a * XY() - b * Y());
1763 } // LinearFit<T>::ChiSquare()
Data_t I() const
Aliases.
Definition: SimpleFits.h:920
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
Data_t X2() const
Aliases.
Definition: SimpleFits.h:922
std::array< Data_t, NParams > FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:866
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: SimpleFits.h:441
Data_t XY() const
Aliases.
Definition: SimpleFits.h:924
Data_t Y() const
Aliases.
Definition: SimpleFits.h:923
Data_t Y2() const
Aliases.
Definition: SimpleFits.h:925
template<typename T , unsigned int D>
void lar::util::details::SimplePolyFitterDataBase< T, D >::clear ( )
inlineinherited

Clears all the statistics.

Definition at line 421 of file SimpleFits.h.

421 { stats.clear(); }
void clear()
Clears all the statistics.
Definition: SimpleFits.h:1509
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
static constexpr Data_t lar::util::details::SimpleFitterInterface< T, N >::cube ( Data_t  v)
inlinestaticinherited

Returns the cube of the specified data value.

Definition at line 610 of file SimpleFits.h.

610 { return v*v*v; }
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::Determinant ( FitMatrix_t const &  mat) const
inlineprotectedvirtualinherited

Computes the determinant of a matrix.

Definition at line 615 of file SimpleFits.h.

616  { return MatrixOps::Determinant(mat); }
Float_t mat
Definition: plot.C:40
virtual Data_t lar::util::details::SimpleFitterInterface< T, N >::Evaluate ( Data_t  x) const
pure virtualinherited

Evaluates the fitted function at the specified point.

Parameters
xthe point where to evaluate the fit function
Returns
the value of the fit function

No check is performed whether the fit is valid.

virtual Data_t lar::util::details::SimplePolyFitterBase< T, D >::Evaluate ( Data_t  x) const
overridevirtualinherited

Evaluates the fitted function at the specified point.

Parameters
xthe point where to evaluate the fit function
Returns
the value of the fit function

No check is performed whether the fit is valid.

static FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::ExtractParameterErrors ( FitMatrix_t const &  Smat)
staticinherited

Extracts parameter errors from diagonal of the covarriance matrix.

virtual bool lar::util::details::SimpleFitterInterface< T, N >::FillResults ( FitParameters_t params,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
pure virtualinherited

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
virtual bool lar::util::details::SimpleFitterInterface< T, N >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
pure virtualinherited

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
paramerrorsthe uncertainty on the fitted parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
overrideinherited

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors,
FitMatrix_t Xmat,
Data_t det,
FitMatrix_t Smat 
) const
overrideinherited

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
paramerrorsthe uncertainty on the fitted parameters
Xmatthe matrix of the x^n/s^2 sums
Smatthe covariance matrix
detthe determinant of Xmat
Returns
true if the fit is valid (i.e. if a unique solution exists)
bool lar::util::details::SimplePolyFitterBase< T, D >::FillResults ( FitParameters_t params,
FitParameters_t paramerrors 
) const
overridevirtualinherited

Fills the specified parameters.

Parameters
paramsthe fitted values of the parameters
paramerrorsthe uncertainty on the fitted parameters
Returns
true if the fit is valid (i.e. if a unique solution exists)

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual Data_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameter ( unsigned int  n) const
overridevirtualinherited

Returns the parameter n of the fit result.

Parameters
ndegree of the parameter; must be no larger than Degree
Returns
the parameter of the fit, in y/x^n units
Exceptions
std::range_errorif there is no unique solution

Reimplemented from lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual FitMatrix_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameterCovariance ( ) const
overridevirtualinherited

Computes and returns all the covariance matrix of the fit result.

Returns
the the covariance matrix of the fit
Exceptions
std::range_errorif there is no unique solution

The matrix is symmetric, and stored in a linear way (say, first row, then second row).

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual Data_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameterError ( unsigned int  n) const
overridevirtualinherited

Returns the error on parameter n of the fit result.

Parameters
ndegree of the parameter; must be no larger than Degree
Returns
the error on the parameter of the fit, in y/x^n units
Exceptions
std::range_errorif there is no unique solution

Reimplemented from lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameterErrors ( ) const
overridevirtualinherited

Computes and returns all the parameter errors of the fit result.

Returns
the full set of parameter errors of the fit
Exceptions
std::range_errorif there is no unique solution

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameterErrors ( FitMatrix_t const &  Smat) const
inlineprotectedvirtualinherited

Computes and returns all the parameter errors of the fit result.

Definition at line 798 of file SimpleFits.h.

799  { return ExtractParameterErrors(Smat); }
static FitParameters_t ExtractParameterErrors(FitMatrix_t const &Smat)
Extracts parameter errors from diagonal of the covarriance matrix.
virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( ) const
overridevirtualinherited

Computes and returns all the parameters of the fit result.

Returns
the full set of parameters of the fit
Exceptions
std::range_errorif there is no unique solution

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Referenced by cluster::ClusterParamsAlg::IntegrateFitCharge().

virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( FitMatrix_t const &  Xmat) const
protectedvirtualinherited

Returns the fitted parameters using the provided information.

virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::FitParameters ( FitMatrix_t const &  Smat,
Data_t   
) const
protectedvirtualinherited

Returns the fitted parameters using the provided information.

template<typename T>
Data_t lar::util::LinearFit< T >::I ( ) const
inlineprotected

Aliases.

Definition at line 920 of file SimpleFits.h.

920 { return Base_t::stats.template XN<0>(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::Intercept ( ) const
inline

Returns the intercept of the fit.

Returns
the intercept of the fit, in y units
Exceptions
std::range_errorif there is no unique solution

Definition at line 877 of file SimpleFits.h.

877 { return this->FitParameter(0); }
virtual Data_t FitParameter(unsigned int n) const override
Returns the parameter n of the fit result.
template<typename T>
Data_t lar::util::LinearFit< T >::InterceptError ( ) const
inline

Returns the error on intercept of the fit.

Returns
the error on intercept of the fit, in y units
Exceptions
std::range_errorif there is no unique solution

Definition at line 891 of file SimpleFits.h.

891 { return this->FitParameterError(0); }
virtual Data_t FitParameterError(unsigned int n) const override
Returns the error on parameter n of the fit result.
template<typename T>
Data_t lar::util::LinearFit< T >::InterceptSlopeCovariance ( ) const
inline

Returns the covariance between intercept and slope of the fit.

Returns
the covariance between intercept and slope of the fit, in y^2 units
Exceptions
std::range_errorif there is no unique solution

Definition at line 905 of file SimpleFits.h.

906  { return this->FitParameterCovariance()[0 * NParams + 1]; }
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
virtual FitMatrix_t FitParameterCovariance() const override
Computes and returns all the covariance matrix of the fit result.
virtual FitMatrix_t lar::util::details::SimpleFitterInterface< T, N >::InvertMatrix ( FitMatrix_t const &  mat,
Data_t  det 
) const
inlineprotectedvirtualinherited

Computes the inverse of a matrix (using provided determinant)

Definition at line 620 of file SimpleFits.h.

621  { return MatrixOps::InvertSymmetricMatrix(mat, det); }
Float_t mat
Definition: plot.C:40
virtual FitMatrix_t lar::util::details::SimpleFitterInterface< T, N >::InvertMatrix ( FitMatrix_t const &  mat) const
inlineprotectedvirtualinherited

Computes the inverse of a matrix.

Definition at line 624 of file SimpleFits.h.

625  { return MatrixOps::InvertSymmetricMatrix(mat); }
Float_t mat
Definition: plot.C:40
virtual bool lar::util::details::SimplePolyFitterBase< T, D >::isValid ( ) const
overridevirtualinherited

Returns if the fit has valid results.

Returns
if the fit has valid results

The fit has no valid results if:

  1. insufficient data has been add()ed (no more than the fit Degree)
  2. if input points are vertically aligned

Note that checking point 2 is expensive in terms of time.

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

virtual FitMatrix_t lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixX ( ) const
protectedvirtualinherited

Fills and returns the matrix of x^n sum coefficients ( { x^(i+j) } )

virtual FitParameters_t lar::util::details::SimplePolyFitterBase< T, D >::MakeMatrixY ( ) const
protectedvirtualinherited

Fills and returns the matrix (vector) of x^n y sum coefficients.

virtual FitParameters_t lar::util::details::SimpleFitterInterface< T, N >::MatrixProduct ( FitMatrix_t const &  mat,
FitParameters_t const &  vec 
) const
inlineprotectedvirtualinherited

Computes the product of a FitMatrix_t and a FitParameters_t.

Definition at line 629 of file SimpleFits.h.

630  { return MatrixOps::MatrixVectorProduct(mat, vec); }
Float_t mat
Definition: plot.C:40
template<typename T , unsigned int D>
int lar::util::details::SimplePolyFitterDataBase< T, D >::N ( ) const
inlineinherited

Definition at line 427 of file SimpleFits.h.

427 { return stats.N(); }
int N() const
Returns the number of entries added.
Definition: SimpleFits.h:266
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
virtual int lar::util::details::SimplePolyFitterBase< T, D >::NDF ( ) const
inlineoverridevirtualinherited

Returns the degrees of freedom in the determination of the fit.

Returns
the degrees of freedom in the determination of the fit

The return value may be 0 or negative if insufficient points have been added.

Implements lar::util::details::SimpleFitterInterface< T, D+1 >.

Definition at line 731 of file SimpleFits.h.

731 { return Base_t::N() - NParams; }
static constexpr unsigned int NParams
Number of parameters in the fit.
Definition: SimpleFits.h:651
Data_t lar::util::details::SimpleFitterInterface< T, N >::operator() ( Data_t  x) const
inlineinherited

Evaluates the fitted function; alias of Evaluate()

Definition at line 603 of file SimpleFits.h.

603 { return Evaluate(x); }
Float_t x
Definition: compare.C:6
virtual Data_t Evaluate(Data_t x) const =0
Evaluates the fitted function at the specified point.
virtual Data_t lar::util::details::SimplePolyFitterBase< T, D >::Param ( unsigned int  n,
FitMatrix_t const &  Xmat 
) const
protectedvirtualinherited

Computes a single fit parameter using the given information.

virtual Data_t lar::util::details::SimplePolyFitterBase< T, D >::Param ( unsigned int  n,
FitMatrix_t const &  Xmat,
Data_t  detXmat 
) const
protectedvirtualinherited

Computes a single fit parameter using the given information.

template<typename T , unsigned int D>
template<typename Stream >
void lar::util::details::SimplePolyFitterDataBase< T, D >::PrintStats ( Stream &  out) const
inlineinherited

Prints the collected statistics into a stream.

Definition at line 436 of file SimpleFits.h.

436 { stats.Print(out); }
void Print(Stream &out) const
Prints the statistics into a stream.
Definition: SimpleFits.h:1519
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::Slope ( ) const
inline

Returns the slope of the fit.

Returns
the slope of the fit, in y/x units
Exceptions
std::range_errorif there is no unique solution

Definition at line 884 of file SimpleFits.h.

884 { return this->FitParameter(1); }
virtual Data_t FitParameter(unsigned int n) const override
Returns the parameter n of the fit result.
template<typename T>
Data_t lar::util::LinearFit< T >::SlopeError ( ) const
inline

Returns the error in slope of the fit.

Returns
the error on slope of the fit, in y/x units
Exceptions
std::range_errorif there is no unique solution

Definition at line 898 of file SimpleFits.h.

898 { return this->FitParameterError(1); }
virtual Data_t FitParameterError(unsigned int n) const override
Returns the error on parameter n of the fit result.
template<typename T , unsigned int D>
template<typename V >
static constexpr V lar::util::details::SimplePolyFitterDataBase< T, D >::sqr ( V const &  v)
inlinestaticinherited

Returns the square of the specified value.

Definition at line 441 of file SimpleFits.h.

References geo::sqr().

441 { return Collector_t::sqr(v); }
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: SimpleFits.h:283
static constexpr Data_t lar::util::details::SimpleFitterInterface< T, N >::sqr ( Data_t  v)
inlinestaticinherited

Returns the square of the specified data value.

Definition at line 607 of file SimpleFits.h.

607 { return v*v; }
template<typename T>
Data_t lar::util::LinearFit< T >::X ( ) const
inlineprotected

Aliases.

Definition at line 921 of file SimpleFits.h.

921 { return Base_t::stats.template XN<1>(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::X2 ( ) const
inlineprotected

Aliases.

Definition at line 922 of file SimpleFits.h.

922 { return Base_t::stats.template XN<2>(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
Data_t lar::util::details::SimplePolyFitterDataBase< T, D >::XN ( unsigned int  n) const
inlineprotectedinherited

Returns the weighted sum of x^n.

Definition at line 447 of file SimpleFits.h.

References lar::util::details::FitDataCollector< T, D >::XN().

447 { return stats.XN(n); }
Data_t XN(unsigned int n) const
Returns the weighted sum of x^n.
Definition: SimpleFits.h:287
Char_t n[5]
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T , unsigned int D>
Data_t lar::util::details::SimplePolyFitterDataBase< T, D >::XNY ( unsigned int  n) const
inlineprotectedinherited

Returns the weighted sum of x^n y.

Definition at line 450 of file SimpleFits.h.

References lar::util::details::FitDataCollector< T, D >::XNY().

450 { return stats.XNY(n); }
Data_t XNY(unsigned int n) const
Returns the weighted sum of x^n y.
Definition: SimpleFits.h:291
Char_t n[5]
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::XY ( ) const
inlineprotected

Aliases.

Definition at line 924 of file SimpleFits.h.

924 { return Base_t::stats.template XNY<1>(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::Y ( ) const
inlineprotected

Aliases.

Definition at line 923 of file SimpleFits.h.

923 { return Base_t::stats.template XNY<0>(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
template<typename T>
Data_t lar::util::LinearFit< T >::Y2 ( ) const
inlineprotected

Aliases.

Definition at line 925 of file SimpleFits.h.

925 { return Base_t::stats.Y2(); }
Collector_t stats
statistics collected from fit data input
Definition: SimpleFits.h:444
Data_t Y2() const
Returns the weighted sum of y^2.
Definition: SimpleFits.h:307

Member Data Documentation

constexpr unsigned int lar::util::details::SimplePolyFitterBase< T, D >::Degree
staticinherited

Degree of the fit.

Definition at line 648 of file SimpleFits.h.

constexpr unsigned int lar::util::details::SimplePolyFitterBase< T, D >::NParams
staticinherited

Number of parameters in the fit.

Definition at line 651 of file SimpleFits.h.

template<typename T , unsigned int D>
Collector_t lar::util::details::SimplePolyFitterDataBase< T, D >::stats
protectedinherited

statistics collected from fit data input

Definition at line 444 of file SimpleFits.h.


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