Attached is the test macro I am trying to calculate integral under the fit curve. I do not understand why the fit integral is approx (or maybe exactly) 10 times the expected value or the corresponding th1::integral value. Can some please explain?
void test() {
TH1F* trial = new TH1F("","",100,-5, 5);
TRandom3 rndgen;
for (int i = 0; i < 10000; ++i)
trial->Fill(rndgen.Gaus(0.,1.));
trial->Scale(1./trial->GetEntries());
TF1 *g = new TF1("g","gaus",-5.,5.);
trial->Fit("g","R");
// g->SetParameters(2,0,1);
//default gaus integration method uses 6 points
//not suitable to integrate on a large domain
double r1 = g->Integral(-5.,5.);
double r2 = trial->Integral(trial->FindBin(-5),trial->FindBin(5));
// trial->GetYaxis()->SetRangeUser(0,2);
trial->GetXaxis()->SetRangeUser(-5,5);
gStyle->SetOptFit(1);
trial->Draw();
printf("g->Integral(-5,5) = %g\n",r1);
printf("hist->Integral(-5,5) = %g\n",r2);
}
Result I get is
g->Integral(-5,5) = 0.0991864
hist->Integral(-5,5) = 1
ROOT Version: 6.26.14