diff --git a/python/DatacardParser.py b/python/DatacardParser.py index af6de64f1ef..e6ed8f44938 100644 --- a/python/DatacardParser.py +++ b/python/DatacardParser.py @@ -620,7 +620,7 @@ def parseCard(file, options): raise RuntimeError( "Malformed systematics line %s of length %d: while bins and process lines have length %d" % (lsyst, len(numbers), len(ret.keyline)) ) - errline = dict([(b, {}) for b in ret.bins]) + errline = {b: {} for b in ret.bins} nonNullEntries = 0 for (b, p, s), r in zip(ret.keyline, numbers): if "/" in r: # "number/number" @@ -632,8 +632,11 @@ def parseCard(file, options): raise ValueError('Found "%s" in the nuisances affecting %s for %s. This would lead to NANs later on, so please fix it.' % (r, p, b)) else: if r == "-" * len(r): - r = 0.0 - errline[b][p] = float(r) + continue + r_float = float(r) + if r_float == 0.0: + continue + errline[b][p] = r_float # values of 0.0 are treated as 1.0; scrap negative values. if pdf not in ["trG", "dFD", "dFD2"] and errline[b][p] < 0: raise ValueError('Found "%s" in the nuisances affecting %s in %s. This would lead to NANs later on, so please fix it.' % (r, p, b)) @@ -674,7 +677,7 @@ def parseCard(file, options): syst2.append((lsyst, nofloat, pdf, args, errline)) continue for (b, p, s) in ret.keyline: - r = errline[b][p] + r = errline[b].get(p, 0.0) nullEffect = r == 0.0 or (pdf == "lnN" and r == 1.0) if not nullEffect and ret.exp[b][p] != 0: nonNullEntries += 1 # is this a zero background? diff --git a/python/NuisanceModifier.py b/python/NuisanceModifier.py index 5e5058d2e9c..6c09438e373 100644 --- a/python/NuisanceModifier.py +++ b/python/NuisanceModifier.py @@ -370,10 +370,10 @@ def doSplitNuisance(datacard, args): for p in datacard.exp[b]: if process == "*" or fullmatch(cprocess, p): foundProc = True - if errline[b][p] not in [0.0, 1.0]: + if errline[b].get(p, 0.0) not in [0.0, 1.0]: doAddNuisance(datacard, [p, b, newname1, pdf, value1, "overwrite"]) doAddNuisance(datacard, [p, b, newname2, pdf, value2, "overwrite"]) - errline[b][p] = 0 + del errline[b][p] if not foundProc and channel != "*": if "ifexists" not in opts: @@ -432,7 +432,7 @@ def doFlipNuisance(datacard, args): for p in datacard.exp[b]: if process == "*" or fullmatch(cprocess, p): foundProc = True - if errline[b][p] not in [0.0, 1.0]: + if errline[b].get(p, 0.0) not in [0.0, 1.0]: if type(errline[b][p]) is list: if errline[b][p][0] < 1: if "p2n" in opts: diff --git a/scripts/combineCards.py b/scripts/combineCards.py index 38e98a6a9d4..7beb9fc57da 100755 --- a/scripts/combineCards.py +++ b/scripts/combineCards.py @@ -230,15 +230,15 @@ def compareParamSystLines(a, b): constraint_terms.append(line) warnings.warn(warning_message, RuntimeWarning) break - if type(errline[b][p]) == list: + if errline[b].get(p, 0.0) == 0.0: + r = "-" + elif type(errline[b][p]) == list: r = "%s/%s" % ( FloatToString(errline[b][p][0]), FloatToString(errline[b][p][1]), ) elif type in ("lnN", "gmM"): r = "%s" % FloatToString(errline[b][p]) - if errline[b][p] == 0: - r = "-" if len(r) > cmax: cmax = len(r) # get max col length, as it's more tricky to do it later with a map systeffect[bout][p] = r diff --git a/test/datacardDump.py b/test/datacardDump.py index fb9fbda85da..1f11337b6b1 100755 --- a/test/datacardDump.py +++ b/test/datacardDump.py @@ -111,7 +111,7 @@ continue # end skip systematics for p in DC.exp[b].keys(): # so that we get only self.DC.processes contributing to this bin - if errline[b][p] == 0: + if errline[b].get(p, 0.0) == 0.0: continue if pdf == "gmN": exps[p][1].append(1 / sqrt(pdfargs[0] + 1)) diff --git a/test/systematicsAnalyzer.py b/test/systematicsAnalyzer.py index 4f7c013dba9..a78f32cd1b9 100755 --- a/test/systematicsAnalyzer.py +++ b/test/systematicsAnalyzer.py @@ -228,7 +228,7 @@ def addTo(dic, key, l): if lsyst in list(check_list.keys()): if [p, b] in check_list[lsyst]: continue - if (not pdf == "param") and errline[b][p] == 0: + if (not pdf == "param") and errline[b].get(p, 0.0) == 0.0: continue if pdf == "gmN": numKeysFound += 1 @@ -273,7 +273,7 @@ def addTo(dic, key, l): elif "shape" in pdf and MB.isShapeSystematic(b, p, lsyst): - if errline[b][p] == 0: + if errline[b].get(p, 0.0) == 0.0: continue systShapeName = lsyst # vals = []