Adding TF1

Hi
I would like to add a bunch of TF1’s together. So I followed this set of instructions:

In principle I want to do more than just 2 though… I want to do N where N is a large number (say 10k)

I have uploaded a simple file “test.c” which tries to add a bunch of gaussians. Set the number of events to say 100, it’s fine. Set it to 1000, there is a problem. This may be due to sloppy memory management on my part, but I think I deleted all the pointers.

So I’m wondering if this is a fundamental limit of adding TF1’s.

Thank
Ben
test.c (569 Bytes)

I suggest a big simplification of your code as illustrated in the code below

Rene

[code]double myfunc(double *x, double *par)
{
double f = 0;
int nfunc = int(par[0]);
double mean = 0;
for (int i=1;i<=nfunc;i++) {
f += TMath::Gaus(mean,par[i],x[0]);
}
return f;
}
void test()
{
double sigma = 1;
int nfunc = 1000;
TF1 *f1 = new TF1(“f1”,myfunc,-1,1,nfunc+1);
f1->SetParameter(0,nfunc);

for (int i=1;i<=nfunc;i++) {
f1->SetParameter(i,sigma);
sigma -= 0.0001;
}
f1->Draw();
}
[/code]

Hi
I tried this, and it’s working very well for my analysis.

Thanks
Ben