File: test_boost_p4.py

package info (click to toggle)
python-vector 1.6.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 2,984 kB
  • sloc: python: 40,200; makefile: 13
file content (99 lines) | stat: -rw-r--r-- 3,270 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (c) 2019-2025, Saransh Chopra, Henry Schreiner, Eduardo Rodrigues, Jonas Eschle, and Jim Pivarski.
#
# Distributed under the 3-clause BSD license, see accompanying file LICENSE
# or https://github.com/scikit-hep/vector for details.

from __future__ import annotations

import pytest

import vector

sympy = pytest.importorskip("sympy")

pytestmark = pytest.mark.sympy

x, y, z, t, px, py, pz, M = sympy.symbols("x y z t px py pz M", real=True)
values = {x: 1, y: 2, z: 3, t: 4, px: 5, py: 6, pz: 7, M: 15}


def test():
    vec = vector.VectorSympy4D(
        azimuthal=vector.backends.sympy.AzimuthalSympyXY(x, y),
        longitudinal=vector.backends.sympy.LongitudinalSympyZ(z),
        temporal=vector.backends.sympy.TemporalSympyT(t),
    )
    p4 = vector.MomentumSympy4D(
        azimuthal=vector.backends.sympy.AzimuthalSympyXY(px, py),
        longitudinal=vector.backends.sympy.LongitudinalSympyZ(pz),
        temporal=vector.backends.sympy.TemporalSympyT(M),
    )
    out = vec.boost_p4(p4)
    assert out.x.simplify() == (
        M**2 * x
        + M * px * t
        + M * x * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
        + px * py * y
        + px * pz * z
        + px * t * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
        - py**2 * x
        - pz**2 * x
    ) / (M**2 + M * sympy.sqrt(M**2 - px**2 - py**2 - pz**2) - px**2 - py**2 - pz**2)
    assert out.y.simplify() == (
        M**2 * y
        + M * py * t
        + M * y * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
        - px**2 * y
        + px * py * x
        + py * pz * z
        + py * t * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
        - pz**2 * y
    ) / (M**2 + M * sympy.sqrt(M**2 - px**2 - py**2 - pz**2) - px**2 - py**2 - pz**2)
    assert out.z.simplify() == (
        M**2 * z
        + M * pz * t
        + M * z * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
        - px**2 * z
        + px * pz * x
        - py**2 * z
        + py * pz * y
        + pz * t * sympy.sqrt(M**2 - px**2 - py**2 - pz**2)
    ) / (M**2 + M * sympy.sqrt(M**2 - px**2 - py**2 - pz**2) - px**2 - py**2 - pz**2)
    assert out.t.simplify() == (M * t + px * x + py * y + pz * z) / sympy.sqrt(
        M**2 - px**2 - py**2 - pz**2
    )

    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",
        ):
            tvec, tp4 = getattr(vec, "to_" + t1)(), getattr(p4, "to_" + t2)()
            out = tvec.boost_p4(tp4)
            assert out.x.subs(values).evalf() == pytest.approx(3.5537720741941676)
            assert out.y.subs(values).evalf() == pytest.approx(5.0645264890330015)
            assert out.z.subs(values).evalf() == pytest.approx(6.575280903871835)
            assert out.t.subs(values).evalf() == pytest.approx(9.138547120755076)