Combining two built-in functions for fitting

I have a function for fitting:

TF1 *total = new TF1("tot","gausn(0)*0.001 + pol1(3)", 0.5, 0.6);

I want to create it as a sum two TF1:

TF1 *core = new TF1("core","gausn");
TF1 *bg = new TF1("bg","pol1");

TF1 *total = new TF1("tot","core(0)*0.001 + bg(3)", 0.5, 0.6)

But i give bad resalts of fitting. What do I do wrong?


Please read tips for efficient and successful posting and posting code

ROOT Version: 6.22/02
Platform: Ubuntu 20.04
Compiler: Root


Try (see the “names” of parameters and compare with their “numbers” and note how “(0)” and “(3)” are treated): total->Print();

You might try (but again, watch the “names” of parameters and compare with their “numbers”):
TF1 *total = new TF1("tot", "core*0.001 + bg", 0.5, 0.6)

For

TF1 *core = new TF1("core","gausn");
TF1 *bg = new TF1("bg","pol1");

TF1 *total = new TF1("tot","core*0.001 + bg", 0.5, 0.6);

total->Print() shows

[Constant]*exp(-0.5*((x-[Mean])/[Sigma])*((x-[Mean])/[Sigma]))/(sqrt(2*pi)*[Sigma]))*0.001+(([p3]+[p4]*x)

But the results of fitting is bad. For

TF1 *total = new TF1("tot","gausn(0)*0.001 + pol1(3)", 0.5, 0.6);

total->Print() shows

[p0]*exp(-0.5*((x-[p1])/[p2])*((x-[p1])/[p2]))/(sqrt(2*pi)*[p2])*0.001+([p3]+[p4]*x)

And the results of fitting is good. Why?

I guess that, in your fit procedure, you use parameters’ “numbers” that do not correspond to actual parameters’ “names”, e.g. try: total->GetParName(0)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.