89 if (
this == &rhs)
return *
this;
115 MATH_WARN_MSG(
"Fitter::SetFunction",
"Requested function does not provide gradient - use it as non-gradient function ");
141 MATH_WARN_MSG(
"Fitter::SetFunction",
"Requested function does not provide gradient - use it as non-gradient function ");
183 unsigned int npar = fcn.
NDim();
185 MATH_ERROR_MSG(
"Fitter::SetFCN",
"FCN function has zero parameters ");
210 if (!
SetFCN(static_cast<const ROOT::Math::IMultiGenFunction &>(fcn),params, dataSize, chi2fit) )
return false;
219 if (!
SetFCN(fcn,params,fcn.
NPoints(), chi2fit) )
return false;
229 if (!
SetFCN(fcn,params,fcn.
NPoints(), chi2fit) )
return false;
240 if (!
SetFCN(fcn, params,dataSize,chi2fit) )
return false;
249 if (!
SetFCN(fcn, params,dataSize, chi2fit) )
return false;
255 if (!
SetFCN(fcn, params) )
return false;
261 if (!
SetFCN(fcn, params) )
return false;
273 MATH_ERROR_MSG(
"Fitter::FitFCN",
"Fit Parameter settings have not been created ");
279 return SetFCN(newFcn,params,dataSize,chi2fit);
285 if (!
SetFCN(fcn, npar, params, dataSize, chi2fit))
return false;
297 MATH_ERROR_MSG(
"Fitter::FitFCN",
"Objective function has not been set");
314 MATH_ERROR_MSG(
"Fitter::FitFCN",
"Objective function has not been set");
320 double fcnval = (*fObjFunction)(
fResult->GetParams() );
336 MATH_ERROR_MSG(
"Fitter::DoLeastSquareFit",
"model function is not set");
357 MATH_INFO_MSG(
"Fitter::DoLeastSquareFit",
"use gradient from model function");
364 MATH_ERROR_MSG(
"Fitter::DoLeastSquareFit",
"wrong type of function - it does not provide gradient");
380 MATH_ERROR_MSG(
"Fitter::DoBinnedLikelihoodFit",
"model function is not set");
390 MATH_INFO_MSG(
"Fitter::DoBinnedLikelihoodFit",
"MINOS errors cannot be computed in weighted likelihood fits");
414 MATH_INFO_MSG(
"Fitter::DoLikelihoodFit",
"use gradient from model function");
418 MATH_ERROR_MSG(
"Fitter::DoBinnedLikelihoodFit",
"wrong type of function - it does not provide gradient");
424 MATH_WARN_MSG(
"Fitter::DoBinnedLikelihoodFit",
"Not-extended binned fit with gradient not yet supported - do an extended fit");
448 MATH_ERROR_MSG(
"Fitter::DoUnbinnedLikelihoodFit",
"model function is not set");
453 MATH_INFO_MSG(
"Fitter::DoUnbinnedLikelihoodFit",
"MINOS errors cannot be computed in weighted likelihood fits");
485 MATH_INFO_MSG(
"Fitter::DoUnbinnedLikelihoodFit",
"use gradient from model function");
489 MATH_WARN_MSG(
"Fitter::DoUnbinnedLikelihoodFit",
"Extended unbinned fit with gradient not yet supported - do a not-extended fit");
500 MATH_ERROR_MSG(
"Fitter::DoUnbinnedLikelihoodFit",
"wrong type of function - it does not provide gradient");
527 MATH_ERROR_MSG(
"Fitter::CalculateHessErrors",
"Objective function has not been set");
536 MATH_ERROR_MSG(
"Fitter::CalculateHessErrors",
"Re-computation of Hesse errors not implemented for weighted likelihood fits");
537 MATH_INFO_MSG(
"Fitter::CalculateHessErrors",
"Do the Fit using configure option FitConfig::SetParabErrors()");
562 MATH_ERROR_MSG(
"Fitter::CalculateHessErrors",
"Error initializing the minimizer");
569 MATH_ERROR_MSG(
"Fitter::CalculateHessErrors",
"Need to do a fit before calculating the errors");
575 if (!ret)
MATH_WARN_MSG(
"Fitter::CalculateHessErrors",
"Error when calculating Hessian");
607 MATH_ERROR_MSG(
"Fitter::CalculateMinosErrors",
"Minimizer does not exist - cannot calculate Minos errors");
612 MATH_ERROR_MSG(
"Fitter::CalculateMinosErrors",
"Invalid Fit Result - cannot calculate Minos errors");
617 MATH_ERROR_MSG(
"Fitter::CalculateMinosErrors",
"Computation of MINOS errors not implemented for weighted likelihood fits");
627 unsigned int n = (ipars.size() > 0) ? ipars.size() :
fResult->Parameters().size();
629 for (
unsigned int i = 0; i <
n; ++i) {
631 unsigned int index = (ipars.size() > 0) ? ipars[i] : i;
632 bool ret =
fMinimizer->GetMinosError(index, elow, eup);
633 if (ret)
fResult->SetMinosError(index, elow, eup);
637 MATH_ERROR_MSG(
"Fitter::CalculateMinosErrors",
"Minos error calculation failed for all parameters");
646 struct ObjFuncTrait {
647 static unsigned int NCalls(
const Func & ) {
return 0; }
648 static int Type(
const Func & ) {
return -1; }
649 static bool IsGrad() {
return false; }
655 static bool IsGrad() {
return false; }
661 static bool IsGrad() {
return true; }
672 MATH_ERROR_MSG(
"Fitter::DoInitMinimizer",
"wrong function dimension or wrong size for FitConfig");
688 MATH_ERROR_MSG(
"Fitter::DoInitMinimizer",
"wrong type of function - it does not provide gradient");
731 std::cout <<
"ROOT::Fit::Fitter::DoMinimization : ncalls = " <<
fResult->fNCalls <<
" type of objfunc " << fFitFitResType <<
" typeid: " <<
typeid(*fObjFunction).name() <<
" use gradient " <<
fUseGradient << std::endl;
750 fObjFunction = std::unique_ptr<ROOT::Math::IMultiGenFunction> ( objFunc.
Clone() );
759 for (
unsigned int i = 0; i <
fConfig.
NPar(); ++i) {
772 if (fcn) ncalls = fcn->
NCalls();
776 if (fcn) ncalls = fcn->
NCalls();
791 MATH_ERROR_MSG(
"Fitter::ApplyWeightCorrection",
"Must perform first a fit before applying the correction");
795 unsigned int n = loglw2.
NDim();
797 std::vector<double> cov(n*n);
798 bool ret =
fMinimizer->GetCovMatrix(&cov[0] );
800 MATH_ERROR_MSG(
"Fitter::ApplyWeightCorrection",
"Previous fit has no valid Covariance matrix");
804 fObjFunction = std::unique_ptr<ROOT::Math::IMultiGenFunction> ( loglw2.
Clone() );
817 MATH_ERROR_MSG(
"Fitter::ApplyWeightCorrection",
"Error running Hesse on weight2 likelihood - cannot compute errors");
822 MATH_WARN_MSG(
"Fitter::ApplyWeightCorrection",
"Covariance matrix for weighted likelihood is not accurate, the errors may be not reliable");
824 MATH_WARN_MSG(
"Fitter::ApplyWeightCorrection",
"Covariance matrix for weighted likelihood was forced to be defined positive");
827 MATH_ERROR_MSG(
"Fitter::ApplyWeightCorrection",
"Covariance matrix for weighted likelihood is not valid !");
841 std::vector<double> hes(n*n);
844 MATH_ERROR_MSG(
"Fitter::ApplyWeightCorrection",
"Error retrieving Hesse on weight2 likelihood - cannot compute errors");
860 std::vector<double> tmp(n*n);
861 for (
unsigned int i = 0; i <
n; ++i) {
862 for (
unsigned int j = 0; j <
n; ++j) {
863 for (
unsigned int k = 0; k <
n; ++k)
864 tmp[i*n+j] += hes[i*n + k] * cov[k*n + j];
868 std::vector<double> newCov(n*n);
869 for (
unsigned int i = 0; i <
n; ++i) {
870 for (
unsigned int j = 0; j <
n; ++j) {
871 for (
unsigned int k = 0; k <
n; ++k)
872 newCov[i*n+j] += cov[i*n + k] * tmp[k*n + j];
877 for (
unsigned int i = 0; i <
n; ++i) {
879 for (
unsigned int j = 0; j <= i; ++j)
880 fResult->fCovMatrix[k++] = newCov[i *n + j];
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
void ExamineFCN()
look at the user provided FCN and get data and model function is they derive from ROOT::Fit FCN class...
Namespace for new ROOT classes and functions.
void(* MinuitFCN_t)(int &npar, double *gin, double &f, double *u, int flag)
fit using user provided FCN with Minuit-like interface If npar = 0 it is assumed that the parameters ...
ROOT::Math::Minimizer * CreateMinimizer()
create a new minimizer according to chosen configuration
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
Fitter & operator=(const Fitter &rhs)
Assignment operator (disabled, class is not copyable)
bool EvalFCN()
Perform a simple FCN evaluation.
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
bool NormalizeErrors() const
flag to check if resulting errors are be normalized according to chi2/ndf
bool DoBinnedLikelihoodFit(bool extended=true)
binned likelihood fit
const std::vector< unsigned int > & MinosParams() const
return vector of parameter indeces for which the Minos Error will be computed
LogLikelihoodFCN class for likelihood fits.
unsigned int NPar() const
number of parameters settings
std::shared_ptr< IModelFunction > fFunc
virtual unsigned int NPoints() const
return the number of data points used in evaluating the function
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
Clone a function.
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
virtual BaseObjFunction::Type_t Type() const
get type of fit method function
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
bool DoLinearFit()
linear least square fit
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
void SetErrorDef(double err)
set error def
#define MATH_WARN_MSG(loc, str)
std::shared_ptr< ROOT::Fit::FitResult > fResult
copy of the fitted function containing on output the fit result
MultiDimParamFunctionAdapter class to wrap a one-dimensional parametric function in a multi dimension...
bool CalculateHessErrors()
perform an error analysis on the result using the Hessian Errors are obtaied from the inverse of the ...
const ParameterSettings & ParSettings(unsigned int i) const
get the parameter settings for the i-th parameter (const method)
void SetValue(double val)
set the value
void CreateParamsSettings(const ROOT::Math::IParamMultiFunction &func)
set the parameter settings from a model function.
Fitter()
Default constructor.
bool UseWeightCorrection() const
Apply Weight correction for error matrix computation.
class evaluating the log likelihood for binned Poisson likelihood fits it is template to distinguish ...
int PrintLevel() const
non-static methods for retrieving options
virtual Type_t Type() const
return the type of method, override if needed
bool UpdateAfterFit() const
Update configuration after a fit using the FitResult.
bool ParabErrors() const
do analysis for parabolic errors
bool ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction &loglw2, bool minimizeW2L=false)
apply correction in the error matrix for the weights for likelihood fits This method can be called on...
const FitConfig & Config() const
access to the fit configuration (const method)
#define MATH_ERROR_MSG(loc, str)
void UseSumOfWeightSquare(bool on=true)
void SetMinosErrors(bool on=true)
set Minos erros computation to be performed after fitting
Documentation for the abstract class IBaseFunctionMultiDim.
Chi2FCN class for binnned fits using the least square methods.
std::shared_ptr< ROOT::Fit::FitData > fData
pointer to used minimizer
#define MATH_INFO_MSG(loc, str)
void SetMinimizer(const char *type, const char *algo=0)
set minimizer type
void SetStepSize(double err)
set the step size
virtual BaseObjFunction::Type_t Type() const
get type of fit method function
BasicFCN class: base class for the objective functions used in the fits It has a reference to the dat...
Fitter class, entry point for performing all type of fits.
const std::vector< ROOT::Fit::ParameterSettings > & ParamsSettings() const
get the vector of parameter settings (const method)
virtual BaseObjFunction::Type_t Type() const
get type of fit method function
static double DefaultErrorDef()
bool FitFCN()
Perform a fit with the previously set FCN function.
void UseSumOfWeightSquare(bool on=true)
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
void SetFunction(const IModelFunction &func, bool useGradient=false)
Set the fitted function (model function) from a parametric function interface.
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
pointer to the object containing the result of the fit
Type
enumeration specifying the integration types.
Interface (abstract class) for parametric one-dimensional gradient functions providing in addition to...
class containg the result of the fit and all the related information (fitted parameter values...
Specialized IParamFunction interface (abstract class) for one-dimensional parametric functions It is ...
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
const std::string & MinimizerType() const
return type of minimizer package
double func(double *x, double *p)
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
pointer to the fit data (binned or unbinned data)
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
bool DoLeastSquareFit()
least square fit
virtual unsigned int NCalls() const
return the total number of function calls (overrided if needed)
bool MinosErrors() const
do minos errros analysis on the parameters
bool SetFCN(unsigned int npar, Function &fcn, const double *params=0, unsigned int dataSize=0, bool chi2fit=false)
Set a generic FCN function as a C++ callable object implementing double () (const double *) Note that...
MultiDimParamGradFunctionAdapter class to wrap a one-dimensional parametric gradient function in a mu...
void SetParamsSettings(unsigned int npar, const double *params, const double *vstep=0)
set the parameter settings from number of parameters and a vector of values and optionally step value...
double ErrorDef() const
error definition
bool DoMinimization(const BaseFunc &f, const ROOT::Math::IMultiGenFunction *chifunc=0)
do minimization
virtual unsigned int NDim() const =0
Retrieve the dimension of the function.
bool DoUnbinnedLikelihoodFit(bool extended=false)
un-binned likelihood fit