/
kmatrix.py
407 lines (374 loc) · 14.3 KB
/
kmatrix.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
r"""Experimental, symbol :math:`\boldsymbol{K}`-matrix implementations.
.. seealso:: :doc:`/usage/dynamics/k-matrix`.
This module is an implementation of :doc:`compwa:report/005`,
:doc:`compwa:report/009`, and :doc:`compwa:report/010`. It works with classes to
keep the code organized and to enable caching of the matrix multiplications, but this
might change once these dynamics are implemented into the amplitude builder.
"""
from __future__ import annotations
import functools
from abc import ABC, abstractmethod
import sympy as sp
from ampform.dynamics import (
EnergyDependentWidth,
PhaseSpaceFactor,
PhaseSpaceFactorProtocol,
formulate_form_factor,
)
from ampform.sympy import create_symbol_matrix
class TMatrix(ABC):
@classmethod
@abstractmethod
def formulate(
cls, n_channels, n_poles, parametrize: bool = True, **kwargs
) -> sp.MutableDenseMatrix:
"""Formulate :math:`K`-matrix with its own parametrization."""
class RelativisticKMatrix(TMatrix):
@staticmethod
@functools.lru_cache(maxsize=None)
def _create_matrices(
n_channels, return_t_hat: bool = False
) -> tuple[sp.MutableDenseMatrix, sp.MutableDenseMatrix]:
rho = _create_rho_matrix(n_channels)
sqrt_rho: sp.MutableDenseMatrix = sp.sqrt(rho).doit()
sqrt_rho_conj = sp.conjugate(sqrt_rho)
k_matrix = create_symbol_matrix("K", n_channels, n_channels)
t_hat = k_matrix * (sp.eye(n_channels) - sp.I * rho * k_matrix).inv()
if return_t_hat:
return t_hat, k_matrix
t_matrix = sqrt_rho_conj * t_hat * sqrt_rho
return t_matrix, k_matrix
@classmethod
def formulate( # type: ignore[override] # noqa: D417
cls,
n_channels,
n_poles,
parametrize: bool = True,
return_t_hat: bool = False,
phsp_factor: PhaseSpaceFactorProtocol = PhaseSpaceFactor,
angular_momentum=0,
meson_radius=1,
) -> sp.MutableDenseMatrix:
r"""Implementation of :eq:`T-hat-in-terms-of-K-hat`.
Args:
n_channels: Number of coupled channels.
n_poles: Number of poles.
parametrize: Set to `False` if don't want to parametrize and only get
symbols for the matrix multiplication of :math:`\boldsymbol{K}` and
:math:`\boldsymbol{\rho}`.
return_t_hat: Set to `True` if you want to get the Lorentz-invariant
:math:`\boldsymbol{\hat{T}}`-matrix instead of the
:math:`\boldsymbol{T}`-matrix from Eq. :eq:`K-hat-and-T-hat`.
"""
t_matrix, k_matrix = cls._create_matrices(n_channels, return_t_hat)
if not parametrize:
return t_matrix
s = sp.Symbol("s", nonnegative=True)
m_a = sp.IndexedBase("m_a", nonnegative=True)
m_b = sp.IndexedBase("m_b", nonnegative=True)
return t_matrix.xreplace({
k_matrix[i, j]: cls.parametrization(
i=i,
j=j,
s=s,
pole_position=sp.IndexedBase("m", nonnegative=True),
pole_width=sp.IndexedBase("Gamma", nonnegative=True),
m_a=m_a,
m_b=m_b,
residue_constant=sp.IndexedBase("gamma", nonnegative=True),
n_poles=n_poles,
pole_id=sp.Symbol("R", integer=True, positive=True),
angular_momentum=angular_momentum,
meson_radius=meson_radius,
phsp_factor=phsp_factor,
)
for i in range(n_channels)
for j in range(n_channels)
}).xreplace({
sp.Symbol(f"rho{i}"): phsp_factor(s, m_a[i], m_b[i])
for i in range(n_channels)
})
@staticmethod
def parametrization( # noqa: PLR0917
i,
j,
s,
pole_position: sp.IndexedBase,
pole_width: sp.IndexedBase,
m_a: sp.IndexedBase,
m_b: sp.IndexedBase,
residue_constant: sp.IndexedBase,
n_poles,
pole_id,
angular_momentum=0,
meson_radius=1,
phsp_factor: PhaseSpaceFactorProtocol = PhaseSpaceFactor,
) -> sp.Expr:
def residue_function(pole_id, i) -> sp.Expr:
return residue_constant[pole_id, i] * sp.sqrt(
pole_position[pole_id]
* EnergyDependentWidth(
s=s,
mass0=pole_position[pole_id],
gamma0=pole_width[pole_id, i],
m_a=m_a[i],
m_b=m_b[i],
angular_momentum=angular_momentum,
meson_radius=meson_radius,
phsp_factor=phsp_factor,
)
)
g_i = residue_function(pole_id, i)
g_j = residue_function(pole_id, j)
parametrization = (g_i * g_j) / (pole_position[pole_id] ** 2 - s)
return sp.Sum(parametrization, (pole_id, 1, n_poles))
class NonRelativisticKMatrix(TMatrix):
@staticmethod
@functools.lru_cache(maxsize=None)
def _create_matrices(
n_channels,
) -> tuple[sp.MutableDenseMatrix, sp.MutableDenseMatrix]:
k_matrix = create_symbol_matrix("K", n_channels, n_channels)
t_matrix = k_matrix * (sp.eye(n_channels) - sp.I * k_matrix).inv()
return t_matrix, k_matrix
@classmethod
def formulate(
cls,
n_channels,
n_poles,
parametrize: bool = True,
**kwargs,
) -> sp.MutableDenseMatrix:
t_matrix, k_matrix = cls._create_matrices(n_channels)
if not parametrize:
return t_matrix
return t_matrix.xreplace({
k_matrix[i, j]: cls.parametrization(
i=i,
j=j,
s=sp.Symbol("s", nonnegative=True),
pole_position=sp.IndexedBase("m", nonnegative=True),
pole_width=sp.IndexedBase("Gamma", nonnegative=True),
residue_constant=sp.IndexedBase("gamma", nonnegative=True),
n_poles=n_poles,
pole_id=sp.Symbol("R", integer=True, positive=True),
)
for i in range(n_channels)
for j in range(n_channels)
})
@staticmethod
def parametrization( # noqa: PLR0917
i,
j,
s,
pole_position: sp.IndexedBase,
pole_width: sp.IndexedBase,
residue_constant: sp.IndexedBase,
n_poles,
pole_id,
) -> sp.Expr:
def residue_function(pole_id, i) -> sp.Expr:
return residue_constant[pole_id, i] * sp.sqrt(
pole_position[pole_id] * pole_width[pole_id, i]
)
g_i = residue_function(pole_id, i)
g_j = residue_function(pole_id, j)
parametrization = (g_i * g_j) / (pole_position[pole_id] ** 2 - s)
return sp.Sum(parametrization, (pole_id, 1, n_poles))
class NonRelativisticPVector(TMatrix):
@staticmethod
@functools.lru_cache(maxsize=None)
def _create_matrices(
n_channels,
) -> tuple[sp.MutableDenseMatrix, sp.MutableDenseMatrix, sp.MutableDenseMatrix]:
k_matrix = create_symbol_matrix("K", m=n_channels, n=n_channels)
p_vector = create_symbol_matrix("P", m=n_channels, n=1)
f_vector = (sp.eye(n_channels) - sp.I * k_matrix).inv() * p_vector
return f_vector, k_matrix, p_vector
@classmethod
def formulate(
cls,
n_channels,
n_poles,
parametrize: bool = True,
**kwargs,
) -> sp.MutableDenseMatrix:
f_vector, k_matrix, p_vector = cls._create_matrices(n_channels)
if not parametrize:
return f_vector
s = sp.Symbol("s", nonnegative=True)
pole_position = sp.IndexedBase("m", nonnegative=True)
pole_width = sp.IndexedBase("Gamma", nonnegative=True)
residue_constant = sp.IndexedBase("gamma", nonnegative=True)
pole_id = sp.Symbol("R", integer=True, positive=True)
return f_vector.xreplace({
k_matrix[i, j]: NonRelativisticKMatrix.parametrization(
i=i,
j=j,
s=s,
pole_position=pole_position,
pole_width=pole_width,
residue_constant=residue_constant,
n_poles=n_poles,
pole_id=pole_id,
)
for i in range(n_channels)
for j in range(n_channels)
}).xreplace({
p_vector[i]: cls.parametrization(
i=i,
s=sp.Symbol("s", nonnegative=True),
pole_position=pole_position,
pole_width=pole_width,
residue_constant=residue_constant,
beta_constant=sp.IndexedBase("beta", nonnegative=True),
n_poles=n_poles,
pole_id=pole_id,
)
for i in range(n_channels)
})
@staticmethod
def parametrization( # noqa: PLR0917
i,
s,
pole_position: sp.IndexedBase,
pole_width: sp.IndexedBase,
residue_constant: sp.IndexedBase,
beta_constant: sp.IndexedBase,
n_poles,
pole_id,
) -> sp.Expr:
beta = beta_constant[pole_id]
gamma = residue_constant[pole_id, i]
mass = pole_position[pole_id]
width = pole_width[pole_id, i]
parametrization = beta * gamma * mass * width / (mass**2 - s)
return sp.Sum(parametrization, (pole_id, 1, n_poles))
class RelativisticPVector(TMatrix):
@staticmethod
@functools.lru_cache(maxsize=None)
def _create_matrices(
n_channels, return_f_hat: bool = False
) -> tuple[sp.MutableDenseMatrix, sp.MutableDenseMatrix, sp.MutableDenseMatrix]:
k_matrix = create_symbol_matrix("K", m=n_channels, n=n_channels)
rho = _create_rho_matrix(n_channels)
sqrt_rho: sp.MutableDenseMatrix = sp.sqrt(rho).doit()
sqrt_rho_conj: sp.MutableDenseMatrix = sp.conjugate(sqrt_rho)
k_matrix = create_symbol_matrix("K", n_channels, n_channels)
k_hat = sqrt_rho_conj.inv() * k_matrix * sqrt_rho.inv()
p_vector = create_symbol_matrix("P", m=n_channels, n=1)
f_hat = (sp.eye(n_channels) - sp.I * k_hat * rho).inv() * p_vector
if return_f_hat:
return f_hat, k_matrix, p_vector
f_vector = sqrt_rho * f_hat
return f_vector, k_matrix, p_vector
@classmethod
def formulate( # type: ignore[override] # noqa: D417
cls,
n_channels,
n_poles,
parametrize: bool = True,
return_f_hat: bool = False,
phsp_factor: PhaseSpaceFactorProtocol = PhaseSpaceFactor,
angular_momentum=0,
meson_radius=1,
) -> sp.MutableDenseMatrix:
r"""Implementation of :eq:`F-in-terms-of-P`.
Args:
n_channels: Number of coupled channels.
n_poles: Number of poles.
parametrize: Set to `False` if don't want to parametrize and only get
symbols for the matrix multiplication of :math:`\boldsymbol{K}` and
:math:`\boldsymbol{\rho}`.
return_f_hat: Set to `True` if you want to get theLorentz-invariant
:math:`\hat{F}`-vector instead of the :math:`T`-vector from Eq.
:eq:`invariant-vectors`.
"""
f_vector, k_matrix, p_vector = cls._create_matrices(n_channels, return_f_hat)
if not parametrize:
return f_vector
s = sp.Symbol("s", nonnegative=True)
pole_position = sp.IndexedBase("m", nonnegative=True)
pole_width = sp.IndexedBase("Gamma", nonnegative=True)
residue_constant = sp.IndexedBase("gamma", nonnegative=True)
m_a = sp.IndexedBase("m_a", nonnegative=True)
m_b = sp.IndexedBase("m_b", nonnegative=True)
pole_id = sp.Symbol("R", integer=True, positive=True)
return (
f_vector.xreplace({
k_matrix[i, j]: RelativisticKMatrix.parametrization(
i=i,
j=j,
s=s,
pole_position=pole_position,
pole_width=pole_width,
m_a=m_a,
m_b=m_b,
residue_constant=residue_constant,
n_poles=n_poles,
pole_id=pole_id,
angular_momentum=angular_momentum,
meson_radius=meson_radius,
)
for i in range(n_channels)
for j in range(n_channels)
})
.xreplace({
p_vector[i]: cls.parametrization(
i=i,
s=s,
pole_position=pole_position,
pole_width=pole_width,
m_a=m_a,
m_b=m_b,
beta_constant=sp.IndexedBase("beta", nonnegative=True),
residue_constant=residue_constant,
n_poles=n_poles,
pole_id=pole_id,
angular_momentum=angular_momentum,
meson_radius=meson_radius,
)
for i in range(n_channels)
})
.xreplace({
sp.Symbol(f"rho{i}"): phsp_factor(s, m_a[i], m_b[i])
for i in range(n_channels)
})
)
@staticmethod
def parametrization( # noqa: PLR0917
i,
s,
pole_position: sp.IndexedBase,
pole_width: sp.IndexedBase,
m_a: sp.IndexedBase,
m_b: sp.IndexedBase,
beta_constant: sp.IndexedBase,
residue_constant: sp.IndexedBase,
n_poles,
pole_id,
angular_momentum=0,
meson_radius=1,
) -> sp.Expr:
beta = beta_constant[pole_id]
gamma = residue_constant[pole_id, i]
mass0 = pole_position[pole_id]
width = pole_width[pole_id, i]
form_factor = formulate_form_factor(
s, m_a[i], m_b[i], angular_momentum, meson_radius
)
return sp.Sum(
beta * gamma * mass0 * width * form_factor / (mass0**2 - s),
(pole_id, 1, n_poles),
)
def _create_rho_matrix(n_channels) -> sp.MutableDenseMatrix:
"""Create a phase space matrix with :code:`n_channels`.
>>> _create_rho_matrix(n_channels=2)
Matrix([
[rho0, 0],
[ 0, rho1]])
"""
rho_matrix: sp.MutableDenseMatrix = sp.zeros(n_channels, n_channels)
for i in range(n_channels):
rho_matrix[i, i] = sp.Symbol(f"rho{i}")
return rho_matrix