From e7a0eec99a4e43e37ceb8e8c97b8898e8c59772b Mon Sep 17 00:00:00 2001 From: Wolfgang Waltenberger Date: Wed, 31 Jul 2024 13:57:47 +0200 Subject: [PATCH] more accurately reproduce old behavior, everything with CR is now CR --- smodels/statistics/pyhfInterface.py | 43 +++++++++++++++-------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/smodels/statistics/pyhfInterface.py b/smodels/statistics/pyhfInterface.py index 51b5e17b4..85ad6ecd2 100755 --- a/smodels/statistics/pyhfInterface.py +++ b/smodels/statistics/pyhfInterface.py @@ -80,18 +80,31 @@ countWarning = {"llhdszero": 0} +def guessPyhfType ( name : str ) -> str: + """ given the pyhf analysis region name, + guess the type. awkward, phase this out! """ + if name.startswith ( "CR" ): + return "CR" + if name.startswith ( "VR" ): + return "VR" + if name.startswith ( "SR" ): + return "SR" + if "CR" in name: ## arggh!! + logger.warning ( f"old jsonFiles format used, and 'CR' in the middle of the region name: {name}. I will assume it is a control region but do switch to the new format ASAP" ) + return "CR" + return "SR" class PyhfData: """ Holds data for use in pyhf - :ivar nsignals: signal predictions dictionary of dictionaries, + :ivar nsignals: signal predictions dictionary of dictionaries, one for each json file, one entry per signal region :ivar inputJsons: list of json instances :ivar jsonFiles: optional list of json files :ivar nWS: number of workspaces = number of json files """ - def __init__( self, nsignals : Dict[str, Dict], inputJsons, jsonFiles=None, + def __init__( self, nsignals : Dict[str, Dict], inputJsons, jsonFiles=None, includeCRs=False, signalUncertainty=None): self.nsignals = nsignals self.getTotalYield() @@ -109,7 +122,7 @@ def __init__( self, nsignals : Dict[str, Dict], inputJsons, jsonFiles=None, else: for j in range( len ( sregions ) ): srname = f"SR1[{j}]" - regions.append ( { "smodels": srname, "type": "SR", + regions.append ( { "smodels": srname, "type": "SR", "pyhf": srname } ) jsonFiles[ jFile ] = regions self.jsonFiles = jsonFiles @@ -181,7 +194,7 @@ def createPatchForRegion ( self, region, i_ch, ch, jsName ): "signal": signal }, "signalRegions" return ret - ret = { 'path': f"/channels/{i_ch}", 'name': chname, + ret = { 'path': f"/channels/{i_ch}", 'name': chname, 'type': region['type']}, "otherRegions" return ( ret ) @@ -191,16 +204,6 @@ def updatePyhfNames ( self, jsName : str, observations : List ): if "pyhf" in self.jsonFiles[jsName][0]: return - def guessPyhfName ( name : str ) -> str: - if name.startswith ( "CR" ): - return "CR" - if name.startswith ( "VR" ): - return "VR" - if name.startswith ( "SR" ): - return "SR" - if "_CR_" in name: - return "CR" - return "SR" ## we dont have the mapping smodels<->pyhf ctr = 0 #ic ( "---" ) @@ -212,31 +215,31 @@ def guessPyhfName ( name : str ) -> str: nSRs = 0 for observation in observations: name = observation["name"] - regionType = guessPyhfName ( name ) + regionType = guessPyhfType ( name ) if regionType == "SR": nSRs += 1 # ic ( nSRs, nCRs ) for observation in observations: name = observation["name"] - regionType = guessPyhfName ( name ) + regionType = guessPyhfType ( name ) if regionType in [ "VR" ]: - region = { "pyhf": observation["name"], "smodels": None, + region = { "pyhf": observation["name"], "smodels": None, "type": regionType } self.jsonFiles[jsName].append ( region ) continue if not self.includeCRs and regionType in [ "CR" ]: - region = { "pyhf": observation["name"], "smodels": None, + region = { "pyhf": observation["name"], "smodels": None, "type": regionType } self.jsonFiles[jsName].append ( region ) continue if self.includeCRs and regionType in [ "CR" ]: if nSRs == nJsonFiles: # and nSRs+nCRs == nObs: ## the signal regions alone do it - region = { "pyhf": observation["name"], "smodels": None, + region = { "pyhf": observation["name"], "smodels": None, "type": regionType } self.jsonFiles[jsName].append ( region ) continue - + if len(observation["data"])==1: if ctr < len(self.jsonFiles[jsName]): self.jsonFiles[jsName][ctr]["pyhf"]=f"{name}"