ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
TBackCompFitter.h
Go to the documentation of this file.
1 // @(#)root/minuit2:$Id$
2 // Author: L. Moneta 08/2008
3 
4 /**********************************************************************
5  * *
6  * Copyright (c) 2008 ROOT Foundation, CERN/PH-SFT *
7  * *
8  **********************************************************************/
9 
10 #ifndef ROOT_TBackCompFitter_H_
11 #define ROOT_TBackCompFitter_H_
12 
13 #ifndef ROOT_TVirtualFitter
14 #include "TVirtualFitter.h"
15 #endif
16 
17 #include "Fit/BasicFCN.h"
18 #include "Fit/FitResult.h"
19 
20 #ifndef ROOT_Fit_Fitter
21 #include "Fit/Fitter.h"
22 #endif
23 
24 #ifndef ROOT_Fit_DataVector
25 #include "Fit/DataVector.h"
26 #endif
27 
28 #ifndef ROOT_Math_IFunctionfwd
29 #include "Math/IFunctionfwd.h"
30 #endif
31 
32 
33 
34 #include <vector>
35 
36 /*
37  TVirtualFitter backward compatibility implementation using new ROOT::Fit::Fitter
38 */
39 
40 class TGraph;
41 class TFitResult;
42 
43 namespace ROOT {
44  namespace Fit {
45  class FitData;
46  }
47  namespace Math {
48  class Minimizer;
49  }
50 }
51 
52 
54 
55 public:
56 
57 
58 
60 
61  //TBackCompFitter(ROOT::Fit::Fitter & fitter, ROOT::Fit::FitData * );
62  TBackCompFitter( const std::shared_ptr<ROOT::Fit::Fitter> & fitter, const std::shared_ptr<ROOT::Fit::FitData> & data );
63 
64  virtual ~TBackCompFitter();
65 
66 public:
67 
68  enum {
69  kCanDeleteLast = BIT(9) // object can be deleted before creating a new one
70  };
71 
72  // inherited interface
73  virtual Double_t Chisquare(Int_t npar, Double_t *params) const;
74  virtual void Clear(Option_t *option="");
75  virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs);
76  virtual void FixParameter(Int_t ipar);
77 
78  virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95);
79  virtual void GetConfidenceIntervals(TObject *obj, Double_t cl=0.95);
80 
81  virtual Double_t *GetCovarianceMatrix() const;
82  virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const;
83  virtual Int_t GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const;
84  virtual Int_t GetNumberTotalParameters() const;
85  virtual Int_t GetNumberFreeParameters() const;
86 
87  virtual Double_t GetParError(Int_t ipar) const;
88  virtual Double_t GetParameter(Int_t ipar) const;
89  virtual Int_t GetParameter(Int_t ipar,char *name,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh) const;
90  virtual const char *GetParName(Int_t ipar) const;
91  virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const;
92  virtual Double_t GetSumLog(Int_t i);
93 
94  virtual Bool_t IsFixed(Int_t ipar) const ;
95 
96  virtual void PrintResults(Int_t level, Double_t amin) const;
97  virtual void ReleaseParameter(Int_t ipar);
98  virtual void SetFitMethod(const char *name);
99  virtual Int_t SetParameter(Int_t ipar,const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh);
100 
101  virtual void SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t) );
102  // this for CINT (interactive functions)
103  virtual void SetFCN(void * );
104  // for using interpreted function passed by the user
105  virtual void SetMethodCall(TMethodCall * m) { fMethodCall = m; }
106 
107  // get reference to Fit configuration (NOTE: it will be invalid when class is deleted)
108  ROOT::Fit::FitConfig & GetFitConfig() { return fFitter->Config(); }
109 
110  // get reference to Fit Result object (NOTE: it will be invalid when class is deleted)
111  const ROOT::Fit::FitResult & GetFitResult() const { return fFitter->Result(); }
112 
113  // get a copy of the Fit result returning directly a new TFitResult
114  TFitResult * GetTFitResult() const;
115 
116  // get reference to Fit Data object (NOTE: it will be invalid when class is deleted)
117  const ROOT::Fit::FitData & GetFitData() const { return *fFitData; }
118 
119  // return pointer to last used minimizer
121 
122  // return pointer to last used objective function
124 
125  // scan likelihood value of parameter and fill the given graph.
126  bool Scan(unsigned int ipar, TGraph * gr, double xmin = 0, double xmax = 0);
127 
128  // scan likelihood value for two parameters and fill the given graph.
129  // bool Scan2D(unsigned int ipar, unsigned int jpar, TGraph2D * gr,
130  // double xmin = 0, double xmax = 0, double ymin = 0, double ymax = 0);
131 
132  // create contour of two parameters around the minimum
133  // pass as option confidence level: default is a value of 0.683
134  bool Contour(unsigned int ipar, unsigned int jpar, TGraph * gr , double confLevel = 0.683);
135 
136  // set FCN using new interface
138 
139  // recreate minimizer and FCN for TMinuit fits and standard printout
140  void ReCreateMinimizer();
141 
142 
143 protected:
144 
145  bool ValidParameterIndex(int ipar) const;
146  void DoSetDimension();
147 
148 private:
149 
150  //ROOT::Fit::FitData * fFitData;
151  std::shared_ptr<ROOT::Fit::FitData> fFitData; //! data of the fit
152  std::shared_ptr<ROOT::Fit::Fitter> fFitter; //! pointer to fitter object
156  mutable std::vector<double> fCovar; // cached covariance matrix (NxN)
157 
158 
159 
160  ClassDef(TBackCompFitter,1) // Class providing backward compatibility for fitting by implementing the TVirtualFitter interface
161 
162 };
163 
164 
165 
166 #endif //ROOT_TBackCompFitter_H_
void DoSetDimension()
Private method to set dimension in objective function.
virtual Bool_t IsFixed(Int_t ipar) const
Query if parameter ipar is fixed.
float xmin
Definition: THbookFile.cxx:93
virtual Int_t GetNumberFreeParameters() const
bool ValidParameterIndex(int ipar) const
Check if ipar is a valid parameter index.
void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
Definition: Ifit.C:26
const ROOT::Fit::FitResult & GetFitResult() const
virtual void Clear(Option_t *option="")
Clear resources for consecutive fits.
bool Contour(unsigned int ipar, unsigned int jpar, TGraph *gr, double confLevel=0.683)
Create a 2D contour around the minimum for the parameter ipar and jpar if a minimum does not exist or...
virtual Int_t GetNumberTotalParameters() const
Number of total parameters.
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute the command (Fortran Minuit compatible interface)
virtual void SetMethodCall(TMethodCall *m)
const char Option_t
Definition: RtypesCore.h:62
bool Scan(unsigned int ipar, TGraph *gr, double xmin=0, double xmax=0)
Scan parameter ipar between value of xmin and xmax A graph must be given which will be on return fill...
#define BIT(n)
Definition: Rtypes.h:120
Base class for all the fit data types.
Definition: DataVector.h:67
ROOT::Math::Minimizer * fMinimizer
pointer to fitter object
virtual const char * GetParName(Int_t ipar) const
Return name of parameter ipar.
void ReCreateMinimizer()
Recreate a minimizer instance using the function and data set objective function in minimizers functi...
virtual Double_t GetParError(Int_t ipar) const
Parameter error.
virtual void SetFCN(void(*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t))
Override setFCN to use the Adapter to Minuit2 FCN interface To set the address of the minimization fu...
Backward compatible implementation of TVirtualFitter.
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
virtual Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const
Get fit errors.
TFile * f
Double_t x[n]
Definition: legend1.C:17
#define ClassDef(name, id)
Definition: Rtypes.h:254
TBackCompFitter()
Constructor needed by TVirtualFitter interface.
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O...
Definition: TFitResult.h:36
virtual ~TBackCompFitter()
Destructor - delete the managed objects.
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2, Minuit, GSL, etc..) Plug-in's exist in ROOT to be able to instantiate the derived classes like ROOT::Math::GSLMinimizer or ROOT::Math::Minuit2Minimizer via the plug-in manager.
Definition: Minimizer.h:86
Method or function calling interface.
Definition: TMethodCall.h:41
virtual void FixParameter(Int_t ipar)
Fix the parameter.
virtual void SetObjFunction(ROOT::Math::IMultiGenFunction *f)
Set the objective function for fitting Needed if fitting directly using TBackCompFitter class The cla...
virtual Double_t GetParameter(Int_t ipar) const
Parameter value.
ROOT::Math::IMultiGenFunction * fObjFunc
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
RooCmdArg Minimizer(const char *type, const char *alg=0)
TMarker * m
Definition: textangle.C:8
ROOT::Math::Minimizer * GetMinimizer() const
Return a pointer to the minimizer.
virtual Double_t GetSumLog(Int_t i)
Sum of log (un-needed)
virtual Double_t * GetCovarianceMatrix() const
Get the error matrix in a pointer to a NxN array.
float xmax
Definition: THbookFile.cxx:93
TGraphErrors * gr
Definition: legend1.C:25
virtual void PrintResults(Int_t level, Double_t amin) const
Print the fit result.
virtual void ReleaseParameter(Int_t ipar)
Release a fit parameter.
class containg the result of the fit and all the related information (fitted parameter values...
Definition: FitResult.h:52
virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const
Get error matrix element (return all zero if matrix is not available)
std::shared_ptr< ROOT::Fit::FitData > fFitData
double Double_t
Definition: RtypesCore.h:55
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
TFitResult * GetTFitResult() const
Return a new copy of the TFitResult object which needs to be deleted later by the user...
const ROOT::Fit::FitData & GetFitData() const
#define name(a, b)
Definition: linkTestLib0.cpp:5
Abstract Base Class for Fitting.
Mother of all ROOT objects.
Definition: TObject.h:58
std::vector< double > fCovar
A Graph is a graphics object made of two arrays X and Y with npoints each.
Definition: TGraph.h:53
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
Get fit statistical information.
virtual Int_t SetParameter(Int_t ipar, const char *parname, Double_t value, Double_t verr, Double_t vlow, Double_t vhigh)
Set (add) a new fit parameter passing initial value, step size (verr) and parameter limits if vlow > ...
std::shared_ptr< ROOT::Fit::Fitter > fFitter
data of the fit
ROOT::Math::IMultiGenFunction * GetObjFunction() const
Return a pointer to the objective function (FCN) If fitting directly using TBackCompFitter the pointe...
virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95)
Computes point-by-point confidence intervals for the fitted function.
virtual Double_t Chisquare(Int_t npar, Double_t *params) const
Do chisquare calculations in case of likelihood fits Do evaluation a the minimum only.
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:63
TObject * obj
float value
Definition: math.cpp:443
virtual void SetFitMethod(const char *name)
Set fit method (chi2 or likelihood).
const Int_t n
Definition: legend1.C:16
ROOT::Math::IParamMultiFunction * fModelFunc
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition: FitConfig.h:51
TMethodCall * fMethodCall
ROOT::Fit::FitConfig & GetFitConfig()