From f285e3ce92eb0073b2e86e0d1e05cc258ce88350 Mon Sep 17 00:00:00 2001 From: davidwalter2 Date: Fri, 3 Jan 2025 07:42:17 -0500 Subject: [PATCH] Fix bug in lowPU and restore previous behaviour --- scripts/combine/setupCombine.py | 75 +++++++++++++++++++++++++-------- 1 file changed, 58 insertions(+), 17 deletions(-) diff --git a/scripts/combine/setupCombine.py b/scripts/combine/setupCombine.py index 1265f8eed..adcdc2af3 100644 --- a/scripts/combine/setupCombine.py +++ b/scripts/combine/setupCombine.py @@ -1243,7 +1243,8 @@ def assertSample(name, startsWith=["W", "Z"], excludeMatch=[]): cardTool.addProcessGroup( "MCnoQCD", lambda x: x - not in ["QCD", "Data", "Fake"] + (["Fake"] if simultaneousABCD else []), + not in ["QCD", "Data", "Fake", "Fake_mu", "Fake_e"] + + (["Fake"] if simultaneousABCD else []), ) # FIXME/FOLLOWUP: the following groups may actually not exclude the OOA when it is not defined as an independent process with specific name cardTool.addProcessGroup( @@ -1617,23 +1618,63 @@ def assertSample(name, startsWith=["W", "Z"], excludeMatch=[]): return cardTool # Below: experimental uncertainties - cardTool.addSystematic( - cardTool.nominalName, - rename="luminosity", - processes=["MCnoQCD"], - group=f"luminosity", - splitGroup={"experiment": ".*", "expNoCalib": ".*"}, - passToFakes=passSystToFakes, - mirror=True, - preOp=hh.scaleHist, - preOpArgs={ - "scale": ( - cardTool.datagroups.lumi_uncertainty - if args.lumiUncertainty is None - else args.lumiUncertainty + + if wmass: + # mirror hist in linear scale, this was done in the old definition of luminosity uncertainty from a histogram + def scale_hist_up_down(h, scale): + hUp = hh.scaleHist(h, scale) + hDown = hh.scaleHist(h, 1 / scale) + + hVar = hist.Hist( + *[a for a in h.axes], + common.down_up_axis, + storage=hist.storage.Weight(), ) - }, - ) + hVar.values(flow=True)[...] = np.stack( + [hUp.values(flow=True), hDown.values(flow=True)], axis=-1 + ) + hVar.variances(flow=True)[...] = np.stack( + [hUp.variances(flow=True), hDown.variances(flow=True)], axis=-1 + ) + return hVar + + cardTool.addSystematic( + cardTool.nominalName, + rename="luminosity", + processes=["MCnoQCD"], + group=f"luminosity", + splitGroup={"experiment": ".*", "expNoCalib": ".*"}, + passToFakes=passSystToFakes, + outNames=["lumiDown", "lumiUp"], + systAxes=["downUpVar"], + labelsByAxis=["downUpVar"], + preOp=scale_hist_up_down, + preOpArgs={ + "scale": ( + cardTool.datagroups.lumi_uncertainty + if args.lumiUncertainty is None + else args.lumiUncertainty + ) + }, + ) + else: + cardTool.addSystematic( + cardTool.nominalName, + rename="luminosity", + processes=["MCnoQCD"], + group=f"luminosity", + splitGroup={"experiment": ".*", "expNoCalib": ".*"}, + passToFakes=passSystToFakes, + mirror=True, + preOp=hh.scaleHist, + preOpArgs={ + "scale": ( + cardTool.datagroups.lumi_uncertainty + if args.lumiUncertainty is None + else args.lumiUncertainty + ) + }, + ) if not lowPU: # lowPU does not include PhotonInduced as a process. skip it: cardTool.addSystematic(