[ROOT] RE: combining custom functions

From: Philippe Canal (pcanal@fnal.gov)
Date: Tue Feb 24 2004 - 17:09:20 MET


Hi,

It is currently not possible to 'combine' custom function using the TFormula
parser.
I.e. in your example:
   TF1 *f3 = new TF1("f3",f1*f2,xminFunc3,xmaxFunc3,NparsFunc1+NparsFunc2);
will not work.

Also
    TF1 *f3 = new
TF1("f3",Func1*Func2,xminFunc3,xmaxFunc3,NparsFunc1+NparsFunc2);
is illegal C++.

You need to do:
    Double_t Func3(Double_t *x,Double_t *pars)
    {
        ... Func1(...,&par[0] ... Func2(...,...&par[NparsFunc1])
    }
and
   TF1 *f3 = new TF1("f3",Func3,xminFunc3,xmaxFunc3,NparsFunc1+NparsFunc2);
Cheers,
Philippe.
-----Original Message-----
From: owner-about-root@listserv.fnal.gov
[mailto:owner-about-root@listserv.fnal.gov]On Behalf Of Stilianos Kesisoglou
Sent: Tuesday, February 24, 2004 2:59 AM
To: roottalk@root.cern.ch; about-root@fnal.gov
Subject: combining custom functions


Hi,

    Is it possible to use custom made functions on ROOT the same way that
we use the canned ones?

    For example:

    a)    I define first :

    Double_t Func1(Double_t *x,Double_t *pars)
    {
        <my function here>
    }

    Double_t Func2(Double_t *x,Double_t *pars)
    {
        <my function here>
    }


    b)    then load the functions:

    .L Func1.C
    .L Func2.C


    c)    and then I do:

    TF1 *f1 = new TF1("f1",Func1,xminFunc1,xmaxFunc1,NparsFunc1);
    TF1 *f2 = new TF1("f2",Func2,xminFunc2,xmaxFunc2,NparsFunc2);

    f1->Draw();    or     f2->Draw();


    The above works well. But when I try to do:


    TF1 *f1 = new TF1("f1",Func1,xminFunc1,xmaxFunc1,NparsFunc1);
    TF1 *f2 = new TF1("f2",Func2,xminFunc2,xmaxFunc2,NparsFunc2);

    TF1 *f3 = new TF1("f3",f1*f2,xminFunc3,xmaxFunc3,NparsFunc1+NparsFunc2);

    f3->Draw();

    It fails with a message that the function f3 could not be compiled.

    Is it possible to make the above code to work. I would like to be able
to load a set of functions and then decide on the fly what is the
combination I want.
    I would really like to avoid definning a third function.

    Also is it possible to make the f3 directly i.e:

    TF1 *f3 = new
TF1("f3",Func1*Func2,xminFunc3,xmaxFunc3,NparsFunc1+NparsFunc2);

or something like that avoiding the definition of f1 and f2?

    Thanks!


Stelios.



This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:06 MET