31 #ifndef ROOT_Math_GSLFunctionWrapper
32 #define ROOT_Math_GSLFunctionWrapper
34 #include "gsl/gsl_math.h"
45 typedef double ( * GSLFuncPointer ) ( double,
void *);
46 typedef void ( * GSLFdfPointer ) ( double,
void *,
double *,
double *);
57 class GSLFunctionWrapper {
68 void SetFuncPointer( GSLFuncPointer f) { fFunc.function = f; }
71 void SetParams (
void * p) { fFunc.params = p; }
75 template<
class FuncType>
76 void SetFunction(
const FuncType &f) {
79 SetFuncPointer(&GSLFunctionAdapter<FuncType >::F);
80 SetParams(const_cast<void *>(p));
83 gsl_function * GetFunc() {
return &fFunc; }
85 GSLFuncPointer FunctionPtr() {
return fFunc.function; }
88 double operator() (
double x) {
return GSL_FN_EVAL(&fFunc, x); }
92 return (fFunc.function != 0) ?
true :
false;
105 class GSLFunctionDerivWrapper {
109 GSLFunctionDerivWrapper()
118 void SetFuncPointer( GSLFuncPointer f) { fFunc.f = f; }
119 void SetDerivPointer( GSLFuncPointer f) { fFunc.df = f; }
120 void SetFdfPointer( GSLFdfPointer f) { fFunc.fdf = f; }
121 void SetParams (
void * p) { fFunc.params = p; }
124 gsl_function_fdf * GetFunc() {
return &fFunc; }
127 double operator() (
double x) {
return GSL_FN_FDF_EVAL_F(&fFunc, x); }
129 double Derivative (
double x) {
return GSL_FN_FDF_EVAL_DF(&fFunc, x); }
131 void Fdf(
double x,
double & f,
double & df) {
132 return GSL_FN_FDF_EVAL_F_DF(&fFunc, x, &f, &df);
137 return (fFunc.f != 0 ) ?
true :
false;
141 gsl_function_fdf fFunc;