Reading branches from a TTree with PYROOT

Dear experts,

I am having trouble to read info from the branches of a TTree using the following code:

    z = array('d',[0.])
    tree.SetBranchAddress("L0_END_VZ",z)
    pt = array('d',[0.])
    tree.SetBranchAddress("L0_PT",pt)

    for j in range(tree.GetEntries()):
        tree.GetEntry(j)
        print(z[0])
        print(pt[0])

   and I got in the prints very small numbers like 5.721481036e-315 I don't understand because this method used to work for me...

Thanks in advance for your time!

Diego

tree.Print()

yeah they were float numbers instead of doubles… dumb error, thanks!
Also, there is another branch I want to store:

proton_HASVELO : proton_HASVELO/O

they are doubles, can I use for example:
ar = array(‘i’,[0]) to store them?

sorry they are “booleans”, I meant

Well, "/O" means ROOT “Bool_t” which is then probably an ordinary C++ “bool”.
I think “numpy.array” supports “dtype=bool”.

Perfect, works for me. Thanks!

Hi @mendoza ,

please note that while reading TTree data from a Python for loop works fine in general, it is also much slower than alternative interfaces (namely RDataFrame) so make sure you don’t use raw Python loops for large-scale, full-blown analysis.

Cheers,
Enrico