# How to integrate TH2 correctly?

**URL:** <https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582>\
**Category:** ROOT\
**Created:** [February 2, 2010, 2:00pm UTC](https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582 "2010-02-02T14:00:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![thart](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@thart](https://root-forum.cern.ch/u/thart)\
**Post date:** [February 2, 2010, 2:00pm UTC](https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582/1 "2010-02-02T14:00:02Z")

</div>

Hi,

I want to integrate bins in a subrange of a TH2D histogram but I fail with the syntax of Integral()

For example, how would I integrate a a rectangular subrange in (x\_min,y\_min) & (x\_max,y\_max)?  
Following the Integral() definitions

```auto

```

I thought that it would work with

```auto

```

But ROOT computes the integral value for my test histogram as 0 although the histogram is definitely not empty…

Maybe somebody could help me with the correct syntax?

Cheers & Thanks,  
Thomas

---

<div class="post-metadata">

**Author:** ![brun](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/b9e5f3/32.png) [@brun](https://root-forum.cern.ch/u/brun)\
**Post date:** [February 2, 2010, 2:07pm UTC](https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582/2 "2010-02-02T14:07:39Z")

</div>

using

`Double_t Integral(Int_t binx1, Int_t binx2, Int_t biny1, Int_t biny2, Option_t* option = "")
`with

`binx1 = myhist->GetXaxis()->FindBin(xmin);
binx2 = myhist->GetXaxis()->FindBin(xmax);
biny1 = myhist->GetYaxis()->FindBin(ymin);
biny2 = myhist->GetYaxis()->FindBin(ymax);
`  
The TH1::FindBin function returns a global bin number (see doc)

Rene

---

<div class="post-metadata">

**Author:** ![thart](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/t/f1d935/32.png) [@thart](https://root-forum.cern.ch/u/thart)\
**Post date:** [February 2, 2010, 2:13pm UTC](https://root-forum.cern.ch/t/how-to-integrate-th2-correctly/9582/3 "2010-02-02T14:13:00Z")

</div>

Hi Rene,

many thanks – I have not considered that I have to ask the particular axis. But now it seems quite obvious 😉

Thanks,  
Thomas
