TF1 as a class member and problem with DrawCopy

Dear All,

I have simple macro like below:

[code]class asd : public TObject {
private:
TF1 * f_n_Ev_r;

public:
double fcn2(double * a_, double * p_) {
return a_[0]/2.0;
}

double fcn_Ev_r(double * th_, double * p_);

asd() {
	param = 3.14;
	TF1 * f2 = new TF1("f2", asd::fcn2, 0, 10, 0);
	f_n_Ev_r = new TF1("n(Ev, r);Energy;radius", asd::fcn_Ev_r, 0, TMath::Pi()/128.0, 0);//1

	f2->DrawCopy("same");
	f_n_Ev_r->DrawCopy("same");
}

};

double asd::fcn_Ev_r(double * th_, double * p_) {
double th = atan(th_/1.0);
return 0.999 * 30 * (1.0 + 0.9
cos(th));
}

double fcn(double * a_, double * p_) {
return p_[0] * a_[0];
}

double fcnn(double * a_, double * p_) {
return p_[0] * a_[0];
}

test() {
TF1 * f = new TF1(“f”, fcn, 0, 10, 1);
TF1 * fn = new TF1(“fn”, fcnn, 0, 10, 1);

f->SetParameter(0, 3);
fn->SetParameter(0, 2);

f->DrawCopy();
fn->DrawCopy("same");
new asd();

}[/code]

Problem is when I run it, i get:

Error: Cint::G__CallFunc::SetArgArray() must be initialized with 'Cint::G__CallFunc::SetFunc(G__ClassInfo* cls,char* fname,char* args,long* poffset)' first Error: Cint::G__CallFunc::SetArgArray() must be initialized with 'Cint::G__CallFunc::SetFunc(G__ClassInfo* cls,char* fname,char* args,long* poffset)' first
This problem relates to:

f2->DrawCopy("same"); f_n_Ev_r->DrawCopy("same");

But problem exist only for TF1 created from class member functions. Other two created from global functions work fine.

Can somebody explain it to me?

Cheers,
Rafal

To create a TF1 from a member function, you have to do as documented in

root.cern.ch/root/htmldoc/TF1.html#F5

You need in particular to pass the pointer to the class implementing the member function.
Furthermore, if you want to work in interpreted mode (CINT), you need to pass also the name of the class and of the member function.

Best Regards

Lorenzo

Yes, I have seen this documentation, but it doesn’t solve the problem. DrawCopy() still doesn’t work but Draw() works fine.

I also tried this

f_n_Ev_r = new TF1("n(Ev, r);Energy;radius", this, &asd::fcn_Ev_r, 0, TMath::Pi()/128.0, 0, "asd", "fcn_Ev_r"); but problem still exist.

In documentation is situation, when function declaration is inside the class, but TF1 object is outside. In my case I have function and TF1 inside the same class. What more, I would like to use several functions from class so I cannot override operator() or Eval().

Regards,
Rafal

Yes, I could reproduce it your problem when copying the function.
There is a bug in copying the TF1 made from a member function when running in interpreted mode.
If you compile your macro with AClic you should not have this problem.
I will fix for the next release the TF1::Copy function

Regards

Lorenzo