How To: Run SModelS as a python library

In [1]:
# Set up the path to SModelS installation folder
import sys; sys.path.append("."); import smodels_paths
In [2]:
from imp import reload
from smodels.tools import runtime
from smodels import particlesLoader
from smodels.theory import slhaDecomposer,lheDecomposer
from smodels.tools.physicsUnits import fb, GeV, TeV
from smodels.theory.theoryPrediction import theoryPredictionsFor
from smodels.experiment.databaseObj import Database
from smodels.tools import coverage
from smodels.tools.smodelsLogging import setLogLevel
setLogLevel("info")

Main input:

In [3]:
#Define your model (list of rEven and rOdd particles)
runtime.modelFile = 'smodels.share.models.mssm' 
reload(particlesLoader) #Make sure all the model particles are up-to-date
# Path to input file (either a SLHA or LHE file)
slhafile = 'inputFiles/slha/lightEWinos.slha'

Decompose the input model:

In [4]:
# Set main options for decomposition
sigmacut = 0.01 * fb
mingap = 5. * GeV
# Decompose model (use slhaDecomposer for SLHA input or lheDecomposer for LHE input)
toplist = slhaDecomposer.decompose(slhafile, sigmacut, doCompress=True, doInvisible=True, minmassgap=mingap)

# Access basic information from decomposition, using the topology list and topology objects:
print( "\n Decomposition Results: " )
print( "\t  Total number of topologies: %i " %len(toplist) )
nel = sum([len(top.elementList) for top in toplist])
print( "\t  Total number of elements = %i " %nel )
 Decomposition Results: 
	  Total number of topologies: 51 
	  Total number of elements = 14985 

Load the Database of experimental results:

In [5]:
# Set the path to the database
database = Database("official")
# Load the experimental results to be used.
# In this case, all results are employed.
listOfExpRes = database.getExpResults()

# Print basic information about the results loaded.
# Count the number of loaded UL and EM experimental results:
nUL, nEM = 0, 0
for exp in listOfExpRes:
    expType = exp.getValuesFor('dataType')[0]
    if expType == 'upperLimit':
        nUL += 1
    elif  expType == 'efficiencyMap':
        nEM += 1
print("\n Loaded Database with %i UL results and %i EM results " %(nUL,nEM))
INFO in databaseObj.fetchFromScratch() in 308: need to fetch http://smodels.hephy.at/database/official122.pcl. size is 416.0MB.
loading >...................................................
INFO in databaseObj.fetchFromScratch() in 326: fetched http://smodels.hephy.at/database/official122.pcl in 56 secs.
INFO in databaseObj.loadBinaryFile() in 176: loading binary db file ./official122.pcl format version 201
done.
INFO in databaseObj.loadBinaryFile() in 183: Loaded database from ./official122.pcl in 1.0 secs.
 Loaded Database with 59 UL results and 21 EM results 

Match the decomposed simplified models with the experimental database of constraints:

In [6]:
# Compute the theory predictions for each experimental result and print them:
print("\n Theory Predictions and Constraints:")
rmax = 0.
bestResult = None
for expResult in listOfExpRes:
    predictions = theoryPredictionsFor(expResult, toplist)
    if not predictions: continue # Skip if there are no constraints from this result
    print('\n %s (%i TeV)' %(expResult.globalInfo.id,expResult.globalInfo.sqrts.asNumber(TeV)))
    for theoryPrediction in predictions:
        dataset = theoryPrediction.dataset
        datasetID = dataset.dataInfo.dataId            
        mass = theoryPrediction.mass
        txnames = [str(txname) for txname in theoryPrediction.txnames]
        PIDs =  theoryPrediction.PIDs         
        print( "------------------------" )
        print( "TxNames = ",txnames )  
        print( "Theory Prediction = ",theoryPrediction.xsection.value )  #Signal cross section
        # Get the corresponding upper limit:
        print( "UL for theory prediction = ",theoryPrediction.upperLimit )
        # Compute the r-value
        r = theoryPrediction.getRValue()
        print( "r = ",r )
        #Compute likelihhod and chi^2 for EM-type results:
        if dataset.dataInfo.dataType == 'efficiencyMap':
            theoryPrediction.computeStatistics()
            print( 'Chi2, likelihood=', theoryPrediction.chi2, theoryPrediction.likelihood )
        if r > rmax:
            rmax = r
            bestResult = expResult.globalInfo.id

