Logo ROOT  
Reference Guide
TBackCompFitter.h
Go to the documentation of this file.
1 // @(#)root/hist:$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 #include "TVirtualFitter.h"
14 #include "Fit/BasicFCN.h"
15 #include "Fit/FitResult.h"
16 #include "Fit/Fitter.h"
17 #include "Math/IFunctionfwd.h"
18 #include <vector>
19 
20 /*
21  TVirtualFitter backward compatibility implementation using new ROOT::Fit::Fitter
22 */
23 
24 class TGraph;
25 class TFitResult;
26 
27 namespace ROOT {
28  namespace Fit {
29  class FitData;
30  }
31  namespace Math {
32  class Minimizer;
33  }
34 }
35 
36 
38 
39 public:
40 
41 
42 
44 
45  //TBackCompFitter(ROOT::Fit::Fitter & fitter, ROOT::Fit::FitData * );
46  TBackCompFitter( const std::shared_ptr<ROOT::Fit::Fitter> & fitter, const std::shared_ptr<ROOT::Fit::FitData> & data );
47 
48  virtual ~TBackCompFitter();
49 
50 public:
51 
52  enum EStatusBits {
53  kCanDeleteLast = BIT(9) // object can be deleted before creating a new one
54  };
55 
56  // inherited interface
57  virtual Double_t Chisquare(Int_t npar, Double_t *params) const;
58  virtual void Clear(Option_t *option="");
59  virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs);
60  virtual void FixParameter(Int_t ipar);
61 
62  virtual void GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95);
63  virtual void GetConfidenceIntervals(TObject *obj, Double_t cl=0.95);
64 
65  virtual Double_t *GetCovarianceMatrix() const;
66  virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const;
67  virtual Int_t GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const;
68  virtual Int_t GetNumberTotalParameters() const;
69  virtual Int_t GetNumberFreeParameters() const;
70 
71  virtual Double_t GetParError(Int_t ipar) const;
72  virtual Double_t GetParameter(Int_t ipar) const;
73  virtual Int_t GetParameter(Int_t ipar,char *name,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh) const;
74  virtual const char *GetParName(Int_t ipar) const;
75  virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const;
76  virtual Double_t GetSumLog(Int_t i);
77 
78  virtual Bool_t IsFixed(Int_t ipar) const ;
79 
80  virtual void PrintResults(Int_t level, Double_t amin) const;
81  virtual void ReleaseParameter(Int_t ipar);
82  virtual void SetFitMethod(const char *name);
83  virtual Int_t SetParameter(Int_t ipar,const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh);
84 
85  virtual void SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t) );
86  // for using interpreted function passed by the user
87  virtual void SetMethodCall(TMethodCall * m) { fMethodCall = m; }
88 
89  // get reference to Fit configuration (NOTE: it will be invalid when class is deleted)
90  ROOT::Fit::FitConfig & GetFitConfig() { return fFitter->Config(); }
91 
92  // get reference to Fit Result object (NOTE: it will be invalid when class is deleted)
93  const ROOT::Fit::FitResult & GetFitResult() const { return fFitter->Result(); }
94 
95  // get a copy of the Fit result returning directly a new TFitResult
96  TFitResult * GetTFitResult() const;
97 
98  // get reference to Fit Data object (NOTE: it will be invalid when class is deleted)
99  const ROOT::Fit::FitData & GetFitData() const { return *fFitData; }
100 
101  // return pointer to last used minimizer
103 
104  // return pointer to last used objective function
106 
107  // scan likelihood value of parameter and fill the given graph.
108  bool Scan(unsigned int ipar, TGraph * gr, double xmin = 0, double xmax = 0);
109 
110  // scan likelihood value for two parameters and fill the given graph.
111  // bool Scan2D(unsigned int ipar, unsigned int jpar, TGraph2D * gr,
112  // double xmin = 0, double xmax = 0, double ymin = 0, double ymax = 0);
113 
114  // create contour of two parameters around the minimum
115  // pass as option confidence level: default is a value of 0.683
116  bool Contour(unsigned int ipar, unsigned int jpar, TGraph * gr , double confLevel = 0.683);
117 
118  // set FCN using new interface
120 
121  // recreate minimizer and FCN for TMinuit fits and standard printout
122  void ReCreateMinimizer();
123 
124 
125 protected:
126 
127  bool ValidParameterIndex(int ipar) const;
128  void DoSetDimension();
129 
130 private:
131 
132  //ROOT::Fit::FitData * fFitData;
133  std::shared_ptr<ROOT::Fit::FitData> fFitData; //! data of the fit
134  std::shared_ptr<ROOT::Fit::Fitter> fFitter; //! pointer to fitter object
138  mutable std::vector<double> fCovar; // cached covariance matrix (NxN)
139 
140 
141 
142  ClassDef(TBackCompFitter,1) // Class providing backward compatibility for fitting by implementing the TVirtualFitter interface
143 
144 };
145 
146 
147 
148 #endif //ROOT_TBackCompFitter_H_
ROOT::Fit::FitData
Base class for all the fit data types: Stores the coordinates and the DataOptions.
Definition: FitData.h:66
m
auto * m
Definition: textangle.C:8
TVirtualFitter::fMethodCall
TMethodCall * fMethodCall
Definition: TVirtualFitter.h:45
n
const Int_t n
Definition: legend1.C:16
TGeant4Unit::eplus
static constexpr double eplus
Definition: TGeant4SystemOfUnits.h:170
HFit::Fit
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
TBackCompFitter::GetErrors
virtual Int_t GetErrors(Int_t ipar, Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const
Get fit errors.
Definition: TBackCompFitter.cxx:511
f
#define f(i)
Definition: RSha256.hxx:104
Option_t
const char Option_t
Definition: RtypesCore.h:66
TBackCompFitter::TBackCompFitter
TBackCompFitter()
Constructor needed by TVirtualFitter interface.
Definition: TBackCompFitter.cxx:77
TBackCompFitter::DoSetDimension
void DoSetDimension()
Private method to set dimension in objective function.
Definition: TBackCompFitter.cxx:754
BasicFCN.h
xmax
float xmax
Definition: THbookFile.cxx:95
TBackCompFitter::SetMethodCall
virtual void SetMethodCall(TMethodCall *m)
Definition: TBackCompFitter.h:87
TFitResult
Extends the ROOT::Fit::Result class with a TNamed inheritance providing easy possibility for I/O.
Definition: TFitResult.h:34
TBackCompFitter::ReCreateMinimizer
void ReCreateMinimizer()
Recreate a minimizer instance using the function and data set objective function in minimizers functi...
Definition: TBackCompFitter.cxx:688
IFunctionfwd.h
TBackCompFitter::GetConfidenceIntervals
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.
Definition: TBackCompFitter.cxx:333
Int_t
int Int_t
Definition: RtypesCore.h:45
TBackCompFitter::GetCovarianceMatrixElement
virtual Double_t GetCovarianceMatrixElement(Int_t i, Int_t j) const
Get error matrix element (return all zero if matrix is not available)
Definition: TBackCompFitter.cxx:498
TBackCompFitter::fFitData
std::shared_ptr< ROOT::Fit::FitData > fFitData
Definition: TBackCompFitter.h:133
x
Double_t x[n]
Definition: legend1.C:17
TBackCompFitter::GetFitConfig
ROOT::Fit::FitConfig & GetFitConfig()
Definition: TBackCompFitter.h:90
TBackCompFitter::fModelFunc
ROOT::Math::IParamMultiFunction * fModelFunc
Definition: TBackCompFitter.h:137
TVirtualFitter.h
Bool_t
bool Bool_t
Definition: RtypesCore.h:63
TVirtualFitter
Abstract Base Class for Fitting.
Definition: TVirtualFitter.h:29
TBackCompFitter::GetNumberFreeParameters
virtual Int_t GetNumberFreeParameters() const
Definition: TBackCompFitter.cxx:533
ROOT::Math::IParametricFunctionMultiDimTempl
IParamFunction interface (abstract class) describing multi-dimensional parameteric functions It is a ...
Definition: IParamFunction.h:105
TBackCompFitter
Backward compatible implementation of TVirtualFitter.
Definition: TBackCompFitter.h:37
TBackCompFitter::Scan
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...
Definition: TBackCompFitter.cxx:797
TBackCompFitter::GetParameter
virtual Double_t GetParameter(Int_t ipar) const
Parameter value.
Definition: TBackCompFitter.cxx:552
xmin
float xmin
Definition: THbookFile.cxx:95
TBackCompFitter::SetParameter
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 > ...
Definition: TBackCompFitter.cxx:663
TBackCompFitter::fCovar
std::vector< double > fCovar
Definition: TBackCompFitter.h:138
TBackCompFitter::kCanDeleteLast
@ kCanDeleteLast
Definition: TBackCompFitter.h:53
gr
TGraphErrors * gr
Definition: legend1.C:25
TBackCompFitter::Clear
virtual void Clear(Option_t *option="")
Clear resources for consecutive fits.
Definition: TBackCompFitter.cxx:129
TBackCompFitter::fFitter
std::shared_ptr< ROOT::Fit::Fitter > fFitter
data of the fit
Definition: TBackCompFitter.h:134
ROOT::Fit::FitResult
class containg the result of the fit and all the related information (fitted parameter values,...
Definition: FitResult.h:47
BIT
#define BIT(n)
Definition: Rtypes.h:85
TBackCompFitter::ValidParameterIndex
bool ValidParameterIndex(int ipar) const
Check if ipar is a valid parameter index.
Definition: TBackCompFitter.cxx:304
TBackCompFitter::GetParName
virtual const char * GetParName(Int_t ipar) const
Return name of parameter ipar.
Definition: TBackCompFitter.cxx:590
TBackCompFitter::GetStats
virtual Int_t GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const
Get fit statistical information.
Definition: TBackCompFitter.cxx:600
ROOT::Fit::FitConfig
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
Definition: FitConfig.h:47
TBackCompFitter::fObjFunc
ROOT::Math::IMultiGenFunction * fObjFunc
Definition: TBackCompFitter.h:136
RooFit::Minimizer
RooCmdArg Minimizer(const char *type, const char *alg=0)
Definition: RooGlobalFunc.cxx:214
TBackCompFitter::fMinimizer
ROOT::Math::Minimizer * fMinimizer
pointer to fitter object
Definition: TBackCompFitter.h:135
Fitter.h
TBackCompFitter::~TBackCompFitter
virtual ~TBackCompFitter()
Destructor - delete the managed objects.
Definition: TBackCompFitter.cxx:102
TBackCompFitter::PrintResults
virtual void PrintResults(Int_t level, Double_t amin) const
Print the fit result.
Definition: TBackCompFitter.cxx:632
Double_t
double Double_t
Definition: RtypesCore.h:59
TGraph
A TGraph is an object made of two arrays X and Y with npoints each.
Definition: TGraph.h:41
ROOT::Math::Minimizer
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
Definition: Minimizer.h:75
TBackCompFitter::GetParError
virtual Double_t GetParError(Int_t ipar) const
Parameter error.
Definition: TBackCompFitter.cxx:541
TBackCompFitter::ExecuteCommand
virtual Int_t ExecuteCommand(const char *command, Double_t *args, Int_t nargs)
Execute the command (Fortran Minuit compatible interface)
Definition: TBackCompFitter.cxx:136
TBackCompFitter::SetFCN
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...
Definition: TBackCompFitter.cxx:732
TObject
Mother of all ROOT objects.
Definition: TObject.h:37
ClassDef
#define ClassDef(name, id)
Definition: Rtypes.h:325
name
char name[80]
Definition: TGX11.cxx:110
TBackCompFitter::GetObjFunction
ROOT::Math::IMultiGenFunction * GetObjFunction() const
Return a pointer to the objective function (FCN) If fitting directly using TBackCompFitter the pointe...
Definition: TBackCompFitter.cxx:769
TBackCompFitter::GetFitData
const ROOT::Fit::FitData & GetFitData() const
Definition: TBackCompFitter.h:99
TBackCompFitter::IsFixed
virtual Bool_t IsFixed(Int_t ipar) const
Query if parameter ipar is fixed.
Definition: TBackCompFitter.cxx:621
TBackCompFitter::GetNumberTotalParameters
virtual Int_t GetNumberTotalParameters() const
Number of total parameters.
Definition: TBackCompFitter.cxx:530
TBackCompFitter::GetFitResult
const ROOT::Fit::FitResult & GetFitResult() const
Definition: TBackCompFitter.h:93
TMethodCall
Method or function calling interface.
Definition: TMethodCall.h:37
TBackCompFitter::GetMinimizer
ROOT::Math::Minimizer * GetMinimizer() const
Return a pointer to the minimizer.
Definition: TBackCompFitter.cxx:779
TBackCompFitter::GetTFitResult
TFitResult * GetTFitResult() const
Return a new copy of the TFitResult object which needs to be deleted later by the user.
Definition: TBackCompFitter.cxx:787
TBackCompFitter::Contour
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...
Definition: TBackCompFitter.cxx:852
FitResult.h
TBackCompFitter::FixParameter
virtual void FixParameter(Int_t ipar)
Fix the parameter.
Definition: TBackCompFitter.cxx:317
TBackCompFitter::SetObjFunction
virtual void SetObjFunction(ROOT::Math::IMultiGenFunction *f)
Set the objective function for fitting Needed if fitting directly using TBackCompFitter class The cla...
Definition: TBackCompFitter.cxx:746
ROOT::Math::IBaseFunctionMultiDimTempl
Documentation for the abstract class IBaseFunctionMultiDim.
Definition: IFunction.h:62
TBackCompFitter::GetSumLog
virtual Double_t GetSumLog(Int_t i)
Sum of log (un-needed)
Definition: TBackCompFitter.cxx:613
TBackCompFitter::Chisquare
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.
Definition: TBackCompFitter.cxx:112
TBackCompFitter::ReleaseParameter
virtual void ReleaseParameter(Int_t ipar)
Release a fit parameter.
Definition: TBackCompFitter.cxx:645
ROOT
VSD Structures.
Definition: StringConv.hxx:21
Math
Namespace for new Math classes and functions.
TObject::EStatusBits
EStatusBits
Definition: TObject.h:57
TBackCompFitter::SetFitMethod
virtual void SetFitMethod(const char *name)
Set fit method (chi2 or likelihood).
Definition: TBackCompFitter.cxx:654
TBackCompFitter::GetCovarianceMatrix
virtual Double_t * GetCovarianceMatrix() const
Get the error matrix in a pointer to a NxN array.
Definition: TBackCompFitter.cxx:467