pyslha.py

changeset 124
7bd52be093b2
parent 123
c85e29bc13c4
child 127
bfd5be72d711
     1.1 --- a/pyslha.py	Sun Feb 27 00:14:05 2011 +0100
     1.2 +++ b/pyslha.py	Sun Feb 27 00:35:57 2011 +0100
     1.3 @@ -262,6 +262,152 @@
     1.4      return rtn
     1.5  
     1.6  
     1.7 +def writeSLHAFile(spcfilename, blocks, decays, **kwargs):
     1.8 +    """
     1.9 +    Write an SLHA file from the supplied blocks and decays dicts.
    1.10 +
    1.11 +    Other keyword parameters are passed to writeSLHA.
    1.12 +    """
    1.13 +    f = open(spcfilename, "w")
    1.14 +    f.write(writeSLHA(blocks, decays, kwargs))
    1.15 +    f.close()
    1.16 +
    1.17 +
    1.18 +# TODO: Split writeSLHA into writeSLHA{Blocks,Decays}
    1.19 +
    1.20 +
    1.21 +def writeSLHA(blocks, decays, ignorenobr=False):
    1.22 +    """
    1.23 +    Return an SLHA definition as a string, from the supplied blocks and decays dicts.
    1.24 +    """
    1.25 +    sep = "   "
    1.26 +    out = ""
    1.27 +    def dict_hier_strs(d, s=""):
    1.28 +        if type(d) is dict:
    1.29 +            for k, v in sorted(d.iteritems()):
    1.30 +                for s2 in dict_hier_strs(v, s + sep + _autostr(k)):
    1.31 +                    yield s2
    1.32 +        else:
    1.33 +            yield s + sep + _autostr(d)
    1.34 +    ## Blocks
    1.35 +    for bname, b in sorted(blocks.iteritems()):
    1.36 +        namestr = b.name
    1.37 +        if b.q is not None:
    1.38 +            namestr += " Q= %e" % b.q
    1.39 +        out += "BLOCK %s\n" % namestr
    1.40 +        for s in dict_hier_strs(b.entries):
    1.41 +            out += sep + s + "\n"
    1.42 +        out += "\n"
    1.43 +    ## Decays
    1.44 +    for pid, particle in sorted(decays.iteritems()):
    1.45 +        out += "DECAY %d %e\n" % (particle.pid, particle.totalwidth or -1)
    1.46 +        for d in sorted(particle.decays):
    1.47 +            if d.br > 0.0 or not ignorenobr:
    1.48 +                products_str = "   ".join(map(str, d.ids))
    1.49 +                out += sep + "%e" % d.br + sep + "%d" % len(d.ids) + sep + products_str + "\n"
    1.50 +        out += "\n"
    1.51 +    return out
    1.52 +
    1.53 +
    1.54 +
    1.55 +###############################################################################
    1.56 +## ISAWIG handling
    1.57 +
    1.58 +## Static array of HERWIG IDHW codes mapped to PDG MC ID codes, based on
    1.59 +## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
    1.60 +## + the IDPDG array and section 4.13 of the HERWIG manual.
    1.61 +_HERWIGID2PDGID = {}
    1.62 +_HERWIGID2PDGID[7]   = -1
    1.63 +_HERWIGID2PDGID[8]   = -2
    1.64 +_HERWIGID2PDGID[9]   = -3
    1.65 +_HERWIGID2PDGID[10]  = -4
    1.66 +_HERWIGID2PDGID[11]  = -5
    1.67 +_HERWIGID2PDGID[12]  = -6
    1.68 +_HERWIGID2PDGID[13]  =  21
    1.69 +_HERWIGID2PDGID[59]  =  22
    1.70 +_HERWIGID2PDGID[121] =  11
    1.71 +_HERWIGID2PDGID[122] =  12
    1.72 +_HERWIGID2PDGID[123] =  13
    1.73 +_HERWIGID2PDGID[124] =  14
    1.74 +_HERWIGID2PDGID[125] =  15
    1.75 +_HERWIGID2PDGID[126] =  16
    1.76 +_HERWIGID2PDGID[127] = -11
    1.77 +_HERWIGID2PDGID[128] = -12
    1.78 +_HERWIGID2PDGID[129] = -13
    1.79 +_HERWIGID2PDGID[130] = -14
    1.80 +_HERWIGID2PDGID[131] = -15
    1.81 +_HERWIGID2PDGID[132] = -16
    1.82 +_HERWIGID2PDGID[203] =  25 ## HIGGSL0 (== PDG standard in this direction)
    1.83 +_HERWIGID2PDGID[204] =  35 ## HIGGSH0
    1.84 +_HERWIGID2PDGID[205] =  36 ## HIGGSA0
    1.85 +_HERWIGID2PDGID[206] =  37 ## HIGGS+
    1.86 +_HERWIGID2PDGID[207] = -37 ## HIGGS-
    1.87 +_HERWIGID2PDGID[401] =  1000001 ## SSDLBR
    1.88 +_HERWIGID2PDGID[407] = -1000001 ## SSDLBR
    1.89 +_HERWIGID2PDGID[402] =  1000002 ## SSULBR
    1.90 +_HERWIGID2PDGID[408] = -1000002 ## SSUL
    1.91 +_HERWIGID2PDGID[403] =  1000003 ## SSSLBR
    1.92 +_HERWIGID2PDGID[409] = -1000003 ## SSSL
    1.93 +_HERWIGID2PDGID[404] =  1000004 ## SSCLBR
    1.94 +_HERWIGID2PDGID[410] = -1000004 ## SSCL
    1.95 +_HERWIGID2PDGID[405] =  1000005 ## SSB1BR
    1.96 +_HERWIGID2PDGID[411] = -1000005 ## SSB1
    1.97 +_HERWIGID2PDGID[406] =  1000006 ## SST1BR
    1.98 +_HERWIGID2PDGID[412] = -1000006 ## SST1
    1.99 +_HERWIGID2PDGID[413] =  2000001 ## SSDR
   1.100 +_HERWIGID2PDGID[419] = -2000001 ## SSDRBR
   1.101 +_HERWIGID2PDGID[414] =  2000002 ## SSUR
   1.102 +_HERWIGID2PDGID[420] = -2000002 ## SSURBR
   1.103 +_HERWIGID2PDGID[415] =  2000003 ## SSSR
   1.104 +_HERWIGID2PDGID[421] = -2000003 ## SSSRBR
   1.105 +_HERWIGID2PDGID[416] =  2000004 ## SSCR
   1.106 +_HERWIGID2PDGID[422] = -2000004 ## SSCRBR
   1.107 +_HERWIGID2PDGID[417] =  2000005 ## SSB2
   1.108 +_HERWIGID2PDGID[423] = -2000005 ## SSB2BR
   1.109 +_HERWIGID2PDGID[418] =  2000006 ## SST2
   1.110 +_HERWIGID2PDGID[424] = -2000006 ## SST2BR
   1.111 +_HERWIGID2PDGID[425] =  1000011 ## SSEL-
   1.112 +_HERWIGID2PDGID[431] = -1000011 ## SSEL+
   1.113 +_HERWIGID2PDGID[426] =  1000012 ## SSNUEL
   1.114 +_HERWIGID2PDGID[432] = -1000012 ## SSNUELBR
   1.115 +_HERWIGID2PDGID[427] =  1000013 ## SSMUL-
   1.116 +_HERWIGID2PDGID[433] = -1000013 ## SSMUL+
   1.117 +_HERWIGID2PDGID[428] =  1000014 ## SSNUMUL
   1.118 +_HERWIGID2PDGID[434] = -1000014 ## SSNUMLBR
   1.119 +_HERWIGID2PDGID[429] =  1000015 ## SSTAU1-
   1.120 +_HERWIGID2PDGID[435] = -1000015 ## SSTAU1+
   1.121 +_HERWIGID2PDGID[430] =  1000016 ## SSNUTL
   1.122 +_HERWIGID2PDGID[436] = -1000016 ## SSNUTLBR
   1.123 +_HERWIGID2PDGID[437] =  2000011 ## SSEL-
   1.124 +_HERWIGID2PDGID[443] = -2000011 ## SSEL+
   1.125 +_HERWIGID2PDGID[438] =  2000012 ## SSNUEL
   1.126 +_HERWIGID2PDGID[444] = -2000012 ## SSNUELBR
   1.127 +_HERWIGID2PDGID[439] =  2000013 ## SSMUL-
   1.128 +_HERWIGID2PDGID[445] = -2000013 ## SSMUL+
   1.129 +_HERWIGID2PDGID[440] =  2000014 ## SSNUMUL
   1.130 +_HERWIGID2PDGID[446] = -2000014 ## SSNUMLBR
   1.131 +_HERWIGID2PDGID[441] =  2000015 ## SSTAU1-
   1.132 +_HERWIGID2PDGID[447] = -2000015 ## SSTAU1+
   1.133 +_HERWIGID2PDGID[442] =  2000016 ## SSNUTL
   1.134 +_HERWIGID2PDGID[448] = -2000016 ## SSNUTLBR
   1.135 +_HERWIGID2PDGID[449] =  1000021 ## GLUINO
   1.136 +_HERWIGID2PDGID[450] =  1000022 ## NTLINO1
   1.137 +_HERWIGID2PDGID[451] =  1000023 ## NTLINO2
   1.138 +_HERWIGID2PDGID[452] =  1000025 ## NTLINO3
   1.139 +_HERWIGID2PDGID[453] =  1000035 ## NTLINO4
   1.140 +_HERWIGID2PDGID[454] =  1000024 ## CHGINO1+
   1.141 +_HERWIGID2PDGID[456] = -1000024 ## CHGINO1-
   1.142 +_HERWIGID2PDGID[455] =  1000037 ## CHGINO2+
   1.143 +_HERWIGID2PDGID[457] = -1000037 ## CHGINO2-
   1.144 +_HERWIGID2PDGID[458] =  1000039 ## GRAVTINO
   1.145 +
   1.146 +def herwigid2pdgid(hwid):
   1.147 +    """
   1.148 +    Convert a particle ID code in the HERWIG internal IDHW format (as used by
   1.149 +    ISAWIG) into its equivalent in the standard PDG ID code definition.
   1.150 +    """
   1.151 +    return _HERWIGID2PDGID.get(hwid, hwid)
   1.152 +
   1.153  
   1.154  def readISAWIG(isastr, ignorenobr=False):
   1.155      """
   1.156 @@ -277,93 +423,6 @@
   1.157      branching ratio of zero.
   1.158      """
   1.159  
   1.160 -    ## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   1.161 -    ## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   1.162 -    ## + the IDPDG array and section 4.13 of the HERWIG manual.
   1.163 -    HERWIGID2PDGID = {}
   1.164 -    HERWIGID2PDGID[7]   = -1
   1.165 -    HERWIGID2PDGID[8]   = -2
   1.166 -    HERWIGID2PDGID[9]   = -3
   1.167 -    HERWIGID2PDGID[10]  = -4
   1.168 -    HERWIGID2PDGID[11]  = -5
   1.169 -    HERWIGID2PDGID[12]  = -6
   1.170 -    HERWIGID2PDGID[13]  =  21
   1.171 -    HERWIGID2PDGID[59]  =  22
   1.172 -    HERWIGID2PDGID[121] =  11
   1.173 -    HERWIGID2PDGID[122] =  12
   1.174 -    HERWIGID2PDGID[123] =  13
   1.175 -    HERWIGID2PDGID[124] =  14
   1.176 -    HERWIGID2PDGID[125] =  15
   1.177 -    HERWIGID2PDGID[126] =  16
   1.178 -    HERWIGID2PDGID[127] = -11
   1.179 -    HERWIGID2PDGID[128] = -12
   1.180 -    HERWIGID2PDGID[129] = -13
   1.181 -    HERWIGID2PDGID[130] = -14
   1.182 -    HERWIGID2PDGID[131] = -15
   1.183 -    HERWIGID2PDGID[132] = -16
   1.184 -    HERWIGID2PDGID[203] =  25 ## HIGGSL0 (== PDG standard in this direction)
   1.185 -    HERWIGID2PDGID[204] =  35 ## HIGGSH0
   1.186 -    HERWIGID2PDGID[205] =  36 ## HIGGSA0
   1.187 -    HERWIGID2PDGID[206] =  37 ## HIGGS+
   1.188 -    HERWIGID2PDGID[207] = -37 ## HIGGS-
   1.189 -    HERWIGID2PDGID[401] =  1000001 ## SSDLBR
   1.190 -    HERWIGID2PDGID[407] = -1000001 ## SSDLBR
   1.191 -    HERWIGID2PDGID[402] =  1000002 ## SSULBR
   1.192 -    HERWIGID2PDGID[408] = -1000002 ## SSUL
   1.193 -    HERWIGID2PDGID[403] =  1000003 ## SSSLBR
   1.194 -    HERWIGID2PDGID[409] = -1000003 ## SSSL
   1.195 -    HERWIGID2PDGID[404] =  1000004 ## SSCLBR
   1.196 -    HERWIGID2PDGID[410] = -1000004 ## SSCL
   1.197 -    HERWIGID2PDGID[405] =  1000005 ## SSB1BR
   1.198 -    HERWIGID2PDGID[411] = -1000005 ## SSB1
   1.199 -    HERWIGID2PDGID[406] =  1000006 ## SST1BR
   1.200 -    HERWIGID2PDGID[412] = -1000006 ## SST1
   1.201 -    HERWIGID2PDGID[413] =  2000001 ## SSDR
   1.202 -    HERWIGID2PDGID[419] = -2000001 ## SSDRBR
   1.203 -    HERWIGID2PDGID[414] =  2000002 ## SSUR
   1.204 -    HERWIGID2PDGID[420] = -2000002 ## SSURBR
   1.205 -    HERWIGID2PDGID[415] =  2000003 ## SSSR
   1.206 -    HERWIGID2PDGID[421] = -2000003 ## SSSRBR
   1.207 -    HERWIGID2PDGID[416] =  2000004 ## SSCR
   1.208 -    HERWIGID2PDGID[422] = -2000004 ## SSCRBR
   1.209 -    HERWIGID2PDGID[417] =  2000005 ## SSB2
   1.210 -    HERWIGID2PDGID[423] = -2000005 ## SSB2BR
   1.211 -    HERWIGID2PDGID[418] =  2000006 ## SST2
   1.212 -    HERWIGID2PDGID[424] = -2000006 ## SST2BR
   1.213 -    HERWIGID2PDGID[425] =  1000011 ## SSEL-
   1.214 -    HERWIGID2PDGID[431] = -1000011 ## SSEL+
   1.215 -    HERWIGID2PDGID[426] =  1000012 ## SSNUEL
   1.216 -    HERWIGID2PDGID[432] = -1000012 ## SSNUELBR
   1.217 -    HERWIGID2PDGID[427] =  1000013 ## SSMUL-
   1.218 -    HERWIGID2PDGID[433] = -1000013 ## SSMUL+
   1.219 -    HERWIGID2PDGID[428] =  1000014 ## SSNUMUL
   1.220 -    HERWIGID2PDGID[434] = -1000014 ## SSNUMLBR
   1.221 -    HERWIGID2PDGID[429] =  1000015 ## SSTAU1-
   1.222 -    HERWIGID2PDGID[435] = -1000015 ## SSTAU1+
   1.223 -    HERWIGID2PDGID[430] =  1000016 ## SSNUTL
   1.224 -    HERWIGID2PDGID[436] = -1000016 ## SSNUTLBR
   1.225 -    HERWIGID2PDGID[437] =  2000011 ## SSEL-
   1.226 -    HERWIGID2PDGID[443] = -2000011 ## SSEL+
   1.227 -    HERWIGID2PDGID[438] =  2000012 ## SSNUEL
   1.228 -    HERWIGID2PDGID[444] = -2000012 ## SSNUELBR
   1.229 -    HERWIGID2PDGID[439] =  2000013 ## SSMUL-
   1.230 -    HERWIGID2PDGID[445] = -2000013 ## SSMUL+
   1.231 -    HERWIGID2PDGID[440] =  2000014 ## SSNUMUL
   1.232 -    HERWIGID2PDGID[446] = -2000014 ## SSNUMLBR
   1.233 -    HERWIGID2PDGID[441] =  2000015 ## SSTAU1-
   1.234 -    HERWIGID2PDGID[447] = -2000015 ## SSTAU1+
   1.235 -    HERWIGID2PDGID[442] =  2000016 ## SSNUTL
   1.236 -    HERWIGID2PDGID[448] = -2000016 ## SSNUTLBR
   1.237 -    HERWIGID2PDGID[449] =  1000021 ## GLUINO
   1.238 -    HERWIGID2PDGID[450] =  1000022 ## NTLINO1
   1.239 -    HERWIGID2PDGID[451] =  1000023 ## NTLINO2
   1.240 -    HERWIGID2PDGID[452] =  1000025 ## NTLINO3
   1.241 -    HERWIGID2PDGID[453] =  1000035 ## NTLINO4
   1.242 -    HERWIGID2PDGID[454] =  1000024 ## CHGINO1+
   1.243 -    HERWIGID2PDGID[456] = -1000024 ## CHGINO1-
   1.244 -    HERWIGID2PDGID[455] =  1000037 ## CHGINO2+
   1.245 -    HERWIGID2PDGID[457] = -1000037 ## CHGINO2-
   1.246 -    HERWIGID2PDGID[458] =  1000039 ## GRAVTINO
   1.247  
   1.248      blocks = {}
   1.249      decays = {}
   1.250 @@ -391,7 +450,7 @@
   1.251      for i in xrange(numentries):
   1.252          hwid, mass, lifetime = getnextvalidlineitems()
   1.253          width = 1.0/(lifetime * 1.51926778e24) ## width in GeV == hbar/lifetime in seconds
   1.254 -        pdgid = HERWIGID2PDGID.get(hwid, hwid)
   1.255 +        pdgid = herwigid2pdgid(hwid)
   1.256          masses.add_entry((pdgid, mass))
   1.257          decays[pdgid] = Particle(pdgid, width, mass)
   1.258          #print pdgid, mass, width
   1.259 @@ -404,14 +463,14 @@
   1.260              #print n, numentries-1, d, numdecays-1
   1.261              decayitems = getnextvalidlineitems()
   1.262              hwid = decayitems[0]
   1.263 -            pdgid = HERWIGID2PDGID.get(hwid, hwid)
   1.264 +            pdgid = herwigid2pdgid(hwid)
   1.265              br = decayitems[1]
   1.266              nme = decayitems[2]
   1.267              daughter_hwids = decayitems[3:]
   1.268              daughter_pdgids = []
   1.269              for hw in daughter_hwids:
   1.270                  if hw != 0:
   1.271 -                    daughter_pdgids.append(HERWIGID2PDGID.get(hw, hw))
   1.272 +                    daughter_pdgids.append(herwigid2pdgid(hw))
   1.273              if not decays.has_key(pdgid):
   1.274                  #print "Decay for unlisted particle %d, %d" % (hwid, pdgid)
   1.275                  decays[pdgid] = Particle(pdgid)
   1.276 @@ -478,51 +537,102 @@
   1.277      return blocks, decays
   1.278  
   1.279  
   1.280 -def writeSLHAFile(spcfilename, blocks, decays, **kwargs):
   1.281 +## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   1.282 +## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   1.283 +## + the IDPDG array and section 4.13 of the HERWIG manual.
   1.284 +_PDGID2HERWIGID = {}
   1.285 +_PDGID2HERWIGID[      -1] = 7
   1.286 +_PDGID2HERWIGID[      -2] = 8
   1.287 +_PDGID2HERWIGID[      -3] = 9
   1.288 +_PDGID2HERWIGID[      -4] = 10
   1.289 +_PDGID2HERWIGID[      -5] = 11
   1.290 +_PDGID2HERWIGID[      -6] = 12
   1.291 +_PDGID2HERWIGID[      21] = 13
   1.292 +_PDGID2HERWIGID[      22] = 59
   1.293 +_PDGID2HERWIGID[      11] = 121
   1.294 +_PDGID2HERWIGID[      12] = 122
   1.295 +_PDGID2HERWIGID[      13] = 123
   1.296 +_PDGID2HERWIGID[      14] = 124
   1.297 +_PDGID2HERWIGID[      15] = 125
   1.298 +_PDGID2HERWIGID[      16] = 126
   1.299 +_PDGID2HERWIGID[     -11] = 127
   1.300 +_PDGID2HERWIGID[     -12] = 128
   1.301 +_PDGID2HERWIGID[     -13] = 129
   1.302 +_PDGID2HERWIGID[     -14] = 130
   1.303 +_PDGID2HERWIGID[     -15] = 131
   1.304 +_PDGID2HERWIGID[     -16] = 132
   1.305 +_PDGID2HERWIGID[      25] = 203 ## HIGGSL0 (added for PDG standard -> HERWIG IDHW)
   1.306 +_PDGID2HERWIGID[      26] = 203 ## HIGGSL0
   1.307 +_PDGID2HERWIGID[      35] = 204 ## HIGGSH0
   1.308 +_PDGID2HERWIGID[      36] = 205 ## HIGGSA0
   1.309 +_PDGID2HERWIGID[      37] = 206 ## HIGGS+
   1.310 +_PDGID2HERWIGID[     -37] = 207 ## HIGGS-
   1.311 +_PDGID2HERWIGID[ 1000001] = 401 ## SSDLBR
   1.312 +_PDGID2HERWIGID[-1000001] = 407 ## SSDLBR
   1.313 +_PDGID2HERWIGID[ 1000002] = 402 ## SSULBR
   1.314 +_PDGID2HERWIGID[-1000002] = 408 ## SSUL
   1.315 +_PDGID2HERWIGID[ 1000003] = 403 ## SSSLBR
   1.316 +_PDGID2HERWIGID[-1000003] = 409 ## SSSL
   1.317 +_PDGID2HERWIGID[ 1000004] = 404 ## SSCLBR
   1.318 +_PDGID2HERWIGID[-1000004] = 410 ## SSCL
   1.319 +_PDGID2HERWIGID[ 1000005] = 405 ## SSB1BR
   1.320 +_PDGID2HERWIGID[-1000005] = 411 ## SSB1
   1.321 +_PDGID2HERWIGID[ 1000006] = 406 ## SST1BR
   1.322 +_PDGID2HERWIGID[-1000006] = 412 ## SST1
   1.323 +_PDGID2HERWIGID[ 2000001] = 413 ## SSDR
   1.324 +_PDGID2HERWIGID[-2000001] = 419 ## SSDRBR
   1.325 +_PDGID2HERWIGID[ 2000002] = 414 ## SSUR
   1.326 +_PDGID2HERWIGID[-2000002] = 420 ## SSURBR
   1.327 +_PDGID2HERWIGID[ 2000003] = 415 ## SSSR
   1.328 +_PDGID2HERWIGID[-2000003] = 421 ## SSSRBR
   1.329 +_PDGID2HERWIGID[ 2000004] = 416 ## SSCR
   1.330 +_PDGID2HERWIGID[-2000004] = 422 ## SSCRBR
   1.331 +_PDGID2HERWIGID[ 2000005] = 417 ## SSB2
   1.332 +_PDGID2HERWIGID[-2000005] = 423 ## SSB2BR
   1.333 +_PDGID2HERWIGID[ 2000006] = 418 ## SST2
   1.334 +_PDGID2HERWIGID[-2000006] = 424 ## SST2BR
   1.335 +_PDGID2HERWIGID[ 1000011] = 425 ## SSEL-
   1.336 +_PDGID2HERWIGID[-1000011] = 431 ## SSEL+
   1.337 +_PDGID2HERWIGID[ 1000012] = 426 ## SSNUEL
   1.338 +_PDGID2HERWIGID[-1000012] = 432 ## SSNUELBR
   1.339 +_PDGID2HERWIGID[ 1000013] = 427 ## SSMUL-
   1.340 +_PDGID2HERWIGID[-1000013] = 433 ## SSMUL+
   1.341 +_PDGID2HERWIGID[ 1000014] = 428 ## SSNUMUL
   1.342 +_PDGID2HERWIGID[-1000014] = 434 ## SSNUMLBR
   1.343 +_PDGID2HERWIGID[ 1000015] = 429 ## SSTAU1-
   1.344 +_PDGID2HERWIGID[-1000015] = 435 ## SSTAU1+
   1.345 +_PDGID2HERWIGID[ 1000016] = 430 ## SSNUTL
   1.346 +_PDGID2HERWIGID[-1000016] = 436 ## SSNUTLBR
   1.347 +_PDGID2HERWIGID[ 2000011] = 437 ## SSEL-
   1.348 +_PDGID2HERWIGID[-2000011] = 443 ## SSEL+
   1.349 +_PDGID2HERWIGID[ 2000012] = 438 ## SSNUEL
   1.350 +_PDGID2HERWIGID[-2000012] = 444 ## SSNUELBR
   1.351 +_PDGID2HERWIGID[ 2000013] = 439 ## SSMUL-
   1.352 +_PDGID2HERWIGID[-2000013] = 445 ## SSMUL+
   1.353 +_PDGID2HERWIGID[ 2000014] = 440 ## SSNUMUL
   1.354 +_PDGID2HERWIGID[-2000014] = 446 ## SSNUMLBR
   1.355 +_PDGID2HERWIGID[ 2000015] = 441 ## SSTAU1-
   1.356 +_PDGID2HERWIGID[-2000015] = 447 ## SSTAU1+
   1.357 +_PDGID2HERWIGID[ 2000016] = 442 ## SSNUTL
   1.358 +_PDGID2HERWIGID[-2000016] = 448 ## SSNUTLBR
   1.359 +_PDGID2HERWIGID[ 1000021] = 449 ## GLUINO
   1.360 +_PDGID2HERWIGID[ 1000022] = 450 ## NTLINO1
   1.361 +_PDGID2HERWIGID[ 1000023] = 451 ## NTLINO2
   1.362 +_PDGID2HERWIGID[ 1000025] = 452 ## NTLINO3
   1.363 +_PDGID2HERWIGID[ 1000035] = 453 ## NTLINO4
   1.364 +_PDGID2HERWIGID[ 1000024] = 454 ## CHGINO1+
   1.365 +_PDGID2HERWIGID[-1000024] = 456 ## CHGINO1-
   1.366 +_PDGID2HERWIGID[ 1000037] = 455 ## CHGINO2+
   1.367 +_PDGID2HERWIGID[-1000037] = 457 ## CHGINO2-
   1.368 +_PDGID2HERWIGID[ 1000039] = 458 ## GRAVTINO
   1.369 +
   1.370 +def pdgid2herwigid(pdgid):
   1.371      """
   1.372 -    Write an SLHA file from the supplied blocks and decays dicts.
   1.373 +    Convert a particle ID code in the standard PDG ID code definition into
   1.374 +    its equivalent in the HERWIG internal IDHW format (as used by ISAWIG).
   1.375 +    """
   1.376 +    return _PDGID2HERWIGID.get(pdgid, pdgid)
   1.377  
   1.378 -    Other keyword parameters are passed to writeSLHA.
   1.379 -    """
   1.380 -    f = open(spcfilename, "w")
   1.381 -    f.write(writeSLHA(blocks, decays, kwargs))
   1.382 -    f.close()
   1.383 -
   1.384 -
   1.385 -# TODO: Split writeSLHA into writeSLHA{Blocks,Decays}
   1.386 -
   1.387 -
   1.388 -def writeSLHA(blocks, decays, ignorenobr=False):
   1.389 -    """
   1.390 -    Return an SLHA definition as a string, from the supplied blocks and decays dicts.
   1.391 -    """
   1.392 -    sep = "   "
   1.393 -    out = ""
   1.394 -    def dict_hier_strs(d, s=""):
   1.395 -        if type(d) is dict:
   1.396 -            for k, v in sorted(d.iteritems()):
   1.397 -                for s2 in dict_hier_strs(v, s + sep + _autostr(k)):
   1.398 -                    yield s2
   1.399 -        else:
   1.400 -            yield s + sep + _autostr(d)
   1.401 -    ## Blocks
   1.402 -    for bname, b in sorted(blocks.iteritems()):
   1.403 -        namestr = b.name
   1.404 -        if b.q is not None:
   1.405 -            namestr += " Q= %e" % b.q
   1.406 -        out += "BLOCK %s\n" % namestr
   1.407 -        for s in dict_hier_strs(b.entries):
   1.408 -            out += sep + s + "\n"
   1.409 -        out += "\n"
   1.410 -    ## Decays
   1.411 -    for pid, particle in sorted(decays.iteritems()):
   1.412 -        out += "DECAY %d %e\n" % (particle.pid, particle.totalwidth or -1)
   1.413 -        for d in sorted(particle.decays):
   1.414 -            if d.br > 0.0 or not ignorenobr:
   1.415 -                products_str = "   ".join(map(str, d.ids))
   1.416 -                out += sep + "%e" % d.br + sep + "%d" % len(d.ids) + sep + products_str + "\n"
   1.417 -        out += "\n"
   1.418 -    return out
   1.419  
   1.420  
   1.421  
   1.422 @@ -549,94 +659,6 @@
   1.423      If the ignorenobr parameter is True, do not write decay entries with a
   1.424      branching ratio of zero.
   1.425      """
   1.426 -    ## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   1.427 -    ## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   1.428 -    ## + the IDPDG array and section 4.13 of the HERWIG manual.
   1.429 -    PDGID2HERWIGID = {}
   1.430 -    PDGID2HERWIGID[      -1] = 7
   1.431 -    PDGID2HERWIGID[      -2] = 8
   1.432 -    PDGID2HERWIGID[      -3] = 9
   1.433 -    PDGID2HERWIGID[      -4] = 10
   1.434 -    PDGID2HERWIGID[      -5] = 11
   1.435 -    PDGID2HERWIGID[      -6] = 12
   1.436 -    PDGID2HERWIGID[      21] = 13
   1.437 -    PDGID2HERWIGID[      22] = 59
   1.438 -    PDGID2HERWIGID[      11] = 121
   1.439 -    PDGID2HERWIGID[      12] = 122
   1.440 -    PDGID2HERWIGID[      13] = 123
   1.441 -    PDGID2HERWIGID[      14] = 124
   1.442 -    PDGID2HERWIGID[      15] = 125
   1.443 -    PDGID2HERWIGID[      16] = 126
   1.444 -    PDGID2HERWIGID[     -11] = 127
   1.445 -    PDGID2HERWIGID[     -12] = 128
   1.446 -    PDGID2HERWIGID[     -13] = 129
   1.447 -    PDGID2HERWIGID[     -14] = 130
   1.448 -    PDGID2HERWIGID[     -15] = 131
   1.449 -    PDGID2HERWIGID[     -16] = 132
   1.450 -    PDGID2HERWIGID[      25] = 203 ## HIGGSL0 (added for PDG standard -> HERWIG IDHW)
   1.451 -    PDGID2HERWIGID[      26] = 203 ## HIGGSL0
   1.452 -    PDGID2HERWIGID[      35] = 204 ## HIGGSH0
   1.453 -    PDGID2HERWIGID[      36] = 205 ## HIGGSA0
   1.454 -    PDGID2HERWIGID[      37] = 206 ## HIGGS+
   1.455 -    PDGID2HERWIGID[     -37] = 207 ## HIGGS-
   1.456 -    PDGID2HERWIGID[ 1000001] = 401 ## SSDLBR
   1.457 -    PDGID2HERWIGID[-1000001] = 407 ## SSDLBR
   1.458 -    PDGID2HERWIGID[ 1000002] = 402 ## SSULBR
   1.459 -    PDGID2HERWIGID[-1000002] = 408 ## SSUL
   1.460 -    PDGID2HERWIGID[ 1000003] = 403 ## SSSLBR
   1.461 -    PDGID2HERWIGID[-1000003] = 409 ## SSSL
   1.462 -    PDGID2HERWIGID[ 1000004] = 404 ## SSCLBR
   1.463 -    PDGID2HERWIGID[-1000004] = 410 ## SSCL
   1.464 -    PDGID2HERWIGID[ 1000005] = 405 ## SSB1BR
   1.465 -    PDGID2HERWIGID[-1000005] = 411 ## SSB1
   1.466 -    PDGID2HERWIGID[ 1000006] = 406 ## SST1BR
   1.467 -    PDGID2HERWIGID[-1000006] = 412 ## SST1
   1.468 -    PDGID2HERWIGID[ 2000001] = 413 ## SSDR
   1.469 -    PDGID2HERWIGID[-2000001] = 419 ## SSDRBR
   1.470 -    PDGID2HERWIGID[ 2000002] = 414 ## SSUR
   1.471 -    PDGID2HERWIGID[-2000002] = 420 ## SSURBR
   1.472 -    PDGID2HERWIGID[ 2000003] = 415 ## SSSR
   1.473 -    PDGID2HERWIGID[-2000003] = 421 ## SSSRBR
   1.474 -    PDGID2HERWIGID[ 2000004] = 416 ## SSCR
   1.475 -    PDGID2HERWIGID[-2000004] = 422 ## SSCRBR
   1.476 -    PDGID2HERWIGID[ 2000005] = 417 ## SSB2
   1.477 -    PDGID2HERWIGID[-2000005] = 423 ## SSB2BR
   1.478 -    PDGID2HERWIGID[ 2000006] = 418 ## SST2
   1.479 -    PDGID2HERWIGID[-2000006] = 424 ## SST2BR
   1.480 -    PDGID2HERWIGID[ 1000011] = 425 ## SSEL-
   1.481 -    PDGID2HERWIGID[-1000011] = 431 ## SSEL+
   1.482 -    PDGID2HERWIGID[ 1000012] = 426 ## SSNUEL
   1.483 -    PDGID2HERWIGID[-1000012] = 432 ## SSNUELBR
   1.484 -    PDGID2HERWIGID[ 1000013] = 427 ## SSMUL-
   1.485 -    PDGID2HERWIGID[-1000013] = 433 ## SSMUL+
   1.486 -    PDGID2HERWIGID[ 1000014] = 428 ## SSNUMUL
   1.487 -    PDGID2HERWIGID[-1000014] = 434 ## SSNUMLBR
   1.488 -    PDGID2HERWIGID[ 1000015] = 429 ## SSTAU1-
   1.489 -    PDGID2HERWIGID[-1000015] = 435 ## SSTAU1+
   1.490 -    PDGID2HERWIGID[ 1000016] = 430 ## SSNUTL
   1.491 -    PDGID2HERWIGID[-1000016] = 436 ## SSNUTLBR
   1.492 -    PDGID2HERWIGID[ 2000011] = 437 ## SSEL-
   1.493 -    PDGID2HERWIGID[-2000011] = 443 ## SSEL+
   1.494 -    PDGID2HERWIGID[ 2000012] = 438 ## SSNUEL
   1.495 -    PDGID2HERWIGID[-2000012] = 444 ## SSNUELBR
   1.496 -    PDGID2HERWIGID[ 2000013] = 439 ## SSMUL-
   1.497 -    PDGID2HERWIGID[-2000013] = 445 ## SSMUL+
   1.498 -    PDGID2HERWIGID[ 2000014] = 440 ## SSNUMUL
   1.499 -    PDGID2HERWIGID[-2000014] = 446 ## SSNUMLBR
   1.500 -    PDGID2HERWIGID[ 2000015] = 441 ## SSTAU1-
   1.501 -    PDGID2HERWIGID[-2000015] = 447 ## SSTAU1+
   1.502 -    PDGID2HERWIGID[ 2000016] = 442 ## SSNUTL
   1.503 -    PDGID2HERWIGID[-2000016] = 448 ## SSNUTLBR
   1.504 -    PDGID2HERWIGID[ 1000021] = 449 ## GLUINO
   1.505 -    PDGID2HERWIGID[ 1000022] = 450 ## NTLINO1
   1.506 -    PDGID2HERWIGID[ 1000023] = 451 ## NTLINO2
   1.507 -    PDGID2HERWIGID[ 1000025] = 452 ## NTLINO3
   1.508 -    PDGID2HERWIGID[ 1000035] = 453 ## NTLINO4
   1.509 -    PDGID2HERWIGID[ 1000024] = 454 ## CHGINO1+
   1.510 -    PDGID2HERWIGID[-1000024] = 456 ## CHGINO1-
   1.511 -    PDGID2HERWIGID[ 1000037] = 455 ## CHGINO2+
   1.512 -    PDGID2HERWIGID[-1000037] = 457 ## CHGINO2-
   1.513 -    PDGID2HERWIGID[ 1000039] = 458 ## GRAVTINO
   1.514  
   1.515      masses = blocks["MASS"].entries
   1.516  
   1.517 @@ -658,7 +680,7 @@
   1.518                  lifetime = 1.0/(width * 1.51926778e24) ## lifetime in seconds == hbar/width in GeV
   1.519          except:
   1.520              pass
   1.521 -        massout += "%d %e %e\n" % (PDGID2HERWIGID.get(pid, pid), masses[pid], lifetime)
   1.522 +        massout += "%d %e %e\n" % (pdgid2herwigid(pid), masses[pid], lifetime)
   1.523      out += "%d\n" % massout.count("\n")
   1.524      out += massout
   1.525  
   1.526 @@ -675,7 +697,7 @@
   1.527      for i, pid in enumerate(decays.keys()):
   1.528          # if not decays.has_key(pid):
   1.529          #     continue
   1.530 -        hwid = PDGID2HERWIGID.get(pid, pid)
   1.531 +        hwid = pdgid2herwigid(pid)
   1.532          decayout = ""
   1.533          #decayout += "@@@@ %d %d %d\n" % (i, pid, hwid)
   1.534          for i_d, d in enumerate(decays[pid].decays):

mercurial