Skip to content

Commit

Permalink
Merge 63388d2 into e8e7889
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Aug 8, 2018
2 parents e8e7889 + 63388d2 commit ed22ddb
Show file tree
Hide file tree
Showing 22 changed files with 598 additions and 340 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ include tox.ini .travis.yml .appveyor.yml
recursive-include decaylanguage *.py
recursive-include decaylanguage *.csv
recursive-include decaylanguage *.txt
recursive-include decaylanguage *.lark

recursive-include images *.pdf
recursive-include images *.png
Expand Down
12 changes: 5 additions & 7 deletions Pipfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
[[source]]

url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"


[packages]

attrs = ">=17.0"
pandas = ">=0.22"
plumbum = ">=1.6.6"
numpy = ">=1.12"
six = ">=1.11"
pathlib2 = {version = ">=2.3", markers="python_version < '3.5'"}
enum34 = {version = ">=1.1", markers="python_version < '3.4'"}

lark-parser = ">=0.6.3"

[dev-packages]

graphviz = ">=0.8.2""
graphviz = ">=0.8.2"
pytest = "*"
jupyter = {extras = ["all"]}
sphinx = "*"
sphinx-rtd-theme = "*"

jupyterlab = "*"
ipykernel = "*"
decaylanguage = {editable = true, path = "."}
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ particle. There are lots of printing choices, `describe()`,
`programmatic_name()`, `html_name()`, html printing outs in notebooks,
and of course `repr` and `str` support.

You can quickly search for particles from the command line with:

```
python -m decaylanguage.particle 311
```

You can put one or more PDG ID numbers here, or string names.

## Decays

The most common way to create a decay chain is to read in an [AmpGen]
Expand Down
2 changes: 1 addition & 1 deletion decaylanguage/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


class DecayLanguageDecay(cli.Application):
generator = cli.SwitchAttr('-G,--generator', cli.Set('goofit'))
generator = cli.SwitchAttr(['-G','--generator'], cli.Set('goofit'), mandatory=True)

def main(self, filename):
if self.generator == 'goofit':
Expand Down
12 changes: 0 additions & 12 deletions decaylanguage/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,3 @@
from importlib.resources import open_text
except ImportError:
from importlib_resources import open_text


def get_mass_width():
return open_text('decaylanguage.data', 'mass_width_2008.csv')


def get_special():
return open_text('decaylanguage.data', 'MintDalitzSpecialParticles.csv')


def get_latex():
return open_text('decaylanguage.data', 'pdgID_to_latex.txt')
60 changes: 60 additions & 0 deletions decaylanguage/data/ampgen.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
start : _NEWLINE? (line _NEWLINE)+

?line : cplx_decay_line | cart_decay_line | invert_line | constant | variable | options | event_type

options : fast_coherent_sum | output | nevents

fast_coherent_sum : "FastCoherentSum::UseCartesian" INT
output : "Output" ESCAPED_STRING
nevents : "nEvents" INT
event_type : "EventType" particle particle+

constant : particle SIGNED_NUMBER
variable : particle fix SIGNED_NUMBER SIGNED_NUMBER
cplx_decay_line : decay fixed_cplx fixed_cplx
cart_decay_line : decay fixed_cplx

// Particle could have a number in front
// TODO: This could pull out the - or -NUMBER* part
invert_line : particle "=" particle

fixed_cplx : fix SIGNED_NUMBER SIGNED_NUMBER

fix : "0" -> free
| "2" -> fixed

decay : particle ( decaytype? subdecay )?

decaytype : "[" (spinfactor | lineshape) (";" lineshape)? "]"

spinfactor : SPIN
lineshape : LINESHAPE

particle : LABEL

subdecay : "{" decay "," decay "}"

// Terminal defintions

%import common.WS_INLINE
%import common.SIGNED_NUMBER
%import common.DIGIT
%import common.INT
%import common.LETTER
%import common.ESCAPED_STRING

