TTreeReader and TEventList

Dear experts,
I don’t see a way to get TTreeReader to respect a TTree/TChain’s .SetEventList() value. Here’s a simplified example showing it does not do it by default:

import ROOT
from array import array
t = ROOT.TTree("t1", "test tree")
n = array('i',[0])
t.Branch("mynum", n, "mynum/I")
for i in range(20):
    n[0] = i*2
# Making a list of selected events
evlist = ROOT.gROOT.Get("evlist")

# This was %%cpp in the Jupyter notebook
TTreeReader tread(t1);
TTreeReaderValue<Int_t> value(tread, "mynum");
    cout << *value << endl;

This outputs all 20 numbers, rather than the selected five.

I looked for a TTreeReader setting to enable this behavior but didn’t find one.


Hi Henry, I am not an expert but it seems that the loop over the ‘Next’ entry with the TTreeReader ignores the TEventList that has been added into the TTree (I have to ask the real experts to see if this is bug or a feature). What works for me is to loop over entries in the TEventList. This is the cell that do the work (this time in Python).

reader = ROOT.TTreeReader(t)
value = ROOT.TTreeReaderValue('Int_t')(reader,'mynum')
for i in range(evlist.GetN()):
    print value.Get()[0]

Cheers, Pere

Hi Pete,

Thanks, I was trying an all Python method, and got the template part, but then missed out on the value.get()[0] part.

I was hoping to write a library function that would accept Trees or Trees with selected events; for now I’m using something like:

signal = chain.CopyTree(str(cut))

before calling the library function. If this does not provide a significant loss in speed, and works without an EventList in C++, it might be the solution for now. It does seem like it would be a nice thing to have built into TTreeReader, though.