# Fit integral issue

**URL:** <https://root-forum.cern.ch/t/fit-integral-issue/59701>\
**Category:** Newbie\
**Created:** [June 20, 2024, 7:22am UTC](https://root-forum.cern.ch/t/fit-integral-issue/59701 "2024-06-20T07:22:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shailesh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@Shailesh](https://root-forum.cern.ch/u/Shailesh)\
**Post date:** [June 20, 2024, 7:22am UTC](https://root-forum.cern.ch/t/fit-integral-issue/59701/1 "2024-06-20T07:22:31Z")

</div>

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?

```auto
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_

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [June 20, 2024, 7:35am UTC](https://root-forum.cern.ch/t/fit-integral-issue/59701/2 "2024-06-20T07:35:50Z")

</div>

Use instead:

```auto
double r2 = trial->Integral(trial->FindBin(-5),trial->FindBin(5), "width");

```

---

<div class="post-metadata">

**Author:** ![Shailesh](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/50afbb/32.png) [@Shailesh](https://root-forum.cern.ch/u/Shailesh)\
**Post date:** [June 20, 2024, 8:19am UTC](https://root-forum.cern.ch/t/fit-integral-issue/59701/3 "2024-06-20T08:19:13Z")

</div>

This worked. The values are much closer now, and probably will keep on getting close the better the fit. Can you explain what the “width” option did here?

Thank You

---

<div class="post-metadata">

**Author:** ![ferhue](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/ferhue/32/29462_2.png) [@ferhue](https://root-forum.cern.ch/u/ferhue)\
**Post date:** [June 20, 2024, 10:01am UTC](https://root-forum.cern.ch/t/fit-integral-issue/59701/4 "2024-06-20T10:01:52Z")

</div>

See [ROOT: TH1 Class Reference](https://root.cern.ch/doc/master/classTH1.html#a919887c7b8431299713ec22e544cc396)
