Cut strings and looping over events

Hi, I’d like to extract a list of all the event numbers associated with entries that pass a given cut.
For, instance, setting up with

from ROOT import *
f = TFile.Open("myfile.root","r")
t = f.Get("mytree")
cut = "nJets>4 && pT_1jet>20 && nLeptons==0" #or whatever
saved = []

I can then get the total number of entries satisfying my cut with


or I can loop over the tree and extract some variables:

for entry in t:

Now, how do I get myvar only for events that pass cut? Surely there’s another way than manually writing:

for entry in t:
    if entry.nJets>4 and entry.pT_1jet>20 and entry.nLeptons==0:

Ideally I should be able to use this script with any arbitrarily long or complex cut string…

Apparently the following works:

elist = TEventList()
for i in range(0,elist.GetN()):

Is that correct?

1 Like

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