NAGASH 0.9.8
Next Generation Analysis System
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Private Attributes | List of all members
NAGASH::Chi2Fitter Class Reference

fit the parameters of a \(\chi^2\) shape function. More...

#include "NAGASH/Chi2Fitter.h"

Inheritance diagram for NAGASH::Chi2Fitter:
NAGASH::Tool

Classes

class  Chi2FitterFCN
 fcn function to calculate the \(\chi^2\) More...
 

Public Types

enum class  FitMethod { Eigen , Minuit }
 Fit method. More...
 

Public Member Functions

 Chi2Fitter (std::shared_ptr< MSGTool >, uint64_t)
 Constructor.
 
 Chi2Fitter (std::shared_ptr< MSGTool >, uint64_t, TH1D *, TH2D *_cov_=nullptr)
 Constructor.
 
const TMatrixD & Cov ()
 
double Error (uint64_t)
 Get the fit error of ith parameter.
 
void Fit (FitMethod fm=FitMethod::Eigen)
 Start to fit.
 
double FitChi2 ()
 Get the \(\chi^2\) of the fitting procedure.
 
double GetChi2 (uint64_t)
 Get the \(\chi^2\) of ith model.
 
double OffSet ()
 The offset parameter \( b\) of the fitted \(\chi^2\) function.
 
void SetModel (const std::vector< double > &, double)
 Set the \(\chi^2\) value of a set of parameters.
 
void SetModel (const std::vector< double > &, TH1D *, TH2D *cov=nullptr)
 Set the model with a set of parameter.
 
void SetRange (int min, int max)
 Set the range of calculation of \(\chi^2\) of the target histogram.
 
const std::vector< double > & Value ()
 
double Value (uint64_t)
 Get the best-fit value of ith parameter.
 

Private Attributes

double chi2 = 0
 
TMatrixD cov
 
uint64_t dimension = 1
 
HistTool histtool
 
bool isvalid = false
 
double offset = 0
 
int RangeMax = 1
 
int RangeMin = 1
 
TH1D * target = nullptr
 
TH2D * targetcov = nullptr
 
std::vector< double > value
 
std::vector< double > vchi2
 
std::vector< std::vector< double > > vvalue
 
std::vector< double > vvaluemax
 
std::vector< double > vvaluemin
 

Additional Inherited Members

- Protected Member Functions inherited from NAGASH::Tool
 Tool ()=delete
 
 Tool (const Tool &tool)=delete
 
 Tool (std::shared_ptr< MSGTool > MSG)
 Constructor.
 
 Tool (Tool &&tool)=delete
 
virtual ~Tool ()=default
 
std::shared_ptr< MSGToolMSGUser ()
 return the MSGTool inside.
 
Tooloperator= (const Tool &tool)=delete
 
Tooloperator= (Tool &&tool)=delete
 

Detailed Description

fit the parameters of a \(\chi^2\) shape function.

For a given set of \(\chi^2\) at different points: \((\vec{x},\chi^2)\), fit to the quadratic function:

\[ \chi^2(\vec{x},\vec{v},\Sigma)=(\vec{x}-\vec{v})^{T}\Sigma^{-1}(\vec{x}-\vec{v})+b \]

Where \(\vec{v}\) are best-fit value of parameters with \(\Sigma\) as their covariance matrix.

This tool provides methods of processing histograms. Firstly, user should pass the target histogram as well as its covariance matrix to this tool, then set different models with different parameters. Then the \(\chi^2\)s are calculated and best-fit parameters are fitted along with their covariance matrix.

Definition at line 23 of file Chi2Fitter.h.

Member Enumeration Documentation

◆ FitMethod

enum class NAGASH::Chi2Fitter::FitMethod
strong

Fit method.

Enumerator
Eigen 

use matrix calculation to get the fitted value, Eigen library is used.

Minuit 

use minuit library to fit the value.

Definition at line 27 of file Chi2Fitter.h.

Constructor & Destructor Documentation

◆ Chi2Fitter() [1/2]

Chi2Fitter::Chi2Fitter ( std::shared_ptr< MSGTool msg,
uint64_t  dim,
TH1D *  _target_,
TH2D *  _cov_ = nullptr 
)

Constructor.

Parameters
msginput MSGTool.
dimthe degrees of freedomof the \(\chi^2\).
_target_the target histogram to be compared with.
_cov_the covariance matrix of the target histogram.

Definition at line 32 of file Chi2Fitter.cxx.

◆ Chi2Fitter() [2/2]

Chi2Fitter::Chi2Fitter ( std::shared_ptr< MSGTool msg,
uint64_t  dim 
)

Constructor.

Parameters
msginput MSGTool.
dimthe degrees of freedomof the \(\chi^2\).

Definition at line 51 of file Chi2Fitter.cxx.

Member Function Documentation

◆ Cov()

const TMatrixD & NAGASH::Chi2Fitter::Cov ( )
inline

Definition at line 44 of file Chi2Fitter.h.

◆ Error()

