Dear Lorenzo
I tried your code and I was still getting an error:
Error: Can’t call MyFunction::MyFunction(g60_5) in current scope new_lauyout.C:7110:
Possible candidates are…
(in MyFunction)
MyFunction.h 2:1 0 public: MyFunction MyFunction::MyFunction(TGraph& g);
*** Interpreter error recovered ***
As for the .h file, I just opened a file named it MyFunction.h and pasted the code from you below without changing anything
so since I define the TGraph like this
TGraph *g60_5=new TGraph();,
I changed the code to
MyFunction f(*g60_5) (is this actually correct?)
That solved, I got another error:
Error: Can’t call TF1::TF1(“f1”,f,1,10,0,“MyFunction”) in current scope (tmpfile):1:
So I changed it to (“f1”,&f,1,10,0,“MyFunction”)
and in this way I did not get any error messages and could compute the integral. But I am not sure whether I was am doing the right thing.
[quote=“moneta”]OK, if you are using this old ROOT version then you don;t have support for these new features.
In that case you can create a free function or a C++ functor as described in
root.cern.ch/doc/master/classTF1.html#F5
struct MyFunction {
MyFunction(TGraph & g) : fGraph(&g) {}
double operator() (double *x, double *) { return fGraph->Eval(x[0]); }
TGraph * fGraph;
};
Then at the prompt you can do
.L MyFunction.h
double x[] = { 1,2,3,4,5,6,7,8,9,10};
double y[] = { 1,2,3,4,5,6,7,8,9,10};
TGraph g(10,x,y);
MyFunction f(g);
TF1 f1("f1",f,1,10,0,"MyFunction");
Lorenzo[/quote]