-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_boosts.py
177 lines (137 loc) · 4.61 KB
/
test_boosts.py
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
"""
Unit tests for boosting things
"""
import numpy as np
import pytest
from fourbody import boosts
import pylorentz
def test_stationary():
"""
Check if we can identify whether particles are stationary
"""
particles = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [1.0, 25.0]])
stationary = boosts._stationary(particles)
assert stationary[0] == True
assert stationary[1] == False
def test_convert_one():
"""
Check converting arrays for one particle to pylorentz gives us an obj of the correct type
"""
particles = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [1.0, 25.0]])
(converted,) = boosts._convert_to_pylorentz(particles)
assert isinstance(converted, pylorentz.Momentum4)
def test_convert_multiple():
"""
Check converting arrays for two particles to pylorentz gives us an obj of the correct type
"""
particles = np.array([[0.0, 1.0], [0.0, 1.0], [0.0, 1.0], [1.0, 25.0]])
a, b = boosts._convert_to_pylorentz(particles, particles)
assert isinstance(a, pylorentz.Momentum4)
assert isinstance(b, pylorentz.Momentum4)
def test_boost_not_stationary():
"""
Test boosting a particle if we assume it is not stationary
"""
particle = np.array([[53.89743437], [-385.779829], [-1782.366763], [2116.4343876]])
# Target particle moving in x-direction with gamma = 2.0
m = 1.0
gamma, beta = 2.0, np.sqrt(3) / 2.0
target = np.array([[gamma * beta * m], [0.0], [0.0], [gamma * m]])
expected = np.array(
[
-beta * gamma * particle[3][0] + gamma * particle[0][0], # px
particle[1][0],
particle[2][0],
gamma * particle[3][0] - beta * gamma * particle[0][0], # energy
]
)
(boosted_particle,) = boosts._boost_not_stationary(target, particle)
assert np.allclose(
[
boosted_particle.p_x[0],
boosted_particle.p_y[0],
boosted_particle.p_z[0],
boosted_particle.e[0],
],
expected,
)
def test_no_op_boost():
"""
Test boosting a particle works when we're already in the target frame
"""
particle = np.array([[53.89743437], [-385.779829], [-1782.366763], [2116.4343876]])
# Target particle has no 3-momentum; it's stationary, so our boost shouldn't do anything
target = np.array([[0.0], [0.0], [0.0], [1.8]])
(boosted_particle,) = boosts.boost(target, particle)
assert np.allclose(
[
boosted_particle.p_x[0],
boosted_particle.p_y[0],
boosted_particle.p_z[0],
boosted_particle.e[0],
],
particle.flatten(),
)
def test_all_moving_boost():
"""
Test boost where all target particles are moving
"""
# Target particles moving in x-direction with gamma = 2.0
particle = np.array(
[
[53.89743437, -53.89743437],
[-385.779829, -385.779829],
[-1782.366763, -1782.366763],
[2116.4343876, 2116.4343876],
]
)
m1, m2 = 1.0, 5.0
gamma, beta = 2.0, np.sqrt(3) / 2.0
target = np.array(
[
[gamma * beta * m1, gamma * beta * m2],
[0.0, 0.0],
[0.0, 0.0],
[gamma * m1, gamma * m2],
]
)
# Might have accidentally done the boost backwards. We'll see if it affects anything...
expected_1 = np.array(
[
-beta * gamma * particle[3][0] + gamma * particle[0][0], # px
particle[1][0],
particle[2][0],
gamma * particle[3][0] - beta * gamma * particle[0][0], # energy
]
)
expected_2 = np.array(
[
-beta * gamma * particle[3][1] + gamma * particle[0][1], # px
particle[1][1],
particle[2][1],
gamma * particle[3][1] - beta * gamma * particle[0][1], # energy
]
)
(boosted,) = boosts.boost(target, tuple(particle))
assert np.allclose(
[boosted.p_x[0], boosted.p_y[0], boosted.p_z[0], boosted.e[0]], expected_1
)
assert np.allclose(
[boosted.p_x[1], boosted.p_y[1], boosted.p_z[1], boosted.e[1]], expected_2
)
def test_some_moving_boost():
particle = np.array(
[
[53.89743437, -53.89743437],
[-385.779829, -385.779829],
[-1782.366763, -1782.366763],
[2116.4343876, 2116.4343876],
]
)
m1, m2 = 1.0, 5.0
gamma, beta = 2.0, np.sqrt(3) / 2.0
target = np.array(
[[gamma * beta * m1, 0], [0.0, 0.0], [0.0, 0.0], [gamma * m1, m2]]
)
with pytest.raises(NotImplementedError):
boosts.boost(target, particle)