# Uncertainity in the integral of a histogram?

**URL:** <https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259>\
**Category:** Newbie\
**Created:** [February 23, 2024, 8:02am UTC](https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259 "2024-02-23T08:02:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [February 23, 2024, 8:02am UTC](https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259/1 "2024-02-23T08:02:12Z")

</div>

Hello everyone,  
I am trying to get the error on the Integral of a TH1F histogram.

```auto
hist1->Integral(bin1, bin2)

```

Is there any pre-defined functionality to achieve this?

Thanks a lot !

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [February 23, 2024, 8:47am UTC](https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259/2 "2024-02-23T08:47:51Z")

</div>

Hi,

You can use `IntegralAndError` function showing here:  
[https://root.cern.ch/doc/master/classTH1.html#a72750b362fbf8fae7a4c26579ece18bb](https://root.cern.ch/doc/master/classTH1.html#a72750b362fbf8fae7a4c26579ece18bb)

An example

```auto
	TH1F* hist = new TH1F( "hist", "", 10, 0, 10 );
	hist -> Fill( 3, 4 );
	hist -> Fill( 5 );

	double integral_err;
	double integral_val = hist->IntegralAndError( 3, 4, integral_err );
	printf( "Integral = %.4f +- %.4f\n",
			integral_val, integral_err );

	return 0;

```

---

<div class="post-metadata">

**Author:** ![utkarsh-2000](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/u/e47774/32.png) [@utkarsh-2000](https://root-forum.cern.ch/u/utkarsh-2000)\
**Post date:** [February 26, 2024, 7:42am UTC](https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259/3 "2024-02-26T07:42:05Z")

</div>

Thanks @LongHoa for the assistance.

---

<div class="post-metadata">

**Author:** ![LongHoa](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/longhoa/32/25905_2.png) [@LongHoa](https://root-forum.cern.ch/u/LongHoa)\
**Post date:** [February 27, 2024, 12:52pm UTC](https://root-forum.cern.ch/t/uncertainity-in-the-integral-of-a-histogram/58259/4 "2024-02-27T12:52:41Z")

</div>

glad I can help.
