How to create a new object with awkward? #1507
Replies: 2 comments 4 replies
-
First things's first, I'd import awkward as ak
jet = ak.zip({
'pt': events.SelectedJet_pt,
'eta': events.SelectedJet_eta,
'phi': events.SelectedJet_phi,
'mass': events.SelectedJet_mass,
}) The import vector
jet = vector.zip({
'pt': events.SelectedJet_pt,
'eta': events.SelectedJet_eta,
'phi': events.SelectedJet_phi,
'mass': events.SelectedJet_mass,
}) Note that, vector.register_awkward()
jet = ak.zip({
'pt': events.SelectedJet_pt,
'eta': events.SelectedJet_eta,
'phi': events.SelectedJet_phi,
'mass': events.SelectedJet_mass,
}, with_name="Momentum4D") To solve your problem, we don't need this behaviour, because you just want the invariant mass. But, it's helpful to use it in case you later decide to do something more complex. The subsequent solutions will make use of four_jet = jet[ak.num(jet, axis=-1) >= 4] To explore all of the pairwise combinations of the jets, you can use pair = ak.combinations(four_jet, axis=1, n=2) Then you can add together the four vectors to compute the boson vector boson = pair.slot0 + pair.slot1 With the w_boson_mass = ...
delta_mass = np.abs(boson.mass - w_boson_mass) Then, finally, we can pull out the boson with the shortest mass. i_best = ak.argmin(
delta_mass,
axis=-1,
keepdims=True
)
w_boson = boson[i_best] |
Beta Was this translation helpful? Give feedback.
-
Just linking everything together, so that we can see what you've tried and what's working/not working: |
Beta Was this translation helpful? Give feedback.
-
Hi experts,
I read the jets kinematic from a root file, and save it as an awkward array. And it's a jagged array, every event has different numbers of jets. How can I combine two of those jets in each event to be a new object(W boson), and then choose the one closest to the W inv mass in each event and save it in the event array as a new object called "W"?
Beta Was this translation helpful? Give feedback.
All reactions