recently I started to use pyRoot for the analysis of root files I get from a simulation. For most of the branches it works to read the data. However, a few branches have less entries (than the number given by tree.GetEntries() (here 1000)), according to the number of entries, shown in the histogram of the TBrowser (here 478). In this case, I get a segmentation fault. The properties of this branch (via object inspector) tell me that it has more entries(here 1000).
I understand that this is a problem, but I have no idea how to solve it.
Can anyone help me?
here is the file. Thanks for your help. The branch I have problems with, is “NCapture”. I manage to readout the leave “evtID”, but I cannot read the other leaves.
Hi Axel,
Looking a the TTree it is normal the discrepancy between entries in the tree and entries in the histogram. These branches are variable size arrays, so what is shown in the histogram is the accumulation of all the elements of all the array in all the entries. Many of them are zero size. See the following code:
import ROOT
f = ROOT.TFile('muon-user.root')
tree = f.nCapture
kines = 0
entries = 0
for entry in tree:
entries += 1
for i in entry.NeutronKine:
kines += 1
print 'entries = %d, kines = %d' %(entries, kines)
thanks for this reply. It helped me a lot to understand pyROOT. Unfortunately I still cannot read out the data from the nCapture Tree (which I associated with the different entry numbers).
For the geninfo Tree I get the numbers I want via: