All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Types | Public Member Functions | Private Types | List of all members
lar::util::QuadraticFit< T > Class Template Reference

Performs a second-degree fit of data. More...

#include <SimpleFits.h>

Inheritance diagram for lar::util::QuadraticFit< T >:
lar::util::details::SimplePolyFitterBase< T, 2U > 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...
 
- Public Types inherited from lar::util::details::SimplePolyFitterBase< T, 2U >
using Data_t = typename Base_t::Data_t
 type of the data More...
 
using FitParameters_t = typename Interface_t::FitParameters_t
 type of set of fit parameters More...
 
using FitMatrix_t = typename Interface_t::FitMatrix_t
 type of matrix for covariance (a std::array) More...
 
- Public Types inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
using Data_t = T
 type of the data More...
 
using MatrixOps = FastMatrixOperations< Data_t, NParams >
 
using FitParameters_t = std::array< Data_t, NParams >
 type of set of fit parameters More...
 
using FitMatrix_t = typename MatrixOps::Matrix_t
 type of matrix for covariance (a std::array) More...
 
- Public Types inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
using Data_t = typename Collector_t::Data_t
 type of the data More...
 
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

virtual Data_t ChiSquare () const override
 Returns the $ \chi^{2} $ of the fit. More...
 
- Public Member Functions inherited from lar::util::details::SimplePolyFitterBase< T, 2U >
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 Data_t Evaluate (Data_t x) const override
 Evaluates the fitted function at the specified point. More...
 
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...
 
- Public Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
virtual ~SimpleFitterInterface ()=default
 Virtual destructor: compiler's default. 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 =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...
 
- Public Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
void clear ()
 Clears all the statistics. More...
 
template<typename Stream >
void PrintStats (Stream &out) const
 Prints the collected statistics into a stream. More...
 
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)
 
int N () const
 
Data_t AverageUncertainty () const
 

Protected Member Functions

Data_t I () const
 Aliases. More...
 
Data_t X () const
 
Data_t X2 () const
 
Data_t X3 () const
 
Data_t X4 () const
 
Data_t Y () const
 
Data_t XY () const
 
Data_t X2Y () const
 
Data_t Y2 () const
 
- Protected Member Functions inherited from lar::util::details::SimplePolyFitterBase< T, 2U >
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 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
 
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
 
- Protected Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
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...
 
- Protected Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
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...
 

Private Types

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

Additional Inherited Members

- Static Public Member Functions inherited from lar::util::details::SimplePolyFitterBase< T, 2U >
static FitParameters_t ExtractParameterErrors (FitMatrix_t const &Smat)
 Extracts parameter errors from diagonal of the covarriance matrix. More...
 
- Static Public Member Functions inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
static constexpr Data_t sqr (Data_t v)
 Returns the square of the specified data value. More...
 
static constexpr Data_t cube (Data_t v)
 Returns the cube of the specified data value. More...
 
- Static Public Member Functions inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
template<typename V >
static constexpr V sqr (V const &v)
 Returns the square of the specified value. More...
 
- Static Public Attributes inherited from lar::util::details::SimplePolyFitterBase< T, 2U >
static constexpr unsigned int Degree
 Degree of the fit. More...
 
static constexpr unsigned int NParams
 Number of parameters in the fit. More...
 
- Static Public Attributes inherited from lar::util::details::SimpleFitterInterface< T, D+1 >
static constexpr unsigned int NParams
 Number of parameters in the fit. More...
 
- Static Public Attributes inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
static constexpr unsigned int Degree = Collector_t::Degree
 Degree of the fit. More...
 
- Protected Attributes inherited from lar::util::details::SimplePolyFitterDataBase< T, D >
Collector_t stats
 statistics collected from fit data input More...
 

Detailed Description

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

Performs a second-degree fit of data.


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

The quadratic fit connects measurements $ ( y_{i} \pm \sigma_{y,i} ) $ with a parameter $ ( x_{i} ) $ not affected by uncertainty. The returned parameters describe a quadratic curve $ f(x) = a_{0} + a_{1} x + a_{2} x^{2} $ obtained by minimization of $ \chi^{2} = \sum_{i} \frac{ \left(y_{i} - f(x_{i}) \right)^{2} }{ \sigma^{2}_{y,i} }$

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

This simple quadratic 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 953 of file SimpleFits.h.

Member Typedef Documentation

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

Definition at line 954 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::QuadraticFit< T >::FitMatrix_t = std::array<Data_t, sqr(NParams)>

Definition at line 971 of file SimpleFits.h.

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

type of set of fit parameters

Definition at line 970 of file SimpleFits.h.

Member Function Documentation

template<typename T >
auto lar::util::QuadraticFit< 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, 2U >.

Definition at line 1771 of file SimpleFits.h.

1772 {
1773  FitParameters_t a = this->FitParameters();
1774  return Y2() - Data_t(2) * (a[0]*Y() + a[1]*XY() + a[2]*X2Y())
1775  + sqr(a[0])*I() + Data_t(2) * a[0] * ( a[1]*X() + a[2]*X2() )
1776  + sqr(a[1])*X2() + Data_t(2) * a[1] * ( a[2]*X3() )
1777  + sqr(a[2])*X4();
1778 } // QuadraticFit<T>::ChiSquare()
Data_t X4() const
Definition: SimpleFits.h:991
Data_t Y2() const
Definition: SimpleFits.h:995
process_name gaushit a
typename Base_t::Data_t Data_t
type of the data
Definition: SimpleFits.h:653
std::array< Data_t, NParams > FitParameters_t
type of set of fit parameters
Definition: SimpleFits.h:970
Data_t Y() const
Definition: SimpleFits.h:992
static constexpr V sqr(V const &v)
Returns the square of the specified value.
Definition: SimpleFits.h:441
Data_t X2Y() const
Definition: SimpleFits.h:994
Data_t I() const
Aliases.
Definition: SimpleFits.h:987
virtual FitParameters_t FitParameters() const override
Computes and returns all the parameters of the fit result.
Data_t XY() const
Definition: SimpleFits.h:993
Data_t X() const
Definition: SimpleFits.h:988
Data_t X2() const
Definition: SimpleFits.h:989
Data_t X3() const
Definition: SimpleFits.h:990
template<typename T>
Data_t lar::util::QuadraticFit< T >::I ( ) const
inlineprotected

Aliases.

Definition at line 987 of file SimpleFits.h.

987 { 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::QuadraticFit< T >::X ( ) const
inlineprotected

Definition at line 988 of file SimpleFits.h.

988 { 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::QuadraticFit< T >::X2 ( ) const
inlineprotected

Definition at line 989 of file SimpleFits.h.

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

Definition at line 994 of file SimpleFits.h.

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

Definition at line 990 of file SimpleFits.h.

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

Definition at line 991 of file SimpleFits.h.

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

Definition at line 993 of file SimpleFits.h.

993 { 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::QuadraticFit< T >::Y ( ) const
inlineprotected

Definition at line 992 of file SimpleFits.h.

992 { 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::QuadraticFit< T >::Y2 ( ) const
inlineprotected

Definition at line 995 of file SimpleFits.h.

995 { 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

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