Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add several methods to handle decay descriptors #331

Merged
merged 28 commits into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1c1b43a
add DecayChain.to_string method plus tests
admorris Jun 7, 2023
e6e495e
style: pre-commit fixes
pre-commit-ci[bot] Jun 7, 2023
4463eba
Update src/decaylanguage/decay/decay.py
admorris Jun 9, 2023
88164a6
style: pre-commit fixes
pre-commit-ci[bot] Jun 9, 2023
26cc605
add example to docstring, fix typo in test
admorris Jun 13, 2023
0691974
Update src/decaylanguage/decay/decay.py
admorris Jun 14, 2023
8833b58
use DaughtersDict
admorris Jun 14, 2023
be23fe6
Merge branch 'print_descriptors' of github.com:admorris/decaylanguage…
admorris Jun 14, 2023
3e46c92
enforce list type
admorris Jun 14, 2023
6a29552
functionality to expand decay chain dicts
admorris Jun 15, 2023
36f193f
Update src/decaylanguage/dec/dec.py
admorris Jun 22, 2023
43759d6
Apply suggestions from code review
eduardo-rodrigues Jun 22, 2023
abc1bfd
add DescriptorFormat class for customising the format of descriptors
admorris Jun 22, 2023
d73c0d3
Merge branch 'print_descriptors' of github.com:admorris/decaylanguage…
admorris Jun 22, 2023
058d554
Apply suggestions from code review
admorris Jun 22, 2023
a23c78d
add FLATSQDALITZ to known EvtGen model names
admorris Jun 27, 2023
f8c4eb0
Merge branch 'print_descriptors' of github.com:admorris/decaylanguage…
admorris Jun 27, 2023
4b9c113
Apply suggestions from code review
eduardo-rodrigues Jun 27, 2023
cf47af0
Merge branch 'master' into print_descriptors
admorris Jun 28, 2023
a3198bb
move DescriptorFormat test to tests/utils
admorris Jun 28, 2023
3962734
mention implicit use of aliases in docstring for DecFileParser.expand…
admorris Jun 28, 2023
901e5a4
example of aliases in _expand_decay_modes
admorris Jun 28, 2023
7031379
add import statement to example to satisfy doctest(?)
admorris Jun 28, 2023
1ba9aae
comply with RUF012
admorris Jun 28, 2023
ac5aedd
use typing.Dict in typedef
admorris Jun 28, 2023
c84198a
use typing.List in typedef
admorris Jun 28, 2023
e23cec2
one more
admorris Jun 28, 2023
4291823
Update decay.py
admorris Jun 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/decaylanguage/decay/decay.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,33 @@ def ndecays(self) -> int:
"""
return len(self.decays)

def to_string(self, arrow="->") -> str:
admorris marked this conversation as resolved.
Show resolved Hide resolved
admorris marked this conversation as resolved.
Show resolved Hide resolved
"""
One-line string representation of the entire decay chain. Sub-decays are
admorris marked this conversation as resolved.
Show resolved Hide resolved
enclosed in round parentheses.
admorris marked this conversation as resolved.
Show resolved Hide resolved
"""
admorris marked this conversation as resolved.
Show resolved Hide resolved

def _str(
decay: dict[str, list[dict[str, float | str | list[Any]]]] | str,
top=False,
admorris marked this conversation as resolved.
Show resolved Hide resolved
) -> str:
if isinstance(decay, dict):
mother = list(decay.keys())[0]
admorris marked this conversation as resolved.
Show resolved Hide resolved
fs = [_str(fsp) for i_decay in decay[mother] for fsp in i_decay["fs"]]
descriptor = " ".join([mother, arrow, *fs])
if not top:
return f"({descriptor})"
return descriptor

elif isinstance(decay, str):
return decay

else:
raise TypeError(f"Don't know how to handle {type(decay)}")

dc_dict = self.to_dict()
return _str(dc_dict, True)

def print_as_tree(self) -> None: # pragma: no cover
"""
Tree-structure like print of the entire decay chain.
Expand Down
42 changes: 42 additions & 0 deletions tests/decay/test_descriptor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import annotations

import pytest

from decaylanguage import DecayChain, DecayMode

dm1 = DecayMode(0.6770, "D0 pi+") # D*+
dm2 = DecayMode(0.0124, "K_S0 pi0") # D0
dm3 = DecayMode(0.692, "pi+ pi-") # K_S0
dm4 = DecayMode(0.98823, "gamma gamma") # pi-
dm5 = DecayMode(0.0105, "D- tau+ nu_tau") # B0
dm6 = DecayMode(0.0938, "K+ pi- pi-") # D-
dm7 = DecayMode(0.0931, "pi+ pi+ pi- anti-nu_tau") # tau+
dm8 = DecayMode(1.85e-6, "phi phi'") # B_s0
dm9a = DecayMode(0.491, "K+ K-") # phi
dm9b = DecayMode(0.154, "pi+ pi- pi0") # phi


@pytest.mark.parametrize(
("dc", "expected"),
[
(
DecayChain("D0", {"D0": dm2, "K_S0": dm3, "pi0": dm4}),
"D0 -> (K_S0 -> pi+ pi-) (pi0 -> gamma gamma)",
),
(
DecayChain("D*+", {"D*+": dm1, "D0": dm2, "K_S0": dm3, "pi0": dm4}),
"D*+ -> (D0 -> (K_S0 -> pi+ pi-) (pi0 -> gamma gamma)) pi+",
),
(
DecayChain("B0", {"B0": dm5, "D-": dm6, "tau+": dm7}),
"B0 -> (D- -> K+ pi- pi-) nu_tau (tau+ -> anti-nu_tau pi+ pi+ pi-)",
),
(
DecayChain("B_s0", {"B_s0": dm8, "phi": dm9a, "phi'": dm9b}),
"B_s0 -> (phi -> K+ K-) (phi' -> pi+ pi- pi0)",
),
],
)
def test_descriptor(dc: DecayChain, expected: str):
descriptor = dc.to_string()
assert descriptor == expected