Stransverse mass computation as a numpy ufunc.

Project description

This package may be used to evaluate MT2 in all its variants. This includes both symmetric and asymmetric MT2. MT2 is also known as the “stransverse mass”.

This package provides an interface to the bisection algorithm of http://arxiv.org/abs/1411.4312, via an implementation detailed below. The variable MT2 itself is described here. Related information may be found in papers relating to MT2 linked from here.

Getting started

Install from pip:

pip install mt2

One can then compute MT2 as follows; here for the “symmetric” case, where both invisible particles have the same mass:

from mt2 import mt2

# The units of all quantities are the same, e.g. GeV
val = mt2(
100, 410, 20,  # Visible 1: mass, px, py
150, -210, -300,  # Visible 2: mass, px, py
-200, 280,  # Missing transverse momentum: x, y
100, 100)  # Invisible 1 mass, invisible 2 mass
print("Expected mT2 = 412.628.  Computed mT2 = ", val)

Examples

Vectorisation

The mt2 function supports broadcasting over its arguments if they are array-like. For example, one could scan over a grid of invisible particle masses like so:

n1 = 20
n2 = 20
mass_1 = numpy.linspace(10, 200, n1).reshape((-1, 1))
mass_2 = numpy.linspace(10, 200, n2).reshape((1, -1))

# val has shape (n1, n2)
val = mt2(
100, 410, 20,  # Visible 1: mass, px, py
150, -210, -300,  # Visible 2: mass, px, py
-200, 280,  # Missing transverse momentum: x, y
mass_1, mass_2)  # Invisible 1 mass, invisible 2 mass

Note on performance

With full precision, the main reason to use vectorisation as above is convenience. The time spent in the C++ MT2 calculation is somewhat larger than the overhead introduced by a Python for loop. Vectorising can give a runtime reduction of ⪅30% in this case.

However, the benefit can be more significant when using a lower precision. This corresponds to a larger value for the desired_precision_on_mt2 argument. This is because less time is spent in C++, so proportionally the Python overhead of a for loop is more significant.

Toy MC

A fun example using a toy Monte-Carlo simulation can be viewed in this notebook

Other notes

For further information, see the documentation:

help(mt2)

Also exported is mt2_ufunc. This is the raw implementation as a numpy ufunc. Usage is the same as for mt2, but it supports some additional arguments, like where. The reader should refer to the numpy documentation for a description of these.

Implementation

The underlying implementation of the Lester-Nachman algorithm used in this package is by Rupert Tombs, found in src/mt2_bisect.h. It provides results consistent with the implementation provided with http://arxiv.org/abs/1411.4312, but is 3x to 4x faster. Note that this does not implement the “deci-sectioning” described in the paper, since it is found to provide a more significant performance penalty in the majority of cases. Our version is also scale invariant, and is suitable for large ranges of input magnitude.

The legacy implementation, as it appears on arXiv, is also wrapped and exposed as mt2_arxiv for those that wish to independently cross-check the re-implementation. If you find any discrepancies, please file a bug report! We strongly encourage all users to use the primary mt2 method, due to the higher performance and scale invariance.

Performance

The default installation method via pip uses a precompiled wheel for your platform. If you wish to compile from source for your platform, you could instead install like so:

pip install mt2 --no-binary :all:

Since this can allow use of newer compilers, and code more optimised for your architecture, this can give a small speedup. On the author’s computer, there was 1% runtime reduction as measured with examples/benchmark.py.

All files other than src/lester_mt2_bisect_v7.h and src/mt2_Lallyver2.h are released under the MIT license.

Other implementations

A list of alternative implementations of the MT2 calculation can be found here:

https://www.hep.phy.cam.ac.uk/~lester/mt2/#Alternatives

In Python, the other wrapper of the same algorithm known to the authors is by Nikolai Hartmann, here: https://gitlab.cern.ch/nihartma/pymt2

Authors

• @kesterlester: Original C++ implementation of mT2.

• @rupt: Current C++ implementation used in this package.

• @tpgillam: Python packaging

Project details

Source Distribution

mt2-1.2.2.tar.gz (36.0 kB view hashes)

Uploaded Source

Built Distributions

mt2-1.2.2-cp312-cp312-win_amd64.whl (53.1 kB view hashes)

Uploaded CPython 3.12 Windows x86-64

