# Finding error of a TH1F plot

**URL:** <https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544>\
**Category:** Newbie\
**Created:** [June 12, 2019, 3:51am UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544 "2019-06-12T03:51:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 12, 2019, 3:51am UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544/1 "2019-06-12T03:51:42Z")

</div>

Dear All,

I have a distribution and I am trying to find the error associated with this histogram. I used h\_pt -\>Sumw2() before filling then I have a loop but I am getting zero for the error value.

**Sample code:**

double err\_pt = 0;  
for (ibins = 1; ibins \<= h\_pt-\>GetNbinsX();ibins++)  
{  
err\_pt = pow(h\_pt-\>GetBinError(ibins),2);  
}  
cout \<\< err\_pt \<\< endl;

This is the distribution

 ![52%20PM](https://root-forum.cern.ch/uploads/default/original/3X/1/1/11e38024b243ebbdbcc24cd8682f8ed153f341be.png)

---

<div class="post-metadata">

**Author:** ![Dilicus](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dilicus/32/14338_2.png) [@Dilicus](https://root-forum.cern.ch/u/Dilicus)\
**Post date:** [June 12, 2019, 5:25am UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544/2 "2019-06-12T05:25:07Z")

</div>

Hi,

maybe you need a + here

```auto
err_pt+ = pow(h_pt->GetBinError(ibins),2);

```

otherwise you print the squared error of the last bin that is 0.

Cheers,  
Stefano

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 12, 2019, 1:00pm UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544/3 "2019-06-12T13:00:41Z")

</div>

Thank you for your response, however I tried that and got the following error:

error: expected primary-expression before ‘=’ token  
err\_pt+ = pow(h\_pt-\>GetBinError(ibins),2);

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 12, 2019, 1:06pm UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544/4 "2019-06-12T13:06:15Z")

</div>

```auto
err_pt += ...

```

---

<div class="post-metadata">

**Author:** ![Prya13](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/p/ea666f/32.png) [@Prya13](https://root-forum.cern.ch/u/Prya13)\
**Post date:** [June 13, 2019, 1:32pm UTC](https://root-forum.cern.ch/t/finding-error-of-a-th1f-plot/34544/5 "2019-06-13T13:32:23Z")

</div>

Thank you Wile,

Still didn’t work. I did it another way.
