Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
Fitter.h
Go to the documentation of this file.
1// @(#)root/mathcore:$Id$
2// Author: L. Moneta Wed Aug 30 11:05:19 2006
3
4/**********************************************************************
5 * *
6 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT *
7 * *
8 * *
9 **********************************************************************/
10
11// 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 Make it virtual in case users derive from Fitter class to extend it by adding new methods.
113 This is needed to avoid a warning seen when doing from Python
114 (see ROOT issue [#12391](https://github.com/root-project/root/issues/12391) ).
115 Note that the Fitter class does not provide virtual functions to be re-implemented by derived classes.
116 */
117 virtual ~Fitter () {}
118
119 /**
120 Copy constructor (disabled, class is not copyable)
121 */
122 Fitter(const Fitter &) = delete;
123
124 /**
125 Assignment operator (disabled, class is not copyable)
126 */
127 Fitter & operator = (const Fitter &) = delete;
128
129
130public:
131
132 /**
133 fit a data set using any generic model function
134 If data set is binned a least square fit is performed
135 If data set is unbinned a maximum likelihood fit (not extended) is done
136 Pre-requisite on the function:
137 it must implement the 1D or multidimensional parametric function interface.
138 Note that both the input data and the function object are copied by the Fitter.
139 */
140 template <class Data, class Function,
141 class cond = typename std::enable_if<!(std::is_same<Function, ROOT::EExecutionPolicy>::value ||
142 std::is_same<Function, int>::value),
144 bool Fit(const Data &data, const Function &func,
146 {
147 SetFunction(func);
148 return Fit(data, executionPolicy);
149 }
150
151 /**
152 Fit a binned data set using a least square fit.
153 Note that the provided input data are copied in the Fitter class.
154 Use the next function (passing a `shared_ptr` to the BinData class if you want to avoid
155 copying.
156 */
158 return LeastSquareFit(data, executionPolicy);
159 }
160
161 /**
162 Fit a binned data set using a least square fit.
163 Pass the input data using a `shared_ptr` for NOT copying the input data.
164 */
165 bool Fit(const std::shared_ptr<BinData> & data, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
166 return LeastSquareFit(data, executionPolicy);
167 }
168
169 /**
170 Fit a binned data set using a least square fit copying the input data.
171 */
173 SetData(data);
174 return DoLeastSquareFit(executionPolicy);
175 }
176 /**
177 Fit a binned data set using a least square fit NOT copying the input data.
178 */
179 bool LeastSquareFit(const std::shared_ptr<BinData> & data, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
180 SetData(data);
181 return DoLeastSquareFit(executionPolicy);
182 }
183
184 /**
185 Fit an un-binned data set using the negative log-likelihood method.
186 This function copies the input data.
187 */
188 bool Fit(const UnBinData & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
189 return LikelihoodFit(data, extended, executionPolicy);
190 }
191 /**
192 Fit an un-binned data set using the negative log-likelihood method.
193 This function uses a `shared_ptr` to avoid copying the input data.
194 */
195 bool Fit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
196 return LikelihoodFit(data, extended, executionPolicy);
197 }
198
199 /**
200 Binned Likelihood fit copying the input data.
201 Default is extended.
202 */
203 bool LikelihoodFit(const BinData &data, bool extended = true,
205 SetData(data);
206 return DoBinnedLikelihoodFit(extended, executionPolicy);
207 }
208 /**
209 Binned Likelihood fit using a `shared_ptr` for NOT copying the input data.
210 Default is extended.
211 */
212 bool LikelihoodFit(const std::shared_ptr<BinData> &data, bool extended = true,
214 SetData(data);
215 return DoBinnedLikelihoodFit(extended, executionPolicy);
216 }
217 /**
218 Un-binned Likelihood fit copying the input data
219 Default is NOT extended
220 */
221 bool LikelihoodFit(const UnBinData & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
222 SetData(data);
223 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
224 }
225 /**
226 Un-binned Likelihood fit using a `shared_ptr` for NOT copying the input data.
227 Default is NOT extended
228 */
229 bool LikelihoodFit(const std::shared_ptr<UnBinData> & data, bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential) {
230 SetData(data);
231 return DoUnbinnedLikelihoodFit(extended, executionPolicy);
232 }
233
234 /**
235 Likelihood fit given a data set (Binned or Un-binned) using any generic model function.
236 This interface copies the input data and the model function object
237 */
238 template < class Data , class Function>
239 bool LikelihoodFit( const Data & data, const Function & func, bool extended) {
240 SetFunction(func);
241 return LikelihoodFit(data, extended);
242 }
243
244 /**
245 Do a linear fit copying the input data
246 */
247 bool LinearFit(const BinData & data) {
248 SetData(data);
249 return DoLinearFit();
250 }
251 /**
252 Do a linear fit using a `shared_ptr` for NOT copying the input data
253 */
254 bool LinearFit(const std::shared_ptr<BinData> & data) {
255 SetData(data);
256 return DoLinearFit();
257 }
258
259 /**
260 Fit using the a generic FCN function as a C++ callable object implementing
261 double () (const double *)
262 Note that the function dimension (i.e. the number of parameter) is needed in this case
263 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
264 */
265 template <class Function>
266 bool FitFCN(unsigned int npar, Function & fcn, const double * params = nullptr, unsigned int dataSize = 0, int fitType = 0);
267
268 /**
269 Set a generic FCN function as a C++ callable object implementing
270 double () (const double *)
271 Note that the function dimension (i.e. the number of parameter) is needed in this case
272 For the options see documentation for following methods FitFCN(IMultiGenFunction & fcn,..)
273 */
274 template <class Function>
275 bool SetFCN(unsigned int npar, Function & fcn, const double * params = nullptr, unsigned int dataSize = 0, int fitType = 0);
276
277 /**
278 Fit using the given FCN function represented by a multi-dimensional function interface
279 (ROOT::Math::IMultiGenFunction).
280 Give optionally the initial parameter values, data size to have the fit Ndf correctly
281 set in the FitResult and flag specifying the type of fit. The fitType can be:
282 0 undefined, 1 least square fit, 2 unbinned likelihood fit, 3 binned likelihood fit
283 Note that if the parameters values are not given (params=0) the
284 current parameter settings are used. The parameter settings can be created before
285 by using the FitConfig::SetParamsSetting. If they have not been created they are created
286 automatically when the params pointer is not zero.
287 Note that passing a params != 0 will set the parameter settings to the new value AND also the
288 step sizes to some pre-defined value (stepsize = 0.3 * abs(parameter_value) )
289 */
290 bool FitFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
291
292 /**
293 Fit using a FitMethodFunction interface. Same as method above, but now extra information
294 can be taken from the function class
295 */
296 bool FitFCN(const ROOT::Math::FitMethodFunction & fcn, const double *params = nullptr);
297
298 /**
299 Set the FCN function represented by a multi-dimensional function interface
300 (ROOT::Math::IMultiGenFunction) and optionally the initial parameters
301 See also note above for the initial parameters for FitFCN
302 */
303 bool SetFCN(const ROOT::Math::IMultiGenFunction &fcn, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
304
305 /**
306 Set the FCN function represented by a multi-dimensional function interface
307 (ROOT::Math::IMultiGenFunction) 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::IMultiGenFunction &fcn, const IModelFunction & func, const double *params = nullptr,
313 unsigned int dataSize = 0, int fitType = 0);
314
315 /**
316 Set the objective function (FCN) using a FitMethodFunction interface.
317 Same as method above, but now extra information can be taken from the function class
318 */
319 bool SetFCN(const ROOT::Math::FitMethodFunction & fcn, const double *params = nullptr);
320
321 /**
322 Fit using a FitMethodGradFunction interface. Same as method above, but now extra information
323 can be taken from the function class
324 */
325 bool FitFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double *params = nullptr);
326
327 /**
328 Set the objective function (FCN) using a FitMethodGradFunction interface.
329 Same as method above, but now extra information can be taken from the function class
330 */
331 bool SetFCN(const ROOT::Math::FitMethodGradFunction & fcn, const double *params = nullptr);
332
333
334 /**
335 fit using user provided FCN with Minuit-like interface
336 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
337 For the options same consideration as in the previous method
338 */
339 typedef void (* MinuitFCN_t )(int &npar, double *gin, double &f, double *u, int flag);
340 bool FitFCN( MinuitFCN_t fcn, int npar = 0, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
341
342 /**
343 set objective function using user provided FCN with Minuit-like interface
344 If npar = 0 it is assumed that the parameters are specified in the parameter settings created before
345 For the options same consideration as in the previous method
346 */
347 bool SetFCN( MinuitFCN_t fcn, int npar = 0, const double *params = nullptr, unsigned int dataSize = 0, int fitType = 0);
348
349 /**
350 Perform a fit with the previously set FCN function. Require SetFCN before
351 */
352 bool FitFCN();
353
354 /**
355 Perform a simple FCN evaluation. FitResult will be modified and contain the value of the FCN
356 */
357 bool EvalFCN();
358
359
360
361 /**
362 Set the fitted function (model function) from a parametric function interface
363 */
364 void SetFunction(const IModelFunction & func, bool useGradient = false);
365
366 /**
367 Set the fitted function (model function) from a vectorized parametric function interface
368 */
369#ifdef R__HAS_VECCORE
370 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
371 void SetFunction(const IModelFunction_v &func, bool useGradient = false);
372
373 template <class NotCompileIfScalarBackend = std::enable_if<!(std::is_same<double, ROOT::Double_v>::value)>>
374 void SetFunction(const IGradModelFunction_v &func, bool useGradient = true);
375#endif
376 /**
377 Set the fitted function from a parametric 1D function interface
378 */
379 void SetFunction(const IModel1DFunction & func, bool useGradient = false);
380
381 /**
382 Set the fitted function (model function) from a parametric gradient function interface
383 */
384 void SetFunction(const IGradModelFunction & func, bool useGradient = true);
385 /**
386 Set the fitted function from 1D gradient parametric function interface
387 */
388 void SetFunction(const IGradModel1DFunction & func, bool useGradient = true);
389
390
391 /**
392 get fit result
393 */
394 const FitResult & Result() const {
395 assert( fResult.get() );
396 return *fResult;
397 }
398
399
400 /**
401 perform an error analysis on the result using the Hessian
402 Errors are obtained from the inverse of the Hessian matrix
403 To be called only after fitting and when a minimizer supporting the Hessian calculations is used
404 otherwise an error (false) is returned.
405 A new FitResult with the Hessian result will be produced
406 */
407 bool CalculateHessErrors();
408
409 /**
410 perform an error analysis on the result using MINOS
411 To be called only after fitting and when a minimizer supporting MINOS is used
412 otherwise an error (false) is returned.
413 The result will be appended in the fit result class
414 Optionally a vector of parameter indices can be passed for selecting
415 the parameters to analyse using FitConfig::SetMinosErrors
416 */
418
419 /**
420 access to the fit configuration (const method)
421 */
422 const FitConfig & Config() const { return fConfig; }
423
424 /**
425 access to the configuration (non const method)
426 */
427 FitConfig & Config() { return fConfig; }
428
429 /**
430 query if fit is binned. In cse of false the fit can be unbinned
431 or is not defined (like in case of fitting through a ROOT::Fit::Fitter::FitFCN)
432 */
433 bool IsBinFit() const { return fBinFit; }
434
435 /**
436 return pointer to last used minimizer
437 (is NULL in case fit is not yet done)
438 This pointer is guaranteed to be valid as far as the fitter class is valid and a new fit is not redone.
439 To be used only after fitting.
440 The pointer should not be stored and will be invalided after performing a new fitting.
441 In this case a new instance of ROOT::Math::Minimizer will be re-created and can be
442 obtained calling again GetMinimizer()
443 */
445
446 /**
447 return pointer to last used objective function
448 (is NULL in case fit is not yet done)
449 This pointer will be valid as far as the fitter class
450 has not been deleted. To be used after the fitting.
451 The pointer should not be stored and will be invalided after performing a new fitting.
452 In this case a new instance of the function pointer will be re-created and can be
453 obtained calling again GetFCN()
454 */
456 return fObjFunction.get();
457 }
458
459
460 /**
461 apply correction in the error matrix for the weights for likelihood fits
462 This method can be called only after a fit. The
463 passed function (loglw2) is a log-likelihood function implemented using the
464 sum of weight squared
465 When using FitConfig.SetWeightCorrection() this correction is applied
466 automatically when doing a likelihood fit (binned or unbinned)
467 */
468 bool ApplyWeightCorrection(const ROOT::Math::IMultiGenFunction & loglw2, bool minimizeW2L=false);
469
470 /// Set number of fit points when using an external FCN function
471 /// This function can be called after Fit to set the correct number of Ndf in FitResult
472 void SetNumberOfFitPoints(unsigned int npoints) {
473 if (fExtObjFunction) fDataSize = npoints;
474 if (!fResult->IsEmpty()) fResult->SetChi2AndNdf(-1,npoints);
475 }
476
477 /// Set the type of fit when using an external FCN
478 /// possible types are : 1 (least-square), 2 (unbinned-likelihood), 3 (binned-likelihood)
479 /// Note that in case of binned likelihood fit the chi2 will be computed as 2 * MinFCN()
480 /// Note this function should be called before fitting to have effect on th FitResult
481 void SetFitType(int type) {
483 }
484
485
486protected:
487
488
489 /// least square fit
491 /// binned likelihood fit
492 bool DoBinnedLikelihoodFit(bool extended = true, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential);
493 /// un-binned likelihood fit
494 bool DoUnbinnedLikelihoodFit( bool extended = false, const ROOT::EExecutionPolicy &executionPolicy = ROOT::EExecutionPolicy::kSequential);
495 /// linear least square fit
496 bool DoLinearFit();
497 /// Set Objective function
498 bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize,
499 int fitType);
500
501 // initialize the minimizer
502 bool DoInitMinimizer();
503 /// do minimization
504 template<class ObjFunc_t>
505 bool DoMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
506 // do minimization for weighted likelihood fits
507 template<class ObjFunc_t>
508 bool DoWeightMinimization(std::unique_ptr<ObjFunc_t> f, const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
509 // do minimization after having set the objective function
510 bool DoMinimization(const ROOT::Math::IMultiGenFunction * chifunc = nullptr);
511 // update config after fit
512 void DoUpdateFitConfig();
513 // update minimizer options for re-fitting
514 bool DoUpdateMinimizerOptions(bool canDifferentMinim = true);
515 // get function calls from the FCN
516 int GetNCallsFromFCN();
517
518 /// Set the input data for the fit using a shared ptr (No Copying)
519 template <class Data>
520 void SetData(const std::shared_ptr<Data> & data) {
521 fData = std::static_pointer_cast<Data>(data);
522 }
523
524 /// Set the input data for the fit (Copying the given data object)
525 template <class Data>
526 void SetData(const Data & data) {
527 auto dataClone = std::make_shared<Data>(data);
528 SetData(dataClone);
529 }
530
531 /// look at the user provided FCN and get data and model function is
532 /// they derive from ROOT::Fit FCN classes
533 void ExamineFCN();
534
535
536 /// internal functions to get data set and model function from FCN
537 /// useful for fits done with customized FCN classes
538 template <class ObjFuncType>
539 bool GetDataFromFCN();
540
541 /// Return pointer to the used objective function for fitting.
542 /// If using an external function (e.g. given in SetFCN), return the cached pointer,
543 /// otherwise use the one stored as shared ptr and managed by the Fitter class
545 // need to specify here full return type since when using the typedef (IMultiGenFunction)
546 // there is an error when using the class in Python (see issue #12391)
548 }
549
550private:
551
552 bool fUseGradient = false; ///< flag to indicate if using gradient or not
553
554 bool fBinFit = false; ///< flag to indicate if fit is binned
555 ///< in case of false the fit is unbinned or undefined)
556 ///< flag it is used to compute chi2 for binned likelihood fit
557
558 int fFitType = 0; ///< type of fit (0 undefined, 1 least square, 2 likelihood, 3 binned likelihood)
559
560 int fDataSize = 0; ///< size of data sets (need for Fumili or LM fitters)
561
562 FitConfig fConfig; ///< fitter configuration (options and parameter settings)
563
564 std::shared_ptr<IModelFunction_v> fFunc_v; ///<! copy of the fitted function containing on output the fit result
565
566 std::shared_ptr<IModelFunction> fFunc; ///<! copy of the fitted function containing on output the fit result
567
568 std::shared_ptr<ROOT::Fit::FitResult> fResult; ///<! pointer to the object containing the result of the fit
569
570 std::shared_ptr<ROOT::Math::Minimizer> fMinimizer; ///<! pointer to used minimizer
571
572 std::shared_ptr<ROOT::Fit::FitData> fData; ///<! pointer to the fit data (binned or unbinned data)
573
574 std::shared_ptr<ROOT::Math::IMultiGenFunction> fObjFunction; ///<! pointer to used objective function
575
576 const ROOT::Math::IMultiGenFunction * fExtObjFunction = nullptr; ///<! pointer to an external FCN
577
578};
579
580
581// internal functions to get data set and model function from FCN
582// useful for fits done with customized FCN classes
583template <class ObjFuncType>
585 const ObjFuncType * objfunc = dynamic_cast<const ObjFuncType*>(ObjFunction());
586 if (objfunc) {
587 fFunc = objfunc->ModelFunctionPtr();
588 fData = objfunc->DataPtr();
589 return true;
590 }
591 else {
592 return false;
593 }
594}
595
596#ifdef R__HAS_VECCORE
597template <class NotCompileIfScalarBackend>
598void Fitter::SetFunction(const IModelFunction_v &func, bool useGradient)
599{
600 fUseGradient = useGradient;
601 if (fUseGradient) {
602 const IGradModelFunction_v *gradFunc = dynamic_cast<const IGradModelFunction_v *>(&func);
603 if (gradFunc) {
604 SetFunction(*gradFunc, true);
605 return;
606 } else {
607 MATH_WARN_MSG("Fitter::SetFunction",
608 "Requested function does not provide gradient - use it as non-gradient function ");
609 }
610 }
611
612 // set the fit model function (clone the given one and keep a copy )
613 // std::cout << "set a non-grad function" << std::endl;
614 fUseGradient = false;
615 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IModelFunction_v *>(func.Clone()));
616 assert(fFunc_v);
617
618 // creates the parameter settings
620 fFunc.reset();
621}
622
623template <class NotCompileIfScalarBackend>
624void Fitter::SetFunction(const IGradModelFunction_v &func, bool useGradient)
625{
626 fUseGradient = useGradient;
627
628 // set the fit model function (clone the given one and keep a copy )
629 fFunc_v = std::shared_ptr<IModelFunction_v>(dynamic_cast<IGradModelFunction_v *>(func.Clone()));
630 assert(fFunc_v);
631
632 // creates the parameter settings
634 fFunc.reset();
635}
636#endif
637
638 } // end namespace Fit
639
640} // end namespace ROOT
641
642// implementation of inline methods
643
644
645
646#include "Math/WrappedFunction.h"
647
648template<class Function>
649bool ROOT::Fit::Fitter::FitFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,int fitType) {
651 if (!DoSetFCN(false, wf, par, datasize, fitType))
652 return false;
653 return FitFCN();
654}
655template<class Function>
656bool ROOT::Fit::Fitter::SetFCN(unsigned int npar, Function & f, const double * par, unsigned int datasize,int fitType) {
658 return DoSetFCN(false, wf, par, datasize, fitType);
659}
660
661
662
663
664#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 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
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)
Un-binned Likelihood fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:229
bool LinearFit(const BinData &data)
Do a linear fit copying the input data.
Definition Fitter.h:247
bool LeastSquareFit(const std::shared_ptr< BinData > &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit NOT copying the input data.
Definition Fitter.h:179
bool EvalFCN()
Perform a simple FCN evaluation.
Definition Fitter.cxx:288
const ROOT::Math::IMultiGenFunction * fExtObjFunction
! pointer to an external FCN
Definition Fitter.h:576
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:269
void DoUpdateFitConfig()
Definition Fitter.cxx:860
bool DoMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
do minimization
Definition Fitter.cxx:836
bool DoSetFCN(bool useExtFCN, const ROOT::Math::IMultiGenFunction &fcn, const double *params, unsigned int dataSize, int fitType)
Set Objective function.
Definition Fitter.cxx:137
int fDataSize
size of data sets (need for Fumili or LM fitters)
Definition Fitter.h:560
bool DoUnbinnedLikelihoodFit(bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
un-binned likelihood fit
Definition Fitter.cxx:440
void SetData(const Data &data)
Set the input data for the fit (Copying the given data object)
Definition Fitter.h:526
const ROOT::Math::IBaseFunctionMultiDimTempl< double > * ObjFunction() const
Return pointer to the used objective function for fitting.
Definition Fitter.h:544
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.
Definition Fitter.h:157
std::shared_ptr< ROOT::Math::Minimizer > fMinimizer
! pointer to used minimizer
Definition Fitter.h:570
bool DoWeightMinimization(std::unique_ptr< ObjFunc_t > f, const ROOT::Math::IMultiGenFunction *chifunc=nullptr)
Definition Fitter.cxx:845
bool LikelihoodFit(const Data &data, const Function &func, bool extended)
Likelihood fit given a data set (Binned or Un-binned) using any generic model function.
Definition Fitter.h:239
bool DoBinnedLikelihoodFit(bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
binned likelihood fit
Definition Fitter.cxx:360
int fFitType
type of fit (0 undefined, 1 least square, 2 likelihood, 3 binned likelihood)
Definition Fitter.h:558
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:455
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:572
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:444
ROOT::Math::IMultiGenFunction BaseFunc
Definition Fitter.h:95
FitConfig & Config()
access to the configuration (non const method)
Definition Fitter.h:427
bool fUseGradient
flag to indicate if using gradient or not
Definition Fitter.h:552
void SetNumberOfFitPoints(unsigned int npoints)
Set number of fit points when using an external FCN function This function can be called after Fit to...
Definition Fitter.h:472
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:554
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:339
bool IsBinFit() const
query if fit is binned.
Definition Fitter.h:433
bool LinearFit(const std::shared_ptr< BinData > &data)
Do a linear fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:254
std::shared_ptr< ROOT::Math::IMultiGenFunction > fObjFunction
! pointer to used objective function
Definition Fitter.h:574
void SetFitType(int type)
Set the type of fit when using an external FCN possible types are : 1 (least-square),...
Definition Fitter.h:481
virtual ~Fitter()
Destructor.
Definition Fitter.h:117
bool Fit(const std::shared_ptr< BinData > &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit.
Definition Fitter.h:165
const FitResult & Result() const
get fit result
Definition Fitter.h:394
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:422
void SetData(const std::shared_ptr< Data > &data)
Set the input data for the fit using a shared ptr (No Copying)
Definition Fitter.h:520
bool DoLeastSquareFit(const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
least square fit
Definition Fitter.cxx:309
ROOT::Math::IParamMultiFunction IModelFunction
Definition Fitter.h:81
ROOT::Math::IParamFunction IModel1DFunction
Definition Fitter.h:92
bool SetFCN(unsigned int npar, Function &fcn, const double *params=nullptr, unsigned int dataSize=0, int fitType=0)
Set a generic FCN function as a C++ callable object implementing double () (const double *) Note that...
Definition Fitter.h:656
bool LikelihoodFit(const BinData &data, bool extended=true, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Binned Likelihood fit copying the input data.
Definition Fitter.h:203
std::shared_ptr< IModelFunction_v > fFunc_v
! copy of the fitted function containing on output the fit result
Definition Fitter.h:564
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)
Binned Likelihood fit using a shared_ptr for NOT copying the input data.
Definition Fitter.h:212
std::shared_ptr< ROOT::Fit::FitResult > fResult
! pointer to the object containing the result of the fit
Definition Fitter.h:568
bool GetDataFromFCN()
internal functions to get data set and model function from FCN useful for fits done with customized F...
Definition Fitter.h:584
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:593
Fitter(const Fitter &)=delete
Copy constructor (disabled, class is not copyable)
bool DoUpdateMinimizerOptions(bool canDifferentMinim=true)
Definition Fitter.cxx:763
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:144
bool Fit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit an un-binned data set using the negative log-likelihood method.
Definition Fitter.h:188
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:530
FitConfig fConfig
fitter configuration (options and parameter settings)
Definition Fitter.h:562
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:566
bool SetFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=nullptr)
Set the objective function (FCN) using a FitMethodGradFunction interface.
bool LeastSquareFit(const BinData &data, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit a binned data set using a least square fit copying the input data.
Definition Fitter.h:172
bool FitFCN(const ROOT::Math::FitMethodGradFunction &fcn, const double *params=nullptr)
Fit using a FitMethodGradFunction interface.
bool Fit(const std::shared_ptr< UnBinData > &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Fit an un-binned data set using the negative log-likelihood method.
Definition Fitter.h:195
bool LikelihoodFit(const UnBinData &data, bool extended=false, const ROOT::EExecutionPolicy &executionPolicy=ROOT::EExecutionPolicy::kSequential)
Un-binned Likelihood fit copying the input data Default is NOT extended.
Definition Fitter.h:221
bool DoLinearFit()
linear least square fit
Definition Fitter.cxx:513
bool DoInitMinimizer()
Definition Fitter.cxx:692
int GetNCallsFromFCN()
Definition Fitter.cxx:870
Class describing the un-binned data sets (just x coordinates values) of any dimensions.
Definition UnBinData.h:46
FitMethodFunction class Interface for objective functions (like chi2 and likelihood used in the fit) ...
Documentation for the abstract class IBaseFunctionMultiDim.
Definition IFunction.h:61
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
Definition IFunction.h:168
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:119
Template class to wrap any C++ callable object implementing operator() (const double * x) in a multi-...
RooCmdArg Minimizer(const char *type, const char *alg=nullptr)
Namespace for new Math classes and functions.
BasicFitMethodFunction< ROOT::Math::IMultiGenFunction > FitMethodFunction
Definition Fitter.h:43
BasicFitMethodFunction< ROOT::Math::IMultiGradFunction > FitMethodGradFunction
Definition Fitter.h:44
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...