pyslha.py

changeset 211
91f559c01cf7
parent 210
0f4f5472b7d8
child 212
3a6db3deedef
     1.1 --- a/pyslha.py	Mon Apr 29 14:35:12 2013 +0200
     1.2 +++ b/pyslha.py	Mon Apr 29 14:54:16 2013 +0200
     1.3 @@ -36,11 +36,10 @@
     1.4  TODOs:
     1.5  
     1.6    For 2.0.0:
     1.7 -   * Output column alignment cosmetics
     1.8 -   * Precision setting obedience in SLHA output of values
     1.9 +   * Preserve comments from read -> write (needs full-line/inline comment separation?)
    1.10  
    1.11    For 2.1.0:
    1.12 -   * Preserve comments from read -> write (needs full-line/inline comment separation?)
    1.13 +   * Output column alignment cosmetics
    1.14  
    1.15    Later/maybe:
    1.16     * Identify HERWIG decay matrix element to use in ISAWIG
    1.17 @@ -383,22 +382,21 @@
    1.18  def writeSLHABlocks(blocks, precision=8):
    1.19      """Return an SLHA definition as a string, from the supplied blocks dict."""
    1.20      # TODO: Pay attention to space-padding and minus signs for column alignment
    1.21 -    fmte = "%." + str(precision) + "e"
    1.22 -    sep = "   "
    1.23 +    sep = 3 * " "
    1.24      blockstrs = []
    1.25      for bname, b in blocks.iteritems():
    1.26          namestr = b.name
    1.27          if b.q is not None:
    1.28 -            namestr += (" Q= " + fmte) % float(b.q)
    1.29 +            namestr += " Q= " + _autostr(float(b.q), precision)
    1.30          blockstr = "BLOCK %s\n" % namestr
    1.31          entrystrs = []
    1.32          for k, v in b.items():
    1.33              entrystr = ""
    1.34              if type(k) == tuple:
    1.35 -                entrystr += sep.join(_autostr(i) for i in k)
    1.36 +                entrystr += sep.join(_autostr(i, precision) for i in k)
    1.37              elif k is not None:
    1.38 -                entrystr += _autostr(k)
    1.39 -            entrystr += sep + _autostr(v) # TODO: apply precision formatting for floats
    1.40 +                entrystr += _autostr(k, precision)
    1.41 +            entrystr += sep + _autostr(v, precision)
    1.42              entrystrs.append(entrystr)
    1.43          blockstr += "\n".join(entrystrs)
    1.44          blockstrs.append(blockstr)
    1.45 @@ -408,16 +406,15 @@
    1.46  
    1.47  def writeSLHADecays(decays, ignorenobr=False, precision=8):
    1.48      """Return an SLHA decay definition as a string, from the supplied decays dict."""
    1.49 -    fmte = "%." + str(precision) + "e"
    1.50 -    sep = "   "
    1.51 +    sep = 3 * " "
    1.52      blockstrs = []
    1.53      for pid, particle in decays.iteritems():
    1.54 -        blockstr = ("DECAY %d " + fmte + "\n") % (particle.pid, particle.totalwidth or -1)
    1.55 +        blockstr = ("DECAY %d " % particle.pid) + _autostr(particle.totalwidth or -1, precision) + "\n"
    1.56          decaystrs = []
    1.57          for d in particle.decays:
    1.58              if d.br > 0.0 or not ignorenobr:
    1.59                  products_str = sep.join(map(str, d.ids))
    1.60 -                decaystr = sep + (fmte % d.br) + sep + ("%d" % len(d.ids)) + sep + products_str
    1.61 +                decaystr = sep + _autostr(d.br, precision) + sep + str(len(d.ids)) + sep + products_str
    1.62                  decaystrs.append(decaystr)
    1.63          blockstr += "\n".join(decaystrs)
    1.64          blockstrs.append(blockstr)
    1.65 @@ -769,58 +766,6 @@
    1.66      return blocks, decays
    1.67  
    1.68  
    1.69 -def writeISAJET(blocks, decays, outname, ignorenobr=False, precision=8):
    1.70 -    """
    1.71 -    Return a SUSY spectrum definition in the format required for input by ISAJET,
    1.72 -    as a string, from the supplied blocks and decays dicts.
    1.73 -
    1.74 -    The outname parameter specifies the desired output filename from ISAJET: this
    1.75 -    will appear in the first line of the return value.
    1.76 -
    1.77 -    If the ignorenobr parameter is True, do not write decay entries with a
    1.78 -    branching ratio of zero.
    1.79 -    """
    1.80 -    fmte = "%." + str(precision) + "e"
    1.81 -
    1.82 -    masses = blocks["MASS"]
    1.83 -
    1.84 -    ## Init output string
    1.85 -    out = ""
    1.86 -
    1.87 -    ## First line is the output name
    1.88 -    out += "'%s'" % outname + "\n"
    1.89 -
    1.90 -    ## Next the top mass
    1.91 -    out += fmte % masses[6] + "\n"
    1.92 -
    1.93 -    ## Next the top mass
    1.94 -    out += fmte % masses[6] + "\n"
    1.95 -
    1.96 -    ## mSUGRA parameters (one line)
    1.97 -    # e.g. 1273.78,713.286,804.721,4.82337
    1.98 -
    1.99 -    ## Masses and trilinear couplings (3 lines)
   1.100 -    # e.g. 1163.14,1114.15,1118.99,374.664,209.593
   1.101 -    # e.g. 1069.54,1112.7,919.908,374.556,209.381,-972.817,-326.745,-406.494
   1.102 -    # e.g. 1163.14,1114.15,1118.99,374.712,210.328
   1.103 -
   1.104 -    ## RPV couplings (?? lines)
   1.105 -    # e.g. 232.615,445.477
   1.106 -
   1.107 -    ## Etc ???!!!
   1.108 -    # e.g. /
   1.109 -    # e.g. n
   1.110 -    # e.g. y
   1.111 -    # e.g. y
   1.112 -    # e.g. 0.047441 3.80202e-23 0 0 0 2.17356e-22 0 0 5.23773e-09
   1.113 -    # e.g. y
   1.114 -    # e.g. 3.35297e-25 0 0 0 7.34125e-24 0 0 0 3.17951e-22 8.07984e-12 0 0 0 1.76906e-10 0 0 0 7.66184e-09 0 0 0 0 0 0 0 0 0
   1.115 -    # e.g. n
   1.116 -    # e.g. 'susy_RPV_stau_BC1scan_m560_tanb05.txt'
   1.117 -
   1.118 -    return out
   1.119 -
   1.120 -
   1.121  def writeISAWIG(blocks, decays, ignorenobr=False, precision=8):
   1.122      """
   1.123      Return a SUSY spectrum definition in the format produced by ISAWIG for inut to HERWIG
   1.124 @@ -832,8 +777,6 @@
   1.125      If the ignorenobr parameter is True, do not write decay entries with a
   1.126      branching ratio of zero.
   1.127      """
   1.128 -    fmte = "%." + str(precision) + "e"
   1.129 -
   1.130      masses = blocks["MASS"]
   1.131  
   1.132      ## Init output string
   1.133 @@ -854,7 +797,7 @@
   1.134                  lifetime = 1.0/(width * 1.51926778e24) ## lifetime in seconds == hbar/width in GeV
   1.135          except:
   1.136              pass
   1.137 -        massout += ("%d " + fmte + " " + fmte + "\n") % (pdgid2herwigid(pid), masses[pid], lifetime)
   1.138 +        massout += ("%d " % pdgid2herwigid(pid)) + _autostr(masses[pid], precision) + " " + _autostr(lifetime, precision) + "\n"
   1.139      out += "%d\n" % massout.count("\n")
   1.140      out += massout
   1.141  
   1.142 @@ -892,7 +835,7 @@
   1.143              if len(d.ids) == 3:
   1.144                  # TODO: How to determine the conditions for using 200 and 300 MEs? Enumeration of affected decays?
   1.145                  pass
   1.146 -            decayout += ("%d " + fmte + " %d ") % (hwid, d.br, nme)
   1.147 +            decayout += ("%d " % hwid) + _autostr(d.br, precision) + (" %d " % nme)
   1.148  
   1.149              def is_quark(pid):
   1.150                  return (abs(pid) in range(1, 7))
   1.151 @@ -1038,25 +981,34 @@
   1.152  
   1.153      ## Now the SUSY parameters
   1.154      ## TANB, ALPHAH:
   1.155 -    out += (fmte + " " + fmte + "\n") % (blocks["MINPAR"].value(3), blocks["ALPHA"].value())
   1.156 +    out += _autostr(blocks["MINPAR"][3], precision) + " " + _autostr(blocks["ALPHA"].value(), precision) + "\n"
   1.157      ## Neutralino mixing matrix
   1.158      nmix = blocks["NMIX"]
   1.159      for i in xrange(1, 5):
   1.160 -        out += (fmte + " " + fmte + " " + fmte + " " + fmte + "\n") % (nmix[i,1], nmix[i,2], nmix[i,3], nmix[i,4])
   1.161 +        out += _autostr(nmix[i,1], precision) + " " + \
   1.162 +               _autostr(nmix[i,2], precision) + " " + \
   1.163 +               _autostr(nmix[i,3], precision) + " " + \
   1.164 +               _autostr(nmix[i,4], precision) + "\n"
   1.165      ## Chargino mixing matrices V and U
   1.166      vmix = blocks["VMIX"]
   1.167 -    out += (fmte + " " + fmte + " " + fmte + " " + fmte + "\n") % (vmix[1,1], vmix[1,2], vmix[2,1], vmix[2,2])
   1.168 +    out += _autostr(vmix[1,1], precision) + " " + \
   1.169 +           _autostr(vmix[1,2], precision) + " " + \
   1.170 +           _autostr(vmix[2,1], precision) + " " + \
   1.171 +           _autostr(vmix[2,2], precision) + "\n"
   1.172      umix = blocks["UMIX"]
   1.173 -    out += (fmte + " " + fmte + " " + fmte + " " + fmte + "\n") % (umix[1,1], umix[1,2], umix[2,1], umix[2,2])
   1.174 +    out += _autostr(umix[1,1], precision) + " " + \
   1.175 +           _autostr(umix[1,2], precision) + " " + \
   1.176 +           _autostr(umix[2,1], precision) + " " + \
   1.177 +           _autostr(umix[2,2], precision) + "\n"
   1.178      ## THETAT,THETAB,THETAL
   1.179      import math
   1.180 -    out += (fmte + " " + fmte + " " + fmte + " " + "\n") % (math.acos(blocks["STOPMIX"][1,1]),
   1.181 -                                                            math.acos(blocks["SBOTMIX"][1,1]),
   1.182 -                                                            math.acos(blocks["STAUMIX"][1,1]))
   1.183 +    out += _autostr(math.acos(blocks["STOPMIX"][1,1]), precision) + " " + \
   1.184 +           _autostr(math.acos(blocks["SBOTMIX"][1,1]), precision) + " " + \
   1.185 +           _autostr(math.acos(blocks["STAUMIX"][1,1]), precision) + "\n"
   1.186      ## ATSS,ABSS,ALSS
   1.187 -    out += (fmte + " " + fmte + " " + fmte + " " + "\n") % (blocks["AU"][3,3],
   1.188 -                                                            blocks["AD"][3,3],
   1.189 -                                                            blocks["AE"][3,3])
   1.190 +    out += _autostr(blocks["AU"][3,3], precision) + " " + \
   1.191 +           _autostr(blocks["AD"][3,3], precision) + " " + \
   1.192 +           _autostr(blocks["AE"][3,3], precision) + "\n"
   1.193      ## MUSS == sign(mu)
   1.194      out += "%f\n" % blocks["MINPAR"][4]
   1.195  

mercurial