From 498d27f8655a17e8429c6b7de13f5718538908ae Mon Sep 17 00:00:00 2001 From: Jim Pivarski Date: Wed, 17 Mar 2021 09:51:09 -0500 Subject: [PATCH] Compare vector results with ROOT's. --- .github/workflows/ci.yml | 24 ++++++------ tests/root/test_PxPyPzEVector.py | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 tests/root/test_PxPyPzEVector.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 04c66cc6..e73eb111 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -34,20 +34,20 @@ jobs: - name: Test package run: python -m pytest -ra - # root: - # runs-on: ubuntu-latest - # steps: - # - uses: actions/checkout@v2 + root: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 - # - name: Get Conda - # uses: conda-incubator/setup-miniconda@v2 - # with: - # environment-file: environment.yml - # activate-environment: vector + - name: Get Conda + uses: conda-incubator/setup-miniconda@v2 + with: + environment-file: environment.yml + activate-environment: vector - # - name: Run tests - # shell: "bash -l {0}" - # run: python -m pytest tests/root_tests -ra + - name: Run tests + shell: "bash -l {0}" + run: python -m pytest tests/root -ra dist: runs-on: ubuntu-20.04 diff --git a/tests/root/test_PxPyPzEVector.py b/tests/root/test_PxPyPzEVector.py new file mode 100644 index 00000000..2ba0491c --- /dev/null +++ b/tests/root/test_PxPyPzEVector.py @@ -0,0 +1,64 @@ +# Copyright (c) 2019-2021, Jonas Eschle, Jim Pivarski, Eduardo Rodrigues, and Henry Schreiner. +# +# Distributed under the 3-clause BSD license, see accompanying file LICENSE +# or https://github.com/scikit-hep/vector for details. + +import pytest + +import vector + +# If ROOT is not available, skip these tests. +ROOT = pytest.importorskip("ROOT") + +# ROOT.Math.PxPyPzEVector constructor arguments to get all the weird cases. +constructor = [ + (0, 0, 0, 0), + (0, 0, 0, 10), + (0, 0, 0, -10), + (1, 2, 3, 0), + (1, 2, 3, 10), + (1, 2, 3, -10), + (1, 2, 3, 2.5), + (1, 2, 3, -2.5), +] + +# Coordinate conversion methods to apply to the VectorObject4D. +coordinates = [ + "to_xyzt", + "to_xythetat", + "to_xyetat", + "to_rhophizt", + "to_rhophithetat", + "to_rhophietat", + "to_xyztau", + "to_xythetatau", + "to_xyetatau", + "to_rhophiztau", + "to_rhophithetatau", + "to_rhophietatau", +] + + +# Run a test that compares ROOT's 'M2()' with vector's 'tau2' for all cases. +@pytest.mark.parametrize("constructor", constructor) +@pytest.mark.parametrize("coordinates", coordinates) +def test_M2(constructor, coordinates): + assert ROOT.Math.PxPyPzEVector(*constructor).M2() == pytest.approx( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates + )().tau2 + ) + + +# Run a test that compares ROOT's 'M()' with vector's 'tau' for all cases. +@pytest.mark.parametrize("constructor", constructor) +@pytest.mark.parametrize("coordinates", coordinates) +def test_M(constructor, coordinates): + assert ROOT.Math.PxPyPzEVector(*constructor).M() == pytest.approx( + getattr( + vector.obj(**dict(zip(["x", "y", "z", "t"], constructor))), coordinates + )().tau + ) + + +# etc.