# My histogram is not working "AttributeError: 'TObject' object has no attribute 'GetEntries'"

**URL:** <https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375>\
**Category:** Newbie\
**Tags:** python, root\
**Created:** [July 31, 2024, 9:10am UTC](https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375 "2024-07-31T09:10:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![greentree](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/greentree/32/30929_2.png) [@greentree](https://root-forum.cern.ch/u/greentree)\
**Post date:** [July 31, 2024, 9:10am UTC](https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375/1 "2024-07-31T09:10:07Z")

</div>

I have a 3d histogram that I can see from TBrowser that has entries in it. However when I try to print entries i get AttributeError: ‘TObject’ object has no attribute ‘GetEntries’.

The type of the object is:  
\<class cppyy.gbl.TObject at 0x644a380\>

What else can I do to troubleshoot this?  
Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![seligman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@seligman](https://root-forum.cern.ch/u/seligman)\
**Post date:** [July 31, 2024, 10:32am UTC](https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375/2 "2024-07-31T10:32:01Z")

</div>

You may want to consider posting the code that you’re using to access the histogram.

The error message means that ROOT/C++/cling considers the object to be a TObject, not a TH3D (or TH3F). If you’re doing something like this:

auto myFile = TFile::Open(“myfile.root”);  
auto myHist = myFile-\>Get(“myHist”);

Then myHist will be a TObject\*, not a TH3D\*. If my guess is right (and I’m making a few unjustified assumptions about your code here), what you may want to consider is:

```auto
auto myHist = (TH3D*)myFile->Get("myHist");
if ( myHist == nullptr ) {
  // error; 'myHist' is either not in 'myFile' or it's not a TH3D*
}
else {
  auto myEntries = myHist->GetEntries();
}

```

---

<div class="post-metadata">

**Author:** ![greentree](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/greentree/32/30929_2.png) [@greentree](https://root-forum.cern.ch/u/greentree)\
**Post date:** [July 31, 2024, 10:47am UTC](https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375/3 "2024-07-31T10:47:25Z")

</div>

Thank you very much for your answer. Your guess is correct. I was doing something like this:

```auto
my_file = ROOT.TFile.Open(filename)
name = "myhist"
Myhist =my_file.Get(name)

```

I am using python do you know how I can do this in python?

```auto
auto myHist = (TH3D*)myFile->Get("myHist");

```

---

<div class="post-metadata">

**Author:** ![seligman](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/b9bd4f/32.png) [@seligman](https://root-forum.cern.ch/u/seligman)\
**Post date:** [July 31, 2024, 11:06am UTC](https://root-forum.cern.ch/t/my-histogram-is-not-working-attributeerror-tobject-object-has-no-attribute-getentries/60375/4 "2024-07-31T11:06:39Z")

</div>

Based on my limited experience with Python and pyroot, the code you have should have worked. The Python-C++ bindings are usually pretty good about converting types.

However, when I look at my own Python example code, I see that I’ve done things slightly differently:

```auto
inputFile = ROOT.TFile("myFile.root")
tree = ROOT.gDirectory.Get( 'myTree' )

```

Perhaps gDirectory is more robust than a simple ROOT.TFile.Get().
