reading in every Nth event from a file #287
-
I'd like to load a TTree from a rootfile but with a prescale applied. ie. Instead of loading each event into the array I only load events where event_id(mod)10=0 or event_id(mod)100=0. I imagine this is fairly easy to do if the event_id is already in the TTree as a branch, by just requiring the event meets the mod 0 requirement. But what about if there is no explicit event number branch? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Any array in Python can use a slice syntax like this: array[::10] The above will take event There's no way to avoid reading all the events before applying this prescale because contiguous events have to be read together (due to the columnar structure of a ROOT TBranch), but this will get you every 10th event after they've been read. |
Beta Was this translation helpful? Give feedback.
Any array in Python can use a slice syntax like this:
The above will take event
0
, event10
, event20
, etc. (If you wanted event9
,19
,29
, etc., then you can doarray[9::10]
. That would agree better witheventId % 10
if theeventId
started with1
instead of0
.)There's no way to avoid reading all the events before applying this prescale because contiguous events have to be read together (due to the columnar structure of a ROOT TBranch), but this will get you every 10th event after they've been read.