SPIN : "S" | "P" | "D"
LINESHAPE : CHAR (CHAR | ".")+
CHAR : LETTER | DIGIT | "_" | "/"
PRIME : "'"
STAR : "*"
PARENS : "(" | ")"
LABEL : ( CHAR | DIGIT | PRIME | STAR | "::" | "+" | "-" | PARENS )+
COMMENT : /[#][^\n]*/
_NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+

// We should ignore comments
%ignore COMMENT

// Disregard spaces in text
%ignore WS_INLINE
55 changes: 55 additions & 0 deletions decaylanguage/data/decfile.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
start : _NEWLINE? (line _NEWLINE)+ ("End" _NEWLINE)?
?line : define | pythia_def | alias | chargeconj | commands | decay | cdecay | setlspw

pythia_def : "PythiaBothParam" LABEL ":" LABEL "=" (LABEL | SIGNED_NUMBER)

setlspw : "SetLineshapePW" label label label value

cdecay : "CDecay" label

define : "Define" label SIGNED_NUMBER

alias : "Alias" label label

chargeconj : "ChargeConj" label label

?commands : global_photos

global_photos : boolean_photos

boolean_photos : "yesPhotos" -> yes
| "noPhotos" -> no

decay : "Decay" particle _NEWLINE decayline+ "Enddecay"
decayline : value particle* photos? model _NEWLINE // There is always a ; here
value : SIGNED_NUMBER
photos : "PHOTOS"

label : LABEL
particle : LABEL // Add full particle parsing here

model : MODEL_NAME model_options?
model_options : (value | LABEL)+

// model : model_generic
// model_helamp : "HELAMP" (SIGNED_NUMBER SIGNED_NUMBER)+

// Terminal defintions
// To use a fast parser, we need to avoid conflicts

%import common.WS_INLINE
%import common.SIGNED_NUMBER

// New lines filter our comments too, and multiple new lines
_NEWLINE: ( /\r?\n[\t ]*/ | COMMENT )+

// We must set priorities here to use lalr - match model name above label, and label above something else
MODEL_NAME.2 : "BaryonPCR"|"BTO3PI_CP"|"BTOSLLALI"|"BTOSLLBALL"|"BTOXSGAMMA"|"BTOXSLL"|"CB3PI-MPP"|"CB3PI-P00"|"D_DALITZ"|"ETA_DALITZ"|"GOITY_ROBERTS"|"HELAMP"|"HQET"|"ISGW2"|"OMEGA_DALITZ"|"PARTWAVE"|"PHSP"|"PI0_DALITZ"|"PYTHIA"|"SLN"|"STS"|"SVP_HELAMP"|"SVS"|"SVV_HELAMP"|"TAUHADNU"|"TAULNUNU"|"TAUSCALARNU"|"TAUVECTORNU"|"TSS"|"TVS_PWAVE"|"VLL"|"VSP_PWAVE"|"VSS"|"VSS_BMIX"|"VUB"|"VVP"|"VVPIPI"|"VVS_PWAVE"
LABEL : /[a-zA-Z0-9\/\-+*_()']+/
COMMENT : /[;#][^\n]*/

// We should ignore comments
%ignore COMMENT

// Disregard spaces in text
%ignore WS_INLINE
35 changes: 35 additions & 0 deletions decaylanguage/data/particle.lark
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Forms:
# ampgen
# decfile

start : prebar? name family? spin? mass? bar? charge

name : PNAME
charge : CHARGE
prebar : "anti-"
bar : "~"

spin : spin_brackets | spin_underscore | spin_star
family : family_brackets | family_underscore

spin_brackets : "(" DIGIT ")"
spin_underscore : "_" DIGIT
spin_star : "*"

family_brackets : "(" CNAME ")"

mass : "(" MASS ")"

bar : BAR
star : STAR
prime : PRIME
PRIME : "'"
STAR : "*"

MASS : DIGIT DIGIT+
BAR : "bar"
PNAME : (LETTER | "/")+
CHARGE : "--" | "+" | "0" | "-" | "--"

%import common.CNAME
%import common.DIGIT
Empty file modified decaylanguage/decay/ampgen2goofit.py
100755 → 100644
Empty file.
44 changes: 44 additions & 0 deletions decaylanguage/decay/ampgentransform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from lark import Transformer, Tree

def get_from_parser(parser, key):
return [v.children for v in parser.find_data(key)]

class AmpGenTransformer(Transformer):
def constant(self, lines):
particle, value = lines
return Tree('constant', [str(particle.children[0]), float(value)])
def event_type(self, lines):
return Tree('event_type', [str(p.children[0]) for p in lines])
def fixed(self, lines):
return False
def free(self, lines):
return True
def variable(self, lines):
p, free, value, error = lines
return Tree('variable', [str(p.children[0]), free, float(value), float(error)])
def cplx_decay_line(self, lines):
decay, real, imag = lines
real_free, real_val, real_err = real.children
imag_free, imag_val, imag_err = imag.children

decay['fix'] = not (real_free and imag_free)
decay['amp'] = complex(float(real_val), float(imag_val))
decay['err'] = complex(float(real_err), float(imag_err))

return Tree('cplx_decay_line', decay)

def decay(self, lines):
particle, = lines[0].children
dic = {'name' : str(particle), 'daughters' : []}

for line in lines[1:]:
if line.data == 'subdecay':
dic['daughters'] += line.children
elif line.data == 'decaytype':
for children in line.children:
if children.data == 'spinfactor':
dic['spinfactor'], = children.children
elif children.data == 'lineshape':
dic['lineshape'], = children.children

return dic
79 changes: 0 additions & 79 deletions decaylanguage/decay/ampline.py

This file was deleted.

Loading

0 comments on commit ed22ddb

Please sign in to comment.