Skip to content

Commit b5fd8b4

Browse files
jpivarskiianna
authored andcommitted
Compare vector results with ROOT's.
1 parent f19f856 commit b5fd8b4

File tree

2 files changed

+69
-5
lines changed

2 files changed

+69
-5
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ jobs:
7575
# steps:
7676
# - uses: actions/checkout@v2
7777

78-
# - name: Get Conda
79-
# uses: conda-incubator/setup-miniconda@v2
80-
# with:
81-
# environment-file: environment.yml
82-
# activate-environment: vector
78+
- name: Get Conda
79+
uses: conda-incubator/setup-miniconda@v2
80+
with:
81+
environment-file: environment.yml
82+
activate-environment: vector
8383

8484
# - name: Run tests
8585
# shell: "bash -l {0}"

tests/root/test_PxPyPzEVector.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)