Problem in calculating areas under fitted peak

Yes, this should be correct. A potential difficult comes when you wants to calculate the error in the background area. In that case you need to take into account correlations between the two terms you are subtracting.

Lorenzo

Thanks so much @moneta

std::cout << "peak area = " << f1->Integral(395., 435.) << std::endl;

std::cout << h->Integral(h->FindFixBin(395.), h->FindFixBin(435.)) << std::endl;

I was checking the values from both. But able to find that there is a difference.
First gives 15360 while second gives 15483.
Could you please elaborate why the two values are different?

@moneta
Initially i was using:
TF1 *f1 = new TF1(“f1”, “gausn(0) + pol1(3)”, 395., 435.); // linear background
f1->SetParameters(2800., 415., 2., 0., 0.);
h->Fit(“f1”, “LBR+”);

But if i want to use TF1NormSum in order to normalize the background function.
F1 *f1 = new TF1(“f1”, “gausn(0)”, 395., 435.); // linear background
f1->SetParameters(2800., 415., 2.);
TF1 *f2 = new TF1(“f2”, “pol1(3)”, 395., 435.); // linear background
f2->SetParameters( 0., 0.);
TF1NormSum *f3 = new TF1NormSum(f1, f2, ?, ? );
TF1 *f_sum = new TF1(“fsum”, *f3, 395., 435., f3->GetNpar.data() );
f_sum->Draw();
f_sum->SetParameters(f3->GetParameters.data());

Could you please help me in completing the code because there are a few things that i am unable to understand.

Here you compare integral of a function and of an histogram. It is normal that can give different results

@moneta
Also if u need the code
basic.C (6.3 KB) eu_gu_1.txt (44.1 KB)

For using TF1NormSum you should do, as following (as in the tutorial)

F1 *f1 = new TF1(“f1”, “gaus”, 395., 435.); // gaus signal  (no need to use gausn here)
f1->SetParameters(2800., 415., 2.);
TF1 *f2 = new TF1(“f2”, “pol1(3)”, 395., 435.); // linear background - should not use (3) now !!!
f2->SetParameters( 1., 0.);  // using 0,0 is not a good choice
// estimate numbers for gaus and  background events
int nsig = 1000; 
int nbkg = 1000;  
TF1NormSum *f3 = new TF1NormSum(f1, f2, nsig, nbkg );
TF1 *f_sum = new TF1(“fsum”, *f3, 395., 435., f3->GetNpar() );
f_sum->SetParameters(f3->GetParameters.data());
f_sum->Draw();

histogram->Fit(f_sum);

Thanks @moneta