Logo ROOT  
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 chi2fit = false);
256
257 /**
258 Fit using a FitMethodFunction interface. Same as method above, but now extra information
259 can be taken from the function class
260 */
261 bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
262
263 /**
264 Set the FCN function represented by a multi-dimensional function interface
265 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
266 See also note above for the initial parameters for FitFCN
267 */
268 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
269
270 /**
271 Set the FCN function represented by a multi-dimensional function interface
272 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
273 See also note above for the initial parameters for FitFCN
274 With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
275 used to compute confidence interval of the fit
276 */
277 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const IModelFunction & func, const double *params = 0,
278 unsigned int dataSize = 0, bool chi2fit = false);
279
280 /**
281 Set the objective function (FCN) using a FitMethodFunction interface.
282 Same as method above, but now extra information can be taken from the function class
283 */
284 bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
285
286 /**
287 Fit using the given FCN function representing a multi-dimensional gradient function
288 interface (ROOT::Math::IMultiGradFunction). In this case the minimizer will use the
289 gradient information provided by the function.
290 For the options same consideration as in the previous method
291 */
292 bool FitFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
293
294 /**
295 Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
296 can be taken from the function class
297 */
298 bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
299
300 /**
301 Set the FCN function represented by a multi-dimensional gradient function interface
302 (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
303 See also note above for the initial parameters for FitFCN
304 */
305 bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
306
307 /**
308 Set the FCN function represented by a multi-dimensional gradient function interface
309 (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
310 See also note above for the initial parameters for FitFCN
311 With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
312 used to compute confidence interval of the fit
313 */
314 bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const IModelFunction &func, const double *params = 0,
315 unsigned int dataSize = 0, bool chi2fit = false);
316
317 /**
318 Set the objective function (FCN) using a FitMethodGradFunction interface.
319 Same as method above, but now extra information can be taken from the function class
320 */
321 bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
322
323
324 /**
325 fit using user provided FCN with Minuit-like interface
326 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
327 For the options same consideration as in the previous method
328 */
329 typedef void (* MinuitFCN_t )(int &npar, double *gin, double &f, double *u, int flag);
330 bool FitFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
331
332 /**
333 set objective function using user provided FCN with Minuit-like interface
334 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
335 For the options same consideration as in the previous method
336 */
337 bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
338
339 /**
340 Perform a fit with the previously set FCN function. Require SetFCN before
341 */
342 bool FitFCN();
343
344 /**
345 Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
346 */
347 bool EvalFCN();
348
349
350
351 /**
352 Set the fitted function (model function) from a parametric function interface
353 */
354 void SetFunction(const IModelFunction & func, bool useGradient = false);
355
356 /**
357 Set the fitted function (model function) from a vectorized parametric function interface
358 */
359#ifdef R__HAS_VECCORE
360 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
361 void SetFunction(const IModelFunction_v &func, bool useGradient = false);
362
363 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
364 void SetFunction(const IGradModelFunction_v &func, bool useGradient = true);
365#endif
366 /**
367 Set the fitted function from a parametric 1D function interface
368 */
369 void SetFunction(const IModel1DFunction & func, bool useGradient = false);
370
371 /**
372 Set the fitted function (model function) from a parametric gradient function interface
373 */
374 void SetFunction(const IGradModelFunction & func, bool useGradient = true);
375 /**
376 Set the fitted function from 1D gradient parametric function interface
377 */
378 void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
379
380
381 /**
382 get fit result
383 */
384 const FitResult & Result() const {
385 assert( fResult.get() );
386 return *fResult;
387 }
388
389
390 /**
391 perform an error analysis on the result using the Hessian
392 Errors are obtaied from the inverse of the Hessian matrix
393 To be called only after fitting and when a minimizer supporting the Hessian calculations is used
394 otherwise an error (false) is returned.
395 A new FitResult with the Hessian result will be produced
396 */
397 bool CalculateHessErrors();
398
399 /**
400 perform an error analysis on the result using MINOS
401 To be called only after fitting and when a minimizer supporting MINOS is used
402 otherwise an error (false) is returned.
403 The result will be appended in the fit result class
404 Optionally a vector of parameter indeces can be passed for selecting
405 the parameters to analyse using FitConfig::SetMinosErrors
406 */
408
409 /**
410 access to the fit configuration (const method)
411 */
412 const FitConfig & Config() const { return fConfig; }
413
414 /**
415 access to the configuration (non const method)
416 */
417 FitConfig & Config() { return fConfig; }
418
419 /**
420 query if fit is binned. In cse of false teh fit can be unbinned
421 or is not defined (like in case of fitting through a ::FitFCN)
422 */
423 bool IsBinFit() const { return fBinFit; }
424
425 /**
426 return pointer to last used minimizer
427 (is NULL in case fit is not yet done)
428 This pointer is guranteed to be valid as far as the fitter class is valid and a new fit is not redone.
429 To be used only after fitting.
430 The pointer should not be stored and will be invalided after performing a new fitting.
431 In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
432 obtained calling again GetMinimizer()
433 */
435
436 /**
437 return pointer to last used objective function
438 (is NULL in case fit is not yet done)
439 This pointer will be valid as far as the fitter class
440 has not been deleted. To be used after the fitting.
441 The pointer should not be stored and will be invalided after performing a new fitting.
442 In this case a new instance of the function pointer will be re-created and can be
443 obtained calling again GetFCN()
444 */
446
447
448 /**
449 apply correction in the error matrix for the weights for likelihood fits
450 This method can be called only after a fit. The
451 passed function (loglw2) is a log-likelihood function impelemented using the
452 sum of weight squared
453 When using FitConfig.SetWeightCorrection() this correction is applied
454 automatically when doing a likelihood fit (binned or unbinned)
455 */
456 bool ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction & loglw2, bool minimizeW2L=false);
457
458
459protected:
460
461
462 /// least square fit
464 /// binned likelihood fit
465 bool DoBinnedLikelihoodFit(bool extended = true, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
466 /// un-binned likelihood fit
467 bool DoUnbinnedLikelihoodFit( bool extended = false, const ROOT::Fit::ExecutionPolicy &executionPolicy = ROOT::Fit::ExecutionPolicy::kSerial);
468 /// linear least square fit
469 bool DoLinearFit();
470
471 // initialize the minimizer
472 bool DoInitMinimizer();
473 /// do minimization
474 bool DoMinimization(const BaseFunc & f, const ROOT::Math::IMultiGenFunction * chifunc = 0);
475 // do minimization after having set obj function
476 bool DoMinimization(const ROOT::Math::IMultiGenFunction * chifunc = 0);
477 // update config after fit
478 void DoUpdateFitConfig();
479 // update minimizer options for re-fitting
480 bool DoUpdateMinimizerOptions(bool canDifferentMinim = true);
481 // get function calls from the FCN
482 int GetNCallsFromFCN();
483
484 //set data for the fit
485 void SetData(const FitData & data) {
486 fData = std::shared_ptr<FitData>(const_cast<FitData*>(&data),DummyDeleter<FitData>());
487 }
488 // set data and function without cloning them
489 template <class T>
490 void SetFunctionAndData(const IModelFunctionTempl<T> & func, const FitData & data) {
491 SetData(data);
492 fFunc = std::shared_ptr<IModelFunctionTempl<T>>(const_cast<IModelFunctionTempl<T>*>(&func),DummyDeleter<IModelFunctionTempl<T>>());
493 }
494
495 //set data for the fit using a shared ptr
496 template <class Data>
497 void SetData(const std::shared_ptr<Data> & data) {
498 fData = std::static_pointer_cast<Data>(data);
499 }
500
501 /// look at the user provided FCN and get data and model function is
502 /// they derive from ROOT::Fit FCN classes
503 void ExamineFCN();
504
505
506 /// internal functions to get data set and model function from FCN
507 /// useful for fits done with customized FCN classes
508 template <class ObjFuncType>
509 bool GetDataFromFCN();
510
511
512private:
513
514 bool fUseGradient; // flag to indicate if using gradient or not
515
516 bool fBinFit; // flag to indicate if fit is binned
517 // in case of false the fit is unbinned or undefined)
518 // flag it is used to compute chi2 for binned likelihood fit
519
520 int fFitType; // type of fit (0 undefined, 1 least square, 2 likelihood)
521
522 int fDataSize; // size of data sets (need for Fumili or LM fitters)
523
524 FitConfig fConfig; // fitter configuration (options and parameter settings)
525
526 std::shared_ptr<IModelFunction_v> fFunc_v; //! copy of the fitted function containing on output the fit result
527
528 std::shared_ptr<IModelFunction> fFunc; //! copy of the fitted function containing on output the fit result
529
530 std::shared_ptr<ROOT::Fit::FitResult> fResult; //! pointer to the object containing the result of the fit
531
532 std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; //! pointer to used minimizer
533
534 std::shared_ptr<ROOT::Fit::FitData> fData; //! pointer to the fit data (binned or unbinned data)
535
536 std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; //! pointer to used objective function
537
538};
539
540
541// internal functions to get data set and model function from FCN
542// useful for fits done with customized FCN classes
543template <class ObjFuncType>
545 ObjFuncType * objfunc = dynamic_cast<ObjFuncType*>(fObjFunction.get() );
546 if (objfunc) {
547 fFunc = objfunc->ModelFunctionPtr();
548 fData = objfunc->DataPtr();
549 return true;
550 }
551 else {
552 return false;
553 }
554}
555
556#ifdef R__HAS_VECCORE
557template <class NotCompileIfScalarBackend>
558void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
559{
560 fUseGradient = useGradient;
561 if (fUseGradient) {
562 const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
563 if (gradFunc) {
564 SetFunction(*gradFunc, true);
565 return;
566 } else {
567 MATH_WARN_MSG("Fitter::SetFunction",
568 "Requested function does not provide gradient - use it as non-gradient function ");
569 }
570 }
571
572 // set the fit model function (clone the given one and keep a copy )
573 // std::cout << "set a non-grad function" << std::endl;
574 fUseGradient = false;
575 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
576 assert(fFunc_v);
577
578 // creates the parameter settings
580 fFunc.reset();
581}
582
583template <class NotCompileIfScalarBackend>
584void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
585{
586 fUseGradient = useGradient;
587
588 // set the fit model function (clone the given one and keep a copy )
589 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
590 assert(fFunc_v);
591
592 // creates the parameter settings
594 fFunc.reset();
595}
596#endif
597
598 } // end namespace Fit
599
600} // end namespace ROOT
601
602// implementation of inline methods
603
604
605#ifndef __CINT__
606
607#include "Math/WrappedFunction.h"
608
609template<class Function>
610bool ROOT::Fit::Fitter::FitFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
612 return FitFCN(wf,par,datasize,chi2fit);
613}
614template<class Function>
615bool ROOT::Fit::Fitter::SetFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
617 return SetFCN(wf,par,datasize,chi2fit);
618}
619
620
621
622
623#endif // endif __CINT__
624
625#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:485
bool EvalFCN()
Perform a simple FCN evaluation.
Definition: Fitter.cxx:344
bool FitFCN()
Perform a fit with the previously set FCN function.
Definition: Fitter.cxx:326
void DoUpdateFitConfig()
Definition: Fitter.cxx:928
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:532
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:445
bool DoBinnedLikelihoodFit(bool extended=true, const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
binned likelihood fit
Definition: Fitter.cxx:424
ROOT::Math::IParamGradFunction IGradModel1DFunction
Definition: Fitter.h:93
std::shared_ptr< ROOT::Fit::FitData > fData
pointer to used minimizer
Definition: Fitter.h:534
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:434
ROOT::Math::IMultiGenFunction BaseFunc
Definition: Fitter.h:95
FitConfig & Config()
access to the configuration (non const method)
Definition: Fitter.h:417
bool LeastSquareFit(const BinData &data)
Fit a binned data set using a least square fit.
Definition: Fitter.h:163
bool fUseGradient
Definition: Fitter.h:514
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:615
void SetFunctionAndData(const IModelFunctionTempl< T > &func, const FitData &data)
Definition: Fitter.h:490
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:329
bool IsBinFit() const
query if fit is binned.
Definition: Fitter.h:423
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:917
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:536
const FitResult & Result() const
get fit result
Definition: Fitter.h:384
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:954
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:1061
const FitConfig & Config() const
access to the fit configuration (const method)
Definition: Fitter.h:412
void SetData(const std::shared_ptr< Data > &data)
Definition: Fitter.h:497
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:526
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:533
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:530
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
Definition: Fitter.h:544
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:731
~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 DoUpdateMinimizerOptions(bool canDifferentMinim=true)
Definition: Fitter.cxx:849
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:655
FitConfig fConfig
Definition: Fitter.h:524
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:528
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:638
bool DoInitMinimizer()
Definition: Fitter.cxx:807
int GetNCallsFromFCN()
Definition: Fitter.cxx:938
bool DoLeastSquareFit(const ROOT::Fit::ExecutionPolicy &executionPolicy=ROOT::Fit::ExecutionPolicy::kSerial)
least square fit
Definition: Fitter.cxx:365
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
VSD Structures.
Definition: StringConv.hxx:21
RooCmdArg Minimizer(const char *type, const char *alg=0)