Different entry numbers in branches of one tree

Hi there,

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?


The number of entries in each branch is always identical. Can you place your file in a public area to have a look?
Cheers, Pere

Hi Pere,

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.

Cheers, Axel
muon-user.root (263 KB)

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)


entries = 1000, kines = 478



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:


(dependent on how it is stored). If I leave out the [0] for the InitX branch it gives back:

     <Float_t buffer, size 1>

Now I want to make a similar readout for the nCapture tree:


The NeutronNumber works great again. For the second line I get:

    <Float_t buffer, size 1>

So I tried to access the data via attaching [0], but now i get the Error Message:

    IndexError: buffer index out of range

Is there an obvious problem in my approach, or am I understanding something completely wrong?

What is the difference in the file between NeutronN and NCStartX?