Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce memory footprint of parsed datacard #791

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions python/DatacardParser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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))
Expand Down Expand Up @@ -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?
Expand Down
6 changes: 3 additions & 3 deletions python/NuisanceModifier.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
6 changes: 3 additions & 3 deletions scripts/combineCards.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/datacardDump.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions test/systematicsAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = []
Expand Down