How To: Compute likelihood and chi2

In [1]:
# Set up the path to SModelS installation folder
import sys; sys.path.append("."); import smodels_paths
In [2]:
from smodels.tools.simplifiedLikelihoods import LikelihoodComputer, Data

How to compute the likelihood and chi2 from the number of events

In [3]:
# If the number of observed events, the number of expected background events,
# its error and the number of signal events and its error are known, the likelihood
# for the signal (assuming a truncated gaussian distribution for the background and signal uncertainties)
# can be computed as:
m=Data ( observed=5, backgrounds=4.2, covariance=0.71**2, third_moment=None, nsignal=.1 )
comp=LikelihoodComputer ( m )
print ('likelihood=',comp.likelihood(nsig = 10. ) )
print ('chi2=',comp.chi2( nsig=10.))
likelihood= 0.0014241306489629875
chi2= 8.425350487466552

How to compute the likelihood and chi2 from a theory prediction

In [4]:
# In most cases one wants to compute the likelihood and chi2 for a given theory prediction computed by SModelS.
# Below we generate theory predictions and compute the likelihood and chi2 values for them
# First we import those parts of smodels that are needed for this exercise
#(We will assume the input is a SLHA file. For LHE files, use the lheDecomposer instead)
from smodels.theory import slhaDecomposer
from smodels.installation import installDirectory
from smodels.tools.physicsUnits import fb, GeV
from smodels.theory.theoryPrediction import theoryPredictionsFor
from smodels.experiment.databaseObj import Database
In [5]:
# Define the SLHA input file name
filename="%s/inputFiles/slha/gluino_squarks.slha" % installDirectory()
In [6]:
# Load the database, do the decomposition and compute theory predictions:
# (Look at the theory predictions HowTo to learn how to compute theory predictions)
database = Database("official")
expResults = database.getExpResults()
topList = slhaDecomposer.decompose(filename, sigcut = 0.03 * fb, doCompress=True, doInvisible=True,minmassgap = 5* GeV)
allThPredictions = [theoryPredictionsFor(exp, topList) for exp in expResults]
FastLim v1.1 efficiencies loaded. Please cite: arXiv:1402.0492, EPJC74 (2014) 11
In [7]:
# For each theory prediction, compute the corresponding likelihood and chi2 values
# (This is only possible for efficiency map-type results):
for i,thPreds in enumerate(allThPredictions):
    if not thPreds: continue #skip results with no predictions
    expID = expResults[i].globalInfo.id
    dataType = expResults[i].getValuesFor('dataType')[0]    
    for theoryPred in thPreds:
        #Compute the likelihood and chi2:
        theoryPred.computeStatistics()
        print ("\nExperimental Result: %s (%s-type)" %(expID,dataType)) #Result ID and type
        print ("Theory prediction xsec = ",theoryPred.xsection.value) #Signal xsection*efficiency*BR
        if dataType == 'efficiencyMap':
            print ('likelihood =',theoryPred.likelihood,', chi2 =',theoryPred.chi2)
        else:
            print ("(likelihood not available)")
Experimental Result: ATLAS-SUSY-2015-06 (efficiencyMap-type)
Theory prediction xsec =  2.79E-04 [pb]
likelihood = 0.0050359628700245174 , chi2 = 3.0840515186725916

Experimental Result: CMS-PAS-SUS-16-022 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-PAS-SUS-17-004 (upperLimit-type)
Theory prediction xsec =  2.07E-01 [pb]
(likelihood not available)

Experimental Result: CMS-PAS-SUS-17-004 (upperLimit-type)
Theory prediction xsec =  3.99E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-033 (upperLimit-type)
Theory prediction xsec =  7.53E-03 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-033 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-033 (upperLimit-type)
Theory prediction xsec =  1.15E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-034 (upperLimit-type)
Theory prediction xsec =  3.99E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-035 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-036 (upperLimit-type)
Theory prediction xsec =  1.15E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-036 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-036 (upperLimit-type)
Theory prediction xsec =  7.53E-03 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-037 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-039 (upperLimit-type)
Theory prediction xsec =  2.07E-01 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-039 (upperLimit-type)
Theory prediction xsec =  3.99E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-041 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-042 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-043 (upperLimit-type)
Theory prediction xsec =  2.07E-01 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-045 (upperLimit-type)
Theory prediction xsec =  2.07E-01 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-050 (upperLimit-type)
Theory prediction xsec =  3.50E-05 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-16-050-agg (efficiencyMap-type)
Theory prediction xsec =  1.38E-07 [pb]
likelihood = 39.50248049732107 , chi2 = 0.019736370894965383

Experimental Result: CMS-SUS-16-050-agg (efficiencyMap-type)
Theory prediction xsec =  3.95E-06 [pb]
likelihood = 1.8680525463965295e-95 , chi2 = 31.67271912861827

Experimental Result: ATLAS-CONF-2013-007 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: ATLAS-CONF-2013-024 (efficiencyMap-type)
Theory prediction xsec =  1.57E-06 [pb]
likelihood = 0.03552144112434013 , chi2 = 1.2908610697112488

