|
| 1 | +# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner. |
| 2 | +# |
| 3 | +# Distributed under the 3-clause BSD license, see accompanying file LICENSE |
| 4 | +# or https://github.com/scikit-hep/vector for details. |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +import vector |
| 9 | + |
| 10 | +# If ROOT is not available, skip these tests. |
| 11 | +ROOT = pytest.importorskip("ROOT") |
| 12 | + |
| 13 | +# ROOT.Math.PxPyPzEVector constructor arguments to get all the weird cases. |
| 14 | +constructor = [ |
| 15 | + (0, 0, 0, 0), |
| 16 | + (0, 0, 0, 10), |
| 17 | + (0, 0, 0, -10), |
| 18 | + (1, 2, 3, 0), |
| 19 | + (1, 2, 3, 10), |
| 20 | + (1, 2, 3, -10), |
| 21 | + (1, 2, 3, 2.5), |
| 22 | + (1, 2, 3, -2.5), |
| 23 | +] |
| 24 | + |
| 25 | +# Coordinate conversion methods to apply to the VectorObject4D. |
| 26 | +coordinates = [ |
| 27 | + "to_xyzt", |
| 28 | + "to_xythetat", |
| 29 | + "to_xyetat", |
| 30 | + "to_rhophizt", |
| 31 | + "to_rhophithetat", |
| 32 | + "to_rhophietat", |
| 33 | + "to_xyztau", |
| 34 | + "to_xythetatau", |
| 35 | + "to_xyetatau", |
| 36 | + "to_rhophiztau", |
| 37 | + "to_rhophithetatau", |
| 38 | + "to_rhophietatau", |
| 39 | +] |
| 40 | + |
| 41 | + |
| 42 | +# Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. |
| 43 | +@pytest.mark.parametrize("constructor", constructor) |
| 44 | +@pytest.mark.parametrize("coordinates", coordinates) |
| 45 | +def test_M2(constructor, coordinates): |
| 46 | + assert ROOT.Math.PxPyPzEVector(*constructor).M2() == pytest.approx( |
| 47 | + getattr( |
| 48 | + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates |
| 49 | + )().tau2 |
| 50 | + ) |
| 51 | + |
| 52 | + |
| 53 | +# Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. |
| 54 | +@pytest.mark.parametrize("constructor", constructor) |
| 55 | +@pytest.mark.parametrize("coordinates", coordinates) |
| 56 | +def test_M(constructor, coordinates): |
| 57 | + assert ROOT.Math.PxPyPzEVector(*constructor).M() == pytest.approx( |
| 58 | + getattr( |
| 59 | + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates |
| 60 | + )().tau |
| 61 | + ) |
| 62 | + |
| 63 | + |
| 64 | +# etc. |
0 commit comments