Skip to content

Commit

Permalink
Adding demo files and a few fixes (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed May 13, 2019
1 parent 0951503 commit 45ceadb
Show file tree
Hide file tree
Showing 4 changed files with 368 additions and 9 deletions.
2 changes: 2 additions & 0 deletions decaylanguage/decay/amplitudechain.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import attr
import numpy as np
import pandas as pd
import re

from lark import Lark

Expand Down Expand Up @@ -173,6 +174,7 @@ def L(self):

def _get_html(self):
name = self.particle.html_name
name = re.sub(r'<SPAN STYLE="text-decoration:overline">(.*)</SPAN>', u'\\1\u0305', name)

if self.spinfactor or self.lineshape:
name += '<br/><br/>'
Expand Down
19 changes: 10 additions & 9 deletions decaylanguage/decay/goofit.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,16 @@ def strip_pararray(pars, begin, convert=lambda x: x):
series = pd.Series(mysplines, vals).sort_index()
return ',\n'.join(series.map(lambda x: ' '+programmatic_name(x)))

splines = GooFitChain.consts.index[GooFitChain.consts.index.str.contains("Spline")]
splines = set(splines.str.rstrip("::Spline::N").str.rstrip(
"::Spline::Min").str.rstrip("::Spline::Max"))

for spline in splines:
header += '\n std::vector<Variable> ' + programmatic_name(spline) + "_SplineArr {{\n"
header += strip_pararray(GooFitChain.pars,
"{spline}::Spline::Gamma::".format(spline=spline))
header += '\n }};\n'
if not GooFitChain.consts.empty:
splines = GooFitChain.consts.index[GooFitChain.consts.index.str.contains("Spline")]
splines = set(splines.str.rstrip("::Spline::N").str.rstrip(
"::Spline::Min").str.rstrip("::Spline::Max"))

for spline in splines:
header += '\n std::vector<Variable> ' + programmatic_name(spline) + "_SplineArr {{\n"
header += strip_pararray(GooFitChain.pars,
"{spline}::Spline::Gamma::".format(spline=spline))
header += '\n }};\n'

f_scatt = GooFitChain.pars.index[GooFitChain.pars.index.str.contains("f_scatt")]
if len(f_scatt):
Expand Down
348 changes: 348 additions & 0 deletions notebooks/DecayLanguageDemo.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,348 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"![DecayLanguage](../images/DecayLanguage.png)\n",
"\n",
"### Henry Schreiner and Eduardo Rodrigues\n",
"\n",
"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."
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"DecayLanguage was designed to support manipulating decay structures in Python. It started with a <font color=\"green\">specific focus</font>, and is <font color=\"green\">slowly generalizing</font>. The current package has:\n",
"\n",
"* **Decay**: Amplitude Analysis decay language\n",
" - Input based on AmpGen\n",
" - Current output formats:\n",
" * GooFit C++\n",
"* **Dec**: DecFile parsers\n",
" - Read DecFiles, such as the LHCb master DecFile\n",
" - Manipulate in Python"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## DecayLanuage: Decay\n",
"\n",
"This takes a file in the <font color=\"green\">\"AmpGen\" format</font> and converts it to a DecayChain. Currently one output converter is included: <font color=\"green\">GooFit C++</font>."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"with open('simple_model.txt') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"!python3 -m decaylanguage -G goofit simple_model.txt"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"You can query this information from Python too:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from decaylanguage.decay.goofit import GooFitChain"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lines, all_states = GooFitChain.read_ampgen('simple_model.txt')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"lines[0]"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"## DecayLanguage: DecFile\n",
"\n",
"<font color=\"red\">Under heavy development, syntax may change</font>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from decaylanguage.dec import DecFileParser\n",
"from decaylanguage.dec.dec import ChargeConjugateReplacement"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"with open('../tests/data/test_example_Dst.dec') as f:\n",
" print(f.read())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"parser = DecFileParser('../tests/data/test_example_Dst.dec')\n",
"parser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser.parse()\n",
"parser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"d = parser.build_decay_chain('D+')\n",
"d"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"parser.print_decay_modes('D*+')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser.list_decay_mother_names()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser.list_decay_modes('D*+')"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"source": [
"#### Charge conj:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser._parsed_dec_file.children[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ChargeConjugateReplacement().visit(parser._parsed_dec_file.children[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"ChargeConjugateReplacement().visit(parser._parsed_dec_file.children[0])"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"### Large DecFiles\n",
"\n",
"Now let's read in a 11,000 line dec file."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%time\n",
"parser = DecFileParser('../decaylanguage/data/DECAY_LHCB.DEC')\n",
"parser.parse(include_ccdecays=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"parser"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"parser.dict_aliases()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"slideshow": {
"slide_type": "subslide"
}
},
"outputs": [],
"source": [
"parser.dict_charge_conjugates()"
]
},
{
"cell_type": "markdown",
"metadata": {
"slideshow": {
"slide_type": "slide"
}
},
"source": [
"Stay tuned, follow the development and/or contribute!"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
8 changes: 8 additions & 0 deletions notebooks/simple_model.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
EventType D0 K- pi+ pi+ pi-

D0[D]{K*(892)bar0{K-,pi+},rho(770)0{pi+,pi-}} 2 1 0 2 0 0
D0[D]{rho(1450)0{pi+,pi-},K*(892)bar0{K-,pi+}} 0 0.648936 0.0205762 0 -0.271637 0.0342107
D0[P]{K*(892)bar0{K-,pi+},rho(770)0{pi+,pi-}} 0 0.362058 0.00237314 0 -1.79607 0.00663691
D0[P]{rho(1450)0{pi+,pi-},K*(892)bar0{K-,pi+}} 0 0.642781 0.00570074 0 1.69828 0.00900026

D0_radius 2 0.0037559 0

0 comments on commit 45ceadb

Please sign in to comment.