Skip to content

Commit

Permalink
Compare vector results with ROOT's.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpivarski committed Mar 17, 2021
1 parent 64ad9ae commit 498d27f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 12 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 64 additions & 0 deletions tests/root/test_PxPyPzEVector.py
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 498d27f

Please sign in to comment.