Skip to content

Commit

Permalink
Changed behavior of reportAllSRs
Browse files Browse the repository at this point in the history
  • Loading branch information
andlessa committed Jan 18, 2024
1 parent f25cfda commit b1e01ef
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
1 change: 0 additions & 1 deletion smodels/matching/modelTester.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ def testPoint(inputFile, outputDir, parser, database):
allSRs = parser.getboolean("options", "reportAllSRs")
if allSRs: # If set print out all SRs and skip combination
useBest = False
combineResults = False
except (NoSectionError, NoOptionError):
pass
try:
Expand Down
33 changes: 18 additions & 15 deletions smodels/matching/theoryPrediction.py
Original file line number Diff line number Diff line change
Expand Up @@ -676,21 +676,17 @@ def theoryPredictionsFor(database : Database, smsTopDict : Dict,
# For results with more than one dataset keep all dataset predictions
if len(dataSetResults) == 1: # only a single dataset? Easy case.
expResults = dataSetResults[0]

# if useBestDataSet=False and combinedResults=False:
elif not useBestDataset and not combinedResults:
expResults = sum(dataSetResults)

elif combinedResults: # Try to combine results
expResults = TheoryPredictionList()
combinedRes = _getCombinedResultFor(dataSetResults,
else:
if combinedResults: # Include combination
combinedRes = _getCombinedResultFor(dataSetResults,
expResult)
if combinedRes is None: # Can not combine, use best dataset:
combinedRes = _getBestResult(dataSetResults)
expResults.append(combinedRes)
else: # Use best dataset:
expResults = TheoryPredictionList()
expResults.append(_getBestResult(dataSetResults))
if combinedRes is not None:
dataSetResults.append(TheoryPredictionList([combinedRes]))
if not useBestDataset: # Report all datasets
expResults = sum(dataSetResults)
else:
expResults = TheoryPredictionList()
expResults.append(_getBestResult(dataSetResults)) # Best result = combination if available

for theoPred in expResults:
theoPred.expResult = expResult
Expand Down Expand Up @@ -770,7 +766,8 @@ def _getCombinedResultFor(dataSetResults, expResult):

def _getBestResult(dataSetResults):
"""
Returns the best result according to the expected upper limit
Returns the best result according to the expected upper limit.
If a combined result is included in the list, always return it.
:param datasetPredictions: list of TheoryPredictionList objects
:return: best result (TheoryPrediction object)
Expand All @@ -780,6 +777,12 @@ def _getBestResult(dataSetResults):
# return the single result:
if len(dataSetResults) == 1:
return dataSetResults[0]

# If combination is included, always return it
for predList in dataSetResults:
for tp in predList:
if isinstance(tp.dataset,CombinedDataSet):
return tp

# For efficiency-map analyses with multipler signal regions,
# select the best one according to the expected upper limit:
Expand Down
6 changes: 5 additions & 1 deletion smodels/statistics/simplifiedLikelihoods.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,8 @@ def findThetaHat(self, mu : float ):
"""Compute nuisance parameters theta that maximize our likelihood
(poisson*gauss).
"""
if isinstance(mu,(np.ndarray,list)):
mu = mu[0]
mu = float(mu)
if np.isinf ( mu ):
return None
Expand Down Expand Up @@ -825,7 +827,9 @@ def findMuHat(
theta_hat, _ = self.findThetaHat( avgr )
minr, avgr, maxr = self.findAvgr( theta_hat )

def myllhd( mu : float ):
def myllhd( mu ):
if isinstance(mu,(np.ndarray,list)):
mu = mu[0]
theta = self.findThetaHat ( mu=float(mu) )
ret = self.likelihood(return_nll=True, mu = mu )
return ret
Expand Down
2 changes: 1 addition & 1 deletion unittests/testTopoComb.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def testCombinedResult(self):

database.selectExpResults( analysisIDs = [ "CMS-SUS-16-050-agg" ] )
# print ( "Experimental result: %s" % expRes )
tp = theoryPredictionsFor(database, deco, useBestDataset=False, combinedResults=True)
tp = theoryPredictionsFor(database, deco, useBestDataset=True, combinedResults=True)
for t in tp:
predXSecs[case]=t.xsection
rvalues[case]=t.getRValue(expected=True)
Expand Down

0 comments on commit b1e01ef

Please sign in to comment.