Make and use HWID <-> PDGID translation functions, which are publicly available in the pyslha API

Sun, 27 Feb 2011 00:35:57 +0100

author
Andy Buckley <andy@insectnation.org>
date
Sun, 27 Feb 2011 00:35:57 +0100
changeset 124
7bd52be093b2
parent 123
c85e29bc13c4
child 125
a16fb4116ac5

Make and use HWID <-> PDGID translation functions, which are publicly available in the pyslha API

ChangeLog file | annotate | diff | comparison | revisions
pyslha.py file | annotate | diff | comparison | revisions
     1.1 --- a/ChangeLog	Sun Feb 27 00:14:05 2011 +0100
     1.2 +++ b/ChangeLog	Sun Feb 27 00:35:57 2011 +0100
     1.3 @@ -1,5 +1,9 @@
     1.4  2011-02-27  Andy Buckley  <andy@insectnation.org>
     1.5  
     1.6 +	* Improving the newly-fixed HERWIG <-> PDG particle ID translation
     1.7 +	with a pair of functions, pdgid2herwigis and herwigid2pdgid, which
     1.8 +	are publicly available in the pyslha API.
     1.9 +
    1.10  	* Enabling simultaneous rendering of multiple input files.
    1.11  
    1.12  	* Adding repr() implementations for the pyslha objects.
     2.1 --- a/pyslha.py	Sun Feb 27 00:14:05 2011 +0100
     2.2 +++ b/pyslha.py	Sun Feb 27 00:35:57 2011 +0100
     2.3 @@ -262,6 +262,152 @@
     2.4      return rtn
     2.5  
     2.6  
     2.7 +def writeSLHAFile(spcfilename, blocks, decays, **kwargs):
     2.8 +    """
     2.9 +    Write an SLHA file from the supplied blocks and decays dicts.
    2.10 +
    2.11 +    Other keyword parameters are passed to writeSLHA.
    2.12 +    """
    2.13 +    f = open(spcfilename, "w")
    2.14 +    f.write(writeSLHA(blocks, decays, kwargs))
    2.15 +    f.close()
    2.16 +
    2.17 +
    2.18 +# TODO: Split writeSLHA into writeSLHA{Blocks,Decays}
    2.19 +
    2.20 +
    2.21 +def writeSLHA(blocks, decays, ignorenobr=False):
    2.22 +    """
    2.23 +    Return an SLHA definition as a string, from the supplied blocks and decays dicts.
    2.24 +    """
    2.25 +    sep = "   "
    2.26 +    out = ""
    2.27 +    def dict_hier_strs(d, s=""):
    2.28 +        if type(d) is dict:
    2.29 +            for k, v in sorted(d.iteritems()):
    2.30 +                for s2 in dict_hier_strs(v, s + sep + _autostr(k)):
    2.31 +                    yield s2
    2.32 +        else:
    2.33 +            yield s + sep + _autostr(d)
    2.34 +    ## Blocks
    2.35 +    for bname, b in sorted(blocks.iteritems()):
    2.36 +        namestr = b.name
    2.37 +        if b.q is not None:
    2.38 +            namestr += " Q= %e" % b.q
    2.39 +        out += "BLOCK %s\n" % namestr
    2.40 +        for s in dict_hier_strs(b.entries):
    2.41 +            out += sep + s + "\n"
    2.42 +        out += "\n"
    2.43 +    ## Decays
    2.44 +    for pid, particle in sorted(decays.iteritems()):
    2.45 +        out += "DECAY %d %e\n" % (particle.pid, particle.totalwidth or -1)
    2.46 +        for d in sorted(particle.decays):
    2.47 +            if d.br > 0.0 or not ignorenobr:
    2.48 +                products_str = "   ".join(map(str, d.ids))
    2.49 +                out += sep + "%e" % d.br + sep + "%d" % len(d.ids) + sep + products_str + "\n"
    2.50 +        out += "\n"
    2.51 +    return out
    2.52 +
    2.53 +
    2.54 +
    2.55 +###############################################################################
    2.56 +## ISAWIG handling
    2.57 +
    2.58 +## Static array of HERWIG IDHW codes mapped to PDG MC ID codes, based on
    2.59 +## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
    2.60 +## + the IDPDG array and section 4.13 of the HERWIG manual.
    2.61 +_HERWIGID2PDGID = {}
    2.62 +_HERWIGID2PDGID[7]   = -1
    2.63 +_HERWIGID2PDGID[8]   = -2
    2.64 +_HERWIGID2PDGID[9]   = -3
    2.65 +_HERWIGID2PDGID[10]  = -4
    2.66 +_HERWIGID2PDGID[11]  = -5
    2.67 +_HERWIGID2PDGID[12]  = -6
    2.68 +_HERWIGID2PDGID[13]  =  21
    2.69 +_HERWIGID2PDGID[59]  =  22
    2.70 +_HERWIGID2PDGID[121] =  11
    2.71 +_HERWIGID2PDGID[122] =  12
    2.72 +_HERWIGID2PDGID[123] =  13
    2.73 +_HERWIGID2PDGID[124] =  14
    2.74 +_HERWIGID2PDGID[125] =  15
    2.75 +_HERWIGID2PDGID[126] =  16
    2.76 +_HERWIGID2PDGID[127] = -11
    2.77 +_HERWIGID2PDGID[128] = -12
    2.78 +_HERWIGID2PDGID[129] = -13
    2.79 +_HERWIGID2PDGID[130] = -14
    2.80 +_HERWIGID2PDGID[131] = -15
    2.81 +_HERWIGID2PDGID[132] = -16
    2.82 +_HERWIGID2PDGID[203] =  25 ## HIGGSL0 (== PDG standard in this direction)
    2.83 +_HERWIGID2PDGID[204] =  35 ## HIGGSH0
    2.84 +_HERWIGID2PDGID[205] =  36 ## HIGGSA0
    2.85 +_HERWIGID2PDGID[206] =  37 ## HIGGS+
    2.86 +_HERWIGID2PDGID[207] = -37 ## HIGGS-
    2.87 +_HERWIGID2PDGID[401] =  1000001 ## SSDLBR
    2.88 +_HERWIGID2PDGID[407] = -1000001 ## SSDLBR
    2.89 +_HERWIGID2PDGID[402] =  1000002 ## SSULBR
    2.90 +_HERWIGID2PDGID[408] = -1000002 ## SSUL
    2.91 +_HERWIGID2PDGID[403] =  1000003 ## SSSLBR
    2.92 +_HERWIGID2PDGID[409] = -1000003 ## SSSL
    2.93 +_HERWIGID2PDGID[404] =  1000004 ## SSCLBR
    2.94 +_HERWIGID2PDGID[410] = -1000004 ## SSCL
    2.95 +_HERWIGID2PDGID[405] =  1000005 ## SSB1BR
    2.96 +_HERWIGID2PDGID[411] = -1000005 ## SSB1
    2.97 +_HERWIGID2PDGID[406] =  1000006 ## SST1BR
    2.98 +_HERWIGID2PDGID[412] = -1000006 ## SST1
    2.99 +_HERWIGID2PDGID[413] =  2000001 ## SSDR
   2.100 +_HERWIGID2PDGID[419] = -2000001 ## SSDRBR
   2.101 +_HERWIGID2PDGID[414] =  2000002 ## SSUR
   2.102 +_HERWIGID2PDGID[420] = -2000002 ## SSURBR
   2.103 +_HERWIGID2PDGID[415] =  2000003 ## SSSR
   2.104 +_HERWIGID2PDGID[421] = -2000003 ## SSSRBR
   2.105 +_HERWIGID2PDGID[416] =  2000004 ## SSCR
   2.106 +_HERWIGID2PDGID[422] = -2000004 ## SSCRBR
   2.107 +_HERWIGID2PDGID[417] =  2000005 ## SSB2
   2.108 +_HERWIGID2PDGID[423] = -2000005 ## SSB2BR
   2.109 +_HERWIGID2PDGID[418] =  2000006 ## SST2
   2.110 +_HERWIGID2PDGID[424] = -2000006 ## SST2BR
   2.111 +_HERWIGID2PDGID[425] =  1000011 ## SSEL-
   2.112 +_HERWIGID2PDGID[431] = -1000011 ## SSEL+
   2.113 +_HERWIGID2PDGID[426] =  1000012 ## SSNUEL
   2.114 +_HERWIGID2PDGID[432] = -1000012 ## SSNUELBR
   2.115 +_HERWIGID2PDGID[427] =  1000013 ## SSMUL-
   2.116 +_HERWIGID2PDGID[433] = -1000013 ## SSMUL+
   2.117 +_HERWIGID2PDGID[428] =  1000014 ## SSNUMUL
   2.118 +_HERWIGID2PDGID[434] = -1000014 ## SSNUMLBR
   2.119 +_HERWIGID2PDGID[429] =  1000015 ## SSTAU1-
   2.120 +_HERWIGID2PDGID[435] = -1000015 ## SSTAU1+
   2.121 +_HERWIGID2PDGID[430] =  1000016 ## SSNUTL
   2.122 +_HERWIGID2PDGID[436] = -1000016 ## SSNUTLBR
   2.123 +_HERWIGID2PDGID[437] =  2000011 ## SSEL-
   2.124 +_HERWIGID2PDGID[443] = -2000011 ## SSEL+
   2.125 +_HERWIGID2PDGID[438] =  2000012 ## SSNUEL
   2.126 +_HERWIGID2PDGID[444] = -2000012 ## SSNUELBR
   2.127 +_HERWIGID2PDGID[439] =  2000013 ## SSMUL-
   2.128 +_HERWIGID2PDGID[445] = -2000013 ## SSMUL+
   2.129 +_HERWIGID2PDGID[440] =  2000014 ## SSNUMUL
   2.130 +_HERWIGID2PDGID[446] = -2000014 ## SSNUMLBR
   2.131 +_HERWIGID2PDGID[441] =  2000015 ## SSTAU1-
   2.132 +_HERWIGID2PDGID[447] = -2000015 ## SSTAU1+
   2.133 +_HERWIGID2PDGID[442] =  2000016 ## SSNUTL
   2.134 +_HERWIGID2PDGID[448] = -2000016 ## SSNUTLBR
   2.135 +_HERWIGID2PDGID[449] =  1000021 ## GLUINO
   2.136 +_HERWIGID2PDGID[450] =  1000022 ## NTLINO1
   2.137 +_HERWIGID2PDGID[451] =  1000023 ## NTLINO2
   2.138 +_HERWIGID2PDGID[452] =  1000025 ## NTLINO3
   2.139 +_HERWIGID2PDGID[453] =  1000035 ## NTLINO4
   2.140 +_HERWIGID2PDGID[454] =  1000024 ## CHGINO1+
   2.141 +_HERWIGID2PDGID[456] = -1000024 ## CHGINO1-
   2.142 +_HERWIGID2PDGID[455] =  1000037 ## CHGINO2+
   2.143 +_HERWIGID2PDGID[457] = -1000037 ## CHGINO2-
   2.144 +_HERWIGID2PDGID[458] =  1000039 ## GRAVTINO
   2.145 +
   2.146 +def herwigid2pdgid(hwid):
   2.147 +    """
   2.148 +    Convert a particle ID code in the HERWIG internal IDHW format (as used by
   2.149 +    ISAWIG) into its equivalent in the standard PDG ID code definition.
   2.150 +    """
   2.151 +    return _HERWIGID2PDGID.get(hwid, hwid)
   2.152 +
   2.153  
   2.154  def readISAWIG(isastr, ignorenobr=False):
   2.155      """
   2.156 @@ -277,93 +423,6 @@
   2.157      branching ratio of zero.
   2.158      """
   2.159  
   2.160 -    ## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   2.161 -    ## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   2.162 -    ## + the IDPDG array and section 4.13 of the HERWIG manual.
   2.163 -    HERWIGID2PDGID = {}
   2.164 -    HERWIGID2PDGID[7]   = -1
   2.165 -    HERWIGID2PDGID[8]   = -2
   2.166 -    HERWIGID2PDGID[9]   = -3
   2.167 -    HERWIGID2PDGID[10]  = -4
   2.168 -    HERWIGID2PDGID[11]  = -5
   2.169 -    HERWIGID2PDGID[12]  = -6
   2.170 -    HERWIGID2PDGID[13]  =  21
   2.171 -    HERWIGID2PDGID[59]  =  22
   2.172 -    HERWIGID2PDGID[121] =  11
   2.173 -    HERWIGID2PDGID[122] =  12
   2.174 -    HERWIGID2PDGID[123] =  13
   2.175 -    HERWIGID2PDGID[124] =  14
   2.176 -    HERWIGID2PDGID[125] =  15
   2.177 -    HERWIGID2PDGID[126] =  16
   2.178 -    HERWIGID2PDGID[127] = -11
   2.179 -    HERWIGID2PDGID[128] = -12
   2.180 -    HERWIGID2PDGID[129] = -13
   2.181 -    HERWIGID2PDGID[130] = -14
   2.182 -    HERWIGID2PDGID[131] = -15
   2.183 -    HERWIGID2PDGID[132] = -16
   2.184 -    HERWIGID2PDGID[203] =  25 ## HIGGSL0 (== PDG standard in this direction)
   2.185 -    HERWIGID2PDGID[204] =  35 ## HIGGSH0
   2.186 -    HERWIGID2PDGID[205] =  36 ## HIGGSA0
   2.187 -    HERWIGID2PDGID[206] =  37 ## HIGGS+
   2.188 -    HERWIGID2PDGID[207] = -37 ## HIGGS-
   2.189 -    HERWIGID2PDGID[401] =  1000001 ## SSDLBR
   2.190 -    HERWIGID2PDGID[407] = -1000001 ## SSDLBR
   2.191 -    HERWIGID2PDGID[402] =  1000002 ## SSULBR
   2.192 -    HERWIGID2PDGID[408] = -1000002 ## SSUL
   2.193 -    HERWIGID2PDGID[403] =  1000003 ## SSSLBR
   2.194 -    HERWIGID2PDGID[409] = -1000003 ## SSSL
   2.195 -    HERWIGID2PDGID[404] =  1000004 ## SSCLBR
   2.196 -    HERWIGID2PDGID[410] = -1000004 ## SSCL
   2.197 -    HERWIGID2PDGID[405] =  1000005 ## SSB1BR
   2.198 -    HERWIGID2PDGID[411] = -1000005 ## SSB1
   2.199 -    HERWIGID2PDGID[406] =  1000006 ## SST1BR
   2.200 -    HERWIGID2PDGID[412] = -1000006 ## SST1
   2.201 -    HERWIGID2PDGID[413] =  2000001 ## SSDR
   2.202 -    HERWIGID2PDGID[419] = -2000001 ## SSDRBR
   2.203 -    HERWIGID2PDGID[414] =  2000002 ## SSUR
   2.204 -    HERWIGID2PDGID[420] = -2000002 ## SSURBR
   2.205 -    HERWIGID2PDGID[415] =  2000003 ## SSSR
   2.206 -    HERWIGID2PDGID[421] = -2000003 ## SSSRBR
   2.207 -    HERWIGID2PDGID[416] =  2000004 ## SSCR
   2.208 -    HERWIGID2PDGID[422] = -2000004 ## SSCRBR
   2.209 -    HERWIGID2PDGID[417] =  2000005 ## SSB2
   2.210 -    HERWIGID2PDGID[423] = -2000005 ## SSB2BR
   2.211 -    HERWIGID2PDGID[418] =  2000006 ## SST2
   2.212 -    HERWIGID2PDGID[424] = -2000006 ## SST2BR
   2.213 -    HERWIGID2PDGID[425] =  1000011 ## SSEL-
   2.214 -    HERWIGID2PDGID[431] = -1000011 ## SSEL+
   2.215 -    HERWIGID2PDGID[426] =  1000012 ## SSNUEL
   2.216 -    HERWIGID2PDGID[432] = -1000012 ## SSNUELBR
   2.217 -    HERWIGID2PDGID[427] =  1000013 ## SSMUL-
   2.218 -    HERWIGID2PDGID[433] = -1000013 ## SSMUL+
   2.219 -    HERWIGID2PDGID[428] =  1000014 ## SSNUMUL
   2.220 -    HERWIGID2PDGID[434] = -1000014 ## SSNUMLBR
   2.221 -    HERWIGID2PDGID[429] =  1000015 ## SSTAU1-
   2.222 -    HERWIGID2PDGID[435] = -1000015 ## SSTAU1+
   2.223 -    HERWIGID2PDGID[430] =  1000016 ## SSNUTL
   2.224 -    HERWIGID2PDGID[436] = -1000016 ## SSNUTLBR
   2.225 -    HERWIGID2PDGID[437] =  2000011 ## SSEL-
   2.226 -    HERWIGID2PDGID[443] = -2000011 ## SSEL+
   2.227 -    HERWIGID2PDGID[438] =  2000012 ## SSNUEL
   2.228 -    HERWIGID2PDGID[444] = -2000012 ## SSNUELBR
   2.229 -    HERWIGID2PDGID[439] =  2000013 ## SSMUL-
   2.230 -    HERWIGID2PDGID[445] = -2000013 ## SSMUL+
   2.231 -    HERWIGID2PDGID[440] =  2000014 ## SSNUMUL
   2.232 -    HERWIGID2PDGID[446] = -2000014 ## SSNUMLBR
   2.233 -    HERWIGID2PDGID[441] =  2000015 ## SSTAU1-
   2.234 -    HERWIGID2PDGID[447] = -2000015 ## SSTAU1+
   2.235 -    HERWIGID2PDGID[442] =  2000016 ## SSNUTL
   2.236 -    HERWIGID2PDGID[448] = -2000016 ## SSNUTLBR
   2.237 -    HERWIGID2PDGID[449] =  1000021 ## GLUINO
   2.238 -    HERWIGID2PDGID[450] =  1000022 ## NTLINO1
   2.239 -    HERWIGID2PDGID[451] =  1000023 ## NTLINO2
   2.240 -    HERWIGID2PDGID[452] =  1000025 ## NTLINO3
   2.241 -    HERWIGID2PDGID[453] =  1000035 ## NTLINO4
   2.242 -    HERWIGID2PDGID[454] =  1000024 ## CHGINO1+
   2.243 -    HERWIGID2PDGID[456] = -1000024 ## CHGINO1-
   2.244 -    HERWIGID2PDGID[455] =  1000037 ## CHGINO2+
   2.245 -    HERWIGID2PDGID[457] = -1000037 ## CHGINO2-
   2.246 -    HERWIGID2PDGID[458] =  1000039 ## GRAVTINO
   2.247  
   2.248      blocks = {}
   2.249      decays = {}
   2.250 @@ -391,7 +450,7 @@
   2.251      for i in xrange(numentries):
   2.252          hwid, mass, lifetime = getnextvalidlineitems()
   2.253          width = 1.0/(lifetime * 1.51926778e24) ## width in GeV == hbar/lifetime in seconds
   2.254 -        pdgid = HERWIGID2PDGID.get(hwid, hwid)
   2.255 +        pdgid = herwigid2pdgid(hwid)
   2.256          masses.add_entry((pdgid, mass))
   2.257          decays[pdgid] = Particle(pdgid, width, mass)
   2.258          #print pdgid, mass, width
   2.259 @@ -404,14 +463,14 @@
   2.260              #print n, numentries-1, d, numdecays-1
   2.261              decayitems = getnextvalidlineitems()
   2.262              hwid = decayitems[0]
   2.263 -            pdgid = HERWIGID2PDGID.get(hwid, hwid)
   2.264 +            pdgid = herwigid2pdgid(hwid)
   2.265              br = decayitems[1]
   2.266              nme = decayitems[2]
   2.267              daughter_hwids = decayitems[3:]
   2.268              daughter_pdgids = []
   2.269              for hw in daughter_hwids:
   2.270                  if hw != 0:
   2.271 -                    daughter_pdgids.append(HERWIGID2PDGID.get(hw, hw))
   2.272 +                    daughter_pdgids.append(herwigid2pdgid(hw))
   2.273              if not decays.has_key(pdgid):
   2.274                  #print "Decay for unlisted particle %d, %d" % (hwid, pdgid)
   2.275                  decays[pdgid] = Particle(pdgid)
   2.276 @@ -478,51 +537,102 @@
   2.277      return blocks, decays
   2.278  
   2.279  
   2.280 -def writeSLHAFile(spcfilename, blocks, decays, **kwargs):
   2.281 +## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   2.282 +## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   2.283 +## + the IDPDG array and section 4.13 of the HERWIG manual.
   2.284 +_PDGID2HERWIGID = {}
   2.285 +_PDGID2HERWIGID[      -1] = 7
   2.286 +_PDGID2HERWIGID[      -2] = 8
   2.287 +_PDGID2HERWIGID[      -3] = 9
   2.288 +_PDGID2HERWIGID[      -4] = 10
   2.289 +_PDGID2HERWIGID[      -5] = 11
   2.290 +_PDGID2HERWIGID[      -6] = 12
   2.291 +_PDGID2HERWIGID[      21] = 13
   2.292 +_PDGID2HERWIGID[      22] = 59
   2.293 +_PDGID2HERWIGID[      11] = 121
   2.294 +_PDGID2HERWIGID[      12] = 122
   2.295 +_PDGID2HERWIGID[      13] = 123
   2.296 +_PDGID2HERWIGID[      14] = 124
   2.297 +_PDGID2HERWIGID[      15] = 125
   2.298 +_PDGID2HERWIGID[      16] = 126
   2.299 +_PDGID2HERWIGID[     -11] = 127
   2.300 +_PDGID2HERWIGID[     -12] = 128
   2.301 +_PDGID2HERWIGID[     -13] = 129
   2.302 +_PDGID2HERWIGID[     -14] = 130
   2.303 +_PDGID2HERWIGID[     -15] = 131
   2.304 +_PDGID2HERWIGID[     -16] = 132
   2.305 +_PDGID2HERWIGID[      25] = 203 ## HIGGSL0 (added for PDG standard -> HERWIG IDHW)
   2.306 +_PDGID2HERWIGID[      26] = 203 ## HIGGSL0
   2.307 +_PDGID2HERWIGID[      35] = 204 ## HIGGSH0
   2.308 +_PDGID2HERWIGID[      36] = 205 ## HIGGSA0
   2.309 +_PDGID2HERWIGID[      37] = 206 ## HIGGS+
   2.310 +_PDGID2HERWIGID[     -37] = 207 ## HIGGS-
   2.311 +_PDGID2HERWIGID[ 1000001] = 401 ## SSDLBR
   2.312 +_PDGID2HERWIGID[-1000001] = 407 ## SSDLBR
   2.313 +_PDGID2HERWIGID[ 1000002] = 402 ## SSULBR
   2.314 +_PDGID2HERWIGID[-1000002] = 408 ## SSUL
   2.315 +_PDGID2HERWIGID[ 1000003] = 403 ## SSSLBR
   2.316 +_PDGID2HERWIGID[-1000003] = 409 ## SSSL
   2.317 +_PDGID2HERWIGID[ 1000004] = 404 ## SSCLBR
   2.318 +_PDGID2HERWIGID[-1000004] = 410 ## SSCL
   2.319 +_PDGID2HERWIGID[ 1000005] = 405 ## SSB1BR
   2.320 +_PDGID2HERWIGID[-1000005] = 411 ## SSB1
   2.321 +_PDGID2HERWIGID[ 1000006] = 406 ## SST1BR
   2.322 +_PDGID2HERWIGID[-1000006] = 412 ## SST1
   2.323 +_PDGID2HERWIGID[ 2000001] = 413 ## SSDR
   2.324 +_PDGID2HERWIGID[-2000001] = 419 ## SSDRBR
   2.325 +_PDGID2HERWIGID[ 2000002] = 414 ## SSUR
   2.326 +_PDGID2HERWIGID[-2000002] = 420 ## SSURBR
   2.327 +_PDGID2HERWIGID[ 2000003] = 415 ## SSSR
   2.328 +_PDGID2HERWIGID[-2000003] = 421 ## SSSRBR
   2.329 +_PDGID2HERWIGID[ 2000004] = 416 ## SSCR
   2.330 +_PDGID2HERWIGID[-2000004] = 422 ## SSCRBR
   2.331 +_PDGID2HERWIGID[ 2000005] = 417 ## SSB2
   2.332 +_PDGID2HERWIGID[-2000005] = 423 ## SSB2BR
   2.333 +_PDGID2HERWIGID[ 2000006] = 418 ## SST2
   2.334 +_PDGID2HERWIGID[-2000006] = 424 ## SST2BR
   2.335 +_PDGID2HERWIGID[ 1000011] = 425 ## SSEL-
   2.336 +_PDGID2HERWIGID[-1000011] = 431 ## SSEL+
   2.337 +_PDGID2HERWIGID[ 1000012] = 426 ## SSNUEL
   2.338 +_PDGID2HERWIGID[-1000012] = 432 ## SSNUELBR
   2.339 +_PDGID2HERWIGID[ 1000013] = 427 ## SSMUL-
   2.340 +_PDGID2HERWIGID[-1000013] = 433 ## SSMUL+
   2.341 +_PDGID2HERWIGID[ 1000014] = 428 ## SSNUMUL
   2.342 +_PDGID2HERWIGID[-1000014] = 434 ## SSNUMLBR
   2.343 +_PDGID2HERWIGID[ 1000015] = 429 ## SSTAU1-
   2.344 +_PDGID2HERWIGID[-1000015] = 435 ## SSTAU1+
   2.345 +_PDGID2HERWIGID[ 1000016] = 430 ## SSNUTL
   2.346 +_PDGID2HERWIGID[-1000016] = 436 ## SSNUTLBR
   2.347 +_PDGID2HERWIGID[ 2000011] = 437 ## SSEL-
   2.348 +_PDGID2HERWIGID[-2000011] = 443 ## SSEL+
   2.349 +_PDGID2HERWIGID[ 2000012] = 438 ## SSNUEL
   2.350 +_PDGID2HERWIGID[-2000012] = 444 ## SSNUELBR
   2.351 +_PDGID2HERWIGID[ 2000013] = 439 ## SSMUL-
   2.352 +_PDGID2HERWIGID[-2000013] = 445 ## SSMUL+
   2.353 +_PDGID2HERWIGID[ 2000014] = 440 ## SSNUMUL
   2.354 +_PDGID2HERWIGID[-2000014] = 446 ## SSNUMLBR
   2.355 +_PDGID2HERWIGID[ 2000015] = 441 ## SSTAU1-
   2.356 +_PDGID2HERWIGID[-2000015] = 447 ## SSTAU1+
   2.357 +_PDGID2HERWIGID[ 2000016] = 442 ## SSNUTL
   2.358 +_PDGID2HERWIGID[-2000016] = 448 ## SSNUTLBR
   2.359 +_PDGID2HERWIGID[ 1000021] = 449 ## GLUINO
   2.360 +_PDGID2HERWIGID[ 1000022] = 450 ## NTLINO1
   2.361 +_PDGID2HERWIGID[ 1000023] = 451 ## NTLINO2
   2.362 +_PDGID2HERWIGID[ 1000025] = 452 ## NTLINO3
   2.363 +_PDGID2HERWIGID[ 1000035] = 453 ## NTLINO4
   2.364 +_PDGID2HERWIGID[ 1000024] = 454 ## CHGINO1+
   2.365 +_PDGID2HERWIGID[-1000024] = 456 ## CHGINO1-
   2.366 +_PDGID2HERWIGID[ 1000037] = 455 ## CHGINO2+
   2.367 +_PDGID2HERWIGID[-1000037] = 457 ## CHGINO2-
   2.368 +_PDGID2HERWIGID[ 1000039] = 458 ## GRAVTINO
   2.369 +
   2.370 +def pdgid2herwigid(pdgid):
   2.371      """
   2.372 -    Write an SLHA file from the supplied blocks and decays dicts.
   2.373 +    Convert a particle ID code in the standard PDG ID code definition into
   2.374 +    its equivalent in the HERWIG internal IDHW format (as used by ISAWIG).
   2.375 +    """
   2.376 +    return _PDGID2HERWIGID.get(pdgid, pdgid)
   2.377  
   2.378 -    Other keyword parameters are passed to writeSLHA.
   2.379 -    """
   2.380 -    f = open(spcfilename, "w")
   2.381 -    f.write(writeSLHA(blocks, decays, kwargs))
   2.382 -    f.close()
   2.383 -
   2.384 -
   2.385 -# TODO: Split writeSLHA into writeSLHA{Blocks,Decays}
   2.386 -
   2.387 -
   2.388 -def writeSLHA(blocks, decays, ignorenobr=False):
   2.389 -    """
   2.390 -    Return an SLHA definition as a string, from the supplied blocks and decays dicts.
   2.391 -    """
   2.392 -    sep = "   "
   2.393 -    out = ""
   2.394 -    def dict_hier_strs(d, s=""):
   2.395 -        if type(d) is dict:
   2.396 -            for k, v in sorted(d.iteritems()):
   2.397 -                for s2 in dict_hier_strs(v, s + sep + _autostr(k)):
   2.398 -                    yield s2
   2.399 -        else:
   2.400 -            yield s + sep + _autostr(d)
   2.401 -    ## Blocks
   2.402 -    for bname, b in sorted(blocks.iteritems()):
   2.403 -        namestr = b.name
   2.404 -        if b.q is not None:
   2.405 -            namestr += " Q= %e" % b.q
   2.406 -        out += "BLOCK %s\n" % namestr
   2.407 -        for s in dict_hier_strs(b.entries):
   2.408 -            out += sep + s + "\n"
   2.409 -        out += "\n"
   2.410 -    ## Decays
   2.411 -    for pid, particle in sorted(decays.iteritems()):
   2.412 -        out += "DECAY %d %e\n" % (particle.pid, particle.totalwidth or -1)
   2.413 -        for d in sorted(particle.decays):
   2.414 -            if d.br > 0.0 or not ignorenobr:
   2.415 -                products_str = "   ".join(map(str, d.ids))
   2.416 -                out += sep + "%e" % d.br + sep + "%d" % len(d.ids) + sep + products_str + "\n"
   2.417 -        out += "\n"
   2.418 -    return out
   2.419  
   2.420  
   2.421  
   2.422 @@ -549,94 +659,6 @@
   2.423      If the ignorenobr parameter is True, do not write decay entries with a
   2.424      branching ratio of zero.
   2.425      """
   2.426 -    ## PDG MC ID codes mapped to HERWIG IDHW codes, based on
   2.427 -    ## http://www.hep.phy.cam.ac.uk/~richardn/HERWIG/ISAWIG/susycodes.html
   2.428 -    ## + the IDPDG array and section 4.13 of the HERWIG manual.
   2.429 -    PDGID2HERWIGID = {}
   2.430 -    PDGID2HERWIGID[      -1] = 7
   2.431 -    PDGID2HERWIGID[      -2] = 8
   2.432 -    PDGID2HERWIGID[      -3] = 9
   2.433 -    PDGID2HERWIGID[      -4] = 10
   2.434 -    PDGID2HERWIGID[      -5] = 11
   2.435 -    PDGID2HERWIGID[      -6] = 12
   2.436 -    PDGID2HERWIGID[      21] = 13
   2.437 -    PDGID2HERWIGID[      22] = 59
   2.438 -    PDGID2HERWIGID[      11] = 121
   2.439 -    PDGID2HERWIGID[      12] = 122
   2.440 -    PDGID2HERWIGID[      13] = 123
   2.441 -    PDGID2HERWIGID[      14] = 124
   2.442 -    PDGID2HERWIGID[      15] = 125
   2.443 -    PDGID2HERWIGID[      16] = 126
   2.444 -    PDGID2HERWIGID[     -11] = 127
   2.445 -    PDGID2HERWIGID[     -12] = 128
   2.446 -    PDGID2HERWIGID[     -13] = 129
   2.447 -    PDGID2HERWIGID[     -14] = 130
   2.448 -    PDGID2HERWIGID[     -15] = 131
   2.449 -    PDGID2HERWIGID[     -16] = 132
   2.450 -    PDGID2HERWIGID[      25] = 203 ## HIGGSL0 (added for PDG standard -> HERWIG IDHW)
   2.451 -    PDGID2HERWIGID[      26] = 203 ## HIGGSL0
   2.452 -    PDGID2HERWIGID[      35] = 204 ## HIGGSH0
   2.453 -    PDGID2HERWIGID[      36] = 205 ## HIGGSA0
   2.454 -    PDGID2HERWIGID[      37] = 206 ## HIGGS+
   2.455 -    PDGID2HERWIGID[     -37] = 207 ## HIGGS-
   2.456 -    PDGID2HERWIGID[ 1000001] = 401 ## SSDLBR
   2.457 -    PDGID2HERWIGID[-1000001] = 407 ## SSDLBR
   2.458 -    PDGID2HERWIGID[ 1000002] = 402 ## SSULBR
   2.459 -    PDGID2HERWIGID[-1000002] = 408 ## SSUL
   2.460 -    PDGID2HERWIGID[ 1000003] = 403 ## SSSLBR
   2.461 -    PDGID2HERWIGID[-1000003] = 409 ## SSSL
   2.462 -    PDGID2HERWIGID[ 1000004] = 404 ## SSCLBR
   2.463 -    PDGID2HERWIGID[-1000004] = 410 ## SSCL
   2.464 -    PDGID2HERWIGID[ 1000005] = 405 ## SSB1BR
   2.465 -    PDGID2HERWIGID[-1000005] = 411 ## SSB1
   2.466 -    PDGID2HERWIGID[ 1000006] = 406 ## SST1BR
   2.467 -    PDGID2HERWIGID[-1000006] = 412 ## SST1
   2.468 -    PDGID2HERWIGID[ 2000001] = 413 ## SSDR
   2.469 -    PDGID2HERWIGID[-2000001] = 419 ## SSDRBR
   2.470 -    PDGID2HERWIGID[ 2000002] = 414 ## SSUR
   2.471 -    PDGID2HERWIGID[-2000002] = 420 ## SSURBR
   2.472 -    PDGID2HERWIGID[ 2000003] = 415 ## SSSR
   2.473 -    PDGID2HERWIGID[-2000003] = 421 ## SSSRBR
   2.474 -    PDGID2HERWIGID[ 2000004] = 416 ## SSCR
   2.475 -    PDGID2HERWIGID[-2000004] = 422 ## SSCRBR
   2.476 -    PDGID2HERWIGID[ 2000005] = 417 ## SSB2
   2.477 -    PDGID2HERWIGID[-2000005] = 423 ## SSB2BR
   2.478 -    PDGID2HERWIGID[ 2000006] = 418 ## SST2
   2.479 -    PDGID2HERWIGID[-2000006] = 424 ## SST2BR
   2.480 -    PDGID2HERWIGID[ 1000011] = 425 ## SSEL-
   2.481 -    PDGID2HERWIGID[-1000011] = 431 ## SSEL+
   2.482 -    PDGID2HERWIGID[ 1000012] = 426 ## SSNUEL
   2.483 -    PDGID2HERWIGID[-1000012] = 432 ## SSNUELBR
   2.484 -    PDGID2HERWIGID[ 1000013] = 427 ## SSMUL-
   2.485 -    PDGID2HERWIGID[-1000013] = 433 ## SSMUL+
   2.486 -    PDGID2HERWIGID[ 1000014] = 428 ## SSNUMUL
   2.487 -    PDGID2HERWIGID[-1000014] = 434 ## SSNUMLBR
   2.488 -    PDGID2HERWIGID[ 1000015] = 429 ## SSTAU1-
   2.489 -    PDGID2HERWIGID[-1000015] = 435 ## SSTAU1+
   2.490 -    PDGID2HERWIGID[ 1000016] = 430 ## SSNUTL
   2.491 -    PDGID2HERWIGID[-1000016] = 436 ## SSNUTLBR
   2.492 -    PDGID2HERWIGID[ 2000011] = 437 ## SSEL-
   2.493 -    PDGID2HERWIGID[-2000011] = 443 ## SSEL+
   2.494 -    PDGID2HERWIGID[ 2000012] = 438 ## SSNUEL
   2.495 -    PDGID2HERWIGID[-2000012] = 444 ## SSNUELBR
   2.496 -    PDGID2HERWIGID[ 2000013] = 439 ## SSMUL-
   2.497 -    PDGID2HERWIGID[-2000013] = 445 ## SSMUL+
   2.498 -    PDGID2HERWIGID[ 2000014] = 440 ## SSNUMUL
   2.499 -    PDGID2HERWIGID[-2000014] = 446 ## SSNUMLBR
   2.500 -    PDGID2HERWIGID[ 2000015] = 441 ## SSTAU1-
   2.501 -    PDGID2HERWIGID[-2000015] = 447 ## SSTAU1+
   2.502 -    PDGID2HERWIGID[ 2000016] = 442 ## SSNUTL
   2.503 -    PDGID2HERWIGID[-2000016] = 448 ## SSNUTLBR
   2.504 -    PDGID2HERWIGID[ 1000021] = 449 ## GLUINO
   2.505 -    PDGID2HERWIGID[ 1000022] = 450 ## NTLINO1
   2.506 -    PDGID2HERWIGID[ 1000023] = 451 ## NTLINO2
   2.507 -    PDGID2HERWIGID[ 1000025] = 452 ## NTLINO3
   2.508 -    PDGID2HERWIGID[ 1000035] = 453 ## NTLINO4
   2.509 -    PDGID2HERWIGID[ 1000024] = 454 ## CHGINO1+
   2.510 -    PDGID2HERWIGID[-1000024] = 456 ## CHGINO1-
   2.511 -    PDGID2HERWIGID[ 1000037] = 455 ## CHGINO2+
   2.512 -    PDGID2HERWIGID[-1000037] = 457 ## CHGINO2-
   2.513 -    PDGID2HERWIGID[ 1000039] = 458 ## GRAVTINO
   2.514  
   2.515      masses = blocks["MASS"].entries
   2.516  
   2.517 @@ -658,7 +680,7 @@
   2.518                  lifetime = 1.0/(width * 1.51926778e24) ## lifetime in seconds == hbar/width in GeV
   2.519          except:
   2.520              pass
   2.521 -        massout += "%d %e %e\n" % (PDGID2HERWIGID.get(pid, pid), masses[pid], lifetime)
   2.522 +        massout += "%d %e %e\n" % (pdgid2herwigid(pid), masses[pid], lifetime)
   2.523      out += "%d\n" % massout.count("\n")
   2.524      out += massout
   2.525  
   2.526 @@ -675,7 +697,7 @@
   2.527      for i, pid in enumerate(decays.keys()):
   2.528          # if not decays.has_key(pid):
   2.529          #     continue
   2.530 -        hwid = PDGID2HERWIGID.get(pid, pid)
   2.531 +        hwid = pdgid2herwigid(pid)
   2.532          decayout = ""
   2.533          #decayout += "@@@@ %d %d %d\n" % (i, pid, hwid)
   2.534          for i_d, d in enumerate(decays[pid].decays):

mercurial