# Error with TH1::GetEntries()

**URL:** <https://root-forum.cern.ch/t/error-with-th1-getentries/42385>\
**Category:** Newbie\
**Tags:** hist\
**Created:** [November 21, 2020, 3:06am UTC](https://root-forum.cern.ch/t/error-with-th1-getentries/42385 "2020-11-21T03:06:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hammiu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hammiu/32/20395_2.png) [@hammiu](https://root-forum.cern.ch/u/hammiu)\
**Post date:** [November 21, 2020, 3:06am UTC](https://root-forum.cern.ch/t/error-with-th1-getentries/42385/1 "2020-11-21T03:06:32Z")

</div>

Hi everyone.  
I want to return the entries of my histogram, but I see that it return not correct result.

```auto
#include <iostream>
#include <TH1.h>
using namespace std;

void anh()
{
    delete gROOT->FindObject("h"); //delete old object
    TH1D *h = new TH1D("h", "his", 10, 0, 10);
    for (int i = 1; i <= h->GetNbinsX(); i++)
    {
        h->SetBinContent(i, i);
    }
    cout << "Entries: " << h->GetEntries() << endl;
    h->Draw();
}

```

Here is an output.

```auto
root [9] .x anh.cpp
Entries: 10

```

I think correct entries are **55** (1+2+…+10 = 55).

---

<div class="post-metadata">

**Author:** ![yus](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/y/9fc348/32.png) [@yus](https://root-forum.cern.ch/u/yus)\
**Post date:** [November 21, 2020, 1:00pm UTC](https://root-forum.cern.ch/t/error-with-th1-getentries/42385/2 "2020-11-21T13:00:01Z")

</div>

Hi,

actually no, everything is correct. Number of entries is the number of times you called `TH1::Fill(...)` or `TH1::SetBinContent(...)`. You are calling the latter in the loop over bins, and you have 10 bins. So you should end up with 10 entries.

The 1+2+3+…+10=55 you are thinking of is the [integral](https://root.cern.ch/doc/v616/classTH1.html#a919887c7b8431299713ec22e544cc396).

---

<div class="post-metadata">

**Author:** ![hammiu](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hammiu/32/20395_2.png) [@hammiu](https://root-forum.cern.ch/u/hammiu)\
**Post date:** [November 21, 2020, 2:16pm UTC](https://root-forum.cern.ch/t/error-with-th1-getentries/42385/3 "2020-11-21T14:16:54Z")

</div>

Hi, thank you. It corrected my code and it was fine.
