phasespace 1.10.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- phasespace/__init__.py +33 -0
- phasespace/_version.py +24 -0
- phasespace/backend.py +23 -0
- phasespace/fromdecay/__init__.py +28 -0
- phasespace/fromdecay/genmultidecay.py +340 -0
- phasespace/fromdecay/mass_functions.py +109 -0
- phasespace/kinematics.py +188 -0
- phasespace/phasespace.py +841 -0
- phasespace/random.py +40 -0
- phasespace-1.10.4.dist-info/METADATA +342 -0
- phasespace-1.10.4.dist-info/RECORD +14 -0
- phasespace-1.10.4.dist-info/WHEEL +4 -0
- phasespace-1.10.4.dist-info/licenses/AUTHORS.rst +20 -0
- phasespace-1.10.4.dist-info/licenses/LICENSE +24 -0
phasespace/kinematics.py
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# =============================================================================
|
|
3
|
+
# @file kinematics.py
|
|
4
|
+
# @author Albert Puig (albert.puig@cern.ch)
|
|
5
|
+
# @date 12.02.2019
|
|
6
|
+
# =============================================================================
|
|
7
|
+
"""Basic kinematics."""
|
|
8
|
+
|
|
9
|
+
import tensorflow.experimental.numpy as tnp
|
|
10
|
+
from phasespace.backend import function, function_jit
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@function_jit
|
|
14
|
+
def scalar_product(vec1, vec2):
|
|
15
|
+
"""Calculate scalar product of two 3-vectors.
|
|
16
|
+
|
|
17
|
+
Args:
|
|
18
|
+
vec1: First vector.
|
|
19
|
+
vec2: Second vector.
|
|
20
|
+
|
|
21
|
+
Returns:
|
|
22
|
+
Scalar product of the two vectors.
|
|
23
|
+
"""
|
|
24
|
+
return tnp.sum(vec1 * vec2, axis=1)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
@function_jit
|
|
28
|
+
def spatial_component(vector):
|
|
29
|
+
"""Extract spatial components of the input Lorentz vector.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
vector: Input Lorentz vector (where indexes 0-2 are space, index 3 is time).
|
|
33
|
+
|
|
34
|
+
Returns:
|
|
35
|
+
Spatial components (3-vector) of the input Lorentz vector.
|
|
36
|
+
"""
|
|
37
|
+
return tnp.take(vector, indices=[0, 1, 2], axis=-1)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@function_jit
|
|
41
|
+
def time_component(vector):
|
|
42
|
+
"""Extract time component of the input Lorentz vector.
|
|
43
|
+
|
|
44
|
+
Args:
|
|
45
|
+
vector: Input Lorentz vector (where indexes 0-2 are space, index 3 is time).
|
|
46
|
+
|
|
47
|
+
Returns:
|
|
48
|
+
Time component of the input Lorentz vector.
|
|
49
|
+
"""
|
|
50
|
+
return tnp.take(vector, indices=[3], axis=-1)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
@function
|
|
54
|
+
def x_component(vector):
|
|
55
|
+
"""Extract spatial X component of the input Lorentz or 3-vector.
|
|
56
|
+
|
|
57
|
+
Args:
|
|
58
|
+
vector: Input vector.
|
|
59
|
+
|
|
60
|
+
Returns:
|
|
61
|
+
X component of the input vector.
|
|
62
|
+
"""
|
|
63
|
+
return tnp.take(vector, indices=[0], axis=-1)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
@function_jit
|
|
67
|
+
def y_component(vector):
|
|
68
|
+
"""Extract spatial Y component of the input Lorentz or 3-vector.
|
|
69
|
+
|
|
70
|
+
Args:
|
|
71
|
+
vector: Input vector.
|
|
72
|
+
|
|
73
|
+
Returns:
|
|
74
|
+
Y component of the input vector.
|
|
75
|
+
"""
|
|
76
|
+
return tnp.take(vector, indices=[1], axis=-1)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
@function_jit
|
|
80
|
+
def z_component(vector):
|
|
81
|
+
"""Extract spatial Z component of the input Lorentz or 3-vector.
|
|
82
|
+
|
|
83
|
+
Args:
|
|
84
|
+
vector: Input vector.
|
|
85
|
+
|
|
86
|
+
Returns:
|
|
87
|
+
Z component of the input vector.
|
|
88
|
+
"""
|
|
89
|
+
return tnp.take(vector, indices=[2], axis=-1)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@function_jit
|
|
93
|
+
def mass(vector):
|
|
94
|
+
"""Calculate mass scalar for Lorentz 4-momentum.
|
|
95
|
+
|
|
96
|
+
Args:
|
|
97
|
+
vector: Input Lorentz momentum vector.
|
|
98
|
+
|
|
99
|
+
Returns:
|
|
100
|
+
Mass of the Lorentz 4-momentum vector.
|
|
101
|
+
"""
|
|
102
|
+
return tnp.sqrt(
|
|
103
|
+
tnp.sum(tnp.square(vector) * metric_tensor(), axis=-1, keepdims=True)
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@function_jit
|
|
108
|
+
def lorentz_vector(space, time):
|
|
109
|
+
"""Make a Lorentz vector from spatial and time components.
|
|
110
|
+
|
|
111
|
+
Args:
|
|
112
|
+
space: 3-vector of spatial components.
|
|
113
|
+
time: Time component.
|
|
114
|
+
|
|
115
|
+
Returns:
|
|
116
|
+
Lorentz 4-vector combining spatial and time components.
|
|
117
|
+
"""
|
|
118
|
+
return tnp.concatenate([space, time], axis=-1)
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
@function_jit
|
|
122
|
+
def lorentz_boost(vector, boostvector):
|
|
123
|
+
"""Perform Lorentz boost.
|
|
124
|
+
|
|
125
|
+
Args:
|
|
126
|
+
vector: 4-vector to be boosted
|
|
127
|
+
boostvector: Boost vector. Can be either 3-vector or 4-vector, since
|
|
128
|
+
only spatial components are used.
|
|
129
|
+
|
|
130
|
+
Returns:
|
|
131
|
+
Boosted 4-vector.
|
|
132
|
+
"""
|
|
133
|
+
boost = spatial_component(boostvector)
|
|
134
|
+
b2 = tnp.expand_dims(scalar_product(boost, boost), axis=-1)
|
|
135
|
+
|
|
136
|
+
def boost_fn():
|
|
137
|
+
gamma = 1.0 / tnp.sqrt(1.0 - b2)
|
|
138
|
+
gamma2 = (gamma - 1.0) / b2
|
|
139
|
+
ve = time_component(vector)
|
|
140
|
+
vp = spatial_component(vector)
|
|
141
|
+
bp = tnp.expand_dims(scalar_product(vp, boost), axis=-1)
|
|
142
|
+
vp2 = vp + (gamma2 * bp + gamma * ve) * boost
|
|
143
|
+
ve2 = gamma * (ve + bp)
|
|
144
|
+
return lorentz_vector(vp2, ve2)
|
|
145
|
+
|
|
146
|
+
# if boost vector is zero, return the original vector
|
|
147
|
+
all_b2_zero = tnp.all(tnp.equal(b2, tnp.zeros_like(b2)))
|
|
148
|
+
boosted_vector = tnp.where(all_b2_zero, vector, boost_fn())
|
|
149
|
+
return boosted_vector
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
@function_jit
|
|
153
|
+
def beta(vector):
|
|
154
|
+
"""Calculate beta of a given 4-vector.
|
|
155
|
+
|
|
156
|
+
Args:
|
|
157
|
+
vector: Input Lorentz momentum vector.
|
|
158
|
+
|
|
159
|
+
Returns:
|
|
160
|
+
Beta (v/c) of the Lorentz momentum vector.
|
|
161
|
+
"""
|
|
162
|
+
return mass(vector) / time_component(vector)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
@function_jit
|
|
166
|
+
def boost_components(vector):
|
|
167
|
+
"""Get the boost components of a given 4-vector.
|
|
168
|
+
|
|
169
|
+
Args:
|
|
170
|
+
vector: Input Lorentz momentum vector.
|
|
171
|
+
|
|
172
|
+
Returns:
|
|
173
|
+
Boost components (3-vector) of the Lorentz momentum vector.
|
|
174
|
+
"""
|
|
175
|
+
return spatial_component(vector) / time_component(vector)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
@function_jit
|
|
179
|
+
def metric_tensor():
|
|
180
|
+
"""Metric tensor for Lorentz space (constant).
|
|
181
|
+
|
|
182
|
+
Returns:
|
|
183
|
+
Metric tensor for Lorentz space with signature (-1, -1, -1, 1).
|
|
184
|
+
"""
|
|
185
|
+
return tnp.asarray([-1.0, -1.0, -1.0, 1.0], dtype=tnp.float64)
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
# EOF
|