double Chi2Fitter::Error ( uint64_t  index)

Get the fit error of ith parameter.

Parameters
indexindex of the parameter.
Returns
error of ith parameter.

Definition at line 242 of file Chi2Fitter.cxx.

◆ Fit()

void Chi2Fitter::Fit ( FitMethod  fm = FitMethod::Eigen)

Start to fit.

Parameters
fmthe fit method.

Definition at line 315 of file Chi2Fitter.cxx.

◆ FitChi2()

double Chi2Fitter::FitChi2 ( )

Get the \(\chi^2\) of the fitting procedure.

Returns
the \(\chi^2\) of the fitting procedure.

Definition at line 223 of file Chi2Fitter.cxx.

◆ GetChi2()

double Chi2Fitter::GetChi2 ( uint64_t  index)

Get the \(\chi^2\) of ith model.

Parameters
indexthe index of the model.
Returns
the \(\chi^2\) value.

Definition at line 213 of file Chi2Fitter.cxx.

◆ OffSet()

double Chi2Fitter::OffSet ( )

The offset parameter \( b\) of the fitted \(\chi^2\) function.

Returns
the offset parameter \( b\).

Definition at line 252 of file Chi2Fitter.cxx.

◆ SetModel() [1/2]

void Chi2Fitter::SetModel ( const std::vector< double > &  vv,
double  _chi2_ 
)

Set the \(\chi^2\) value of a set of parameters.

Parameters
vvthe set of parameters, must be the same size as the dimension of the \(\chi^2\).
_chi2_the corresponding \(\chi^2\) value.

Definition at line 77 of file Chi2Fitter.cxx.

◆ SetModel() [2/2]

void Chi2Fitter::SetModel ( const std::vector< double > &  vv,
TH1D *  hmodel,
TH2D *  covmodel = nullptr 
)

Set the model with a set of parameter.

Parameters
vvthe parameters defining the model, must be the same size as the dimension of the \(\chi^2\).
hmodelthe histogram of the model.
covmodelthe covariance matrix of the histogram.

Definition at line 111 of file Chi2Fitter.cxx.

◆ SetRange()

void Chi2Fitter::SetRange ( int  min,
int  max 
)

Set the range of calculation of \(\chi^2\) of the target histogram.

Parameters
minmininum bin index.
maxmaximum bin index.

Definition at line 60 of file Chi2Fitter.cxx.

◆ Value() [1/2]

const std::vector< double > & NAGASH::Chi2Fitter::Value ( )
inline

Definition at line 43 of file Chi2Fitter.h.

◆ Value() [2/2]

double Chi2Fitter::Value ( uint64_t  index)

Get the best-fit value of ith parameter.

Parameters
indexindex of the parameter.
Returns
best-fit value of ith parameter.

Definition at line 231 of file Chi2Fitter.cxx.

Member Data Documentation

◆ chi2

double NAGASH::Chi2Fitter::chi2 = 0
private

Definition at line 81 of file Chi2Fitter.h.

◆ cov

TMatrixD NAGASH::Chi2Fitter::cov
private

Definition at line 80 of file Chi2Fitter.h.

◆ dimension

uint64_t NAGASH::Chi2Fitter::dimension = 1
private

Definition at line 70 of file Chi2Fitter.h.

◆ histtool

HistTool NAGASH::Chi2Fitter::histtool
private

Definition at line 84 of file Chi2Fitter.h.

◆ isvalid

bool NAGASH::Chi2Fitter::isvalid = false
private

Definition at line 69 of file Chi2Fitter.h.

◆ offset

double NAGASH::Chi2Fitter::offset = 0
private

Definition at line 82 of file Chi2Fitter.h.

◆ RangeMax

int NAGASH::Chi2Fitter::RangeMax = 1
private

Definition at line 72 of file Chi2Fitter.h.

◆ RangeMin

int NAGASH::Chi2Fitter::RangeMin = 1
private

Definition at line 71 of file Chi2Fitter.h.

◆ target

TH1D* NAGASH::Chi2Fitter::target = nullptr
private

Definition at line 73 of file Chi2Fitter.h.

◆ targetcov

TH2D* NAGASH::Chi2Fitter::targetcov = nullptr
private

Definition at line 74 of file Chi2Fitter.h.

◆ value

std::vector<double> NAGASH::Chi2Fitter::value
private

Definition at line 79 of file Chi2Fitter.h.

◆ vchi2

std::vector<double> NAGASH::Chi2Fitter::vchi2
private

Definition at line 75 of file Chi2Fitter.h.

◆ vvalue

std::vector<std::vector<double> > NAGASH::Chi2Fitter::vvalue
private

Definition at line 76 of file Chi2Fitter.h.

◆ vvaluemax

std::vector<double> NAGASH::Chi2Fitter::vvaluemax
private

Definition at line 77 of file Chi2Fitter.h.

◆ vvaluemin

std::vector<double> NAGASH::Chi2Fitter::vvaluemin
private

Definition at line 78 of file Chi2Fitter.h.


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