mt2-1.2.2-cp312-cp312-win32.whl (52.6 kB view hashes)

Uploaded CPython 3.12 Windows x86

mt2-1.2.2-cp312-cp312-musllinux_1_2_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ x86-64

mt2-1.2.2-cp312-cp312-musllinux_1_2_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.12 musllinux: musl 1.2+ i686

mt2-1.2.2-cp312-cp312-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (119.2 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

mt2-1.2.2-cp312-cp312-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (109.1 kB view hashes)

Uploaded CPython 3.12 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

mt2-1.2.2-cp312-cp312-macosx_11_0_arm64.whl (50.4 kB view hashes)

Uploaded CPython 3.12 macOS 11.0+ ARM64

mt2-1.2.2-cp312-cp312-macosx_10_9_universal2.whl (72.0 kB view hashes)

Uploaded CPython 3.12 macOS 10.9+ universal2 (ARM64, x86-64)

mt2-1.2.2-cp311-cp311-win_amd64.whl (53.1 kB view hashes)

Uploaded CPython 3.11 Windows x86-64

mt2-1.2.2-cp311-cp311-win32.whl (52.5 kB view hashes)

Uploaded CPython 3.11 Windows x86

mt2-1.2.2-cp311-cp311-musllinux_1_2_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ x86-64

mt2-1.2.2-cp311-cp311-musllinux_1_2_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.11 musllinux: musl 1.2+ i686

mt2-1.2.2-cp311-cp311-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.8 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

mt2-1.2.2-cp311-cp311-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (108.6 kB view hashes)

Uploaded CPython 3.11 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

mt2-1.2.2-cp311-cp311-macosx_11_0_arm64.whl (50.4 kB view hashes)

Uploaded CPython 3.11 macOS 11.0+ ARM64

mt2-1.2.2-cp311-cp311-macosx_10_9_universal2.whl (72.0 kB view hashes)

Uploaded CPython 3.11 macOS 10.9+ universal2 (ARM64, x86-64)

mt2-1.2.2-cp310-cp310-win_amd64.whl (53.1 kB view hashes)

Uploaded CPython 3.10 Windows x86-64

mt2-1.2.2-cp310-cp310-win32.whl (52.5 kB view hashes)

Uploaded CPython 3.10 Windows x86

mt2-1.2.2-cp310-cp310-musllinux_1_2_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ x86-64

mt2-1.2.2-cp310-cp310-musllinux_1_2_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.10 musllinux: musl 1.2+ i686

mt2-1.2.2-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.6 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

mt2-1.2.2-cp310-cp310-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (108.5 kB view hashes)

Uploaded CPython 3.10 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

mt2-1.2.2-cp310-cp310-macosx_11_0_arm64.whl (50.4 kB view hashes)

Uploaded CPython 3.10 macOS 11.0+ ARM64

mt2-1.2.2-cp310-cp310-macosx_10_9_universal2.whl (72.0 kB view hashes)

Uploaded CPython 3.10 macOS 10.9+ universal2 (ARM64, x86-64)

mt2-1.2.2-cp39-cp39-win_amd64.whl (53.1 kB view hashes)

Uploaded CPython 3.9 Windows x86-64

mt2-1.2.2-cp39-cp39-win32.whl (52.6 kB view hashes)

Uploaded CPython 3.9 Windows x86

mt2-1.2.2-cp39-cp39-musllinux_1_2_x86_64.whl (1.1 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ x86-64

mt2-1.2.2-cp39-cp39-musllinux_1_2_i686.whl (1.2 MB view hashes)

Uploaded CPython 3.9 musllinux: musl 1.2+ i686

mt2-1.2.2-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (118.6 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.17+ x86-64

mt2-1.2.2-cp39-cp39-manylinux_2_12_i686.manylinux2010_i686.manylinux_2_17_i686.manylinux2014_i686.whl (108.5 kB view hashes)

Uploaded CPython 3.9 manylinux: glibc 2.12+ i686 manylinux: glibc 2.17+ i686

mt2-1.2.2-cp39-cp39-macosx_11_0_arm64.whl (50.4 kB view hashes)

Uploaded CPython 3.9 macOS 11.0+ ARM64

mt2-1.2.2-cp39-cp39-macosx_10_9_universal2.whl (72.0 kB view hashes)

Uploaded CPython 3.9 macOS 10.9+ universal2 (ARM64, x86-64)