# Print the most constraining experimental result
print( "\nThe largest r-value (theory/upper limit ratio) is ",rmax )
if rmax > 1.:
    print( "(The input model is likely excluded by %s)" %bestResult )
else:
    print( "(The input model is not excluded by the simplified model results)" )
 Theory Predictions and Constraints:

 ATLAS-SUSY-2015-06 (13 TeV)
------------------------
TxNames =  ['T1']
Theory Prediction =  5.19E-06 [pb]
UL for theory prediction =  1.79E+00 [fb]
r =  0.002901393530776837
Chi2, likelihood= 2.3776849368423356 0.007169156710956845

 ATLAS-SUSY-2017-03 (13 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  2.79E-04 [pb]
UL for theory prediction =  1.81E+02 [fb]
r =  0.0015451916855517046

 CMS-PAS-SUS-17-004 (13 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  2.79E-04 [pb]
UL for theory prediction =  1.18E+02 [fb]
r =  0.002362228895825259
------------------------
TxNames =  ['TChiWH']
Theory Prediction =  6.10E-04 [pb]
UL for theory prediction =  3.79E+02 [fb]
r =  0.001609898825011838

 CMS-SUS-16-033 (13 TeV)
------------------------
TxNames =  ['T2']
Theory Prediction =  2.54E-05 [pb]
UL for theory prediction =  3.60E+01 [fb]
r =  0.0007039737677262512

 CMS-SUS-16-034 (13 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  2.79E-04 [pb]
UL for theory prediction =  2.32E+02 [fb]
r =  0.0012033340641033744

 CMS-SUS-16-036 (13 TeV)
------------------------
TxNames =  ['T2']
Theory Prediction =  2.54E-05 [pb]
UL for theory prediction =  4.72E+01 [fb]
r =  0.0005373045514341562

 CMS-SUS-16-039 (13 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  2.79E-04 [pb]
UL for theory prediction =  2.04E+02 [fb]
r =  0.0013677427530865407
------------------------
TxNames =  ['TChiWH']
Theory Prediction =  6.10E-04 [pb]
UL for theory prediction =  1.01E+03 [fb]
r =  0.0006026014643944023

 CMS-SUS-16-043 (13 TeV)
------------------------
TxNames =  ['TChiWH']
Theory Prediction =  6.10E-04 [pb]
UL for theory prediction =  4.07E+02 [fb]
r =  0.0014991669480561279

 CMS-SUS-16-045 (13 TeV)
------------------------
TxNames =  ['TChiWH']
Theory Prediction =  6.10E-04 [pb]
UL for theory prediction =  1.36E+03 [fb]
r =  0.0004482020614998026

 ATLAS-CONF-2013-007 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  3.69E+01 [fb]
r =  0.01817836755233765

 ATLAS-CONF-2013-061 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  7.68E+01 [fb]
r =  0.00873129242824064
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  7.63E-03 [pb]
UL for theory prediction =  3.03E+01 [fb]
r =  0.2519685756334373

 ATLAS-SUSY-2013-02 (8 TeV)
------------------------
TxNames =  ['T1']
Theory Prediction =  1.53E+00 [pb]
UL for theory prediction =  2.33E+07 [fb]
r =  6.559431112202458e-05
------------------------
TxNames =  ['T1']
Theory Prediction =  2.03E-04 [pb]
UL for theory prediction =  6.82E+01 [fb]
r =  0.002969071686726256
------------------------
TxNames =  ['T2']
Theory Prediction =  3.82E-06 [pb]
UL for theory prediction =  4.16E+01 [fb]
r =  9.197296418036862e-05

 ATLAS-SUSY-2013-02 (8 TeV)
------------------------
TxNames =  ['T1', 'T2']
Theory Prediction =  6.62E-04 [pb]
UL for theory prediction =  1.33E+01 [fb]
r =  0.04978006084345905
Chi2, likelihood= 0.08132725271856245 2.9710110111789358e-05

 ATLAS-SUSY-2013-04 (8 TeV)
------------------------
TxNames =  ['T1bbbb', 'T1tttt', 'T5WWoff']
Theory Prediction =  8.37E-06 [pb]
UL for theory prediction =  2.72E-01 [fb]
r =  0.030767680880237083
Chi2, likelihood= 0.3443540093807065 0.14224359106869794

 ATLAS-SUSY-2013-09 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  2.90E+01 [fb]
r =  0.02313564987756535

 ATLAS-SUSY-2013-11 (8 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  1.64E-04 [pb]
UL for theory prediction =  1.39E+02 [fb]
r =  0.0011809582545823961
------------------------
TxNames =  ['TSlepSlep']
Theory Prediction =  5.20E-06 [pb]
UL for theory prediction =  2.72E+00 [fb]
r =  0.0019109797495987135

 ATLAS-SUSY-2013-11 (8 TeV)
------------------------
TxNames =  ['TChiWW', 'TSlepSlep']
Theory Prediction =  3.91E-07 [pb]
UL for theory prediction =  2.68E-01 [fb]
r =  0.0014598576263559757
Chi2, likelihood= 0.008725032138717559 0.12692248897821493

 ATLAS-SUSY-2013-12 (8 TeV)
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  1.64E-04 [pb]
UL for theory prediction =  1.23E+02 [fb]
r =  0.0013388999951741917
------------------------
TxNames =  ['TChiWZoff']
Theory Prediction =  1.40E+00 [pb]
UL for theory prediction =  1.83E+03 [fb]
r =  0.7657432899792156

 ATLAS-SUSY-2013-18 (8 TeV)
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  7.11E-03 [pb]
UL for theory prediction =  3.82E+01 [fb]
r =  0.1859260427641961
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  5.20E-04 [pb]
UL for theory prediction =  6.57E+01 [fb]
r =  0.00791445297036886

 ATLAS-SUSY-2013-18 (8 TeV)
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  1.03E-04 [pb]
UL for theory prediction =  3.32E-01 [fb]
r =  0.3116972806998665
Chi2, likelihood= 0.09446292139475698 0.08861660305104042

 CMS-PAS-SUS-13-016 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  9.85E+01 [fb]
r =  0.006802055377757174

 CMS-PAS-SUS-13-016 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  2.55E-06 [pb]
UL for theory prediction =  2.11E-01 [fb]
r =  0.012089682604272263
Chi2, likelihood= 0.027333181017898056 0.13795784056579297

 CMS-SUS-12-024 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  2.03E+02 [fb]
r =  0.0033039788382466027

 CMS-SUS-12-024 (8 TeV)
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  1.65E-04 [pb]
UL for theory prediction =  4.25E-01 [fb]
r =  0.38708893994109467
Chi2, likelihood= 0.9833666132793653 0.016206306028910874

 CMS-SUS-12-028 (8 TeV)
------------------------
TxNames =  ['T2']
Theory Prediction =  3.82E-06 [pb]
UL for theory prediction =  5.83E+01 [fb]
r =  6.560853619143274e-05
------------------------
TxNames =  ['T1']
Theory Prediction =  2.03E-04 [pb]
UL for theory prediction =  1.28E+02 [fb]
r =  0.0015825004905329382
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  7.63E-03 [pb]
UL for theory prediction =  2.68E+01 [fb]
r =  0.2844650937046408
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  5.11E+02 [fb]
r =  0.0013107368638801743

 CMS-SUS-13-004 (8 TeV)
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  7.11E-03 [pb]
UL for theory prediction =  2.16E+01 [fb]
r =  0.3285527157263929
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  5.20E-04 [pb]
UL for theory prediction =  2.90E+01 [fb]
r =  0.017904411190784716
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  1.40E+02 [fb]
r =  0.004803007554347874

 CMS-SUS-13-006 (8 TeV)
------------------------
TxNames =  ['TSlepSlep']
Theory Prediction =  5.20E-06 [pb]
UL for theory prediction =  2.82E+00 [fb]
r =  0.0018447844626653426
------------------------
TxNames =  ['TChiWH']
Theory Prediction =  3.59E-04 [pb]
UL for theory prediction =  2.68E+02 [fb]
r =  0.001339451744664113
------------------------
TxNames =  ['TChiWZ']
Theory Prediction =  1.64E-04 [pb]
UL for theory prediction =  1.96E+02 [fb]
r =  0.0008389798746432437
------------------------
TxNames =  ['TChiWZoff']
Theory Prediction =  1.40E+00 [pb]
UL for theory prediction =  1.17E+03 [fb]
r =  1.1955787770632587

 CMS-SUS-13-007 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  3.45E+01 [fb]
r =  0.019410417368143775

 CMS-SUS-13-007 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  2.89E-06 [pb]
UL for theory prediction =  1.56E-01 [fb]
r =  0.018587027434426178
Chi2, likelihood= 3.744332110918336 0.06339934745404696

 CMS-SUS-13-012 (8 TeV)
------------------------
TxNames =  ['T1']
Theory Prediction =  2.03E-04 [pb]
UL for theory prediction =  5.63E+01 [fb]
r =  0.0035971001930282867
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  9.91E+01 [fb]
r =  0.00676083789692253
------------------------
TxNames =  ['T2']
Theory Prediction =  3.82E-06 [pb]
UL for theory prediction =  7.57E+01 [fb]
r =  5.0492342410963783e-05

 CMS-SUS-13-012 (8 TeV)
------------------------
TxNames =  ['T1', 'T1bbbb', 'T1tttt', 'T2', 'T5WWoff']
Theory Prediction =  3.18E-05 [pb]
UL for theory prediction =  2.65E-01 [fb]
r =  0.11996458287620515
Chi2, likelihood= 0.1498465542697609 0.021283888388827565

 CMS-SUS-13-013 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  3.35E+01 [fb]
r =  0.020002345839295096

 CMS-SUS-13-013 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  4.71E-06 [pb]
UL for theory prediction =  2.58E-01 [fb]
r =  0.0182883542214002
Chi2, likelihood= 0.018456286893814067 0.10912239638341135

 CMS-SUS-13-019 (8 TeV)
------------------------
TxNames =  ['T2']
Theory Prediction =  3.82E-06 [pb]
UL for theory prediction =  2.84E+01 [fb]
r =  0.00013468278995197111
------------------------
TxNames =  ['T1']
Theory Prediction =  2.03E-04 [pb]
UL for theory prediction =  7.45E+01 [fb]
r =  0.002718495202475519
------------------------
TxNames =  ['T1bbbb']
Theory Prediction =  7.63E-03 [pb]
UL for theory prediction =  9.31E+00 [fb]
r =  0.8192068101182405
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  7.57E+01 [fb]
r =  0.008852430712219648

 CMS-SUS-14-010 (8 TeV)
------------------------
TxNames =  ['T1tttt']
Theory Prediction =  6.70E-04 [pb]
UL for theory prediction =  1.75E+01 [fb]
r =  0.038230354251720854

The largest r-value (theory/upper limit ratio) is  1.1955787770632587
(The input model is likely excluded by CMS-SUS-13-006)

Check for simplified models in the input model which were not tested by the Database:

In [7]:
#Find out missing topologies for sqrts=8*TeV:
uncovered = coverage.Uncovered(toplist,sqrts=8.*TeV)
#Print uncovered cross-sections:
print( "\nTotal missing topology cross section (fb): %10.3E\n" %(uncovered.getMissingXsec()) )
print( "Total cross section where we are outside the mass grid (fb): %10.3E\n" %(uncovered.getOutOfGridXsec()) )
print( "Total cross section in long cascade decays (fb): %10.3E\n" %(uncovered.getLongCascadeXsec()) )
print( "Total cross section in decays with asymmetric branches (fb): %10.3E\n" %(uncovered.getAsymmetricXsec()) )

#Print some of the missing topologies:
print( 'Missing topologies (up to 3):' )
for topo in uncovered.missingTopos.topos[:3]:
    print( 'Topology:',topo.topo )
    print( 'Contributing elements (up to 2):' )
    for el in topo.contributingElements[:2]:
        print( el,'cross-section (fb):', el.missingX )

#Print elements with long cascade decay:
print( '\nElements outside the grid (up to 2):' )
for topo in uncovered.outsideGrid.topos[:2]:
    print( 'Topology:',topo.topo )
    print( 'Contributing elements (up to 4):' )
    for el in topo.contributingElements[:4]:
        print( el,'cross-section (fb):', el.missingX )
        print( '\tmass:',el.getMasses() )
Total missing topology cross section (fb):  3.717E+03

Total cross section where we are outside the mass grid (fb):  9.989E+01

Total cross section in long cascade decays (fb):  8.992E+02

Total cross section in decays with asymmetric branches (fb):  2.790E+03

Missing topologies (up to 3):
Topology: [[],[]](MET,MET)
Contributing elements (up to 2):
[[],[]] cross-section (fb): 0.45069449699999997
[[],[]] cross-section (fb): 0.11641645217403078
Topology: [[],[[W]]](MET,MET)
Contributing elements (up to 2):
[[],[[W+]]] cross-section (fb): 0.11376799860548632
[[],[[W+]]] cross-section (fb): 0.05277778742404712
Topology: [[],[[Z]]](MET,MET)
Contributing elements (up to 2):
[[],[[Z]]] cross-section (fb): 0.8060860593513246
[[],[[Z]]] cross-section (fb): 0.07370694075178172

Elements outside the grid (up to 2):
Topology: [[[W]],[[Z]]](MET,MET)
Contributing elements (up to 4):
[[[W+]],[[Z]]] cross-section (fb): 0.3637955190752928
	mass: [[2.93E+02 [GeV], 6.81E+01 [GeV]], [2.66E+02 [GeV], 6.81E+01 [GeV]]]
[[[W+]],[[Z]]] cross-section (fb): 0.03326475437600832
	mass: [[2.93E+02 [GeV], 6.81E+01 [GeV]], [2.66E+02 [GeV], 1.35E+02 [GeV]]]
[[[W+]],[[Z]]] cross-section (fb): 0.16876734061357362
	mass: [[2.93E+02 [GeV], 1.35E+02 [GeV]], [2.66E+02 [GeV], 6.81E+01 [GeV]]]
[[[W+]],[[Z]]] cross-section (fb): 0.05769812445390672
	mass: [[2.93E+02 [GeV], 1.35E+02 [GeV]], [2.92E+02 [GeV], 6.81E+01 [GeV]]]
Topology: [[[W]],[[higgs]]](MET,MET)
Contributing elements (up to 4):
[[[W+]],[[higgs]]] cross-section (fb): 0.054017773163696554
	mass: [[2.93E+02 [GeV], 6.81E+01 [GeV]], [2.66E+02 [GeV], 6.81E+01 [GeV]]]
[[[W+]],[[higgs]]] cross-section (fb): 0.026550971397703387
	mass: [[2.93E+02 [GeV], 6.81E+01 [GeV]], [2.92E+02 [GeV], 1.35E+02 [GeV]]]
[[[W+]],[[higgs]]] cross-section (fb): 0.025059230926969038
	mass: [[2.93E+02 [GeV], 1.35E+02 [GeV]], [2.66E+02 [GeV], 6.81E+01 [GeV]]]
[[[W+]],[[higgs]]] cross-section (fb): 0.12605534539410615
	mass: [[2.93E+02 [GeV], 1.35E+02 [GeV]], [2.92E+02 [GeV], 6.81E+01 [GeV]]]