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 */
114
115 /**
116 Copy constructor (disabled, class is not copyable)
117 */
118 Fitter(const Fitter &) = delete;
119
120 /**
121 Assignment operator (disabled, class is not copyable)
122 */
123 Fitter & operator = (const Fitter &) = delete;
124
125
126public:
127
128 /**
129 fit a data set using any generic model function
130 If data set is binned a least square fit is performed
131 If data set is unbinned a maximum likelihood fit (not extended) is done
132 Pre-requisite on the function:
133 it must implement the 1D or multidimensional parametric function interface
134 */
135 template <class Data, class Function,
136 class cond = typename std::enable_if<!(std::is_same<Function, ROOT::EExecutionPolicy>::value ||
139 bool Fit(const Data &data, const Function &func,
141 {
142 SetFunction(func);
143 return Fit(data, executionPolicy);
144 }
145
146 /**
147 Fit a binned data set using a least square fit (default method)
148 */
150 SetData(data);
151 return DoLeastSquareFit(executionPolicy);
152 }
153 bool Fit(const std::shared_ptr<BinData> & data, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
154 SetData(data);
155 return DoLeastSquareFit(executionPolicy);
156 }
157
158 /**
159 Fit a binned data set using a least square fit
160 */
162 return Fit(data);
163 }
164
165 /**
166 fit an unbinned data set using loglikelihood method
167 */
168 bool Fit(const UnBinData & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
169 SetData(data);
170 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
171 }
172
173 /**
174 Binned Likelihood fit. Default is extended
175 */
176 bool LikelihoodFit(const BinData &data, bool extended = true,
178 SetData(data);
179 return DoBinnedLikelihoodFit(extended, executionPolicy);
180 }
181
182 bool LikelihoodFit(const std::shared_ptr<BinData> &data, bool extended = true,
184 SetData(data);
185 return DoBinnedLikelihoodFit(extended, executionPolicy);
186 }
187 /**
188 Unbinned Likelihood fit. Default is not extended
189 */
190 bool LikelihoodFit(const UnBinData & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
191 SetData(data);
192 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
193 }
194 bool LikelihoodFit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
195 SetData(data);
196 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
197 }
198
199
200 /**
201 fit a data set using any generic model function
202 Pre-requisite on the function:
203 */
204 template < class Data , class Function>
205 bool LikelihoodFit( const Data & data, const Function & func, bool extended) {
206 SetFunction(func);
207 return LikelihoodFit(data, extended);
208 }
209
210 /**
211 do a linear fit on a set of bin-data
212 */
213 bool LinearFit(const BinData & data) {
214 SetData(data);
215 return DoLinearFit();
216 }
217 bool LinearFit(const std::shared_ptr<BinData> & data) {
218 SetData(data);
219 return DoLinearFit();
220 }
221
222
223 /**
224 Fit using the a generic FCN function as a C++ callable object implementing
225 double () (const double *)
226 Note that the function dimension (i.e. the number of parameter) is needed in this case
227 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
228 */
229 template <class Function>
230 bool FitFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
231
232 /**
233 Set a generic FCN function as a C++ callable object implementing
234 double () (const double *)
235 Note that the function dimension (i.e. the number of parameter) is needed in this case
236 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
237 */
238 template <class Function>
239 bool SetFCN(unsigned int npar, Function & fcn, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
240
241 /**
242 Fit using the given FCN function represented by a multi-dimensional function interface
243 (ROOT::Math::IMultiGenFunction).
244 Give optionally the initial parameter values, data size to have the fit Ndf correctly
245 set in the FitResult and flag specifying if it is a chi2 fit.
246 Note that if the parameters values are not given (params=0) the
247 current parameter settings are used. The parameter settings can be created before
248 by using the FitConfig::SetParamsSetting. If they have not been created they are created
249 automatically when the params pointer is not zero.
250 Note that passing a params != 0 will set the parameter settings to the new value AND also the
251 step sizes to some pre-defined value (stepsize = 0.3 * abs(parameter_value) )
252 */
253 bool FitFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
254
255 /**
256 Fit using a FitMethodFunction interface. Same as method above, but now extra information
257 can be taken from the function class
258 */
259 bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
260
261 /**
262 Set the FCN function represented by a multi-dimensional function interface
263 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
264 See also note above for the initial parameters for FitFCN
265 */
266 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
267
268 /**
269 Set the FCN function represented by a multi-dimensional function interface
270 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
271 See also note above for the initial parameters for FitFCN
272 With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
273 used to compute confidence interval of the fit
274 */
275 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const IModelFunction & func, const double *params = 0,
276 unsigned int dataSize = 0, bool chi2fit = false);
277
278 /**
279 Set the objective function (FCN) using a FitMethodFunction interface.
280 Same as method above, but now extra information can be taken from the function class
281 */
282 bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double * params = 0);
283
284 /**
285 Fit using the given FCN function representing a multi-dimensional gradient function
286 interface (ROOT::Math::IMultiGradFunction). In this case the minimizer will use the
287 gradient information provided by the function.
288 For the options same consideration as in the previous method
289 */
290 bool FitFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
291
292 /**
293 Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
294 can be taken from the function class
295 */
296 bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
297
298 /**
299 Set the FCN function represented by a multi-dimensional gradient function interface
300 (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
301 See also note above for the initial parameters for FitFCN
302 */
303 bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const double *params = 0, unsigned int dataSize = 0, bool chi2fit = false);
304
305 /**
306 Set the FCN function represented by a multi-dimensional gradient function interface
307 (ROOT::Math::IMultiGradFunction) and optionally the initial parameters
308 See also note above for the initial parameters for FitFCN
309 With this interface we pass in addition a ModelFunction that will be attached to the FitResult and
310 used to compute confidence interval of the fit
311 */
312 bool SetFCN(const ROOT::Math::IMultiGradFunction &fcn, const IModelFunction &func, const double *params = 0,
313 unsigned int dataSize = 0, bool chi2fit = false);
314
315 /**
316 Set the objective function (FCN) using a FitMethodGradFunction interface.
317 Same as method above, but now extra information can be taken from the function class
318 */
319 bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double * params = 0);
320
321
322 /**
323 fit using user provided FCN with Minuit-like interface
324 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
325 For the options same consideration as in the previous method
326 */
327 typedef void (* MinuitFCN_t )(int &npar, double *gin, double &f, double *u, int flag);
328 bool FitFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
329
330 /**
331 set objective function using user provided FCN with Minuit-like interface
332 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
333 For the options same consideration as in the previous method
334 */
335 bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double * params = 0, unsigned int dataSize = 0, bool chi2fit = false);
336
337 /**
338 Perform a fit with the previously set FCN function. Require SetFCN before
339 */
340 bool FitFCN();
341
342 /**
343 Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
344 */
345 bool EvalFCN();
346
347
348
349 /**
350 Set the fitted function (model function) from a parametric function interface
351 */
352 void SetFunction(const IModelFunction & func, bool useGradient = false);
353
354 /**
355 Set the fitted function (model function) from a vectorized parametric function interface
356 */
357#ifdef R__HAS_VECCORE
358 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
359 void SetFunction(const IModelFunction_v &func, bool useGradient = false);
360
361 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
362 void SetFunction(const IGradModelFunction_v &func, bool useGradient = true);
363#endif
364 /**
365 Set the fitted function from a parametric 1D function interface
366 */
367 void SetFunction(const IModel1DFunction & func, bool useGradient = false);
368
369 /**
370 Set the fitted function (model function) from a parametric gradient function interface
371 */
372 void SetFunction(const IGradModelFunction & func, bool useGradient = true);
373 /**
374 Set the fitted function from 1D gradient parametric function interface
375 */
376 void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
377
378
379 /**
380 get fit result
381 */
382 const FitResult & Result() const {
383 assert( fResult.get() );
384 return *fResult;
385 }
386
387
388 /**
389 perform an error analysis on the result using the Hessian
390 Errors are obtained from the inverse of the Hessian matrix
391 To be called only after fitting and when a minimizer supporting the Hessian calculations is used
392 otherwise an error (false) is returned.
393 A new FitResult with the Hessian result will be produced
394 */
395 bool CalculateHessErrors();
396
397 /**
398 perform an error analysis on the result using MINOS
399 To be called only after fitting and when a minimizer supporting MINOS is used
400 otherwise an error (false) is returned.
401 The result will be appended in the fit result class
402 Optionally a vector of parameter indices can be passed for selecting
403 the parameters to analyse using FitConfig::SetMinosErrors
404 */
406
407 /**
408 access to the fit configuration (const method)
409 */
410 const FitConfig & Config() const { return fConfig; }
411
412 /**
413 access to the configuration (non const method)
414 */
415 FitConfig & Config() { return fConfig; }
416
417 /**
418 query if fit is binned. In cse of false the fit can be unbinned
419 or is not defined (like in case of fitting through a ROOT::Fit::Fitter::FitFCN)
420 */
421 bool IsBinFit() const { return fBinFit; }
422
423 /**
424 return pointer to last used minimizer
425 (is NULL in case fit is not yet done)
426 This pointer is guaranteed to be valid as far as the fitter class is valid and a new fit is not redone.
427 To be used only after fitting.
428 The pointer should not be stored and will be invalided after performing a new fitting.
429 In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
430 obtained calling again GetMinimizer()
431 */
433
434 /**
435 return pointer to last used objective function
436 (is NULL in case fit is not yet done)
437 This pointer will be valid as far as the fitter class
438 has not been deleted. To be used after the fitting.
439 The pointer should not be stored and will be invalided after performing a new fitting.
440 In this case a new instance of the function pointer will be re-created and can be
441 obtained calling again GetFCN()
442 */
444 return fObjFunction.get();
445 }
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 implemented 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::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential);
466 /// un-binned likelihood fit
467 bool DoUnbinnedLikelihoodFit( bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential);
468 /// linear least square fit
469 bool DoLinearFit();
470 /// Set Objective function
471 bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize,
472 bool chi2fit);
473
474 // initialize the minimizer
475 bool DoInitMinimizer();
476 /// do minimization
477 template<class ObjFunc_t>
478 bool DoMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
479 // do minimization for weighted likelihood fits
480 template<class ObjFunc_t>
481 bool DoWeightMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
482 // do minimization after having set the objective function
483 bool DoMinimization(const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
484 // update config after fit
485 void DoUpdateFitConfig();
486 // update minimizer options for re-fitting
487 bool DoUpdateMinimizerOptions(bool canDifferentMinim = true);
488 // get function calls from the FCN
489 int GetNCallsFromFCN();
490
491 //set data for the fit
492 void SetData(const FitData & data) {
493 fData = std::shared_ptr<FitData>(const_cast<FitData*>(&data),DummyDeleter<FitData>());
494 }
495 // set data and function without cloning them
496 template <class T>
498 SetData(data);
499 fFunc = std::shared_ptr<IModelFunctionTempl<T>>(const_cast<IModelFunctionTempl<T>*>(&func),DummyDeleter<IModelFunctionTempl<T>>());
500 }
501
502 //set data for the fit using a shared ptr
503 template <class Data>
504 void SetData(const std::shared_ptr<Data> & data) {
505 fData = std::static_pointer_cast<Data>(data);
506 }
507
508 /// look at the user provided FCN and get data and model function is
509 /// they derive from ROOT::Fit FCN classes
510 void ExamineFCN();
511
512
513 /// internal functions to get data set and model function from FCN
514 /// useful for fits done with customized FCN classes
515 template <class ObjFuncType>
516 bool GetDataFromFCN();
517
518 /// return pointer to used objective function
519 /// if using an external one use external, otherwise use the one stored
520 /// in shared ptr
523 }
524
525private:
526
527 bool fUseGradient = false; ///< flag to indicate if using gradient or not
528
529 bool fBinFit = false; ///< flag to indicate if fit is binned
530 ///< in case of false the fit is unbinned or undefined)
531 ///< flag it is used to compute chi2 for binned likelihood fit
532
533 int fFitType = 0; ///< type of fit (0 undefined, 1 least square, 2 likelihood)
534
535 int fDataSize = 0; ///< size of data sets (need for Fumili or LM fitters)
536
537 FitConfig fConfig; ///< fitter configuration (options and parameter settings)
538
539 std::shared_ptr<IModelFunction_v> fFunc_v; ///<! copy of the fitted function containing on output the fit result
540
541 std::shared_ptr<IModelFunction> fFunc; ///<! copy of the fitted function containing on output the fit result
542
543 std::shared_ptr<ROOT::Fit::FitResult> fResult; ///<! pointer to the object containing the result of the fit
544
545 std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; ///<! pointer to used minimizer
546
547 std::shared_ptr<ROOT::Fit::FitData> fData; ///<! pointer to the fit data (binned or unbinned data)
548
549 std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; ///<! pointer to used objective function
550
551 const ROOT::Math::IMultiGenFunction * fExtObjFunction = nullptr; ///<! pointer to an external FCN
552
553};
554
555
556// internal functions to get data set and model function from FCN
557// useful for fits done with customized FCN classes
558template <class ObjFuncType>
560 const ObjFuncType * objfunc = dynamic_cast<const ObjFuncType*>(ObjFunction());
561 if (objfunc) {
562 fFunc = objfunc->ModelFunctionPtr();
563 fData = objfunc->DataPtr();
564 return true;
565 }
566 else {
567 return false;
568 }
569}
570
571#ifdef R__HAS_VECCORE
572template <class NotCompileIfScalarBackend>
573void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
574{
575 fUseGradient = useGradient;
576 if (fUseGradient) {
577 const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
578 if (gradFunc) {
579 SetFunction(*gradFunc, true);
580 return;
581 } else {
582 MATH_WARN_MSG("Fitter::SetFunction",
583 "Requested function does not provide gradient - use it as non-gradient function ");
584 }
585 }
586
587 // set the fit model function (clone the given one and keep a copy )
588 // std::cout << "set a non-grad function" << std::endl;
589 fUseGradient = false;
590 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
591 assert(fFunc_v);
592
593 // creates the parameter settings
595 fFunc.reset();
596}
597
598template <class NotCompileIfScalarBackend>
599void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
600{
601 fUseGradient = useGradient;
602
603 // set the fit model function (clone the given one and keep a copy )
604 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
605 assert(fFunc_v);
606
607 // creates the parameter settings
609 fFunc.reset();
610}
611#endif
612
613 } // end namespace Fit
614
615} // end namespace ROOT
616
617// implementation of inline methods
618
619
620#ifndef __CINT__
621
622#include "Math/WrappedFunction.h"
623
624template<class Function>
625bool ROOT::Fit::Fitter::FitFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
627 if (!DoSetFCN(false, wf, par, datasize, chi2fit))
628 return false;
629 return FitFCN();
630}
631template<class Function>
632bool ROOT::Fit::Fitter::SetFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,bool chi2fit) {
634 return DoSetFCN(false, wf, par, datasize, chi2fit);
635}
636
637
638
639
640#endif // endif __CINT__
641
642#endif /* ROOT_Fit_Fitter */
#define MATH_WARN_MSG(loc, str)
Definition: Error.h:80
#define f(i)
Definition: RSha256.hxx:104
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 value
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:47
void CreateParamsSettings(const ROOT::Math::IParamMultiFunctionTempl< T > &func)
set the parameter settings from a model function.
Definition: FitConfig.h:109
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
class containing the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:47
Fitter class, entry point for performing all type of fits.
Definition: Fitter.h:77
bool LikelihoodFit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Definition: Fitter.h:194
bool LinearFit(const BinData &data)
do a linear fit on a set of bin-data
Definition: Fitter.h:213
void SetData(const FitData &data)
Definition: Fitter.h:492
bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize, bool chi2fit)
Set Objective function.
Definition: Fitter.cxx:137
bool EvalFCN()
Perform a simple FCN evaluation.
Definition: Fitter.cxx:314
const ROOT::Math::IMultiGenFunction * fExtObjFunction
! pointer to an external FCN
Definition: Fitter.h:551
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:295
void DoUpdateFitConfig()
Definition: Fitter.cxx:860
const ROOT::Math::IMultiGenFunction * ObjFunction() const
return pointer to used objective function if using an external one use external, otherwise use the on...
Definition: Fitter.h:521
bool DoMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
do minimization
Definition: Fitter.cxx:838
int fDataSize
size of data sets (need for Fumili or LM fitters)
Definition: Fitter.h:535
bool DoUnbinnedLikelihoodFit(bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
un-binned likelihood fit
Definition: Fitter.cxx:466
ROOT::Math::IParamMultiFunction IModelFunction_v
Definition: Fitter.h:88
bool Fit(const BinData &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit (default method)
Definition: Fitter.h:149
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
! pointer to used minimizer
Definition: Fitter.h:545
bool DoWeightMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
Definition: Fitter.cxx:847
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:205
bool DoBinnedLikelihoodFit(bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
binned likelihood fit
Definition: Fitter.cxx:386
int fFitType
type of fit (0 undefined, 1 least square, 2 likelihood)
Definition: Fitter.h:533
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:443
ROOT::Math::IParamGradFunction IGradModel1DFunction
Definition: Fitter.h:93
std::shared_ptr< ROOT::Fit::FitData > fData
! pointer to the fit data (binned or unbinned data)
Definition: Fitter.h:547
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:432
ROOT::Math::IMultiGenFunction BaseFunc
Definition: Fitter.h:95
FitConfig & Config()
access to the configuration (non const method)
Definition: Fitter.h:415
bool LeastSquareFit(const BinData &data)
Fit a binned data set using a least square fit.
Definition: Fitter.h:161
bool fUseGradient
flag to indicate if using gradient or not
Definition: Fitter.h:527
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:529
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:632
void SetFunctionAndData(const IModelFunctionTempl< T > &func, const FitData &data)
Definition: Fitter.h:497
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:327
bool IsBinFit() const
query if fit is binned.
Definition: Fitter.h:421
bool LinearFit(const std::shared_ptr< BinData > &data)
Definition: Fitter.h:217
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
! pointer to used objective function
Definition: Fitter.h:549
bool Fit(const std::shared_ptr< BinData > &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Definition: Fitter.h:153
const FitResult & Result() const
get fit result
Definition: Fitter.h:382
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:886
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:979
const FitConfig & Config() const
access to the fit configuration (const method)
Definition: Fitter.h:410
void SetData(const std::shared_ptr< Data > &data)
Definition: Fitter.h:504
bool DoLeastSquareFit(const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
least square fit
Definition: Fitter.cxx:335
ROOT::Math::IParamMultiFunction IModelFunction
Definition: Fitter.h:81
ROOT::Math::IParamFunction IModel1DFunction
Definition: Fitter.h:92
bool LikelihoodFit(const BinData &data, bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Binned Likelihood fit.
Definition: Fitter.h:176
std::shared_ptr< IModelFunction_v > fFunc_v
! copy of the fitted function containing on output the fit result
Definition: Fitter.h:539
ROOT::Math::IParamMultiGradFunction IGradModelFunction_v
Definition: Fitter.h:89
bool LikelihoodFit(const std::shared_ptr< BinData > &data, bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Definition: Fitter.h:182
std::shared_ptr< ROOT::Fit::FitResult > fResult
! pointer to the object containing the result of the fit
Definition: Fitter.h:543
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
Definition: Fitter.h:559
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:619
~Fitter()
Destructor.
Definition: Fitter.h:113
Fitter(const Fitter &)=delete
Copy constructor (disabled, class is not copyable)
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:764
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:139
bool Fit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
fit an unbinned data set using loglikelihood method
Definition: Fitter.h:168
void SetFunction(const IModelFunction &func, bool useGradient=false)
Set the fitted function (model function) from a parametric function interface.
Definition: Fitter.cxx:59
bool CalculateHessErrors()
perform an error analysis on the result using the Hessian Errors are obtained from the inverse of the...
Definition: Fitter.cxx:556
FitConfig fConfig
fitter configuration (options and parameter settings)
Definition: Fitter.h:537
Fitter()
Default constructor.
Definition: Fitter.h:102
std::shared_ptr< IModelFunction > fFunc
! copy of the fitted function containing on output the fit result
Definition: Fitter.h:541
bool LikelihoodFit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Unbinned Likelihood fit.
Definition: Fitter.h:190
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:539
bool DoInitMinimizer()
Definition: Fitter.cxx:718
int GetNCallsFromFCN()
Definition: Fitter.cxx:870
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:343
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:75
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
RooCmdArg Minimizer(const char *type, const char *alg=0)
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133
Namespace for new Math classes and functions.
void(off) SmallVectorTemplateBase< T
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition: Fitter.h:43
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
Definition: Fitter.h:44
This file contains a specialised ROOT message handler to test for diagnostic in unit tests.