Possible to have a view of a MomentumObject4D with pt, eta, phi, m ? #324
-
Somewhat motivated by poking on scikit-hep/fastjet#182 I've noticed that if I construct a Is there another API to do this? If not, is this intentional and I'm missing something? import awkward as ak
import fastjet
import vector
jetdef = fastjet.JetDefinition(fastjet.kt_algorithm, 0.6)
array = ak.Array(
[
{"px": 1.2, "py": 3.2, "pz": 5.4, "E": 2.5, "ex": 0.78},
{"px": 32.2, "py": 64.21, "pz": 543.34, "E": 24.12, "ex": 0.35},
{"px": 32.45, "py": 63.21, "pz": 543.14, "E": 24.56, "ex": 0.0},
],
)
cluster = fastjet.ClusterSequence(array, jetdef)
inclusive_jets = cluster.inclusive_jets()
print(f"{inclusive_jets=}")
four_vector = vector.obj(**inclusive_jets[0].tolist())
print(f"{four_vector=}")
# Have ability to get pt, eta, phi, m as attributes
print(
f"(pt, eta, phi, m): {four_vector.pt, four_vector.eta, four_vector.phi, four_vector.m}"
)
print(f"{four_vector.to_rhophithetatau()=}") # This exists
# print(f"{four_vector.to_ptetaphim()=}") # This API doesn't exist so can't get something
# Nonsense numbers
# but this works with pt eta phi m keys
# c.f. https://github.com/scikit-hep/fastjet/issues/182
pt_eta_phi_m_record_array = ak.Array(
[{"pt": 1.1, "eta": 2.1, "phi": 3.1, "m": 4.1, "ex": 0.78}],
with_name="Momentum4D",
behavior=vector.backends.awkward.behavior,
) $ python example.py
#--------------------------------------------------------------------------
# FastJet release 3.4.0
# M. Cacciari, G.P. Salam and G. Soyez
# A software package for jet finding and analysis at colliders
# http://fastjet.fr
#
# Please cite EPJC72(2012)1896 [arXiv:1111.6097] if you use this package
# for scientific work and optionally PLB641(2006)57 [hep-ph/0512210].
#
# FastJet is provided without warranty under the GNU GPL v2 or higher.
# It uses T. Chan's closest pair algorithm, S. Fortune's Voronoi code,
# CGAL and 3rd party plugin jet algorithms. See COPYING file for details.
#--------------------------------------------------------------------------
inclusive_jets=<Array [{px: 64.7, py: 127, pz: ..., ...}, ...] type='2 * Momentum4D[px: fl...'>
four_vector=MomentumObject4D(px=64.65, py=127.41999999999999, pz=1086.48, E=48.68)
(pt, eta, phi, m): (142.88274528437645, 2.726117171791057, 1.1012644074821902, -1094.7531808129172)
four_vector.to_rhophithetatau()=MomentumObject4D(pt=142.88274528437645, phi=1.1012644074821902, theta=0.1307594047706852, mass=-1094.7531808129172) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
vector automatically converts generic type coordinates to momentum type and vice versa when needed. So, for example - In [1]: import vector
In [2]: v = vector.obj(px=1, py=2, pz=3, E=4)
In [3]: v
Out[3]: MomentumObject4D(px=1, py=2, pz=3, E=4)
In [4]: v.to_rhophietat()
Out[4]: MomentumObject4D(pt=2.23606797749979, phi=1.1071487177940904, eta=1.103586841560145, E=4)
In [5]: v.to_rhophietatau()
Out[5]: MomentumObject4D(pt=2.23606797749979, phi=1.1071487177940904, eta=1.103586841560145, mass=1.4142135623730951) Similar to your example, vector understands that if a user calls The missing API is not an intentional behavior. In fact, there is an issue open for this - #168, but users can still accomplish the conversion without explicitly using the Momentum type methods. This behavior is not limited to In [1]: import vector
In [2]: v = vector.obj(px=1, py=2)
In [3]: v
Out[3]: MomentumObject2D(px=1, py=2)
In [4]: v.to_Vector3D(z=4)
Out[4]: MomentumObject3D(px=1, py=2, pz=4)
In [5]: v.to_Vector4D(z=4, tau=5)
Out[5]: MomentumObject4D(px=1, py=2, pz=4, mass=5) |
Beta Was this translation helpful? Give feedback.
vector automatically converts generic type coordinates to momentum type and vice versa when needed. So, for example -
Similar to your example, vector understands that if a user calls
to_rhophietatau
orto_rhophietat
on aMomentumVector
, it must automatically usept
instead ofphi
andmass
/E
inste…