Skip to content

Keep the same base collection in selection proxies

Pieter David requested to merge piedavid/bamboo:fixnestedselectbase into master

This showed up (thanks @vischia for reporting) when using the result of op.select(op.select(...)...) as range argument, originally cleaning taus with selected and muon-cleaned electrons, minimally something like

muons_1 = op.select(t.Muon, lambda mu : mu.p4.Pt() > 20.)
muons_2 = op.select(muons_1, lambda mu : op.abs(mu.p4.Eta()) < 2.4)
electrons = op.select(t.Electron, lambda el : op.NOT(op.rng_any(muons_2, lambda im : op.deltaR(el.p4, im.p4) < 0.3 )))

For the curious: the way these selections work is that there is one "base" collection (t.Muon, t.Electron), and a selection proxy keeps a reference to that and a vector of indices (in the original collection) for the objects that pass. This bug gives wrong results in general, and may lead to a segmentation fault, because the index from the list for the second selection is used to get an element from the first list (instead of being used directly) - which may be incorrect or end up beyond the end of that one. In pseudocode:

container_var1 = [ .2, .3 ]
# length of original collection: 2, only the second passes the first selection (and also the second)
sel1_indices = [ 1 ]
sel2_indices = [ 1 ]
container_var1[sel1_indices[sel2_indices[0]]] ## WRONG: out of bounds of sel1_indices
container_var1[sel2_indices[0]] ## correct
Edited by Pieter David

Merge request reports