Warning about using TF1 into TF1

Hi there,

Just a warning about using the “John Odonnell’s method” described in http://root.cern.ch/root/html520/TF1.html (C - A general C function with parameters) to reference a TF1 into a TF1 :
Some TMath functions such as TMath::\Pi() or TMath::\DegToRad() will NOT be recognized.

[code]TF1* getf1 ( Double_t cst1 )
TF1 *f1 = new TF1 (“f1name”,"[0]*cos(x)", 0., 10.) ;
// !!! Here TMath::Pi() OR TMath::DegToRad() WON’T BE TAKEN INTO ACCOUNT !!!
f1->SetParameter(0,cst1) ;
return (f1) ;

TF1* mytest ( Double_t cst2 )
TF1 *f1 = getf1 (2.) ;
TF1 *f2 = new TF1 (“f2”,"[0]*f1name",0.,10.) ;
// Here TMath::Pi() OR TMath::DegToRad() CAN BE USED SAFELY
f2->SetParameter(0,cst2) ;
return (f2) ;

If this can be fixed, thanks for doing it.
This kind of jokes can be very time-consuming…

Cheers, Z


the TF1 doc is clear about this:

TMath functions are CINT interpreted functions and therefore this functionality wont work for them.

However if you use the case D (i.e. using the TF1 as a functor, see

it will work fine. Attached is the example code working also in interpreted mode.


TF1Func.C (542 Bytes)

Thanks Lorenzo, I’d missed the point about TMath functions.
Anyway, this is still not exactly what I’d like to do.
I’d like to be able to get my two TF1 independently (the second depending on the first).

TF1* f1 = getf1() ;
TF1* f2 = getf2() ; // with f2 = g(x) * f1

Do you see any other way ?
Thanks in advance, Z


if you don’t need to use interpreted expressions, using case D, you can make your own class (or structure) as you wish, for example like this
(g(x) is your own function used to define f2)

struct MyFunction { 
 MyFunction () { 
   f1 = getf1(); 

 double operator() (const double *x, double *p) { 
    return p[0] * (*f1)(x,p) * g(x); 
 TF1 * f1;
TF1 * getf2() { return new TF1("f2",MyFunction(),xmin,xmax,npar);}