Hello, root users. I am a complete novice that is trying to extract data from the attached root file. I found a similar thread: How to extract a data from dna.root file? where the guy solved the question.
My data goes 1 more folder down and I just don’t know how to write the code to extract it. I tried it by editing the dump.cxx file but it’s not working. Thank you for help in advance!
Hi,
I am not sure what you want to dump from this file, which contains 4 histograms and 2 ntuples. A simple python script to dump the contents can be the following:
from ROOT import TFile, TCanvas
f = TFile('AnaEx01.root')
# Get the histograms and draw them
histos = [f.Get('histo/%d'%(i+1)) for i in range(4)]
c = TCanvas()
c.Divide(2,2)
for i in range(4):
c.cd(i+1)
histos[i].Draw()
c.Draw()
# Get the tuples and print their contents
ntuples = [f.Get('ntuple/%d'%(i+101)) for i in range(2)]
for i in range(2):
ntuple = ntuples[i]
names = [b.GetName() for b in ntuple.GetListOfBranches()]
print '--------NTuple %s------------------'% ntuple.GetName()
for n in names : print n,
print ';'
for e in ntuple:
for n in names:
print getattr(e,n),
print ';'
Thank you that totally worked but it didn’t quite do what I wanted. Basically I want to get the x-axis and y-axis data for ntuple 101 so I can recreate graph for example on excel based on data. Thanks for your helps! dump.txt (74.5 KB)
[quote=“mato”]Hi,
I am not sure what you want to dump from this file, which contains 4 histograms and 2 ntuples. A simple python script to dump the contents can be the following:
[code]
from ROOT import TFile, TCanvas
f = TFile(‘AnaEx01.root’)
Get the histograms and draw them
histos = [f.Get(‘histo/%d’%(i+1)) for i in range(4)]
c = TCanvas()
c.Divide(2,2)
for i in range(4): c.cd(i+1)
histos[i].Draw()
c.Draw()
Get the tuples and print their contents
ntuples = [f.Get(‘ntuple/%d’%(i+101)) for i in range(2)]
for i in range(2):
ntuple = ntuples[i]
names = [b.GetName() for b in ntuple.GetListOfBranches()]
print ‘--------NTuple %s------------------’% ntuple.GetName()
for n in names : print n,
print ';'
for e in ntuple:
for n in names:
print getattr(e,n),
print ‘;’
[/code][/quote]
I tried running the code and I got error message saying ImportError: No module named ROOT.
[quote=“mato”][quote]
I tried running the code and I got error message saying ImportError: No module named ROOT.
[/quote]
Does your installation of ROOT has the python option enabled?
Did you set the environment by sourcing /bin/thisroot.sh[/quote]
I am using Windows 7 and not sure where to find this. Is there a different way to get this done? For histogram, I did the following and it worked before.