Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
37 class TBackCompFitter : public TVirtualFitter {
38 
39 public:
40 
41 
42 
43  TBackCompFitter();
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
102  ROOT::Math::Minimizer * GetMinimizer() const;
103 
104  // return pointer to last used objective function
105  ROOT::Math::IMultiGenFunction * GetObjFunction() const;
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
119  virtual void SetObjFunction( ROOT::Math::IMultiGenFunction * f);
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
135  ROOT::Math::Minimizer * fMinimizer;
136  ROOT::Math::IMultiGenFunction * fObjFunc;
137  ROOT::Math::IParamMultiFunction * fModelFunc;
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_