Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Fitter.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Wed Aug 30 11:05:19 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11#ifndef ROOT_Fit_Fitter
12#define ROOT_Fit_Fitter
13
14/**
15@defgroup Fit Fitting and Parameter Estimation
16
17Classes used for fitting (regression analysis) and estimation of parameter values given a data sample.
18
19@ingroup MathCore
20
21@see ROOT::Math::MinimizerOptions::SetDefaultMinimizer
22
23*/
24
25#include "Fit/BinData.h"
26#include "Fit/FitConfig.h"
27#include "Fit/FitResult.h"
28#include "Fit/UnBinData.h"
29#include "Math/IParamFunction.h"
32
33#include <memory>
34
35namespace ROOT::Math {
36
37class Minimizer;
38
39// should maybe put this in a FitMethodFunctionfwd file
40template <class FunctionType>
41class BasicFitMethodFunction;
42
43// define the normal and gradient function
46
47} // namespace ROOT::Math
48
49 /**
50 Namespace for the fitting classes
51 @ingroup Fit
52 */
53
54namespace ROOT::Fit {
55
56/**
57 @defgroup FitMain User Fitting classes
58
59 Main Classes used for fitting a given data set
60 @ingroup Fit
61*/
62
63
64//___________________________________________________________________________________
65/**
66 Fitter class, entry point for performing all type of fits.
67 Fits are performed using the generic ROOT::Fit::Fitter::Fit method.
68 The inputs are the data points and a model function (using a ROOT::Math::IParamFunction)
69 The result of the fit is returned and kept internally in the ROOT::Fit::FitResult class.
70 The configuration of the fit (parameters, options, etc...) are specified in the
71 ROOT::Math::FitConfig class.
72 After fitting the config of the fit will be modified to have the new values the resulting
73 parameter of the fit with step sizes equal to the errors. FitConfig can be preserved with
74 initial parameters by calling FitConfig.SetUpdateAfterFit(false);
75
76 @ingroup FitMain
77*/
78class Fitter {
79
80public:
81
83 template <class T>
85#ifdef R__HAS_VECCORE
88#else
91#endif
95
98
99
100 /**
101 Default constructor
102 */
103 Fitter () {}
104
105 /**
106 Constructor from a result
107 */
108 Fitter (const std::shared_ptr<FitResult> & result);
109
110
111 /**
112 Destructor.
113 Make it virtual in case users derive from Fitter class to extend it by adding new methods.
114 This is needed to avoid a warning seen when doing from Python
115 (see ROOT issue [#12391](https://github.com/root-project/root/issues/12391) ).
116 Note that the Fitter class does not provide virtual functions to be re-implemented by derived classes.
117 */
118 virtual ~Fitter () {}
119
120 /**
121 Copy constructor (disabled, class is not copyable)
122 */
123 Fitter(const Fitter &) = delete;
124
125 /**
126 Assignment operator (disabled, class is not copyable)
127 */
128 Fitter & operator = (const Fitter &) = delete;
129
130
131public:
132
133 /**
134 fit a data set using any generic model function
135 If data set is binned a least square fit is performed
136 If data set is unbinned a maximum likelihood fit (not extended) is done
137 Pre-requisite on the function:
138 it must implement the 1D or multidimensional parametric function interface.
139 Note that both the input data and the function object are copied by the Fitter.
140 */
141 template <class Data, class Function,
142 class cond = typename std::enable_if<!(std::is_same<Function, ROOT::EExecutionPolicy>::value ||
143 std::is_same<Function, int>::value),
145 bool Fit(const Data &data, const Function &func,
147 {
148 SetFunction(func);
149 return Fit(data, executionPolicy);
150 }
151
152 /**
153 Fit a binned data set using a least square fit.
154 Note that the provided input data are copied in the Fitter class.
155 Use the next function (passing a `shared_ptr` to the BinData class if you want to avoid
156 copying.
157 */
161
162 /**
163 Fit a binned data set using a least square fit.
164 Pass the input data using a `shared_ptr` for NOT copying the input data.
165 */
166 bool Fit(const std::shared_ptr<BinData> & data, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
168 }
169
170 /**
171 Fit a binned data set using a least square fit copying the input data.
172 */
177 /**
178 Fit a binned data set using a least square fit NOT copying the input data.
179 */
184
185 /**
186 Fit an un-binned data set using the negative log-likelihood method.
187 This function copies the input data.
188 */
192 /**
193 Fit an un-binned data set using the negative log-likelihood method.
194 This function uses a `shared_ptr` to avoid copying the input data.
195 */
196 bool Fit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
198 }
199
200 /**
201 Binned Likelihood fit copying the input data.
202 Default is extended.
203 */
209 /**
210 Binned Likelihood fit using a `shared_ptr` for NOT copying the input data.
211 Default is extended.
212 */
213 bool LikelihoodFit(const std::shared_ptr<BinData> &data, bool extended = true,
215 SetData(data);
217 }
218 /**
219 Un-binned Likelihood fit copying the input data
220 Default is NOT extended
221 */
226 /**
227 Un-binned Likelihood fit using a `shared_ptr` for NOT copying the input data.
228 Default is NOT extended
229 */
234
235 /**
236 Likelihood fit given a data set (Binned or Un-binned) using any generic model function.
237 This interface copies the input data and the model function object
238 */
239 template < class Data , class Function>
240 bool LikelihoodFit( const Data & data, const Function & func, bool extended) {
241 SetFunction(func);
242 return LikelihoodFit(data, extended);
243 }
244
245 /**
246 Do a linear fit copying the input data
247 */
248 bool LinearFit(const BinData & data) {
249 SetData(data);
250 return DoLinearFit();
251 }
252 /**
253 Do a linear fit using a `shared_ptr` for NOT copying the input data
254 */
255 bool LinearFit(const std::shared_ptr<BinData> & data) {
256 SetData(data);
257 return DoLinearFit();
258 }
259
260 /**
261 Fit using the a generic FCN function as a C++ callable object implementing
262 double () (const double *)
263 Note that the function dimension (i.e. the number of parameter) is needed in this case
264 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
265 */
266 template <class Function>
267 bool FitFCN(unsigned int npar, Function & fcn, const double * params = nullptr, unsigned int dataSize = 0, int fitType = 0) {
269 }
270
271 /**
272 Set a generic FCN function as a C++ callable object implementing
273 double () (const double *)
274 Note that the function dimension (i.e. the number of parameter) is needed in this case
275 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
276 */
277 template <class Function>
278 bool SetFCN(unsigned int npar, Function & fcn, const double * params = nullptr, unsigned int dataSize = 0, int fitType = 0) {
280 }
281
282 /**
283 Fit using the given FCN function represented by a multi-dimensional function interface
284 (ROOT::Math::IMultiGenFunction).
285 Give optionally the initial parameter values, data size to have the fit Ndf correctly
286 set in the FitResult and flag specifying the type of fit. The fitType can be:
287 0 undefined, 1 least square fit, 2 unbinned likelihood fit, 3 binned likelihood fit
288 Note that if the parameters values are not given (params=0) the
289 current parameter settings are used. The parameter settings can be created before
290 by using the FitConfig::SetParamsSetting. If they have not been created they are created
291 automatically when the params pointer is not zero.
292 Note that passing a params != 0 will set the parameter settings to the new value AND also the
293 step sizes to some pre-defined value (stepsize = 0.3 * abs(parameter_value) )
294 */
295 bool FitFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
296
297 /**
298 Fit using a FitMethodFunction interface. Same as method above, but now extra information
299 can be taken from the function class
300 */
301 bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double *params = nullptr);
302
303 /**
304 Set the FCN function represented by a multi-dimensional function interface
305 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
306 See also note above for the initial parameters for FitFCN
307 */
308 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
309
310 /**
311 Set the FCN function represented by a multi-dimensional function interface
312 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
313 See also note above for the initial parameters for FitFCN
314 With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
315 used to compute confidence interval of the fit
316 */
317 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const IModelFunction & func, const double *params = nullptr,
318 unsigned int dataSize = 0, int fitType = 0);
319
320 /**
321 Set the objective function (FCN) using a FitMethodFunction interface.
322 Same as method above, but now extra information can be taken from the function class
323 */
324 bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double *params = nullptr);
325
326 /**
327 Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
328 can be taken from the function class
329 */
330 bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double *params = nullptr);
331
332 /**
333 Set the objective function (FCN) using a FitMethodGradFunction interface.
334 Same as method above, but now extra information can be taken from the function class
335 */
336 bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double *params = nullptr);
337
338
339 /**
340 fit using user provided FCN with Minuit-like interface
341 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
342 For the options same consideration as in the previous method
343 */
344 typedef void (* MinuitFCN_t )(int &npar, double *gin, double &f, double *u, int flag);
345 bool FitFCN( MinuitFCN_t fcn, int npar = 0, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
346
347 /**
348 set objective function using user provided FCN with Minuit-like interface
349 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
350 For the options same consideration as in the previous method
351 */
352 bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
353
354 /**
355 Perform a fit with the previously set FCN function. Require SetFCN before
356 */
357 bool FitFCN();
358
359 /**
360 Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
361 */
362 bool EvalFCN();
363
364
365
366 /**
367 Set the fitted function (model function) from a parametric function interface.
368 @param useGradient if true, the minimizer uses the gradient information provided by the user, otherwise a numerical gradient is computed and used.
369 */
370 void SetFunction(const IModelFunction & func, bool useGradient = false);
371
372 /**
373 Set the fitted function (model function) from a vectorized parametric function interface
374 */
375#ifdef R__HAS_VECCORE
376 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
377 void SetFunction(const IModelFunction_v &func, bool useGradient = false);
378
379 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
380 void SetFunction(const IGradModelFunction_v &func, bool useGradient = true);
381#endif
382 /**
383 Set the fitted function from a parametric 1D function interface
384 */
385 void SetFunction(const IModel1DFunction & func, bool useGradient = false);
386
387 /**
388 Set the fitted function (model function) from a parametric gradient function interface
389 */
390 void SetFunction(const IGradModelFunction & func, bool useGradient = true);
391 /**
392 Set the fitted function from 1D gradient parametric function interface
393 */
394 void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
395
396
397 /**
398 get fit result
399 */
400 const FitResult & Result() const {
401 assert( fResult.get() );
402 return *fResult;
403 }
404
405
406 /**
407 perform an error analysis on the result using the Hessian
408 Errors are obtained from the inverse of the Hessian matrix
409 To be called only after fitting and when a minimizer supporting the Hessian calculations is used
410 otherwise an error (false) is returned.
411 A new FitResult with the Hessian result will be produced
412 */
413 bool CalculateHessErrors();
414
415 /**
416 perform an error analysis on the result using MINOS
417 To be called only after fitting and when a minimizer supporting MINOS is used
418 otherwise an error (false) is returned.
419 The result will be appended in the fit result class
420 Optionally a vector of parameter indices can be passed for selecting
421 the parameters to analyse using FitConfig::SetMinosErrors
422 */
424
425 /**
426 access to the fit configuration (const method)
427 */
428 const FitConfig & Config() const { return fConfig; }
429
430 /**
431 access to the configuration (non const method)
432 */
433 FitConfig & Config() { return fConfig; }
434
435 /**
436 query if fit is binned. In cse of false the fit can be unbinned
437 or is not defined (like in case of fitting through a ROOT::Fit::Fitter::FitFCN)
438 */
439 bool IsBinFit() const { return fBinFit; }
440
441 /**
442 return pointer to last used minimizer
443 (is NULL in case fit is not yet done)
444 This pointer is guaranteed to be valid as far as the fitter class is valid and a new fit is not redone.
445 To be used only after fitting.
446 The pointer should not be stored and will be invalided after performing a new fitting.
447 In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
448 obtained calling again GetMinimizer()
449 */
451
452 /**
453 return pointer to last used objective function
454 (is NULL in case fit is not yet done)
455 This pointer will be valid as far as the fitter class
456 has not been deleted. To be used after the fitting.
457 The pointer should not be stored and will be invalided after performing a new fitting.
458 In this case a new instance of the function pointer will be re-created and can be
459 obtained calling again GetFCN()
460 */
462 return fObjFunction.get();
463 }
464
465
466 /**
467 apply correction in the error matrix for the weights for likelihood fits
468 This method can be called only after a fit. The
469 passed function (loglw2) is a log-likelihood function implemented using the
470 sum of weight squared
471 When using FitConfig.SetWeightCorrection() this correction is applied
472 automatically when doing a likelihood fit (binned or unbinned)
473 */
475
476 /// Set number of fit points when using an external FCN function
477 /// This function can be called after Fit to set the correct number of Ndf in FitResult
478 void SetNumberOfFitPoints(unsigned int npoints) {
480 if (!fResult->IsEmpty()) fResult->SetChi2AndNdf(-1,npoints);
481 }
482
483 /// Set the type of fit when using an external FCN
484 /// possible types are : 1 (least-square), 2 (unbinned-likelihood), 3 (binned-likelihood)
485 /// Note that in case of binned likelihood fit the chi2 will be computed as 2 * MinFCN()
486 /// Note this function should be called before fitting to have effect on th FitResult
487 void SetFitType(int type) {
489 }
490
491
492protected:
493
494
495 /// least square fit
497 /// binned likelihood fit
499 /// un-binned likelihood fit
501 /// linear least square fit
502 bool DoLinearFit();
503 /// Set Objective function
504 bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize,
505 int fitType);
506
507 // initialize the minimizer
508 bool DoInitMinimizer();
509 /// do minimization
510 template<class ObjFunc_t>
511 bool DoMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
512 // do minimization for weighted likelihood fits
513 template<class ObjFunc_t>
514 bool DoWeightMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
515 // do minimization after having set the objective function
517 // update config after fit
518 void DoUpdateFitConfig();
519 // update minimizer options for re-fitting
521 // get function calls from the FCN
522 int GetNCallsFromFCN();
523
524 /// Set the input data for the fit using a shared ptr (No Copying)
525 template <class Data>
526 void SetData(const std::shared_ptr<Data> & data) {
527 fData = std::static_pointer_cast<Data>(data);
528 }
529
530 /// Set the input data for the fit (Copying the given data object)
531 template <class Data>
532 void SetData(const Data & data) {
533 SetData(std::make_shared<Data>(data));
534 }
535
536 /// internal functions to get data set and model function from FCN
537 /// useful for fits done with customized FCN classes
538 template <class ObjFuncType>
540 if (const ObjFuncType *objfunc = dynamic_cast<const ObjFuncType *>(ObjFunction())) {
541 fFunc = objfunc->ModelFunctionPtr();
542 fData = objfunc->DataPtr();
543 return true;
544 }
545 return false;
546 }
547
548 /// Return pointer to the used objective function for fitting.
549 /// If using an external function (e.g. given in SetFCN), return the cached pointer,
550 /// otherwise use the one stored as shared ptr and managed by the Fitter class
552 // need to specify here full return type since when using the typedef (IMultiGenFunction)
553 // there is an error when using the class in Python (see issue #12391)
555 }
556
557private:
558
559 bool fUseGradient = false; ///< flag to indicate if using gradient or not
560 bool fBinFit = false; ///< flag to indicate if fit is binned
561 ///< in case of false the fit is unbinned or undefined)
562 ///< flag it is used to compute chi2 for binned likelihood fit
563 int fFitType = 0; ///< type of fit (0 undefined, 1 least square, 2 likelihood, 3 binned likelihood)
564 int fDataSize = 0; ///< size of data sets (need for Fumili or LM fitters)
565 FitConfig fConfig; ///< fitter configuration (options and parameter settings)
566 std::shared_ptr<IModelFunction_v> fFunc_v; ///<! copy of the fitted function containing on output the fit result
567 std::shared_ptr<IModelFunction> fFunc; ///<! copy of the fitted function containing on output the fit result
568 std::shared_ptr<ROOT::Fit::FitResult> fResult; ///<! pointer to the object containing the result of the fit
569 std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; ///<! pointer to used minimizer
570 std::shared_ptr<ROOT::Fit::FitData> fData; ///<! pointer to the fit data (binned or unbinned data)
571 std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; ///<! pointer to used objective function
572 const ROOT::Math::IMultiGenFunction *fExtObjFunction = nullptr; ///<! pointer to an external FCN
573};
574
575
576#ifdef R__HAS_VECCORE
577template <class NotCompileIfScalarBackend>
578void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
579{
580 fUseGradient = useGradient;
581 if (fUseGradient) {
582 const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
583 if (gradFunc) {
584 SetFunction(*gradFunc, true);
585 return;
586 } else {
587 MATH_WARN_MSG("Fitter::SetFunction",
588 "Requested function does not provide gradient - use it as non-gradient function ");
589 }
590 }
591
592 // set the fit model function (clone the given one and keep a copy )
593 // std::cout << "set a non-grad function" << std::endl;
594 fUseGradient = false;
595 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
597
598 // creates the parameter settings
600 fFunc.reset();
601}
602
603template <class NotCompileIfScalarBackend>
604void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
605{
606 fUseGradient = useGradient;
607
608 // set the fit model function (clone the given one and keep a copy )
609 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
611
612 // creates the parameter settings
614 fFunc.reset();
615}
616#endif
617
618} // namespace ROOT::Fit
619
620#endif /* ROOT_Fit_Fitter */
#define MATH_WARN_MSG(loc, str)
Definition Error.h:80
#define f(i)
Definition RSha256.hxx:104
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
Double_t(* Function)(Double_t)
Definition Functor.C:4
Class describing the binned data sets : vectors of x coordinates, y values and optionally error on y ...
Definition BinData.h:52
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition FitConfig.h:49
void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl< T > &func)
set the parameter settings from a model function.
Definition FitConfig.h:111
class containing the result of the fit and all the related information (fitted parameter values,...
Definition FitResult.h:44
Fitter class, entry point for performing all type of fits.
Definition Fitter.h:78
bool LikelihoodFit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Un-binned Likelihood fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:230
bool LinearFit(const BinData &data)
Do a linear fit copying the input data.
Definition Fitter.h:248
bool LeastSquareFit(const std::shared_ptr< BinData > &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit NOT copying the input data.
Definition Fitter.h:180
bool EvalFCN()
Perform a simple FCN evaluation.
Definition Fitter.cxx:275
const ROOT::Math::IMultiGenFunction * fExtObjFunction
! pointer to an external FCN
Definition Fitter.h:572
Fitter & operator=(const Fitter &)=delete
Assignment operator (disabled, class is not copyable)
bool FitFCN()
Perform a fit with the previously set FCN function.
Definition Fitter.cxx:259
void DoUpdateFitConfig()
Definition Fitter.cxx:845
bool DoMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
do minimization
Definition Fitter.cxx:822
bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize, int fitType)
Set Objective function.
Definition Fitter.cxx:127
int fDataSize
size of data sets (need for Fumili or LM fitters)
Definition Fitter.h:564
bool DoUnbinnedLikelihoodFit(bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
un-binned likelihood fit
Definition Fitter.cxx:427
void SetData(const Data &data)
Set the input data for the fit (Copying the given data object)
Definition Fitter.h:532
const ROOT::Math::IBaseFunctionMultiDimTempl< double > * ObjFunction() const
Return pointer to the used objective function for fitting.
Definition Fitter.h:551
ROOT::Math::IParamMultiFunction IModelFunction_v
Definition Fitter.h:89
bool Fit(const BinData &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit.
Definition Fitter.h:158
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
! pointer to used minimizer
Definition Fitter.h:569
bool DoWeightMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
Definition Fitter.cxx:830
bool LikelihoodFit(const Data &data, const Function &func, bool extended)
Likelihood fit given a data set (Binned or Un-binned) using any generic model function.
Definition Fitter.h:240
bool DoBinnedLikelihoodFit(bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
binned likelihood fit
Definition Fitter.cxx:347
int fFitType
type of fit (0 undefined, 1 least square, 2 likelihood, 3 binned likelihood)
Definition Fitter.h:563
ROOT::Math::IMultiGenFunction * GetFCN() const
return pointer to last used objective function (is NULL in case fit is not yet done) This pointer wil...
Definition Fitter.h:461
ROOT::Math::IParamGradFunction IGradModel1DFunction
Definition Fitter.h:94
std::shared_ptr< ROOT::Fit::FitData > fData
! pointer to the fit data (binned or unbinned data)
Definition Fitter.h:570
ROOT::Math::Minimizer * GetMinimizer() const
return pointer to last used minimizer (is NULL in case fit is not yet done) This pointer is guarantee...
Definition Fitter.h:450
ROOT::Math::IMultiGenFunction BaseFunc
Definition Fitter.h:96
FitConfig & Config()
access to the configuration (non const method)
Definition Fitter.h:433
bool fUseGradient
flag to indicate if using gradient or not
Definition Fitter.h:559
void SetNumberOfFitPoints(unsigned int npoints)
Set number of fit points when using an external FCN function This function can be called after Fit to...
Definition Fitter.h:478
bool fBinFit
flag to indicate if fit is binned in case of false the fit is unbinned or undefined) flag it is used ...
Definition Fitter.h:560
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 ...
Definition Fitter.h:344
bool IsBinFit() const
query if fit is binned.
Definition Fitter.h:439
bool LinearFit(const std::shared_ptr< BinData > &data)
Do a linear fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:255
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
! pointer to used objective function
Definition Fitter.h:571
void SetFitType(int type)
Set the type of fit when using an external FCN possible types are : 1 (least-square),...
Definition Fitter.h:487
virtual ~Fitter()
Destructor.
Definition Fitter.h:118
bool Fit(const std::shared_ptr< BinData > &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit.
Definition Fitter.h:166
const FitResult & Result() const
get fit result
Definition Fitter.h:400
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...
Definition Fitter.cxx:868
bool FitFCN(unsigned int npar, Function &fcn, const double *params=nullptr, unsigned int dataSize=0, int fitType=0)
Fit using the a generic FCN function as a C++ callable object implementing double () (const double *)...
Definition Fitter.h:267
ROOT::Math::IMultiGradFunction BaseGradFunc
Definition Fitter.h:97
const FitConfig & Config() const
access to the fit configuration (const method)
Definition Fitter.h:428
void SetData(const std::shared_ptr< Data > &data)
Set the input data for the fit using a shared ptr (No Copying)
Definition Fitter.h:526
bool DoLeastSquareFit(const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
least square fit
Definition Fitter.cxx:296
ROOT::Math::IParamMultiFunction IModelFunction
Definition Fitter.h:82
ROOT::Math::IParamFunction IModel1DFunction
Definition Fitter.h:93
bool SetFCN(unsigned int npar, Function &fcn, const double *params=nullptr, unsigned int dataSize=0, int fitType=0)
Set a generic FCN function as a C++ callable object implementing double () (const double *) Note that...
Definition Fitter.h:278
bool LikelihoodFit(const BinData &data, bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Binned Likelihood fit copying the input data.
Definition Fitter.h:204
std::shared_ptr< IModelFunction_v > fFunc_v
! copy of the fitted function containing on output the fit result
Definition Fitter.h:566
ROOT::Math::IParamMultiGradFunction IGradModelFunction_v
Definition Fitter.h:90
bool LikelihoodFit(const std::shared_ptr< BinData > &data, bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Binned Likelihood fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:213
std::shared_ptr< ROOT::Fit::FitResult > fResult
! pointer to the object containing the result of the fit
Definition Fitter.h:568
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
Definition Fitter.h:539
ROOT::Math::IParamMultiGradFunction IGradModelFunction
Definition Fitter.h:92
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
Definition Fitter.cxx:580
Fitter(const Fitter &)=delete
Copy constructor (disabled, class is not copyable)
bool DoUpdateMinimizerOptions(bool canDifferentMinim=true)
Definition Fitter.cxx:749
bool Fit(const Data &data, const Function &func, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
fit a data set using any generic model function If data set is binned a least square fit is performed...
Definition Fitter.h:145
bool Fit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit an un-binned data set using the negative log-likelihood method.
Definition Fitter.h:189
void SetFunction(const IModelFunction &func, bool useGradient=false)
Set the fitted function (model function) from a parametric function interface.
Definition Fitter.cxx:49
bool CalculateHessErrors()
perform an error analysis on the result using the Hessian Errors are obtained from the inverse of the...
Definition Fitter.cxx:517
FitConfig fConfig
fitter configuration (options and parameter settings)
Definition Fitter.h:565
Fitter()
Default constructor.
Definition Fitter.h:103
std::shared_ptr< IModelFunction > fFunc
! copy of the fitted function containing on output the fit result
Definition Fitter.h:567
bool SetFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=nullptr)
Set the objective function (FCN) using a FitMethodGradFunction interface.
bool LeastSquareFit(const BinData &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit copying the input data.
Definition Fitter.h:173
bool FitFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=nullptr)
Fit using a FitMethodGradFunction interface.
bool Fit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit an un-binned data set using the negative log-likelihood method.
Definition Fitter.h:196
bool LikelihoodFit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Un-binned Likelihood fit copying the input data Default is NOT extended.
Definition Fitter.h:222
bool DoLinearFit()
linear least square fit
Definition Fitter.cxx:500
bool DoInitMinimizer()
Definition Fitter.cxx:679
int GetNCallsFromFCN()
Definition Fitter.cxx:855
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
Definition UnBinData.h:46
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:63
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:239
Specialized IParamFunction interface (abstract class) for one-dimensional parametric functions It is ...
Interface (abstract class) for parametric gradient multi-dimensional functions providing in addition ...
Interface (abstract class) for parametric one-dimensional gradient functions providing in addition to...
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition Minimizer.h:124
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
RooCmdArg Minimizer(const char *type, const char *alg=nullptr)
Namespace for the fitting classes.
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition Fitter.h:44
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
Definition Fitter.h:45