Kinematics Quickstart¶
This notebook shows basic usage of the kinematic helpers with both scalar and vectorized inputs.
In [ ]:
Copied!
import numpy as np
from analysis_helpers.kinematics import momentum, pt, pseudorapidity, phi, distance
import numpy as np
from analysis_helpers.kinematics import momentum, pt, pseudorapidity, phi, distance
Scalar example¶
In [ ]:
Copied!
px, py, pz = 1200.0, -350.0, 5100.0
print('p =', round(momentum(px, py, pz), 3))
print('pt =', round(pt(px, py), 3))
print('eta =', round(pseudorapidity(px, py, pz), 3))
print('phi =', round(phi(px, py, pz), 3))
px, py, pz = 1200.0, -350.0, 5100.0
print('p =', round(momentum(px, py, pz), 3))
print('pt =', round(pt(px, py), 3))
print('eta =', round(pseudorapidity(px, py, pz), 3))
print('phi =', round(phi(px, py, pz), 3))
Vectorized example¶
The helpers also work naturally on NumPy arrays.
In [ ]:
Copied!
px_arr = np.array([500.0, 900.0, 1300.0])
py_arr = np.array([200.0, -100.0, 300.0])
pz_arr = np.array([2000.0, 4500.0, 6200.0])
print('p =', np.round(momentum(px_arr, py_arr, pz_arr), 2))
print('pt =', np.round(pt(px_arr, py_arr), 2))
print('eta =', np.round(pseudorapidity(px_arr, py_arr, pz_arr), 3))
print('phi =', np.round(phi(px_arr, py_arr, pz_arr), 3))
px_arr = np.array([500.0, 900.0, 1300.0])
py_arr = np.array([200.0, -100.0, 300.0])
pz_arr = np.array([2000.0, 4500.0, 6200.0])
print('p =', np.round(momentum(px_arr, py_arr, pz_arr), 2))
print('pt =', np.round(pt(px_arr, py_arr), 2))
print('eta =', np.round(pseudorapidity(px_arr, py_arr, pz_arr), 3))
print('phi =', np.round(phi(px_arr, py_arr, pz_arr), 3))
Geometry helper¶
In [ ]:
Copied!
pv = np.array([0.12, -0.03, 0.40])
sv = np.array([0.35, 0.07, 8.95])
flight_distance = distance(pv[0], pv[1], pv[2], sv[0], sv[1], sv[2])
print('flight distance =', round(flight_distance, 4))
pv = np.array([0.12, -0.03, 0.40])
sv = np.array([0.35, 0.07, 8.95])
flight_distance = distance(pv[0], pv[1], pv[2], sv[0], sv[1], sv[2])
print('flight distance =', round(flight_distance, 4))