ROOT logo
// @(#)root/minuit2:$Id: TBackCompFitter.h 35643 2010-09-23 12:48:32Z moneta $
// Author: L. Moneta    08/2008  

/**********************************************************************
 *                                                                    *
 * Copyright (c) 2008 ROOT Foundation,  CERN/PH-SFT                   *
 *                                                                    *
 **********************************************************************/

#ifndef ROOT_TBackCompFitter_H_
#define ROOT_TBackCompFitter_H_

#ifndef ROOT_TVirtualFitter
#include "TVirtualFitter.h"
#endif

#ifndef ROOT_Fit_Fitter
#include "Fit/Fitter.h"
#endif

#ifndef ROOT_Fit_DataVector
#include "Fit/DataVector.h"
#endif

#ifndef ROOT_Math_IFunctionfwd
#include "Math/IFunctionfwd.h"
#endif



#include <vector>

/**
    TVirtualFitter backward compatibility implementation using new ROOT::Fit::Fitter
*/

class TGraph; 
class TFitResult; 

namespace ROOT { 
   namespace Fit { 
      class FitData; 
   }
   namespace Math { 
      class Minimizer; 
   }
}


class TBackCompFitter : public TVirtualFitter {

public:



   TBackCompFitter();

   //TBackCompFitter(ROOT::Fit::Fitter & fitter, ROOT::Fit::FitData * ); 
   TBackCompFitter( std::auto_ptr<ROOT::Fit::Fitter>  fitter, std::auto_ptr<ROOT::Fit::FitData> data  ); 

   virtual ~TBackCompFitter();

public:

   enum { 
      kCanDeleteLast = BIT(9)  // object can be deleted before creating a new one
   };

   // inherited interface
   virtual Double_t  Chisquare(Int_t npar, Double_t *params) const;
   virtual void      Clear(Option_t *option="");
   virtual Int_t     ExecuteCommand(const char *command, Double_t *args, Int_t nargs);
   virtual void      FixParameter(Int_t ipar);

   virtual void      GetConfidenceIntervals(Int_t n, Int_t ndim, const Double_t *x, Double_t *ci, Double_t cl=0.95);
   virtual void      GetConfidenceIntervals(TObject *obj, Double_t cl=0.95);

   virtual Double_t *GetCovarianceMatrix() const;
   virtual Double_t  GetCovarianceMatrixElement(Int_t i, Int_t j) const;
   virtual Int_t     GetErrors(Int_t ipar,Double_t &eplus, Double_t &eminus, Double_t &eparab, Double_t &globcc) const;
   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
   virtual Int_t     GetNumberTotalParameters() const;
   virtual Int_t     GetNumberFreeParameters() const;

   virtual Double_t  GetParError(Int_t ipar) const;
   virtual Double_t  GetParameter(Int_t ipar) const;
   virtual Int_t     GetParameter(Int_t ipar,char *name,Double_t &value,Double_t &verr,Double_t &vlow, Double_t &vhigh) const;
   virtual const char *GetParName(Int_t ipar) const;
   virtual Int_t     GetStats(Double_t &amin, Double_t &edm, Double_t &errdef, Int_t &nvpar, Int_t &nparx) const;
   virtual Double_t  GetSumLog(Int_t i);

   //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
   virtual Bool_t    IsFixed(Int_t ipar) const ;

   virtual void      PrintResults(Int_t level, Double_t amin) const;
   virtual void      ReleaseParameter(Int_t ipar);
   virtual void      SetFitMethod(const char *name);
   virtual Int_t     SetParameter(Int_t ipar,const char *parname,Double_t value,Double_t verr,Double_t vlow, Double_t vhigh);

   virtual void      SetFCN(void (*fcn)(Int_t &, Double_t *, Double_t &f, Double_t *, Int_t) );
   // this for CINT (interactive functions)
   virtual void      SetFCN(void * );
   // for using interpreted function passed by the user
   virtual void SetMethodCall(TMethodCall * m) { fMethodCall = m; }

   ///!!!! new method (of this interface) 


   // get reference to Fit configuration (NOTE: it will be invalid when class is deleted) 
   ROOT::Fit::FitConfig & GetFitConfig()  { return fFitter->Config(); }

