how to add two LorentzVector? #205
Replies: 1 comment 4 replies
-
@Saransh-cpp, this is a problem with the >>> import awkward as ak
>>> pt = ak.Array([[1, 2], [], [3]])
>>> eta = ak.Array([[1, 2], [], [3]])
>>> phi = ak.Array([[1, 2], [], [3]])
>>> mass = ak.Array([[1, 2], [], [3]]) then what I want to create is three lists of vectors, two in the first list and one in the last. But >>> wrong_types = vector.awk({"pt": pt, "eta": eta, "phi": phi, "mass": mass})
>>> print(wrong_types.type)
3 * Momentum4D["rho": var * int64, "phi": var * int64, "eta": var * int64, "tau": var * int64] This is three vectors, and the attributes have list type. Components of vectors may be integers or floats, but they shouldn't be allowed to be lists! What we really wanted in this case was the ak.zip of these four jagged arrays: >>> right_types = vector.awk(ak.zip({"pt": pt, "eta": eta, "phi": phi, "mass": mass}))
>>> print(right_types.type)
3 * var * Momentum4D["rho": int64, "phi": int64, "eta": int64, "tau": int64] so that we now have three lists of vectors. The problem (which @ZhenxuanZhang-Jensen ran into) is that Note: with this correction, it's possible to add vectors. >>> right_types[0, 1] + right_types[2, 0]
<MomentumRecord4D ... phi: 2.61, eta: 2.83, tau: 6.57} type='Momentum4D["rho": f...'> The object and NumPy backends do type-checking. The Awkward Array backend is harder to check like that (if the vectors are buried inside a data structure, they're not represented by a Python type, so we can't run code to check their correctness; also, we don't want correctness checks after every slice!). However, this We wouldn't want the fields of vectors to be boolean or complex, either. (I don't think the object or NumPy backends check that, though.) |
Beta Was this translation helpful? Give feedback.
-
I am trying to add two jets together to form a W boson in the >=4 jets category. I load a paquent file, and the events['SelectedJet_*'] type are all
awkward.highlevel.Array
and I write like:And the last line has a bug : ValueError: cannot broadcast records in this type of operation
Is this mean I don't use the Momentum4D in the right way? how can I fix this? thanks
Beta Was this translation helpful? Give feedback.
All reactions