00001 // Author: Wim Lavrijsen November 2010 00002 00003 #ifndef ROOT_TPyFitFunction 00004 #define ROOT_TPyFitFunction 00005 00006 ////////////////////////////////////////////////////////////////////////////// 00007 // // 00008 // TPyFitFunction // 00009 // // 00010 // Python base class to work with Math::IMultiGenFunction // 00011 // // 00012 ////////////////////////////////////////////////////////////////////////////// 00013 00014 00015 //- ROOT 00016 #ifndef ROOT_Math_IFunction 00017 #include "Math/IFunction.h" 00018 #endif 00019 00020 // Python 00021 struct _object; 00022 typedef _object PyObject; 00023 00024 00025 class TPyMultiGenFunction : public ROOT::Math::IMultiGenFunction { 00026 public: 00027 // ctor/dtor, and assignment 00028 TPyMultiGenFunction( PyObject* self = 0 ); 00029 virtual ~TPyMultiGenFunction(); 00030 00031 // Math::IMultiGenFunction implementation 00032 virtual ROOT::Math::IBaseFunctionMultiDim* Clone() const 00033 { return new TPyMultiGenFunction( fPySelf ); } 00034 virtual unsigned int NDim() const; 00035 virtual double DoEval( const double* x ) const; 00036 00037 ClassDef( TPyMultiGenFunction, 1 ); //Python for Math::IMultiGenFunction equivalent 00038 00039 private: 00040 // to prevent confusion when handing 'self' from python 00041 TPyMultiGenFunction( const TPyMultiGenFunction& src ) : ROOT::Math::IMultiGenFunction( src ) {} 00042 TPyMultiGenFunction& operator=( const TPyMultiGenFunction& ) { return *this; } 00043 00044 private: 00045 PyObject* fPySelf; //! actual python object 00046 }; 00047 00048 00049 class TPyMultiGradFunction : public ROOT::Math::IMultiGradFunction { 00050 public: 00051 // ctor/dtor, and assignment 00052 TPyMultiGradFunction( PyObject* self = 0 ); 00053 virtual ~TPyMultiGradFunction(); 00054 00055 // Math::IMultiGenFunction implementation 00056 virtual ROOT::Math::IBaseFunctionMultiDim* Clone() const 00057 { return new TPyMultiGradFunction( fPySelf ); } 00058 virtual unsigned int NDim() const; 00059 virtual double DoEval( const double* x ) const; 00060 00061 virtual void Gradient( const double* x, double* grad ) const; 00062 virtual void FdF( const double* x, double& f, double* df ) const; 00063 virtual double DoDerivative( const double * x, unsigned int icoord ) const; 00064 00065 ClassDef( TPyMultiGradFunction, 1 ); //Python for Math::IMultiGradFunction equivalent 00066 00067 private: 00068 // to prevent confusion when handing 'self' from python 00069 TPyMultiGradFunction( const TPyMultiGradFunction& src ) : 00070 ROOT::Math::IMultiGenFunction( src ), ROOT::Math::IMultiGradFunction( src ) {} 00071 TPyMultiGradFunction& operator=( const TPyMultiGradFunction& ) { return *this; } 00072 00073 private: 00074 PyObject* fPySelf; //! actual python object 00075 }; 00076 00077 #endif