Complex TDraw selection

Hi.

I have a TTree and would like to select events according to some cut. This cut affects 2 vector collections in my tree, say muon_pt and muon_z. Logically, what I want to select are all events that contain at least 2 muons with pt>20 (for the first one) and 10 (for the second one) and where these two muons have a difference in their z position below some value, e.g. abs(muon_z[index1] - muon_z[index2]) < 0.5. I am a big fan of TDraw which I use for all sorts of selections, but for this one I would like to ask if it is actually possible to do with TDraw.
I think what would be necessary is to have a way to access the index of the first, second, etc. element in a vector that passes a selection I have something like this in mind:

tree.TDraw("Sum$(muon_pt>20)>=1 && Sum$(muon_pt>=10)>=2 && (abs(muon_z[Index1$(muon_pt>20)] - muon_z[Index2$(muon_pt>10)]) < 0.5 || ....going through all permutations of Index1 and 2)")

The selection would probably not be nice and clean, but right now I do not really mind. It is rather a technical question if it is actually possible or not (I know it can also be done with looping over the events and the collections, but I prefer to avoid it if its possible otherwise too). In the aforementioned example, Index1$ and Index2$ would be functions — here the question is: do they exist? — that return the index of the first element in the muon_pt collection that satisfies muon_pt>20, and Index2$ would be the index of the second element, etc.
Of course, all cases where 3, 4, 5, or more such muons exist would need to be included in the cut string.

I somehow have the feeling that the post from 2013 below contains the answer to my question, but the links are broken and the code snippets are missing:

Thanks for any suggestion!
heico

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