Skip to content

Commit

Permalink
Tests and docs for deltaRapidityPhi (#187)
Browse files Browse the repository at this point in the history
* Tests for deltaRapidityPhi and deltaRapidityPhi2

* Docs for deltaRapidityPhi and deltaRapidityPhi2
  • Loading branch information
raymondEhlers committed Apr 22, 2022
1 parent 51ef936 commit b9c60a8
Show file tree
Hide file tree
Showing 5 changed files with 262 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,8 @@ The (current) list of properties and methods is:
* `tau` (`M`, `mass`): see note above
* `tau2` (`M2`, `mass2`)
* `beta`: scalar(s) between $0$ (inclusive) and $1$ (exclusive, unless the vector components are infinite)
* `deltaRapidityPhi`: $Delta R_{\mbox{rapidity}} = \Delta\phi^2 + \Delta \mbox{rapidity}^2$
* `deltaRapidityPhi2`: the above, squared
* `gamma`: scalar(s) between $1$ (inclusive) and $\infty$
* `rapidity`: scalar(s) between $0$ (inclusive) and $\infty$
* `boost_p4(four_vector)`: change coordinate system using another 4D vector as the difference
Expand Down
18 changes: 18 additions & 0 deletions docs/api/vector._compute.lorentz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,24 @@ vector.\_compute.lorentz.boost\_p4 module
:show-inheritance:
:private-members:

vector.\_compute.lorentz.deltaRapidityPhi module
--------------------------------------

.. automodule:: vector._compute.lorentz.deltaRapidityPhi
:members:
:undoc-members:
:show-inheritance:
:private-members:

vector.\_compute.lorentz.deltaRapidityPhi2 module
---------------------------------------

.. automodule:: vector._compute.lorentz.deltaRapidityPhi2
:members:
:undoc-members:
:show-inheritance:
:private-members:

vector.\_compute.lorentz.dot module
-----------------------------------

Expand Down
2 changes: 2 additions & 0 deletions docs/usage/intro.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2310,6 +2310,8 @@
" * `tau` (`M`, `mass`): see note above\n",
" * `tau2` (`M2`, `mass2`)\n",
" * `beta`: scalar(s) between $0$ (inclusive) and $1$ (exclusive, unless the vector components are infinite)\n",
" * `deltaRapidityPhi`: $Delta R_{\mbox{rapidity}} = \Delta\phi^2 + \Delta \mbox{rapidity}^2$\n",
" * `deltaRapidityPhi2`: the above, squared\n",
" * `gamma`: scalar(s) between $1$ (inclusive) and $\\infty$\n",
" * `rapidity`: scalar(s) between $0$ (inclusive) and $\\infty$\n",
" * `boost_p4(four_vector)`: change coordinate system using another 4D vector as the difference\n",
Expand Down
120 changes: 120 additions & 0 deletions tests/compute/lorentz/test_deltaRapidityPhi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# 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 numpy
import pytest

import vector._backends.numpy_
import vector._backends.object_


def test_lorentz_object():
v1 = vector._backends.object_.MomentumObject4D(
vector._backends.object_.AzimuthalObjectXY(1.0, 1.0),
vector._backends.object_.LongitudinalObjectZ(1.0),
vector._backends.object_.TemporalObjectTau(1.0),
)
v2 = vector._backends.object_.MomentumObject4D(
vector._backends.object_.AzimuthalObjectXY(-1.0, -1.0),
vector._backends.object_.LongitudinalObjectZ(-1.0),
vector._backends.object_.TemporalObjectTau(1.0),
)
expected_result = numpy.sqrt(
# phi
numpy.pi**2
# rapidity
+ ((0.5 * numpy.log(3 / 1) - 0.5 * numpy.log(1 / 3)) ** 2)
)
assert v1.deltaRapidityPhi(v2) == pytest.approx(expected_result)

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
for t2 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tr1, tr2 = getattr(v1, "to_" + t1)(), getattr(v2, "to_" + t2)()
assert tr1.deltaRapidityPhi(tr2) == pytest.approx(expected_result)


def test_lorentz_numpy():
v1 = vector._backends.numpy_.VectorNumpy4D(
[(1.0, 1.0, 1.0, 1.0)],
dtype=[
("x", numpy.float64),
("y", numpy.float64),
("z", numpy.float64),
("tau", numpy.float64),
],
)
v2 = vector._backends.numpy_.VectorNumpy4D(
[(-1.0, -1.0, -1.0, 1.0)],
dtype=[
("x", numpy.float64),
("y", numpy.float64),
("z", numpy.float64),
("tau", numpy.float64),
],
)
expected_result = numpy.sqrt(
# phi
numpy.pi**2
# rapidity
+ ((0.5 * numpy.log(3 / 1) - 0.5 * numpy.log(1 / 3)) ** 2)
)
assert v1.deltaRapidityPhi(v2) == pytest.approx(expected_result)

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
for t2 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tr1, tr2 = getattr(v1, "to_" + t1)(), getattr(v2, "to_" + t2)()
assert numpy.allclose(tr1.deltaRapidityPhi(tr2), expected_result)
120 changes: 120 additions & 0 deletions tests/compute/lorentz/test_deltaRapidityPhi2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# 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 numpy
import pytest

import vector._backends.numpy_
import vector._backends.object_


def test_lorentz_object():
v1 = vector._backends.object_.MomentumObject4D(
vector._backends.object_.AzimuthalObjectXY(1.0, 1.0),
vector._backends.object_.LongitudinalObjectZ(1.0),
vector._backends.object_.TemporalObjectTau(1.0),
)
v2 = vector._backends.object_.MomentumObject4D(
vector._backends.object_.AzimuthalObjectXY(-1.0, -1.0),
vector._backends.object_.LongitudinalObjectZ(-1.0),
vector._backends.object_.TemporalObjectTau(1.0),
)
expected_result = (
# phi
numpy.pi**2
# rapidity
+ ((0.5 * numpy.log(3 / 1) - 0.5 * numpy.log(1 / 3)) ** 2)
)
assert v1.deltaRapidityPhi2(v2) == pytest.approx(expected_result)

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
for t2 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tr1, tr2 = getattr(v1, "to_" + t1)(), getattr(v2, "to_" + t2)()
assert tr1.deltaRapidityPhi2(tr2) == pytest.approx(expected_result)


def test_lorentz_numpy():
v1 = vector._backends.numpy_.VectorNumpy4D(
[(1.0, 1.0, 1.0, 1.0)],
dtype=[
("x", numpy.float64),
("y", numpy.float64),
("z", numpy.float64),
("tau", numpy.float64),
],
)
v2 = vector._backends.numpy_.VectorNumpy4D(
[(-1.0, -1.0, -1.0, 1.0)],
dtype=[
("x", numpy.float64),
("y", numpy.float64),
("z", numpy.float64),
("tau", numpy.float64),
],
)
expected_result = (
# phi
numpy.pi**2
# rapidity
+ ((0.5 * numpy.log(3 / 1) - 0.5 * numpy.log(1 / 3)) ** 2)
)
assert v1.deltaRapidityPhi2(v2) == pytest.approx(expected_result)

for t1 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
for t2 in (
"xyzt",
"xythetat",
"xyetat",
"rhophizt",
"rhophithetat",
"rhophietat",
"xyztau",
"xythetatau",
"xyetatau",
"rhophiztau",
"rhophithetatau",
"rhophietatau",
):
tr1, tr2 = getattr(v1, "to_" + t1)(), getattr(v2, "to_" + t2)()
assert numpy.allclose(tr1.deltaRapidityPhi2(tr2), expected_result)

0 comments on commit b9c60a8

Please sign in to comment.