Skip to content

Commit

Permalink
DOC: improve docstrings multichannel Breit-Wigner
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed May 20, 2024
1 parent 512dc5f commit f59ab43
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 34 additions & 2 deletions docs/_extend_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,36 @@ def extend_is_within_phasespace() -> None:
)


def extend_MultichannelBreitWigner() -> None:
from ampform.dynamics import (
ChannelArguments,
MultichannelBreitWigner,
SimpleBreitWigner,
)

s, m0, w0 = sp.symbols("s m0 Gamma0", nonnegative=True)
channels = [
ChannelArguments(*sp.symbols("Gamma1 m_a1 m_b1 L1 d", nonnegative=True)),
ChannelArguments(*sp.symbols("Gamma2 m_a2 m_b2 L2 d", nonnegative=True)),
]
expr = MultichannelBreitWigner(s, m0, channels=channels)
_append_latex_doit_definition(expr)
bw = SimpleBreitWigner(s, m0, w0)
_append_to_docstring(
MultichannelBreitWigner,
Rf"""
with :math:`{sp.latex(bw)}` defined by Equation :eq:`SimpleBreitWigner`, a
`SimpleBreitWigner`.
""",
)
_append_to_docstring(
ChannelArguments.formulate_width,
Rf"""
.. math:: {sp.latex(channels[0].formulate_width(s, m0))}
""",
)


def extend_PhaseSpaceFactor() -> None:
from ampform.dynamics.phasespace import PhaseSpaceFactor

Expand Down Expand Up @@ -743,8 +773,10 @@ def _create_latex_doit_definition(expr: sp.Expr, deep: bool = False) -> str:


def _append_to_docstring(class_type: Callable | type, appended_text: str) -> None:
assert class_type.__doc__ is not None
class_type.__doc__ += appended_text
if class_type.__doc__ is None:
class_type.__doc__ = appended_text
else:
class_type.__doc__ += appended_text


def __generate_transitions_cached(
Expand Down
4 changes: 4 additions & 0 deletions src/ampform/dynamics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def _latex_repr_(self, printer: LatexPrinter, *args) -> str:

@unevaluated
class MultichannelBreitWigner(sp.Expr):
"""`BreitWigner` for multiple channels."""

s: Any
mass: Any
channels: list[ChannelArguments] = argument(sympify=False)
Expand All @@ -155,6 +157,8 @@ def _latex_repr_(self, printer: LatexPrinter, *args) -> str:

@frozen
class ChannelArguments:
"""Arguments for a channel in a `MultichannelBreitWigner`."""

width: Any
m1: Any = 0
m2: Any = 0
Expand Down

0 comments on commit f59ab43

Please sign in to comment.