All Projects → scikit-hep → decaylanguage

scikit-hep / decaylanguage

Licence: BSD-3-Clause license
Package to parse decay files, describe and convert particle decays between digital representations.

Programming Languages

Jupyter Notebook
11667 projects
python
139335 projects - #7 most used programming language
Cuda
1817 projects

Projects that are alternatives of or similar to decaylanguage

Corpuscles.jl
Julia package for particle physics
Stars: ✭ 25 (-26.47%)
Mutual labels:  analysis, particles, high-energy-physics, hep, particle-physics, hep-ex
particle
Package to deal with particles, the PDG particle data table, PDGIDs, etc.
Stars: ✭ 113 (+232.35%)
Mutual labels:  analysis, high-energy-physics, hep, particle-physics, scikit-hep
UnROOT.jl
Native Julia I/O package to work with CERN ROOT files
Stars: ✭ 52 (+52.94%)
Mutual labels:  analysis, high-energy-physics, hep, particle-physics, hep-ex
root pandas
A Python module for conveniently loading/saving ROOT files as pandas DataFrames
Stars: ✭ 108 (+217.65%)
Mutual labels:  analysis, hep, scikit-hep
ml-lpi
Materials for ML course at Lebedev Physical Institute
Stars: ✭ 31 (-8.82%)
Mutual labels:  hep, particle-physics, hep-ex
pylhe
Lightweight Python interface to read Les Houches Event (LHE) files
Stars: ✭ 29 (-14.71%)
Mutual labels:  hep, particle-physics, scikit-hep
LatticeQCD.jl
A native Julia code for lattice QCD with dynamical fermions in 4 dimension.
Stars: ✭ 85 (+150%)
Mutual labels:  hep, particle-physics
alice-rs
Analyze the public data from the CERN base ALICE collaboration with Rust
Stars: ✭ 81 (+138.24%)
Mutual labels:  hep, particle-physics
numpythia
The interface between PYTHIA and NumPy
Stars: ✭ 33 (-2.94%)
Mutual labels:  hep, scikit-hep
pyjet
The interface between FastJet and NumPy
Stars: ✭ 31 (-8.82%)
Mutual labels:  hep, scikit-hep
zfit
Model manipulation and fitting library based on TensorFlow and optimised for simple and direct manipulation of probability density functions. Its main focus is on scalability, parallelisation and user friendly experience.
Stars: ✭ 134 (+294.12%)
Mutual labels:  high-energy-physics, scikit-hep
Scikit Hep
Metapackage of Scikit-HEP project data analysis packages for Particle Physics.
Stars: ✭ 131 (+285.29%)
Mutual labels:  analysis, hep
Uproot4
ROOT I/O in pure Python and NumPy.
Stars: ✭ 80 (+135.29%)
Mutual labels:  analysis, hep
weaver
Streamlined neural network training.
Stars: ✭ 22 (-35.29%)
Mutual labels:  hep, hep-ex
Uproot3
ROOT I/O in pure Python and NumPy.
Stars: ✭ 312 (+817.65%)
Mutual labels:  analysis, hep
Statistics-Notes
Personal notes on statistics with a focus on applications to experimental high energy physics
Stars: ✭ 19 (-44.12%)
Mutual labels:  high-energy-physics, hep
Mirheo
Computational Microfluidics
Stars: ✭ 34 (+0%)
Mutual labels:  particles
traffic analyser
Retrieve useful information from apache/nginx access logs to help troubleshoot traffic related problems
Stars: ✭ 44 (+29.41%)
Mutual labels:  analysis
atacr
Analysing Capture Seq Count Data
Stars: ✭ 14 (-58.82%)
Mutual labels:  analysis
prmon
Standalone monitor for process resource consumption
Stars: ✭ 37 (+8.82%)
Mutual labels:  high-energy-physics

DecayLanguage logo

DecayLanguage: describe, manipulate and convert particle decays

Scikit-HEP PyPI Package latest release Conda latest release Supported versions DOI

GitHub Actions Status: CI Code Coverage Documentation Status Code style: black

Binder demo

DecayLanguage implements a language to describe and convert particle decays between digital representations, effectively making it possible to interoperate several fitting programs. Particular interest is given to programs dedicated to amplitude analyses.

DecayLanguage provides tools to parse so-called .dec decay files, and describe, manipulate and visualize decay chains.

Installation

Just run the following:

pip install decaylanguage

You can use a virtual environment through pipenv or with --user if you know what those are. Python 3.7+ supported (see version 0.12 for Python 2 & 3.5 support, 0.14 for Python 3.6 support).

Dependencies: (click to expand)

Required and compatibility dependencies will be automatically installed by pip.

Required dependencies:

  • particle: PDG particle data and identification codes
  • NumPy: The numerical library for Python
  • pandas: Tabular data in Python
  • attrs: DataClasses for Python
  • plumbum: Command line tools
  • lark-parser: A modern parsing library for Python
  • graphviz to render (DOT language) graph descriptions and visualizations of decay chains.

Python compatibility:

Getting started

The Binder demo is an excellent way to get started with DecayLanguage.

This is a quick user guide. For a full API docs, go here (note that it is presently work-in-progress).

What is DecayLanguage?

DecayLanguage is a set of tools for building and transforming particle decays:

  1. It provides tools to parse so-called .dec decay files, and describe, manipulate and visualize the resulting decay chains.

  2. It implements a language to describe and convert particle decays between digital representations, effectively making it possible to interoperate several fitting programs. Particular interest is given to programs dedicated to amplitude analyses.

