# TF1 definition using a class member

I would like to perform a numeral integration and define my function wrapped in classes. How can I do it? I enclosed the macro eluminating the scheme I would like to use but it doesn’t work.

Jan
P.S. I know there is a mathmore stuff, but it doesn’t solve my probelm.

const int GLN=100;
double glx[GLN],glw[GLN];

struct MyIntegClass{

``````MyIntegClass() {
mypar=2.0;
fFunc = new TF1("fFunc",F_func,0,10);
fFunc->CalcGaussLegendreSamplingPoints(GLN,glx,glw);
}

double F_func(double *x, double *par){
return mypar*x;
}

double operator() (double *x, double * ) const {
//return fFunc->Derivative(*x);
return fFunc->Eval(*x);
}

double Eval(double par) {
mypar=par;
return fFunc->IntegralFast(GLN,glx,glw, 0, 1);
}

TF1 * fFunc;
double mypar;
``````

};

void myInteg(){

``````MyIntegClass *myinteg = new MyIntegClass();

TF1 * f2 = new TF1("f2",myinteg, -10, 10, 0, "MyIntegClass");
f2->Draw();

cout<<"Integral = "<< myinteg->Eval(5) <<endl;
``````

}

Hi,

For now, you need to write a free standing function that wraps the call to the object function.

Cheers,
Philippe

For example you could have[code]MyIntegClass *myinteg = 0;
double my_wrapper(double *x, double *par)
{
return (*myinteg)(x,par);
};

void myInteg(){

myinteg = new MyIntegClass();

TF1 * f2 = new TF1(“f2”,myinteg, -10, 10, 0, “MyIntegClass”);
f2->Draw();

``````cout<<"Integral = "<< myinteg->Eval(5) <<endl;
``````

}[/code]

Cheers,
Philippe