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.])
    pt = array('d',[0.])

    for j in range(tree.GetEntries()):

   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!



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.


This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.