34#ifndef ROOT_Math_GSLMultiFitFunctionAdapter
35#define ROOT_Math_GSLMultiFitFunctionAdapter
37#include "gsl/gsl_vector.h"
38#include "gsl/gsl_matrix.h"
68template<
class FuncVector>
73 static int F(
const gsl_vector *
x,
void * p, gsl_vector *
f ) {
75 unsigned int n =
f->size;
77 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
78 if (
n == 0)
return -1;
79 for (
unsigned int i = 0; i <
n ; ++i) {
80 gsl_vector_set(
f, i, (funcVec[i])(
x->data) );
86 static int Df(
const gsl_vector *
x,
void * p, gsl_matrix *
h) {
89 unsigned int n =
h->size1;
90 unsigned int npar =
h->size2;
91 if (
n == 0)
return -1;
92 if (npar == 0)
return -2;
93 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
94 for (
unsigned int i = 0; i <
n ; ++i) {
95 double *
g = (
h->data)+i*npar;
96 assert ( npar == (funcVec[i]).NDim() );
97 (funcVec[i]).Gradient(
x->data,
g);
103 static int FDf(
const gsl_vector *
x,
void * p, gsl_vector *
f, gsl_matrix *
h) {
106 unsigned int n =
h->size1;
107 unsigned int npar =
h->size2;
108 if (
n == 0)
return -1;
109 if (npar == 0)
return -2;
110 FuncVector & funcVec = *(
reinterpret_cast< FuncVector *
> (p) );
111 assert (
f->size ==
n);
112 for (
unsigned int i = 0; i <
n ; ++i) {
113 assert ( npar == (funcVec[i]).NDim() );
115 double *
g = (
h->data)+i*npar;
116 (funcVec[i]).FdF(
x->data, fval,
g);
117 gsl_vector_set(
f, i, fval );
Class for adapting a C++ functor class to C function pointers used by GSL MultiFit Algorithm The temp...
static int FDf(const gsl_vector *x, void *p, gsl_vector *f, gsl_matrix *h)
evaluate derivative and function at the same time
static int Df(const gsl_vector *x, void *p, gsl_matrix *h)
static int F(const gsl_vector *x, void *p, gsl_vector *f)
Namespace for new Math classes and functions.