compounding TF1's?

From: Petar Maksimovic (petar@heplcdf1.harvard.edu)
Date: Thu Mar 18 1999 - 17:17:40 MET


Hi Rooters,

I would like to be able to combine TF1 objects into compound
functions, just like one can do with the TFormula objects.
Let me remind of you of an example that was bandied about
this list a few months ago:

Rene Brun wrote:
> Hi Thierry,
> I have no problems executing your macro. I have made slight changes
> to show two functions on the same graph.
> A similar example is given in tutorials/fillrandom.C
> I assume you run with 2.00/13 or 2.20.
> 
> Rene Brun
> 
> {
>   gROOT->Reset();
>   TFormula *pomeron = new
>   TFormula("pomeron","[0]*pow((x-0.939*0.939)/1.878,[1])");
>   TFormula *f = new
>   TFormula("f","([2]*pow((x-0.939*0.939)/1.878,[3]))");
>   TF1 *total = new TF1("total","pomeron + f",1,20);
>   total->SetParameters(1,2,1.5,2.4);
>   total->Draw();
>   TF1 *one = new TF1("one","pomeron",1,20);
>   one->SetParameters(1,2,1.5);
>   one->Draw("same");
> }

What I have in mind is to be able to use TF1's associated with
user-defined functions (a.k.a. "type C").  Since the above example works,
and TF1 *is a* TFormula, I would naively expect that the following
example should work as well:

-------------8<--------------------------------------------
Double_t internalFunA(Double_t *x, Double_t *par)
{
  return x[0]*0.1 + 5.0;
}

Double_t internalFunB(Double_t *x, Double_t *par)
{
  return x[0]*x[0]*77;
}

void test(void)
{
  TF1 myFuncA("myA", internalFunA, 0.0, 0.4, 1);  // myA is a TFormula
  TF1 myFuncB("myB", internalFunB, 0.0, 0.4, 1);  // myB is a TFormula
  TF1 myFuncAB("myAB", "myA + myB", 0.0, 0.4 );   // this doesn't work
}
-------------8<--------------------------------------------

However it fails when trying to construct myFuncAB:

*ERROR 26 : 
 Unknown name : "myA"

Am I doing something wrong here?


To summarize:
- it would be really nice to be able to do something like this (so
  that one can build very complex fits by building functions from 
  smaller -- but also non-trivial -- functions)

- if TF1 is a TFormula, I would expect this to work


I might be missing something, and perhaps the above behavior is
expected.  If that's so, please let me know how one can get
around it...

Thanks a lot!

	Petar



This archive was generated by hypermail 2b29 : Tue Jan 04 2000 - 00:43:30 MET