#ifndef ROOT_Math_GSLNLSMinimizer
#define ROOT_Math_GSLNLSMinimizer
#ifndef ROOT_Math_Minimizer
#include "Math/Minimizer.h"
#endif
#ifndef ROOT_Math_IFunctionfwd
#include "Math/IFunctionfwd.h"
#endif
#ifndef ROOT_Math_IParamFunctionfwd
#include "Math/IParamFunctionfwd.h"
#endif
#include "Math/FitMethodFunction.h"
namespace ROOT { 
   namespace Math { 
      class GSLMultiFit; 
class LSResidualFunc : public IMultiGradFunction { 
public: 
   
   LSResidualFunc() : fIndex(0), fChi2(0)
   {}
   LSResidualFunc(const ROOT::Math::FitMethodFunction & func, unsigned int i) : 
      fIndex(i), 
      fChi2(&func), 
      fX2(std::vector<double>(func.NDim() ) )
   {}
   
   LSResidualFunc(const LSResidualFunc & rhs) :
      IMultiGenFunction(), 
      IMultiGradFunction() 
   { 
      operator=(rhs);
   } 
   
   LSResidualFunc & operator= (const LSResidualFunc & rhs) 
   { 
      fIndex = rhs.fIndex;
      fChi2 = rhs.fChi2; 
      fX2 = rhs.fX2;
      return *this;
   } 
   IMultiGenFunction * Clone() const { 
      return new LSResidualFunc(*fChi2,fIndex); 
   }
   unsigned int NDim() const { return fChi2->NDim(); }
   void Gradient( const double * x, double * g) const { 
      unsigned int n = NDim(); 
      std::copy(x,x+n,fX2.begin());
      const double kEps = 1.0E-4;
      double f0 = DoEval(x); 
      for (unsigned int i = 0; i < n; ++i) { 
         fX2[i] += kEps;
         g[i] =  ( DoEval(&fX2.front()) - f0 )/kEps;
         fX2[i] = x[i];
      }
   } 
private: 
   double DoEval (const double * x) const { 
      return fChi2->DataElement(x, fIndex);
   }
   
   double DoDerivative(const double * x, unsigned int icoord) const { 
      
      std::copy(x,x+NDim(),fX2.begin());
      const double kEps = 1.0E-4;
      fX2[icoord] += kEps;
      return ( DoEval(&fX2.front()) - DoEval(x) )/kEps;
   }
   unsigned int fIndex; 
   const ROOT::Math::FitMethodFunction * fChi2; 
   mutable std::vector<double> fX2;  
};
 
class GSLNLSMinimizer : public  ROOT::Math::Minimizer {
public: 
    
   GSLNLSMinimizer (int type = 0); 
    
   ~GSLNLSMinimizer ();  
private:
   
    
   GSLNLSMinimizer(const GSLNLSMinimizer &) : ROOT::Math::Minimizer() {} 
    
   GSLNLSMinimizer & operator = (const GSLNLSMinimizer & rhs)  {
      if (this == &rhs) return *this;  
      return *this;
   }
public: 
   
   virtual void SetFunction(const Minimizer::IObjFunction & func); 
   
   virtual void SetFunction(const Minimizer::IGradObjFunction & func); 
   
   virtual bool SetVariable(unsigned int ivar, const std::string & name, double val, double step); 
#ifdef LATER
   
   virtual bool SetLowerLimitedVariable(unsigned int  ivar , const std::string & name , double val , double step , double lower );
   
   virtual bool SetUpperLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double upper ); 
   
   virtual bool SetLimitedVariable(unsigned int ivar , const std::string & name , double val , double step , double , double ); 
   
   virtual bool SetFixedVariable(unsigned int , const std::string & , double );  
#endif
   
   virtual  bool Minimize(); 
   
   virtual double MinValue() const { return fMinVal; } 
   
   virtual double Edm() const { return 0; } 
   
   virtual const double *  X() const { return &fValues.front(); } 
   
   virtual const double *  MinGradient() const; 
   
   virtual unsigned int NCalls() const { return 0; } 
   
   
   virtual unsigned int NDim() const { return fDim; }   
   
   
   virtual unsigned int NFree() const { return fDim; }  
   
   virtual bool ProvidesError() const { return true; } 
   
   virtual const double * Errors() const { 
      static std::vector<double> err; 
      err.resize(fDim);
      return &err.front(); 
   }
    
   virtual double CovMatrix(unsigned int , unsigned int ) const { return 0; }
   
   virtual bool GetMinosError(unsigned int , double &  , double &  ) { return false; }
   
   
protected: 
private: 
   
   
   unsigned int fDim; 
   
   unsigned int fSize; 
   ROOT::Math::GSLMultiFit * fGSLMultiFit;        
   const Minimizer::IObjFunction * fObjFunc;      
   
   double fMinVal;                                
   double fLSTolerance;                           
   mutable std::vector<double> fValues;           
   
   std::vector<double> fSteps;
   std::vector<std::string> fNames;
   std::vector<LSResidualFunc> fResiduals;   
}; 
   } 
} 
#endif /* ROOT_Math_GSLNLSMinimizer */
Last update: Thu Jan 17 08:41:33 2008
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.