# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# + [markdown] slideshow={"slide_type": "slide"}
# ![DecayLanguage](../images/DecayLanguage.png)
#
# ### <NAME> and <NAME>
#
# The demos assume you have run `python -m pip install decaylanguage`. The demos use Python 3, though the package also supports Python 2 for now. You can also [access them on binder](https://mybinder.org/v2/gh/scikit-hep/decaylanguage/master?urlpath=lab/tree/notebooks/DecayLanguageDemo.ipynb) or [view them here](https://nbviewer.jupyter.org/github/scikit-hep/decaylanguage/blob/master/notebooks/DecayLanguageDemo.ipynb).

# + [markdown] slideshow={"slide_type": "slide"}
# `DecayLanguage` was designed to support manipulating decay structures in Python. It started with a specific focus, and is slowly generalizing. The current package has:
#
# * **Amplitude Analysis decay language**:
#     - Input based on AmpGen generator
#     - Current output formats:
#         * GooFit C++
# * **Decay file parsers**:
#     - Read DecFiles, such as the LHCb master DecFile
#     - Manipulate adn visualize them in Python

# + [markdown] slideshow={"slide_type": "slide"}
# ## DecayLanguage: decay modelling
#
# This takes a file in the **"AmpGen" format** and converts it to a DecayChain. Currently one output converter is included: **GooFit C++**.
# -

with open('simple_model.txt') as f:
    print(f.read())

# + slideshow={"slide_type": "subslide"}
# !python -m decaylanguage -G goofit simple_model.txt

# + [markdown] slideshow={"slide_type": "subslide"}
# You can query this information from Python too:
# -

from decaylanguage.modeling.goofit import GooFitChain

lines, all_states = GooFitChain.read_ampgen('simple_model.txt')

lines[0]

# + [markdown] slideshow={"slide_type": "slide"}
# ## DecayLanguage: DecFile
#
# **_Under development, syntax may change_.**
# -

from decaylanguage import DecFileParser
from decaylanguage.dec.dec import ChargeConjugateReplacement

# + slideshow={"slide_type": "subslide"}
with open('../tests/data/test_example_Dst.dec') as f:
    print(f.read())

# + slideshow={"slide_type": "subslide"}
parser = DecFileParser('../tests/data/test_example_Dst.dec')
parser
# -

parser.parse()
parser

# + slideshow={"slide_type": "subslide"}
parser.print_decay_modes('D*+')
# -

parser.list_decay_mother_names()

parser.list_decay_modes('D*+')

# + [markdown] slideshow={"slide_type": "subslide"}
# ### Viewing decay chains
# -

from decaylanguage import DecayChainViewer

# + slideshow={"slide_type": "subslide"}
d = parser.build_decay_chains('D+')
d
# -

DecayChainViewer(d)

# + slideshow={"slide_type": "subslide"}
d = parser.build_decay_chains('D*+')
DecayChainViewer(d)

# + slideshow={"slide_type": "subslide"}
d = parser.build_decay_chains('D*+', stable_particles=['D+'])
DecayChainViewer(d)

# + [markdown] slideshow={"slide_type": "subslide"}
# #### Charge conjugation:
# -

ChargeConjugateReplacement().visit(parser._parsed_dec_file.children[0])

d = parser.build_decay_chains('D*-')
DecayChainViewer(d)

# + [markdown] slideshow={"slide_type": "slide"}
# ### Large DecFiles
#
# Now let's read in a 11,000 line dec file - LHCb master file with generic decays.
# -

parser = DecFileParser('../src/decaylanguage/data/DECAY_LHCB.DEC')
parser

# %%time
parser.parse()
parser

# + slideshow={"slide_type": "subslide"}
parser.dict_aliases()

# + slideshow={"slide_type": "subslide"}
parser.dict_charge_conjugates()

# + [markdown] slideshow={"slide_type": "slide"}
# Stay tuned, follow the development and/or contribute!

StarcoderdataJupyterScriptsDedupFiltered