Package: xslha
xSLHAxSLHAis apythonparser for files written in the SLHA format. It is optimised for fast reading of a large sample of files.InstallationThe package can be installed viapip install xslhaand is loaded in python byimport xslhaReading a single spectrum fileReading a spectrum filefileand stroing the information in a class objectspcis done via the commandspc=xslha.read(file)One has afterwards access to the different information by using theValuecommand, e.gprint("tan(beta): ",spc.Value('MINPAR',[3]))
print("T_u(3,3): ",spc.Value('TU',[3,3]))
print("m_h [GeV]: ",spc.Value('MASS',[25]))
print("Gamma(h) [GeV]: ",spc.Value('WIDTH',25))
print("BR(h->W^+W^-): ",spc.Value('BR',[25,[-13,13]]))
print("Sigma(pp->N1 N1,Q=8TeV): ",spc.Value('XSECTION',[8000,(2212,2212),(1000021,1000021)]))produces the following outputtan(beta):  16.870458
T_u(3,3):  954.867627
m_h [GeV]:  117.758677
Gamma(h) [GeV]:  0.00324670136
BR(h->W^+W^-):  0.000265688227
Sigma(pp->N1 N1,Q=8TeV): [[(0, 2, 0, 0, 0, 0), 0.00496483158]]Thus, the conventions are:for information given in the different SLHA blocks is returned by using using the name of the block as input as well as the numbers in the block as listthe widths of particles are returned via the keywordWIDHTand the pdg of the particlefor branching ratios, the keywordBRis used together with a nested list which states the pdg of the decay particle as well as of the final statesfor cross-sections the keywordXSECTIONis used together with a nested list which states the center-of-mass energy and the pdgs of the initial/final states. The result is a list containing all calculated cross-sections for the given options for the renormalisation scheme, the QED & QCD order, etc. (see the SLHA recommendations for details).Another possibility to access the information in the spectrum file is to look at the different dictionariesspc.blocks
spc.widths
spc.br
spc.xsctionswhich contain all informationReading all spectrum files from a directoryIn order to read several spectrum files located in a directorydir, one can make use of the commandlist_spc=xslha.read_dir(dir)This generates a listlist_spcwhere each entry corresponds to one spectrum. Thus, one can for instance use[[x.Value('MINPAR',[1]),x.Value('MASS',[25])] for x in list_spc]to extract the input for a 2D-scatter plot.Fast read-in of many filesReading many spectrum files can be time consuming. However, many of the information which is given in a SLHA file is often not needed for a current study. Therefore, one can speed up the reading by extracting first all relevant information. This generates smaller files which are faster to read in. This can be done via the optional argumententriesforread_dir:list_spc_fast=xslha.read_dir("/home/$USER/Documents/spc1000",entries=["# m0","# m12","# hh_1"])`entriesdefines a list of strings which can be used to extract the necessary lines from the SLHA file by usinggrep. The speed improvement can be easily an order of magnitude if only some entries from a SLHA file are actually needed.SpeedThe impact of this optimisation for reading 1000 files is as follows:%%time
list_spc=xslha.read_dir("/home/$USER/Documents/spc1000")

CPU times: user 5.05 s, sys: 105 ms, total: 5.15 s
Wall time: 5.51 scompared to%%time
list_spc_fast=xslha.read_dir("/home/$USER/Documents/spc1000",entries=["# m0","# m12","# hh_1"])

CPU times: user 147 ms, sys: 132 ms, total: 280 ms
Wall time: 917 msOne can also compares this with other available python parser:pylha:%%time
all_spc=[]
for filename in os.listdir("/home/$USER/Documents/spc1000/"): 
  with open("~/Documents/spc1000/"+filename) as f:
    input=f.read()
    all_spc.append(pylha.load(input))

CPU times: user 21.5 s, sys: 174 ms, total: 21.7 s
Wall time: 21.7 spyslha{%%time
all_spc=[]
for filename in os.listdir("/home/$USER/Documents/spc1000/"): 
    all_spc.append(pyslha.read(("/home/$USER/Documents/spc1000/"+filename)))

CPU times: user 13.3 s, sys: 152 ms, total: 13.5 s
Wall time: 13.5 sReading spectra stored in one fileAnother common approach for saving spectrum files is to produce one huge file in which the different spectra are separated by a keyword.xSLHAcan read such files by setting the optional argumentseparatorforread:list_spc=xslha.read(file,separator=keyword)In order to speed up the reading of many spectra also in this case, it is possible to define the entries as well which are need:list_spc=xslha.read(file,separator=keyword,entries=list)In this casexSLHAwill produce first a smaller spectrum file usingcatandgrep. For instance, in order to read efficiently files produced withSSP, one can use:list_spc=xslha.read("SpectrumFiles.spc",separator="ENDOFPARAMETERFILE",entries=["# m0", "# m12", "# hh_1"])Special blocksThere are some programs which use blocks that are not supported by the official SLHA conventions:HiggsBoundsexpects the effective coupling ratios in blocksHIGGSBOUNDSINPUTHIGGSCOUPLINGSBOSONSandHIGGSBOUNDSINPUTHIGGSCOUPLINGSFERMIONSwhich are differently order compared to other blocks (first the numerical entries are stated before the PDGs of the involved particles follow)SPhenoversion generated bySARAHcan calculate one-loop corrections to the decays. The results are given in the blocksDECAY1Lwhich appear in parallel toDECAYcontaining the standard calculation.xSLHAwill distinguish these cases when reading the file and offer the two following options forValuesin addtion:spc.Values('WIDTH1L',1000022)
spc.Values('BR1L',[1000023,[25,1000022]])Writing filesFiles in the SLHA format can be written viaxslha.write(blocks,file)where it might be the best to use ordered dictionaries to define the blocks and the values in the blocks. For instanceimport collections
out_blocks=collections.OrderedDict([
              ('MODSEL',collections.OrderedDict([('1', 1), ('2', 2),('6',0)])),
              ('MINPAR',collections.OrderedDict([('1', 1000.),('2', 2000),('3',10),('4',1),('5',0)]))
])
xslha.write(out_blocks,"/home/$USER/Documents/LH.in")