   // get reference to Fit Result object (NOTE: it will be invalid when class is deleted) 
   const ROOT::Fit::FitResult & GetFitResult() const { return fFitter->Result(); }

   // get a copy of the Fit result returning directly a new  TFitResult 
   TFitResult * GetTFitResult() const; 

   // get reference to Fit Data object (NOTE: it will be invalid when class is deleted) 
   const ROOT::Fit::FitData & GetFitData() const { return *fFitData; }

   // return pointer to last used minimizer
   ROOT::Math::Minimizer * GetMinimizer() const; 

   // return pointer to last used objective function
   ROOT::Math::IMultiGenFunction * GetObjFunction() const; 
   
   // scan likelihood value of  parameter and fill the given graph. 
   bool  Scan(unsigned int ipar, TGraph * gr, double xmin = 0, double xmax = 0);

//    // scan likelihood value for two  parameters and fill the given graph. 
//    bool  Scan2D(unsigned int ipar, unsigned int jpar, TGraph2D * gr, 
//                         double xmin = 0, double xmax = 0, double ymin = 0, double ymax = 0);

   // create contour of two parameters around the minimum
   // pass as option confidence level:  default is a value of 0.683 
   bool  Contour(unsigned int ipar, unsigned int jpar, TGraph * gr , double confLevel = 0.683); 
   
   // set FCN using new interface
   virtual void SetObjFunction(  ROOT::Math::IMultiGenFunction * f);

   // recreate minimizer and FCN for TMinuit fits and standard printout 
   void ReCreateMinimizer();
   

protected: 

   // internal methods

   bool ValidParameterIndex(int ipar) const;
  
   void DoSetDimension(); 
   
   
private:


   //ROOT::Fit::FitData * fFitData;          
   std::auto_ptr<ROOT::Fit::FitData>  fFitData;  //! data of the fit (managed by TBackCompFitter)
   std::auto_ptr<ROOT::Fit::Fitter>   fFitter;   //! pointer to fitter object (managed by TBackCompFitter)
   ROOT::Math::Minimizer * fMinimizer;
   ROOT::Math::IMultiGenFunction * fObjFunc; 
   ROOT::Math::IParamMultiFunction * fModelFunc; 
   mutable std::vector<double> fCovar; // cached covariance matrix (NxN)



   ClassDef(TBackCompFitter,1)  // Class providing backward compatibility for fitting by implementing the TVirtualFitter interface

};



