Extracting Data from a TH1F and a TNtuple (Pyroot)

ROOT Version: root-6.20.04
Platform: Any/All
Compiler: Python 2.7.16


I am trying to extract different data points from a root file. Inside the root file it contains TH1F and a TNtuple with multiple leaves.

I have tried to extract the data from the TH1F called mass using

f = ROOT.TFile ( "file.root" , "r")

mass = f.Get("mass")

entries = mass.GetEntries()

Put the entries I get out are the number of events per bin not the actual data. How do I extract the actual data.

Also how do I do the same for the TNtuple as well for each leaf?

Thanks!

You can find the data points in the ntuple (not in the histogram). The ROOT primer has some information on how to access an ntuple in a ROOT file. It might help to first open a browser to visually inspect the file: just open root -l /path/to/file.root and run

new TBrowser

You can then double-click on the ROOT file on the left side to view its contents.

Cheers,
Jakob

Hi @Daniel_Ricardo_Vega ,

I think the following lines should work:

get the data in a TTree format

fi = r.TFile(’<your_file_name>.root’, ‘READ’)
tr = r.TTree()
fi.GetObject(the_name_of_your_tree, tr)

check we have the tree

print(tr.GetEntries())

get the data in RooFit land

deltaM = r.RooRealVar(name_of_your_leaf, ‘delta_M’, 0.14, 0.159, ‘GeV/c^{2}’)
rds = r.RooDataSet(
‘data’, ‘D^{0}#rightarrow K^{0}{S} K^{0}{S}’, tr, r.RooArgSet(deltaM))
Here, 0.14 to 0.159 is the range I specified and deltaM is simply a name I specified. You can set these as per your requirement.

Regards,
Sanjeeda