Combinations within an array of p4 vectors #107
-
Hi, I have an array of p4 vectors and I am trying to calculate the DeltaR between all vectors in the array. I build the array like this:
for each event in a ROOT file. For now, there are exactly 6 entries in the array but this may vary later. The output is a list of these arrays. Then, I try to find the combinations of pairs but I get an error when running the following code:
The error is as follows:
Any advice on how to handle this? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 8 replies
-
The default If I'm interpreting the data type correctly, Instead of putting this inside an event loop, collect all your data as lists of vectors in all events (one list per event). Then call Here's an example of doing that without having to create a bunch of Python objects (which use a lot of memory). It uses ak.ArrayBuilder: builder = ak.ArrayBuilder()
for event in events:
sixb_pt = event["sixb_pt"] # however you get these from the events
sixb_eta = event["sixb_eta"]
sixb_phi = event["sixb_phi"]
with builder.list():
for pt, eta, phi in zip(sixb_pt, sixb_eta, sixb_phi):
with builder.record("Momentum4D"): # not MomentumObject4D
builder.field("pt"); builder.real(pt)
builder.field("eta"); builder.real(eta)
builder.field("phi"); builder.real(phi)
signal_p4 = builder.snapshot()
combos = ak.combinations(signal_p4, 2)
lefts, rights = ak.unzip(combos)
deltaRs = lefts.deltaR(rights) (The name of the record type is not "MomentumObject4D" because it is not a Python object.) |
Beta Was this translation helpful? Give feedback.
The default
axis
for ak.combinations is 1 because a typical use-case is lists of particles per event. I don't think that's the data type you're building—sincesignal
consists of records ({"pt": pt, "eta": eta, "phi": phi, "mass": mass}
) and not lists of records,axis=1
is beyond the depth of this array.If I'm interpreting the data type correctly,
axis=0
would work for this array, but the idea is not to find all combinations of particles in a single event, it's to find all combinations of particles in all events, with a single function call.Instead of putting this inside an event loop, collect all your data as lists of vectors in all events (one list per event). Then call
ak.combinations
…