#endif //ROOT_TBackCompFitter_H_
 TBackCompFitter.h:1
 TBackCompFitter.h:2
 TBackCompFitter.h:3
 TBackCompFitter.h:4
 TBackCompFitter.h:5
 TBackCompFitter.h:6
 TBackCompFitter.h:7
 TBackCompFitter.h:8
 TBackCompFitter.h:9
 TBackCompFitter.h:10
 TBackCompFitter.h:11
 TBackCompFitter.h:12
 TBackCompFitter.h:13
 TBackCompFitter.h:14
 TBackCompFitter.h:15
 TBackCompFitter.h:16
 TBackCompFitter.h:17
 TBackCompFitter.h:18
 TBackCompFitter.h:19
 TBackCompFitter.h:20
 TBackCompFitter.h:21
 TBackCompFitter.h:22
 TBackCompFitter.h:23
 TBackCompFitter.h:24
 TBackCompFitter.h:25
 TBackCompFitter.h:26
 TBackCompFitter.h:27
 TBackCompFitter.h:28
 TBackCompFitter.h:29
 TBackCompFitter.h:30
 TBackCompFitter.h:31
 TBackCompFitter.h:32
 TBackCompFitter.h:33
 TBackCompFitter.h:34
 TBackCompFitter.h:35
 TBackCompFitter.h:36
 TBackCompFitter.h:37
 TBackCompFitter.h:38
 TBackCompFitter.h:39
 TBackCompFitter.h:40
 TBackCompFitter.h:41
 TBackCompFitter.h:42
 TBackCompFitter.h:43
 TBackCompFitter.h:44
 TBackCompFitter.h:45
 TBackCompFitter.h:46
 TBackCompFitter.h:47
 TBackCompFitter.h:48
 TBackCompFitter.h:49
 TBackCompFitter.h:50
 TBackCompFitter.h:51
 TBackCompFitter.h:52
 TBackCompFitter.h:53
 TBackCompFitter.h:54
 TBackCompFitter.h:55
 TBackCompFitter.h:56
 TBackCompFitter.h:57
 TBackCompFitter.h:58
 TBackCompFitter.h:59
 TBackCompFitter.h:60
 TBackCompFitter.h:61
 TBackCompFitter.h:62
 TBackCompFitter.h:63
 TBackCompFitter.h:64
 TBackCompFitter.h:65
 TBackCompFitter.h:66
 TBackCompFitter.h:67
 TBackCompFitter.h:68
 TBackCompFitter.h:69
 TBackCompFitter.h:70
 TBackCompFitter.h:71
 TBackCompFitter.h:72
 TBackCompFitter.h:73
 TBackCompFitter.h:74
 TBackCompFitter.h:75
 TBackCompFitter.h:76
 TBackCompFitter.h:77
 TBackCompFitter.h:78
 TBackCompFitter.h:79
 TBackCompFitter.h:80
 TBackCompFitter.h:81
 TBackCompFitter.h:82
 TBackCompFitter.h:83
 TBackCompFitter.h:84
 TBackCompFitter.h:85
 TBackCompFitter.h:86
 TBackCompFitter.h:87
 TBackCompFitter.h:88
 TBackCompFitter.h:89
 TBackCompFitter.h:90
 TBackCompFitter.h:91
 TBackCompFitter.h:92
 TBackCompFitter.h:93
 TBackCompFitter.h:94
 TBackCompFitter.h:95
 TBackCompFitter.h:96
 TBackCompFitter.h:97
 TBackCompFitter.h:98
 TBackCompFitter.h:99
 TBackCompFitter.h:100
 TBackCompFitter.h:101
 TBackCompFitter.h:102
 TBackCompFitter.h:103
 TBackCompFitter.h:104
 TBackCompFitter.h:105
 TBackCompFitter.h:106
 TBackCompFitter.h:107
 TBackCompFitter.h:108
 TBackCompFitter.h:109
 TBackCompFitter.h:110
 TBackCompFitter.h:111
 TBackCompFitter.h:112
 TBackCompFitter.h:113
 TBackCompFitter.h:114
 TBackCompFitter.h:115
 TBackCompFitter.h:116
 TBackCompFitter.h:117
 TBackCompFitter.h:118
 TBackCompFitter.h:119
 TBackCompFitter.h:120
 TBackCompFitter.h:121
 TBackCompFitter.h:122
 TBackCompFitter.h:123
 TBackCompFitter.h:124
 TBackCompFitter.h:125
 TBackCompFitter.h:126
 TBackCompFitter.h:127
 TBackCompFitter.h:128
 TBackCompFitter.h:129
 TBackCompFitter.h:130
 TBackCompFitter.h:131
 TBackCompFitter.h:132
 TBackCompFitter.h:133
 TBackCompFitter.h:134
 TBackCompFitter.h:135
 TBackCompFitter.h:136
 TBackCompFitter.h:137
 TBackCompFitter.h:138
 TBackCompFitter.h:139
 TBackCompFitter.h:140
 TBackCompFitter.h:141
 TBackCompFitter.h:142
 TBackCompFitter.h:143
 TBackCompFitter.h:144
 TBackCompFitter.h:145
 TBackCompFitter.h:146
 TBackCompFitter.h:147
 TBackCompFitter.h:148
 TBackCompFitter.h:149
 TBackCompFitter.h:150
 TBackCompFitter.h:151
 TBackCompFitter.h:152
 TBackCompFitter.h:153
 TBackCompFitter.h:154
 TBackCompFitter.h:155
 TBackCompFitter.h:156
 TBackCompFitter.h:157
 TBackCompFitter.h:158
 TBackCompFitter.h:159
 TBackCompFitter.h:160
 TBackCompFitter.h:161
 TBackCompFitter.h:162
 TBackCompFitter.h:163
 TBackCompFitter.h:164
 TBackCompFitter.h:165
 TBackCompFitter.h:166
 TBackCompFitter.h:167
 TBackCompFitter.h:168
 TBackCompFitter.h:169
 TBackCompFitter.h:170
 TBackCompFitter.h:171
 TBackCompFitter.h:172
 TBackCompFitter.h:173