Skip to content

Commit

Permalink
Adding more parts for decfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
henryiii committed Nov 8, 2018
1 parent c48da31 commit 809a77c
Show file tree
Hide file tree
Showing 9 changed files with 3,490 additions and 1 deletion.
3 changes: 2 additions & 1 deletion decaylanguage/data/decfile.lark
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ setlspw : "SetLineshapePW" label label label value

cdecay : "CDecay" label

define : "Define" label SIGNED_NUMBER
define : "Define" label value

alias : "Alias" label label

Expand Down Expand Up @@ -45,6 +45,7 @@ _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]*/

Expand Down
252 changes: 252 additions & 0 deletions decaylanguage/data/mass_width_2018.mcd

Large diffs are not rendered by default.

Empty file added decaylanguage/dec/__init__.py
Empty file.
54 changes: 54 additions & 0 deletions decaylanguage/dec/dec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from ..data import open_text
from .. import data
from ..decay.decay import Decay

from enum import Enum

from lark import Lark, Transformer, Tree


class ProtosEnum(Enum):
no = 0
yes = 1


class TreeToDec(Transformer):
def yes(self, items):
return True
def no(self, items):
return False
def global_photos(self, items):
item, = items
return ProtosEnum.yes if item else ProtosEnum.no
def value(self, items):
item, = items
return float(item)
def label(self, items):
item, = items
return str(item)
def photos(self, items):
return ProtosEnum.yes




def define(transformed):
return {x.children[0]:x.children[1] for x in transformed.find_data('define')}
def pythia_def(transformed):
return [x.children for x in transformed.find_data('pythia_def')]
def alias(transformed):
return {x.children[0]:x.children[1] for x in transformed.find_data('alias')}

def chargeconj(transformed):
return {x.children[0]:x.children[1] for x in transformed.find_data('chargeconj')}

# Commands
def global_photos(transformed):
return {x.children[0]:x.children[1] for x in transformed.find_data('global_photos')}

def decay(transformed):
return Tree('decay', list(transformed.find_data('decay')))
def cdecay(transformed):
return [x.children[0] for x in transformed.find_data('cdecay')]
def setlspw(transformed):
return list(transformed.find_data('setlspw'))
5 changes: 5 additions & 0 deletions decaylanguage/particle/particle.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ def from_search(cls, **search_terms):
def from_string(cls, name):
'Get a particle from an AmpGen style name'

# Patch in common names
if name == 'Upsilon':
name = 'Upsilon(1S)'

# Forcable override
bar = False

Expand Down Expand Up @@ -504,3 +508,4 @@ def from_string(cls, name):
vals = sorted(vals)

return vals[0]

121 changes: 121 additions & 0 deletions decaylanguage/particle/pdgid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# encoding : utf8

from __future__ import unicode_literals, print_function, division

# PDG RULE 2
QUARKS = ('d', 'u', 's', 'c', 'b', 't', "b'", "t'")

#PDG RULE 3
LEPTONS = ('e-', 'ν_e', 'µ-', 'ν_µ', 'τ-', 'ν_τ', "τ'-", "ν_τ'")

class PDGID(int):
__slots__ = ()

def valid(self):
'The various queries return 0 if they are false, so this works there too'
return self != 0

@property
def digits(self):
return format(abs(self), '07')

# The PDG digits by name
@property
def n(self):
return int(self.digits[0])
@property
def n_r(self):
return int(self.digits[1])
@property
def n_L(self):
return int(self.digits[2])
@property
def n_q1(self):
return int(self.digits[3])
@property
def n_q2(self):
return int(self.digits[4])
@property
def n_q3(self):
return int(self.digits[5])
@property
def n_J(self):
return int(self.digits[6])

# PDG RULE 1
def is_particle(self):
'Check to see if this is a particle or antiparticle.'
return self > 0

# PDG RULE 2
def is_quark(self):
return 0 < self < 11

# PDG RULE 3
def is_lepton(self):
return 11 < self < 19


@property
def compquark(self):
return CompositeQuark(self)

@property
def diquark(self):
return DiQuark(self)

@property
def meson(self):
return Meson(self)

@property
def baryon(self):
return Baryon(self)


class CompositeQuark(PDGID):
__slots__ = ()

@property
def quarks(self):
return ''.join(QUARKS[int(q)-1] for q in self.digits[3:6] if q != '0')

@property
def spin(self):
return self.n_J

@property
def J(self):
return (self.spin - 1) // 2

class DiQuark(CompositeQuark):
__slots__ = ()

def valid(self):
valid = self < 10**5 and self.n_q1 >= self.n_q2 and self.n_q3 == 0 # PDG RULE 4
valid &= self.n_q2 > 0 # Must contain quarks
valid &= self.n_J % 2 == 1 # Must not have invalid spin
valid &= self.n_q1 <= 6 and self.n_q2 <= 6 # Must have one of 6 quarks
return valid

class Meson(CompositeQuark):
__slots__ = ()

def valid(self):
valid = self < 10**5 and self.n_q2 >= self.n_q3 and self.n_q1 == 0 # PDG RULE 5.a
valid &= self.n_q2 > 0 # Must contain quarks
valid &= self.n_J % 2 == 1 # Must not have invalid spin
valid &= self.n_q1 <= 6 and self.n_q2 <= 6 # Must have one of 6 quarks
return valid

class Baryon(CompositeQuark):
__slots__ = ()

class Custom(PDGID):
__slots__ = ()

class SUSY(PDGID):
__slots__ = ()

class Nuclear(PDGID):
__slots__ = ()
Loading

0 comments on commit 809a77c

Please sign in to comment.