Experimental Result: ATLAS-CONF-2013-037 (efficiencyMap-type)
Theory prediction xsec =  7.32E-07 [pb]
likelihood = 0.024499151313233693 , chi2 = 0.34726082857627727

Experimental Result: ATLAS-CONF-2013-047 (efficiencyMap-type)
Theory prediction xsec =  2.67E-04 [pb]
likelihood = 0.002412978100802775 , chi2 = 1.1001933139076296

Experimental Result: ATLAS-CONF-2013-048 (efficiencyMap-type)
Theory prediction xsec =  1.34E-07 [pb]
likelihood = 0.03343980433243834 , chi2 = 0.3629550573418445

Experimental Result: ATLAS-CONF-2013-053 (efficiencyMap-type)
Theory prediction xsec =  9.67E-08 [pb]
likelihood = 0.14305663806518287 , chi2 = 0.053559313990082735

Experimental Result: ATLAS-CONF-2013-054 (efficiencyMap-type)
Theory prediction xsec =  9.49E-06 [pb]
likelihood = 0.020329418637285657 , chi2 = 0.0316808134090083

Experimental Result: ATLAS-CONF-2013-061 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: ATLAS-CONF-2013-061 (efficiencyMap-type)
Theory prediction xsec =  1.22E-06 [pb]
likelihood = 0.07305778571920976 , chi2 = 0.2333050177556828

Experimental Result: ATLAS-CONF-2013-062 (efficiencyMap-type)
Theory prediction xsec =  8.87E-07 [pb]
likelihood = 0.11929764353379285 , chi2 = 3.1575684527847923

Experimental Result: ATLAS-CONF-2013-089 (upperLimit-type)
Theory prediction xsec =  6.66E-03 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-02 (upperLimit-type)
Theory prediction xsec =  6.62E-04 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-02 (upperLimit-type)
Theory prediction xsec =  1.96E-03 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-02 (upperLimit-type)
Theory prediction xsec =  6.66E-03 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-02 (upperLimit-type)
Theory prediction xsec =  9.07E-03 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-02 (efficiencyMap-type)
Theory prediction xsec =  6.23E-04 [pb]
likelihood = 0.0012785956928507054 , chi2 = 0.12618145188070073

Experimental Result: ATLAS-SUSY-2013-04 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-04 (efficiencyMap-type)
Theory prediction xsec =  1.53E-04 [pb]
likelihood = 0.017686308162496105 , chi2 = 0.3102372950900598

Experimental Result: ATLAS-SUSY-2013-09 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-11 (upperLimit-type)
Theory prediction xsec =  1.85E-02 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-11 (efficiencyMap-type)
Theory prediction xsec =  4.39E-05 [pb]
likelihood = 0.020730697027885686 , chi2 = 0.05404478894414755

Experimental Result: ATLAS-SUSY-2013-12 (upperLimit-type)
Theory prediction xsec =  1.85E-02 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-18 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: ATLAS-SUSY-2013-18 (efficiencyMap-type)
Theory prediction xsec =  1.32E-07 [pb]
likelihood = 0.05698838999145924 , chi2 = 4.246330204023675

Experimental Result: CMS-PAS-SUS-13-016 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-PAS-SUS-13-016 (efficiencyMap-type)
Theory prediction xsec =  2.88E-08 [pb]
likelihood = 0.13866390723201363 , chi2 = 0.01712330843623011

Experimental Result: CMS-SUS-12-024 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-12-024 (efficiencyMap-type)
Theory prediction xsec =  3.79E-08 [pb]
likelihood = 0.04653167016160565 , chi2 = 0.7282558489640794

Experimental Result: CMS-SUS-12-028 (upperLimit-type)
Theory prediction xsec =  6.62E-04 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-12-028 (upperLimit-type)
Theory prediction xsec =  1.96E-03 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-12-028 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-002 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-004 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-006 (upperLimit-type)
Theory prediction xsec =  1.85E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-006 (upperLimit-type)
Theory prediction xsec =  9.59E-02 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-007 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-007 (efficiencyMap-type)
Theory prediction xsec =  2.07E-08 [pb]
likelihood = 0.3773394259512739 , chi2 = 1.1588822770817544

Experimental Result: CMS-SUS-13-012 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-012 (upperLimit-type)
Theory prediction xsec =  1.96E-03 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-012 (upperLimit-type)
Theory prediction xsec =  6.62E-04 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-012 (efficiencyMap-type)
Theory prediction xsec =  8.65E-05 [pb]
likelihood = 0.041106586954831464 , chi2 = 0.007342449997104872

Experimental Result: CMS-SUS-13-013 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-013 (efficiencyMap-type)
Theory prediction xsec =  4.16E-08 [pb]
likelihood = 0.10977273124946735 , chi2 = 0.006572298674409005

Experimental Result: CMS-SUS-13-019 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-019 (upperLimit-type)
Theory prediction xsec =  6.62E-04 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-13-019 (upperLimit-type)
Theory prediction xsec =  1.96E-03 [pb]
(likelihood not available)

Experimental Result: CMS-SUS-14-010 (upperLimit-type)
Theory prediction xsec =  3.07E-06 [pb]
(likelihood not available)