Logo ROOT   6.18/05
Reference Guide
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// Header file for class Fitter
12
13#ifndef ROOT_Fit_Fitter
14#define ROOT_Fit_Fitter
15
16/**
17@defgroup Fit Fitting and Parameter Estimation
18
19Classes used for fitting (regression analysis) and estimation of parameter values given a data sample.
20
21@ingroup MathCore
22
23*/
24
25#include "Fit/BinData.h"
26#include "Fit/UnBinData.h"
27#include "Fit/FitConfig.h"
29#include "Fit/FitResult.h"
30#include "Math/IParamFunction.h"
31#include <memory>
32
33namespace ROOT {
34
35
36 namespace Math {
37 class Minimizer;
38
39 // should maybe put this in a FitMethodFunctionfwd file
40 template<class FunctionType> class BasicFitMethodFunction;
41
42 // define the normal and gradient function
45
46 }
47
48 /**
49 Namespace for the fitting classes
50 @ingroup Fit
51 */
52
53 namespace Fit {
54
55/**
56 @defgroup FitMain User Fitting classes
57
58 Main Classes used for fitting a given data set
59 @ingroup Fit
60*/
61
62
63//___________________________________________________________________________________
64/**
65 Fitter class, entry point for performing all type of fits.
66 Fits are performed using the generic ROOT::Fit::Fitter::Fit method.
67 The inputs are the data points and a model function (using a ROOT::Math::IParamFunction)
68 The result of the fit is returned and kept internally in the ROOT::Fit::FitResult class.
69 The configuration of the fit (parameters, options, etc...) are specified in the
70 ROOT::Math::FitConfig class.
71 After fitting the config of the fit will be modified to have the new values the resulting
72 parameter of the fit with step sizes equal to the errors. FitConfig can be preserved with
73 initial parameters by calling FitConfig.SetUpdateAfterFit(false);
74
75 @ingroup FitMain
76*/
77class Fitter {
78
79public:
80
82 template <class T>
84#ifdef R__HAS_VECCORE
87#else
90#endif
94
97
98
99 /**
100 Default constructor
101 */
102 Fitter ();
103
104 /**
105 Constructor from a result
106 */
107 Fitter (const std::shared_ptr<FitResult> & result);
108
109
110 /**
111 Destructor
112 */
113 ~Fitter ();
114
115private:
116
117 /**
118 Copy constructor (disabled, class is not copyable)
119 */
120 Fitter(const Fitter &);
121
122 /**
123 Assignment operator (disabled, class is not copyable)
124 */
125 Fitter & operator = (const Fitter & rhs);
126
127
128public:
129
130 /**
131 fit a data set using any generic model function
132 If data set is binned a least square fit is performed
133 If data set is unbinned a maximum likelihood fit (not extended) is done
134 Pre-requisite on the function:
135 it must implement the 1D or multidimensional parametric function interface
136 */
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,
143 {
144 SetFunction(func);
145 return Fit(data, executionPolicy);
146 }
147
148 /**
149 Fit a binned data set using a least square fit (default method)
150 */
151 bool Fit(const BinData & data, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
152 SetData(data);
153 return DoLeastSquareFit(executionPolicy);
154 }
155 bool Fit(const std::shared_ptr<BinData> & data, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
156 SetData(data);
157 return DoLeastSquareFit(executionPolicy);
158 }
159
160 /**
161 Fit a binned data set using a least square fit
162 */
163 bool LeastSquareFit(const BinData & data) {
164 return Fit(data);
165 }
166
167 /**
168 fit an unbinned data set using loglikelihood method
169 */
170 bool Fit(const UnBinData & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
171 SetData(data);
172 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
173 }
174
175 /**
176 Binned Likelihood fit. Default is extended
177 */
178 bool LikelihoodFit(const BinData &data, bool extended = true,
180 SetData(data);
181 return DoBinnedLikelihoodFit(extended, executionPolicy);
182 }
183
184 bool LikelihoodFit(const std::shared_ptr<BinData> &data, bool extended = true,
186 SetData(data);
187 return DoBinnedLikelihoodFit(extended, executionPolicy);
188 }
189 /**
190 Unbinned Likelihood fit. Default is not extended
191 */
192 bool LikelihoodFit(const UnBinData & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
193 SetData(data);
194 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
195 }
196 bool LikelihoodFit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial) {
197 SetData(data);
198 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
199 }
200
201
202 /**
203 fit a data set using any generic model function
204 Pre-requisite on the function:
205 */
206 template < class Data , class Function>
207 bool LikelihoodFit( const Data & data, const Function & func, bool extended) {
208 SetFunction(func);
209 return LikelihoodFit(data, extended);
210 }
211
212 /**
213 do a linear fit on a set of bin-data
214 */
215 bool LinearFit(const BinData & data) {
216 SetData(data);
217 return DoLinearFit();
218 }
219 bool LinearFit(const std::shared_ptr<BinData> & data) {
220 SetData(data);
221 return DoLinearFit();
222 }
223
224
225 /**
226 Fit using the a generic FCN function as a C++ callable object implementing
227 double () (const double *)
228 Note that the function dimension (i.e. the number of parameter) is needed in this case
229 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
230 */
231 template <class Function>
232 bool FitFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
233
234 /**
235 Set a generic FCN function as a C++ callable object implementing
236 double () (const double *)
237 Note that the function dimension (i.e. the number of parameter) is needed in this case
238 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
239 */
240 template <class Function>
241 bool SetFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
242
243 /**
244 Fit using the given FCN function represented by a multi-dimensional function interface
245 (ROOT::Math::IMultiGenFunction).
246 Give optionally the initial arameter values, data size to have the fit Ndf correctly
247 set in the FitResult and flag specifying if it is a chi2 fit.
248 Note that if the parameters values are not given (params=0) the
249 current parameter settings are used. The parameter settings can be created before
250 by using the FitConfig::SetParamsSetting. If they have not been created they are created
251 automatically when the params pointer is not zero.
252 Note that passing a params != 0 will set the parameter settings to the new value AND also the
253 step sizes to some pre-defined value (stepsize = 0.3 * abs(parameter_value) )
254 */
255 bool FitFCN(const ROOT::Math::IMultiGenFunction & fcn, const double * params = 0, unsigned int dataSize = 0, bool
256 chi2fit = false);
257
258 /**
259 Fit using a FitMethodFunction interface. Same as method above, but now extra information
260 can be taken from the function class
261 */
262 bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
263
264 /**
265 Set the FCN function represented by a multi-dimensional function interface
266 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
267 See also note above for the initial parameters for FitFCN
268 */
269 bool SetFCN(const ROOT::Math::IMultiGenFunction & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
270
271 /**
272 Set the objective function (FCN) using a FitMethodFunction interface.
273 Same as method above, but now extra information can be taken from the function class
274 */
275 bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
276
277 /**
278 Fit using the given FCN function representing a multi-dimensional gradient function
279 interface (ROOT::Math::IMultiGradFunction). In this case the minimizer will use the
280 gradient information provided by the function.
281 For the options same consideration as in the previous method
282 */
283 bool FitFCN(const ROOT::Math::IMultiGradFunction & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
284
285 /**
286 Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
287 can be taken from the function class
288 */
289 bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
290
291 /**
292 Set the FCN function represented by a multi-dimensional gradient function interface
293 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
294 See also note above for the initial parameters for FitFCN
295 */
296 bool SetFCN(const ROOT::Math::IMultiGradFunction & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
297
298 /**
299 Set the objective function (FCN) using a FitMethodGradFunction interface.
300 Same as method above, but now extra information can be taken from the function class
301 */
302 bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
303
304
305 /**
306 fit using user provided FCN with Minuit-like interface
307 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
308 For the options same consideration as in the previous method
309 */
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);
312
313 /**
314 set objective function using user provided FCN with Minuit-like interface
315 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
316 For the options same consideration as in the previous method
317 */
318 bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
319
320 /**
321 Perform a fit with the previously set FCN function. Require SetFCN before
322 */
323 bool FitFCN();
324
325 /**
326 Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
327 */
328 bool EvalFCN();
329
330
331
332 /**
333 Set the fitted function (model function) from a parametric function interface
334 */
335 void SetFunction(const IModelFunction & func, bool useGradient = false);
336
337 /**
338 Set the fitted function (model function) from a vectorized parametric function interface
339 */
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);
343
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);
346#endif
347 /**
348 Set the fitted function from a parametric 1D function interface
349 */
350 void SetFunction(const IModel1DFunction & func, bool useGradient = false);
351
352 /**
353 Set the fitted function (model function) from a parametric gradient function interface
354 */
355 void SetFunction(const IGradModelFunction & func, bool useGradient = true);
356 /**
357 Set the fitted function from 1D gradient parametric function interface
358 */
359 void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
360
361
362 /**
363 get fit result
364 */
365 const FitResult & Result() const {
366 assert( fResult.get() );
367 return *fResult;
368 }
369
370
371 /**
372 perform an error analysis on the result using the Hessian
373 Errors are obtaied from the inverse of the Hessian matrix
374 To be called only after fitting and when a minimizer supporting the Hessian calculations is used
375 otherwise an error (false) is returned.
376 A new FitResult with the Hessian result will be produced
377 */
378 bool CalculateHessErrors();
379
380 /**
381 perform an error analysis on the result using MINOS
382 To be called only after fitting and when a minimizer supporting MINOS is used
383 otherwise an error (false) is returned.
384 The result will be appended in the fit result class
385 Optionally a vector of parameter indeces can be passed for selecting
386 the parameters to analyse using FitConfig::SetMinosErrors
387 */
389
390 /**
391 access to the fit configuration (const method)
392 */
393 const FitConfig & Config() const { return fConfig; }
394
395 /**
396 access to the configuration (non const method)
397 */
398 FitConfig & Config() { return fConfig; }
399
400 /**
401 query if fit is binned. In cse of false teh fit can be unbinned
402 or is not defined (like in case of fitting through a ::FitFCN)
403 */
404 bool IsBinFit() const { return fBinFit; }
405
406 /**
407 return pointer to last used minimizer
408 (is NULL in case fit is not yet done)
409 This pointer is guranteed to be valid as far as the fitter class is valid and a new fit is not redone.
410 To be used only after fitting.
411 The pointer should not be stored and will be invalided after performing a new fitting.
412 In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
413 obtained calling again GetMinimizer()
414 */
416
417 /**
418 return pointer to last used objective function
419 (is NULL in case fit is not yet done)
420 This pointer will be valid as far as the fitter class
421 has not been deleted. To be used after the fitting.
422 The pointer should not be stored and will be invalided after performing a new fitting.
423 In this case a new instance of the function pointer will be re-created and can be
424 obtained calling again GetFCN()
425 */
427
428
429 /**
430 apply correction in the error matrix for the weights for likelihood fits
431 This method can be called only after a fit. The
432 passed function (loglw2) is a log-likelihood function impelemented using the
433 sum of weight squared
434 When using FitConfig.SetWeightCorrection() this correction is applied
435 automatically when doing a likelihood fit (binned or unbinned)
436 */
437 bool ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction & loglw2, bool minimizeW2L=false);
438
439
440protected:
441
442
443 /// least square fit
445 /// binned likelihood fit
446 bool DoBinnedLikelihoodFit(bool extended = true, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
447 /// un-binned likelihood fit
448 bool DoUnbinnedLikelihoodFit( bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
449 /// linear least square fit
450 bool DoLinearFit();
451
452 // initialize the minimizer
453 bool DoInitMinimizer();
454 /// do minimization
455 bool DoMinimization(const BaseFunc & f, const ROOT::Math::IMultiGenFunction * chifunc = 0);
456 // do minimization after having set obj function
457 bool DoMinimization(const ROOT::Math::IMultiGenFunction * chifunc = 0);
458 // update config after fit
459 void DoUpdateFitConfig();
460 // get function calls from the FCN
461 int GetNCallsFromFCN();
462
463
464 //set data for the fit
465 void SetData(const FitData & data) {
466 fData = std::shared_ptr<FitData>(const_cast<FitData*>(&data),DummyDeleter<FitData>());
467 }
468 // set data and function without cloning them
469 template <class T>
470 void SetFunctionAndData(const IModelFunctionTempl<T> & func, const FitData & data) {
471 SetData(data);
472 fFunc = std::shared_ptr<IModelFunctionTempl<T>>(const_cast<IModelFunctionTempl<T>*>(&func),DummyDeleter<IModelFunctionTempl<T>>());
473 }
474
475 //set data for the fit using a shared ptr
476 template <class Data>
477 void SetData(const std::shared_ptr<Data> & data) {
478 fData = std::static_pointer_cast<Data>(data);
479 }
480
481 /// look at the user provided FCN and get data and model function is
482 /// they derive from ROOT::Fit FCN classes
483 void ExamineFCN();
484
485
486 /// internal functions to get data set and model function from FCN
487 /// useful for fits done with customized FCN classes
488 template <class ObjFuncType>
489 bool GetDataFromFCN();
490
491
492private:
493
494 bool fUseGradient; // flag to indicate if using gradient or not
495
496 bool fBinFit; // flag to indicate if fit is binned
497 // in case of false the fit is unbinned or undefined)
498 // flag it is used to compute chi2 for binned likelihood fit
499
500 int fFitType; // type of fit (0 undefined, 1 least square, 2 likelihood)
501
502 int fDataSize; // size of data sets (need for Fumili or LM fitters)
503
504 FitConfig fConfig; // fitter configuration (options and parameter settings)
505
506 std::shared_ptr<IModelFunction_v> fFunc_v; //! copy of the fitted function containing on output the fit result
507
508 std::shared_ptr<IModelFunction> fFunc; //! copy of the fitted function containing on output the fit result
509
510 std::shared_ptr<ROOT::Fit::FitResult> fResult; //! pointer to the object containing the result of the fit
511
512 std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; //! pointer to used minimizer
513
514 std::shared_ptr<ROOT::Fit::FitData> fData; //! pointer to the fit data (binned or unbinned data)
515
516 std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; //! pointer to used objective function
517
518};
519
520
521// internal functions to get data set and model function from FCN
522// useful for fits done with customized FCN classes
523template <class ObjFuncType>
525 ObjFuncType * objfunc = dynamic_cast<ObjFuncType*>(fObjFunction.get() );
526 if (objfunc) {
527 fFunc = objfunc->ModelFunctionPtr();
528 fData = objfunc->DataPtr();
529 return true;
530 }
531 else {
532 return false;
533 }
534}
535
536#ifdef R__HAS_VECCORE
537template <class NotCompileIfScalarBackend>
538void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
539{
540 fUseGradient = useGradient;
541 if (fUseGradient) {
542 const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
543 if (gradFunc) {
544 SetFunction(*gradFunc, true);
545 return;
546 } else {
547 MATH_WARN_MSG("Fitter::SetFunction",
548 "Requested function does not provide gradient - use it as non-gradient function ");
549 }
550 }
551
552 // set the fit model function (clone the given one and keep a copy )
553 // std::cout << "set a non-grad function" << std::endl;
554 fUseGradient = false;
555 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
556 assert(fFunc_v);
557
558 // creates the parameter settings
560 fFunc.reset();
561}
562
563template <class NotCompileIfScalarBackend>
564void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
565{
566 fUseGradient = useGradient;
567
568 // set the fit model function (clone the given one and keep a copy )
569 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
570 assert(fFunc_v);
571
572 // creates the parameter settings
574 fFunc.reset();
575}
576#endif
577
578 } // end namespace Fit
579
580} // end namespace ROOT
581
582// implementation of inline methods
583
584
585#ifndef __CINT__
586
587#include "Math/WrappedFunction.h"
588
589template<class Function>
590bool ROOT::Fit::Fitter::FitFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
592 return FitFCN(wf,par,datasize,chi2fit);
593}
594template<class Function>
595bool ROOT::Fit::Fitter::SetFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
597 return SetFCN(wf,par,datasize,chi2fit);
598}
599
600
601
602
603#endif // endif __CINT__
604
605#endif /* ROOT_Fit_Fitter */
#define MATH_WARN_MSG(loc, str)
Definition: Error.h:79
#define f(i)
Definition: RSha256.hxx:104
int type
Definition: TGX11.cxx:120
typedef void((*Func_t)())
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:53
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition: FitConfig.h:46
void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl< T > &func)
set the parameter settings from a model function.
Definition: FitConfig.h:108
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
class containg the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:48
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
bool LinearFit(const BinData &data)
do a linear fit on a set of bin-data
Definition: Fitter.h:215
void SetData(const FitData &data)
Definition: Fitter.h:465
bool EvalFCN()
Perform a simple FCN evaluation.
Definition: Fitter.cxx:311
bool FitFCN()
Perform a fit with the previously set FCN function.
Definition: Fitter.cxx:296
void DoUpdateFitConfig()
Definition: Fitter.cxx:851
ROOT::Math::IParamMultiFunction IModelFunction_v
Definition: Fitter.h:88
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
pointer to the object containing the result of the fit
Definition: Fitter.h:512
bool LikelihoodFit(const Data &data, const Function &func, bool extended)
fit a data set using any generic model function Pre-requisite on the function:
Definition: Fitter.h:207
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:426
bool DoBinnedLikelihoodFit(bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
binned likelihood fit
Definition: Fitter.cxx:389
ROOT::Math::IParamGradFunction IGradModel1DFunction
Definition: Fitter.h:93
std::shared_ptr< ROOT::Fit::FitData > fData
pointer to used minimizer
Definition: Fitter.h:514
ROOT::Math::Minimizer * GetMinimizer() const
return pointer to last used minimizer (is NULL in case fit is not yet done) This pointer is guranteed...
Definition: Fitter.h:415
ROOT::Math::IMultiGenFunction BaseFunc
Definition: Fitter.h:95
FitConfig & Config()
access to the configuration (non const method)
Definition: Fitter.h:398
bool LeastSquareFit(const BinData &data)
Fit a binned data set using a least square fit.
Definition: Fitter.h:163
bool fUseGradient
Definition: Fitter.h:494
bool LikelihoodFit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Definition: Fitter.h:196
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...
Definition: Fitter.h:595
void SetFunctionAndData(const IModelFunctionTempl< T > &func, const FitData &data)
Definition: Fitter.h:470
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:310
bool IsBinFit() const
query if fit is binned.
Definition: Fitter.h:404
bool LikelihoodFit(const BinData &data, bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Binned Likelihood fit.
Definition: Fitter.h:178
bool DoMinimization(const BaseFunc &f, const ROOT::Math::IMultiGenFunction *chifunc=0)
do minimization
Definition: Fitter.cxx:840
bool LinearFit(const std::shared_ptr< BinData > &data)
Definition: Fitter.h:219
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
pointer to the fit data (binned or unbinned data)
Definition: Fitter.h:516
const FitResult & Result() const
get fit result
Definition: Fitter.h:365
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:877
bool Fit(const std::shared_ptr< BinData > &data, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Definition: Fitter.h:155
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
Definition: Fitter.h:170
ROOT::Math::IMultiGradFunction BaseGradFunc
Definition: Fitter.h:96
void ExamineFCN()
look at the user provided FCN and get data and model function is they derive from ROOT::Fit FCN class...
Definition: Fitter.cxx:984
const FitConfig & Config() const
access to the fit configuration (const method)
Definition: Fitter.h:393
void SetData(const std::shared_ptr< Data > &data)
Definition: Fitter.h:477
bool LikelihoodFit(const UnBinData &data, bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Unbinned Likelihood fit.
Definition: Fitter.h:192
ROOT::Math::IParamMultiFunction IModelFunction
Definition: Fitter.h:81
ROOT::Math::IParamFunction IModel1DFunction
Definition: Fitter.h:92
std::shared_ptr< IModelFunction_v > fFunc_v
Definition: Fitter.h:506
ROOT::Math::IParamMultiGradFunction IGradModelFunction_v
Definition: Fitter.h:89
bool DoUnbinnedLikelihoodFit(bool extended=false, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
un-binned likelihood fit
Definition: Fitter.cxx:498
Fitter & operator=(const Fitter &rhs)
Assignment operator (disabled, class is not copyable)
Definition: Fitter.cxx:84
std::shared_ptr< ROOT::Fit::FitResult > fResult
copy of the fitted function containing on output the fit result
Definition: Fitter.h:510
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
Definition: Fitter.h:524
ROOT::Math::IParamMultiGradFunction IGradModelFunction
Definition: Fitter.h:91
bool CalculateMinosErrors()
perform an error analysis on the result using MINOS To be called only after fitting and when a minimi...
Definition: Fitter.cxx:696
~Fitter()
Destructor.
Definition: Fitter.cxx:70
bool SetFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=0)
Set the objective function (FCN) using a FitMethodGradFunction interface.
bool LikelihoodFit(const std::shared_ptr< BinData > &data, bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
Definition: Fitter.h:184
void SetFunction(const IModelFunction &func, bool useGradient=false)
Set the fitted function (model function) from a parametric function interface.
Definition: Fitter.cxx:103
bool CalculateHessErrors()
perform an error analysis on the result using the Hessian Errors are obtaied from the inverse of the ...
Definition: Fitter.cxx:620
FitConfig fConfig
Definition: Fitter.h:504
Fitter()
Default constructor.
Definition: Fitter.cxx:51
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)
Definition: Fitter.h:151
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...
Definition: Fitter.h:141
std::shared_ptr< IModelFunction > fFunc
copy of the fitted function containing on output the fit result
Definition: Fitter.h:508
bool FitFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=0)
Fit using a FitMethodGradFunction interface.
bool DoLinearFit()
linear least square fit
Definition: Fitter.cxx:603
bool DoInitMinimizer()
Definition: Fitter.cxx:761
int GetNCallsFromFCN()
Definition: Fitter.cxx:861
bool DoLeastSquareFit(const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
least square fit
Definition: Fitter.cxx:330
Class describing the unbinned data sets (just x coordinates values) of any dimensions.
Definition: UnBinData.h:42
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition: IFunction.h:327
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:78
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:134
Namespace for new Math classes and functions.
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition: Fitter.h:40
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
Definition: Fitter.h:44
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
RooCmdArg Minimizer(const char *type, const char *alg=0)