mt2 - Stransverse Mass Computation as a NumPy UFunc
raw JSON → 1.3.1 verified Fri May 01 auth: no python
mt2 provides a fast, numerically stable computation of the stransverse mass (M_T2) as a NumPy universal function (ufunc). It is commonly used in high-energy physics for SUSY searches and dilepton event analysis. Current version: 1.3.1, with release cadence approximately every 3-4 months. Requires Python >=3.9.
pip install mt2 Common errors
error ModuleNotFoundError: No module named 'mt2' ↓
cause The package is not installed or installed in an incorrect environment.
fix
Run
pip install mt2 or conda install -c conda-forge mt2. error ImportError: numpy.core.multiarray failed to import ↓
cause A version mismatch between numpy and mt2 (e.g., numpy 2.0.0 with mt2 <1.2.1).
fix
Upgrade mt2 to >=1.2.1 and ensure numpy is compatible:
pip install 'mt2>=1.2.1'. error ValueError: operands could not be broadcast together with shapes ↓
cause Input arrays have incompatible shapes. mt2 expects either scalar or 1D arrays of same length or broadcastable shapes.
fix
Reshape inputs to have consistent leading dimensions, ensuring pa, pb, pt_miss are all 1D arrays of same length or broadcastable.
error AssertionError: Invalid input dimensions ↓
cause pa or pb must have exactly 3 elements (px, py, m) and pt_miss exactly 2 elements (px, py). This error arises from wrong shape.
fix
Check shapes: pa.shape == (3,), pb.shape == (3,), pt_miss.shape == (2,). For arrays, ensure last dimension is correct.
Warnings
breaking In v1.2.1, numpy 2.0 compatibility was fixed. Older versions (pre-1.2.1) may fail with numpy 2.0. ↓
fix Upgrade to mt2>=1.2.1 and ensure numpy is compatible (numpy>=1.23,<2.1 recommended).
breaking In v1.2.2, the Python source code was moved to src/mt2 to avoid import confusion. Direct imports from the old location (e.g., import mt2 as before) still work, but any references to internal modules may break. ↓
fix Use standard `import mt2`. If you relied on internal paths, adjust imports accordingly.
deprecated In v1.2.0, the function signature changed: the argument order was updated for consistency. Old code using positional arguments may break. ↓
fix Use keyword arguments or check the new signature: mt2(pa, pb, pt_miss, m_invis, ...).
gotcha The `pt_miss` vector must have exactly 2 elements (px, py). Providing a 3-element vector (e.g., (px, py, m)) will cause an error. ↓
fix Ensure pt_miss is a 1D array of length 2. Use e.g. np.array([px, py]).
gotcha Negative masses in input are clipped to zero in v1.3.0 and later. In earlier versions, negative masses might produce undefined results or errors. ↓
fix Upgrade to >=1.3.0 or explicitly clip negative masses to zero before passing to mt2.
Install
conda install -c conda-forge mt2 Imports
- mt2
import mt2
Quickstart
import numpy as np
import mt2
# Define transverse momenta and masses
pa = np.array([100.0, 50.0, 0.0]) # (px, py, m) for visible particle a
pb = np.array([80.0, -30.0, 0.0]) # (px, py, m) for visible particle b
pt_miss = np.array([20.0, 10.0]) # missing transverse momentum (px, py)
m_invis = 0.0 # mass of the invisible particle
# Compute M_T2
result = mt2.mt2(pa, pb, pt_miss, m_invis)
print(f"M_T2 = {result:.2f}")