Use when working in Python with scikit-hep vector and Awkward Array to build vector records, register behaviors, compute deltaR or invariant masses, combine or boost vectors, or access vector properties from ak.zip records of type (Momentum3D/Momentum4D/Vector4D). Vector is only useful if you are also using Awkward.
Create Awkward Arrays that behave like vector objects and use vector methods without writing custom kinematic math. Use these steps to register behaviors, build records with the right field names, and perform common HEP operations like deltaR and invariant mass.
import vector
vector.register_awkward()
import awkward as ak
events = ak.Array({
"electron": ak.zip(
{"pt": [50.0, 30.2], "eta": [1.4, -0.8], "phi": [2.1, 0.5], "mass": [0.0005, 0.0005]},
with_name="Momentum4D",
)
})
ak.zip(..., with_name="Momentum3D") for 3D operations like deltaR.ak.zip(..., with_name="Momentum4D") for 4D operations like invariant mass or boosts.pt/eta/phi/mass or px/py/pz/E so vector can infer coordinate systems.vector.register_awkward() before accessing vector properties or methods.particles = ak.zip({"px": px, "py": py, "pz": pz, "E": E}, with_name="Vector4D")
particles.pt
particles.phi
particles.eta
particles.mass
Calculate deltaR between two collections:
pairs = ak.cartesian([events.electron, events.muon])
electrons, muons = ak.unzip(pairs)
dR = electrons.deltaR(muons)
Combine 4-vectors and compute invariant mass:
first_e, second_e = ak.unzip(ak.combinations(events.electron, 2))
inv_mass = (first_e + second_e).mass
Boost to a parent rest frame:
parent = particle1 + particle2
particle1_rf = particle1.boostCM_of_p4(parent)
Load references/vector-hints.md for more examples, method notes, and advanced snippets.