'ROOT.MethodProxy' object has no attribute ' '

Hi.
I am trying to read root files and extract out information out of histograms and trees (such as mean of multiple histograms) to plot. I am not experienced with root, and I was testing a simple exercise to draw one of the histograms using the following:

file = ROOT.TFile(‘filename.root’)
hist = file.Get(‘histogram’).Clone
hist.draw()

I get the following error:
'AttributeError: ‘ROOT.MethodProxy’ object has no attribute ‘draw’

What is this error saying and is there a fix?

Thanks.


_ROOT Version:5.34/36
_Platform:Windows 10
Compiler: Not Provided


Hi,

You are not invoking the Clone method, but rather copying it into the variable hist.
The right syntax is:

file = ROOT.TFile(‘filename.root’)
hist = file.Get(‘histogram’).Clone()
hist.draw()

Or better:

file = ROOT.TFile(‘filename.root’)
file.histogram.DrawClone()

Cheers,
D

Hi,

Thanks for the reply. I’m still very new to this and don’t understand what is going on. Trying your first suggested method I get a ReferenceError: attempt to access a null pointer. While your second method gives me an AttributeError: TFile object has no attribute ‘histogram.’

I think I understand the second error as file is a variable for the root file instead of the histograms within (though I may be wrong). However I do not understand the ReferenceError.

Thanks

Hi,

both errors point to the fact that no object labelled “histogram” is present in the file.

Cheers,
D

Hi,

There are 1D histograms in the file I am looking into. More specifically to what I am trying to do, I want to get into each of the histograms and extract the mean values out of each one.

Thanks,
Ryan

Hi Ryan,

then one thing you could do is:

myHistList = ["Eabs0", "Eabs1", ...] # Here the list of histogram names
file = ROOT.TFile(‘filename.root’)
for hName in myHistList:
    hist = file.Get(hName)
    print hist.GetMean()

Cheers,
D

Ahhh I see now. Thank you so much for your help! :slight_smile:

Ryan

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.