13 #ifndef ROOT_Fit_Fitter 14 #define ROOT_Fit_Fitter 107 Fitter (
const std::shared_ptr<FitResult> & result);
137 template <
class Data,
class Function,
138 class cond =
typename std::enable_if<!(std::is_same<Function, ROOT::Fit::ExecutionPolicy>::value ||
139 std::is_same<Function, int>::value),
141 bool Fit(
const Data &
data,
const Function &func,
145 return Fit(data, executionPolicy);
153 return DoLeastSquareFit(executionPolicy);
157 return DoLeastSquareFit(executionPolicy);
172 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
181 return DoBinnedLikelihoodFit(extended, executionPolicy);
184 bool LikelihoodFit(
const std::shared_ptr<BinData> &data,
bool extended =
true,
187 return DoBinnedLikelihoodFit(extended, executionPolicy);
194 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
198 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
206 template <
class Data ,
class Function>
207 bool LikelihoodFit(
const Data & data,
const Function & func,
bool extended) {
209 return LikelihoodFit(data, extended);
217 return DoLinearFit();
221 return DoLinearFit();
231 template <
class Function>
232 bool FitFCN(
unsigned int npar, Function & fcn,
const double * params = 0,
unsigned int dataSize = 0,
bool chi2fit =
false);
240 template <
class Function>
241 bool SetFCN(
unsigned int npar, Function & fcn,
const double * params = 0,
unsigned int dataSize = 0,
bool chi2fit =
false);
310 typedef void (* MinuitFCN_t )(
int &npar,
double *gin,
double &f,
double *u,
int flag);
311 bool FitFCN( MinuitFCN_t fcn,
int npar = 0,
const double * params = 0,
unsigned int dataSize = 0,
bool chi2fit =
false);
318 bool SetFCN( MinuitFCN_t fcn,
int npar = 0,
const double * params = 0,
unsigned int dataSize = 0,
bool chi2fit =
false);
335 void SetFunction(
const IModelFunction & func,
bool useGradient =
false);
340 #ifdef R__HAS_VECCORE 341 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
342 void SetFunction(
const IModelFunction_v &func,
bool useGradient =
false);
344 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
345 void SetFunction(
const IGradModelFunction_v &func,
bool useGradient =
true);
350 void SetFunction(
const IModel1DFunction & func,
bool useGradient =
false);
355 void SetFunction(
const IGradModelFunction & func,
bool useGradient =
true);
359 void SetFunction(
const IGradModel1DFunction & func,
bool useGradient =
true);
366 assert( fResult.get() );
378 bool CalculateHessErrors();
388 bool CalculateMinosErrors();
453 bool DoInitMinimizer();
459 void DoUpdateFitConfig();
461 int GetNCallsFromFCN();
476 template <
class Data>
477 void SetData(
const std::shared_ptr<Data> & data) {
478 fData = std::static_pointer_cast<Data>(
data);
488 template <
class ObjFuncType>
489 bool GetDataFromFCN();
508 std::shared_ptr<IModelFunction>
fFunc;
510 std::shared_ptr<ROOT::Fit::FitResult>
fResult;
514 std::shared_ptr<ROOT::Fit::FitData>
fData;
523 template <
class ObjFuncType>
524 bool Fitter::GetDataFromFCN() {
525 ObjFuncType * objfunc =
dynamic_cast<ObjFuncType*
>(fObjFunction.get() );
527 fFunc = objfunc->ModelFunctionPtr();
528 fData = objfunc->DataPtr();
536 #ifdef R__HAS_VECCORE 537 template <
class NotCompileIfScalarBackend>
538 void Fitter::SetFunction(
const IModelFunction_v &func,
bool useGradient)
540 fUseGradient = useGradient;
542 const IGradModelFunction_v *gradFunc =
dynamic_cast<const IGradModelFunction_v *
>(&func);
544 SetFunction(*gradFunc,
true);
548 "Requested function does not provide gradient - use it as non-gradient function ");
554 fUseGradient =
false;
555 fFunc_v = std::shared_ptr<IModelFunction_v>(
dynamic_cast<IModelFunction_v *
>(func.
Clone()));
559 fConfig.CreateParamsSettings(*fFunc_v);
563 template <
class NotCompileIfScalarBackend>
564 void Fitter::SetFunction(
const IGradModelFunction_v &func,
bool useGradient)
566 fUseGradient = useGradient;
569 fFunc_v = std::shared_ptr<IModelFunction_v>(
dynamic_cast<IGradModelFunction_v *
>(func.
Clone()));
573 fConfig.CreateParamsSettings(*fFunc_v);
589 template<
class Function>
592 return FitFCN(wf,par,datasize,chi2fit);
594 template<
class Function>
597 return SetFCN(wf,par,datasize,chi2fit);
603 #endif // endif __CINT__ ROOT::Math::IParamFunction IModel1DFunction
bool Fit(const UnBinData &data, bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
fit an unbinned data set using loglikelihood method
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Namespace for new ROOT classes and functions.
FitConfig & Config()
access to the configuration (non const method)
bool Fit(const BinData &data, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Fit a binned data set using a least square fit (default method)
Base class for all the fit data types: Stores the coordinates and the DataOptions.
void SetData(const FitData &data)
bool LikelihoodFit(const UnBinData &data, bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Unbinned Likelihood fit.
ROOT::Math::IMultiGenFunction BaseFunc
std::shared_ptr< IModelFunction > fFunc
copy of the fitted function containing on output the fit result
virtual IBaseFunctionMultiDimTempl< T > * Clone() const =0
Clone a function.
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
bool LikelihoodFit(const BinData &data, bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Binned Likelihood fit.
void SetFunctionAndData(const IModelFunctionTempl< T > &func, const FitData &data)
#define MATH_WARN_MSG(loc, str)
std::shared_ptr< ROOT::Fit::FitResult > fResult
copy of the fitted function containing on output the fit result
bool LeastSquareFit(const BinData &data)
Fit a binned data set using a least square fit.
const FitResult & Result() const
get fit result
ROOT::Math::IParamMultiGradFunction IGradModelFunction
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in's exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
ROOT::Math::IParamGradFunction IGradModel1DFunction
bool LinearFit(const BinData &data)
do a linear fit on a set of bin-data
bool Fit(const std::shared_ptr< BinData > &data, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
std::shared_ptr< IModelFunction_v > fFunc_v
const FitConfig & Config() const
access to the fit configuration (const method)
Documentation for the abstract class IBaseFunctionMultiDim.
std::shared_ptr< ROOT::Fit::FitData > fData
pointer to used minimizer
Double_t(* Function)(Double_t)
bool IsBinFit() const
query if fit is binned.
RooCmdArg Minimizer(const char *type, const char *alg=0)
Fitter class, entry point for performing all type of fits.
ROOT::Math::IParamMultiGradFunction IGradModelFunction_v
ROOT::Math::IMultiGenFunction * GetFCN() const
return pointer to last used objective function (is NULL in case fit is not yet done) This pointer wil...
bool LikelihoodFit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
bool FitFCN()
Perform a fit with the previously set FCN function.
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
pointer to the object containing the result of the fit
Interface (abstract class) for parametric one-dimensional gradient functions providing in addition to...
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
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)
ROOT::Math::IMultiGradFunction BaseGradFunc
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
pointer to the fit data (binned or unbinned data)
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
Namespace for new Math classes and functions.
Binding & operator=(OUT(*fun)(void))
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
typedef void((*Func_t)())
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...
bool LikelihoodFit(const std::shared_ptr< BinData > &data, bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
ROOT::Math::IParamMultiFunction IModelFunction_v
ROOT::Math::Minimizer * GetMinimizer() const
return pointer to last used minimizer (is NULL in case fit is not yet done) This pointer is guranteed...
bool LikelihoodFit(const Data &data, const Function &func, bool extended)
fit a data set using any generic model function Pre-requisite on the function:
bool Fit(const Data &data, const Function &func, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
fit a data set using any generic model function If data set is binned a least square fit is performed...
bool LinearFit(const std::shared_ptr< BinData > &data)
void SetData(const std::shared_ptr< Data > &data)
ROOT::Math::IParamMultiFunction IModelFunction
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction