00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef ROOT_Math_GSLFunctionWrapper
00032 #define ROOT_Math_GSLFunctionWrapper
00033
00034 #include "gsl/gsl_math.h"
00035
00036 #include "Math/GSLFunctionAdapter.h"
00037
00038 #include <cassert>
00039
00040 namespace ROOT {
00041 namespace Math {
00042
00043
00044
00045 typedef double ( * GSLFuncPointer ) ( double, void *);
00046 typedef void ( * GSLFdfPointer ) ( double, void *, double *, double *);
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 class GSLFunctionWrapper {
00058
00059 public:
00060
00061 GSLFunctionWrapper()
00062 {
00063 fFunc.function = 0;
00064 fFunc.params = 0;
00065 }
00066
00067
00068 void SetFuncPointer( GSLFuncPointer f) { fFunc.function = f; }
00069
00070
00071 void SetParams ( void * p) { fFunc.params = p; }
00072
00073
00074
00075 template<class FuncType>
00076 void SetFunction(const FuncType &f) {
00077 const void * p = &f;
00078 assert (p != 0);
00079 SetFuncPointer(&GSLFunctionAdapter<FuncType >::F);
00080 SetParams(const_cast<void *>(p));
00081 }
00082
00083 gsl_function * GetFunc() { return &fFunc; }
00084
00085 GSLFuncPointer FunctionPtr() { return fFunc.function; }
00086
00087
00088 double operator() (double x) { return GSL_FN_EVAL(&fFunc, x); }
00089
00090
00091 bool IsValid() {
00092 return (fFunc.function != 0) ? true : false;
00093 }
00094
00095 private:
00096 gsl_function fFunc;
00097
00098
00099 };
00100
00101
00102
00103
00104
00105 class GSLFunctionDerivWrapper {
00106
00107 public:
00108
00109 GSLFunctionDerivWrapper()
00110 {
00111 fFunc.f = 0;
00112 fFunc.df = 0;
00113 fFunc.fdf = 0;
00114 fFunc.params = 0;
00115 }
00116
00117
00118 void SetFuncPointer( GSLFuncPointer f) { fFunc.f = f; }
00119 void SetDerivPointer( GSLFuncPointer f) { fFunc.df = f; }
00120 void SetFdfPointer( GSLFdfPointer f) { fFunc.fdf = f; }
00121 void SetParams ( void * p) { fFunc.params = p; }
00122
00123
00124 gsl_function_fdf * GetFunc() { return &fFunc; }
00125
00126
00127 double operator() (double x) { return GSL_FN_FDF_EVAL_F(&fFunc, x); }
00128
00129 double Derivative (double x) { return GSL_FN_FDF_EVAL_DF(&fFunc, x); }
00130
00131 void Fdf(double x, double & f, double & df) {
00132 return GSL_FN_FDF_EVAL_F_DF(&fFunc, x, &f, &df);
00133 }
00134
00135
00136 bool IsValid() {
00137 return (fFunc.f != 0 ) ? true : false;
00138 }
00139
00140 private:
00141 gsl_function_fdf fFunc;
00142
00143 };
00144
00145
00146
00147 }
00148 }
00149
00150 #endif