00001 // @(#)root/minuit:$Id: TLinearMinimizer.h 34753 2010-08-10 10:02:27Z moneta $ 00002 // Author: L. Moneta Wed Oct 25 16:28:55 2006 00003 00004 /********************************************************************** 00005 * * 00006 * Copyright (c) 2006 LCG ROOT Math Team, CERN/PH-SFT * 00007 * * 00008 * * 00009 **********************************************************************/ 00010 00011 // Header file for class TLinearMinimizer 00012 00013 #ifndef ROOT_TLinearMinimizer 00014 #define ROOT_TLinearMinimizer 00015 00016 #ifndef ROOT_Math_Minimizer 00017 #include "Math/Minimizer.h" 00018 #endif 00019 00020 #ifndef ROOT_Rtypes 00021 #include "Rtypes.h" 00022 #endif 00023 00024 #include <vector> 00025 00026 class TLinearFitter; 00027 00028 00029 00030 00031 /** 00032 TLinearMinimizer class: minimizer implementation based on TMinuit. 00033 */ 00034 class TLinearMinimizer : public ROOT::Math::Minimizer { 00035 00036 public: 00037 00038 /** 00039 Default constructor 00040 */ 00041 TLinearMinimizer (int type = 0); 00042 00043 /** 00044 Constructor from a char * (used by PM) 00045 */ 00046 TLinearMinimizer ( const char * type ); 00047 00048 /** 00049 Destructor (no operations) 00050 */ 00051 virtual ~TLinearMinimizer (); 00052 00053 private: 00054 // usually copying is non trivial, so we make this unaccessible 00055 00056 /** 00057 Copy constructor 00058 */ 00059 TLinearMinimizer(const TLinearMinimizer &); 00060 00061 /** 00062 Assignment operator 00063 */ 00064 TLinearMinimizer & operator = (const TLinearMinimizer & rhs); 00065 00066 public: 00067 00068 /// set the fit model function 00069 virtual void SetFunction(const ROOT::Math::IMultiGenFunction & func); 00070 00071 /// set the function to minimize 00072 virtual void SetFunction(const ROOT::Math::IMultiGradFunction & func); 00073 00074 /// set free variable (dummy impl. ) 00075 virtual bool SetVariable(unsigned int , const std::string & , double , double ) { return false; } 00076 00077 /// set fixed variable (override if minimizer supports them ) 00078 virtual bool SetFixedVariable(unsigned int /* ivar */, const std::string & /* name */, double /* val */); 00079 00080 /// method to perform the minimization 00081 virtual bool Minimize(); 00082 00083 /// return minimum function value 00084 virtual double MinValue() const { return fMinVal; } 00085 00086 /// return expected distance reached from the minimum 00087 virtual double Edm() const { return 0; } 00088 00089 /// return pointer to X values at the minimum 00090 virtual const double * X() const { return &fParams.front(); } 00091 00092 /// return pointer to gradient values at the minimum 00093 virtual const double * MinGradient() const { return 0; } // not available in Minuit2 00094 00095 /// number of function calls to reach the minimum 00096 virtual unsigned int NCalls() const { return 0; } 00097 00098 /// this is <= Function().NDim() which is the total 00099 /// number of variables (free+ constrained ones) 00100 virtual unsigned int NDim() const { return fDim; } 00101 00102 /// number of free variables (real dimension of the problem) 00103 /// this is <= Function().NDim() which is the total 00104 virtual unsigned int NFree() const { return fNFree; } 00105 00106 /// minimizer provides error and error matrix 00107 virtual bool ProvidesError() const { return true; } 00108 00109 /// return errors at the minimum 00110 virtual const double * Errors() const { return (fErrors.empty()) ? 0 : &fErrors.front(); } 00111 00112 /** return covariance matrices elements 00113 if the variable is fixed the matrix is zero 00114 The ordering of the variables is the same as in errors 00115 */ 00116 virtual double CovMatrix(unsigned int i, unsigned int j) const { 00117 return (fCovar.empty()) ? 0 : fCovar[i + fDim* j]; 00118 } 00119 00120 /// return covariance matrix status 00121 virtual int CovMatrixStatus() const { 00122 if (fCovar.size() == 0) return 0; 00123 return (fStatus ==0) ? 3 : 1; 00124 } 00125 00126 /// return reference to the objective function 00127 ///virtual const ROOT::Math::IGenFunction & Function() const; 00128 00129 00130 00131 00132 protected: 00133 00134 private: 00135 00136 bool fRobust; 00137 unsigned int fDim; 00138 unsigned int fNFree; 00139 double fMinVal; 00140 std::vector<double> fParams; 00141 std::vector<double> fErrors; 00142 std::vector<double> fCovar; 00143 00144 const ROOT::Math::IMultiGradFunction * fObjFunc; 00145 TLinearFitter * fFitter; 00146 00147 ClassDef(TLinearMinimizer,1) //Implementation of the Minimizer interface using TLinearFitter 00148 00149 }; 00150 00151 00152 00153 #endif /* ROOT_TLinearMinimizer */