Particles

Particles are a key component when dealing with decays. Refer to the particle package for how to deal with particles and Monte Carlo particle identification codes.

Parse decay files

Decay .dec files can be parsed simply with

from decaylanguage import DecFileParser

parser = DecFileParser('my-decay-file.dec')
parser.parse()

# Inspect what decays are defined
parser.list_decay_mother_names()

# Print decay modes, etc. ...

A copy of the master DECAY.DEC file used by the LHCb experiment is provided here for convenience.

The DecFileParser class implements a series of methods giving access to all information stored in decay files: the decays themselves, particle name aliases, definitions of charge-conjugate particles, variable and Pythia-specific definitions, etc.

It can be handy to parse from a multi-line string rather than a file:

s = """Decay pi0
0.988228297   gamma   gamma                   PHSP;
0.011738247   e+      e-      gamma           PI0_DALITZ;
0.000033392   e+      e+      e-      e-      PHSP;
0.000000065   e+      e-                      PHSP;
Enddecay
"""

dfp = DecFileParser.from_string(s)
dfp.parse()

Advanced usage

The list of .dec file decay models known to the package can be inspected via

from decaylanguage.dec import known_decay_models

Say you have to deal with a decay file containing a new model not yet on the list above. Running the parser as usual will result in a UnexpectedToken exception. It is nevertheless easy to deal with this issue; no need to wait for a new release. It is just a matter of adding the model name to the list in decaylanguage/data/decfile.lark (or your private copy), see the line MODEL_NAME.2 : "BaryonPCR"|"BTO3PI_CP"|"BTOSLLALI"|..., and then proceed as usual apart from adding an extra line to call to load_grammar to specify the Lark grammar to use:

dfp = DecFileParser('my_decfile.dec')
dfp.load_grammar('path/to/my_updated_decfile.lark')
dfp.parse()
...

This being said, please do submit a pull request to add new models, if you spot missing ones ...

Visualize decay files

The class DecayChainViewer allows the visualization of parsed decay chains:

from decaylanguage import DecayChainViewer

# Build the (dictionary-like) D*+ decay chain representation setting the
# D+ and D0 mesons to stable, to avoid too cluttered an image
d = dfp.build_decay_chains('D*+', stable_particles=('D+', 'D0'))
DecayChainViewer(d)  # works in a notebook

DecayChain D*

The actual graph is available as

# ...
dcv = DecayChainViewer(d)
dcv.graph

making all graphviz.Digraph class properties and methods available, such as

dcv.graph.render(filename='mygraph', format='pdf', view=True, cleanup=True)

In the same way, all graphviz.Digraph class attributes are settable upon instantiation of DecayChainViewer:

dcv = DecayChainViewer(chain, name='TEST', format='pdf')

Universal representation of decay chains

A series of classes and methods have been designed to provide universal representations of particle decay chains of any complexity, and to provide the ability to convert between these representations. Specifically, class- and dictionary-based representations have been implemented.

An example of a class-based representation of a decay chain is the following:

>>> from decaylanguage import DaughtersDict, DecayMode, DecayChain
>>>
>>> dm1 = DecayMode(0.0124, 'K_S0 pi0', model='PHSP')
>>> dm2 = DecayMode(0.692, 'pi+ pi-')
>>> dm3 = DecayMode(0.98823, 'gamma gamma')
>>> dc = DecayChain('D0', {'D0':dm1, 'K_S0':dm2, 'pi0':dm3})
>>> dc
<DecayChain: D0 -> K_S0 pi0 (2 sub-decays), BF=0.0124>

Decay chains can be visualised with the DecayChainViewer class making use of the dictionary representation dc.to_dict(), which is the simple representation understood by DecayChainViewer, as see above:

DecayChainViewer(dc.to_dict())

The fact that 2 representations of particle decay chains are provided ensures the following:

  1. Human-readable (class) and computer-efficient (dictionary) alternatives.
  2. Flexibility for parsing, manipulation and storage of decay chain information.

Decay modeling

The most common way to create a decay chain is to read in an AmpGen style syntax from a file or a string. You can use:

from decaylanguage.modeling import AmplitudeChain
lines, parameters, constants, states = AmplitudeChain.read_ampgen(text='''
EventType D0 K- pi+ pi+ pi-

D0[D]{K*(892)bar0{K-,pi+},rho(770)0{pi+,pi-}}                            0 1 0.1 0 1 0.1

K(1460)bar-_mass  0 1460 1
K(1460)bar-_width 0  250 1

a(1)(1260)+::Spline::Min 0.18412
a(1)(1260)+::Spline::Max 1.86869
a(1)(1260)+::Spline::N 34
''')

Here, lines will be a list of AmplitudeChain lines (pretty print supported in Jupyter notebooks), parameters will be a table of parameters (ranged parameters not yet supported), constants will be a table of constants, and states will be the list of known states (EventType).

Converters

You can output to a format (currently only GooFit supported, feel free to make a PR to add more). Use a subclass of DecayChain, in this case, GooFitChain. To use the GooFit output, type from the shell:

python -m decaylanguage -G goofit myinput.opts

Acknowledgements

The UK Science and Technology Facilities Council (STFC) and the University of Liverpool provide funding for Eduardo Rodrigues (2020-) to work on this project part-time.

Support for this work was provided by the National Science Foundation cooperative agreement OAC-1450377 (DIANA/HEP) in 2016-2019 and has been provided by OAC-1836650 (IRIS-HEP) since 2019. Any opinions, findings, conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].