From fc992c4410c447ee12c16fead9dd6892f4b64628 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 17 Oct 2025 15:44:19 +0200 Subject: [PATCH 01/46] generalize eta labels better for plot_decorr_params --- scripts/plotting/plot_decorr_params.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/plotting/plot_decorr_params.py b/scripts/plotting/plot_decorr_params.py index 4dd1d18aa..32564cc88 100644 --- a/scripts/plotting/plot_decorr_params.py +++ b/scripts/plotting/plot_decorr_params.py @@ -226,15 +226,15 @@ def get_values_and_impacts_as_panda( if "eta" in axes: # this assumes the 48 eta bins are rebinned uniformly, and 0 is an edge of the central bins nEtaBins = df_p.shape[0] if "charge" not in axes else int(df_p.shape[0] / 2) - nEtaBinsOneSide = int(nEtaBins / 2) + lowest_eta = -2.4 etaWidth = 4.8 / nEtaBins df_p["yticks"] = ( df_p["eta"] - .apply(lambda x: round((x - nEtaBinsOneSide) * etaWidth, 1)) + .apply(lambda x: round(lowest_eta + x * etaWidth, 1)) .astype(str) + r"<\mathit{\eta}^{\mu}<" + df_p["eta"] - .apply(lambda x: round((x - nEtaBinsOneSide) * etaWidth + etaWidth, 1)) + .apply(lambda x: round(lowest_eta + (x + 1) * etaWidth, 1)) .astype(str) ) if "charge" in axes: From d330024bc3343f4a5fdf891ccf8072007a4b1d4d Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 13 Nov 2025 11:11:24 +0100 Subject: [PATCH 02/46] plotting and testing --- scripts/analysisTools/tests/testFakesVsMt.py | 843 +++++++++++------- scripts/analysisTools/tests/testPlots1D.py | 7 +- scripts/histmakers/mw_with_mu_eta_pt.py | 181 +++- scripts/histmakers/mz_wlike_with_mu_eta_pt.py | 2 - scripts/plotting/makeDataMCStackPlot.py | 14 +- utilities/parsing.py | 6 + utilities/styles/styles.py | 3 +- wremnants/include/utils.hpp | 2 +- wremnants/muon_selections.py | 3 +- 9 files changed, 703 insertions(+), 358 deletions(-) diff --git a/scripts/analysisTools/tests/testFakesVsMt.py b/scripts/analysisTools/tests/testFakesVsMt.py index 2f9666b08..49ef70a32 100644 --- a/scripts/analysisTools/tests/testFakesVsMt.py +++ b/scripts/analysisTools/tests/testFakesVsMt.py @@ -87,6 +87,7 @@ def plotProjection1D( mTvalueRange=[], rebinVariable=None, scaleQCDMC=1.0, + noMtABCD=False, ): firstBinMt = 1 @@ -109,8 +110,9 @@ def plotProjection1D( rootHists[d].GetAxis(2).SetRange(chargeBin, chargeBin) rootHists[d].GetAxis(3).SetRange(firstBinMt, lastBinMt) rootHists[d].GetAxis(4).SetRange(isoAxisRange[0], isoAxisRange[1]) - rootHists[d].GetAxis(5).SetRange(jetAxisRange[0], jetAxisRange[1]) - rootHists[d].GetAxis(6).SetRange(1, rootHists[d].GetAxis(6).GetNbins()) + if not noMtABCD: + rootHists[d].GetAxis(5).SetRange(jetAxisRange[0], jetAxisRange[1]) + rootHists[d].GetAxis(6).SetRange(1, rootHists[d].GetAxis(6).GetNbins()) if d == "Data": hdata = rootHists[d].Projection(projectAxisToKeep, "EO") hdata.SetName(f"{plotName}_{d}") @@ -231,6 +233,8 @@ def drawAndFitFRF( # following two are test histograms which make sense for pol1 fits histoChi2diffTest=None, histoPullsPol1Slope=None, + noMtABCD=False, + erfAsMainModel=False, ): # moreTextLatex is used to write text with TLatex, and the syntax is textToWrite::x1,y1,ypass,textsize @@ -321,7 +325,7 @@ def drawAndFitFRF( fitBinLow = h1.GetXaxis().FindFixBin(xMinFit + 0.001) fitBinHigh = h1.GetXaxis().FindFixBin(xMaxFit + 0.001) fitBinEdges = [ - round(h1.GetXaxis().GetBinLowEdge(i), 2) + round(h1.GetXaxis().GetBinLowEdge(i), 3) for i in range(fitBinLow, fitBinHigh + 1) ] # logger.info(fitBinEdges) @@ -335,11 +339,14 @@ def drawAndFitFRF( binOriginalHisto = ib + fitBinLow - 1 h1fitRange.SetBinContent(ib, h1.GetBinContent(binOriginalHisto)) h1fitRange.SetBinError(ib, h1.GetBinError(binOriginalHisto)) + # logger.error(h1fitRange.GetXaxis().GetBinLowEdge(ib)) boost_hist = narf.root_to_hist(h1fitRange) + fitModel = ( + "1-Erf[x]" if erfAsMainModel else f"pol{fitPolDegree}" + ) # just for legend, set here to make sure it is changed consistently with line below # FIT WITH TENSORFLOW global polN_scaled_global - fitModel = f"pol{fitPolDegree}" # just for legend, set here to make sure it is changed consistently with line below params = np.array([1.0] + [0.0 for i in range(fitPolDegree)]) if polN_scaled_global == None: polN_scaled_global = partial( @@ -349,10 +356,45 @@ def drawAndFitFRF( degree=fitPolDegree, ) - fitres_tf1 = wums.fitutils.fit_hist(boost_hist, polN_scaled_global, params) - f1 = ROOT.TF1("f1", polN_scaled_global, xMinFit, xMaxFit, len(params)) - status = fitres_tf1["status"] - covstatus = fitres_tf1["covstatus"] + xvalMin = h1.GetXaxis().GetBinLowEdge(1) + xvalMax = h1.GetXaxis().GetBinUpEdge(h1.GetNbinsX()) + + fitres_tf1_antiErf = None + f1_antiErf = None + if erfAsMainModel: + fitres_tf1_main = wums.fitutils.fit_hist( + boost_hist, antiErf_tf, np.array([1.0, 60.0, 5.0]) + ) + f1_main = ROOT.TF1( + "f1_antiErf", + "[0] * (1.0 - TMath::Erf((x-[1])/[2]))", + xMinFit, + xMaxFit, + ) + funcFullRange = ROOT.TF1( + "funcFullRange", "[0] * (1.0 - TMath::Erf((x-[1])/[2]))", xvalMin, 200 + ) # define this one until "infinity" + funcFullRange.SetParameters(np.array(fitres_tf1_main["x"], dtype=np.dtype("d"))) + else: + fitres_tf1_main = wums.fitutils.fit_hist(boost_hist, polN_scaled_global, params) + f1_main = ROOT.TF1("f1_main", polN_scaled_global, xMinFit, xMaxFit, len(params)) + if not noMtABCD: + fitres_tf1_antiErf = wums.fitutils.fit_hist( + boost_hist, antiErf_tf, np.array([1.0, 60.0, 5.0]) + ) + f1_antiErf = ROOT.TF1( + "f1_antiErf", + "[0] * (1.0 - TMath::Erf((x-[1])/[2]))", + xMinFit, + xMaxFit, + ) + funcFullRange = ROOT.TF1( + "funcFullRange", polN_scaled_global, xvalMin, 200, len(params) + ) # define this one until "infinity" + funcFullRange.SetParameters(np.array(fitres_tf1_main["x"], dtype=np.dtype("d"))) + + status = fitres_tf1_main["status"] + covstatus = fitres_tf1_main["covstatus"] if status: logger.warning(f"\n\n-----> STATUS: fit had status {status}\n\n") if status not in badFitsID.keys(): @@ -366,31 +408,21 @@ def drawAndFitFRF( else: badCovMatrixID[covstatus] += 1 - fitres_tf1_antiErf = wums.fitutils.fit_hist( - boost_hist, antiErf_tf, np.array([1.0, 60.0, 5.0]) - ) - f1_antiErf = ROOT.TF1( - "f1_antiErf", - "[0] * (1.0 - TMath::Erf((x-[1])/[2]))", - xMinFit, - xMaxFit, - ) - # get chi 2: - chi2 = fitres_tf1["loss_val"] - ndof = int(len(fitBinEdges) - 1 - f1.GetNpar()) + chi2 = fitres_tf1_main["loss_val"] + ndof = int(len(fitBinEdges) - 1 - f1_main.GetNpar()) chi2prob = ROOT.TMath.Prob(chi2, ndof) chi2text = f"#chi^{{2}} = {round(chi2,1)} / {ndof}" - if chi2prob < 0.05: - perc_chi2prob = 100.0 * chi2prob - sign = "=" - if perc_chi2prob < 0.1: - perc_chi2prob = 0.1 - sign = "<" - chi2text += " (prob {} {}%)".format(sign, round(perc_chi2prob, 1)) + # if chi2prob < 0.05: + # perc_chi2prob = 100.0 * chi2prob + # sign = "=" + # if perc_chi2prob < 0.1: + # perc_chi2prob = 0.1 + # sign = "<" + # chi2text += " (prob {} {}%)".format(sign, round(perc_chi2prob, 1)) global pol0_scaled_global - if fitPolDegree == 1: + if fitPolDegree == 1 and not erfAsMainModel: params0 = np.array([1.0]) if pol0_scaled_global == None: pol0_scaled_global = partial( @@ -406,51 +438,56 @@ def drawAndFitFRF( histoChi2diffTest.Fill(chi2diffTest) if histoPullsPol1Slope: histoPullsPol1Slope.Fill( - fitres_tf1["x"][1] / np.sqrt(fitres_tf1["cov"][1][1]) + fitres_tf1_main["x"][1] / np.sqrt(fitres_tf1_main["cov"][1][1]) ) - f1.SetParameters(np.array(fitres_tf1["x"], dtype=np.dtype("d"))) - f1.SetLineWidth(3) - # f1.SetLineStyle(9) # ROOT.kDashed == thin dashes, almost dotted - f1.SetLineColor(ROOT.kBlue + 1) + f1_main.SetParameters(np.array(fitres_tf1_main["x"], dtype=np.dtype("d"))) + f1_main.SetLineWidth(3) + # f1_main.SetLineStyle(9) # ROOT.kDashed == thin dashes, almost dotted + f1_main.SetLineColor(ROOT.kBlue + 1) + # draw extrapolation - f2 = ROOT.TF1( - "f2", - polN_scaled_global, - xMaxFit, - h1.GetXaxis().GetBinLowEdge(1 + h1.GetNbinsX()), - len(params), - ) - for i in range(1 + fitPolDegree): - f2.SetParameter(i, f1.GetParameter(i)) + if erfAsMainModel: + f2 = ROOT.TF1( + "f2_antiErf", + "[0] * (1.0 - TMath::Erf((x-[1])/[2]))", + xMaxFit, + h1.GetXaxis().GetBinLowEdge(1 + h1.GetNbinsX()), + ) + else: + f2 = ROOT.TF1( + "f2", + polN_scaled_global, + xMaxFit, + h1.GetXaxis().GetBinLowEdge(1 + h1.GetNbinsX()), + len(params), + ) + + for i in range(3 if erfAsMainModel else (1 + fitPolDegree)): + f2.SetParameter(i, f1_main.GetParameter(i)) + f2.SetLineColor(ROOT.kRed + 2) - f2.SetLineWidth(3) - f2.SetLineStyle(9) + f2.SetLineWidth(2) + f2.SetLineStyle(2) - # test anti error function - f1_antiErf.SetParameters(np.array(fitres_tf1_antiErf["x"], dtype=np.dtype("d"))) - f1_antiErf.SetLineWidth(3) - # f1_antiErf.SetLineStyle(9) # ROOT.kDashed == thin dashes, almost dotted - f1_antiErf.SetLineColor(ROOT.kRed + 2) + if not noMtABCD and not erfAsMainModel: + # test anti error function + f1_antiErf.SetParameters(np.array(fitres_tf1_antiErf["x"], dtype=np.dtype("d"))) + f1_antiErf.SetLineWidth(3) + f1_antiErf.SetLineColor(ROOT.kRed + 2) - xvalMin = h1.GetXaxis().GetBinLowEdge(1) - xvalMax = h1.GetXaxis().GetBinUpEdge(h1.GetNbinsX()) - funcFullRange = ROOT.TF1( - "funcFullRange", polN_scaled_global, xvalMin, 200, len(params) - ) # define this one until "infinity" - funcFullRange.SetParameters(np.array(fitres_tf1["x"], dtype=np.dtype("d"))) hband = ROOT.TH1D("hband", "", 400, xvalMin, xvalMax) hband.SetStats(0) hband.SetFillColor(ROOT.kGray) # hband.SetFillStyle(3001) for ib in range(1, hband.GetNbinsX() + 1): xval = hband.GetBinCenter(ib) - val = f1.Eval(xval) + val = f1_main.Eval(xval) # logger.info(f"val({xval}) = {val}") hband.SetBinContent(ib, val) - npar = len(params) + npar = 3 if erfAsMainModel else len(params) # diagonalize and get eigenvalues and eigenvectors - e, v = np.linalg.eigh(fitres_tf1["cov"]) + e, v = np.linalg.eigh(fitres_tf1_main["cov"]) # store all variations for faster access below altParameters = np.array( [np.zeros(npar, dtype=np.dtype("d"))] * (npar * 2), dtype=np.dtype("d") @@ -458,8 +495,8 @@ def drawAndFitFRF( # logger.info(altParameters) for ivar in range(npar): shift = np.sqrt(e[ivar]) * v[:, ivar] - altParameters[ivar] = fitres_tf1["x"] + shift - altParameters[ivar + npar] = fitres_tf1["x"] - shift + altParameters[ivar] = fitres_tf1_main["x"] + shift + altParameters[ivar + npar] = fitres_tf1_main["x"] - shift tf1_func_alt = ROOT.TF1() tf1_func_alt.SetName("tf1_func_alt") @@ -480,10 +517,11 @@ def drawAndFitFRF( hband.SetBinError(ib, err) hband.Draw("E2 SAME") - f1.Draw("L SAME") + f1_main.Draw("L SAME") if xMaxFit < xvalMax: f2.Draw("L SAME") - f1_antiErf.Draw("L SAME") + if not noMtABCD and not erfAsMainModel: + f1_antiErf.Draw("L SAME") h1.Draw("EP SAME") nColumnsLeg = 1 @@ -501,11 +539,16 @@ def drawAndFitFRF( leg.SetNColumns(nColumnsLeg) leg.AddEntry(h1, "Measurement", "PE") - leg.AddEntry(f1, f"Fit {fitModel} in [{int(xMinFit)}, {int(xMaxFit)}]", "L") + # TODO improve rounding based on variable + leg_xMinFit = int(xMinFit) if xMinFit > 1 else float(round(xMinFit, 3)) + leg_xMaxFit = int(xMaxFit) if xMaxFit > 1 else float(round(xMaxFit, 3)) + leg.AddEntry(f1_main, f"Fit {fitModel}", "L") + # leg.AddEntry(f1_main, f"Fit {fitModel} in [{leg_xMinFit}, {leg_xMaxFit}]", "L") if xMaxFit < xvalMax: leg.AddEntry(f2, f"Extrapolation", "L") leg.AddEntry(hband, "Fit uncertainty", "F") - leg.AddEntry(f1_antiErf, f"Fit f(x) = 1 - Erf[x]", "L") + if not noMtABCD and not erfAsMainModel: + leg.AddEntry(f1_antiErf, f"Fit f(x) = 1 - Erf[x]", "L") leg.Draw("same") canvas.RedrawAxis("sameaxis") @@ -667,13 +710,35 @@ def runStudy(fname, charges, mainOutputFolder, args): histoChi2diffTest = None histoPullsPol1Slope = None - etaLabel = "#eta" if not args.absEta else "|#eta|" + inputHistDict = { + "mt": "mTStudyForFakes", + "oneMinusCosdphi": "mTStudyForFakesAlt", + "mtOverPt": "mTStudyForFakesAlt2", + "altMt": "mTStudyForFakesAlt3", + "dxybs": "mTStudyForFakesAlt4", + } + + etaLabel = "#eta^{#mu}" if not args.absEta else "|#eta^{#mu}|" + ptLabel = "#it{p}_{T}^{#mu}" + mtLabel = "#it{m}_{T}" + metLabel = "#it{p}_{T}^{miss}" + dphiMuMetLabel = "#Delta#phi(#mu,^{ }#it{p}_{T}^{miss})" + + zAxisNames = { + "mt": f"{mtLabel} (GeV)", + "oneMinusCosdphi": f"1 - {dphiMuMetLabel}", + "mtOverPt": "#it{m}_{T} / #it{p}_{T}^{#mu}", + "altMt": f"{metLabel} (1 - {dphiMuMetLabel})", + "dxybs": "Thr - |dxy_{bs}^{#mu}| (cm)", + } + xABCD = args.xABCD + noMtABCD = xABCD != "mt" xAxisName = args.xAxisName - if args.absEta and "|#eta|" not in xAxisName and "#eta" in xAxisName: - xAxisName.replace("#eta", "|#eta|") + if args.absEta and "|#eta" not in xAxisName and "#eta" in xAxisName: + xAxisName = etaLabel yAxisName = args.yAxisName - zAxisName = args.met + " " + args.zAxisName + zAxisName = args.zAxisName if len(args.zAxisName) else zAxisNames[xABCD] adjustSettings_CMS_lumi() canvas = ROOT.TCanvas("canvas", "", 800, 800) @@ -702,7 +767,7 @@ def runStudy(fname, charges, mainOutputFolder, args): datasetsNoFakes = list(filter(lambda x: x != "Fake", datasets)) datasetsNoQCDFakes = list(filter(lambda x: x not in ["QCD", "Fake"], datasets)) logger.info(f"All original datasets available {datasets}") - inputHistName = "mTStudyForFakes" + inputHistName = inputHistDict[xABCD] groups.setNominalName(inputHistName) groups.loadHistsForDatagroups( inputHistName, syst="", procsToRead=datasets, applySelection=False @@ -723,7 +788,7 @@ def runStudy(fname, charges, mainOutputFolder, args): d: None for d in datasets } # for 1D plots, mt rebinned by 2 but no eta-pt rebinning rootHists_asNominal = {d: None for d in datasets} - rootHists_forMtWithDataDrivenFakes = {d: None for d in datasetsNoQCD} + rootHists_forMtWithDataDrivenFakes = {d: None for d in datasets} hnarf_fakerateDeltaPhi = None for d in datasets: s = hist.tag.Slicer() @@ -739,7 +804,11 @@ def runStudy(fname, charges, mainOutputFolder, args): hnarfTMP = hnarfTMP[ {"absdz_cm": s[:: hist.sum]} ] # FIXME: JUST A TEST !!! - # hnarfTMP = hnarfTMP[{"absdz_cm": s[complex(0,0.1)::hist.sum]}] # FIXME: JUST A TEST !!! + if noMtABCD and "passMT" in hnarfTMP.axes.name: + # integrate all mT (unless required differently, + # but to use dphi should not cut on mT) + hnarfTMP = hnarfTMP[{"passMT": s[:: hist.sum]}] + # hnarfTMP = hnarfTMP[{"passMT": False}] hnarf = hnarfTMP.copy() hnarf_forplots = hnarf.copy() hnarf_asNominal = hnarf.copy() @@ -782,142 +851,151 @@ def runStudy(fname, charges, mainOutputFolder, args): hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ {"hasJets": s[:: hist.sum]} ] - lowMtUpperBound = int(args.mtNominalRange.split(",")[1]) + lowMtUpperBound = float(args.mtNominalRange.split(",")[1]) hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ - {"mt": s[: complex(0, lowMtUpperBound) : hist.sum]} + {xABCD: s[: complex(0, lowMtUpperBound) : hist.sum]} ] chargeIndex = 0 if charge in ["minus", "inclusive"] else 1 hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ {"charge": s[chargeIndex : chargeIndex + 1 : hist.sum]} ] - hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ - {"DphiMuonMet": s[:: hist.rebin(2)]} - ] - # make all TH of FRF in bins of dphi - histo_fakes_dphiBins = narf.hist_to_root( - hnarf_fakerateDeltaPhi - ) # this is a THnD with eta-pt-passIso-DphiMuonMet - histo_FRFvsDphi = {} - nBinsDphi = histo_fakes_dphiBins.GetAxis(3).GetNbins() - for idp in range(nBinsDphi): - idpBin = idp + 1 - histo_fakes_dphiBins.GetAxis(3).SetRange(idpBin, idpBin) + if "DphiMuonMet" in hnarf_fakerateDeltaPhi.axes.name: + hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ + {"DphiMuonMet": s[:: hist.rebin(2)]} + ] + if not noMtABCD: + # make all TH of FRF in bins of dphi + histo_fakes_dphiBins = narf.hist_to_root( + hnarf_fakerateDeltaPhi + ) # this is a THnD with eta-pt-passIso-DphiMuonMet + histo_FRFvsDphi = {} + nBinsDphi = histo_fakes_dphiBins.GetAxis(3).GetNbins() + for idp in range(nBinsDphi): + idpBin = idp + 1 + histo_fakes_dphiBins.GetAxis(3).SetRange(idpBin, idpBin) + histo_fakes_dphiBins.GetAxis(2).SetRange(1, 1) + histo_fakes_dphiBins_failIso = histo_fakes_dphiBins.Projection( + 1, 0, "E" + ) + histo_fakes_dphiBins_failIso.SetName( + f"histo_fakes_dphiBins_failIso_idp{idp}" + ) + histo_fakes_dphiBins.GetAxis(3).SetRange(idpBin, idpBin) + histo_fakes_dphiBins.GetAxis(2).SetRange(2, 2) + histo_fakes_dphiBins_passIso = histo_fakes_dphiBins.Projection( + 1, 0, "E" + ) + histo_fakes_dphiBins_passIso.SetName( + f"histo_fakes_dphiBins_passIso_idp{idp}" + ) + histo_FRFvsDphi[idp] = copy.deepcopy( + histo_fakes_dphiBins_passIso.Clone( + f"histo_FRFvsDphi_idp{idp}" + ) + ) + histo_FRFvsDphi[idp].Divide(histo_fakes_dphiBins_failIso) + ## + histo_fakes_dphiBins.GetAxis(3).SetRange(1, nBinsDphi) histo_fakes_dphiBins.GetAxis(2).SetRange(1, 1) histo_fakes_dphiBins_failIso = histo_fakes_dphiBins.Projection( 1, 0, "E" ) histo_fakes_dphiBins_failIso.SetName( - f"histo_fakes_dphiBins_failIso_idp{idp}" + "histo_fakes_dphiBins_failIso_idpInclusive" ) - histo_fakes_dphiBins.GetAxis(3).SetRange(idpBin, idpBin) + histo_fakes_dphiBins.GetAxis(3).SetRange(1, nBinsDphi) histo_fakes_dphiBins.GetAxis(2).SetRange(2, 2) histo_fakes_dphiBins_passIso = histo_fakes_dphiBins.Projection( 1, 0, "E" ) histo_fakes_dphiBins_passIso.SetName( - f"histo_fakes_dphiBins_passIso_idp{idp}" - ) - histo_FRFvsDphi[idp] = copy.deepcopy( - histo_fakes_dphiBins_passIso.Clone(f"histo_FRFvsDphi_idp{idp}") + "histo_fakes_dphiBins_passIso_idpInclusive" ) - histo_FRFvsDphi[idp].Divide(histo_fakes_dphiBins_failIso) - ## - histo_fakes_dphiBins.GetAxis(3).SetRange(1, nBinsDphi) - histo_fakes_dphiBins.GetAxis(2).SetRange(1, 1) - histo_fakes_dphiBins_failIso = histo_fakes_dphiBins.Projection( - 1, 0, "E" - ) - histo_fakes_dphiBins_failIso.SetName( - "histo_fakes_dphiBins_failIso_idpInclusive" - ) - histo_fakes_dphiBins.GetAxis(3).SetRange(1, nBinsDphi) - histo_fakes_dphiBins.GetAxis(2).SetRange(2, 2) - histo_fakes_dphiBins_passIso = histo_fakes_dphiBins.Projection( - 1, 0, "E" - ) - histo_fakes_dphiBins_passIso.SetName( - "histo_fakes_dphiBins_passIso_idpInclusive" - ) - histo_FRFvsDphi["inclusive"] = copy.deepcopy( - histo_fakes_dphiBins_passIso.Clone("histo_FRFvsDphi_idpInclusive") - ) - histo_FRFvsDphi["inclusive"].Divide(histo_fakes_dphiBins_failIso) - ## - # now should plot - hists = [ - unroll2Dto1D( - histo_FRFvsDphi["inclusive"], - newname=f"unrolled_{histo_FRFvsDphi['inclusive'].GetName()}", - cropNegativeBins=False, + histo_FRFvsDphi["inclusive"] = copy.deepcopy( + histo_fakes_dphiBins_passIso.Clone( + "histo_FRFvsDphi_idpInclusive" + ) ) - ] - for idp in range(nBinsDphi): - hists.append( + histo_FRFvsDphi["inclusive"].Divide(histo_fakes_dphiBins_failIso) + ## + # now should plot + hists = [ unroll2Dto1D( - histo_FRFvsDphi[idp], - newname=f"unrolled_{histo_FRFvsDphi[idp].GetName()}", + histo_FRFvsDphi["inclusive"], + newname=f"unrolled_{histo_FRFvsDphi['inclusive'].GetName()}", cropNegativeBins=False, ) - ) + ] + for idp in range(nBinsDphi): + hists.append( + unroll2Dto1D( + histo_FRFvsDphi[idp], + newname=f"unrolled_{histo_FRFvsDphi[idp].GetName()}", + cropNegativeBins=False, + ) + ) - legEntries = ["inclusive"] + [ - f"#Delta#phi bin {idp}" for idp in range(nBinsDphi) - ] - ptBinRanges = [] - for ipt in range(histo_FRFvsDphi["inclusive"].GetNbinsY()): - ptBinRanges.append( - "[{ptmin},{ptmax}] GeV".format( - ptmin=int( - histo_FRFvsDphi["inclusive"] - .GetYaxis() - .GetBinLowEdge(ipt + 1) - ), - ptmax=int( - histo_FRFvsDphi["inclusive"] - .GetYaxis() - .GetBinLowEdge(ipt + 2) - ), + legEntries = ["inclusive"] + [ + f"#Delta#phi bin {idp}" for idp in range(nBinsDphi) + ] + ptBinRanges = [] + for ipt in range(histo_FRFvsDphi["inclusive"].GetNbinsY()): + ptBinRanges.append( + "[{ptmin},{ptmax}] GeV".format( + ptmin=int( + histo_FRFvsDphi["inclusive"] + .GetYaxis() + .GetBinLowEdge(ipt + 1) + ), + ptmax=int( + histo_FRFvsDphi["inclusive"] + .GetYaxis() + .GetBinLowEdge(ipt + 2) + ), + ) ) + drawNTH1( + hists, + legEntries, + "Unrolled (%s, %s) bin" % (etaLabel, ptLabel), + "Fakerate factor", + f"FRFvsDeltaPhi_{charge}", + outfolder, + leftMargin=0.06, + rightMargin=0.01, + labelRatioTmp="BinX/inclusive::0.7,1.3", + legendCoords="0.06,0.99,0.91,0.99;6", + lowerPanelHeight=0.5, + skipLumi=True, + passCanvas=canvas_unroll, + drawVertLines="{a},{b}".format( + a=histo_FRFvsDphi["inclusive"].GetNbinsY(), + b=histo_FRFvsDphi["inclusive"].GetNbinsX(), + ), + textForLines=ptBinRanges, + transparentLegend=False, + drawErrorAll=True, + onlyLineColor=True, + noErrorRatioDen=False, + useLineFirstHistogram=True, + setOnlyLineRatio=True, + lineWidth=1, ) - drawNTH1( - hists, - legEntries, - "Unrolled " + etaLabel + "-p_{{T}} bin", - "Fakerate factor", - f"FRFvsDeltaPhi_{charge}", - outfolder, - leftMargin=0.06, - rightMargin=0.01, - labelRatioTmp="BinX/inclusive::0.7,1.3", - legendCoords="0.06,0.99,0.91,0.99;6", - lowerPanelHeight=0.5, - skipLumi=True, - passCanvas=canvas_unroll, - drawVertLines="{a},{b}".format( - a=histo_FRFvsDphi["inclusive"].GetNbinsY(), - b=histo_FRFvsDphi["inclusive"].GetNbinsX(), - ), - textForLines=ptBinRanges, - transparentLegend=False, - drawErrorAll=True, - onlyLineColor=True, - noErrorRatioDen=False, - useLineFirstHistogram=True, - setOnlyLineRatio=True, - lineWidth=1, - ) ## dphiMuonMetCut = args.dphiMuonMetCut * np.pi - hnarf = hnarf[ - {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :: hist.sum]} - ] # test dphi cut + if "DphiMuonMet" in hnarf.axes.name: + hnarf = hnarf[ + {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :: hist.sum]} + ] # test dphi cut rootHists[d] = narf.hist_to_root( hnarf ) # this is a THnD with eta-pt-charge-mt-passIso-hasJets-DphiMuonMet - hnarf_forplots = hnarf_forplots[ - {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :]} - ] # cut but do not integrate - hnarf_forplots = hnarf_forplots[{"mt": s[:: hist.rebin(2)]}] + if "DphiMuonMet" in hnarf_forplots.axes.name: + hnarf_forplots = hnarf_forplots[ + {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :]} + ] # cut but do not integrate + if xABCD == "mt": + hnarf_forplots = hnarf_forplots[{xABCD: s[:: hist.rebin(2)]}] rootHists_forplots[d] = narf.hist_to_root( hnarf_forplots ) # this is a THnD with eta-pt-charge-mt-passIso-hasJets-DphiMuonMet @@ -925,9 +1003,10 @@ def runStudy(fname, charges, mainOutputFolder, args): # integrate njet and Dphi in appropriate range if "hasJets" in hnarf_asNominal.axes.name: hnarf_asNominal = hnarf_asNominal[{"hasJets": s[:: hist.sum]}] - hnarf_asNominal = hnarf_asNominal[ - {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :: hist.sum]} - ] + if "DphiMuonMet" in hnarf_asNominal.axes.name: + hnarf_asNominal = hnarf_asNominal[ + {"DphiMuonMet": s[complex(0, 0.01 + dphiMuonMetCut) :: hist.sum]} + ] hnarf_forMtWithDataDrivenFakes = hnarf_asNominal.copy() mtThreshold = float(args.mtNominalRange.split(",")[-1]) # now select signal region @@ -936,30 +1015,30 @@ def runStudy(fname, charges, mainOutputFolder, args): hnarf_asNominal = sel.fakeHistABCD( hnarf_asNominal, thresholdMT=mtThreshold, - axis_name_mt="mt", + axis_name_mt=xABCD, integrateLowMT=True, integrateHighMT=True, ) hnarf_forMtWithDataDrivenFakes = sel.fakeHistABCD( hnarf_forMtWithDataDrivenFakes, thresholdMT=mtThreshold, - axis_name_mt="mt", + axis_name_mt=xABCD, integrateLowMT=True, integrateHighMT=False, ) else: - nMtBins = hnarf_asNominal.axes["mt"].size + nMtBins = hnarf_asNominal.axes[xABCD].size # just select signal region: pass isolation and mT > mtThreshold with overflow included hnarf_asNominal = hnarf_asNominal[ { "passIso": True, - "mt": s[complex(0, mtThreshold) :: hist.sum], + xABCD: s[complex(0, mtThreshold) :: hist.sum], } ] hnarf_forMtWithDataDrivenFakes = hnarf_forMtWithDataDrivenFakes[ { "passIso": True, - "mt": s[complex(0, mtThreshold) : nMtBins], + xABCD: s[complex(0, mtThreshold) : nMtBins], } ] rootHists_asNominal[d] = narf.hist_to_root(hnarf_asNominal) @@ -972,7 +1051,7 @@ def runStudy(fname, charges, mainOutputFolder, args): "charge": 0 if charge in ["minus", "inclusive"] else 1, } ] - if d in datasetsNoQCD: + if d in datasets: rootHists_forMtWithDataDrivenFakes[d] = narf.hist_to_root( hnarf_forMtWithDataDrivenFakes ) @@ -1002,17 +1081,20 @@ def runStudy(fname, charges, mainOutputFolder, args): axisVar = { 0: ["muon_eta", etaLabel], - 1: ["muon_pt", "p_{T} (GeV)"], - 3: ["mT", args.met + " m_{T} (GeV)"], - 6: ["deltaPhiMuonMET", "#Delta#phi(#mu,MET) (GeV)"], + 1: ["muon_pt", ptLabel + " (GeV)"], } + if noMtABCD: + axisVar[3] = [xABCD, zAxisName] + else: + axisVar[3] = ["mT", args.met + f" {mtLabel} (GeV)"] + axisVar[6] = ["deltaPhiMuonMET", dphiMuMetLabel] # bin number from root histogram chargeBin = 1 if charge in ["minus", "inclusive"] else 2 # plot mT with data-driven fakes, as a test (should add the mT correction in fact) hmcMt = {} - for d in datasetsNoQCD: + for d in datasets: if d == "Data": continue hmcMt[d] = rootHists_forMtWithDataDrivenFakes[d] @@ -1020,128 +1102,164 @@ def runStudy(fname, charges, mainOutputFolder, args): if "Data" in rootHists_forMtWithDataDrivenFakes.keys(): hdataMt = rootHists_forMtWithDataDrivenFakes["Data"] + plotName = xABCD + "_passIso_jetInclusive_passCut" plotDistribution1D( hdataMt, hmcMt, - datasetsNoQCD, - outfolder_dataMC, - canvas1Dshapes=canvas1Dshapes, - xAxisName=f"{args.met} m_{{T}} (GeV)", - plotName=f"mT_passIso_jetInclusive_passMT_dataDrivenFakes", - ) - - # plot mT, eta, pt in some regions iso-nJet regions, for checks - # don't plot fakes here - for xbin in axisVar.keys(): - if "Data" not in rootHists_forplots.keys(): - continue - # Dphi in 4 mT bins, for jet inclusive and pass/fail iso - if xbin == 6: - mtRanges = [0, 20, 40, 60, -1] - for imt in range(len(mtRanges) - 1): - mtLow = str(mtRanges[imt]) - mtHigh = "inf" if mtRanges[imt + 1] < 0 else str(mtRanges[imt + 1]) - mtTitle = f"mT{mtLow}to{mtHigh}" - mtRange = [mtRanges[imt], mtRanges[imt + 1]] - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, - outfolder_dataMC, - canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_failIso_jetInclusive_{mtTitle}", - isoAxisRange=[1, 1], - jetAxisRange=[1, 2], - mTvalueRange=mtRange, - scaleQCDMC=args.scaleQCDMC, - ) - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, - outfolder_dataMC, - canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive_{mtTitle}", - isoAxisRange=[2, 2], - jetAxisRange=[1, 2], - mTvalueRange=mtRange, - scaleQCDMC=args.scaleQCDMC, - ) - continue # no need for the rest of the plots for this variable - ###### - - plotProjection1D( - rootHists_forplots, datasetsNoFakes, outfolder_dataMC, canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_passIso_1orMoreJet", - isoAxisRange=[2, 2], - jetAxisRange=[2, 2], - scaleQCDMC=args.scaleQCDMC, + xAxisName=zAxisName, + plotName=plotName, + scaleProcs={"QCD": args.scaleQCDMC} if args.scaleQCDMC else {}, ) - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, - outfolder_dataMC, - canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive", - isoAxisRange=[2, 2], - jetAxisRange=[1, 2], - scaleQCDMC=args.scaleQCDMC, - ) - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, - outfolder_dataMC, - canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_failIso_1orMoreJet", - isoAxisRange=[1, 1], - jetAxisRange=[2, 2], - scaleQCDMC=args.scaleQCDMC, - ) - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, + plotDistribution1D( + hdataMt, + hmcMt, + datasetsNoQCD, outfolder_dataMC, canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_failIso_jetInclusive", - isoAxisRange=[1, 1], - jetAxisRange=[1, 2], - scaleQCDMC=args.scaleQCDMC, + xAxisName=zAxisName, + plotName=f"{plotName}_dataDrivenFakes", ) - # signal region adding mT cut too - plotProjection1D( - rootHists_forplots, - datasetsNoFakes, + # hmcMt_noFakes = {d: v for d,v in hmcMt.items() if d != "Fake"} + plotDistribution1D( + hdataMt, + hmcMt, # hmcMt_noFakes, + datasetsNoQCDFakes, outfolder_dataMC, canvas1Dshapes=canvas1Dshapes, - chargeBin=chargeBin, - projectAxisToKeep=xbin, - xAxisName=axisVar[xbin][1], - plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive_passMt", - isoAxisRange=[2, 2], - jetAxisRange=[1, 2], - mTvalueRange=[40, -1], - scaleQCDMC=args.scaleQCDMC, + xAxisName=zAxisName, + plotName=f"{plotName}_noFakes", ) + # plot mT, eta, pt in some regions iso-nJet regions, for checks + # don't plot fakes here + for xbin in axisVar.keys(): + if "Data" not in rootHists_forplots.keys(): + continue + if noMtABCD: + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive", + isoAxisRange=[2, 2], + jetAxisRange=None, + scaleQCDMC=args.scaleQCDMC, + noMtABCD=noMtABCD, + ) + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_failIso_jetInclusive", + isoAxisRange=[1, 1], + jetAxisRange=None, + scaleQCDMC=args.scaleQCDMC, + noMtABCD=noMtABCD, + ) + else: + # Dphi in 4 mT bins, for jet inclusive and pass/fail iso + if xbin == 6: + mtRanges = [0, 20, 40, 60, -1] + for imt in range(len(mtRanges) - 1): + mtLow = str(mtRanges[imt]) + mtHigh = ( + "inf" if mtRanges[imt + 1] < 0 else str(mtRanges[imt + 1]) + ) + mtTitle = f"mT{mtLow}to{mtHigh}" + mtRange = [mtRanges[imt], mtRanges[imt + 1]] + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_failIso_jetInclusive_{mtTitle}", + isoAxisRange=[1, 1], + jetAxisRange=[1, 2], + mTvalueRange=mtRange, + scaleQCDMC=args.scaleQCDMC, + ) + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive_{mtTitle}", + isoAxisRange=[2, 2], + jetAxisRange=[1, 2], + mTvalueRange=mtRange, + scaleQCDMC=args.scaleQCDMC, + ) + continue # no need for the rest of the plots for this variable + ###### + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_passIso_1orMoreJet", + isoAxisRange=[2, 2], + jetAxisRange=[2, 2], + scaleQCDMC=args.scaleQCDMC, + ) + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_failIso_1orMoreJet", + isoAxisRange=[1, 1], + jetAxisRange=[2, 2], + scaleQCDMC=args.scaleQCDMC, + ) + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_passIso_jetInclusive", + isoAxisRange=[2, 2], + jetAxisRange=[1, 2], + scaleQCDMC=args.scaleQCDMC, + ) + plotProjection1D( + rootHists_forplots, + datasetsNoFakes, + outfolder_dataMC, + canvas1Dshapes=canvas1Dshapes, + chargeBin=chargeBin, + projectAxisToKeep=xbin, + xAxisName=axisVar[xbin][1], + plotName=f"{axisVar[xbin][0]}_failIso_jetInclusive", + isoAxisRange=[1, 1], + jetAxisRange=[1, 2], + scaleQCDMC=args.scaleQCDMC, + ) ################################### ################################### ### Now the actual study on fakes @@ -1155,14 +1273,16 @@ def runStudy(fname, charges, mainOutputFolder, args): # set charge from charge axis histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) + if not noMtABCD: + histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) # now get a TH3 histoPassIso = histo_fakes.Projection(0, 1, 3, "E") histoPassIso.SetName("fakes_passIso") histoPassIso.SetTitle("fakes_passIso") histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(4).SetRange(1, 1) # FailIso - histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) + if not noMtABCD: + histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) histoFailIso = histo_fakes.Projection(0, 1, 3, "E") histoFailIso.SetName("fakes_failIso") histoFailIso.SetTitle("fakes_failIso") @@ -1172,11 +1292,12 @@ def runStudy(fname, charges, mainOutputFolder, args): mtThreshold = float(args.mtNominalRange.split(",")[-1]) histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(3).SetRange( - histo_fakes.GetAxis(3).FindFixBin(mtThreshold + 0.001), + histo_fakes.GetAxis(3).FindFixBin(mtThreshold + 0.0005), histo_fakes.GetAxis(3).GetNbins(), ) # high mT histo_fakes.GetAxis(4).SetRange(1, 1) # FailIso - histo_fakes.GetAxis(5).SetRange(1, 2) # jet inclusive + if not noMtABCD: + histo_fakes.GetAxis(5).SetRange(1, 2) # jet inclusive histoPassMtFailIso = histo_fakes.Projection(0, 1, 3, "E") histoPassMtFailIso.SetName("fakes_passMt_failIso_jetInclusive") histoPassMtFailIso.SetTitle("fakes_passMt_failIso_jetInclusive") @@ -1190,10 +1311,11 @@ def runStudy(fname, charges, mainOutputFolder, args): # also integrate mt < mtThreshold histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(3).SetRange( - 1, histo_fakes.GetAxis(3).FindFixBin(mtThreshold - 0.001) + 1, histo_fakes.GetAxis(3).FindFixBin(mtThreshold - 0.0005) ) histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - histo_fakes.GetAxis(5).SetRange(1, 2) # always integrate jet here + if not noMtABCD: + histo_fakes.GetAxis(5).SetRange(1, 2) # always integrate jet here # now get a TH2 for passIso histoPassIsoLowMt_jetInclusive_vsEtaPt = histo_fakes.Projection(1, 0, "E") histoPassIsoLowMt_jetInclusive_vsEtaPt.SetName( @@ -1228,7 +1350,8 @@ def runStudy(fname, charges, mainOutputFolder, args): ## now redo the same for the >=1 jet region ## could be done from previous TH3 histograms integrating in mT, but they don't always have the same jet cut histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - histo_fakes.GetAxis(5).SetRange(2, 2) # always integrate jet here + if not noMtABCD: + histo_fakes.GetAxis(5).SetRange(2, 2) # always integrate jet here # now get a TH2 for passIso histoPassIsoLowMt_1orMoreJet_vsEtaPt = histo_fakes.Projection(1, 0, "E") histoPassIsoLowMt_1orMoreJet_vsEtaPt.SetName( @@ -1321,7 +1444,11 @@ def runStudy(fname, charges, mainOutputFolder, args): # histoFailIso.Rebin3D(args.rebinEta, args.rebinPt, 1) # histoPassMtFailIso.Rebin3D(args.rebinEta, args.rebinPt, 1) - mtEdges = [round(int(x), 1) for x in args.mtBinEdges.split(",")] + mtEdges = ( + [round(float(x), 3) for x in args.mtBinEdges.strip().split(",")] + if noMtABCD + else [round(int(x), 1) for x in args.mtBinEdges.split(",")] + ) nMtBins = len(mtEdges) - 1 ratio = [] for imt in range(nMtBins): @@ -1345,10 +1472,10 @@ def runStudy(fname, charges, mainOutputFolder, args): ) h2PassIso.SetTitle( - "Low Iso: %s m_{T} #in [%d, %d]" % (args.met, lowEdge, highEdge) + "Low Iso: %s #in [%d, %d]" % (zAxisName, lowEdge, highEdge) ) h2FailIso.SetTitle( - "High Iso: %s m_{T} #in [%d, %d]" % (args.met, lowEdge, highEdge) + "High Iso: %s #in [%d, %d]" % (zAxisName, lowEdge, highEdge) ) if not args.skipPlot2D: drawCorrelationPlot( @@ -1383,7 +1510,7 @@ def runStudy(fname, charges, mainOutputFolder, args): ) ratio.append(h2PassIso.Clone(f"fakerateFactor_mt{lowEdge}to{highEdge}")) - ratio[imt].SetTitle("%s m_{T} #in [%d, %d]" % (args.met, lowEdge, highEdge)) + ratio[imt].SetTitle("%s #in [%d, %d]" % (zAxisName, lowEdge, highEdge)) ratio[imt].Divide(h2FailIso) if not args.skipPlot2D: drawCorrelationPlot( @@ -1403,7 +1530,14 @@ def runStudy(fname, charges, mainOutputFolder, args): ) if args.mtNominalRange: - lowEdge, highEdge = map(int, args.mtNominalRange.split(",")) + lowEdge, highEdge = ( + map(float, args.mtNominalRange.split(",")) + if noMtABCD + else map(int, args.mtNominalRange.split(",")) + ) + lowEdgeStr, highEdgeStr = args.mtNominalRange.split(",") + lowEdgeStr = lowEdgeStr.replace(".", "p") + highEdgeStr = highEdgeStr.replace(".", "p") binStart = histoPassIso.GetZaxis().FindFixBin(lowEdge) binEnd = ( histoPassIso.GetZaxis().FindFixBin(highEdge + 0.001) - 1 @@ -1418,13 +1552,13 @@ def runStudy(fname, charges, mainOutputFolder, args): ) h2PassIso = getTH2fromTH3( histoPassIso, - f"pt_eta_nominalmt{lowEdge}to{highEdge}_passIso", + f"pt_eta_nominalmt{lowEdgeStr}to{highEdgeStr}_passIso", binStart, binEnd, ) h2FailIso = getTH2fromTH3( histoFailIso, - f"pt_eta_nominalmt{lowEdge}to{highEdge}_failIso", + f"pt_eta_nominalmt{lowEdgeStr}to{highEdgeStr}_failIso", binStart, binEnd, ) @@ -1432,10 +1566,10 @@ def runStudy(fname, charges, mainOutputFolder, args): cropNegativeContent(h2FailIso) nominalFakerateFactor = h2PassIso.Clone( - f"nominalFakerateFactor_mt{lowEdge}to{highEdge}" + f"nominalFakerateFactor_mt{lowEdgeStr}to{highEdgeStr}" ) nominalFakerateFactor.SetTitle( - "%s m_{T} #in [%d, %d]" % (args.met, lowEdge, highEdge) + "%s #in [%s, %s]" % (zAxisName, lowEdgeStr, highEdgeStr) ) nominalFakerateFactor.Divide(h2FailIso) drawCorrelationPlot( @@ -1456,22 +1590,22 @@ def runStudy(fname, charges, mainOutputFolder, args): # plot also at high mt, including overflow h2PassIso_highMt = getTH2fromTH3( histoPassIso, - f"pt_eta_mt{highEdge}toInf_passIso", + f"pt_eta_mt{highEdgeStr}toInf_passIso", binEnd, 1 + histoPassIso.GetNbinsZ(), ) h2FailIso_highMt = getTH2fromTH3( histoFailIso, - f"pt_eta_mt{highEdge}toInf_failIso", + f"pt_eta_mt{highEdgeStr}toInf_failIso", binEnd, 1 + histoFailIso.GetNbinsZ(), ) cropNegativeContent(h2PassIso_highMt) cropNegativeContent(h2FailIso_highMt) highMtFakerateFactor = h2PassIso_highMt.Clone( - f"highMtFakerateFactor_mt{highEdge}toInf" + f"highMtFakerateFactor_mt{highEdgeStr}toInf" ) - highMtFakerateFactor.SetTitle("%s m_{T} > %d" % (args.met, highEdge)) + highMtFakerateFactor.SetTitle("%s > %s" % (zAxisName, highEdgeStr)) highMtFakerateFactor.Divide(h2FailIso_highMt) drawCorrelationPlot( highMtFakerateFactor, @@ -1514,13 +1648,13 @@ def runStudy(fname, charges, mainOutputFolder, args): drawNTH1( [highMtFRF_unrolled, nomiFRF_unrolled], [highMtFakerateFactor.GetTitle(), nominalFakerateFactor.GetTitle()], - "Unrolled eta-p_{T} bin", + "Unrolled (%s, %s) bin" % (etaLabel, ptLabel), "Fakerate factor", f"FRFnomiAndHighMt_etaPt_{charge}", outfolder, leftMargin=0.06, rightMargin=0.01, - labelRatioTmp="Nomi/highMt", + labelRatioTmp=f"High {zAxisName} / nomi", legendCoords="0.06,0.99,0.91,0.99;2", lowerPanelHeight=0.5, skipLumi=True, @@ -1556,7 +1690,7 @@ def runStudy(fname, charges, mainOutputFolder, args): hFRFcorr = ROOT.TH2D( f"fakerateFactorCorrection_{charge}", - "%s m_{T} > %d GeV" % (args.met, int(args.mtNominalRange.split(",")[1])), + "%s > %s GeV" % (zAxisName, args.mtNominalRange.split(",")[1]), h2PassIso.GetNbinsX(), round(etaLow, 1), round(etaHigh, 1), @@ -1586,7 +1720,7 @@ def runStudy(fname, charges, mainOutputFolder, args): ptBinHigh = int(h2PassIso.GetYaxis().GetBinLowEdge(ipt + 1)) fakerateFactor_vs_etaMt = ROOT.TH2D( "fakerateFactor_vs_etaMt_pt%dto%d" % (ptBinLow, ptBinHigh), - "Muon p_{T} #in [%d, %d] GeV" % (ptBinLow, ptBinHigh), + "%s #in [%d, %d] GeV" % (ptLabel, ptBinLow, ptBinHigh), h2PassIso.GetNbinsX(), round(etaLow, 1), round(etaHigh, 1), @@ -1613,8 +1747,8 @@ def runStudy(fname, charges, mainOutputFolder, args): # logger.info(f"ieta = {ieta} {ptBinLow} < pt < {ptBinHigh} {etaBinLow} < eta < {etaBinHigh} {etaBinLow} < etaNoRound < {etaBinHigh}") hFRfactorVsMt = ROOT.TH1D( f"hFRfactorVsMt_ieta{ieta}_pt{ptBinLow}to{ptBinHigh}", - "%.1f < %s < %.1f, p_{T} #in [%d, %d] GeV" - % (etaBinLow, etaLabel, etaBinHigh, ptBinLow, ptBinHigh), + "%.1f < %s < %.1f, %s #in [%d, %d] GeV" + % (etaBinLow, etaLabel, etaBinHigh, ptLabel, ptBinLow, ptBinHigh), nMtBins, array.array("d", mtEdges), ) @@ -1634,9 +1768,13 @@ def runStudy(fname, charges, mainOutputFolder, args): hTmp[imt - 1].SetBinContent(1, max(0.0, binContent)) hTmp[imt - 1].SetBinError(1, binError) - textLatex = ( - "%.1f < %s < %.1f;%d < p_{T} < %d GeV::0.2,0.88,0.08,0.045" - % (etaBinLow, etaLabel, etaBinHigh, ptBinLow, ptBinHigh) + textLatex = "%.1f < %s < %.1f;%d < %s < %d GeV::0.2,0.88,0.08,0.045" % ( + etaBinLow, + etaLabel, + etaBinHigh, + ptBinLow, + ptLabel, + ptBinHigh, ) if nMtBins > 2: ## get high mt value to evaluate the correction, can use the mean of the mt distribution for each etapt bin @@ -1676,6 +1814,8 @@ def runStudy(fname, charges, mainOutputFolder, args): useBinnedCorr=args.useBinnedCorrection, histoChi2diffTest=histoChi2diffTest, histoPullsPol1Slope=histoPullsPol1Slope, + noMtABCD=noMtABCD, + erfAsMainModel=args.fitErf, ) # logger.info(f"{valFRF}, {valFRFCap}") if valFRF < 0: @@ -1851,7 +1991,7 @@ def runStudy(fname, charges, mainOutputFolder, args): drawNTH1( hList, legEntries, - "Unrolled eta-p_{T} bin", + "Unrolled (%s, %s) bin" % (etaLabel, ptLabel), "FRF correction", f"FRFcorrAndUnc_etaPt_{charge}", outfolder, @@ -1895,7 +2035,7 @@ def runStudy(fname, charges, mainOutputFolder, args): drawNTH1( hListV2, legEntriesV2, - "Unrolled eta-p_{T} bin", + "Unrolled (%s, %s) bin" % (etaLabel, ptLabel), "FRF correction::0.5,1.6", f"FRFcorrAndUnc_etaPt_{charge}_v2", outfolder, @@ -1945,7 +2085,7 @@ def runStudy(fname, charges, mainOutputFolder, args): nominalFakerateFactor.GetTitle(), f"{nominalFakerateFactor.GetTitle()} with FRF corr", ], - "Unrolled eta-p_{T} bin", + "Unrolled (%s, %s) bin" % (etaLabel, ptLabel), "Fakerate factor", f"FRFnomiAndHighMtAndCorr_etaPt_{charge}", outfolder, @@ -2098,7 +2238,8 @@ def runStudy(fname, charges, mainOutputFolder, args): def runStudyVsDphi(fname, charges, mainOutputFolder, args): - etaLabel = "#eta" if not args.absEta else "|#eta|" + etaLabel = "#eta^{#mu}" if not args.absEta else "|#eta^{#mu}|" + ptLabel = "#it{p}_{T}^{#mu}" xAxisName = args.xAxisName yAxisName = args.yAxisName @@ -2167,9 +2308,9 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): logger.warning(f"Histogram has {nPtBins} pt bins") nPtBins = hnarf.axes["pt"].size - lowMtUpperBound = int(args.mtNominalRange.split(",")[1]) - hnarf = hnarf[{"mt": s[: complex(0, lowMtUpperBound) : hist.sum]}] - # hnarf = hnarf[{"mt" : s[::hist.sum]}] + lowMtUpperBound = float(args.mtNominalRange.split(",")[1]) + hnarf = hnarf[{args.xABCD: s[: complex(0, lowMtUpperBound) : hist.sum]}] + # hnarf = hnarf[{args.xABCD : s[::hist.sum]}] chargeIndex = 0 if charge in ["minus", "inclusive"] else 1 hnarf = hnarf[{"charge": s[chargeIndex : chargeIndex + 1 : hist.sum]}] @@ -2251,13 +2392,13 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): for b in etapt_bins: hs.append(hists[b]) etaText = f"{htmp.GetXaxis().GetBinLowEdge(b[0]):.1f} < {etaLabel} < {htmp.GetXaxis().GetBinLowEdge(b[0]+1):.1f}" - ptText = f"{htmp.GetYaxis().GetBinLowEdge(b[1]):.0f} < p_{{T}} < {htmp.GetYaxis().GetBinLowEdge(b[1]+1):.0f}" + ptText = f"{htmp.GetYaxis().GetBinLowEdge(b[1]):.0f} < {ptLabel} < {htmp.GetYaxis().GetBinLowEdge(b[1]+1):.0f}" legEntries.append(f"{etaText} && {ptText} GeV") drawNTH1( hs, legEntries, - "#Delta#phi(#mu,MET)", + "#Delta#phi(#mu, #it{p}_{T}^{miss})", "Fakerate factor", f"FRFvsDeltaPhi_{d}_someBins_ipt{ipt}_{charge}", outfolder, @@ -2285,11 +2426,17 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): parser = common_plot_parser() parser.add_argument("inputfile", type=str, nargs=1) parser.add_argument("outputfolder", type=str, nargs=1) - parser.add_argument("-x", "--xAxisName", default="Muon #eta", help="x axis name") parser.add_argument( - "-y", "--yAxisName", default="Muon p_{T} (GeV)", help="y axis name" + "--xABCD", + default="mt", + choices=["mt", "oneMinusCosdphi", "mtOverPt", "altMt", "dxybs"], + help="X variable to use for ABCD method (y is pass isolation)", + ) + parser.add_argument("-x", "--xAxisName", default="#eta^{#mu}", help="x axis name") + parser.add_argument( + "-y", "--yAxisName", default="#it{p}_{T}^{#mu} (GeV)", help="y axis name" ) - parser.add_argument("-z", "--zAxisName", default="m_{T} (GeV)", help="z axis name") + parser.add_argument("-z", "--zAxisName", default="", help="z axis name") parser.add_argument( "--met", default="DeepMET", @@ -2327,6 +2474,11 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): type=int, help="Degree for polynomial used in the fits", ) + parser.add_argument( + "--fitErf", + action="store_true", + help="Main fit is an (inverse) error function, only if using mT for ABCD", + ) parser.add_argument( "--maxPt", default=50, @@ -2396,9 +2548,6 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): args = parser.parse_args() logger = logging.setup_logger(os.path.basename(__file__), args.verbose) - # if args.absEta: - # logger.error("Option --absolute-eta not implemented correctly yet. Abort") - # quit() if args.charge == "both": charges = ["plus", "minus"] @@ -2407,7 +2556,11 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): ROOT.TH1.SetDefaultSumw2() - subFolder = f"/{args.integralMtMethod}Integral_fit{args.mtFitRange.replace(',','to')}_pol{args.fitPolDegree}" + fitRangeStr = args.mtFitRange.strip() + fitRangeStr = fitRangeStr.replace(",", "to").replace(".", "p").replace("-", "m") + subFolder = ( + f"/{args.integralMtMethod}Integral_fit{fitRangeStr}_pol{args.fitPolDegree}" + ) if args.rebinEta > 1: subFolder += f"_rebinEta{args.rebinEta}" if args.rebinPt > 1: @@ -2424,6 +2577,10 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): subFolder += f"_absEta" if args.postfix: subFolder += f"_{args.postfix}" + if args.xABCD != "mt": + subFolder += f"_{args.xABCD}" + if args.fitErf: + subFolder += f"_fitErf" subFolder += "/" outdir_original = args.outputfolder[0] + subFolder diff --git a/scripts/analysisTools/tests/testPlots1D.py b/scripts/analysisTools/tests/testPlots1D.py index 299aed71a..da80d0c1f 100644 --- a/scripts/analysisTools/tests/testPlots1D.py +++ b/scripts/analysisTools/tests/testPlots1D.py @@ -47,6 +47,7 @@ def plotDistribution1D( ratioPadYaxisTitle="Data/pred::0.9,1.1", scaleToUnitArea=False, noRatioPanel=False, + scaleProcs={}, ): createPlotDirAndCopyPhp(outfolder_dataMC) @@ -71,13 +72,17 @@ def plotDistribution1D( hmc[d].SetLineColor(ROOT.kBlack) hmc[d].SetMarkerSize(0) hmc[d].SetMarkerStyle(0) + if d in scaleProcs.keys(): + hmc[d].Scale(scaleProcs[d]) stackIntegral += hmc[d].Integral() if scaleToUnitArea: hdata.Scale(1.0 / hdata.Integral()) stack_1D = ROOT.THStack("stack_1D", "signal and backgrounds") - hmcSortedKeys = sorted(hmc.keys(), key=lambda x: hmc[x].Integral()) + hmcSortedKeys = sorted( + [x for x in hmc.keys() if x in datasets], key=lambda x: hmc[x].Integral() + ) for i in hmcSortedKeys: if scaleToUnitArea: hmc[i].Scale(1.0 / stackIntegral) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 7d9761de9..6de2a6c84 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -133,6 +133,11 @@ action="store_true", help="Add another fit axis with the sign of the uT recoil projection", ) +parser.add_argument( + "--addAxisMt", + action="store_true", + help="Add another fit axis with mT", +) parser.add_argument( "--utAngleCosineCut", nargs=2, @@ -279,6 +284,12 @@ overflow=True, ) axis_met = hist.axis.Regular(25, 0.0, 100.0, name="met", underflow=False, overflow=True) +axis_mt_testfit = hist.axis.Variable( + (*np.arange(0, mtw_min + 20, 20), *np.arange(mtw_min + 2, 122, 2)), + name="mt", + underflow=False, + overflow=True, +) # for mt, met, ptW plots, to compute the fakes properly (but FR pretty stable vs pt and also vs eta) # may not exactly reproduce the same pt range as analysis, though @@ -334,6 +345,24 @@ nominal_axes = [axis_eta, axis_pt, axis_charge, axis_ut_analysis, *axes_abcd] nominal_cols = columns_fakerate +elif args.addAxisMt: + axes_fakerate = [ + axis_fakes_eta, + axis_fakes_pt, + axis_charge, + axis_mt_testfit, + axis_isoCat, + ] + columns_fakerate = [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "transverseMass", + "goodMuons_relIso0", + ] + + nominal_axes = [axis_eta, axis_pt, axis_charge, axis_mt_testfit, axis_isoCat] + nominal_cols = columns_fakerate else: axes_fakerate = [axis_fakes_eta, axis_fakes_pt, axis_charge, *axes_abcd] columns_fakerate = [ @@ -431,6 +460,27 @@ axis_dphi_fakes = hist.axis.Regular( 8, 0.0, np.pi, name="DphiMuonMet", underflow=False, overflow=False ) +# filled with 1 - cos, as in mT and such that W peaks at +2 +axis_oneMinusCosdphi = hist.axis.Regular( + 20, 0.0, 2.0, name="oneMinusCosdphi", underflow=False, overflow=False +) +axis_metOverPt = hist.axis.Regular( + 40, 0.0, 2.0, name="metOverPt", underflow=False, overflow=True +) +axis_mtOverPt = hist.axis.Regular( + 80, 0.0, 4.0, name="mtOverPt", underflow=False, overflow=True +) +axis_altMt = hist.axis.Regular( + 120, 0.0, 120.0, name="altMt", underflow=False, overflow=True +) +axis_dxybs = hist.axis.Regular( + int(args.dxybs / 0.002), + 0.0, + args.dxybs, + name="dxybs", + underflow=False, + overflow=True, +) axis_hasjet_fakes = hist.axis.Boolean( name="hasJets" ) # only need case with 0 jets or > 0 for now @@ -443,6 +493,38 @@ axis_hasjet_fakes, axis_dphi_fakes, ] +mTStudyForFakesAlt_axes = [ + axis_eta, + axis_pt, + axis_charge, + axis_oneMinusCosdphi, + axis_passIso, + axis_passMT, +] +mTStudyForFakesAlt2_axes = [ + axis_eta, + axis_pt, + axis_charge, + axis_mtOverPt, + axis_passIso, + axis_passMT, +] +mTStudyForFakesAlt3_axes = [ + axis_eta, + axis_pt, + axis_charge, + axis_altMt, + axis_passIso, + axis_passMT, +] +mTStudyForFakesAlt4_axes = [ + axis_eta, + axis_pt, + axis_charge, + axis_dxybs, + axis_passIso, + axis_passMT, +] axis_met = hist.axis.Regular( 100, 0.0, 200.0, name="met", underflow=False, overflow=True @@ -863,6 +945,7 @@ def build_graph(df, dataset): nMuons=1, ptCut=args.vetoRecoPt, etaCut=args.vetoRecoEta, + dxybsCut=args.dxybs, useGlobalOrTrackerVeto=useGlobalOrTrackerVeto, ) df = muon_selections.select_good_muons( @@ -1272,8 +1355,10 @@ def build_graph(df, dataset): df = df.Define("hasCleanJet", "Sum(goodCleanJetsNoPt && Jet_pt > 30) >= 1") df = df.Define( - "deltaPhiMuonMet", "std::abs(wrem::deltaPhi(goodMuons_phi0,MET_corr_rec_phi))" + "goodMuons_dphiMuMet0", + "std::abs(wrem::deltaPhi(goodMuons_phi0,MET_corr_rec_phi))", ) + df = df.Define("passMT", f"transverseMass >= {mtw_min}") if auxiliary_histograms: # would move the following in a function but there are too many dependencies on axes defined in the main loop @@ -1354,7 +1439,7 @@ def build_graph(df, dataset): "passIso", "nJetsClean", "leadjetPt", - "deltaPhiMuonMet", + "goodMuons_dphiMuMet0", "nominal_weight", ], ) @@ -1538,6 +1623,23 @@ def build_graph(df, dataset): # instead of passIso in mTStudyForFakes # df = df.Define("passIsoAlt", "(goodMuons_pfRelIso04_all0 * Muon_pt[goodMuons][0] / goodMuons_jetpt0) < 0.12") # df = df.Define("passIsoAlt", "(Muon_vtxAgnPfRelIso04_chg[goodMuons][0] * Muon_pt[goodMuons][0]) < 5.0") + + df = df.Define( + # fill with 1 - cos so that W signal is at +1 instead of -1, for convenience + "goodMuons_oneMinusCosdphiMuMet0", + "1.0 - std::cos(goodMuons_dphiMuMet0)", + ) + df = df.Define("goodMuons_metOverPt0", "MET_corr_rec_pt/goodMuons_pt0") + df = df.Define("goodMuons_mtOverPt0", "transverseMass/goodMuons_pt0") + df = df.Define( + "goodMuons_altMt0", "MET_corr_rec_pt*goodMuons_oneMinusCosdphiMuMet0" + ) + # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 + # for convenience in the later study + df = df.Define( + "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" + ) + mTStudyForFakes = df.HistoBoost( "mTStudyForFakes", mTStudyForFakes_axes, @@ -1548,21 +1650,79 @@ def build_graph(df, dataset): "transverseMass", "passIso", "hasCleanJet", - "deltaPhiMuonMet", + "goodMuons_dphiMuMet0", "nominal_weight", ], ) results.append(mTStudyForFakes) + mTStudyForFakesAlt = df.HistoBoost( + "mTStudyForFakesAlt", + mTStudyForFakesAlt_axes, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_oneMinusCosdphiMuMet0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakesAlt) + + mTStudyForFakesAlt2 = df.HistoBoost( + "mTStudyForFakesAlt2", + mTStudyForFakesAlt2_axes, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_mtOverPt0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakesAlt2) + + mTStudyForFakesAlt3 = df.HistoBoost( + "mTStudyForFakesAlt3", + mTStudyForFakesAlt3_axes, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_altMt0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakesAlt3) + + mTStudyForFakesAlt4 = df.HistoBoost( + "mTStudyForFakesAlt4", + mTStudyForFakesAlt4_axes, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_dxybs0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakesAlt4) + # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: dphiMuonMetCut = args.dphiMuonMetCut * np.pi df = df.Filter( - f"deltaPhiMuonMet > {dphiMuonMetCut}" + f"goodMuons_dphiMuMet0 > {dphiMuonMetCut}" ) # pi/4 was found to be a good threshold for signal with mT > 40 GeV - df = df.Define("passMT", f"transverseMass >= {mtw_min}") - if auxiliary_histograms: # control plots, lepton, met, to plot them later (need eta-pt to make fakes) @@ -1591,7 +1751,14 @@ def build_graph(df, dataset): df.HistoBoost( "deltaPhiMuonMet", [axis_phi, *axes_fakerate], - ["deltaPhiMuonMet", *columns_fakerate, "nominal_weight"], + ["goodMuons_dphiMuMet0", *columns_fakerate, "nominal_weight"], + ) + ) + results.append( + df.HistoBoost( + "metOverPt", + [axis_metOverPt, *axes_fakerate], + ["goodMuons_metOverPt0", *columns_fakerate, "nominal_weight"], ) ) results.append( diff --git a/scripts/histmakers/mz_wlike_with_mu_eta_pt.py b/scripts/histmakers/mz_wlike_with_mu_eta_pt.py index ee022dfc5..7b7852d4d 100644 --- a/scripts/histmakers/mz_wlike_with_mu_eta_pt.py +++ b/scripts/histmakers/mz_wlike_with_mu_eta_pt.py @@ -227,8 +227,6 @@ [0, 0.15, 0.3, 100], name="relIso", underflow=False, overflow=False ) -nominal_axes = [axis_eta, axis_pt, common.axis_charge] -nominal_cols = ["trigMuons_eta0", "trigMuons_pt0", "trigMuons_charge0"] if args.addIsoMtAxes: nominal_axes.extend([axis_mtCat, axis_isoCat]) nominal_cols.extend(["transverseMass", "trigMuons_relIso0"]) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 990f2112e..66118ba5c 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -71,7 +71,13 @@ "--procFilters", type=str, nargs="*", - help="Filter to plot (default no filter, only specify if you want a subset", + help="Filter to plot (default no filter, only specify if you want a subset)", +) +parser.add_argument( + "--procExcludes", + type=str, + nargs="*", + help="Exclude some processes", ) parser.add_argument("--noData", action="store_true", help="Don't plot data") parser.add_argument("--noFill", action="store_true", help="Don't fill") @@ -266,7 +272,11 @@ def padArray(ref, matchLength): groups = Datagroups( args.infile, filterGroups=args.procFilters, - excludeGroups=None if args.procFilters else ["QCD"], + excludeGroups=( + args.procExcludes + if args.procExcludes + else None if args.procFilters else ["QCD"] + ), ) if not args.fineGroups: diff --git a/utilities/parsing.py b/utilities/parsing.py index 3b2ee11c7..a083e8953 100644 --- a/utilities/parsing.py +++ b/utilities/parsing.py @@ -507,6 +507,12 @@ def __call__(self, parser, namespace, values, option_string=None): type=float, help="Upper threshold for muon absolute eta in the veto definition", ) + parser.add_argument( + "--dxybs", + default=0.05, + type=float, + help="Upper threshold for muon absolute dxy with respect to beamspot", + ) # Options to test splitting of data into subsets parser.add_argument( "--addRunAxis", diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index 2841d38c0..47ab5b0c2 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -146,7 +146,8 @@ def translate_html_to_latex(n): "MET_pt": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, "MET": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, "met": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, - "mt": {"label": r"$\mathit{m}_{T}^{\mu,MET}$", "unit": "GeV"}, + # "mt": {"label": r"$\mathit{m}_{T}^{\mu,MET}$", "unit": "GeV"}, + "mt": {"label": r"$\mathit{m}_{T}^{W}$", "unit": "GeV"}, "mtfix": {"label": r"$\mathit{m}_{T}^\mathrm{fix}$", "unit": "GeV"}, "etaPlus": r"$\mathit{\eta}^{\mu(+)}$", "etaMinus": r"$\mathit{\eta}^{\mu(-)}$", diff --git a/wremnants/include/utils.hpp b/wremnants/include/utils.hpp index 2508a71e2..5be87e91a 100644 --- a/wremnants/include/utils.hpp +++ b/wremnants/include/utils.hpp @@ -365,7 +365,7 @@ float zqtproj0(const float &goodMuons_pt0, const float &goodMuons_eta0, GenPart_eta[postFSRnusIdx[0]], GenPart_phi[postFSRnusIdx[0]], 0.); TVector2 Muon(muon.X(), muon.Y()), Neutrino(neutrino.X(), neutrino.Y()); - return (Muon * ((Muon + Neutrino))) / sqrt(Muon * Muon); + return (Muon * ((Muon + Neutrino))) / std::sqrt(Muon * Muon); } float zqtproj0(float pt, float phi, float ptOther, float phiOther) { diff --git a/wremnants/muon_selections.py b/wremnants/muon_selections.py index ff1ab2758..9951f5bc2 100644 --- a/wremnants/muon_selections.py +++ b/wremnants/muon_selections.py @@ -66,6 +66,7 @@ def select_veto_muons( ptCut=15.0, staPtCut=15.0, etaCut=2.4, + dxybsCut=0.05, useGlobalOrTrackerVeto=False, tightGlobalOrTracker=True, ): @@ -75,7 +76,7 @@ def select_veto_muons( # tightGlobalOrTracker relevant only when useGlobalOrTrackerVeto = True df = df.Define( "vetoMuonsPre", - "Muon_looseId && abs(Muon_dxybs) < 0.05 && Muon_correctedCharge != -99", + f"Muon_looseId && abs(Muon_dxybs) < {dxybsCut} && Muon_correctedCharge != -99", ) df = df.Define( "Muon_isGoodGlobal", From 09c630f87fec99f59256e30ba30bc17384cd5132 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Mon, 10 Nov 2025 17:12:45 +0100 Subject: [PATCH 03/46] Protection on the fakes estimation: fake yield is set to zero for the analysis bins of specific axes (e.g. utAngleSign) which have identically zero yield in the A-Ax-B-Bx regions (cherry picked from commit 773c1d92f16d0919c37e2db4168972106919410b) --- wremnants/datasets/datagroups.py | 3 +- wremnants/histselections.py | 200 +++++++++++++++++++++++++------ 2 files changed, 167 insertions(+), 36 deletions(-) diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index fa9e4edd4..d4b6345bf 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -79,6 +79,7 @@ def __init__(self, infile, mode=None, **kwargs): self.gen_axes = {} self.fit_axes = [] self.fakerate_axes = ["pt", "eta", "charge"] + self.decorrFakeAxis = "utAngleSign" self.setGenAxes() @@ -314,6 +315,7 @@ def set_histselectors( h, global_scalefactor=scale, fakerate_axes=self.fakerate_axes, + decorrFakeAxis=self.decorrFakeAxis, smoothing_mode=smoothing_mode, smoothing_order_fakerate=smoothingOrderFakerate, smoothing_order_spectrum=smoothingOrderSpectrum, @@ -646,7 +648,6 @@ def loadHistsForDatagroups( if self.rebinOp and self.rebinBeforeSelection: logger.debug(f"Apply rebin operation for process {procName}") group.hists[label] = self.rebinOp(group.hists[label]) - if group.histselector is not None: if not applySelection: logger.warning( diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 95de5cf8a..ba4346e13 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -123,6 +123,7 @@ def __init__( name_x=None, name_y=None, fakerate_axes=["eta", "pt", "charge"], + decorrFakeAxis="", smoothing_axis_name="pt", rebin_smoothing_axis="automatic", # can be a list of bin edges, "automatic", or None upper_bound_y=None, # using an upper bound on the abcd y-axis (e.g. isolation) @@ -196,17 +197,17 @@ def __init__( self.set_selections_x() self.set_selections_y() + self.decorrFakeAxis = decorrFakeAxis if fakerate_axes is not None: self.fakerate_axes = fakerate_axes self.fakerate_integration_axes = [ n for n in h.axes.name - if n not in [self.name_x, self.name_y, *fakerate_axes] + if n not in [self.name_x, self.name_y, *fakerate_axes, self.decorrFakeAxis] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" ) - self.smoothing_axis_name = smoothing_axis_name edges = h.axes[smoothing_axis_name].edges if rebin_smoothing_axis == "automatic": @@ -753,9 +754,14 @@ def smoothen( y = np.moveaxis(y, idx_ax_smoothing, -1) w = np.moveaxis(w, idx_ax_smoothing, -1) + logger.debug("Sorted axes for smoothing: " + ", ".join(axes)) + # smoothen regressor.solve(x, y, w) + + logger.debug("Reduce is " + str(reduce)) + if reduce: # add up parameters from smoothing of individual sideband regions if type(self) == FakeSelectorSimpleABCD: @@ -805,6 +811,45 @@ def smoothen( ) return y_smooth_orig, y_smooth_var_orig + + + def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=True): + # get output shape from original hist axes, but as for result histogram + + hOut = ( + h[{self.name_x: self.sel_x if not self.integrate_x else hist.sum}] + if self.name_x in h.axes.name + else h + ) + out = np.zeros( + [a.extent if flow else a.shape for a in hOut.axes if a.name not in [self.name_y, self.decorrFakeAxis]], + dtype=sval.dtype, + ) + # leave the underflow and overflow unchanged if present + out[*sel[:-1]] = sval + if syst_variations: + outvar = np.zeros_like(out) + outvar = outvar[..., None, None] * np.ones( + (*outvar.shape, *svar.shape[-2:]), dtype=outvar.dtype + ) + + logger.debug("Doing syst_variations... something might be wrong here") + logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + + # leave the underflow and overflow unchanged if present + outvar[*sel[:-1], :, :] = svar + + logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + + + else: + # with full smoothing all of the statistical uncertainty is included in the + # explicit variations, so the remaining binned uncertainty is zero + outvar = np.zeros_like(out) + + return out, outvar + + def smoothen_spectrum( self, @@ -823,6 +868,8 @@ def smoothen_spectrum( smoothing_axis = h.axes[self.smoothing_axis_name] nax = sval.ndim + logger.debug("Smoothing spectrum along axis " + self.smoothing_axis_name) + # underflow and overflow are left unchanged along the smoothing axis # so we need to exclude them if they have been otherwise included if flow: @@ -867,6 +914,9 @@ def smoothen_spectrum( sval *= 1.0 / xwidth svar *= 1.0 / xwidth**2 + logger.debug("Sval shape after xwidth scaling: " + str(sval.shape)) + logger.debug("Svar shape after xwidth scaling: " + str(svar.shape)) + goodbin = (sval > 0.0) & (svar > 0.0) if goodbin.size - np.sum(goodbin) > 0: logger.warning( @@ -890,6 +940,9 @@ def smoothen_spectrum( reduce=reduce, ) + logger.debug("Svar shape after smoothing: " + (str(svar.shape) if svar is not None else "None")) + logger.debug("xwidthgt shape: " + str(xwidthtgt.shape)) + sval = np.exp(sval) * xwidthtgt sval = np.where(np.isfinite(sval), sval, 0.0) if syst_variations: @@ -899,30 +952,14 @@ def smoothen_spectrum( svar, sval[..., None, None], ) + - # get output shape from original hist axes, but as for result histogram - hOut = ( - h[{self.name_x: self.sel_x if not self.integrate_x else hist.sum}] - if self.name_x in h.axes.name - else h - ) - out = np.zeros( - [a.extent if flow else a.shape for a in hOut.axes if a.name != self.name_y], - dtype=sval.dtype, - ) - # leave the underflow and overflow unchanged if present - out[*sel[:-1]] = sval - if syst_variations: - outvar = np.zeros_like(out) - outvar = outvar[..., None, None] * np.ones( - (*outvar.shape, *svar.shape[-2:]), dtype=outvar.dtype - ) - # leave the underflow and overflow unchanged if present - outvar[*sel[:-1], :, :] = svar - else: - # with full smoothing all of the statistical uncertainty is included in the - # explicit variations, so the remaining binned uncertainty is zero - outvar = np.zeros_like(out) + logger.debug("Smoothing completed. Getting output tensors.") + + + out, outvar = self.get_smoothed_tensor(h, sel, sval, svar, syst_variations, flow=flow) + + logger.debug("Smoothing completed.") return out, outvar @@ -1044,16 +1081,109 @@ def calculate_fullABCD_smoothed( ..., :-1 ] - return self.smoothen_spectrum( - h, - hNew.axes[self.smoothing_axis_name].edges, - sval, - svar, - syst_variations=syst_variations, - use_spline=use_spline, - reduce=not signal_region, - flow=flow, - ) + logger.debug("X and Y axes: " + self.name_x + ", " + self.name_y) + logger.debug("hNew axes: " + ", ".join(hNew.axes.name)) + logger.debug(f"Sval shape after flattening: {sval.shape}") + logger.debug(f"Svar shape after flattening: {svar.shape}") + + baseOutTensor = np.zeros(sval.shape[:-1]) + baseOutVarTensor = ( + np.zeros(svar.shape[:-1]) # if not syst_variations + #else np.zeros((*svar.shape[:-1], svar.shape[-1], svar.shape[-1])) + ) + + logger.debug(f"baseOutTensor shape: {baseOutTensor.shape}") + logger.debug(f"baseOutVarTensor shape: {baseOutVarTensor.shape}") + + if self.decorrFakeAxis!="" and self.decorrFakeAxis in hNew.axes.name: + decorrFake_idx = [n for n in hNew.axes.name].index(self.decorrFakeAxis) + nbins_decorr = hNew.axes[self.decorrFakeAxis].size + logger.debug( + f"Found decorrelation axis {self.decorrFakeAxis} with {nbins_decorr} bins, applying smoothing independently in each bin." + ) + else: + nbins_decorr = 1 + decorrFake_idx = -1 + + logger.debug(f"Decorrelation axis index: {decorrFake_idx}") + + for i in range(nbins_decorr): + smoothing_slices = [slice(None)]*(sval.ndim) + outTensor_slices = [slice(None)]*(baseOutTensor.ndim) + outVarTensor_slices = [slice(None)]*(baseOutVarTensor.ndim) + if decorrFake_idx >= 0: + smoothing_slices[decorrFake_idx] = i + outTensor_slices[decorrFake_idx] = i + outVarTensor_slices[decorrFake_idx] = i + + sval_sliced = sval[tuple(smoothing_slices)] + svar_sliced = svar[tuple(smoothing_slices)] + + logger.debug(f"Shape of sval_sliced: {sval_sliced.shape}") + logger.debug(f"Shape of svar_sliced: {svar_sliced.shape}") + + logger.debug(f"Starting smoothing for decorrelation bin {i}.") + + goodbin = (sval_sliced > 0.0) & (svar_sliced > 0.0) + if goodbin.size - np.sum(goodbin) > 0: + logger.warning( + f"Found {goodbin.size-np.sum(goodbin)} of {goodbin.size} bins with 0 or negative bin content, those will be set to 0 and a large error" + ) + + logd = np.where(goodbin, np.log(sval_sliced), 0.0) + if np.all(logd[..., :4]==0.0): + logger.debug(f"All ABCD values are zeros! Returning zero as Fake estimate.") + logger.debug(f"Syst variations: {syst_variations}") + sval_sliced = np.zeros_like(sval_sliced[..., 0]) + svar_sliced = np.zeros_like( + svar_sliced[..., 0] if not syst_variations + else svar_sliced[..., 0][..., None, None] + ) + + out, outvar = self.get_smoothed_tensor( + h, (sval_sliced.ndim)*[slice(None)], sval_sliced, svar_sliced, syst_variations=syst_variations, flow=flow + ) + + else: + out, outvar = self.smoothen_spectrum( + h, hNew.axes[self.smoothing_axis_name].edges, sval_sliced, svar_sliced, + syst_variations=syst_variations, use_spline=use_spline, reduce=not signal_region, flow=flow + ) + + if syst_variations and i==0: + logger.debug("Updatng baseOutVarTensor to correctly include syst variations") + logger.debug(f"Current outvar shape: {outvar.shape}") + logger.debug(f"Current baseOutVarTensor shape: {baseOutVarTensor.shape}") + baseOutVarTensor = np.zeros( + (*baseOutVarTensor.shape, *outvar.shape[-2:]), dtype=baseOutVarTensor.dtype + ) + outVarTensor_slices += [slice(None), slice(None)] + + + logger.debug(f"Smoothing completed for decorrelation bin {i}.") + logger.debug(f"Smoothing output shape: {out.shape}") + logger.debug(f"Smoothing output var shape: {outvar.shape}") + logger.debug(f"Smoothing baseOutTensor shape: {baseOutTensor.shape}") + logger.debug(f"Smoothing baseOutVarTensor shape: {baseOutVarTensor.shape}") + + + if syst_variations and outvar.shape[-2:]!=baseOutVarTensor.shape[-2:]: + logger.warning( + f"Shape mismatch in syst variations: existing is {baseOutVarTensor.shape[-2:]}, new is {outvar.shape[-2:]}. Overwriting baseOutVarTensor." + ) + baseOutVarTensor = baseOutVarTensor[..., 0, 0] + baseOutVarTensor = np.broadcast_to(baseOutVarTensor[..., None, None], baseOutVarTensor.shape + outvar.shape[-2:]).copy() + + logger.debug(f"New baseOutVarTensor shape: {baseOutVarTensor.shape}") + + baseOutTensor[tuple(outTensor_slices)] = out + baseOutVarTensor[tuple(outVarTensor_slices)] = outvar + + + out = baseOutTensor + outvar = baseOutVarTensor + + return out, outvar class FakeSelector1DExtendedABCD(FakeSelectorSimpleABCD): From 8c5d50d1b3ade89a9b43a7dcf2dd4e73d28059fa Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Mon, 10 Nov 2025 17:12:45 +0100 Subject: [PATCH 04/46] Protection on the fakes estimation: fake yield is set to zero for the analysis bins of specific axes (e.g. utAngleSign) which have identically zero yield in the A-Ax-B-Bx regions --- wremnants/datasets/datagroups.py | 3 +- wremnants/histselections.py | 200 +++++++++++++++++++++++++------ 2 files changed, 167 insertions(+), 36 deletions(-) diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index fa9e4edd4..d4b6345bf 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -79,6 +79,7 @@ def __init__(self, infile, mode=None, **kwargs): self.gen_axes = {} self.fit_axes = [] self.fakerate_axes = ["pt", "eta", "charge"] + self.decorrFakeAxis = "utAngleSign" self.setGenAxes() @@ -314,6 +315,7 @@ def set_histselectors( h, global_scalefactor=scale, fakerate_axes=self.fakerate_axes, + decorrFakeAxis=self.decorrFakeAxis, smoothing_mode=smoothing_mode, smoothing_order_fakerate=smoothingOrderFakerate, smoothing_order_spectrum=smoothingOrderSpectrum, @@ -646,7 +648,6 @@ def loadHistsForDatagroups( if self.rebinOp and self.rebinBeforeSelection: logger.debug(f"Apply rebin operation for process {procName}") group.hists[label] = self.rebinOp(group.hists[label]) - if group.histselector is not None: if not applySelection: logger.warning( diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 95de5cf8a..ba4346e13 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -123,6 +123,7 @@ def __init__( name_x=None, name_y=None, fakerate_axes=["eta", "pt", "charge"], + decorrFakeAxis="", smoothing_axis_name="pt", rebin_smoothing_axis="automatic", # can be a list of bin edges, "automatic", or None upper_bound_y=None, # using an upper bound on the abcd y-axis (e.g. isolation) @@ -196,17 +197,17 @@ def __init__( self.set_selections_x() self.set_selections_y() + self.decorrFakeAxis = decorrFakeAxis if fakerate_axes is not None: self.fakerate_axes = fakerate_axes self.fakerate_integration_axes = [ n for n in h.axes.name - if n not in [self.name_x, self.name_y, *fakerate_axes] + if n not in [self.name_x, self.name_y, *fakerate_axes, self.decorrFakeAxis] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" ) - self.smoothing_axis_name = smoothing_axis_name edges = h.axes[smoothing_axis_name].edges if rebin_smoothing_axis == "automatic": @@ -753,9 +754,14 @@ def smoothen( y = np.moveaxis(y, idx_ax_smoothing, -1) w = np.moveaxis(w, idx_ax_smoothing, -1) + logger.debug("Sorted axes for smoothing: " + ", ".join(axes)) + # smoothen regressor.solve(x, y, w) + + logger.debug("Reduce is " + str(reduce)) + if reduce: # add up parameters from smoothing of individual sideband regions if type(self) == FakeSelectorSimpleABCD: @@ -805,6 +811,45 @@ def smoothen( ) return y_smooth_orig, y_smooth_var_orig + + + def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=True): + # get output shape from original hist axes, but as for result histogram + + hOut = ( + h[{self.name_x: self.sel_x if not self.integrate_x else hist.sum}] + if self.name_x in h.axes.name + else h + ) + out = np.zeros( + [a.extent if flow else a.shape for a in hOut.axes if a.name not in [self.name_y, self.decorrFakeAxis]], + dtype=sval.dtype, + ) + # leave the underflow and overflow unchanged if present + out[*sel[:-1]] = sval + if syst_variations: + outvar = np.zeros_like(out) + outvar = outvar[..., None, None] * np.ones( + (*outvar.shape, *svar.shape[-2:]), dtype=outvar.dtype + ) + + logger.debug("Doing syst_variations... something might be wrong here") + logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + + # leave the underflow and overflow unchanged if present + outvar[*sel[:-1], :, :] = svar + + logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + + + else: + # with full smoothing all of the statistical uncertainty is included in the + # explicit variations, so the remaining binned uncertainty is zero + outvar = np.zeros_like(out) + + return out, outvar + + def smoothen_spectrum( self, @@ -823,6 +868,8 @@ def smoothen_spectrum( smoothing_axis = h.axes[self.smoothing_axis_name] nax = sval.ndim + logger.debug("Smoothing spectrum along axis " + self.smoothing_axis_name) + # underflow and overflow are left unchanged along the smoothing axis # so we need to exclude them if they have been otherwise included if flow: @@ -867,6 +914,9 @@ def smoothen_spectrum( sval *= 1.0 / xwidth svar *= 1.0 / xwidth**2 + logger.debug("Sval shape after xwidth scaling: " + str(sval.shape)) + logger.debug("Svar shape after xwidth scaling: " + str(svar.shape)) + goodbin = (sval > 0.0) & (svar > 0.0) if goodbin.size - np.sum(goodbin) > 0: logger.warning( @@ -890,6 +940,9 @@ def smoothen_spectrum( reduce=reduce, ) + logger.debug("Svar shape after smoothing: " + (str(svar.shape) if svar is not None else "None")) + logger.debug("xwidthgt shape: " + str(xwidthtgt.shape)) + sval = np.exp(sval) * xwidthtgt sval = np.where(np.isfinite(sval), sval, 0.0) if syst_variations: @@ -899,30 +952,14 @@ def smoothen_spectrum( svar, sval[..., None, None], ) + - # get output shape from original hist axes, but as for result histogram - hOut = ( - h[{self.name_x: self.sel_x if not self.integrate_x else hist.sum}] - if self.name_x in h.axes.name - else h - ) - out = np.zeros( - [a.extent if flow else a.shape for a in hOut.axes if a.name != self.name_y], - dtype=sval.dtype, - ) - # leave the underflow and overflow unchanged if present - out[*sel[:-1]] = sval - if syst_variations: - outvar = np.zeros_like(out) - outvar = outvar[..., None, None] * np.ones( - (*outvar.shape, *svar.shape[-2:]), dtype=outvar.dtype - ) - # leave the underflow and overflow unchanged if present - outvar[*sel[:-1], :, :] = svar - else: - # with full smoothing all of the statistical uncertainty is included in the - # explicit variations, so the remaining binned uncertainty is zero - outvar = np.zeros_like(out) + logger.debug("Smoothing completed. Getting output tensors.") + + + out, outvar = self.get_smoothed_tensor(h, sel, sval, svar, syst_variations, flow=flow) + + logger.debug("Smoothing completed.") return out, outvar @@ -1044,16 +1081,109 @@ def calculate_fullABCD_smoothed( ..., :-1 ] - return self.smoothen_spectrum( - h, - hNew.axes[self.smoothing_axis_name].edges, - sval, - svar, - syst_variations=syst_variations, - use_spline=use_spline, - reduce=not signal_region, - flow=flow, - ) + logger.debug("X and Y axes: " + self.name_x + ", " + self.name_y) + logger.debug("hNew axes: " + ", ".join(hNew.axes.name)) + logger.debug(f"Sval shape after flattening: {sval.shape}") + logger.debug(f"Svar shape after flattening: {svar.shape}") + + baseOutTensor = np.zeros(sval.shape[:-1]) + baseOutVarTensor = ( + np.zeros(svar.shape[:-1]) # if not syst_variations + #else np.zeros((*svar.shape[:-1], svar.shape[-1], svar.shape[-1])) + ) + + logger.debug(f"baseOutTensor shape: {baseOutTensor.shape}") + logger.debug(f"baseOutVarTensor shape: {baseOutVarTensor.shape}") + + if self.decorrFakeAxis!="" and self.decorrFakeAxis in hNew.axes.name: + decorrFake_idx = [n for n in hNew.axes.name].index(self.decorrFakeAxis) + nbins_decorr = hNew.axes[self.decorrFakeAxis].size + logger.debug( + f"Found decorrelation axis {self.decorrFakeAxis} with {nbins_decorr} bins, applying smoothing independently in each bin." + ) + else: + nbins_decorr = 1 + decorrFake_idx = -1 + + logger.debug(f"Decorrelation axis index: {decorrFake_idx}") + + for i in range(nbins_decorr): + smoothing_slices = [slice(None)]*(sval.ndim) + outTensor_slices = [slice(None)]*(baseOutTensor.ndim) + outVarTensor_slices = [slice(None)]*(baseOutVarTensor.ndim) + if decorrFake_idx >= 0: + smoothing_slices[decorrFake_idx] = i + outTensor_slices[decorrFake_idx] = i + outVarTensor_slices[decorrFake_idx] = i + + sval_sliced = sval[tuple(smoothing_slices)] + svar_sliced = svar[tuple(smoothing_slices)] + + logger.debug(f"Shape of sval_sliced: {sval_sliced.shape}") + logger.debug(f"Shape of svar_sliced: {svar_sliced.shape}") + + logger.debug(f"Starting smoothing for decorrelation bin {i}.") + + goodbin = (sval_sliced > 0.0) & (svar_sliced > 0.0) + if goodbin.size - np.sum(goodbin) > 0: + logger.warning( + f"Found {goodbin.size-np.sum(goodbin)} of {goodbin.size} bins with 0 or negative bin content, those will be set to 0 and a large error" + ) + + logd = np.where(goodbin, np.log(sval_sliced), 0.0) + if np.all(logd[..., :4]==0.0): + logger.debug(f"All ABCD values are zeros! Returning zero as Fake estimate.") + logger.debug(f"Syst variations: {syst_variations}") + sval_sliced = np.zeros_like(sval_sliced[..., 0]) + svar_sliced = np.zeros_like( + svar_sliced[..., 0] if not syst_variations + else svar_sliced[..., 0][..., None, None] + ) + + out, outvar = self.get_smoothed_tensor( + h, (sval_sliced.ndim)*[slice(None)], sval_sliced, svar_sliced, syst_variations=syst_variations, flow=flow + ) + + else: + out, outvar = self.smoothen_spectrum( + h, hNew.axes[self.smoothing_axis_name].edges, sval_sliced, svar_sliced, + syst_variations=syst_variations, use_spline=use_spline, reduce=not signal_region, flow=flow + ) + + if syst_variations and i==0: + logger.debug("Updatng baseOutVarTensor to correctly include syst variations") + logger.debug(f"Current outvar shape: {outvar.shape}") + logger.debug(f"Current baseOutVarTensor shape: {baseOutVarTensor.shape}") + baseOutVarTensor = np.zeros( + (*baseOutVarTensor.shape, *outvar.shape[-2:]), dtype=baseOutVarTensor.dtype + ) + outVarTensor_slices += [slice(None), slice(None)] + + + logger.debug(f"Smoothing completed for decorrelation bin {i}.") + logger.debug(f"Smoothing output shape: {out.shape}") + logger.debug(f"Smoothing output var shape: {outvar.shape}") + logger.debug(f"Smoothing baseOutTensor shape: {baseOutTensor.shape}") + logger.debug(f"Smoothing baseOutVarTensor shape: {baseOutVarTensor.shape}") + + + if syst_variations and outvar.shape[-2:]!=baseOutVarTensor.shape[-2:]: + logger.warning( + f"Shape mismatch in syst variations: existing is {baseOutVarTensor.shape[-2:]}, new is {outvar.shape[-2:]}. Overwriting baseOutVarTensor." + ) + baseOutVarTensor = baseOutVarTensor[..., 0, 0] + baseOutVarTensor = np.broadcast_to(baseOutVarTensor[..., None, None], baseOutVarTensor.shape + outvar.shape[-2:]).copy() + + logger.debug(f"New baseOutVarTensor shape: {baseOutVarTensor.shape}") + + baseOutTensor[tuple(outTensor_slices)] = out + baseOutVarTensor[tuple(outVarTensor_slices)] = outvar + + + out = baseOutTensor + outvar = baseOutVarTensor + + return out, outvar class FakeSelector1DExtendedABCD(FakeSelectorSimpleABCD): From e5ed649a75f697db4a79a796fcccd444f3b52958 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Fri, 5 Dec 2025 11:40:12 +0100 Subject: [PATCH 05/46] small changes for plotting --- scripts/plotting/makeDataMCStackPlot.py | 63 ++++++++++++++++--------- utilities/styles/styles.py | 11 +++++ wremnants/datasets/datagroups.py | 4 +- wremnants/histselections.py | 13 +++-- 4 files changed, 62 insertions(+), 29 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 214e63345..184b1ba76 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -158,6 +158,14 @@ help="Axes for the fakerate binning", default=["eta", "pt", "charge"], ) +parser.add_argument( + "--decorrFakeAxis", + type=str, + default="utAngleSign", + help="Axis on which to enforce a decorrelation the in the fake rate smoothing (e.g., utAngleSign)", + # Created to exclude the bin utAngleSign<0, in which any ABCD method cannot + # take place, since the four regions at low mt are empty +) parser.add_argument( "--fineGroups", action="store_true", @@ -296,9 +304,19 @@ def padArray(ref, matchLength): for ps in args.presel: if "=" in ps: axName, axRange = ps.split("=") - axMin, axMax = map(float, axRange.split(",")) - logger.info(f"{axName} in [{axMin},{axMax}]") - presel[axName] = s[complex(0, axMin) : complex(0, axMax) : hist.sum] + if "," in ps: + #axMin, axMax = map(float, axRange.split(",")) + axMin, axMax = [float(p) if p != str() else None for p in axRange.split(",")] + logger.info(f"{axName} in [{axMin},{axMax}]") + presel[axName] = s[complex(0, axMin) : complex(0, axMax) : hist.sum] + else: + logger.info(f"Selecting {axName} {axRange.split('.')[1]}") + if axRange == "hist.overflow": + presel[axName] = hist.overflow + if axRange == "hist.underflow": + presel[axName] = hist.underflow + if axRange == "hist.sum": + presel[axName] = hist.sum else: logger.info(f"Integrating boolean {ps} axis") presel[ps] = s[:: hist.sum] @@ -314,32 +332,35 @@ def padArray(ref, matchLength): args.rebinBeforeSelection, ) -if args.selection: - applySelection = False - if args.selection != "none": - translate = { +if args.selection and args.selection != "none": + translate = { "hist.overflow": hist.overflow, "hist.underflow": hist.underflow, "hist.sum": hist.sum, } - for selection in args.selection.split(","): - axis, value = selection.split("=") - if value.startswith("["): - parts = [ - translate[p] if p in translate else int(p) if p != str() else None - for p in value[1:-1].split(":") - ] - select[axis] = hist.tag.Slicer()[parts[0] : parts[1] : parts[2]] - elif value == "hist.overflow": - select[axis] = hist.overflow - elif value == "hist.underflow": - select[axis] = hist.overflow - else: - select[axis] = int(value) + for selection in args.selection.split(","): + axis, value = selection.split("=") + if value.startswith("["): + parts = [ + translate[p] if p in translate else int(p) if p != str() else None + for p in value[1:-1].split(":") + ] + select[axis] = hist.tag.Slicer()[parts[0] : parts[1] : parts[2]] + elif value == "hist.overflow": + select[axis] = hist.overflow + elif value == "hist.underflow": + select[axis] = hist.underflow + else: + select[axis] = int(value) + applySelection = False if any( # does not trigger ABCD fake estimation if a cut is applied on the variables used to define ABCD regions + abcd_var in [cut_str.split("=")[0] for cut_str in args.selection.split(",")] + for abcd_var in ["relIso", "mt"] + ) else True else: applySelection = True groups.fakerate_axes = args.fakerateAxes +groups.decorrFakeAxis = args.decorrFakeAxis if applySelection: groups.set_histselectors( datasets, diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index d72c5cd17..387142439 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -38,6 +38,7 @@ def translate_html_to_latex(n): "Ztautau": "#964a8b", "Wmunu": "#E42536", "Wenu": "#E42536", + "WmunuOOA": "#2E9B92E6", "Wtaunu": "#F89C20", "DYlowMass": "deepskyblue", "PhotonInduced": "gold", @@ -74,6 +75,14 @@ def translate_html_to_latex(n): "Fake": ["Fake"], "Rare": ["PhotonInduced", "Top", "Diboson"], }, + "w_mass_ext": { + "Wmunu": ["Wmunu"], + "WmunuOOA": ["WmunuOOA"], + "Wtaunu": ["Wtaunu"], + "Z": ["Ztautau", "Zmumu", "DYlowMass"], + "Fake": ["Fake"], + "Rare": ["PhotonInduced", "Top", "Diboson"], + }, "z_dilepton": { "Zmumu": ["Zmumu"], "Other": ["Other", "Ztautau", "PhotonInduced"], @@ -95,6 +104,7 @@ def translate_html_to_latex(n): "Ztautau": r"Z/$\gamma^{\star}\to\tau\tau$", "Wmunu": r"W$^{\pm}\to\mu\nu$", "Wenu": r"W$^{\pm}\to e\nu$", + "WmunuOOA": r"W$^{\pm}\to\mu\nu$ OOA", "Wtaunu": r"W$^{\pm}\to\tau\nu$", "DYlowMass": r"Z/$\gamma^{\star}\to\mu\mu$, $10 Date: Fri, 5 Dec 2025 11:45:17 +0100 Subject: [PATCH 06/46] consider the polVar as noi - workaround to better interface with the current version of Rabbit, it will be probably reverted when the definitions of poi/noi/nuisanceNotConstrained are fixed --- wremnants/combine_theoryAgnostic_helper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wremnants/combine_theoryAgnostic_helper.py b/wremnants/combine_theoryAgnostic_helper.py index a7a6a6d87..0e588d170 100644 --- a/wremnants/combine_theoryAgnostic_helper.py +++ b/wremnants/combine_theoryAgnostic_helper.py @@ -60,7 +60,8 @@ def add_theoryAgnostic_polVar_uncertainty(self): noConstraint=True, systAxes=["nPolVarSyst", "downUpVar"], labelsByAxis=["v", "downUpVar"], - # splitGroup={f"{groupName}_{coeffKey}" : f"{groupName}_{coeffKey}"} + # splitGroup={f"{groupName}_{coeffKey}" : f"{groupName}_{coeffKey}"}, + noi=True, ) def add_muRmuF_polVar_uncertainty(self): From 5f8ce1fe3705798cf2d13e9c98214fe65d17a2a0 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Fri, 5 Dec 2025 11:54:35 +0100 Subject: [PATCH 07/46] fake prediction for uT<0 is now evaluated by scaling the ABCD prediction on uT>0 with an hardcoded factor (normalization) --- wremnants/histselections.py | 109 ++++++++++++++++++++++++------------ 1 file changed, 73 insertions(+), 36 deletions(-) diff --git a/wremnants/histselections.py b/wremnants/histselections.py index ddbf06abd..6f9623de2 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -399,6 +399,7 @@ def __init__( super().__init__(h, *args, **kwargs) # nominal histogram to be used to transfer variances for systematic variations + logger.debug("Setting h_nominal to None") self.h_nominal = None self.global_scalefactor = global_scalefactor @@ -544,8 +545,12 @@ def apply_correction(self, y, yvar=None, flow=True): def transfer_variances(self, h, set_nominal=False): if set_nominal: + logger.debug("Setting h_nominal to h") self.h_nominal = h.copy() elif self.h_nominal is not None: + logger.debug("Setting variances in h from h_nominal") + logger.debug(f"Shape of h: {h.values().shape}") + logger.debug(f"Shape of h_nominal: {self.h_nominal.values().shape}") h = hh.transfer_variances(h, self.h_nominal) elif h.storage_type == hist.storage.Weight: logger.warning( @@ -629,7 +634,11 @@ def get_hist( dvar = y_frf**2 * cvar elif self.smoothing_mode == "full": - h = self.transfer_variances(h, set_nominal=is_nominal) + if not (variations_frf or variations_smoothing): + logger.debug("Transferring variances for full smoothing without systematic variations") + h = self.transfer_variances(h, set_nominal=is_nominal) + else: + logger.warning("Not transferring variances before full smoothing, since systematic variations are requested") d, dvar = self.calculate_fullABCD_smoothed( h, flow=flow, syst_variations=variations_smoothing, use_spline=False ) @@ -834,12 +843,12 @@ def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=Tr ) logger.debug("Doing syst_variations... something might be wrong here") - logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + logger.debug("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) # leave the underflow and overflow unchanged if present outvar[*sel[:-1], :, :] = svar - logger.error("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) + logger.debug("Shapes of outvar and svar: " + str(outvar.shape) + " " + str(svar.shape)) else: @@ -850,7 +859,6 @@ def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=Tr return out, outvar - def smoothen_spectrum( self, h, @@ -954,7 +962,7 @@ def smoothen_spectrum( ) logger.debug("Smoothing completed. Getting output tensors.") - + out, outvar = self.get_smoothed_tensor(h, sel, sval, svar, syst_variations, flow=flow) logger.debug("Smoothing completed.") @@ -1094,33 +1102,33 @@ def calculate_fullABCD_smoothed( logger.debug(f"baseOutVarTensor shape: {baseOutVarTensor.shape}") if self.decorrFakeAxis!="" and self.decorrFakeAxis in hNew.axes.name: - decorrFake_idx = [n for n in hNew.axes.name].index(self.decorrFakeAxis) + decorrFakeAxis_idx = [n for n in hNew.axes.name].index(self.decorrFakeAxis) nbins_separateFakes = hNew.axes[self.decorrFakeAxis].size logger.debug( f"Found decorrelation axis {self.decorrFakeAxis} with {nbins_separateFakes} bins, applying smoothing independently in each bin." ) else: nbins_separateFakes = 1 - decorrFake_idx = -1 + decorrFakeAxis_idx = -1 - logger.debug(f"Decorrelation axis index: {decorrFake_idx}") + logger.debug(f"Decorrelation axis index: {decorrFakeAxis_idx}") - for i in range(nbins_separateFakes): - smoothing_slices = [slice(None)]*(sval.ndim) + for idx_fakeSep in range(nbins_separateFakes): + fakeSep_slices = [slice(None)]*(sval.ndim) outTensor_slices = [slice(None)]*(baseOutTensor.ndim) outVarTensor_slices = [slice(None)]*(baseOutVarTensor.ndim) - if decorrFake_idx >= 0: - smoothing_slices[decorrFake_idx] = i - outTensor_slices[decorrFake_idx] = i - outVarTensor_slices[decorrFake_idx] = i + if decorrFakeAxis_idx >= 0: + fakeSep_slices[decorrFakeAxis_idx] = idx_fakeSep + outTensor_slices[decorrFakeAxis_idx] = idx_fakeSep + outVarTensor_slices[decorrFakeAxis_idx] = idx_fakeSep - sval_sliced = sval[tuple(smoothing_slices)] - svar_sliced = svar[tuple(smoothing_slices)] + sval_sliced = sval[tuple(fakeSep_slices)] + svar_sliced = svar[tuple(fakeSep_slices)] logger.debug(f"Shape of sval_sliced: {sval_sliced.shape}") logger.debug(f"Shape of svar_sliced: {svar_sliced.shape}") - - logger.debug(f"Starting smoothing for decorrelation bin {i}.") + logger.debug(f"Number of nonvalid bins in sval AFTER the first SELECTION: {np.sum(sval<=0.0)} out of {sval.size}") + logger.debug(f"Starting smoothing for decorrelation bin {idx_fakeSep}.") goodbin = (sval_sliced > 0.0) & (svar_sliced > 0.0) if goodbin.size - np.sum(goodbin) > 0: @@ -1130,36 +1138,65 @@ def calculate_fullABCD_smoothed( logd = np.where(goodbin, np.log(sval_sliced), 0.0) if np.all(logd[..., :4]==0.0): - logger.debug(f"All ABCD values are zeros! Returning zero as Fake estimate.") - logger.debug(f"Syst variations: {syst_variations}") - sval_sliced = np.zeros_like(sval_sliced[..., 0]) - svar_sliced = np.zeros_like( - svar_sliced[..., 0] if not syst_variations - else svar_sliced[..., 0][..., None, None] + + if decorrFakeAxis_idx <0: + logger.debug(f"All ABCD values are zeros! Returning zero as Fake estimate.") + logger.debug(f"Syst variations: {syst_variations}") + sval_sliced = np.zeros_like(sval_sliced[..., 0]) + svar_sliced = np.zeros_like( + svar_sliced[..., 0] if not syst_variations + else svar_sliced[..., 0][..., None, None] ) - - out, outvar = self.get_smoothed_tensor( - h, (sval_sliced.ndim)*[slice(None)], sval_sliced, svar_sliced, - syst_variations=syst_variations, flow=flow + + out, outvar = self.get_smoothed_tensor( + h, (sval_sliced.ndim)*[slice(None)], sval_sliced, svar_sliced, + syst_variations=syst_variations, flow=flow + ) + + else: + logger.debug(f"All ABCD values are zeros! Returning Fake estimate based on other bin, with an HARDCODED norm. factor") + logger.debug(f"Syst variations: {syst_variations}") + compl_mask = np.array([True if j!=idx_fakeSep else False for j in range(nbins_separateFakes)]) + + logger.debug(f"Complement mask: {compl_mask}") + logger.debug(f"APPLIED 'np.where'; {np.where(compl_mask)[0]}") + + sval_slicedCompl = sval.take(indices=np.where(compl_mask)[0], axis=decorrFakeAxis_idx).sum(axis=decorrFakeAxis_idx) + svar_slicedCompl = svar.take(indices=np.where(compl_mask)[0], axis=decorrFakeAxis_idx).sum(axis=decorrFakeAxis_idx) + + logger.debug(f"Sval_slicedCompl shape: {sval_slicedCompl.shape}") + count_nonvalid = np.sum(sval_slicedCompl<=0.0) + logger.debug(f"Number of nonvalid bins in complement: {count_nonvalid} out of {sval_slicedCompl.size}") + + out_other, outvar_other = self.smoothen_spectrum( + h, hNew.axes[self.smoothing_axis_name].edges, sval_slicedCompl, svar_slicedCompl, + syst_variations=syst_variations, use_spline=use_spline, + reduce=not signal_region, flow=flow ) + NORMFACTOR = 0.1196 # Ratio of nonprompt data in SV for uT<0 (num.) to ut>0 (den.) + + out = out_other * NORMFACTOR + outvar = outvar_other * NORMFACTOR**2 + else: out, outvar = self.smoothen_spectrum( h, hNew.axes[self.smoothing_axis_name].edges, sval_sliced, svar_sliced, - syst_variations=syst_variations, use_spline=use_spline, reduce=not signal_region, flow=flow - ) - - if syst_variations and i==0: - logger.debug("Updatng baseOutVarTensor to correctly include syst variations") + syst_variations=syst_variations, use_spline=use_spline, + reduce=not signal_region, flow=flow + ) + + if syst_variations and idx_fakeSep==0: + logger.debug("Updating baseOutVarTensor to correctly include syst variations") logger.debug(f"Current outvar shape: {outvar.shape}") logger.debug(f"Current baseOutVarTensor shape: {baseOutVarTensor.shape}") baseOutVarTensor = np.zeros( (*baseOutVarTensor.shape, *outvar.shape[-2:]), dtype=baseOutVarTensor.dtype ) outVarTensor_slices += [slice(None), slice(None)] - - - logger.debug(f"Smoothing completed for decorrelation bin {i}.") + + + logger.debug(f"Smoothing completed for decorrelation bin {idx_fakeSep}.") logger.debug(f"Smoothing output shape: {out.shape}") logger.debug(f"Smoothing output var shape: {outvar.shape}") logger.debug(f"Smoothing baseOutTensor shape: {baseOutTensor.shape}") From c9354b7dbec7106c41083c5db420d8623fe72969 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Fri, 5 Dec 2025 12:18:57 +0100 Subject: [PATCH 08/46] label change for the utAngleSign axis --- scripts/plotting/makeDataMCStackPlot.py | 10 ++++---- wremnants/datasets/datagroups.py | 4 +-- wremnants/histselections.py | 34 ++++++++++++------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 184b1ba76..068d365e5 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -159,12 +159,12 @@ default=["eta", "pt", "charge"], ) parser.add_argument( - "--decorrFakeAxis", + "--fakeTransferAxis", type=str, default="utAngleSign", - help="Axis on which to enforce a decorrelation the in the fake rate smoothing (e.g., utAngleSign)", - # Created to exclude the bin utAngleSign<0, in which any ABCD method cannot - # take place, since the four regions at low mt are empty + help=""" + Axis where the fake prediction on non-valid bins (i.e. where the A-Ax-B-Bx regions are empty) + is estimated by using the other 'valid' bins of this axis, via a normalization or shape reweighting.""", ) parser.add_argument( "--fineGroups", @@ -360,7 +360,7 @@ def padArray(ref, matchLength): applySelection = True groups.fakerate_axes = args.fakerateAxes -groups.decorrFakeAxis = args.decorrFakeAxis +groups.fakeTransferAxis = args.fakeTransferAxis if applySelection: groups.set_histselectors( datasets, diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index 287af1b03..6e2ec9558 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -79,7 +79,7 @@ def __init__(self, infile, mode=None, **kwargs): self.gen_axes = {} self.fit_axes = [] self.fakerate_axes = ["pt", "eta", "charge"] - self.decorrFakeAxis = "utAngleSign" + self.fakeTransferAxis = "utAngleSign" self.setGenAxes() @@ -315,7 +315,7 @@ def set_histselectors( h, global_scalefactor=scale, fakerate_axes=self.fakerate_axes, - decorrFakeAxis=self.decorrFakeAxis, + fakeTransferAxis=self.fakeTransferAxis, smoothing_mode=smoothing_mode, smoothing_order_fakerate=smoothingOrderFakerate, smoothing_order_spectrum=smoothingOrderSpectrum, diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 6f9623de2..8f51c4c79 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -123,7 +123,7 @@ def __init__( name_x=None, name_y=None, fakerate_axes=["eta", "pt", "charge"], - decorrFakeAxis="", + fakeTransferAxis="", smoothing_axis_name="pt", rebin_smoothing_axis="automatic", # can be a list of bin edges, "automatic", or None upper_bound_y=None, # using an upper bound on the abcd y-axis (e.g. isolation) @@ -197,13 +197,13 @@ def __init__( self.set_selections_x() self.set_selections_y() - self.decorrFakeAxis = decorrFakeAxis + self.fakeTransferAxis = fakeTransferAxis if fakerate_axes is not None: self.fakerate_axes = fakerate_axes self.fakerate_integration_axes = [ n for n in h.axes.name - if n not in [self.name_x, self.name_y, *fakerate_axes, self.decorrFakeAxis] + if n not in [self.name_x, self.name_y, *fakerate_axes, self.fakeTransferAxis] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" @@ -831,7 +831,7 @@ def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=Tr else h ) out = np.zeros( - [a.extent if flow else a.shape for a in hOut.axes if a.name not in [self.name_y, self.decorrFakeAxis]], + [a.extent if flow else a.shape for a in hOut.axes if a.name not in [self.name_y, self.fakeTransferAxis]], dtype=sval.dtype, ) # leave the underflow and overflow unchanged if present @@ -1101,26 +1101,26 @@ def calculate_fullABCD_smoothed( logger.debug(f"baseOutTensor shape: {baseOutTensor.shape}") logger.debug(f"baseOutVarTensor shape: {baseOutVarTensor.shape}") - if self.decorrFakeAxis!="" and self.decorrFakeAxis in hNew.axes.name: - decorrFakeAxis_idx = [n for n in hNew.axes.name].index(self.decorrFakeAxis) - nbins_separateFakes = hNew.axes[self.decorrFakeAxis].size + if self.fakeTransferAxis!="" and self.fakeTransferAxis in hNew.axes.name: + fakeTransferAxis_idx = [n for n in hNew.axes.name].index(self.fakeTransferAxis) + nbins_separateFakes = hNew.axes[self.fakeTransferAxis].size logger.debug( - f"Found decorrelation axis {self.decorrFakeAxis} with {nbins_separateFakes} bins, applying smoothing independently in each bin." + f"Found decorrelation axis {self.fakeTransferAxis} with {nbins_separateFakes} bins, applying smoothing independently in each bin." ) else: nbins_separateFakes = 1 - decorrFakeAxis_idx = -1 + fakeTransferAxis_idx = -1 - logger.debug(f"Decorrelation axis index: {decorrFakeAxis_idx}") + logger.debug(f"Decorrelation axis index: {fakeTransferAxis_idx}") for idx_fakeSep in range(nbins_separateFakes): fakeSep_slices = [slice(None)]*(sval.ndim) outTensor_slices = [slice(None)]*(baseOutTensor.ndim) outVarTensor_slices = [slice(None)]*(baseOutVarTensor.ndim) - if decorrFakeAxis_idx >= 0: - fakeSep_slices[decorrFakeAxis_idx] = idx_fakeSep - outTensor_slices[decorrFakeAxis_idx] = idx_fakeSep - outVarTensor_slices[decorrFakeAxis_idx] = idx_fakeSep + if fakeTransferAxis_idx >= 0: + fakeSep_slices[fakeTransferAxis_idx] = idx_fakeSep + outTensor_slices[fakeTransferAxis_idx] = idx_fakeSep + outVarTensor_slices[fakeTransferAxis_idx] = idx_fakeSep sval_sliced = sval[tuple(fakeSep_slices)] svar_sliced = svar[tuple(fakeSep_slices)] @@ -1139,7 +1139,7 @@ def calculate_fullABCD_smoothed( logd = np.where(goodbin, np.log(sval_sliced), 0.0) if np.all(logd[..., :4]==0.0): - if decorrFakeAxis_idx <0: + if fakeTransferAxis_idx <0: logger.debug(f"All ABCD values are zeros! Returning zero as Fake estimate.") logger.debug(f"Syst variations: {syst_variations}") sval_sliced = np.zeros_like(sval_sliced[..., 0]) @@ -1161,8 +1161,8 @@ def calculate_fullABCD_smoothed( logger.debug(f"Complement mask: {compl_mask}") logger.debug(f"APPLIED 'np.where'; {np.where(compl_mask)[0]}") - sval_slicedCompl = sval.take(indices=np.where(compl_mask)[0], axis=decorrFakeAxis_idx).sum(axis=decorrFakeAxis_idx) - svar_slicedCompl = svar.take(indices=np.where(compl_mask)[0], axis=decorrFakeAxis_idx).sum(axis=decorrFakeAxis_idx) + sval_slicedCompl = sval.take(indices=np.where(compl_mask)[0], axis=fakeTransferAxis_idx).sum(axis=fakeTransferAxis_idx) + svar_slicedCompl = svar.take(indices=np.where(compl_mask)[0], axis=fakeTransferAxis_idx).sum(axis=fakeTransferAxis_idx) logger.debug(f"Sval_slicedCompl shape: {sval_slicedCompl.shape}") count_nonvalid = np.sum(sval_slicedCompl<=0.0) From e433ca3600aab46f7fcc6f23a98e6c7d01df5d49 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Mon, 8 Dec 2025 17:38:38 +0100 Subject: [PATCH 09/46] small fix --- scripts/analysisTools/tests/testFakesVsMt.py | 4 ++-- utilities/styles/styles.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/analysisTools/tests/testFakesVsMt.py b/scripts/analysisTools/tests/testFakesVsMt.py index 49ef70a32..5bc17c419 100644 --- a/scripts/analysisTools/tests/testFakesVsMt.py +++ b/scripts/analysisTools/tests/testFakesVsMt.py @@ -293,8 +293,8 @@ def drawAndFitFRF( ymax += diff * 0.45 if ymin < 0: ymin = 0 - if ymax > 5.0: - ymax = 5.0 + if ymax > 4.0: + ymax = 4.0 h1.GetXaxis().SetTitle(xAxisName) h1.GetXaxis().SetTitleOffset(1.2) diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index 47ab5b0c2..72d549c14 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -164,6 +164,8 @@ def translate_html_to_latex(n): "run": r"Run range", "nRecoVtx": r"Number of reconstructed vertices", "PV_npvsGood": r"Number of reconstructed vertices", + "utmu": {"label": r"$\mathit{u}_{T}^{\mu}$", "unit": "GeV"}, + "utAngleSign": r"sign($\mathit{u}_{T}^{\mu}$)", # "ewPTll": r"$\mathrm{Post\ FSR}\ p_\mathrm{T}^{\mu\mu}$", # "ewMll": r"$\mathrm{Post\ FSR}\ m^{\mu\mu}$", # "ewYll": r"$\mathrm{Post\ FSR}\ Y^{\mu\mu}$", @@ -421,6 +423,7 @@ def translate_html_to_latex(n): "absYVGen": lambda l, h: rf"${round(l,3)} < |Y| < {round(h,3)}$", "helicitySig": lambda x: rf"$\sigma_{{{'UL' if x==-1 else int(x)}}}$", "ai": lambda x: rf"$A_{int(x)}$", + "utAngleSign": lambda x: rf"$\mathit{{sign}}(\mathit{{u}}_{{T}}^\mu) = {int(x)}$", } impact_labels = { From c79eca9ac76ff416a053797b822ef655e6a68029 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Tue, 9 Dec 2025 11:08:57 +0100 Subject: [PATCH 10/46] moved reference commit of rabbit --- rabbit | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rabbit b/rabbit index 6d6791ac3..febf9a78e 160000 --- a/rabbit +++ b/rabbit @@ -1 +1 @@ -Subproject commit 6d6791ac309536785826946c0cefc38af7b17107 +Subproject commit febf9a78eaf36929ad6519c1061fb6939b33f807 From 4c957892dfb746b368b72a3302bcf94de8ca2180 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Tue, 9 Dec 2025 11:51:13 +0100 Subject: [PATCH 11/46] remove Zmumu OOA for theory agnostic with pol var --- scripts/histmakers/mw_with_mu_eta_pt.py | 1 - 1 file changed, 1 deletion(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 68101cd87..23d9cae36 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -481,7 +481,6 @@ args.theoryAgnosticPolVar and args.theoryAgnosticSplitOOA ): # this splitting is not needed for the normVar version of the theory agnostic datasets = unfolding_tools.add_out_of_acceptance(datasets, group="Wmunu") - datasets = unfolding_tools.add_out_of_acceptance(datasets, group="Zmumu") groups_to_aggregate.append("WmunuOOA") # axes for study of fakes From 488f6cc16c91cee571a0ff7926e82433b35c3f16 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Mon, 22 Dec 2025 21:53:26 +0100 Subject: [PATCH 12/46] fakes in uT<0 are evaluated by scaling the ABCD prediction on uT>0 with a pT dependent shape --- .../analysisTools/makeFakeTransferTemplate.py | 254 ++++++++++++++++++ wremnants/datasets/datagroups.py | 2 +- wremnants/histselections.py | 37 ++- 3 files changed, 273 insertions(+), 20 deletions(-) create mode 100644 scripts/analysisTools/makeFakeTransferTemplate.py diff --git a/scripts/analysisTools/makeFakeTransferTemplate.py b/scripts/analysisTools/makeFakeTransferTemplate.py new file mode 100644 index 000000000..a086099ea --- /dev/null +++ b/scripts/analysisTools/makeFakeTransferTemplate.py @@ -0,0 +1,254 @@ +import hist +import ROOT +import os +import argparse +import numpy as np +import hist +import pickle +import tensorflow as tf +from wremnants.datasets.datagroups import Datagroups +from wums import boostHistHelpers as hh +from wums.fitutils import fit_hist +from narf import histutils +from functools import partial +from array import array + +ROOT.gROOT.SetBatch(True) + +def pol4_root(xvals, parms, xLowVal=0.0, xFitRange=1.0): + xscaled = (xvals[0] - xLowVal) / xFitRange + return ( + parms[0] + + parms[1] * xscaled + + parms[2] * xscaled**2 + + parms[3] * xscaled**3 + + parms[4] * xscaled**4 + ) + +def crystal_ball_right_tf(xvals, parms): + # parms: [A, MPV, sigma, alpha, n] + x = tf.convert_to_tensor(xvals[0]) + A = tf.cast(parms[0], x.dtype) + MPV = tf.cast(parms[1], x.dtype) + sigma = tf.maximum(tf.cast(parms[2], x.dtype), 1e-8) + alpha = tf.cast(parms[3], x.dtype) + n = tf.cast(parms[4], x.dtype) + + t = (x - MPV) / sigma + + # constants for continuity + # for right-tail CrystalBall: tail when t > alpha + # tail shape: A * ( (n/alpha)^n * exp(-alpha^2/2) ) / ( (n/alpha) + t )^n + # gaussian part: A * exp(-t^2/2) + prefactor = tf.pow(n/alpha, n) * tf.exp(-0.5 * alpha * alpha) + + gauss = A * tf.exp(-0.5 * t * t) + tail = A * prefactor / tf.pow((n/alpha) + t, n) + + return tf.where(t > alpha, tail, gauss) + + +def convert_binEdges_idx(ed_list, binning): + low, high = 0, 0 + for binEdge in binning: + if binEdge+0.01 < ed_list[0]: low+=1 + if binEdge+0.01 < ed_list[1]: high+=1 + return (low, high) + +parser = argparse.ArgumentParser() + +parser.add_argument("-i", "--infile", type=str, + default = "/scratch/rforti/wremnants_hists/mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles_m1_x0p50_y3p00_THAGNV0_fromSV.hdf5", + help="Input file with histograms") +parser.add_argument("-o", "--outdir", type=str, default = "./", help="Output directory") +parser.add_argument( "--nEtaBins", type=int, default=1, choices=[1,2,3,4,6,8], help="Number of eta bins where to evaluate the templates") +parser.add_argument( "--nChargeBins", type=int, default=1, choices=[1,2], help="Number of charge bins where to evaluate the templates") +parser.add_argument( "--doQCD", action="store_true", help="Make templates with QCD instead of nonprompt contribution") + +args = parser.parse_args() + +groupsToConsider = ( + ["Data", "Wmunu", "Wtaunu", "Diboson", "Zmumu", "DYlowMass", "PhotonInduced", "Ztautau", "Top"] + if not args.doQCD + else ["QCD"] +) + +eta_genBinning = array("d", [round(-2.4+0.1*i,1) for i in range(49)]) +charge_genBinning = array("d", [-2, 0, 2]) + +delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins +delta_ch = (charge_genBinning[-1] - charge_genBinning[0]) / args.nChargeBins + +decorrBins_eta = [ + (round((eta_genBinning[0] + i *delta_eta), 1), + round((eta_genBinning[0] + (i+1)*delta_eta), 1)) + for i in range(args.nEtaBins) +] +decorrBins_ch = [ + (round((charge_genBinning[0] + i *delta_ch), 1), + round((charge_genBinning[0] + (i+1)*delta_ch), 1)) + for i in range(args.nChargeBins) +] + +print("Decorrelating in the eta bins: ", decorrBins_eta) +print("Decorrelating in the charge bins: ", decorrBins_ch) + +groups = Datagroups( + args.infile, + filterGroups=groupsToConsider, + excludeGroups=None, +) + +# There is probably a better way to do this but I don't want to deal with it +datasets = groups.getNames() +print(f"Will work on datasets {datasets}") + +exclude = ["Data"] if not args.doQCD else [] +prednames = list(groups.getNames([d for d in datasets if d not in exclude], exclude=False, match_exact=True)) + +print(f"Unstacked processes are {exclude}") +print(f"Stacked processes are {prednames}") + +histInfo = groups.groups + +select_utMinus = {"utAngleSign" : hist.tag.Slicer()[0:1:hist.sum]} +select_utPlus = {"utAngleSign" : hist.tag.Slicer()[1:2:hist.sum]} + +groups.set_histselectors( + datasets, + "nominal", + smoothing_mode="full", + smoothingOrderSpectrum=3, + smoothingPolynomialSpectrum="chebyshev", + integrate_x=all("mt" not in x.split("-") for x in ["pt"]), + mode="extended1D", + forceGlobalScaleFakes=None, + mcCorr=[None], +) + +groups.setNominalName("nominal") +groups.loadHistsForDatagroups("nominal", syst="", procsToRead=datasets, applySelection=True) + +out_hist = ROOT.TH3D(f"fakeRatio_utAngleSign_{'Data' if not args.doQCD else 'QCD'}", "", + len(eta_genBinning)-1, eta_genBinning, + 30, array("d", [round(26.0+1.0*i, 1) for i in range(31)]), + len(charge_genBinning)-1, charge_genBinning) + +for ch_edges in decorrBins_ch: + for eta_edges in decorrBins_eta: + + ch_low_idx, ch_high_idx = convert_binEdges_idx(ch_edges, charge_genBinning) + eta_low_idx, eta_high_idx = convert_binEdges_idx(eta_edges, eta_genBinning) + + print(ch_low_idx, ch_high_idx) + print(eta_low_idx, eta_high_idx) + + select_utMinus["charge"] = hist.tag.Slicer()[ch_low_idx:ch_high_idx:hist.sum] + select_utMinus["eta"] = hist.tag.Slicer()[eta_low_idx:eta_high_idx:hist.sum] + + select_utPlus["charge"] = hist.tag.Slicer()[ch_low_idx:ch_high_idx:hist.sum] + select_utPlus["eta"] = hist.tag.Slicer()[eta_low_idx:eta_high_idx:hist.sum] + + print(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") + + boost_h_utMinus = histInfo["Data"].copy("Data_utMinus").hists["nominal"] + boost_h_utMinus = boost_h_utMinus[select_utMinus] + boost_h_utMinus = hh.projectNoFlow(boost_h_utMinus, ["pt"], ["relIso", "mt"]) + root_h_utMinus = histutils.hist_to_root(boost_h_utMinus) + + boost_h_utPlus = histInfo["Data"].copy("Data_utPlus").hists["nominal"] + boost_h_utPlus = boost_h_utPlus[select_utPlus] + boost_h_utPlus = hh.projectNoFlow(boost_h_utPlus, ["pt"], ["relIso", "mt"]) + root_h_utPlus = histutils.hist_to_root(boost_h_utPlus) + + print("Integrals BEFORE prompt subraction", root_h_utMinus.Integral(), root_h_utPlus.Integral()) + + for mcName in prednames: + if args.doQCD: continue + print(f"Subtracting {mcName} from data") + boost_h_mc_utMinus = histInfo[mcName].copy(f"{mcName}_utMinus").hists["nominal"] + boost_h_mc_utMinus = boost_h_mc_utMinus[select_utMinus] + boost_h_mc_utMinus = hh.projectNoFlow(boost_h_mc_utMinus, ["pt"], ["relIso", "mt"]) + root_h_mc_utMinus = histutils.hist_to_root(boost_h_mc_utMinus) + root_h_utMinus.Add(root_h_mc_utMinus, -1) + + boost_h_mc_utPlus = histInfo[mcName].copy(f"{mcName}_utPlus").hists["nominal"] + boost_h_mc_utPlus = boost_h_mc_utPlus[select_utPlus] + boost_h_mc_utPlus = hh.projectNoFlow(boost_h_mc_utPlus, ["pt"], ["relIso", "mt"]) + root_h_mc_utPlus = histutils.hist_to_root(boost_h_mc_utPlus) + root_h_utPlus.Add(root_h_mc_utPlus, -1) + + print("Integrals AFTER prompt subraction", root_h_utMinus.Integral(), root_h_utPlus.Integral()) + + + ratio_h = root_h_utMinus.Clone(f"fakeRatio_utAngleSign") + ratio_h.Sumw2() + ratio_h.Divide(root_h_utPlus) + + for idx_ch in range(ch_low_idx+1, ch_high_idx+1): + for idx_eta in range(eta_low_idx+1, eta_high_idx+1): + print(f"Setting weights for chBin={idx_ch}, etaBin={idx_eta}") + for idx_pt in range(1, 31): + out_hist.SetBinContent( + idx_eta, idx_pt, idx_ch, + ratio_h.GetBinContent(idx_pt) + ) + out_hist.SetBinError( + idx_eta, idx_pt, idx_ch, + ratio_h.GetBinError(idx_pt) + ) + if ratio_h.GetBinContent(idx_pt)<=0.0: + print("WARNING - found negative value in bin: ", idx_eta, idx_pt, idx_ch) + + +boost_out_hist = histutils.root_to_hist(out_hist) + +with open(f"{args.outdir}/fakeTransferTemplates.pkl", "wb") as fout: + pickle.dump(boost_out_hist, fout) + +fout = ROOT.TFile(f"{args.outdir}/fakeTransferTemplates{'' if not args.doQCD else '_QCD'}.root", "RECREATE") +fout.cd() +out_hist.Write() + +''' +x_axis = hist.axis.Regular(30, 26, 56, name="pt", flow=False) + +tr_hist = hist.Hist(x_axis, storage=hist.storage.Weight()) + +for i in range(30): + tr_hist[i] = (arr_val[i], arr_var[i]) + + +params = np.array([1.0, 0.0, 0.0, 0.0, 0.0]) # Initial parameters for pol4_root + +res = fit_hist( + tr_hist, + partial(pol4_root, xLowVal=26.0, xFitRange=30.0), + params, +) + +tr_func = [] +for i in range(len(bincenters)): + tr_func.append( + float( + pol4_root( + [bincenters[i]], + res["x"], + xLowVal=26.0, + xFitRange=30.0, + ))) +print(tr_func) +print("Params:", res["x"]) + +chi2 = res["loss_val"] +ndof = len(bincenters) - len(res["x"]) +chi2Prob = ROOT.TMath.Prob(chi2, ndof) + +print(chi2, ndof, chi2Prob) + +''' + + +fout.Close() + + diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index 6e2ec9558..dabb83acf 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -1373,7 +1373,7 @@ def addSystematic( ) for proc in procs_to_add: - logger.error(f"Now doing syst {name} for proc {proc}!") + logger.debug(f"Now doing syst {name} for proc {proc}!") hvar = self.groups[proc].hists["syst"] logger.debug(f"Actions: {action}, args: {actionArgs}") diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 8f51c4c79..59907241b 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -1,4 +1,6 @@ import hist +import os +import pickle import numpy as np from scipy import interpolate @@ -199,11 +201,11 @@ def __init__( self.fakeTransferAxis = fakeTransferAxis if fakerate_axes is not None: - self.fakerate_axes = fakerate_axes + self.fakerate_axes = fakerate_axes # list of axes names where to perform independent fakerate computation self.fakerate_integration_axes = [ n for n in h.axes.name - if n not in [self.name_x, self.name_y, *fakerate_axes, self.fakeTransferAxis] + if n not in [self.name_x, self.name_y, *fakerate_axes] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" @@ -435,6 +437,16 @@ def __init__( ) else: self.spectrum_regressor = None + + if self.fakeTransferAxis in h.axes.name: + logger.debug("Loaded transfer tensor for fakes") + trTensorPath = os.path.join( + os.environ["WREM_BASE"], + "wremnants-data/data/fakesWmass/fakeTransferTemplates.pkl" + ) + with open(trTensorPath, "rb") as fTens: + self.fakeTransferTensor = pickle.load(fTens) + if self.smoothing_mode in ["binned"]: # rebinning doesn't make sense for binned estimation @@ -1169,15 +1181,14 @@ def calculate_fullABCD_smoothed( logger.debug(f"Number of nonvalid bins in complement: {count_nonvalid} out of {sval_slicedCompl.size}") out_other, outvar_other = self.smoothen_spectrum( - h, hNew.axes[self.smoothing_axis_name].edges, sval_slicedCompl, svar_slicedCompl, + h, hNew.axes[self.smoothing_axis_name].edges, + sval_slicedCompl, svar_slicedCompl, syst_variations=syst_variations, use_spline=use_spline, reduce=not signal_region, flow=flow ) - NORMFACTOR = 0.1196 # Ratio of nonprompt data in SV for uT<0 (num.) to ut>0 (den.) - - out = out_other * NORMFACTOR - outvar = outvar_other * NORMFACTOR**2 + out = out_other * self.fakeTransferTensor.values()[..., *[None]*(out_other.ndim-3)] + outvar = outvar_other * (self.fakeTransferTensor.values()[..., *[None]*(outvar_other.ndim-3)]**2) else: out, outvar = self.smoothen_spectrum( @@ -1195,27 +1206,15 @@ def calculate_fullABCD_smoothed( ) outVarTensor_slices += [slice(None), slice(None)] - logger.debug(f"Smoothing completed for decorrelation bin {idx_fakeSep}.") logger.debug(f"Smoothing output shape: {out.shape}") logger.debug(f"Smoothing output var shape: {outvar.shape}") logger.debug(f"Smoothing baseOutTensor shape: {baseOutTensor.shape}") logger.debug(f"Smoothing baseOutVarTensor shape: {baseOutVarTensor.shape}") - - if syst_variations and outvar.shape[-2:]!=baseOutVarTensor.shape[-2:]: - logger.warning( - f"Shape mismatch in syst variations: existing is {baseOutVarTensor.shape[-2:]}, new is {outvar.shape[-2:]}. Overwriting baseOutVarTensor." - ) - baseOutVarTensor = baseOutVarTensor[..., 0, 0] - baseOutVarTensor = np.broadcast_to(baseOutVarTensor[..., None, None], baseOutVarTensor.shape + outvar.shape[-2:]).copy() - - logger.debug(f"New baseOutVarTensor shape: {baseOutVarTensor.shape}") - baseOutTensor[tuple(outTensor_slices)] = out baseOutVarTensor[tuple(outVarTensor_slices)] = outvar - out = baseOutTensor outvar = baseOutVarTensor From 92931262c98dbdc83ed88758e35dd07c813317fc Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Mon, 22 Dec 2025 21:57:52 +0100 Subject: [PATCH 13/46] decorrelate FakeParam syst in uT bins --- scripts/rabbit/setupRabbit.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 4e4a7c71c..aadd31151 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -65,7 +65,7 @@ def make_subparsers(parser): "--priorNormXsec", type=float, default=1, - help=r"Prior for shape uncertainties on cross sections for theory agnostic or unfolding analysis with POIs as NOIs (1 means 100%). If negative, it will use shapeNoConstraint in the fit", + help=r"Prior for shape uncertainties on cross sections for theory agnostic or unfolding analysis with POIs as NOIs (1 means 100%%). If negative, it will use shapeNoConstraint in the fit", ) parser.add_argument( "--scaleNormXsecHistYields", @@ -236,7 +236,7 @@ def make_parser(parser=None): parser.add_argument( "--lumiUncertainty", type=float, - help=r"Uncertainty for luminosity in excess to 1 (e.g. 1.012 means 1.2%); automatic by default", + help=r"Uncertainty for luminosity in excess to 1 (e.g. 1.012 means 1.2%%); automatic by default", default=None, ) parser.add_argument( @@ -647,7 +647,7 @@ def make_parser(parser=None): default=0, type=float, help=r"""Add normalization uncertainty for W signal. - If negative, treat as free floating with the absolute being the size of the variation (e.g. -1.01 means +/-1% of the nominal is varied). + If negative, treat as free floating with the absolute being the size of the variation (e.g. -1.01 means +/-1%% of the nominal is varied). If 0 nothing is added""", ) parser.add_argument( @@ -655,7 +655,7 @@ def make_parser(parser=None): default=0, type=float, help=r"""Add normalization uncertainty for W->tau,nu process. - If negative, treat as free floating with the absolute being the size of the variation (e.g. -1.01 means +/-1% of the nominal is varied). + If negative, treat as free floating with the absolute being the size of the variation (e.g. -1.01 means +/-1%% of the nominal is varied). If 0 nothing is added""", ) parser.add_argument( @@ -1856,7 +1856,7 @@ def fake_nonclosure( return hvar for axesToDecorrNames in [ - [], + [datagroups.fakeTransferAxis] if True else [], ]: for idx, mag in [ (1, 0.1), From 3f96a4c53bbc0058910f902a6c92b69cb96994d6 Mon Sep 17 00:00:00 2001 From: Ruben Forti Date: Mon, 22 Dec 2025 22:01:03 +0100 Subject: [PATCH 14/46] new syst for eta nonclosure in ut<0 bin --- scripts/rabbit/setupRabbit.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index aadd31151..d013df9a4 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -1891,6 +1891,41 @@ def fake_nonclosure( ), ) + def fake_nonclosure_utMinus( + h, + axesToDecorrNames=["eta"], + variation_size=0.1, + *args, + **kwargs, + ): + logger.error("Doing decorr nonclosure for utMinus") + hnom = fakeselector.get_hist(h, *args, **kwargs) + hvar = (1+variation_size)*hnom + # applying the variations only on the utAngleSign<0 bin + hvar.values()[..., -1] = hnom.values()[..., -1] + + hvar = syst_tools.decorrelateByAxes(hvar, hnom, axesToDecorrNames) + + return hvar + + datagroups.addSystematic( + inputBaseName, + groups=[subgroup, "Fake", "experiment", "expNoCalib"], + name=f"{datagroups.fakeName}EtaClos_eta", + baseName=f"{datagroups.fakeName}EtaClos", + processes=datagroups.fakeName, + noConstraint=False, + mirror=True, + scale=1, + applySelection=False, # don't apply selection, external parameters need to be added + action=fake_nonclosure_utMinus, + actionArgs=dict( + axesToDecorrNames=["eta"], + variation_size=0.1, + ), + systAxes=["eta_decorr"] + ) + if not args.noEfficiencyUnc: if not lowPU: From fec8acea75abb82d94fcb1d41e3f677271c40ab8 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 24 Dec 2025 09:46:37 +0100 Subject: [PATCH 15/46] updates for veto (no default change) --- scripts/histmakers/mw_with_mu_eta_pt.py | 3 ++- utilities/parsing.py | 6 ++++++ wremnants/muon_selections.py | 3 ++- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 23d9cae36..1d99de7d0 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -1038,6 +1038,7 @@ def build_graph(df, dataset): nMuons=1, ptCut=args.vetoRecoPt, etaCut=args.vetoRecoEta, + staPtCut=args.vetoRecoStaPt, dxybsCut=args.dxybs, useGlobalOrTrackerVeto=useGlobalOrTrackerVeto, ) @@ -1158,7 +1159,7 @@ def build_graph(df, dataset): if args.selectVetoEventsMC: # in principle a gen muon with eta = 2.401 might still be matched to a reco muon with eta < 2.4, same for pt, so this condition is potentially fragile, but it is just for test plots df = df.Filter("Sum(postfsrMuons_inAcc) >= 2") - if not args.noVetoSF: + if not args.noVetoSF or args.scaleDYvetoFraction > 0.0: df = df.Define( "hasMatchDR2idx", "wrem::hasMatchDR2idx_closest(goodMuons_eta0,goodMuons_phi0,GenPart_eta[postfsrMuons_inAcc],GenPart_phi[postfsrMuons_inAcc],0.09)", diff --git a/utilities/parsing.py b/utilities/parsing.py index 47f1f0fff..5918d74b4 100644 --- a/utilities/parsing.py +++ b/utilities/parsing.py @@ -501,6 +501,12 @@ def __call__(self, parser, namespace, values, option_string=None): type=float, help="Lower threshold for muon pt in the veto definition", ) + parser.add_argument( + "--vetoRecoStaPt", + default=15, + type=float, + help="Lower threshold for muon standalone pt in the veto definition (should typically match vetoRecoPt, but not necessary)", + ) parser.add_argument( "--vetoRecoEta", default=2.4, diff --git a/wremnants/muon_selections.py b/wremnants/muon_selections.py index 9951f5bc2..1fa3ac528 100644 --- a/wremnants/muon_selections.py +++ b/wremnants/muon_selections.py @@ -78,9 +78,10 @@ def select_veto_muons( "vetoMuonsPre", f"Muon_looseId && abs(Muon_dxybs) < {dxybsCut} && Muon_correctedCharge != -99", ) + nHitsSA = common.muonEfficiency_standaloneNumberOfValidHits df = df.Define( "Muon_isGoodGlobal", - f"Muon_isGlobal && Muon_highPurity && Muon_standalonePt > {staPtCut} && Muon_standaloneNumberOfValidHits > 0 && wrem::vectDeltaR2(Muon_standaloneEta, Muon_standalonePhi, Muon_correctedEta, Muon_correctedPhi) < 0.09", + f"Muon_isGlobal && Muon_highPurity && Muon_standalonePt > {staPtCut} && Muon_standaloneNumberOfValidHits >= {nHitsSA} && wrem::vectDeltaR2(Muon_standaloneEta, Muon_standalonePhi, Muon_correctedEta, Muon_correctedPhi) < 0.09", ) if useGlobalOrTrackerVeto: if tightGlobalOrTracker: From 65201f6bba4d117562e70435a894c62dfc6aa7b2 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 25 Dec 2025 10:09:54 +0100 Subject: [PATCH 16/46] updates --- scripts/plotting/makeDataMCStackPlot.py | 9 ++++ scripts/rabbit/setupRabbit.py | 72 ++++++++++++++----------- utilities/styles/styles.py | 2 +- wremnants/histselections.py | 51 +----------------- 4 files changed, 51 insertions(+), 83 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 4b01d48e5..1d30bc25b 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -204,6 +204,14 @@ default=(0.05, 0.8), help="Location in (x,y) for additional text, aligned to upper left", ) +parser.add_argument( + "--vertLineEdges", + type=float, + nargs="*", + default=[], + help="Horizontal axis edges where to plot vertical lines", +) + subparsers = parser.add_subparsers(dest="variation") variation = subparsers.add_parser( "variation", help="Arguments for adding variation hists" @@ -617,6 +625,7 @@ def collapseSyst(h): lowerLegPos=args.lowerLegPos, lower_leg_padding=args.lowerLegPadding, subplotsizes=args.subplotSizes, + x_vertLines_edges=args.vertLineEdges, ) to_join = [f"{h.replace('-','_')}"] diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index c3cd2b876..6c5a547e6 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -2042,8 +2042,13 @@ def fake_nonclosure( return hvar + fakeParamDecorrAxes = ( + [datagroups.fakeTransferAxis] + if (datagroups.fakeTransferAxis != "" and "utAngleSign" in fitvar) + else [] + ) for axesToDecorrNames in [ - [datagroups.fakeTransferAxis] if True else [], + fakeParamDecorrAxes, ]: for idx, mag in [ (1, 0.1), @@ -2084,40 +2089,43 @@ def fake_nonclosure( ), ) - def fake_nonclosure_utMinus( - h, - axesToDecorrNames=["eta"], - variation_size=0.1, - *args, - **kwargs, - ): - logger.error("Doing decorr nonclosure for utMinus") - hnom = fakeselector.get_hist(h, *args, **kwargs) - hvar = (1 + variation_size) * hnom - # applying the variations only on the utAngleSign<0 bin - hvar.values()[..., -1] = hnom.values()[..., -1] + if "utAngleSign" in fitvar: + # TODO: extend and use previous function fake_nonclosure(...) + def fake_nonclosure_utMinus( + h, + axesToDecorrNames=["eta"], + variation_size=0.1, + *args, + **kwargs, + ): + logger.debug("Doing decorr nonclosure for utMinus") + hnom = fakeselector.get_hist(h, *args, **kwargs) + hvar = (1 + variation_size) * hnom + # applying the variations only on the utAngleSign<0 bin + ## TODO: select axis by name and bin id by input argument + hvar.values()[..., -1] = hnom.values()[..., -1] - hvar = syst_tools.decorrelateByAxes(hvar, hnom, axesToDecorrNames) + hvar = syst_tools.decorrelateByAxes(hvar, hnom, axesToDecorrNames) - return hvar + return hvar - datagroups.addSystematic( - inputBaseName, - groups=[subgroup, "Fake", "experiment", "expNoCalib"], - name=f"{datagroups.fakeName}EtaClos_eta", - baseName=f"{datagroups.fakeName}EtaClos", - processes=datagroups.fakeName, - noConstraint=False, - mirror=True, - scale=1, - applySelection=False, # don't apply selection, external parameters need to be added - action=fake_nonclosure_utMinus, - actionArgs=dict( - axesToDecorrNames=["eta"], - variation_size=0.1, - ), - systAxes=["eta_decorr"], - ) + datagroups.addSystematic( + inputBaseName, + groups=[subgroup, "Fake", "experiment", "expNoCalib"], + name=f"{datagroups.fakeName}EtaClos_eta", + baseName=f"{datagroups.fakeName}EtaClos", + processes=datagroups.fakeName, + noConstraint=False, + mirror=True, + scale=1, + applySelection=False, # don't apply selection, external parameters need to be added + action=fake_nonclosure_utMinus, + actionArgs=dict( + axesToDecorrNames=["eta"], + variation_size=0.1, + ), + systAxes=["eta_decorr"], + ) if not args.noEfficiencyUnc: diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index 6ad089a95..51306c48d 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -192,7 +192,7 @@ def translate_html_to_latex(n): "nRecoVtx": r"Number of reconstructed vertices", "PV_npvsGood": r"Number of reconstructed vertices", "utmu": {"label": r"$\mathit{u}_{T}^{\mu}$", "unit": "GeV"}, - "utAngleSign": r"$\mathrm{sign}(\mathit{u}_{T}{\mu})$", + "utAngleSign": r"$\mathrm{sign}(\mathit{u}_{T}^{\mu})$", # "ewPTll": r"$\mathrm{Post\ FSR}\ p_\mathrm{T}^{\mu\mu}$", # "ewMll": r"$\mathrm{Post\ FSR}\ m^{\mu\mu}$", # "ewYll": r"$\mathrm{Post\ FSR}\ Y^{\mu\mu}$", diff --git a/wremnants/histselections.py b/wremnants/histselections.py index d9b3cde7d..d080e4801 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -207,7 +207,7 @@ def __init__( n for n in h.axes.name if n - not in [self.name_x, self.name_y, *fakerate_axes, self.decorrFakeAxis] + not in [self.name_x, self.name_y, *fakerate_axes, self.fakeTransferAxis] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" @@ -886,55 +886,6 @@ def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=Tr return out, outvar - def get_smoothed_tensor(self, h, sel, sval, svar, syst_variations=False, flow=True): - # get output shape from original hist axes, but as for result histogram - - hOut = ( - h[{self.name_x: self.sel_x if not self.integrate_x else hist.sum}] - if self.name_x in h.axes.name - else h - ) - out = np.zeros( - [ - a.extent if flow else a.shape - for a in hOut.axes - if a.name not in [self.name_y, self.decorrFakeAxis] - ], - dtype=sval.dtype, - ) - # leave the underflow and overflow unchanged if present - out[*sel[:-1]] = sval - if syst_variations: - outvar = np.zeros_like(out) - outvar = outvar[..., None, None] * np.ones( - (*outvar.shape, *svar.shape[-2:]), dtype=outvar.dtype - ) - - logger.debug("Doing syst_variations... something might be wrong here") - logger.error( - "Shapes of outvar and svar: " - + str(outvar.shape) - + " " - + str(svar.shape) - ) - - # leave the underflow and overflow unchanged if present - outvar[*sel[:-1], :, :] = svar - - logger.error( - "Shapes of outvar and svar: " - + str(outvar.shape) - + " " - + str(svar.shape) - ) - - else: - # with full smoothing all of the statistical uncertainty is included in the - # explicit variations, so the remaining binned uncertainty is zero - outvar = np.zeros_like(out) - - return out, outvar - def smoothen_spectrum( self, h, From f1a26ce0d6bc6bf7fc040989b4e156551adf1bac Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 26 Dec 2025 10:09:16 +0100 Subject: [PATCH 17/46] updates for fakes vs uT --- .../w_mass_13TeV/makeFakeTransferTemplate.py | 113 +++++++++++------- scripts/histmakers/mw_with_mu_eta_pt.py | 2 +- scripts/rabbit/setupRabbit.py | 16 +++ wremnants/datasets/datagroups.py | 2 +- wremnants/histselections.py | 17 +-- 5 files changed, 100 insertions(+), 50 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py index a71ec44b2..d9c84c161 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py +++ b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py @@ -1,16 +1,33 @@ +#!/usr/bin/env python3 import argparse +import os import pickle +import sys from array import array import hist +import lz4.frame import ROOT import tensorflow as tf -from narf import histutils +# from narf import histutils +import narf +import wums.output_tools +from utilities import common from wremnants.datasets.datagroups import Datagroups from wums import boostHistHelpers as hh +from wums import logging + +args = sys.argv[:] +sys.argv = ["-b"] +sys.argv = args ROOT.gROOT.SetBatch(True) +ROOT.PyConfig.IgnoreCommandLineOptions = True + +from scripts.analysisTools.plotUtils.utility import ( + safeOpenFile, +) def pol4_root(xvals, parms, xLowVal=0.0, xFitRange=1.0): @@ -67,6 +84,13 @@ def convert_binEdges_idx(ed_list, binning): help="Input file with histograms", ) parser.add_argument("-o", "--outdir", type=str, default="./", help="Output directory") +parser.add_argument( + "-p", + "--postfix", + type=str, + default=None, + help="Postfix appended to output file name", +) parser.add_argument( "--nEtaBins", type=int, @@ -89,6 +113,9 @@ def convert_binEdges_idx(ed_list, binning): args = parser.parse_args() +logger = logging.setup_logger(os.path.basename(__file__), 4) +ROOT.TH1.SetDefaultSumw2() + groupsToConsider = ( [ "Data", @@ -126,8 +153,8 @@ def convert_binEdges_idx(ed_list, binning): for i in range(args.nChargeBins) ] -print("Decorrelating in the eta bins: ", decorrBins_eta) -print("Decorrelating in the charge bins: ", decorrBins_ch) +logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") +logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") groups = Datagroups( args.infile, @@ -137,7 +164,7 @@ def convert_binEdges_idx(ed_list, binning): # There is probably a better way to do this but I don't want to deal with it datasets = groups.getNames() -print(f"Will work on datasets {datasets}") +logger.info(f"Will work on datasets {datasets}") exclude = ["Data"] if not args.doQCD else [] prednames = list( @@ -146,8 +173,8 @@ def convert_binEdges_idx(ed_list, binning): ) ) -print(f"Unstacked processes are {exclude}") -print(f"Stacked processes are {prednames}") +logger.info(f"Unstacked processes are {exclude}") +logger.info(f"Stacked processes are {prednames}") histInfo = groups.groups @@ -188,8 +215,8 @@ def convert_binEdges_idx(ed_list, binning): ch_low_idx, ch_high_idx = convert_binEdges_idx(ch_edges, charge_genBinning) eta_low_idx, eta_high_idx = convert_binEdges_idx(eta_edges, eta_genBinning) - print(ch_low_idx, ch_high_idx) - print(eta_low_idx, eta_high_idx) + logger.info(f"{ch_low_idx}, {ch_high_idx}") + logger.info(f"{eta_low_idx}, {eta_high_idx}") select_utMinus["charge"] = hist.tag.Slicer()[ ch_low_idx : ch_high_idx : hist.sum @@ -199,28 +226,25 @@ def convert_binEdges_idx(ed_list, binning): select_utPlus["charge"] = hist.tag.Slicer()[ch_low_idx : ch_high_idx : hist.sum] select_utPlus["eta"] = hist.tag.Slicer()[eta_low_idx : eta_high_idx : hist.sum] - print(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") + logger.info(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") boost_h_utMinus = histInfo["Data"].copy("Data_utMinus").hists["nominal"] boost_h_utMinus = boost_h_utMinus[select_utMinus] boost_h_utMinus = hh.projectNoFlow(boost_h_utMinus, ["pt"], ["relIso", "mt"]) - root_h_utMinus = histutils.hist_to_root(boost_h_utMinus) + root_h_utMinus = narf.hist_to_root(boost_h_utMinus) boost_h_utPlus = histInfo["Data"].copy("Data_utPlus").hists["nominal"] boost_h_utPlus = boost_h_utPlus[select_utPlus] boost_h_utPlus = hh.projectNoFlow(boost_h_utPlus, ["pt"], ["relIso", "mt"]) - root_h_utPlus = histutils.hist_to_root(boost_h_utPlus) + root_h_utPlus = narf.hist_to_root(boost_h_utPlus) - print( - "Integrals BEFORE prompt subraction", - root_h_utMinus.Integral(), - root_h_utPlus.Integral(), - ) + logger.info(f"Integrals BEFORE prompt subraction (uT < 0, uT > 0)") + logger.info(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") for mcName in prednames: if args.doQCD: continue - print(f"Subtracting {mcName} from data") + logger.info(f"Subtracting {mcName} from data") boost_h_mc_utMinus = ( histInfo[mcName].copy(f"{mcName}_utMinus").hists["nominal"] ) @@ -228,7 +252,7 @@ def convert_binEdges_idx(ed_list, binning): boost_h_mc_utMinus = hh.projectNoFlow( boost_h_mc_utMinus, ["pt"], ["relIso", "mt"] ) - root_h_mc_utMinus = histutils.hist_to_root(boost_h_mc_utMinus) + root_h_mc_utMinus = narf.hist_to_root(boost_h_mc_utMinus) root_h_utMinus.Add(root_h_mc_utMinus, -1) boost_h_mc_utPlus = ( @@ -238,14 +262,11 @@ def convert_binEdges_idx(ed_list, binning): boost_h_mc_utPlus = hh.projectNoFlow( boost_h_mc_utPlus, ["pt"], ["relIso", "mt"] ) - root_h_mc_utPlus = histutils.hist_to_root(boost_h_mc_utPlus) + root_h_mc_utPlus = narf.hist_to_root(boost_h_mc_utPlus) root_h_utPlus.Add(root_h_mc_utPlus, -1) - print( - "Integrals AFTER prompt subraction", - root_h_utMinus.Integral(), - root_h_utPlus.Integral(), - ) + logger.info(f"Integrals AFTER prompt subraction (uT < 0, uT > 0)") + logger.info(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") ratio_h = root_h_utMinus.Clone(f"fakeRatio_utAngleSign") ratio_h.Sumw2() @@ -253,7 +274,7 @@ def convert_binEdges_idx(ed_list, binning): for idx_ch in range(ch_low_idx + 1, ch_high_idx + 1): for idx_eta in range(eta_low_idx + 1, eta_high_idx + 1): - print(f"Setting weights for chBin={idx_ch}, etaBin={idx_eta}") + # logger.debug(f"Setting weights for chBin={idx_ch}, etaBin={idx_eta}") for idx_pt in range(1, 31): out_hist.SetBinContent( idx_eta, idx_pt, idx_ch, ratio_h.GetBinContent(idx_pt) @@ -262,25 +283,35 @@ def convert_binEdges_idx(ed_list, binning): idx_eta, idx_pt, idx_ch, ratio_h.GetBinError(idx_pt) ) if ratio_h.GetBinContent(idx_pt) <= 0.0: - print( - "WARNING - found negative value in bin: ", - idx_eta, - idx_pt, - idx_ch, + logger.info( + "WARNING - found negative value in bin: ({idx_eta}, {idx_pt}, {idx_ch})" ) -boost_out_hist = histutils.root_to_hist(out_hist) +boost_out_hist = narf.root_to_hist(out_hist) +resultDict = {"fakeCorr": boost_out_hist} +base_dir = common.base_dir +resultDict.update( + {"meta_info": wums.output_tools.make_meta_info_dict(args=args, wd=base_dir)} +) -with open(f"{args.outdir}/fakeTransferTemplates.pkl", "wb") as fout: - pickle.dump(boost_out_hist, fout) +outfileName = "fakeTransferTemplates" +if args.postfix: + outfileName += f"_{args.postfix}" +if args.doQCD: + outfileName += "_QCD" -fout = ROOT.TFile( - f"{args.outdir}/fakeTransferTemplates{'' if not args.doQCD else '_QCD'}.root", - "RECREATE", -) -fout.cd() +pklfileName = f"{args.outdir}/{outfileName}.pkl.lz4" +with lz4.frame.open(pklfileName, "wb") as fout: + pickle.dump(resultDict, fout, protocol=pickle.HIGHEST_PROTOCOL) +logger.warning(f"Created file {pklfileName}") + +rootfileName = f"{args.outdir}/{outfileName}.root" +fout = safeOpenFile(rootfileName, mode="RECREATE") out_hist.Write() +fout.Close() +logger.warning(f"Created file {rootfileName}") + """ x_axis = hist.axis.Regular(30, 26, 56, name="pt", flow=False) @@ -309,14 +340,14 @@ def convert_binEdges_idx(ed_list, binning): xLowVal=26.0, xFitRange=30.0, ))) -print(tr_func) -print("Params:", res["x"]) +logger.info(tr_func) +logger.info("Params:", res["x"]) chi2 = res["loss_val"] ndof = len(bincenters) - len(res["x"]) chi2Prob = ROOT.TMath.Prob(chi2, ndof) -print(chi2, ndof, chi2Prob) +logger.info(chi2, ndof, chi2Prob) """ diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 1d99de7d0..44bfc3068 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -284,7 +284,7 @@ ) axis_met = hist.axis.Regular(25, 0.0, 100.0, name="met", underflow=False, overflow=True) axis_mt_testfit = hist.axis.Variable( - (*np.arange(0, mtw_min + 20, 20), *np.arange(mtw_min + 2, 122, 2)), + (*np.arange(0, 40, 20), *np.arange(40, 122, 2)), name="mt", underflow=False, overflow=True, diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 6c5a547e6..093e6b850 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -449,6 +449,16 @@ def make_parser(parser=None): choices=Regressor.polynomials, help="Type of polynomial for the smoothing of the application region or full prediction, depending on the smoothing mode", ) + parser.add_argument( + "--fakeTransferCorrFileName", + type=str, + default="fakeTransferTemplates", + help=""" + Name of pkl.lz4 file (without extension) with pTmu correction for the shape of data-driven fakes. + Currently used only when utAngleSign is a fakerate axis (detected automatically), since the shape + at negative uTmu must be taken from positive bin, but a shape correction is needed versus pTmu. + """, + ) parser.add_argument( "--ABCDedgesByAxis", type=str, @@ -1150,6 +1160,8 @@ def setup( if wmass and not datagroups.xnorm: datagroups.fakerate_axes = args.fakerateAxes + # datagroups.fakeTransferAxis = "utAngleSign" if "utAngleSign" in args.fakerateAxes else "" + # datagroups.fakeTransferCorrFileName = args.fakeTransferCorrFileName histselector_kwargs = dict( mode=args.fakeEstimation, smoothing_mode=args.fakeSmoothingMode, @@ -1159,6 +1171,10 @@ def setup( integrate_x="mt" not in fitvar, forceGlobalScaleFakes=args.forceGlobalScaleFakes, abcdExplicitAxisEdges=abcdExplicitAxisEdges, + fakeTransferAxis=( + "utAngleSign" if "utAngleSign" in args.fakerateAxes else "" + ), + fakeTransferCorrFileName=args.fakeTransferCorrFileName, ) datagroups.set_histselectors( datagroups.getNames(), inputBaseName, **histselector_kwargs diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index df660f7d2..94018f406 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -80,6 +80,7 @@ def __init__(self, infile, mode=None, xnorm=False, **kwargs): self.fit_axes = [] self.fakerate_axes = ["pt", "eta", "charge"] self.fakeTransferAxis = "utAngleSign" + self.fakeTransferCorrFileName = "fakeTransferTemplates" self.setGenAxes() @@ -320,7 +321,6 @@ def set_histselectors( h, global_scalefactor=scale, fakerate_axes=self.fakerate_axes, - fakeTransferAxis=self.fakeTransferAxis, smoothing_mode=smoothing_mode, smoothing_order_fakerate=smoothingOrderFakerate, smoothing_order_spectrum=smoothingOrderSpectrum, diff --git a/wremnants/histselections.py b/wremnants/histselections.py index d080e4801..90b86cb23 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -1,7 +1,7 @@ -import os import pickle import hist +import lz4.frame import numpy as np from scipy import interpolate @@ -127,6 +127,7 @@ def __init__( name_y=None, fakerate_axes=["eta", "pt", "charge"], fakeTransferAxis="", + fakeTransferCorrFileName="fakeTransferTemplates", # only with fakeTransferAxis smoothing_axis_name="pt", rebin_smoothing_axis="automatic", # can be a list of bin edges, "automatic", or None upper_bound_y=None, # using an upper bound on the abcd y-axis (e.g. isolation) @@ -200,6 +201,7 @@ def __init__( self.set_selections_x() self.set_selections_y() self.fakeTransferAxis = fakeTransferAxis + self.fakeTransferCorrFileName = fakeTransferCorrFileName if fakerate_axes is not None: self.fakerate_axes = fakerate_axes # list of axes names where to perform independent fakerate computation @@ -441,13 +443,14 @@ def __init__( self.spectrum_regressor = None if self.fakeTransferAxis in h.axes.name: - logger.debug("Loaded transfer tensor for fakes") - trTensorPath = os.path.join( - os.environ["WREM_BASE"], - "wremnants-data/data/fakesWmass/fakeTransferTemplates.pkl", + data_dir = common.data_dir + trTensorPath = ( + f"{data_dir}/fakesWmass/{self.fakeTransferCorrFileName}.pkl.lz4" ) - with open(trTensorPath, "rb") as fTens: - self.fakeTransferTensor = pickle.load(fTens) + logger.warning(f"Loaded transfer tensor for fakes: {trTensorPath}") + with lz4.frame.open(trTensorPath) as fTens: + resultDict = pickle.load(fTens) + self.fakeTransferTensor = resultDict["fakeCorr"] if self.smoothing_mode in ["binned"]: # rebinning doesn't make sense for binned estimation From ea0dfe2434f691814932ba7b501b3366da6646ac Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 26 Dec 2025 17:52:13 +0100 Subject: [PATCH 18/46] updates --- scripts/plotting/makeDataMCStackPlot.py | 15 ++++++++++++++- scripts/rabbit/setupRabbit.py | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 1d30bc25b..3e2fba60a 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -178,6 +178,16 @@ Axis where the fake prediction on non-valid bins (i.e. where the A-Ax-B-Bx regions are empty) is estimated by using the other 'valid' bins of this axis, via a normalization or shape reweighting.""", ) +parser.add_argument( + "--fakeTransferCorrFileName", + type=str, + default="fakeTransferTemplates", + help=""" + Name of pkl.lz4 file (without extension) with pTmu correction for the shape of data-driven fakes. + Currently used only when utAngleSign is a fakerate axis (detected automatically), since the shape + at negative uTmu must be taken from positive bin, but a shape correction is needed versus pTmu. + """, +) parser.add_argument( "--fineGroups", action="store_true", @@ -386,7 +396,10 @@ def padArray(ref, matchLength): applySelection = True groups.fakerate_axes = args.fakerateAxes -groups.fakeTransferAxis = args.fakeTransferAxis +groups.fakeTransferAxis = ( + args.fakeTransferAxis if "utAngleSign" in args.fakerateAxes else "" +) +groups.fakeTransferCorrFileName = args.fakeTransferCorrFileName if applySelection: groups.set_histselectors( datasets, diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 093e6b850..9cbd1ee3a 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -367,7 +367,9 @@ def make_parser(parser=None): choices=[ "run", "phi", + "utAngleSign", "nRecoVtx", + # variables above, systematics below "prefire", "effi", "lumi", From 2fc7884e8bb8ddb608d0e662e379ec22eec23684 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 28 Dec 2025 18:53:22 +0100 Subject: [PATCH 19/46] set noi=False for polynomial variations --- wremnants/combine_theoryAgnostic_helper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wremnants/combine_theoryAgnostic_helper.py b/wremnants/combine_theoryAgnostic_helper.py index 0e588d170..b7138bcdd 100644 --- a/wremnants/combine_theoryAgnostic_helper.py +++ b/wremnants/combine_theoryAgnostic_helper.py @@ -61,7 +61,7 @@ def add_theoryAgnostic_polVar_uncertainty(self): systAxes=["nPolVarSyst", "downUpVar"], labelsByAxis=["v", "downUpVar"], # splitGroup={f"{groupName}_{coeffKey}" : f"{groupName}_{coeffKey}"}, - noi=True, + # noi=True, ) def add_muRmuF_polVar_uncertainty(self): From 811a7b0dd52ece1012b5e51661028e6bd217edf6 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 28 Dec 2025 18:54:56 +0100 Subject: [PATCH 20/46] fixes and updates to fit uT^mu --- .../w_mass_13TeV/makeEfficiencyCorrection.py | 24 ++++++++++--- scripts/histmakers/mz_wlike_with_mu_eta_pt.py | 35 ++++++++++++++++--- scripts/plotting/plot_decorr_params.py | 8 +++++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py b/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py index 2d906bcc8..05a1917dd 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py +++ b/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py @@ -58,7 +58,7 @@ "--corrvar", type=str, default="run", - choices=["run", "phi"], + choices=["run", "phi", "utAngleSign"], help="Variable to be used for the correction", ) parser.add_argument( @@ -162,6 +162,11 @@ f"{round(corrEdges[i], 2)} < #phi^{{#mu}} < {round(corrEdges[i+1], 2)}" for i in range(nCorrBins) ] + elif args.corrvar == "utAngleSign": + legEntries = [ + "#it{u}_{T}^{#mu} < 0", + "#it{u}_{T}^{#mu} > 0", + ] else: legEntries = [f"{corrvar} bin {i}" for i in range(nCorrBins)] @@ -209,9 +214,20 @@ f"{corrvar}-eta ID = {i} {j}: {round(corr,3)} +/- {round(corr_unc,3)}" ) - title_var = "Run" if corrvar == "run" else "#phi" if corrvar == "phi" else "CorrVar" - - effRange = "0.85,1.05" if corrvar == "run" else "0.80,1.1" + titles = { + "run": "Run", + "phi": "#phi^{#mu}", + "utAngleSign": "sign(#it{u}_{T}^{#mu})", + } + title_var = "CorrVar" + if corrvar in titles.keys(): + title_var = titles[corrvar] + + effrange = "0.80,1.1" + if corrvar == "run": + effRange = "0.85,1.05" + elif corrvar == "utAngleSign": + effRange = "0.8,1.2" for d in datasets: drawNTH1( diff --git a/scripts/histmakers/mz_wlike_with_mu_eta_pt.py b/scripts/histmakers/mz_wlike_with_mu_eta_pt.py index f39abb35e..2ebf0840d 100644 --- a/scripts/histmakers/mz_wlike_with_mu_eta_pt.py +++ b/scripts/histmakers/mz_wlike_with_mu_eta_pt.py @@ -84,6 +84,11 @@ action="store_true", help="Flip even with odd event numbers to consider the positive or negative muon as the W-like muon", ) +parser.add_argument( + "--addAxisSignUt", + action="store_true", + help="Add another fit axis with the sign of the uT recoil projection", +) parser.add_argument( "--useTnpMuonVarForSF", action="store_true", @@ -214,9 +219,21 @@ nominal_axes = [axis_eta, axis_pt, common.axis_charge] nominal_cols = ["trigMuons_eta0", "trigMuons_pt0", "trigMuons_charge0"] +axis_ut_analysis = hist.axis.Regular( + 2, -2, 2, underflow=False, overflow=False, name="utAngleSign" +) # used only to separate positive/negative uT for now +if args.addAxisSignUt: + nominal_axes.append(axis_ut_analysis) + nominal_cols.append( + "nonTrigMuons_angleSignUt0" + if args.fillHistNonTrig + else "trigMuons_angleSignUt0" + ) + # for isoMt region validation and related tests # use very high upper edge as a proxy for infinity (cannot exploit overflow bins in the fit) # can probably use numpy infinity, but this is compatible with the root conversion +# FIXME: now we can probably use overflow bins in the fit axis_mtCat = hist.axis.Variable( [0, int(args.mtCut / 2.0), args.mtCut, 1000], name="mt", @@ -282,7 +299,6 @@ # axes for mT measurement axis_mt = hist.axis.Regular(200, 0.0, 200.0, name="mt", underflow=False, overflow=True) -axis_eta_mT = hist.axis.Variable([-2.4, 2.4], name="eta") # define helpers muon_prefiring_helper, muon_prefiring_helper_stat, muon_prefiring_helper_syst = ( @@ -947,10 +963,12 @@ def build_graph(df, dataset): ########### # utility plots of transverse mass, with or without recoil corrections ########### + muonKey = "nonTrigMuons" if args.fillHistNonTrig else "trigMuons" + muonAntiKey = "trigMuons" if args.fillHistNonTrig else "nonTrigMuons" met_vars = ("MET_pt", "MET_phi") df = df.Define( "transverseMass_uncorr", - f"wrem::get_mt_wlike(trigMuons_pt0, trigMuons_phi0, nonTrigMuons_pt0, nonTrigMuons_phi0, {', '.join(met_vars)})", + f"wrem::get_mt_wlike({muonKey}_pt0, {muonKey}_phi0, {muonAntiKey}_pt0, {muonAntiKey}_phi0, {', '.join(met_vars)})", ) results.append( df.HistoBoost( @@ -963,11 +981,11 @@ def build_graph(df, dataset): met_vars = ("MET_corr_rec_pt", "MET_corr_rec_phi") df = df.Define( "met_wlike_TV2", - f"wrem::get_met_wlike(nonTrigMuons_pt0, nonTrigMuons_phi0, {', '.join(met_vars)})", + f"wrem::get_met_wlike({muonAntiKey}_pt0, {muonAntiKey}_phi0, {', '.join(met_vars)})", ) df = df.Define( "transverseMass", - "wrem::get_mt_wlike(trigMuons_pt0, trigMuons_phi0, met_wlike_TV2)", + f"wrem::get_mt_wlike({muonKey}_pt0, {muonKey}_phi0, met_wlike_TV2)", ) results.append( df.HistoBoost("transverseMass", [axis_mt], ["transverseMass", "nominal_weight"]) @@ -987,6 +1005,13 @@ def build_graph(df, dataset): ["met_wlike_TV2_pt", "nominal_weight"], ) ) + if args.addAxisSignUt: + # use Wlike met instead of only the second lepton, for consistency with the W, + # also because the relevant quantity should be the recoil rather than the boson + df = df.Define( + f"{muonKey}_angleSignUt0", + f"wrem::zqtproj0_angleSign({muonKey}_pt0, {muonKey}_phi0, met_wlike_TV2_pt, met_wlike_TV2.Phi())", + ) ########### df = df.Define("passWlikeMT", f"transverseMass >= {mtw_min}") @@ -1117,7 +1142,7 @@ def build_graph(df, dataset): 6, 0, 2.4, name="abseta", overflow=False, underflow=False ) cols_vertexZstudy = [ - "trigMuons_eta0", + "trigMuons_abseta0", "trigMuons_passIso0", "passWlikeMT", "absDiffGenRecoVtx_z", diff --git a/scripts/plotting/plot_decorr_params.py b/scripts/plotting/plot_decorr_params.py index 32564cc88..879bbacc2 100644 --- a/scripts/plotting/plot_decorr_params.py +++ b/scripts/plotting/plot_decorr_params.py @@ -370,6 +370,14 @@ def get_values_and_impacts_as_panda( df_p["yticks"] = ( df_p["phi"].apply(lambda x: str(axis_ranges[x])).astype(str) ) + elif "utAngleSign" in axes: + axis_ranges = { + 0: rf"$\mathit{{u}}_{{T}}^{{\mu}}$ < 0", + 1: rf"$\mathit{{u}}_{{T}}^{{\mu}}$ > 0", + } + df_p["yticks"] = ( + df_p["utAngleSign"].apply(lambda x: str(axis_ranges[x])).astype(str) + ) elif "nRecoVtx" in axes: nRecoVtxBins = df.shape[0] if nRecoVtxBins == 5: From ba08ba70d60d5d134f1a01801bed0871b108607f Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 28 Dec 2025 18:57:19 +0100 Subject: [PATCH 21/46] foo --- scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py b/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py index 05a1917dd..0ed014065 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py +++ b/scripts/analysisTools/w_mass_13TeV/makeEfficiencyCorrection.py @@ -180,7 +180,7 @@ sign = "minus" if args.charge < 0 else "plus" chargePostfix = f"_{sign}" - # create a TH2 and convrt into boost again to save it + # create a TH2 and convert into boost again to save it nx = heffiroot["Data"][0].GetNbinsX() xmin = heffiroot["Data"][0].GetXaxis().GetBinLowEdge(1) xmax = heffiroot["Data"][0].GetXaxis().GetBinLowEdge(1 + nx) From 4d1e7b505d8bddae577d3a77acfa0a72aba005e2 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 31 Dec 2025 17:28:18 +0100 Subject: [PATCH 22/46] fixes --- scripts/plotting/makeDataMCStackPlot.py | 6 ++++-- scripts/rabbit/setupRabbit.py | 19 +++++++++++++++---- wremnants/datasets/datagroups.py | 7 +++++++ wremnants/datasets/datasetDict_v9.py | 1 + wremnants/histselections.py | 16 +++++++++++++++- 5 files changed, 42 insertions(+), 7 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 3e2fba60a..880379ae3 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -386,9 +386,10 @@ def padArray(ref, matchLength): select[axis] = int(value) applySelection = ( False - if any( # does not trigger ABCD fake estimation if a cut is applied on the variables used to define ABCD regions + # do not trigger ABCD method if a cut is applied on the variables defining the ABCD regions + if any( abcd_var in [cut_str.split("=")[0] for cut_str in args.selection.split(",")] - for abcd_var in ["relIso", "mt"] + for abcd_var in ["relIso", "mt", "passMT", "passIso"] ) else True ) @@ -400,6 +401,7 @@ def padArray(ref, matchLength): args.fakeTransferAxis if "utAngleSign" in args.fakerateAxes else "" ) groups.fakeTransferCorrFileName = args.fakeTransferCorrFileName +groups.histAxesRemovedBeforeFakes = [str(x.split("=")[0]) for x in args.presel] if applySelection: groups.set_histselectors( datasets, diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 9cbd1ee3a..8246f63f0 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -994,7 +994,10 @@ def setup( if massConstraintMode == "automatic": constrainMass = ( - "xsec" in args.noi or (dilepton and not "mll" in fitvar) or genfit + "xsec" in args.noi + or (dilepton and not "mll" in fitvar) + or genfit + or (wmass and "wmass" not in args.noi) ) else: constrainMass = True if massConstraintMode == "constrained" else False @@ -1177,6 +1180,9 @@ def setup( "utAngleSign" if "utAngleSign" in args.fakerateAxes else "" ), fakeTransferCorrFileName=args.fakeTransferCorrFileName, + histAxesRemovedBeforeFakes=( + [str(x.split()[0]) for x in args.selection] if args.selection else [] + ), ) datagroups.set_histselectors( datagroups.getNames(), inputBaseName, **histselector_kwargs @@ -1613,15 +1619,20 @@ def setup( if wmass and ("wwidth" in args.noi or (not stat_only and not args.noTheoryUnc)): width_info = dict( - name="WidthW0p6MeV", + # 42, 'widthW2p043GeV', 'widthW2p127GeV' + # 0p6, 'widthW2p09053GeV', 'widthW2p09173GeV' + # name="WidthW0p6MeV", + name="WidthW42MeV", processes=signal_samples_forMass, groups=["widthW", "theory"], mirror=False, noi="wwidth" in args.noi, noConstraint="wwidth" in args.noi, - skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), + # skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), + skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), systAxes=["width"], - systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], + # systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], + systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], passToFakes=passSystToFakes, ) widthWeightName = f"widthWeight{label}" diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index 94018f406..91c8ba04c 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -81,6 +81,13 @@ def __init__(self, infile, mode=None, xnorm=False, **kwargs): self.fakerate_axes = ["pt", "eta", "charge"] self.fakeTransferAxis = "utAngleSign" self.fakeTransferCorrFileName = "fakeTransferTemplates" + # in case some fit axes are integrated out, to make full smoothing work, + # we need to warn the class that these don't belong to fit axes nor fakerate axes, + # but are also not "integration axes" because they are removed before entering + # the fake estimate, this can happen for example + # with option --select in setupRabbit.py or --presel in makeDataMCStackPlot.py, + # which slice and remove the axis + self.histAxesRemovedBeforeFakes = [] self.setGenAxes() diff --git a/wremnants/datasets/datasetDict_v9.py b/wremnants/datasets/datasetDict_v9.py index ba178746c..0838e35ca 100644 --- a/wremnants/datasets/datasetDict_v9.py +++ b/wremnants/datasets/datasetDict_v9.py @@ -28,6 +28,7 @@ "DYJetsToMuMuMass10to50PostVFP": { "filepaths": [ "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos/NanoV9MCPostVFP_{NANO_PROD_TAG}", + # "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", ], "xsec": common.xsec_DYJetsToMuMuMass10to50, "group": "DYlowMass", diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 90b86cb23..0c7336b61 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -128,6 +128,11 @@ def __init__( fakerate_axes=["eta", "pt", "charge"], fakeTransferAxis="", fakeTransferCorrFileName="fakeTransferTemplates", # only with fakeTransferAxis + # histAxesRemovedBeforeFakes is needed when some axes are in the histograms, + # but are not supposed to be fit or used as fakerate axes, and are sliced/integrated and removed + # before computing the fakes, so they are technically not "fake integration axes", which is + # needed to make the full smoothing work (integration axes within the method are not implemented) + histAxesRemovedBeforeFakes=[], smoothing_axis_name="pt", rebin_smoothing_axis="automatic", # can be a list of bin edges, "automatic", or None upper_bound_y=None, # using an upper bound on the abcd y-axis (e.g. isolation) @@ -202,6 +207,7 @@ def __init__( self.set_selections_y() self.fakeTransferAxis = fakeTransferAxis self.fakeTransferCorrFileName = fakeTransferCorrFileName + self.histAxesRemovedBeforeFakes = histAxesRemovedBeforeFakes if fakerate_axes is not None: self.fakerate_axes = fakerate_axes # list of axes names where to perform independent fakerate computation @@ -209,11 +215,19 @@ def __init__( n for n in h.axes.name if n - not in [self.name_x, self.name_y, *fakerate_axes, self.fakeTransferAxis] + not in [ + self.name_x, + self.name_y, + *fakerate_axes, + *histAxesRemovedBeforeFakes, + ] ] logger.debug( f"Setting fakerate integration axes to {self.fakerate_integration_axes}" ) + logger.debug(f"histAxesRemovedBeforeFakes = {histAxesRemovedBeforeFakes}") + logger.debug(f"fakerate_integration_axes = {self.fakerate_integration_axes}") + self.smoothing_axis_name = smoothing_axis_name edges = h.axes[smoothing_axis_name].edges if rebin_smoothing_axis == "automatic": From ea60c341f33d7fb23fe4f95615eaa844c9be5ebc Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Tue, 6 Jan 2026 18:46:02 +0100 Subject: [PATCH 23/46] fixes --- scripts/plotting/makeDataMCStackPlot.py | 26 +++++++++++++++++-------- scripts/rabbit/setupRabbit.py | 5 ++++- utilities/parsing.py | 5 +++++ utilities/styles/styles.py | 19 ++++++++++++++++-- wremnants/histselections.py | 5 ++++- 5 files changed, 48 insertions(+), 12 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 880379ae3..94f64a9f2 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -335,12 +335,12 @@ def padArray(ref, matchLength): if "=" in ps: axName, axRange = ps.split("=") if "," in ps: - # axMin, axMax = map(float, axRange.split(",")) axMin, axMax = [ - float(p) if p != str() else None for p in axRange.split(",") + complex(0, float(p)) if p != str() else None + for p in axRange.split(",") ] logger.info(f"{axName} in [{axMin},{axMax}]") - presel[axName] = s[complex(0, axMin) : complex(0, axMax) : hist.sum] + presel[axName] = s[axMin : axMax : hist.sum] else: logger.info(f"Selecting {axName} {axRange.split('.')[1]}") if axRange == "hist.overflow": @@ -397,11 +397,13 @@ def padArray(ref, matchLength): applySelection = True groups.fakerate_axes = args.fakerateAxes -groups.fakeTransferAxis = ( - args.fakeTransferAxis if "utAngleSign" in args.fakerateAxes else "" +histselector_kwargs = dict( + fakeTransferAxis=( + args.fakeTransferAxis if args.fakeTransferAxis in args.fakerateAxes else "" + ), + fakeTransferCorrFileName=args.fakeTransferCorrFileName, + histAxesRemovedBeforeFakes=[str(x.split("=")[0]) for x in args.presel], ) -groups.fakeTransferCorrFileName = args.fakeTransferCorrFileName -groups.histAxesRemovedBeforeFakes = [str(x.split("=")[0]) for x in args.presel] if applySelection: groups.set_histselectors( datasets, @@ -413,6 +415,7 @@ def padArray(ref, matchLength): mode=args.fakeEstimation, forceGlobalScaleFakes=args.forceGlobalScaleFakes, mcCorr=args.fakeMCCorr, + **histselector_kwargs, ) if not args.nominalRef: @@ -568,6 +571,9 @@ def collapseSyst(h): else: binwnorm = None ylabel = r"$Events\,/\,bin$" + if args.noBinWidthNorm: + binwnorm = None + ylabel = r"$Events\,/\,bin$" if args.rlabel is None: if args.noData: @@ -632,7 +638,11 @@ def collapseSyst(h): normalize_to_data=args.normToData, noSci=args.noSciy, logoPos=args.logoPos, - width_scale=1.25 if len(h.split("-")) == 1 else 1, + width_scale=( + args.customFigureWidth + if args.customFigureWidth + else 1.25 if len(h.split("-")) == 1 else 1 + ), legPos=args.legPos, leg_padding=args.legPadding, lowerLeg=not args.noLowerLeg, diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 8246f63f0..2b0ccf3ef 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -875,7 +875,7 @@ def make_parser(parser=None): parser.add_argument( "--breitwignerWMassWeights", action="store_true", - help="Use the Breit-Wigner mass wights for mW.", + help="Use the Breit-Wigner mass weights for mW.", ) parser = make_subparsers(parser) @@ -1623,6 +1623,7 @@ def setup( # 0p6, 'widthW2p09053GeV', 'widthW2p09173GeV' # name="WidthW0p6MeV", name="WidthW42MeV", + # name="WidthWm6p36MeV", processes=signal_samples_forMass, groups=["widthW", "theory"], mirror=False, @@ -1630,9 +1631,11 @@ def setup( noConstraint="wwidth" in args.noi, # skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), + # skipEntries=widthWeightNames(proc="W", exclude=(2.085, 2.127)), systAxes=["width"], # systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], + # systNameReplace=[["2p085GeV", "Down"], ["2p127GeV", "Up"]], passToFakes=passSystToFakes, ) widthWeightName = f"widthWeight{label}" diff --git a/utilities/parsing.py b/utilities/parsing.py index 5918d74b4..f1a716f92 100644 --- a/utilities/parsing.py +++ b/utilities/parsing.py @@ -916,5 +916,10 @@ def plot_parser(): default=None, help="Use a custom figure width, otherwise chosen automatic", ) + parser.add_argument( + "--noBinWidthNorm", + action="store_true", + help="Do not normalize bin yields by bin width", + ) return parser diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index 51306c48d..d5baca537 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -300,6 +300,8 @@ def translate_html_to_latex(n): "angularCoeffs_A6", "angularCoeffs_A7", "pdfCT18Z", + "pdfCT18ZNoAlphaS", + "pdfCT18ZAlphaS", "pTModeling", "muon_eff_syst", "muon_eff_stat", @@ -343,6 +345,18 @@ def translate_html_to_latex(n): "normZ_Helicity3", "normZ_Helicity4", ], + "width": common_groups + + [ + "angularCoeffs", + "pdfCT18Z", + "pTModeling", + "muon_eff_syst", + "muon_eff_stat", + "prefire", + "muonCalibration", + "Fake", + "massShift", + ], "min": common_groups + [ "massShiftW", @@ -525,12 +539,13 @@ def translate_html_to_latex(n): "FakeeLowMT": "FakeLowMT", "massShiftZ": "Z boson mass", "massShiftW": "W boson mass", + "massShift": "W boson mass", "pdfMSHT20": "PDF", "pdfCT18Z": "PDF", - "pdfMSHT20NoAlphaS": "PDF", + "pdfMSHT20NoAlphaS": "PDF no αS", "pdfMSHT20AlphaS": "αS PDF", "pdfCT18ZAlphaS": "αS PDF", - "pdfCT18ZNoAlphaS": "PDF", + "pdfCT18ZNoAlphaS": "PDF no αS", "pTModeling": "pTV modelling", "resum": "Resummation", "resumTNP": "Non pert. trans.", diff --git a/wremnants/histselections.py b/wremnants/histselections.py index 0c7336b61..c2a6ec9e1 100644 --- a/wremnants/histselections.py +++ b/wremnants/histselections.py @@ -471,7 +471,10 @@ def __init__( self.rebin_smoothing_axis = None if hasattr(self, "fakerate_integration_axes"): - if smoothing_mode == "full" and self.fakerate_integration_axes: + logger.warning( + f"self.fakerate_integration_axes = {self.fakerate_integration_axes}" + ) + if smoothing_mode == "full" and len(self.fakerate_integration_axes): raise NotImplementedError( "Smoothing of full fake prediction is not currently supported together with integration axes." ) From 1cd1a13ae6a39008fcde8ec855206c6ee63eab64 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 7 Jan 2026 19:50:59 +0100 Subject: [PATCH 24/46] set default W width variation to original 0.6 MeV --- scripts/rabbit/setupRabbit.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 2b0ccf3ef..281423d76 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -1621,20 +1621,20 @@ def setup( width_info = dict( # 42, 'widthW2p043GeV', 'widthW2p127GeV' # 0p6, 'widthW2p09053GeV', 'widthW2p09173GeV' - # name="WidthW0p6MeV", - name="WidthW42MeV", + name="WidthW0p6MeV", + # name="WidthW42MeV", # name="WidthWm6p36MeV", processes=signal_samples_forMass, groups=["widthW", "theory"], mirror=False, noi="wwidth" in args.noi, noConstraint="wwidth" in args.noi, - # skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), - skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), + skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), + # skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), # skipEntries=widthWeightNames(proc="W", exclude=(2.085, 2.127)), systAxes=["width"], - # systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], - systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], + systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], + # systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], # systNameReplace=[["2p085GeV", "Down"], ["2p127GeV", "Up"]], passToFakes=passSystToFakes, ) From 98d150a742f702b76952f0a863a40239c2b463ee Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 11 Jan 2026 17:18:38 +0100 Subject: [PATCH 25/46] updates --- scripts/histmakers/mw_with_mu_eta_pt.py | 286 +++++------------------- scripts/rabbit/setupRabbit.py | 248 ++++++++++++++------ utilities/parsing.py | 2 +- wremnants/combine_helpers.py | 25 +-- wremnants/datasets/datasetDict_v9.py | 2 +- wremnants/recoil_tools.py | 9 +- 6 files changed, 263 insertions(+), 309 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 44bfc3068..bbedae951 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -132,11 +132,6 @@ action="store_true", help="Add another fit axis with the sign of the uT recoil projection", ) -parser.add_argument( - "--addAxisMt", - action="store_true", - help="Add another fit axis with mT", -) parser.add_argument( "--utAngleCosineCut", nargs=2, @@ -283,12 +278,6 @@ overflow=True, ) axis_met = hist.axis.Regular(25, 0.0, 100.0, name="met", underflow=False, overflow=True) -axis_mt_testfit = hist.axis.Variable( - (*np.arange(0, 40, 20), *np.arange(40, 122, 2)), - name="mt", - underflow=False, - overflow=True, -) # for mt, met, ptW plots, to compute the fakes properly (but FR pretty stable vs pt and also vs eta) # may not exactly reproduce the same pt range as analysis, though @@ -347,24 +336,6 @@ nominal_axes = [axis_eta, axis_pt, axis_charge, axis_ut_analysis, *axes_abcd] nominal_cols = columns_fakerate -elif args.addAxisMt: - axes_fakerate = [ - axis_fakes_eta, - axis_fakes_pt, - axis_charge, - axis_mt_testfit, - axis_isoCat, - ] - columns_fakerate = [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "transverseMass", - "goodMuons_relIso0", - ] - - nominal_axes = [axis_eta, axis_pt, axis_charge, axis_mt_testfit, axis_isoCat] - nominal_cols = columns_fakerate else: axes_fakerate = [axis_fakes_eta, axis_fakes_pt, axis_charge, *axes_abcd] columns_fakerate = [ @@ -490,27 +461,6 @@ axis_dphi_fakes = hist.axis.Regular( 8, 0.0, np.pi, name="DphiMuonMet", underflow=False, overflow=False ) -# filled with 1 - cos, as in mT and such that W peaks at +2 -axis_oneMinusCosdphi = hist.axis.Regular( - 20, 0.0, 2.0, name="oneMinusCosdphi", underflow=False, overflow=False -) -axis_metOverPt = hist.axis.Regular( - 40, 0.0, 2.0, name="metOverPt", underflow=False, overflow=True -) -axis_mtOverPt = hist.axis.Regular( - 80, 0.0, 4.0, name="mtOverPt", underflow=False, overflow=True -) -axis_altMt = hist.axis.Regular( - 120, 0.0, 120.0, name="altMt", underflow=False, overflow=True -) -axis_dxybs = hist.axis.Regular( - int(args.dxybs / 0.002), - 0.0, - args.dxybs, - name="dxybs", - underflow=False, - overflow=True, -) axis_hasjet_fakes = hist.axis.Boolean( name="hasJets" ) # only need case with 0 jets or > 0 for now @@ -523,38 +473,6 @@ axis_hasjet_fakes, axis_dphi_fakes, ] -mTStudyForFakesAlt_axes = [ - axis_eta, - axis_pt, - axis_charge, - axis_oneMinusCosdphi, - axis_passIso, - axis_passMT, -] -mTStudyForFakesAlt2_axes = [ - axis_eta, - axis_pt, - axis_charge, - axis_mtOverPt, - axis_passIso, - axis_passMT, -] -mTStudyForFakesAlt3_axes = [ - axis_eta, - axis_pt, - axis_charge, - axis_altMt, - axis_passIso, - axis_passMT, -] -mTStudyForFakesAlt4_axes = [ - axis_eta, - axis_pt, - axis_charge, - axis_dxybs, - axis_passIso, - axis_passMT, -] axis_met = hist.axis.Regular( 100, 0.0, 200.0, name="met", underflow=False, overflow=True @@ -709,25 +627,25 @@ filePath=args.theoryAgnosticFilePath, ) -# Helper for muR and muF as polynomial variations -muRmuFPolVar_helpers_minus = makehelicityWeightHelper_polvar( - genVcharge=-1, - fileTag=args.muRmuFPolVarFileTag, - filePath=args.muRmuFPolVarFilePath, - noUL=True, -) -muRmuFPolVar_helpers_plus = makehelicityWeightHelper_polvar( - genVcharge=1, - fileTag=args.muRmuFPolVarFileTag, - filePath=args.muRmuFPolVarFilePath, - noUL=True, -) -muRmuFPolVar_helpers_Z = makehelicityWeightHelper_polvar( - genVcharge=0, - fileTag=args.muRmuFPolVarFileTag, - filePath=args.muRmuFPolVarFilePath, - noUL=True, -) +# # Helper for muR and muF as polynomial variations +# muRmuFPolVar_helpers_minus = makehelicityWeightHelper_polvar( +# genVcharge=-1, +# fileTag=args.muRmuFPolVarFileTag, +# filePath=args.muRmuFPolVarFilePath, +# noUL=True, +# ) +# muRmuFPolVar_helpers_plus = makehelicityWeightHelper_polvar( +# genVcharge=1, +# fileTag=args.muRmuFPolVarFileTag, +# filePath=args.muRmuFPolVarFilePath, +# noUL=True, +# ) +# muRmuFPolVar_helpers_Z = makehelicityWeightHelper_polvar( +# genVcharge=0, +# fileTag=args.muRmuFPolVarFileTag, +# filePath=args.muRmuFPolVarFilePath, +# noUL=True, +# ) # recoil initialization if not args.noRecoil: @@ -1717,23 +1635,6 @@ def build_graph(df, dataset): # instead of passIso in mTStudyForFakes # df = df.Define("passIsoAlt", "(goodMuons_pfRelIso04_all0 * Muon_pt[goodMuons][0] / goodMuons_jetpt0) < 0.12") # df = df.Define("passIsoAlt", "(Muon_vtxAgnPfRelIso04_chg[goodMuons][0] * Muon_pt[goodMuons][0]) < 5.0") - - df = df.Define( - # fill with 1 - cos so that W signal is at +1 instead of -1, for convenience - "goodMuons_oneMinusCosdphiMuMet0", - "1.0 - std::cos(goodMuons_dphiMuMet0)", - ) - df = df.Define("goodMuons_metOverPt0", "MET_corr_rec_pt/goodMuons_pt0") - df = df.Define("goodMuons_mtOverPt0", "transverseMass/goodMuons_pt0") - df = df.Define( - "goodMuons_altMt0", "MET_corr_rec_pt*goodMuons_oneMinusCosdphiMuMet0" - ) - # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 - # for convenience in the later study - df = df.Define( - "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" - ) - mTStudyForFakes = df.HistoBoost( "mTStudyForFakes", mTStudyForFakes_axes, @@ -1750,66 +1651,6 @@ def build_graph(df, dataset): ) results.append(mTStudyForFakes) - mTStudyForFakesAlt = df.HistoBoost( - "mTStudyForFakesAlt", - mTStudyForFakesAlt_axes, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_oneMinusCosdphiMuMet0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(mTStudyForFakesAlt) - - mTStudyForFakesAlt2 = df.HistoBoost( - "mTStudyForFakesAlt2", - mTStudyForFakesAlt2_axes, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_mtOverPt0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(mTStudyForFakesAlt2) - - mTStudyForFakesAlt3 = df.HistoBoost( - "mTStudyForFakesAlt3", - mTStudyForFakesAlt3_axes, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_altMt0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(mTStudyForFakesAlt3) - - mTStudyForFakesAlt4 = df.HistoBoost( - "mTStudyForFakesAlt4", - mTStudyForFakesAlt4_axes, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_dxybs0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(mTStudyForFakesAlt4) - # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: dphiMuonMetCut = args.dphiMuonMetCut * np.pi @@ -1848,13 +1689,6 @@ def build_graph(df, dataset): ["goodMuons_dphiMuMet0", *columns_fakerate, "nominal_weight"], ) ) - results.append( - df.HistoBoost( - "metOverPt", - [axis_metOverPt, *axes_fakerate], - ["goodMuons_metOverPt0", *columns_fakerate, "nominal_weight"], - ) - ) results.append( df.HistoBoost( "ptW", @@ -2001,47 +1835,47 @@ def build_graph(df, dataset): nominal_cols, ) - if isWorZ and not hasattr(dataset, "out_of_acceptance"): - theoryAgnostic_helpers_cols = [ - "qtOverQ", - "absYVgen", - "chargeVgen", - "csSineCosThetaPhigen", - "nominal_weight", - ] - # assume to have same coeffs for plus and minus (no reason for it not to be the case) - if dataset.name in ["WplusmunuPostVFP", "WplustaunuPostVFP"]: - helpers_class = muRmuFPolVar_helpers_plus - process_name = "W" - elif dataset.name in ["WminusmunuPostVFP", "WminustaunuPostVFP"]: - helpers_class = muRmuFPolVar_helpers_minus - process_name = "W" - elif dataset.name in ["ZmumuPostVFP", "ZtautauPostVFP"]: - helpers_class = muRmuFPolVar_helpers_Z - process_name = "Z" - else: - helpers_class = {} - - for coeffKey in helpers_class.keys(): - logger.debug( - f"Creating muR/muF histograms with polynomial variations for {coeffKey}" - ) - helperQ = helpers_class[coeffKey] - df = df.Define( - f"muRmuFPolVar_{coeffKey}_tensor", helperQ, theoryAgnostic_helpers_cols - ) - muRmuFWithPolHistName = Datagroups.histName( - "nominal", syst=f"muRmuFPolVar{process_name}_{coeffKey}" - ) - results.append( - df.HistoBoost( - muRmuFWithPolHistName, - nominal_axes, - [*nominal_cols, f"muRmuFPolVar_{coeffKey}_tensor"], - tensor_axes=helperQ.tensor_axes, - storage=hist.storage.Double(), - ) - ) + # if isWorZ and not hasattr(dataset, "out_of_acceptance"): + # theoryAgnostic_helpers_cols = [ + # "qtOverQ", + # "absYVgen", + # "chargeVgen", + # "csSineCosThetaPhigen", + # "nominal_weight", + # ] + # # assume to have same coeffs for plus and minus (no reason for it not to be the case) + # if dataset.name in ["WplusmunuPostVFP", "WplustaunuPostVFP"]: + # helpers_class = muRmuFPolVar_helpers_plus + # process_name = "W" + # elif dataset.name in ["WminusmunuPostVFP", "WminustaunuPostVFP"]: + # helpers_class = muRmuFPolVar_helpers_minus + # process_name = "W" + # elif dataset.name in ["ZmumuPostVFP", "ZtautauPostVFP"]: + # helpers_class = muRmuFPolVar_helpers_Z + # process_name = "Z" + # else: + # helpers_class = {} + + # for coeffKey in helpers_class.keys(): + # logger.debug( + # f"Creating muR/muF histograms with polynomial variations for {coeffKey}" + # ) + # helperQ = helpers_class[coeffKey] + # df = df.Define( + # f"muRmuFPolVar_{coeffKey}_tensor", helperQ, theoryAgnostic_helpers_cols + # ) + # muRmuFWithPolHistName = Datagroups.histName( + # "nominal", syst=f"muRmuFPolVar{process_name}_{coeffKey}" + # ) + # results.append( + # df.HistoBoost( + # muRmuFWithPolHistName, + # nominal_axes, + # [*nominal_cols, f"muRmuFPolVar_{coeffKey}_tensor"], + # tensor_axes=helperQ.tensor_axes, + # storage=hist.storage.Double(), + # ) + # ) if not args.onlyMainHistograms: syst_tools.add_QCDbkg_jetPt_hist( diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 2b0ccf3ef..3e9679072 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -687,6 +687,12 @@ def make_parser(parser=None): default=None, help="Rescale equivalent luminosity for efficiency stat uncertainty by this value (e.g. 10 means ten times more data from tag and probe)", ) + parser.add_argument( + "--effSystScale", + type=float, + default=1.0, + help="Rescale efficiency systematic uncertainty by this value", + ) parser.add_argument( "--binnedScaleFactors", action="store_true", @@ -1618,25 +1624,32 @@ def setup( ) if wmass and ("wwidth" in args.noi or (not stat_only and not args.noTheoryUnc)): - width_info = dict( - # 42, 'widthW2p043GeV', 'widthW2p127GeV' - # 0p6, 'widthW2p09053GeV', 'widthW2p09173GeV' - # name="WidthW0p6MeV", - name="WidthW42MeV", + if "wwidth" in args.noi: + width_info = dict( + name="WidthW42MeV", + skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), + systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], + ) # name="WidthWm6p36MeV", - processes=signal_samples_forMass, - groups=["widthW", "theory"], - mirror=False, - noi="wwidth" in args.noi, - noConstraint="wwidth" in args.noi, # skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), - skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), - # skipEntries=widthWeightNames(proc="W", exclude=(2.085, 2.127)), - systAxes=["width"], # systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], - systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], - # systNameReplace=[["2p085GeV", "Down"], ["2p127GeV", "Up"]], - passToFakes=passSystToFakes, + else: + width_info = dict( + name="WidthW0p6MeV", + skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), + systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], + ) + + width_info.update( + dict( + processes=signal_samples_forMass, + groups=["widthW", "theory"], + mirror=False, + noi="wwidth" in args.noi, + noConstraint="wwidth" in args.noi, + systAxes=["width"], + passToFakes=passSystToFakes, + ) ) widthWeightName = f"widthWeight{label}" if args.breitwignerWMassWeights: @@ -2123,19 +2136,37 @@ def fake_nonclosure( if "utAngleSign" in fitvar: # TODO: extend and use previous function fake_nonclosure(...) - def fake_nonclosure_utMinus( + def fake_nonclosure_byAxis( h, axesToDecorrNames=["eta"], variation_size=0.1, + keepConstantAxisBin={}, *args, **kwargs, ): - logger.debug("Doing decorr nonclosure for utMinus") + + # with keepConstantAxisBin one can keep a range of bins untouched by passing slice(start, stop) + # e.g. keepConstantAxisBin={"utAngleSign": slice(1, 2)}, maybe also by values with complex numbers + + logger.debug( + f"Doing decorr nonclosure with keepConstantAxisBin={keepConstantAxisBin}" + ) hnom = fakeselector.get_hist(h, *args, **kwargs) hvar = (1 + variation_size) * hnom - # applying the variations only on the utAngleSign<0 bin + ## applying the variations only on the utAngleSign<0 bin ## TODO: select axis by name and bin id by input argument - hvar.values()[..., -1] = hnom.values()[..., -1] + # hvar.values()[..., -1] = hnom.values()[..., -1] + if keepConstantAxisBin: + ax_names = [n for n in hvar.axes.name] + for name in keepConstantAxisBin.keys(): + if name not in ax_names: + raise ValueError( + f"In fake_nonclosure_byAxis(): axis '{name}' not found in hvar, valid names are {ax_names}" + ) + ax_index = ax_names.index(name) + idxs = [slice(None)] * hvar.ndim + idxs[ax_index] = keepConstantAxisBin[name] + hvar.values()[tuple(idxs)] = hnom.values()[tuple(idxs)] hvar = syst_tools.decorrelateByAxes(hvar, hnom, axesToDecorrNames) @@ -2151,10 +2182,11 @@ def fake_nonclosure_utMinus( mirror=True, scale=1, applySelection=False, # don't apply selection, external parameters need to be added - action=fake_nonclosure_utMinus, + action=fake_nonclosure_byAxis, actionArgs=dict( axesToDecorrNames=["eta"], variation_size=0.1, + keepConstantAxisBin={"utAngleSign": 1}, ), systAxes=["eta_decorr"], ) @@ -2164,7 +2196,8 @@ def fake_nonclosure_utMinus( if not lowPU: chargeDependentSteps = common.muonEfficiency_chargeDependentSteps - effTypesNoIso = ["reco", "tracking", "idip", "trigger"] + effTypesNoUt = ["reco", "tracking", "idip"] + effTypesNoIso = [*effTypesNoUt, "trigger"] effStatTypes = [x for x in effTypesNoIso] if args.binnedScaleFactors or not args.isoEfficiencySmoothing: effStatTypes.extend(["iso"]) @@ -2173,6 +2206,14 @@ def fake_nonclosure_utMinus( allEffTnP = [f"effStatTnP_sf_{eff}" for eff in effStatTypes] + [ "effSystTnP" ] + effTypesUt = [x for x in effStatTypes if x not in effTypesNoUt] + effSystTypes = [*effTypesNoIso, "iso"] + effCommonGroups = [ + "muon_eff_all", + "experiment", + "expNoLumi", + "expNoCalib", + ] for name in allEffTnP: if "Syst" in name: axes = ["reco-tracking-idip-trigger-iso", "n_syst_variations"] @@ -2186,29 +2227,113 @@ def fake_nonclosure_utMinus( ("effSystTnP", "effSyst"), ("etaDecorr0", "fullyCorr"), ] - scale = 1 mirror = True groupName = "muon_eff_syst" - splitGroupDict = { - f"{groupName}_{x}": f".*effSyst.*{x}" - for x in list(effTypesNoIso + ["iso"]) - } + scale = args.effSystScale actionSF = None effActionArgs = {} if ( any(x in args.decorrSystByVar for x in ["effi", "effisyst"]) - and decorr_syst_var in fitvar + and "utAngleSign" in fitvar + and decorr_syst_var == "utAngleSign" ): - axes = [ - "reco-tracking-idip-trigger-iso", - "n_syst_variations", - f"{decorr_syst_var}_", - ] - axlabels = ["WPSYST", "_etaDecorr", decorr_syst_var] - actionSF = syst_tools.decorrelateByAxes - effActionArgs = dict( - axesToDecorrNames=[decorr_syst_var], - newDecorrAxesNames=[f"{decorr_syst_var}_"], + logger.warning( + "'utAngleSign' is a fit axis, effSyst will be decorrelated by it" + ) + logger.warning( + "but only for trigger/isolation steps (others are kept correlated)" + ) + logger.warning( + "with an additional scaling of their magnitude by sqrt(2)" + ) + # if "utAngleSign" in fitvar and decorr_syst_var == "utAngleSign": + # then decorrelate only for trigger and iso + # this is because the effSyst were derived inclusively in uT + # but it was impossible to measure them in bins of uT, + # so we dont't really know if they are flat vs uT or not. + # This also includes an additional inflation by sqrt(2) for trigger/isolation + # + # reco-tracking-idip + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup={ + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effTypesNoUt) + }, + systAxes=axes, + labelsByAxis=axlabels, + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale, + skipEntries=[{"reco-tracking-idip-trigger-iso": [3, 4]}], + ) + # trigger-isolation + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup={ + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effTypesUt) + }, + systAxes=[ + "reco-tracking-idip-trigger-iso", + "n_syst_variations", + f"{decorr_syst_var}_", + ], + labelsByAxis=["WPSYST", "_etaDecorr", decorr_syst_var], + actionRequiresNomi=True, + action=syst_tools.decorrelateByAxes, + actionArgs=dict( + axesToDecorrNames=[decorr_syst_var], + newDecorrAxesNames=[f"{decorr_syst_var}_"], + ), + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale * np.sqrt(2), + skipEntries=[{"reco-tracking-idip-trigger-iso": [0, 1, 2]}], + ) + else: + splitGroupDict = { + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effSystTypes) + } + if ( + any(x in args.decorrSystByVar for x in ["effi", "effisyst"]) + and decorr_syst_var in fitvar + ): + axes = [ + "reco-tracking-idip-trigger-iso", + "n_syst_variations", + f"{decorr_syst_var}_", + ] + axlabels = ["WPSYST", "_etaDecorr", decorr_syst_var] + actionSF = syst_tools.decorrelateByAxes + effActionArgs = dict( + axesToDecorrNames=[decorr_syst_var], + newDecorrAxesNames=[f"{decorr_syst_var}_"], + ) + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup=splitGroupDict, + systAxes=axes, + labelsByAxis=axlabels, + actionRequiresNomi=True, + action=actionSF, + actionArgs=effActionArgs, + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale, ) else: nameReplace = ( @@ -2243,31 +2368,25 @@ def fake_nonclosure_utMinus( axesToDecorrNames=[decorr_syst_var], newDecorrAxesNames=[f"{decorr_syst_var}_"], ) - if args.effStatLumiScale and "Syst" not in name: - scale /= math.sqrt(args.effStatLumiScale) + if args.effStatLumiScale and "Syst" not in name: + scale /= math.sqrt(args.effStatLumiScale) - datagroups.addSystematic( - name, - mirror=mirror, - groups=[ - groupName, - "muon_eff_all", - "experiment", - "expNoLumi", - "expNoCalib", - ], - splitGroup=splitGroupDict, - systAxes=axes, - labelsByAxis=axlabels, - actionRequiresNomi=True, - action=actionSF, - actionArgs=effActionArgs, - baseName=name + "_", - processes=["MCnoQCD"], - passToFakes=passSystToFakes, - systNameReplace=nameReplace, - scale=scale, - ) + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup=splitGroupDict, + systAxes=axes, + labelsByAxis=axlabels, + actionRequiresNomi=True, + action=actionSF, + actionArgs=effActionArgs, + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale, + ) # now add other systematics if present if name == "effSystTnP": for es in common.muonEfficiency_altBkgSyst_effSteps: @@ -2277,10 +2396,7 @@ def fake_nonclosure_utMinus( groups=[ f"muon_eff_syst_{es}_altBkg", groupName, - "muon_eff_all", - "experiment", - "expNoLumi", - "expNoCalib", + *effCommonGroups, ], systAxes=["n_syst_variations"], labelsByAxis=[f"{es}_altBkg_etaDecorr"], diff --git a/utilities/parsing.py b/utilities/parsing.py index f1a716f92..ab1cafd67 100644 --- a/utilities/parsing.py +++ b/utilities/parsing.py @@ -190,7 +190,7 @@ def __call__(self, parser, namespace, values, option_string=None): help="Skip the qcdScaleByHelicity histogram (it can be huge)", ) parser.add_argument( - "--noRecoil", action="store_true", help="Don't apply recoild correction" + "--noRecoil", action="store_true", help="Don't apply recoil correction" ) parser.add_argument( "--recoilHists", diff --git a/wremnants/combine_helpers.py b/wremnants/combine_helpers.py index 254b8eda5..a5335e6ce 100644 --- a/wremnants/combine_helpers.py +++ b/wremnants/combine_helpers.py @@ -1,7 +1,6 @@ import hist import numpy as np -from utilities.io_tools import input_tools from wremnants import histselections, syst_tools from wums import boostHistHelpers as hh from wums import logging @@ -88,20 +87,20 @@ def add_mass_diff_variations( def add_recoil_uncertainty( - card_tool, + datagroups, samples, passSystToFakes=False, pu_type="highPU", flavor="", group_compact=True, ): - met = input_tools.args_from_metadata(card_tool, "met") + met = datagroups.args_from_metadata("met") if flavor == "": - flavor = input_tools.args_from_metadata(card_tool, "flavor") + flavor = datagroups.args_from_metadata("flavor") if pu_type == "highPU" and ( met in ["RawPFMET", "DeepMETReso", "DeepMETPVRobust", "DeepMETPVRobustNoPUPPI"] ): - card_tool.addSystematic( + datagroups.addSystematic( "recoil_stat", processes=samples, mirror=True, @@ -116,7 +115,7 @@ def add_recoil_uncertainty( if pu_type == "lowPU": group_compact = False - card_tool.addSystematic( + datagroups.addSystematic( "recoil_syst", processes=samples, mirror=True, @@ -129,7 +128,7 @@ def add_recoil_uncertainty( passToFakes=passSystToFakes, ) - card_tool.addSystematic( + datagroups.addSystematic( "recoil_stat", processes=samples, mirror=True, @@ -290,7 +289,7 @@ def add_nominal_with_correlated_BinByBinStat( def add_electroweak_uncertainty( - card_tool, + datagroups, ewUncs, flavor="mu", samples="single_v_samples", @@ -298,7 +297,7 @@ def add_electroweak_uncertainty( wlike=False, ): # different uncertainty for W and Z samples - all_samples = card_tool.procGroups[samples] + all_samples = datagroups.procGroups[samples] z_samples = [p for p in all_samples if p[0] == "Z"] w_samples = [p for p in all_samples if p[0] == "W"] @@ -306,7 +305,7 @@ def add_electroweak_uncertainty( if "renesanceEW" in ewUnc: if w_samples: # add renesance (virtual EW) uncertainty on W samples - card_tool.addSystematic( + datagroups.addSystematic( f"{ewUnc}Corr", processes=w_samples, preOp=lambda h: h[{"var": ["nlo_ew_virtual"]}], @@ -319,7 +318,7 @@ def add_electroweak_uncertainty( ) elif ewUnc == "powhegFOEW": if z_samples: - card_tool.addSystematic( + datagroups.addSystematic( f"{ewUnc}Corr", preOp=lambda h: h[{"weak": ["weak_ps", "weak_aem"]}], processes=z_samples, @@ -331,7 +330,7 @@ def add_electroweak_uncertainty( passToFakes=passSystToFakes, name="ewScheme", ) - card_tool.addSystematic( + datagroups.addSystematic( f"{ewUnc}Corr", preOp=lambda h: h[{"weak": ["weak_default"]}], processes=z_samples, @@ -376,7 +375,7 @@ def add_electroweak_uncertainty( else: preOp = lambda h: h[{"systIdx": s[1:2]}] - card_tool.addSystematic( + datagroups.addSystematic( f"{ewUnc}Corr", systAxes=["systIdx"], mirror=True, diff --git a/wremnants/datasets/datasetDict_v9.py b/wremnants/datasets/datasetDict_v9.py index 0838e35ca..726bf8750 100644 --- a/wremnants/datasets/datasetDict_v9.py +++ b/wremnants/datasets/datasetDict_v9.py @@ -28,7 +28,7 @@ "DYJetsToMuMuMass10to50PostVFP": { "filepaths": [ "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos/NanoV9MCPostVFP_{NANO_PROD_TAG}", - # "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", + "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", ], "xsec": common.xsec_DYJetsToMuMuMass10to50, "group": "DYlowMass", diff --git a/wremnants/recoil_tools.py b/wremnants/recoil_tools.py index fe45c19ed..9b45a00d7 100644 --- a/wremnants/recoil_tools.py +++ b/wremnants/recoil_tools.py @@ -84,6 +84,9 @@ def __init__(self, pu_type, args, flavor="mu"): self.storeHists = args.recoilHists self.pu_type = pu_type self.isW = False + self.recoil_unc_stat_weights_with_nom = "" + self.recoil_var_ax_stat = None + self.recoil_var_ax_syst = None self.met_xy_helper_data, self.met_xy_helper_mc = METXYCorrectionHelper( f"{common.data_dir}/recoil/{pu_type}_{self.met}/met_xy_{self.flavor}.json" @@ -1452,7 +1455,8 @@ def add_recoil_unc_W( return df def setup_recoil_Z_unc(self): - if not self.dataset.name in self.datasets_to_apply or not self.storeHists: + # if not self.dataset.name in self.datasets_to_apply or not self.storeHists: + if not self.dataset.name in self.datasets_to_apply: return hNames, cols, axes = [], [], [] @@ -1542,7 +1546,8 @@ def setup_recoil_Z_unc(self): ) def setup_recoil_W_unc(self): - if not self.dataset.name in self.datasets_to_apply or not self.storeHists: + # if not self.dataset.name in self.datasets_to_apply or not self.storeHists: + if not self.dataset.name in self.datasets_to_apply: return hNames, cols, axes = [], [], [] From 4369f3a2144fc37fa2cc2ffab7a6ba8da161ebf2 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 11 Jan 2026 17:21:53 +0100 Subject: [PATCH 26/46] restore default dictionary for datasets --- wremnants/datasets/datasetDict_v9.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wremnants/datasets/datasetDict_v9.py b/wremnants/datasets/datasetDict_v9.py index 93c1d72ff..8898728e3 100644 --- a/wremnants/datasets/datasetDict_v9.py +++ b/wremnants/datasets/datasetDict_v9.py @@ -28,7 +28,7 @@ "DYJetsToMuMuMass10to50PostVFP": { "filepaths": [ "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos/NanoV9MCPostVFP_{NANO_PROD_TAG}", - "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", + # "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", ], "xsec": common.xsec_DYJetsToMuMuMass10to50, "group": "DYlowMass", From 02f25408b9fe88d79232927d4e51ac0b63e5ad05 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 14 Jan 2026 23:19:46 +0100 Subject: [PATCH 27/46] updates --- .../w_mass_13TeV/makeFakeTransferTemplate.py | 133 ++++++++++---- scripts/plotting/plot_decorr_params.py | 8 + scripts/rabbit/setupRabbit.py | 171 +++++++++--------- utilities/styles/styles.py | 43 ++++- 4 files changed, 237 insertions(+), 118 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py index d9c84c161..6ed9209d0 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py +++ b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import argparse import os import pickle import sys @@ -26,6 +25,12 @@ ROOT.PyConfig.IgnoreCommandLineOptions = True from scripts.analysisTools.plotUtils.utility import ( + adjustSettings_CMS_lumi, + common_plot_parser, + copyOutputToEos, + createPlotDirAndCopyPhp, + drawNTH1, + getMinMaxMultiHisto, safeOpenFile, ) @@ -74,8 +79,7 @@ def convert_binEdges_idx(ed_list, binning): return (low, high) -parser = argparse.ArgumentParser() - +parser = common_plot_parser() parser.add_argument( "-i", "--infile", @@ -110,7 +114,9 @@ def convert_binEdges_idx(ed_list, binning): action="store_true", help="Make templates with QCD instead of nonprompt contribution", ) - +parser.add_argument( + "--plotdir", type=str, default=None, help="Output directory for plots" +) args = parser.parse_args() logger = logging.setup_logger(os.path.basename(__file__), 4) @@ -132,30 +138,6 @@ def convert_binEdges_idx(ed_list, binning): else ["QCD"] ) -eta_genBinning = array("d", [round(-2.4 + 0.1 * i, 1) for i in range(49)]) -charge_genBinning = array("d", [-2, 0, 2]) - -delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins -delta_ch = (charge_genBinning[-1] - charge_genBinning[0]) / args.nChargeBins - -decorrBins_eta = [ - ( - round((eta_genBinning[0] + i * delta_eta), 1), - round((eta_genBinning[0] + (i + 1) * delta_eta), 1), - ) - for i in range(args.nEtaBins) -] -decorrBins_ch = [ - ( - round((charge_genBinning[0] + i * delta_ch), 1), - round((charge_genBinning[0] + (i + 1) * delta_ch), 1), - ) - for i in range(args.nChargeBins) -] - -logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") -logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") - groups = Datagroups( args.infile, filterGroups=groupsToConsider, @@ -198,13 +180,45 @@ def convert_binEdges_idx(ed_list, binning): "nominal", syst="", procsToRead=datasets, applySelection=True ) +hnomi = histInfo[datasets[0]].hists["nominal"] +nPtBins = hnomi.axes["pt"].size +ptEdges = hnomi.axes["pt"].edges +nEtaBins = hnomi.axes["eta"].size +etaEdges = hnomi.axes["eta"].edges +nChargeBins = hnomi.axes["charge"].size +chargeEdges = hnomi.axes["charge"].edges + +eta_genBinning = array("d", [round(x, 1) for x in etaEdges]) +charge_genBinning = array("d", chargeEdges) + +delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins +delta_ch = (charge_genBinning[-1] - charge_genBinning[0]) / args.nChargeBins + +decorrBins_eta = [ + ( + round((eta_genBinning[0] + i * delta_eta), 1), + round((eta_genBinning[0] + (i + 1) * delta_eta), 1), + ) + for i in range(args.nEtaBins) +] +decorrBins_ch = [ + ( + round((charge_genBinning[0] + i * delta_ch), 1), + round((charge_genBinning[0] + (i + 1) * delta_ch), 1), + ) + for i in range(args.nChargeBins) +] + +logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") +logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") + out_hist = ROOT.TH3D( f"fakeRatio_utAngleSign_{'Data' if not args.doQCD else 'QCD'}", "", len(eta_genBinning) - 1, eta_genBinning, - 30, - array("d", [round(26.0 + 1.0 * i, 1) for i in range(31)]), + nPtBins, + array("d", [round(x, 1) for x in ptEdges]), len(charge_genBinning) - 1, charge_genBinning, ) @@ -275,7 +289,7 @@ def convert_binEdges_idx(ed_list, binning): for idx_ch in range(ch_low_idx + 1, ch_high_idx + 1): for idx_eta in range(eta_low_idx + 1, eta_high_idx + 1): # logger.debug(f"Setting weights for chBin={idx_ch}, etaBin={idx_eta}") - for idx_pt in range(1, 31): + for idx_pt in range(1, 1 + nPtBins): out_hist.SetBinContent( idx_eta, idx_pt, idx_ch, ratio_h.GetBinContent(idx_pt) ) @@ -295,6 +309,63 @@ def convert_binEdges_idx(ed_list, binning): {"meta_info": wums.output_tools.make_meta_info_dict(args=args, wd=base_dir)} ) +if args.plotdir is not None: + + plotdir_original = args.plotdir + plotdir = createPlotDirAndCopyPhp(plotdir_original, eoscp=args.eoscp) + hists_corr = [] + legEntries = [] + etaID = 0 + # for 1D plots + canvas1D = ROOT.TCanvas("canvas1D", "", 800, 900) + adjustSettings_CMS_lumi() + integrateCharge = True + for ieta in [1, 24, 48]: + etamu = "#eta^{#mu}" + etaleg = f"{decorrBins_eta[etaID][0]} < {etamu} < {decorrBins_eta[etaID][1]}" + etaID += 1 + for icharge in [1] if integrateCharge else [1, 2]: + hists_corr.append( + out_hist.ProjectionY( + f"projPt_{ieta}_{icharge}", ieta, ieta, icharge, icharge + ) + ) + if integrateCharge: + chargeleg = "" + legEntries.append(f"{etaleg}") + else: + chargeleg = "#it{q}^{#mu} = " + ("-1" if icharge == 1 else "+1") + legEntries.append(f"{etaleg}, {chargeleg}") + + miny, maxy = getMinMaxMultiHisto(hists_corr) + if miny < 0: + miny = 0 + maxy = 1.4 * (maxy - miny) + drawNTH1( + hists_corr, + legEntries, + "#it{p}_{T}^{#mu}", + "Correction: #it{u}_{T}^{#mu} > 0 #rightarrow #it{u}_{T}^{#mu} < 0" + + f"::{miny},{maxy}", + "correction_uT_vs_pT_eta_charge", + plotdir, + lowerPanelHeight=0.4, + legendCoords=( + "0.4,0.98,0.74,0.92" if integrateCharge else "0.16,0.98,0.74,0.92;2" + ), + labelRatioTmp="Ratio to first::0.2,1.8", + topMargin=0.06, + rightMargin=0.02, + drawLumiLatex=True, + onlyLineColor=True, + useLineFirstHistogram=True, + drawErrorAll=True, + yAxisExtendConstant=1.0, + ) + + copyOutputToEos(plotdir, plotdir_original, eoscp=args.eoscp) + + outfileName = "fakeTransferTemplates" if args.postfix: outfileName += f"_{args.postfix}" diff --git a/scripts/plotting/plot_decorr_params.py b/scripts/plotting/plot_decorr_params.py index 879bbacc2..aadcc8874 100644 --- a/scripts/plotting/plot_decorr_params.py +++ b/scripts/plotting/plot_decorr_params.py @@ -370,6 +370,14 @@ def get_values_and_impacts_as_panda( df_p["yticks"] = ( df_p["phi"].apply(lambda x: str(axis_ranges[x])).astype(str) ) + elif "charge" in axes: + axis_ranges = { + 0: rf"$\mathit{{q}}_{{T}}^{{\mu}}$ < 0", + 1: rf"$\mathit{{q}}_{{T}}^{{\mu}}$ > 0", + } + df_p["yticks"] = ( + df_p["charge"].apply(lambda x: str(axis_ranges[x])).astype(str) + ) elif "utAngleSign" in axes: axis_ranges = { 0: rf"$\mathit{{u}}_{{T}}^{{\mu}}$ < 0", diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 3e9679072..2c2e623c0 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -375,6 +375,7 @@ def make_parser(parser=None): "lumi", "fakenorm", "effisyst", + "effisystTrigIso", "decornorm", "ptscale", ], @@ -1524,7 +1525,7 @@ def setup( suffix = "".join([a.capitalize() for a in args.massDiffWVar.split("-")]) combine_helpers.add_mass_diff_variations( datagroups, - args.massDiffWVa, + args.massDiffWVar, name=massWeightName, processes=signal_samples_forMass, constrain=constrainMass, @@ -2153,9 +2154,6 @@ def fake_nonclosure_byAxis( ) hnom = fakeselector.get_hist(h, *args, **kwargs) hvar = (1 + variation_size) * hnom - ## applying the variations only on the utAngleSign<0 bin - ## TODO: select axis by name and bin id by input argument - # hvar.values()[..., -1] = hnom.values()[..., -1] if keepConstantAxisBin: ax_names = [n for n in hvar.axes.name] for name in keepConstantAxisBin.keys(): @@ -2166,7 +2164,7 @@ def fake_nonclosure_byAxis( ax_index = ax_names.index(name) idxs = [slice(None)] * hvar.ndim idxs[ax_index] = keepConstantAxisBin[name] - hvar.values()[tuple(idxs)] = hnom.values()[tuple(idxs)] + hvar.values()[tuple(idxs)] = hnom.values()[tuple(idxs)] hvar = syst_tools.decorrelateByAxes(hvar, hnom, axesToDecorrNames) @@ -2230,84 +2228,81 @@ def fake_nonclosure_byAxis( mirror = True groupName = "muon_eff_syst" scale = args.effSystScale + splitGroupDict = { + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effSystTypes) + } actionSF = None effActionArgs = {} - if ( - any(x in args.decorrSystByVar for x in ["effi", "effisyst"]) - and "utAngleSign" in fitvar - and decorr_syst_var == "utAngleSign" + if any( + x in args.decorrSystByVar + for x in ["effi", "effisyst", "effisystTrigIso"] ): - logger.warning( - "'utAngleSign' is a fit axis, effSyst will be decorrelated by it" - ) - logger.warning( - "but only for trigger/isolation steps (others are kept correlated)" - ) - logger.warning( - "with an additional scaling of their magnitude by sqrt(2)" - ) - # if "utAngleSign" in fitvar and decorr_syst_var == "utAngleSign": - # then decorrelate only for trigger and iso - # this is because the effSyst were derived inclusively in uT - # but it was impossible to measure them in bins of uT, - # so we dont't really know if they are flat vs uT or not. - # This also includes an additional inflation by sqrt(2) for trigger/isolation - # - # reco-tracking-idip - datagroups.addSystematic( - name, - mirror=mirror, - groups=[groupName, *effCommonGroups], - splitGroup={ - f"{groupName}_{x}": f".*effSyst.*{x}" - for x in list(effTypesNoUt) - }, - systAxes=axes, - labelsByAxis=axlabels, - baseName=name + "_", - processes=["MCnoQCD"], - passToFakes=passSystToFakes, - systNameReplace=nameReplace, - scale=scale, - skipEntries=[{"reco-tracking-idip-trigger-iso": [3, 4]}], - ) - # trigger-isolation - datagroups.addSystematic( - name, - mirror=mirror, - groups=[groupName, *effCommonGroups], - splitGroup={ - f"{groupName}_{x}": f".*effSyst.*{x}" - for x in list(effTypesUt) - }, - systAxes=[ - "reco-tracking-idip-trigger-iso", - "n_syst_variations", - f"{decorr_syst_var}_", - ], - labelsByAxis=["WPSYST", "_etaDecorr", decorr_syst_var], - actionRequiresNomi=True, - action=syst_tools.decorrelateByAxes, - actionArgs=dict( - axesToDecorrNames=[decorr_syst_var], - newDecorrAxesNames=[f"{decorr_syst_var}_"], - ), - baseName=name + "_", - processes=["MCnoQCD"], - passToFakes=passSystToFakes, - systNameReplace=nameReplace, - scale=scale * np.sqrt(2), - skipEntries=[{"reco-tracking-idip-trigger-iso": [0, 1, 2]}], - ) - else: - splitGroupDict = { - f"{groupName}_{x}": f".*effSyst.*{x}" - for x in list(effSystTypes) - } if ( - any(x in args.decorrSystByVar for x in ["effi", "effisyst"]) - and decorr_syst_var in fitvar + "effisystTrigIso" in args.decorrSystByVar + and "utAngleSign" in fitvar + and decorr_syst_var == "utAngleSign" ): + # if "utAngleSign" in fitvar and decorr_syst_var == "utAngleSign": + # then decorrelate only for trigger and iso + # This also includes an additional inflation by sqrt(2) for trigger/isolation + # + logger.warning( + "'utAngleSign' is a fit axis, effSyst will be decorrelated by it" + ) + logger.warning( + "but only for trigger/isolation steps (others are kept correlated)" + ) + logger.warning( + "with an additional scaling of their magnitude by sqrt(2)" + ) + # reco-tracking-idip + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup={ + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effTypesNoUt) + }, + systAxes=axes, + labelsByAxis=axlabels, + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale, + skipEntries=[ + {"reco-tracking-idip-trigger-iso": [3, 4]} + ], + ) + # trigger-isolation + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup={ + f"{groupName}_{x}": f".*effSyst.*{x}" + for x in list(effTypesUt) + }, + systAxes=[*axes, f"{decorr_syst_var}_"], + labelsByAxis=[*axlabels, decorr_syst_var], + actionRequiresNomi=True, + action=syst_tools.decorrelateByAxes, + actionArgs=dict( + axesToDecorrNames=[decorr_syst_var], + newDecorrAxesNames=[f"{decorr_syst_var}_"], + ), + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale * np.sqrt(2), + skipEntries=[ + {"reco-tracking-idip-trigger-iso": [0, 1, 2]} + ], + ) + else: axes = [ "reco-tracking-idip-trigger-iso", "n_syst_variations", @@ -2319,6 +2314,23 @@ def fake_nonclosure_byAxis( axesToDecorrNames=[decorr_syst_var], newDecorrAxesNames=[f"{decorr_syst_var}_"], ) + datagroups.addSystematic( + name, + mirror=mirror, + groups=[groupName, *effCommonGroups], + splitGroup=splitGroupDict, + systAxes=axes, + labelsByAxis=axlabels, + actionRequiresNomi=True, + action=actionSF, + actionArgs=effActionArgs, + baseName=name + "_", + processes=["MCnoQCD"], + passToFakes=passSystToFakes, + systNameReplace=nameReplace, + scale=scale, + ) + else: datagroups.addSystematic( name, mirror=mirror, @@ -2326,9 +2338,6 @@ def fake_nonclosure_byAxis( splitGroup=splitGroupDict, systAxes=axes, labelsByAxis=axlabels, - actionRequiresNomi=True, - action=actionSF, - actionArgs=effActionArgs, baseName=name + "_", processes=["MCnoQCD"], passToFakes=passSystToFakes, diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index d5baca537..08231cafc 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -309,6 +309,23 @@ def translate_html_to_latex(n): "muonCalibration", "Fake", ], + "efficiency": [ + "muon_eff_all", + "muon_eff_stat", + "muon_eff_syst", + "muon_eff_stat_reco", + "muon_eff_stat_tracking", + "muon_eff_stat_idip", + "muon_eff_stat_trigger", + "muon_eff_stat_iso", + "muon_eff_syst_reco", + "muon_eff_syst_tracking", + "muon_eff_syst_idip", + "muon_eff_syst_trigger", + "muon_eff_syst_iso", + "muon_eff_syst_veto", + "muon_eff_stat_veto", + ], "max": common_groups + [ "angularCoeffs", @@ -540,12 +557,12 @@ def translate_html_to_latex(n): "massShiftZ": "Z boson mass", "massShiftW": "W boson mass", "massShift": "W boson mass", - "pdfMSHT20": "PDF", - "pdfCT18Z": "PDF", - "pdfMSHT20NoAlphaS": "PDF no αS", + "pdfMSHT20": "PDF + αS", + "pdfCT18Z": "PDF + αS", + "pdfMSHT20NoAlphaS": "PDF", "pdfMSHT20AlphaS": "αS PDF", "pdfCT18ZAlphaS": "αS PDF", - "pdfCT18ZNoAlphaS": "PDF no αS", + "pdfCT18ZNoAlphaS": "PDF", "pTModeling": "pTV modelling", "resum": "Resummation", "resumTNP": "Non pert. trans.", @@ -653,8 +670,22 @@ def translate_html_to_latex(n): "pdfMSHT20mcrangeSymDiff": "PDF Δmc [diff.]", "pdfMSHT20mbrangeSymAvg": "PDF Δmb [avg.]", "pdfMSHT20mbrangeSymDiff": "PDF Δmb [diff.]", - "QCDscaleWinclusive_PtV0_13000helicity_0_SymAvg": "A0 angular coeff., W, inc.", - "QCDscaleWinclusive_PtV0_13000helicity_2_SymAvg": "A2 angular coeff., W, inc.", + "QCDscaleWinclusive_PtV0_13000helicity_0_SymAvg": "A0 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_1_SymAvg": "A1 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_2_SymAvg": "A2 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_3_SymAvg": "A3 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_4_SymAvg": "A4 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_5_SymAvg": "A5 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_6_SymAvg": "A6 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_7_SymAvg": "A7 angular coeff., W, inc. [avg.]", + "QCDscaleWinclusive_PtV0_13000helicity_0_SymDiff": "A0 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_1_SymDiff": "A1 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_2_SymDiff": "A2 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_3_SymDiff": "A3 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_4_SymDiff": "A4 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_5_SymDiff": "A5 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_6_SymDiff": "A6 angular coeff., W, inc. [diff.]", + "QCDscaleWinclusive_PtV0_13000helicity_7_SymDiff": "A7 angular coeff., W, inc. [diff.]", "scetlibNPgamma": "SCETLib γ", "chargeVgenNP0scetlibNPZLambda2": "SCETLib λ²(Z)", "chargeVgenNP1scetlibNPWLambda2": "SCETLib λ²(W⁻)", From 78f3057a983e2d37d804f8677a9cb6c6ccda17a7 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Mon, 19 Jan 2026 11:52:34 +0100 Subject: [PATCH 28/46] updates --- scripts/rabbit/setupRabbit.py | 1 + scripts/utilities/browse_hdf5.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 2c2e623c0..d5033eeac 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -1356,6 +1356,7 @@ def setup( pseudodataGroups.fakerate_axes = args.fakerateAxes datagroups.addPseudodataHistogramFakes(pseudodata, pseudodataGroups) + if args.pseudoData and not datagroups.xnorm: if args.pseudoDataFitInputFile: indata = rabbit.debugdata.FitInputData(args.pseudoDataFitInputFile) diff --git a/scripts/utilities/browse_hdf5.py b/scripts/utilities/browse_hdf5.py index a87fd39f4..fc1eba77e 100644 --- a/scripts/utilities/browse_hdf5.py +++ b/scripts/utilities/browse_hdf5.py @@ -18,6 +18,9 @@ parser.add_argument("inputfile", type=str, nargs=1, help="Input file") parsers = parser.add_subparsers(dest="printMode") printAll = parsers.add_parser("all", help="Print everything in the input file") + printMeta = parsers.add_parser( + "meta", help="Print only meta info in the input file" + ) printProcs = parsers.add_parser("proc", help="Print only names of processes") printHist = parsers.add_parser( "hist", help="Print more information about histograms" @@ -25,6 +28,13 @@ # printHist.add_argument("-w", "--what", type=str, default="all", # choices=["all", "procs", "hists", "axes"], # help="What to print") + printMeta.add_argument( + "-k", + "--key", + type=str, + default=None, + help="Print only the content of this key (the default shows all keys)", + ) printHist.add_argument( "-p", "--process", type=str, default=None, help="Select this process to print" ) @@ -52,6 +62,12 @@ if args.printMode == "all": print(results) + elif args.printMode == "meta": + if args.key: + print(results["meta_info"][args.key]) + else: + print(results["meta_info"]) + print(f"All keys: {results["meta_info"].keys()}") elif args.printMode == "proc": procs = list(filter(lambda x: x != "meta_info", results.keys())) print("\nList of processes:\n") From 32b866ccb7c227bf5ae126dcc134eeca3f7d4219 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Mon, 19 Jan 2026 22:16:56 +0100 Subject: [PATCH 29/46] implement some comments for the PR --- scripts/plotting/makeDataMCStackPlot.py | 4 +++- wremnants/datasets/datasetDict_v9.py | 1 - 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/plotting/makeDataMCStackPlot.py b/scripts/plotting/makeDataMCStackPlot.py index 94f64a9f2..2a8e43b5a 100644 --- a/scripts/plotting/makeDataMCStackPlot.py +++ b/scripts/plotting/makeDataMCStackPlot.py @@ -364,7 +364,9 @@ def padArray(ref, matchLength): args.rebinBeforeSelection, ) -if args.selection and args.selection != "none": +if args.selection == "none": + applySelection = False +elif args.selection: translate = { "hist.overflow": hist.overflow, "hist.underflow": hist.underflow, diff --git a/wremnants/datasets/datasetDict_v9.py b/wremnants/datasets/datasetDict_v9.py index 8898728e3..7b295ec29 100644 --- a/wremnants/datasets/datasetDict_v9.py +++ b/wremnants/datasets/datasetDict_v9.py @@ -28,7 +28,6 @@ "DYJetsToMuMuMass10to50PostVFP": { "filepaths": [ "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos/NanoV9MCPostVFP_{NANO_PROD_TAG}", - # "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", ], "xsec": common.xsec_DYJetsToMuMuMass10to50, "group": "DYlowMass", From 32e3feab964189562419f5f87038981fc769f796 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 30 Jan 2026 17:02:40 +0100 Subject: [PATCH 30/46] updates for tests --- scripts/plotting/plot_decorr_params.py | 21 +++++++--- scripts/rabbit/setupRabbit.py | 54 +++++++++++++++++++++----- utilities/styles/styles.py | 7 ++++ 3 files changed, 67 insertions(+), 15 deletions(-) diff --git a/scripts/plotting/plot_decorr_params.py b/scripts/plotting/plot_decorr_params.py index aadcc8874..9349250d8 100644 --- a/scripts/plotting/plot_decorr_params.py +++ b/scripts/plotting/plot_decorr_params.py @@ -19,9 +19,10 @@ def get_values_and_impacts_as_panda( global_impacts=False, scale=1.0, scale_from_poi_name=False, + result=None, ): - fitres, meta = rabbit.io_tools.get_fitresult(input_file, meta=True) + fitres, meta = rabbit.io_tools.get_fitresult(input_file, meta=True, result=result) poi_names = rabbit.io_tools.get_poi_names(meta) poi_values = [] totals = [] @@ -80,6 +81,12 @@ def get_values_and_impacts_as_panda( default=None, help="Fitresult file from combinetf with nominal fit", ) + parser.add_argument( + "--result", + default=None, + type=str, + help="fitresults key in file (e.g. 'asimov'). Leave empty for data fit result.", + ) parser.add_argument( "--data", action="store_true", @@ -152,6 +159,7 @@ def get_values_and_impacts_as_panda( args.infileInclusive, partial_impacts_to_read=partial_impacts_to_read, global_impacts=args.globalImpacts, + result=args.result, ) fInclusive = rabbit.io_tools.get_fitresult(args.infileInclusive) nll_inclusive = fInclusive["nllvalreduced"] @@ -162,12 +170,14 @@ def get_values_and_impacts_as_panda( args.infileNominal, partial_impacts_to_read=partial_impacts_to_read, global_impacts=args.globalImpacts, + result=args.result, ) df = get_values_and_impacts_as_panda( args.infile, partial_impacts_to_read=partial_impacts_to_read, global_impacts=args.globalImpacts, + result=args.result, ) df["Params"] = df["Name"].apply(lambda x: x.split("_")[0]) @@ -490,12 +500,13 @@ def get_values_and_impacts_as_panda( logger.info(f"nll_inclusive = {nll_inclusive}; nll = {nll}") chi2_stat = 2 * (nll_inclusive - nll) - if args.data: - chi2_label = r"\mathit{\chi}^2/\mathit{ndf}" - else: + chi2_label = r"\mathit{\chi}^2/\mathit{ndf}" + if args.result == "asimov": + chi2_stat = 0 + elif not args.data: # in case of pseudodata fits there are no statistical fluctuations and we can only access the expected p-value, where ndf has to be added to the test statistic chi2_stat += ndf - chi2_label = r"<\mathit{\chi}^2/\mathit{ndf}>" + chi2_label = f"<{chi2_label}>" p_value = 1 - chi2.cdf(chi2_stat, ndf) logger.info(f"ndf = {ndf}; Chi2 = {chi2_stat}; p-value={p_value}") diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index d5033eeac..1e385bce9 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -583,6 +583,17 @@ def make_parser(parser=None): parser.add_argument( "--massVariation", type=float, default=100, help="Variation of boson mass" ) + parser.add_argument( + "--widthVariationW", + type=str, + nargs=2, + default=["0.6", "0.6"], + choices=["0.6", "6", "36", "48"], + # [["0.6", "0.6"], ["6", "0.6"], ["48", "0.6"], ["0.6", "36"], ["6", "36"], ["48", "36"]], + help="""Variation of W boson width (as string), specifying Down/Up variations. + If using --noi wwidth, the default is changed to ["48", "36"]. + """, + ) parser.add_argument( "--ewUnc", type=str, @@ -1626,21 +1637,40 @@ def setup( ) if wmass and ("wwidth" in args.noi or (not stat_only and not args.noTheoryUnc)): - if "wwidth" in args.noi: - width_info = dict( - name="WidthW42MeV", - skipEntries=widthWeightNames(proc="W", exclude=(2.043, 2.127)), - systNameReplace=[["2p043GeV", "Down"], ["2p127GeV", "Up"]], - ) - # name="WidthWm6p36MeV", - # skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), - # systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], - else: + widthVarTag = "" + if ( + args.widthVariationW[0] == args.widthVariationW[1] + and args.widthVariationW[0] == "0.6" + ): width_info = dict( name="WidthW0p6MeV", skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], ) + else: + widthLowValues = { + "0.6": "2.09053", + "6": "2.085", + "48": "2.043", + } + widthHighValues = { + "0.6": "2.09173", + "36": "2.127", + } + widthVarDown = args.widthVariationW[0].replace(".", "p") + widthVarUp = args.widthVariationW[1].replace(".", "p") + widthVarTag = f"WidthWm{widthVarDown}p{widthVarUp}MeV" + wlv = widthLowValues[args.widthVariationW[0]] + whv = widthHighValues[args.widthVariationW[1]] + wlvStr = wlv.replace(".", "p") + "GeV" + whvStr = whv.replace(".", "p") + "GeV" + width_info = dict( + name=widthVarTag, + skipEntries=widthWeightNames( + proc="W", exclude=(float(wlv), float(whv)) + ), + systNameReplace=[[wlvStr, "Down"], [whvStr, "Up"]], + ) width_info.update( dict( @@ -3003,6 +3033,10 @@ def outputFolderName(outfolder, datagroups, doStatOnly, postfix): logger = logging.setup_logger(__file__, args.verbose, args.noColorLogger) + if "wwidth" in args.noi: + parser = parsing.set_parser_default(parser, "widthVariationW", ["48", "36"]) + args = parser.parse_args() + isUnfolding = args.analysisMode == "unfolding" isTheoryAgnostic = args.analysisMode in [ "theoryAgnosticNormVar", diff --git a/utilities/styles/styles.py b/utilities/styles/styles.py index 08231cafc..e14bdaf4e 100644 --- a/utilities/styles/styles.py +++ b/utilities/styles/styles.py @@ -308,6 +308,13 @@ def translate_html_to_latex(n): "prefire", "muonCalibration", "Fake", + "massShift", + "pythia_shower_kt", + "resumTNP", + "resumNonpert", + "resumTransition", + "resumScale", + "bcQuarkMass", ], "efficiency": [ "muon_eff_all", From 5e5e6d990585851da367a80e7e0b4db085cc718e Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Mon, 2 Feb 2026 11:44:58 +0100 Subject: [PATCH 31/46] updates for width and uT --- scripts/plotting/plot_decorr_params.py | 43 ++++++++------ scripts/rabbit/setupRabbit.py | 77 ++++++++++++++++++++++++-- wremnants/datasets/datagroups.py | 20 +++++++ wremnants/datasets/datasetDict_v9.py | 1 - 4 files changed, 118 insertions(+), 23 deletions(-) diff --git a/scripts/plotting/plot_decorr_params.py b/scripts/plotting/plot_decorr_params.py index 9349250d8..909179e9d 100644 --- a/scripts/plotting/plot_decorr_params.py +++ b/scripts/plotting/plot_decorr_params.py @@ -136,6 +136,12 @@ def get_values_and_impacts_as_panda( action="store_true", help="Use the global impacts to plot uncertainties (they must be present in the input file)", ) + parser.add_argument( + "--poiScale", + type=float, + default=-1, + help="Scale poi uncertainty by this factor, default does nothing", + ) parser = parsing.set_parser_default(parser, "legCols", 1) @@ -186,27 +192,32 @@ def get_values_and_impacts_as_panda( for param, df_p in df.groupby("Params"): logger.info(f"Make plot for {param}") - if param is not None and "MeV" in param: - xlabel = param.split("MeV")[0] - if xlabel.startswith("massShift"): - proc = xlabel.replace("massShift", "")[0] + scale = args.poiScale if args.poiScale > 0 else 1 + + if param is not None and ("MeV" in param or "width" in param): + if param.startswith("massShift"): + proc = param.split("MeV")[0].replace("massShift", "")[0] xlabel = r"$\mathit{m}_\mathrm{" + str(proc) + "}$ (MeV)" offset = 80354 if proc == "W" else 91187.6 - if xlabel.startswith("Width"): - proc = xlabel.replace("Width", "")[0] + scale = float( + re.search( + r"\d+(\.\d+)?", param.split("MeV")[0].replace("p", ".") + ).group() + ) + elif param.startswith("width"): + proc = param.replace("width", "")[0] xlabel = r"$\mathit{\Gamma}_\mathrm{" + str(proc) + "}$ (MeV)" offset = 2091.13 if proc == "W" else 2494.13 + if args.poiScale < 0: + logger.warning(f"No scaling set for {param} uncertainty, using 1.0") + else: + xlabel = param - scale = float( - re.search( - r"\d+(\.\d+)?", param.split("MeV")[0].replace("p", ".") - ).group() - ) if "Diff" in param: scale *= 2 # take diffs by 2 as up and down pull in opposite directions else: - scale = 1 + scale = args.poiScale if args.poiScale > 0 else 1 offset = 0 xlabel = param @@ -425,7 +436,7 @@ def get_values_and_impacts_as_panda( val = df_p["value"].values * scale + offset err = df_p["err_Total"].values * scale err_stat = df_p["err_stat"].values * scale - err_cal = df_p[f"err_{partialImpact}"].values * scale + err_part = df_p[f"err_{partialImpact}"].values * scale if args.infileNominal: if len(dfNominal) > 1: @@ -455,7 +466,7 @@ def get_values_and_impacts_as_panda( ) c_err_stat = dfInclusive["err_stat"].values[0] * scale - c_err_cal = dfInclusive[f"err_{partialImpact}"].values[0] * scale + c_err_part = dfInclusive[f"err_{partialImpact}"].values[0] * scale c_err = dfInclusive["err_Total"].values[0] * scale c = dfInclusive["value"].values[0] * scale + offset @@ -557,7 +568,7 @@ def get_values_and_impacts_as_panda( alpha=0.3, ) ax1.fill_between( - [c - c_err_cal, c + c_err_cal], + [c - c_err_part, c + c_err_part], ylim[0], ylim[1], color="gray", @@ -583,7 +594,7 @@ def get_values_and_impacts_as_panda( ax1.errorbar( val, y, - xerr=err_cal, + xerr=err_part, color="orange", marker="", linestyle="", diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 1e385bce9..9818ff119 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -296,6 +296,7 @@ def make_parser(parser=None): "wwidth", "xsec", "massdiffW", + "widthdiffW", "massdiffZ", ], default=["wmass"], @@ -316,6 +317,15 @@ def make_parser(parser=None): ], help="For use with --noi massDiffW, select the variable to define the different mass differences", ) + parser.add_argument( + "--widthDiffWVar", + type=str, + default=None, + choices=[ + "charge", + ], + help="For use with --noi widthDiffW, select the variable to define the different mass differences", + ) parser.add_argument( "--massDiffZVar", type=str, @@ -338,6 +348,13 @@ def make_parser(parser=None): nargs="*", help="Decorrelate POI for given axes, fit multiple POIs for the different POIs", ) + parser.add_argument( + "--fitWidthDecorr", + type=str, + default=[], + nargs="*", + help="Decorrelate POI for given axes, fit multiple POIs for the different POIs", + ) parser.add_argument( "--decorrRebin", type=int, @@ -1642,8 +1659,9 @@ def setup( args.widthVariationW[0] == args.widthVariationW[1] and args.widthVariationW[0] == "0.6" ): + widthVarTag = "WidthW0p6MeV" width_info = dict( - name="WidthW0p6MeV", + name=widthVarTag, skipEntries=widthWeightNames(proc="W", exclude=(2.09053, 2.09173)), systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], ) @@ -1702,10 +1720,56 @@ def setup( **width_info, ) else: - datagroups.addSystematic( - widthWeightName, - **width_info, - ) + if len(args.fitWidthDecorr) == 0: + datagroups.addSystematic( + widthWeightName, + **width_info, + ) + else: + suffix = "".join([a.capitalize() for a in args.fitWidthDecorr]) + new_names = [f"{a}_decorr" for a in args.fitWidthDecorr] + datagroups.addSystematic( + histname=widthWeightName, + processes=signal_samples_forMass, + name=f"{widthVarTag}Decorr{suffix}{label}", + groups=[f"widthDecorr{label}", "theory"], + skipEntries=[ + (x, *[-1] * len(args.fitWidthDecorr)) + for x in width_info["skipEntries"] + ], + noi="wwidth" in args.noi, + noConstraint="wwidth" in args.noi, + mirror=False, + systAxes=["width", *new_names], + systNameReplace=width_info["systNameReplace"], + passToFakes=passSystToFakes, + # isPoiHistDecorr is a special flag to deal with how the massShift variations are internally formed + isPoiHistDecorr=len(args.fitWidthDecorr), + actionRequiresNomi=True, + action=syst_tools.decorrelateByAxes, + actionArgs=dict( + axesToDecorrNames=args.fitWidthDecorr, + newDecorrAxesNames=new_names, + axlim=args.decorrAxlim, + rebin=args.decorrRebin, + absval=args.decorrAbsval, + ), + ) + + if "widthdiffW" in args.noi: + suffix = "".join( + [a.capitalize() for a in args.widthDiffWVar.split("-")] + ) + combine_helpers.add_mass_diff_variations( + datagroups, + args.widthDiffWVar, + name=widthWeightName, + processes=signal_samples_forMass, + constrain=constrainMass, + suffix=suffix, + label=label, + passSystToFakes=passSystToFakes, + ) if "sin2thetaW" in args.noi or (not stat_only and not args.noTheoryUnc): datagroups.addSystematic( @@ -2166,6 +2230,7 @@ def fake_nonclosure( ), ) + # must skip this part when fitting only utPlus with --select 'utAngleSign 1 2' if "utAngleSign" in fitvar: # TODO: extend and use previous function fake_nonclosure(...) def fake_nonclosure_byAxis( @@ -2180,7 +2245,7 @@ def fake_nonclosure_byAxis( # with keepConstantAxisBin one can keep a range of bins untouched by passing slice(start, stop) # e.g. keepConstantAxisBin={"utAngleSign": slice(1, 2)}, maybe also by values with complex numbers - logger.debug( + logger.info( f"Doing decorr nonclosure with keepConstantAxisBin={keepConstantAxisBin}" ) hnom = fakeselector.get_hist(h, *args, **kwargs) diff --git a/wremnants/datasets/datagroups.py b/wremnants/datasets/datagroups.py index 91c8ba04c..beb014795 100644 --- a/wremnants/datasets/datagroups.py +++ b/wremnants/datasets/datagroups.py @@ -1315,6 +1315,9 @@ def addSystematic( action=None, actionArgs={}, actionRequiresNomi=False, + lastAction=None, + lastActionArgs={}, + lastActionRequiresNomi=False, **kwargs, ): """ @@ -1322,6 +1325,8 @@ def addSystematic( 'action': Operation that is applied after everything else """ + s = hist.tag.Slicer() + if group is not None: groups = [*groups, group] if splitGroup is not None: @@ -1436,6 +1441,21 @@ def addSystematic( ] logger.debug(f"Add systematic {var_name}") + + if lastAction is not None: + if lastActionRequiresNomi: + hnom = self.groups[proc].hists[self.nominalName] + apply_last_action = lambda h: lastAction( + h, hnom, **lastActionArgs + ) + else: + apply_last_action = lambda h: lastAction(h, **lastActionArgs) + + if isinstance(hists, hist.Hist): + hists = apply_last_action(hists) + else: + hists = tuple(apply_last_action(h) for h in hists) + self.writer.add_systematic( hists, var_name, diff --git a/wremnants/datasets/datasetDict_v9.py b/wremnants/datasets/datasetDict_v9.py index 726bf8750..ba178746c 100644 --- a/wremnants/datasets/datasetDict_v9.py +++ b/wremnants/datasets/datasetDict_v9.py @@ -28,7 +28,6 @@ "DYJetsToMuMuMass10to50PostVFP": { "filepaths": [ "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos/NanoV9MCPostVFP_{NANO_PROD_TAG}", - "{BASE_PATH}/DYJetsToMuMu_M-10to50_H2ErratumFix_TuneCP5_13TeV-powhegMiNNLO-pythia8-photos_ext1/NanoV9MCPostVFP_{NANO_PROD_TAG}", ], "xsec": common.xsec_DYJetsToMuMuMass10to50, "group": "DYlowMass", From d2f75343db0de7bad10e4ae2d65873f2894d4a91 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Tue, 17 Feb 2026 18:00:17 +0100 Subject: [PATCH 32/46] small fix --- scripts/rabbit/setupRabbit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 9818ff119..7cae8852e 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -1731,7 +1731,7 @@ def setup( datagroups.addSystematic( histname=widthWeightName, processes=signal_samples_forMass, - name=f"{widthVarTag}Decorr{suffix}{label}", + name=f"widthDecorr{suffix}{label}", groups=[f"widthDecorr{label}", "theory"], skipEntries=[ (x, *[-1] * len(args.fitWidthDecorr)) From d0d76ea069dbdacc4a8ba8dae75301a2d79bd246 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Tue, 17 Feb 2026 18:47:10 +0100 Subject: [PATCH 33/46] pylint --- scripts/analysisTools/w_mass_13TeV/diffNuisances.py | 6 ++---- wremnants/unfolding_tools.py | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/diffNuisances.py b/scripts/analysisTools/w_mass_13TeV/diffNuisances.py index 3b1d4a5d2..4c231250c 100644 --- a/scripts/analysisTools/w_mass_13TeV/diffNuisances.py +++ b/scripts/analysisTools/w_mass_13TeV/diffNuisances.py @@ -541,8 +541,7 @@ def sortParameters(params): sigsub = ("sig", r"σ") highlight = "%s" morelight = "%s" - txtfile.write( - """ + txtfile.write(""" Comparison of nuisances

Comparison of nuisances

- """ - ) + """) if args.absolute_values: what = "x, σfit" diff --git a/wremnants/unfolding_tools.py b/wremnants/unfolding_tools.py index da58b539a..aae3cd98d 100644 --- a/wremnants/unfolding_tools.py +++ b/wremnants/unfolding_tools.py @@ -415,13 +415,11 @@ def __init__( ] if any(ax.edges != wbh_axis.edges): - raise RuntimeError( - f""" + raise RuntimeError(f""" Unfolding axes must be consistent with axes from weightsByHelicity_helper.\n Found unfolding axis {ax}\n And weightsByHelicity_helper axis {wbh_axis} - """ - ) + """) self.unfolding_corr_helper = ( reweight_to_fitresult( From 048935ef201381d5da181b7f6a9a916038843250 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Tue, 17 Feb 2026 18:49:00 +0100 Subject: [PATCH 34/46] trying to fix pylint --- notebooks/CompareCorrections.ipynb | 995 +++++++++------ notebooks/EWClosure.ipynb | 106 +- notebooks/EWCorrections_FSR.ipynb | 394 +++++- notebooks/LowPileupScratch.ipynb | 10 +- notebooks/MiNNLOFixedOrderValidation.ipynb | 403 ++++-- notebooks/PlotScratch.ipynb | 98 +- notebooks/PostfitGen.ipynb | 1129 ++++++++++------- notebooks/SmoothNNLOjet.ipynb | 656 +++++----- notebooks/WCharm.ipynb | 224 +++- notebooks/angularCoefficients.ipynb | 440 ++++--- notebooks/bestPlot.ipynb | 4 +- notebooks/closureFakes.ipynb | 503 +++++--- notebooks/comparisonPlots.ipynb | 221 ++-- notebooks/genPlots.ipynb | 377 +++--- notebooks/genScratch.ipynb | 125 +- notebooks/mTResolution.ipynb | 302 +++-- notebooks/mWPostfit.ipynb | 515 +++++--- notebooks/match_scetlib_dyurbo.ipynb | 962 ++++++++------ notebooks/muonMomentumScale.ipynb | 1019 ++++++++------- notebooks/postfitPlots.ipynb | 153 ++- notebooks/scetlib.ipynb | 1115 ++++++++++++---- notebooks/summaryPlot.ipynb | 199 ++- notebooks/systsScratch.ipynb | 449 +++++-- notebooks/testPdfUnc.ipynb | 354 ++++-- notebooks/testPostfitPdf.ipynb | 340 ++++- notebooks/theoryAngularCoeffComparisons.ipynb | 1054 ++++++++++----- notebooks/unblindedPostfitGen.ipynb | 512 ++++---- 27 files changed, 8328 insertions(+), 4331 deletions(-) diff --git a/notebooks/CompareCorrections.ipynb b/notebooks/CompareCorrections.ipynb index a000c4d16..bc9843f0c 100644 --- a/notebooks/CompareCorrections.ipynb +++ b/notebooks/CompareCorrections.ipynb @@ -20,7 +20,7 @@ "import matplotlib.pyplot as plt\n", "import mplhep as hep\n", "from wremnants import plot_tools, theory_tools\n", - "from wums import boostHistHelpers as hh,input_tools\n", + "from wums import boostHistHelpers as hh, input_tools\n", "import uproot\n", "import pickle, lz4.frame\n", "import glob" @@ -56,6 +56,7 @@ ], "source": [ "from wums import ioutils\n", + "\n", "ioutils" ] }, @@ -67,12 +68,28 @@ "outputs": [], "source": [ "genfile = \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\"\n", - "minnlo_wm = input_tools.read_and_scale(genfile, \"WminusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)\n", - "minnlo_wm_pdf = input_tools.read_and_scale(genfile, \"WminusmunuPostVFP\", \"nominal_gen_pdfMSHT20\", calculate_lumi=False, scale=1)\n", - "minnlo_wm_pdfas = input_tools.read_and_scale(genfile, \"WminusmunuPostVFP\", \"nominal_gen_pdfMSHT20alphaS002\", calculate_lumi=False, scale=1)\n", - "minnlo_wp = input_tools.read_and_scale(genfile, \"WplusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)\n", - "minnlo_z = input_tools.read_and_scale(genfile, \"ZmumuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)\n", - "minnlo_z_pdf = input_tools.read_and_scale(genfile, \"ZmumuPostVFP\", \"nominal_gen_pdfMSHT20\", calculate_lumi=False, scale=1)" + "minnlo_wm = input_tools.read_and_scale(\n", + " genfile, \"WminusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1\n", + ")\n", + "minnlo_wm_pdf = input_tools.read_and_scale(\n", + " genfile, \"WminusmunuPostVFP\", \"nominal_gen_pdfMSHT20\", calculate_lumi=False, scale=1\n", + ")\n", + "minnlo_wm_pdfas = input_tools.read_and_scale(\n", + " genfile,\n", + " \"WminusmunuPostVFP\",\n", + " \"nominal_gen_pdfMSHT20alphaS002\",\n", + " calculate_lumi=False,\n", + " scale=1,\n", + ")\n", + "minnlo_wp = input_tools.read_and_scale(\n", + " genfile, \"WplusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1\n", + ")\n", + "minnlo_z = input_tools.read_and_scale(\n", + " genfile, \"ZmumuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1\n", + ")\n", + "minnlo_z_pdf = input_tools.read_and_scale(\n", + " genfile, \"ZmumuPostVFP\", \"nominal_gen_pdfMSHT20\", calculate_lumi=False, scale=1\n", + ")" ] }, { @@ -90,7 +107,10 @@ } ], "source": [ - "scetlib_n3ll_wm = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\", nonsing=\"\")" + "scetlib_n3ll_wm = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\",\n", + " nonsing=\"\",\n", + ")" ] }, { @@ -110,9 +130,17 @@ } ], "source": [ - "scetlib_n3ll_z = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20.pkl\", nonsing=\"\")\n", - "scetlib_n3ll_z_oldnp = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\", nonsing=\"\")\n", - "scetlib_n3ll_z_other = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z_vars/inclusive_Z_MSHT20_N3LL_NP.pkl\", nonsing=\"\")" + "scetlib_n3ll_z = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20.pkl\", nonsing=\"\"\n", + ")\n", + "scetlib_n3ll_z_oldnp = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\",\n", + " nonsing=\"\",\n", + ")\n", + "scetlib_n3ll_z_other = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z_vars/inclusive_Z_MSHT20_N3LL_NP.pkl\",\n", + " nonsing=\"\",\n", + ")" ] }, { @@ -122,7 +150,17 @@ "metadata": {}, "outputs": [], "source": [ - "minnlo_z_pt, scetlib_n3ll_z_pt, scetlib_n3ll_z_oldnp_pt, scetlib_n3ll_z_other_pt = hh.rebinHistsToCommon([minnlo_z.project(\"ptVgen\"), scetlib_n3ll_z.project(\"qT\", \"vars\"), scetlib_n3ll_z_oldnp[{\"vars\" : 0}].project(\"qT\"), scetlib_n3ll_z_other[{\"vars\" : 0}].project(\"qT\")], 0)" + "minnlo_z_pt, scetlib_n3ll_z_pt, scetlib_n3ll_z_oldnp_pt, scetlib_n3ll_z_other_pt = (\n", + " hh.rebinHistsToCommon(\n", + " [\n", + " minnlo_z.project(\"ptVgen\"),\n", + " scetlib_n3ll_z.project(\"qT\", \"vars\"),\n", + " scetlib_n3ll_z_oldnp[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_n3ll_z_other[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " 0,\n", + " )\n", + ")" ] }, { @@ -212,11 +250,12 @@ } ], "source": [ - "scetlib_dyturbo_n3ll = input_tools.read_matched_scetlib_dyturbo_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_vars_combined.pkl\",\n", + "scetlib_dyturbo_n3ll = input_tools.read_matched_scetlib_dyturbo_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_vars_combined.pkl\",\n", " \"/home/k/kelong/TheoryCorrections/SCETlib/Z/msht20nnlo/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\",\n", " \"/home/k/kelong/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/pdfvariations/msht20nnlo/z0/results_z-2d-nnlo-vj-member0-scetlibmatch.txt.txt\",\n", " axes=(\"Y\", \"qT\"),\n", - " #charge=0,\n", + " # charge=0,\n", ")" ] }, @@ -227,7 +266,9 @@ "metadata": {}, "outputs": [], "source": [ - "corrf = pickle.load(lz4.frame.open(\"../wremnants/data/TheoryCorrections/scetlib_dyturboCorrZ.pkl.lz4\"))" + "corrf = pickle.load(\n", + " lz4.frame.open(\"../wremnants/data/TheoryCorrections/scetlib_dyturboCorrZ.pkl.lz4\")\n", + ")" ] }, { @@ -295,7 +336,9 @@ } ], "source": [ - "corrf[\"Z\"][\"scetlib_dyturbo_minnlo_ratio\"][{\"vars\" : 0, \"charge\" : 0, \"massVgen\" : 0}].plot()\n", + "corrf[\"Z\"][\"scetlib_dyturbo_minnlo_ratio\"][\n", + " {\"vars\": 0, \"charge\": 0, \"massVgen\": 0}\n", + "].plot()\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"MSHT20\")\n", "out = os.path.join(out, \"MSHT20\")\n", @@ -358,21 +401,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"absy\"),\n", - " corrf[\"Z\"][\"scetlib_dyturbo_hist\"][{\"vars\" : 0}].project(\"absY\"),\n", - " ],\n", - " [\"MiNNLO\", \n", - " \"SCETlib+DYTurbo N$^{3}$LL+NNLO\", \n", - " ],\n", - " colors=[\"orange\", \"mediumpurple\"], \n", - " linestyles=[\"solid\", \"dashed\", ],\n", - " xlabel=r\"$|y^{\\ell\\ell}|$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " legtext_size=16,\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True, extra_text=r\"$Z\\rightarrow\\mu\\mu$\")\n", + " [\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"absy\"),\n", + " corrf[\"Z\"][\"scetlib_dyturbo_hist\"][{\"vars\": 0}].project(\"absY\"),\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"SCETlib+DYTurbo N$^{3}$LL+NNLO\",\n", + " ],\n", + " colors=[\"orange\", \"mediumpurple\"],\n", + " linestyles=[\n", + " \"solid\",\n", + " \"dashed\",\n", + " ],\n", + " xlabel=r\"$|y^{\\ell\\ell}|$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " legtext_size=16,\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " extra_text=r\"$Z\\rightarrow\\mu\\mu$\",\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"MSHT20\")\n", @@ -400,21 +452,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"ptVgen\"),\n", - " corrf[\"Z\"][\"scetlib_dyturbo_hist\"][{\"vars\" : 0}].project(\"qT\"),\n", - " ],\n", - " [\"MiNNLO\", \n", - " \"SCETlib+DYTurbo N$^{3}$LL+NNLO\", \n", - " ],\n", - " colors=[\"orange\", \"mediumpurple\"], \n", - " linestyles=[\"solid\", \"dashed\", ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " legtext_size=16,\n", - " rrange=[0.8, 1.2],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True, extra_text=r\"$Z\\rightarrow\\mu\\mu$\")\n", + " [\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"ptVgen\"),\n", + " corrf[\"Z\"][\"scetlib_dyturbo_hist\"][{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"SCETlib+DYTurbo N$^{3}$LL+NNLO\",\n", + " ],\n", + " colors=[\"orange\", \"mediumpurple\"],\n", + " linestyles=[\n", + " \"solid\",\n", + " \"dashed\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " legtext_size=16,\n", + " rrange=[0.8, 1.2],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " extra_text=r\"$Z\\rightarrow\\mu\\mu$\",\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"MSHT20\")\n", @@ -468,7 +529,7 @@ } ], "source": [ - "scetlib_dyturbo_n3ll[{\"Y\" : s[-5.j:5.j+1:hist.sum], \"vars\" : 0}]" + "scetlib_dyturbo_n3ll[{\"Y\": s[-5.0j : 5.0j + 1 : hist.sum], \"vars\": 0}]" ] }, { @@ -489,7 +550,7 @@ } ], "source": [ - "scetlib_dyturbo_n3ll[{\"vars\" : 0}].sum().value/minnlo_z_y.sum(flow=False).value" + "scetlib_dyturbo_n3ll[{\"vars\": 0}].sum().value / minnlo_z_y.sum(flow=False).value" ] }, { @@ -510,7 +571,7 @@ } ], "source": [ - "minnlo_z[{\"ptVgen\" : s[0.j:100.j]}].project(\"y\").sum()" + "minnlo_z[{\"ptVgen\": s[0.0j:100.0j]}].project(\"y\").sum()" ] }, { @@ -564,29 +625,37 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnlo_z_pt,\n", - " scetlib_n3ll_z_pt[{\"vars\" : \"central\"}],\n", - " scetlib_n3ll_z_oldnp_pt,\n", - " scetlib_n3ll_z_other_pt,\n", - " scetlib_n3ll_z_pt[{\"vars\" : \"Omega0.\"}],\n", - " scetlib_n3ll_z_pt[{\"vars\" : 'c_nu-0.15-omega_nu0.43'}],\n", - " scetlib_n3ll_z_pt[{\"vars\" : 'c_nu0.05'}],\n", - " ],\n", - " [\"MiNNLO\", \"SCETlib N$^{3}$LL (new NP)\", \"SCETlib N$^{3}$LL (old NP)\", \n", - " \"SCETlib N$^{3}$LL (other)\", \n", - " r\"SCETlib N$^{3}$LL $\\Omega = 0.0$\", \n", - " r\"SCETlib N$^{3}$LL $\\Omega = 0.43, c_{\\nu} = 0.15$\",\n", - " r\"SCETlib N$^{3}$LL $c_{\\nu} = 0.15$\"\n", - " ],\n", - " colors=[\"orange\", \"mediumpurple\", \"purple\", \"red\", \"green\", \"darkred\", \"pink\"], \n", - " linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " legtext_size=16,\n", - " rrange=[0.6, 1.4],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True, extra_text=r\"$Z\\rightarrow\\mu\\mu$\")" + " [\n", + " minnlo_z_pt,\n", + " scetlib_n3ll_z_pt[{\"vars\": \"central\"}],\n", + " scetlib_n3ll_z_oldnp_pt,\n", + " scetlib_n3ll_z_other_pt,\n", + " scetlib_n3ll_z_pt[{\"vars\": \"Omega0.\"}],\n", + " scetlib_n3ll_z_pt[{\"vars\": \"c_nu-0.15-omega_nu0.43\"}],\n", + " scetlib_n3ll_z_pt[{\"vars\": \"c_nu0.05\"}],\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"SCETlib N$^{3}$LL (new NP)\",\n", + " \"SCETlib N$^{3}$LL (old NP)\",\n", + " \"SCETlib N$^{3}$LL (other)\",\n", + " r\"SCETlib N$^{3}$LL $\\Omega = 0.0$\",\n", + " r\"SCETlib N$^{3}$LL $\\Omega = 0.43, c_{\\nu} = 0.15$\",\n", + " r\"SCETlib N$^{3}$LL $c_{\\nu} = 0.15$\",\n", + " ],\n", + " colors=[\"orange\", \"mediumpurple\", \"purple\", \"red\", \"green\", \"darkred\", \"pink\"],\n", + " linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " legtext_size=16,\n", + " rrange=[0.6, 1.4],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " extra_text=r\"$Z\\rightarrow\\mu\\mu$\",\n", + ")" ] }, { @@ -596,7 +665,12 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_new = pickle.load(open(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\", \"rb\"))" + "scetlib_new = pickle.load(\n", + " open(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\",\n", + " \"rb\",\n", + " )\n", + ")" ] }, { @@ -614,7 +688,12 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibZ_pdf = pickle.load(open(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\", \"rb\"))[\"hist\"]" + "scetlibZ_pdf = pickle.load(\n", + " open(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\",\n", + " \"rb\",\n", + " )\n", + ")[\"hist\"]" ] }, { @@ -636,19 +715,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibZ_pdf[{\"vars\" : x}].project(\"qT\") for x in scetlibZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [scetlibZ_pdf[{\"vars\": x}].project(\"qT\") for x in scetlibZ_pdf.axes[\"vars\"]],\n", + " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -680,19 +760,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibZ_pdf[{\"vars\" : x}].project(\"Y\") for x in scetlibZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [scetlibZ_pdf[{\"vars\": x}].project(\"Y\") for x in scetlibZ_pdf.axes[\"vars\"]],\n", + " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"SCETlib\")" ] }, @@ -711,7 +792,12 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibWm_pdf = pickle.load(open(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_NP0_PDFVars_combined.pkl\", \"rb\"))[\"hist\"]" + "scetlibWm_pdf = pickle.load(\n", + " open(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_NP0_PDFVars_combined.pkl\",\n", + " \"rb\",\n", + " )\n", + ")[\"hist\"]" ] }, { @@ -744,19 +830,20 @@ "source": [ "s = hist.tag.Slicer()\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibWm_pdf[{\"vars\" : x}].project(\"Y\") for x in scetlibWm_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibWm_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell^{-}\\nu}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [scetlibWm_pdf[{\"vars\": x}].project(\"Y\") for x in scetlibWm_pdf.axes[\"vars\"]],\n", + " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibWm_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell^{-}\\nu}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"SCETlib\")" ] }, @@ -787,19 +874,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibZ_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " *theory_tools.hessianPdfUnc(scetlibZ_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"),\n", - " ],\n", - " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=18,\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " scetlibZ_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " *theory_tools.hessianPdfUnc(\n", + " scetlibZ_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"\n", + " ),\n", + " ],\n", + " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=18,\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -810,19 +902,20 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibWm_pdf[{\"vars\" : x}].project(\"qT\") for x in scetlibWm_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibWm_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"p$_{T}^{\\ell^{-}\\nu}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [scetlibWm_pdf[{\"vars\": x}].project(\"qT\") for x in scetlibWm_pdf.axes[\"vars\"]],\n", + " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibWm_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"p$_{T}^{\\ell^{-}\\nu}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -856,19 +949,23 @@ "s = hist.tag.Slicer()\n", "minnlo_wm_pdf_rebin = hh.rebinHist(minnlo_wm_pdf, \"y\", scetlibWm_pdf.axes[\"Y\"].edges)\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " minnlo_wm_pdf_rebin[{\"pdfVar\" : x}].project(\"y\") for x in minnlo_wm_pdf.axes[\"pdfVar\"]\n", - " ],\n", - " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibWm_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell^{-}\\nu}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " minnlo_wm_pdf_rebin[{\"pdfVar\": x}].project(\"y\")\n", + " for x in minnlo_wm_pdf.axes[\"pdfVar\"]\n", + " ],\n", + " labels=list(scetlibWm_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibWm_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell^{-}\\nu}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"MiNNLO\")" ] }, @@ -900,23 +997,25 @@ } ], "source": [ - "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " minnlo_wm_pdf[{\"pdfVar\" : 0}].project(\"y\"),\n", - " minnlo_wm_pdfas[{\"alphasVar\" : \"as0116\"}].project(\"y\"),\n", - " minnlo_wm_pdfas[{\"alphasVar\" : \"as0120\"}].project(\"y\"),\n", - " ],\n", - " labels=[\"central\", \"asDown\", \"asUp\"],\n", - " colors=[\"red\", \"grey\", \"blue\"], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell^{-}\\nu}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " minnlo_wm_pdf[{\"pdfVar\": 0}].project(\"y\"),\n", + " minnlo_wm_pdfas[{\"alphasVar\": \"as0116\"}].project(\"y\"),\n", + " minnlo_wm_pdfas[{\"alphasVar\": \"as0120\"}].project(\"y\"),\n", + " ],\n", + " labels=[\"central\", \"asDown\", \"asUp\"],\n", + " colors=[\"red\", \"grey\", \"blue\"],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell^{-}\\nu}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"MiNNLO\")" ] }, @@ -951,8 +1050,12 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboZ_pdf = input_tools.read_dyturbo_pdf_hist(\"/scratch/shared/TheoryPredictions/DYTurbo/Z/msht20nnlo/pdfvars/results_z-2d-nnlo-vj-member{i}-scetlibmatch.txt\",\n", - " pdf_members=65, axes=(\"Y\", \"qT\"), charge=0)" + "dyturboZ_pdf = input_tools.read_dyturbo_pdf_hist(\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/msht20nnlo/pdfvars/results_z-2d-nnlo-vj-member{i}-scetlibmatch.txt\",\n", + " pdf_members=65,\n", + " axes=(\"Y\", \"qT\"),\n", + " charge=0,\n", + ")" ] }, { @@ -984,19 +1087,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturboZ_pdf[{\"vars\" : x}].project(\"Y\") for x in dyturboZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturboZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturboZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [dyturboZ_pdf[{\"vars\": x}].project(\"Y\") for x in dyturboZ_pdf.axes[\"vars\"]],\n", + " labels=list(dyturboZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturboZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo\")" ] }, @@ -1029,19 +1133,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturboZ_pdf[{\"vars\" : x}].project(\"qT\") for x in dyturboZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturboZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturboZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [dyturboZ_pdf[{\"vars\": x}].project(\"qT\") for x in dyturboZ_pdf.axes[\"vars\"]],\n", + " labels=list(dyturboZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturboZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo\")" ] }, @@ -1074,19 +1179,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturboZ_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " *theory_tools.hessianPdfUnc(dyturboZ_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"),\n", - " ],\n", - " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturboZ_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " *theory_tools.hessianPdfUnc(\n", + " dyturboZ_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"\n", + " ),\n", + " ],\n", + " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo\")" ] }, @@ -1131,19 +1241,23 @@ "s = hist.tag.Slicer()\n", "minnlo_z_pdf_rebin = hh.rebinHist(minnlo_z_pdf, \"y\", scetlibZ_pdf.axes[\"Y\"].edges)\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " minnlo_z_pdf_rebin[{\"pdfVar\" : x}].project(\"y\") for x in minnlo_wm_pdf.axes[\"pdfVar\"]\n", - " ],\n", - " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " minnlo_z_pdf_rebin[{\"pdfVar\": x}].project(\"y\")\n", + " for x in minnlo_wm_pdf.axes[\"pdfVar\"]\n", + " ],\n", + " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"MiNNLO\")" ] }, @@ -1177,19 +1291,26 @@ "source": [ "minnlo_z_pdf_rebin = hh.rebinHist(minnlo_z_pdf, \"ptVgen\", scetlibZ_pdf.axes[\"qT\"].edges)\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " minnlo_z_pdf_rebin[{\"pdfVar\" : \"pdf0MSHT20\"}].project(\"ptVgen\"),\n", - " *theory_tools.hessianPdfUnc(minnlo_z_pdf_rebin.project(\"ptVgen\", \"pdfVar\"), \"pdfVar\", uncType=\"asymHessian\"),\n", - " ],\n", - " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " minnlo_z_pdf_rebin[{\"pdfVar\": \"pdf0MSHT20\"}].project(\"ptVgen\"),\n", + " *theory_tools.hessianPdfUnc(\n", + " minnlo_z_pdf_rebin.project(\"ptVgen\", \"pdfVar\"),\n", + " \"pdfVar\",\n", + " uncType=\"asymHessian\",\n", + " ),\n", + " ],\n", + " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"MiNNLO\")" ] }, @@ -1200,7 +1321,8 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_scetlib_pdf = input_tools.read_matched_scetlib_dyturbo_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\",\n", + "dyturbo_scetlib_pdf = input_tools.read_matched_scetlib_dyturbo_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/msht20nnlo/pdfvars/results_z-2d-nnlo-vj-member{i}-scetlibmatch.txt\",\n", " axes=(\"Y\", \"qT\"),\n", @@ -1247,19 +1369,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_pdf[{\"vars\" : x}].project(\"Y\") for x in dyturbo_scetlib_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$y^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_pdf[{\"vars\": x}].project(\"Y\")\n", + " for x in dyturbo_scetlib_pdf.axes[\"vars\"]\n", + " ],\n", + " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$y^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib\")" ] }, @@ -1271,7 +1397,12 @@ "outputs": [], "source": [ "import lz4.frame\n", - "res = pickle.load(lz4.frame.open(\"/home/k/kelong/work/WRemnants/utilities/../wremnants/data//TheoryCorrections/scetlib_dyturboMSHT20UncCorrZ.pkl.lz4\"))" + "\n", + "res = pickle.load(\n", + " lz4.frame.open(\n", + " \"/home/k/kelong/work/WRemnants/utilities/../wremnants/data//TheoryCorrections/scetlib_dyturboMSHT20UncCorrZ.pkl.lz4\"\n", + " )\n", + ")" ] }, { @@ -1281,7 +1412,7 @@ "metadata": {}, "outputs": [], "source": [ - "res[\"Z\"][\"scetlib_dyturboMSHT20Unc_hist\"][{\"vars\" : 0}].sum()" + "res[\"Z\"][\"scetlib_dyturboMSHT20Unc_hist\"][{\"vars\": 0}].sum()" ] }, { @@ -1313,19 +1444,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " *theory_tools.hessianPdfUnc(dyturbo_scetlib_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"),\n", - " ],\n", - " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " *theory_tools.hessianPdfUnc(\n", + " dyturbo_scetlib_pdf.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"\n", + " ),\n", + " ],\n", + " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib\")" ] }, @@ -1358,19 +1494,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_pdf[{\"vars\" : x}].project(\"qT\") for x in dyturbo_scetlib_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.98, 1.02],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_pdf[{\"vars\": x}].project(\"qT\")\n", + " for x in dyturbo_scetlib_pdf.axes[\"vars\"]\n", + " ],\n", + " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.98, 1.02],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib\")" ] }, @@ -1403,19 +1543,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibZ_pdf[{\"vars\" : x}].project(\"qT\") for x in scetlibZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibZ_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [scetlibZ_pdf[{\"vars\": x}].project(\"qT\") for x in scetlibZ_pdf.axes[\"vars\"]],\n", + " labels=list(scetlibZ_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibZ_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"SCETlib\")" ] }, @@ -1448,19 +1589,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturboZ_pdf[{\"vars\" : x}].project(\"qT\") for x in dyturboZ_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [dyturboZ_pdf[{\"vars\": x}].project(\"qT\") for x in dyturboZ_pdf.axes[\"vars\"]],\n", + " labels=list(dyturbo_scetlib_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturbo_scetlib_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo\")" ] }, @@ -1471,7 +1613,9 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibZ_pdf = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\")" + "scetlibZ_pdf = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\"\n", + ")" ] }, { @@ -1481,7 +1625,9 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibZ_nnlo_sing_pdf = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\")" + "scetlibZ_nnlo_sing_pdf = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\"\n", + ")" ] }, { @@ -1524,22 +1670,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " dyturbo_pt_temp[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " scetlibZ_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " -1*scetlibZ_nnlo_sing_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " dyturbo_pt_temp[{\"vars\" : \"pdf0\"}].project(\"qT\")+-1*scetlibZ_nnlo_sing_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\")\n", - " ],\n", - " labels=[\"NNLO+N3LL\", \"DYTurbo NNLO\", \"SCETlib N$^{3}LL$\", \"SCETlib NNLO sing.\", \"NNLO nonsing.\"],\n", - " colors=[\"black\", \"red\", \"blue\", \"purple\", \"green\"],\n", - " linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", ],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/NNLO+N3LL\",\n", - " legtext_size=20,\n", - " rrange=[0.0,2],\n", - " yscale=1.1,\n", + " [\n", + " dyturbo_scetlib_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " dyturbo_pt_temp[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " scetlibZ_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " -1 * scetlibZ_nnlo_sing_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " dyturbo_pt_temp[{\"vars\": \"pdf0\"}].project(\"qT\")\n", + " + -1 * scetlibZ_nnlo_sing_pdf[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"NNLO+N3LL\",\n", + " \"DYTurbo NNLO\",\n", + " \"SCETlib N$^{3}LL$\",\n", + " \"SCETlib NNLO sing.\",\n", + " \"NNLO nonsing.\",\n", + " ],\n", + " colors=[\"black\", \"red\", \"blue\", \"purple\", \"green\"],\n", + " linestyles=[\n", + " \"solid\",\n", + " \"solid\",\n", + " \"solid\",\n", + " \"dashed\",\n", + " \"dashdot\",\n", + " ],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/NNLO+N3LL\",\n", + " legtext_size=20,\n", + " rrange=[0.0, 2],\n", + " yscale=1.1,\n", ")\n", "fig.get_axes()[0].set_title(\"Central pdf\")" ] @@ -1573,22 +1732,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_pdf[{\"vars\" : \"pdf1\"}].project(\"qT\"),\n", - " dyturbo_pt_temp[{\"vars\" : \"pdf1\"}].project(\"qT\"),\n", - " scetlibZ_pdf[{\"vars\" : \"pdf1\"}].project(\"qT\"),\n", - " -1*scetlibZ_nnlo_sing_pdf[{\"vars\" : \"pdf1\"}].project(\"qT\"),\n", - " dyturbo_pt_temp[{\"vars\" : \"pdf1\"}].project(\"qT\")+-1*scetlibZ_nnlo_sing_pdf[{\"vars\" : \"pdf1\"}].project(\"qT\")\n", - " ],\n", - " labels=[\"NNLO+N3LL\", \"DYTurbo NNLO\", \"SCETlib N$^{3}LL$\", \"SCETlib NNLO sing.\", \"NNLO nonsing.\"],\n", - " colors=[\"black\", \"red\", \"blue\", \"purple\", \"green\"],\n", - " linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", ],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/NNLO+N3LL\",\n", - " legtext_size=20,\n", - " rrange=[0.5, 1.5],\n", - " yscale=1.1,\n", + " [\n", + " dyturbo_scetlib_pdf[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " dyturbo_pt_temp[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " scetlibZ_pdf[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " -1 * scetlibZ_nnlo_sing_pdf[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " dyturbo_pt_temp[{\"vars\": \"pdf1\"}].project(\"qT\")\n", + " + -1 * scetlibZ_nnlo_sing_pdf[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"NNLO+N3LL\",\n", + " \"DYTurbo NNLO\",\n", + " \"SCETlib N$^{3}LL$\",\n", + " \"SCETlib NNLO sing.\",\n", + " \"NNLO nonsing.\",\n", + " ],\n", + " colors=[\"black\", \"red\", \"blue\", \"purple\", \"green\"],\n", + " linestyles=[\n", + " \"solid\",\n", + " \"solid\",\n", + " \"solid\",\n", + " \"dashed\",\n", + " \"dashdot\",\n", + " ],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/NNLO+N3LL\",\n", + " legtext_size=20,\n", + " rrange=[0.5, 1.5],\n", + " yscale=1.1,\n", ")\n", "fig.get_axes()[0].set_title(\"pdf1\")" ] @@ -1622,19 +1794,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " scetlibZ_nnlo_sing_pdf[{\"vars\" : x}].project(\"qT\") for x in scetlibZ_nnlo_sing_pdf.axes[\"vars\"]\n", - " ],\n", - " labels=list(scetlibZ_nnlo_sing_pdf.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(scetlibZ_nnlo_sing_pdf.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " scetlibZ_nnlo_sing_pdf[{\"vars\": x}].project(\"qT\")\n", + " for x in scetlibZ_nnlo_sing_pdf.axes[\"vars\"]\n", + " ],\n", + " labels=list(scetlibZ_nnlo_sing_pdf.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(scetlibZ_nnlo_sing_pdf.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"SCETlib NNLO sing.\")" ] }, @@ -1656,10 +1832,10 @@ } ], "source": [ - "print(scetlibZ_nnlo_sing_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\")[99.j])\n", - "print(scetlibZ_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\")[99.j])\n", - "print(dyturbo_pt_temp[{\"vars\" : \"pdf0\"}].project(\"qT\")[99.j])\n", - "print(dyturbo_scetlib_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\")[99.j])" + "print(scetlibZ_nnlo_sing_pdf[{\"vars\": \"pdf0\"}].project(\"qT\")[99.0j])\n", + "print(scetlibZ_pdf[{\"vars\": \"pdf0\"}].project(\"qT\")[99.0j])\n", + "print(dyturbo_pt_temp[{\"vars\": \"pdf0\"}].project(\"qT\")[99.0j])\n", + "print(dyturbo_scetlib_pdf[{\"vars\": \"pdf0\"}].project(\"qT\")[99.0j])" ] }, { @@ -1680,11 +1856,11 @@ } ], "source": [ - "pdf=\"pdf12\"\n", - "print(scetlibZ_nnlo_sing_pdf[{\"vars\" : pdf}].project(\"qT\")[99.j])\n", - "print(scetlibZ_pdf[{\"vars\" : pdf}].project(\"qT\")[99.j])\n", - "print(dyturbo_pt_temp[{\"vars\" : pdf}].project(\"qT\")[99.j])\n", - "print(dyturbo_scetlib_pdf[{\"vars\" : pdf}].project(\"qT\")[99.j])" + "pdf = \"pdf12\"\n", + "print(scetlibZ_nnlo_sing_pdf[{\"vars\": pdf}].project(\"qT\")[99.0j])\n", + "print(scetlibZ_pdf[{\"vars\": pdf}].project(\"qT\")[99.0j])\n", + "print(dyturbo_pt_temp[{\"vars\": pdf}].project(\"qT\")[99.0j])\n", + "print(dyturbo_scetlib_pdf[{\"vars\": pdf}].project(\"qT\")[99.0j])" ] }, { @@ -1710,7 +1886,8 @@ } ], "source": [ - "dyturbo_scetlib_nons_pdf = input_tools.read_matched_scetlib_dyturbo_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\",\n", + "dyturbo_scetlib_nons_pdf = input_tools.read_matched_scetlib_dyturbo_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/msht20nnlo/pdfvars/results_z-2d-nnlo-vj-member{i}-scetlibmatch.txt\",\n", " axes=(\"Y\", \"qT\"),\n", @@ -1760,7 +1937,7 @@ } ], "source": [ - "scetlibZ_pdf[{\"vars\" : \"pdf0\"}].project(\"qT\").values()" + "scetlibZ_pdf[{\"vars\": \"pdf0\"}].project(\"qT\").values()" ] }, { @@ -1808,19 +1985,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_msht20an3lo[{\"vars\" : x}].project(\"qT\") for x in dyturbo_scetlib_msht20an3lo.axes[\"vars\"]\n", - " ],\n", - " labels=list(dyturbo_scetlib_msht20an3lo.axes[\"vars\"]),\n", - " colors=[\"red\"]+([\"grey\"]*len(dyturbo_scetlib_msht20an3lo.axes[\"vars\"]))[:-1], \n", - " #linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.98, 1.02],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_msht20an3lo[{\"vars\": x}].project(\"qT\")\n", + " for x in dyturbo_scetlib_msht20an3lo.axes[\"vars\"]\n", + " ],\n", + " labels=list(dyturbo_scetlib_msht20an3lo.axes[\"vars\"]),\n", + " colors=[\"red\"] + ([\"grey\"] * len(dyturbo_scetlib_msht20an3lo.axes[\"vars\"]))[:-1],\n", + " # linestyles=[\"solid\", \"solid\", \"solid\", \"dashed\", \"dashdot\", \"solid\", \"solid\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.98, 1.02],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib (MSHT20aN3LO)\")" ] }, @@ -1853,19 +2034,26 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_msht20an3lo[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " *theory_tools.hessianPdfUnc(dyturbo_scetlib_msht20an3lo.project(\"qT\", \"vars\"), \"vars\", uncType=\"asymHessian\"),\n", - " ],\n", - " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_msht20an3lo[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " *theory_tools.hessianPdfUnc(\n", + " dyturbo_scetlib_msht20an3lo.project(\"qT\", \"vars\"),\n", + " \"vars\",\n", + " uncType=\"asymHessian\",\n", + " ),\n", + " ],\n", + " labels=[\"Central\", \"PDF $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib (MSHT20aN3LO)\")" ] }, @@ -2002,20 +2190,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " dyturbo_scetlib_tnp[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " dyturbo_scetlib_tnp[{\"vars\" : \"b_qqV+1\"}].project(\"qT\"),\n", - " dyturbo_scetlib_tnp[{\"vars\" : \"b_qqV-1\"}].project(\"qT\"),\n", - " ],\n", - " labels=[\"Central\", \"gamma_cusp $\\pm 1\\sigma$\", \"\"],\n", - " colors=[\"red\"]+[\"grey\"]*2, \n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/pdf0\",\n", - " legtext_size=8,\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " dyturbo_scetlib_tnp[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " dyturbo_scetlib_tnp[{\"vars\": \"b_qqV+1\"}].project(\"qT\"),\n", + " dyturbo_scetlib_tnp[{\"vars\": \"b_qqV-1\"}].project(\"qT\"),\n", + " ],\n", + " labels=[\"Central\", \"gamma_cusp $\\pm 1\\sigma$\", \"\"],\n", + " colors=[\"red\"] + [\"grey\"] * 2,\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/pdf0\",\n", + " legtext_size=8,\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "fig.get_axes()[0].set_title(\"DYTurbo+SCETlib\")" ] } diff --git a/notebooks/EWClosure.ipynb b/notebooks/EWClosure.ipynb index d116fa077..35bcd592d 100644 --- a/notebooks/EWClosure.ipynb +++ b/notebooks/EWClosure.ipynb @@ -29,7 +29,9 @@ "metadata": {}, "outputs": [], "source": [ - "res, meta, _ = input_tools.read_infile(\"/scratch/dwalter/results_histmaker/230907_ew_closure/w_z_gen_dists.hdf5\")" + "res, meta, _ = input_tools.read_infile(\n", + " \"/scratch/dwalter/results_histmaker/230907_ew_closure/w_z_gen_dists.hdf5\"\n", + ")" ] }, { @@ -79,21 +81,21 @@ "base_process = \"WplusToMuNu\"\n", "# base_process = \"WminusToMuNu\"\n", "# base_process = \"ZToMuMu\"\n", - "# generator = \"winhac\" \n", + "# generator = \"winhac\"\n", "generator = \"horace\"\n", "generatorNLO = \"horace\"\n", "process = f\"{base_process}_{generator}\"\n", "processNLO = f\"{base_process}_{generatorNLO}\"\n", "var = \"ewLepEta1\"\n", "showFlow = False\n", - "flow=True\n", + "flow = True\n", "colors = mpl.colormaps[\"tab10\"]\n", "text_dict = {\n", " \"ZToMuMu\": r\"$\\mathrm{Z}\\rightarrow\\mu\\mu$\",\n", " \"WplusToMuNu\": r\"$\\mathrm{W}^+\\rightarrow\\mu\\nu$\",\n", - " \"WminusToMuNu\": r\"$\\mathrm{W}^-\\rightarrow\\mu\\nu$\"\n", + " \"WminusToMuNu\": r\"$\\mathrm{W}^-\\rightarrow\\mu\\nu$\",\n", "}\n", - "plotname = f\"{process}{var}\"\n" + "plotname = f\"{process}{var}\"" ] }, { @@ -105,11 +107,15 @@ "source": [ "def load(process, order, var, appendix=\"\", idx=None):\n", " proc_name = f\"{process}-{order}\"\n", - " histo = res[proc_name]['output'][f\"nominal_{var}{appendix}\"].get()\n", + " histo = res[proc_name][\"output\"][f\"nominal_{var}{appendix}\"].get()\n", " if idx is not None:\n", - " histo = histo[...,idx]\n", - " histo = hh.scaleHist(histo, res[proc_name][\"dataset\"][\"xsec\"]*10e6/res[proc_name]['weight_sum'], createNew=True)\n", - " return histo\n" + " histo = histo[..., idx]\n", + " histo = hh.scaleHist(\n", + " histo,\n", + " res[proc_name][\"dataset\"][\"xsec\"] * 10e6 / res[proc_name][\"weight_sum\"],\n", + " createNew=True,\n", + " )\n", + " return histo" ] }, { @@ -121,7 +127,7 @@ "source": [ "hLO_Uncorr = load(process, \"lo-photos\", var)\n", "hLO_Corr = load(process, \"lo-photos\", var, appendix=\"_horacenloewCorr\", idx=1)\n", - "hNLO = load(processNLO, \"nlo\", var)\n" + "hNLO = load(processNLO, \"nlo\", var)" ] }, { @@ -152,61 +158,89 @@ "outputs": [], "source": [ "def plot(h1ds, ratio=False):\n", - " \n", - " labels = [f\"{generator} LO\",f\"{generator} \" + r\"LO $\\times$ Corr(Horace)\", f\"{generatorNLO} NLO\"]\n", + "\n", + " labels = [\n", + " f\"{generator} LO\",\n", + " f\"{generator} \" + r\"LO $\\times$ Corr(Horace)\",\n", + " f\"{generatorNLO} NLO\",\n", + " ]\n", " linestyles = [\"-\", \"--\", \":\"]\n", - " \n", + "\n", " if ratio:\n", - " ylabel=f\"1./{labels[-1]}\"\n", + " ylabel = f\"1./{labels[-1]}\"\n", " else:\n", - " ylabel=\"a.u.\"\n", - " \n", + " ylabel = \"a.u.\"\n", + "\n", " ymin = None if ratio else 0\n", " ymax = None\n", "\n", - " ymax = ymax if ymax is not None else max([max(h.values(flow=showFlow)) for h in h1ds])\n", - " ymin = ymin if ymin is not None else min([min(h.values(flow=showFlow)) for h in h1ds])\n", + " ymax = (\n", + " ymax if ymax is not None else max([max(h.values(flow=showFlow)) for h in h1ds])\n", + " )\n", + " ymin = (\n", + " ymin if ymin is not None else min([min(h.values(flow=showFlow)) for h in h1ds])\n", + " )\n", " yrange = ymax - ymin\n", - " ymin = ymin if ymin == 0 else ymin - yrange*0.3\n", - " ymax = ymax + yrange*0.3\n", + " ymin = ymin if ymin == 0 else ymin - yrange * 0.3\n", + " ymax = ymax + yrange * 0.3\n", "\n", - " fig, ax = plot_tools.figure(hNLO, \n", - " xlabel=xaxis_labels[var], ylabel=ylabel, cms_label=\"Preliminary\", \n", - " automatic_scale=False, width_scale=1.2,ylim=(ymin, ymax))\n", + " fig, ax = plot_tools.figure(\n", + " hNLO,\n", + " xlabel=xaxis_labels[var],\n", + " ylabel=ylabel,\n", + " cms_label=\"Preliminary\",\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", + " ylim=(ymin, ymax),\n", + " )\n", " if ratio:\n", " x = h1ds[0].axes.edges[0][:-1]\n", - " ax.plot([min(x), max(x)], [1,1], color=\"black\", linestyle=\"--\")\n", - " \n", + " ax.plot([min(x), max(x)], [1, 1], color=\"black\", linestyle=\"--\")\n", + "\n", " for i, h1d in enumerate(h1ds):\n", " x = h1d.axes.edges[0][:-1]\n", " y = h1d.values(flow=flow)\n", " err = np.sqrt(h1d.variances(flow=flow))\n", "\n", - " ax.set_xlim((min(x),max(x)))\n", - " ax.set_ylim((ymin,ymax))\n", + " ax.set_xlim((min(x), max(x)))\n", + " ax.set_ylim((ymin, ymax))\n", "\n", " if flow:\n", " # add extra bin with bin wdith of 1% of total width\n", " rangex = x[-1] - x[0]\n", "\n", " if h1d.axes[0].traits.underflow:\n", - " x = np.insert(x, 0, x[0] - rangex*0.02)\n", + " x = np.insert(x, 0, x[0] - rangex * 0.02)\n", " if h1d.axes[0].traits.overflow:\n", - " x = np.append(x, x[-1] + rangex*0.02)\n", + " x = np.append(x, x[-1] + rangex * 0.02)\n", "\n", " if showFlow:\n", - " ax.set_xlim((min(x),max(x)))\n", - " \n", - "# ax.set_xlim(26,56)#-2.4,2.4)\n", + " ax.set_xlim((min(x), max(x)))\n", + "\n", + " # ax.set_xlim(26,56)#-2.4,2.4)\n", "\n", - " ax.step(x, y, color=colors(i), linestyle=linestyles[i], label=labels[i], where=\"post\")\n", + " ax.step(\n", + " x,\n", + " y,\n", + " color=colors(i),\n", + " linestyle=linestyles[i],\n", + " label=labels[i],\n", + " where=\"post\",\n", + " )\n", " # ax.fill_between(x, y - err, y + err, alpha=0.3, color=colors(i), step=\"post\")\n", "\n", - " ax.text(1.0, 1.003, text_dict[base_process], transform=ax.transAxes, fontsize=30,\n", - " verticalalignment='bottom', horizontalalignment=\"right\")\n", + " ax.text(\n", + " 1.0,\n", + " 1.003,\n", + " text_dict[base_process],\n", + " transform=ax.transAxes,\n", + " fontsize=30,\n", + " verticalalignment=\"bottom\",\n", + " horizontalalignment=\"right\",\n", + " )\n", " plot_tools.addLegend(ax, ncols=2, text_size=12)\n", " if ratio:\n", - " plot_name = plotname+\"_ratio\"\n", + " plot_name = plotname + \"_ratio\"\n", " else:\n", " plot_name = plotname\n", " plot_tools.save_pdf_and_png(\"./\", plot_name)" diff --git a/notebooks/EWCorrections_FSR.ipynb b/notebooks/EWCorrections_FSR.ipynb index c421bba55..739892548 100644 --- a/notebooks/EWCorrections_FSR.ipynb +++ b/notebooks/EWCorrections_FSR.ipynb @@ -32,22 +32,22 @@ " \"absYVgen\": r\"Pre FSR $|Y^{\\ell\\ell}|$\",\n", "}\n", "t_label_num = {\n", - " \"pythiaew_ISR\": \"pythia QED ISR on\", \n", - " \"winhacloew\": \"winhac FSR\", \n", - " \"horaceqedew\": \"horace FSR\", \n", - " \"horacelophotosmecoffew\": \"photos(MEC off) FSR\", \n", + " \"pythiaew_ISR\": \"pythia QED ISR on\",\n", + " \"winhacloew\": \"winhac FSR\",\n", + " \"horaceqedew\": \"horace FSR\",\n", + " \"horacelophotosmecoffew\": \"photos(MEC off) FSR\",\n", " \"MiNNLOew_ISR\": \"QED ISR\",\n", " \"MiNNLOew_v2\": \"QED ISR\",\n", - " \"MiNNLOnoqedisrew_ISR\": \"pythia no QED ISR\", \n", + " \"MiNNLOnoqedisrew_ISR\": \"pythia no QED ISR\",\n", "}\n", "t_label_den = {\n", - " \"pythiaew_ISR\": \"pythia QED ISR off\", \n", - " \"winhacloew\": \"photos FSR\", \n", - " \"horaceqedew\": \"photos FSR\", \n", - " \"horacelophotosmecoffew\": \"photos FSR\", \n", + " \"pythiaew_ISR\": \"pythia QED ISR off\",\n", + " \"winhacloew\": \"photos FSR\",\n", + " \"horaceqedew\": \"photos FSR\",\n", + " \"horacelophotosmecoffew\": \"photos FSR\",\n", " \"MiNNLOew_ISR\": \"no QED ISR\",\n", " \"MiNNLOew_v2\": \"no QED ISR\",\n", - " \"MiNNLOnoqedisrew_ISR\": \"pythia QED ISR\", \n", + " \"MiNNLOnoqedisrew_ISR\": \"pythia QED ISR\",\n", "}\n", "\n", "translate_txt = {\n", @@ -88,7 +88,9 @@ } ], "source": [ - "res, _1, _2 = input_tools.read_infile(\"/scratch/dwalter/results_histmaker/240307_ewISR/w_z_gen_dists.hdf5\")\n", + "res, _1, _2 = input_tools.read_infile(\n", + " \"/scratch/dwalter/results_histmaker/240307_ewISR/w_z_gen_dists.hdf5\"\n", + ")\n", "res.keys()" ] }, @@ -112,8 +114,12 @@ } ], "source": [ - "h1 = input_tools.load_and_scale(res, \"Zmumu_MiNNLO-noqedisr\", \"preFSR_absYVptV\", apply_xsec=False)\n", - "h2 = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"preFSR_absYVptV\", apply_xsec=False)\n", + "h1 = input_tools.load_and_scale(\n", + " res, \"Zmumu_MiNNLO-noqedisr\", \"preFSR_absYVptV\", apply_xsec=False\n", + ")\n", + "h2 = input_tools.load_and_scale(\n", + " res, \"ZmumuPostVFP\", \"preFSR_absYVptV\", apply_xsec=False\n", + ")\n", "print(h1.values(flow=True).sum())\n", "print(h2.values(flow=True).sum())\n", "\n", @@ -123,8 +129,17 @@ "count1 = res[\"Zmumu_MiNNLO-noqedisr\"][\"event_count\"]\n", "count2 = res[\"ZmumuPostVFP\"][\"event_count\"]\n", "\n", - "print(res[\"Zmumu_MiNNLO-noqedisr\"][\"output\"][\"preFSR_absYVptV\"].get().values(flow=True).sum() / count1)\n", - "print(res[\"ZmumuPostVFP\"][\"output\"][\"preFSR_absYVptV\"].get().values(flow=True).sum() / count2)\n" + "print(\n", + " res[\"Zmumu_MiNNLO-noqedisr\"][\"output\"][\"preFSR_absYVptV\"]\n", + " .get()\n", + " .values(flow=True)\n", + " .sum()\n", + " / count1\n", + ")\n", + "print(\n", + " res[\"ZmumuPostVFP\"][\"output\"][\"preFSR_absYVptV\"].get().values(flow=True).sum()\n", + " / count2\n", + ")" ] }, { @@ -146,7 +161,7 @@ } ], "source": [ - "gen=\"pythia\"\n", + "gen = \"pythia\"\n", "hists = get_corr(f\"../test/{gen}ew_ISRCorrZ.pkl.lz4\")\n", "hists.update(get_corr(f\"../test/{gen}ew_ISRCorrW.pkl.lz4\"))\n", "\n", @@ -179,7 +194,9 @@ ], "source": [ "hists = get_corr(\"../wremnants-data/data/TheoryCorrections/MiNNLOew_v2CorrZ.pkl.lz4\")\n", - "hists.update(get_corr(\"../wremnants-data/data/TheoryCorrections/MiNNLOew_v2CorrW.pkl.lz4\"))\n", + "hists.update(\n", + " get_corr(\"../wremnants-data/data/TheoryCorrections/MiNNLOew_v2CorrW.pkl.lz4\")\n", + ")\n", "hists.keys()\n", "hists[\"W\"].keys()" ] @@ -191,39 +208,51 @@ "metadata": {}, "outputs": [], "source": [ - "def plot_corr(process, axis, nums, den, selection=None, xlim=[0,100], rrange=None):\n", - " if type(axis)!=list:\n", + "def plot_corr(process, axis, nums, den, selection=None, xlim=[0, 100], rrange=None):\n", + " if type(axis) != list:\n", " axis = [axis]\n", - " \n", + "\n", " if selection:\n", " h1ds = [\n", - " hists[process][f\"{den}_den\"][selection].project(*axis), \n", - " *[hists[process][f\"{n}_num\"][selection].project(*axis) for n in nums]]\n", + " hists[process][f\"{den}_den\"][selection].project(*axis),\n", + " *[hists[process][f\"{n}_num\"][selection].project(*axis) for n in nums],\n", + " ]\n", " rrange = [0.9975, 1.0025] if rrange is None else rrange\n", " if \"charge\" in selection:\n", - " process = process.replace(\"W\", \"Wminus\") if selection[\"charge\"] == 0 else process.replace(\"W\", \"Wplus\")\n", + " process = (\n", + " process.replace(\"W\", \"Wminus\")\n", + " if selection[\"charge\"] == 0\n", + " else process.replace(\"W\", \"Wplus\")\n", + " )\n", " else:\n", - " h1ds = [hists[process][f\"{den}_den\"].project(*axis), *[hists[process][f\"{n}_num\"].project(*axis) for n in nums]]\n", + " h1ds = [\n", + " hists[process][f\"{den}_den\"].project(*axis),\n", + " *[hists[process][f\"{n}_num\"].project(*axis) for n in nums],\n", + " ]\n", " rrange = [0.996, 1.004] if rrange is None else rrange\n", "\n", " h1ds = [h[{\"massVgen\": hist.rebin(4)}] for h in h1ds]\n", - " \n", - " if len(axis)>1:\n", + "\n", + " if len(axis) > 1:\n", " h1ds = [sel.unrolledHist(h1d, binwnorm=1, obs=axis) for h1d in h1ds]\n", "\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " h1ds,\n", - " [t_label_den.get(den,den), *[t_label_num.get(n, n) for n in nums]],\n", - " colors=[\"black\", *[\"red\", \"blue\"][:len(nums)]], \n", - " linestyles=[\"solid\", *[\"dashed\", \"dotted\"][:len(nums)]],\n", - " xlabel=\" \".join([t_axis.get(a, a) for a in axis]), \n", - " ylabel=\"Events/bin\",\n", - " rlabel=f\"x/{t_label_den.get(den,den)}\",\n", - " legtext_size=16,\n", - " rrange=rrange,\n", - " yscale=1.0,\n", - " xlim=xlim, binwnorm=1.0, baseline=True, extra_text=translate_txt.get(process, rf\"${process}\\rightarrow\\mu\\mu$\"))\n", - " \n", + " h1ds,\n", + " [t_label_den.get(den, den), *[t_label_num.get(n, n) for n in nums]],\n", + " colors=[\"black\", *[\"red\", \"blue\"][: len(nums)]],\n", + " linestyles=[\"solid\", *[\"dashed\", \"dotted\"][: len(nums)]],\n", + " xlabel=\" \".join([t_axis.get(a, a) for a in axis]),\n", + " ylabel=\"Events/bin\",\n", + " rlabel=f\"x/{t_label_den.get(den,den)}\",\n", + " legtext_size=16,\n", + " rrange=rrange,\n", + " yscale=1.0,\n", + " xlim=xlim,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " extra_text=translate_txt.get(process, rf\"${process}\\rightarrow\\mu\\mu$\"),\n", + " )\n", + "\n", " output_tools.make_plot_dir(webdir, process)\n", " out = os.path.join(webdir, process)\n", " plot_tools.save_pdf_and_png(out, f\"{den}_{process}_{axis}\")\n", @@ -248,7 +277,16 @@ } ], "source": [ - "plot_corr(\"Z\", [\"absYVgen\",\"ptVgen\"], [f\"{gen}ew_ISR\",], f\"{gen}ew_ISR\", xlim=[0,2.5], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"Z\",\n", + " [\"absYVgen\", \"ptVgen\"],\n", + " [\n", + " f\"{gen}ew_ISR\",\n", + " ],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 2.5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -274,7 +312,14 @@ } ], "source": [ - "plot_corr(\"Z\", \"massVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[60,120], rrange=[0.995,1.005])\n", + "plot_corr(\n", + " \"Z\",\n", + " \"massVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[60, 120],\n", + " rrange=[0.995, 1.005],\n", + ")\n", "# plot_corr(\"W\", \"ewMll\", [\"MiNNLOew_v2\"], \"MiNNLOew_v2\", selection={\"charge\":0}, xlim=[50,110], rrange=[0.995,1.005])\n", "# plot_corr(\"W\", \"ewMll\", [\"MiNNLOew_v2\"], \"MiNNLOew_v2\", selection={\"charge\":1}, xlim=[50,110], rrange=[0.995,1.005])" ] @@ -347,12 +392,53 @@ } ], "source": [ - "plot_corr(\"Z\", \"ptVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,100], rrange=[0.99,1.01])\n", - "plot_corr(\"Z\", \"absYVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,5], rrange=[0.998,1.002])\n", - "plot_corr(\"W\", \"ptVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,100], rrange=[0.995,1.005], selection={\"charge\":0})\n", - "plot_corr(\"W\", \"absYVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,5], rrange=[0.998,1.002], selection={\"charge\":0})\n", - "plot_corr(\"W\", \"ptVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,100], rrange=[0.995,1.005], selection={\"charge\":1})\n", - "plot_corr(\"W\", \"absYVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0,5], rrange=[0.998,1.002], selection={\"charge\":1})" + "plot_corr(\n", + " \"Z\", \"ptVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[0, 100], rrange=[0.99, 1.01]\n", + ")\n", + "plot_corr(\n", + " \"Z\",\n", + " \"absYVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 5],\n", + " rrange=[0.998, 1.002],\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"ptVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 100],\n", + " rrange=[0.995, 1.005],\n", + " selection={\"charge\": 0},\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"absYVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 5],\n", + " rrange=[0.998, 1.002],\n", + " selection={\"charge\": 0},\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"ptVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 100],\n", + " rrange=[0.995, 1.005],\n", + " selection={\"charge\": 1},\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"absYVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[0, 5],\n", + " rrange=[0.998, 1.002],\n", + " selection={\"charge\": 1},\n", + ")" ] }, { @@ -383,8 +469,24 @@ } ], "source": [ - "plot_corr(\"W\", \"ewPTll\", [\"MiNNLOew_ISR\"], \"MiNNLOew_ISR\", selection={\"charge\":0}, xlim=[0,100], rrange=[0.995,1.005])\n", - "plot_corr(\"W\", \"ewAbsYll\", [\"MiNNLOew_ISR\"], \"MiNNLOew_ISR\", selection={\"charge\":0}, xlim=[0,5], rrange=[0.995,1.005])" + "plot_corr(\n", + " \"W\",\n", + " \"ewPTll\",\n", + " [\"MiNNLOew_ISR\"],\n", + " \"MiNNLOew_ISR\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 100],\n", + " rrange=[0.995, 1.005],\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"ewAbsYll\",\n", + " [\"MiNNLOew_ISR\"],\n", + " \"MiNNLOew_ISR\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 5],\n", + " rrange=[0.995, 1.005],\n", + ")" ] }, { @@ -415,8 +517,24 @@ } ], "source": [ - "plot_corr(\"W\", \"ewPTll\", [\"MiNNLOew_ISR\"], \"MiNNLOew_ISR\", selection={\"charge\":1}, xlim=[0,100], rrange=[0.995,1.005])\n", - "plot_corr(\"W\", \"ewAbsYll\", [\"MiNNLOew_ISR\"], \"MiNNLOew_ISR\", selection={\"charge\":1}, xlim=[0,5], rrange=[0.995,1.005])" + "plot_corr(\n", + " \"W\",\n", + " \"ewPTll\",\n", + " [\"MiNNLOew_ISR\"],\n", + " \"MiNNLOew_ISR\",\n", + " selection={\"charge\": 1},\n", + " xlim=[0, 100],\n", + " rrange=[0.995, 1.005],\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"ewAbsYll\",\n", + " [\"MiNNLOew_ISR\"],\n", + " \"MiNNLOew_ISR\",\n", + " selection={\"charge\": 1},\n", + " xlim=[0, 5],\n", + " rrange=[0.995, 1.005],\n", + ")" ] }, { @@ -457,9 +575,32 @@ } ], "source": [ - "plot_corr(\"Z\", \"massVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[60,120], rrange=[0.998,1.002])\n", - "plot_corr(\"W\", \"massVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[50,110], rrange=[0.998,1.002], selection={\"charge\":0})\n", - "plot_corr(\"W\", \"massVgen\", [f\"{gen}ew_ISR\"], f\"{gen}ew_ISR\", xlim=[50,110], rrange=[0.998,1.002], selection={\"charge\":1})" + "plot_corr(\n", + " \"Z\",\n", + " \"massVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[60, 120],\n", + " rrange=[0.998, 1.002],\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"massVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[50, 110],\n", + " rrange=[0.998, 1.002],\n", + " selection={\"charge\": 0},\n", + ")\n", + "plot_corr(\n", + " \"W\",\n", + " \"massVgen\",\n", + " [f\"{gen}ew_ISR\"],\n", + " f\"{gen}ew_ISR\",\n", + " xlim=[50, 110],\n", + " rrange=[0.998, 1.002],\n", + " selection={\"charge\": 1},\n", + ")" ] }, { @@ -480,7 +621,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Mll\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", selection={\"charge\":1}, xlim=[50,110], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Mll\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " selection={\"charge\": 1},\n", + " xlim=[50, 110],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -501,7 +650,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Mll\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", selection={\"charge\":0}, xlim=[50,110], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Mll\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[50, 110],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -522,7 +679,16 @@ } ], "source": [ - "plot_corr(\"W\", \"ewPTll\", [\"winhacloew\", ], \"winhacloew\", selection={\"charge\":0}, xlim=[0,100])" + "plot_corr(\n", + " \"W\",\n", + " \"ewPTll\",\n", + " [\n", + " \"winhacloew\",\n", + " ],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 100],\n", + ")" ] }, { @@ -543,7 +709,16 @@ } ], "source": [ - "plot_corr(\"W\", \"ewPTll\", [\"winhacloew\", ], \"winhacloew\", selection={\"charge\":1}, xlim=[0,100])" + "plot_corr(\n", + " \"W\",\n", + " \"ewPTll\",\n", + " [\n", + " \"winhacloew\",\n", + " ],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 1},\n", + " xlim=[0, 100],\n", + ")" ] }, { @@ -564,7 +739,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Mll\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":0}, xlim=[50,110], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Mll\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[50, 110],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -585,7 +768,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Mll\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":1}, xlim=[50,110], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Mll\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 1},\n", + " xlim=[50, 110],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -606,7 +797,14 @@ } ], "source": [ - "plot_corr(\"Z\", \"Yll\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", xlim=[0,5], rrange=[0.99, 1.01])" + "plot_corr(\n", + " \"Z\",\n", + " \"Yll\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " xlim=[0, 5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -627,7 +825,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Yll\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", selection={\"charge\":0}, xlim=[0,5], rrange=[0.99, 1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Yll\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -648,7 +854,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Yll\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", selection={\"charge\":1}, xlim=[0,5], rrange=[0.99, 1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Yll\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " selection={\"charge\": 1},\n", + " xlim=[0, 5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -669,7 +883,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Yll\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":0}, xlim=[0,5], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Yll\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -690,7 +912,15 @@ } ], "source": [ - "plot_corr(\"W\", \"Yll\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":1}, xlim=[0,5], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"Yll\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 1},\n", + " xlim=[0, 5],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -711,7 +941,13 @@ } ], "source": [ - "plot_corr(\"Z\", \"postfsrLep_pt\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", xlim=[20,70])" + "plot_corr(\n", + " \"Z\",\n", + " \"postfsrLep_pt\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " xlim=[20, 70],\n", + ")" ] }, { @@ -732,7 +968,13 @@ } ], "source": [ - "plot_corr(\"Z\", \"postfsrLep_absEta\", [\"horaceqedew\", \"horacelophotosmecoffew\"], \"horaceqedew\", xlim=[0,2.5])" + "plot_corr(\n", + " \"Z\",\n", + " \"postfsrLep_absEta\",\n", + " [\"horaceqedew\", \"horacelophotosmecoffew\"],\n", + " \"horaceqedew\",\n", + " xlim=[0, 2.5],\n", + ")" ] }, { @@ -776,7 +1018,15 @@ } ], "source": [ - "plot_corr(\"W\", \"postfsrLep_pt\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":0}, xlim=[20,70], rrange=[0.99,1.01])" + "plot_corr(\n", + " \"W\",\n", + " \"postfsrLep_pt\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[20, 70],\n", + " rrange=[0.99, 1.01],\n", + ")" ] }, { @@ -797,7 +1047,15 @@ } ], "source": [ - "plot_corr(\"W\", \"postfsrLep_absEta\", [\"winhacloew\"], \"winhacloew\", selection={\"charge\":0}, xlim=[0,2.5], rrange=[0.999,1.001])" + "plot_corr(\n", + " \"W\",\n", + " \"postfsrLep_absEta\",\n", + " [\"winhacloew\"],\n", + " \"winhacloew\",\n", + " selection={\"charge\": 0},\n", + " xlim=[0, 2.5],\n", + " rrange=[0.999, 1.001],\n", + ")" ] }, { diff --git a/notebooks/LowPileupScratch.ipynb b/notebooks/LowPileupScratch.ipynb index 853324091..15abe0326 100644 --- a/notebooks/LowPileupScratch.ipynb +++ b/notebooks/LowPileupScratch.ipynb @@ -42,8 +42,8 @@ "source": [ "procDict = groups.datagroupsForHist(\"mt_reco_pf\", syst=\"nominal\", label=\"nominal\")\n", "\n", - "#procDict = groups.datagroupsForHist(\"mt_gen_reco_pf\", procsToRead=[\"Wmunu\"], syst=\"nominal\", label=\"nominal\")\n", - "#procDict[\"Wmunu\"][\"nominal\"]# = procDict[\"Wmunu\"][\"nominal\"].project(\"qTreco\", \"charge\", \"mt\")" + "# procDict = groups.datagroupsForHist(\"mt_gen_reco_pf\", procsToRead=[\"Wmunu\"], syst=\"nominal\", label=\"nominal\")\n", + "# procDict[\"Wmunu\"][\"nominal\"]# = procDict[\"Wmunu\"][\"nominal\"].project(\"qTreco\", \"charge\", \"mt\")" ] }, { @@ -53,7 +53,9 @@ "metadata": {}, "outputs": [], "source": [ - "procDict = groups.datagroupsForHist(\"mt_reco_pf\", syst=\"PDF\", procsToRead=[\"Wmunu\"], label=\"PDF\")" + "procDict = groups.datagroupsForHist(\n", + " \"mt_reco_pf\", syst=\"PDF\", procsToRead=[\"Wmunu\"], label=\"PDF\"\n", + ")" ] }, { @@ -155,7 +157,7 @@ "source": [ "s = hist.tag.Slicer()\n", "h = procDict[\"Wmunu\"][\"PDF\"]\n", - "#procDict[\"Wmunu\"][\"PDF\"][{\"mt\" : s[::hist.sum]}]\n", + "# procDict[\"Wmunu\"][\"PDF\"][{\"mt\" : s[::hist.sum]}]\n", "h.project(\"qTreco\", \"charge\", \"systAx\")" ] } diff --git a/notebooks/MiNNLOFixedOrderValidation.ipynb b/notebooks/MiNNLOFixedOrderValidation.ipynb index 8d32724ea..fc70b48aa 100644 --- a/notebooks/MiNNLOFixedOrderValidation.ipynb +++ b/notebooks/MiNNLOFixedOrderValidation.ipynb @@ -65,10 +65,21 @@ "metadata": {}, "outputs": [], "source": [ - "minloZ = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuMiNLO\", \"nominal_gen\")\n", - "nnlopsZ = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuNNLOPS\", \"nominal_gen\")\n", - "minnloZ = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuPostVFP\", \"nominal_gen_pdfNNPDF31\")[{\"pdfVar\" : \"pdfpdfNNPDF310\"}]\n", - "matrixZ = input_tools.read_matrixRadish_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Zinclusive/run_matchMiNNLOEWParams/results/yZ__NNLO_QCD.dat\", \"Y\")" + "minloZ = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuMiNLO\", \"nominal_gen\"\n", + ")\n", + "nnlopsZ = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuNNLOPS\", \"nominal_gen\"\n", + ")\n", + "minnloZ = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen_pdfNNPDF31\",\n", + ")[{\"pdfVar\": \"pdfpdfNNPDF310\"}]\n", + "matrixZ = input_tools.read_matrixRadish_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Zinclusive/run_matchMiNNLOEWParams/results/yZ__NNLO_QCD.dat\",\n", + " \"Y\",\n", + ")" ] }, { @@ -5677,7 +5688,7 @@ "metadata": {}, "outputs": [], "source": [ - "dytsf = dytrubo_z_2d_old.sum().value/dytrubo_z_2d.sum().value" + "dytsf = dytrubo_z_2d_old.sum().value / dytrubo_z_2d.sum().value" ] }, { @@ -5700,8 +5711,16 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWm = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WminusmunuPostVFP\", \"nominal_gen_pdfNNPDF31\")[{\"pdfVar\" : \"pdfpdfNNPDF310\"}]\n", - "minnloWp = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WplusmunuPostVFP\", \"nominal_gen_pdfNNPDF31\")[{\"pdfVar\" : \"pdfpdfNNPDF310\"}]" + "minnloWm = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"WminusmunuPostVFP\",\n", + " \"nominal_gen_pdfNNPDF31\",\n", + ")[{\"pdfVar\": \"pdfpdfNNPDF310\"}]\n", + "minnloWp = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_gen_pdfNNPDF31\",\n", + ")[{\"pdfVar\": \"pdfpdfNNPDF310\"}]" ] }, { @@ -5710,7 +5729,10 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_msht20_Z = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"], axes=[\"Q\", \"Y\", \"qT\"])" + "dyturbo_msht20_Z = input_tools.read_dyturbo_hist(\n", + " [\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"],\n", + " axes=[\"Q\", \"Y\", \"qT\"],\n", + ")" ] }, { @@ -5719,7 +5741,9 @@ "metadata": {}, "outputs": [], "source": [ - "minloZ,nnlopsZ,minnloZ,matrixZ,dyturbo_nnlo_Z = hh.rebinHistsToCommon([minloZ,nnlopsZ,minnloZ,matrixZ,dyturbo_nnlo_Z], (\"Y\", \"y\"))" + "minloZ, nnlopsZ, minnloZ, matrixZ, dyturbo_nnlo_Z = hh.rebinHistsToCommon(\n", + " [minloZ, nnlopsZ, minnloZ, matrixZ, dyturbo_nnlo_Z], (\"Y\", \"y\")\n", + ")" ] }, { @@ -5728,7 +5752,11 @@ "metadata": {}, "outputs": [], "source": [ - "minnloZ_msht20 = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuPostVFP\", \"nominal_gen_pdfMSHT20\")[{\"pdfVar\" : \"pdf0MSHT20\"}]" + "minnloZ_msht20 = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen_pdfMSHT20\",\n", + ")[{\"pdfVar\": \"pdf0MSHT20\"}]" ] }, { @@ -5781,7 +5809,12 @@ } ], "source": [ - "input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-1d-yw-nnlo-all-scetlibmatch-from0p0.txt\"], axes=[\"Y\"])" + "input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-1d-yw-nnlo-all-scetlibmatch-from0p0.txt\"\n", + " ],\n", + " axes=[\"Y\"],\n", + ")" ] }, { @@ -5809,18 +5842,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " matrixZ[{\"vars\" : 0}].project(\"Y\"), minnloZ.project(\"y\"), \n", - " nnlopsZ.project(\"y\"), \n", - " ],\n", - " [\"MATRIX\", \"MiNNLO\", 'NNLO$_{PS}$',], \n", - " colors=[\"green\", \"orange\", 'black',], \n", - " xlabel=\"y$^{Z}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MATRIX\",\n", - " rrange=[0.8, 1.2],\n", - " ylim=[0,380],\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " matrixZ[{\"vars\": 0}].project(\"Y\"),\n", + " minnloZ.project(\"y\"),\n", + " nnlopsZ.project(\"y\"),\n", + " ],\n", + " [\n", + " \"MATRIX\",\n", + " \"MiNNLO\",\n", + " \"NNLO$_{PS}$\",\n", + " ],\n", + " colors=[\n", + " \"green\",\n", + " \"orange\",\n", + " \"black\",\n", + " ],\n", + " xlabel=\"y$^{Z}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MATRIX\",\n", + " rrange=[0.8, 1.2],\n", + " ylim=[0, 380],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"NNPDF31\")\n", "out = os.path.join(out, \"NNPDF31\")\n", @@ -5846,17 +5891,36 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"y\") for x in \n", - " [minnloZ, minloZ, nnlopsZ, ]\n", - " ]+[matrixZ[{\"vars\" : 0}]],\n", - " [\"MiNNLO\", \"MiNLO'\", \"NNLO$_{PS}$\", \"MATRIX\", ], \n", - " colors=[\"orange\", \"lightblue\", \"black\", \"green\",], \n", - " xlabel=\"y$^{Z}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.8, 1.2],\n", - " ylim=[0,380],\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " x.project(\"y\")\n", + " for x in [\n", + " minnloZ,\n", + " minloZ,\n", + " nnlopsZ,\n", + " ]\n", + " ]\n", + " + [matrixZ[{\"vars\": 0}]],\n", + " [\n", + " \"MiNNLO\",\n", + " \"MiNLO'\",\n", + " \"NNLO$_{PS}$\",\n", + " \"MATRIX\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"lightblue\",\n", + " \"black\",\n", + " \"green\",\n", + " ],\n", + " xlabel=\"y$^{Z}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.8, 1.2],\n", + " ylim=[0, 380],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"NNPDF31\")\n", "out = os.path.join(out, \"NNPDF31\")\n", @@ -5907,9 +5971,24 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboZ_nnlo = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nnlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboZ_nlo_nnlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboZ_nlo_nlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nlo_nnpdf31nlo_yw.txt\"], axes=[\"y\"])" + "dyturboZ_nnlo = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nnlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboZ_nlo_nnlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboZ_nlo_nlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nlo_nnpdf31nlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")" ] }, { @@ -5955,9 +6034,24 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboWm_nnlo = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nnlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboWm_nlo_nnlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboWm_nlo_nlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nlo_nnpdf31nlo_yw.txt\"], axes=[\"y\"])" + "dyturboWm_nnlo = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nnlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboWm_nlo_nnlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboWm_nlo_nlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wm/nnpdf31/results_wm_nlo_nnpdf31nlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")" ] }, { @@ -6003,9 +6097,24 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboWp_nnlo = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nnlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboWp_nlo_nnlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])\n", - "dyturboWp_nlo_nlopdf = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nlo_nnpdf31nlo_yw.txt\"], axes=[\"y\"])" + "dyturboWp_nnlo = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nnlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboWp_nlo_nnlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")\n", + "dyturboWp_nlo_nlopdf = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nlo_nnpdf31nlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")" ] }, { @@ -6062,20 +6171,30 @@ } ], "source": [ - "dyturboWp_nnlo_rebin, minnloWp_rebin = hh.rebinHistsToCommon([dyturboWp_nnlo, minnloWp.project(\"y\")], 0)\n", + "dyturboWp_nnlo_rebin, minnloWp_rebin = hh.rebinHistsToCommon(\n", + " [dyturboWp_nnlo, minnloWp.project(\"y\")], 0\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [dyturboWp_nnlo_rebin, \n", - " minnloWp_rebin], \n", - " [\"DYTurbo NNLO (NNPDF3.1_nnlo)\", \"MiNNLO\",], \n", - " colors=['#66c2a5', 'orange',], \n", - " xlabel=\"y$^{W^{+}}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/NNLO\",\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", - " \n", + " [dyturboWp_nnlo_rebin, minnloWp_rebin],\n", + " [\n", + " \"DYTurbo NNLO (NNPDF3.1_nnlo)\",\n", + " \"MiNNLO\",\n", + " ],\n", + " colors=[\n", + " \"#66c2a5\",\n", + " \"orange\",\n", + " ],\n", + " xlabel=\"y$^{W^{+}}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/NNLO\",\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", + "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W\"\n", "plot_tools.make_plot_dir(out, \"NNPDF31\")\n", "out = os.path.join(out, \"NNPDF31\")\n", @@ -6089,7 +6208,12 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboWp_nnlo_msht20 = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nnlo_nnpdf31nnlo_yw.txt\"], axes=[\"y\"])" + "dyturboWp_nnlo_msht20 = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Wp/nnpdf31/results_wp_nnlo_nnpdf31nnlo_yw.txt\"\n", + " ],\n", + " axes=[\"y\"],\n", + ")" ] }, { @@ -6109,20 +6233,30 @@ } ], "source": [ - "dyturboWm_nnlo_rebin, minnloWm_rebin = hh.rebinHistsToCommon([dyturboWm_nnlo, minnloWm.project(\"y\")], 0)\n", + "dyturboWm_nnlo_rebin, minnloWm_rebin = hh.rebinHistsToCommon(\n", + " [dyturboWm_nnlo, minnloWm.project(\"y\")], 0\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [dyturboWm_nnlo_rebin, \n", - " minnloWm_rebin], \n", - " [\"DYTurbo NNLO (NNPDF3.1_nnlo)\", \"MiNNLO\",], \n", - " colors=['#66c2a5', 'orange',], \n", - " xlabel=\"y$^{W^{+}}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/NNLO\",\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", - " \n", + " [dyturboWm_nnlo_rebin, minnloWm_rebin],\n", + " [\n", + " \"DYTurbo NNLO (NNPDF3.1_nnlo)\",\n", + " \"MiNNLO\",\n", + " ],\n", + " colors=[\n", + " \"#66c2a5\",\n", + " \"orange\",\n", + " ],\n", + " xlabel=\"y$^{W^{+}}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/NNLO\",\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", + "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W\"\n", "plot_tools.make_plot_dir(out, \"NNPDF31\")\n", "out = os.path.join(out, \"NNPDF31\")\n", @@ -6136,8 +6270,15 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWm_msht20 = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WminusmunuPostVFP\", \"nominal_gen\")\n", - "dyturboWm = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-2d-nnlo-vj-scetlibmatch.txt\"], axes=(\"Y\", \"qT\"))" + "minnloWm_msht20 = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WminusmunuPostVFP\", \"nominal_gen\"\n", + ")\n", + "dyturboWm = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-2d-nnlo-vj-scetlibmatch.txt\"\n", + " ],\n", + " axes=(\"Y\", \"qT\"),\n", + ")" ] }, { @@ -6146,7 +6287,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWm_msht20_y, dyturboWm_y = hh.rebinHistsToCommon([minnloWm_msht20, dyturboWm], (\"y\", \"Y\"))" + "minnloWm_msht20_y, dyturboWm_y = hh.rebinHistsToCommon(\n", + " [minnloWm_msht20, dyturboWm], (\"y\", \"Y\")\n", + ")" ] }, { @@ -6155,8 +6298,15 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWp_msht20 = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WplusmunuPostVFP\", \"nominal_gen\")\n", - "dyturboWp = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-2d-nnlo-vj-scetlibmatch.txt\"], axes=(\"Y\", \"qT\"))" + "minnloWp_msht20 = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WplusmunuPostVFP\", \"nominal_gen\"\n", + ")\n", + "dyturboWp = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-2d-nnlo-vj-scetlibmatch.txt\"\n", + " ],\n", + " axes=(\"Y\", \"qT\"),\n", + ")" ] }, { @@ -6165,7 +6315,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWp_msht20_y, dyturboWp_y = hh.rebinHistsToCommon([minnloWp_msht20, dyturboWp], (\"y\", \"Y\"))" + "minnloWp_msht20_y, dyturboWp_y = hh.rebinHistsToCommon(\n", + " [minnloWp_msht20, dyturboWp], (\"y\", \"Y\")\n", + ")" ] }, { @@ -6174,7 +6326,15 @@ "metadata": {}, "outputs": [], "source": [ - "minnloZ_msht20_y, dyturboZ_msht20_y, minnloZ_y, dyturboZ_nnlo_y = hh.rebinHistsToCommon([minnloZ_msht20[...,:100.j].project(\"y\"), dyturbo_msht20_Z.project(\"Y\"), minnloZ[...,:100.j].project(\"y\"), dyturboZ_nnlo.project(\"y\")], 0)" + "minnloZ_msht20_y, dyturboZ_msht20_y, minnloZ_y, dyturboZ_nnlo_y = hh.rebinHistsToCommon(\n", + " [\n", + " minnloZ_msht20[..., :100.0j].project(\"y\"),\n", + " dyturbo_msht20_Z.project(\"Y\"),\n", + " minnloZ[..., :100.0j].project(\"y\"),\n", + " dyturboZ_nnlo.project(\"y\"),\n", + " ],\n", + " 0,\n", + ")" ] }, { @@ -6195,19 +6355,18 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnloZ_msht20_y, \n", - " minnloZ_y,\n", - " dyturboZ_msht20_y,\n", - " dyturboZ_nnlo_y\n", - " ], \n", - " [\"MiNNLO\", \"MiNNLO (NNPDF3.1)\", \"DYTurbo\", \"DYTurbo (NNPDF3.1)\"], \n", - " colors=['orange', \"darkred\", 'blue', 'lightblue'], \n", - " xlabel=r\"y$^{\\ell\\ell}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [minnloZ_msht20_y, minnloZ_y, dyturboZ_msht20_y, dyturboZ_nnlo_y],\n", + " [\"MiNNLO\", \"MiNNLO (NNPDF3.1)\", \"DYTurbo\", \"DYTurbo (NNPDF3.1)\"],\n", + " colors=[\"orange\", \"darkred\", \"blue\", \"lightblue\"],\n", + " xlabel=r\"y$^{\\ell\\ell}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -6228,16 +6387,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnloWp_msht20_y[...,:100.j,].project(\"y\"), \n", - " dyturboWp_y.project(\"Y\")*dytsfZ], \n", - " [\"MiNNLO\", \"DYTurbo\",], \n", - " colors=['orange', 'blue',], \n", - " xlabel=r\"y$^{\\ell\\ell}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " minnloWp_msht20_y[\n", + " ...,\n", + " :100.0j,\n", + " ].project(\"y\"),\n", + " dyturboWp_y.project(\"Y\") * dytsfZ,\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"DYTurbo\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"y$^{\\ell\\ell}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -6258,16 +6431,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnloWm_msht20_y[...,:100.j,].project(\"y\"), \n", - " dyturboWm_y.project(\"Y\")*dytsfZ], \n", - " [\"MiNNLO\", \"DYTurbo\",], \n", - " colors=['orange', 'blue',], \n", - " xlabel=r\"y$^{\\ell\\ell}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " minnloWm_msht20_y[\n", + " ...,\n", + " :100.0j,\n", + " ].project(\"y\"),\n", + " dyturboWm_y.project(\"Y\") * dytsfZ,\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"DYTurbo\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"y$^{\\ell\\ell}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] } ], diff --git a/notebooks/PlotScratch.ipynb b/notebooks/PlotScratch.ipynb index 009a82652..f904069ca 100644 --- a/notebooks/PlotScratch.ipynb +++ b/notebooks/PlotScratch.ipynb @@ -111,7 +111,9 @@ "metadata": {}, "outputs": [], "source": [ - "histInfo = groups.datagroupsForHist(\"nominal\", syst=\"\", selectSignal=True, label=\"nominal\")\n", + "histInfo = groups.datagroupsForHist(\n", + " \"nominal\", syst=\"\", selectSignal=True, label=\"nominal\"\n", + ")\n", "histInfo = groups.datagroupsForHist(\"nominal\", syst=\"uncorr\", selectSignal=True)\n", "prednames = [x for x in histInfo.keys() if x not in [\"Data\", \"Wmunu_uncorr\"]]" ] @@ -150,7 +152,9 @@ "histInfo[\"Wmunu_uncorr\"][\"label\"] = r\"W$^{\\pm}\\to\\mu\\nu$ (no corr.)\"\n", "histInfo[\"Wmunu_uncorr\"][\"color\"] = \"red\"\n", "prednames_corr = [x for x in histInfo.keys() if x not in [\"Data\", \"Wmunu\"]]\n", - "histInfo[\"Wmunu_uncorr\"][\"nominal\"] = sum([histInfo[x][\"uncorr\"] for x in prednames_corr])" + "histInfo[\"Wmunu_uncorr\"][\"nominal\"] = sum(\n", + " [histInfo[x][\"uncorr\"] for x in prednames_corr]\n", + ")" ] }, { @@ -211,7 +215,16 @@ } ], "source": [ - "fig = plot_tools.makeStackPlotWithRatio(histInfo, prednames, action=lambda x: x.project(\"eta\"), label=\"nominal\", unstacked=[\"uncorr\", \"Data\"], xlabel=r\"p$_{T}$ (GeV)\", scale=1e7, rrange=[0.8, 1.1])" + "fig = plot_tools.makeStackPlotWithRatio(\n", + " histInfo,\n", + " prednames,\n", + " action=lambda x: x.project(\"eta\"),\n", + " label=\"nominal\",\n", + " unstacked=[\"uncorr\", \"Data\"],\n", + " xlabel=r\"p$_{T}$ (GeV)\",\n", + " scale=1e7,\n", + " rrange=[0.8, 1.1],\n", + ")" ] }, { @@ -234,7 +247,17 @@ } ], "source": [ - "ptfig = plot_tools.makeStackPlotWithRatio(histInfo, prednames, label=\"nominal\", scale=1e7, action=lambda x: x.project(\"pt\"), unstacked=[\"Wmunu_uncorr\", \"Data\"], xlabel=\"\", ylabel=\"Events/bin\", rrange=[0.9, 1.1])" + "ptfig = plot_tools.makeStackPlotWithRatio(\n", + " histInfo,\n", + " prednames,\n", + " label=\"nominal\",\n", + " scale=1e7,\n", + " action=lambda x: x.project(\"pt\"),\n", + " unstacked=[\"Wmunu_uncorr\", \"Data\"],\n", + " xlabel=\"\",\n", + " ylabel=\"Events/bin\",\n", + " rrange=[0.9, 1.1],\n", + ")" ] }, { @@ -294,9 +317,20 @@ "metadata": {}, "outputs": [], "source": [ - "histInfoWlike = groupsWlike.datagroupsForHist(\"nominal\", syst=\"\", selectSignal=True, label=\"nominal\")\n", - "histInfoWlike = groupsWlike.datagroupsForHist(\"nominal\", syst=\"uncorr\", selectSignal=True)\n", - "prednamesWlike = [x for x in histInfoWlike.keys() if x not in [\"Data\",]]" + "histInfoWlike = groupsWlike.datagroupsForHist(\n", + " \"nominal\", syst=\"\", selectSignal=True, label=\"nominal\"\n", + ")\n", + "histInfoWlike = groupsWlike.datagroupsForHist(\n", + " \"nominal\", syst=\"uncorr\", selectSignal=True\n", + ")\n", + "prednamesWlike = [\n", + " x\n", + " for x in histInfoWlike.keys()\n", + " if x\n", + " not in [\n", + " \"Data\",\n", + " ]\n", + "]" ] }, { @@ -306,7 +340,9 @@ "metadata": {}, "outputs": [], "source": [ - "histInfoWlike = groupsWlike.addUncorrectedProc(\"nominal\", \"uncorr\", label=\"No N$^{3}$LL Corr.\")" + "histInfoWlike = groupsWlike.addUncorrectedProc(\n", + " \"nominal\", \"uncorr\", label=\"No N$^{3}$LL Corr.\"\n", + ")" ] }, { @@ -329,7 +365,17 @@ } ], "source": [ - "ptfig = plot_tools.makeStackPlotWithRatio(histInfoWlike, prednamesWlike, label=\"nominal\", scale=6e5, action=lambda x: x.project(\"pt\"), unstacked=[\"uncorr\", \"Data\"], xlabel=\"\", ylabel=\"Events/bin\", rrange=[0.9, 1.1])\n" + "ptfig = plot_tools.makeStackPlotWithRatio(\n", + " histInfoWlike,\n", + " prednamesWlike,\n", + " label=\"nominal\",\n", + " scale=6e5,\n", + " action=lambda x: x.project(\"pt\"),\n", + " unstacked=[\"uncorr\", \"Data\"],\n", + " xlabel=\"\",\n", + " ylabel=\"Events/bin\",\n", + " rrange=[0.9, 1.1],\n", + ")" ] }, { @@ -352,7 +398,17 @@ } ], "source": [ - "ptfig = plot_tools.makeStackPlotWithRatio(histInfoWlike, prednamesWlike, label=\"nominal\", scale=1.6e4, action=sel.unrolledHist, unstacked=[\"uncorr\", \"Data\"], xlabel=\"\", ylabel=\"Events/bin\", rrange=[0.9, 1.1])" + "ptfig = plot_tools.makeStackPlotWithRatio(\n", + " histInfoWlike,\n", + " prednamesWlike,\n", + " label=\"nominal\",\n", + " scale=1.6e4,\n", + " action=sel.unrolledHist,\n", + " unstacked=[\"uncorr\", \"Data\"],\n", + " xlabel=\"\",\n", + " ylabel=\"Events/bin\",\n", + " rrange=[0.9, 1.1],\n", + ")" ] }, { @@ -363,7 +419,9 @@ "outputs": [], "source": [ "histInfoWlike = groupsWlike.datagroupsForHist(\"dilepton\", syst=\"\", selectSignal=True)\n", - "histInfoWlike = groupsWlike.datagroupsForHist(\"dilepton\", syst=\"uncorr\", selectSignal=True)" + "histInfoWlike = groupsWlike.datagroupsForHist(\n", + " \"dilepton\", syst=\"uncorr\", selectSignal=True\n", + ")" ] }, { @@ -373,7 +431,9 @@ "metadata": {}, "outputs": [], "source": [ - "histInfoWlike = groupsWlike.addUncorrectedProc(\"dilepton\", \"uncorr\", label=\"No N$^{3}$LL Corr.\")" + "histInfoWlike = groupsWlike.addUncorrectedProc(\n", + " \"dilepton\", \"uncorr\", label=\"No N$^{3}$LL Corr.\"\n", + ")" ] }, { @@ -412,8 +472,18 @@ } ], "source": [ - "yfig = plot_tools.makeStackPlotWithRatio(histInfoWlike, prednamesWlike, label=\"dilepton\", scale=6e5, action=lambda x: x.project(\"yll\"), unstacked=[\"uncorr\",\"Data\"], xlabel=\"\", ylabel=\"Events/bin\", rrange=[0.95, 1.05], xlim=[-2.4,2.4])\n", - "\n" + "yfig = plot_tools.makeStackPlotWithRatio(\n", + " histInfoWlike,\n", + " prednamesWlike,\n", + " label=\"dilepton\",\n", + " scale=6e5,\n", + " action=lambda x: x.project(\"yll\"),\n", + " unstacked=[\"uncorr\", \"Data\"],\n", + " xlabel=\"\",\n", + " ylabel=\"Events/bin\",\n", + " rrange=[0.95, 1.05],\n", + " xlim=[-2.4, 2.4],\n", + ")" ] } ], diff --git a/notebooks/PostfitGen.ipynb b/notebooks/PostfitGen.ipynb index a762198fd..19e2d34d4 100644 --- a/notebooks/PostfitGen.ipynb +++ b/notebooks/PostfitGen.ipynb @@ -24,7 +24,7 @@ "outputs": [], "source": [ "import uproot\n", - "from utilities.io_tools import input_tools,combinetf2_input,combinetf_input\n", + "from utilities.io_tools import input_tools, combinetf2_input, combinetf_input\n", "from wums import boostHistHelpers as hh\n", "from wremnants import histselections as sel\n", "from wremnants import plot_tools\n", @@ -67,7 +67,9 @@ "metadata": {}, "outputs": [], "source": [ - "res_n3ll_data = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N3LL_results.hdf5\")" + "res_n3ll_data = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N3LL_results.hdf5\"\n", + ")" ] }, { @@ -77,7 +79,9 @@ "metadata": {}, "outputs": [], "source": [ - "res_n2p1ll_data = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N2p1LL_results.hdf5\")" + "res_n2p1ll_data = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N2p1LL_results.hdf5\"\n", + ")" ] }, { @@ -87,7 +91,9 @@ "metadata": {}, "outputs": [], "source": [ - "res_n3p0ll_data = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N3p0LL_results.hdf5\")\n" + "res_n3p0ll_data = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/dataFit_N3p0LL_results.hdf5\"\n", + ")" ] }, { @@ -141,7 +147,7 @@ } ], "source": [ - "res_n3ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"]" + "res_n3ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"]" ] }, { @@ -179,26 +185,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " res_n3ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"],\n", - " res_n2p1ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"],\n", - " res_n3p0ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"],\n", - " ],\n", - " labels=[\"N3LL (old TNP)\",\n", - " \"N2+1LL\",\n", - " \"N3+0LL\",\n", - " ],\n", - " colors=[\"purple\",\n", - " \"blue\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.95, 1.05],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " res_n3ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"],\n", + " res_n2p1ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"],\n", + " res_n3p0ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"],\n", + " ],\n", + " labels=[\n", + " \"N3LL (old TNP)\",\n", + " \"N2+1LL\",\n", + " \"N3+0LL\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.95, 1.05],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -236,23 +246,27 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " res_n2p1ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"],\n", - " res_n3p0ll_data[\"hist_postfit\"][\"ch0\"].get()[...,\"Zmumu\"],\n", - " ],\n", - " labels=[\"N$^{2+1}$LL\",\n", - " \"N$^{3+0}$LL\",\n", - " ],\n", - " colors=[\"purple\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/N$^{2+1}$LL\",\n", - " rrange=[0.95, 1.05],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " res_n2p1ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"],\n", + " res_n3p0ll_data[\"hist_postfit\"][\"ch0\"].get()[..., \"Zmumu\"],\n", + " ],\n", + " labels=[\n", + " \"N$^{2+1}$LL\",\n", + " \"N$^{3+0}$LL\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/N$^{2+1}$LL\",\n", + " rrange=[0.95, 1.05],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -272,7 +286,12 @@ "metadata": {}, "outputs": [], "source": [ - "unfolded_data = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_Data/results_unfolded.pkl\", \"rb\"))" + "unfolded_data = pickle.load(\n", + " open(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_Data/results_unfolded.pkl\",\n", + " \"rb\",\n", + " )\n", + ")" ] }, { @@ -282,7 +301,12 @@ "metadata": {}, "outputs": [], "source": [ - "unfolded_exp = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll/results_unfolded_expected.pkl\", \"rb\"))" + "unfolded_exp = pickle.load(\n", + " open(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll/results_unfolded_expected.pkl\",\n", + " \"rb\",\n", + " )\n", + ")" ] }, { @@ -302,7 +326,9 @@ "metadata": {}, "outputs": [], "source": [ - "unfolded_datah = unfolded_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]" + "unfolded_datah = unfolded_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\n", + " \"hist_ptVGen\"\n", + "]" ] }, { @@ -341,7 +367,11 @@ "metadata": {}, "outputs": [], "source": [ - "hfid = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_fiducial.hdf5\", \"ZmumuPostVFP\", \"nominal_gen\")" + "hfid = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_fiducial.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen\",\n", + ")" ] }, { @@ -431,7 +461,9 @@ "metadata": {}, "outputs": [], "source": [ - "postfit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen_fiducial/ZGen_postfit_recoFitToData.hdf5\")" + "postfit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen_fiducial/ZGen_postfit_recoFitToData.hdf5\"\n", + ")" ] }, { @@ -441,7 +473,7 @@ "metadata": {}, "outputs": [], "source": [ - "#postfit_combine = combinetf_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen_fiducial/fitresults_123456791.hdf5\")" + "# postfit_combine = combinetf_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen_fiducial/fitresults_123456791.hdf5\")" ] }, { @@ -451,7 +483,13 @@ "metadata": {}, "outputs": [], "source": [ - "postfit_pt = hh.rebinHist(postfit[\"hist_postfit\"][\"ch0\"].get(), \"ptVgen\", hdata.axes[0].edges[:-2])*0.001/16.8" + "postfit_pt = (\n", + " hh.rebinHist(\n", + " postfit[\"hist_postfit\"][\"ch0\"].get(), \"ptVgen\", hdata.axes[0].edges[:-2]\n", + " )\n", + " * 0.001\n", + " / 16.8\n", + ")" ] }, { @@ -461,7 +499,11 @@ "metadata": {}, "outputs": [], "source": [ - "pt_gen_unfolding = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mz_dilepton_scetlib_dyturboN3p0LLCorr_unfolding.hdf5\", \"ZmumuPostVFP\", \"xnorm\")" + "pt_gen_unfolding = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mz_dilepton_scetlib_dyturboN3p0LLCorr_unfolding.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"xnorm\",\n", + ")" ] }, { @@ -525,33 +567,37 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " unfolded_datah[:40j],\n", - " hfid_pt[:40j],\n", - " postfit_pt[...,\"Zmumu\"],\n", - " unfolded_exph[:40j],\n", - " unfolded_datah[:40j],\n", - " ],\n", - " labels=[\"\",\n", - " \"SCETlib+DYturbo N$^{3}$LL+NNLO\",\n", - " r\"postfit RECO $p_{T}^{\\ell\\ell}$ fit\",\n", - " \"Expected unfolding\",\n", - " \"Unfolded data\",\n", - " ],\n", - " data=True,\n", - " colors=[\"black\",\n", - " \"red\",\n", - " \"blue\",\n", - " \"green\",\n", - " \"black\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/Data\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " unfolded_datah[:40j],\n", + " hfid_pt[:40j],\n", + " postfit_pt[..., \"Zmumu\"],\n", + " unfolded_exph[:40j],\n", + " unfolded_datah[:40j],\n", + " ],\n", + " labels=[\n", + " \"\",\n", + " \"SCETlib+DYturbo N$^{3}$LL+NNLO\",\n", + " r\"postfit RECO $p_{T}^{\\ell\\ell}$ fit\",\n", + " \"Expected unfolding\",\n", + " \"Unfolded data\",\n", + " ],\n", + " data=True,\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"blue\",\n", + " \"green\",\n", + " \"black\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/Data\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -573,28 +619,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hfid_pt[:40j],\n", - " #unfolded_exph[:40j],\n", - " pt_gen_unfolding.project(\"ptVGen\")[:40j],\n", - " ],\n", - " labels=[\n", - " \"gen fiducial\",\n", - " #\"Expected unfolding\",\n", - " \"gen unfolding\",\n", - " ],\n", - " colors=[\n", - " \"green\",\n", - " #\"blue\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/gen\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " hfid_pt[:40j],\n", + " # unfolded_exph[:40j],\n", + " pt_gen_unfolding.project(\"ptVGen\")[:40j],\n", + " ],\n", + " labels=[\n", + " \"gen fiducial\",\n", + " # \"Expected unfolding\",\n", + " \"gen unfolding\",\n", + " ],\n", + " colors=[\n", + " \"green\",\n", + " # \"blue\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/gen\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -606,7 +654,7 @@ "source": [ "filename = \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen_fiducial//ZGen.hdf5\"\n", "indata = narf.combineutils.FitInputData(filename)\n", - "debug = narf.combineutils.FitDebugData(indata)\n" + "debug = narf.combineutils.FitDebugData(indata)" ] }, { @@ -616,7 +664,13 @@ "metadata": {}, "outputs": [], "source": [ - "yields = [-abs(debug.syst_hists[\"ch0\"][{\"systs\" : s, \"DownUp\" : \"Up\"}].sum()-debug.nominal_hists[\"ch0\"].sum()) for s in debug.syst_hists[\"ch0\"].axes[\"systs\"]]\n" + "yields = [\n", + " -abs(\n", + " debug.syst_hists[\"ch0\"][{\"systs\": s, \"DownUp\": \"Up\"}].sum()\n", + " - debug.nominal_hists[\"ch0\"].sum()\n", + " )\n", + " for s in debug.syst_hists[\"ch0\"].axes[\"systs\"]\n", + "]" ] }, { @@ -1148,27 +1202,33 @@ "proc = \"Zmumu\"\n", "for syst in ordered_systs[:50]:\n", " plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " debug.nominal_hists[\"ch0\"][{\"processes\" : proc}],\n", - " debug.syst_hists[\"ch0\"][{\"processes\" : proc, \"systs\" : syst, \"DownUp\" : \"Down\"}],\n", - " debug.syst_hists[\"ch0\"][{\"processes\" : proc, \"systs\" : syst, \"DownUp\" : \"Up\"}]\n", - " ],\n", - " labels=[\"Nominal\",\n", - " f\"{syst} Up\",\n", - " f\"{syst} Down\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"red\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )\n", - " #fig.close()" + " hists=[\n", + " debug.nominal_hists[\"ch0\"][{\"processes\": proc}],\n", + " debug.syst_hists[\"ch0\"][\n", + " {\"processes\": proc, \"systs\": syst, \"DownUp\": \"Down\"}\n", + " ],\n", + " debug.syst_hists[\"ch0\"][{\"processes\": proc, \"systs\": syst, \"DownUp\": \"Up\"}],\n", + " ],\n", + " labels=[\n", + " \"Nominal\",\n", + " f\"{syst} Up\",\n", + " f\"{syst} Down\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " )\n", + " # fig.close()" ] }, { @@ -2790,27 +2850,33 @@ "proc = \"Zmumu\"\n", "for syst in [x for x in ordered_systs if \"QCD\" in x]:\n", " plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " debug.nominal_hists[\"ch0\"][{\"processes\" : proc}],\n", - " debug.syst_hists[\"ch0\"][{\"processes\" : proc, \"systs\" : syst, \"DownUp\" : \"Down\"}],\n", - " debug.syst_hists[\"ch0\"][{\"processes\" : proc, \"systs\" : syst, \"DownUp\" : \"Up\"}]\n", - " ],\n", - " labels=[\"Nominal\",\n", - " f\"{syst} Up\",\n", - " f\"{syst} Down\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"red\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )\n", - " #fig.close()" + " hists=[\n", + " debug.nominal_hists[\"ch0\"][{\"processes\": proc}],\n", + " debug.syst_hists[\"ch0\"][\n", + " {\"processes\": proc, \"systs\": syst, \"DownUp\": \"Down\"}\n", + " ],\n", + " debug.syst_hists[\"ch0\"][{\"processes\": proc, \"systs\": syst, \"DownUp\": \"Up\"}],\n", + " ],\n", + " labels=[\n", + " \"Nominal\",\n", + " f\"{syst} Up\",\n", + " f\"{syst} Down\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " )\n", + " # fig.close()" ] }, { @@ -2820,7 +2886,11 @@ "metadata": {}, "outputs": [], "source": [ - "pt_gen = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_fiducial_wlike.hdf5\", \"ZmumuPostVFP\", \"nominal_genlep\")" + "pt_gen = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_fiducial_wlike.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_genlep\",\n", + ")" ] }, { @@ -2830,7 +2900,12 @@ "metadata": {}, "outputs": [], "source": [ - "pt_unfolded = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassWLike_eta_pt_charge/results_unfolded.pkl\", \"rb\"))" + "pt_unfolded = pickle.load(\n", + " open(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassWLike_eta_pt_charge/results_unfolded.pkl\",\n", + " \"rb\",\n", + " )\n", + ")" ] }, { @@ -2861,8 +2936,10 @@ } ], "source": [ - "pt_unfolded[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptGen_absEtaGen\"].project(\"ptGen\").plot(binwnorm=1., label=\"unfold\")\n", - "pt_gen.project(\"pt\")[28j::hist.rebin(2)].plot(label=\"gen\", binwnorm=1.)\n", + "pt_unfolded[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptGen_absEtaGen\"].project(\n", + " \"ptGen\"\n", + ").plot(binwnorm=1.0, label=\"unfold\")\n", + "pt_gen.project(\"pt\")[28j :: hist.rebin(2)].plot(label=\"gen\", binwnorm=1.0)\n", "plt.legend()" ] }, @@ -2885,22 +2962,28 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " pt_unfolded[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptGen_absEtaGen\"].project(\"ptGen\"),\n", - " pt_gen.project(\"pt\")[28j::hist.rebin(2)]\n", - " ],\n", - " labels=[\"unfolded expected\",\n", - " \"gen\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", + " hists=[\n", + " pt_unfolded[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\n", + " \"hist_ptGen_absEtaGen\"\n", + " ].project(\"ptGen\"),\n", + " pt_gen.project(\"pt\")[28j :: hist.rebin(2)],\n", + " ],\n", + " labels=[\n", + " \"unfolded expected\",\n", + " \"gen\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", ")" ] }, @@ -2911,7 +2994,11 @@ "metadata": {}, "outputs": [], "source": [ - "gen_inc = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_maxFiles_m1_masswindow_ptVbins.hdf5\", \"ZmumuPostVFP\", \"nominal_gen\")\n" + "gen_inc = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_maxFiles_m1_masswindow_ptVbins.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen\",\n", + ")" ] }, { @@ -2937,7 +3024,11 @@ } ], "source": [ - "gen_unfolding_inc = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mz_dilepton_scetlib_dyturboN3p0LLCorr_unfolding.hdf5\", \"ZmumuPostVFP\", \"xnorm\")\n", + "gen_unfolding_inc = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mz_dilepton_scetlib_dyturboN3p0LLCorr_unfolding.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"xnorm\",\n", + ")\n", "gen_unfolding_inc" ] }, @@ -2948,10 +3039,17 @@ "metadata": {}, "outputs": [], "source": [ - "unfolding_inc_data = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_inclusive_ptV1GeV/results_unfolded.pkl\", \"rb\"))\n", - "#unfolding_inch = unfolding_inc[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", - "#unfolding_inc_datah = unfolding_inc_data[\"results\"][\"sumpois\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", - "unfolding_inc_datah = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]" + "unfolding_inc_data = pickle.load(\n", + " open(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_inclusive_ptV1GeV/results_unfolded.pkl\",\n", + " \"rb\",\n", + " )\n", + ")\n", + "# unfolding_inch = unfolding_inc[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", + "# unfolding_inc_datah = unfolding_inc_data[\"results\"][\"sumpois\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", + "unfolding_inc_datah = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\n", + " \"hist_ptVGen\"\n", + "]" ] }, { @@ -3001,7 +3099,9 @@ "metadata": {}, "outputs": [], "source": [ - "res_n3p0ll_data = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/ZGen_postfit_recoFitToData.hdf5\")" + "res_n3p0ll_data = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies//ZGen_ptVgen/ZGen_postfit_recoFitToData.hdf5\"\n", + ")" ] }, { @@ -3033,8 +3133,12 @@ "metadata": {}, "outputs": [], "source": [ - "res_n3p0ll_wlikefit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow_ptbin/wlikePtllCorrPDFit_N3p0LL.hdf5\")\n", - "res_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow_ptbin/ptllDataFit_N3p0LL.hdf5\")\n" + "res_n3p0ll_wlikefit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow_ptbin/wlikePtllCorrPDFit_N3p0LL.hdf5\"\n", + ")\n", + "res_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow_ptbin/ptllDataFit_N3p0LL.hdf5\"\n", + ")" ] }, { @@ -3044,8 +3148,22 @@ "metadata": {}, "outputs": [], "source": [ - "n3p0ll_wlikefith = hh.rebinHist(res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000.\n", - "n3p0ll_ptlldatafith = hh.rebinHist(res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000.\n" + "n3p0ll_wlikefith = (\n", + " hh.rebinHist(\n", + " res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get(),\n", + " \"ptVgen\",\n", + " unfolding_inc_datah.axes[\"ptVGen\"].edges,\n", + " )\n", + " / 1000.0\n", + ")\n", + "n3p0ll_ptlldatafith = (\n", + " hh.rebinHist(\n", + " res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get(),\n", + " \"ptVgen\",\n", + " unfolding_inc_datah.axes[\"ptVGen\"].edges,\n", + " )\n", + " / 1000.0\n", + ")" ] }, { @@ -3055,8 +3173,22 @@ "metadata": {}, "outputs": [], "source": [ - "prefit_datah = hh.rebinHist(res_n3p0ll_data[\"hist_prefit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000.\n", - "postfit_datah = hh.rebinHist(res_n3p0ll_data[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000." + "prefit_datah = (\n", + " hh.rebinHist(\n", + " res_n3p0ll_data[\"hist_prefit_inclusive\"][\"ch0\"].get(),\n", + " \"ptVgen\",\n", + " unfolding_inc_datah.axes[\"ptVGen\"].edges,\n", + " )\n", + " / 1000.0\n", + ")\n", + "postfit_datah = (\n", + " hh.rebinHist(\n", + " res_n3p0ll_data[\"hist_postfit_inclusive\"][\"ch0\"].get(),\n", + " \"ptVgen\",\n", + " unfolding_inc_datah.axes[\"ptVGen\"].edges,\n", + " )\n", + " / 1000.0\n", + ")" ] }, { @@ -3113,43 +3245,48 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " unfolding_inc_datah,\n", - " n3p0ll_ptlldatafith,\n", - " n3p0ll_wlikefith,\n", - " gen_inc.project(\"ptVgen\"),\n", - " wlikeup,\n", - " wlikedown,\n", - " ptllup,\n", - " ptlldown,\n", - " ],\n", - " labels=[\n", - " \"Unfolded data\",\n", - " r\"Postfit $p_{T}^{\\ell\\ell}$ data, N$^{3+0}LL+NNLO$\",\n", - " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt. W-like, N$^{3+0}LL+NNLO$\",\n", - " r\"Prefit N$^{3}LL+NNLO$\",\n", - " \"\", \"\", \"\", \"\",\n", - " ],\n", - " dataIdx=0,\n", - " colors=[\n", - " \"black\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkred\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*3+[\"dashed\"]+[\"solid\"]*2,\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"x/Data\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " unfolding_inc_datah,\n", + " n3p0ll_ptlldatafith,\n", + " n3p0ll_wlikefith,\n", + " gen_inc.project(\"ptVgen\"),\n", + " wlikeup,\n", + " wlikedown,\n", + " ptllup,\n", + " ptlldown,\n", + " ],\n", + " labels=[\n", + " \"Unfolded data\",\n", + " r\"Postfit $p_{T}^{\\ell\\ell}$ data, N$^{3+0}LL+NNLO$\",\n", + " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt. W-like, N$^{3+0}LL+NNLO$\",\n", + " r\"Prefit N$^{3}LL+NNLO$\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " dataIdx=0,\n", + " colors=[\n", + " \"black\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkred\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 3 + [\"dashed\"] + [\"solid\"] * 2,\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"x/Data\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", ")" ] }, @@ -3172,28 +3309,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " unfolding_inc_datah,\n", - " #postfit_datah,\n", - " gen_inc.project(\"ptVgen\"),\n", - " ],\n", - " labels=[\"Unfolded data\",\n", - " #\"SCETlib+DYTurbo N$^{3+0}$LL postfit\",\n", - " \"SCETlib+DYTurbo N$^{3}$LL\",\n", - " ],\n", - " dataIdx=0,\n", - " colors=[\n", - " \"black\",\n", - " #\"mediumpurple\",\n", - " \"purple\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/data\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", + " hists=[\n", + " unfolding_inc_datah,\n", + " # postfit_datah,\n", + " gen_inc.project(\"ptVgen\"),\n", + " ],\n", + " labels=[\n", + " \"Unfolded data\",\n", + " # \"SCETlib+DYTurbo N$^{3+0}$LL postfit\",\n", + " \"SCETlib+DYTurbo N$^{3}$LL\",\n", + " ],\n", + " dataIdx=0,\n", + " colors=[\n", + " \"black\",\n", + " # \"mediumpurple\",\n", + " \"purple\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/data\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", ")" ] }, @@ -3215,37 +3355,38 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " postfit_datah,\n", - " hup,\n", - " hdown,\n", - " gen_inc,\n", - " unfolding_inc_datah,\n", - " ],\n", - " labels=[\n", - " \"SCETlib+DYTurbo N$^{3+0}$LL postfit\",\n", - " \"\",\n", - " \"\",\n", - " \"SCETlib+DYTurbo N$^{3}$LL\",\n", - " \"unfolded data\",\n", - "\n", - " ],\n", - " data=True,\n", - " colors=[\n", - " \"mediumpurple\",\n", - " \"mediumpurple\",\n", - " \"mediumpurple\",\n", - " \"purple\",\n", - " \"black\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=2,\n", + " hists=[\n", + " postfit_datah,\n", + " hup,\n", + " hdown,\n", + " gen_inc,\n", + " unfolding_inc_datah,\n", + " ],\n", + " labels=[\n", + " \"SCETlib+DYTurbo N$^{3+0}$LL postfit\",\n", + " \"\",\n", + " \"\",\n", + " \"SCETlib+DYTurbo N$^{3}$LL\",\n", + " \"unfolded data\",\n", + " ],\n", + " data=True,\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"mediumpurple\",\n", + " \"mediumpurple\",\n", + " \"purple\",\n", + " \"black\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=2,\n", ")" ] }, @@ -3276,34 +3417,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " prefit_datah,\n", - " unfolding_inc_datah,\n", - " preup,\n", - " predown,\n", - " ],\n", - " labels=[\n", - " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", - " \"unfolded data\",\n", - " \"\",\n", - " \"\",\n", - "\n", - " ],\n", - " dataIdx=1,\n", - " colors=[\n", - " \"purple\",\n", - " \"black\",\n", - " \"purple\",\n", - " \"purple\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=2,\n", + " hists=[\n", + " prefit_datah,\n", + " unfolding_inc_datah,\n", + " preup,\n", + " predown,\n", + " ],\n", + " labels=[\n", + " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", + " \"unfolded data\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " dataIdx=1,\n", + " colors=[\n", + " \"purple\",\n", + " \"black\",\n", + " \"purple\",\n", + " \"purple\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=2,\n", ")" ] }, @@ -3314,7 +3456,7 @@ "metadata": {}, "outputs": [], "source": [ - "import lz4.frame,pickle" + "import lz4.frame, pickle" ] }, { @@ -3324,7 +3466,11 @@ "metadata": {}, "outputs": [], "source": [ - "resz = pickle.load(lz4.frame.open(\"/home/submit/kdlong/work/WRemnants/wremnants-data/data/TheoryCorrections/dataPtllCorrZ.pkl.lz4\"))" + "resz = pickle.load(\n", + " lz4.frame.open(\n", + " \"/home/submit/kdlong/work/WRemnants/wremnants-data/data/TheoryCorrections/dataPtllCorrZ.pkl.lz4\"\n", + " )\n", + ")" ] }, { @@ -3334,10 +3480,18 @@ "metadata": {}, "outputs": [], "source": [ - "ptllfit_gen_expected = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/ptllDataFit_N3p0LL_expected.hdf5\")\n", - "ptllfit_gen_expectedh = ptllfit_gen_expected[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]\n", - "ptllfit_gen_expectedh_up,ptllfit_gen_expectedh_down = hist_to_up_down_unc(ptllfit_gen_expectedh)\n", - "gen_prefit_up,gen_prefit_down = hist_to_up_down_unc(ptllfit_gen_expected[\"hist_prefit_inclusive\"][\"ch0\"].get()[:100j])" + "ptllfit_gen_expected = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/ptllDataFit_N3p0LL_expected.hdf5\"\n", + ")\n", + "ptllfit_gen_expectedh = ptllfit_gen_expected[\"hist_postfit_inclusive\"][\"ch0\"].get()[\n", + " :100j\n", + "]\n", + "ptllfit_gen_expectedh_up, ptllfit_gen_expectedh_down = hist_to_up_down_unc(\n", + " ptllfit_gen_expectedh\n", + ")\n", + "gen_prefit_up, gen_prefit_down = hist_to_up_down_unc(\n", + " ptllfit_gen_expected[\"hist_prefit_inclusive\"][\"ch0\"].get()[:100j]\n", + ")" ] }, { @@ -3347,9 +3501,15 @@ "metadata": {}, "outputs": [], "source": [ - "wlikefit_gen_expected = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/wlikePtllCorrPDFit_N3p0LL_expected.hdf5\")\n", - "wlikefit_gen_expectedh = wlikefit_gen_expected[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]\n", - "wlikefit_gen_expectedh_up,wlikefit_gen_expectedh_down = hist_to_up_down_unc(wlikefit_gen_expectedh)\n" + "wlikefit_gen_expected = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/wlikePtllCorrPDFit_N3p0LL_expected.hdf5\"\n", + ")\n", + "wlikefit_gen_expectedh = wlikefit_gen_expected[\"hist_postfit_inclusive\"][\"ch0\"].get()[\n", + " :100j\n", + "]\n", + "wlikefit_gen_expectedh_up, wlikefit_gen_expectedh_down = hist_to_up_down_unc(\n", + " wlikefit_gen_expectedh\n", + ")" ] }, { @@ -3371,41 +3531,43 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " ptllfit_gen_expectedh,\n", - " gen_prefit_up,\n", - " gen_prefit_down,\n", - " ptllfit_gen_expectedh_up,\n", - " ptllfit_gen_expectedh_down,\n", - " wlikefit_gen_expectedh_up,\n", - " wlikefit_gen_expectedh_down,\n", - " ],\n", - " labels=[\n", - " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", - " \"\",\n", - " \"\",\n", - " \"postfit unc. ptll fit\",\n", - " \"\",\n", - " \"postfit unc. w-like\",\n", - " \"\",\n", - " ],\n", - " colors=[\n", - " \"purple\",\n", - " \"purple\",\n", - " \"purple\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=False,\n", - " yerr=False,\n", - " fill_between=6,\n", + " hists=[\n", + " ptllfit_gen_expectedh,\n", + " gen_prefit_up,\n", + " gen_prefit_down,\n", + " ptllfit_gen_expectedh_up,\n", + " ptllfit_gen_expectedh_down,\n", + " wlikefit_gen_expectedh_up,\n", + " wlikefit_gen_expectedh_down,\n", + " ],\n", + " labels=[\n", + " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", + " \"\",\n", + " \"\",\n", + " \"postfit unc. ptll fit\",\n", + " \"\",\n", + " \"postfit unc. w-like\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"purple\",\n", + " \"purple\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=False,\n", + " yerr=False,\n", + " fill_between=6,\n", ")" ] }, @@ -3416,9 +3578,11 @@ "metadata": {}, "outputs": [], "source": [ - "ptllfit_gen = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/ptllDataFit_N3p0LL.hdf5\")\n", + "ptllfit_gen = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/ptllDataFit_N3p0LL.hdf5\"\n", + ")\n", "ptllfit_genh = ptllfit_gen[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]\n", - "ptllfit_genh_up,ptllfit_genh_down = hist_to_up_down_unc(ptllfit_genh)\n" + "ptllfit_genh_up, ptllfit_genh_down = hist_to_up_down_unc(ptllfit_genh)" ] }, { @@ -3428,9 +3592,11 @@ "metadata": {}, "outputs": [], "source": [ - "wlikefit_gen = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/wlikePtllCorrPDFit_N3p0LL.hdf5\")\n", + "wlikefit_gen = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/ZGen_ptVgen_N3p0LL_masswindow/wlikePtllCorrPDFit_N3p0LL.hdf5\"\n", + ")\n", "wlikefit_genh = wlikefit_gen[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]\n", - "wlikefit_genh_up,wlikefit_genh_down = hist_to_up_down_unc(wlikefit_genh)" + "wlikefit_genh_up, wlikefit_genh_down = hist_to_up_down_unc(wlikefit_genh)" ] }, { @@ -3452,35 +3618,37 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " ptllfit_gen_expectedh,\n", - " ptllfit_genh_up,\n", - " ptllfit_genh_down,\n", - " wlikefit_genh_up,\n", - " wlikefit_genh_down,\n", - " ],\n", - " labels=[\n", - " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", - " \"postfit unc. ptll fit\",\n", - " \"\",\n", - " \"postfit unc. w-like\",\n", - " \"\",\n", - " ],\n", - " colors=[\n", - " \"purple\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/prefit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=False,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " ptllfit_gen_expectedh,\n", + " ptllfit_genh_up,\n", + " ptllfit_genh_down,\n", + " wlikefit_genh_up,\n", + " wlikefit_genh_down,\n", + " ],\n", + " labels=[\n", + " \"SCETlib+DYTurbo N$^{3+0}$LL prefit\",\n", + " \"postfit unc. ptll fit\",\n", + " \"\",\n", + " \"postfit unc. w-like\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/prefit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=False,\n", + " yerr=False,\n", + " fill_between=4,\n", ")" ] }, @@ -3503,34 +3671,37 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " ptllfit_genh,\n", - " ptllfit_genh_up,\n", - " ptllfit_genh_down,\n", - " wlikefit_genh_up,\n", - " wlikefit_genh_down,\n", - " ],\n", - " labels=[\"\",\n", - " \"postfit unc. ptll fit\",\n", - " \"\",\n", - " \"postfit unc. w-like\",\n", - " \"\",\n", - " ],\n", - " colors=[\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/ptll-fit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=False,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " ptllfit_genh,\n", + " ptllfit_genh_up,\n", + " ptllfit_genh_down,\n", + " wlikefit_genh_up,\n", + " wlikefit_genh_down,\n", + " ],\n", + " labels=[\n", + " \"\",\n", + " \"postfit unc. ptll fit\",\n", + " \"\",\n", + " \"postfit unc. w-like\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/ptll-fit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=False,\n", + " yerr=False,\n", + " fill_between=4,\n", ")" ] }, @@ -3597,7 +3768,11 @@ "metadata": {}, "outputs": [], "source": [ - "mw_gen_prefit = input_tools.read_all_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_maxFiles_m1_masswindow_ptVbins.hdf5\", [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"], [\"nominal_gen\"])" + "mw_gen_prefit = input_tools.read_all_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_scetlib_dyturboN3p0LLCorr_maxFiles_m1_masswindow_ptVbins.hdf5\",\n", + " [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", + " [\"nominal_gen\"],\n", + ")" ] }, { @@ -3607,9 +3782,11 @@ "metadata": {}, "outputs": [], "source": [ - "mw_combined_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_combinedZ_ptllCorrPDFit_N3p0LL.hdf5\")\n", + "mw_combined_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_combinedZ_ptllCorrPDFit_N3p0LL.hdf5\"\n", + ")\n", "mw_combined_h = mw_combined_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get()\n", - "mw_combined_uph,mw_combined_downh = hist_to_up_down_unc(mw_combined_h)" + "mw_combined_uph, mw_combined_downh = hist_to_up_down_unc(mw_combined_h)" ] }, { @@ -3619,9 +3796,11 @@ "metadata": {}, "outputs": [], "source": [ - "mw_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_ptllCorrPDFit_N3p0LL.hdf5\")\n", + "mw_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_ptllCorrPDFit_N3p0LL.hdf5\"\n", + ")\n", "mw_h = mw_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get()\n", - "mw_uph,mw_downh = hist_to_up_down_unc(mw_h)" + "mw_uph, mw_downh = hist_to_up_down_unc(mw_h)" ] }, { @@ -3686,9 +3865,11 @@ "metadata": {}, "outputs": [], "source": [ - "mw_combined_n3p0ll_exp = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_combinedZ_N3p0LL_expected.hdf5\")\n", + "mw_combined_n3p0ll_exp = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_combinedZ_N3p0LL_expected.hdf5\"\n", + ")\n", "mw_combined_exp_h = mw_combined_n3p0ll_exp[\"hist_postfit_inclusive\"][\"ch0\"].get()\n", - "mw_combined_exp_uph,mw_combined_exp_downh = hist_to_up_down_unc(mw_combined_exp_h)" + "mw_combined_exp_uph, mw_combined_exp_downh = hist_to_up_down_unc(mw_combined_exp_h)" ] }, { @@ -3698,9 +3879,11 @@ "metadata": {}, "outputs": [], "source": [ - "mw_n3p0ll_exp = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_N3p0LL_expected.hdf5\")\n", + "mw_n3p0ll_exp = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/TheoryBiasStudies/WGen_ptVgen_N3p0LL_ptVbin/mw_N3p0LL_expected.hdf5\"\n", + ")\n", "mw_exp_h = mw_n3p0ll_exp[\"hist_postfit_inclusive\"][\"ch0\"].get()\n", - "mw_exp_uph,mw_exp_downh = hist_to_up_down_unc(mw_exp_h)" + "mw_exp_uph, mw_exp_downh = hist_to_up_down_unc(mw_exp_h)" ] }, { @@ -3722,36 +3905,41 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " mw_h,\n", - " mw_combined_h,\n", - " mw_uph,\n", - " mw_downh,\n", - " mw_combined_uph,\n", - " mw_combined_downh,\n", - " ],\n", - " labels=[\n", - " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt.; W-only, N$^{3+0}LL+NNLO$\",\n", - " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt.; W+$p_{T}^{\\ell\\ell}$, N$^{3+0}LL+NNLO$\",\n", - " \"\", \"\", \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*6,\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"x/W-only\",\n", - " rrange=[0.95, 1.05],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " mw_h,\n", + " mw_combined_h,\n", + " mw_uph,\n", + " mw_downh,\n", + " mw_combined_uph,\n", + " mw_combined_downh,\n", + " ],\n", + " labels=[\n", + " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt.; W-only, N$^{3+0}LL+NNLO$\",\n", + " r\"Postfit $p_{T}^{\\ell\\ell}$ rwt.; W+$p_{T}^{\\ell\\ell}$, N$^{3+0}LL+NNLO$\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 6,\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"x/W-only\",\n", + " rrange=[0.95, 1.05],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", ")" ] }, @@ -3774,36 +3962,41 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " mw_exp_h,\n", - " mw_combined_exp_h,\n", - " mw_exp_uph,\n", - " mw_exp_downh,\n", - " mw_combined_exp_uph,\n", - " mw_combined_exp_downh,\n", - " ],\n", - " labels=[\n", - " r\"Prefit $p_{T}^{\\ell\\ell}$ rwt.; W-only, N$^{3+0}LL+NNLO$\",\n", - " r\"Pretfit $p_{T}^{\\ell\\ell}$ rwt.; W+$p_{T}^{\\ell\\ell}$, N$^{3+0}LL+NNLO$\",\n", - " \"\", \"\", \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*6,\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"x/W-only\",\n", - " rrange=[0.95, 1.05],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " mw_exp_h,\n", + " mw_combined_exp_h,\n", + " mw_exp_uph,\n", + " mw_exp_downh,\n", + " mw_combined_exp_uph,\n", + " mw_combined_exp_downh,\n", + " ],\n", + " labels=[\n", + " r\"Prefit $p_{T}^{\\ell\\ell}$ rwt.; W-only, N$^{3+0}LL+NNLO$\",\n", + " r\"Pretfit $p_{T}^{\\ell\\ell}$ rwt.; W+$p_{T}^{\\ell\\ell}$, N$^{3+0}LL+NNLO$\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 6,\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"x/W-only\",\n", + " rrange=[0.95, 1.05],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", ")" ] }, diff --git a/notebooks/SmoothNNLOjet.ipynb b/notebooks/SmoothNNLOjet.ipynb index 3c31e2bf8..c74fed8ec 100644 --- a/notebooks/SmoothNNLOjet.ipynb +++ b/notebooks/SmoothNNLOjet.ipynb @@ -8,7 +8,7 @@ "outputs": [], "source": [ "from utilities.io_tools import input_tools\n", - "from wums import plot_tools,boostHistHelpers as hh\n", + "from wums import plot_tools, boostHistHelpers as hh\n", "from wremnants import theory_corrections\n", "import numpy as np\n", "import hist\n", @@ -76,12 +76,15 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_dyturbo_n4ll_nnlo = read_corr(\"Z\", \"scetlib_dyturbo\", \n", - " [\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", + "scetlib_dyturbo_n4ll_nnlo = read_corr(\n", + " \"Z\",\n", + " \"scetlib_dyturbo\",\n", + " [\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Z_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/z0/results_z-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\",\n", " ],\n", - " [\"Y\", \"qT\"]\n", + " [\"Y\", \"qT\"],\n", ")" ] }, @@ -147,9 +150,17 @@ "metadata": {}, "outputs": [], "source": [ - "nnlojet_fo = input_tools.read_nnlojet_pty_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Z/ZjNNLO/final/ptz\")\n", - "nnlojet_fo_smooth_pt = hh.smooth_hist(nnlojet_fo.project(\"qT\", \"vars\"), \"qT\", start_bin=4)\n", - "nnlojet_fo_smooth = hh.smooth_hist(hh.smooth_hist(nnlojet_fo, \"Y\", exclude_axes=[\"qT\"], start_bin=2, end_bin=30), \"qT\", start_bin=4)" + "nnlojet_fo = input_tools.read_nnlojet_pty_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Z/ZjNNLO/final/ptz\"\n", + ")\n", + "nnlojet_fo_smooth_pt = hh.smooth_hist(\n", + " nnlojet_fo.project(\"qT\", \"vars\"), \"qT\", start_bin=4\n", + ")\n", + "nnlojet_fo_smooth = hh.smooth_hist(\n", + " hh.smooth_hist(nnlojet_fo, \"Y\", exclude_axes=[\"qT\"], start_bin=2, end_bin=30),\n", + " \"qT\",\n", + " start_bin=4,\n", + ")" ] }, { @@ -211,28 +222,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " nnlojet_fo[{\"vars\" : 0}].project(\"qT\"),\n", - " nnlojet_fo_smooth[{\"vars\" : 0}].project(\"qT\"), \n", - " nnlojet_fo_smooth_pt[{\"vars\" : 0}].project(\"qT\"),\n", - " ],\n", - " labels=[\n", - " \"N3LO FO Unsmoothed\",\n", - " \"N3LO FO Smoothed\",\n", - " \"N3LO FO Smoothed pT only\",\n", - " ],\n", - " colors=[\n", - " \"black\",\n", - " \"pink\",\n", - " \"purple\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[\n", + " nnlojet_fo[{\"vars\": 0}].project(\"qT\"),\n", + " nnlojet_fo_smooth[{\"vars\": 0}].project(\"qT\"),\n", + " nnlojet_fo_smooth_pt[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"N3LO FO Unsmoothed\",\n", + " \"N3LO FO Smoothed\",\n", + " \"N3LO FO Smoothed pT only\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"pink\",\n", + " \"purple\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -255,25 +268,27 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " scetlib_nnlojet_n4lln3lo_sm[{\"vars\" : 0}].project(\"qT\"),\n", - " scetlib_nnlojet_n4lln3lo[{\"vars\" : 0}].project(\"qT\"), \n", - " ],\n", - " labels=[\n", - " \"N3LO+N4LL Unsmoothed\",\n", - " \"N3LO+N4LL Smoothed\",\n", - " ],\n", - " colors=[\n", - " \"black\",\n", - " \"pink\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[\n", + " scetlib_nnlojet_n4lln3lo_sm[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_nnlojet_n4lln3lo[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"N3LO+N4LL Unsmoothed\",\n", + " \"N3LO+N4LL Smoothed\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"pink\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -298,28 +313,28 @@ "scale_vars = list(scetlib_nnlojet_n4lln3lo.axes[\"vars\"])[:9]\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " scetlib_dyturbo_n4ll_nnlo[{\"vars\" : v}].project(\"qT\") for v in scale_vars\n", - " ],\n", - " labels=scale_vars,\n", - " colors=[\n", - " \"black\",\n", - " \"pink\",\n", - " \"pink\",\n", - " \"orange\",\n", - " \"orange\",\n", - " \"red\",\n", - " \"red\",\n", - " \"blue\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.8, 1.2],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[scetlib_dyturbo_n4ll_nnlo[{\"vars\": v}].project(\"qT\") for v in scale_vars],\n", + " labels=scale_vars,\n", + " colors=[\n", + " \"black\",\n", + " \"pink\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"orange\",\n", + " \"red\",\n", + " \"red\",\n", + " \"blue\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.8, 1.2],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -344,28 +359,28 @@ "scale_vars = list(scetlib_nnlojet_n4lln3lo.axes[\"vars\"])[:9]\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " scetlib_nnlojet_n4lln3lo_sm[{\"vars\" : v}].project(\"qT\") for v in scale_vars\n", - " ],\n", - " labels=scale_vars,\n", - " colors=[\n", - " \"black\",\n", - " \"pink\",\n", - " \"pink\",\n", - " \"orange\",\n", - " \"orange\",\n", - " \"red\",\n", - " \"red\",\n", - " \"blue\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.8, 1.2],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[scetlib_nnlojet_n4lln3lo_sm[{\"vars\": v}].project(\"qT\") for v in scale_vars],\n", + " labels=scale_vars,\n", + " colors=[\n", + " \"black\",\n", + " \"pink\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"orange\",\n", + " \"red\",\n", + " \"red\",\n", + " \"blue\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.8, 1.2],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -376,10 +391,18 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_n4ll = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\")\n", - "scetlib_n3lo_sing = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_n3lo_sing.pkl\")\n", - "scetlib_nnlo_sing = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Z_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\")\n", - "dyturbo_fo = input_tools.read_dyturbo_vars_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/z0/results_z-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\")" + "scetlib_n4ll = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\"\n", + ")\n", + "scetlib_n3lo_sing = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_n3lo_sing.pkl\"\n", + ")\n", + "scetlib_nnlo_sing = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Z_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\"\n", + ")\n", + "dyturbo_fo = input_tools.read_dyturbo_vars_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/z0/results_z-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\"\n", + ")" ] }, { @@ -418,12 +441,12 @@ } ], "source": [ - "nnlojet_fo[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", - "nnlojet_fo_smooth[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO smoothed\")\n", - "dyturbo_fo[{\"vars\" : 0}].project(\"qT\").plot(label=\"NNLO FO\")\n", - "scetlib_n4ll[{\"vars\" : 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", - "(-1*scetlib_n3lo_sing[{\"vars\" : 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", - "(-1*scetlib_nnlo_sing[{\"vars\" : 0}]).project(\"qT\").plot(label=\"NNLO singular\")\n", + "nnlojet_fo[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", + "nnlojet_fo_smooth[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO smoothed\")\n", + "dyturbo_fo[{\"vars\": 0}].project(\"qT\").plot(label=\"NNLO FO\")\n", + "scetlib_n4ll[{\"vars\": 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", + "(-1 * scetlib_n3lo_sing[{\"vars\": 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", + "(-1 * scetlib_nnlo_sing[{\"vars\": 0}]).project(\"qT\").plot(label=\"NNLO singular\")\n", "plt.legend()" ] }, @@ -455,12 +478,12 @@ } ], "source": [ - "nnlojet_fo[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", - "nnlojet_fo_smooth[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO smoothed\")\n", - "scetlib_n4ll[{\"vars\" : 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", - "(-1*scetlib_n3lo_sing[{\"vars\" : 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", - "scetlib_nnlojet_n4lln3lo_sm[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO+N4LL smoothed\")\n", - "scetlib_dyturbo_n4ll_nnlo[{\"vars\" : 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", + "nnlojet_fo[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", + "nnlojet_fo_smooth[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO smoothed\")\n", + "scetlib_n4ll[{\"vars\": 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", + "(-1 * scetlib_n3lo_sing[{\"vars\": 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", + "scetlib_nnlojet_n4lln3lo_sm[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO+N4LL smoothed\")\n", + "scetlib_dyturbo_n4ll_nnlo[{\"vars\": 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", "plt.legend()" ] }, @@ -482,31 +505,31 @@ } ], "source": [ - "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " scetlib_dyturbo_n4ll_nnlo[{\"vars\" : 0}].project(\"qT\"),\n", - " scetlib_nnlojet_n4lln3lo_sm[{\"vars\" : 0}].project(\"qT\"),\n", - " scetlib_nnlojet_n4lln3lo[{\"vars\" : 0}].project(\"qT\"),\n", - " \n", - " ],\n", - " labels=[\n", - " \"NNLO+N4LL\",\n", - " \"N3LO+N4LL Smoothed\",\n", - " \"N3LO+N4LL Unsmoothed\",\n", - " ],\n", - " colors=[\n", - " \"purple\",\n", - " \"black\",\n", - " \"pink\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[\n", + " scetlib_dyturbo_n4ll_nnlo[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_nnlojet_n4lln3lo_sm[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_nnlojet_n4lln3lo[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"NNLO+N4LL\",\n", + " \"N3LO+N4LL Smoothed\",\n", + " \"N3LO+N4LL Unsmoothed\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"black\",\n", + " \"pink\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -517,8 +540,11 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_nnlojet = read_corr(\"Z\", \"scetlib_nnlojet\", \n", - " [\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", + "scetlib_nnlojet = read_corr(\n", + " \"Z\",\n", + " \"scetlib_nnlojet\",\n", + " [\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_n3lo_sing.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Z/ZjNNLO/final/ptz\",\n", " ],\n", @@ -533,12 +559,15 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_dyturbo = read_corr(\"Z\", \"scetlib_dyturbo\", \n", - " [\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", + "scetlib_dyturbo = read_corr(\n", + " \"Z\",\n", + " \"scetlib_dyturbo\",\n", + " [\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Z_CT18Z_nplambda_N4+0LL_combined.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Z_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\",\n", " \"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/z0/results_z-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\",\n", " ],\n", - " [\"Y\", \"qT\"]\n", + " [\"Y\", \"qT\"],\n", ")" ] }, @@ -561,29 +590,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " scetlib_dyturbo[{\"vars\" : 0}].project(\"qT\"),\n", - " scetlib_nnlojet[{\"vars\" : 0}].project(\"qT\"),\n", - " hsmooth[{\"vars\" : 0}].project(\"qT\"),\n", - " \n", - " ],\n", - " labels=[\n", - " \"NNLO+N4LL\",\n", - " \"N3LO+N4LL Smoothed\",\n", - " \"N3LO+N4LL Unsmoothed\",\n", - " ],\n", - " colors=[\n", - " \"purple\",\n", - " \"black\",\n", - " \"pink\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", + " hists=[\n", + " scetlib_dyturbo[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_nnlojet[{\"vars\": 0}].project(\"qT\"),\n", + " hsmooth[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"NNLO+N4LL\",\n", + " \"N3LO+N4LL Smoothed\",\n", + " \"N3LO+N4LL Unsmoothed\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"black\",\n", + " \"pink\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", ")" ] }, @@ -594,7 +624,11 @@ "metadata": {}, "outputs": [], "source": [ - "corrf = pickle.load(lz4.frame.open(\"../wremnants-data/data/TheoryCorrections/scetlib_nnlojetN4LLN3LO_pdfasCorrZ.pkl.lz4\"))" + "corrf = pickle.load(\n", + " lz4.frame.open(\n", + " \"../wremnants-data/data/TheoryCorrections/scetlib_nnlojetN4LLN3LO_pdfasCorrZ.pkl.lz4\"\n", + " )\n", + ")" ] }, { @@ -646,38 +680,48 @@ } ], "source": [ - "nnlojetas = hh.multiplyHists(corrf[\"Z\"][\"minnlo_ref_hist\"], corrf[\"Z\"][\"scetlib_nnlojetN4LLN3LO_pdfas_minnlo_ratio\"], flow=False)\n", - "nnlojeth = hh.multiplyHists(corrf[\"Z\"][\"minnlo_ref_hist\"], corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_minnlo_ratio\"], flow=False)\n", + "nnlojetas = hh.multiplyHists(\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"],\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4LLN3LO_pdfas_minnlo_ratio\"],\n", + " flow=False,\n", + ")\n", + "nnlojeth = hh.multiplyHists(\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"],\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_minnlo_ratio\"],\n", + " flow=False,\n", + ")\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " nnlojeth[{\"vars\" : 0}].project(\"qT\"),\n", - " nnlojetas[{\"vars\" : 1}].project(\"qT\"),\n", - " nnlojetas[{\"vars\" : 2}].project(\"qT\"),\n", - " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"qT\"),\n", - " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_hist\"][{\"vars\" : 0}].project(\"qT\"),\n", - " ],\n", - " labels=[\n", - " \"Corr to NNLOjet\",\n", - " \"NNLOjet as up\",\n", - " \"NNLOjet as down\",\n", - " \"MiNNLO\",\n", - " \"NNLOjet\",\n", - " ],\n", - " colors=[\n", - " \"black\",\n", - " \"pink\",\n", - " \"pink\",\n", - " \"orange\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.95, 1.05],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", - " )" + " hists=[\n", + " nnlojeth[{\"vars\": 0}].project(\"qT\"),\n", + " nnlojetas[{\"vars\": 1}].project(\"qT\"),\n", + " nnlojetas[{\"vars\": 2}].project(\"qT\"),\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"qT\"),\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_hist\"][{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"Corr to NNLOjet\",\n", + " \"NNLOjet as up\",\n", + " \"NNLOjet as down\",\n", + " \"MiNNLO\",\n", + " \"NNLOjet\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"pink\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.95, 1.05],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", + ")" ] }, { @@ -708,32 +752,42 @@ } ], "source": [ - "nnlojetas = hh.multiplyHists(corrf[\"Z\"][\"minnlo_ref_hist\"], corrf[\"Z\"][\"scetlib_nnlojetN4LLN3LO_pdfas_minnlo_ratio\"], flow=False)\n", - "nnlojeth = hh.multiplyHists(corrf[\"Z\"][\"minnlo_ref_hist\"], corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_minnlo_ratio\"], flow=False)\n", + "nnlojetas = hh.multiplyHists(\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"],\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4LLN3LO_pdfas_minnlo_ratio\"],\n", + " flow=False,\n", + ")\n", + "nnlojeth = hh.multiplyHists(\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"],\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_minnlo_ratio\"],\n", + " flow=False,\n", + ")\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"qT\"),\n", - " nnlojeth[{\"vars\" : 0}].project(\"qT\"),\n", - " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_hist\"][{\"vars\" : 0}].project(\"qT\"),\n", - " ],\n", - " labels=[\n", - " \"MiNNLO\",\n", - " \"NNLOjet smooth\",\n", - " \"NNLOjet\",\n", - " ],\n", - " colors=[\n", - " \"orange\",\n", - " \"black\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.8, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", - " )" + " hists=[\n", + " corrf[\"Z\"][\"minnlo_ref_hist\"].project(\"qT\"),\n", + " nnlojeth[{\"vars\": 0}].project(\"qT\"),\n", + " corrf[\"Z\"][\"scetlib_nnlojetN4p0LLN3LO_hist\"][{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"MiNNLO\",\n", + " \"NNLOjet smooth\",\n", + " \"NNLOjet\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.8, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", + ")" ] }, { @@ -4032,7 +4086,7 @@ } ], "source": [ - "scetlib_nnlojet_n4lln3lo_wm[{\"vars\" : 0}]" + "scetlib_nnlojet_n4lln3lo_wm[{\"vars\": 0}]" ] }, { @@ -4042,7 +4096,11 @@ "metadata": {}, "outputs": [], "source": [ - "minnlow = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists_maxFiles_m1_msht20.hdf5\", \"WminusmunuPostVFP\", \"nominal_gen\")" + "minnlow = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists_maxFiles_m1_msht20.hdf5\",\n", + " \"WminusmunuPostVFP\",\n", + " \"nominal_gen\",\n", + ")" ] }, { @@ -4064,30 +4122,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " minnlow.project(\"ptVgen\")[:100j],\n", - " scetlib_nnlojet_n4lln3lo_wmsm[{\"vars\" : 0}].project(\"qT\"), \n", - " scetlib_nnlojet_n4lln3lo_wm[{\"vars\" : 0}].project(\"qT\"), \n", - "\n", - " ],\n", - " labels=[\n", - " \"MiNNLO\",\n", - " \"NNLOjet smooth\",\n", - " \"NNLOjet\",\n", - " ],\n", - " colors=[\n", - " \"orange\",\n", - " \"black\",\n", - " \"red\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.8, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", - " )" + " hists=[\n", + " minnlow.project(\"ptVgen\")[:100j],\n", + " scetlib_nnlojet_n4lln3lo_wmsm[{\"vars\": 0}].project(\"qT\"),\n", + " scetlib_nnlojet_n4lln3lo_wm[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"MiNNLO\",\n", + " \"NNLOjet smooth\",\n", + " \"NNLOjet\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.8, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", + ")" ] }, { @@ -4105,8 +4164,12 @@ "metadata": {}, "outputs": [], "source": [ - "nnlojet_fow = input_tools.read_nnlojet_pty_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw\")\n", - "nnlojet_fow_pt = input_tools.read_nnlojet_file(\"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw_all.dat\")" + "nnlojet_fow = input_tools.read_nnlojet_pty_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw\"\n", + ")\n", + "nnlojet_fow_pt = input_tools.read_nnlojet_file(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw_all.dat\"\n", + ")" ] }, { @@ -4116,11 +4179,21 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_n4llw = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Wm_CT18Z_nplambda_N4+0LL_combined.pkl\")\n", - "scetlib_n3lo_singw = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/msht20_nplambda_n4+0ll/inclusive_Wm_MSHT20_nplambda_n3lo_sing.pkl\")\n", - "scetlib_nnlo_singw = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Wm_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\")\n", - "dyturbo_fowm = input_tools.read_dyturbo_vars_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/wminus/results_wm-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\")\n", - "dyturbo_fowp = input_tools.read_dyturbo_vars_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/wplus/results_wp-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\")" + "scetlib_n4llw = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n4+0ll/inclusive_Wm_CT18Z_nplambda_N4+0LL_combined.pkl\"\n", + ")\n", + "scetlib_n3lo_singw = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/msht20_nplambda_n4+0ll/inclusive_Wm_MSHT20_nplambda_n3lo_sing.pkl\"\n", + ")\n", + "scetlib_nnlo_singw = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_scalevars/inclusive_Wm_CT18Z_nplambda_scalevars_nnlo_sing_combined.pkl\"\n", + ")\n", + "dyturbo_fowm = input_tools.read_dyturbo_vars_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/wminus/results_wm-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\"\n", + ")\n", + "dyturbo_fowp = input_tools.read_dyturbo_vars_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/scalevariations/wplus/results_wp-2d-nnlo-vj-CT18ZNNLO-{scale}-scetlibmatch.txt\"\n", + ")" ] }, { @@ -4151,10 +4224,10 @@ } ], "source": [ - "nnlojet_fow[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", - "scetlib_n4llw[{\"vars\" : 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", - "(-1*scetlib_n3lo_singw[{\"vars\" : 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", - "scetlib_nnlojet_n4lln3lo_wmsm[{\"vars\" : 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", + "nnlojet_fow[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", + "scetlib_n4llw[{\"vars\": 0}].project(\"qT\").plot(label=\"N4LL resum\")\n", + "(-1 * scetlib_n3lo_singw[{\"vars\": 0}]).project(\"qT\").plot(label=\"N3LO singular\")\n", + "scetlib_nnlojet_n4lln3lo_wmsm[{\"vars\": 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", "plt.legend()" ] }, @@ -4165,7 +4238,7 @@ "metadata": {}, "outputs": [], "source": [ - "nonsingw = hh.addHists(nnlojet_fow, -1*scetlib_n3lo_singw)" + "nonsingw = hh.addHists(nnlojet_fow, -1 * scetlib_n3lo_singw)" ] }, { @@ -4204,8 +4277,8 @@ } ], "source": [ - "nonsingw[{\"vars\" : 0}].project(\"qT\").plot()\n", - "scetlib_n4llw[{\"vars\" : 0}].project(\"qT\").plot(label=\"N4LL resum\")" + "nonsingw[{\"vars\": 0}].project(\"qT\").plot()\n", + "scetlib_n4llw[{\"vars\": 0}].project(\"qT\").plot(label=\"N4LL resum\")" ] }, { @@ -4223,9 +4296,13 @@ "metadata": {}, "outputs": [], "source": [ - "nnlojet_fow = input_tools.read_nnlojet_pty_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw\")\n", - "scetlib_n3lo_singw = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/msht20_nplambda_n4+0ll/inclusive_Wm_MSHT20_nplambda_n3lo_sing.pkl\")\n", - "nonsingw = nnlojet_fow[{\"vars\" : 0}]+ -1*scetlib_n3lo_singw[{\"vars\" : 0, \"Q\" : 0}]\n" + "nnlojet_fow = input_tools.read_nnlojet_pty_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/NNLOjet/Wm/WmjNNLO/ptw\"\n", + ")\n", + "scetlib_n3lo_singw = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/msht20_nplambda_n4+0ll/inclusive_Wm_MSHT20_nplambda_n3lo_sing.pkl\"\n", + ")\n", + "nonsingw = nnlojet_fow[{\"vars\": 0}] + -1 * scetlib_n3lo_singw[{\"vars\": 0, \"Q\": 0}]" ] }, { @@ -4272,8 +4349,8 @@ } ], "source": [ - "nnlojet_fow[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", - "scetlib_n3lo_singw[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO sing\")\n", + "nnlojet_fow[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", + "scetlib_n3lo_singw[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO sing\")\n", "nonsingw.project(\"qT\").plot()" ] }, @@ -7539,7 +7616,7 @@ } ], "source": [ - "nnlojet_fow[{\"vars\" : 0}]" + "nnlojet_fow[{\"vars\": 0}]" ] }, { @@ -7570,10 +7647,12 @@ } ], "source": [ - "nnlojet_fo[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", - "scetlib_n3lo_sing[{\"vars\" : 0}].project(\"qT\").plot(label=\"N3LO singular\")\n", - "scetlib_dyturbo_n4ll_nnlo[{\"vars\" : 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", - "(nnlojet_fo[{\"vars\" : 0}]+-1*scetlib_n3lo_sing[{\"vars\" : 0, \"Q\" : 0}]).project(\"qT\").plot(label=\"Nonsingular\")\n", + "nnlojet_fo[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO FO unsmoothed\")\n", + "scetlib_n3lo_sing[{\"vars\": 0}].project(\"qT\").plot(label=\"N3LO singular\")\n", + "scetlib_dyturbo_n4ll_nnlo[{\"vars\": 0}].project(\"qT\").plot(label=\"NNLO+N4LL\")\n", + "(nnlojet_fo[{\"vars\": 0}] + -1 * scetlib_n3lo_sing[{\"vars\": 0, \"Q\": 0}]).project(\n", + " \"qT\"\n", + ").plot(label=\"Nonsingular\")\n", "plt.legend()" ] }, @@ -7596,27 +7675,28 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " dyturbo_fowm[{\"vars\" : 0}].project(\"qT\"), \n", - " dyturbo_fowp[{\"vars\" : 0}].project(\"qT\"), \n", - "\n", - " ],\n", - " labels=[\n", - " \"W+\",\n", - " \"W-\",\n", - " ],\n", - " colors=[\n", - " \"orange\",\n", - " \"black\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[1.0, 1.5],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " ratio_legend=False,\n", - " )" + " hists=[\n", + " dyturbo_fowm[{\"vars\": 0}].project(\"qT\"),\n", + " dyturbo_fowp[{\"vars\": 0}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " \"W+\",\n", + " \"W-\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"black\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[1.0, 1.5],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " ratio_legend=False,\n", + ")" ] }, { diff --git a/notebooks/WCharm.ipynb b/notebooks/WCharm.ipynb index 9a98366f2..810130af5 100644 --- a/notebooks/WCharm.ipynb +++ b/notebooks/WCharm.ipynb @@ -21,7 +21,9 @@ "metadata": {}, "outputs": [], "source": [ - "res, meta, _ = input_tools.read_infile(\"/scratch/dwalter/results_histmaker/250304_w_z_gen_massiveCharm/w_z_gen_dists_maxFiles_m1_nnpdf31_nnpdf31.hdf5\")" + "res, meta, _ = input_tools.read_infile(\n", + " \"/scratch/dwalter/results_histmaker/250304_w_z_gen_massiveCharm/w_z_gen_dists_maxFiles_m1_nnpdf31_nnpdf31.hdf5\"\n", + ")" ] }, { @@ -56,7 +58,7 @@ " \"ptGen\": r\"$pre\\ FSR\\ p_\\mathrm{T}^{\\ell}$\",\n", " \"absEtaGen\": r\"$pre\\ FSR\\ |\\eta^{\\ell}|$\",\n", " \"massVgen\": r\"pre FSR W mass\",\n", - " \"absYVgen\": r\"pre FSR W |Y|\", \n", + " \"absYVgen\": r\"pre FSR W |Y|\",\n", " \"ptVgen\": r\"$pre\\ FSR\\ p_\\mathrm{T}^{W}$\",\n", "}\n", "# xsec = {\n", @@ -75,8 +77,10 @@ "outputs": [], "source": [ "def load(proc, hist):\n", - " h = res[proc]['output'][hist].get()\n", - " h = hh.scaleHist(h, res[proc][\"dataset\"][\"xsec\"]*10e6/res[proc]['weight_sum'], createNew=True)\n", + " h = res[proc][\"output\"][hist].get()\n", + " h = hh.scaleHist(\n", + " h, res[proc][\"dataset\"][\"xsec\"] * 10e6 / res[proc][\"weight_sum\"], createNew=True\n", + " )\n", " return h" ] }, @@ -88,98 +92,130 @@ "outputs": [], "source": [ "def plot(h1ds, labels, var, ratio=False, plotname=\"hists\", normalize=False):\n", - " \n", - " linestyles = [\"-\", \"--\", \":\"][::-1][:len(h1ds)]\n", - " colors = [\"black\",\"blue\",\"red\"][::-1][:len(h1ds)]\n", - " labels = labels[:len(h1ds)]\n", - " \n", + "\n", + " linestyles = [\"-\", \"--\", \":\"][::-1][: len(h1ds)]\n", + " colors = [\"black\", \"blue\", \"red\"][::-1][: len(h1ds)]\n", + " labels = labels[: len(h1ds)]\n", + "\n", " if normalize:\n", - " ylabel=\"a.u.\"\n", + " ylabel = \"a.u.\"\n", " else:\n", - " ylabel=\"Events / bin\"\n", + " ylabel = \"Events / bin\"\n", "\n", " widths = np.diff(h1ds[0].axes.edges[0])\n", - " \n", + "\n", " ymin = None if ratio else 0\n", " ymax = None\n", "\n", " if normalize:\n", - " ymax = ymax if ymax is not None else max([max(h.values()/(np.sum(h.values())*widths)) for h in h1ds])\n", - " ymin = ymin if ymin is not None else min([min(h.values()/(np.sum(h.values())*widths)) for h in h1ds])\n", + " ymax = (\n", + " ymax\n", + " if ymax is not None\n", + " else max([max(h.values() / (np.sum(h.values()) * widths)) for h in h1ds])\n", + " )\n", + " ymin = (\n", + " ymin\n", + " if ymin is not None\n", + " else min([min(h.values() / (np.sum(h.values()) * widths)) for h in h1ds])\n", + " )\n", " else:\n", - " ymax = ymax if ymax is not None else max([max(h.values()/widths) for h in h1ds])\n", - " ymin = ymin if ymin is not None else min([min(h.values()/widths) for h in h1ds])\n", + " ymax = (\n", + " ymax if ymax is not None else max([max(h.values() / widths) for h in h1ds])\n", + " )\n", + " ymin = (\n", + " ymin if ymin is not None else min([min(h.values() / widths) for h in h1ds])\n", + " )\n", " yrange = ymax - ymin\n", - " ymin = ymin if ymin == 0 else ymin - yrange*0.3\n", - " ymax = ymax + yrange*0.3\n", + " ymin = ymin if ymin == 0 else ymin - yrange * 0.3\n", + " ymax = ymax + yrange * 0.3\n", "\n", " if ratio:\n", " fig, ax, ratio_axes = plot_tools.figureWithRatio(\n", - " h1ds[0], \n", - " xlabel=xaxis_labels[var], \n", - " ylabel=ylabel, \n", + " h1ds[0],\n", + " xlabel=xaxis_labels[var],\n", + " ylabel=ylabel,\n", " rlabel=\"matched/nominal\",\n", - " rrange=(0.5,1.5),\n", - " automatic_scale=False, \n", - " width_scale=1.2, \n", + " rrange=(0.5, 1.5),\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", " ylim=(ymin, ymax),\n", " )\n", " ax2 = ratio_axes[0]\n", " x = h1ds[0].axes.edges[0][:-1]\n", - " ax2.plot([min(x), max(x)], [1,1], color=\"black\", linestyle=\"--\")\n", - " \n", + " ax2.plot([min(x), max(x)], [1, 1], color=\"black\", linestyle=\"--\")\n", + "\n", " # for i, h1d in enumerate(h1ds):\n", " x = h1ds[-1].axes.edges[0][:-1]\n", " y = h1ds[-1].values()\n", " yN = h1ds[-2].values()\n", " # err = np.sqrt(h1ds[2].variances() + h1ds[1].variances())\n", "\n", - " ax2.set_xlim((min(x),max(x)))\n", + " ax2.set_xlim((min(x), max(x)))\n", "\n", " if normalize:\n", - " y = y/sum(y)\n", - " yN = yN/sum(yN)\n", + " y = y / sum(y)\n", + " yN = yN / sum(yN)\n", "\n", - " ax2.step(x, y/yN, color=colors[-1], linestyle=linestyles[-1], label=labels[-1], where=\"post\")\n", + " ax2.step(\n", + " x,\n", + " y / yN,\n", + " color=colors[-1],\n", + " linestyle=linestyles[-1],\n", + " label=labels[-1],\n", + " where=\"post\",\n", + " )\n", "\n", " else:\n", " fig, ax = plot_tools.figure(\n", - " h1ds[0], \n", - " xlabel=xaxis_labels[var], \n", - " ylabel=ylabel, \n", - " automatic_scale=False, \n", - " width_scale=1.2, \n", + " h1ds[0],\n", + " xlabel=xaxis_labels[var],\n", + " ylabel=ylabel,\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", " ylim=(ymin, ymax),\n", " )\n", - " \n", + "\n", " for i, h1d in enumerate(h1ds):\n", " x = h1d.axes.edges[0][:-1]\n", " y = h1d.values()\n", " err = np.sqrt(h1d.variances())\n", "\n", - " ax.set_xlim((min(x),max(x)))\n", - " ax.set_ylim((0,ymax))\n", + " ax.set_xlim((min(x), max(x)))\n", + " ax.set_ylim((0, ymax))\n", "\n", - "# ax.set_xlim(26,56)#-2.4,2.4)\n", + " # ax.set_xlim(26,56)#-2.4,2.4)\n", "\n", " if normalize:\n", - " y = y/sum(y)\n", - " \n", - " ax.step(x, y/widths, color=colors[i], linestyle=linestyles[i], label=labels[i], where=\"post\")\n", + " y = y / sum(y)\n", + "\n", + " ax.step(\n", + " x,\n", + " y / widths,\n", + " color=colors[i],\n", + " linestyle=linestyles[i],\n", + " label=labels[i],\n", + " where=\"post\",\n", + " )\n", " # ax.fill_between(x, y - err, y + err, alpha=0.3, color=colors(i), step=\"post\")\n", "\n", " # ax.text(1.0, 1.003, text_dict[base_process], transform=ax.transAxes, fontsize=30,\n", " # verticalalignment='bottom', horizontalalignment=\"right\")\n", " plot_tools.addLegend(ax, ncols=1)\n", - " plot_name = plotname+\"_\"+var\n", + " plot_name = plotname + \"_\" + var\n", " if ratio:\n", " plot_name += \"_ratio\"\n", "\n", " if normalize:\n", " plot_name += \"_normalized\"\n", - " ax.text(1.0, 1.003, \"Normalized\", transform=ax.transAxes, #fontsize=30,\n", - " verticalalignment='bottom', horizontalalignment=\"right\")\n", - " \n", + " ax.text(\n", + " 1.0,\n", + " 1.003,\n", + " \"Normalized\",\n", + " transform=ax.transAxes, # fontsize=30,\n", + " verticalalignment=\"bottom\",\n", + " horizontalalignment=\"right\",\n", + " )\n", + "\n", " plot_tools.save_pdf_and_png(\"./250305_WCharm/\", plot_name)" ] }, @@ -199,10 +235,22 @@ } ], "source": [ - "WCharmToMuNu = [load(\"WminusCharmToMuNu\", \"prefsr_lep\"), load(\"WplusCharmToMuNu\", \"prefsr_lep\")]\n", - "WmunuPostVFP = [load(\"WminusmunuPostVFP\", \"prefsr_lep\"), load(\"WplusmunuPostVFP\", \"prefsr_lep\")]\n", - "print(WmunuPostVFP[0][{\"charm\":1}].values(flow=True).sum() / WmunuPostVFP[0].values(flow=True).sum())\n", - "print(WmunuPostVFP[1][{\"charm\":1}].values(flow=True).sum() / WmunuPostVFP[1].values(flow=True).sum())" + "WCharmToMuNu = [\n", + " load(\"WminusCharmToMuNu\", \"prefsr_lep\"),\n", + " load(\"WplusCharmToMuNu\", \"prefsr_lep\"),\n", + "]\n", + "WmunuPostVFP = [\n", + " load(\"WminusmunuPostVFP\", \"prefsr_lep\"),\n", + " load(\"WplusmunuPostVFP\", \"prefsr_lep\"),\n", + "]\n", + "print(\n", + " WmunuPostVFP[0][{\"charm\": 1}].values(flow=True).sum()\n", + " / WmunuPostVFP[0].values(flow=True).sum()\n", + ")\n", + "print(\n", + " WmunuPostVFP[1][{\"charm\": 1}].values(flow=True).sum()\n", + " / WmunuPostVFP[1].values(flow=True).sum()\n", + ")" ] }, { @@ -294,21 +342,42 @@ ], "source": [ "for i, (hCharm, hNominal) in enumerate(zip(WCharmToMuNu, WmunuPostVFP)):\n", - " for var in [\"ptGen\",\"absEtaGen\"]:\n", + " for var in [\"ptGen\", \"absEtaGen\"]:\n", " hC = hCharm.project(var)\n", " hN = hNominal.project(var)\n", - " hNC = hNominal[{\"charm\":1}].project(var)\n", - " hNNC = hNominal[{\"charm\":0}].project(var)\n", + " hNC = hNominal[{\"charm\": 1}].project(var)\n", + " hNNC = hNominal[{\"charm\": 0}].project(var)\n", " hM = hh.addHists(hNNC, hC)\n", - " if i==0:\n", - " labels = [r\"$W^{-}$ incl.\", r\"$W^{-}+{c}$ (massive)\", r\"$W^{-}+{c}$ (massless)\"]\n", + " if i == 0:\n", + " labels = [\n", + " r\"$W^{-}$ incl.\",\n", + " r\"$W^{-}+{c}$ (massive)\",\n", + " r\"$W^{-}+{c}$ (massless)\",\n", + " ]\n", " # labels = [r\"$W^{-}$ nominal\", r\"$W^{-}$ matched\", ]\n", " else:\n", - " labels = [r\"$W^{+}$ incl.\", r\"$W^{+}+\\bar{c}$ (massive)\", r\"$W^{+}+\\bar{c}$ (massless)\"]\n", + " labels = [\n", + " r\"$W^{+}$ incl.\",\n", + " r\"$W^{+}+\\bar{c}$ (massive)\",\n", + " r\"$W^{+}+\\bar{c}$ (massless)\",\n", + " ]\n", " # labels = [r\"$W^{+}$ nominal\", r\"$W^{+}$ matched\", ]\n", - " \n", - " plot([hN, hM][::-1], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", ratio=True)\n", - " plot([hN, hM][::-1], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", normalize=True, ratio=True)\n", + "\n", + " plot(\n", + " [hN, hM][::-1],\n", + " labels[::-1],\n", + " var,\n", + " plotname=\"Wminus\" if i == 0 else \"Wplus\",\n", + " ratio=True,\n", + " )\n", + " plot(\n", + " [hN, hM][::-1],\n", + " labels[::-1],\n", + " var,\n", + " plotname=\"Wminus\" if i == 0 else \"Wplus\",\n", + " normalize=True,\n", + " ratio=True,\n", + " )\n", " # plot([hC, hNC], [\"W+c (massive)\", \"W+c (massless)\"], var)" ] }, @@ -319,8 +388,14 @@ "metadata": {}, "outputs": [], "source": [ - "WCharmToMuNu = [load(\"WminusCharmToMuNu\",\"nominal_gen\"), load(\"WplusCharmToMuNu\", \"nominal_gen\")]\n", - "WmunuPostVFP = [load(\"WminusmunuPostVFP\", \"nominal_gen\"), load(\"WplusmunuPostVFP\", \"nominal_gen\")]" + "WCharmToMuNu = [\n", + " load(\"WminusCharmToMuNu\", \"nominal_gen\"),\n", + " load(\"WplusCharmToMuNu\", \"nominal_gen\"),\n", + "]\n", + "WmunuPostVFP = [\n", + " load(\"WminusmunuPostVFP\", \"nominal_gen\"),\n", + " load(\"WplusmunuPostVFP\", \"nominal_gen\"),\n", + "]" ] }, { @@ -452,13 +527,13 @@ ], "source": [ "for i, (hCharm, hNominal) in enumerate(zip(WCharmToMuNu, WmunuPostVFP)):\n", - " for var in [\"massVgen\",\"absYVgen\", \"ptVgen\"]:\n", + " for var in [\"massVgen\", \"absYVgen\", \"ptVgen\"]:\n", " hN = hNominal.project(var)\n", " hC = hCharm.project(var)\n", - " hNC = hNominal[{\"charm\":1}].project(var)\n", - " hNNC = hNominal[{\"charm\":0}].project(var)\n", + " hNC = hNominal[{\"charm\": 1}].project(var)\n", + " hNNC = hNominal[{\"charm\": 0}].project(var)\n", " hM = hh.addHists(hNNC, hC)\n", - " if i==0:\n", + " if i == 0:\n", " labels = [r\"$W^{-}+{c}$ (massive)\", r\"$W^{-}+{c}$ (massless)\"]\n", " # labels = [r\"$W^{-}$ nominal\", r\"$W^{-}$ matched\", ]\n", " else:\n", @@ -467,9 +542,22 @@ "\n", " # plot([hN, hM][::-1], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", ratio=True)\n", " # plot([hN, hM][::-1], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", ratio=True, normalize=True)\n", - " \n", - " plot([hNC, hC], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", ratio=True)\n", - " plot([hNC, hC], labels[::-1], var, plotname=\"Wminus\" if i==0 else \"Wplus\", ratio=True, normalize=True)\n", + "\n", + " plot(\n", + " [hNC, hC],\n", + " labels[::-1],\n", + " var,\n", + " plotname=\"Wminus\" if i == 0 else \"Wplus\",\n", + " ratio=True,\n", + " )\n", + " plot(\n", + " [hNC, hC],\n", + " labels[::-1],\n", + " var,\n", + " plotname=\"Wminus\" if i == 0 else \"Wplus\",\n", + " ratio=True,\n", + " normalize=True,\n", + " )\n", " # plot([hC, hNC], [\"W+c (massive)\", \"W+c (massless)\"], var)" ] }, diff --git a/notebooks/angularCoefficients.ipynb b/notebooks/angularCoefficients.ipynb index 2ade23c10..3c65f2c62 100644 --- a/notebooks/angularCoefficients.ipynb +++ b/notebooks/angularCoefficients.ipynb @@ -27,6 +27,7 @@ "import wremnants\n", "import lz4.frame\n", "import pickle\n", + "\n", "hep.style.use(hep.style.ROOT)" ] }, @@ -66,7 +67,7 @@ "source": [ "with lz4.frame.open(\"../w_z_gen_dists_reweight_h2.pkl.lz4\") as f:\n", " file = pickle.load(f)\n", - "file['WplusmunuPostVFP' ][\"output\"][\"helicity_moments_scale\"]" + "file[\"WplusmunuPostVFP\"][\"output\"][\"helicity_moments_scale\"]" ] }, { @@ -93,39 +94,83 @@ "source": [ "hist_ang_coeff = {}\n", "sigma_UL = {}\n", - "boson_channels = ['wp', 'wm', 'z']\n", - "projection_axes = ['ptVgen', 'absYVgen']\n", + "boson_channels = [\"wp\", \"wm\", \"z\"]\n", + "projection_axes = [\"ptVgen\", \"absYVgen\"]\n", "for chn in boson_channels:\n", " hist_ang_coeff[chn] = {}\n", " sigma_UL[chn] = {}\n", "\n", "# read full histogram for angular coefficients\n", - "hist_ang_coeff['wp']['bugged'] = file['WplusmunuPostVFP' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['wp']['bugfix'] = file['WplusmunuPostVFP_bugfix' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['wm']['bugged'] = file['WminusmunuPostVFP' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['wm']['bugfix'] = file['WminusmunuPostVFP_bugfix']['output']['helicity_moments_scale']\n", - "hist_ang_coeff['z' ]['bugged'] = file['ZmumuPostVFP' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['z' ]['bugfix'] = file['ZmumuPostVFP_bugfix' ]['output']['helicity_moments_scale']\n", + "hist_ang_coeff[\"wp\"][\"bugged\"] = file[\"WplusmunuPostVFP\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"wp\"][\"bugfix\"] = file[\"WplusmunuPostVFP_bugfix\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"wm\"][\"bugged\"] = file[\"WminusmunuPostVFP\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"wm\"][\"bugfix\"] = file[\"WminusmunuPostVFP_bugfix\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"z\"][\"bugged\"] = file[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"]\n", + "hist_ang_coeff[\"z\"][\"bugfix\"] = file[\"ZmumuPostVFP_bugfix\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", "\n", "s = hist.tag.Slicer()\n", - "sigma_UL['wp']['bugged'] = (file['WplusmunuPostVFP' ]['output']['nominal_gen']* file[\"WplusmunuPostVFP\" ][\"dataset\"][\"xsec\"] / file[\"WplusmunuPostVFP\" ][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['wp']['bugfix'] = (file['WplusmunuPostVFP_bugfix' ]['output']['nominal_gen']* file[\"WplusmunuPostVFP_bugfix\" ][\"dataset\"][\"xsec\"] / file[\"WplusmunuPostVFP_bugfix\" ][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['wm']['bugged'] = (file['WminusmunuPostVFP' ]['output']['nominal_gen']* file[\"WminusmunuPostVFP\" ][\"dataset\"][\"xsec\"] / file[\"WminusmunuPostVFP\" ][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['wm']['bugfix'] = (file['WminusmunuPostVFP_bugfix']['output']['nominal_gen']* file[\"WminusmunuPostVFP_bugfix\"][\"dataset\"][\"xsec\"] / file[\"WminusmunuPostVFP_bugfix\"][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['z' ]['bugged'] = (file['ZmumuPostVFP' ]['output']['nominal_gen'][{'massVgen':s[80j:100j:hist.sum]}] * file[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"] / file[\"ZmumuPostVFP\"][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['z' ]['bugfix'] = (file['ZmumuPostVFP_bugfix' ]['output']['nominal_gen'][{'massVgen':s[80j:100j:hist.sum]}] * file[\"ZmumuPostVFP_bugfix\"][\"dataset\"][\"xsec\"] / file[\"ZmumuPostVFP_bugfix\"][\"weight_sum\"]).project('ptVgen')\n", - "# make projected 1D histograms; \"normalize\" and calculate the angular coefficients \n", + "sigma_UL[\"wp\"][\"bugged\"] = (\n", + " file[\"WplusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * file[\"WplusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / file[\"WplusmunuPostVFP\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"wp\"][\"bugfix\"] = (\n", + " file[\"WplusmunuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"]\n", + " * file[\"WplusmunuPostVFP_bugfix\"][\"dataset\"][\"xsec\"]\n", + " / file[\"WplusmunuPostVFP_bugfix\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"wm\"][\"bugged\"] = (\n", + " file[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * file[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / file[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"wm\"][\"bugfix\"] = (\n", + " file[\"WminusmunuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"]\n", + " * file[\"WminusmunuPostVFP_bugfix\"][\"dataset\"][\"xsec\"]\n", + " / file[\"WminusmunuPostVFP_bugfix\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"z\"][\"bugged\"] = (\n", + " file[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"][\n", + " {\"massVgen\": s[80j : 100j : hist.sum]}\n", + " ]\n", + " * file[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / file[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"z\"][\"bugfix\"] = (\n", + " file[\"ZmumuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"][\n", + " {\"massVgen\": s[80j : 100j : hist.sum]}\n", + " ]\n", + " * file[\"ZmumuPostVFP_bugfix\"][\"dataset\"][\"xsec\"]\n", + " / file[\"ZmumuPostVFP_bugfix\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "# make projected 1D histograms; \"normalize\" and calculate the angular coefficients\n", "hist1D_ang_coeff = {}\n", "s = hist.tag.Slicer()\n", "for chn in boson_channels:\n", " hist1D_ang_coeff[chn] = {}\n", - " for group in ['bugged', 'bugfix']:\n", + " for group in [\"bugged\", \"bugfix\"]:\n", " hist1D_ang_coeff[chn][group] = {}\n", " for ax in projection_axes:\n", - " if chn == 'z':\n", - " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(hist_ang_coeff[chn][group][{'massVgen':s[80j:100j:hist.sum]}].project('helicity',ax))\n", + " if chn == \"z\":\n", + " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(\n", + " hist_ang_coeff[chn][group][\n", + " {\"massVgen\": s[80j : 100j : hist.sum]}\n", + " ].project(\"helicity\", ax)\n", + " )\n", " else:\n", - " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(hist_ang_coeff[chn][group].project('helicity',ax))\n" + " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(\n", + " hist_ang_coeff[chn][group].project(\"helicity\", ax)\n", + " )" ] }, { @@ -135,17 +180,18 @@ "metadata": {}, "outputs": [], "source": [ - "'''make plots for angular coefficients in the following scheme'''\n", + "\"\"\"make plots for angular coefficients in the following scheme\"\"\"\n", + "\n", "# Z\n", - "#-----------ptV A_0-7 ----------\n", - "#-----------etaV A_0-7 ----------\n", + "# -----------ptV A_0-7 ----------\n", + "# -----------etaV A_0-7 ----------\n", "# W+\n", - "#-----------ptV A_0-7 ----------\n", - "#-----------etaV A_0-7 ----------\n", + "# -----------ptV A_0-7 ----------\n", + "# -----------etaV A_0-7 ----------\n", "# W-\n", - "#-----------ptV A_0-7 ----------\n", - "#-----------etaV A_0-7 ----------\n", - "'''\n", + "# -----------ptV A_0-7 ----------\n", + "# -----------etaV A_0-7 ----------\n", + "\"\"\"\n", "fig, axs = plt.subplots(6, 9, figsize=(36,54))\n", "\n", "for idx_ang in range(-1,8):\n", @@ -160,7 +206,7 @@ " rlabel=\"bugfix/bugged\",\n", " xlim=None, binwnorm=None).plot(axs[0+idx_ax, idx_ang+1])\n", "\n", - "'''" + "\"\"\"" ] }, { @@ -172,47 +218,62 @@ "source": [ "rrange_opt = None\n", "\n", - "for idx_ang in range(-1,8):\n", + "for idx_ang in range(-1, 8):\n", " if idx_ang == -1:\n", " ang_name = \"Const_term\"\n", " else:\n", " ang_name = f\"A_{idx_ang}\"\n", - " \n", - " rrange_opt = [0.9,1.1]\n", + "\n", + " rrange_opt = [0.9, 1.1]\n", " if idx_ang == 0:\n", - " rrange_opt = [0.8,1.2]\n", + " rrange_opt = [0.8, 1.2]\n", "\n", " for idx_ax, ax in enumerate(projection_axes):\n", " fig_z = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['z']['bugged'][ax][{\"helicity\":hist.loc(idx_ang)}], \n", - " hist1D_ang_coeff['z']['bugfix'][ax][{\"helicity\":hist.loc(idx_ang)}]], \n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel=ax, \n", + " [\n", + " hist1D_ang_coeff[\"z\"][\"bugged\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " hist1D_ang_coeff[\"z\"][\"bugfix\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=ax,\n", " ylabel=\"Events/bin\",\n", " rlabel=\"bugfix/bugged\",\n", " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", " fig_wp = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['wp']['bugged'][ax][{\"helicity\":hist.loc(idx_ang)}], \n", - " hist1D_ang_coeff['wp']['bugfix'][ax][{\"helicity\":hist.loc(idx_ang)}]], \n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel=ax, \n", + " [\n", + " hist1D_ang_coeff[\"wp\"][\"bugged\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " hist1D_ang_coeff[\"wp\"][\"bugfix\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=ax,\n", " ylabel=\"Events/bin\",\n", " rlabel=\"bugfix/bugged\",\n", " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", " fig_wm = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['wm']['bugged'][ax][{\"helicity\":hist.loc(idx_ang)}], \n", - " hist1D_ang_coeff['wm']['bugfix'][ax][{\"helicity\":hist.loc(idx_ang)}]], \n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel=ax, \n", + " [\n", + " hist1D_ang_coeff[\"wm\"][\"bugged\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " hist1D_ang_coeff[\"wm\"][\"bugfix\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=ax,\n", " ylabel=\"Events/bin\",\n", " rlabel=\"bugfix/bugged\",\n", " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", " fig_z.savefig(f\"ang_coeff-{ang_name}-{ax}-Z.pdf\")\n", " fig_wp.savefig(f\"ang_coeff-{ang_name}-{ax}-wp.pdf\")\n", " fig_wm.savefig(f\"ang_coeff-{ang_name}-{ax}-wm.pdf\")\n", @@ -229,29 +290,42 @@ "outputs": [], "source": [ "import uproot\n", - "f = uproot.open(\"/eos/user/k/kelong/HistFiles/ZGen/ZToMuMu_MATRIX_RadISH_MatchEWParams_NNPDF31.root\")\n", + "\n", + "f = uproot.open(\n", + " \"/eos/user/k/kelong/HistFiles/ZGen/ZToMuMu_MATRIX_RadISH_MatchEWParams_NNPDF31.root\"\n", + ")\n", "hist_corr = f[\"DYm50_matrix__radish/ptZ_lhe_mm\"].to_hist()\n", "\n", "with lz4.frame.open(\"../w_z_gen_dists_fine_bin.pkl.lz4\") as f:\n", " minnlo = pickle.load(f)\n", - " \n", - "hist_bugged = (minnlo[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"] *\n", - " minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"] / minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]).project('ptVgen')\n", - "hist_bugfix = (minnlo[\"ZmumuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"] *\n", - " minnlo[\"ZmumuPostVFP_bugfix\"][\"dataset\"][\"xsec\"] / minnlo[\"ZmumuPostVFP_bugfix\"][\"weight_sum\"]).project('ptVgen')\n", "\n", - "plot_tools.makePlotWithRatioToRef(\n", - " [hist_corr, \n", - " hist_bugged,\n", - " hist_bugfix], \n", - " [\"MATRIX+RadISH (NNLO+N$^{3}$LL)\", \"MiNNLO (H$^{(2)}$ sign error\", \"MiNNLO (H$^{(2)}$ sign error fixed)\"], \n", + "hist_bugged = (\n", + " minnlo[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "hist_bugfix = (\n", + " minnlo[\"ZmumuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo[\"ZmumuPostVFP_bugfix\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"ZmumuPostVFP_bugfix\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", "\n", - " colors=['blue', 'green', 'orange'], \n", - " xlabel=\"$p_T^Z$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/NNLO+N$^{3}$LL\",\n", - " rrange=[0.9, 1.1],\n", - " xlim=None, binwnorm=None, baseline=True)" + "plot_tools.makePlotWithRatioToRef(\n", + " [hist_corr, hist_bugged, hist_bugfix],\n", + " [\n", + " \"MATRIX+RadISH (NNLO+N$^{3}$LL)\",\n", + " \"MiNNLO (H$^{(2)}$ sign error\",\n", + " \"MiNNLO (H$^{(2)}$ sign error fixed)\",\n", + " ],\n", + " colors=[\"blue\", \"green\", \"orange\"],\n", + " xlabel=\"$p_T^Z$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/NNLO+N$^{3}$LL\",\n", + " rrange=[0.9, 1.1],\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")" ] }, { @@ -261,7 +335,7 @@ "metadata": {}, "outputs": [], "source": [ - "file['WplusmunuPostVFP_bugfix' ]['output']['nominal_gen'].project('ptVgen')" + "file[\"WplusmunuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"].project(\"ptVgen\")" ] }, { @@ -272,37 +346,57 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['z']['bugged']['ptVgen'][{\"helicity\":4j}], \n", - " hist1D_ang_coeff['z']['bugfix']['ptVgen'][{\"helicity\":4j}]],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='ptVgen', \n", - " ylabel=\"$A_4$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [\n", + " hist1D_ang_coeff[\"z\"][\"bugged\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " hist1D_ang_coeff[\"z\"][\"bugfix\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"ptVgen\",\n", + " ylabel=\"$A_4$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=rrange_opt,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [sigma_UL['z']['bugged'], \n", - " sigma_UL['z']['bugfix']],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='ptVgen', \n", - " ylabel=\"$\\sigma_{UL}$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=[0.95,1.05],\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [sigma_UL[\"z\"][\"bugged\"], sigma_UL[\"z\"][\"bugfix\"]],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"ptVgen\",\n", + " ylabel=\"$\\sigma_{UL}$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=[0.95, 1.05],\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hh.multiplyHists(hist1D_ang_coeff['z']['bugged']['ptVgen'][{\"helicity\":4j}], sigma_UL['z']['bugged'], allowBroadcast=True), \n", - " hh.multiplyHists(hist1D_ang_coeff['z']['bugfix']['ptVgen'][{\"helicity\":4j}], sigma_UL['z']['bugfix'], allowBroadcast=True)],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='ptVgen', \n", - " ylabel=\"$A_4 * \\sigma _{UL}$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)" + " [\n", + " hh.multiplyHists(\n", + " hist1D_ang_coeff[\"z\"][\"bugged\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " sigma_UL[\"z\"][\"bugged\"],\n", + " allowBroadcast=True,\n", + " ),\n", + " hh.multiplyHists(\n", + " hist1D_ang_coeff[\"z\"][\"bugfix\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " sigma_UL[\"z\"][\"bugfix\"],\n", + " allowBroadcast=True,\n", + " ),\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"ptVgen\",\n", + " ylabel=\"$A_4 * \\sigma _{UL}$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=rrange_opt,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")" ] }, { @@ -313,37 +407,57 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['wp']['bugged']['ptVgen'][{\"helicity\":4j}], \n", - " hist1D_ang_coeff['wp']['bugfix']['ptVgen'][{\"helicity\":4j}]],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='$p_T^{W^+}$', \n", - " ylabel=\"$A_4$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [\n", + " hist1D_ang_coeff[\"wp\"][\"bugged\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " hist1D_ang_coeff[\"wp\"][\"bugfix\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"$p_T^{W^+}$\",\n", + " ylabel=\"$A_4$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=rrange_opt,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [sigma_UL['wp']['bugged'], \n", - " sigma_UL['wp']['bugfix']],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='$p_T^{W^+}$', \n", - " ylabel=\"$\\sigma_{UL}$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=[0.95,1.05],\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [sigma_UL[\"wp\"][\"bugged\"], sigma_UL[\"wp\"][\"bugfix\"]],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"$p_T^{W^+}$\",\n", + " ylabel=\"$\\sigma_{UL}$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=[0.95, 1.05],\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hh.multiplyHists(hist1D_ang_coeff['wp']['bugged']['ptVgen'][{\"helicity\":4j}], sigma_UL['wp']['bugged'], allowBroadcast=True), \n", - " hh.multiplyHists(hist1D_ang_coeff['wp']['bugfix']['ptVgen'][{\"helicity\":4j}], sigma_UL['wp']['bugfix'], allowBroadcast=True)],\n", - " [\"bugged\", 'bugfix'], \n", - " colors=['black', 'red'], \n", - " xlabel='$p_T^{W^+}$', \n", - " ylabel=\"$A_4 * \\sigma _{UL}$\",\n", - " rlabel=\"bugfix/bugged\",\n", - " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)" + " [\n", + " hh.multiplyHists(\n", + " hist1D_ang_coeff[\"wp\"][\"bugged\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " sigma_UL[\"wp\"][\"bugged\"],\n", + " allowBroadcast=True,\n", + " ),\n", + " hh.multiplyHists(\n", + " hist1D_ang_coeff[\"wp\"][\"bugfix\"][\"ptVgen\"][{\"helicity\": 4j}],\n", + " sigma_UL[\"wp\"][\"bugfix\"],\n", + " allowBroadcast=True,\n", + " ),\n", + " ],\n", + " [\"bugged\", \"bugfix\"],\n", + " colors=[\"black\", \"red\"],\n", + " xlabel=\"$p_T^{W^+}$\",\n", + " ylabel=\"$A_4 * \\sigma _{UL}$\",\n", + " rlabel=\"bugfix/bugged\",\n", + " rrange=rrange_opt,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")" ] }, { @@ -357,36 +471,59 @@ " file_slc7 = pickle.load(f)\n", "hist_ang_coeff = {}\n", "sigma_UL = {}\n", - "boson_channels = ['wm']\n", - "projection_axes = ['ptVgen', 'absYVgen']\n", + "boson_channels = [\"wm\"]\n", + "projection_axes = [\"ptVgen\", \"absYVgen\"]\n", "for chn in boson_channels:\n", " hist_ang_coeff[chn] = {}\n", " sigma_UL[chn] = {}\n", "\n", "# read full histogram for angular coefficients\n", "\n", - "hist_ang_coeff['wm']['bugged' ] = file_slc7['WminusmunuPostVFP' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['wm']['bugfix' ] = file_slc7['WminusmunuPostVFP_bugfix' ]['output']['helicity_moments_scale']\n", - "hist_ang_coeff['wm']['bugfix_slc7'] = file_slc7['WminusmunuPostVFP_bugfix_slc7']['output']['helicity_moments_scale']\n", - "\n", + "hist_ang_coeff[\"wm\"][\"bugged\"] = file_slc7[\"WminusmunuPostVFP\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"wm\"][\"bugfix\"] = file_slc7[\"WminusmunuPostVFP_bugfix\"][\"output\"][\n", + " \"helicity_moments_scale\"\n", + "]\n", + "hist_ang_coeff[\"wm\"][\"bugfix_slc7\"] = file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\n", + " \"output\"\n", + "][\"helicity_moments_scale\"]\n", "\n", "\n", - "sigma_UL['wm']['bugged' ] = (file_slc7['WminusmunuPostVFP' ]['output']['nominal_gen']* file_slc7[\"WminusmunuPostVFP\" ][\"dataset\"][\"xsec\"] / file_slc7[\"WminusmunuPostVFP\" ][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['wm']['bugfix' ] = (file_slc7['WminusmunuPostVFP_bugfix' ]['output']['nominal_gen']* file_slc7[\"WminusmunuPostVFP_bugfix\" ][\"dataset\"][\"xsec\"] / file_slc7[\"WminusmunuPostVFP_bugfix\" ][\"weight_sum\"]).project('ptVgen')\n", - "sigma_UL['wm']['bugfix_slc7'] = (file_slc7['WminusmunuPostVFP_bugfix_slc7']['output']['nominal_gen']* file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\"dataset\"][\"xsec\"] / file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\"weight_sum\"]).project('ptVgen')\n", + "sigma_UL[\"wm\"][\"bugged\"] = (\n", + " file_slc7[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * file_slc7[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / file_slc7[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"wm\"][\"bugfix\"] = (\n", + " file_slc7[\"WminusmunuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"]\n", + " * file_slc7[\"WminusmunuPostVFP_bugfix\"][\"dataset\"][\"xsec\"]\n", + " / file_slc7[\"WminusmunuPostVFP_bugfix\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", + "sigma_UL[\"wm\"][\"bugfix_slc7\"] = (\n", + " file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\"output\"][\"nominal_gen\"]\n", + " * file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\"dataset\"][\"xsec\"]\n", + " / file_slc7[\"WminusmunuPostVFP_bugfix_slc7\"][\"weight_sum\"]\n", + ").project(\"ptVgen\")\n", "\n", - "# make projected 1D histograms; \"normalize\" and calculate the angular coefficients \n", + "# make projected 1D histograms; \"normalize\" and calculate the angular coefficients\n", "hist1D_ang_coeff = {}\n", "s = hist.tag.Slicer()\n", "for chn in boson_channels:\n", " hist1D_ang_coeff[chn] = {}\n", - " for group in ['bugged', 'bugfix', 'bugfix_slc7']:\n", + " for group in [\"bugged\", \"bugfix\", \"bugfix_slc7\"]:\n", " hist1D_ang_coeff[chn][group] = {}\n", " for ax in projection_axes:\n", - " if chn == 'z':\n", - " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(hist_ang_coeff[chn][group][{'massVgen':s[80j:100j:hist.sum]}].project('helicity',ax))\n", + " if chn == \"z\":\n", + " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(\n", + " hist_ang_coeff[chn][group][\n", + " {\"massVgen\": s[80j : 100j : hist.sum]}\n", + " ].project(\"helicity\", ax)\n", + " )\n", " else:\n", - " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(hist_ang_coeff[chn][group].project('helicity',ax))\n" + " hist1D_ang_coeff[chn][group][ax] = wremnants.moments_to_angular_coeffs(\n", + " hist_ang_coeff[chn][group].project(\"helicity\", ax)\n", + " )" ] }, { @@ -398,28 +535,35 @@ "source": [ "rrange_opt = None\n", "\n", - "for idx_ang in range(-1,8):\n", + "for idx_ang in range(-1, 8):\n", " if idx_ang == -1:\n", " ang_name = \"Const_term\"\n", " else:\n", " ang_name = f\"A_{idx_ang}\"\n", - " \n", - " rrange_opt = [0.9,1.1]\n", + "\n", + " rrange_opt = [0.9, 1.1]\n", " if idx_ang == 0:\n", - " rrange_opt = [0.8,1.2]\n", + " rrange_opt = [0.8, 1.2]\n", "\n", " for idx_ax, ax in enumerate(projection_axes):\n", " fig_wm = plot_tools.makePlotWithRatioToRef(\n", - " [hist1D_ang_coeff['wm']['bugged'][ax][{\"helicity\":hist.loc(idx_ang)}], \n", - " hist1D_ang_coeff['wm']['bugfix'][ax][{\"helicity\":hist.loc(idx_ang)}],\n", - " hist1D_ang_coeff['wm']['bugfix_slc7'][ax][{\"helicity\":hist.loc(idx_ang)}]], \n", - " [\"bugged\", 'bugfix', 'bugfix_slc7'], \n", - " colors=['black', 'red', 'green'], \n", - " xlabel=ax, \n", + " [\n", + " hist1D_ang_coeff[\"wm\"][\"bugged\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " hist1D_ang_coeff[\"wm\"][\"bugfix\"][ax][{\"helicity\": hist.loc(idx_ang)}],\n", + " hist1D_ang_coeff[\"wm\"][\"bugfix_slc7\"][ax][\n", + " {\"helicity\": hist.loc(idx_ang)}\n", + " ],\n", + " ],\n", + " [\"bugged\", \"bugfix\", \"bugfix_slc7\"],\n", + " colors=[\"black\", \"red\", \"green\"],\n", + " xlabel=ax,\n", " ylabel=\"Events/bin\",\n", " rlabel=\"bugfixes/bugged\",\n", " rrange=rrange_opt,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", "\n", " fig_wm.savefig(f\"ang_coeff-{ang_name}-{ax}-wm.pdf\")\n", " fig_wm.savefig(f\"ang_coeff-{ang_name}-{ax}-wm.png\")" diff --git a/notebooks/bestPlot.ipynb b/notebooks/bestPlot.ipynb index d65831925..57ce65d9c 100644 --- a/notebooks/bestPlot.ipynb +++ b/notebooks/bestPlot.ipynb @@ -17,7 +17,9 @@ "metadata": {}, "outputs": [], "source": [ - "f = ROOT.TFile(\"/scratch/submit/cms/kdlong/CombineStudies/WMass_eta_pt_charge_statOnly_root/WMassCombineInput.root\")" + "f = ROOT.TFile(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/WMass_eta_pt_charge_statOnly_root/WMassCombineInput.root\"\n", + ")" ] }, { diff --git a/notebooks/closureFakes.ipynb b/notebooks/closureFakes.ipynb index b5934e4a5..73525a585 100644 --- a/notebooks/closureFakes.ipynb +++ b/notebooks/closureFakes.ipynb @@ -34,7 +34,9 @@ "metadata": {}, "outputs": [], "source": [ - "output_dir = \"/eos/home-d/dwalter/www/WMassAnalysis/240119_closure_fakes/dPhiMuonMetCut/QCDPt5\"" + "output_dir = (\n", + " \"/eos/home-d/dwalter/www/WMassAnalysis/240119_closure_fakes/dPhiMuonMetCut/QCDPt5\"\n", + ")" ] }, { @@ -45,9 +47,9 @@ "outputs": [], "source": [ "def load(name, ptMuon=5):\n", - " if name==\"\":\n", + " if name == \"\":\n", " h = input_tools.load_and_scale(res, f\"QCDmuEnrichPt15PostVFP\", histname)\n", - " else: \n", + " else:\n", " h = input_tools.load_and_scale(res2, f\"QCDPt{name}muEnrichPt5PostVFP\", histname)\n", " return h" ] @@ -97,7 +99,7 @@ "outputs": [], "source": [ "histograms2 = \"/scratch/dwalter/results_histmaker/240119_AllQCDMC/mw_with_mu_eta_pt_dPhiMuonMetCut.hdf5\"\n", - "histname = \"nominal\" #histname\n", + "histname = \"nominal\" # histname\n", "res2, meta2, _ = input_tools.read_infile(histograms2)\n", "\n", "hQCD15To20 = load(\"15To20\")\n", @@ -121,7 +123,7 @@ "metadata": {}, "outputs": [], "source": [ - "hQCDFake = sel.fakeHistABCD(hQCD)#, fakerate_integration_axes=[\"eta\"])\n", + "hQCDFake = sel.fakeHistABCD(hQCD) # , fakerate_integration_axes=[\"eta\"])\n", "hQCDSig = sel.signalHistWmass(hQCD)" ] }, @@ -145,6 +147,7 @@ "source": [ "from scipy.optimize import curve_fit\n", "\n", + "\n", "def exp_fall(x, a, b, c):\n", " return a * np.exp(-b * x) + c" ] @@ -156,68 +159,105 @@ "metadata": {}, "outputs": [], "source": [ - "def plot(hss, labels, linestyles=None, h1ds_nom=None, ratio=True, flow=False, showFlow=False, vars=[\"pt\"], name=\"\", \n", - " fit=True, variances=False, uncertainty_bands=True):\n", + "def plot(\n", + " hss,\n", + " labels,\n", + " linestyles=None,\n", + " h1ds_nom=None,\n", + " ratio=True,\n", + " flow=False,\n", + " showFlow=False,\n", + " vars=[\"pt\"],\n", + " name=\"\",\n", + " fit=True,\n", + " variances=False,\n", + " uncertainty_bands=True,\n", + "):\n", "\n", " if linestyles is None:\n", - " linestyles = [\"-\"]*len(labels)\n", - " \n", + " linestyles = [\"-\"] * len(labels)\n", + "\n", " if h1ds_nom is not None:\n", " hs = [*hss, *h1ds_nom]\n", - " hr = [*[hh.divideHists(h1d, hss[0]) for h1d in hss], *[hh.divideHists(h1d, h1ds_nom[0]) for h1d in h1ds_nom]]\n", + " hr = [\n", + " *[hh.divideHists(h1d, hss[0]) for h1d in hss],\n", + " *[hh.divideHists(h1d, h1ds_nom[0]) for h1d in h1ds_nom],\n", + " ]\n", " else:\n", " hs = hss\n", " hr = [hh.divideHists(h1d, hss[0]) for h1d in hss]\n", "\n", " if variances:\n", - " ratio=False\n", + " ratio = False\n", " for h in hs:\n", - " h.values(flow=True)[...] = np.sqrt(h.variances(flow=True))/h.values(flow=True)\n", - " h.variances(flow=True)[...] = np.zeros(h.values(flow=True).shape).astype(int)\n", + " h.values(flow=True)[...] = np.sqrt(h.variances(flow=True)) / h.values(\n", + " flow=True\n", + " )\n", + " h.variances(flow=True)[...] = np.zeros(h.values(flow=True).shape).astype(\n", + " int\n", + " )\n", " for h in hr:\n", - " h.values(flow=True)[...] = np.sqrt(h.variances(flow=True))/h.values(flow=True)\n", - " h.variances(flow=True)[...] = np.zeros(h.values(flow=True).shape).astype(int)\n", - "\n", - " ylabel=\"a.u.\"\n", + " h.values(flow=True)[...] = np.sqrt(h.variances(flow=True)) / h.values(\n", + " flow=True\n", + " )\n", + " h.variances(flow=True)[...] = np.zeros(h.values(flow=True).shape).astype(\n", + " int\n", + " )\n", + "\n", + " ylabel = \"a.u.\"\n", " if variances:\n", - " ylabel=\"Rel. uncertainty\"\n", - " \n", + " ylabel = \"Rel. uncertainty\"\n", + "\n", " ymin = 0\n", " ymax = None\n", "\n", " ymax = ymax if ymax is not None else max([max(h.values(flow=showFlow)) for h in hs])\n", " ymin = ymin if ymin is not None else min([min(h.values(flow=showFlow)) for h in hs])\n", " yrange = ymax - ymin\n", - " ymin = ymin if ymin == 0 else ymin - yrange*0.3\n", - " ymax = ymax + yrange*0.3\n", + " ymin = ymin if ymin == 0 else ymin - yrange * 0.3\n", + " ymax = ymax + yrange * 0.3\n", "\n", " if ratio:\n", - " fig, ax1, ax2 = plot_tools.figureWithRatio(hss[0], xlabel=f\"{'-'.join(vars)} Bin\", ylabel=ylabel,\n", - " rlabel=\"1./nominal\", rrange=(0.25, 1.75), cms_label=\"Preliminary\",\n", - " automatic_scale=False, width_scale=1.2, ylim=(ymin, ymax))\n", + " fig, ax1, ax2 = plot_tools.figureWithRatio(\n", + " hss[0],\n", + " xlabel=f\"{'-'.join(vars)} Bin\",\n", + " ylabel=ylabel,\n", + " rlabel=\"1./nominal\",\n", + " rrange=(0.25, 1.75),\n", + " cms_label=\"Preliminary\",\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", + " ylim=(ymin, ymax),\n", + " )\n", " else:\n", - " fig, ax1 = plot_tools.figure(hss[0], xlabel=f\"{'-'.join(vars)} Bin\", ylabel=ylabel,\n", - " cms_label=\"Preliminary\",\n", - " automatic_scale=False, width_scale=1.2, ylim=(ymin, ymax))\n", - " \n", + " fig, ax1 = plot_tools.figure(\n", + " hss[0],\n", + " xlabel=f\"{'-'.join(vars)} Bin\",\n", + " ylabel=ylabel,\n", + " cms_label=\"Preliminary\",\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", + " ylim=(ymin, ymax),\n", + " )\n", + "\n", " hep.histplot(\n", " hs,\n", - " histtype = \"step\",\n", - " color = [colors(i) for i in range(len(hss))],\n", - " label = labels[:len(hs)],\n", - " linestyle = linestyles[:len(hs)],\n", - " ax = ax1\n", + " histtype=\"step\",\n", + " color=[colors(i) for i in range(len(hss))],\n", + " label=labels[: len(hs)],\n", + " linestyle=linestyles[: len(hs)],\n", + " ax=ax1,\n", " )\n", "\n", " if ratio:\n", " hep.histplot(\n", " hr,\n", " yerr=False,\n", - " histtype = \"step\",\n", - " color = [colors(i) for i in range(len(hss))],\n", - " label = labels[:len(hs)],\n", - " linestyle = linestyles[:len(hs)],\n", - " ax = ax2\n", + " histtype=\"step\",\n", + " color=[colors(i) for i in range(len(hss))],\n", + " label=labels[: len(hs)],\n", + " linestyle=linestyles[: len(hs)],\n", + " ax=ax2,\n", " )\n", "\n", " if fit:\n", @@ -234,7 +274,17 @@ "\n", " ax1.plot(x, y_fit, linestyle=\"--\", color=colors(i))\n", " if uncertainty_bands:\n", - " ax1.bar(x=xedges[:-1], height=2*y_err, bottom=y_fit - y_err, width=np.diff(xedges), align='edge', linewidth=0, alpha=0.3, color=colors(i), zorder=-1)\n", + " ax1.bar(\n", + " x=xedges[:-1],\n", + " height=2 * y_err,\n", + " bottom=y_fit - y_err,\n", + " width=np.diff(xedges),\n", + " align=\"edge\",\n", + " linewidth=0,\n", + " alpha=0.3,\n", + " color=colors(i),\n", + " zorder=-1,\n", + " )\n", "\n", " # if i==0:\n", " # y_fit0 = y_fit\n", @@ -242,9 +292,15 @@ " # ax2.plot(x, y_fit/y_fit0, linestyle=\"--, color=colors(i))\n", "\n", " if ratio:\n", - " ax2.plot(x, y/y_fit, linewidth=0, linestyle=None, marker=\"o\", color=colors(i))\n", - " \n", - " \n", + " ax2.plot(\n", + " x,\n", + " y / y_fit,\n", + " linewidth=0,\n", + " linestyle=None,\n", + " marker=\"o\",\n", + " color=colors(i),\n", + " )\n", + "\n", " # ax.fill_between(x, y - err, y + err, alpha=0.3, color=colors(i), step=\"post\")\n", "\n", " # ax.text(1.0, 1.003, text_dict[base_process], transform=ax.transAxes, fontsize=30,\n", @@ -298,15 +354,39 @@ } ], "source": [ - "hists = [hQCD15To20, hQCD20To30, hQCD30To50, hQCD50To80, hQCD80To120, hQCD120To170, \n", - " hQCD170To300, hQCD300To470, hQCD470To600, hQCD600To800, hQCD800To1000, hQCD1000]\n", - "labels = [\"hQCD15To20\", \"hQCD20To30\", \"hQCD30To50\", \"hQCD50To80\", \"hQCD80To120\", \"hQCD120To17\", \n", - " \"hQCD170To300\", \"hQCD300To470\", \"hQCD470To600\", \"hQCD600To800\", \"hQCD800To1000\", \"hQCD1000\"]\n", - "\n", - "hists_sum = hh.sumHists(hists)#.project(\"pt\")\n", - "\n", - "\n", - "hist_sumall = hh.sumHists([*hists, hQCD])#.project(\"pt\")\n", + "hists = [\n", + " hQCD15To20,\n", + " hQCD20To30,\n", + " hQCD30To50,\n", + " hQCD50To80,\n", + " hQCD80To120,\n", + " hQCD120To170,\n", + " hQCD170To300,\n", + " hQCD300To470,\n", + " hQCD470To600,\n", + " hQCD600To800,\n", + " hQCD800To1000,\n", + " hQCD1000,\n", + "]\n", + "labels = [\n", + " \"hQCD15To20\",\n", + " \"hQCD20To30\",\n", + " \"hQCD30To50\",\n", + " \"hQCD50To80\",\n", + " \"hQCD80To120\",\n", + " \"hQCD120To17\",\n", + " \"hQCD170To300\",\n", + " \"hQCD300To470\",\n", + " \"hQCD470To600\",\n", + " \"hQCD600To800\",\n", + " \"hQCD800To1000\",\n", + " \"hQCD1000\",\n", + "]\n", + "\n", + "hists_sum = hh.sumHists(hists) # .project(\"pt\")\n", + "\n", + "\n", + "hist_sumall = hh.sumHists([*hists, hQCD]) # .project(\"pt\")\n", "hQCD = hh.scaleHist(hist_sumall, 0.5)\n", "print(f\"Sum(all) = {hist_sumall.sum()}\")\n", "\n", @@ -364,8 +444,16 @@ "hQCDFake_ptq = hQCDFake.project(\"pt\", \"charge\")\n", "hQCDSig_ptq = hQCDSig.project(\"pt\", \"charge\")\n", "\n", - "hratio = plot([hQCDFake_ptq[{\"charge\":0}], hQCDSig_ptq[{\"charge\":0}]], labels=[\"C*B/A\", \"D\"], name=\"QCD_minus\")\n", - "hratio = plot([hQCDFake_ptq[{\"charge\":1}], hQCDSig_ptq[{\"charge\":1}]], labels=[\"C*B/A\", \"D\"], name=\"QCD_plus\")\n", + "hratio = plot(\n", + " [hQCDFake_ptq[{\"charge\": 0}], hQCDSig_ptq[{\"charge\": 0}]],\n", + " labels=[\"C*B/A\", \"D\"],\n", + " name=\"QCD_minus\",\n", + ")\n", + "hratio = plot(\n", + " [hQCDFake_ptq[{\"charge\": 1}], hQCDSig_ptq[{\"charge\": 1}]],\n", + " labels=[\"C*B/A\", \"D\"],\n", + " name=\"QCD_plus\",\n", + ")\n", "\n", "hratio = plot([hQCDFake_pt, hQCDSig_pt], labels=[\"C*B/A\", \"D\"], name=\"QCD\")\n", "hratio[1].values()" @@ -440,23 +528,23 @@ ], "source": [ "# plot fakes in each region separately\n", - "for idx_x in (0,1):\n", - " idx_eta=0\n", - " hQCD_D = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":1}]\n", - " hQCD_B = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":0}]\n", - " hQCD_C = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":1}]\n", - " hQCD_A = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":0}]\n", + "for idx_x in (0, 1):\n", + " idx_eta = 0\n", + " hQCD_D = hQCD[{\"charge\": idx_c, \"passIso\": 1, \"passMT\": 1}]\n", + " hQCD_B = hQCD[{\"charge\": idx_c, \"passIso\": 1, \"passMT\": 0}]\n", + " hQCD_C = hQCD[{\"charge\": idx_c, \"passIso\": 0, \"passMT\": 1}]\n", + " hQCD_A = hQCD[{\"charge\": idx_c, \"passIso\": 0, \"passMT\": 0}]\n", "\n", " hQCD_A_pt = hQCD_A.project(\"pt\")\n", " hQCD_B_pt = hQCD_B.project(\"pt\")\n", " hQCD_C_pt = hQCD_C.project(\"pt\")\n", " hQCD_D_pt = hQCD_D.project(\"pt\")\n", - " \n", + "\n", " # hQCDFake_BA_pt = hh.divideHists(hQCD_B,hQCD_A).project(\"pt\")\n", " # hQCDFake_CBA_pt = hh.multiplyHists(hQCD_C,hh.divideHists(hQCD_B,hQCD_A)).project(\"pt\")\n", - " \n", + "\n", " # plot([hQCD_A_pt, hQCD_B_pt, hQCD_C_pt, hQCD_D_pt], labels=[\"A\", \"B\", \"C\", \"D\"], name=f\"QCD_q{idx_c}\", ratio=True)\n", - " \n", + "\n", " # plot([hQCD_A_pt], labels=[\"A\"], name=f\"QCD_A_q{idx_c}\", ratio=True)\n", " # plot([hQCD_B_pt], labels=[\"B\"], name=f\"QCD_B_q{idx_c}\", ratio=True)\n", " # plot([hQCD_C_pt], labels=[\"C\"], name=f\"QCD_C_q{idx_c}\", ratio=True)\n", @@ -464,7 +552,7 @@ "\n", " def set(h):\n", " vals = sel.fit_multijet_bkg(h)\n", - " h.view()[...] = np.array([(v.n,v.s**2) for v in vals])\n", + " h.view()[...] = np.array([(v.n, v.s**2) for v in vals])\n", "\n", " set(hQCD_A_pt)\n", " set(hQCD_B_pt)\n", @@ -480,9 +568,16 @@ " hQCD_CBA = hh.multiplyHists(hQCD_C_pt, hQCD_FR)\n", " hQCD_DCBA = hh.divideHists(hQCD_D_pt, hQCD_CBA)\n", " plot([hQCD_FR], labels=[\"FR\"], name=f\"FR_q{idx_c}_smooth\", ratio=True, fit=False)\n", - " plot([hQCD_CBA], labels=[\"C*FR\"], name=f\"CFR_q{idx_c}_smooth\", ratio=True, fit=False)\n", - " plot([hQCD_DCBA], labels=[\"D/C*FR\"], name=f\"DCFR_q{idx_c}_smooth\", ratio=True, fit=False)\n", - "\n" + " plot(\n", + " [hQCD_CBA], labels=[\"C*FR\"], name=f\"CFR_q{idx_c}_smooth\", ratio=True, fit=False\n", + " )\n", + " plot(\n", + " [hQCD_DCBA],\n", + " labels=[\"D/C*FR\"],\n", + " name=f\"DCFR_q{idx_c}_smooth\",\n", + " ratio=True,\n", + " fit=False,\n", + " )" ] }, { @@ -493,11 +588,11 @@ "outputs": [], "source": [ "# plot fakes in each region separately\n", - "idx_c=0\n", - "hQCD_D = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":1}]\n", - "hQCD_B = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":0}]\n", - "hQCD_C = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":1}]\n", - "hQCD_A = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":0}]\n", + "idx_c = 0\n", + "hQCD_D = hQCD[{\"charge\": idx_c, \"passIso\": 1, \"passMT\": 1}]\n", + "hQCD_B = hQCD[{\"charge\": idx_c, \"passIso\": 1, \"passMT\": 0}]\n", + "hQCD_C = hQCD[{\"charge\": idx_c, \"passIso\": 0, \"passMT\": 1}]\n", + "hQCD_A = hQCD[{\"charge\": idx_c, \"passIso\": 0, \"passMT\": 0}]\n", "\n", "hQCD_A_pt = hQCD_A.project(\"pt\")\n", "hQCD_B_pt = hQCD_B.project(\"pt\")\n", @@ -536,10 +631,15 @@ } ], "source": [ - "hQCDFake_BA_pt = hh.divideHists(hQCD_B,hQCD_A).project(\"pt\")\n", - "hQCDFake_CBA_pt = hh.multiplyHists(hQCD_C,hh.divideHists(hQCD_B,hQCD_A)).project(\"pt\")\n", - "\n", - "plot([hQCD_D_pt, hQCD_A_pt, hQCD_B_pt, hQCD_C_pt], labels=[\"D\", \"A\", \"B\", \"C\"], name=\"QCD\", ratio=True)" + "hQCDFake_BA_pt = hh.divideHists(hQCD_B, hQCD_A).project(\"pt\")\n", + "hQCDFake_CBA_pt = hh.multiplyHists(hQCD_C, hh.divideHists(hQCD_B, hQCD_A)).project(\"pt\")\n", + "\n", + "plot(\n", + " [hQCD_D_pt, hQCD_A_pt, hQCD_B_pt, hQCD_C_pt],\n", + " labels=[\"D\", \"A\", \"B\", \"C\"],\n", + " name=\"QCD\",\n", + " ratio=True,\n", + ")" ] }, { @@ -573,10 +673,16 @@ ], "source": [ "# compute fakes via ABCD directly here, not using wremnants functions, check numerical stability\n", - "hQCDFake_v1_pt = hh.multiplyHists(hQCD_C_pt,hh.divideHists(hQCD_B_pt,hQCD_A_pt))\n", - "hQCDFake_v2_pt = hh.divideHists(hh.multiplyHists(hQCD_C_pt,hQCD_B_pt),hQCD_A_pt)\n", - "\n", - "plot([hQCD_D_pt, hQCDFake_v1_pt, hQCDFake_v2_pt], labels=[\"D\", \"C*B/A v1\", \"C*B/A v2\"], name=\"QCD\", fit=False, linestyles=[\"-\",\"--\", \":\"])" + "hQCDFake_v1_pt = hh.multiplyHists(hQCD_C_pt, hh.divideHists(hQCD_B_pt, hQCD_A_pt))\n", + "hQCDFake_v2_pt = hh.divideHists(hh.multiplyHists(hQCD_C_pt, hQCD_B_pt), hQCD_A_pt)\n", + "\n", + "plot(\n", + " [hQCD_D_pt, hQCDFake_v1_pt, hQCDFake_v2_pt],\n", + " labels=[\"D\", \"C*B/A v1\", \"C*B/A v2\"],\n", + " name=\"QCD\",\n", + " fit=False,\n", + " linestyles=[\"-\", \"--\", \":\"],\n", + ")" ] }, { @@ -587,7 +693,9 @@ "outputs": [], "source": [ "import hist\n", - "def unrolledHist(h, obs=['pt', 'eta']):\n", + "\n", + "\n", + "def unrolledHist(h, obs=[\"pt\", \"eta\"]):\n", " bins = np.multiply(*[len(a) for a in h.axes if a.name in obs])\n", " newh = hist.Hist(hist.axis.Regular(bins, 0, bins), storage=h.storage_type())\n", " newh[...] = np.ravel(h.project(*obs))\n", @@ -633,16 +741,22 @@ } ], "source": [ - "vars = [\"pt\",\"eta\"]\n", - "h1ds = [unrolledHist(h, obs=vars) if len(vars) > 1 else h.project(*vars) for h in [hQCDFake, hQCDSig]]\n", + "vars = [\"pt\", \"eta\"]\n", + "h1ds = [\n", + " unrolledHist(h, obs=vars) if len(vars) > 1 else h.project(*vars)\n", + " for h in [hQCDFake, hQCDSig]\n", + "]\n", "plot(h1ds, [\"C*B/A\", \"D\"], name=\"QCD_pt_eta\", fit=False, vars=vars)\n", "\n", "hQCD_DC = hh.divideHists(hQCD_D, hQCD_C)\n", "hQCD_BA = hh.divideHists(hQCD_B, hQCD_A)\n", "\n", - "h1ds = [unrolledHist(h, obs=vars) if len(vars) > 1 else h.project(*vars) for h in [hQCD_DC, hQCD_BA]]\n", + "h1ds = [\n", + " unrolledHist(h, obs=vars) if len(vars) > 1 else h.project(*vars)\n", + " for h in [hQCD_DC, hQCD_BA]\n", + "]\n", "\n", - "plot(h1ds, [\"D/C\", \"B/A\"], name=\"QCD_pt_eta_ratios\", fit=False, vars=vars)\n" + "plot(h1ds, [\"D/C\", \"B/A\"], name=\"QCD_pt_eta_ratios\", fit=False, vars=vars)" ] }, { @@ -655,16 +769,32 @@ "def project(flow=False):\n", " # average over bins\n", " if flow:\n", - " return lambda h, axes: h.project(*axes)/np.prod([a.extent for a in h.axes if a.name not in axes])\n", + " return lambda h, axes: h.project(*axes) / np.prod(\n", + " [a.extent for a in h.axes if a.name not in axes]\n", + " )\n", " else:\n", - " return lambda h, axes: hh.projectNoFlow(h, axes)/np.prod([a.size for a in h.axes if a.name not in axes])\n", + " return lambda h, axes: hh.projectNoFlow(h, axes) / np.prod(\n", + " [a.size for a in h.axes if a.name not in axes]\n", + " )\n", + "\n", + "\n", + "def make_plot_2d(\n", + " h,\n", + " name,\n", + " proc,\n", + " axes,\n", + " corr=None,\n", + " plot_error=False,\n", + " clim=None,\n", + " flow=False,\n", + " density=False,\n", + " log=False,\n", + "):\n", "\n", - "def make_plot_2d(h, name, proc, axes, corr=None, plot_error=False, clim=None, flow=False, density=False, log=False):\n", - " \n", " h2d = project(flow)(h, axes)\n", "\n", - " xlabel = styles.axis_labels.get(axes[0],axes[0])\n", - " ylabel = styles.axis_labels.get(axes[1],axes[1])\n", + " xlabel = styles.axis_labels.get(axes[0], axes[0])\n", + " ylabel = styles.axis_labels.get(axes[1], axes[1])\n", "\n", " if flow:\n", " xedges, yedges = plot_tools.extendEdgesByFlow(h2d)\n", @@ -676,47 +806,82 @@ " if density:\n", " xbinwidths = np.diff(xedges)\n", " ybinwidths = np.diff(yedges)\n", - " binwidths = np.outer(xbinwidths, ybinwidths) \n", + " binwidths = np.outer(xbinwidths, ybinwidths)\n", " h2d.values(flow=flow)[...] = h2d.values(flow=flow) / binwidths\n", "\n", " if plot_error:\n", " # plot relative errors instead\n", - " h2d.values(flow=flow)[...] = np.sqrt(hh.relVariance(h2d.values(flow=flow), h2d.variances(flow=flow), fillOnes=True))\n", + " h2d.values(flow=flow)[...] = np.sqrt(\n", + " hh.relVariance(\n", + " h2d.values(flow=flow), h2d.variances(flow=flow), fillOnes=True\n", + " )\n", + " )\n", "\n", " # if args.xlim[0] is None:\n", - " xlim = (xedges[0],xedges[-1])\n", + " xlim = (xedges[0], xedges[-1])\n", " # else:\n", " # xlim = args.xlim\n", "\n", " # if args.ylim[0] is None:\n", - " ylim = (yedges[0],yedges[-1])\n", + " ylim = (yedges[0], yedges[-1])\n", " # else:\n", " # ylim = args.ylim\n", "\n", - " fig, ax = plot_tools.figure(h2d, xlabel=xlabel, ylabel=ylabel, cms_label=\"Work in progress\", automatic_scale=False, width_scale=1.2, xlim=xlim, ylim=ylim)\n", + " fig, ax = plot_tools.figure(\n", + " h2d,\n", + " xlabel=xlabel,\n", + " ylabel=ylabel,\n", + " cms_label=\"Work in progress\",\n", + " automatic_scale=False,\n", + " width_scale=1.2,\n", + " xlim=xlim,\n", + " ylim=ylim,\n", + " )\n", "\n", " if clim is None:\n", " if log:\n", - " cmin = min(h2d.values(flow=flow)[h2d.values(flow=flow)>0]) # smallest value that is not 0\n", + " cmin = min(\n", + " h2d.values(flow=flow)[h2d.values(flow=flow) > 0]\n", + " ) # smallest value that is not 0\n", " cmax = h2d.values(flow=flow).max()\n", " else:\n", - " cmin = max(0.95,h2d.values(flow=flow).min())\n", - " cmax = min(1.05,h2d.values(flow=flow).max())\n", + " cmin = max(0.95, h2d.values(flow=flow).min())\n", + " cmax = min(1.05, h2d.values(flow=flow).max())\n", " # make symmetric range\n", - " crange = max((cmax-1), (1-cmin))\n", - " clim = [max(0.95,1-crange), min(1.05,1+crange)]\n", + " crange = max((cmax - 1), (1 - cmin))\n", + " clim = [max(0.95, 1 - crange), min(1.05, 1 + crange)]\n", " else:\n", " # colormesh = ax.pcolormesh(xedges, yedges, h2d.values(flow=flow).T, norm=LogNorm(vmin=clim[0], vmax=clim[1]), cmap=cm.RdBu)\n", "\n", " if log:\n", - " colormesh = ax.pcolormesh(xedges, yedges, h2d.values(flow=flow).T, cmap=cm.RdBu, norm=LogNorm(vmin=clim[0], vmax=clim[1]))\n", + " colormesh = ax.pcolormesh(\n", + " xedges,\n", + " yedges,\n", + " h2d.values(flow=flow).T,\n", + " cmap=cm.RdBu,\n", + " norm=LogNorm(vmin=clim[0], vmax=clim[1]),\n", + " )\n", " else:\n", - " colormesh = ax.pcolormesh(xedges, yedges, h2d.values(flow=flow).T, cmap=cm.RdBu, vmin=clim[0], vmax=clim[1])\n", + " colormesh = ax.pcolormesh(\n", + " xedges,\n", + " yedges,\n", + " h2d.values(flow=flow).T,\n", + " cmap=cm.RdBu,\n", + " vmin=clim[0],\n", + " vmax=clim[1],\n", + " )\n", "\n", " cbar = fig.colorbar(colormesh, ax=ax)\n", "\n", - " ax.text(1.0, 1.003, styles.text_dict.get(proc, proc), transform=ax.transAxes, fontsize=30,\n", - " verticalalignment='bottom', horizontalalignment=\"right\")\n", + " ax.text(\n", + " 1.0,\n", + " 1.003,\n", + " styles.text_dict.get(proc, proc),\n", + " transform=ax.transAxes,\n", + " fontsize=30,\n", + " verticalalignment=\"bottom\",\n", + " horizontalalignment=\"right\",\n", + " )\n", "\n", " # outfile = f\"hist2d_{'_'.join(axes)}_{proc}_{name}\"\n", " # if corr:\n", @@ -755,20 +920,20 @@ "source": [ "# compute nonclosure in 3D (eta-pt-charge)\n", "hQCD1 = hh.makeAbsHist(hQCD, \"eta\", rename=False)\n", - "hQCD1 = hQCD1[{\"pt\":hist.rebin(4), \"eta\":hist.rebin(8)}]\n", + "hQCD1 = hQCD1[{\"pt\": hist.rebin(4), \"eta\": hist.rebin(8)}]\n", "\n", - "hQCD_D = hQCD1[{\"passIso\":1,\"passMT\":1}]\n", - "hQCD_B = hQCD1[{\"passIso\":1,\"passMT\":0}]\n", - "hQCD_C = hQCD1[{\"passIso\":0,\"passMT\":1}]\n", - "hQCD_A = hQCD1[{\"passIso\":0,\"passMT\":0}]\n", + "hQCD_D = hQCD1[{\"passIso\": 1, \"passMT\": 1}]\n", + "hQCD_B = hQCD1[{\"passIso\": 1, \"passMT\": 0}]\n", + "hQCD_C = hQCD1[{\"passIso\": 0, \"passMT\": 1}]\n", + "hQCD_A = hQCD1[{\"passIso\": 0, \"passMT\": 0}]\n", "\n", - "print((hQCD1.values()==0).sum())\n", + "print((hQCD1.values() == 0).sum())\n", "\n", "hQCDFake = sel.fakeHistABCD(hQCD1, fakerate_integration_axes=[\"charge\"])\n", "hQCDSig = sel.signalHistWmass(hQCD1)\n", "\n", "hQCDClosure = hh.divideHists(hQCDFake, hQCDSig)\n", - "make_plot_2d(hQCDClosure, \"QCD\", \"QCD\", [\"pt\",\"eta\"],clim=(0,2))" + "make_plot_2d(hQCDClosure, \"QCD\", \"QCD\", [\"pt\", \"eta\"], clim=(0, 2))" ] }, { @@ -789,8 +954,8 @@ } ], "source": [ - "hQCDClosure = hh.divideHists(hQCDFake[{\"charge\":0}], hQCDSig[{\"charge\":0}])\n", - "make_plot_2d(hQCDClosure, \"QCD_minus\", \"$QCD^{-}$\", [\"pt\",\"eta\"],clim=(0.1,1.9))" + "hQCDClosure = hh.divideHists(hQCDFake[{\"charge\": 0}], hQCDSig[{\"charge\": 0}])\n", + "make_plot_2d(hQCDClosure, \"QCD_minus\", \"$QCD^{-}$\", [\"pt\", \"eta\"], clim=(0.1, 1.9))" ] }, { @@ -811,8 +976,8 @@ } ], "source": [ - "hQCDClosure = hh.divideHists(hQCDFake[{\"charge\":1}], hQCDSig[{\"charge\":1}])\n", - "make_plot_2d(hQCDClosure, \"QCD_plus\", \"$QCD^{+}$\", [\"pt\",\"eta\"],clim=(0.1,1.9))" + "hQCDClosure = hh.divideHists(hQCDFake[{\"charge\": 1}], hQCDSig[{\"charge\": 1}])\n", + "make_plot_2d(hQCDClosure, \"QCD_plus\", \"$QCD^{+}$\", [\"pt\", \"eta\"], clim=(0.1, 1.9))" ] }, { @@ -903,27 +1068,27 @@ } ], "source": [ - "hQCD_D_m = hQCD[{\"charge\":0,\"passIso\":1,\"passMT\":1}]\n", - "hQCD_B_m = hQCD[{\"charge\":0,\"passIso\":1,\"passMT\":0}]\n", - "hQCD_C_m = hQCD[{\"charge\":0,\"passIso\":0,\"passMT\":1}]\n", - "hQCD_A_m = hQCD[{\"charge\":0,\"passIso\":0,\"passMT\":0}]\n", - "\n", - "hQCD_D_p = hQCD[{\"charge\":1,\"passIso\":1,\"passMT\":1}]\n", - "hQCD_B_p = hQCD[{\"charge\":1,\"passIso\":1,\"passMT\":0}]\n", - "hQCD_C_p = hQCD[{\"charge\":1,\"passIso\":0,\"passMT\":1}]\n", - "hQCD_A_p = hQCD[{\"charge\":1,\"passIso\":0,\"passMT\":0}]\n", - "\n", - "clim=(0, 0.01)\n", - "\n", - "make_plot_2d(hQCD_A_m, \"QCD_A_minus\", \"$QCD^{-}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_B_m, \"QCD_B_minus\", \"$QCD^{-}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_C_m, \"QCD_C_minus\", \"$QCD^{-}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_D_m, \"QCD_D_minus\", \"$QCD^{-}$\", [\"pt\",\"eta\"],clim=clim)\n", - "\n", - "make_plot_2d(hQCD_A_p, \"QCD_A_plus\", \"$QCD^{+}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_B_p, \"QCD_B_plus\", \"$QCD^{+}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_C_p, \"QCD_C_plus\", \"$QCD^{+}$\", [\"pt\",\"eta\"],clim=clim)\n", - "make_plot_2d(hQCD_D_p, \"QCD_D_plus\", \"$QCD^{+}$\", [\"pt\",\"eta\"],clim=clim)" + "hQCD_D_m = hQCD[{\"charge\": 0, \"passIso\": 1, \"passMT\": 1}]\n", + "hQCD_B_m = hQCD[{\"charge\": 0, \"passIso\": 1, \"passMT\": 0}]\n", + "hQCD_C_m = hQCD[{\"charge\": 0, \"passIso\": 0, \"passMT\": 1}]\n", + "hQCD_A_m = hQCD[{\"charge\": 0, \"passIso\": 0, \"passMT\": 0}]\n", + "\n", + "hQCD_D_p = hQCD[{\"charge\": 1, \"passIso\": 1, \"passMT\": 1}]\n", + "hQCD_B_p = hQCD[{\"charge\": 1, \"passIso\": 1, \"passMT\": 0}]\n", + "hQCD_C_p = hQCD[{\"charge\": 1, \"passIso\": 0, \"passMT\": 1}]\n", + "hQCD_A_p = hQCD[{\"charge\": 1, \"passIso\": 0, \"passMT\": 0}]\n", + "\n", + "clim = (0, 0.01)\n", + "\n", + "make_plot_2d(hQCD_A_m, \"QCD_A_minus\", \"$QCD^{-}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_B_m, \"QCD_B_minus\", \"$QCD^{-}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_C_m, \"QCD_C_minus\", \"$QCD^{-}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_D_m, \"QCD_D_minus\", \"$QCD^{-}$\", [\"pt\", \"eta\"], clim=clim)\n", + "\n", + "make_plot_2d(hQCD_A_p, \"QCD_A_plus\", \"$QCD^{+}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_B_p, \"QCD_B_plus\", \"$QCD^{+}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_C_p, \"QCD_C_plus\", \"$QCD^{+}$\", [\"pt\", \"eta\"], clim=clim)\n", + "make_plot_2d(hQCD_D_p, \"QCD_D_plus\", \"$QCD^{+}$\", [\"pt\", \"eta\"], clim=clim)" ] }, { @@ -1177,58 +1342,64 @@ "# plot fakes in each region separately\n", "clim = (0, 1000)\n", "nRebin = 16\n", - "for idx_x in (0,1):\n", - " hQCD_D = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":1, \"eta\": hist.rebin(nRebin)}]\n", - " hQCD_B = hQCD[{\"charge\":idx_c,\"passIso\":1,\"passMT\":0, \"eta\": hist.rebin(nRebin)}]\n", - " hQCD_C = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":1, \"eta\": hist.rebin(nRebin)}]\n", - " hQCD_D = hQCD[{\"charge\":idx_c,\"passIso\":0,\"passMT\":0, \"eta\": hist.rebin(nRebin)}]\n", + "for idx_x in (0, 1):\n", + " hQCD_D = hQCD[\n", + " {\"charge\": idx_c, \"passIso\": 1, \"passMT\": 1, \"eta\": hist.rebin(nRebin)}\n", + " ]\n", + " hQCD_B = hQCD[\n", + " {\"charge\": idx_c, \"passIso\": 1, \"passMT\": 0, \"eta\": hist.rebin(nRebin)}\n", + " ]\n", + " hQCD_C = hQCD[\n", + " {\"charge\": idx_c, \"passIso\": 0, \"passMT\": 1, \"eta\": hist.rebin(nRebin)}\n", + " ]\n", + " hQCD_D = hQCD[\n", + " {\"charge\": idx_c, \"passIso\": 0, \"passMT\": 0, \"eta\": hist.rebin(nRebin)}\n", + " ]\n", "\n", " proc = \"$QCD^{-}$\" if idx_c == 0 else \"$QCD^{+}$\"\n", "\n", - " \n", - " make_plot_2d(hQCD_A, f\"QCD_A_q{idx_c}\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_B, f\"QCD_B_q{idx_c}\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_C, f\"QCD_C_q{idx_c}\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_A, f\"QCD_D_q{idx_c}\", proc, [\"pt\",\"eta\"],clim=clim)\n", + " make_plot_2d(hQCD_A, f\"QCD_A_q{idx_c}\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_B, f\"QCD_B_q{idx_c}\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_C, f\"QCD_C_q{idx_c}\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_A, f\"QCD_D_q{idx_c}\", proc, [\"pt\", \"eta\"], clim=clim)\n", "\n", - " \n", " pos_eta = hQCD_A.axes.name.index(\"eta\")\n", " for idx_eta in range(hQCD_A.axes[\"eta\"].size):\n", " print(f\"Now at eta idx={idx_eta}\")\n", - " \n", - " hQCD_A_pt = hQCD_A[{\"eta\":idx_eta}]\n", - " hQCD_B_pt = hQCD_B[{\"eta\":idx_eta}]\n", - " hQCD_C_pt = hQCD_C[{\"eta\":idx_eta}]\n", - " hQCD_D_pt = hQCD_D[{\"eta\":idx_eta}]\n", "\n", - " slices = [slice(None) if n!=\"eta\" else idx_eta for n in hQCD_A.axes.name]\n", + " hQCD_A_pt = hQCD_A[{\"eta\": idx_eta}]\n", + " hQCD_B_pt = hQCD_B[{\"eta\": idx_eta}]\n", + " hQCD_C_pt = hQCD_C[{\"eta\": idx_eta}]\n", + " hQCD_D_pt = hQCD_D[{\"eta\": idx_eta}]\n", + "\n", + " slices = [slice(None) if n != \"eta\" else idx_eta for n in hQCD_A.axes.name]\n", "\n", " def set(h):\n", - " h_pt = h[{\"eta\":idx_eta}]\n", + " h_pt = h[{\"eta\": idx_eta}]\n", " # print(f\"hist = {h_pt.values()}\")\n", - " \n", + "\n", " vals = sel.fit_multijet_bkg(h_pt)\n", " # print(f\"vals = {vals}\")\n", - " h.view()[*slices] = np.array([(v.n,v.s**2) for v in vals])\n", - " \n", + " h.view()[*slices] = np.array([(v.n, v.s**2) for v in vals])\n", + "\n", " set(hQCD_A)\n", " set(hQCD_B)\n", " set(hQCD_C)\n", " set(hQCD_D)\n", - " \n", "\n", - " make_plot_2d(hQCD_A, f\"QCD_A_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_B, f\"QCD_B_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_C, f\"QCD_C_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_D, f\"QCD_D_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=clim)\n", + " make_plot_2d(hQCD_A, f\"QCD_A_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_B, f\"QCD_B_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_C, f\"QCD_C_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(hQCD_D, f\"QCD_D_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=clim)\n", "\n", " hQCD_FR = hh.divideHists(hQCD_B, hQCD_A)\n", " hQCD_CBA = hh.multiplyHists(hQCD_C, hQCD_FR)\n", " hQCD_DCBA = hh.divideHists(hQCD_D, hQCD_CBA)\n", - " make_plot_2d(hQCD_FR, f\"FR_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=(0.5,1.5))\n", - " make_plot_2d(hQCD_CBA, f\"CFR_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=clim)\n", - " make_plot_2d(hQCD_DCBA, f\"DCFR_q{idx_c}_smooth\", proc, [\"pt\",\"eta\"],clim=(0.5,1.5))\n", - "\n" + " make_plot_2d(hQCD_FR, f\"FR_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=(0.5, 1.5))\n", + " make_plot_2d(hQCD_CBA, f\"CFR_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=clim)\n", + " make_plot_2d(\n", + " hQCD_DCBA, f\"DCFR_q{idx_c}_smooth\", proc, [\"pt\", \"eta\"], clim=(0.5, 1.5)\n", + " )" ] }, { diff --git a/notebooks/comparisonPlots.ipynb b/notebooks/comparisonPlots.ipynb index 072c72dde..850585250 100644 --- a/notebooks/comparisonPlots.ipynb +++ b/notebooks/comparisonPlots.ipynb @@ -16,6 +16,7 @@ "from wremnants import datasets2016\n", "import lz4.frame\n", "import pickle\n", + "\n", "hep.style.use(hep.style.ROOT)" ] }, @@ -59,12 +60,15 @@ "def readForDataset(output, name, histname=\"nominal\"):\n", " if name not in output:\n", " raise ValueError(f\"Sample {name} not in file\")\n", - " lumi = 1. if not \"dataPostVFP\" in output else output[\"dataPostVFP\"][\"lumi\"]*1000\n", + " lumi = 1.0 if not \"dataPostVFP\" in output else output[\"dataPostVFP\"][\"lumi\"] * 1000\n", " info = output[name]\n", - " scale = 1. if output[name][\"dataset\"][\"is_data\"] else \\\n", - " lumi*info[\"dataset\"][\"xsec\"]/info[\"weight_sum\"]\n", + " scale = (\n", + " 1.0\n", + " if output[name][\"dataset\"][\"is_data\"]\n", + " else lumi * info[\"dataset\"][\"xsec\"] / info[\"weight_sum\"]\n", + " )\n", " print(scale)\n", - " return info[\"output\"][histname]*scale" + " return info[\"output\"][histname] * scale" ] }, { @@ -89,48 +93,48 @@ "outputs": [], "source": [ "def makeVariationPlot(chn, variations, obs, xlabel, rrange=[0.9, 1.1], scale=8.5e6):\n", - " if type(variations) == str: variations = list(variations)\n", - " width=3 if \"unrolled\" in obs else 1\n", - " fig = plt.figure(figsize=(8*width,8))\n", - " ax1 = fig.add_subplot(4, 1, (1, 3)) \n", - " ax2 = fig.add_subplot(4, 1, 4) \n", - " \n", - " op = lambda x: x.project(obs) \n", + " if type(variations) == str:\n", + " variations = list(variations)\n", + " width = 3 if \"unrolled\" in obs else 1\n", + " fig = plt.figure(figsize=(8 * width, 8))\n", + " ax1 = fig.add_subplot(4, 1, (1, 3))\n", + " ax2 = fig.add_subplot(4, 1, 4)\n", + "\n", + " op = lambda x: x.project(obs)\n", " if obs == \"unrolled\":\n", " op = unrolledHist\n", "\n", - " hists = [op(wgen[chn]['hist']['nominal']), *[op(wgen[chn]['hist']['vars'][x]) for x in variations]]\n", - " colors = [wgen[chn]['color']['nominal'], *wgen[chn]['color']['vars']]\n", - " labels = [wgen[chn]['label']['nominal'], *wgen[chn]['label']['vars']]\n", - " \n", - " hep.histplot(\n", - " hists,\n", - " histtype = \"step\",\n", - " color = colors,\n", - " label = labels,\n", - " ax = ax1\n", - " )\n", - " \n", + " hists = [\n", + " op(wgen[chn][\"hist\"][\"nominal\"]),\n", + " *[op(wgen[chn][\"hist\"][\"vars\"][x]) for x in variations],\n", + " ]\n", + " colors = [wgen[chn][\"color\"][\"nominal\"], *wgen[chn][\"color\"][\"vars\"]]\n", + " labels = [wgen[chn][\"label\"][\"nominal\"], *wgen[chn][\"label\"][\"vars\"]]\n", + "\n", + " hep.histplot(hists, histtype=\"step\", color=colors, label=labels, ax=ax1)\n", "\n", " hep.histplot(\n", " [hh.divideHists(x, hists[0]) for x in hists],\n", " histtype=\"step\",\n", " yerr=False,\n", " color=colors,\n", - " ax=ax2\n", + " ax=ax2,\n", " )\n", - " \n", + "\n", " ax1.set_xlabel(\"\")\n", " ax2.set_xlabel(xlabel)\n", " ax1.set_ylabel(\"Events/bin\")\n", " ax1.set_xticklabels([])\n", - " xrange = [hists[0].axes[0].edges[0], hists[0].axes[0].edges[len(hists[0].axes[0])-1]]\n", + " xrange = [\n", + " hists[0].axes[0].edges[0],\n", + " hists[0].axes[0].edges[len(hists[0].axes[0]) - 1],\n", + " ]\n", " ax1.set_xlim(xrange)\n", " ax2.set_xlim(xrange)\n", " ax2.set_ylabel(\"variation/nominal\", fontsize=22)\n", " ax2.set_ylim(rrange)\n", " ax1.set_ylim([0, scale])\n", - " ax1.legend(prop={'size' : 20*(0.7 if width == 1 else 1.3)}, loc='upper right')" + " ax1.legend(prop={\"size\": 20 * (0.7 if width == 1 else 1.3)}, loc=\"upper right\")" ] }, { @@ -141,7 +145,7 @@ "outputs": [], "source": [ "boost.keys()\n", - "boost['WplusmunuPostVFP']['output']['nominal']" + "boost[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"]" ] }, { @@ -151,7 +155,7 @@ "metadata": {}, "outputs": [], "source": [ - "boost['WplusmunuPostVFP']['output']['pdfNNPDF31']" + "boost[\"WplusmunuPostVFP\"][\"output\"][\"pdfNNPDF31\"]" ] }, { @@ -162,89 +166,77 @@ "outputs": [], "source": [ "datagroups = {\n", - " \"Data\" : dict(\n", - " members = [\"dataPostVFP\"],\n", - " color = \"black\",\n", - " label = \"Data\",\n", - " hist = {},\n", + " \"Data\": dict(\n", + " members=[\"dataPostVFP\"],\n", + " color=\"black\",\n", + " label=\"Data\",\n", + " hist={},\n", + " ),\n", + " \"Fake\": dict(\n", + " members=list(boost.keys()),\n", + " label=\"Nonprompt\",\n", + " color=\"grey\",\n", + " hist={},\n", " ),\n", - " \"Fake\" : dict(\n", - " members = list(boost.keys()),\n", - " label = \"Nonprompt\",\n", - " color = \"grey\",\n", - " hist = {},\n", + " \"Zmumu\": dict(\n", + " members=[\"ZmumuPostVFP\"],\n", + " label=r\"Z$\\to\\mu\\mu$\",\n", + " color=\"lightblue\",\n", + " hist={},\n", " ),\n", - " \"Zmumu\" : dict(\n", - " members = [\"ZmumuPostVFP\"],\n", - " label = r\"Z$\\to\\mu\\mu$\",\n", - " color = \"lightblue\",\n", - " hist = {},\n", - " ), \n", - " \"Wtau\" : dict(\n", - " members = [\"WminustaunuPostVFP\", \"WplustaunuPostVFP\"],\n", - " label = r\"W$^{\\pm}\\to\\tau\\nu$\",\n", - " color = \"orange\",\n", - " hist = {},\n", + " \"Wtau\": dict(\n", + " members=[\"WminustaunuPostVFP\", \"WplustaunuPostVFP\"],\n", + " label=r\"W$^{\\pm}\\to\\tau\\nu$\",\n", + " color=\"orange\",\n", + " hist={},\n", " ),\n", - " \"W\" : dict(\n", - " members = [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", - " label = r\"W$^{\\pm}\\to\\mu\\nu$\",\n", - " color = \"darkred\",\n", - " hist = {},\n", + " \"W\": dict(\n", + " members=[\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", + " label=r\"W$^{\\pm}\\to\\mu\\nu$\",\n", + " color=\"darkred\",\n", + " hist={},\n", + " ),\n", + " \"Ztt\": dict(\n", + " members=[\"ZtautauPostVFP\"],\n", + " label=r\"Z$\\to\\tau\\tau$\",\n", + " color=\"darkblue\",\n", + " hist={},\n", + " ),\n", + " \"Top\": dict(\n", + " members=[\"TTSemileptonicPostVFP\", \"TTLeptonicPostVFP\"],\n", + " label=\"Top\",\n", + " color=\"green\",\n", + " hist={},\n", + " ),\n", + " \"Diboson\": dict(\n", + " members=[\"WWPostVFP\"],\n", + " label=\"Diboson\",\n", + " color=\"pink\",\n", + " hist={},\n", " ),\n", - " \"Ztt\" : dict(\n", - " members = [\"ZtautauPostVFP\"],\n", - " label = r\"Z$\\to\\tau\\tau$\",\n", - " color = \"darkblue\",\n", - " hist = {},\n", - " ), \n", - " \"Top\" : dict(\n", - " members = [\"TTSemileptonicPostVFP\", \"TTLeptonicPostVFP\"],\n", - " label = \"Top\",\n", - " color = \"green\",\n", - " hist = {},\n", - " ), \n", - " \"Diboson\" : dict(\n", - " members = [\"WWPostVFP\"],\n", - " label = \"Diboson\",\n", - " color = \"pink\",\n", - " hist = {},\n", - " ), \n", "}\n", "\n", "\n", - "variations = ['qcdScale', 'pdfNNPDF31', 'muonScaleSyst']\n", - "variation_labels = ['QCD Scale', 'NNPDF31', 'Muon Scale']\n", - "variation_colors = ['red', 'green', 'blue']\n", + "variations = [\"qcdScale\", \"pdfNNPDF31\", \"muonScaleSyst\"]\n", + "variation_labels = [\"QCD Scale\", \"NNPDF31\", \"Muon Scale\"]\n", + "variation_colors = [\"red\", \"green\", \"blue\"]\n", "wgen = {\n", - " 'WminusmunuPostVFP': dict(\n", - " label = {\n", - " 'nominal': r'$W^{-}$ nominal',\n", - " 'vars': [r'$W^{-}$ ' + x for x in variation_labels]\n", - " },\n", - " color = {\n", - " 'nominal': 'black',\n", - " 'vars': variation_colors\n", + " \"WminusmunuPostVFP\": dict(\n", + " label={\n", + " \"nominal\": r\"$W^{-}$ nominal\",\n", + " \"vars\": [r\"$W^{-}$ \" + x for x in variation_labels],\n", " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", + " color={\"nominal\": \"black\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", " ),\n", - " 'WplusmunuPostVFP': dict(\n", - " label = {\n", - " 'nominal': r'$W^{+}$ nominal',\n", - " 'vars': [r'$W^{+}$ ' + x for x in variation_labels]\n", + " \"WplusmunuPostVFP\": dict(\n", + " label={\n", + " \"nominal\": r\"$W^{+}$ nominal\",\n", + " \"vars\": [r\"$W^{+}$ \" + x for x in variation_labels],\n", " },\n", - " color = {\n", - " 'nominal': 'black',\n", - " 'vars': variation_colors\n", - " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", - " )\n", + " color={\"nominal\": \"black\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", + " ),\n", "}\n", "\n", "\n", @@ -254,19 +246,19 @@ " except ValueError as e:\n", " print(e)\n", " continue\n", - " v['hist']['nominal'] = h_nominal\n", - " v['hist']['nominal'] = sel.signalHistABCD(v['hist']['nominal'])\n", - " \n", + " v[\"hist\"][\"nominal\"] = h_nominal\n", + " v[\"hist\"][\"nominal\"] = sel.signalHistABCD(v[\"hist\"][\"nominal\"])\n", + "\n", " for var in variations:\n", " try:\n", - " h_var = readForDataset(boost, chn, histname = var)\n", + " h_var = readForDataset(boost, chn, histname=var)\n", " except ValueError as e:\n", " print(e)\n", " continue\n", "\n", - " v['hist']['vars'][var] = h_var\n", + " v[\"hist\"][\"vars\"][var] = h_var\n", " # does not change bin contents\n", - " v['hist']['vars'][var] = sel.signalHistABCD(v['hist']['vars'][var])" + " v[\"hist\"][\"vars\"][var] = sel.signalHistABCD(v[\"hist\"][\"vars\"][var])" ] }, { @@ -276,7 +268,7 @@ "metadata": {}, "outputs": [], "source": [ - "#data" + "# data" ] }, { @@ -286,8 +278,17 @@ "metadata": {}, "outputs": [], "source": [ - "makeVariationPlot('WminusmunuPostVFP', variations, \"pt\", xlabel=r\"p$_{T}$ (GeV)\", rrange=[0.95, 1.05], scale=5e8)\n", - "makeVariationPlot('WplusmunuPostVFP', variations, \"pt\", xlabel=r\"p$_{T}$ (GeV)\", rrange=[0.95, 1.05])\n" + "makeVariationPlot(\n", + " \"WminusmunuPostVFP\",\n", + " variations,\n", + " \"pt\",\n", + " xlabel=r\"p$_{T}$ (GeV)\",\n", + " rrange=[0.95, 1.05],\n", + " scale=5e8,\n", + ")\n", + "makeVariationPlot(\n", + " \"WplusmunuPostVFP\", variations, \"pt\", xlabel=r\"p$_{T}$ (GeV)\", rrange=[0.95, 1.05]\n", + ")" ] }, { diff --git a/notebooks/genPlots.ipynb b/notebooks/genPlots.ipynb index d1b7b5936..7f3f4e3e1 100644 --- a/notebooks/genPlots.ipynb +++ b/notebooks/genPlots.ipynb @@ -16,6 +16,7 @@ "from wremnants import datasets2016\n", "import lz4.frame\n", "import pickle\n", + "\n", "hep.style.use(hep.style.ROOT)" ] }, @@ -59,12 +60,15 @@ "def readForDataset(output, name, histname=\"nominal_gen\"):\n", " if name not in output:\n", " raise ValueError(f\"Sample {name} not in file\")\n", - " lumi = 1. if not \"dataPostVFP\" in output else output[\"dataPostVFP\"][\"lumi\"]*1000\n", + " lumi = 1.0 if not \"dataPostVFP\" in output else output[\"dataPostVFP\"][\"lumi\"] * 1000\n", " info = output[name]\n", - " scale = 1. if output[name][\"dataset\"][\"is_data\"] else \\\n", - " lumi*info[\"dataset\"][\"xsec\"]/info[\"weight_sum\"]\n", + " scale = (\n", + " 1.0\n", + " if output[name][\"dataset\"][\"is_data\"]\n", + " else lumi * info[\"dataset\"][\"xsec\"] / info[\"weight_sum\"]\n", + " )\n", " print(scale)\n", - " return info[\"output\"][histname]*scale" + " return info[\"output\"][histname] * scale" ] }, { @@ -74,7 +78,7 @@ "metadata": {}, "outputs": [], "source": [ - "def unrolledHist(h, obs=['prefsr_lepton_pt_gen', 'prefsr_lepton_eta_gen']):\n", + "def unrolledHist(h, obs=[\"prefsr_lepton_pt_gen\", \"prefsr_lepton_eta_gen\"]):\n", " bins = np.multiply(*[len(a) for a in h.axes if a.name in obs])\n", " newh = hist.Hist(hist.axis.Regular(bins, 0, bins), storage=hist.storage.Weight())\n", " newh[...] = np.ravel(h.project(*obs))\n", @@ -89,48 +93,48 @@ "outputs": [], "source": [ "def makeVariationPlot(chns, variations, obs, xlabel, rrange=[0.9, 1.1], scale=8.5e6):\n", - " if type(variations) == str: variations = list(variations)\n", - " width=3 if \"unrolled\" in obs else 1\n", - " fig = plt.figure(figsize=(8*width,8))\n", - " ax1 = fig.add_subplot(4, 1, (1, 3)) \n", - " ax2 = fig.add_subplot(4, 1, 4) \n", - " \n", - " op = lambda x: x.project(obs) \n", + " if type(variations) == str:\n", + " variations = list(variations)\n", + " width = 3 if \"unrolled\" in obs else 1\n", + " fig = plt.figure(figsize=(8 * width, 8))\n", + " ax1 = fig.add_subplot(4, 1, (1, 3))\n", + " ax2 = fig.add_subplot(4, 1, 4)\n", + "\n", + " op = lambda x: x.project(obs)\n", " if obs == \"unrolled\":\n", " op = unrolledHist\n", "\n", - " hists = [op(wgen[chn]['hist']['nominal']), *[op(wgen[chn]['hist']['vars'][x]) for x in variations]]\n", - " colors = [wgen[chn]['color']['nominal'], *wgen[chn]['color']['vars']]\n", - " labels = [wgen[chn]['label']['nominal'], *wgen[chn]['label']['vars']]\n", - " \n", - " hep.histplot(\n", - " hists,\n", - " histtype = \"step\",\n", - " color = colors,\n", - " label = labels,\n", - " ax = ax1\n", - " )\n", - " \n", + " hists = [\n", + " op(wgen[chn][\"hist\"][\"nominal\"]),\n", + " *[op(wgen[chn][\"hist\"][\"vars\"][x]) for x in variations],\n", + " ]\n", + " colors = [wgen[chn][\"color\"][\"nominal\"], *wgen[chn][\"color\"][\"vars\"]]\n", + " labels = [wgen[chn][\"label\"][\"nominal\"], *wgen[chn][\"label\"][\"vars\"]]\n", + "\n", + " hep.histplot(hists, histtype=\"step\", color=colors, label=labels, ax=ax1)\n", "\n", " hep.histplot(\n", " [hh.divideHists(x, hists[0]) for x in hists],\n", " histtype=\"step\",\n", " yerr=False,\n", " color=colors,\n", - " ax=ax2\n", + " ax=ax2,\n", " )\n", - " \n", + "\n", " ax1.set_xlabel(\"\")\n", " ax2.set_xlabel(xlabel)\n", " ax1.set_ylabel(\"Events/bin\")\n", " ax1.set_xticklabels([])\n", - " xrange = [hists[0].axes[0].edges[0], hists[0].axes[0].edges[len(hists[0].axes[0])-1]]\n", + " xrange = [\n", + " hists[0].axes[0].edges[0],\n", + " hists[0].axes[0].edges[len(hists[0].axes[0]) - 1],\n", + " ]\n", " ax1.set_xlim(xrange)\n", " ax2.set_xlim(xrange)\n", " ax2.set_ylabel(\"variation/nominal\", fontsize=22)\n", " ax2.set_ylim(rrange)\n", " ax1.set_ylim([0, scale])\n", - " ax1.legend(prop={'size' : 20*(0.7 if width == 1 else 1.3)}, loc='upper right')" + " ax1.legend(prop={\"size\": 20 * (0.7 if width == 1 else 1.3)}, loc=\"upper right\")" ] }, { @@ -143,50 +147,49 @@ "# comparing the same distribution in different sets of samples\n", "# to figure out the effect of certain bug fixes\n", "\n", + "\n", "def makeComparisonPlot(chns, obs, xlabel, rrange=[0.9, 1.1], scale=8.5e6):\n", - " if type(chns) == str: chns = list(chns)\n", - " width=3 if \"unrolled\" in obs else 1\n", - " fig = plt.figure(figsize=(8*width,8))\n", - " ax1 = fig.add_subplot(4, 1, (1, 3)) \n", - " ax2 = fig.add_subplot(4, 1, 4) \n", - " \n", - " op = lambda x: x.project(obs) \n", + " if type(chns) == str:\n", + " chns = list(chns)\n", + " width = 3 if \"unrolled\" in obs else 1\n", + " fig = plt.figure(figsize=(8 * width, 8))\n", + " ax1 = fig.add_subplot(4, 1, (1, 3))\n", + " ax2 = fig.add_subplot(4, 1, 4)\n", + "\n", + " op = lambda x: x.project(obs)\n", " if obs == \"unrolled\":\n", " op = unrolledHist\n", "\n", - " hists = [op(wgen[chn]['hist']['nominal']) for chn in chns]\n", - " colors = [wgen[chn]['color']['nominal'] for chn in chns]\n", - " labels = [wgen[chn]['label']['nominal'] for chn in chns]\n", - " \n", + " hists = [op(wgen[chn][\"hist\"][\"nominal\"]) for chn in chns]\n", + " colors = [wgen[chn][\"color\"][\"nominal\"] for chn in chns]\n", + " labels = [wgen[chn][\"label\"][\"nominal\"] for chn in chns]\n", + "\n", " hep.histplot(\n", - " hists,\n", - " histtype = \"step\",\n", - " color = colors,\n", - " label = labels,\n", - " ax = ax1,\n", - " binwnorm=True\n", + " hists, histtype=\"step\", color=colors, label=labels, ax=ax1, binwnorm=True\n", " )\n", - " \n", "\n", " hep.histplot(\n", " [hh.divideHists(x, hists[0]) for x in hists],\n", " histtype=\"step\",\n", " yerr=False,\n", " color=colors,\n", - " ax=ax2\n", + " ax=ax2,\n", " )\n", - " \n", + "\n", " ax1.set_xlabel(\"\")\n", " ax2.set_xlabel(xlabel)\n", " ax1.set_ylabel(\"Events/bin\")\n", " ax1.set_xticklabels([])\n", - " xrange = [hists[0].axes[0].edges[0], hists[0].axes[0].edges[len(hists[0].axes[0])-1]]\n", + " xrange = [\n", + " hists[0].axes[0].edges[0],\n", + " hists[0].axes[0].edges[len(hists[0].axes[0]) - 1],\n", + " ]\n", " ax1.set_xlim(xrange)\n", " ax2.set_xlim(xrange)\n", " ax2.set_ylabel(\"variation/nominal\", fontsize=22)\n", " ax2.set_ylim(rrange)\n", " ax1.set_ylim([0, scale])\n", - " ax1.legend(prop={'size' : 20*(0.7 if width == 1 else 1.3)}, loc='upper right')" + " ax1.legend(prop={\"size\": 20 * (0.7 if width == 1 else 1.3)}, loc=\"upper right\")" ] }, { @@ -196,7 +199,7 @@ "metadata": {}, "outputs": [], "source": [ - "boost['ZmumuPostVFP_bugfix']['output']['nominal_gen']" + "boost[\"ZmumuPostVFP_bugfix\"][\"output\"][\"nominal_gen\"]" ] }, { @@ -206,7 +209,7 @@ "metadata": {}, "outputs": [], "source": [ - "boost['WplusmunuPostVFP']['output']['nominal_gen'].axes" + "boost[\"WplusmunuPostVFP\"][\"output\"][\"nominal_gen\"].axes" ] }, { @@ -251,54 +254,54 @@ "outputs": [], "source": [ "datagroups = {\n", - " \"Data\" : dict(\n", - " members = [\"dataPostVFP\"],\n", - " color = \"black\",\n", - " label = \"Data\",\n", - " hist = {},\n", + " \"Data\": dict(\n", + " members=[\"dataPostVFP\"],\n", + " color=\"black\",\n", + " label=\"Data\",\n", + " hist={},\n", " ),\n", - " \"Fake\" : dict(\n", - " members = list(boost.keys()),\n", - " label = \"Nonprompt\",\n", - " color = \"grey\",\n", - " hist = {},\n", + " \"Fake\": dict(\n", + " members=list(boost.keys()),\n", + " label=\"Nonprompt\",\n", + " color=\"grey\",\n", + " hist={},\n", " ),\n", - " \"Zmumu\" : dict(\n", - " members = [\"ZmumuPostVFP\"],\n", - " label = r\"Z$\\to\\mu\\mu$\",\n", - " color = \"lightblue\",\n", - " hist = {},\n", - " ), \n", - " \"Wtau\" : dict(\n", - " members = [\"WminustaunuPostVFP\", \"WplustaunuPostVFP\"],\n", - " label = r\"W$^{\\pm}\\to\\tau\\nu$\",\n", - " color = \"orange\",\n", - " hist = {},\n", + " \"Zmumu\": dict(\n", + " members=[\"ZmumuPostVFP\"],\n", + " label=r\"Z$\\to\\mu\\mu$\",\n", + " color=\"lightblue\",\n", + " hist={},\n", " ),\n", - " \"W\" : dict(\n", - " members = [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", - " label = r\"W$^{\\pm}\\to\\mu\\nu$\",\n", - " color = \"darkred\",\n", - " hist = {},\n", + " \"Wtau\": dict(\n", + " members=[\"WminustaunuPostVFP\", \"WplustaunuPostVFP\"],\n", + " label=r\"W$^{\\pm}\\to\\tau\\nu$\",\n", + " color=\"orange\",\n", + " hist={},\n", + " ),\n", + " \"W\": dict(\n", + " members=[\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", + " label=r\"W$^{\\pm}\\to\\mu\\nu$\",\n", + " color=\"darkred\",\n", + " hist={},\n", + " ),\n", + " \"Ztt\": dict(\n", + " members=[\"ZtautauPostVFP\"],\n", + " label=r\"Z$\\to\\tau\\tau$\",\n", + " color=\"darkblue\",\n", + " hist={},\n", + " ),\n", + " \"Top\": dict(\n", + " members=[\"TTSemileptonicPostVFP\", \"TTLeptonicPostVFP\"],\n", + " label=\"Top\",\n", + " color=\"green\",\n", + " hist={},\n", + " ),\n", + " \"Diboson\": dict(\n", + " members=[\"WWPostVFP\"],\n", + " label=\"Diboson\",\n", + " color=\"pink\",\n", + " hist={},\n", " ),\n", - " \"Ztt\" : dict(\n", - " members = [\"ZtautauPostVFP\"],\n", - " label = r\"Z$\\to\\tau\\tau$\",\n", - " color = \"darkblue\",\n", - " hist = {},\n", - " ), \n", - " \"Top\" : dict(\n", - " members = [\"TTSemileptonicPostVFP\", \"TTLeptonicPostVFP\"],\n", - " label = \"Top\",\n", - " color = \"green\",\n", - " hist = {},\n", - " ), \n", - " \"Diboson\" : dict(\n", - " members = [\"WWPostVFP\"],\n", - " label = \"Diboson\",\n", - " color = \"pink\",\n", - " hist = {},\n", - " ), \n", "}\n", "\n", "\n", @@ -307,62 +310,38 @@ "variation_colors = []\n", "\n", "wgen = {\n", - " 'WminusmunuPostVFP': dict(\n", - " label = {\n", - " 'nominal': r'$W^{-}$ nominal_gen',\n", - " 'vars': [r'$W^{-}$ ' + x for x in variation_labels]\n", - " },\n", - " color = {\n", - " 'nominal': 'black',\n", - " 'vars': variation_colors\n", + " \"WminusmunuPostVFP\": dict(\n", + " label={\n", + " \"nominal\": r\"$W^{-}$ nominal_gen\",\n", + " \"vars\": [r\"$W^{-}$ \" + x for x in variation_labels],\n", " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", + " color={\"nominal\": \"black\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", " ),\n", - " 'WplusmunuPostVFP': dict(\n", - " label = {\n", - " 'nominal': r'$W^{+}$ nominal_gen',\n", - " 'vars': [r'$W^{+}$ ' + x for x in variation_labels]\n", - " },\n", - " color = {\n", - " 'nominal': 'black',\n", - " 'vars': variation_colors\n", + " \"WplusmunuPostVFP\": dict(\n", + " label={\n", + " \"nominal\": r\"$W^{+}$ nominal_gen\",\n", + " \"vars\": [r\"$W^{+}$ \" + x for x in variation_labels],\n", " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", + " color={\"nominal\": \"black\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", " ),\n", - " 'ZmumuPostVFP': dict(\n", - " label = {\n", - " 'nominal': r'$Z \\rightarrow \\mu\\mu$ nominal_gen',\n", - " 'vars': [r'$Z \\rightarrow \\mu\\mu$ ' + x for x in variation_labels]\n", + " \"ZmumuPostVFP\": dict(\n", + " label={\n", + " \"nominal\": r\"$Z \\rightarrow \\mu\\mu$ nominal_gen\",\n", + " \"vars\": [r\"$Z \\rightarrow \\mu\\mu$ \" + x for x in variation_labels],\n", " },\n", - " color = {\n", - " 'nominal': 'black',\n", - " 'vars': variation_colors\n", - " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", + " color={\"nominal\": \"black\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", " ),\n", - " 'ZmumuPostVFP_bugfix': dict(\n", - " label = {\n", - " 'nominal': r'$Z \\rightarrow \\mu\\mu$ nominal_gen bugfix',\n", - " 'vars': [r'$Z \\rightarrow \\mu\\mu$ ' + x for x in variation_labels]\n", - " },\n", - " color = {\n", - " 'nominal': 'red',\n", - " 'vars': variation_colors\n", + " \"ZmumuPostVFP_bugfix\": dict(\n", + " label={\n", + " \"nominal\": r\"$Z \\rightarrow \\mu\\mu$ nominal_gen bugfix\",\n", + " \"vars\": [r\"$Z \\rightarrow \\mu\\mu$ \" + x for x in variation_labels],\n", " },\n", - " hist = {\n", - " 'nominal': None,\n", - " 'vars': {}\n", - " }\n", - " )\n", + " color={\"nominal\": \"red\", \"vars\": variation_colors},\n", + " hist={\"nominal\": None, \"vars\": {}},\n", + " ),\n", "}\n", "\n", "\n", @@ -372,27 +351,29 @@ " except ValueError as e:\n", " print(e)\n", " continue\n", - " v['hist']['nominal'] = h_nominal\n", - "# v['hist']['nominal'] = sel.signalHistABCD(v['hist']['nominal'])\n", - " \n", + " v[\"hist\"][\"nominal\"] = h_nominal\n", + " # v['hist']['nominal'] = sel.signalHistABCD(v['hist']['nominal'])\n", + "\n", " for var in variations:\n", " try:\n", - " h_var = readForDataset(boost, chn, histname = var)\n", + " h_var = readForDataset(boost, chn, histname=var)\n", " except ValueError as e:\n", " print(e)\n", " continue\n", - " if 'pdf' in var:\n", - " v['hist']['vars'][var] = h_var[...,1] #get the first var set after nominal\n", - " v['hist']['vars'][var] = sel.signalHistABCD(v['hist']['vars'][var])\n", - " elif 'qcd' in var:\n", - " v['hist']['vars'][var] = h_var[...,0]\n", - " v['hist']['vars'][var] = sel.signalHistABCD(v['hist']['vars'][var])\n", - " elif 'muonScale' in var:\n", - " v['hist']['vars'][var] = h_var[...,0,0] #[down, 2nd_eta_bin]\n", - " v['hist']['vars'][var] = sel.signalHistABCD(v['hist']['vars'][var])\n", - " elif 'massWeight' in var:\n", - " v['hist']['vars'][var] = h_var[...,20] #for 100 MeV mass shift\n", - " v['hist']['vars'][var] = sel.signalHistABCD(v['hist']['vars'][var]) " + " if \"pdf\" in var:\n", + " v[\"hist\"][\"vars\"][var] = h_var[\n", + " ..., 1\n", + " ] # get the first var set after nominal\n", + " v[\"hist\"][\"vars\"][var] = sel.signalHistABCD(v[\"hist\"][\"vars\"][var])\n", + " elif \"qcd\" in var:\n", + " v[\"hist\"][\"vars\"][var] = h_var[..., 0]\n", + " v[\"hist\"][\"vars\"][var] = sel.signalHistABCD(v[\"hist\"][\"vars\"][var])\n", + " elif \"muonScale\" in var:\n", + " v[\"hist\"][\"vars\"][var] = h_var[..., 0, 0] # [down, 2nd_eta_bin]\n", + " v[\"hist\"][\"vars\"][var] = sel.signalHistABCD(v[\"hist\"][\"vars\"][var])\n", + " elif \"massWeight\" in var:\n", + " v[\"hist\"][\"vars\"][var] = h_var[..., 20] # for 100 MeV mass shift\n", + " v[\"hist\"][\"vars\"][var] = sel.signalHistABCD(v[\"hist\"][\"vars\"][var])" ] }, { @@ -402,7 +383,7 @@ "metadata": {}, "outputs": [], "source": [ - "#data" + "# data" ] }, { @@ -412,10 +393,34 @@ "metadata": {}, "outputs": [], "source": [ - "makeVariationPlot('WminusmunuPostVFP', variations, \"prefsr_lepton_eta_gen\", xlabel=r\"$\\eta$\", rrange=[0.9, 1.1])\n", - "makeVariationPlot('WplusmunuPostVFP', variations, \"prefsr_lepton_eta_gen\", xlabel=r\"$\\eta$\", rrange=[0.9, 1.1])\n", - "makeVariationPlot('WminusmunuPostVFP', variations, \"prefsr_lepton_pt_gen\", xlabel=r\"p$_{T}$ [GeV]\", rrange=[0.9, 1.1])\n", - "makeVariationPlot('WplusmunuPostVFP', variations, \"prefsr_lepton_pt_gen\", xlabel=r\"p$_{T}$ [GeV]\", rrange=[0.95, 1.05])\n" + "makeVariationPlot(\n", + " \"WminusmunuPostVFP\",\n", + " variations,\n", + " \"prefsr_lepton_eta_gen\",\n", + " xlabel=r\"$\\eta$\",\n", + " rrange=[0.9, 1.1],\n", + ")\n", + "makeVariationPlot(\n", + " \"WplusmunuPostVFP\",\n", + " variations,\n", + " \"prefsr_lepton_eta_gen\",\n", + " xlabel=r\"$\\eta$\",\n", + " rrange=[0.9, 1.1],\n", + ")\n", + "makeVariationPlot(\n", + " \"WminusmunuPostVFP\",\n", + " variations,\n", + " \"prefsr_lepton_pt_gen\",\n", + " xlabel=r\"p$_{T}$ [GeV]\",\n", + " rrange=[0.9, 1.1],\n", + ")\n", + "makeVariationPlot(\n", + " \"WplusmunuPostVFP\",\n", + " variations,\n", + " \"prefsr_lepton_pt_gen\",\n", + " xlabel=r\"p$_{T}$ [GeV]\",\n", + " rrange=[0.95, 1.05],\n", + ")" ] }, { @@ -425,9 +430,27 @@ "metadata": {}, "outputs": [], "source": [ - "makeComparisonPlot(['ZmumuPostVFP', 'ZmumuPostVFP_bugfix'], \"prefsr_lepton_pt_gen\", xlabel=r\"p$_{T}^{\\ell}$ [GeV]\" , rrange=[0.95, 1.05], scale=2e6)\n", - "makeComparisonPlot(['ZmumuPostVFP', 'ZmumuPostVFP_bugfix'], \"prefsr_lepton_eta_gen\", xlabel=r\"$\\eta^{\\ell}$\" , rrange=[0.95, 1.05], scale=8e6)\n", - "makeComparisonPlot(['ZmumuPostVFP', 'ZmumuPostVFP_bugfix'], \"unrolled\", xlabel=r\"$(p_{T}^{\\ell},\\eta^{\\ell})$\" , rrange=[0.85, 1.15], scale=2e4)" + "makeComparisonPlot(\n", + " [\"ZmumuPostVFP\", \"ZmumuPostVFP_bugfix\"],\n", + " \"prefsr_lepton_pt_gen\",\n", + " xlabel=r\"p$_{T}^{\\ell}$ [GeV]\",\n", + " rrange=[0.95, 1.05],\n", + " scale=2e6,\n", + ")\n", + "makeComparisonPlot(\n", + " [\"ZmumuPostVFP\", \"ZmumuPostVFP_bugfix\"],\n", + " \"prefsr_lepton_eta_gen\",\n", + " xlabel=r\"$\\eta^{\\ell}$\",\n", + " rrange=[0.95, 1.05],\n", + " scale=8e6,\n", + ")\n", + "makeComparisonPlot(\n", + " [\"ZmumuPostVFP\", \"ZmumuPostVFP_bugfix\"],\n", + " \"unrolled\",\n", + " xlabel=r\"$(p_{T}^{\\ell},\\eta^{\\ell})$\",\n", + " rrange=[0.85, 1.15],\n", + " scale=2e4,\n", + ")" ] }, { @@ -437,8 +460,20 @@ "metadata": {}, "outputs": [], "source": [ - "makeComparisonPlot(['ZmumuPostVFP', 'ZmumuPostVFP_bugfix'], \"ptVgen\", xlabel=r\"Z p$_{T}$ [GeV]\" , rrange=[0.95, 1.05], scale=4e6)\n", - "makeComparisonPlot(['ZmumuPostVFP', 'ZmumuPostVFP_bugfix'], \"absYVgen\", xlabel=r\"Z absolute rapidity\" , rrange=[0.95, 1.05], scale=2e7)" + "makeComparisonPlot(\n", + " [\"ZmumuPostVFP\", \"ZmumuPostVFP_bugfix\"],\n", + " \"ptVgen\",\n", + " xlabel=r\"Z p$_{T}$ [GeV]\",\n", + " rrange=[0.95, 1.05],\n", + " scale=4e6,\n", + ")\n", + "makeComparisonPlot(\n", + " [\"ZmumuPostVFP\", \"ZmumuPostVFP_bugfix\"],\n", + " \"absYVgen\",\n", + " xlabel=r\"Z absolute rapidity\",\n", + " rrange=[0.95, 1.05],\n", + " scale=2e7,\n", + ")" ] }, { diff --git a/notebooks/genScratch.ipynb b/notebooks/genScratch.ipynb index 222e1b245..0f3ec276e 100644 --- a/notebooks/genScratch.ipynb +++ b/notebooks/genScratch.ipynb @@ -9,8 +9,8 @@ "source": [ "import matplotlib.pyplot as plt\n", "from wremnants.datasets.datagroups import datagroups2016\n", - "from wums import boostHistHelpers as hh,input_tools\n", - "from wremnants import plot_tools,syst_tools\n", + "from wums import boostHistHelpers as hh, input_tools\n", + "from wremnants import plot_tools, syst_tools\n", "from wremnants import histselections as sel\n", "import lz4.frame\n", "import pickle\n", @@ -36,7 +36,10 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo = input_tools.read_dyturbo_file(\"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nnlo_nnpdf31nnlo_yw.txt\", axnames=[\"y\"])\n" + "dyturbo = input_tools.read_dyturbo_file(\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31/rapidities/results_z0_nnlo_nnpdf31nnlo_yw.txt\",\n", + " axnames=[\"y\"],\n", + ")" ] }, { @@ -100,7 +103,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloh = input_tools.read_all_and_scale(\"../w_z_gen_dists_nnpdf31.pkl.lz4\", [\"WminusmunuPostVFP\"], [\"nominal_gen\"])[0]" + "minnloh = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists_nnpdf31.pkl.lz4\", [\"WminusmunuPostVFP\"], [\"nominal_gen\"]\n", + ")[0]" ] }, { @@ -110,7 +115,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloh_uncorr = input_tools.read_all_and_scale(\"../w_z_gen_dists_nnpdf31.pkl.lz4\", [\"WminusmunuPostVFP\"], [\"nominal_gen\"])[0]" + "minnloh_uncorr = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists_nnpdf31.pkl.lz4\", [\"WminusmunuPostVFP\"], [\"nominal_gen\"]\n", + ")[0]" ] }, { @@ -136,7 +143,7 @@ } ], "source": [ - "minnloh[{\"ptVgen\" : hist.rebin(minnloh.axes[\"ptVgen\"].size)}]" + "minnloh[{\"ptVgen\": hist.rebin(minnloh.axes[\"ptVgen\"].size)}]" ] }, { @@ -146,7 +153,10 @@ "metadata": {}, "outputs": [], "source": [ - "hh.divideHists(coeffs[...,3,1,1].project(\"ptVgen\", \"absYVgen\"), coeffs[...,2,1,1].project(\"ptVgen\", \"absYVgen\")).plot()" + "hh.divideHists(\n", + " coeffs[..., 3, 1, 1].project(\"ptVgen\", \"absYVgen\"),\n", + " coeffs[..., 2, 1, 1].project(\"ptVgen\", \"absYVgen\"),\n", + ").plot()" ] }, { @@ -156,7 +166,9 @@ "metadata": {}, "outputs": [], "source": [ - "res = pickle.load(lz4.frame.open(\"../wremnants/data/TheoryCorrections/dyturboYOnlyCorrW.pkl.lz4\"))" + "res = pickle.load(\n", + " lz4.frame.open(\"../wremnants/data/TheoryCorrections/dyturboYOnlyCorrW.pkl.lz4\")\n", + ")" ] }, { @@ -177,7 +189,7 @@ } ], "source": [ - "res[\"W\"][\"dyturboYOnly_minnlo_ratio\"][1644.39j, 0.696957j, 8.95676j, -1.j, 0]" + "res[\"W\"][\"dyturboYOnly_minnlo_ratio\"][1644.39j, 0.696957j, 8.95676j, -1.0j, 0]" ] }, { @@ -214,7 +226,9 @@ "metadata": {}, "outputs": [], "source": [ - "res = pickle.load(lz4.frame.open(\"../mw_with_mu_eta_pt_dyturboYOnlyCorr_nnpdf31.pkl.lz4\"))" + "res = pickle.load(\n", + " lz4.frame.open(\"../mw_with_mu_eta_pt_dyturboYOnlyCorr_nnpdf31.pkl.lz4\")\n", + ")" ] }, { @@ -271,16 +285,27 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [sel.unrolledHist(sel.signalHistABCD(corr)), \n", - " sel.unrolledHist(sel.signalHistABCD(uncorr))], \n", - " [\"DYTurbo y-corrected\", \"MiNNLO uncorr\",], \n", - " colors=['#66c2a5', 'orange',], \n", - " xlabel=\"$(p_{T}, \\eta$) bin\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/DYturbo\",\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " sel.unrolledHist(sel.signalHistABCD(corr)),\n", + " sel.unrolledHist(sel.signalHistABCD(uncorr)),\n", + " ],\n", + " [\n", + " \"DYTurbo y-corrected\",\n", + " \"MiNNLO uncorr\",\n", + " ],\n", + " colors=[\n", + " \"#66c2a5\",\n", + " \"orange\",\n", + " ],\n", + " xlabel=\"$(p_{T}, \\eta$) bin\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/DYturbo\",\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -290,7 +315,9 @@ "metadata": {}, "outputs": [], "source": [ - "res = pickle.load(lz4.frame.open(\"../mz_wlike_with_mu_eta_pt_dyturboYOnlyCorr_nnpdf31.pkl.lz4\"))\n", + "res = pickle.load(\n", + " lz4.frame.open(\"../mz_wlike_with_mu_eta_pt_dyturboYOnlyCorr_nnpdf31.pkl.lz4\")\n", + ")\n", "corrZ = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"nominal\")\n", "uncorrZ = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"nominal_uncorr\")" ] @@ -321,16 +348,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [sel.unrolledHist(corrZ), \n", - " sel.unrolledHist(uncorrZ)], \n", - " [\"DYTurbo y-corrected\", \"MiNNLO uncorr\",], \n", - " colors=['#66c2a5', 'orange',], \n", - " xlabel=\"$(p_{T}, \\eta$) bin\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/DYturbo\",\n", - " rrange=[0.98, 1.02],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [sel.unrolledHist(corrZ), sel.unrolledHist(uncorrZ)],\n", + " [\n", + " \"DYTurbo y-corrected\",\n", + " \"MiNNLO uncorr\",\n", + " ],\n", + " colors=[\n", + " \"#66c2a5\",\n", + " \"orange\",\n", + " ],\n", + " xlabel=\"$(p_{T}, \\eta$) bin\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/DYturbo\",\n", + " rrange=[0.98, 1.02],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -370,16 +405,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [corrZll.project(\"yll\"), \n", - " uncorrZll.project(\"yll\")], \n", - " [\"DYTurbo y-corrected\", \"MiNNLO uncorr\",], \n", - " colors=['#66c2a5', 'orange',], \n", - " xlabel=\"$(p_{T}, \\eta$) bin\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/DYturbo\",\n", - " rrange=[0.98, 1.02],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [corrZll.project(\"yll\"), uncorrZll.project(\"yll\")],\n", + " [\n", + " \"DYTurbo y-corrected\",\n", + " \"MiNNLO uncorr\",\n", + " ],\n", + " colors=[\n", + " \"#66c2a5\",\n", + " \"orange\",\n", + " ],\n", + " xlabel=\"$(p_{T}, \\eta$) bin\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/DYturbo\",\n", + " rrange=[0.98, 1.02],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] } ], diff --git a/notebooks/mTResolution.ipynb b/notebooks/mTResolution.ipynb index 92f2c0003..ac878e84f 100644 --- a/notebooks/mTResolution.ipynb +++ b/notebooks/mTResolution.ipynb @@ -15,7 +15,7 @@ "metadata": {}, "outputs": [], "source": [ - "from utilities.io_tools import input_tools,output_tools\n", + "from utilities.io_tools import input_tools, output_tools\n", "from wremnants import histselections as hs\n", "from wremnants import plot_tools\n", "import hist\n", @@ -42,8 +42,14 @@ "metadata": {}, "outputs": [], "source": [ - "pt = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_noMTCut.hdf5\", \"WplusmunuPostVFP\", \"nominal_massWeightW\"))\n", - "pt = pt/pt[{\"pt\" : ptsel, \"massShift\" : \"massShiftW0MeV\"}].sum()" + "pt = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_noMTCut.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_massWeightW\",\n", + " )\n", + ")\n", + "pt = pt / pt[{\"pt\": ptsel, \"massShift\": \"massShiftW0MeV\"}].sum()" ] }, { @@ -53,8 +59,14 @@ "metadata": {}, "outputs": [], "source": [ - "pt_uncorr = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_noMTCut.hdf5\", \"WplusmunuPostVFP\", \"nominal_uncorr\"))\n", - "pt_uncorr = pt_uncorr/pt_uncorr[{\"pt\" : ptsel}].sum()" + "pt_uncorr = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_noMTCut.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_uncorr\",\n", + " )\n", + ")\n", + "pt_uncorr = pt_uncorr / pt_uncorr[{\"pt\": ptsel}].sum()" ] }, { @@ -64,7 +76,11 @@ "metadata": {}, "outputs": [], "source": [ - "mt_pfmet_mu4 = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_pfMet_mu4.hdf5\", \"Wplusmunu\", \"transverseMass\")" + "mt_pfmet_mu4 = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_pfMet_mu4.hdf5\",\n", + " \"Wplusmunu\",\n", + " \"transverseMass\",\n", + ")" ] }, { @@ -74,7 +90,11 @@ "metadata": {}, "outputs": [], "source": [ - "mt_pfmet_mu4_mw = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_pfMet_mu4.hdf5\", \"Wplusmunu\", \"transverseMass_massWeightW\")" + "mt_pfmet_mu4_mw = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_pfMet_mu4.hdf5\",\n", + " \"Wplusmunu\",\n", + " \"transverseMass_massWeightW\",\n", + ")" ] }, { @@ -94,8 +114,12 @@ "metadata": {}, "outputs": [], "source": [ - "mt_pfmet_highpu_mw = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_MtPFMET_ptlcut.hdf5\", \"WplusmunuPostVFP\", \"nominal_massWeightW\")\n", - "mt_pfmet_highpu_mw *= 1/mt_pfmet_highpu_mw[{\"massShift\" : \"massShiftW0MeV\"}].sum()" + "mt_pfmet_highpu_mw = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_MtPFMET_ptlcut.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_massWeightW\",\n", + ")\n", + "mt_pfmet_highpu_mw *= 1 / mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW0MeV\"}].sum()" ] }, { @@ -105,8 +129,12 @@ "metadata": {}, "outputs": [], "source": [ - "mt_pfmet_highpu_uncorr = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_MtPFMET_ptlcut.hdf5\", \"WplusmunuPostVFP\", \"nominal_uncorr\")\n", - "mt_pfmet_highpu_uncorr *= 1/mt_pfmet_highpu_uncorr.sum()" + "mt_pfmet_highpu_uncorr = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_MtPFMET_ptlcut.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_uncorr\",\n", + ")\n", + "mt_pfmet_highpu_uncorr *= 1 / mt_pfmet_highpu_uncorr.sum()" ] }, { @@ -116,8 +144,12 @@ "metadata": {}, "outputs": [], "source": [ - "mt_gen = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_fiducial.hdf5\", \"WplusmunuPostVFP\", \"mt\")\n", - "mt_gen = mt_gen/mt_gen.sum().value" + "mt_gen = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists_fiducial.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"mt\",\n", + ")\n", + "mt_gen = mt_gen / mt_gen.sum().value" ] }, { @@ -127,12 +159,16 @@ "metadata": {}, "outputs": [], "source": [ - "pt_gen = input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists.hdf5\", \"WplusmunuPostVFP\", \"nominal_postfsr\")\n", - "#pt_gen = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"WplusmunuPostVFP\", \"genPt\"))\n", + "pt_gen = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_postfsr\",\n", + ")\n", + "# pt_gen = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"WplusmunuPostVFP\", \"genPt\"))\n", "if \"postfsrLep_pt\" in pt_gen.axes.name:\n", " pt_gen.axes[\"postfsrLep_pt\"]._ax.metadata[\"name\"] = \"pt\"\n", - "pt_gen = pt_gen[{\"pt\" : ptsel}]\n", - "pt_gen = pt_gen/pt_gen.sum().value" + "pt_gen = pt_gen[{\"pt\": ptsel}]\n", + "pt_gen = pt_gen / pt_gen.sum().value" ] }, { @@ -984,12 +1020,25 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hs.signalHistWmass(h).project(\"mt\")[40j:100j]\n", - " for h in ([mt_pfmet_mu2_mw[{\"massShift\": v}] for v in [\"massShiftW0MeV\", \"massShiftW20MeVUp\", \"massShiftW20MeVDown\"]]+\n", - " [mt_pfmet_highpu_mw[{\"massShift\": v}] for v in [\"massShiftW0MeV\", \"massShiftW20MeVUp\", \"massShiftW20MeVDown\"]])\n", + " [\n", + " hs.signalHistWmass(h).project(\"mt\")[40j:100j]\n", + " for h in (\n", + " [\n", + " mt_pfmet_mu2_mw[{\"massShift\": v}]\n", + " for v in [\"massShiftW0MeV\", \"massShiftW20MeVUp\", \"massShiftW20MeVDown\"]\n", + " ]\n", + " + [\n", + " mt_pfmet_highpu_mw[{\"massShift\": v}]\n", + " for v in [\"massShiftW0MeV\", \"massShiftW20MeVUp\", \"massShiftW20MeVDown\"]\n", + " ]\n", + " )\n", " ],\n", " [\"nominal\", \"$m_{W} \\pm 20\\,$MeV\", \"\", \"highPU\", \"test\", \"\"],\n", - " [\"black\", \"grey\", \"grey\", \"red\", \"pink\", \"pink\"], binwnorm=1., rrange=[0.99, 1.01], xlim=[40, 100])" + " [\"black\", \"grey\", \"grey\", \"red\", \"pink\", \"pink\"],\n", + " binwnorm=1.0,\n", + " rrange=[0.99, 1.01],\n", + " xlim=[40, 100],\n", + ")" ] }, { @@ -1011,19 +1060,42 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [h.project(\"mt\")[40j:120j]\n", - " for h in [mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW0MeV\"}], \n", - " mt_pfmet_highpu_uncorr,\n", - " mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW100MeVUp\"}],\n", - " mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW100MeVDown\"}],\n", - " mt_gen,\n", - " ]\n", + " [\n", + " h.project(\"mt\")[40j:120j]\n", + " for h in [\n", + " mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW0MeV\"}],\n", + " mt_pfmet_highpu_uncorr,\n", + " mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW100MeVUp\"}],\n", + " mt_pfmet_highpu_mw[{\"massShift\": \"massShiftW100MeVDown\"}],\n", + " mt_gen,\n", + " ]\n", + " ],\n", + " [\n", + " \"$m_T^{reco.}(\\\\ell, p_{T}^{miss})$\",\n", + " \"$m_T^{reco}(\\\\ell, p_{T}^{miss})$ w/ $p_{T}^{W}$ var.\",\n", + " \"$m_{W} = 80379 \\pm 100\\, MeV$\",\n", + " \"\",\n", + " \"$m_T^{true}(\\\\ell, \\\\nu)$\",\n", + " ],\n", + " [\n", + " \"black\",\n", + " \"#984ea3\",\n", + " \"#377eb8\",\n", + " \"#377eb8\",\n", + " \"#4daf4a\",\n", " ],\n", - " [\"$m_T^{reco.}(\\\\ell, p_{T}^{miss})$\", \"$m_T^{reco}(\\\\ell, p_{T}^{miss})$ w/ $p_{T}^{W}$ var.\", \"$m_{W} = 80379 \\pm 100\\, MeV$\", \"\", \"$m_T^{true}(\\\\ell, \\\\nu)$\",],\n", - " [\"black\", \"#984ea3\", \"#377eb8\", \"#377eb8\", \"#4daf4a\", ], \n", - " xlabel=\"$m_{T}^W$ (GeV)\", ylabel=\"A.U.\",\n", - " binwnorm=1., rrange=[0.98, 1.02], xlim=[40, 120], yscale=1.3,rlabel=\"var./nom.\",\n", - " cms_label=\"Simulation, Private Work\", skip_ratio=1, legtext_size=22, nlegcols=2)\n", + " xlabel=\"$m_{T}^W$ (GeV)\",\n", + " ylabel=\"A.U.\",\n", + " binwnorm=1.0,\n", + " rrange=[0.98, 1.02],\n", + " xlim=[40, 120],\n", + " yscale=1.3,\n", + " rlabel=\"var./nom.\",\n", + " cms_label=\"Simulation, Private Work\",\n", + " skip_ratio=1,\n", + " legtext_size=22,\n", + " nlegcols=2,\n", + ")\n", "out = \"/eos/user/k/kelong/www/WMassAnalysis/SNSFStudies\"\n", "dir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "out = os.path.join(out, \"W\")\n", @@ -1060,26 +1132,48 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [hh.projectNoFlow(h, \"pt\")\n", - " for h in [pt[{\"massShift\": \"massShiftW0MeV\"}], \n", - " pt_uncorr,\n", - " pt[{\"massShift\": \"massShiftW100MeVUp\"}],\n", - " pt[{\"massShift\": \"massShiftW100MeVDown\"}],\n", - " pt[...,10],\n", - " ]\n", + " [\n", + " hh.projectNoFlow(h, \"pt\")\n", + " for h in [\n", + " pt[{\"massShift\": \"massShiftW0MeV\"}],\n", + " pt_uncorr,\n", + " pt[{\"massShift\": \"massShiftW100MeVUp\"}],\n", + " pt[{\"massShift\": \"massShiftW100MeVDown\"}],\n", + " pt[..., 10],\n", + " ]\n", + " ],\n", + " [\n", + " \"$p_T^{\\\\ell,reco.}$\",\n", + " \"$p_T^{\\\\ell,reco}$ w/ $p_{T}^{W}$ var.\",\n", + " \"$m_{W} = 80379 \\pm 100\\, MeV$\",\n", + " \"\",\n", + " \"$p_T^{\\\\ell,true}$\",\n", " ],\n", - " [\"$p_T^{\\\\ell,reco.}$\", \"$p_T^{\\\\ell,reco}$ w/ $p_{T}^{W}$ var.\", \"$m_{W} = 80379 \\pm 100\\, MeV$\", \"\", \"$p_T^{\\\\ell,true}$\",],\n", - " [\"black\", \"#984ea3\", \"#377eb8\", \"#377eb8\", \"#4daf4a\", ], \n", - " xlabel=\"$p_{T}^\\\\ell$ (GeV)\", ylabel=\"A.U.\",\n", - " binwnorm=1., rrange=[0.98, 1.02], yscale=1.3,rlabel=\"var./nom.\",\n", - " #cms_label=\"Simulation, Private Work\", skip_ratio=1, legtext_size=24, nlegcols=2)\n", - " cms_label=\"Simulation\", skip_ratio=1, legtext_size=24, nlegcols=2)\n", + " [\n", + " \"black\",\n", + " \"#984ea3\",\n", + " \"#377eb8\",\n", + " \"#377eb8\",\n", + " \"#4daf4a\",\n", + " ],\n", + " xlabel=\"$p_{T}^\\\\ell$ (GeV)\",\n", + " ylabel=\"A.U.\",\n", + " binwnorm=1.0,\n", + " rrange=[0.98, 1.02],\n", + " yscale=1.3,\n", + " rlabel=\"var./nom.\",\n", + " # cms_label=\"Simulation, Private Work\", skip_ratio=1, legtext_size=24, nlegcols=2)\n", + " cms_label=\"Simulation\",\n", + " skip_ratio=1,\n", + " legtext_size=24,\n", + " nlegcols=2,\n", + ")\n", "out = \"/eos/user/k/kelong/www/WMassAnalysis/SNSFStudies\"\n", "dir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "out = os.path.join(out, \"W\")\n", "plot_tools.save_pdf_and_png(dir, \"compareRecoGenPtl_recoMatch\")\n", "plot_tools.write_index_and_log(dir, \"compareRecoGenPtl_recoMatch\")\n", - "output_tools.copy_to_eos(out)\n" + "output_tools.copy_to_eos(out)" ] }, { @@ -1089,7 +1183,13 @@ "metadata": {}, "outputs": [], "source": [ - "mt_mu23 = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"WplusmunuPostVFP\", \"transverseMass\"))" + "mt_mu23 = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"transverseMass\",\n", + " )\n", + ")" ] }, { @@ -1099,7 +1199,13 @@ "metadata": {}, "outputs": [], "source": [ - "mt_mu23_pf = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_mT_PFMET.hdf5\", \"WplusmunuPostVFP\", \"transverseMass\"))" + "mt_mu23_pf = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_with_mu_eta_pt_scetlib_dyturboCorr_mT_PFMET.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"transverseMass\",\n", + " )\n", + ")" ] }, { @@ -1109,7 +1215,13 @@ "metadata": {}, "outputs": [], "source": [ - "mt_mu2_pf = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_mu1.hdf5\", \"Wplusmunu\", \"transverseMass\"))" + "mt_mu2_pf = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_mu1.hdf5\",\n", + " \"Wplusmunu\",\n", + " \"transverseMass\",\n", + " )\n", + ")" ] }, { @@ -1119,7 +1231,13 @@ "metadata": {}, "outputs": [], "source": [ - "mt_mu5_pf = hs.signalHistWmass(input_tools.read_and_scale(\"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_mu4.hdf5\", \"Wplusmunu\", \"transverseMass\"))" + "mt_mu5_pf = hs.signalHistWmass(\n", + " input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/kdlong/Analysis/mw_lowPU_mu_scetlib_dyturboCorr_mu4.hdf5\",\n", + " \"Wplusmunu\",\n", + " \"transverseMass\",\n", + " )\n", + ")" ] }, { @@ -1140,13 +1258,37 @@ } ], "source": [ - "hs.signalHistWmass(mt_mu23).project(\"mt\")[40j:100j].plot(density=True, label=\"DeepMET $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 23$\", flow='none', color=\"#1b9e77\")\n", - "hs.signalHistWmass(mt_mu23_pf).project(\"mt\")[40j:100j].plot(density=True, label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 23$\", flow='none', color=\"#d95f02\")\n", - "hs.signalHistWmass(mt_mu2_pf).project(\"mt\")[40j:100j].plot(density=True, label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 2$\", flow='none', color=\"#7570b3\")\n", - "a = hs.signalHistWmass(mt_mu5_pf).project(\"mt\")[40j:100j].plot(density=True, label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 5$\", flow='none', color=\"#e7298a\")\n", - "plt.legend(loc='upper center', ncol=2)\n", - "plt.xlim([40,100])\n", - "plt.ylim([0, .042])\n", + "hs.signalHistWmass(mt_mu23).project(\"mt\")[40j:100j].plot(\n", + " density=True,\n", + " label=\"DeepMET $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 23$\",\n", + " flow=\"none\",\n", + " color=\"#1b9e77\",\n", + ")\n", + "hs.signalHistWmass(mt_mu23_pf).project(\"mt\")[40j:100j].plot(\n", + " density=True,\n", + " label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 23$\",\n", + " flow=\"none\",\n", + " color=\"#d95f02\",\n", + ")\n", + "hs.signalHistWmass(mt_mu2_pf).project(\"mt\")[40j:100j].plot(\n", + " density=True,\n", + " label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 2$\",\n", + " flow=\"none\",\n", + " color=\"#7570b3\",\n", + ")\n", + "a = (\n", + " hs.signalHistWmass(mt_mu5_pf)\n", + " .project(\"mt\")[40j:100j]\n", + " .plot(\n", + " density=True,\n", + " label=\"PF $p_{T}^{miss}$ $\\\\langle\\\\mu\\\\rangle = 5$\",\n", + " flow=\"none\",\n", + " color=\"#e7298a\",\n", + " )\n", + ")\n", + "plt.legend(loc=\"upper center\", ncol=2)\n", + "plt.xlim([40, 100])\n", + "plt.ylim([0, 0.042])\n", "plt.xlabel(\"$m_{T}^W$ (GeV)\")\n", "plt.ylabel(\"A.U.\")\n", "hep.cms.label(fontsize=20, data=False, label=\"Preliminary\")\n", @@ -1203,25 +1345,31 @@ } ], "source": [ - "df = pd.DataFrame.from_dict({\"Total\" : [33, 23, 15, 12],\n", - " \"Data stat.\" : [17, 11, 6.5, 5.5], \n", - " \"Background\" : [16, 10, 6, 5],\n", - " \"Theory\" : [9, 8, 6.8, 6],\n", - " \"PDF\" : [14, 10, 7, 5],\n", - " \"Recoil calib.\" : [14, 9, 6, 5],\n", - " \"Other\" : [5.5, 5.1, 4.9, 4.8],\n", - " \"lumi\" : [0.2, 0.5, 1.0, 2.0],\n", - " })\n", - "df.plot.line(x=\"lumi\", marker=\"o\",\n", - " color={\"Total\" : \"black\", \n", - " \"Data stat.\" : \"#1f78b4\",\n", - " \"Background\" : \"#b2df8a\",\n", - " \"Theory\" : \"#33a02c\",\n", - " \"PDF\" : \"#fb9a99\",\n", - " \"Recoil calib.\" : \"#e31a1c\",\n", - " \"Other\" : \"#fdbf6f\",\n", + "df = pd.DataFrame.from_dict(\n", + " {\n", + " \"Total\": [33, 23, 15, 12],\n", + " \"Data stat.\": [17, 11, 6.5, 5.5],\n", + " \"Background\": [16, 10, 6, 5],\n", + " \"Theory\": [9, 8, 6.8, 6],\n", + " \"PDF\": [14, 10, 7, 5],\n", + " \"Recoil calib.\": [14, 9, 6, 5],\n", + " \"Other\": [5.5, 5.1, 4.9, 4.8],\n", + " \"lumi\": [0.2, 0.5, 1.0, 2.0],\n", " }\n", ")\n", + "df.plot.line(\n", + " x=\"lumi\",\n", + " marker=\"o\",\n", + " color={\n", + " \"Total\": \"black\",\n", + " \"Data stat.\": \"#1f78b4\",\n", + " \"Background\": \"#b2df8a\",\n", + " \"Theory\": \"#33a02c\",\n", + " \"PDF\": \"#fb9a99\",\n", + " \"Recoil calib.\": \"#e31a1c\",\n", + " \"Other\": \"#fdbf6f\",\n", + " },\n", + ")\n", "plt.xlim([0.2, 2.0])\n", "hep.cms.label(fontsize=20, data=False, label=\"Projection\", com=13.6)\n", "plt.xlabel(\"Integrated luminosity (fb$^{-1})$\")\n", @@ -1257,7 +1405,7 @@ } ], "source": [ - "df.iloc[0,2:]" + "df.iloc[0, 2:]" ] }, { @@ -1295,7 +1443,7 @@ ], "source": [ "for i in range(len(df)):\n", - " print(df[\"Total\"][i], math.sqrt(sum(pow(df.iloc[i,1:],2))))" + " print(df[\"Total\"][i], math.sqrt(sum(pow(df.iloc[i, 1:], 2))))" ] } ], diff --git a/notebooks/mWPostfit.ipynb b/notebooks/mWPostfit.ipynb index 1990241d4..3db95eec2 100644 --- a/notebooks/mWPostfit.ipynb +++ b/notebooks/mWPostfit.ipynb @@ -9,7 +9,7 @@ "source": [ "from wremnants import plot_tools\n", "import matplotlib.pyplot as plt\n", - "from utilities.io_tools import combinetf_input,output_tools\n", + "from utilities.io_tools import combinetf_input, output_tools\n", "import uproot\n", "import numpy as np\n", "import hist" @@ -54,7 +54,13 @@ "outputs": [], "source": [ "def pt_hist(h):\n", - " return hist.Hist(eta_ax, charge_ax, data=np.sum(np.split(h.values(), eta_ax.size), axis=0).reshape((pt_ax.size, eta_ax.size, charge_ax.size)))" + " return hist.Hist(\n", + " eta_ax,\n", + " charge_ax,\n", + " data=np.sum(np.split(h.values(), eta_ax.size), axis=0).reshape(\n", + " (pt_ax.size, eta_ax.size, charge_ax.size)\n", + " ),\n", + " )" ] }, { @@ -65,7 +71,12 @@ "outputs": [], "source": [ "def full_hist(h):\n", - " return hist.Hist(eta_ax, pt_ax, charge_ax, data=h.values().reshape((eta_ax.size, pt_ax.size, charge_ax.size)))" + " return hist.Hist(\n", + " eta_ax,\n", + " pt_ax,\n", + " charge_ax,\n", + " data=h.values().reshape((eta_ax.size, pt_ax.size, charge_ax.size)),\n", + " )" ] }, { @@ -75,7 +86,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult = uproot.open(\"/scratch/dwalter/CombineStudies/240819_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.root\")\n", + "fitresult = uproot.open(\n", + " \"/scratch/dwalter/CombineStudies/240819_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.root\"\n", + ")\n", "prefit_fake = fitresult[\"expproc_Fake_prefit\"].to_hist()\n", "postfit_fake = fitresult[\"expproc_Fake_postfit\"].to_hist()" ] @@ -106,7 +119,7 @@ "metadata": {}, "outputs": [], "source": [ - "out, outfolder = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded\", \"W\"\n" + "out, outfolder = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded\", \"W\"" ] }, { @@ -128,13 +141,15 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [prefit_fake_pt.project(\"pt\"), \n", - " postfit_fake_pt.project(\"pt\")\n", + " [prefit_fake_pt.project(\"pt\"), postfit_fake_pt.project(\"pt\")],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", " ],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit\", \"postfit\"], \n", - " rrange=[.5, 3], \n", - " binwnorm=1.)" + " labels=[\"prefit\", \"postfit\"],\n", + " rrange=[0.5, 3],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -152,7 +167,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_hybrid = uproot.open(\"/scratch/dwalter/CombineStudies/240819_mw_unblinding/WMass_eta_pt_charge_hybrid/fitresults_123456789_data.root\")\n", + "fitresult_hybrid = uproot.open(\n", + " \"/scratch/dwalter/CombineStudies/240819_mw_unblinding/WMass_eta_pt_charge_hybrid/fitresults_123456789_data.root\"\n", + ")\n", "prefit_hybrid = fitresult_hybrid[\"expproc_Fake_prefit\"].to_hist()\n", "postfit_hybrid = fitresult_hybrid[\"expproc_Fake_postfit\"].to_hist()" ] @@ -195,12 +212,15 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [prefit_hybrid_pt.project(\"pt\"), \n", - " psotfit_hybrid_pt.project(\"pt\")],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit hybrid\", \"postfit hybrid\"], \n", - " rrange=[.5, 3], \n", - " binwnorm=1.)" + " [prefit_hybrid_pt.project(\"pt\"), psotfit_hybrid_pt.project(\"pt\")],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\"prefit hybrid\", \"postfit hybrid\"],\n", + " rrange=[0.5, 3],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -231,10 +251,14 @@ "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", " [prefit_fake_pt.project(\"pt\"), prefit_hybrid_pt.project(\"pt\")],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit nominal\", \"prefit hybrid\"], \n", - " rrange=[.8, 1.2], \n", - " binwnorm=1.)" + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\"prefit nominal\", \"prefit hybrid\"],\n", + " rrange=[0.8, 1.2],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -257,10 +281,14 @@ "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", " [postfit_fake_pt.project(\"pt\"), postfit_hybrid_pt.project(\"pt\")],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"postfit nominal\", \"postfit hybrid\"], \n", - " rrange=[.8, 1.2], \n", - " binwnorm=1.)" + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\"postfit nominal\", \"postfit hybrid\"],\n", + " rrange=[0.8, 1.2],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -290,7 +318,7 @@ "outputs": [], "source": [ "prefit_pt_all = full_hist(prefit_all)\n", - "postfit_pt_all = full_hist(postfit_all)\n" + "postfit_pt_all = full_hist(postfit_all)" ] }, { @@ -313,10 +341,14 @@ "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", " [prefit_pt_all.project(\"pt\"), postfit_pt_all.project(\"pt\")],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit all\", \"postfit all\"], \n", - " rrange=[.95, 1.05], \n", - " binwnorm=1.)" + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\"prefit all\", \"postfit all\"],\n", + " rrange=[0.95, 1.05],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -388,10 +420,14 @@ " prefit_w_pt.project(\"pt\"),\n", " postfit_w_pt.project(\"pt\"),\n", " ],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit all\", \"postfit all\"], \n", - " rrange=[.95, 1.05], \n", - " binwnorm=1.)" + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\"prefit all\", \"postfit all\"],\n", + " rrange=[0.95, 1.05],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -412,7 +448,7 @@ } ], "source": [ - "postfit_newnom.sum()/prefit_newnom.sum()" + "postfit_newnom.sum() / prefit_newnom.sum()" ] }, { @@ -422,7 +458,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_new = uproot.open(\"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.root\")\n", + "fitresult_new = uproot.open(\n", + " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.root\"\n", + ")\n", "postfit_newnom = full_hist(fitresult_new[\"expproc_Fake_postfit\"].to_hist())\n", "prefit_newnom = full_hist(fitresult_new[\"expproc_Fake_prefit\"].to_hist())" ] @@ -446,18 +484,25 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_newnom, \n", - " postfit_newnom,\n", - " postfit_fake_pt,\n", - " ]],\n", - " colors=[\"blue\", \"black\", \"red\",], \n", - " labels=[\"prefit nominal\", \"postfit nominal\", \"postfit nom, old\"], \n", - " rrange=[.5, 3], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_newnom,\n", + " postfit_newnom,\n", + " postfit_fake_pt,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " labels=[\"prefit nominal\", \"postfit nominal\", \"postfit nom, old\"],\n", + " rrange=[0.5, 3],\n", " rlabel=\"post/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -467,9 +512,11 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_hybnew = uproot.open(\"/eos/cms/store/cmst3/group/wmass/results_Aug20_51483092e6/WMass_eta_pt_charge_hybrid/fitresults_123456789_unblind.root\")\n", + "fitresult_hybnew = uproot.open(\n", + " \"/eos/cms/store/cmst3/group/wmass/results_Aug20_51483092e6/WMass_eta_pt_charge_hybrid/fitresults_123456789_unblind.root\"\n", + ")\n", "postfit_hybnew = full_hist(fitresult_hybnew[\"expproc_Fake_postfit\"].to_hist())\n", - "prefit_hybnew =full_hist(fitresult_hybnew[\"expproc_Fake_prefit\"].to_hist())" + "prefit_hybnew = full_hist(fitresult_hybnew[\"expproc_Fake_prefit\"].to_hist())" ] }, { @@ -491,18 +538,25 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_hybnew, \n", - " postfit_hybnew,\n", - " postfit_hybrid_pt,\n", - " ]],\n", - " colors=[\"blue\", \"black\", \"red\",], \n", - " labels=[\"prefit hybrid\", \"postfit hybrid\", \"postfit hybrid, old\"], \n", - " rrange=[.5, 3], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_hybnew,\n", + " postfit_hybnew,\n", + " postfit_hybrid_pt,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " labels=[\"prefit hybrid\", \"postfit hybrid\", \"postfit hybrid, old\"],\n", + " rrange=[0.5, 3],\n", " rlabel=\"post/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -524,21 +578,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " postfit_newnom, \n", - " postfit_hybnew,\n", - " postfit_fake_pt,\n", - " postfit_hybrid_pt,\n", - " ]],\n", - " colors=[\"blue\", \"black\", \"red\", \"green\"], \n", - " labels=[\"postfit nominal\", \"postfit hybrid\", \"postfit nom. old\", \"postfit hybrid old\"], \n", - " rrange=[.7, 1.3], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " postfit_newnom,\n", + " postfit_hybnew,\n", + " postfit_fake_pt,\n", + " postfit_hybrid_pt,\n", + " ]\n", + " ],\n", + " colors=[\"blue\", \"black\", \"red\", \"green\"],\n", + " labels=[\n", + " \"postfit nominal\",\n", + " \"postfit hybrid\",\n", + " \"postfit nom. old\",\n", + " \"postfit hybrid old\",\n", + " ],\n", + " rrange=[0.7, 1.3],\n", " rlabel=\"x/nominal\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "ax1, ax2 = fig.get_axes()\n", - "ax1.ticklabel_format(style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4,4), useLocale=True)\n", + "ax1.ticklabel_format(\n", + " style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4, 4), useLocale=True\n", + ")\n", "ax1.yaxis.get_offset_text().set_x(-0.08)" ] }, @@ -568,7 +632,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_nonc = uproot.open(\"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789.root\")\n", + "fitresult_nonc = uproot.open(\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789.root\"\n", + ")\n", "postfit_nonc = full_hist(fitresult_nonc[\"expproc_Fake_postfit\"].to_hist())\n", "prefit_nonc = full_hist(fitresult_nonc[\"expproc_Fake_prefit\"].to_hist())" ] @@ -599,19 +665,28 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_nonc, \n", - " postfit_nonc,\n", - " ]],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit\", \"postfit, no param. unc.\",], \n", - " rrange=[.5, 2], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_nonc,\n", + " postfit_nonc,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\n", + " \"prefit\",\n", + " \"postfit, no param. unc.\",\n", + " ],\n", + " rrange=[0.5, 2],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)\n", - "#ax1, ax2 = fig.get_axes()\n", - "#x1.ticklabel_format(style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4,4), useLocale=True)\n", + " binwnorm=1.0,\n", + ")\n", + "# ax1, ax2 = fig.get_axes()\n", + "# x1.ticklabel_format(style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4,4), useLocale=True)\n", "name = \"fakes_PostfitVsPrefitNominalNoParamUnc_pt\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", @@ -638,19 +713,30 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " postfit_nonc[{\"charge\" : 0}], \n", - " postfit_nonc[{\"charge\" : 1}],\n", - " ]],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"postfit+\", \"postfit-\",], \n", - " rrange=[.95, 1.05], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " postfit_nonc[{\"charge\": 0}],\n", + " postfit_nonc[{\"charge\": 1}],\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\n", + " \"postfit+\",\n", + " \"postfit-\",\n", + " ],\n", + " rrange=[0.95, 1.05],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "ax1, ax2 = fig.get_axes()\n", - "ax1.ticklabel_format(style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4,4), useLocale=True)\n", + "ax1.ticklabel_format(\n", + " style=\"sci\", useMathText=True, axis=\"y\", scilimits=(4, 4), useLocale=True\n", + ")\n", "ax1.yaxis.get_offset_text().set_x(-0.08)" ] }, @@ -661,7 +747,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_smoothfr = uproot.open(\"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_smoothFR//fitresults_123456789.root\")\n", + "fitresult_smoothfr = uproot.open(\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_smoothFR//fitresults_123456789.root\"\n", + ")\n", "postfit_smoothfr = full_hist(fitresult_smoothfr[\"expproc_Fake_postfit\"].to_hist())\n", "prefit_smoothfr = full_hist(fitresult_smoothfr[\"expproc_Fake_prefit\"].to_hist())" ] @@ -685,17 +773,26 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_smoothfr, \n", - " postfit_smoothfr,\n", - " ]],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit\", \"postfit, smoothfr\",], \n", - " rrange=[.5, 1.5], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_smoothfr,\n", + " postfit_smoothfr,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\n", + " \"prefit\",\n", + " \"postfit, smoothfr\",\n", + " ],\n", + " rrange=[0.5, 1.5],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -705,7 +802,9 @@ "metadata": {}, "outputs": [], "source": [ - "fitresult_binned = uproot.open(\"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_binnedFake//fitresults_123456789.root\")\n", + "fitresult_binned = uproot.open(\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_binnedFake//fitresults_123456789.root\"\n", + ")\n", "postfit_binned = full_hist(fitresult_binned[\"expproc_Fake_postfit\"].to_hist())\n", "prefit_binned = full_hist(fitresult_binned[\"expproc_Fake_prefit\"].to_hist())" ] @@ -729,17 +828,26 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_binned, \n", - " postfit_binned,\n", - " ]],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit\", \"postfit, binned\",], \n", - " rrange=[.5, 2], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_binned,\n", + " postfit_binned,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\n", + " \"prefit\",\n", + " \"postfit, binned\",\n", + " ],\n", + " rrange=[0.5, 2],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -782,20 +890,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " postfit_newnom, \n", - " postfit_nonc,\n", - " postfit_smoothfr,\n", - " postfit_hybnew,\n", - " postfit_binned\n", - " ]],\n", - " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.25, 1.5], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " postfit_newnom,\n", + " postfit_nonc,\n", + " postfit_smoothfr,\n", + " postfit_hybnew,\n", + " postfit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"],\n", + " rrange=[0.25, 1.5],\n", " rlabel=\"x/nominal\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -824,20 +935,23 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_newnom, \n", - " prefit_nonc,\n", - " prefit_smoothfr,\n", - " prefit_hybnew,\n", - " prefit_binned\n", - " ]],\n", - " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.5, 1.5], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_newnom,\n", + " prefit_nonc,\n", + " prefit_smoothfr,\n", + " prefit_hybnew,\n", + " prefit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"],\n", + " rrange=[0.5, 1.5],\n", " rlabel=\"x/nominal\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "name = \"fakes_PostfitScan_pt\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", @@ -871,17 +985,26 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_newnom, \n", - " postfit_newnom,\n", - " ]],\n", - " colors=[\"blue\", \"black\",], \n", - " labels=[\"prefit nominal\", \"postfit nominal\",], \n", - " rrange=[.5, 2.5], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_newnom,\n", + " postfit_newnom,\n", + " ]\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"black\",\n", + " ],\n", + " labels=[\n", + " \"prefit nominal\",\n", + " \"postfit nominal\",\n", + " ],\n", + " rrange=[0.5, 2.5],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "name = \"fakes_PostfitVsPrefitNominal_pt\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", @@ -908,21 +1031,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"eta\") for x in \n", " [\n", - " postfit_newnom, \n", - " postfit_nonc,\n", - " postfit_smoothfr,\n", - " postfit_hybnew,\n", - " postfit_binned\n", - " ]],\n", - " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.25, 1.5], \n", + " x.project(\"eta\")\n", + " for x in [\n", + " postfit_newnom,\n", + " postfit_nonc,\n", + " postfit_smoothfr,\n", + " postfit_hybnew,\n", + " postfit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"],\n", + " rrange=[0.25, 1.5],\n", " rlabel=\"x/nominal\",\n", " xlabel=\"$\\eta$\",\n", " yscale=1.2,\n", - " binwnorm=1.)" + " binwnorm=1.0,\n", + ")" ] }, { @@ -951,21 +1077,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"eta\") for x in \n", " [\n", - " prefit_newnom, \n", - " prefit_nonc,\n", - " prefit_smoothfr,\n", - " prefit_hybnew,\n", - " prefit_binned\n", - " ]],\n", - " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.8, 1.2], \n", + " x.project(\"eta\")\n", + " for x in [\n", + " prefit_newnom,\n", + " prefit_nonc,\n", + " prefit_smoothfr,\n", + " prefit_hybnew,\n", + " prefit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"],\n", + " rrange=[0.8, 1.2],\n", " rlabel=\"x/nominal\",\n", " xlabel=\"$\\eta$\",\n", " yscale=1.2,\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "name = \"fakes_PrefitScan_eta\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", @@ -999,23 +1128,32 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"eta\") for x in \n", " [\n", - " prefit_newnom,\n", - " postfit_newnom, \n", - " postfit_nonc,\n", - " postfit_smoothfr,\n", - " postfit_hybnew,\n", - " postfit_binned\n", - " ]],\n", - " colors=[\"black\", \n", - " \"navy\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal prefit\", \"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.25, 1.5], \n", + " x.project(\"eta\")\n", + " for x in [\n", + " prefit_newnom,\n", + " postfit_newnom,\n", + " postfit_nonc,\n", + " postfit_smoothfr,\n", + " postfit_hybnew,\n", + " postfit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"navy\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\n", + " \"Nominal prefit\",\n", + " \"Nominal\",\n", + " \"Nominal, no param unc\",\n", + " \"Smooth Fake rate\",\n", + " \"Hybrid\",\n", + " \"Binned\",\n", + " ],\n", + " rrange=[0.25, 1.5],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$\\eta$\",\n", " yscale=1.2,\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "name = \"fakes_postfitScanVsPrefitNom_eta\"\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", "plot_tools.write_index_and_log(outdir, name)\n", @@ -1048,23 +1186,32 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"pt\") for x in \n", " [\n", - " prefit_newnom,\n", - " postfit_newnom, \n", - " postfit_nonc,\n", - " postfit_smoothfr,\n", - " postfit_hybnew,\n", - " postfit_binned\n", - " ]],\n", - " colors=[\"black\", \n", - " \"navy\", \"blue\", \"red\", \"green\", \"purple\"], \n", - " labels=[\"Nominal prefit\", \"Nominal\", \"Nominal, no param unc\", \"Smooth Fake rate\", \"Hybrid\", \"Binned\"], \n", - " rrange=[.25, 2.5], \n", + " x.project(\"pt\")\n", + " for x in [\n", + " prefit_newnom,\n", + " postfit_newnom,\n", + " postfit_nonc,\n", + " postfit_smoothfr,\n", + " postfit_hybnew,\n", + " postfit_binned,\n", + " ]\n", + " ],\n", + " colors=[\"black\", \"navy\", \"blue\", \"red\", \"green\", \"purple\"],\n", + " labels=[\n", + " \"Nominal prefit\",\n", + " \"Nominal\",\n", + " \"Nominal, no param unc\",\n", + " \"Smooth Fake rate\",\n", + " \"Hybrid\",\n", + " \"Binned\",\n", + " ],\n", + " rrange=[0.25, 2.5],\n", " rlabel=\"x/prefit\",\n", " xlabel=\"$p_{T}$ (GeV)\",\n", " yscale=1.2,\n", - " binwnorm=1.)\n", + " binwnorm=1.0,\n", + ")\n", "name = \"fakes_postfitScanVsPrefitNom\"\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", "plot_tools.write_index_and_log(outdir, name)\n", diff --git a/notebooks/match_scetlib_dyurbo.ipynb b/notebooks/match_scetlib_dyurbo.ipynb index 9eb8fc081..9bb80f8fb 100644 --- a/notebooks/match_scetlib_dyurbo.ipynb +++ b/notebooks/match_scetlib_dyurbo.ipynb @@ -10,7 +10,7 @@ "from utilities.io_tools import input_tools\n", "from wremnants import theory_tools\n", "from wums import boostHistHelpers as hh, plot_tools\n", - "import lz4.frame,pickle\n", + "import lz4.frame, pickle\n", "import hist\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", @@ -35,9 +35,27 @@ "metadata": {}, "outputs": [], "source": [ - "minnlo_wm = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WminusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)\n", - "minnlo_wp = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"WplusmunuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)\n", - "minnlo_z = input_tools.read_and_scale(\"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\", \"ZmumuPostVFP\", \"nominal_gen\", calculate_lumi=False, scale=1)" + "minnlo_wm = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"WminusmunuPostVFP\",\n", + " \"nominal_gen\",\n", + " calculate_lumi=False,\n", + " scale=1,\n", + ")\n", + "minnlo_wp = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"WplusmunuPostVFP\",\n", + " \"nominal_gen\",\n", + " calculate_lumi=False,\n", + " scale=1,\n", + ")\n", + "minnlo_z = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/w_z_gen_dists.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen\",\n", + " calculate_lumi=False,\n", + " scale=1,\n", + ")" ] }, { @@ -47,9 +65,18 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_nlo_full_z = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z_mll/inclusive_Z_MSHT20_nlo_full.pkl\", nonsing=\"\")\n", - "scetlib_nlo_full_wm = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/W/inclusive_Wm_MSHT20_nlo_full.pkl\", nonsing=\"\")\n", - "scetlib_nlo_full_wp = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/W/inclusive_Wp_MSHT20_nlo_full.pkl\", nonsing=\"\")" + "scetlib_nlo_full_z = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z_mll/inclusive_Z_MSHT20_nlo_full.pkl\",\n", + " nonsing=\"\",\n", + ")\n", + "scetlib_nlo_full_wm = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/W/inclusive_Wm_MSHT20_nlo_full.pkl\",\n", + " nonsing=\"\",\n", + ")\n", + "scetlib_nlo_full_wp = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/W/inclusive_Wp_MSHT20_nlo_full.pkl\",\n", + " nonsing=\"\",\n", + ")" ] }, { @@ -59,9 +86,21 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_nlo_z = input_tools.read_dyturbo_hist([\"results_z_vj_nlo.txt\"], path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\", axes=[\"qT\"])\n", - "dyturbo_nlo_wm = input_tools.read_dyturbo_hist([\"results_wm-1d-nlo-scetlibmatch.txt\"], path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\", axes=[\"qT\"])\n", - "dyturbo_nlo_wp = input_tools.read_dyturbo_hist([\"results_wp_vj_nlo.txt\"], path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\", axes=[\"qT\"])" + "dyturbo_nlo_z = input_tools.read_dyturbo_hist(\n", + " [\"results_z_vj_nlo.txt\"],\n", + " path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\",\n", + " axes=[\"qT\"],\n", + ")\n", + "dyturbo_nlo_wm = input_tools.read_dyturbo_hist(\n", + " [\"results_wm-1d-nlo-scetlibmatch.txt\"],\n", + " path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\",\n", + " axes=[\"qT\"],\n", + ")\n", + "dyturbo_nlo_wp = input_tools.read_dyturbo_hist(\n", + " [\"results_wp_vj_nlo.txt\"],\n", + " path=\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/\",\n", + " axes=[\"qT\"],\n", + ")" ] }, { @@ -83,21 +122,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x.project(\"qT\") for x in [scetlib_nlo_full_z, dyturbo_nlo_z, ]],\n", - " labels=[\"NLO full (SCETlib)\",\n", - " \"NLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"purple\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.98, 1.02],\n", - " yscale=0.5,\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x.project(\"qT\")\n", + " for x in [\n", + " scetlib_nlo_full_z,\n", + " dyturbo_nlo_z,\n", + " ]\n", + " ],\n", + " labels=[\n", + " \"NLO full (SCETlib)\",\n", + " \"NLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.98, 1.02],\n", + " yscale=0.5,\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -119,21 +168,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x.project(\"qT\") for x in [scetlib_nlo_full_wp, dyturbo_nlo_wp, ]],\n", - " labels=[\"NLO full (SCETlib)\",\n", - " \"NLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"purple\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell^{+}\\nu}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.98, 1.02],\n", - " yscale=0.5,\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x.project(\"qT\")\n", + " for x in [\n", + " scetlib_nlo_full_wp,\n", + " dyturbo_nlo_wp,\n", + " ]\n", + " ],\n", + " labels=[\n", + " \"NLO full (SCETlib)\",\n", + " \"NLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell^{+}\\nu}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.98, 1.02],\n", + " yscale=0.5,\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -155,21 +214,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x.project(\"qT\") for x in [scetlib_nlo_full_wm, dyturbo_nlo_wm, ]],\n", - " labels=[\"NLO full (SCETlib)\",\n", - " \"NLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"purple\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell^{-}\\nu}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/scetlib\",\n", - " rrange=[0.98, 1.02],\n", - " yscale=0.5,\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x.project(\"qT\")\n", + " for x in [\n", + " scetlib_nlo_full_wm,\n", + " dyturbo_nlo_wm,\n", + " ]\n", + " ],\n", + " labels=[\n", + " \"NLO full (SCETlib)\",\n", + " \"NLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell^{-}\\nu}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/scetlib\",\n", + " rrange=[0.98, 1.02],\n", + " yscale=0.5,\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -180,10 +249,13 @@ "outputs": [], "source": [ "hn3ll_nnlo_z_2d = input_tools.read_matched_scetlib_dyturbo_hist(\n", - " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20.pkl\", \n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20.pkl\",\n", " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z-2d-vj-nnlo-scetlibmatch.txt\",\n", - " axes=[\"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -194,7 +266,10 @@ "metadata": {}, "outputs": [], "source": [ - "dytrubo_z_3d = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"], axes=[\"Q\", \"Y\", \"qT\"])" + "dytrubo_z_3d = input_tools.read_dyturbo_hist(\n", + " [\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"],\n", + " axes=[\"Q\", \"Y\", \"qT\"],\n", + ")" ] }, { @@ -204,7 +279,12 @@ "metadata": {}, "outputs": [], "source": [ - "dytrubo_z_1d = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z_vj_nnlo.txt\"], axes=[\"qT\"])" + "dytrubo_z_1d = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z_vj_nnlo.txt\"\n", + " ],\n", + " axes=[\"qT\"],\n", + ")" ] }, { @@ -214,7 +294,12 @@ "metadata": {}, "outputs": [], "source": [ - "dytrubo_z_2d = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z-2d-vj-nnlo-scetlibmatch.txt\"], axes=[\"Y\", \"qT\"])" + "dytrubo_z_2d = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z-2d-vj-nnlo-scetlibmatch.txt\"\n", + " ],\n", + " axes=[\"Y\", \"qT\"],\n", + ")" ] }, { @@ -224,7 +309,10 @@ "metadata": {}, "outputs": [], "source": [ - "dytrubo_z_3d = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"], axes=[\"Q\", \"Y\", \"qT\"])" + "dytrubo_z_3d = input_tools.read_dyturbo_hist(\n", + " [\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\"],\n", + " axes=[\"Q\", \"Y\", \"qT\"],\n", + ")" ] }, { @@ -256,22 +344,26 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x.project(\"qT\") for x in [dytrubo_z_1d, dytrubo_z_2d, dytrubo_z_3d]],\n", - " labels=[\"1D\",\n", - " \"2D integrated\",\n", - " \"3D integrated\",\n", - " ],\n", - " colors=[\"mediumpurple\",\n", - " \"pink\",\n", - " \"darkgreen\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/1D\",\n", - " rrange=[0.98, 1.02],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[x.project(\"qT\") for x in [dytrubo_z_1d, dytrubo_z_2d, dytrubo_z_3d]],\n", + " labels=[\n", + " \"1D\",\n", + " \"2D integrated\",\n", + " \"3D integrated\",\n", + " ],\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"pink\",\n", + " \"darkgreen\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/1D\",\n", + " rrange=[0.98, 1.02],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -293,21 +385,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x.project(\"Y\") for x in [dytrubo_z_2d, dytrubo_z_3d]],\n", - " labels=[\n", - " \"2D integrated\",\n", - " \"3D integrated\",\n", - " ],\n", - " colors=[\"mediumpurple\",\n", - " \"pink\",\n", - " ],\n", - " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/1D\",\n", - " rrange=[0.98, 1.02],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[x.project(\"Y\") for x in [dytrubo_z_2d, dytrubo_z_3d]],\n", + " labels=[\n", + " \"2D integrated\",\n", + " \"3D integrated\",\n", + " ],\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"pink\",\n", + " ],\n", + " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/1D\",\n", + " rrange=[0.98, 1.02],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -336,7 +431,11 @@ " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20.pkl\",\n", " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-3d-scetlibmatch.txt\",\n", - " axes=[\"Q\", \"Y\", \"qT\",],\n", + " axes=[\n", + " \"Q\",\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -371,9 +470,14 @@ } ], "source": [ - "#hn3ll_z = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\")\n", - "hn3ll_nlo_z = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\", nonsing=\"auto\")\n", - "hn3ll_z = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20.pkl\")" + "# hn3ll_z = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\")\n", + "hn3ll_nlo_z = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/matchFO/Z/inclusive_Z_MSHT20.pkl\",\n", + " nonsing=\"auto\",\n", + ")\n", + "hn3ll_z = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20.pkl\"\n", + ")" ] }, { @@ -383,8 +487,15 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_n3ll_nnlo_tmp = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-1d-nnlon3llp-g0p8.txt\"], axes=[\"qT\"])\n", - "dyturbo_n3ll_nnlo = hist.Hist(hist.axis.Regular(100, 0, 100, name=\"qT\"), storage=hist.storage.Weight(), data=dyturbo_n3ll_nnlo_tmp.view(flow=True))\n" + "dyturbo_n3ll_nnlo_tmp = input_tools.read_dyturbo_hist(\n", + " [\"/scratch/shared/TheoryPredictions/DYTurbo/Z/results_z-1d-nnlon3llp-g0p8.txt\"],\n", + " axes=[\"qT\"],\n", + ")\n", + "dyturbo_n3ll_nnlo = hist.Hist(\n", + " hist.axis.Regular(100, 0, 100, name=\"qT\"),\n", + " storage=hist.storage.Weight(),\n", + " data=dyturbo_n3ll_nnlo_tmp.view(flow=True),\n", + ")" ] }, { @@ -398,7 +509,10 @@ " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20an3lo.pkl\",\n", " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20an3lo_N3LLp_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z-2d-nnlo-vj-scetlibmatch_msht20an3lo.txt\",\n", - " axes=[ \"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -428,7 +542,10 @@ " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20an3lo_N3LLp.pkl\",\n", " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/production/Z/inclusive_Z_MSHT20an3lo_N3LLp_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_z-2d-nnlo-vj-scetlibmatch_msht20an3lo.txt\",\n", - " axes=[ \"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -451,26 +568,39 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[{\"vars\" : 0}].project(\"qT\") for x in [hn3ll_nnlo_z, hn3ll_nnlo_z_an3lopdf, hn3llp_nnlo_z_an3lopdf, hn3ll_z, hn3ll_nlo_z, ]],\n", - " labels=[\"N$^{3}$LL+NNLO (MSHT20)\",\n", - " \"N$^{3}$LL'+NNLO (MSTH20an3lo)\",\n", - " \"N$^{3}$LL+NNLO (MSTH20an3lo)\",\n", - " \"N$^{3}$LL (MSHT20)\",\n", - " \"N$^{3}$LL+NLO (MSHT20)\",\n", - " ],\n", - " colors=[\"mediumpurple\",\n", - " \"pink\",\n", - " \"darkgreen\",\n", - " \"grey\",\n", - " \"purple\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/sl+dyturbo\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x[{\"vars\": 0}].project(\"qT\")\n", + " for x in [\n", + " hn3ll_nnlo_z,\n", + " hn3ll_nnlo_z_an3lopdf,\n", + " hn3llp_nnlo_z_an3lopdf,\n", + " hn3ll_z,\n", + " hn3ll_nlo_z,\n", + " ]\n", + " ],\n", + " labels=[\n", + " \"N$^{3}$LL+NNLO (MSHT20)\",\n", + " \"N$^{3}$LL'+NNLO (MSTH20an3lo)\",\n", + " \"N$^{3}$LL+NNLO (MSTH20an3lo)\",\n", + " \"N$^{3}$LL (MSHT20)\",\n", + " \"N$^{3}$LL+NLO (MSHT20)\",\n", + " ],\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"pink\",\n", + " \"darkgreen\",\n", + " \"grey\",\n", + " \"purple\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/sl+dyturbo\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -492,29 +622,42 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[{\"vars\" : 0}].project(\"qT\") for x in [hn3ll_nnlo_z, hn3ll_z, hn3ll_nlo_z, hn3ll_nnlo_z_an3lopdf, hn3llp_nnlo_z_an3lopdf]]\n", - " +[dyturbo_n3ll_nnlo],\n", - " labels=[\"N$^{3}$LL+NNLO (SCETlib+DYTurbo)\",\n", - " \"N$^{3}$LL (SCETlib)\",\n", - " \"N$^{3}$LL+NLO (SCETlib)\",\n", - " \"N$^{3}$LL+NNLO MSTH20an3lo (SCETlib+DYTurbo)\",\n", - " \"N$^{3}$LL'+NNLO MSTH20an3lo (SCETlib+DYTurbo)\",\n", - " \"N$^{3}$LL+NNLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"mediumpurple\",\n", - " \"pink\",\n", - " \"purple\",\n", - " \"red\",\n", - " \"darkred\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/sl+dyturbo\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x[{\"vars\": 0}].project(\"qT\")\n", + " for x in [\n", + " hn3ll_nnlo_z,\n", + " hn3ll_z,\n", + " hn3ll_nlo_z,\n", + " hn3ll_nnlo_z_an3lopdf,\n", + " hn3llp_nnlo_z_an3lopdf,\n", + " ]\n", + " ]\n", + " + [dyturbo_n3ll_nnlo],\n", + " labels=[\n", + " \"N$^{3}$LL+NNLO (SCETlib+DYTurbo)\",\n", + " \"N$^{3}$LL (SCETlib)\",\n", + " \"N$^{3}$LL+NLO (SCETlib)\",\n", + " \"N$^{3}$LL+NNLO MSTH20an3lo (SCETlib+DYTurbo)\",\n", + " \"N$^{3}$LL'+NNLO MSTH20an3lo (SCETlib+DYTurbo)\",\n", + " \"N$^{3}$LL+NNLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"pink\",\n", + " \"purple\",\n", + " \"red\",\n", + " \"darkred\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/sl+dyturbo\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -525,25 +668,37 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[{\"vars\" : 0}].project(\"qT\") for x in [hn3ll_nnlo_z, hn3ll_nlo_z, hn3ll_nnlo_z_an3lopdf, hn3llp_nnlo_z_an3lopdf]]\n", - " +[dyturbo_n3ll_nnlo],\n", - " labels=[\"N$^{3}$LL+NNLO (SCETlib+DYTurbo)\",\n", - " \"N$^{3}$LL+NNLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"mediumpurple\",\n", - " \"pink\",\n", - " \"purple\",\n", - " \"red\",\n", - " \"darkred\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/sl+dyturbo\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x[{\"vars\": 0}].project(\"qT\")\n", + " for x in [\n", + " hn3ll_nnlo_z,\n", + " hn3ll_nlo_z,\n", + " hn3ll_nnlo_z_an3lopdf,\n", + " hn3llp_nnlo_z_an3lopdf,\n", + " ]\n", + " ]\n", + " + [dyturbo_n3ll_nnlo],\n", + " labels=[\n", + " \"N$^{3}$LL+NNLO (SCETlib+DYTurbo)\",\n", + " \"N$^{3}$LL+NNLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"mediumpurple\",\n", + " \"pink\",\n", + " \"purple\",\n", + " \"red\",\n", + " \"darkred\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/sl+dyturbo\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -565,22 +720,28 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[{\"vars\" : \"central\"}].project(\"qT\") for x in [hn3ll_nnlo_z, hn3ll_nnlo_z_2d]],\n", - " #+[dyturbo_n3ll_nnlo[:100.j]],\n", - " labels=[\"N$^{3}$LL+NNLO 1D (SCETlib+DYTurbo)\",\n", - " \"N$^{3}$LL+NNLO 2D (SCETlib+DYTurbo)\",\n", - " #\"N$^{3}$LL+NNLO (DYTurbo)\",\n", - " ],\n", - " colors=[\"red\",\n", - " \"blue\",\n", - " ],\n", - " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/1D\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " x[{\"vars\": \"central\"}].project(\"qT\") for x in [hn3ll_nnlo_z, hn3ll_nnlo_z_2d]\n", + " ],\n", + " # +[dyturbo_n3ll_nnlo[:100.j]],\n", + " labels=[\n", + " \"N$^{3}$LL+NNLO 1D (SCETlib+DYTurbo)\",\n", + " \"N$^{3}$LL+NNLO 2D (SCETlib+DYTurbo)\",\n", + " # \"N$^{3}$LL+NNLO (DYTurbo)\",\n", + " ],\n", + " colors=[\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=r\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/1D\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -606,7 +767,9 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_wm_n3ll = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\")" + "scetlib_wm_n3ll = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\"\n", + ")" ] }, { @@ -616,7 +779,12 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_nnlo_wm = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-1d-yw-nnlo-pt0to100.txt\"], axes=[\"Y\"])" + "dyturbo_nnlo_wm = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-1d-yw-nnlo-pt0to100.txt\"\n", + " ],\n", + " axes=[\"Y\"],\n", + ")" ] }, { @@ -626,7 +794,12 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_nnlo_wm_full = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-1d-yw-nnlo.txt\"], axes=[\"Y\"])" + "dyturbo_nnlo_wm_full = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-1d-yw-nnlo.txt\"\n", + " ],\n", + " axes=[\"Y\"],\n", + ")" ] }, { @@ -640,7 +813,10 @@ " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wm_MSHT20_tnp_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wm-2d-nnlo-vj-scetlibmatch.txt\",\n", - " axes=[\"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -655,7 +831,10 @@ " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wp_MSHT20_tnp_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wp_MSHT20_tnp_nnlo_sing.pkl\",\n", " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-2d-nnlo-vj-scetlibmatch.txt\",\n", - " axes=[\"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -666,7 +845,18 @@ "metadata": {}, "outputs": [], "source": [ - "minnlo_wm_rebin, scetlib_wm_n3ll_rebin, dyturbo_nnlo_wm_rebin, = hh.rebinHistsToCommon([minnlo_wm, scetlib_wm_n3ll, dyturbo_nnlo_wm, ], (\"y\", \"Y\"))" + "(\n", + " minnlo_wm_rebin,\n", + " scetlib_wm_n3ll_rebin,\n", + " dyturbo_nnlo_wm_rebin,\n", + ") = hh.rebinHistsToCommon(\n", + " [\n", + " minnlo_wm,\n", + " scetlib_wm_n3ll,\n", + " dyturbo_nnlo_wm,\n", + " ],\n", + " (\"y\", \"Y\"),\n", + ")" ] }, { @@ -729,7 +919,7 @@ } ], "source": [ - "hn3ll_nnlo_wm[{\"vars\" : \"central\"}].sum().value/dyturbo_nnlo_wm_rebin.sum().value" + "hn3ll_nnlo_wm[{\"vars\": \"central\"}].sum().value / dyturbo_nnlo_wm_rebin.sum().value" ] }, { @@ -739,7 +929,10 @@ "metadata": {}, "outputs": [], "source": [ - "sfwm = minnlo_wm_rebin[{\"ptVgen\" : s[0.j:100.j]}].sum().value/minnlo_wm_rebin.sum().value" + "sfwm = (\n", + " minnlo_wm_rebin[{\"ptVgen\": s[0.0j:100.0j]}].sum().value\n", + " / minnlo_wm_rebin.sum().value\n", + ")" ] }, { @@ -761,32 +954,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " minnlo_wm_rebin[{\"ptVgen\" : s[0.j:100.j]}].project(\"y\"),\n", - " scetlib_wm_n3ll_rebin[{\"qT\" : s[0.j:100.j], \"vars\" : \"central\"}].project(\"Y\"),\n", - " hn3ll_nnlo_wm[{\"qT\" : s[0.j:100.j], \"vars\" : \"central\"}].project(\"Y\"),\n", - " sfwm*dyturbo_nnlo_wm_rebin,\n", - " \n", - " ],\n", - " labels=[\"MiNNLO (NNLO+PS)\",\n", - " \"SCETlib (N$^{3}$LO)\",\n", - " \"SCETlib+DYTurbo (NNLO+N$^{3}$LL)\",\n", - " \"DYTurbo (NNLO)\",\n", - " ],\n", - " colors=[\"orange\",\n", - " \"purple\",\n", - " \"mediumpurple\",\n", - " \"blue\",\n", - " ],\n", - " linestyles=[\"solid\", \"solid\", \"dashed\", \"dashdot\"],\n", - " xlabel=r\"$|y^{\\ell^{-}\\nu}|$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " yscale=1.5,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )\n", + " hists=[\n", + " minnlo_wm_rebin[{\"ptVgen\": s[0.0j:100.0j]}].project(\"y\"),\n", + " scetlib_wm_n3ll_rebin[{\"qT\": s[0.0j:100.0j], \"vars\": \"central\"}].project(\"Y\"),\n", + " hn3ll_nnlo_wm[{\"qT\": s[0.0j:100.0j], \"vars\": \"central\"}].project(\"Y\"),\n", + " sfwm * dyturbo_nnlo_wm_rebin,\n", + " ],\n", + " labels=[\n", + " \"MiNNLO (NNLO+PS)\",\n", + " \"SCETlib (N$^{3}$LO)\",\n", + " \"SCETlib+DYTurbo (NNLO+N$^{3}$LL)\",\n", + " \"DYTurbo (NNLO)\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " \"mediumpurple\",\n", + " \"blue\",\n", + " ],\n", + " linestyles=[\"solid\", \"solid\", \"dashed\", \"dashdot\"],\n", + " xlabel=r\"$|y^{\\ell^{-}\\nu}|$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " yscale=1.5,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W\"\n", "plot_tools.make_plot_dir(out, \"MSHT20\")\n", "out = os.path.join(out, \"MSHT20\")\n", @@ -801,7 +997,12 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_nnlo_wp_y = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-1d-yw-nnlo-all-scetlibmatch-from0p0.txt\"], axes=[\"Y\"])" + "dyturbo_nnlo_wp_y = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/scetlib_validation/results_wp-1d-yw-nnlo-all-scetlibmatch-from0p0.txt\"\n", + " ],\n", + " axes=[\"Y\"],\n", + ")" ] }, { @@ -811,7 +1012,9 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_wp_n3ll = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wp_MSHT20_tnp_combined.pkl\")" + "scetlib_wp_n3ll = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Wp_MSHT20_tnp_combined.pkl\"\n", + ")" ] }, { @@ -821,7 +1024,17 @@ "metadata": {}, "outputs": [], "source": [ - "minnlo_wp_rebin, n3ll_nnlo_wp_rebin, dyturbo_nnlo_wp_y_rebin, scetlib_wp_n3ll_rebin = hh.rebinHistsToCommon([minnlo_wp[{\"massVgen\" :hist.sum}], hn3ll_nnlo_wp, dyturbo_nnlo_wp_y, scetlib_wp_n3ll], (\"y\", \"Y\"))" + "minnlo_wp_rebin, n3ll_nnlo_wp_rebin, dyturbo_nnlo_wp_y_rebin, scetlib_wp_n3ll_rebin = (\n", + " hh.rebinHistsToCommon(\n", + " [\n", + " minnlo_wp[{\"massVgen\": hist.sum}],\n", + " hn3ll_nnlo_wp,\n", + " dyturbo_nnlo_wp_y,\n", + " scetlib_wp_n3ll,\n", + " ],\n", + " (\"y\", \"Y\"),\n", + " )\n", + ")" ] }, { @@ -851,32 +1064,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " minnlo_wp_rebin[{\"ptVgen\" : s[0.j:100.j]}].project(\"y\"),\n", - " scetlib_wp_n3ll_rebin[{\"qT\" : s[0.j:100.j], \"vars\" : \"central\"}].project(\"Y\"),\n", - " hn3ll_nnlo_wp[{\"qT\" : s[0.j:100.j], \"vars\" : \"central\"}].project(\"Y\"),\n", - " dyturbo_nnlo_wp_y_rebin,\n", - " \n", - " ],\n", - " labels=[\"MiNNLO (NNLO+PS)\",\n", - " \"SCETlib (N$^{3}$LO)\",\n", - " \"SCETlib+DYTurbo (NNLO+N$^{3}$LL)\",\n", - " \"DYTurbo (NNLO)\",\n", - " ],\n", - " colors=[\"orange\",\n", - " \"purple\",\n", - " \"mediumpurple\",\n", - " \"blue\",\n", - " ],\n", - " linestyles=[\"solid\", \"solid\", \"dashed\", \"dashdot\"],\n", - " xlabel=r\"$|y^{\\ell^{+}\\nu}|$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " yscale=1.5,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " minnlo_wp_rebin[{\"ptVgen\": s[0.0j:100.0j]}].project(\"y\"),\n", + " scetlib_wp_n3ll_rebin[{\"qT\": s[0.0j:100.0j], \"vars\": \"central\"}].project(\"Y\"),\n", + " hn3ll_nnlo_wp[{\"qT\": s[0.0j:100.0j], \"vars\": \"central\"}].project(\"Y\"),\n", + " dyturbo_nnlo_wp_y_rebin,\n", + " ],\n", + " labels=[\n", + " \"MiNNLO (NNLO+PS)\",\n", + " \"SCETlib (N$^{3}$LO)\",\n", + " \"SCETlib+DYTurbo (NNLO+N$^{3}$LL)\",\n", + " \"DYTurbo (NNLO)\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " \"mediumpurple\",\n", + " \"blue\",\n", + " ],\n", + " linestyles=[\"solid\", \"solid\", \"dashed\", \"dashdot\"],\n", + " xlabel=r\"$|y^{\\ell^{+}\\nu}|$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " yscale=1.5,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -914,23 +1130,27 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " n3ll_nnlo_wp_rebin[{\"qT\" : s[0.j:100.j], \"vars\" : \"central\"}].project(\"Y\"),\n", - " dyturbo_nnlo_wp_y_rebin,\n", - " ],\n", - " labels=[\"MiNNLO\",\n", - " \"SCETlib+DYTurbo\",\n", - " ],\n", - " colors=[\"orange\",\n", - " \"purple\",\n", - " ],\n", - " xlabel=r\"$|y^{\\ell\\nu}|$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/MiNNLO\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " n3ll_nnlo_wp_rebin[{\"qT\": s[0.0j:100.0j], \"vars\": \"central\"}].project(\"Y\"),\n", + " dyturbo_nnlo_wp_y_rebin,\n", + " ],\n", + " labels=[\n", + " \"MiNNLO\",\n", + " \"SCETlib+DYTurbo\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " ],\n", + " xlabel=r\"$|y^{\\ell\\nu}|$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -941,7 +1161,7 @@ "outputs": [], "source": [ "s = hist.tag.Slicer()\n", - "print(dyturbo_nnlo_wp_rebin[{\"qT\" : s[0.j:40.j]}].sum())\n", + "print(dyturbo_nnlo_wp_rebin[{\"qT\": s[0.0j:40.0j]}].sum())\n", "print(dyturbo_nnlo_wp_rebin.sum())" ] }, @@ -952,7 +1172,7 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_wm_n3ll_rebin[{\"vars\" : \"central\"}]" + "scetlib_wm_n3ll_rebin[{\"vars\": \"central\"}]" ] }, { @@ -962,7 +1182,7 @@ "metadata": {}, "outputs": [], "source": [ - "hn3ll_nnlo_wm[{\"vars\" : \"central\"}]" + "hn3ll_nnlo_wm[{\"vars\": \"central\"}]" ] }, { @@ -972,7 +1192,9 @@ "metadata": {}, "outputs": [], "source": [ - "hn3ll = input_tools.read_scetlib_hist(\"/home/k/kelong/TheoryCorrections/SCETlib/Z/msht20nnlo/inclusive_Z_MSHT20_NP0_PDFs_combined.pkl\")" + "hn3ll = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/TheoryCorrections/SCETlib/Z/msht20nnlo/inclusive_Z_MSHT20_NP0_PDFs_combined.pkl\"\n", + ")" ] }, { @@ -982,7 +1204,9 @@ "metadata": {}, "outputs": [], "source": [ - "hscetlib_as = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFvars_combine.pkl\")" + "hscetlib_as = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFvars_combine.pkl\"\n", + ")" ] }, { @@ -1004,7 +1228,9 @@ } ], "source": [ - "hscetlib_nnlosing_as = input_tools.read_scetlib_hist(\"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFalphas_nnlo_sing_combined.pkl\")" + "hscetlib_nnlosing_as = input_tools.read_scetlib_hist(\n", + " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFalphas_nnlo_sing_combined.pkl\"\n", + ")" ] }, { @@ -1022,7 +1248,11 @@ "metadata": {}, "outputs": [], "source": [ - "hdyturbo_nnlo_as = input_tools.read_dyturbo_pdf_hist(\"/home/k/kelong/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/pdfvariations/MSHT20nnlo_as_smallrange/z0/results_z-2d-nnlo-vj-MSHT20nnlo_as_smallrange-member{i}-scetlibmatch.txt\", pdf_members=7, axes=(\"Y\", \"qT\"))" + "hdyturbo_nnlo_as = input_tools.read_dyturbo_pdf_hist(\n", + " \"/home/k/kelong/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/pdfvariations/MSHT20nnlo_as_smallrange/z0/results_z-2d-nnlo-vj-MSHT20nnlo_as_smallrange-member{i}-scetlibmatch.txt\",\n", + " pdf_members=7,\n", + " axes=(\"Y\", \"qT\"),\n", + ")" ] }, { @@ -1051,7 +1281,10 @@ " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFvars_combine.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_NP0_nnlo_sing_combined.pkl\",\n", " \"/home/k/kelong/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/pdfvariations/msht20nnlo/z0/results_z-2d-nnlo-vj-member0-scetlibmatch.txt.txt\",\n", - " axes=[\"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -1066,7 +1299,10 @@ " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFalphas_combined.pkl\",\n", " \"/scratch/shared/TheoryPredictions/ScetlibFiles/inclusive_Z_MSHT20_PDFalphas_nnlo_sing_combined.pkl\",\n", " \"/home/k/kelong/TheoryCorrections/DYTURBO/nnlo-scetlibmatch/pdfvariations/MSHT20nnlo_as_smallrange/z0/results_z-2d-nnlo-vj-MSHT20nnlo_as_smallrange-member{i}-scetlibmatch.txt\",\n", - " axes=[\"Y\", \"qT\",],\n", + " axes=[\n", + " \"Y\",\n", + " \"qT\",\n", + " ],\n", ")" ] }, @@ -1097,41 +1333,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf0\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf1\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf2\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf3\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf4\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf5\"}].project(\"qT\"),\n", - " hn3ll_nnlo_z_alphas[{\"vars\" : \"pdf6\"}].project(\"qT\"),\n", - " ],\n", - " labels=[r\"$\\alpha_S = 0.118$\",\n", - " r\"$\\alpha_S = 0.115$\",\n", - " r\"$\\alpha_S = 0.116$\",\n", - " r\"$\\alpha_S = 0.117$\",\n", - " r\"$\\alpha_S = 0.119$\",\n", - " r\"$\\alpha_S = 0.120$\",\n", - " r\"$\\alpha_S = 0.121$\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"green\",\n", - " \"purple\",\n", - " \"grey\",\n", - " \"grey\",\n", - " \"purple\",\n", - " \"green\"\n", - " ],\n", - " linestyles=[\n", - " \"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"\n", - " ],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/0.118\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf0\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf1\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf2\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf3\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf4\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf5\"}].project(\"qT\"),\n", + " hn3ll_nnlo_z_alphas[{\"vars\": \"pdf6\"}].project(\"qT\"),\n", + " ],\n", + " labels=[\n", + " r\"$\\alpha_S = 0.118$\",\n", + " r\"$\\alpha_S = 0.115$\",\n", + " r\"$\\alpha_S = 0.116$\",\n", + " r\"$\\alpha_S = 0.117$\",\n", + " r\"$\\alpha_S = 0.119$\",\n", + " r\"$\\alpha_S = 0.120$\",\n", + " r\"$\\alpha_S = 0.121$\",\n", + " ],\n", + " colors=[\"black\", \"green\", \"purple\", \"grey\", \"grey\", \"purple\", \"green\"],\n", + " linestyles=[\"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/0.118\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -1153,41 +1383,35 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hscetlib_as[{\"vars\" : \"pdf0\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf1\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf2\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf3\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf4\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf5\"}].project(\"qT\")[:40.j],\n", - " hscetlib_as[{\"vars\" : \"pdf6\"}].project(\"qT\")[:40.j],\n", - " ],\n", - " labels=[r\"$\\alpha_S = 0.118$\",\n", - " r\"$\\alpha_S = 0.115$\",\n", - " r\"$\\alpha_S = 0.116$\",\n", - " r\"$\\alpha_S = 0.117$\",\n", - " r\"$\\alpha_S = 0.119$\",\n", - " r\"$\\alpha_S = 0.120$\",\n", - " r\"$\\alpha_S = 0.121$\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"green\",\n", - " \"purple\",\n", - " \"grey\",\n", - " \"grey\",\n", - " \"purple\",\n", - " \"green\"\n", - " ],\n", - " linestyles=[\n", - " \"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"\n", - " ],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/0.118\",\n", - " rrange=[0.99, 1.01],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " hscetlib_as[{\"vars\": \"pdf0\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf1\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf2\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf3\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf4\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf5\"}].project(\"qT\")[:40.0j],\n", + " hscetlib_as[{\"vars\": \"pdf6\"}].project(\"qT\")[:40.0j],\n", + " ],\n", + " labels=[\n", + " r\"$\\alpha_S = 0.118$\",\n", + " r\"$\\alpha_S = 0.115$\",\n", + " r\"$\\alpha_S = 0.116$\",\n", + " r\"$\\alpha_S = 0.117$\",\n", + " r\"$\\alpha_S = 0.119$\",\n", + " r\"$\\alpha_S = 0.120$\",\n", + " r\"$\\alpha_S = 0.121$\",\n", + " ],\n", + " colors=[\"black\", \"green\", \"purple\", \"grey\", \"grey\", \"purple\", \"green\"],\n", + " linestyles=[\"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/0.118\",\n", + " rrange=[0.99, 1.01],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -1198,41 +1422,35 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf0\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf1\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf2\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf3\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf4\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf5\"}].project(\"qT\")[:40.j],\n", - " hdyturbo_nnlo_as[{\"vars\" : \"pdf6\"}].project(\"qT\")[:40.j],\n", - " ],\n", - " labels=[r\"$\\alpha_S = 0.118$\",\n", - " r\"$\\alpha_S = 0.115$\",\n", - " r\"$\\alpha_S = 0.116$\",\n", - " r\"$\\alpha_S = 0.117$\",\n", - " r\"$\\alpha_S = 0.119$\",\n", - " r\"$\\alpha_S = 0.120$\",\n", - " r\"$\\alpha_S = 0.121$\",\n", - " ],\n", - " colors=[\"black\",\n", - " \"green\",\n", - " \"purple\",\n", - " \"grey\",\n", - " \"grey\",\n", - " \"purple\",\n", - " \"green\"\n", - " ],\n", - " linestyles=[\n", - " \"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"\n", - " ],\n", - " xlabel=r\"$p_{T}^{\\ell\\ell}$\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/0.118\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True, \n", - " )" + " hists=[\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf0\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf1\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf2\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf3\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf4\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf5\"}].project(\"qT\")[:40.0j],\n", + " hdyturbo_nnlo_as[{\"vars\": \"pdf6\"}].project(\"qT\")[:40.0j],\n", + " ],\n", + " labels=[\n", + " r\"$\\alpha_S = 0.118$\",\n", + " r\"$\\alpha_S = 0.115$\",\n", + " r\"$\\alpha_S = 0.116$\",\n", + " r\"$\\alpha_S = 0.117$\",\n", + " r\"$\\alpha_S = 0.119$\",\n", + " r\"$\\alpha_S = 0.120$\",\n", + " r\"$\\alpha_S = 0.121$\",\n", + " ],\n", + " colors=[\"black\", \"green\", \"purple\", \"grey\", \"grey\", \"purple\", \"green\"],\n", + " linestyles=[\"solid\", \"dashed\", \"dotted\", \"dashed\", \"dotted\", \"dashed\", \"dotted\"],\n", + " xlabel=r\"$p_{T}^{\\ell\\ell}$\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/0.118\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] } ], diff --git a/notebooks/muonMomentumScale.ipynb b/notebooks/muonMomentumScale.ipynb index 778a42036..63351eaa4 100644 --- a/notebooks/muonMomentumScale.ipynb +++ b/notebooks/muonMomentumScale.ipynb @@ -40,6 +40,7 @@ "import h5py\n", "import uproot\n", "import narf\n", + "\n", "hep.style.use(hep.style.ROOT)" ] }, @@ -52,8 +53,8 @@ "source": [ "with h5py.File(\"../mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles1.hdf5\", \"r\") as f:\n", " result = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - " #print(result['WminustaunuPostVFP']['event_count'])\n", - " print(result['ZmumuPostVFP']['output'].keys())" + " # print(result['WminustaunuPostVFP']['event_count'])\n", + " print(result[\"ZmumuPostVFP\"][\"output\"].keys())" ] }, { @@ -83,50 +84,48 @@ "f = h5py.File(\"../mw_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"r\")\n", "results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", "\n", - "proc = 'WplusmunuPostVFP'\n", + "proc = \"WplusmunuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$'\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$\",\n", "}\n", - "print(results[proc]['output'].keys())\n", + "print(results[proc][\"output\"].keys())\n", "\n", "nuisances = [\n", - " 'muonScaleSyst_responseWeights',\n", - "# 'Z_non_closure_parametrized',\n", - " 'Z_non_closure_parametrized_A',\n", - " 'Z_non_closure_parametrized_M',\n", - "# 'Z_non_closure_binned'\n", + " \"muonScaleSyst_responseWeights\",\n", + " # 'Z_non_closure_parametrized',\n", + " \"Z_non_closure_parametrized_A\",\n", + " \"Z_non_closure_parametrized_M\",\n", + " # 'Z_non_closure_binned'\n", "]\n", "hists = {}\n", - "hists['nominal'] = results[proc]['output']['nominal'].get()\n", - "hists['nominal_gensmear'] = results[proc]['output']['nominal_gen_smeared'].get()\n", + "hists[\"nominal\"] = results[proc][\"output\"][\"nominal\"].get()\n", + "hists[\"nominal_gensmear\"] = results[proc][\"output\"][\"nominal_gen_smeared\"].get()\n", "for nuisance in nuisances:\n", - " hists[nuisance + '_gensmear'] = results[proc]['output'][nuisance + '_gensmear'].get()\n", - " hists['nominal_' + nuisance] = results[proc]['output']['nominal_' + nuisance].get()\n", + " hists[nuisance + \"_gensmear\"] = results[proc][\"output\"][\n", + " nuisance + \"_gensmear\"\n", + " ].get()\n", + " hists[\"nominal_\" + nuisance] = results[proc][\"output\"][\"nominal_\" + nuisance].get()\n", "\n", - "action = lambda x: x.project('pt')\n", + "action = lambda x: x.project(\"pt\")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nominal_gensmear']),\n", - " action(hists['muonScaleSyst_responseWeights_gensmear'][...,141,0]),\n", - " action(hists['muonScaleSyst_responseWeights_gensmear'][...,141,1])\n", - " ],\n", - " labels = [\n", - " 'nominal', \n", - " 'smearing weights DOWN',\n", - " 'smearing weights UP'\n", + " action(hists[\"nominal_gensmear\"]),\n", + " action(hists[\"muonScaleSyst_responseWeights_gensmear\"][..., 141, 0]),\n", + " action(hists[\"muonScaleSyst_responseWeights_gensmear\"][..., 141, 1]),\n", " ],\n", - " colors = ['black', 'green', 'green'],\n", - " rrange = [0.99995, 1.00005],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'GEN smeared $p_T^{\\mu}$',\n", - " plot_title = proc_name_latex[proc],\n", - " grid = True\n", + " labels=[\"nominal\", \"smearing weights DOWN\", \"smearing weights UP\"],\n", + " colors=[\"black\", \"green\", \"green\"],\n", + " rrange=[0.99995, 1.00005],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"GEN smeared $p_T^{\\mu}$\",\n", + " plot_title=proc_name_latex[proc],\n", + " grid=True,\n", ")\n", - "#hists['nominal_Z_non_closure_parametrized'].values()" + "# hists['nominal_Z_non_closure_parametrized'].values()" ] }, { @@ -214,94 +213,162 @@ "import uproot\n", "import narf\n", "import os\n", + "\n", "hep.style.use(hep.style.ROOT)\n", "\n", - "proc = 'WplusmunuPostVFP'\n", + "proc = \"WplusmunuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$'\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$\",\n", "}\n", - "dummyVar = ''\n", - "dummyVar_title = 'AeM #143 var'\n", - "#dummyVar = '_dummyVar'\n", - "#dummyVar_title = 'A=1e-4 dummy var'\n", + "dummyVar = \"\"\n", + "dummyVar_title = \"AeM #143 var\"\n", + "# dummyVar = '_dummyVar'\n", + "# dummyVar_title = 'A=1e-4 dummy var'\n", "\n", - "action = lambda x: x.project('pt')\n", + "action = lambda x: x.project(\"pt\")\n", "unc = {}\n", - "etas = {\n", - " '(-2.0, -1.8)':3,\n", - " '(0.0, 0.2)':12,\n", - " '(1.8, 2.0)':21,\n", - " '(-2.4, 2.4)':24\n", - "}\n", + "etas = {\"(-2.0, -1.8)\": 3, \"(0.0, 0.2)\": 12, \"(1.8, 2.0)\": 21, \"(-2.4, 2.4)\": 24}\n", + "\n", "\n", "def save_pdf_and_png_toEos(outdir, plot_basename, eosdir, fig=None):\n", " plot_tools.save_pdf_and_png(out_dir, plot_basename, fig)\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}')\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}')\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", + "\n", "\n", "for etabin in etas.keys():\n", - " sel_nom = {'eta':etas[etabin], 'charge':1j, 'passIso':1j, 'passMT':1j}\n", - " sel_dn = {'eta':etas[etabin], 'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':0}\n", - " sel_up = {'eta':etas[etabin], 'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':1}\n", - " sel_dn_m = {'eta':etas[etabin], 'charge':1j, 'passIso':1j, 'passMT':1j, 'downUpVar':0}\n", - " sel_up_m = {'eta':etas[etabin], 'charge':1j, 'passIso':1j, 'passMT':1j, 'downUpVar':1}\n", - " if etabin == '(-2.4, 2.4)':\n", - " sel_nom.pop('eta')\n", - " sel_dn.pop('eta')\n", - " sel_up.pop('eta')\n", - " sel_dn_m.pop('eta')\n", - " sel_up_m.pop('eta')\n", - " with h5py.File(f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_validation{dummyVar}.hdf5\", \"r\") as f:\n", + " sel_nom = {\"eta\": etas[etabin], \"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j}\n", + " sel_dn = {\n", + " \"eta\": etas[etabin],\n", + " \"charge\": 1j,\n", + " \"passIso\": 1j,\n", + " \"passMT\": 1j,\n", + " \"unc\": 143,\n", + " \"downUpVar\": 0,\n", + " }\n", + " sel_up = {\n", + " \"eta\": etas[etabin],\n", + " \"charge\": 1j,\n", + " \"passIso\": 1j,\n", + " \"passMT\": 1j,\n", + " \"unc\": 143,\n", + " \"downUpVar\": 1,\n", + " }\n", + " sel_dn_m = {\n", + " \"eta\": etas[etabin],\n", + " \"charge\": 1j,\n", + " \"passIso\": 1j,\n", + " \"passMT\": 1j,\n", + " \"downUpVar\": 0,\n", + " }\n", + " sel_up_m = {\n", + " \"eta\": etas[etabin],\n", + " \"charge\": 1j,\n", + " \"passIso\": 1j,\n", + " \"passMT\": 1j,\n", + " \"downUpVar\": 1,\n", + " }\n", + " if etabin == \"(-2.4, 2.4)\":\n", + " sel_nom.pop(\"eta\")\n", + " sel_dn.pop(\"eta\")\n", + " sel_up.pop(\"eta\")\n", + " sel_dn_m.pop(\"eta\")\n", + " sel_up_m.pop(\"eta\")\n", + " with h5py.File(\n", + " f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_validation{dummyVar}.hdf5\",\n", + " \"r\",\n", + " ) as f:\n", " results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - " nom = action(results[proc]['output']['nominal'].get()[sel_nom])\n", - " unc['spline_dn'] = action(results[proc]['output']['muonScaleSyst_responseWeights_spline'].get()[sel_dn])\n", - " unc['spline_up'] = action(results[proc]['output']['muonScaleSyst_responseWeights_spline'].get()[sel_up])\n", - " unc['gensmear_dn'] = action(results[proc]['output']['nominal_muonScaleSyst_responseWeights'].get()[sel_dn])\n", - " unc['gensmear_up'] = action(results[proc]['output']['nominal_muonScaleSyst_responseWeights'].get()[sel_up])\n", - " unc['massweights_dn'] = action(results[proc]['output']['muonScaleSyst_responseWeights_massweights'].get()[sel_dn])\n", - " unc['massweights_up'] = action(results[proc]['output']['muonScaleSyst_responseWeights_massweights'].get()[sel_up])\n", - " unc['manual_dn'] = action(results[proc]['output']['muonScaleSyst_manualShift'].get()[sel_dn_m])\n", - " unc['manual_up'] = action(results[proc]['output']['muonScaleSyst_manualShift'].get()[sel_up_m])\n", + " nom = action(results[proc][\"output\"][\"nominal\"].get()[sel_nom])\n", + " unc[\"spline_dn\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_responseWeights_spline\"].get()[\n", + " sel_dn\n", + " ]\n", + " )\n", + " unc[\"spline_up\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_responseWeights_spline\"].get()[\n", + " sel_up\n", + " ]\n", + " )\n", + " unc[\"gensmear_dn\"] = action(\n", + " results[proc][\"output\"][\"nominal_muonScaleSyst_responseWeights\"].get()[\n", + " sel_dn\n", + " ]\n", + " )\n", + " unc[\"gensmear_up\"] = action(\n", + " results[proc][\"output\"][\"nominal_muonScaleSyst_responseWeights\"].get()[\n", + " sel_up\n", + " ]\n", + " )\n", + " unc[\"massweights_dn\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_responseWeights_massweights\"].get()[\n", + " sel_dn\n", + " ]\n", + " )\n", + " unc[\"massweights_up\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_responseWeights_massweights\"].get()[\n", + " sel_up\n", + " ]\n", + " )\n", + " unc[\"manual_dn\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_manualShift\"].get()[sel_dn_m]\n", + " )\n", + " unc[\"manual_up\"] = action(\n", + " results[proc][\"output\"][\"muonScaleSyst_manualShift\"].get()[sel_up_m]\n", + " )\n", "\n", " fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", " nom,\n", - " unc['gensmear_dn'],\n", - " unc['gensmear_up'],\n", - " unc['spline_dn'],\n", - " unc['spline_up'],\n", - " unc['massweights_dn'],\n", - " unc['massweights_up']\n", - " #unc['manual_dn'],\n", - " #unc['manual_up']\n", + " unc[\"gensmear_dn\"],\n", + " unc[\"gensmear_up\"],\n", + " unc[\"spline_dn\"],\n", + " unc[\"spline_up\"],\n", + " unc[\"massweights_dn\"],\n", + " unc[\"massweights_up\"],\n", + " # unc['manual_dn'],\n", + " # unc['manual_up']\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi stats gensmear',\n", - " '_jpsi stats gensmear',\n", - " 'jpsi stats spline',\n", - " '_jpsi stats spline',\n", - " 'jpsi stats massweights',\n", - " '_jpsi stats massweights'\n", + " labels=[\n", + " \"nominal\",\n", + " \"jpsi stats gensmear\",\n", + " \"_jpsi stats gensmear\",\n", + " \"jpsi stats spline\",\n", + " \"_jpsi stats spline\",\n", + " \"jpsi stats massweights\",\n", + " \"_jpsi stats massweights\",\n", " #'jpsi stats manual',\n", " #'_jpsi stats manual'\n", " ],\n", - " colors = ['black', 'green', 'green', 'red', 'red', 'blue', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{dummyVar_title} for {proc_name_latex[proc]} \\n $\\eta \\in {etabin}$',\n", - " grid = True\n", + " colors=[\n", + " \"black\",\n", + " \"green\",\n", + " \"green\",\n", + " \"red\",\n", + " \"red\",\n", + " \"blue\",\n", + " \"blue\",\n", + " ], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{dummyVar_title} for {proc_name_latex[proc]} \\n $\\eta \\in {etabin}$\",\n", + " grid=True,\n", " )\n", "\n", - " out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - " plot_basename = f'muonScaleComparison{dummyVar}_eta{etas[etabin]}_parameterFix'\n", - " eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline'\n", - " #save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=None)\n", - " " + " out_dir = \"/home/submit/tyjyang/analysis/wmass/WRemnants/plots\"\n", + " plot_basename = f\"muonScaleComparison{dummyVar}_eta{etas[etabin]}_parameterFix\"\n", + " eos_dir = (\n", + " \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline\"\n", + " )\n", + " # save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=None)" ] }, { @@ -356,63 +423,85 @@ "import uproot\n", "import narf\n", "import os\n", + "\n", "hep.style.use(hep.style.ROOT)\n", "\n", + "\n", "def save_pdf_and_png_toEos(outdir, plot_basename, eosdir, fig=None):\n", " plot_tools.save_pdf_and_png(out_dir, plot_basename, fig)\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}')\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}')\n", - " \n", - "dummyVar = '_dummyVar'\n", - "dummyVar_title = 'A=1e-4 dummy var'\n", - "#dummyVar = ''\n", - "#dummyVar_title = 'AeM var'\n", - "action = lambda x: x.project('weights')\n", - "sel_nom = {'passIso': 1j, 'passMT': 1j}\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", + "\n", "\n", + "dummyVar = \"_dummyVar\"\n", + "dummyVar_title = \"A=1e-4 dummy var\"\n", + "# dummyVar = ''\n", + "# dummyVar_title = 'AeM var'\n", + "action = lambda x: x.project(\"weights\")\n", + "sel_nom = {\"passIso\": 1j, \"passMT\": 1j}\n", "\n", - "with h5py.File(f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_validation{dummyVar}.hdf5\", \"r\") as f:\n", + "\n", + "with h5py.File(\n", + " f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_validation{dummyVar}.hdf5\",\n", + " \"r\",\n", + ") as f:\n", " results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - " proc = 'WplusmunuPostVFP'\n", + " proc = \"WplusmunuPostVFP\"\n", " fig, ax = plt.subplots()\n", " hep.histplot(\n", - " action(results[proc]['output']['weights_gensmear_dn'].get()[sel_nom]), \n", - " label = 'gensmear', ax = ax, yerr = False, color = 'green'\n", + " action(results[proc][\"output\"][\"weights_gensmear_dn\"].get()[sel_nom]),\n", + " label=\"gensmear\",\n", + " ax=ax,\n", + " yerr=False,\n", + " color=\"green\",\n", " )\n", " hep.histplot(\n", - " action(results[proc]['output']['weights_gensmear_up'].get()[sel_nom]),\n", - " label = '_gensmear', ax = ax, yerr = False, color = 'green'\n", + " action(results[proc][\"output\"][\"weights_gensmear_up\"].get()[sel_nom]),\n", + " label=\"_gensmear\",\n", + " ax=ax,\n", + " yerr=False,\n", + " color=\"green\",\n", " )\n", " hep.histplot(\n", - " action(results[proc]['output']['weights_spline_dn'].get()[sel_nom]),\n", - " label = 'spline', ax = ax, yerr = False, color = 'red'\n", + " action(results[proc][\"output\"][\"weights_spline_dn\"].get()[sel_nom]),\n", + " label=\"spline\",\n", + " ax=ax,\n", + " yerr=False,\n", + " color=\"red\",\n", " )\n", " hep.histplot(\n", - " action(results[proc]['output']['weights_spline_up'].get()[sel_nom]),\n", - " label = '_spline', ax = ax, yerr = False, color = 'red'\n", + " action(results[proc][\"output\"][\"weights_spline_up\"].get()[sel_nom]),\n", + " label=\"_spline\",\n", + " ax=ax,\n", + " yerr=False,\n", + " color=\"red\",\n", " )\n", - "# hep.histplot(\n", - " # action(results[proc]['output']['weights_massweights_dn'].get()[sel_nom]),\n", - "# label = 'massweights', ax = ax, yerr = False, color = 'blue'\n", - "# )\n", - " # hep.histplot(\n", - "# action(results[proc]['output']['weights_massweights_up'].get()[sel_nom]),\n", - " # label = '_massweights', ax = ax, yerr = False, color = 'blue'\n", - " # )\n", + " # hep.histplot(\n", + " # action(results[proc]['output']['weights_massweights_dn'].get()[sel_nom]),\n", + " # label = 'massweights', ax = ax, yerr = False, color = 'blue'\n", + " # )\n", + " # hep.histplot(\n", + " # action(results[proc]['output']['weights_massweights_up'].get()[sel_nom]),\n", + " # label = '_massweights', ax = ax, yerr = False, color = 'blue'\n", + " # )\n", " ax.legend()\n", - " ax.set_title(f'smearing weights with {dummyVar_title}')\n", - " ax.set_ylabel('Events/bin')\n", - " ax.set_xlim(0.99,1.01)\n", - " #ax.set_ylim(0,1e6)\n", - " out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - " plot_basename = f'weightsComparison{dummyVar}_parameterFix'\n", - " eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline'\n", + " ax.set_title(f\"smearing weights with {dummyVar_title}\")\n", + " ax.set_ylabel(\"Events/bin\")\n", + " ax.set_xlim(0.99, 1.01)\n", + " # ax.set_ylim(0,1e6)\n", + " out_dir = \"/home/submit/tyjyang/analysis/wmass/WRemnants/plots\"\n", + " plot_basename = f\"weightsComparison{dummyVar}_parameterFix\"\n", + " eos_dir = (\n", + " \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline\"\n", + " )\n", " save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig)\n", "\n", - "\n", - " print(action(results[proc]['output']['weights_massweights_dn'].get()[sel_nom]).sum)\n", - " print(action(results[proc]['output']['weights_gensmear_dn'].get()[sel_nom]).sum)\n", - "\n" + " print(action(results[proc][\"output\"][\"weights_massweights_dn\"].get()[sel_nom]).sum)\n", + " print(action(results[proc][\"output\"][\"weights_gensmear_dn\"].get()[sel_nom]).sum)" ] }, { @@ -437,38 +526,47 @@ "import numpy as np\n", "from wremnants import muon_validation\n", "\n", + "\n", "def get_covmat(filepath, n_scale_params, n_tot_params, n_eta_bins):\n", " f = uproot.open(filepath)\n", - " cov = f['covariance_matrix'].to_hist()\n", + " cov = f[\"covariance_matrix\"].to_hist()\n", " cov_scale_params = muon_validation.get_jpsi_scale_param_cov_mat(\n", " cov, n_scale_params, n_tot_params, n_eta_bins\n", " )\n", " return cov_scale_params\n", "\n", + "\n", "def make_hist_covmat_diag(cov_scale_params):\n", - " w,v = np.linalg.eigh(cov_scale_params)\n", + " w, v = np.linalg.eigh(cov_scale_params)\n", " var_mat = np.sqrt(w) * v\n", - " axis_eta = hist.axis.Regular(n_eta_bins, -2.4, 2.4, name = 'eta')\n", - " axis_scale_params = hist.axis.Regular(n_scale_params, 0, 1, name = 'scale_params')\n", + " axis_eta = hist.axis.Regular(n_eta_bins, -2.4, 2.4, name=\"eta\")\n", + " axis_scale_params = hist.axis.Regular(n_scale_params, 0, 1, name=\"scale_params\")\n", " axis_scale_params_unc = hist.axis.Regular(\n", - " n_eta_bins * n_scale_params, 0, n_eta_bins * n_scale_params,\n", - " underflow = False, overflow = False, name = 'unc'\n", + " n_eta_bins * n_scale_params,\n", + " 0,\n", + " n_eta_bins * n_scale_params,\n", + " underflow=False,\n", + " overflow=False,\n", + " name=\"unc\",\n", + " )\n", + " hist_scale_params_unc = hist.Hist(\n", + " axis_eta, axis_scale_params, axis_scale_params_unc\n", " )\n", - " hist_scale_params_unc = hist.Hist(axis_eta, axis_scale_params, axis_scale_params_unc)\n", " for i in range(n_eta_bins):\n", " lb, ub = i * n_scale_params, (i + 1) * n_scale_params\n", - " hist_scale_params_unc.view()[i,...] = var_mat[lb:ub][:]\n", + " hist_scale_params_unc.view()[i, ...] = var_mat[lb:ub][:]\n", " return hist_scale_params_unc\n", "\n", + "\n", "def get_variance_on_AeM(filepath, n_scale_params, n_tot_params, n_eta_bins):\n", " covmat = get_covmat(filepath, n_scale_params, n_tot_params, n_eta_bins)\n", " A_var = np.empty(n_eta_bins)\n", " e_var = np.empty(n_eta_bins)\n", " M_var = np.empty(n_eta_bins)\n", " for i in range(n_eta_bins):\n", - " A_var[i] = (covmat.diagonal()[n_scale_params*i])\n", - " e_var[i] = (covmat.diagonal()[n_scale_params*i+1])\n", - " M_var[i] = (covmat.diagonal()[n_scale_params*i+2])\n", + " A_var[i] = covmat.diagonal()[n_scale_params * i]\n", + " e_var[i] = covmat.diagonal()[n_scale_params * i + 1]\n", + " M_var[i] = covmat.diagonal()[n_scale_params * i + 2]\n", " return A_var, e_var, M_var" ] }, @@ -482,45 +580,56 @@ "n_scale_params = 3\n", "n_tot_params = 4\n", "n_eta_bins = 48\n", - "filepath_old = '../wremnants/data/calibration/calibrationJDATA_rewtgr_3dmap_LBL_v721.root'\n", - "filepath_new = '../wremnants/data/calibration/calibrationJDATA_rewtgr_3dmap_LBL_MCstat.root'\n", - "A_var_old, e_var_old, M_var_old = get_variance_on_AeM(filepath_old, n_scale_params, n_tot_params, n_eta_bins)\n", - "A_var_new, e_var_new, M_var_new = get_variance_on_AeM(filepath_new, n_scale_params, n_tot_params, n_eta_bins)\n", + "filepath_old = (\n", + " \"../wremnants/data/calibration/calibrationJDATA_rewtgr_3dmap_LBL_v721.root\"\n", + ")\n", + "filepath_new = (\n", + " \"../wremnants/data/calibration/calibrationJDATA_rewtgr_3dmap_LBL_MCstat.root\"\n", + ")\n", + "A_var_old, e_var_old, M_var_old = get_variance_on_AeM(\n", + " filepath_old, n_scale_params, n_tot_params, n_eta_bins\n", + ")\n", + "A_var_new, e_var_new, M_var_new = get_variance_on_AeM(\n", + " filepath_new, n_scale_params, n_tot_params, n_eta_bins\n", + ")\n", "ratio_A_var = A_var_new / A_var_old\n", "ratio_e_var = e_var_new / e_var_old\n", "ratio_M_var = M_var_new / M_var_old\n", "\n", "from wremnants import plot_tools\n", + "\n", "eta = np.arange(-2.4, 2.4, 0.1)\n", "ratio_vars = {\n", - " r'$\\sigma^2_{A_{{data+MC}}}/\\sigma^2_{A_{{data}}}$': ratio_A_var,\n", - " r'$\\sigma^2_{e_{{data+MC}}}/\\sigma^2_{e_{{data}}}$': ratio_e_var,\n", - " r'$\\sigma^2_{M_{{data+MC}}}/\\sigma^2_{M_{{data}}}$': ratio_M_var\n", + " r\"$\\sigma^2_{A_{{data+MC}}}/\\sigma^2_{A_{{data}}}$\": ratio_A_var,\n", + " r\"$\\sigma^2_{e_{{data+MC}}}/\\sigma^2_{e_{{data}}}$\": ratio_e_var,\n", + " r\"$\\sigma^2_{M_{{data+MC}}}/\\sigma^2_{M_{{data}}}$\": ratio_M_var,\n", "}\n", "width = 0.027 # the width of the bars\n", "multiplier = 1\n", "\n", - "fig, ax = plt.subplots(layout='constrained')\n", + "fig, ax = plt.subplots(layout=\"constrained\")\n", "\n", "for group, var in ratio_vars.items():\n", " offset = width * multiplier\n", " rects = ax.bar(eta + offset, var, width, label=group)\n", - " #ax.bar_label(rects, padding=3)\n", + " # ax.bar_label(rects, padding=3)\n", " multiplier += 1\n", - "ax.axhline(y=3.04, color='r', linestyle='--', label=r'inflation factor on $\\sigma^2_{MC}$')\n", + "ax.axhline(\n", + " y=3.04, color=\"r\", linestyle=\"--\", label=r\"inflation factor on $\\sigma^2_{MC}$\"\n", + ")\n", "\n", "# Add some text for labels, title and custom x-axis tick labels, etc.\n", - "ax.set_ylabel(r'$\\sigma_{data+MC}/\\sigma_{data}$')\n", - "ax.set_xlabel(r'$\\eta$')\n", - "ax.set_title(r'Ratios of $J/\\Psi$ calibration parameters stats. unc.')\n", + "ax.set_ylabel(r\"$\\sigma_{data+MC}/\\sigma_{data}$\")\n", + "ax.set_xlabel(r\"$\\eta$\")\n", + "ax.set_title(r\"Ratios of $J/\\Psi$ calibration parameters stats. unc.\")\n", "ticks = np.arange(-2.4, 2.8, 0.4)\n", "ax.set_xticks(ticks)\n", - "ax.legend(loc='upper right', ncols = 2)\n", + "ax.legend(loc=\"upper right\", ncols=2)\n", "ax.set_ylim(0, 4)\n", "\n", "plot_tools.save_pdf_and_png(\n", - " '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi_stats_unc',\n", - " 'jpsi_stats_unc_boostrapping_vs_inflation'\n", + " \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi_stats_unc\",\n", + " \"jpsi_stats_unc_boostrapping_vs_inflation\",\n", ")\n", "plt.show()" ] @@ -535,7 +644,7 @@ "outputs": [], "source": [ "f = uproot.open(filepath_new)\n", - "f['covariance_matrix'].values()" + "f[\"covariance_matrix\"].values()" ] }, { @@ -1787,124 +1896,122 @@ "##########################################\n", "# muon scale for the mw analysis\n", "##########################################\n", - "out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - "eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_analyses'\n", + "out_dir = \"/home/submit/tyjyang/analysis/wmass/WRemnants/plots\"\n", + "eos_dir = \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_analyses\"\n", "\n", - "f = h5py.File(\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles100.hdf5\", \"r\")\n", + "f = h5py.File(\n", + " \"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles100.hdf5\", \"r\"\n", + ")\n", "results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - "proc = 'WplusmunuPostVFP'\n", + "proc = \"WplusmunuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$'\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$\",\n", "}\n", - "action = lambda x: x.project('pt')\n", - "output = results[proc]['output']\n", + "action = lambda x: x.project(\"pt\")\n", + "output = results[proc][\"output\"]\n", "hists = {}\n", - "hists['nom'] = output['nominal'].get()\n", - "hists['msv'] = output['nominal_muonScaleSyst_responseWeights'].get()\n", - "hists['non_closure_A'] = output['nominal_Z_non_closure_parametrized_A'].get()\n", - "hists['non_closure_M'] = output['nominal_Z_non_closure_parametrized_M'].get()\n", - "hists['reso_unc'] = output['dataMC_reso_unc'].get()\n", + "hists[\"nom\"] = output[\"nominal\"].get()\n", + "hists[\"msv\"] = output[\"nominal_muonScaleSyst_responseWeights\"].get()\n", + "hists[\"non_closure_A\"] = output[\"nominal_Z_non_closure_parametrized_A\"].get()\n", + "hists[\"non_closure_M\"] = output[\"nominal_Z_non_closure_parametrized_M\"].get()\n", + "hists[\"reso_unc\"] = output[\"dataMC_reso_unc\"].get()\n", "\n", - "sel_nom = {'charge':1j, 'passIso':1j, 'passMT':1j}\n", - "sel_dn = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':0}\n", - "sel_up = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':1}\n", - "sel_dn_nc = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':13, 'downUpVar':0}\n", - "sel_up_nc = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':13, 'downUpVar':1}\n", - "sel_dn_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':64, 'downUpVar':0}\n", - "sel_up_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':64, 'downUpVar':1}\n", + "sel_nom = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j}\n", + "sel_dn = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 143, \"downUpVar\": 0}\n", + "sel_up = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 143, \"downUpVar\": 1}\n", + "sel_dn_nc = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 13, \"downUpVar\": 0}\n", + "sel_up_nc = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 13, \"downUpVar\": 1}\n", + "sel_dn_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 64, \"downUpVar\": 0}\n", + "sel_up_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 64, \"downUpVar\": 1}\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['msv'][sel_dn]),\n", - " action(hists['msv'][sel_up])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"msv\"][sel_dn]),\n", + " action(hists[\"msv\"][sel_up]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi stats spline #143 dn',\n", - " 'jpsi stats spline #143 up'\n", - " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " labels=[\"nominal\", \"jpsi stats spline #143 dn\", \"jpsi stats spline #143 up\"],\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mw_stats'\n", - "#save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", + "plot_basename = f\"mw_stats\"\n", + "# save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_A'][sel_dn_nc]),\n", - " action(hists['non_closure_A'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_A\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_A\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ up'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ up\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mw_ncA'\n", - "#save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", + "plot_basename = f\"mw_ncA\"\n", + "# save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_M'][sel_dn_nc]),\n", - " action(hists['non_closure_M'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_M\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_M\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ up'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ up\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mw_ncM'\n", - "#save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", + "plot_basename = f\"mw_ncM\"\n", + "# save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "for i in range(120):\n", - " sel_dn_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':i, 'downUpVar':0}\n", - " sel_up_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':i, 'downUpVar':1}\n", + " sel_dn_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": i, \"downUpVar\": 0}\n", + " sel_up_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": i, \"downUpVar\": 1}\n", " fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['reso_unc'][sel_dn_reso]),\n", - " action(hists['reso_unc'][sel_up_reso])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"reso_unc\"][sel_dn_reso]),\n", + " action(hists[\"reso_unc\"][sel_up_reso]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " f'data/MC resolution unc #{i} dn',\n", - " f'data/MC resolution unc #{i} up'\n", + " labels=[\n", + " \"nominal\",\n", + " f\"data/MC resolution unc #{i} dn\",\n", + " f\"data/MC resolution unc #{i} up\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", " )\n", - " \n", - "plot_basename = f'mw_reso_unc'\n", - "#save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)" + "\n", + "plot_basename = f\"mw_reso_unc\"\n", + "# save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)" ] }, { @@ -1962,97 +2069,90 @@ "##########################################\n", "# muon scale for the mz dilepton analysis\n", "##########################################\n", - "out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - "eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_alalyses'\n", + "out_dir = \"/home/submit/tyjyang/analysis/wmass/WRemnants/plots\"\n", + "eos_dir = \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_alalyses\"\n", "\n", "f = h5py.File(\"../hdf5Files/splines/mz_dilepton_scetlib_dyturboCorr.hdf5\", \"r\")\n", "results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - "proc = 'ZmumuPostVFP'\n", + "proc = \"ZmumuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$ Di-lepton'\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$ Di-lepton\",\n", "}\n", - "action = lambda x: x.project('mll')\n", - "output = results[proc]['output']\n", + "action = lambda x: x.project(\"mll\")\n", + "output = results[proc][\"output\"]\n", "hists = {}\n", - "hists['nom'] = output['nominal'].get()\n", - "hists['msv'] = output['nominal_muonScaleSyst_responseWeights'].get()\n", - "hists['non_closure_A'] = output['nominal_Z_non_closure_parametrized_A'].get()\n", - "hists['non_closure_M'] = output['nominal_Z_non_closure_parametrized_M'].get()\n", + "hists[\"nom\"] = output[\"nominal\"].get()\n", + "hists[\"msv\"] = output[\"nominal_muonScaleSyst_responseWeights\"].get()\n", + "hists[\"non_closure_A\"] = output[\"nominal_Z_non_closure_parametrized_A\"].get()\n", + "hists[\"non_closure_M\"] = output[\"nominal_Z_non_closure_parametrized_M\"].get()\n", "sel_nom = {}\n", - "sel_dn = {'unc':143, 'downUpVar':0}\n", - "sel_up = {'unc':143, 'downUpVar':1}\n", - "sel_dn_nc = {'unc':13, 'downUpVar':0}\n", - "sel_up_nc = {'unc':13, 'downUpVar':1}\n", + "sel_dn = {\"unc\": 143, \"downUpVar\": 0}\n", + "sel_up = {\"unc\": 143, \"downUpVar\": 1}\n", + "sel_dn_nc = {\"unc\": 13, \"downUpVar\": 0}\n", + "sel_up_nc = {\"unc\": 13, \"downUpVar\": 1}\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['msv'][sel_dn]),\n", - " action(hists['msv'][sel_up])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"msv\"][sel_dn]),\n", + " action(hists[\"msv\"][sel_up]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi stats spline #143 dn',\n", - " 'jpsi stats spline #143 up'\n", - " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9995, 1.0005],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'$m_{\\ell \\ell}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " labels=[\"nominal\", \"jpsi stats spline #143 dn\", \"jpsi stats spline #143 up\"],\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9995, 1.0005],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"$m_{\\ell \\ell}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_dilepton_stats'\n", + "plot_basename = f\"mz_dilepton_stats\"\n", "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_A'][sel_dn_nc]),\n", - " action(hists['non_closure_A'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_A\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_A\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ up'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ up\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.999, 1.001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'$m_{\\ell \\ell}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.999, 1.001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"$m_{\\ell \\ell}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_dilepton_ncA'\n", + "plot_basename = f\"mz_dilepton_ncA\"\n", "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_M'][sel_dn_nc]),\n", - " action(hists['non_closure_M'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_M\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_M\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ dn'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ dn\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'$m_{\\ell \\ell}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"$m_{\\ell \\ell}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_dilepton_ncM'\n", - "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", - " \n", - "\n", - " " + "plot_basename = f\"mz_dilepton_ncM\"\n", + "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)" ] }, { @@ -2112,95 +2212,93 @@ "##########################################\n", "import hdf5plugin\n", "\n", - "out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - "eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_alalyses'\n", + "out_dir = \"/home/submit/tyjyang/analysis/wmass/WRemnants/plots\"\n", + "eos_dir = \"/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/msv_all_alalyses\"\n", "\n", - "f = h5py.File(\"../hdf5Files/splines/mz_wlike_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"r\")\n", + "f = h5py.File(\n", + " \"../hdf5Files/splines/mz_wlike_with_mu_eta_pt_scetlib_dyturboCorr.hdf5\", \"r\"\n", + ")\n", "results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - "proc = 'ZmumuPostVFP'\n", + "proc = \"ZmumuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$ W-like $\\mu^+$',\n", - " 'Wmunu': r'$W \\rightarrow \\mu \\nu$',\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$ W-like $\\mu^+$\",\n", + " \"Wmunu\": r\"$W \\rightarrow \\mu \\nu$\",\n", "}\n", - "action = lambda x: x.project('pt')\n", - "output = results[proc]['output']\n", + "action = lambda x: x.project(\"pt\")\n", + "output = results[proc][\"output\"]\n", "hists = {}\n", - "hists['nom'] = output['nominal'].get()\n", - "hists['msv'] = output['nominal_muonScaleSyst_responseWeights'].get()\n", - "hists['non_closure_A'] = output['nominal_Z_non_closure_parametrized_A'].get()\n", - "hists['non_closure_M'] = output['nominal_Z_non_closure_parametrized_M'].get()\n", + "hists[\"nom\"] = output[\"nominal\"].get()\n", + "hists[\"msv\"] = output[\"nominal_muonScaleSyst_responseWeights\"].get()\n", + "hists[\"non_closure_A\"] = output[\"nominal_Z_non_closure_parametrized_A\"].get()\n", + "hists[\"non_closure_M\"] = output[\"nominal_Z_non_closure_parametrized_M\"].get()\n", "\n", - "sel_nom = {'charge': 1j}\n", - "sel_dn = {'charge': 1j, 'unc':143, 'downUpVar':0}\n", - "sel_up = {'charge': 1j, 'unc':143, 'downUpVar':1}\n", - "sel_dn_nc = {'charge': 1j, 'unc':13, 'downUpVar':0}\n", - "sel_up_nc = {'charge': 1j, 'unc':13, 'downUpVar':1}\n", + "sel_nom = {\"charge\": 1j}\n", + "sel_dn = {\"charge\": 1j, \"unc\": 143, \"downUpVar\": 0}\n", + "sel_up = {\"charge\": 1j, \"unc\": 143, \"downUpVar\": 1}\n", + "sel_dn_nc = {\"charge\": 1j, \"unc\": 13, \"downUpVar\": 0}\n", + "sel_up_nc = {\"charge\": 1j, \"unc\": 13, \"downUpVar\": 1}\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['msv'][sel_dn]),\n", - " action(hists['msv'][sel_up])\n", - " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi stats spline #143 dn',\n", - " 'jpsi stats spline #143 up'\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"msv\"][sel_dn]),\n", + " action(hists[\"msv\"][sel_up]),\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " labels=[\"nominal\", \"jpsi stats spline #143 dn\", \"jpsi stats spline #143 up\"],\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_wlike_stats'\n", + "plot_basename = f\"mz_wlike_stats\"\n", "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_A'][sel_dn_nc]),\n", - " action(hists['non_closure_A'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_A\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_A\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized A in $\\eta = (0.2, 0.4)$ up'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized A in $\\eta = (0.2, 0.4)$ up\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_wlike_ncA'\n", + "plot_basename = f\"mz_wlike_ncA\"\n", "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " action(hists['nom'][sel_nom]),\n", - " action(hists['non_closure_M'][sel_dn_nc]),\n", - " action(hists['non_closure_M'][sel_up_nc])\n", + " action(hists[\"nom\"][sel_nom]),\n", + " action(hists[\"non_closure_M\"][sel_dn_nc]),\n", + " action(hists[\"non_closure_M\"][sel_up_nc]),\n", " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ dn',\n", - " 'parametrized M in $\\eta = (0.2, 0.4)$ dn'\n", + " labels=[\n", + " \"nominal\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ dn\",\n", + " \"parametrized M in $\\eta = (0.2, 0.4)$ dn\",\n", " ],\n", - " colors = ['black','red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'{proc_name_latex[proc]}',\n", - " grid = True\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"{proc_name_latex[proc]}\",\n", + " grid=True,\n", ")\n", - "plot_basename = f'mz_wlike_ncM'\n", + "plot_basename = f\"mz_wlike_ncM\"\n", "save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=fig)" ] }, @@ -2235,14 +2333,14 @@ "import uproot\n", "from utilities import common\n", "\n", - "f = uproot.open(common.closure_filepaths['parametrized'])\n", - "closure_A = f['AZ'].to_hist()\n", + "f = uproot.open(common.closure_filepaths[\"parametrized\"])\n", + "closure_A = f[\"AZ\"].to_hist()\n", "fig, ax = plt.subplots()\n", "\n", - "hep.histplot(closure_A, yerr = False)\n", - "ax.axhline(7.5e-5, color = 'grey', linestyle = '--')\n", - "ax.set_xlabel('eta')\n", - "ax.set_ylabel('non-closure-A')" + "hep.histplot(closure_A, yerr=False)\n", + "ax.axhline(7.5e-5, color=\"grey\", linestyle=\"--\")\n", + "ax.set_xlabel(\"eta\")\n", + "ax.set_ylabel(\"non-closure-A\")" ] }, { @@ -2317,90 +2415,91 @@ "import uproot\n", "import narf\n", "import os\n", + "\n", "hep.style.use(hep.style.ROOT)\n", "\n", - "proc = 'WplusmunuPostVFP'\n", + "proc = \"WplusmunuPostVFP\"\n", "proc_name_latex = {\n", - " 'WplusmunuPostVFP': r'$W^+ \\rightarrow \\mu^+ \\nu$',\n", - " 'WminusmunuPostVFP': r'$W^- \\rightarrow \\mu^- \\nu$',\n", - " 'ZmumuPostVFP': r'$Z \\rightarrow \\mu^+ \\mu^-$'\n", + " \"WplusmunuPostVFP\": r\"$W^+ \\rightarrow \\mu^+ \\nu$\",\n", + " \"WminusmunuPostVFP\": r\"$W^- \\rightarrow \\mu^- \\nu$\",\n", + " \"ZmumuPostVFP\": r\"$Z \\rightarrow \\mu^+ \\mu^-$\",\n", "}\n", "\n", - "action = lambda x: x.project('pt')\n", + "action = lambda x: x.project(\"pt\")\n", "unc = {}\n", "\n", + "\n", "def save_pdf_and_png_toEos(outdir, plot_basename, eosdir, fig=None):\n", " plot_tools.save_pdf_and_png(out_dir, plot_basename, fig)\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}')\n", - " os.system(f'xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}')\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.pdf root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", + " os.system(\n", + " f\"xrdcp -f {out_dir}/{plot_basename}.png root://eosuser.cern.ch/{eos_dir}\"\n", + " )\n", "\n", "\n", - "sel_nom = {'charge':1j, 'passIso':1j, 'passMT':1j}\n", - "sel_dn = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':0}\n", - "sel_up = {'charge':1j, 'passIso':1j, 'passMT':1j, 'unc':143, 'downUpVar':1}\n", - "sel_dn_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'smearing_variation':59}\n", - "sel_up_reso = {'charge':1j, 'passIso':1j, 'passMT':1j, 'smearing_variation':59}\n", + "sel_nom = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j}\n", + "sel_dn = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 143, \"downUpVar\": 0}\n", + "sel_up = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"unc\": 143, \"downUpVar\": 1}\n", + "sel_dn_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"smearing_variation\": 59}\n", + "sel_up_reso = {\"charge\": 1j, \"passIso\": 1j, \"passMT\": 1j, \"smearing_variation\": 59}\n", "\n", - "with h5py.File(f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_NonClosureCorl.hdf5\", \"r\") as f:\n", + "with h5py.File(\n", + " f\"../hdf5Files/splines/mw_with_mu_eta_pt_scetlib_dyturboCorr_NonClosureCorl.hdf5\",\n", + " \"r\",\n", + ") as f:\n", " results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", - " print(results[proc]['output']['muonResolutionSyst_responseWeights'].get().axes)\n", - " nom = action(results[proc]['output']['nominal'].get()[sel_nom])\n", - " unc['spline_dn'] = action(results[proc]['output']['nominal_muonScaleSyst_responseWeights'].get()[sel_dn])\n", - " unc['spline_up'] = action(results[proc]['output']['nominal_muonScaleSyst_responseWeights'].get()[sel_up])\n", - " unc['reso_dn'] = action(results[proc]['output']['muonResolutionSyst_responseWeights'].get()[sel_dn_reso])\n", - " unc['reso_up'] = action(results[proc]['output']['muonResolutionSyst_responseWeights'].get()[sel_up_reso])\n", + " print(results[proc][\"output\"][\"muonResolutionSyst_responseWeights\"].get().axes)\n", + " nom = action(results[proc][\"output\"][\"nominal\"].get()[sel_nom])\n", + " unc[\"spline_dn\"] = action(\n", + " results[proc][\"output\"][\"nominal_muonScaleSyst_responseWeights\"].get()[sel_dn]\n", + " )\n", + " unc[\"spline_up\"] = action(\n", + " results[proc][\"output\"][\"nominal_muonScaleSyst_responseWeights\"].get()[sel_up]\n", + " )\n", + " unc[\"reso_dn\"] = action(\n", + " results[proc][\"output\"][\"muonResolutionSyst_responseWeights\"].get()[sel_dn_reso]\n", + " )\n", + " unc[\"reso_up\"] = action(\n", + " results[proc][\"output\"][\"muonResolutionSyst_responseWeights\"].get()[sel_up_reso]\n", + " )\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " nom,\n", - " unc['spline_dn'],\n", - " unc['spline_up']\n", - " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi stats spline dn',\n", - " 'jpsi stats spline up'\n", - " ],\n", - " colors = ['black', 'red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9999, 1.0001],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'AeM var #143 for {proc_name_latex[proc]} \\n $\\eta \\in (-2.4, 2.4)$',\n", - " grid = True\n", - " )\n", + " [nom, unc[\"spline_dn\"], unc[\"spline_up\"]],\n", + " labels=[\"nominal\", \"jpsi stats spline dn\", \"jpsi stats spline up\"],\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9999, 1.0001],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"AeM var #143 for {proc_name_latex[proc]} \\n $\\eta \\in (-2.4, 2.4)$\",\n", + " grid=True,\n", + ")\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " nom,\n", - " unc['reso_dn'],\n", - " unc['reso_up']\n", - " ],\n", - " labels = [\n", - " 'nominal',\n", - " 'jpsi reso dn',\n", - " 'jpsi reso up'\n", - " ],\n", - " colors = ['black', 'red', 'blue'], #'orange', 'orange'], #'orange', 'orange'],\n", - " rrange = [0.9995, 1.0005],\n", - " nlegcols = 1,\n", - " rlabel = 'var/nominal',\n", - " xlabel = r'RECO $p_T^{\\mu}$',\n", - " plot_title = f'AeM var for {proc_name_latex[proc]} \\n $\\eta \\in (-2.4, 2.4)$',\n", - " grid = True\n", - " )\n", - "#out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", - "#plot_basename = f'muonScaleComparison{dummyVar}_eta{etas[etabin]}_parameterFix'\n", - "#eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline'\n", - "#save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=None)\n", + " [nom, unc[\"reso_dn\"], unc[\"reso_up\"]],\n", + " labels=[\"nominal\", \"jpsi reso dn\", \"jpsi reso up\"],\n", + " colors=[\"black\", \"red\", \"blue\"], #'orange', 'orange'], #'orange', 'orange'],\n", + " rrange=[0.9995, 1.0005],\n", + " nlegcols=1,\n", + " rlabel=\"var/nominal\",\n", + " xlabel=r\"RECO $p_T^{\\mu}$\",\n", + " plot_title=f\"AeM var for {proc_name_latex[proc]} \\n $\\eta \\in (-2.4, 2.4)$\",\n", + " grid=True,\n", + ")\n", + "# out_dir = '/home/submit/tyjyang/analysis/wmass/WRemnants/plots'\n", + "# plot_basename = f'muonScaleComparison{dummyVar}_eta{etas[etabin]}_parameterFix'\n", + "# eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-stats-unc/spline'\n", + "# save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=None)\n", "\n", - "proc = 'ZmumuPostVFP'\n", - "action = lambda x: x.project('mll')\n", + "proc = \"ZmumuPostVFP\"\n", + "action = lambda x: x.project(\"mll\")\n", "sel_nom = {}\n", - "sel_dn = {'smearing_variation':61}\n", - "sel_up = {'smearing_variation':61}\n", - "sel_dn_stats = {'unc':143, 'downUpVar': 0}\n", - "sel_up_stats = {'unc':143, 'downUpVar': 1}\n", - "'''\n", + "sel_dn = {\"smearing_variation\": 61}\n", + "sel_up = {\"smearing_variation\": 61}\n", + "sel_dn_stats = {\"unc\": 143, \"downUpVar\": 0}\n", + "sel_up_stats = {\"unc\": 143, \"downUpVar\": 1}\n", + "\"\"\"\n", "with h5py.File(f\"../hdf5Files/splines/mz_dilepton_scetlib_dyturboCorr_NonClosureCorl.hdf5\", \"r\") as f:\n", " results = wums.ioutils.pickle_load_h5py(f[\"results\"])\n", " nom = action(results[proc]['output']['nominal'].get()[sel_nom])\n", @@ -2433,9 +2532,9 @@ " plot_basename = f'dilepton_resolutionVar_{i}'\n", " eos_dir = '/eos/user/t/tyjyang/www/plots/wmass/muon-calibration/jpsi-resoluton/'\n", " save_pdf_and_png_toEos(out_dir, plot_basename, eos_dir, fig=None)\n", - "'''\n", + "\"\"\"\n", "\n", - "'''\n", + "\"\"\"\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", " nom,\n", @@ -2455,7 +2554,7 @@ " plot_title = f'AeM var for {proc_name_latex[proc]} \\n $\\eta \\in (-2.4, 2.4)$',\n", " grid = True\n", " )\n", - "'''" + "\"\"\"" ] }, { diff --git a/notebooks/postfitPlots.ipynb b/notebooks/postfitPlots.ipynb index ff555d5df..51e44ccad 100644 --- a/notebooks/postfitPlots.ipynb +++ b/notebooks/postfitPlots.ipynb @@ -7,7 +7,7 @@ "metadata": {}, "outputs": [], "source": [ - "from utilities import input_tools, boostHistHelpers as hh,common\n", + "from utilities import input_tools, boostHistHelpers as hh, common\n", "from wremnants import theory_tools, theory_corrections, plot_tools\n", "import uproot\n", "import matplotlib.pyplot as plt\n", @@ -42,8 +42,12 @@ " bins = common.ptV_10quantiles_binning[:-1]\n", " elif bins == \"approx_quant\":\n", " bins = common.ptV_binning[:-1]\n", - " \n", - " return hist.Hist(hist.axis.Variable(bins, name=\"ptll\"), storage=h.storage_type(), data=h.view(flow=True)[:-1])" + "\n", + " return hist.Hist(\n", + " hist.axis.Variable(bins, name=\"ptll\"),\n", + " storage=h.storage_type(),\n", + " data=h.view(flow=True)[:-1],\n", + " )" ] }, { @@ -111,23 +115,24 @@ "with h5py.File(\"../fitresults_gen_quantilesBinning.hdf5\", \"r\") as h5file:\n", " res = ioutils.pickle_load_h5py(h5file[\"results\"])\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " redoBinning(res[\"hist_postfit_inclusive\"].get()),\n", - " redoBinning(res[\"hist_prefit_inclusive\"].get()),\n", - " redoBinning(res[\"hist_data_obs\"].get()),\n", - " ],\n", - " data=True,\n", - " labels=[\"postfit\", 'prefit', \"data\"],#\"muR\", \"\", \"muF\", \"\"],\n", - " colors=['purple', \"grey\", 'black'],\n", - " xlabel=\"p$_{T}^{Zgen}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " linestyles=[None, \"solid\", \"solid\"],\n", - " yerr=True,\n", - " binwnorm=1.,\n", - " rrange=[0.9, 1.1],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)" + " [\n", + " redoBinning(res[\"hist_postfit_inclusive\"].get()),\n", + " redoBinning(res[\"hist_prefit_inclusive\"].get()),\n", + " redoBinning(res[\"hist_data_obs\"].get()),\n", + " ],\n", + " data=True,\n", + " labels=[\"postfit\", \"prefit\", \"data\"], # \"muR\", \"\", \"muF\", \"\"],\n", + " colors=[\"purple\", \"grey\", \"black\"],\n", + " xlabel=\"p$_{T}^{Zgen}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " linestyles=[None, \"solid\", \"solid\"],\n", + " yerr=True,\n", + " binwnorm=1.0,\n", + " rrange=[0.9, 1.1],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " )" ] }, { @@ -140,23 +145,24 @@ "with h5py.File(\"../fitresults_gen_quantilesBinning.hdf5\", \"r\") as h5file:\n", " res = ioutils.pickle_load_h5py(h5file[\"results\"])\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " redoBinning(res[\"hist_postfit_inclusive\"].get()),\n", - " #redoBinning(res[\"hist_prefit_inclusive\"].get()),\n", - " redoBinning(res[\"hist_data_obs\"].get()),\n", - " ],\n", - " data=True,\n", - " labels=[\"postfit\", \"data\"],#\"muR\", \"\", \"muF\", \"\"],\n", - " colors=['purple', 'black'],\n", - " xlabel=\"p$_{T}^{Zgen}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " linestyles=[None, \"solid\", \"solid\"],\n", - " yerr=True,\n", - " binwnorm=1.,\n", - " rrange=[0.9, 1.1],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)" + " [\n", + " redoBinning(res[\"hist_postfit_inclusive\"].get()),\n", + " # redoBinning(res[\"hist_prefit_inclusive\"].get()),\n", + " redoBinning(res[\"hist_data_obs\"].get()),\n", + " ],\n", + " data=True,\n", + " labels=[\"postfit\", \"data\"], # \"muR\", \"\", \"muF\", \"\"],\n", + " colors=[\"purple\", \"black\"],\n", + " xlabel=\"p$_{T}^{Zgen}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " linestyles=[None, \"solid\", \"solid\"],\n", + " yerr=True,\n", + " binwnorm=1.0,\n", + " rrange=[0.9, 1.1],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " )" ] }, { @@ -187,23 +193,24 @@ "with h5py.File(\"../fitresults_gen.hdf5\", \"r\") as h5file:\n", " res = ioutils.pickle_load_h5py(h5file[\"results\"])\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " res[\"hist_postfit_inclusive\"].get(),\n", - " #res[\"hist_prefit_inclusive\"].get(),\n", - " res[\"hist_data_obs\"].get(),\n", - " ],\n", - " data=True,\n", - " labels=[\"postfit\", \"data\"],#\"muR\", \"\", \"muF\", \"\"],\n", - " colors=['purple', 'black'],\n", - " xlabel=\"p$_{T}^{Zgen}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " linestyles=[None, \"solid\", \"solid\"],\n", - " yerr=True,\n", - " binwnorm=1.,\n", - " rrange=[0.9, 1.1],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)" + " [\n", + " res[\"hist_postfit_inclusive\"].get(),\n", + " # res[\"hist_prefit_inclusive\"].get(),\n", + " res[\"hist_data_obs\"].get(),\n", + " ],\n", + " data=True,\n", + " labels=[\"postfit\", \"data\"], # \"muR\", \"\", \"muF\", \"\"],\n", + " colors=[\"purple\", \"black\"],\n", + " xlabel=\"p$_{T}^{Zgen}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " linestyles=[None, \"solid\", \"solid\"],\n", + " yerr=True,\n", + " binwnorm=1.0,\n", + " rrange=[0.9, 1.1],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " )" ] }, { @@ -242,11 +249,15 @@ "metadata": {}, "outputs": [], "source": [ - "d.getDatagroups()[\"Zmumu_prefit\"].hists[\"nominal\"] = d.results[\"hist_prefit_inclusive\"].get()\n", + "d.getDatagroups()[\"Zmumu_prefit\"].hists[\"nominal\"] = d.results[\n", + " \"hist_prefit_inclusive\"\n", + "].get()\n", "d.getDatagroups()[\"Zmumu_prefit\"].label += \" (prefit)\"\n", "d.getDatagroups()[\"Zmumu_prefit\"].color = \"darkblue\"\n", - "d.getDatagroups()[\"Zmumu_postfit\"].hists[\"nominal\"] = d.results[\"hist_postfit_inclusive\"].get()\n", - "#d.getDatagroups()[\"Zmumu_postfit\"].label += \" (postfit)\"\n", + "d.getDatagroups()[\"Zmumu_postfit\"].hists[\"nominal\"] = d.results[\n", + " \"hist_postfit_inclusive\"\n", + "].get()\n", + "# d.getDatagroups()[\"Zmumu_postfit\"].label += \" (postfit)\"\n", "d.getDatagroups()[\"Data\"].hists[\"nominal\"] = d.results[\"hist_data_obs\"].get()" ] }, @@ -328,19 +339,21 @@ } ], "source": [ - "fig = plot_tools.makeStackPlotWithRatio(groups,\n", - " [\n", - " \"Zmumu_postfit\",\n", - " ],\n", - " histName = \"nominal\",\n", - " unstacked = [\"Data\", \"Zmumu_prefit\"],\n", - " xlabel=\"p$_{T}^{Zgen}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/postfit\",\n", - " binwnorm=1.,\n", - " rrange=[0.9, 1.1],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)" + "fig = plot_tools.makeStackPlotWithRatio(\n", + " groups,\n", + " [\n", + " \"Zmumu_postfit\",\n", + " ],\n", + " histName=\"nominal\",\n", + " unstacked=[\"Data\", \"Zmumu_prefit\"],\n", + " xlabel=\"p$_{T}^{Zgen}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/postfit\",\n", + " binwnorm=1.0,\n", + " rrange=[0.9, 1.1],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")" ] } ], diff --git a/notebooks/scetlib.ipynb b/notebooks/scetlib.ipynb index 320e4be44..c4627186c 100644 --- a/notebooks/scetlib.ipynb +++ b/notebooks/scetlib.ipynb @@ -112,8 +112,23 @@ } ], "source": [ - "minnlohZ = minnlo[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"]*minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", - "minnlohW = (minnlo[\"WplusmunuPostVFP\"][\"output\"][\"nominal_gen\"]*minnlo[\"WplusmunuPostVFP\"][\"dataset\"][\"xsec\"]+minnlo[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"])*minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]/(minnlo[\"WplusmunuPostVFP\"][\"weight_sum\"]+minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"])\n" + "minnlohZ = (\n", + " minnlo[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ")\n", + "minnlohW = (\n", + " (\n", + " minnlo[\"WplusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo[\"WplusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " + minnlo[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " )\n", + " * minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / (\n", + " minnlo[\"WplusmunuPostVFP\"][\"weight_sum\"]\n", + " + minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", + " )\n", + ")" ] }, { @@ -123,8 +138,11 @@ "metadata": {}, "outputs": [], "source": [ - "minnlohZ_lowPrec = minnlo_lowprec[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"]*minnlo_lowprec[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo_lowprec[\"ZmumuPostVFP\"][\"weight_sum\"]\n", - "\n" + "minnlohZ_lowPrec = (\n", + " minnlo_lowprec[\"ZmumuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo_lowprec[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo_lowprec[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ")" ] }, { @@ -134,9 +152,21 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibhZ_tot = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\", charge=0)\n", - "scetlibhZ_A4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\", nonsing=None, flip_y_sign=True, charge=0)\n", - "scetlibhZ_nons = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_nons.npz\", nonsing=None, charge=0)" + "scetlibhZ_tot = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\",\n", + " charge=0,\n", + ")\n", + "scetlibhZ_A4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\",\n", + " nonsing=None,\n", + " flip_y_sign=True,\n", + " charge=0,\n", + ")\n", + "scetlibhZ_nons = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_nons.npz\",\n", + " nonsing=None,\n", + " charge=0,\n", + ")" ] }, { @@ -157,8 +187,16 @@ } ], "source": [ - "scetlibhZ_tot = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\", charge=0)\n", - "scetlibhZ_A4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\", nonsing=None, flip_y_sign=True, charge=0)" + "scetlibhZ_tot = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\",\n", + " charge=0,\n", + ")\n", + "scetlibhZ_A4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\",\n", + " nonsing=None,\n", + " flip_y_sign=True,\n", + " charge=0,\n", + ")" ] }, { @@ -217,7 +255,17 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([scetlibhZ_tot.project(\"y\"), scetlibhZ_A4.project(\"y\")], xlim=[-5, 5],colors=[\"red\", \"blue\",], labels=[\"total\", \"A$_{4}$\"], rrange=[-0.5, 0], binwnorm=1.)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [scetlibhZ_tot.project(\"y\"), scetlibhZ_A4.project(\"y\")],\n", + " xlim=[-5, 5],\n", + " colors=[\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\"total\", \"A$_{4}$\"],\n", + " rrange=[-0.5, 0],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -242,7 +290,16 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([scetlibhZ_tot.project(\"pt\"), scetlibhZ_A4.project(\"pt\")],colors=[\"red\", \"blue\",], labels=[\"total\", \"A$_{4}$\"], rrange=[-0.1, 0], binwnorm=1.)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [scetlibhZ_tot.project(\"pt\"), scetlibhZ_A4.project(\"pt\")],\n", + " colors=[\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\"total\", \"A$_{4}$\"],\n", + " rrange=[-0.1, 0],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -262,7 +319,9 @@ "metadata": {}, "outputs": [], "source": [ - "matrixRadish = theory_corrections.read_matrixRadish_hist(\"/home/k/kelong/MATRIX+RadISH/RadISH_observable_binning2__NNLO+N3LL.dat\")" + "matrixRadish = theory_corrections.read_matrixRadish_hist(\n", + " \"/home/k/kelong/MATRIX+RadISH/RadISH_observable_binning2__NNLO+N3LL.dat\"\n", + ")" ] }, { @@ -272,7 +331,14 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo = theory_corrections.read_dyturbo_hist([\"z-cms-wmass-n3lonnll_bornres.txt\", \"z-cms-wmass-n3lonnll_ctres_2.txt\", \"z-cms-wmass-n3lonnll_vj_2.txt\"], \"/home/k/kelong/work/Generators/DYTurboResults/\", )" + "dyturbo = theory_corrections.read_dyturbo_hist(\n", + " [\n", + " \"z-cms-wmass-n3lonnll_bornres.txt\",\n", + " \"z-cms-wmass-n3lonnll_ctres_2.txt\",\n", + " \"z-cms-wmass-n3lonnll_vj_2.txt\",\n", + " ],\n", + " \"/home/k/kelong/work/Generators/DYTurboResults/\",\n", + ")" ] }, { @@ -283,7 +349,18 @@ "outputs": [], "source": [ "s = hist.tag.Slicer()\n", - "minnlo_rebin, matrix_rad_rebin, dyturbo_rebin, scetlib_rebin = hh.rebinHistsToCommon([minnlohZ[{\"massVgen\": s[0:minnlohZ.axes[\"massVgen\"].size:hist.sum]}].project(\"ptVgen\"), matrixRadish, dyturbo, scetlibh.project('pt')], 0, True)\n" + "minnlo_rebin, matrix_rad_rebin, dyturbo_rebin, scetlib_rebin = hh.rebinHistsToCommon(\n", + " [\n", + " minnlohZ[\n", + " {\"massVgen\": s[0 : minnlohZ.axes[\"massVgen\"].size : hist.sum]}\n", + " ].project(\"ptVgen\"),\n", + " matrixRadish,\n", + " dyturbo,\n", + " scetlibh.project(\"pt\"),\n", + " ],\n", + " 0,\n", + " True,\n", + ")" ] }, { @@ -314,13 +391,58 @@ } ], "source": [ - "dyturbo_all = theory_corrections.read_dyturbo_hist([\"z-cms-wmass-n3lonnll_bornres.txt\", \"z-cms-wmass-n3lonnll_ctres_2.txt\", \"z-cms-wmass-n3lonnll_vj_2.txt\"], \"/home/k/kelong/work/Generators/DYTurboResults/\")\n", - "dyturbo_resum = theory_corrections.read_dyturbo_hist([\"z-cms-wmass-n3lonnll_bornres.txt\", \"z-cms-wmass-n3lonnll_ctres_2.txt\",], \"/home/k/kelong/work/Generators/DYTurboResults/\")\n", - "dyturbo_resumOnly = theory_corrections.read_dyturbo_hist([\"z-cms-wmass-n3lonnll_bornres.txt\",], \"/home/k/kelong/work/Generators/DYTurboResults/\")\n", - "dyturbo_fo = theory_corrections.read_dyturbo_hist([\"z-cms-wmass-n3lonnll_vj_2.txt\"], \"/home/k/kelong/work/Generators/DYTurboResults/\")\n", + "dyturbo_all = theory_corrections.read_dyturbo_hist(\n", + " [\n", + " \"z-cms-wmass-n3lonnll_bornres.txt\",\n", + " \"z-cms-wmass-n3lonnll_ctres_2.txt\",\n", + " \"z-cms-wmass-n3lonnll_vj_2.txt\",\n", + " ],\n", + " \"/home/k/kelong/work/Generators/DYTurboResults/\",\n", + ")\n", + "dyturbo_resum = theory_corrections.read_dyturbo_hist(\n", + " [\n", + " \"z-cms-wmass-n3lonnll_bornres.txt\",\n", + " \"z-cms-wmass-n3lonnll_ctres_2.txt\",\n", + " ],\n", + " \"/home/k/kelong/work/Generators/DYTurboResults/\",\n", + ")\n", + "dyturbo_resumOnly = theory_corrections.read_dyturbo_hist(\n", + " [\n", + " \"z-cms-wmass-n3lonnll_bornres.txt\",\n", + " ],\n", + " \"/home/k/kelong/work/Generators/DYTurboResults/\",\n", + ")\n", + "dyturbo_fo = theory_corrections.read_dyturbo_hist(\n", + " [\"z-cms-wmass-n3lonnll_vj_2.txt\"], \"/home/k/kelong/work/Generators/DYTurboResults/\"\n", + ")\n", "\n", "\n", - "fig = plot_tools.makePlotWithRatioToRef([matrix_rad_rebin, dyturbo_all, dyturbo_resum, dyturbo_resumOnly, dyturbo_fo, ],colors=[\"green\", \"red\", \"purple\", \"orange\", \"blue\",], labels=[\"MATRIX+RadISH\", \"DYTurbo N3LL+NNLO\", \"DYTrubo N3LL+CT\", \"DYTurbo N3LL\", \"DYTrubo NNLO\", ], rrange=[0.85, 1.15], binwnorm=1., rlabel=\"x/Mat+Rad\")" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [\n", + " matrix_rad_rebin,\n", + " dyturbo_all,\n", + " dyturbo_resum,\n", + " dyturbo_resumOnly,\n", + " dyturbo_fo,\n", + " ],\n", + " colors=[\n", + " \"green\",\n", + " \"red\",\n", + " \"purple\",\n", + " \"orange\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\n", + " \"MATRIX+RadISH\",\n", + " \"DYTurbo N3LL+NNLO\",\n", + " \"DYTrubo N3LL+CT\",\n", + " \"DYTurbo N3LL\",\n", + " \"DYTrubo NNLO\",\n", + " ],\n", + " rrange=[0.85, 1.15],\n", + " binwnorm=1.0,\n", + " rlabel=\"x/Mat+Rad\",\n", + ")" ] }, { @@ -351,7 +473,25 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([matrix_rad_rebin, minnlo_rebin, scetlib_rebin, dyturbo_rebin],colors=[\"green\", \"red\", \"purple\", \"blue\", ], labels=[\"MATRIX+RadISH\", \"MiNNLO\", \"SCETlib\", \"DYTrubo\", ], rrange=[0.85, 1.15], xlim=[0, 50], binwnorm=1., rlabel=\"x/Mat+Rad\")" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [matrix_rad_rebin, minnlo_rebin, scetlib_rebin, dyturbo_rebin],\n", + " colors=[\n", + " \"green\",\n", + " \"red\",\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\n", + " \"MATRIX+RadISH\",\n", + " \"MiNNLO\",\n", + " \"SCETlib\",\n", + " \"DYTrubo\",\n", + " ],\n", + " rrange=[0.85, 1.15],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " rlabel=\"x/Mat+Rad\",\n", + ")" ] }, { @@ -382,7 +522,24 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([matrix_rad_rebin, minnlo_rebin, scetlib_rebin, dyturbo],colors=[\"green\", \"red\", \"purple\", \"blue\", ], labels=[\"MATRIX+RadISH\", \"MiNNLO\", \"SCETlib\", \"DYTrubo\", ], rrange=[0.85, 1.15], binwnorm=1., rlabel=\"x/Mat+Rad\")" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [matrix_rad_rebin, minnlo_rebin, scetlib_rebin, dyturbo],\n", + " colors=[\n", + " \"green\",\n", + " \"red\",\n", + " \"purple\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\n", + " \"MATRIX+RadISH\",\n", + " \"MiNNLO\",\n", + " \"SCETlib\",\n", + " \"DYTrubo\",\n", + " ],\n", + " rrange=[0.85, 1.15],\n", + " binwnorm=1.0,\n", + " rlabel=\"x/Mat+Rad\",\n", + ")" ] }, { @@ -413,7 +570,16 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([minnlo_rebin.project(\"absYVgen\"), scetlibh.project(\"absy\")],colors=[\"red\", \"blue\",], labels=[\"MiNNLO\", \"SCETlib\"], rrange=[0.95, 1.05], binwnorm=1.)\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [minnlo_rebin.project(\"absYVgen\"), scetlibh.project(\"absy\")],\n", + " colors=[\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " labels=[\"MiNNLO\", \"SCETlib\"],\n", + " rrange=[0.95, 1.05],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -423,10 +589,10 @@ "metadata": {}, "outputs": [], "source": [ - "x = corr[20.j:40.j].axes[\"ptVgen\"].centers\n", - "params = np.polyfit(y=corr[20.j:40.j].values(), x=x, deg = 2)\n", + "x = corr[20.0j:40.0j].axes[\"ptVgen\"].centers\n", + "params = np.polyfit(y=corr[20.0j:40.0j].values(), x=x, deg=2)\n", "poly = np.poly1d(params)\n", - "xeval = corr[30.j:40.j].axes[\"ptVgen\"].centers" + "xeval = corr[30.0j:40.0j].axes[\"ptVgen\"].centers" ] }, { @@ -437,7 +603,7 @@ "outputs": [], "source": [ "corr_orig = corr.copy()\n", - "corr[30:40] = np.stack((poly(xeval), corr[30.j:40.j].variances()), axis=-1)" + "corr[30:40] = np.stack((poly(xeval), corr[30.0j:40.0j].variances()), axis=-1)" ] }, { @@ -470,9 +636,17 @@ } ], "source": [ - "scetlibh_tot = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm.npz\")\n", - "scetlibh_A4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_A4.npz\", flip_y_sign=True)\n", - "scetlibh_tot_s = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm.npz\", nonsing=\"\")\n", + "scetlibh_tot = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm.npz\"\n", + ")\n", + "scetlibh_A4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_A4.npz\",\n", + " flip_y_sign=True,\n", + ")\n", + "scetlibh_tot_s = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm.npz\",\n", + " nonsing=\"\",\n", + ")\n", "scetlibh_tot.shape" ] }, @@ -484,8 +658,12 @@ "outputs": [], "source": [ "scetlib_A4_coeff = hh.divideHists(scetlibh_A4, scetlibh_tot, cutoff=0.0001)\n", - "scetlib_A4_coeff_pt = hh.divideHists(scetlibh_A4.project(\"pt\"), scetlibh_tot.project(\"pt\"), cutoff=0.0001)\n", - "scetlib_A4_coeff_y = hh.divideHists(scetlibh_A4.project(\"y\"), scetlibh_tot.project(\"y\"), cutoff=0.0001)" + "scetlib_A4_coeff_pt = hh.divideHists(\n", + " scetlibh_A4.project(\"pt\"), scetlibh_tot.project(\"pt\"), cutoff=0.0001\n", + ")\n", + "scetlib_A4_coeff_y = hh.divideHists(\n", + " scetlibh_A4.project(\"y\"), scetlibh_tot.project(\"y\"), cutoff=0.0001\n", + ")" ] }, { @@ -495,8 +673,8 @@ "metadata": {}, "outputs": [], "source": [ - "#scetlibW_y_tot = scetlib_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_y_binMinnlo.npz\", add_nonsing=True)\n", - "#scetlibW_y_A4 = scetlib_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_y_binMinnlo_A4.npz\", add_nonsing=True, flip_y_sign=True)" + "# scetlibW_y_tot = scetlib_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_y_binMinnlo.npz\", add_nonsing=True)\n", + "# scetlibW_y_A4 = scetlib_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_y_binMinnlo_A4.npz\", add_nonsing=True, flip_y_sign=True)" ] }, { @@ -517,7 +695,9 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_absy_A4_coeff = hh.divideHists(scetlibW_A4.project(\"absy\"), scetlibW_tot.project(\"absy\"))" + "scetlib_absy_A4_coeff = hh.divideHists(\n", + " scetlibW_A4.project(\"absy\"), scetlibW_tot.project(\"absy\")\n", + ")" ] }, { @@ -563,12 +743,28 @@ "metadata": {}, "outputs": [], "source": [ - "minnloZhel = minnlo[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"]*minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", - "minnloWmhel = minnlo[\"WminusmunuPostVFP\"][\"output\"][\"helicity_moments_scale\"]*minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", - "minnloWm = minnlo[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"]*minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", - "minnloWphel = minnlo[\"WplusmunuPostVFP\"][\"output\"][\"helicity_moments_scale\"]*minnlo[\"WplusmunuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"WplusmunuPostVFP\"][\"weight_sum\"]\n", + "minnloZhel = (\n", + " minnlo[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"]\n", + " * minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ")\n", + "minnloWmhel = (\n", + " minnlo[\"WminusmunuPostVFP\"][\"output\"][\"helicity_moments_scale\"]\n", + " * minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", + ")\n", + "minnloWm = (\n", + " minnlo[\"WminusmunuPostVFP\"][\"output\"][\"nominal_gen\"]\n", + " * minnlo[\"WminusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"WminusmunuPostVFP\"][\"weight_sum\"]\n", + ")\n", + "minnloWphel = (\n", + " minnlo[\"WplusmunuPostVFP\"][\"output\"][\"helicity_moments_scale\"]\n", + " * minnlo[\"WplusmunuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"WplusmunuPostVFP\"][\"weight_sum\"]\n", + ")\n", "\n", - "minnloWhel_cen = minnloWmhel[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}]" + "minnloWhel_cen = minnloWmhel[{\"muRfact\": 1.0j, \"muFfact\": 1.0j}]" ] }, { @@ -589,7 +785,7 @@ } ], "source": [ - "minnloWhel_cen[{\"helicity\" : -1.j}].sum()" + "minnloWhel_cen[{\"helicity\": -1.0j}].sum()" ] }, { @@ -610,7 +806,7 @@ } ], "source": [ - "minnlohW[{\"chargeVgen\" : -1.j}].sum(flow=True)" + "minnlohW[{\"chargeVgen\": -1.0j}].sum(flow=True)" ] }, { @@ -652,7 +848,7 @@ } ], "source": [ - "minnloWmhel[{\"helicity\" : -1.j}].sum(flow=True)" + "minnloWmhel[{\"helicity\": -1.0j}].sum(flow=True)" ] }, { @@ -662,8 +858,14 @@ "metadata": {}, "outputs": [], "source": [ - "hists = hh.rebinHistsToCommon([minnloWmhel[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}], scetlibW_A4, scetlibW_tot], 2, False)\n", - "minnlohel_rebin, scetlibW_A4_rebin, scetlibW_tot_rebin = hh.rebinHistsToCommon(hists, 1, False)" + "hists = hh.rebinHistsToCommon(\n", + " [minnloWmhel[{\"muRfact\": 1.0j, \"muFfact\": 1.0j}], scetlibW_A4, scetlibW_tot],\n", + " 2,\n", + " False,\n", + ")\n", + "minnlohel_rebin, scetlibW_A4_rebin, scetlibW_tot_rebin = hh.rebinHistsToCommon(\n", + " hists, 1, False\n", + ")" ] }, { @@ -696,7 +898,7 @@ } ], "source": [ - "minnlohel_rebin[{\"helicity\" : -1.j}].project(\"ptVgen\").plot()\n", + "minnlohel_rebin[{\"helicity\": -1.0j}].project(\"ptVgen\").plot()\n", "scetlibW_tot_rebin.project(\"pt\").plot()" ] }, @@ -727,8 +929,8 @@ } ], "source": [ - "print(minnlohel_rebin[{\"helicity\" : 4.j}].sum())\n", - "print(minnlohel_scaled[{\"helicity\" : -1.j}].sum())\n", + "print(minnlohel_rebin[{\"helicity\": 4.0j}].sum())\n", + "print(minnlohel_scaled[{\"helicity\": -1.0j}].sum())\n", "print(scetlibW_tot_rebin.sum())" ] }, @@ -752,8 +954,24 @@ } ], "source": [ - "hists_to_plot = [minnlohel_scaled[{\"helicity\" : 4.j}].project(\"ptVgen\"), scetlibW_A4_rebin.project(\"pt\")]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists_to_plot, colors=[\"orange\", \"purple\",], ylim=[-400, 50], ylabel=\"$\\sigma_{4}$/bin\", xlabel=r\"p$_{\\mathrm{T}}^{\\mathrm{W}^{-}}$\", labels=[\"MiNNLO\", \"SCETlib\"], rlabel=\"$\\sigma$/bin\", rrange=[0.9, 1.1], binwnorm=1.)\n" + "hists_to_plot = [\n", + " minnlohel_scaled[{\"helicity\": 4.0j}].project(\"ptVgen\"),\n", + " scetlibW_A4_rebin.project(\"pt\"),\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists_to_plot,\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " ],\n", + " ylim=[-400, 50],\n", + " ylabel=\"$\\sigma_{4}$/bin\",\n", + " xlabel=r\"p$_{\\mathrm{T}}^{\\mathrm{W}^{-}}$\",\n", + " labels=[\"MiNNLO\", \"SCETlib\"],\n", + " rlabel=\"$\\sigma$/bin\",\n", + " rrange=[0.9, 1.1],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -776,8 +994,23 @@ } ], "source": [ - "hists_to_plot = [minnlohel_scaled[{\"helicity\" : 4.j}].project(\"absYVgen\"), scetlibW_A4_rebin.project(\"absy\")]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists_to_plot, colors=[\"orange\", \"purple\",], ylabel=\"$\\sigma_{4}$/bin\", xlabel=r\"$|\\mathrm{y}^{\\mathrm{W}^{-}}|$\", labels=[\"MiNNLO\", \"SCETlib\"], rlabel=\"$\\sigma$/bin\", rrange=[0.9, 1.1], binwnorm=1.)\n" + "hists_to_plot = [\n", + " minnlohel_scaled[{\"helicity\": 4.0j}].project(\"absYVgen\"),\n", + " scetlibW_A4_rebin.project(\"absy\"),\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists_to_plot,\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " ],\n", + " ylabel=\"$\\sigma_{4}$/bin\",\n", + " xlabel=r\"$|\\mathrm{y}^{\\mathrm{W}^{-}}|$\",\n", + " labels=[\"MiNNLO\", \"SCETlib\"],\n", + " rlabel=\"$\\sigma$/bin\",\n", + " rrange=[0.9, 1.1],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -800,10 +1033,29 @@ } ], "source": [ - "minnlo_coeffs = theory_tools.moments_to_angular_coeffs(minnlohel_rebin.project(\"absYVgen\", \"helicity\"))\n", - "scetlib_A4_coeff = hh.divideHists(scetlibW_A4_rebin.project(\"absy\"), scetlibW_tot_rebin.project(\"absy\"))\n", - "coeff_hists_to_plot = [minnlo_coeffs[{\"helicity\" : 4.j}].project(\"absYVgen\"), scetlib_A4_coeff.project(\"absy\")]\n", - "fig = plot_tools.makePlotWithRatioToRef(coeff_hists_to_plot, colors=[\"orange\", \"purple\",], rlabel=\"x/MiNNLO\", ylabel=\"A$_{4}$/bin\", xlabel=r\"$|\\mathrm{y}^{\\mathrm{W}^{-}}|$\", labels=[\"MiNNLO\", \"SCETlib\"], rrange=[0.9, 1.1], binwnorm=1.)" + "minnlo_coeffs = theory_tools.moments_to_angular_coeffs(\n", + " minnlohel_rebin.project(\"absYVgen\", \"helicity\")\n", + ")\n", + "scetlib_A4_coeff = hh.divideHists(\n", + " scetlibW_A4_rebin.project(\"absy\"), scetlibW_tot_rebin.project(\"absy\")\n", + ")\n", + "coeff_hists_to_plot = [\n", + " minnlo_coeffs[{\"helicity\": 4.0j}].project(\"absYVgen\"),\n", + " scetlib_A4_coeff.project(\"absy\"),\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " coeff_hists_to_plot,\n", + " colors=[\n", + " \"orange\",\n", + " \"purple\",\n", + " ],\n", + " rlabel=\"x/MiNNLO\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " xlabel=r\"$|\\mathrm{y}^{\\mathrm{W}^{-}}|$\",\n", + " labels=[\"MiNNLO\", \"SCETlib\"],\n", + " rrange=[0.9, 1.1],\n", + " binwnorm=1.0,\n", + ")" ] }, { @@ -828,8 +1080,14 @@ } ], "source": [ - "scetlibZ_A4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_pT_A4.npz\", nonsing=\"\", flip_y_sign=True)\n", - "scetlibZ_tot = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_pT.npz\")\n", + "scetlibZ_A4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_pT_A4.npz\",\n", + " nonsing=\"\",\n", + " flip_y_sign=True,\n", + ")\n", + "scetlibZ_tot = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z_pT.npz\"\n", + ")\n", "scetlibZ_A4 = hh.makeAbsHist(scetlibZ_A4, \"y\")\n", "scetlibZ_tot = hh.makeAbsHist(scetlibZ_tot, \"y\")" ] @@ -862,7 +1120,13 @@ "metadata": {}, "outputs": [], "source": [ - "minnlohelZ = minnlo[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}]*minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]" + "minnlohelZ = (\n", + " minnlo[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + " ]\n", + " * minnlo[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ")" ] }, { @@ -872,7 +1136,13 @@ "metadata": {}, "outputs": [], "source": [ - "minnlohelZ_lowprec = minnlo_lowprec[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}]*minnlo_lowprec[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]/minnlo_lowprec[\"ZmumuPostVFP\"][\"weight_sum\"]" + "minnlohelZ_lowprec = (\n", + " minnlo_lowprec[\"ZmumuPostVFP\"][\"output\"][\"helicity_moments_scale\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + " ]\n", + " * minnlo_lowprec[\"ZmumuPostVFP\"][\"dataset\"][\"xsec\"]\n", + " / minnlo_lowprec[\"ZmumuPostVFP\"][\"weight_sum\"]\n", + ")" ] }, { @@ -906,8 +1176,14 @@ "metadata": {}, "outputs": [], "source": [ - "ha0 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\" : 0.j}], (\"ptVgen\", \"absYVgen\"))\n", - "ha4 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\" : 4.j}], (\"absYVgen\", \"ptVgen\", ))" + "ha0 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\": 0.0j}], (\"ptVgen\", \"absYVgen\"))\n", + "ha4 = sel.unrolledHist(\n", + " minnlohelZ_coeffs[{\"helicity\": 4.0j}],\n", + " (\n", + " \"absYVgen\",\n", + " \"ptVgen\",\n", + " ),\n", + ")" ] }, { @@ -985,8 +1261,14 @@ "metadata": {}, "outputs": [], "source": [ - "ha0 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\" : 0.j}], (\"ptVgen\", \"absYVgen\"))\n", - "ha4 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\" : 4.j}], (\"absYVgen\", \"ptVgen\", ))" + "ha0 = sel.unrolledHist(minnlohelZ_coeffs[{\"helicity\": 0.0j}], (\"ptVgen\", \"absYVgen\"))\n", + "ha4 = sel.unrolledHist(\n", + " minnlohelZ_coeffs[{\"helicity\": 4.0j}],\n", + " (\n", + " \"absYVgen\",\n", + " \"ptVgen\",\n", + " ),\n", + ")" ] }, { @@ -1010,7 +1292,7 @@ "source": [ "scetlibZ_A4, minnlohelZ = hh.rebinHistsToCommon([scetlibZ_A4, minnlohelZ], 1)\n", "minnlohelZ_scaled = theory_tools.scale_angular_moments(minnlohelZ)\n", - "minnlohelZ_A4_scaled = minnlohelZ_scaled[{\"helicity\" : 4.j}]" + "minnlohelZ_A4_scaled = minnlohelZ_scaled[{\"helicity\": 4.0j}]" ] }, { @@ -1085,7 +1367,7 @@ } ], "source": [ - "minnlohelZ_scaled[{\"helicity\" : 4.j}].project(\"absYVgen\").plot(yerr=False)\n", + "minnlohelZ_scaled[{\"helicity\": 4.0j}].project(\"absYVgen\").plot(yerr=False)\n", "scetlibZ_A4.project(\"absy\").plot(yerr=False)" ] }, @@ -1108,8 +1390,12 @@ } ], "source": [ - "scetlibZ_a4_coeff_y = scetlib_corrections.make_a4_coeff(scetlibZ_A4.project(\"absy\"), scetlibZ_tot.project(\"absy\"))\n", - "minnlohelZ_coeffs_y = theory_tools.moments_to_angular_coeffs(minnlohelZ.project(\"absYVgen\", \"helicity\"))" + "scetlibZ_a4_coeff_y = scetlib_corrections.make_a4_coeff(\n", + " scetlibZ_A4.project(\"absy\"), scetlibZ_tot.project(\"absy\")\n", + ")\n", + "minnlohelZ_coeffs_y = theory_tools.moments_to_angular_coeffs(\n", + " minnlohelZ.project(\"absYVgen\", \"helicity\")\n", + ")" ] }, { @@ -1163,7 +1449,7 @@ ], "source": [ "scetlibZ_a4_coeff_y.plot()\n", - "minnlohelZ_coeffs_y[{\"helicity\" : 4.j}].plot()" + "minnlohelZ_coeffs_y[{\"helicity\": 4.0j}].plot()" ] }, { @@ -1185,7 +1471,9 @@ } ], "source": [ - "scetlibZ_a4_coeff = theory_corrections.make_a4_coeff(scetlibZ_A4.project(\"pt\"), scetlibZ_tot.project(\"pt\"))\n" + "scetlibZ_a4_coeff = theory_corrections.make_a4_coeff(\n", + " scetlibZ_A4.project(\"pt\"), scetlibZ_tot.project(\"pt\")\n", + ")" ] }, { @@ -1208,7 +1496,7 @@ ], "source": [ "scetlibZ_a4_coeff.project(\"pt\").plot()\n", - "minnlohelZ_coeffs_pt[{\"helicity\" : 4.j}].plot()" + "minnlohelZ_coeffs_pt[{\"helicity\": 4.0j}].plot()" ] }, { @@ -1242,7 +1530,7 @@ ], "source": [ "for i in range(8):\n", - " minnlohelZ[{\"helicity\" : i}].project(\"ptVgen\").plot(label=f\"$\\sigma_{{{i-1}}}$\")\n", + " minnlohelZ[{\"helicity\": i}].project(\"ptVgen\").plot(label=f\"$\\sigma_{{{i-1}}}$\")\n", "\n", "plt.legend()\n", "plt.title(\"Z structure functions\")" @@ -1279,7 +1567,7 @@ ], "source": [ "for i in range(-1, 8):\n", - " minnloWmhel[{\"helicity\" : i+1}].project(\"ptVgen\").plot(label=f\"$\\sigma_{{{i}}}$\")\n", + " minnloWmhel[{\"helicity\": i + 1}].project(\"ptVgen\").plot(label=f\"$\\sigma_{{{i}}}$\")\n", "\n", "plt.legend()" ] @@ -1323,7 +1611,7 @@ ], "source": [ "for i in range(-1, 8):\n", - " minnloWmhel[{\"helicity\" : i+1}].project(\"absYVgen\").plot(label=f\"$\\sigma_{{{i}}}$\")\n", + " minnloWmhel[{\"helicity\": i + 1}].project(\"absYVgen\").plot(label=f\"$\\sigma_{{{i}}}$\")\n", "\n", "plt.legend()" ] @@ -1371,7 +1659,14 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([minnloCoeffs[{\"helicity\" : 4.j}], scetlib_absy_A4_coeff], colors=[\"red\", \"blue\"], labels=[\"minnlo\", \"scetlib\"], ylabel=\"A$_{4}$\", rrange=[0.9, 1.1], rlabel=\"scetlib/minnlo\")" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [minnloCoeffs[{\"helicity\": 4.0j}], scetlib_absy_A4_coeff],\n", + " colors=[\"red\", \"blue\"],\n", + " labels=[\"minnlo\", \"scetlib\"],\n", + " ylabel=\"A$_{4}$\",\n", + " rrange=[0.9, 1.1],\n", + " rlabel=\"scetlib/minnlo\",\n", + ")" ] }, { @@ -1392,7 +1687,9 @@ "metadata": {}, "outputs": [], "source": [ - "f = uproot.open(\"/eos/user/k/kelong/HistFiles/ZGen/ZToMuMu_MATRIX_RadISH_MatchEWParams_NNPDF31.root\")" + "f = uproot.open(\n", + " \"/eos/user/k/kelong/HistFiles/ZGen/ZToMuMu_MATRIX_RadISH_MatchEWParams_NNPDF31.root\"\n", + ")" ] }, { @@ -1436,7 +1733,7 @@ "outputs": [], "source": [ "dyturboMatch = matrixRadish.copy()\n", - "dyturboMatch[:40] = dyturboh.view()/1000" + "dyturboMatch[:40] = dyturboh.view() / 1000" ] }, { @@ -1480,7 +1777,26 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"ptll\"), out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"ptll\"), ], colors=[\"blue\", \"green\", ], labels=[\"MiNNLO uncorr\", \"MNNLO+SCETlib\", ], rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", rlabel=\"x/NNLO+N$^{3}$LL\", nlegcols=1, binwnorm=True)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"ptll\"),\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"ptll\"),\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"MiNNLO uncorr\",\n", + " \"MNNLO+SCETlib\",\n", + " ],\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/NNLO+N$^{3}$LL\",\n", + " nlegcols=1,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1503,7 +1819,29 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"mll\"), out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"mll\"), ], colors=[\"blue\", \"green\", ], labels=[\"MiNNLO uncorr\", \"MNNLO+SCETlib\", ], rrange=[0.9, 1.1,], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", rlabel=\"x/NNLO+N$^{3}$LL\", nlegcols=1, binwnorm=True)\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"mll\"),\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"mll\"),\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"MiNNLO uncorr\",\n", + " \"MNNLO+SCETlib\",\n", + " ],\n", + " rrange=[\n", + " 0.9,\n", + " 1.1,\n", + " ],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/NNLO+N$^{3}$LL\",\n", + " nlegcols=1,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1526,7 +1864,26 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"yll\"), out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"yll\"), ], colors=[\"blue\", \"green\", ], labels=[\"MiNNLO uncorr\", \"MNNLO+SCETlib\", ], rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", rlabel=\"x/NNLO+N$^{3}$LL\", nlegcols=1, binwnorm=True)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton_uncorr\"].project(\"yll\"),\n", + " out[\"ZmumuPostVFP\"][\"output\"][\"dilepton\"].project(\"yll\"),\n", + " ],\n", + " colors=[\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"MiNNLO uncorr\",\n", + " \"MNNLO+SCETlib\",\n", + " ],\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/NNLO+N$^{3}$LL\",\n", + " nlegcols=1,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1564,7 +1921,10 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibA4 = theory_corrections.read_scetlib_hist(\"/home/k/kelong//work/Generators/TheoryCorrections/SCETlib/Z/results/inclusive_Z_2D_yqt_A4_pdf0.npz\", flip_y_sign=True)" + "scetlibA4 = theory_corrections.read_scetlib_hist(\n", + " \"/home/k/kelong//work/Generators/TheoryCorrections/SCETlib/Z/results/inclusive_Z_2D_yqt_A4_pdf0.npz\",\n", + " flip_y_sign=True,\n", + ")" ] }, { @@ -1661,7 +2021,12 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibWA4 = theory_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm_A4.npz\", flip_y_sign=True, nonsing=\"\", charge=-1)\n" + "scetlibWA4 = theory_corrections.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm_A4.npz\",\n", + " flip_y_sign=True,\n", + " nonsing=\"\",\n", + " charge=-1,\n", + ")" ] }, { @@ -1681,7 +2046,10 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibh_A4 = theory_corrections.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_A4.npz\", flip_y_sign=True)\n", + "scetlibh_A4 = theory_corrections.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Wm/inclusive_Wm_A4.npz\",\n", + " flip_y_sign=True,\n", + ")\n", "scetlibh_absy_A4 = hh.makeAbsHist(scetlibh_A4, \"y\")" ] }, @@ -1713,7 +2081,13 @@ "metadata": {}, "outputs": [], "source": [ - "hists = hh.rebinHistsToCommon([scetlibh_absy_A4.project(\"pt\", \"absy\"), minnlohel_scaled[{\"helicity\" : 4.j}].project(\"ptVgen\", \"absYVgen\")], 0)\n", + "hists = hh.rebinHistsToCommon(\n", + " [\n", + " scetlibh_absy_A4.project(\"pt\", \"absy\"),\n", + " minnlohel_scaled[{\"helicity\": 4.0j}].project(\"ptVgen\", \"absYVgen\"),\n", + " ],\n", + " 0,\n", + ")\n", "hists = hh.rebinHistsToCommon(hists, 1)" ] }, @@ -1732,8 +2106,20 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_Wm_unrol = sel.unrolledHist(hists[0], (\"absy\", \"pt\", ))\n", - "minnlo_Wm_unrol = sel.unrolledHist(hists[1], (\"absYVgen\", \"ptVgen\", ))" + "scetlib_Wm_unrol = sel.unrolledHist(\n", + " hists[0],\n", + " (\n", + " \"absy\",\n", + " \"pt\",\n", + " ),\n", + ")\n", + "minnlo_Wm_unrol = sel.unrolledHist(\n", + " hists[1],\n", + " (\n", + " \"absYVgen\",\n", + " \"ptVgen\",\n", + " ),\n", + ")" ] }, { @@ -1756,8 +2142,24 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([minnlo_Wm_unrol, scetlib_Wm_unrol], colors=[\"blue\", \"green\", ], labels=[\"MiNNLO\", \"SCETlib\", ], rrange=[0.8, 1.2], ylabel=\"$\\sigma$/bin\", xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\", rlabel=\"x/MiNNLO\", nlegcols=2, binwnorm=True, ylim=[-40, 10])\n", - "\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [minnlo_Wm_unrol, scetlib_Wm_unrol],\n", + " colors=[\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"MiNNLO\",\n", + " \"SCETlib\",\n", + " ],\n", + " rrange=[0.8, 1.2],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " nlegcols=2,\n", + " binwnorm=True,\n", + " ylim=[-40, 10],\n", + ")" ] }, { @@ -1780,7 +2182,23 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([hists[1].project(\"ptVgen\"), hists[0].project(\"pt\")], colors=[\"blue\", \"green\", ], labels=[\"MiNNLO\", \"SCETlib\", ], rrange=[0.8, 1.2], ylabel=\"$\\sigma$/bin\", xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\", rlabel=\"x/MiNNLO\", nlegcols=2, binwnorm=True)\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [hists[1].project(\"ptVgen\"), hists[0].project(\"pt\")],\n", + " colors=[\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"MiNNLO\",\n", + " \"SCETlib\",\n", + " ],\n", + " rrange=[0.8, 1.2],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " nlegcols=2,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1800,11 +2218,19 @@ "metadata": {}, "outputs": [], "source": [ - "helCorrW = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_gen_scetlibHelicityCorr\")\n", - "corrW = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_gen_scetlibCorr\")\n", - "uncorr = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_gen\")\n", - "\n", - "\n" + "helCorrW = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\",\n", + " [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"],\n", + " \"nominal_gen_scetlibHelicityCorr\",\n", + ")\n", + "corrW = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\",\n", + " [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"],\n", + " \"nominal_gen_scetlibCorr\",\n", + ")\n", + "uncorr = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_gen\"\n", + ")" ] }, { @@ -1827,9 +2253,34 @@ } ], "source": [ - "hists = [x[{\"chargeVgen\" : 1.j}].project(\"ptVgen\") for x in [helCorrW, corrW, uncorr, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"blue\", \"grey\", \"purple\", ], labels=[\"SCETlib hel.\", \"Scetlib\", \"MiNNLO\", ], rrange=[0.9, 1.1], xlim=[0, 40], ylabel=\"$\\sigma$/bin\", xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\", rlabel=\"x/MiNNLO\", nlegcols=2, binwnorm=True)\n", - "\n" + "hists = [\n", + " x[{\"chargeVgen\": 1.0j}].project(\"ptVgen\")\n", + " for x in [\n", + " helCorrW,\n", + " corrW,\n", + " uncorr,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"blue\",\n", + " \"grey\",\n", + " \"purple\",\n", + " ],\n", + " labels=[\n", + " \"SCETlib hel.\",\n", + " \"Scetlib\",\n", + " \"MiNNLO\",\n", + " ],\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 40],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"($p_{T}^{W^{-}}$, $|y^{W^{-}}|$) bin\",\n", + " rlabel=\"x/MiNNLO\",\n", + " nlegcols=2,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1852,8 +2303,34 @@ } ], "source": [ - "hists = [x[{\"chargeVgen\" : 1.j}].project(\"absYVgen\") for x in [corrW, helCorrW, uncorr, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"purple\", \"blue\", \"orange\", ], labels=[\"SCETlib\", \"SCETlib hel\", \"MiNNLO\", ], rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=\"$|y^{W^{+}}|$\", rlabel=\"x/MiNNLO\", nlegcols=2, xlim=[0, 5], binwnorm=True)\n" + "hists = [\n", + " x[{\"chargeVgen\": 1.0j}].project(\"absYVgen\")\n", + " for x in [\n", + " corrW,\n", + " helCorrW,\n", + " uncorr,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " \"orange\",\n", + " ],\n", + " labels=[\n", + " \"SCETlib\",\n", + " \"SCETlib hel\",\n", + " \"MiNNLO\",\n", + " ],\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|y^{W^{+}}|$\",\n", + " rlabel=\"x/MiNNLO\",\n", + " nlegcols=2,\n", + " xlim=[0, 5],\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1876,8 +2353,34 @@ } ], "source": [ - "hists = [x[{\"chargeVgen\" : -1.j}].project(\"absYVgen\") for x in [corrW, helCorrW, uncorr, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"purple\", \"blue\", \"orange\", ], labels=[\"SCETlib hel\", \"SCETlib\", \"MiNNLO\", ], rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"$|y^{W^{+}}|$\", rlabel=\"x/MiNNLO\", nlegcols=2, xlim=[0, 5], binwnorm=True)\n" + "hists = [\n", + " x[{\"chargeVgen\": -1.0j}].project(\"absYVgen\")\n", + " for x in [\n", + " corrW,\n", + " helCorrW,\n", + " uncorr,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " \"orange\",\n", + " ],\n", + " labels=[\n", + " \"SCETlib hel\",\n", + " \"SCETlib\",\n", + " \"MiNNLO\",\n", + " ],\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|y^{W^{+}}|$\",\n", + " rlabel=\"x/MiNNLO\",\n", + " nlegcols=2,\n", + " xlim=[0, 5],\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1887,9 +2390,21 @@ "metadata": {}, "outputs": [], "source": [ - "lep_uncorr = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_genlep\")\n", - "lep_helCorr = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_genlep_scetlibHelicityCorr\")\n", - "lep_corr = input_tools.read_all_and_scale(\"../w_z_gen_dists.pkl.lz4\", [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"], \"nominal_genlep_scetlibCorr\")" + "lep_uncorr = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\",\n", + " [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"],\n", + " \"nominal_genlep\",\n", + ")\n", + "lep_helCorr = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\",\n", + " [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"],\n", + " \"nominal_genlep_scetlibHelicityCorr\",\n", + ")\n", + "lep_corr = input_tools.read_all_and_scale(\n", + " \"../w_z_gen_dists.pkl.lz4\",\n", + " [\"WplusmunuPostVFP\", \"WminusmunuPostVFP\"],\n", + " \"nominal_genlep_scetlibCorr\",\n", + ")" ] }, { @@ -1919,9 +2434,33 @@ } ], "source": [ - "hists = [sel.unrolledHist(x[{\"chargeVgen\" : -1.j}]) for x in [lep_corr, lep_helCorr, lep_uncorr, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"purple\", \"blue\", \"orange\", ], labels=[\"SCETlib\", \"SCETlib hel.\", \"MiNNLO\", ], rrange=[0.98, 1.02], ylabel=\"$\\sigma$/bin\", xlabel=\"$|y^{W^{+}}|$\", rlabel=\"x/SCETlib\", nlegcols=2, binwnorm=True)\n", - "\n" + "hists = [\n", + " sel.unrolledHist(x[{\"chargeVgen\": -1.0j}])\n", + " for x in [\n", + " lep_corr,\n", + " lep_helCorr,\n", + " lep_uncorr,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " \"orange\",\n", + " ],\n", + " labels=[\n", + " \"SCETlib\",\n", + " \"SCETlib hel.\",\n", + " \"MiNNLO\",\n", + " ],\n", + " rrange=[0.98, 1.02],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|y^{W^{+}}|$\",\n", + " rlabel=\"x/SCETlib\",\n", + " nlegcols=2,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -1931,7 +2470,13 @@ "metadata": {}, "outputs": [], "source": [ - "lep_uncorr,lep_helCorr,lep_corr = input_tools.read_all_and_scale(\"../mz_wlike_with_mu_eta_pt.pkl.lz4\", [\"ZmumuPostVFP\",], [\"nominal\", \"scetlibCorr\", \"scetlibHelicityCorr\"])" + "lep_uncorr, lep_helCorr, lep_corr = input_tools.read_all_and_scale(\n", + " \"../mz_wlike_with_mu_eta_pt.pkl.lz4\",\n", + " [\n", + " \"ZmumuPostVFP\",\n", + " ],\n", + " [\"nominal\", \"scetlibCorr\", \"scetlibHelicityCorr\"],\n", + ")" ] }, { @@ -2011,8 +2556,33 @@ } ], "source": [ - "hists = [sel.unrolledHist(x) for x in [lep_corr, lep_helCorr, lep_uncorr, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"purple\", \"blue\", \"orange\", ], labels=[\"SCETlib\", \"SCETlib hel.\", \"MiNNLO\", ], rrange=[0.99, 1.01], ylabel=\"$\\sigma$/bin\", xlabel=\"$|y^{W^{+}}|$\", rlabel=\"x/SCETlib\", nlegcols=2, binwnorm=True)" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [\n", + " lep_corr,\n", + " lep_helCorr,\n", + " lep_uncorr,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"purple\",\n", + " \"blue\",\n", + " \"orange\",\n", + " ],\n", + " labels=[\n", + " \"SCETlib\",\n", + " \"SCETlib hel.\",\n", + " \"MiNNLO\",\n", + " ],\n", + " rrange=[0.99, 1.01],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|y^{W^{+}}|$\",\n", + " rlabel=\"x/SCETlib\",\n", + " nlegcols=2,\n", + " binwnorm=True,\n", + ")" ] }, { @@ -2068,9 +2638,9 @@ } ], "source": [ - "hh.divideHists(lep_uncorr,lep_corr).project(\"pt\").plot()\n", - "hh.divideHists(lep_corr,lep_corr).project(\"pt\").plot()\n", - "hh.divideHists(lep_helcorr,lep_corr).project(\"pt\").plot()\n", + "hh.divideHists(lep_uncorr, lep_corr).project(\"pt\").plot()\n", + "hh.divideHists(lep_corr, lep_corr).project(\"pt\").plot()\n", + "hh.divideHists(lep_helcorr, lep_corr).project(\"pt\").plot()\n", "plt.ylim([90, 110])" ] }, @@ -2081,7 +2651,11 @@ "metadata": {}, "outputs": [], "source": [ - "lep_uncorr,lep_corr,lep_helcorr = input_tools.read_all_and_scale(\"../mz_wlike_with_mu_eta_pt.pkl.lz4\", [\"ZmumuPostVFP\"], [\"nominal\", \"scetlibCorr\", \"scetlibHelicityCorr\"])" + "lep_uncorr, lep_corr, lep_helcorr = input_tools.read_all_and_scale(\n", + " \"../mz_wlike_with_mu_eta_pt.pkl.lz4\",\n", + " [\"ZmumuPostVFP\"],\n", + " [\"nominal\", \"scetlibCorr\", \"scetlibHelicityCorr\"],\n", + ")" ] }, { @@ -2110,7 +2684,9 @@ } ], "source": [ - "coeffs = pickle.load(lz4.frame.open(\"../wremnants/data/angularCoefficients/z_coeffs.pkl.lz4\"))\n", + "coeffs = pickle.load(\n", + " lz4.frame.open(\"../wremnants/data/angularCoefficients/z_coeffs.pkl.lz4\")\n", + ")\n", "coeffs.shape" ] }, @@ -2208,7 +2784,12 @@ "metadata": {}, "outputs": [], "source": [ - "mcfm_n4ll = input_tools.read_dyturbo_hist([\"/scratch/shared/TheoryPredictions/MCFM/wminus_n4ll/W_only_resonlyN3LO_MSHT20nnlo_as118_1.00_1.00_13TeV_pt34_fine.txt\"], axes=[\"pt\"])" + "mcfm_n4ll = input_tools.read_dyturbo_hist(\n", + " [\n", + " \"/scratch/shared/TheoryPredictions/MCFM/wminus_n4ll/W_only_resonlyN3LO_MSHT20nnlo_as118_1.00_1.00_13TeV_pt34_fine.txt\"\n", + " ],\n", + " axes=[\"pt\"],\n", + ")" ] }, { @@ -2275,7 +2856,7 @@ } ], "source": [ - "newnp[0,hist.sum,hist.sum,0,:].values()" + "newnp[0, hist.sum, hist.sum, 0, :].values()" ] }, { @@ -2294,23 +2875,28 @@ } ], "source": [ - "npfilt = newnp[{\"vars\" : ['pdf0',\n", - " 'lambda20.75',\n", - " 'lambda4.01',\n", - " 'lambda4.16',\n", - " 'delta_lambda20.02',\n", - " 'lambda4_nu0.1',\n", - " 'lambda4_nu0.1',\n", - " 'lambda2_nu0.2',\n", - " 'lambda2_nu0.05',\n", - " 'lambda2_nu0.3',\n", - " 'lambda2_nu0.5',\n", - " 'lambda2_nu0.4',\n", - " 'lambda2_nu0.001',\n", - " 'lambda20.25',\n", - " 'lambda2-0.25',\n", - " 'lambda20.5',\n", - "]}]" + "npfilt = newnp[\n", + " {\n", + " \"vars\": [\n", + " \"pdf0\",\n", + " \"lambda20.75\",\n", + " \"lambda4.01\",\n", + " \"lambda4.16\",\n", + " \"delta_lambda20.02\",\n", + " \"lambda4_nu0.1\",\n", + " \"lambda4_nu0.1\",\n", + " \"lambda2_nu0.2\",\n", + " \"lambda2_nu0.05\",\n", + " \"lambda2_nu0.3\",\n", + " \"lambda2_nu0.5\",\n", + " \"lambda2_nu0.4\",\n", + " \"lambda2_nu0.001\",\n", + " \"lambda20.25\",\n", + " \"lambda2-0.25\",\n", + " \"lambda20.5\",\n", + " ]\n", + " }\n", + "]" ] }, { @@ -2333,17 +2919,36 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([\n", - " newnp[{\"vars\" : i}].project(\"qT\") for i in newnp.axes[\"vars\"]\n", - " ],\n", - " colors=[\"black\", \"red\", \"red\", \"purple\", \"purple\", \"blue\", \"blue\", \"green\", \"green\", \"orange\", \"orange\",\n", - " \"pink\", \"pink\", \"navy\", \"navy\", \"darkgreen\", \"darkgreen\", \"darkred\", \"darkred\", \"black\",], \n", - " labels=list(newnp.axes[\"vars\"]), \n", - " rrange=[0.85, 1.15], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/nominal\"\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [newnp[{\"vars\": i}].project(\"qT\") for i in newnp.axes[\"vars\"]],\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"red\",\n", + " \"purple\",\n", + " \"purple\",\n", + " \"blue\",\n", + " \"blue\",\n", + " \"green\",\n", + " \"green\",\n", + " \"orange\",\n", + " \"orange\",\n", + " \"pink\",\n", + " \"pink\",\n", + " \"navy\",\n", + " \"navy\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " \"darkred\",\n", + " \"darkred\",\n", + " \"black\",\n", + " ],\n", + " labels=list(newnp.axes[\"vars\"]),\n", + " rrange=[0.85, 1.15],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/nominal\",\n", ")" ] }, @@ -2365,17 +2970,16 @@ } ], "source": [ - "cmap = plt.get_cmap('tab20')\n", - "fig = plot_tools.makePlotWithRatioToRef([\n", - " npfilt[{\"vars\" : i}].project(\"qT\") for i in npfilt.axes[\"vars\"]\n", - " ],\n", - " colors=[cmap(i) for i in range(len(npfilt.axes[\"vars\"]))],\n", - " labels=list(npfilt.axes[\"vars\"]), \n", - " rrange=[0.85, 1.15], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/nominal\"\n", + "cmap = plt.get_cmap(\"tab20\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [npfilt[{\"vars\": i}].project(\"qT\") for i in npfilt.axes[\"vars\"]],\n", + " colors=[cmap(i) for i in range(len(npfilt.axes[\"vars\"]))],\n", + " labels=list(npfilt.axes[\"vars\"]),\n", + " rrange=[0.85, 1.15],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/nominal\",\n", ")" ] }, @@ -2398,7 +3002,7 @@ "outputs": [], "source": [ "altnpf = \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3p0ll_newnp/inclusive_Z_CT18Z_N3p0LL_newnp_alt.pkl\"\n", - "altnp = input_tools.read_scetlib_hist(altnpf, charge=0)\n" + "altnp = input_tools.read_scetlib_hist(altnpf, charge=0)" ] }, { @@ -2427,7 +3031,7 @@ } ], "source": [ - "oldnp[{\"vars\" : 0}]" + "oldnp[{\"vars\": 0}]" ] }, { @@ -2448,16 +3052,18 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([\n", - " x[{\"vars\" : 0}].project(\"qT\")[:40] for x in [newnp, oldnp]\n", - " ],\n", - " colors=[\"black\", \"blue\"],\n", - " labels=[\"New NP\", \"Old NP\",], \n", - " rrange=[0.85, 1.15], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/nominal\"\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [x[{\"vars\": 0}].project(\"qT\")[:40] for x in [newnp, oldnp]],\n", + " colors=[\"black\", \"blue\"],\n", + " labels=[\n", + " \"New NP\",\n", + " \"Old NP\",\n", + " ],\n", + " rrange=[0.85, 1.15],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/nominal\",\n", ")" ] }, @@ -2479,16 +3085,15 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([\n", - " x[{\"vars\" : 0}].project(\"qT\")[:40] for x in [newnp, altnp, oldnp]\n", - " ],\n", - " colors=[\"black\", \"blue\", \"red\"],\n", - " labels=[\"New NP\", \"Alt NP\", \"Old NP\"], \n", - " rrange=[0.85, 1.15], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/nominal\"\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [x[{\"vars\": 0}].project(\"qT\")[:40] for x in [newnp, altnp, oldnp]],\n", + " colors=[\"black\", \"blue\", \"red\"],\n", + " labels=[\"New NP\", \"Alt NP\", \"Old NP\"],\n", + " rrange=[0.85, 1.15],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/nominal\",\n", ")" ] }, @@ -2655,7 +3260,7 @@ "source": [ "oldnp_conf = altnp_conf\n", "for sec in newnp_conf.keys():\n", - " for k in set(list(newnp_conf[sec].keys())+list(oldnp_conf[sec].keys())):\n", + " for k in set(list(newnp_conf[sec].keys()) + list(oldnp_conf[sec].keys())):\n", " if k not in newnp_conf[sec]:\n", " print(\"Unique param in old np:\", sec, k, oldnp_conf[sec][k])\n", " continue\n", @@ -2663,7 +3268,9 @@ " print(\"Unique param in new np:\", sec, k, newnp_conf[sec][k])\n", " continue\n", " if oldnp_conf[sec][k] != newnp_conf[sec][k]:\n", - " print(f\"Unmatched params {sec}/{k}! old: {oldnp_conf[sec][k]}, new: {newnp_conf[sec][k]}\")\n" + " print(\n", + " f\"Unmatched params {sec}/{k}! old: {oldnp_conf[sec][k]}, new: {newnp_conf[sec][k]}\"\n", + " )" ] }, { @@ -2681,9 +3288,18 @@ "metadata": {}, "outputs": [], "source": [ - "newnp = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3p0ll_newnp/inclusive_Z_CT18Z_N3p0LL_newnp.pkl\", charge=0)\n", - "oldnp = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3+0ll/inclusive_Z_CT18Z_nplambda_N3+0LL_combined.pkl\", charge=0)\n", - "franknp = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3p0ll_newnp/inclusive_Z_CT18Z_N3p0LL_newnp_frankvals.pkl\", charge=0)" + "newnp = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3p0ll_newnp/inclusive_Z_CT18Z_N3p0LL_newnp.pkl\",\n", + " charge=0,\n", + ")\n", + "oldnp = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3+0ll/inclusive_Z_CT18Z_nplambda_N3+0LL_combined.pkl\",\n", + " charge=0,\n", + ")\n", + "franknp = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/ct18z_nplambda_n3p0ll_newnp/inclusive_Z_CT18Z_N3p0LL_newnp_frankvals.pkl\",\n", + " charge=0,\n", + ")" ] }, { @@ -2693,7 +3309,10 @@ "metadata": {}, "outputs": [], "source": [ - "newnp_zeros = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib//ct18z_nptan2_n3p0ll/inclusive_Z_CT18Z_N3p0LL_newnp_zeros.pkl\", charge=0)" + "newnp_zeros = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib//ct18z_nptan2_n3p0ll/inclusive_Z_CT18Z_N3p0LL_newnp_zeros.pkl\",\n", + " charge=0,\n", + ")" ] }, { @@ -2714,16 +3333,19 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef([\n", - " x[{\"vars\" : 0}].project(\"qT\")[:40] for x in [oldnp, franknp, newnp_zeros]\n", - " ],\n", - " colors=[\"black\", \"blue\", \"green\", ],\n", - " labels=[\"Old NP\",\"New NP, suggested vals\", \"New NP, lambda2 = 0\"], \n", - " rrange=[0.9, 1.1], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/old\"\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [x[{\"vars\": 0}].project(\"qT\")[:40] for x in [oldnp, franknp, newnp_zeros]],\n", + " colors=[\n", + " \"black\",\n", + " \"blue\",\n", + " \"green\",\n", + " ],\n", + " labels=[\"Old NP\", \"New NP, suggested vals\", \"New NP, lambda2 = 0\"],\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/old\",\n", ")" ] }, @@ -2775,17 +3397,16 @@ } ], "source": [ - "cmap = plt.get_cmap('tab20')\n", - "fig = plot_tools.makePlotWithRatioToRef([\n", - " newnp_zeros[{\"vars\" : i}].project(\"qT\") for i in newnp_zeros.axes[\"vars\"]\n", - " ],\n", - " colors=[cmap(i) for i in range(len(newnp_zeros.axes[\"vars\"]))],\n", - " labels=list(newnp_zeros.axes[\"vars\"]), \n", - " rrange=[0.9, 1.1], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/central\"\n", + "cmap = plt.get_cmap(\"tab20\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [newnp_zeros[{\"vars\": i}].project(\"qT\") for i in newnp_zeros.axes[\"vars\"]],\n", + " colors=[cmap(i) for i in range(len(newnp_zeros.axes[\"vars\"]))],\n", + " labels=list(newnp_zeros.axes[\"vars\"]),\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/central\",\n", ")" ] }, @@ -2817,17 +3438,16 @@ } ], "source": [ - "cmap = plt.get_cmap('tab20')\n", - "fig = plot_tools.makePlotWithRatioToRef([\n", - " newnp_zeros[{\"vars\" : i}].project(\"qT\") for i in filtvars\n", - " ],\n", - " colors=[cmap(i) for i in range(len(filtvars))],\n", - " labels=filtvars, \n", - " rrange=[0.9, 1.1], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/central\"\n", + "cmap = plt.get_cmap(\"tab20\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [newnp_zeros[{\"vars\": i}].project(\"qT\") for i in filtvars],\n", + " colors=[cmap(i) for i in range(len(filtvars))],\n", + " labels=filtvars,\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/central\",\n", ")" ] }, @@ -2849,18 +3469,17 @@ } ], "source": [ - "filtvars = [\"central\"]+[x for x in newnp_zeros.axes[\"vars\"] if \"lambda2_nu\" in x]\n", - "cmap = plt.get_cmap('tab20')\n", - "fig = plot_tools.makePlotWithRatioToRef([\n", - " newnp_zeros[{\"vars\" : i}].project(\"qT\") for i in filtvars\n", - " ],\n", - " colors=[cmap(i) for i in range(len(filtvars))],\n", - " labels=filtvars, \n", - " rrange=[0.9, 1.1], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/central\"\n", + "filtvars = [\"central\"] + [x for x in newnp_zeros.axes[\"vars\"] if \"lambda2_nu\" in x]\n", + "cmap = plt.get_cmap(\"tab20\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [newnp_zeros[{\"vars\": i}].project(\"qT\") for i in filtvars],\n", + " colors=[cmap(i) for i in range(len(filtvars))],\n", + " labels=filtvars,\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/central\",\n", ")" ] }, @@ -2882,18 +3501,21 @@ } ], "source": [ - "filtvars = [\"central\"]+[x for x in newnp_zeros.axes[\"vars\"] if \"lambda2\" in x and \"nu\" not in x and \"delta\" not in x]\n", - "cmap = plt.get_cmap('tab20')\n", - "fig = plot_tools.makePlotWithRatioToRef([\n", - " newnp_zeros[{\"vars\" : i}].project(\"qT\") for i in filtvars\n", - " ],\n", - " colors=[cmap(i) for i in range(len(filtvars))],\n", - " labels=filtvars, \n", - " rrange=[0.9, 1.1], \n", - " xlim=[0, 50], \n", - " binwnorm=1., \n", - " yscale=2,\n", - " rlabel=\"x/central\"\n", + "filtvars = [\"central\"] + [\n", + " x\n", + " for x in newnp_zeros.axes[\"vars\"]\n", + " if \"lambda2\" in x and \"nu\" not in x and \"delta\" not in x\n", + "]\n", + "cmap = plt.get_cmap(\"tab20\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [newnp_zeros[{\"vars\": i}].project(\"qT\") for i in filtvars],\n", + " colors=[cmap(i) for i in range(len(filtvars))],\n", + " labels=filtvars,\n", + " rrange=[0.9, 1.1],\n", + " xlim=[0, 50],\n", + " binwnorm=1.0,\n", + " yscale=2,\n", + " rlabel=\"x/central\",\n", ")" ] }, @@ -2904,9 +3526,14 @@ "metadata": {}, "outputs": [], "source": [ - "import pickle,hist\n", - "zerosnp_conf = pickle.load(open(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib//ct18z_nptan2_n3p0ll/inclusive_Z_CT18Z_N3p0LL_newnp_zeros.pkl\", \"rb\"))[\"config\"]\n", - " " + "import pickle, hist\n", + "\n", + "zerosnp_conf = pickle.load(\n", + " open(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib//ct18z_nptan2_n3p0ll/inclusive_Z_CT18Z_N3p0LL_newnp_zeros.pkl\",\n", + " \"rb\",\n", + " )\n", + ")[\"config\"]" ] }, { @@ -2983,7 +3610,7 @@ } ], "source": [ - "newnp_zeros[0,hist.sum,:20,0,\"lambda20.5\"].values()" + "newnp_zeros[0, hist.sum, :20, 0, \"lambda20.5\"].values()" ] }, { @@ -3008,7 +3635,7 @@ } ], "source": [ - "newnp_zeros[0,hist.sum,:20,0,\"central\"].values()" + "newnp_zeros[0, hist.sum, :20, 0, \"central\"].values()" ] } ], diff --git a/notebooks/summaryPlot.ipynb b/notebooks/summaryPlot.ipynb index 4ce7c7c32..9b3169bf0 100644 --- a/notebooks/summaryPlot.ipynb +++ b/notebooks/summaryPlot.ipynb @@ -7,8 +7,8 @@ "metadata": {}, "outputs": [], "source": [ - "from utilities.io_tools import input_tools,combinetf_input,output_tools\n", - "from wremnants import plot_tools,theory_tools\n", + "from utilities.io_tools import input_tools, combinetf_input, output_tools\n", + "from wremnants import plot_tools, theory_tools\n", "import pandas as pd\n", "import numpy as np\n", "import matplotlib.pyplot as plt\n", @@ -45,7 +45,9 @@ "metadata": {}, "outputs": [], "source": [ - "dfs = {\"ATLAS\" : pd.DataFrame.from_dict({\"mass\" : [80], \"stat_err\" : [10], \"tot_err\" : [15]})}" + "dfs = {\n", + " \"ATLAS\": pd.DataFrame.from_dict({\"mass\": [80], \"stat_err\": [10], \"tot_err\": [15]})\n", + "}" ] }, { @@ -55,7 +57,13 @@ "metadata": {}, "outputs": [], "source": [ - "df1 = combinetf_input.read_groupunc_df(\"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789.hdf5\", [\"Fake\",], name=\"Nominal, no param. unc.\")" + "df1 = combinetf_input.read_groupunc_df(\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789.hdf5\",\n", + " [\n", + " \"Fake\",\n", + " ],\n", + " name=\"Nominal, no param. unc.\",\n", + ")" ] }, { @@ -65,7 +73,13 @@ "metadata": {}, "outputs": [], "source": [ - "df2 = combinetf_input.read_groupunc_df(\"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_data.hdf5\", [\"Fake\",], name=\"Nominal\")\n" + "df2 = combinetf_input.read_groupunc_df(\n", + " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_data.hdf5\",\n", + " [\n", + " \"Fake\",\n", + " ],\n", + " name=\"Nominal\",\n", + ")" ] }, { @@ -76,12 +90,22 @@ "outputs": [], "source": [ "df = combinetf_input.read_all_groupunc_df(\n", - " [\"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_data.hdf5\", \n", - " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789_blind.hdf5\",\n", - " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge_hybrid/WMass_eta_pt_charge_hybrid/fitresults_123456789_data.hdf5\",\n", - " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_smoothFR/fitresults_123456789_blind.hdf5\",\n", + " [\n", + " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_data.hdf5\",\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_noFakeNonClosUnc/fitresults_123456789_blind.hdf5\",\n", + " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge_hybrid/WMass_eta_pt_charge_hybrid/fitresults_123456789_data.hdf5\",\n", + " \"/scratch/kelong/CombineStudies/WMass_eta_pt_charge_smoothFR/fitresults_123456789_blind.hdf5\",\n", + " ],\n", + " [\n", + " \"Fake\",\n", " ],\n", - " [\"Fake\",], names=[\"Nominal\", \"Nominal, no param. unc.\", \"Hybrid smoothing\", \"Smooth FR\",])\n" + " names=[\n", + " \"Nominal\",\n", + " \"Nominal, no param. unc.\",\n", + " \"Hybrid smoothing\",\n", + " \"Smooth FR\",\n", + " ],\n", + ")" ] }, { @@ -104,12 +128,17 @@ "out, outfolder = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded\", \"W\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "nomdf = df[df[\"Name\"] == \"Nominal\"]\n", - "fig = plot_tools.make_summary_plot(nomdf[\"value\"][0], nomdf[\"err_Fake\"][0], \"Nominal $\\pm$ fake unc.\",\n", + "fig = plot_tools.make_summary_plot(\n", + " nomdf[\"value\"][0],\n", + " nomdf[\"err_Fake\"][0],\n", + " \"Nominal $\\pm$ fake unc.\",\n", " df,\n", " colors=\"auto\",\n", " xlim=[80000, 80200],\n", - " xlabel=\"$m_{W}$ (MeV)\", out=\"test\",\n", - " outfolder=\"W\", name=\"temp\",\n", + " xlabel=\"$m_{W}$ (MeV)\",\n", + " out=\"test\",\n", + " outfolder=\"W\",\n", + " name=\"temp\",\n", " legend_loc=\"upper right\",\n", ")\n", "name = \"fakeSummary\"\n", @@ -125,14 +154,27 @@ "metadata": {}, "outputs": [], "source": [ - "dfw = pd.DataFrame.from_dict({\n", - " \"Name\" : [\"LEP Combination\", \"D0\", \"CDF\", \"LHCb\", \"ATLAS\",],\n", - " \"value\" : [80376, 80375, 80434, 80354, 80366],\n", - " \"err_total\" : [33, 23, 9.4, 32, 15.9],\n", - " \"err_stat\" : [25, 11, 6.4, 23, 9.8],\n", - " \"Reference\" : [\"Phys. Rep. 532 (2013) 119\", \"Phys. Rev. Lett. 108 (2012) 151804\",\n", - " \"Science 376 (2022) 6589\", \"JHEP 01 (2022) 036\", \"\", ],\n", - "})\n" + "dfw = pd.DataFrame.from_dict(\n", + " {\n", + " \"Name\": [\n", + " \"LEP Combination\",\n", + " \"D0\",\n", + " \"CDF\",\n", + " \"LHCb\",\n", + " \"ATLAS\",\n", + " ],\n", + " \"value\": [80376, 80375, 80434, 80354, 80366],\n", + " \"err_total\": [33, 23, 9.4, 32, 15.9],\n", + " \"err_stat\": [25, 11, 6.4, 23, 9.8],\n", + " \"Reference\": [\n", + " \"Phys. Rep. 532 (2013) 119\",\n", + " \"Phys. Rev. Lett. 108 (2012) 151804\",\n", + " \"Science 376 (2022) 6589\",\n", + " \"JHEP 01 (2022) 036\",\n", + " \"\",\n", + " ],\n", + " }\n", + ")" ] }, { @@ -142,7 +184,13 @@ "metadata": {}, "outputs": [], "source": [ - "cms_res = combinetf_input.read_groupunc_df(\"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.hdf5\", [\"stat\",], name=\"CMS\")" + "cms_res = combinetf_input.read_groupunc_df(\n", + " \"/scratch/dwalter/CombineStudies/240820_mw_unblinding/WMass_eta_pt_charge/fitresults_123456789_unblind.hdf5\",\n", + " [\n", + " \"stat\",\n", + " ],\n", + " name=\"CMS\",\n", + ")" ] }, { @@ -152,7 +200,7 @@ "metadata": {}, "outputs": [], "source": [ - "#cms_res.loc[0,\"value\"] = 80355\n", + "# cms_res.loc[0,\"value\"] = 80355\n", "cms_res[\"Reference\"] = [\"This work\"]" ] }, @@ -173,7 +221,7 @@ "metadata": {}, "outputs": [], "source": [ - "matplotlib.rc('text', usetex = False)" + "matplotlib.rc(\"text\", usetex=False)" ] }, { @@ -183,30 +231,63 @@ "metadata": {}, "outputs": [], "source": [ - "out, outfolder = \"/eos/user/c/cmsmwbot/www/WMassAnalysis/PlotsForPaper/NaturePreCWR\", \"W\"\n", + "out, outfolder = (\n", + " \"/eos/user/c/cmsmwbot/www/WMassAnalysis/PlotsForPaper/NaturePreCWR\",\n", + " \"W\",\n", + ")\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "name = \"resultsSummary\"\n", - "fig = plot_tools.make_summary_plot(80353, 6, None,\n", + "fig = plot_tools.make_summary_plot(\n", + " 80353,\n", + " 6,\n", + " None,\n", " dfw_cms,\n", - " colors=[\"black\"]*5+[\"#5790FC\"],\n", + " colors=[\"black\"] * 5 + [\"#5790FC\"],\n", " xlim=[80260, 80460],\n", - " xlabel=\"$m_{W}$ (MeV)\", out=outdir[:-2], outfolder=outfolder,\n", + " xlabel=\"$m_{W}$ (MeV)\",\n", + " out=outdir[:-2],\n", + " outfolder=outfolder,\n", " name=name,\n", " legend_loc=None,\n", " capsize=6,\n", " fontsize=18,\n", " width_scale=1.25,\n", - " cms_label=' ',\n", + " cms_label=\" \",\n", ")\n", "ax = plt.gca()\n", - "for i,row in dfw_cms.iterrows():\n", - " isCMS = row.loc[\"Name\"] == \"CMS\" \n", - " ax.annotate(row.loc[\"Name\"], (80170, 6.4-i*1.1), fontsize=18, ha=\"left\", annotation_clip=False, color=\"#5790FC\" if isCMS else \"black\", weight=600)\n", - " ax.annotate(row.loc[\"Reference\"], (80170, 6.4-i*1.1-0.3), fontsize=10, ha=\"left\", color=\"dimgrey\", annotation_clip=False, style='italic' if isCMS else None)\n", - " label = f\"$m_{{W}}$ = {row.loc['value']:.0f} $\\pm$ {round(row.loc['err_total'], 0):.0f}\"\n", + "for i, row in dfw_cms.iterrows():\n", + " isCMS = row.loc[\"Name\"] == \"CMS\"\n", + " ax.annotate(\n", + " row.loc[\"Name\"],\n", + " (80170, 6.4 - i * 1.1),\n", + " fontsize=18,\n", + " ha=\"left\",\n", + " annotation_clip=False,\n", + " color=\"#5790FC\" if isCMS else \"black\",\n", + " weight=600,\n", + " )\n", + " ax.annotate(\n", + " row.loc[\"Reference\"],\n", + " (80170, 6.4 - i * 1.1 - 0.3),\n", + " fontsize=10,\n", + " ha=\"left\",\n", + " color=\"dimgrey\",\n", + " annotation_clip=False,\n", + " style=\"italic\" if isCMS else None,\n", + " )\n", + " label = (\n", + " f\"$m_{{W}}$ = {row.loc['value']:.0f} $\\pm$ {round(row.loc['err_total'], 0):.0f}\"\n", + " )\n", " if row.loc[\"Name\"] in [\"CMS\", \"CDF\"]:\n", " label = f\"$m_{{W}}$ = {row.loc['value']:.1f} $\\pm$ {round(row.loc['err_total'], 1):.1f}\"\n", - " ax.annotate(label, (80170, 6.4-i*1.1-0.6), fontsize=10, ha=\"left\", color=\"dimgrey\", annotation_clip=False)\n", + " ax.annotate(\n", + " label,\n", + " (80170, 6.4 - i * 1.1 - 0.6),\n", + " fontsize=10,\n", + " ha=\"left\",\n", + " color=\"dimgrey\",\n", + " annotation_clip=False,\n", + " )\n", "\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", "plot_tools.write_index_and_log(outdir, name)\n", @@ -223,11 +304,16 @@ "out, outfolder = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded\", \"W\"\n", "outdir = output_tools.make_plot_dir(out, outfolder, eoscp=True)\n", "name = \"resultsSummaryNoCMS\"\n", - "fig = plot_tools.make_summary_plot(80353, 6, None,\n", + "fig = plot_tools.make_summary_plot(\n", + " 80353,\n", + " 6,\n", + " None,\n", " dfw,\n", - " colors=[\"black\"]*5,\n", + " colors=[\"black\"] * 5,\n", " xlim=[80260, 80460],\n", - " xlabel=\"$m_{W}$ (MeV)\", out=outdir[:-2], outfolder=outfolder,\n", + " xlabel=\"$m_{W}$ (MeV)\",\n", + " out=outdir[:-2],\n", + " outfolder=outfolder,\n", " name=name,\n", " legend_loc=None,\n", " capsize=6,\n", @@ -236,14 +322,39 @@ " cms_label=None,\n", ")\n", "ax = plt.gca()\n", - "for i,row in dfw.iterrows():\n", - " isCMS = row.loc[\"Name\"] == \"CMS\" \n", - " ax.annotate(row.loc[\"Name\"], (80170, 5.4-i*1.1), fontsize=18, ha=\"left\", annotation_clip=False, color=\"#5790FC\" if isCMS else \"black\", weight=600)\n", - " ax.annotate(row.loc[\"Reference\"], (80170, 5.4-i*1.1-0.3), fontsize=10, ha=\"left\", color=\"dimgrey\", annotation_clip=False, style='italic' if isCMS else None)\n", - " label = f\"$m_{{W}}$ = {row.loc['value']:.0f} $\\pm$ {round(row.loc['err_total'], 0):.0f}\"\n", + "for i, row in dfw.iterrows():\n", + " isCMS = row.loc[\"Name\"] == \"CMS\"\n", + " ax.annotate(\n", + " row.loc[\"Name\"],\n", + " (80170, 5.4 - i * 1.1),\n", + " fontsize=18,\n", + " ha=\"left\",\n", + " annotation_clip=False,\n", + " color=\"#5790FC\" if isCMS else \"black\",\n", + " weight=600,\n", + " )\n", + " ax.annotate(\n", + " row.loc[\"Reference\"],\n", + " (80170, 5.4 - i * 1.1 - 0.3),\n", + " fontsize=10,\n", + " ha=\"left\",\n", + " color=\"dimgrey\",\n", + " annotation_clip=False,\n", + " style=\"italic\" if isCMS else None,\n", + " )\n", + " label = (\n", + " f\"$m_{{W}}$ = {row.loc['value']:.0f} $\\pm$ {round(row.loc['err_total'], 0):.0f}\"\n", + " )\n", " if row.loc[\"Name\"] in [\"CMS\", \"CDF\"]:\n", " label = f\"$m_{{W}}$ = {row.loc['value']:.1f} $\\pm$ {round(row.loc['err_total'], 1):.1f}\"\n", - " ax.annotate(label, (80170, 5.4-i*1.1-0.6), fontsize=10, ha=\"left\", color=\"dimgrey\", annotation_clip=False)\n", + " ax.annotate(\n", + " label,\n", + " (80170, 5.4 - i * 1.1 - 0.6),\n", + " fontsize=10,\n", + " ha=\"left\",\n", + " color=\"dimgrey\",\n", + " annotation_clip=False,\n", + " )\n", "\n", "plot_tools.save_pdf_and_png(outdir, name, fig)\n", "plot_tools.write_index_and_log(outdir, name)\n", diff --git a/notebooks/systsScratch.ipynb b/notebooks/systsScratch.ipynb index eccbdfc29..17961198f 100644 --- a/notebooks/systsScratch.ipynb +++ b/notebooks/systsScratch.ipynb @@ -83,13 +83,13 @@ "import mplhep as hep\n", "import matplotlib.pyplot as plt\n", "from wremnants.datasets.datagroups import datagroups2016\n", - "from wums import boostHistHelpers as hh,common\n", - "from wremnants import plot_tools,syst_tools\n", + "from wums import boostHistHelpers as hh, common\n", + "from wremnants import plot_tools, syst_tools\n", "from wremnants import histselections as sel\n", "import hist\n", "import narf\n", "import numpy as np\n", - "import pickle,lz4.frame" + "import pickle, lz4.frame" ] }, { @@ -110,7 +110,7 @@ "metadata": {}, "outputs": [], "source": [ - "groups = datagroups2016(\"../mw_with_mu_eta_pt_nnpdf31.pkl.lz4\")\n" + "groups = datagroups2016(\"../mw_with_mu_eta_pt_nnpdf31.pkl.lz4\")" ] }, { @@ -152,7 +152,9 @@ "# This is for reading groups\n", "groups.loadHistsForDatagroups(\"nominal\", syst=\"\", procsToRead=[\"Wmunu\"])\n", "groups.loadHistsForDatagroups(\"\", syst=\"muonScaleSyst\", procsToRead=[\"Wmunu\"])\n", - "groups.loadHistsForDatagroups(\"\", syst=\"muonScaleSyst_responseWeights\", procsToRead=[\"Wmunu\"])\n", + "groups.loadHistsForDatagroups(\n", + " \"\", syst=\"muonScaleSyst_responseWeights\", procsToRead=[\"Wmunu\"]\n", + ")\n", "histInfo = groups.getDatagroups()" ] }, @@ -203,10 +205,16 @@ "metadata": {}, "outputs": [], "source": [ - "hh.divideHists(histInfo[\"Wmunu\"][\"pdfMMHT\"][{\"tensor_axis_0\" : 0}].project(\"eta\"), histInfo[\"Wmunu\"][\"nominal\"].project(\"eta\")).plot(label=\"MMHT14\")\n", - "hh.divideHists(histInfo[\"Wmunu\"][\"pdfCT18\"][{\"tensor_axis_0\" : 0}].project(\"eta\"), histInfo[\"Wmunu\"][\"nominal\"].project(\"eta\")).plot(label=\"CT18\")\n", + "hh.divideHists(\n", + " histInfo[\"Wmunu\"][\"pdfMMHT\"][{\"tensor_axis_0\": 0}].project(\"eta\"),\n", + " histInfo[\"Wmunu\"][\"nominal\"].project(\"eta\"),\n", + ").plot(label=\"MMHT14\")\n", + "hh.divideHists(\n", + " histInfo[\"Wmunu\"][\"pdfCT18\"][{\"tensor_axis_0\": 0}].project(\"eta\"),\n", + " histInfo[\"Wmunu\"][\"nominal\"].project(\"eta\"),\n", + ").plot(label=\"CT18\")\n", "plt.legend()\n", - "plt.ylim([0.95, 1.05])\n" + "plt.ylim([0.95, 1.05])" ] }, { @@ -216,10 +224,16 @@ "metadata": {}, "outputs": [], "source": [ - "hh.divideHists(histInfo[\"Wmunu\"][\"pdfMMHT\"][{\"tensor_axis_0\" : 0}].project(\"pt\"), histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\")).plot(label=\"MMHT14\")\n", - "hh.divideHists(histInfo[\"Wmunu\"][\"pdfCT18\"][{\"tensor_axis_0\" : 0}].project(\"pt\"), histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\")).plot(label=\"CT18\")\n", + "hh.divideHists(\n", + " histInfo[\"Wmunu\"][\"pdfMMHT\"][{\"tensor_axis_0\": 0}].project(\"pt\"),\n", + " histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\"),\n", + ").plot(label=\"MMHT14\")\n", + "hh.divideHists(\n", + " histInfo[\"Wmunu\"][\"pdfCT18\"][{\"tensor_axis_0\": 0}].project(\"pt\"),\n", + " histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\"),\n", + ").plot(label=\"CT18\")\n", "plt.legend()\n", - "plt.ylim([0.95, 1.05])\n" + "plt.ylim([0.95, 1.05])" ] }, { @@ -229,8 +243,8 @@ "metadata": {}, "outputs": [], "source": [ - "hscaleUp = procDict[\"Wmunu\"][\"muonScaleSyst\"][{\"downUpVar\" : 1, \"scaleEtaSlice\" : 1.j}]\n", - "hscaleDown = procDict[\"Wmunu\"][\"muonScaleSyst\"][{\"downUpVar\" : 0, \"scaleEtaSlice\" : 1.j}]" + "hscaleUp = procDict[\"Wmunu\"][\"muonScaleSyst\"][{\"downUpVar\": 1, \"scaleEtaSlice\": 1.0j}]\n", + "hscaleDown = procDict[\"Wmunu\"][\"muonScaleSyst\"][{\"downUpVar\": 0, \"scaleEtaSlice\": 1.0j}]" ] }, { @@ -241,7 +255,7 @@ "outputs": [], "source": [ "hnom = procDict[\"Wmunu\"][\"nominal\"]\n", - "# Can also read specific samples by accessing the original \n", + "# Can also read specific samples by accessing the original\n", "hnomminus = groups.results[\"WminusmunuPostVFP\"][\"output\"][\"nominal\"]" ] }, @@ -285,8 +299,12 @@ "outputs": [], "source": [ "procs = combine.datagroupsForHist(\"x_Wmunu_plus\", label=\"nominal\")\n", - "procs = combine.datagroupsForHist(\"x_Wmunu_CMS_scale_m_ieta0Up_plus\", label=\"scaleEta0Up\")\n", - "procs = combine.datagroupsForHist(\"x_Wmunu_CMS_scale_m_ieta0Down_plus\", label=\"scaleEta0Down\")\n", + "procs = combine.datagroupsForHist(\n", + " \"x_Wmunu_CMS_scale_m_ieta0Up_plus\", label=\"scaleEta0Up\"\n", + ")\n", + "procs = combine.datagroupsForHist(\n", + " \"x_Wmunu_CMS_scale_m_ieta0Down_plus\", label=\"scaleEta0Down\"\n", + ")\n", "procs = combine.datagroupsForHist(\"x_Wmunu_pdf1NNPDF31Up_plus\", label=\"pdf1Up\")\n", "procs = combine.datagroupsForHist(\"x_Wmunu_pdf1NNPDF31Down_plus\", label=\"pdf1Down\")" ] @@ -300,7 +318,7 @@ "source": [ "hh.divideHists(procs[\"Wmunu\"][\"scaleEta0Up\"], procs[\"Wmunu\"][\"nominal\"]).plot()\n", "hh.divideHists(procs[\"Wmunu\"][\"scaleEta0Down\"], procs[\"Wmunu\"][\"nominal\"]).plot()\n", - "#plt.ylim([0.99, 1.01])" + "# plt.ylim([0.99, 1.01])" ] }, { @@ -320,8 +338,12 @@ "metadata": {}, "outputs": [], "source": [ - "hh.divideHists(procs[\"Wmunu\"][\"pdf1Up\"].project(\"pt\"),procs[\"Wmunu\"][\"nominal\"].project(\"pt\")).plot()\n", - "hh.divideHists(procs[\"Wmunu\"][\"pdf1Down\"].project(\"pt\"),procs[\"Wmunu\"][\"nominal\"].project(\"pt\")).plot()\n", + "hh.divideHists(\n", + " procs[\"Wmunu\"][\"pdf1Up\"].project(\"pt\"), procs[\"Wmunu\"][\"nominal\"].project(\"pt\")\n", + ").plot()\n", + "hh.divideHists(\n", + " procs[\"Wmunu\"][\"pdf1Down\"].project(\"pt\"), procs[\"Wmunu\"][\"nominal\"].project(\"pt\")\n", + ").plot()\n", "plt.ylim([0.99, 1.01])" ] }, @@ -332,12 +354,26 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(h) for h in [procs[\"Wmunu\"][\"nominal\"], procs[\"Wmunu\"][\"scaleEta0Up\"], procs[\"Wmunu\"][\"scaleEta0Down\"]]]\n", - "#hists = [h.project(\"pt\") for h in [procs[\"Wmunu\"][\"nominal\"], procs[\"Wmunu\"][\"pdf1Up\"], procs[\"Wmunu\"][\"pdf1Down\"]]]\n", + "hists = [\n", + " sel.unrolledHist(h)\n", + " for h in [\n", + " procs[\"Wmunu\"][\"nominal\"],\n", + " procs[\"Wmunu\"][\"scaleEta0Up\"],\n", + " procs[\"Wmunu\"][\"scaleEta0Down\"],\n", + " ]\n", + "]\n", + "# hists = [h.project(\"pt\") for h in [procs[\"Wmunu\"][\"nominal\"], procs[\"Wmunu\"][\"pdf1Up\"], procs[\"Wmunu\"][\"pdf1Down\"]]]\n", "colors = [\"black\", \"red\", \"pink\"]\n", "labels = [\"nominal\", \"scaleEta0Up\", \"scaleEta0Down\"]\n", "\n", - "fig = plotTools.makePlotsWithRatioToRef(hists, labels, colors, xlabel=r\"($\\eta$, p$_{T}$) bin\", scale=1e5,rrange=[0.998, 1.002])\n" + "fig = plotTools.makePlotsWithRatioToRef(\n", + " hists,\n", + " labels,\n", + " colors,\n", + " xlabel=r\"($\\eta$, p$_{T}$) bin\",\n", + " scale=1e5,\n", + " rrange=[0.998, 1.002],\n", + ")" ] }, { @@ -347,11 +383,25 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(h) for h in [procs[\"Wmunu\"][\"nominal\"], procs[\"Wmunu\"][\"pdf1Up\"], procs[\"Wmunu\"][\"pdf1Down\"]]]\n", + "hists = [\n", + " sel.unrolledHist(h)\n", + " for h in [\n", + " procs[\"Wmunu\"][\"nominal\"],\n", + " procs[\"Wmunu\"][\"pdf1Up\"],\n", + " procs[\"Wmunu\"][\"pdf1Down\"],\n", + " ]\n", + "]\n", "colors = [\"black\", \"red\", \"pink\"]\n", "labels = [\"nominal\", \"pdf1Up\", \"pdf1Down\"]\n", "\n", - "fig = plotTools.makePlotsWithRatioToRef(hists, labels, colors, xlabel=r\"($\\eta$, p$_{T}$) bin\", scale=1e5,rrange=[0.995, 1.005])\n" + "fig = plotTools.makePlotsWithRatioToRef(\n", + " hists,\n", + " labels,\n", + " colors,\n", + " xlabel=r\"($\\eta$, p$_{T}$) bin\",\n", + " scale=1e5,\n", + " rrange=[0.995, 1.005],\n", + ")" ] }, { @@ -362,7 +412,9 @@ "outputs": [], "source": [ "histInfo = groups.getDatagroups()\n", - "groups.loadHistsForDatagroups(\"nominal\", syst=\"\", selectSignal=True, label=\"nominal\", procsToRead=[\"Wmunu\"])" + "groups.loadHistsForDatagroups(\n", + " \"nominal\", syst=\"\", selectSignal=True, label=\"nominal\", procsToRead=[\"Wmunu\"]\n", + ")" ] }, { @@ -372,7 +424,14 @@ "metadata": {}, "outputs": [], "source": [ - "groups.loadHistsForDatagroups(\"\", syst=\"qcdScaleByHelicity\", selectSignal=True, label=\"qcdScaleByHelicity\", procsToRead=[\"Wmunu\"], forceNonzero=False)" + "groups.loadHistsForDatagroups(\n", + " \"\",\n", + " syst=\"qcdScaleByHelicity\",\n", + " selectSignal=True,\n", + " label=\"qcdScaleByHelicity\",\n", + " procsToRead=[\"Wmunu\"],\n", + " forceNonzero=False,\n", + ")" ] }, { @@ -392,7 +451,11 @@ "metadata": {}, "outputs": [], "source": [ - "histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"] = syst_tools.scale_helicity_hist_to_variations(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"])" + "histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"] = (\n", + " syst_tools.scale_helicity_hist_to_variations(\n", + " histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"]\n", + " )\n", + ")" ] }, { @@ -403,7 +466,15 @@ "outputs": [], "source": [ "s = hist.tag.Slicer()\n", - "hVarNom = histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"ptVgen\" : s[::hist.sum], \"chargeVgen\" : s[::hist.sum], \"helicity\" : s[::hist.sum], \"muRfact\" : s[1.j], \"muFfact\" : s[1.j] }]\n" + "hVarNom = histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][\n", + " {\n", + " \"ptVgen\": s[:: hist.sum],\n", + " \"chargeVgen\": s[:: hist.sum],\n", + " \"helicity\": s[:: hist.sum],\n", + " \"muRfact\": s[1.0j],\n", + " \"muFfact\": s[1.0j],\n", + " }\n", + "]" ] }, { @@ -413,8 +484,22 @@ "metadata": {}, "outputs": [], "source": [ - "selections = [{\"muRfact\" : hist.loc(j), \"muFfact\" : hist.loc(j), \"helicity\" : i, \"ptVgen\" : 0, \"chargeVgen\" : -1j} for i in range(2) for j in [0.5,1.,2.]]\n", - "names = [f\"muR{j}_muF{j}_hel_sigma{i}_ptVgen0_minus\" for i in range(2) for j in [0.5,1.,2.]]" + "selections = [\n", + " {\n", + " \"muRfact\": hist.loc(j),\n", + " \"muFfact\": hist.loc(j),\n", + " \"helicity\": i,\n", + " \"ptVgen\": 0,\n", + " \"chargeVgen\": -1j,\n", + " }\n", + " for i in range(2)\n", + " for j in [0.5, 1.0, 2.0]\n", + "]\n", + "names = [\n", + " f\"muR{j}_muF{j}_hel_sigma{i}_ptVgen0_minus\"\n", + " for i in range(2)\n", + " for j in [0.5, 1.0, 2.0]\n", + "]" ] }, { @@ -425,8 +510,13 @@ "outputs": [], "source": [ "hists = [sel.unrolledHist(histInfo[\"Wmunu\"][\"nominal\"])]\n", - "hists.extend([sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"][s]) for s in selections])\n", - "labels = [\"nominal\"]+names\n", + "hists.extend(\n", + " [\n", + " sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"][s])\n", + " for s in selections\n", + " ]\n", + ")\n", + "labels = [\"nominal\"] + names\n", "colors = [\"black\", \"blue\", \"purple\", \"green\", \"pink\", \"orange\", \"lightblue\"]" ] }, @@ -438,7 +528,9 @@ "outputs": [], "source": [ "hists = [histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\")]\n", - "hists.extend([histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"][s].project(\"pt\") for s in selections])" + "hists.extend(\n", + " [histInfo[\"Wmunu\"][\"qcdScaleByHelicitySum\"][s].project(\"pt\") for s in selections]\n", + ")" ] }, { @@ -464,7 +556,9 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plot_tools.makePlotWithRatioToRef(hists, labels, colors, xlabel=r\"p$_{T}$ (GeV)\", ymax=3e7,rrange=[0.99, 1.01])" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists, labels, colors, xlabel=r\"p$_{T}$ (GeV)\", ymax=3e7, rrange=[0.99, 1.01]\n", + ")" ] }, { @@ -474,14 +568,36 @@ "metadata": {}, "outputs": [], "source": [ - "selections = [{\"muRfact\" : 1.j, \"muFfact\" : 1.j, \"helicity\" : i} for i in range(9)]\n", - "#histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"] = syst_tools.scale_helicity_hist_to_variations(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"], sum_ptV=True)\n", + "selections = [{\"muRfact\": 1.0j, \"muFfact\": 1.0j, \"helicity\": i} for i in range(9)]\n", + "# histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"] = syst_tools.scale_helicity_hist_to_variations(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"], sum_ptV=True)\n", "hists = [sel.unrolledHist(histInfo[\"Wmunu\"][\"nominal\"])]\n", - "hists.extend([sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections])\n", - "labels = [\"nominal\"]+[f\"$sigma_{i-1}$*angular\" if i != 0 else \"$\\sigma_\\mathrm{UL}$\" for i in range(9)]\n", - "colors = [\"black\", \"blue\", \"purple\", \"green\", \"pink\", \"orange\", \"lightblue\", \"red\", \"lightgreen\", \"yellow\"]\n", + "hists.extend(\n", + " [sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections]\n", + ")\n", + "labels = [\"nominal\"] + [\n", + " f\"$sigma_{i-1}$*angular\" if i != 0 else \"$\\sigma_\\mathrm{UL}$\" for i in range(9)\n", + "]\n", + "colors = [\n", + " \"black\",\n", + " \"blue\",\n", + " \"purple\",\n", + " \"green\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"lightblue\",\n", + " \"red\",\n", + " \"lightgreen\",\n", + " \"yellow\",\n", + "]\n", "print(len(hists), len(labels), len(colors))\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, labels, colors, xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\", ymax=8e6,rrange=[-0.2, 1.5])\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " labels,\n", + " colors,\n", + " xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\",\n", + " ymax=8e6,\n", + " rrange=[-0.2, 1.5],\n", + ")\n", "fig.get_axes()[0].set_ylim([-1e4, 1.8e5])" ] }, @@ -520,14 +636,35 @@ "metadata": {}, "outputs": [], "source": [ - "selections = [{\"muRfact\" : 1.j, \"muFfact\" : 1.j, \"helicity\" : i} for i in range(9)]\n", - "#histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"] = syst_tools.scale_helicity_hist_to_variations(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"], sum_ptV=True)\n", + "selections = [{\"muRfact\": 1.0j, \"muFfact\": 1.0j, \"helicity\": i} for i in range(9)]\n", + "# histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"] = syst_tools.scale_helicity_hist_to_variations(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"], sum_ptV=True)\n", "hists = [sel.unrolledHist(histInfo[\"Wmunu\"][\"nominal\"])]\n", - "hists.extend([sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections])\n", - "labels = [\"nominal\"]+[\"$\\sigma_{%i}%s$\" % (i-1, angular[i]) for i in range(0,9)]\n", - "colors = [\"black\", \"blue\", \"purple\", \"green\", \"pink\", \"orange\", \"lightblue\", \"red\", \"lightgreen\", \"yellow\"]\n", + "hists.extend(\n", + " [sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections]\n", + ")\n", + "labels = [\"nominal\"] + [\"$\\sigma_{%i}%s$\" % (i - 1, angular[i]) for i in range(0, 9)]\n", + "colors = [\n", + " \"black\",\n", + " \"blue\",\n", + " \"purple\",\n", + " \"green\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"lightblue\",\n", + " \"red\",\n", + " \"lightgreen\",\n", + " \"yellow\",\n", + "]\n", "print(len(hists), len(labels), len(colors))\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, labels, colors, xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\", ymax=8e6,rrange=[0.9, 1.1], rlabel=\"$x/\\sigma_{total}$\")\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " labels,\n", + " colors,\n", + " xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\",\n", + " ymax=8e6,\n", + " rrange=[0.9, 1.1],\n", + " rlabel=\"$x/\\sigma_{total}$\",\n", + ")\n", "fig.get_axes()[0].set_ylim([-1e4, 1.8e5])" ] }, @@ -538,13 +675,33 @@ "metadata": {}, "outputs": [], "source": [ - "selections = [{\"muRfact\" : 1.j, \"muFfact\" : 1.j, \"helicity\" : i} for i in range(9)]\n", + "selections = [{\"muRfact\": 1.0j, \"muFfact\": 1.0j, \"helicity\": i} for i in range(9)]\n", "hists = [sel.unrolledHist(histInfo[\"Wmunu\"][\"nominal\"])]\n", - "hists.extend([sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections])\n", - "labels = [\"nominal\"]+[\"$\\sigma_{%i}%s$\" % (i-1, angular[i]) for i in range(0,9)]\n", - "colors = [\"black\", \"blue\", \"purple\", \"green\", \"pink\", \"orange\", \"lightblue\", \"red\", \"lightgreen\", \"yellow\"]\n", + "hists.extend(\n", + " [sel.unrolledHist(histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][s]) for s in selections]\n", + ")\n", + "labels = [\"nominal\"] + [\"$\\sigma_{%i}%s$\" % (i - 1, angular[i]) for i in range(0, 9)]\n", + "colors = [\n", + " \"black\",\n", + " \"blue\",\n", + " \"purple\",\n", + " \"green\",\n", + " \"pink\",\n", + " \"orange\",\n", + " \"lightblue\",\n", + " \"red\",\n", + " \"lightgreen\",\n", + " \"yellow\",\n", + "]\n", "print(len(hists), len(labels), len(colors))\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, labels, colors, xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\", ymax=8e6,rrange=[-0.05, 0.1])\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " labels,\n", + " colors,\n", + " xlabel=r\"($\\eta_{\\ell}$, p$_{T}$) bin\",\n", + " ymax=8e6,\n", + " rrange=[-0.05, 0.1],\n", + ")\n", "fig.get_axes()[0].set_ylim([-1e4, 1.8e5])" ] }, @@ -566,7 +723,9 @@ "outputs": [], "source": [ "histInfo[\"Wmunu\"][\"nominal\"].project(\"pt\").plot()\n", - "histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"pt\").plot()" + "histInfo[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"muRfact\": 1.0j, \"muFfact\": 1.0j}].project(\n", + " \"pt\"\n", + ").plot()" ] }, { @@ -593,7 +752,11 @@ "outputs": [], "source": [ "print(groups.results[\"WminusmunuPostVFP\"][\"output\"][\"nominal\"].sum(flow=True))\n", - "print(groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScale\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].sum(flow=True))\n" + "print(\n", + " groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScale\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + " ].sum(flow=True)\n", + ")" ] }, { @@ -603,8 +766,12 @@ "metadata": {}, "outputs": [], "source": [ - "groups.results[\"WminusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\").plot(label=\"nominal\")\n", - "groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"pt\").plot()\n", + "groups.results[\"WminusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\").plot(\n", + " label=\"nominal\"\n", + ")\n", + "groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + "].project(\"pt\").plot()\n", "plt.legend()" ] }, @@ -615,8 +782,12 @@ "metadata": {}, "outputs": [], "source": [ - "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\").plot(label=\"nominal\")\n", - "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"pt\").plot()\n", + "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\").plot(\n", + " label=\"nominal\"\n", + ")\n", + "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + "].project(\"pt\").plot()\n", "plt.legend()" ] }, @@ -637,7 +808,7 @@ "metadata": {}, "outputs": [], "source": [ - "#groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"]\n", + "# groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"]\n", "groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"]" ] }, @@ -659,7 +830,7 @@ "metadata": {}, "outputs": [], "source": [ - "orig_sum = orig + groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"]" + "orig_sum = orig + groups.results[\"WminusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"]" ] }, { @@ -669,9 +840,20 @@ "metadata": {}, "outputs": [], "source": [ - "groups.loadHistsForDatagroups(\"nominal\", syst=\"qcdScaleByHelicity\", procsToRead=[\"Wmunu\"], forceNonzero=False, selectSignal=False,\n", - " preOpMap={x : syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", - " preOpArgs={\"sum_axis\" : [ \"helicity\", \"ptVgen\",]})" + "groups.loadHistsForDatagroups(\n", + " \"nominal\",\n", + " syst=\"qcdScaleByHelicity\",\n", + " procsToRead=[\"Wmunu\"],\n", + " forceNonzero=False,\n", + " selectSignal=False,\n", + " preOpMap={x: syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", + " preOpArgs={\n", + " \"sum_axis\": [\n", + " \"helicity\",\n", + " \"ptVgen\",\n", + " ]\n", + " },\n", + ")" ] }, { @@ -681,9 +863,19 @@ "metadata": {}, "outputs": [], "source": [ - "groups.loadHistsForDatagroups(\"nominal\", syst=\"qcdScaleByHelicity\", procsToRead=[\"Zmumu\"], forceNonzero=False, selectSignal=False, \n", - " preOpMap={x : syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", - " preOpArgs={\"sum_axis\" : [\"ptVgen\",]})" + "groups.loadHistsForDatagroups(\n", + " \"nominal\",\n", + " syst=\"qcdScaleByHelicity\",\n", + " procsToRead=[\"Zmumu\"],\n", + " forceNonzero=False,\n", + " selectSignal=False,\n", + " preOpMap={x: syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", + " preOpArgs={\n", + " \"sum_axis\": [\n", + " \"ptVgen\",\n", + " ]\n", + " },\n", + ")" ] }, { @@ -693,7 +885,15 @@ "metadata": {}, "outputs": [], "source": [ - "groups.loadHistsForDatagroups(\"nominal\", syst=\"\", procsToRead=[\"Fake\",], selectSignal=True, forceNonzero=False)" + "groups.loadHistsForDatagroups(\n", + " \"nominal\",\n", + " syst=\"\",\n", + " procsToRead=[\n", + " \"Fake\",\n", + " ],\n", + " selectSignal=True,\n", + " forceNonzero=False,\n", + ")" ] }, { @@ -703,9 +903,16 @@ "metadata": {}, "outputs": [], "source": [ - "groups.loadHistsForDatagroups(\"nominal\", syst=\"qcdScale\", procsToRead=[\"Fake\",], forceNonzero=False, selectSignal=True,\n", - " preOpMap={x : syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", - " )#preOpArgs={\"sum_axis\" : [\"ptVgen\"]})" + "groups.loadHistsForDatagroups(\n", + " \"nominal\",\n", + " syst=\"qcdScale\",\n", + " procsToRead=[\n", + " \"Fake\",\n", + " ],\n", + " forceNonzero=False,\n", + " selectSignal=True,\n", + " preOpMap={x: syst_tools.scale_helicity_hist_to_variations for x in common.vprocs},\n", + ") # preOpArgs={\"sum_axis\" : [\"ptVgen\"]})" ] }, { @@ -725,7 +932,9 @@ "metadata": {}, "outputs": [], "source": [ - "res[\"Fake\"][\"qcdScale\"][{\"muRfact\" : 1.j, \"muFfact\" : 1.j, \"ptVgen\" : 10, \"chargeVgen\" : -1.j}]" + "res[\"Fake\"][\"qcdScale\"][\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j, \"ptVgen\": 10, \"chargeVgen\": -1.0j}\n", + "]" ] }, { @@ -745,10 +954,18 @@ "metadata": {}, "outputs": [], "source": [ - "hh.divideHists(res[\"Fake\"][\"qcdScale\"][{\"muRfact\" : 0.5j, \"muFfact\" : 0.5j, \"ptVgen\" :1, \"chargeVgen\" : 1.j}].project(\"pt\"),\n", - " res[\"Fake\"][\"nominal\"].project(\"pt\")).plot()\n", - "hh.divideHists(res[\"Fake\"][\"qcdScale\"][{\"muRfact\" : 2j, \"muFfact\" : 2j, \"ptVgen\" :1, \"chargeVgen\" : 1.j}].project(\"pt\"),\n", - " res[\"Fake\"][\"nominal\"].project(\"pt\")).plot()\n", + "hh.divideHists(\n", + " res[\"Fake\"][\"qcdScale\"][\n", + " {\"muRfact\": 0.5j, \"muFfact\": 0.5j, \"ptVgen\": 1, \"chargeVgen\": 1.0j}\n", + " ].project(\"pt\"),\n", + " res[\"Fake\"][\"nominal\"].project(\"pt\"),\n", + ").plot()\n", + "hh.divideHists(\n", + " res[\"Fake\"][\"qcdScale\"][\n", + " {\"muRfact\": 2j, \"muFfact\": 2j, \"ptVgen\": 1, \"chargeVgen\": 1.0j}\n", + " ].project(\"pt\"),\n", + " res[\"Fake\"][\"nominal\"].project(\"pt\"),\n", + ").plot()\n", "plt.ylim([0.9, 1.1])" ] }, @@ -759,9 +976,8 @@ "metadata": {}, "outputs": [], "source": [ - "res[\"Fake\"][\"qcdScaleByHelicity\"][{\"muRfact\" : 2j, \"muFfact\" : 2j}].project(\"pt\").plot()\n", - "res[\"Fake\"][\"nominal\"].project(\"pt\").plot()\n", - "\n" + "res[\"Fake\"][\"qcdScaleByHelicity\"][{\"muRfact\": 2j, \"muFfact\": 2j}].project(\"pt\").plot()\n", + "res[\"Fake\"][\"nominal\"].project(\"pt\").plot()" ] }, { @@ -781,8 +997,20 @@ "metadata": {}, "outputs": [], "source": [ - "print(res[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][{\"helicity\" : s[::hist.sum], \"muRfact\" : 1.j, \"muFfact\" :1.j}].sum())\n", - "print(res[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][{\"helicity\" : -1.j, \"muRfact\" : -1.j, \"muFfact\" :1.j,}].sum())" + "print(\n", + " res[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][\n", + " {\"helicity\": s[:: hist.sum], \"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + " ].sum()\n", + ")\n", + "print(\n", + " res[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][\n", + " {\n", + " \"helicity\": -1.0j,\n", + " \"muRfact\": -1.0j,\n", + " \"muFfact\": 1.0j,\n", + " }\n", + " ].sum()\n", + ")" ] }, { @@ -792,7 +1020,15 @@ "metadata": {}, "outputs": [], "source": [ - "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][{\"chargeVgen\" : s[::hist.sum], \"ptVgen\" : s[::hist.sum], \"helicity\" : s[::hist.sum], \"muRfact\" : -1.j, \"muFfact\" :1.j,}]" + "groups.results[\"WplusmunuPostVFP\"][\"output\"][\"qcdScaleByHelicity\"][\n", + " {\n", + " \"chargeVgen\": s[:: hist.sum],\n", + " \"ptVgen\": s[:: hist.sum],\n", + " \"helicity\": s[:: hist.sum],\n", + " \"muRfact\": -1.0j,\n", + " \"muFfact\": 1.0j,\n", + " }\n", + "]" ] }, { @@ -812,7 +1048,9 @@ "metadata": {}, "outputs": [], "source": [ - "res[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"chargeVgen\" : 1.j, \"muRfact\" : 1j, \"muFfact\" : 1j, \"helicity\" : 4.j, \"ptVgen\" : 1}]" + "res[\"Wmunu\"][\"qcdScaleByHelicity\"][\n", + " {\"chargeVgen\": 1.0j, \"muRfact\": 1j, \"muFfact\": 1j, \"helicity\": 4.0j, \"ptVgen\": 1}\n", + "]" ] }, { @@ -823,10 +1061,28 @@ "outputs": [], "source": [ "for i in range(8):\n", - " hh.divideHists(res[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"chargeVgen\" : 1.j, \"muRfact\" : 2j, \"muFfact\" : 2j, \"helicity\" : i, }].project(\"pt\"),\n", - " groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\")).plot()\n", - " hh.divideHists(res[\"Wmunu\"][\"qcdScaleByHelicity\"][{\"chargeVgen\" : 1.j, \"muRfact\" : 0.5j, \"muFfact\" : 0.5j, \"helicity\" : i, }].project(\"pt\"),\n", - " groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\")).plot()\n", + " hh.divideHists(\n", + " res[\"Wmunu\"][\"qcdScaleByHelicity\"][\n", + " {\n", + " \"chargeVgen\": 1.0j,\n", + " \"muRfact\": 2j,\n", + " \"muFfact\": 2j,\n", + " \"helicity\": i,\n", + " }\n", + " ].project(\"pt\"),\n", + " groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\"),\n", + " ).plot()\n", + " hh.divideHists(\n", + " res[\"Wmunu\"][\"qcdScaleByHelicity\"][\n", + " {\n", + " \"chargeVgen\": 1.0j,\n", + " \"muRfact\": 0.5j,\n", + " \"muFfact\": 0.5j,\n", + " \"helicity\": i,\n", + " }\n", + " ].project(\"pt\"),\n", + " groups.results[\"WplusmunuPostVFP\"][\"output\"][\"nominal\"].project(\"pt\"),\n", + " ).plot()\n", "plt.ylim([0.96, 1.04])" ] }, @@ -837,8 +1093,8 @@ "metadata": {}, "outputs": [], "source": [ - "print(res[\"Fake\"][\"nominal\"][{\"charge\" : 1.j}].sum())\n", - "print(res[\"Fake\"][\"nominal\"][{\"charge\" : -1.j}].sum())" + "print(res[\"Fake\"][\"nominal\"][{\"charge\": 1.0j}].sum())\n", + "print(res[\"Fake\"][\"nominal\"][{\"charge\": -1.0j}].sum())" ] }, { @@ -859,6 +1115,7 @@ "outputs": [], "source": [ "import uproot\n", + "\n", "combf = uproot.open(\"../test/WMassCombineInput.root\")" ] }, @@ -902,8 +1159,18 @@ "outputs": [], "source": [ "for c in [\"minus\", \"plus\"]:\n", - " for i in range(0,int(res[\"Fake\"][\"qcdScale\"].axes[\"ptVgen\"].size/2)):\n", - " print(\"Q=\", c, \"bin\", i, combf[f\"x_Fake_QCDscale_genV{c}genPtV{i}muRmuFDown_plus\"].to_hist().sum().value/refp)" + " for i in range(0, int(res[\"Fake\"][\"qcdScale\"].axes[\"ptVgen\"].size / 2)):\n", + " print(\n", + " \"Q=\",\n", + " c,\n", + " \"bin\",\n", + " i,\n", + " combf[f\"x_Fake_QCDscale_genV{c}genPtV{i}muRmuFDown_plus\"]\n", + " .to_hist()\n", + " .sum()\n", + " .value\n", + " / refp,\n", + " )" ] }, { @@ -913,7 +1180,9 @@ "metadata": {}, "outputs": [], "source": [ - "with lz4.frame.open(\"/scratch/kelong/Analysis/mz_wlike_with_mu_eta_pt_RawPFMET_scetlibCorr_nnpdf31.pkl.lz4\") as f:\n", + "with lz4.frame.open(\n", + " \"/scratch/kelong/Analysis/mz_wlike_with_mu_eta_pt_RawPFMET_scetlibCorr_nnpdf31.pkl.lz4\"\n", + ") as f:\n", " res = pickle.load(f)" ] }, diff --git a/notebooks/testPdfUnc.ipynb b/notebooks/testPdfUnc.ipynb index bc30b1958..b56bdb24d 100644 --- a/notebooks/testPdfUnc.ipynb +++ b/notebooks/testPdfUnc.ipynb @@ -23,7 +23,7 @@ "import matplotlib.pyplot as plt\n", "from wums import boostHistHelpers as hh, plot_tools\n", "from utilities.io_tools import input_tools\n", - "from wremnants import syst_tools,theory_tools\n", + "from wremnants import syst_tools, theory_tools\n", "from wremnants import histselections as sel\n", "import lz4.frame\n", "import pickle\n", @@ -92,9 +92,19 @@ } ], "source": [ - "corr_nnpdf4 = pickle.load(lz4.frame.open(\"../wremnants-data/data/TheoryCorrections/dataPtll_nnpdf40CorrZ.pkl.lz4\"))\n", - "corr = pickle.load(lz4.frame.open(\"../wremnants-data/data/TheoryCorrections/dataPtllCorrZ.pkl.lz4\"))\n", - "corr_nnpdf4_inv = pickle.load(lz4.frame.open(\"../wremnants-data/data/TheoryCorrections/dataPtll_nnpdf40_invCorrZ.pkl.lz4\"))" + "corr_nnpdf4 = pickle.load(\n", + " lz4.frame.open(\n", + " \"../wremnants-data/data/TheoryCorrections/dataPtll_nnpdf40CorrZ.pkl.lz4\"\n", + " )\n", + ")\n", + "corr = pickle.load(\n", + " lz4.frame.open(\"../wremnants-data/data/TheoryCorrections/dataPtllCorrZ.pkl.lz4\")\n", + ")\n", + "corr_nnpdf4_inv = pickle.load(\n", + " lz4.frame.open(\n", + " \"../wremnants-data/data/TheoryCorrections/dataPtll_nnpdf40_invCorrZ.pkl.lz4\"\n", + " )\n", + ")" ] }, { @@ -122,11 +132,15 @@ " corr[\"Z\"][\"data_hist\"],\n", " corr_nnpdf4[\"Z\"][\"data_hist\"],\n", " ],\n", - " colors=[\"green\", \"red\", \"black\", \"grey\"], \n", - " labels=[\"CT18Z\", \"NNPDF4.0\", \"data CT18\", \"data NNPDF\"], \n", - " rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", \n", - " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", \n", - " rlabel=\"x/CT18Z\", binwnorm=1.0, nlegcols=1)" + " colors=[\"green\", \"red\", \"black\", \"grey\"],\n", + " labels=[\"CT18Z\", \"NNPDF4.0\", \"data CT18\", \"data NNPDF\"],\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/CT18Z\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -147,19 +161,21 @@ } ], "source": [ - "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", " [\n", - " corr[\"Z\"][\"MC_data_ratio\"][0,0,:,0,0],\n", - " corr_nnpdf4[\"Z\"][\"MC_data_ratio\"][0,0,:,0,0],\n", - " corr_nnpdf4_inv[\"Z\"][\"MC_data_ratio\"][0,0,:,0,0],\n", - " corrh_new[0,0,:,0,0],\n", + " corr[\"Z\"][\"MC_data_ratio\"][0, 0, :, 0, 0],\n", + " corr_nnpdf4[\"Z\"][\"MC_data_ratio\"][0, 0, :, 0, 0],\n", + " corr_nnpdf4_inv[\"Z\"][\"MC_data_ratio\"][0, 0, :, 0, 0],\n", + " corrh_new[0, 0, :, 0, 0],\n", " ],\n", - " colors=[\"black\", \"red\", \"blue\", \"green\"], \n", - " labels=[\"CT18Z\", \"NNPDF4.0\", \"inv\", \"inv2\"], \n", - " rrange=[0.9, 1.1], ylabel=\"Correction\", \n", - " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", \n", - " rlabel=\"x/CT18Z\", nlegcols=1)" + " colors=[\"black\", \"red\", \"blue\", \"green\"],\n", + " labels=[\"CT18Z\", \"NNPDF4.0\", \"inv\", \"inv2\"],\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"Correction\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/CT18Z\",\n", + " nlegcols=1,\n", + ")" ] }, { @@ -184,7 +200,7 @@ } ], "source": [ - "corr[\"Z\"][\"MC_data_ratio\"][0,0,:,0,0].values()" + "corr[\"Z\"][\"MC_data_ratio\"][0, 0, :, 0, 0].values()" ] }, { @@ -196,7 +212,7 @@ "source": [ "corrh_new = corr[\"Z\"][\"MC_data_ratio\"]\n", "vals = corrh_new.values()\n", - "corrh_new[...] = 1/(vals+(vals==0))" + "corrh_new[...] = 1 / (vals + (vals == 0))" ] }, { @@ -231,7 +247,17 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\", \"red\"], labels=[\"central\", \"Up\", \"Down\"], rrange=[0.98, 1.02], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", rlabel=\"x/NNPDF3.1\", binwnorm=1.0, nlegcols=1)\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\"black\", \"red\", \"red\"],\n", + " labels=[\"central\", \"Up\", \"Down\"],\n", + " rrange=[0.98, 1.02],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/NNPDF3.1\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -242,7 +268,9 @@ "outputs": [], "source": [ "hct18 = histInfo[\"Wmunu\"][\"pdfCT18\"]\n", - "hct18Up, hct18Down = theory_tools.hessianPdfUnc(hct18, \"tensor_axis_0\", False, scale=1/1.67)" + "hct18Up, hct18Down = theory_tools.hessianPdfUnc(\n", + " hct18, \"tensor_axis_0\", False, scale=1 / 1.67\n", + ")" ] }, { @@ -263,9 +291,42 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [x.project(\"ptVgen\") for x in [hnnpdf[...,0], hnnpdfUp, hnnpdfDown, hct18[...,0], hct18Up, hct18Down, hmmht[...,0], hmmhtUp, hmmhtDown]]\n", - "names = [\"NNPDF31\", \"NNPDF31 $\\pm1\\sigma$\", \"\", \"CT18\", \"CT18 $\\pm1\\sigma$\", \"\", \"MMHT\", \"MMHT $\\pm1\\sigma$\", \"\"]\n", - "colors = [\"black\", \"gray\", \"gray\", \"blue\", \"lightblue\", \"lightblue\", \"green\", \"lightgreen\", \"lightgreen\"]" + "hists = [\n", + " x.project(\"ptVgen\")\n", + " for x in [\n", + " hnnpdf[..., 0],\n", + " hnnpdfUp,\n", + " hnnpdfDown,\n", + " hct18[..., 0],\n", + " hct18Up,\n", + " hct18Down,\n", + " hmmht[..., 0],\n", + " hmmhtUp,\n", + " hmmhtDown,\n", + " ]\n", + "]\n", + "names = [\n", + " \"NNPDF31\",\n", + " \"NNPDF31 $\\pm1\\sigma$\",\n", + " \"\",\n", + " \"CT18\",\n", + " \"CT18 $\\pm1\\sigma$\",\n", + " \"\",\n", + " \"MMHT\",\n", + " \"MMHT $\\pm1\\sigma$\",\n", + " \"\",\n", + "]\n", + "colors = [\n", + " \"black\",\n", + " \"gray\",\n", + " \"gray\",\n", + " \"blue\",\n", + " \"lightblue\",\n", + " \"lightblue\",\n", + " \"green\",\n", + " \"lightgreen\",\n", + " \"lightgreen\",\n", + "]" ] }, { @@ -276,8 +337,8 @@ "outputs": [], "source": [ "hnnpdf40 = newhists[\"pdfNNPDF40\"]\n", - "hnnpdf40Cen = hnnpdf40[...,0]\n", - "hnnpdf31Cen = hnnpdf[...,0]\n", + "hnnpdf40Cen = hnnpdf40[..., 0]\n", + "hnnpdf31Cen = hnnpdf[..., 0]\n", "hnnpdf40Up, hnnpdf40Down = theory_tools.hessianPdfUnc(hnnpdf40, \"tensor_axis_0\", True)" ] }, @@ -289,8 +350,10 @@ "outputs": [], "source": [ "hnnpdf4lhc = newhists[\"pdfPDF4LHC21\"]\n", - "hnnpdf4lhcCen = hnnpdf4lhc[...,0]\n", - "hnnpdf4lhcUp, hnnpdf4lhcDown = theory_tools.hessianPdfUnc(hnnpdf4lhc, \"tensor_axis_0\", True)" + "hnnpdf4lhcCen = hnnpdf4lhc[..., 0]\n", + "hnnpdf4lhcUp, hnnpdf4lhcDown = theory_tools.hessianPdfUnc(\n", + " hnnpdf4lhc, \"tensor_axis_0\", True\n", + ")" ] }, { @@ -313,7 +376,17 @@ } ], "source": [ - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=colors, labels=names, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\", rlabel=\"x/NNPDF3.1\", binwnorm=1.0, nlegcols=1)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=colors,\n", + " labels=names,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{Z}}$ (GeV)\",\n", + " rlabel=\"x/NNPDF3.1\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -336,10 +409,37 @@ } ], "source": [ - "hists = [x.project(\"ptVgen\") for x in [hnnpdf31Cen, hnnpdfUp, hnnpdfDown, hnnpdf40Cen, hnnpdf40Up, hnnpdf40Down, ]]\n", - "names = [\"NNPDF3.1$\\pm1\\sigma$\", \"\", \"\", \"NNPDF4.0 $\\pm1\\sigma$\", \"\", \"\", ]\n", + "hists = [\n", + " x.project(\"ptVgen\")\n", + " for x in [\n", + " hnnpdf31Cen,\n", + " hnnpdfUp,\n", + " hnnpdfDown,\n", + " hnnpdf40Cen,\n", + " hnnpdf40Up,\n", + " hnnpdf40Down,\n", + " ]\n", + "]\n", + "names = [\n", + " \"NNPDF3.1$\\pm1\\sigma$\",\n", + " \"\",\n", + " \"\",\n", + " \"NNPDF4.0 $\\pm1\\sigma$\",\n", + " \"\",\n", + " \"\",\n", + "]\n", "colors = [\"black\", \"black\", \"black\", \"red\", \"red\", \"red\"]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=colors, labels=names, rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{W}}$ (GeV)\", rlabel=\"x/NNPDF4.0\", binwnorm=1.0, nlegcols=1)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=colors,\n", + " labels=names,\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{W}}$ (GeV)\",\n", + " rlabel=\"x/NNPDF4.0\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -362,8 +462,28 @@ } ], "source": [ - "yhists = [x.project(\"absYVgen\") for x in [hnnpdf31Cen, hnnpdfUp, hnnpdfDown, hnnpdf40Cen, hnnpdf40Up, hnnpdf40Down, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(yhists, colors=colors, labels=names, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\", rlabel=\"x/NNPDF4.0\", binwnorm=1.0, nlegcols=1)\n" + "yhists = [\n", + " x.project(\"absYVgen\")\n", + " for x in [\n", + " hnnpdf31Cen,\n", + " hnnpdfUp,\n", + " hnnpdfDown,\n", + " hnnpdf40Cen,\n", + " hnnpdf40Up,\n", + " hnnpdf40Down,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " yhists,\n", + " colors=colors,\n", + " labels=names,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\",\n", + " rlabel=\"x/NNPDF4.0\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -386,10 +506,37 @@ } ], "source": [ - "names = [\"NNPDF3.1$\\pm1\\sigma$\", \"\", \"\", \"PDF4LHC21 $\\pm1\\sigma$\", \"\", \"\", ]\n", + "names = [\n", + " \"NNPDF3.1$\\pm1\\sigma$\",\n", + " \"\",\n", + " \"\",\n", + " \"PDF4LHC21 $\\pm1\\sigma$\",\n", + " \"\",\n", + " \"\",\n", + "]\n", "colors = [\"black\", \"black\", \"black\", \"red\", \"red\", \"red\"]\n", - "yhists = [x.project(\"absYVgen\") for x in [hnnpdf31Cen, hnnpdfUp, hnnpdfDown, hnnpdf4lhcCen, hnnpdf4lhcUp, hnnpdf4lhcDown, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(yhists, colors=colors, labels=names, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\", rlabel=\"x/NNPDF4.0\", binwnorm=1.0, nlegcols=1)" + "yhists = [\n", + " x.project(\"absYVgen\")\n", + " for x in [\n", + " hnnpdf31Cen,\n", + " hnnpdfUp,\n", + " hnnpdfDown,\n", + " hnnpdf4lhcCen,\n", + " hnnpdf4lhcUp,\n", + " hnnpdf4lhcDown,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " yhists,\n", + " colors=colors,\n", + " labels=names,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\",\n", + " rlabel=\"x/NNPDF4.0\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -412,8 +559,28 @@ } ], "source": [ - "yhists = [x.project(\"ptVgen\") for x in [hnnpdf31Cen, hnnpdfUp, hnnpdfDown, hnnpdf4lhcCen, hnnpdf4lhcUp, hnnpdf4lhcDown, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(yhists, colors=colors, labels=names, rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\", rlabel=\"x/NNPDF3.0\", binwnorm=1.0, nlegcols=1)\n" + "yhists = [\n", + " x.project(\"ptVgen\")\n", + " for x in [\n", + " hnnpdf31Cen,\n", + " hnnpdfUp,\n", + " hnnpdfDown,\n", + " hnnpdf4lhcCen,\n", + " hnnpdf4lhcUp,\n", + " hnnpdf4lhcDown,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " yhists,\n", + " colors=colors,\n", + " labels=names,\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$|\\mathrm{y}^{\\mathrm{W}}$ (GeV)|\",\n", + " rlabel=\"x/NNPDF3.0\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -423,7 +590,11 @@ "metadata": {}, "outputs": [], "source": [ - "h = input_tools.read_and_scale(\"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\", \"ZmumuPostVFP\", \"nominal_pdfMSHT20\")" + "h = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_pdfMSHT20\",\n", + ")" ] }, { @@ -433,7 +604,11 @@ "metadata": {}, "outputs": [], "source": [ - "hnom = input_tools.read_and_scale(\"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\", \"ZmumuPostVFP\", \"nominal\")" + "hnom = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal\",\n", + ")" ] }, { @@ -443,7 +618,11 @@ "metadata": {}, "outputs": [], "source": [ - "has = input_tools.read_and_scale(\"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\", \"ZmumuPostVFP\", \"nominal_alphaS002pdfMSHT20\")" + "has = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/TheoryCorr/mz_dilepton_scetlib_dyturboN4LLCorr.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_alphaS002pdfMSHT20\",\n", + ")" ] }, { @@ -474,7 +653,7 @@ } ], "source": [ - "has[{\"tensor_axis_0\" : 0}].project(\"yll\").plot()" + "has[{\"tensor_axis_0\": 0}].project(\"yll\").plot()" ] }, { @@ -496,19 +675,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"yll\") for x in [hnom,\n", - " h[{\"tensor_axis_0\" : 0}],\n", - " has[{\"tensor_axis_0\" : 0}],\n", - " has[{\"tensor_axis_0\" : 1}],\n", - " ]],\n", - " [\"Nominal\", \"PDF nom.\", r\"$\\alpha_s$ up\", r\"$\\alpha_s$ down\"], \n", - " colors=[\"black\", \"#7fbf7b\", \"#67a9cf\", \"#762a83\",], \n", - " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/nom\",\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " x.project(\"yll\")\n", + " for x in [\n", + " hnom,\n", + " h[{\"tensor_axis_0\": 0}],\n", + " has[{\"tensor_axis_0\": 0}],\n", + " has[{\"tensor_axis_0\": 1}],\n", + " ]\n", + " ],\n", + " [\"Nominal\", \"PDF nom.\", r\"$\\alpha_s$ up\", r\"$\\alpha_s$ down\"],\n", + " colors=[\n", + " \"black\",\n", + " \"#7fbf7b\",\n", + " \"#67a9cf\",\n", + " \"#762a83\",\n", + " ],\n", + " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/nom\",\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -540,18 +731,29 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"yll\") for x in [hnom,\n", - " hup,\n", - " hdown,\n", - " ]],\n", - " [\"Nominal\", \"PDF up\", r\"PDF down\"], \n", - " colors=[\"black\", \"#7fbf7b\", \"#67a9cf\", ], \n", - " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"Events/bin\",\n", - " rlabel=\"x/nom\",\n", - " rrange=[0.9, 1.1],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + " [\n", + " x.project(\"yll\")\n", + " for x in [\n", + " hnom,\n", + " hup,\n", + " hdown,\n", + " ]\n", + " ],\n", + " [\"Nominal\", \"PDF up\", r\"PDF down\"],\n", + " colors=[\n", + " \"black\",\n", + " \"#7fbf7b\",\n", + " \"#67a9cf\",\n", + " ],\n", + " xlabel=r\"y$^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"Events/bin\",\n", + " rlabel=\"x/nom\",\n", + " rrange=[0.9, 1.1],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -561,7 +763,11 @@ "metadata": {}, "outputs": [], "source": [ - "h = input_tools.read_and_scale(\"/scratch/kelong/Analysis/PdfStudy/mw_with_mu_eta_pt_dyturboCorr.hdf5\", \"ZmumuPostVFP\", \"nominal_pdfMSHT20\")" + "h = input_tools.read_and_scale(\n", + " \"/scratch/kelong/Analysis/PdfStudy/mw_with_mu_eta_pt_dyturboCorr.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_pdfMSHT20\",\n", + ")" ] }, { @@ -641,7 +847,7 @@ } ], "source": [ - "h.project(\"ptll\", \"pdfVar\").values(flow=True)[...,1:-1:2].shape" + "h.project(\"ptll\", \"pdfVar\").values(flow=True)[..., 1:-1:2].shape" ] }, { @@ -662,7 +868,7 @@ } ], "source": [ - "h.project(\"ptll\", \"pdfVar\").values(flow=True)[...,2::2].shape" + "h.project(\"ptll\", \"pdfVar\").values(flow=True)[..., 2::2].shape" ] }, { @@ -767,7 +973,7 @@ ], "source": [ "for i in h.axes[\"pdfVar\"]:\n", - " print(h[{\"pdfVar\" : i}].sum())" + " print(h[{\"pdfVar\": i}].sum())" ] } ], diff --git a/notebooks/testPostfitPdf.ipynb b/notebooks/testPostfitPdf.ipynb index 200ef579e..804981424 100644 --- a/notebooks/testPostfitPdf.ipynb +++ b/notebooks/testPostfitPdf.ipynb @@ -11,8 +11,8 @@ "import matplotlib.pyplot as plt\n", "from wremnants.datasets.datagroups import datagroups2016\n", "from wremnants import boostHistHelpers as hh\n", - "from wremnants import plot_tools,syst_tools,theory_tools\n", - "from wremnants import histselections as sel #, combine_helpers as ch\n", + "from wremnants import plot_tools, syst_tools, theory_tools\n", + "from wremnants import histselections as sel # , combine_helpers as ch\n", "import lz4.frame\n", "import pickle\n", "import numpy as np\n", @@ -41,7 +41,10 @@ "outputs": [], "source": [ "combine_path = \"../combineResults/Wmass/qcdScaleByHelicityPt/pdfNNPDF31_PseudoCT18/\"\n", - "postfit_helper = postfit_helpers.PostfitHelper(f\"{combine_path}/fitresults_123456789.root\", f\"{combine_path}/WMassCombineInput.root\")\n", + "postfit_helper = postfit_helpers.PostfitHelper(\n", + " f\"{combine_path}/fitresults_123456789.root\",\n", + " f\"{combine_path}/WMassCombineInput.root\",\n", + ")\n", "postfit_helper.read_covariance_matrix()" ] }, @@ -61,7 +64,7 @@ "outputs": [], "source": [ "postfit_helper.set_nuisance_subset_by_regex(\"pdf\\d+NNPDF31\")\n", - "#postfit_helper.set_nuisance_scaling(\"pdf.*Alpha.*\", 0.75)" + "# postfit_helper.set_nuisance_scaling(\"pdf.*Alpha.*\", 0.75)" ] }, { @@ -125,10 +128,47 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(h[{\"charge\" : hist.sum}]) for h in [hnom, pseudo_data, up_var, down_var, prefit_up_var, prefit_down_var, ]]\n", - "colors = [\"blue\", \"black\", \"red\", \"red\", \"grey\", \"grey\",]\n", - "labels = [\"nominal\", \"pseudo-data (alt. PDF)\", \"postfit $\\pm 1\\sigma$\", \"\", \"pretfit $\\pm 1\\sigma$\", \"\", ]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=colors, labels=labels, rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=\"($\\eta^{\\ell}$, p$_{T}^{\\mathrm{\\ell}}$) bin\", rlabel=\"x/nominal\", binwnorm=1.0, nlegcols=1, fill_between=True, alpha=0.7, skip_fill_between=2)" + "hists = [\n", + " sel.unrolledHist(h[{\"charge\": hist.sum}])\n", + " for h in [\n", + " hnom,\n", + " pseudo_data,\n", + " up_var,\n", + " down_var,\n", + " prefit_up_var,\n", + " prefit_down_var,\n", + " ]\n", + "]\n", + "colors = [\n", + " \"blue\",\n", + " \"black\",\n", + " \"red\",\n", + " \"red\",\n", + " \"grey\",\n", + " \"grey\",\n", + "]\n", + "labels = [\n", + " \"nominal\",\n", + " \"pseudo-data (alt. PDF)\",\n", + " \"postfit $\\pm 1\\sigma$\",\n", + " \"\",\n", + " \"pretfit $\\pm 1\\sigma$\",\n", + " \"\",\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=colors,\n", + " labels=labels,\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"($\\eta^{\\ell}$, p$_{T}^{\\mathrm{\\ell}}$) bin\",\n", + " rlabel=\"x/nominal\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + " fill_between=True,\n", + " alpha=0.7,\n", + " skip_fill_between=2,\n", + ")" ] }, { @@ -149,7 +189,10 @@ "outputs": [], "source": [ "combine_path = \"../combineResults/Wmass/qcdScaleByHelicityPt/pdfCT18_PseudoNNPDF31\"\n", - "postfit_helper_ct18 = postfit_helpers.PostfitHelper(f\"{combine_path}/fitresults_123456789.root\", f\"{combine_path}/WMassCombineInput.root\")\n", + "postfit_helper_ct18 = postfit_helpers.PostfitHelper(\n", + " f\"{combine_path}/fitresults_123456789.root\",\n", + " f\"{combine_path}/WMassCombineInput.root\",\n", + ")\n", "postfit_helper_ct18.read_covariance_matrix()" ] }, @@ -165,7 +208,7 @@ "postfit_helper_ct18.set_hist_name(\"x_Wmunu\")\n", "postfit_helper_ct18.read_nominal_hist()\n", "postfit_helper_ct18.set_nuisance_subset_by_regex(\"pdf\\d+CT18\")\n", - "postfit_helper_ct18.set_nuisance_scaling(\"pdf\\d+CT18\", 1/1.64)" + "postfit_helper_ct18.set_nuisance_scaling(\"pdf\\d+CT18\", 1 / 1.64)" ] }, { @@ -343,10 +386,45 @@ } ], "source": [ - "hists = [sel.unrolledHist(h[{\"charge\" : hist.sum}]) for h in [nom, up_var, down_var, prefit_up_var, prefit_down_var, ]]\n", - "colors = [\"blue\", \"red\", \"red\", \"grey\", \"grey\",]\n", - "labels = [\"nominal\", \"postfit $\\pm 1\\sigma$\", \"\", \"pretfit $\\pm 1\\sigma$\", \"\", ]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, data=sel.unrolledHist(pseudo_data), data_label=\"Pseudodata (NNPDF3.1)\", colors=colors, labels=labels, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\", rlabel=\"x/prefit\", binwnorm=1.0, nlegcols=1, fill_between=True, alpha=0.7)" + "hists = [\n", + " sel.unrolledHist(h[{\"charge\": hist.sum}])\n", + " for h in [\n", + " nom,\n", + " up_var,\n", + " down_var,\n", + " prefit_up_var,\n", + " prefit_down_var,\n", + " ]\n", + "]\n", + "colors = [\n", + " \"blue\",\n", + " \"red\",\n", + " \"red\",\n", + " \"grey\",\n", + " \"grey\",\n", + "]\n", + "labels = [\n", + " \"nominal\",\n", + " \"postfit $\\pm 1\\sigma$\",\n", + " \"\",\n", + " \"pretfit $\\pm 1\\sigma$\",\n", + " \"\",\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " data=sel.unrolledHist(pseudo_data),\n", + " data_label=\"Pseudodata (NNPDF3.1)\",\n", + " colors=colors,\n", + " labels=labels,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\",\n", + " rlabel=\"x/prefit\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + " fill_between=True,\n", + " alpha=0.7,\n", + ")" ] }, { @@ -356,10 +434,38 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(h[{\"charge\" : hist.sum}]) for h in [hnom, prefit_up_var, prefit_down_var, ]]\n", - "colors = [\"blue\", \"grey\", \"grey\",]\n", - "labels = [\"nominal\", \"pretfit $\\pm 1\\sigma$\", \"\", ]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, data=sel.unrolledHist(pseudo_data[{\"charge\" : hist.sum}]), data_label=\"pseudodata\",colors=colors, labels=labels, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\", rlabel=\"x/prefit\", binwnorm=1.0, nlegcols=1, alpha=0.7)\n" + "hists = [\n", + " sel.unrolledHist(h[{\"charge\": hist.sum}])\n", + " for h in [\n", + " hnom,\n", + " prefit_up_var,\n", + " prefit_down_var,\n", + " ]\n", + "]\n", + "colors = [\n", + " \"blue\",\n", + " \"grey\",\n", + " \"grey\",\n", + "]\n", + "labels = [\n", + " \"nominal\",\n", + " \"pretfit $\\pm 1\\sigma$\",\n", + " \"\",\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " data=sel.unrolledHist(pseudo_data[{\"charge\": hist.sum}]),\n", + " data_label=\"pseudodata\",\n", + " colors=colors,\n", + " labels=labels,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\",\n", + " rlabel=\"x/prefit\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + " alpha=0.7,\n", + ")" ] }, { @@ -491,7 +597,7 @@ "metadata": {}, "outputs": [], "source": [ - "theta_down = np.insert(pdf_pulls - np.sqrt(w)*v, 0, values=pdf_pulls, axis=0)" + "theta_down = np.insert(pdf_pulls - np.sqrt(w) * v, 0, values=pdf_pulls, axis=0)" ] }, { @@ -533,7 +639,9 @@ "metadata": {}, "outputs": [], "source": [ - "pdf_up = np.prod(np.power(kappa[...,np.newaxis].T, theta_up[...,np.newaxis,np.newaxis]), axis=1).T" + "pdf_up = np.prod(\n", + " np.power(kappa[..., np.newaxis].T, theta_up[..., np.newaxis, np.newaxis]), axis=1\n", + ").T" ] }, { @@ -543,7 +651,9 @@ "metadata": {}, "outputs": [], "source": [ - "pdf_down = np.prod(np.power(kappa[...,np.newaxis].T, theta_down[...,np.newaxis,np.newaxis]), axis=1).T" + "pdf_down = np.prod(\n", + " np.power(kappa[..., np.newaxis].T, theta_down[..., np.newaxis, np.newaxis]), axis=1\n", + ").T" ] }, { @@ -570,7 +680,7 @@ "outputs": [], "source": [ "pdf_hist_post_up = pdf_hist_pre.copy()\n", - "pdf_hist_post_up[...,:] = nominal_hist.values()[...,np.newaxis]*pdf_up" + "pdf_hist_post_up[..., :] = nominal_hist.values()[..., np.newaxis] * pdf_up" ] }, { @@ -581,7 +691,7 @@ "outputs": [], "source": [ "pdf_hist_post_down = pdf_hist_pre.copy()\n", - "pdf_hist_post_down[...,:] = nominal_hist.values()[...,np.newaxis]*pdf_down" + "pdf_hist_post_down[..., :] = nominal_hist.values()[..., np.newaxis] * pdf_down" ] }, { @@ -591,11 +701,24 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [pdf_hist_pre[...,0], pdf_hist_post_up[...,0], wpost[{\"charge\" : 1.j}]]]\n", + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [pdf_hist_pre[..., 0], pdf_hist_post_up[..., 0], wpost[{\"charge\": 1.0j}]]\n", + "]\n", "labels = [\"pre\", \"post\", \"full post\"]\n", "colors = [\"black\", \"red\", \"green\"]\n", "\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=colors, labels=labels, rrange=[0.9, 1.1], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\", rlabel=\"x/NNPDF3.1\", binwnorm=1.0, nlegcols=1)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=colors,\n", + " labels=labels,\n", + " rrange=[0.9, 1.1],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\",\n", + " rlabel=\"x/NNPDF3.1\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -669,9 +792,9 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [pdf_hist_post_up[...,i] for i in range(101)]]\n", - "colors = [\"black\"]+[\"red\" for i in range(1,101)]\n", - "labels = [\"Cen.\"]+[f\"pdf{i}\" for i in range(1,101)]" + "hists = [sel.unrolledHist(x) for x in [pdf_hist_post_up[..., i] for i in range(101)]]\n", + "colors = [\"black\"] + [\"red\" for i in range(1, 101)]\n", + "labels = [\"Cen.\"] + [f\"pdf{i}\" for i in range(1, 101)]" ] }, { @@ -702,7 +825,17 @@ "metadata": {}, "outputs": [], "source": [ - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=colors, labels=labels, rrange=[0.98, 1.02], ylabel=\"$\\sigma$/bin\", xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\", rlabel=\"x/NNPDF3.1\", binwnorm=1.0, nlegcols=1)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=colors,\n", + " labels=labels,\n", + " rrange=[0.98, 1.02],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"p$_{T}^{\\mathrm{\\ell}}$ (GeV)\",\n", + " rlabel=\"x/NNPDF3.1\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -720,8 +853,23 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [pdf_hist_pre[...,0], preUp, preDown, postUp, postDown]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\", \"red\", \"green\", \"green\"], labels=[\"prefit MC (NNPDF3.1)\", \"prefit unc.\", \"\", \"postfit (CT18)+unc\", \"\"], rrange=[0.97, 1.03], ylabel=\"Events/bin\", xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\", rlabel=\"x/prefit\", binwnorm=1.0, nlegcols=1, fill_between=True, alpha=0.5)\n" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [pdf_hist_pre[..., 0], preUp, preDown, postUp, postDown]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\"black\", \"red\", \"red\", \"green\", \"green\"],\n", + " labels=[\"prefit MC (NNPDF3.1)\", \"prefit unc.\", \"\", \"postfit (CT18)+unc\", \"\"],\n", + " rrange=[0.97, 1.03],\n", + " ylabel=\"Events/bin\",\n", + " xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\",\n", + " rlabel=\"x/prefit\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + " fill_between=True,\n", + " alpha=0.5,\n", + ")" ] }, { @@ -731,8 +879,29 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [wpre[...,1.j], wpost[...,1.j], pdf_hist_post_up[...,0]]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\", \"green\",], labels=[\"central (prefit)\", \"full postfit\", \"postfit PDF only\",], rrange=[0.96, 1.04], ylabel=\"$\\sigma$/bin\", xlabel=\"$\\eta^{\\ell}$\", rlabel=\"x/MC pred.\", binwnorm=1.0, nlegcols=1)" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [wpre[..., 1.0j], wpost[..., 1.0j], pdf_hist_post_up[..., 0]]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"central (prefit)\",\n", + " \"full postfit\",\n", + " \"postfit PDF only\",\n", + " ],\n", + " rrange=[0.96, 1.04],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=\"$\\eta^{\\ell}$\",\n", + " rlabel=\"x/MC pred.\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -742,8 +911,29 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [wpre[...,1.j], wpost[...,1.j], pdf_hist_post_up[...,0]]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\", \"green\",], labels=[\"central (prefit)\", \"W postfit\", \"W postfit PDF only\",], rrange=[0.96, 1.04], ylabel=\"$\\sigma$/bin\", xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\", rlabel=\"x/MC pred.\", binwnorm=1.0, nlegcols=1)\n" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [wpre[..., 1.0j], wpost[..., 1.0j], pdf_hist_post_up[..., 0]]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"central (prefit)\",\n", + " \"W postfit\",\n", + " \"W postfit PDF only\",\n", + " ],\n", + " rrange=[0.96, 1.04],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\",\n", + " rlabel=\"x/MC pred.\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -753,8 +943,33 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [prefit[...,1.j], pseudoData[...,1.j], fitres[...,1.j], ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"red\", \"black\", \"green\",], labels=[\"Pseudodata\", \"full postfit (all procs.)\", \"prefit (MC pred.)\",], rrange=[0.96, 1.04], ylabel=\"Events/bin\", xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\", rlabel=\"x/MC pred.\", binwnorm=1.0, nlegcols=1)\n" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [\n", + " prefit[..., 1.0j],\n", + " pseudoData[..., 1.0j],\n", + " fitres[..., 1.0j],\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"red\",\n", + " \"black\",\n", + " \"green\",\n", + " ],\n", + " labels=[\n", + " \"Pseudodata\",\n", + " \"full postfit (all procs.)\",\n", + " \"prefit (MC pred.)\",\n", + " ],\n", + " rrange=[0.96, 1.04],\n", + " ylabel=\"Events/bin\",\n", + " xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\",\n", + " rlabel=\"x/MC pred.\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -792,8 +1007,8 @@ "metadata": {}, "outputs": [], "source": [ - "font = {'size' : 22}\n", - "matplotlib.rc('font', **font)" + "font = {\"size\": 22}\n", + "matplotlib.rc(\"font\", **font)" ] }, { @@ -804,9 +1019,21 @@ "outputs": [], "source": [ "hists = [pseudoData, fitres, pre]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\", \"blue\"], labels=[\"CT18 pseudodata\", \"postfit sum MC\", \"prefit sum MC\",], rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\", rlabel=\"x/pseudodata\", binwnorm=1.0, nlegcols=1)\n", - "\n", - "\n" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\"black\", \"red\", \"blue\"],\n", + " labels=[\n", + " \"CT18 pseudodata\",\n", + " \"postfit sum MC\",\n", + " \"prefit sum MC\",\n", + " ],\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\",\n", + " rlabel=\"x/pseudodata\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { @@ -826,10 +1053,31 @@ "metadata": {}, "outputs": [], "source": [ - "hists = [sel.unrolledHist(x) for x in [wpre, wpost, ]]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists, colors=[\"black\", \"red\",], labels=[\"prefit (NNPDF3.1)\", \"postfit (CT18)\", \"prefit sum MC\",], rrange=[0.95, 1.05], ylabel=\"$\\sigma$/bin\", xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\", rlabel=\"x/pseudodata\", binwnorm=1.0, nlegcols=1)\n", - "\n", - "\n" + "hists = [\n", + " sel.unrolledHist(x)\n", + " for x in [\n", + " wpre,\n", + " wpost,\n", + " ]\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists,\n", + " colors=[\n", + " \"black\",\n", + " \"red\",\n", + " ],\n", + " labels=[\n", + " \"prefit (NNPDF3.1)\",\n", + " \"postfit (CT18)\",\n", + " \"prefit sum MC\",\n", + " ],\n", + " rrange=[0.95, 1.05],\n", + " ylabel=\"$\\sigma$/bin\",\n", + " xlabel=r\"($\\eta^{\\ell}$, p$_{\\mathrm{T}}^{\\ell}$) bin\",\n", + " rlabel=\"x/pseudodata\",\n", + " binwnorm=1.0,\n", + " nlegcols=1,\n", + ")" ] }, { diff --git a/notebooks/theoryAngularCoeffComparisons.ipynb b/notebooks/theoryAngularCoeffComparisons.ipynb index 804f3c2e9..b88974ff9 100644 --- a/notebooks/theoryAngularCoeffComparisons.ipynb +++ b/notebooks/theoryAngularCoeffComparisons.ipynb @@ -15,7 +15,7 @@ "metadata": {}, "outputs": [], "source": [ - "from wums import boostHistHelpers as hh,output_tools, plot_tools\n", + "from wums import boostHistHelpers as hh, output_tools, plot_tools\n", "from utilities import common\n", "from utilities.io_tools import input_tools\n", "from wremnants import theory_tools, theory_corrections\n", @@ -26,7 +26,7 @@ "import lz4.frame\n", "import os\n", "import numpy as np\n", - "from wremnants import syst_tools,histselections as sel\n", + "from wremnants import syst_tools, histselections as sel\n", "import copy\n", "import math" ] @@ -75,7 +75,9 @@ "metadata": {}, "outputs": [], "source": [ - "hwp = input_tools.read_and_scale(minnlof, \"WplusmunuPostVFP\", \"nominal_gen\", apply_xsec=False)" + "hwp = input_tools.read_and_scale(\n", + " minnlof, \"WplusmunuPostVFP\", \"nominal_gen\", apply_xsec=False\n", + ")" ] }, { @@ -85,7 +87,9 @@ "metadata": {}, "outputs": [], "source": [ - "hhelwp = input_tools.read_and_scale(minnlof, \"WplusmunuPostVFP\", \"nominal_gen_helicity_xsecs_scale_lhe\")" + "hhelwp = input_tools.read_and_scale(\n", + " minnlof, \"WplusmunuPostVFP\", \"nominal_gen_helicity_xsecs_scale_lhe\"\n", + ")" ] }, { @@ -103,7 +107,9 @@ "metadata": {}, "outputs": [], "source": [ - "hhel_wp_pt = hhelwp[{\"absYVgen\" : hist.sum, \"chargeVgen\" : hist.sum, \"massVgen\" : hist.sum}][{\"muRfact\" : 2j, \"muFfact\" : 1j}]" + "hhel_wp_pt = hhelwp[\n", + " {\"absYVgen\": hist.sum, \"chargeVgen\": hist.sum, \"massVgen\": hist.sum}\n", + "][{\"muRfact\": 2j, \"muFfact\": 1j}]" ] }, { @@ -113,7 +119,9 @@ "metadata": {}, "outputs": [], "source": [ - "hhel_wp_y = hhelwp[{\"ptVgen\" : hist.sum, \"chargeVgen\" : hist.sum, \"massVgen\" : hist.sum}][{\"muRfact\" : 2j, \"muFfact\" : 1j}]" + "hhel_wp_y = hhelwp[{\"ptVgen\": hist.sum, \"chargeVgen\": hist.sum, \"massVgen\": hist.sum}][\n", + " {\"muRfact\": 2j, \"muFfact\": 1j}\n", + "]" ] }, { @@ -131,7 +139,9 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_wm_f = uproot.open(\"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/wm-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\")" + "dyturbo_wm_f = uproot.open(\n", + " \"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/wm-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\"\n", + ")" ] }, { @@ -141,7 +151,9 @@ "metadata": {}, "outputs": [], "source": [ - "dyturbo_wp_f = uproot.open(\"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/wp-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\")" + "dyturbo_wp_f = uproot.open(\n", + " \"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/wp-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\"\n", + ")" ] }, { @@ -171,7 +183,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloh = input_tools.read_and_scale(minnlof, \"WplusmunuPostVFP\", \"nominal_gen_qcdScale\")" + "minnloh = input_tools.read_and_scale(\n", + " minnlof, \"WplusmunuPostVFP\", \"nominal_gen_qcdScale\"\n", + ")" ] }, { @@ -210,7 +224,9 @@ ], "source": [ "boson = \"wp\"\n", - "dyturbof = uproot.open(f\"/scratch/submit/cms/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/{boson.lower()}-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\") \n", + "dyturbof = uproot.open(\n", + " f\"/scratch/submit/cms/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/{boson.lower()}-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\"\n", + ")\n", "input_tools.read_dyturbo_angular_coeffs(dyturbof, absy=True)" ] }, @@ -221,7 +237,9 @@ "metadata": {}, "outputs": [], "source": [ - "hcoeff_wp_y = theory_tools.helicity_xsec_to_angular_coeffs(hhel_wp_y[{\"absYVgen\" : hist.rebin(10)}])\n" + "hcoeff_wp_y = theory_tools.helicity_xsec_to_angular_coeffs(\n", + " hhel_wp_y[{\"absYVgen\": hist.rebin(10)}]\n", + ")" ] }, { @@ -235,52 +253,65 @@ " eosout = \"/eos/user/k/kelong/www/WMassAnalysis/TheoryComparisons/\"\n", " out = output_tools.make_plot_dir(eosout, f\"{boson}_angular\", eoscp=True)\n", "\n", - " label = \"Wplusmunu\" if boson == \"Wp\" else (\"Wminusmunu\" if boson == \"Wm\" else \"Zmumu\")\n", + " label = (\n", + " \"Wplusmunu\" if boson == \"Wp\" else (\"Wminusmunu\" if boson == \"Wm\" else \"Zmumu\")\n", + " )\n", " minnlo_obs = \"absYVgen\" if obs == \"y\" else \"ptVgen\"\n", "\n", - " #hhel = input_tools.read_and_scale(minnlof, f\"{label}PostVFP\", \"nominal_gen_helicity_xsecs_scale_lhe\")\n", - " hhel = input_tools.read_and_scale(minnlof, f\"{label}PostVFP\", \"nominal_gen_helicity_xsecs_scale\")\n", + " # hhel = input_tools.read_and_scale(minnlof, f\"{label}PostVFP\", \"nominal_gen_helicity_xsecs_scale_lhe\")\n", + " hhel = input_tools.read_and_scale(\n", + " minnlof, f\"{label}PostVFP\", \"nominal_gen_helicity_xsecs_scale\"\n", + " )\n", " hdyturbo = dyturbof[f\"s_{obs}\"].to_hist()\n", "\n", " if not binning:\n", " binning = hdyturbo.axes[0].edges\n", "\n", " print(binning)\n", - " \n", + "\n", " hhel_rebin = hh.rebinHist(hhel, \"ptVgen\", binning)\n", - " \n", + "\n", " dytax = \"yaxis\" if obs == \"y\" else \"xaxis\"\n", " hdyturbo = hh.rebinHist(hdyturbo, dytax, binning)\n", - " sum_ax = [x for x in hhel.axes.name if x not in [\"helicity\", \"muRfact\", \"muFfact\", minnlo_obs]]\n", - " hcoeff = theory_tools.helicity_xsec_to_angular_coeffs(hhel_rebin[{x : hist.sum for x in sum_ax}][{\"muRfact\" : 2j, \"muFfact\" : 1j}])\n", - " \n", + " sum_ax = [\n", + " x\n", + " for x in hhel.axes.name\n", + " if x not in [\"helicity\", \"muRfact\", \"muFfact\", minnlo_obs]\n", + " ]\n", + " hcoeff = theory_tools.helicity_xsec_to_angular_coeffs(\n", + " hhel_rebin[{x: hist.sum for x in sum_ax}][{\"muRfact\": 2j, \"muFfact\": 1j}]\n", + " )\n", + "\n", " for i in range(8):\n", - " scale=1\n", + " scale = 1\n", " if i in [1, 4]:\n", " scale *= -1\n", "\n", " boson_label = \"Z\" if boson == \"Z\" else (\"W^{-}\" if boson == \"Wm\" else \"W^{+}\")\n", - " label = f\"y$^{{{boson_label}}}$\" if obs == \"y\" else f\"p$_T^{{{boson_label}}}$ (GeV)\"\n", + " label = (\n", + " f\"y$^{{{boson_label}}}$\" if obs == \"y\" else f\"p$_T^{{{boson_label}}}$ (GeV)\"\n", + " )\n", "\n", - " hang = hh.rebinHist(dyturbof[f\"wgt_a{i}_y_qt\"].to_hist().project(dytax), dytax, edges=binning) \n", + " hang = hh.rebinHist(\n", + " dyturbof[f\"wgt_a{i}_y_qt\"].to_hist().project(dytax), dytax, edges=binning\n", + " )\n", " dyturbo_coeff = hh.divideHists(hang, hdyturbo)\n", "\n", - " \n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " hcoeff[{\"helicity\" : complex(0, i)}].project(minnlo_obs)*scale, \n", - " dyturbo_coeff,\n", - " ],\n", - " [\"MiNNLO\", \"DYTurbo\"],\n", - " colors=['orange', plt.get_cmap(\"tab10\")(i)], \n", - " xlabel=label, \n", - " ylabel=f\"A$_{i}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.2, 1.4],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True,\n", - " logx=logx,\n", - " )\n", + " [\n", + " hcoeff[{\"helicity\": complex(0, i)}].project(minnlo_obs) * scale,\n", + " dyturbo_coeff,\n", + " ],\n", + " [\"MiNNLO\", \"DYTurbo\"],\n", + " colors=[\"orange\", plt.get_cmap(\"tab10\")(i)],\n", + " xlabel=label,\n", + " ylabel=f\"A$_{i}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.2, 1.4],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " logx=logx,\n", + " )\n", " plot_tools.save_pdf_and_png(out, f\"{obs}{boson}_MiNNLO_A{i}\")\n", " output_tools.write_index_and_log(out, f\"{obs}{boson}_MiNNLO_A{i}\")\n", " plt.close()\n", @@ -325,9 +356,11 @@ ], "source": [ "for boson in [\"Wp\", \"Wm\", \"Z\"]:\n", - " #for obs in [\"y\", \"qt\"]:\n", + " # for obs in [\"y\", \"qt\"]:\n", " for obs in [\"qt\"]:\n", - " dyturbof = uproot.open(f\"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/{boson.lower()}-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\") \n", + " dyturbof = uproot.open(\n", + " f\"/ceph/submit/data/user/k/kdlong/TheoryCorrections/DYTURBO/ai/DYTurbo_2D_Ais/{boson.lower()}-13tev-cms-2d-ai-qt-y-vj-born-ct-nnlo.root\"\n", + " )\n", " plotCoeffs(minnlof, dyturbof, obs, boson, binning=None)" ] }, @@ -437,8 +470,22 @@ } ], "source": [ - "plotCoeffs(minnlof, dyturbo_wp_f, \"qt\", \"Wp\", binning=[1,8,17,27,40,55,75,100], logx=True)\n", - "plotCoeffs(minnlof, dyturbo_wm_f, \"qt\", \"Wm\", binning=[1,8,17,27,40,55,75,100], logx=True)" + "plotCoeffs(\n", + " minnlof,\n", + " dyturbo_wp_f,\n", + " \"qt\",\n", + " \"Wp\",\n", + " binning=[1, 8, 17, 27, 40, 55, 75, 100],\n", + " logx=True,\n", + ")\n", + "plotCoeffs(\n", + " minnlof,\n", + " dyturbo_wm_f,\n", + " \"qt\",\n", + " \"Wm\",\n", + " binning=[1, 8, 17, 27, 40, 55, 75, 100],\n", + " logx=True,\n", + ")" ] }, { @@ -572,24 +619,27 @@ "eosout = \"/eos/user/k/kelong/www/WMassAnalysis/TheoryComparisons/\"\n", "out = output_tools.make_plot_dir(eosout, \"Wp_angular\", eoscp=True)\n", "for i in range(8):\n", - " scale=1\n", + " scale = 1\n", " if i in [1, 4]:\n", " scale *= -1\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " hcoeff_wp_y[{\"helicity\" : complex(0, i)}].project(\"y\")*scale, \n", - " hh.divideHists(dyturbo_wp_f[f\"wgt_a{i}_y_qt\"].to_hist().project(\"yaxis\"),\n", - " dyturbo_wp_f[f\"s_y\"].to_hist(), move_axes=False)\n", - " ],\n", - " [\"MiNNLO\", \"DYTurbo\"],\n", - " colors=['orange', plt.get_cmap(\"tab10\")(i)], \n", - " xlabel=\"y$^{Z}$ (GeV)\", \n", - " ylabel=f\"A$_{i}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.8, 1.2],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True\n", - " )\n", + " [\n", + " hcoeff_wp_y[{\"helicity\": complex(0, i)}].project(\"y\") * scale,\n", + " hh.divideHists(\n", + " dyturbo_wp_f[f\"wgt_a{i}_y_qt\"].to_hist().project(\"yaxis\"),\n", + " dyturbo_wp_f[f\"s_y\"].to_hist(),\n", + " move_axes=False,\n", + " ),\n", + " ],\n", + " [\"MiNNLO\", \"DYTurbo\"],\n", + " colors=[\"orange\", plt.get_cmap(\"tab10\")(i)],\n", + " xlabel=\"y$^{Z}$ (GeV)\",\n", + " ylabel=f\"A$_{i}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.8, 1.2],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " )\n", " plot_tools.save_pdf_and_png(out, f\"yWp_MiNNLO_A{i}\")\n", " plot_tools.write_index_and_log(out, f\"yWp_MiNNLO_A{i}\")\n", "print(out)\n", @@ -698,20 +748,23 @@ " if i in [1, 4]:\n", " scale *= -1\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " hh.rebinHistsToCommon([\n", - " hhel_wp_pt[{\"helicity\" : complex(0, i)}].project(\"ptVgen\")*scale, \n", - " dyturbo_wp_f[f\"wgt_a{i}_y_qt\"].to_hist().project(\"xaxis\"),\n", - " ], 0),\n", - " [\"MiNNLO\", \"DYTurbo\"],\n", - " colors=['orange', 'green'], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=f\"A$_{i}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.8, 1.2],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True,\n", - " binwnorm=1.\n", - " )" + " hh.rebinHistsToCommon(\n", + " [\n", + " hhel_wp_pt[{\"helicity\": complex(0, i)}].project(\"ptVgen\") * scale,\n", + " dyturbo_wp_f[f\"wgt_a{i}_y_qt\"].to_hist().project(\"xaxis\"),\n", + " ],\n", + " 0,\n", + " ),\n", + " [\"MiNNLO\", \"DYTurbo\"],\n", + " colors=[\"orange\", \"green\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=f\"A$_{i}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.8, 1.2],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + " binwnorm=1.0,\n", + " )" ] }, { @@ -731,9 +784,15 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_dyturboHelh = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", \"nominal_scetlib_dyturboHelicityCorr\")\n", - "scetlib_dyturboNoA4Helh = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", \"nominal_scetlib_dyturboNoA4HelicityCorr\")\n", - "scetlib_dyturboh = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", \"nominal\")" + "scetlib_dyturboHelh = input_tools.read_and_scale(\n", + " minnlo_recof, \"WplusmunuPostVFP\", \"nominal_scetlib_dyturboHelicityCorr\"\n", + ")\n", + "scetlib_dyturboNoA4Helh = input_tools.read_and_scale(\n", + " minnlo_recof, \"WplusmunuPostVFP\", \"nominal_scetlib_dyturboNoA4HelicityCorr\"\n", + ")\n", + "scetlib_dyturboh = input_tools.read_and_scale(\n", + " minnlo_recof, \"WplusmunuPostVFP\", \"nominal\"\n", + ")" ] }, { @@ -743,7 +802,9 @@ "metadata": {}, "outputs": [], "source": [ - "dyturboHelh = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", \"nominal_minnlo_dyturboHelicityCorr\")\n", + "dyturboHelh = input_tools.read_and_scale(\n", + " minnlo_recof, \"WplusmunuPostVFP\", \"nominal_minnlo_dyturboHelicityCorr\"\n", + ")\n", "minnloh = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", \"nominal_uncorr\")" ] }, @@ -766,18 +827,18 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " sel.unrolledHist(minnloh),\n", - " sel.unrolledHist(dyturboHelh[{\"vars\" : 0}]), \n", - " ],\n", - " [\"MiNNLO uncorr.\", \"MiNNLO (DYTurbo angular)\"],\n", - " colors=['orange', 'green'], \n", - " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.99, 1.01],\n", - " baseline=True\n", - " )" + " [\n", + " sel.unrolledHist(minnloh),\n", + " sel.unrolledHist(dyturboHelh[{\"vars\": 0}]),\n", + " ],\n", + " [\"MiNNLO uncorr.\", \"MiNNLO (DYTurbo angular)\"],\n", + " colors=[\"orange\", \"green\"],\n", + " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.99, 1.01],\n", + " baseline=True,\n", + ")" ] }, { @@ -799,20 +860,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " sel.unrolledHist(scetlib_dyturboh), \n", - " sel.unrolledHist(scetlib_dyturboHelh[{\"vars\" : 0}]),\n", - " sel.unrolledHist(minnloh),\n", - " ],\n", - " #[\"SCETlib+DYTurbo (sigmaUL)\", \"SCETlib+DYTurbo (DYTurbo angular)\", \"SCETlib+DYTurbo (DYTurbo Ai's excl. A4)\"],\n", - " [\"SCETlib+DYTurbo (sigmaUL)\", \"SCETlib+DYTurbo (DYTurbo angular)\", \"MiNNLO uncorr.\"],\n", - " colors=['purple', \"blue\", \"orange\"], \n", - " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.99, 1.01],\n", - " baseline=True\n", - " )" + " [\n", + " sel.unrolledHist(scetlib_dyturboh),\n", + " sel.unrolledHist(scetlib_dyturboHelh[{\"vars\": 0}]),\n", + " sel.unrolledHist(minnloh),\n", + " ],\n", + " # [\"SCETlib+DYTurbo (sigmaUL)\", \"SCETlib+DYTurbo (DYTurbo angular)\", \"SCETlib+DYTurbo (DYTurbo Ai's excl. A4)\"],\n", + " [\n", + " \"SCETlib+DYTurbo (sigmaUL)\",\n", + " \"SCETlib+DYTurbo (DYTurbo angular)\",\n", + " \"MiNNLO uncorr.\",\n", + " ],\n", + " colors=[\"purple\", \"blue\", \"orange\"],\n", + " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.99, 1.01],\n", + " baseline=True,\n", + ")" ] }, { @@ -904,20 +969,28 @@ ], "source": [ "for i in range(8):\n", - " scetlib_aih = input_tools.read_and_scale(minnlo_recof, \"WplusmunuPostVFP\", f\"nominal_scetlib_dyturboA{i}HelicityCorr\")\n", + " scetlib_aih = input_tools.read_and_scale(\n", + " minnlo_recof, \"WplusmunuPostVFP\", f\"nominal_scetlib_dyturboA{i}HelicityCorr\"\n", + " )\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " sel.unrolledHist(scetlib_dyturboh), \n", - " sel.unrolledHist(scetlib_aih[{\"vars\" : 0}]),\n", - " ],\n", - " [\"SCETlib+DYTurbo (sigmaUL)\", f\"SCETlib+DYTurbo (DYTurbo $A_{i}$)\", ],\n", - " colors=['purple', plt.get_cmap(\"tab10\")(i), ], \n", - " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.99, 1.01],\n", - " baseline=True\n", - " )" + " [\n", + " sel.unrolledHist(scetlib_dyturboh),\n", + " sel.unrolledHist(scetlib_aih[{\"vars\": 0}]),\n", + " ],\n", + " [\n", + " \"SCETlib+DYTurbo (sigmaUL)\",\n", + " f\"SCETlib+DYTurbo (DYTurbo $A_{i}$)\",\n", + " ],\n", + " colors=[\n", + " \"purple\",\n", + " plt.get_cmap(\"tab10\")(i),\n", + " ],\n", + " xlabel=r\"(p$_T^{\\mu}$, $\\eta^{\\mu}$) bin\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.99, 1.01],\n", + " baseline=True,\n", + " )" ] }, { @@ -993,7 +1066,9 @@ "metadata": {}, "outputs": [], "source": [ - "f = uproot.open(\"/home/submit/kdlong/work/WRemnants/CombineStudies/ZMassDilepton_ptVgen/ZMassDileptonCombineInput.root\")" + "f = uproot.open(\n", + " \"/home/submit/kdlong/work/WRemnants/CombineStudies/ZMassDilepton_ptVgen/ZMassDileptonCombineInput.root\"\n", + ")" ] }, { @@ -1110,24 +1185,24 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " f[\"Zmumu/nominal_gen_Zmumu_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFDown_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFUp_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRDown_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRUp_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muFDown_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muFUp_inclusive\"].to_hist(),\n", - " ],\n", - " [\"nominal\", 'muRmuF', \"\", \"muR\", \"\", \"muF\", \"\"],\n", - " colors=['black', 'red', \"red\", \"green\", \"green\", \"orange\", \"orange\"], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.95, 1.05],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)\n", - "\n" + " [\n", + " f[\"Zmumu/nominal_gen_Zmumu_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFDown_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFUp_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRDown_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRUp_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muFDown_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muFUp_inclusive\"].to_hist(),\n", + " ],\n", + " [\"nominal\", \"muRmuF\", \"\", \"muR\", \"\", \"muF\", \"\"],\n", + " colors=[\"black\", \"red\", \"red\", \"green\", \"green\", \"orange\", \"orange\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.95, 1.05],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")" ] }, { @@ -1151,22 +1226,22 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " f[\"Zmumu/nominal_gen_Zmumu_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFDown_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFUp_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRDown_inclusive\"].to_hist(),\n", - " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRUp_inclusive\"].to_hist(),\n", - " ],\n", - " [\"nominal\", 'muRmuF', \"\", \"muR\", \"\"],\n", - " colors=['black', 'red', \"red\", \"blue\", \"blue\"], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.95, 1.05],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)\n", - "\n" + " [\n", + " f[\"Zmumu/nominal_gen_Zmumu_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFDown_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRmuFUp_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRDown_inclusive\"].to_hist(),\n", + " f[\"Zmumu/nominal_gen_Zmumu_QCDscaleZMiNNLO_muRUp_inclusive\"].to_hist(),\n", + " ],\n", + " [\"nominal\", \"muRmuF\", \"\", \"muR\", \"\"],\n", + " colors=[\"black\", \"red\", \"red\", \"blue\", \"blue\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.95, 1.05],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")" ] }, { @@ -1200,7 +1275,9 @@ "metadata": {}, "outputs": [], "source": [ - "hsyst = syst_tools.scale_helicity_hist_to_variations(hnew, sum_axes=[\"y\", \"helicity\", \"massVgen\"], gen_axes=[\"pt\", \"chargeVgen\"])" + "hsyst = syst_tools.scale_helicity_hist_to_variations(\n", + " hnew, sum_axes=[\"y\", \"helicity\", \"massVgen\"], gen_axes=[\"pt\", \"chargeVgen\"]\n", + ")" ] }, { @@ -1266,7 +1343,7 @@ } ], "source": [ - "hsyst[{\"pt\" : 1, \"muRfact\" : 1.j, \"muFfact\" : 1.j, \"chargeVgen\" : 0}]" + "hsyst[{\"pt\": 1, \"muRfact\": 1.0j, \"muFfact\": 1.0j, \"chargeVgen\": 0}]" ] }, { @@ -1288,19 +1365,20 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [\n", - " hsyst[{\"muRfact\" : 1.j, \"muFfact\" : 1.j, \"chargeVgen\" : 0, \"pt\" : 0}],\n", - " hsyst[{\"muRfact\" : 2.j, \"muFfact\" : 1.j, \"chargeVgen\" : 0, \"pt\" : 1}],\n", - " hsyst[{\"muRfact\" : 0.5j, \"muFfact\" : 1.j, \"chargeVgen\" : 0, \"pt\" : 10}],\n", - " ], \n", - " [\"UL\", 'A0', \"bin3\"], \n", - " colors=['red', \"purple\", \"green\"], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.9, 1.1],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)" + " [\n", + " hsyst[{\"muRfact\": 1.0j, \"muFfact\": 1.0j, \"chargeVgen\": 0, \"pt\": 0}],\n", + " hsyst[{\"muRfact\": 2.0j, \"muFfact\": 1.0j, \"chargeVgen\": 0, \"pt\": 1}],\n", + " hsyst[{\"muRfact\": 0.5j, \"muFfact\": 1.0j, \"chargeVgen\": 0, \"pt\": 10}],\n", + " ],\n", + " [\"UL\", \"A0\", \"bin3\"],\n", + " colors=[\"red\", \"purple\", \"green\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.9, 1.1],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")" ] }, { @@ -1336,23 +1414,38 @@ " if rebin is not None:\n", " minnlo = hh.rebinHist(minnlo, obs, rebin)\n", " nnlops = hh.rebinHist(nnlops, obs, rebin)\n", - " \n", - " minnlo_coeffs = theory_tools.moments_to_angular_coeffs(minnlo.project(obs, \"helicity\"))\n", + "\n", + " minnlo_coeffs = theory_tools.moments_to_angular_coeffs(\n", + " minnlo.project(obs, \"helicity\")\n", + " )\n", "\n", " for i in range(8):\n", - " nnlops_coeffs = theory_tools.moments_to_angular_coeffs(nnlops.project(obs, \"helicity\"))\n", + " nnlops_coeffs = theory_tools.moments_to_angular_coeffs(\n", + " nnlops.project(obs, \"helicity\")\n", + " )\n", "\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnlo_coeffs[{\"helicity\" : complex(i)}], \n", - " nnlops_coeffs[{\"helicity\" : complex(i)}]], \n", - " [\"MiNNLO\", 'NNLOPS',], \n", - " colors=['orange', 'red',], \n", - " xlabel=label, \n", - " ylabel=f\"A$_{i}$\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.5, 1.5],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [\n", + " minnlo_coeffs[{\"helicity\": complex(i)}],\n", + " nnlops_coeffs[{\"helicity\": complex(i)}],\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"NNLOPS\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"red\",\n", + " ],\n", + " xlabel=label,\n", + " ylabel=f\"A$_{i}$\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.5, 1.5],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", " name = f\"A{i}_{obs}_MiNNLO_NNLOPS\"\n", " plot_tools.save_pdf_and_png(out, name)\n", " plot_tools.write_index_and_log(out, name)" @@ -1368,23 +1461,41 @@ "def plotAllCoeffsDYTurbo(obs, minnlo, dyturbof, rebin, label, out):\n", " if rebin is not None:\n", " minnlo = hh.rebinHist(minnlo, obs, rebin)\n", - " \n", - " minnlo_coeffs = theory_tools.moments_to_angular_coeffs(minnlo.project(obs, \"helicity\"))\n", + "\n", + " minnlo_coeffs = theory_tools.moments_to_angular_coeffs(\n", + " minnlo.project(obs, \"helicity\")\n", + " )\n", "\n", " for i in range(8):\n", - " dyturbo = dyturbo_coeff(dyturbof, f\"a{i}\", obs if obs != \"ptVgen\" else \"qt\", binning=minnlo_coeffs.axes[obs].edges)\n", + " dyturbo = dyturbo_coeff(\n", + " dyturbof,\n", + " f\"a{i}\",\n", + " obs if obs != \"ptVgen\" else \"qt\",\n", + " binning=minnlo_coeffs.axes[obs].edges,\n", + " )\n", "\n", " fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnlo_coeffs[{\"helicity\" : complex(i)}], \n", - " dyturbo*(-1. if i in [1,4,6] else 1.)], \n", - " [\"MiNNLO\", 'DYTurbo',], \n", - " colors=['orange', 'blue',], \n", - " xlabel=label, \n", - " ylabel=f\"A$_{i}$\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.5, 1.5],\n", - " yscale=1.2,\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [\n", + " minnlo_coeffs[{\"helicity\": complex(i)}],\n", + " dyturbo * (-1.0 if i in [1, 4, 6] else 1.0),\n", + " ],\n", + " [\n", + " \"MiNNLO\",\n", + " \"DYTurbo\",\n", + " ],\n", + " colors=[\n", + " \"orange\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=label,\n", + " ylabel=f\"A$_{i}$\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.5, 1.5],\n", + " yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + " )\n", " name = f\"A{i}_Wminus_{obs}_MiNNLO_DYTurbo\"\n", " plot_tools.save_pdf_and_png(out, name)\n", " plot_tools.write_index_and_log(out, name)" @@ -1440,10 +1551,14 @@ "metadata": {}, "outputs": [], "source": [ - "minnloZh = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")\n", - "#minloZh = input_tools.load_and_scale(res, \"ZmumuMiNLO\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"absYVgen\", \"massVgen\", \"helicity\")\n", - "#nnlopsZh = input_tools.load_and_scale(res, \"ZmumuNNLOPS\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"absYVgen\", \"massVgen\", \"helicity\")\n", - "minnloWh = input_tools.load_and_scale(res, \"WminusmunuPostVFP\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")" + "minnloZh = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"helicity_moments_scale\")[\n", + " {\"muRfact\": 1.0j, \"muFfact\": 1.0j}\n", + "].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")\n", + "# minloZh = input_tools.load_and_scale(res, \"ZmumuMiNLO\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"absYVgen\", \"massVgen\", \"helicity\")\n", + "# nnlopsZh = input_tools.load_and_scale(res, \"ZmumuNNLOPS\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"absYVgen\", \"massVgen\", \"helicity\")\n", + "minnloWh = input_tools.load_and_scale(\n", + " res, \"WminusmunuPostVFP\", \"helicity_moments_scale\"\n", + ")[{\"muRfact\": 1.0j, \"muFfact\": 1.0j}].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")" ] }, { @@ -1461,12 +1576,21 @@ "metadata": {}, "outputs": [], "source": [ - "scetlib_sigma4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm_A4.npz\", flip_y_sign=True)\n", - "scetlib_sigmaul = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm.npz\")\n", - "scetlib_a4_pt = theory_corrections.make_angular_coeff(scetlib_sigma4.project(\"pt\"), scetlib_sigmaul.project(\"pt\"))\n", + "scetlib_sigma4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm_A4.npz\",\n", + " flip_y_sign=True,\n", + ")\n", + "scetlib_sigmaul = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Wminus/inclusive_Wm.npz\"\n", + ")\n", + "scetlib_a4_pt = theory_corrections.make_angular_coeff(\n", + " scetlib_sigma4.project(\"pt\"), scetlib_sigmaul.project(\"pt\")\n", + ")\n", "\n", "minnloWh = hh.rebinHist(minnloWh, \"y\", 5)\n", - "scetlib_a4_y = theory_corrections.make_angular_coeff(scetlib_sigma4.project(\"y\"), scetlib_sigmaul.project(\"y\"))" + "scetlib_a4_y = theory_corrections.make_angular_coeff(\n", + " scetlib_sigma4.project(\"y\"), scetlib_sigmaul.project(\"y\")\n", + ")" ] }, { @@ -1476,7 +1600,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnlo_coeffs_y = theory_tools.moments_to_angular_coeffs(minnloWh.project(\"y\", \"helicity\"))" + "minnlo_coeffs_y = theory_tools.moments_to_angular_coeffs(\n", + " minnloWh.project(\"y\", \"helicity\")\n", + ")" ] }, { @@ -1504,24 +1630,45 @@ } ], "source": [ - "scetlibhZ_tot = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\", charge=0)\n", - "scetlibhZ_A4 = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\", nonsing=None, flip_y_sign=True, charge=0)\n", - "scetlibhZ_tot, scetlibhZ_A4 = [hh.rebinHist(h, \"pt\", pt_binning[:-2]) for h in [scetlibhZ_tot, scetlibhZ_A4]]\n", + "scetlibhZ_tot = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/Z/inclusive_Z.npz\",\n", + " charge=0,\n", + ")\n", + "scetlibhZ_A4 = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/scetlib-cms/prod/scetlib_run/helicityTest/inclusive_Z_pT_A4.npz\",\n", + " nonsing=None,\n", + " flip_y_sign=True,\n", + " charge=0,\n", + ")\n", + "scetlibhZ_tot, scetlibhZ_A4 = [\n", + " hh.rebinHist(h, \"pt\", pt_binning[:-2]) for h in [scetlibhZ_tot, scetlibhZ_A4]\n", + "]\n", "\n", - "minnloZ_coeffs_pt = theory_tools.moments_to_angular_coeffs(hh.rebinHist(minnloZh.project(\"ptVgen\", \"helicity\"), \"ptVgen\", pt_binning))\n", - "nnlopsZ_coeffs_pt = theory_tools.moments_to_angular_coeffs(hh.rebinHist(nnlopsZh.project(\"ptVgen\", \"helicity\"), \"ptVgen\", pt_binning))\n", - "scetlibZ_a4_coeff = theory_corrections.make_angular_coeff(scetlibhZ_A4.project(\"pt\"), scetlibhZ_tot.project(\"pt\"))\n", + "minnloZ_coeffs_pt = theory_tools.moments_to_angular_coeffs(\n", + " hh.rebinHist(minnloZh.project(\"ptVgen\", \"helicity\"), \"ptVgen\", pt_binning)\n", + ")\n", + "nnlopsZ_coeffs_pt = theory_tools.moments_to_angular_coeffs(\n", + " hh.rebinHist(nnlopsZh.project(\"ptVgen\", \"helicity\"), \"ptVgen\", pt_binning)\n", + ")\n", + "scetlibZ_a4_coeff = theory_corrections.make_angular_coeff(\n", + " scetlibhZ_A4.project(\"pt\"), scetlibhZ_tot.project(\"pt\")\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnloZ_coeffs_pt[{\"helicity\" : 4.j}][:40.j], nnlops_coeffs_pt[{\"helicity\" : 4.j}][:40.j], scetlibZ_a4_coeff], \n", - " [\"MiNNLO\", 'NNLOPS', \"SCETlib\"], \n", - " colors=['orange', 'red', \"purple\"], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.1, 5],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)\n", + " [\n", + " minnloZ_coeffs_pt[{\"helicity\": 4.0j}][:40.0j],\n", + " nnlops_coeffs_pt[{\"helicity\": 4.0j}][:40.0j],\n", + " scetlibZ_a4_coeff,\n", + " ],\n", + " [\"MiNNLO\", \"NNLOPS\", \"SCETlib\"],\n", + " colors=[\"orange\", \"red\", \"purple\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.1, 5],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\"\n", "name = f\"A4_ptVgen_MiNNLO_NNLOPS_SCETlib\"\n", @@ -1550,22 +1697,36 @@ "s = hist.tag.Slicer()\n", "\n", "\n", - "\n", - "minnloZ_coeffs_y = theory_tools.moments_to_angular_coeffs(hh.rebinHist(minnloZh[{\"ptVgen\" : s[0:40.j:hist.sum]}].project(\"y\", \"helicity\"), \"y\", 20))\n", - "nnlopsZ_coeffs_y = theory_tools.moments_to_angular_coeffs(hh.rebinHist(nnlopsZh[{\"ptVgen\" : s[0:40.j:hist.sum]}].project(\"y\", \"helicity\"), \"y\", 20))\n", - "scetlibZ_y_a4_coeff = theory_corrections.make_angular_coeff(scetlibhZ_A4.project(\"y\"), scetlibhZ_tot.project(\"y\"))\n", + "minnloZ_coeffs_y = theory_tools.moments_to_angular_coeffs(\n", + " hh.rebinHist(\n", + " minnloZh[{\"ptVgen\": s[0 : 40.0j : hist.sum]}].project(\"y\", \"helicity\"), \"y\", 20\n", + " )\n", + ")\n", + "nnlopsZ_coeffs_y = theory_tools.moments_to_angular_coeffs(\n", + " hh.rebinHist(\n", + " nnlopsZh[{\"ptVgen\": s[0 : 40.0j : hist.sum]}].project(\"y\", \"helicity\"), \"y\", 20\n", + " )\n", + ")\n", + "scetlibZ_y_a4_coeff = theory_corrections.make_angular_coeff(\n", + " scetlibhZ_A4.project(\"y\"), scetlibhZ_tot.project(\"y\")\n", + ")\n", "\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnloZ_coeffs_y[{\"helicity\" : 4.j}], nnlopsZ_coeffs_y[{\"helicity\" : 4.j}], scetlibZ_y_a4_coeff], \n", - " [\"MiNNLO\", 'NNLOPS', \"SCETlib\"], \n", - " colors=['orange', 'red', \"purple\"], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.1, 5],\n", - " #ylim=[-0.8,-0.3],\n", - " baseline=True)\n", + " [\n", + " minnloZ_coeffs_y[{\"helicity\": 4.0j}],\n", + " nnlopsZ_coeffs_y[{\"helicity\": 4.0j}],\n", + " scetlibZ_y_a4_coeff,\n", + " ],\n", + " [\"MiNNLO\", \"NNLOPS\", \"SCETlib\"],\n", + " colors=[\"orange\", \"red\", \"purple\"],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.1, 5],\n", + " # ylim=[-0.8,-0.3],\n", + " baseline=True,\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\"\n", "name = f\"A4_y_MiNNLO_NNLOPS_SCETlib\"\n", @@ -1607,18 +1768,27 @@ } ], "source": [ - "minnlo_coeffs_pt = theory_tools.moments_to_angular_coeffs(minnloh.project(\"ptVgen\", \"helicity\"))\n", + "minnlo_coeffs_pt = theory_tools.moments_to_angular_coeffs(\n", + " minnloh.project(\"ptVgen\", \"helicity\")\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnlo_coeffs_pt[{\"helicity\" : 4.j}][:40.j], -1*dyturbo_a4_pt[:40.j], scetlib_a4_pt], \n", - " [\"MiNNLO\", 'DYTurbo', \"SCETlib\"], \n", - " colors=['orange', 'blue', \"purple\"], \n", - " xlabel=\"p$_{T}^{W^{-}}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.9, 1.1],\n", - " ylim=[-0.8,-0.3],\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [\n", + " minnlo_coeffs_pt[{\"helicity\": 4.0j}][:40.0j],\n", + " -1 * dyturbo_a4_pt[:40.0j],\n", + " scetlib_a4_pt,\n", + " ],\n", + " [\"MiNNLO\", \"DYTurbo\", \"SCETlib\"],\n", + " colors=[\"orange\", \"blue\", \"purple\"],\n", + " xlabel=\"p$_{T}^{W^{-}}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.9, 1.1],\n", + " ylim=[-0.8, -0.3],\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W\"\n", "name = f\"A4_ptVgen_MiNNLO_DYTurbo_SCETlib\"\n", @@ -1645,18 +1815,23 @@ ], "source": [ "s = hist.tag.Slicer()\n", - "minnlo_coeffs_y_lowpt = theory_tools.moments_to_angular_coeffs(minnloh[{\"ptVgen\" : s[0:40.j:hist.sum]}].project(\"y\", \"helicity\"))\n", + "minnlo_coeffs_y_lowpt = theory_tools.moments_to_angular_coeffs(\n", + " minnloh[{\"ptVgen\": s[0 : 40.0j : hist.sum]}].project(\"y\", \"helicity\")\n", + ")\n", "\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " [minnlo_coeffs_y[{\"helicity\" : 4.j}], -1*dyturbo_a4_y, scetlib_a4_y], \n", - " [\"MiNNLO\", 'DYTurbo', \"SCETlib\"], \n", - " colors=['orange', 'blue', \"purple\"], \n", - " xlabel=\"y$^{W^{-}}$ (GeV)\", \n", - " ylabel=\"A$_{4}$/bin\",\n", - " rlabel=\"x/minnlo\",\n", - " rrange=[0.8, 1.2],\n", - " ylim=[-4,1],\n", - " xlim=None, binwnorm=None, baseline=True)\n", + " [minnlo_coeffs_y[{\"helicity\": 4.0j}], -1 * dyturbo_a4_y, scetlib_a4_y],\n", + " [\"MiNNLO\", \"DYTurbo\", \"SCETlib\"],\n", + " colors=[\"orange\", \"blue\", \"purple\"],\n", + " xlabel=\"y$^{W^{-}}$ (GeV)\",\n", + " ylabel=\"A$_{4}$/bin\",\n", + " rlabel=\"x/minnlo\",\n", + " rrange=[0.8, 1.2],\n", + " ylim=[-4, 1],\n", + " xlim=None,\n", + " binwnorm=None,\n", + " baseline=True,\n", + ")\n", "\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W/AngularCoeffs\"\n", "name = f\"A4_y_MiNNLO_DYTurbo_SCETlib\"\n", @@ -1752,7 +1927,14 @@ } ], "source": [ - "plotAllCoeffs(\"y\", minnloZh[{\"massVgen\" : 90.j}], nnlopsZh[{\"massVgen\" : 90.j}], 5, \"y$^{Z}$\", out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\")" + "plotAllCoeffs(\n", + " \"y\",\n", + " minnloZh[{\"massVgen\": 90.0j}],\n", + " nnlopsZh[{\"massVgen\": 90.0j}],\n", + " 5,\n", + " \"y$^{Z}$\",\n", + " out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\",\n", + ")" ] }, { @@ -1843,7 +2025,14 @@ } ], "source": [ - "plotAllCoeffs(\"ptVgen\", minnloZh[{\"massVgen\" : 90.j}], nnlopsZh[{\"massVgen\" : 90.j}], rebin, \"p$_{T}^{Z}$\", out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\")\n" + "plotAllCoeffs(\n", + " \"ptVgen\",\n", + " minnloZh[{\"massVgen\": 90.0j}],\n", + " nnlopsZh[{\"massVgen\": 90.0j}],\n", + " rebin,\n", + " \"p$_{T}^{Z}$\",\n", + " out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z/AngularCoeffs\",\n", + ")" ] }, { @@ -1934,8 +2123,17 @@ } ], "source": [ - "binning = hh.findCommonBinning([dyturbof_y[\"wgt_a0_y\"].to_hist(), minnloWh.project(\"y\")], 0)[2:-2]\n", - "plotAllCoeffsDYTurbo(\"y\", minnloWh, dyturbof_y, binning, \"y$^{W^{-}}$\", out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W/AngularCoeffs\")" + "binning = hh.findCommonBinning(\n", + " [dyturbof_y[\"wgt_a0_y\"].to_hist(), minnloWh.project(\"y\")], 0\n", + ")[2:-2]\n", + "plotAllCoeffsDYTurbo(\n", + " \"y\",\n", + " minnloWh,\n", + " dyturbof_y,\n", + " binning,\n", + " \"y$^{W^{-}}$\",\n", + " out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W/AngularCoeffs\",\n", + ")" ] }, { @@ -2026,7 +2224,14 @@ } ], "source": [ - "plotAllCoeffsDYTurbo(\"ptVgen\", minnloWh, dyturbof_pt, pt_binning, \"p$_{T}^{W^{-}}$\", out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W/AngularCoeffs\")" + "plotAllCoeffsDYTurbo(\n", + " \"ptVgen\",\n", + " minnloWh,\n", + " dyturbof_pt,\n", + " pt_binning,\n", + " \"p$_{T}^{W^{-}}$\",\n", + " out=\"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/W/AngularCoeffs\",\n", + ")" ] }, { @@ -2059,9 +2264,7 @@ "id": "aff32e25", "metadata": {}, "outputs": [], - "source": [ - " " - ] + "source": [] }, { "cell_type": "code", @@ -2113,7 +2316,10 @@ "minlo = input_tools.load_and_scale(res, \"ZmumuMiNLO\", \"nominal_gen\")\n", "nnlops = input_tools.load_and_scale(res, \"ZmumuNNLOPS\", \"nominal_gen\")\n", "minnlo = input_tools.load_and_scale(res, \"ZmumuPostVFP\", \"nominal_gen\")\n", - "matrix = input_tools.read_matrixRadish_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Zinclusive/run_matchMiNNLOEWParams/results/yZ__NNLO_QCD.dat\", \"y\")" + "matrix = input_tools.read_matrixRadish_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Zinclusive/run_matchMiNNLOEWParams/results/yZ__NNLO_QCD.dat\",\n", + " \"y\",\n", + ")" ] }, { @@ -2123,7 +2329,9 @@ "metadata": {}, "outputs": [], "source": [ - "minlo,nnlops,minnlo,matrix = hh.rebinHistsToCommon([minlo,nnlops,minnlo,matrix], \"y\")" + "minlo, nnlops, minnlo, matrix = hh.rebinHistsToCommon(\n", + " [minlo, nnlops, minnlo, matrix], \"y\"\n", + ")" ] }, { @@ -2145,17 +2353,31 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [x.project(\"y\")[hist.rebin(2)] for x in \n", - " [matrix[{\"vars\" : 0}], minnlo, minlo, nnlops]\n", - " ],\n", - " [\"MATRIX\", \"MiNNLO\", \"MiNLO\", 'NNLOPS',], \n", - " colors=[\"green\", \"orange\", 'red', 'blue',], \n", - " xlabel=\"y$^{Z}$\", \n", - " ylabel=f\"$\\sigma$/bin\",\n", - " rlabel=\"x/MATRIX\",\n", - " rrange=[0.8, 1.2],\n", - " ylim=[0,380],\n", - " xlim=None, binwnorm=1.0, baseline=True)\n", + " [\n", + " x.project(\"y\")[hist.rebin(2)]\n", + " for x in [matrix[{\"vars\": 0}], minnlo, minlo, nnlops]\n", + " ],\n", + " [\n", + " \"MATRIX\",\n", + " \"MiNNLO\",\n", + " \"MiNLO\",\n", + " \"NNLOPS\",\n", + " ],\n", + " colors=[\n", + " \"green\",\n", + " \"orange\",\n", + " \"red\",\n", + " \"blue\",\n", + " ],\n", + " xlabel=\"y$^{Z}$\",\n", + " ylabel=f\"$\\sigma$/bin\",\n", + " rlabel=\"x/MATRIX\",\n", + " rrange=[0.8, 1.2],\n", + " ylim=[0, 380],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")\n", "out = \"/home/k/kelong/www/WMassAnalysis/TheoryComparisons/Z\"\n", "plot_tools.make_plot_dir(out, \"NNPDF31\")\n", "out = os.path.join(out, \"NNPDF31\")\n", @@ -2251,8 +2473,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWh_msht = input_tools.load_and_scale(res_msht, \"WminusmunuPostVFP\", \"helicity_moments_scale\")[{\"muRfact\" : 1.j, \"muFfact\" : 1.j}].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")\n", - "\n" + "minnloWh_msht = input_tools.load_and_scale(\n", + " res_msht, \"WminusmunuPostVFP\", \"helicity_moments_scale\"\n", + ")[{\"muRfact\": 1.0j, \"muFfact\": 1.0j}].project(\"ptVgen\", \"y\", \"massVgen\", \"helicity\")" ] }, { @@ -2263,8 +2486,13 @@ "outputs": [], "source": [ "minnloWh_nnpdf = input_tools.load_and_scale(res, \"WminusmunuPostVFP\", \"nominal_gen\")\n", - "matrixWm_y = input_tools.read_matrixRadish_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Winclusive/yW__NNLO_QCD.dat\", \"y\")\n", - "dyturboWm_y = input_tools.read_dyturbo_file(\"/home/k/kelong/results_wminus_nnlo_yw.txt\", \"y\")" + "matrixWm_y = input_tools.read_matrixRadish_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/MATRIX_RadISH/Winclusive/yW__NNLO_QCD.dat\",\n", + " \"y\",\n", + ")\n", + "dyturboWm_y = input_tools.read_dyturbo_file(\n", + " \"/home/k/kelong/results_wminus_nnlo_yw.txt\", \"y\"\n", + ")" ] }, { @@ -2274,7 +2502,10 @@ "metadata": {}, "outputs": [], "source": [ - "binning = hh.findCommonBinning([minnloWh_nnpdf.project(\"y\")[hist.rebin(5)], matrixWm_y[{\"vars\" : 0}], dyturboWm_y], 0)" + "binning = hh.findCommonBinning(\n", + " [minnloWh_nnpdf.project(\"y\")[hist.rebin(5)], matrixWm_y[{\"vars\": 0}], dyturboWm_y],\n", + " 0,\n", + ")" ] }, { @@ -2308,7 +2539,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloWm_y, matrixWm_y, dyturboWm_y = hh.rebinHistsToCommon([minnloWh_nnpdf.project(\"y\"), matrixWm_y[{\"vars\" : 0}], dyturboWm_y], 0)" + "minnloWm_y, matrixWm_y, dyturboWm_y = hh.rebinHistsToCommon(\n", + " [minnloWh_nnpdf.project(\"y\"), matrixWm_y[{\"vars\": 0}], dyturboWm_y], 0\n", + ")" ] }, { @@ -2329,16 +2562,19 @@ } ], "source": [ - " fig = plot_tools.makePlotWithRatioToRef(\n", - " [matrixWm_y, minnloWm_y, dyturboWm_y],\n", - " [\"MATRIX\", \"MiNNLO\", \"DYTurbo\"], \n", - " colors=['green', 'orange', 'blue'], \n", - " xlabel=\"y$^{W^{-}}$\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/MATRIX\",\n", - " rrange=[0.95, 1.05],\n", - " yscale=1.1,\n", - " xlim=None, binwnorm=1.0, baseline=True)" + "fig = plot_tools.makePlotWithRatioToRef(\n", + " [matrixWm_y, minnloWm_y, dyturboWm_y],\n", + " [\"MATRIX\", \"MiNNLO\", \"DYTurbo\"],\n", + " colors=[\"green\", \"orange\", \"blue\"],\n", + " xlabel=\"y$^{W^{-}}$\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/MATRIX\",\n", + " rrange=[0.95, 1.05],\n", + " yscale=1.1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + ")" ] }, { @@ -2348,8 +2584,15 @@ "metadata": {}, "outputs": [], "source": [ - "def dyturbo_filenames(path, basename, varname, pieces=[\"n3ll_born\", \"n2ll_ct\", \"n2lo_vj\"], append=None):\n", - " return [os.path.join(path, \"_\".join(filter(None, [basename, piece, varname, append]))+\".txt\") for piece in pieces]" + "def dyturbo_filenames(\n", + " path, basename, varname, pieces=[\"n3ll_born\", \"n2ll_ct\", \"n2lo_vj\"], append=None\n", + "):\n", + " return [\n", + " os.path.join(\n", + " path, \"_\".join(filter(None, [basename, piece, varname, append])) + \".txt\"\n", + " )\n", + " for piece in pieces\n", + " ]" ] }, { @@ -2359,16 +2602,30 @@ "metadata": {}, "outputs": [], "source": [ - "def read_dyturbo_variations(path, basename, varnames, axes, pieces=[\"n3ll_born\", \"n2ll_ct\", \"n2lo_vj\"], append=None):\n", + "def read_dyturbo_variations(\n", + " path,\n", + " basename,\n", + " varnames,\n", + " axes,\n", + " pieces=[\"n3ll_born\", \"n2ll_ct\", \"n2lo_vj\"],\n", + " append=None,\n", + "):\n", " central_files = dyturbo_filenames(path, basename, \"\", pieces, append)\n", " centralh = input_tools.read_dyturbo_hist(central_files, axes=axes)\n", - " var_ax = hist.axis.Integer(0, len(varnames)+1, name=\"vars\")\n", + " var_ax = hist.axis.Integer(0, len(varnames) + 1, name=\"vars\")\n", " varh = hist.Hist(*centralh.axes, var_ax, storage=centralh._storage_type())\n", - " varh[...,0] = centralh.view(flow=True)\n", - " for i,var in enumerate(varnames):\n", - " filenames = [os.path.join(path, \"_\".join(filter(None, [basename, piece, var, append]))+\".txt\") for piece in pieces]\n", - " varh[...,i+1] = input_tools.read_dyturbo_hist(filenames, axes=axes).view(flow=True)\n", - " return varh " + " varh[..., 0] = centralh.view(flow=True)\n", + " for i, var in enumerate(varnames):\n", + " filenames = [\n", + " os.path.join(\n", + " path, \"_\".join(filter(None, [basename, piece, var, append])) + \".txt\"\n", + " )\n", + " for piece in pieces\n", + " ]\n", + " varh[..., i + 1] = input_tools.read_dyturbo_hist(filenames, axes=axes).view(\n", + " flow=True\n", + " )\n", + " return varh" ] }, { @@ -2412,7 +2669,14 @@ "metadata": {}, "outputs": [], "source": [ - "varh = input_tools.read_dyturbo_variations(\"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31\", \"results\", varnames, axes=[\"pt\",])" + "varh = input_tools.read_dyturbo_variations(\n", + " \"/scratch/shared/TheoryPredictions/DYTurbo/Z/nnpdf31\",\n", + " \"results\",\n", + " varnames,\n", + " axes=[\n", + " \"pt\",\n", + " ],\n", + ")" ] }, { @@ -2448,23 +2712,55 @@ } ], "source": [ - "hists = [varh[{\"vars\" : 0}], *itertools.chain(*[(varh[{\"vars\" : i}], varh[{\"vars\" : 15-i}]) for i in range(1, 8)])]\n", - "fig = plot_tools.makePlotWithRatioToRef(hists[:-2],\n", - " [\"Nominal\", \n", - " \"$\\mu_{F}, \\mu_{R}, \\mu_{res} \\in [0.5, 2.]\\mu$\", \"\", \n", - " \"$\\mu_{F}, \\mu_{R} \\in [0.5, 2.]\\mu$\", \"\",\n", - " \"$\\mu_{R}, \\mu_{res} \\in [0.5, 2.]\\mu$\", \"\", \n", - " \"$\\mu_{F}, \\mu_{res} \\in [0.5, 2.]\\mu$\", \"\", \n", - " \"$\\mu_{R} \\in [0.5, 2.]\\mu$\", \"\", \n", - " \"$\\mu_{F} \\in [0.5, 2.]\\mu$\", \"\",\n", - " ],#\"$\\mu_{res} \\in [0.5, 2.]\\mu$\", \"\",],\n", - " colors=['black', 'lightgreen', 'lightgreen', \"darkblue\", \"darkblue\", \"lightblue\", \"lightblue\", \"darkred\", \"darkred\",\n", - " \"pink\", \"pink\", \"red\", \"red\", \"grey\", \"grey\"][:-2], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " xlim=None, binwnorm=1.0, baseline=True, fill_between=True)" + "hists = [\n", + " varh[{\"vars\": 0}],\n", + " *itertools.chain(\n", + " *[(varh[{\"vars\": i}], varh[{\"vars\": 15 - i}]) for i in range(1, 8)]\n", + " ),\n", + "]\n", + "fig = plot_tools.makePlotWithRatioToRef(\n", + " hists[:-2],\n", + " [\n", + " \"Nominal\",\n", + " \"$\\mu_{F}, \\mu_{R}, \\mu_{res} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " \"$\\mu_{F}, \\mu_{R} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " \"$\\mu_{R}, \\mu_{res} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " \"$\\mu_{F}, \\mu_{res} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " \"$\\mu_{R} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " \"$\\mu_{F} \\in [0.5, 2.]\\mu$\",\n", + " \"\",\n", + " ], # \"$\\mu_{res} \\in [0.5, 2.]\\mu$\", \"\",],\n", + " colors=[\n", + " \"black\",\n", + " \"lightgreen\",\n", + " \"lightgreen\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"lightblue\",\n", + " \"lightblue\",\n", + " \"darkred\",\n", + " \"darkred\",\n", + " \"pink\",\n", + " \"pink\",\n", + " \"red\",\n", + " \"red\",\n", + " \"grey\",\n", + " \"grey\",\n", + " ][:-2],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " fill_between=True,\n", + ")" ] }, { @@ -2482,8 +2778,10 @@ "metadata": {}, "outputs": [], "source": [ - "scetlibh = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Z/inclusive_Z_MSHT20.pkl\")\n", - "#scetlibh = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Z/inclusive_Z.pkl\")" + "scetlibh = input_tools.read_scetlib_hist(\n", + " \"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Z/inclusive_Z_MSHT20.pkl\"\n", + ")\n", + "# scetlibh = input_tools.read_scetlib_hist(\"/home/k/kelong/work/Generators/TheoryCorrections/SCETlib/Z/inclusive_Z.pkl\")" ] }, { @@ -2523,24 +2821,48 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [scetlib_pt[{\"vars\" : 0}], \n", - " t[\"resumScaleMax\"][\"action\"](scetlib_pt), t[\"resumScaleMin\"][\"action\"](scetlib_pt),\n", - " t[\"resumFOScaleUp\"][\"action\"](scetlib_pt), t[\"resumFOScaleDown\"][\"action\"](scetlib_pt),\n", - " t[\"resumLambdaUp\"][\"action\"](scetlib_pt), t[\"resumLambdaDown\"][\"action\"](scetlib_pt),\n", - " t[\"resumFOScaleUp\"][\"action\"](scetlib_pt), t[\"resumFOScaleDown\"][\"action\"](scetlib_pt),\n", - " ],\n", - " [\"Nominal\", \n", - " \"$\\mu_{res}$\", \"\", \n", - " \"$\\mu_{R,res}$\", \"\",\n", - " \"$\\Lambda_{res}$\", \"\",\n", - " \"transition\", \"\",\n", - " ],\n", - " colors=['black', 'steelblue', 'steelblue', 'crimson', 'crimson', 'forestgreen', 'forestgreen', 'tan', 'tan'], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " xlim=None, binwnorm=1.0, baseline=True, fill_between=True)" + " [\n", + " scetlib_pt[{\"vars\": 0}],\n", + " t[\"resumScaleMax\"][\"action\"](scetlib_pt),\n", + " t[\"resumScaleMin\"][\"action\"](scetlib_pt),\n", + " t[\"resumFOScaleUp\"][\"action\"](scetlib_pt),\n", + " t[\"resumFOScaleDown\"][\"action\"](scetlib_pt),\n", + " t[\"resumLambdaUp\"][\"action\"](scetlib_pt),\n", + " t[\"resumLambdaDown\"][\"action\"](scetlib_pt),\n", + " t[\"resumFOScaleUp\"][\"action\"](scetlib_pt),\n", + " t[\"resumFOScaleDown\"][\"action\"](scetlib_pt),\n", + " ],\n", + " [\n", + " \"Nominal\",\n", + " \"$\\mu_{res}$\",\n", + " \"\",\n", + " \"$\\mu_{R,res}$\",\n", + " \"\",\n", + " \"$\\Lambda_{res}$\",\n", + " \"\",\n", + " \"transition\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"steelblue\",\n", + " \"steelblue\",\n", + " \"crimson\",\n", + " \"crimson\",\n", + " \"forestgreen\",\n", + " \"forestgreen\",\n", + " \"tan\",\n", + " \"tan\",\n", + " ],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " fill_between=True,\n", + ")" ] }, { @@ -2576,7 +2898,9 @@ "metadata": {}, "outputs": [], "source": [ - "minnloW_rebin = hh.rebinHist(hh.makeAbsHist(minnloWh, \"y\"), \"ptVgen\", common.ptV_binning)[{\"absy\" : hist.rebin(8)}]" + "minnloW_rebin = hh.rebinHist(\n", + " hh.makeAbsHist(minnloWh, \"y\"), \"ptVgen\", common.ptV_binning\n", + ")[{\"absy\": hist.rebin(8)}]" ] }, { @@ -2610,7 +2934,16 @@ "metadata": {}, "outputs": [], "source": [ - "unrolledWms = [sel.unrolledHist(minnloW_rebin[{\"helicity\" : i}], (\"ptVgen\", \"absy\", )) for i in range(9)]" + "unrolledWms = [\n", + " sel.unrolledHist(\n", + " minnloW_rebin[{\"helicity\": i}],\n", + " (\n", + " \"ptVgen\",\n", + " \"absy\",\n", + " ),\n", + " )\n", + " for i in range(9)\n", + "]" ] }, { @@ -2655,14 +2988,28 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " unrolledWms,\n", - " [f\"$\\sigma_{{{i-1}}}$\" for i in range(9)],\n", - " colors=['black', 'steelblue', 'green', 'crimson', 'gold', 'forestgreen', 'pink', 'tan', 'grey'], \n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[-1, 1],\n", - " xlim=None, binwnorm=1.0, baseline=True, fill_between=False)" + " unrolledWms,\n", + " [f\"$\\sigma_{{{i-1}}}$\" for i in range(9)],\n", + " colors=[\n", + " \"black\",\n", + " \"steelblue\",\n", + " \"green\",\n", + " \"crimson\",\n", + " \"gold\",\n", + " \"forestgreen\",\n", + " \"pink\",\n", + " \"tan\",\n", + " \"grey\",\n", + " ],\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[-1, 1],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " fill_between=False,\n", + ")" ] }, { @@ -2778,17 +3125,22 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " [f[\"x_Zmumu_minus\"].to_hist(),\n", - " f[\"x_Zmumu_massShift100MeVDown_minus\"].to_hist(),\n", - " f[\"x_Zmumu_massShift100MeVUp_minus\"].to_hist(),\n", - " ],\n", - " [\"nominal\", \"$\\pm 100$ MeV\", \"\"],\n", - " colors=['black', 'green', 'green'], \n", - " xlabel=\"m$_{Z}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=\"x/nominal\",\n", - " rrange=[0.9, 1.1],\n", - " xlim=None, binwnorm=1.0, baseline=True, fill_between=False)" + " [\n", + " f[\"x_Zmumu_minus\"].to_hist(),\n", + " f[\"x_Zmumu_massShift100MeVDown_minus\"].to_hist(),\n", + " f[\"x_Zmumu_massShift100MeVUp_minus\"].to_hist(),\n", + " ],\n", + " [\"nominal\", \"$\\pm 100$ MeV\", \"\"],\n", + " colors=[\"black\", \"green\", \"green\"],\n", + " xlabel=\"m$_{Z}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=\"x/nominal\",\n", + " rrange=[0.9, 1.1],\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " fill_between=False,\n", + ")" ] } ], diff --git a/notebooks/unblindedPostfitGen.ipynb b/notebooks/unblindedPostfitGen.ipynb index cc025648a..ad4584b1d 100644 --- a/notebooks/unblindedPostfitGen.ipynb +++ b/notebooks/unblindedPostfitGen.ipynb @@ -8,7 +8,12 @@ "outputs": [], "source": [ "import uproot\n", - "from utilities.io_tools import input_tools,combinetf2_input,combinetf_input,output_tools\n", + "from utilities.io_tools import (\n", + " input_tools,\n", + " combinetf2_input,\n", + " combinetf_input,\n", + " output_tools,\n", + ")\n", "from wums import boostHistHelpers as hh\n", "from wremnants import histselections as sel\n", "from wremnants import plot_tools\n", @@ -52,7 +57,12 @@ "metadata": {}, "outputs": [], "source": [ - "unfolding_inc_data = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_Data//results_unfolded.pkl\", \"rb\"))" + "unfolding_inc_data = pickle.load(\n", + " open(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_Data//results_unfolded.pkl\",\n", + " \"rb\",\n", + " )\n", + ")" ] }, { @@ -83,10 +93,12 @@ "metadata": {}, "outputs": [], "source": [ - "#unfolding_inc_data = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_UnblindedData//results_unfolded.pkl\", \"rb\"))\n", - "unfolding_inch = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", - "#unfolding_inc_datah = unfolding_inc_data[\"results\"][\"sumpois\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", - "#unfolding_inc_datah = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]" + "# unfolding_inc_data = pickle.load(open(\"/scratch/submit/cms/kdlong/CombineStudies/Unfolding/ZMassDilepton_ptll_yll_UnblindedData//results_unfolded.pkl\", \"rb\"))\n", + "unfolding_inch = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\n", + " \"hist_ptVGen\"\n", + "]\n", + "# unfolding_inc_datah = unfolding_inc_data[\"results\"][\"sumpois\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]\n", + "# unfolding_inc_datah = unfolding_inc_data[\"results\"][\"pmaskedexp\"][\"chan_13TeV\"][\"Z\"][\"hist_ptVGen\"]" ] }, { @@ -130,8 +142,12 @@ "metadata": {}, "outputs": [], "source": [ - "res_n3p0ll_wlikefit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/ZGen_ptVgen/ZGen_postfitFromUnblindedWlike.hdf5\")\n", - "res_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/ZGen_ptVgen/ZGen_postfitFromRecoPtll.hdf5\")" + "res_n3p0ll_wlikefit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/ZGen_ptVgen/ZGen_postfitFromUnblindedWlike.hdf5\"\n", + ")\n", + "res_n3p0ll_ptlldatafit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/ZGen_ptVgen/ZGen_postfitFromRecoPtll.hdf5\"\n", + ")" ] }, { @@ -141,7 +157,11 @@ "metadata": {}, "outputs": [], "source": [ - "gen_inc = input_tools.read_and_scale(\"/scratch/submit/cms/wmass/histmaker_output_Aug1_mZ_w_like_unblinding_ext/w_z_gen_dists_scetlib_dyturboCorr_maxFiles_m1_helicity.hdf5\", \"ZmumuPostVFP\", \"nominal_gen\").project(\"ptVgen\")[:100j]" + "gen_inc = input_tools.read_and_scale(\n", + " \"/scratch/submit/cms/wmass/histmaker_output_Aug1_mZ_w_like_unblinding_ext/w_z_gen_dists_scetlib_dyturboCorr_maxFiles_m1_helicity.hdf5\",\n", + " \"ZmumuPostVFP\",\n", + " \"nominal_gen\",\n", + ").project(\"ptVgen\")[:100j]" ] }, { @@ -151,8 +171,8 @@ "metadata": {}, "outputs": [], "source": [ - "#n3p0ll_wlikefith = hh.rebinHist(res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000.\n", - "#n3p0ll_ptlldatafith = hh.rebinHist(res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000." + "# n3p0ll_wlikefith = hh.rebinHist(res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000.\n", + "# n3p0ll_ptlldatafith = hh.rebinHist(res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get(), \"ptVgen\", unfolding_inc_datah.axes[\"ptVGen\"].edges)/1000." ] }, { @@ -162,8 +182,12 @@ "metadata": {}, "outputs": [], "source": [ - "n3p0ll_wlikefith = res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]/1000.\n", - "n3p0ll_ptlldatafith = res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]/1000." + "n3p0ll_wlikefith = (\n", + " res_n3p0ll_wlikefit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j] / 1000.0\n", + ")\n", + "n3p0ll_ptlldatafith = (\n", + " res_n3p0ll_ptlldatafit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j] / 1000.0\n", + ")" ] }, { @@ -206,7 +230,7 @@ "metadata": {}, "outputs": [], "source": [ - "#out = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded/\"\n", + "# out = \"/eos/user/k/kelong/www/WMassAnalysis/2024Aug_Unblinded/\"\n", "out = \"/eos/user/c/cmsmwbot/www/WMassAnalysis/PlotsForPaper/NaturePreCWR/\"" ] }, @@ -258,55 +282,59 @@ } ], "source": [ - "hists=[\n", - " n3p0ll_ptlldatafith,\n", - " n3p0ll_wlikefith,\n", - " gen_inc,\n", - " wlikeup,\n", - " wlikedown,\n", - " ptllup,\n", - " ptlldown,\n", + "hists = [\n", + " n3p0ll_ptlldatafith,\n", + " n3p0ll_wlikefith,\n", + " gen_inc,\n", + " wlikeup,\n", + " wlikedown,\n", + " ptllup,\n", + " ptlldown,\n", "]\n", "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=hists,\n", - " hists_ratio=hists,\n", - " midratio_idxs=[2,0,1],\n", - " labels=[\n", - " r\"$p_{T}^{\\ell\\ell}$ postfit\",\n", - " r\"W-like $m_{Z}$ postfit\",\n", - " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", - " \"\", \"\", \n", - " \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkred\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*3+[\"dashed\"]+[\"solid\"]*2,\n", - " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/GeV\",\n", - " rlabel=r\"pred./p$_{T}^{\\ell\\ell}$ fit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " legtext_size=24,\n", - " #yscale=1.2,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", - " cms_label=\"Preliminary\",\n", - " subplotsizes=[4,1,1],\n", + " hists=hists,\n", + " hists_ratio=hists,\n", + " midratio_idxs=[2, 0, 1],\n", + " labels=[\n", + " r\"$p_{T}^{\\ell\\ell}$ postfit\",\n", + " r\"W-like $m_{Z}$ postfit\",\n", + " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkred\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 3 + [\"dashed\"] + [\"solid\"] * 2,\n", + " xlabel=\"p$_{T}^{\\ell\\ell}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/GeV\",\n", + " rlabel=r\"pred./p$_{T}^{\\ell\\ell}$ fit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " legtext_size=24,\n", + " # yscale=1.2,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", + " cms_label=\"Preliminary\",\n", + " subplotsizes=[4, 1, 1],\n", ")\n", "\n", - "#outdir = output_tools.make_plot_dir(out, \"Z\", eoscp=True)\n", - "#name = \"ptVgen_postfit_Wlike_RecoPtll_PtllRatio\"\n", - "#plot_tools.save_pdf_and_png(outdir, name)\n", - "#plot_tools.write_index_and_log(outdir, name)\n", - "#output_tools.copy_to_eos(outdir, out, \"Z\", deleteFullTmp=True)" + "# outdir = output_tools.make_plot_dir(out, \"Z\", eoscp=True)\n", + "# name = \"ptVgen_postfit_Wlike_RecoPtll_PtllRatio\"\n", + "# plot_tools.save_pdf_and_png(outdir, name)\n", + "# plot_tools.write_index_and_log(outdir, name)\n", + "# output_tools.copy_to_eos(outdir, out, \"Z\", deleteFullTmp=True)" ] }, { @@ -352,10 +380,10 @@ " hists[0],\n", " \"testx\",\n", " \"testy\",\n", - " [0,10],\n", + " [0, 10],\n", " \"ratio\",\n", " [0.5, 1.5],\n", - " subplotsizes=[4,1,1],\n", + " subplotsizes=[4, 1, 1],\n", ")" ] }, @@ -385,47 +413,58 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[:54j] for x in [\n", - " gen_inc,\n", - " n3p0ll_ptlldatafith,\n", - " n3p0ll_wlikefith,\n", - " unfolding_inch,\n", - " wlikeup,\n", - " wlikedown,\n", - " ptllup,\n", - " ptlldown,\n", - " ]],\n", - " labels=[\n", - " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", - " r\"$p_{T}^{\\ell\\ell}$ postfit\",\n", - " r\"W-like $m_{Z}$ postfit\",\n", - " \"Unfolded data\",\n", - " \"\", \"\", \n", - " \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"black\",\n", - " \"#5790FC\",\n", - " \"#964A8B\",\n", - " \"black\",\n", - " \"#964A8B\",\n", - " \"#964A8B\",\n", - " \"#5790FC\",\n", - " \"#5790FC\",\n", - " ],\n", - " linestyles=[\"solid\",]*3+[\"dashed\"]*4,\n", - " xlabel=\"p$_{T}^{Z}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"postfit/prefit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " legtext_size=22,\n", - " yscale=1.3,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", - " cms_label=\" \",\n", - " dataIdx=3,\n", + " hists=[\n", + " x[:54j]\n", + " for x in [\n", + " gen_inc,\n", + " n3p0ll_ptlldatafith,\n", + " n3p0ll_wlikefith,\n", + " unfolding_inch,\n", + " wlikeup,\n", + " wlikedown,\n", + " ptllup,\n", + " ptlldown,\n", + " ]\n", + " ],\n", + " labels=[\n", + " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", + " r\"$p_{T}^{\\ell\\ell}$ postfit\",\n", + " r\"W-like $m_{Z}$ postfit\",\n", + " \"Unfolded data\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"#5790FC\",\n", + " \"#964A8B\",\n", + " \"black\",\n", + " \"#964A8B\",\n", + " \"#964A8B\",\n", + " \"#5790FC\",\n", + " \"#5790FC\",\n", + " ],\n", + " linestyles=[\n", + " \"solid\",\n", + " ]\n", + " * 3\n", + " + [\"dashed\"] * 4,\n", + " xlabel=\"p$_{T}^{Z}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"postfit/prefit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " legtext_size=22,\n", + " yscale=1.3,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", + " cms_label=\" \",\n", + " dataIdx=3,\n", ")\n", "outdir = output_tools.make_plot_dir(out, \"Z\", eoscp=True)\n", "name = \"ptVgen_postfit_Wlike_RecoPtll_PrefitRatio\"\n", @@ -441,7 +480,11 @@ "metadata": {}, "outputs": [], "source": [ - "gen_inc_w = input_tools.read_all_and_scale(\"/scratch/submit/cms/wmass/histmaker_output_Aug19_fe51c5b/w_z_gen_dists_scetlib_dyturboCorr_maxFiles_m1_helicity_theorynom.hdf5\", [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"], [\"nominal_gen\"])[0].project(\"ptVgen\")[:100j]\n" + "gen_inc_w = input_tools.read_all_and_scale(\n", + " \"/scratch/submit/cms/wmass/histmaker_output_Aug19_fe51c5b/w_z_gen_dists_scetlib_dyturboCorr_maxFiles_m1_helicity_theorynom.hdf5\",\n", + " [\"WminusmunuPostVFP\", \"WplusmunuPostVFP\"],\n", + " [\"nominal_gen\"],\n", + ")[0].project(\"ptVgen\")[:100j]" ] }, { @@ -451,8 +494,12 @@ "metadata": {}, "outputs": [], "source": [ - "mwfit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/WGen_ptVgen/WGen_postfitFromUnblindedReco.hdf5\")\n", - "ptllcombfit = combinetf2_input.get_fitresult(\"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/WGen_ptVgen/WGen_postfitFromUnblindedPtllComb.hdf5\")" + "mwfit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/WGen_ptVgen/WGen_postfitFromUnblindedReco.hdf5\"\n", + ")\n", + "ptllcombfit = combinetf2_input.get_fitresult(\n", + " \"/scratch/submit/cms/kdlong/CombineStudies/Unblinded/WGen_ptVgen/WGen_postfitFromUnblindedPtllComb.hdf5\"\n", + ")" ] }, { @@ -472,8 +519,8 @@ "metadata": {}, "outputs": [], "source": [ - "mwfith = mwfit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]/1000.\n", - "ptllcombfith = ptllcombfit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j]/1000." + "mwfith = mwfit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j] / 1000.0\n", + "ptllcombfith = ptllcombfit[\"hist_postfit_inclusive\"][\"ch0\"].get()[:100j] / 1000.0" ] }, { @@ -523,42 +570,49 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[x[:54j] for x in [\n", - " gen_inc_w,\n", - " mwfith,\n", - " ptllcombfith,\n", - " mwup,\n", - " mwdown,\n", - " ptllcombup,\n", - " ptllcombdown,\n", - " ]],\n", - " labels=[\n", - " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", - " r\"Combined W$+(p_{T}^{\\ell\\ell}, y^{\\ell\\ell})$ postfit\",\n", - " r\"W-only postfit\",\n", - " \"\", \"\", \n", - " \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"black\",\n", - " \"#5790FC\",\n", - " \"#E42536\",\n", - " \"#5790FC\",\n", - " \"#5790FC\",\n", - " \"#E42536\",\n", - " \"#E42536\",\n", - " ],\n", - " linestyles=[\"solid\"]*3+[\"dashed\"]*4,\n", - " xlabel=\"p$_{T}^{W}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"postfit/prefit\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", - " cms_label=' ',\n", - " yscale=1.2,\n", + " hists=[\n", + " x[:54j]\n", + " for x in [\n", + " gen_inc_w,\n", + " mwfith,\n", + " ptllcombfith,\n", + " mwup,\n", + " mwdown,\n", + " ptllcombup,\n", + " ptllcombdown,\n", + " ]\n", + " ],\n", + " labels=[\n", + " r\"SCETlib+DYTurbo N$^{3}LL+NNLO$ (prefit)\",\n", + " r\"Combined W$+(p_{T}^{\\ell\\ell}, y^{\\ell\\ell})$ postfit\",\n", + " r\"W-only postfit\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"black\",\n", + " \"#5790FC\",\n", + " \"#E42536\",\n", + " \"#5790FC\",\n", + " \"#5790FC\",\n", + " \"#E42536\",\n", + " \"#E42536\",\n", + " ],\n", + " linestyles=[\"solid\"] * 3 + [\"dashed\"] * 4,\n", + " xlabel=\"p$_{T}^{W}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"postfit/prefit\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", + " cms_label=\" \",\n", + " yscale=1.2,\n", ")\n", "outdir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "name = \"ptVgen_postfit_RecoPtll_PrefitRatio\"\n", @@ -587,42 +641,46 @@ ], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " mwfith,\n", - " ptllcombfith,\n", - " gen_inc_w,\n", - " mwup,\n", - " mwdown,\n", - " ptllcombup,\n", - " ptllcombdown,\n", - " ],\n", - " labels=[\n", - " r\"$p_{T}^{W}$ postfit\",\n", - " r\"$p_{T}^{W}$ postfit, $p_{T}^{\\ell\\ell}$ simult.\",\n", - " r\"Prefit N$^{3}LL+NNLO$\",\n", - " \"\", \"\", \n", - " \"\", \"\",\n", - " ],\n", - " colors=[\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkred\",\n", - " \"darkblue\",\n", - " \"darkblue\",\n", - " \"darkgreen\",\n", - " \"darkgreen\",\n", - " ],\n", - " linestyles=[\"solid\"]*2+[\"dashed\"]+[\"solid\"]*4,\n", - " xlabel=\"p$_{T}^{W}$ (GeV)\", \n", - " ylabel=\"$\\sigma$/bin\",\n", - " rlabel=r\"x/Nom. fit.\",\n", - " rrange=[0.9, 1.1],\n", - " nlegcols=1,\n", - " xlim=None, binwnorm=1.0, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", - " yscale=1.2,\n", - " cms_decorr=' ',\n", + " hists=[\n", + " mwfith,\n", + " ptllcombfith,\n", + " gen_inc_w,\n", + " mwup,\n", + " mwdown,\n", + " ptllcombup,\n", + " ptllcombdown,\n", + " ],\n", + " labels=[\n", + " r\"$p_{T}^{W}$ postfit\",\n", + " r\"$p_{T}^{W}$ postfit, $p_{T}^{\\ell\\ell}$ simult.\",\n", + " r\"Prefit N$^{3}LL+NNLO$\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " \"\",\n", + " ],\n", + " colors=[\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkred\",\n", + " \"darkblue\",\n", + " \"darkblue\",\n", + " \"darkgreen\",\n", + " \"darkgreen\",\n", + " ],\n", + " linestyles=[\"solid\"] * 2 + [\"dashed\"] + [\"solid\"] * 4,\n", + " xlabel=\"p$_{T}^{W}$ (GeV)\",\n", + " ylabel=\"$\\sigma$/bin\",\n", + " rlabel=r\"x/Nom. fit.\",\n", + " rrange=[0.9, 1.1],\n", + " nlegcols=1,\n", + " xlim=None,\n", + " binwnorm=1.0,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", + " yscale=1.2,\n", + " cms_decorr=\" \",\n", ")\n", "outdir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "name = \"ptVgen_postfit_RecoPtll_NominalRatio\"\n", @@ -649,31 +707,32 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hh.divideHists(gen_inc_w, gen_inc)[:40j],\n", - " hh.divideHists(mwfith, n3p0ll_ptlldatafith)[:40j],\n", - " hh.divideHists(ptllcombfith, n3p0ll_ptlldatafith)[:40j],\n", - " ],\n", - " labels=[\n", - " \"Prefit\",\n", - " \"Nominal postfit\",\n", - " \"Combined postfit\",\n", - " ],\n", - " colors=[\n", - " \"darkred\",\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*2,\n", - " xlabel=\"p$_{T}^{V}$ (GeV)\", \n", - " ylabel=\"W/Z ratio\",\n", - " rlabel=r\"x/prefit\",\n", - " rrange=[0.8, 1.2],\n", - " nlegcols=1,\n", - " ylim=[5, 15],\n", - " xlim=None, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " hh.divideHists(gen_inc_w, gen_inc)[:40j],\n", + " hh.divideHists(mwfith, n3p0ll_ptlldatafith)[:40j],\n", + " hh.divideHists(ptllcombfith, n3p0ll_ptlldatafith)[:40j],\n", + " ],\n", + " labels=[\n", + " \"Prefit\",\n", + " \"Nominal postfit\",\n", + " \"Combined postfit\",\n", + " ],\n", + " colors=[\n", + " \"darkred\",\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 2,\n", + " xlabel=\"p$_{T}^{V}$ (GeV)\",\n", + " ylabel=\"W/Z ratio\",\n", + " rlabel=r\"x/prefit\",\n", + " rrange=[0.8, 1.2],\n", + " nlegcols=1,\n", + " ylim=[5, 15],\n", + " xlim=None,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", ")\n", "outdir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "name = \"ptVgen_postfit_WZRatio\"\n", @@ -690,28 +749,29 @@ "outputs": [], "source": [ "fig = plot_tools.makePlotWithRatioToRef(\n", - " hists=[\n", - " hh.divideHists(mwfith, gen_inc_w),\n", - " hh.divideHists(n3p0ll_wlikefith, gen_inc),\n", - " ],\n", - " labels=[\n", - " \"W\",\n", - " \"W-like Z\",\n", - " ],\n", - " colors=[\n", - " \"darkgreen\",\n", - " \"darkblue\",\n", - " ],\n", - " linestyles=[\"solid\"]*2,\n", - " xlabel=\"p$_{T}^{V}$ (GeV)\", \n", - " ylabel=\"postfit/prefit ratio\",\n", - " rlabel=r\"W-like/W\",\n", - " rrange=[0.8, 1.2],\n", - " nlegcols=1,\n", - " ylim=[0.8, 1.2],\n", - " xlim=None, baseline=True,\n", - " yerr=False,\n", - " fill_between=4,\n", + " hists=[\n", + " hh.divideHists(mwfith, gen_inc_w),\n", + " hh.divideHists(n3p0ll_wlikefith, gen_inc),\n", + " ],\n", + " labels=[\n", + " \"W\",\n", + " \"W-like Z\",\n", + " ],\n", + " colors=[\n", + " \"darkgreen\",\n", + " \"darkblue\",\n", + " ],\n", + " linestyles=[\"solid\"] * 2,\n", + " xlabel=\"p$_{T}^{V}$ (GeV)\",\n", + " ylabel=\"postfit/prefit ratio\",\n", + " rlabel=r\"W-like/W\",\n", + " rrange=[0.8, 1.2],\n", + " nlegcols=1,\n", + " ylim=[0.8, 1.2],\n", + " xlim=None,\n", + " baseline=True,\n", + " yerr=False,\n", + " fill_between=4,\n", ")\n", "outdir = output_tools.make_plot_dir(out, \"W\", eoscp=True)\n", "name = \"ptVgen_postfit_WZCompare\"\n", From 6c68dd1acc073b01766b564d65c8323cb9ddf429 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 11 Mar 2026 19:22:45 +0100 Subject: [PATCH 35/46] fix linting, maybe --- .../analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py index 6ed9209d0..f02270deb 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py +++ b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py @@ -12,8 +12,8 @@ # from narf import histutils import narf import wums.output_tools -from utilities import common -from wremnants.datasets.datagroups import Datagroups +from wremnants.postprocessing.datagroups import Datagroups +from wremnants.utilities import common from wums import boostHistHelpers as hh from wums import logging From 732cb469625f75e827d6111d6ee7fe49876539bf Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 11 Mar 2026 19:38:03 +0100 Subject: [PATCH 36/46] black to reformat --- wremnants/production/unfolding_tools.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/wremnants/production/unfolding_tools.py b/wremnants/production/unfolding_tools.py index 6261f140d..b6b9b1ca9 100644 --- a/wremnants/production/unfolding_tools.py +++ b/wremnants/production/unfolding_tools.py @@ -419,13 +419,11 @@ def __init__( ] if any(ax.edges != wbh_axis.edges): - raise RuntimeError( - f""" + raise RuntimeError(f""" Unfolding axes must be consistent with axes from weightsByHelicity_helper.\n Found unfolding axis {ax}\n And weightsByHelicity_helper axis {wbh_axis} - """ - ) + """) self.unfolding_corr_helper = ( reweight_to_fitresult( From 84791af227107144d98ea45b80e03f8217f85582 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 12 Mar 2026 15:22:23 +0100 Subject: [PATCH 37/46] fix wrong sample name for BSM studies --- scripts/histmakers/w_z_gen_dists.py | 2 +- wremnants/production/theory_corrections.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/histmakers/w_z_gen_dists.py b/scripts/histmakers/w_z_gen_dists.py index 8aaae9c23..e0ef2d719 100644 --- a/scripts/histmakers/w_z_gen_dists.py +++ b/scripts/histmakers/w_z_gen_dists.py @@ -898,7 +898,7 @@ def build_graph(df, dataset): propagateToHelicity=args.propagatePDFstoHelicity, ) - if not dataset.name.startswith("WtoNMu_MN"): + if not dataset.name.startswith(("WtoNMuMass", "WtoMuNuSMEFT")): helicity_axes = nominal_axes[:-1] if args.addHelicityAxis else nominal_axes helicity_cols = nominal_cols[:-2] if args.addHelicityAxis else nominal_cols diff --git a/wremnants/production/theory_corrections.py b/wremnants/production/theory_corrections.py index 6d9f7ff97..e68c9dde6 100644 --- a/wremnants/production/theory_corrections.py +++ b/wremnants/production/theory_corrections.py @@ -397,7 +397,7 @@ def define_theory_weights_and_corrs(df, dataset_name, helpers, args, theory_help if "powheg" not in dataset_name: # no preFSR particles in powheg samples df = generator_level_definitions.define_prefsr_vars(df) - if not dataset_name.startswith("WtoNMu_MN"): + if not dataset_name.startswith(("WtoNMuMass", "WtoMuNuSMEFT")): # no intermediate bosons in some events in madgraph samples logger.debug(f"Define intermediate gen variables for {dataset_name}") df = generator_level_definitions.define_intermediate_gen_vars( From 4a73d6138a9efd1546e8db8cd61d3971429dfbea Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sat, 14 Mar 2026 23:38:48 +0100 Subject: [PATCH 38/46] updates to test custom recoil syst --- .../w_mass_13TeV/makeFakeTransferTemplate.py | 402 +++++++++++++----- scripts/histmakers/mw_with_mu_eta_pt.py | 150 ++++++- scripts/rabbit/setupRabbit.py | 53 ++- wremnants/utilities/styles/styles.py | 17 + 4 files changed, 517 insertions(+), 105 deletions(-) diff --git a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py index f02270deb..11db123a5 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py +++ b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py @@ -1,19 +1,23 @@ #!/usr/bin/env python3 +import math import os import pickle import sys from array import array +from functools import partial import hist import lz4.frame +import numpy as np import ROOT import tensorflow as tf # from narf import histutils import narf +import wums.fitutils import wums.output_tools -from wremnants.postprocessing.datagroups import Datagroups -from wremnants.utilities import common +from utilities import common +from wremnants.datasets.datagroups import Datagroups from wums import boostHistHelpers as hh from wums import logging @@ -34,10 +38,47 @@ safeOpenFile, ) +INFLATION_ERRORS = 9.78**0.5 +INFLATION_FIT_SIGMA = 0 + +inflation = np.sqrt(INFLATION_ERRORS**2 + INFLATION_FIT_SIGMA**2) + + +def pol4_withCut_root(xvals, parms, xLowVal=0.0, xFitRange=1.0, xCut=47.84): + xScaled = (xvals[0] - xLowVal) / xFitRange + xCutScaled = (xCut - xLowVal) / xFitRange + + polN = tf.exp( + parms[0] + + parms[1] * xScaled + + parms[2] * xScaled**2 + + parms[3] * xScaled**3 + + parms[4] * xScaled**4 + ) + + polN_cut = tf.exp( + parms[0] + + parms[1] * xCutScaled + + parms[2] * xCutScaled**2 + + parms[3] * xCutScaled**3 + + parms[4] * xCutScaled**4 + ) + + der_polN_cut = ( + parms[1] + + 2 * parms[2] * xCutScaled + + 3 * parms[3] * xCutScaled**2 + + 4 * parms[4] * xCutScaled**3 + ) * polN_cut + + return tf.where( + xScaled < xCutScaled, polN, polN_cut + der_polN_cut * (xScaled - xCutScaled) + ) + def pol4_root(xvals, parms, xLowVal=0.0, xFitRange=1.0): xscaled = (xvals[0] - xLowVal) / xFitRange - return ( + return tf.exp( parms[0] + parms[1] * xscaled + parms[2] * xscaled**2 @@ -79,6 +120,57 @@ def convert_binEdges_idx(ed_list, binning): return (low, high) +def smoothTF(ratio_boost, x_bins, xLowVal=26.0, xFitRange=30.0): + + pars = np.array([1.0, 0.0, 0.0, 0.0, 0.0]) # Initial parameters for polN_root + fitFunc = partial(pol4_root, xLowVal=xLowVal, xFitRange=xFitRange) + fitRes = wums.fitutils.fit_hist( + ratio_boost, + fitFunc, + pars, + ) + tf1_fit = ROOT.TF1("tf1_fit", fitFunc, ptEdges[0], ptEdges[-1], len(pars)) + tf1_fit.SetParameters(np.array(fitRes["x"], dtype=np.float64)) + + npar = tf1_fit.GetNpar() + altPars = np.array( + [np.zeros(npar, dtype=np.float64)] * (npar * 2), dtype=np.float64 + ) + + e, v = np.linalg.eigh(fitRes["cov"]) + for ivar in range(npar): + shift = np.sqrt(e[ivar]) * v[:, ivar] * inflation + altPars[ivar] = fitRes["x"] + shift + altPars[ivar + npar] = fitRes["x"] - shift + + nomiVals = np.zeros(len(x_bins)) + altVals_sep = [np.zeros(len(x_bins))] * npar + altVals_all = np.zeros(len(x_bins)) + + for iBin in range(len(x_bins)): + pt = ptBinCenters[iBin] + fitVal = max(0.00001, tf1_fit.Eval(pt)) + nomiVals[iBin] = fitVal + + err = 0 + for ivar in range(npar): + tf1_alt = ROOT.TF1() + tf1_alt.SetName(f"tf1_alt_{ivar}") + tf1_fit.Copy(tf1_alt) + + # set parameters for a given hessian + tf1_alt.SetParameters(altPars[ivar]) + altFuncVal = max(0.001, tf1_alt.Eval(pt)) + altVals_sep[ivar][iBin] = altFuncVal + diff = altFuncVal - fitVal + err += diff * diff + + altVals_all[iBin] = fitVal + math.sqrt(err) + print(f"{iBin}: {altVals_all[iBin] / fitVal}") + + return fitRes, nomiVals, altVals_all, altVals_sep + + parser = common_plot_parser() parser.add_argument( "-i", @@ -114,13 +206,26 @@ def convert_binEdges_idx(ed_list, binning): action="store_true", help="Make templates with QCD instead of nonprompt contribution", ) +parser.add_argument( + "--addClosure", + action="store_true", + help="Save variations related to closure with QCD MC and with signal region", +) +parser.add_argument( + "--noSmoothing", + action="store_true", + default=False, + help="Save binned TF instead of smoothed one", +) parser.add_argument( "--plotdir", type=str, default=None, help="Output directory for plots" ) + args = parser.parse_args() logger = logging.setup_logger(os.path.basename(__file__), 4) ROOT.TH1.SetDefaultSumw2() +proc = "Data" if not args.doQCD else "QCD" groupsToConsider = ( [ @@ -158,10 +263,12 @@ def convert_binEdges_idx(ed_list, binning): logger.info(f"Unstacked processes are {exclude}") logger.info(f"Stacked processes are {prednames}") +s = hist.tag.Slicer() + histInfo = groups.groups -select_utMinus = {"utAngleSign": hist.tag.Slicer()[0 : 1 : hist.sum]} -select_utPlus = {"utAngleSign": hist.tag.Slicer()[1 : 2 : hist.sum]} +select_utMinus = {"utAngleSign": s[0 : 1 : hist.sum]} +select_utPlus = {"utAngleSign": s[1 : 2 : hist.sum]} groups.set_histselectors( datasets, @@ -187,8 +294,10 @@ def convert_binEdges_idx(ed_list, binning): etaEdges = hnomi.axes["eta"].edges nChargeBins = hnomi.axes["charge"].size chargeEdges = hnomi.axes["charge"].edges +ptBinCenters = [round((ptEdges[i + 1] + ptEdges[i]) / 2, 1) for i in range(nPtBins)] eta_genBinning = array("d", [round(x, 1) for x in etaEdges]) +pt_genBinning = array("d", [round(x, 0) for x in ptEdges]) charge_genBinning = array("d", chargeEdges) delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins @@ -212,16 +321,38 @@ def convert_binEdges_idx(ed_list, binning): logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") -out_hist = ROOT.TH3D( - f"fakeRatio_utAngleSign_{'Data' if not args.doQCD else 'QCD'}", - "", - len(eta_genBinning) - 1, - eta_genBinning, - nPtBins, - array("d", [round(x, 1) for x in ptEdges]), - len(charge_genBinning) - 1, - charge_genBinning, +out_hist_nomi = hist.Hist( + hist.axis.Regular( + len(etaEdges) - 1, etaEdges[0], etaEdges[-1], name="eta", flow=False + ), + hist.axis.Regular(len(ptEdges) - 1, ptEdges[0], ptEdges[-1], name="pt", flow=False), + hist.axis.Regular( + len(chargeEdges) - 1, chargeEdges[0], chargeEdges[-1], name="charge", flow=False + ), + # hist.axis.Regular(2, -2.0, 2.0, name="utAngleSign") + storage=hist.storage.Weight(), +) +outNomi = out_hist_nomi.view() + +out_hist_altStat = hist.Hist( + *out_hist_nomi.axes, + # FIXME: why not starting from -0.5 such that the first bin is centered at 0? + hist.axis.Regular( + 6, -1.5, 4.5, name="varTF" + ), # 1 inclusive variation (first bin), plus the other 5 + storage=hist.storage.Weight(), ) +outAltStat = out_hist_altStat.view() + +if args.addClosure: + out_hist_closQCDsv = hist.Hist(*out_hist_nomi.axes, storage=hist.storage.Weight()) + out_hist_closQCDsignal = hist.Hist( + *out_hist_nomi.axes, storage=hist.storage.Weight() + ) +else: + out_hist_closQCDsv, out_hist_closQCDsignal = None, None + +out_info = {} for ch_edges in decorrBins_ch: for eta_edges in decorrBins_eta: @@ -232,33 +363,31 @@ def convert_binEdges_idx(ed_list, binning): logger.info(f"{ch_low_idx}, {ch_high_idx}") logger.info(f"{eta_low_idx}, {eta_high_idx}") - select_utMinus["charge"] = hist.tag.Slicer()[ - ch_low_idx : ch_high_idx : hist.sum - ] - select_utMinus["eta"] = hist.tag.Slicer()[eta_low_idx : eta_high_idx : hist.sum] + select_utMinus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] + select_utMinus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] - select_utPlus["charge"] = hist.tag.Slicer()[ch_low_idx : ch_high_idx : hist.sum] - select_utPlus["eta"] = hist.tag.Slicer()[eta_low_idx : eta_high_idx : hist.sum] + select_utPlus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] + select_utPlus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] logger.info(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") - boost_h_utMinus = histInfo["Data"].copy("Data_utMinus").hists["nominal"] + boost_h_utMinus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] boost_h_utMinus = boost_h_utMinus[select_utMinus] boost_h_utMinus = hh.projectNoFlow(boost_h_utMinus, ["pt"], ["relIso", "mt"]) root_h_utMinus = narf.hist_to_root(boost_h_utMinus) - boost_h_utPlus = histInfo["Data"].copy("Data_utPlus").hists["nominal"] + boost_h_utPlus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] boost_h_utPlus = boost_h_utPlus[select_utPlus] boost_h_utPlus = hh.projectNoFlow(boost_h_utPlus, ["pt"], ["relIso", "mt"]) root_h_utPlus = narf.hist_to_root(boost_h_utPlus) - logger.info(f"Integrals BEFORE prompt subraction (uT < 0, uT > 0)") - logger.info(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") + logger.debug(f"Integrals BEFORE prompt subraction (uT < 0, uT > 0)") + logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") for mcName in prednames: if args.doQCD: continue - logger.info(f"Subtracting {mcName} from data") + logger.debug(f"Subtracting {mcName} from data") boost_h_mc_utMinus = ( histInfo[mcName].copy(f"{mcName}_utMinus").hists["nominal"] ) @@ -279,38 +408,117 @@ def convert_binEdges_idx(ed_list, binning): root_h_mc_utPlus = narf.hist_to_root(boost_h_mc_utPlus) root_h_utPlus.Add(root_h_mc_utPlus, -1) - logger.info(f"Integrals AFTER prompt subraction (uT < 0, uT > 0)") - logger.info(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") + logger.debug(f"Integrals AFTER prompt subraction (uT < 0, uT > 0)") + logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") - ratio_h = root_h_utMinus.Clone(f"fakeRatio_utAngleSign") + ratio_h = root_h_utMinus.Clone(f"fakeRatio_utAngleSign_TH1") ratio_h.Sumw2() ratio_h.Divide(root_h_utPlus) - for idx_ch in range(ch_low_idx + 1, ch_high_idx + 1): - for idx_eta in range(eta_low_idx + 1, eta_high_idx + 1): - # logger.debug(f"Setting weights for chBin={idx_ch}, etaBin={idx_eta}") - for idx_pt in range(1, 1 + nPtBins): - out_hist.SetBinContent( - idx_eta, idx_pt, idx_ch, ratio_h.GetBinContent(idx_pt) + ratio_h_boost = narf.root_to_hist(ratio_h) + + sel = ( + slice(eta_low_idx, eta_high_idx), + slice(None), + slice(ch_low_idx, ch_high_idx), + ) + + if args.noSmoothing: + outNomi.value[sel] = np.broadcast_to( + ratio_h_boost.values()[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) + outNomi.variance[sel] = np.broadcast_to( + ratio_h_boost.variances()[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) + + else: + fitRes, nomiVals, altVals_all, altVals_sep = smoothTF( + ratio_h_boost, + ptBinCenters, + xLowVal=ptEdges[0], + xFitRange=(ptEdges[-1] - ptEdges[0]), + ) + + outNomi.value[sel] = np.broadcast_to( + nomiVals[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) + + outAltStat.value[sel + (0,)] = ( + np.broadcast_to( + altVals_all[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) + / outNomi.value[sel] + ) + + # TODO: now have 5 parameters for pol4, can generalize to polN + for iv in range(1, 6): + outAltStat.value[sel + (iv,)] = ( + np.broadcast_to( + altVals_sep[iv - 1][None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), ) - out_hist.SetBinError( - idx_eta, idx_pt, idx_ch, ratio_h.GetBinError(idx_pt) + / outNomi.value[sel] + ) + + if args.addClosure: + + logger.debug("Elaborating corrections evaluated on QCD... ") + logger.debug( + "... be sure that the files are present and the TF has been already smoothed!" + ) + + path_corr_QCD_sv = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_QCD.pkl.lz4" + path_corr_QCD_signal = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_signalRegion_QCD.pkl.lz4" + + if os.path.exists(path_corr_QCD_sv): + with lz4.frame.open(path_corr_QCD_sv) as fTens: + hist_corr_QCDsv = pickle.load(fTens)["fakeCorr"] + out_hist_closQCDsv.values()[sel] = ( + hist_corr_QCDsv[sel].values() / outNomi.value[sel] + ) + else: + logger.warning( + "File with TF correction on QCD (SV region) not found! Skipping..." + ) + out_hist_closQCDsv = None + + if os.path.exists(path_corr_QCD_signal) and out_hist_closQCDsv: + with lz4.frame.open(path_corr_QCD_signal) as fTens: + hist_corr_QCDsignal = pickle.load(fTens)["fakeCorr"] + out_hist_closQCDsignal.values()[sel] = ( + hist_corr_QCDsignal[sel].values() + / hist_corr_QCDsv[sel].values() ) - if ratio_h.GetBinContent(idx_pt) <= 0.0: - logger.info( - "WARNING - found negative value in bin: ({idx_eta}, {idx_pt}, {idx_ch})" - ) + else: + logger.warning( + "File with TF correction on QCD (signal region) not found! Skipping..." + ) + out_hist_closQCDsignal = None + +resultDict = { + "fakeCorr": out_hist_nomi, +} +if args.noSmoothing is False: + resultDict.update({"fakeCorr_altStat": out_hist_altStat}) +if out_hist_closQCDsv: + resultDict.update({"fakeCorr_closQCDsv": out_hist_closQCDsv}) +if out_hist_closQCDsignal: + resultDict.update({"fakeCorr_closQCDsignal": out_hist_closQCDsignal}) -boost_out_hist = narf.root_to_hist(out_hist) -resultDict = {"fakeCorr": boost_out_hist} -base_dir = common.base_dir resultDict.update( - {"meta_info": wums.output_tools.make_meta_info_dict(args=args, wd=base_dir)} + {"meta_info": wums.output_tools.make_meta_info_dict(args=args, wd=common.base_dir)} ) + if args.plotdir is not None: + outRootNomi = narf.hist_to_root(out_hist_nomi.copy()) + plotdir_original = args.plotdir plotdir = createPlotDirAndCopyPhp(plotdir_original, eoscp=args.eoscp) hists_corr = [] @@ -319,39 +527,52 @@ def convert_binEdges_idx(ed_list, binning): # for 1D plots canvas1D = ROOT.TCanvas("canvas1D", "", 800, 900) adjustSettings_CMS_lumi() - integrateCharge = True - for ieta in [1, 24, 48]: + idxs_ch = [0] if args.nChargeBins == 1 else [1, 2] + idxs_eta = ( + [0] + if args.nEtaBins == 1 + else [(1 + int(48 * i / args.nEtaBins)) for i in range(args.nEtaBins)] + ) + for ieta in idxs_eta: etamu = "#eta^{#mu}" - etaleg = f"{decorrBins_eta[etaID][0]} < {etamu} < {decorrBins_eta[etaID][1]}" - etaID += 1 - for icharge in [1] if integrateCharge else [1, 2]: + etaleg = ( + f"{decorrBins_eta[etaID][0]} < {etamu} < {decorrBins_eta[etaID][1]}" + if len(idxs_eta) != 1 + else "" + ) + etaID += 1 if len(idxs_eta) != 1 else 0 + for icharge in idxs_ch: + chargeleg = "#it{q}^{#mu} = " + ( + ("-1" if icharge == 1 else "+1") if len(idxs_ch) != 1 else "#pm 1" + ) hists_corr.append( - out_hist.ProjectionY( + outRootNomi.ProjectionY( f"projPt_{ieta}_{icharge}", ieta, ieta, icharge, icharge ) ) - if integrateCharge: - chargeleg = "" - legEntries.append(f"{etaleg}") - else: - chargeleg = "#it{q}^{#mu} = " + ("-1" if icharge == 1 else "+1") - legEntries.append(f"{etaleg}, {chargeleg}") + legInfo = f"{etaleg}, {chargeleg}".lstrip() + legEntries.append( + legInfo if legInfo != "" else "TF integrated on #eta^{#mu}-#it{q}^{#mu}" + ) miny, maxy = getMinMaxMultiHisto(hists_corr) if miny < 0: miny = 0 maxy = 1.4 * (maxy - miny) + plotfilename = "correction_uT_vs_pT_eta_charge" + if args.postfix: + plotfilename += f"_{args.postfix}" drawNTH1( hists_corr, legEntries, "#it{p}_{T}^{#mu}", "Correction: #it{u}_{T}^{#mu} > 0 #rightarrow #it{u}_{T}^{#mu} < 0" + f"::{miny},{maxy}", - "correction_uT_vs_pT_eta_charge", + plotfilename, plotdir, lowerPanelHeight=0.4, legendCoords=( - "0.4,0.98,0.74,0.92" if integrateCharge else "0.16,0.98,0.74,0.92;2" + "0.4,0.98,0.74,0.92" if len(idxs_ch) == 1 else "0.16,0.98,0.74,0.92;2" ), labelRatioTmp="Ratio to first::0.2,1.8", topMargin=0.06, @@ -371,56 +592,33 @@ def convert_binEdges_idx(ed_list, binning): outfileName += f"_{args.postfix}" if args.doQCD: outfileName += "_QCD" +# if args.noSmoothing: +# outfileName += "_noSmoothing" pklfileName = f"{args.outdir}/{outfileName}.pkl.lz4" with lz4.frame.open(pklfileName, "wb") as fout: pickle.dump(resultDict, fout, protocol=pickle.HIGHEST_PROTOCOL) -logger.warning(f"Created file {pklfileName}") +logger.info(f"Created file {pklfileName}") rootfileName = f"{args.outdir}/{outfileName}.root" fout = safeOpenFile(rootfileName, mode="RECREATE") -out_hist.Write() -fout.Close() -logger.warning(f"Created file {rootfileName}") - - -""" -x_axis = hist.axis.Regular(30, 26, 56, name="pt", flow=False) - -tr_hist = hist.Hist(x_axis, storage=hist.storage.Weight()) - -for i in range(30): - tr_hist[i] = (arr_val[i], arr_var[i]) - - -params = np.array([1.0, 0.0, 0.0, 0.0, 0.0]) # Initial parameters for pol4_root - -res = fit_hist( - tr_hist, - partial(pol4_root, xLowVal=26.0, xFitRange=30.0), - params, -) - -tr_func = [] -for i in range(len(bincenters)): - tr_func.append( - float( - pol4_root( - [bincenters[i]], - res["x"], - xLowVal=26.0, - xFitRange=30.0, - ))) -logger.info(tr_func) -logger.info("Params:", res["x"]) - -chi2 = res["loss_val"] -ndof = len(bincenters) - len(res["x"]) -chi2Prob = ROOT.TMath.Prob(chi2, ndof) - -logger.info(chi2, ndof, chi2Prob) - -""" - +ratio_h.Write() + +outRootNomi = narf.hist_to_root(out_hist_nomi.copy()[(1, slice(None), 1)]) +outRootNomi.SetName("fakeCorr_Nominal") +outRootNomi.Write() +outRootAltStat_all = narf.hist_to_root(out_hist_altStat.copy()[(0, slice(None), 0, 0)]) +outRootAltStat_all.SetName("fakeCorr_altStat_all") +outRootAltStat_all.Write() +if args.addClosure: + outClosSV = narf.hist_to_root(out_hist_closQCDsv.copy()[(0, slice(None), 0)]) + outClosSV.SetName("fakeCorr_closure_QCDsv") + outClosSV.Write() + outClosSignal = narf.hist_to_root( + out_hist_closQCDsignal.copy()[(0, slice(None), 0)] + ) + outClosSignal.SetName("fakeCorr_closure_QCDsignal") + outClosSignal.Write() fout.Close() +logger.info(f"Created file {rootfileName}") diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index a1e01d8a7..589def3fc 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -1374,7 +1374,44 @@ def build_graph(df, dataset): "transverseMass", "wrem::mt_2(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", ) - + # to define dedicated systematics for scale/smearing of met_pt + df = df.Define( + "scaleMET_pt", + "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_pt, 1.01, 0.0)", + ) + df = df.Define( + "smearMET_pt", + "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_pt, 1.0, 0.05)", + ) + df = df.Define( + "smearMET_phi", + "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_phi, 1.0, 0.05)", + ) + df = df.Define( + "transverseMass_scaleMET_pt", + "wrem::mt_2(goodMuons_pt0, goodMuons_phi0, scaleMET_pt, MET_corr_rec_phi)", + ) + df = df.Define( + "transverseMass_smearMET_pt", + "wrem::mt_2(goodMuons_pt0, goodMuons_phi0, smearMET_pt, MET_corr_rec_phi)", + ) + df = df.Define( + "transverseMass_smearMET_phi", + "wrem::mt_2(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, smearMET_phi)", + ) + df = df.Define( + "goodMuons_angleSignUt_scaleMET_pt0", + "wrem::zqtproj0_angleSign(goodMuons_pt0, goodMuons_phi0, scaleMET_pt, MET_corr_rec_phi)", + ) + df = df.Define( + "goodMuons_angleSignUt_smearMET_pt0", + "wrem::zqtproj0_angleSign(goodMuons_pt0, goodMuons_phi0, smearMET_pt, MET_corr_rec_phi)", + ) + df = df.Define( + "goodMuons_angleSignUt_smearMET_phi0", + "wrem::zqtproj0_angleSign(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, smearMET_phi)", + ) + # df = df.Define("hasCleanJet", "Sum(goodCleanJetsNoPt && Jet_pt > 30) >= 1") df = df.Define( "goodMuons_dphiMuMet0", @@ -1661,6 +1698,77 @@ def build_graph(df, dataset): ) results.append(mTStudyForFakes) + if not dataset.is_data: + # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) + df = df.Define( + "goodMuons_utGenMet0", + "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", + ) + df = df.Define( + "goodMuons_angleCosineUtGenMet0", + "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", + ) + ut_bins = ( + *np.arange(-40, -19, 5), + *np.arange(-18, 21, 2), + *np.arange(25, 51, 5), + *np.arange(60, 101, 10), + ) + axis_ut_recoMet = hist.axis.Variable( + ut_bins, name="ut_recoMet", underflow=True, overflow=True + ) + axis_ut_genMet = hist.axis.Variable( + ut_bins, name="ut_genMet", underflow=True, overflow=True + ) + axis_uTAngleCosineGenMet = hist.axis.Regular( + 20, -1, 1, name="uTAngleCosineGenMet", overflow=False, underflow=False + ) + # + etaPtUtGenUt = df.HistoBoost( + "etaPtUtGenUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_genMet, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utReco0", + "goodMuons_utGenMet0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtGenUt) + # + etaPtUtAngleCosineGenUtAngleCosine = df.HistoBoost( + "etaPtUtAngleCosineGenUtAngleCosine", + [ + axis_eta, + axis_pt, + axis_uTAngleCosine, + axis_uTAngleCosineGenMet, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_angleCosineUt0", + "goodMuons_angleCosineUtGenMet0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtAngleCosineGenUtAngleCosine) + # + # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: dphiMuonMetCut = args.dphiMuonMetCut * np.pi @@ -1922,6 +2030,46 @@ def build_graph(df, dataset): ) ) + cols_scaleMET_pt = [ + x.replace("transverseMass", "transverseMass_scaleMET_pt").replace( + "goodMuons_angleSignUt0", "goodMuons_angleSignUt_scaleMET_pt0" + ) + for x in cols + ] + cols_smearMET_pt = [ + x.replace("transverseMass", "transverseMass_smearMET_pt").replace( + "goodMuons_angleSignUt0", "goodMuons_angleSignUt_smearMET_pt0" + ) + for x in cols + ] + cols_smearMET_phi = [ + x.replace("transverseMass", "transverseMass_smearMET_phi").replace( + "goodMuons_angleSignUt0", "goodMuons_angleSignUt_smearMET_phi0" + ) + for x in cols + ] + systematics.add_syst_hist( + results, + df, + "nominal_scaleMET_pt", + axes, + [*cols_scaleMET_pt, "nominal_weight"], + ) + systematics.add_syst_hist( + results, + df, + "nominal_smearMET_pt", + axes, + [*cols_smearMET_pt, "nominal_weight"], + ) + systematics.add_syst_hist( + results, + df, + "nominal_smearMET_phi", + axes, + [*cols_smearMET_phi, "nominal_weight"], + ) + if args.makeMCefficiency: axes_WeffMC = [ axis_eta, diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index ffcc95c4c..6639ddedd 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -336,6 +336,7 @@ def make_parser(parser=None): default=None, choices=[ "charge", + "utAngleSign", "cosThetaStarll", "eta-sign", "eta-range", @@ -503,7 +504,7 @@ def make_parser(parser=None): parser.add_argument( "--fakeTransferCorrFileName", type=str, - default="fakeTransferTemplates", + default="fakeTransferTemplates_smoothTF", help=""" Name of pkl.lz4 file (without extension) with pTmu correction for the shape of data-driven fakes. Currently used only when utAngleSign is a fakerate axis (detected automatically), since the shape @@ -1919,7 +1920,7 @@ def setup( ) if inputBaseName != "prefsr": - # make prefsr ane EW free definition + # make prefsr and EW free definition rabbit_helpers.add_electroweak_uncertainty( datagroups, [*args.ewUnc, *args.fsrUnc, *args.isrUnc], @@ -3002,6 +3003,54 @@ def fake_transferFactor_ptSyst( passToFakes=passSystToFakes, ) + # ad-hoc uncertainties for recoil, scaling and smearing met + datagroups.addSystematic( + "scaleMET_pt", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + # scale=0.1, + systAxes=[], + passToFakes=passSystToFakes, + ) + datagroups.addSystematic( + "smearMET_pt", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + # scale=0.5, + systAxes=[], + passToFakes=passSystToFakes, + ) + datagroups.addSystematic( + "smearMET_phi", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + # scale=0.5, + systAxes=[], + passToFakes=passSystToFakes, + ) + #### + ## decorrelated momentum scale and resolution, when requested if not dilepton and "ptscale" in args.decorrSystByVar and decorr_syst_var in fitvar: datagroups.addSystematic( diff --git a/wremnants/utilities/styles/styles.py b/wremnants/utilities/styles/styles.py index 35e1299e9..b86e76d7e 100644 --- a/wremnants/utilities/styles/styles.py +++ b/wremnants/utilities/styles/styles.py @@ -352,6 +352,19 @@ def translate_html_to_latex(n): "normZ_Helicity3", "normZ_Helicity4", ], + "max_recoil": common_groups + + [ + "angularCoeffs", + "pdfCT18Z", + "pTModeling", + "muon_eff_syst", + "muon_eff_stat", + "prefire", + "muonCalibration", + "Fake", + "recoil_stat", + "recoil_syst_tmp", + ], "width": common_groups + [ "angularCoeffs", @@ -363,6 +376,8 @@ def translate_html_to_latex(n): "muonCalibration", "Fake", "massShift", + "recoil_stat", + "recoil_syst_tmp", ], "min": common_groups + [ @@ -583,6 +598,8 @@ def translate_html_to_latex(n): "binByBinStatWtoNMu_50": "Bin-by-bin stat. (BSM)", "recoil": "recoil", "CMS_background": "Other bkg.", + "recoil_stat": "recoil stat.", + "recoil_syst_tmp": "recoil syst.", "FakeHighMT": "FakeHighMT", "FakeLowMT": "FakeLowMT", "rFake": "fakerate", From b31ead92d7e90d64ff36ff2ce0adbddb0d334ca0 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Wed, 25 Mar 2026 11:59:38 +0100 Subject: [PATCH 39/46] updates --- scripts/analysisTools/tests/testFakesVsMt.py | 68 +- .../w_mass_13TeV/makeFakeTransferTemplate.py | 826 +++++++++--------- scripts/histmakers/mw_with_mu_eta_pt.py | 113 ++- scripts/rabbit/setupRabbit.py | 226 ++--- wremnants/postprocessing/rabbit_helpers.py | 14 + wremnants/postprocessing/syst_tools.py | 88 +- wremnants/production/include/utils.hpp | 16 +- wremnants/utilities/common.py | 2 +- wremnants/utilities/styles/styles.py | 3 + 9 files changed, 790 insertions(+), 566 deletions(-) diff --git a/scripts/analysisTools/tests/testFakesVsMt.py b/scripts/analysisTools/tests/testFakesVsMt.py index 18c2634cf..4407d6bf7 100644 --- a/scripts/analysisTools/tests/testFakesVsMt.py +++ b/scripts/analysisTools/tests/testFakesVsMt.py @@ -65,6 +65,8 @@ from scripts.analysisTools.tests.cropNegativeTemplateBins import cropNegativeContent from scripts.analysisTools.tests.testPlots1D import plotDistribution1D +narf.clingutils.Declare('#include "histHelpers.hpp"') + # will use as input the histogram mTStudyForFakes with eta-pt-charge-mt-passIso-hasJet, where mt is the full distribution @@ -110,7 +112,7 @@ def plotProjection1D( rootHists[d].GetAxis(2).SetRange(chargeBin, chargeBin) rootHists[d].GetAxis(3).SetRange(firstBinMt, lastBinMt) rootHists[d].GetAxis(4).SetRange(isoAxisRange[0], isoAxisRange[1]) - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": rootHists[d].GetAxis(5).SetRange(jetAxisRange[0], jetAxisRange[1]) rootHists[d].GetAxis(6).SetRange(1, rootHists[d].GetAxis(6).GetNbins()) if d == "Data": @@ -716,6 +718,7 @@ def runStudy(fname, charges, mainOutputFolder, args): "mtOverPt": "mTStudyForFakesAlt2", "altMt": "mTStudyForFakesAlt3", "dxybs": "mTStudyForFakesAlt4", + "mtBinnedUt": "mTStudyForFakesAlt5", } etaLabel = "#eta^{#mu}" if not args.absEta else "|#eta^{#mu}|" @@ -731,8 +734,8 @@ def runStudy(fname, charges, mainOutputFolder, args): "altMt": f"{metLabel} (1 - {dphiMuMetLabel})", "dxybs": "Thr - |dxy_{bs}^{#mu}| (cm)", } - xABCD = args.xABCD - noMtABCD = xABCD != "mt" + xABCD = "mt" if args.xABCD in ["mt", "mtBinnedUt"] else args.xABCD + noMtABCD = xABCD not in ["mt", "mtBinnedUt"] xAxisName = args.xAxisName if args.absEta and "|#eta" not in xAxisName and "#eta" in xAxisName: @@ -767,7 +770,7 @@ def runStudy(fname, charges, mainOutputFolder, args): datasetsNoFakes = list(filter(lambda x: x != "Fake", datasets)) datasetsNoQCDFakes = list(filter(lambda x: x not in ["QCD", "Fake"], datasets)) logger.info(f"All original datasets available {datasets}") - inputHistName = inputHistDict[xABCD] + inputHistName = inputHistDict[args.xABCD] groups.setNominalName(inputHistName) groups.loadHistsForDatagroups( inputHistName, syst="", procsToRead=datasets, applySelection=False @@ -794,6 +797,18 @@ def runStudy(fname, charges, mainOutputFolder, args): s = hist.tag.Slicer() # logger.info(d) hnarfTMP = histInfo[d].hists[inputHistName] + if args.presel is not None: + axName, axLow, axHigh = args.presel.split(",") + axLow = float(axLow) + if float(axHigh) >= hnarfTMP.axes[axName].edges[-1]: + hnarfTMP = hnarfTMP[ + {axName: s[complex(0, axLow) : hist.overflow : hist.sum]} + ] + else: + axHigh = float(axHigh) + hnarfTMP = hnarfTMP[ + {axName: s[complex(0, axLow) : complex(0, axHigh) : hist.sum]} + ] if charge == "inclusive": # integrate but keep charge axis with 1 single bin hnarfTMP = hnarfTMP[{"charge": s[:: hist.rebin(2)]}] @@ -863,7 +878,7 @@ def runStudy(fname, charges, mainOutputFolder, args): hnarf_fakerateDeltaPhi = hnarf_fakerateDeltaPhi[ {"DphiMuonMet": s[:: hist.rebin(2)]} ] - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": # make all TH of FRF in bins of dphi histo_fakes_dphiBins = narf.hist_to_root( hnarf_fakerateDeltaPhi @@ -1083,7 +1098,7 @@ def runStudy(fname, charges, mainOutputFolder, args): 0: ["muon_eta", etaLabel], 1: ["muon_pt", ptLabel + " (GeV)"], } - if noMtABCD: + if noMtABCD or args.xABCD == "mtBinnedUt": axisVar[3] = [xABCD, zAxisName] else: axisVar[3] = ["mT", args.met + f" {mtLabel} (GeV)"] @@ -1138,7 +1153,7 @@ def runStudy(fname, charges, mainOutputFolder, args): for xbin in axisVar.keys(): if "Data" not in rootHists_forplots.keys(): continue - if noMtABCD: + if noMtABCD or args.xABCD == "mtBinnedUt": plotProjection1D( rootHists_forplots, datasetsNoFakes, @@ -1273,7 +1288,7 @@ def runStudy(fname, charges, mainOutputFolder, args): # set charge from charge axis histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) # now get a TH3 histoPassIso = histo_fakes.Projection(0, 1, 3, "E") @@ -1281,7 +1296,7 @@ def runStudy(fname, charges, mainOutputFolder, args): histoPassIso.SetTitle("fakes_passIso") histo_fakes.GetAxis(2).SetRange(chargeBin, chargeBin) histo_fakes.GetAxis(4).SetRange(1, 1) # FailIso - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": histo_fakes.GetAxis(5).SetRange(2 if args.jetCut else 1, 2) histoFailIso = histo_fakes.Projection(0, 1, 3, "E") histoFailIso.SetName("fakes_failIso") @@ -1296,7 +1311,7 @@ def runStudy(fname, charges, mainOutputFolder, args): histo_fakes.GetAxis(3).GetNbins(), ) # high mT histo_fakes.GetAxis(4).SetRange(1, 1) # FailIso - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": histo_fakes.GetAxis(5).SetRange(1, 2) # jet inclusive histoPassMtFailIso = histo_fakes.Projection(0, 1, 3, "E") histoPassMtFailIso.SetName("fakes_passMt_failIso_jetInclusive") @@ -1314,7 +1329,7 @@ def runStudy(fname, charges, mainOutputFolder, args): 1, histo_fakes.GetAxis(3).FindFixBin(mtThreshold - 0.0005) ) histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": histo_fakes.GetAxis(5).SetRange(1, 2) # always integrate jet here # now get a TH2 for passIso histoPassIsoLowMt_jetInclusive_vsEtaPt = histo_fakes.Projection(1, 0, "E") @@ -1350,7 +1365,7 @@ def runStudy(fname, charges, mainOutputFolder, args): ## now redo the same for the >=1 jet region ## could be done from previous TH3 histograms integrating in mT, but they don't always have the same jet cut histo_fakes.GetAxis(4).SetRange(2, 2) # passIso, equivalent to lowIso - if not noMtABCD: + if not noMtABCD and args.xABCD != "mtBinnedUt": histo_fakes.GetAxis(5).SetRange(2, 2) # always integrate jet here # now get a TH2 for passIso histoPassIsoLowMt_1orMoreJet_vsEtaPt = histo_fakes.Projection(1, 0, "E") @@ -2238,6 +2253,8 @@ def runStudy(fname, charges, mainOutputFolder, args): def runStudyVsDphi(fname, charges, mainOutputFolder, args): + xABCD = args.xABCD if args.xABCD != "mtBinnedUt" else "mt" + etaLabel = "#eta^{#mu}" if not args.absEta else "|#eta^{#mu}|" ptLabel = "#it{p}_{T}^{#mu}" @@ -2309,8 +2326,8 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): nPtBins = hnarf.axes["pt"].size lowMtUpperBound = float(args.mtNominalRange.split(",")[1]) - hnarf = hnarf[{args.xABCD: s[: complex(0, lowMtUpperBound) : hist.sum]}] - # hnarf = hnarf[{args.xABCD : s[::hist.sum]}] + hnarf = hnarf[{xABCD: s[: complex(0, lowMtUpperBound) : hist.sum]}] + # hnarf = hnarf[{xABCD : s[::hist.sum]}] chargeIndex = 0 if charge in ["minus", "inclusive"] else 1 hnarf = hnarf[{"charge": s[chargeIndex : chargeIndex + 1 : hist.sum]}] @@ -2429,7 +2446,7 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): parser.add_argument( "--xABCD", default="mt", - choices=["mt", "oneMinusCosdphi", "mtOverPt", "altMt", "dxybs"], + choices=["mt", "oneMinusCosdphi", "mtOverPt", "altMt", "dxybs", "mtBinnedUt"], help="X variable to use for ABCD method (y is pass isolation)", ) parser.add_argument("-x", "--xAxisName", default="#eta^{#mu}", help="x axis name") @@ -2534,6 +2551,12 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): help="Threshold to cut |deltaPhi| > thr*np.pi between muon and met", default=-1.0, ) + parser.add_argument( + "--presel", + type=str, + help="Apply slice selection to axis and integrate it away, use as '--presel axisName,low,high'", + default=None, + ) parser.add_argument( "--dphiStudy", action="store_true", @@ -2577,7 +2600,7 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): subFolder += f"_absEta" if args.postfix: subFolder += f"_{args.postfix}" - if args.xABCD != "mt": + if args.xABCD not in ["mt", "mtBinnedUt"]: subFolder += f"_{args.xABCD}" if args.fitErf: subFolder += f"_fitErf" @@ -2602,9 +2625,14 @@ def runStudyVsDphi(fname, charges, mainOutputFolder, args): if len(charges) == 2 and not args.dphiStudy: outFile = mainOutputFolder + fname mergeCmd = f"hadd -f {outFile} {' '.join(filesToMerge)}" - safeSystem(mergeCmd) - logger.info("") - logger.info(f"Saving all FRF corrections vs eta-pt in file {outFile}") - logger.info("") + status = safeSystem(mergeCmd, quitOnFail=False) + if status: + logger.warning( + f"Skip saving of all FRF corrections vs eta-pt in file {outFile}" + ) + else: + logger.info("") + logger.info(f"Saving all FRF corrections vs eta-pt in file {outFile}") + logger.info("") copyOutputToEos(mainOutputFolder, outdir_original, eoscp=args.eoscp) diff --git a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py index 11db123a5..98825ccd3 100644 --- a/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py +++ b/scripts/analysisTools/w_mass_13TeV/makeFakeTransferTemplate.py @@ -16,8 +16,8 @@ import narf import wums.fitutils import wums.output_tools -from utilities import common -from wremnants.datasets.datagroups import Datagroups +from wremnants.postprocessing.datasets.datagroups import Datagroups +from wremnants.utilities import common from wums import boostHistHelpers as hh from wums import logging @@ -171,454 +171,488 @@ def smoothTF(ratio_boost, x_bins, xLowVal=26.0, xFitRange=30.0): return fitRes, nomiVals, altVals_all, altVals_sep -parser = common_plot_parser() -parser.add_argument( - "-i", - "--infile", - type=str, - default="/scratch/rforti/wremnants_hists/mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles_m1_x0p50_y3p00_THAGNV0_fromSV.hdf5", - help="Input file with histograms", -) -parser.add_argument("-o", "--outdir", type=str, default="./", help="Output directory") -parser.add_argument( - "-p", - "--postfix", - type=str, - default=None, - help="Postfix appended to output file name", -) -parser.add_argument( - "--nEtaBins", - type=int, - default=1, - choices=[1, 2, 3, 4, 6, 8], - help="Number of eta bins where to evaluate the templates", -) -parser.add_argument( - "--nChargeBins", - type=int, - default=1, - choices=[1, 2], - help="Number of charge bins where to evaluate the templates", -) -parser.add_argument( - "--doQCD", - action="store_true", - help="Make templates with QCD instead of nonprompt contribution", -) -parser.add_argument( - "--addClosure", - action="store_true", - help="Save variations related to closure with QCD MC and with signal region", -) -parser.add_argument( - "--noSmoothing", - action="store_true", - default=False, - help="Save binned TF instead of smoothed one", -) -parser.add_argument( - "--plotdir", type=str, default=None, help="Output directory for plots" -) - -args = parser.parse_args() - -logger = logging.setup_logger(os.path.basename(__file__), 4) -ROOT.TH1.SetDefaultSumw2() -proc = "Data" if not args.doQCD else "QCD" - -groupsToConsider = ( - [ - "Data", - "Wmunu", - "Wtaunu", - "Diboson", - "Zmumu", - "DYlowMass", - "PhotonInduced", - "Ztautau", - "Top", - ] - if not args.doQCD - else ["QCD"] -) +if __name__ == "__main__": -groups = Datagroups( - args.infile, - filterGroups=groupsToConsider, - excludeGroups=None, -) + parser = common_plot_parser() + parser.add_argument( + "-i", + "--infile", + type=str, + default="/scratch/rforti/wremnants_hists/mw_with_mu_eta_pt_scetlib_dyturboCorr_maxFiles_m1_x0p50_y3p00_THAGNV0_fromSV.hdf5", + help="Input file with histograms", + ) + parser.add_argument( + "-o", "--outdir", type=str, default="./", help="Output directory" + ) + parser.add_argument( + "-p", + "--postfix", + type=str, + default=None, + help="Postfix appended to output file name", + ) + parser.add_argument( + "--transferVariable", + type=str, + default="utAngleSign", + choices=["utAngleSign"], + help="Variables used for the transfer factor", + ) + parser.add_argument( + "--nEtaBins", + type=int, + default=1, + choices=[1, 2, 3, 4, 6, 8], + help="Number of eta bins where to evaluate the templates", + ) + parser.add_argument( + "--nChargeBins", + type=int, + default=1, + choices=[1, 2], + help="Number of charge bins where to evaluate the templates", + ) + parser.add_argument( + "--doQCD", + action="store_true", + help="Make templates with QCD instead of nonprompt contribution", + ) + parser.add_argument( + "--addClosure", + action="store_true", + help="Save variations related to closure with QCD MC and with signal region", + ) + parser.add_argument( + "--noSmoothing", + action="store_true", + default=False, + help="Save binned TF instead of smoothed one", + ) + parser.add_argument( + "--plotdir", type=str, default=None, help="Output directory for plots" + ) -# There is probably a better way to do this but I don't want to deal with it -datasets = groups.getNames() -logger.info(f"Will work on datasets {datasets}") + args = parser.parse_args() + + logger = logging.setup_logger(os.path.basename(__file__), args.verbose) + ROOT.TH1.SetDefaultSumw2() + proc = "Data" if not args.doQCD else "QCD" + transfer_variable = args.transferVariable + + # TODO: take list from some common place + groupsToConsider = ( + [ + "Data", + "Wmunu", + "Wtaunu", + "Diboson", + "Zmumu", + "DYlowMass", + "PhotonInduced", + "Ztautau", + "Top", + ] + if not args.doQCD + else ["QCD"] + ) -exclude = ["Data"] if not args.doQCD else [] -prednames = list( - groups.getNames( - [d for d in datasets if d not in exclude], exclude=False, match_exact=True + groups = Datagroups( + args.infile, + filterGroups=groupsToConsider, + excludeGroups=None, ) -) -logger.info(f"Unstacked processes are {exclude}") -logger.info(f"Stacked processes are {prednames}") + datasets = groups.getNames() + logger.info(f"Will work on datasets {datasets}") -s = hist.tag.Slicer() + exclude = ["Data"] if not args.doQCD else [] + prednames = list( + groups.getNames( + [d for d in datasets if d not in exclude], exclude=False, match_exact=True + ) + ) -histInfo = groups.groups + logger.info(f"Unstacked processes are {exclude}") + logger.info(f"Stacked processes are {prednames}") -select_utMinus = {"utAngleSign": s[0 : 1 : hist.sum]} -select_utPlus = {"utAngleSign": s[1 : 2 : hist.sum]} + s = hist.tag.Slicer() -groups.set_histselectors( - datasets, - "nominal", - smoothing_mode="full", - smoothingOrderSpectrum=3, - smoothingPolynomialSpectrum="chebyshev", - integrate_x=all("mt" not in x.split("-") for x in ["pt"]), - mode="extended1D", - forceGlobalScaleFakes=None, - mcCorr=[None], -) + histInfo = groups.groups -groups.setNominalName("nominal") -groups.loadHistsForDatagroups( - "nominal", syst="", procsToRead=datasets, applySelection=True -) + select_utMinus = {transfer_variable: s[0 : 1 : hist.sum]} + select_utPlus = {transfer_variable: s[1 : 2 : hist.sum]} -hnomi = histInfo[datasets[0]].hists["nominal"] -nPtBins = hnomi.axes["pt"].size -ptEdges = hnomi.axes["pt"].edges -nEtaBins = hnomi.axes["eta"].size -etaEdges = hnomi.axes["eta"].edges -nChargeBins = hnomi.axes["charge"].size -chargeEdges = hnomi.axes["charge"].edges -ptBinCenters = [round((ptEdges[i + 1] + ptEdges[i]) / 2, 1) for i in range(nPtBins)] - -eta_genBinning = array("d", [round(x, 1) for x in etaEdges]) -pt_genBinning = array("d", [round(x, 0) for x in ptEdges]) -charge_genBinning = array("d", chargeEdges) - -delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins -delta_ch = (charge_genBinning[-1] - charge_genBinning[0]) / args.nChargeBins - -decorrBins_eta = [ - ( - round((eta_genBinning[0] + i * delta_eta), 1), - round((eta_genBinning[0] + (i + 1) * delta_eta), 1), - ) - for i in range(args.nEtaBins) -] -decorrBins_ch = [ - ( - round((charge_genBinning[0] + i * delta_ch), 1), - round((charge_genBinning[0] + (i + 1) * delta_ch), 1), + groups.set_histselectors( + datasets, + "nominal", + smoothing_mode="full", + smoothingOrderSpectrum=3, + smoothingPolynomialSpectrum="chebyshev", + integrate_x=all("mt" not in x.split("-") for x in ["pt"]), + mode="extended1D", + forceGlobalScaleFakes=None, + mcCorr=[None], ) - for i in range(args.nChargeBins) -] - -logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") -logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") - -out_hist_nomi = hist.Hist( - hist.axis.Regular( - len(etaEdges) - 1, etaEdges[0], etaEdges[-1], name="eta", flow=False - ), - hist.axis.Regular(len(ptEdges) - 1, ptEdges[0], ptEdges[-1], name="pt", flow=False), - hist.axis.Regular( - len(chargeEdges) - 1, chargeEdges[0], chargeEdges[-1], name="charge", flow=False - ), - # hist.axis.Regular(2, -2.0, 2.0, name="utAngleSign") - storage=hist.storage.Weight(), -) -outNomi = out_hist_nomi.view() - -out_hist_altStat = hist.Hist( - *out_hist_nomi.axes, - # FIXME: why not starting from -0.5 such that the first bin is centered at 0? - hist.axis.Regular( - 6, -1.5, 4.5, name="varTF" - ), # 1 inclusive variation (first bin), plus the other 5 - storage=hist.storage.Weight(), -) -outAltStat = out_hist_altStat.view() -if args.addClosure: - out_hist_closQCDsv = hist.Hist(*out_hist_nomi.axes, storage=hist.storage.Weight()) - out_hist_closQCDsignal = hist.Hist( - *out_hist_nomi.axes, storage=hist.storage.Weight() + groups.setNominalName("nominal") + groups.loadHistsForDatagroups( + "nominal", syst="", procsToRead=datasets, applySelection=True ) -else: - out_hist_closQCDsv, out_hist_closQCDsignal = None, None -out_info = {} + hnomi = histInfo[datasets[0]].hists["nominal"] + nPtBins = hnomi.axes["pt"].size + ptEdges = hnomi.axes["pt"].edges + nEtaBins = hnomi.axes["eta"].size + etaEdges = hnomi.axes["eta"].edges + nChargeBins = hnomi.axes["charge"].size + chargeEdges = hnomi.axes["charge"].edges + ptBinCenters = [ + round(0.5 * (ptEdges[i + 1] + ptEdges[i]), 1) for i in range(nPtBins) + ] -for ch_edges in decorrBins_ch: - for eta_edges in decorrBins_eta: + eta_genBinning = array("d", [round(x, 1) for x in etaEdges]) + pt_genBinning = array("d", [round(x, 0) for x in ptEdges]) + charge_genBinning = array("d", chargeEdges) - ch_low_idx, ch_high_idx = convert_binEdges_idx(ch_edges, charge_genBinning) - eta_low_idx, eta_high_idx = convert_binEdges_idx(eta_edges, eta_genBinning) + delta_eta = (eta_genBinning[-1] - eta_genBinning[0]) / args.nEtaBins + delta_ch = (charge_genBinning[-1] - charge_genBinning[0]) / args.nChargeBins - logger.info(f"{ch_low_idx}, {ch_high_idx}") - logger.info(f"{eta_low_idx}, {eta_high_idx}") + decorrBins_eta = [ + ( + round((eta_genBinning[0] + i * delta_eta), 1), + round((eta_genBinning[0] + (i + 1) * delta_eta), 1), + ) + for i in range(args.nEtaBins) + ] + decorrBins_ch = [ + ( + round((charge_genBinning[0] + i * delta_ch), 1), + round((charge_genBinning[0] + (i + 1) * delta_ch), 1), + ) + for i in range(args.nChargeBins) + ] - select_utMinus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] - select_utMinus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] + logger.info(f"Decorrelating in the eta bins: {decorrBins_eta}") + logger.info(f"Decorrelating in the charge bins: {decorrBins_ch}") - select_utPlus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] - select_utPlus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] + out_hist_nomi = hist.Hist( + hist.axis.Regular( + len(etaEdges) - 1, etaEdges[0], etaEdges[-1], name="eta", flow=False + ), + hist.axis.Regular( + len(ptEdges) - 1, ptEdges[0], ptEdges[-1], name="pt", flow=False + ), + hist.axis.Regular( + len(chargeEdges) - 1, + chargeEdges[0], + chargeEdges[-1], + name="charge", + flow=False, + ), + # hist.axis.Regular(2, -2.0, 2.0, name=transfer_variable) + storage=hist.storage.Weight(), + ) + outNomi = out_hist_nomi.view() + + out_hist_altStat = hist.Hist( + *out_hist_nomi.axes, + # FIXME: why not starting from -0.5 such that the first bin is centered at 0? + hist.axis.Regular( + 6, -1.5, 4.5, name="varTF" + ), # 1 inclusive variation (first bin), plus the other 5 + storage=hist.storage.Weight(), + ) + outAltStat = out_hist_altStat.view() - logger.info(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") + if args.addClosure: + out_hist_closQCDsv = hist.Hist( + *out_hist_nomi.axes, storage=hist.storage.Weight() + ) + out_hist_closQCDsignal = hist.Hist( + *out_hist_nomi.axes, storage=hist.storage.Weight() + ) + else: + out_hist_closQCDsv, out_hist_closQCDsignal = None, None - boost_h_utMinus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] - boost_h_utMinus = boost_h_utMinus[select_utMinus] - boost_h_utMinus = hh.projectNoFlow(boost_h_utMinus, ["pt"], ["relIso", "mt"]) - root_h_utMinus = narf.hist_to_root(boost_h_utMinus) + out_info = {} - boost_h_utPlus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] - boost_h_utPlus = boost_h_utPlus[select_utPlus] - boost_h_utPlus = hh.projectNoFlow(boost_h_utPlus, ["pt"], ["relIso", "mt"]) - root_h_utPlus = narf.hist_to_root(boost_h_utPlus) + for ch_edges in decorrBins_ch: + for eta_edges in decorrBins_eta: - logger.debug(f"Integrals BEFORE prompt subraction (uT < 0, uT > 0)") - logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") + ch_low_idx, ch_high_idx = convert_binEdges_idx(ch_edges, charge_genBinning) + eta_low_idx, eta_high_idx = convert_binEdges_idx(eta_edges, eta_genBinning) - for mcName in prednames: - if args.doQCD: - continue - logger.debug(f"Subtracting {mcName} from data") - boost_h_mc_utMinus = ( - histInfo[mcName].copy(f"{mcName}_utMinus").hists["nominal"] - ) - boost_h_mc_utMinus = boost_h_mc_utMinus[select_utMinus] - boost_h_mc_utMinus = hh.projectNoFlow( - boost_h_mc_utMinus, ["pt"], ["relIso", "mt"] - ) - root_h_mc_utMinus = narf.hist_to_root(boost_h_mc_utMinus) - root_h_utMinus.Add(root_h_mc_utMinus, -1) + logger.info(f"{ch_low_idx}, {ch_high_idx}") + logger.info(f"{eta_low_idx}, {eta_high_idx}") - boost_h_mc_utPlus = ( - histInfo[mcName].copy(f"{mcName}_utPlus").hists["nominal"] - ) - boost_h_mc_utPlus = boost_h_mc_utPlus[select_utPlus] - boost_h_mc_utPlus = hh.projectNoFlow( - boost_h_mc_utPlus, ["pt"], ["relIso", "mt"] + select_utMinus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] + select_utMinus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] + + select_utPlus["charge"] = s[ch_low_idx : ch_high_idx : hist.sum] + select_utPlus["eta"] = s[eta_low_idx : eta_high_idx : hist.sum] + + logger.info(f"Processing charge bin [{ch_edges}] and eta bin [{eta_edges}]") + + boost_h_utMinus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] + boost_h_utMinus = boost_h_utMinus[select_utMinus] + boost_h_utMinus = hh.projectNoFlow( + boost_h_utMinus, ["pt"], ["relIso", "mt"] ) - root_h_mc_utPlus = narf.hist_to_root(boost_h_mc_utPlus) - root_h_utPlus.Add(root_h_mc_utPlus, -1) + root_h_utMinus = narf.hist_to_root(boost_h_utMinus) + + boost_h_utPlus = histInfo[proc].copy(f"{proc}_utMinus").hists["nominal"] + boost_h_utPlus = boost_h_utPlus[select_utPlus] + boost_h_utPlus = hh.projectNoFlow(boost_h_utPlus, ["pt"], ["relIso", "mt"]) + root_h_utPlus = narf.hist_to_root(boost_h_utPlus) + + logger.debug(f"Integrals BEFORE prompt subraction (uT < 0, uT > 0)") + logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") + + for mcName in prednames: + if args.doQCD: + continue + logger.debug(f"Subtracting {mcName} from data") + boost_h_mc_utMinus = ( + histInfo[mcName].copy(f"{mcName}_utMinus").hists["nominal"] + ) + boost_h_mc_utMinus = boost_h_mc_utMinus[select_utMinus] + boost_h_mc_utMinus = hh.projectNoFlow( + boost_h_mc_utMinus, ["pt"], ["relIso", "mt"] + ) + root_h_mc_utMinus = narf.hist_to_root(boost_h_mc_utMinus) + root_h_utMinus.Add(root_h_mc_utMinus, -1) - logger.debug(f"Integrals AFTER prompt subraction (uT < 0, uT > 0)") - logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") + boost_h_mc_utPlus = ( + histInfo[mcName].copy(f"{mcName}_utPlus").hists["nominal"] + ) + boost_h_mc_utPlus = boost_h_mc_utPlus[select_utPlus] + boost_h_mc_utPlus = hh.projectNoFlow( + boost_h_mc_utPlus, ["pt"], ["relIso", "mt"] + ) + root_h_mc_utPlus = narf.hist_to_root(boost_h_mc_utPlus) + root_h_utPlus.Add(root_h_mc_utPlus, -1) - ratio_h = root_h_utMinus.Clone(f"fakeRatio_utAngleSign_TH1") - ratio_h.Sumw2() - ratio_h.Divide(root_h_utPlus) + logger.debug(f"Integrals AFTER prompt subraction (uT < 0, uT > 0)") + logger.debug(f"{root_h_utMinus.Integral()}, {root_h_utPlus.Integral()}") - ratio_h_boost = narf.root_to_hist(ratio_h) + ratio_h = root_h_utMinus.Clone(f"fakeRatio_{transfer_variable}_TH1") + ratio_h.Sumw2() + ratio_h.Divide(root_h_utPlus) - sel = ( - slice(eta_low_idx, eta_high_idx), - slice(None), - slice(ch_low_idx, ch_high_idx), - ) + ratio_h_boost = narf.root_to_hist(ratio_h) - if args.noSmoothing: - outNomi.value[sel] = np.broadcast_to( - ratio_h_boost.values()[None, :, None], - (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), - ) - outNomi.variance[sel] = np.broadcast_to( - ratio_h_boost.variances()[None, :, None], - (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + sel = ( + slice(eta_low_idx, eta_high_idx), + slice(None), + slice(ch_low_idx, ch_high_idx), ) - else: - fitRes, nomiVals, altVals_all, altVals_sep = smoothTF( - ratio_h_boost, - ptBinCenters, - xLowVal=ptEdges[0], - xFitRange=(ptEdges[-1] - ptEdges[0]), - ) + if args.noSmoothing: + outNomi.value[sel] = np.broadcast_to( + ratio_h_boost.values()[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) + outNomi.variance[sel] = np.broadcast_to( + ratio_h_boost.variances()[None, :, None], + (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), + ) - outNomi.value[sel] = np.broadcast_to( - nomiVals[None, :, None], - (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), - ) + else: + fitRes, nomiVals, altVals_all, altVals_sep = smoothTF( + ratio_h_boost, + ptBinCenters, + xLowVal=ptEdges[0], + xFitRange=(ptEdges[-1] - ptEdges[0]), + ) - outAltStat.value[sel + (0,)] = ( - np.broadcast_to( - altVals_all[None, :, None], + outNomi.value[sel] = np.broadcast_to( + nomiVals[None, :, None], (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), ) - / outNomi.value[sel] - ) - # TODO: now have 5 parameters for pol4, can generalize to polN - for iv in range(1, 6): - outAltStat.value[sel + (iv,)] = ( + outAltStat.value[sel + (0,)] = ( np.broadcast_to( - altVals_sep[iv - 1][None, :, None], + altVals_all[None, :, None], (eta_high_idx - eta_low_idx, nPtBins, ch_high_idx - ch_low_idx), ) / outNomi.value[sel] ) - if args.addClosure: - - logger.debug("Elaborating corrections evaluated on QCD... ") - logger.debug( - "... be sure that the files are present and the TF has been already smoothed!" - ) - - path_corr_QCD_sv = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_QCD.pkl.lz4" - path_corr_QCD_signal = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_signalRegion_QCD.pkl.lz4" - - if os.path.exists(path_corr_QCD_sv): - with lz4.frame.open(path_corr_QCD_sv) as fTens: - hist_corr_QCDsv = pickle.load(fTens)["fakeCorr"] - out_hist_closQCDsv.values()[sel] = ( - hist_corr_QCDsv[sel].values() / outNomi.value[sel] - ) - else: - logger.warning( - "File with TF correction on QCD (SV region) not found! Skipping..." + # TODO: now have 5 parameters for pol4, can generalize to polN + for iv in range(1, 6): + outAltStat.value[sel + (iv,)] = ( + np.broadcast_to( + altVals_sep[iv - 1][None, :, None], + ( + eta_high_idx - eta_low_idx, + nPtBins, + ch_high_idx - ch_low_idx, + ), + ) + / outNomi.value[sel] ) - out_hist_closQCDsv = None - - if os.path.exists(path_corr_QCD_signal) and out_hist_closQCDsv: - with lz4.frame.open(path_corr_QCD_signal) as fTens: - hist_corr_QCDsignal = pickle.load(fTens)["fakeCorr"] - out_hist_closQCDsignal.values()[sel] = ( - hist_corr_QCDsignal[sel].values() - / hist_corr_QCDsv[sel].values() - ) - else: - logger.warning( - "File with TF correction on QCD (signal region) not found! Skipping..." - ) - out_hist_closQCDsignal = None - -resultDict = { - "fakeCorr": out_hist_nomi, -} - -if args.noSmoothing is False: - resultDict.update({"fakeCorr_altStat": out_hist_altStat}) -if out_hist_closQCDsv: - resultDict.update({"fakeCorr_closQCDsv": out_hist_closQCDsv}) -if out_hist_closQCDsignal: - resultDict.update({"fakeCorr_closQCDsignal": out_hist_closQCDsignal}) - -resultDict.update( - {"meta_info": wums.output_tools.make_meta_info_dict(args=args, wd=common.base_dir)} -) + if args.addClosure: -if args.plotdir is not None: - - outRootNomi = narf.hist_to_root(out_hist_nomi.copy()) + logger.debug("Elaborating corrections evaluated on QCD... ") + logger.debug( + "... be sure that the files are present and the TF has been already smoothed!" + ) - plotdir_original = args.plotdir - plotdir = createPlotDirAndCopyPhp(plotdir_original, eoscp=args.eoscp) - hists_corr = [] - legEntries = [] - etaID = 0 - # for 1D plots - canvas1D = ROOT.TCanvas("canvas1D", "", 800, 900) - adjustSettings_CMS_lumi() - idxs_ch = [0] if args.nChargeBins == 1 else [1, 2] - idxs_eta = ( - [0] - if args.nEtaBins == 1 - else [(1 + int(48 * i / args.nEtaBins)) for i in range(args.nEtaBins)] + path_corr_QCD_sv = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_QCD.pkl.lz4" + path_corr_QCD_signal = f"{common.data_dir}/fakesWmass/test/fakeTransferTemplates_signalRegion_QCD.pkl.lz4" + + if os.path.exists(path_corr_QCD_sv): + with lz4.frame.open(path_corr_QCD_sv) as fTens: + hist_corr_QCDsv = pickle.load(fTens)["fakeCorr"] + out_hist_closQCDsv.values()[sel] = ( + hist_corr_QCDsv[sel].values() / outNomi.value[sel] + ) + else: + logger.warning( + "File with TF correction on QCD (SV region) not found! Skipping..." + ) + out_hist_closQCDsv = None + + if os.path.exists(path_corr_QCD_signal) and out_hist_closQCDsv: + with lz4.frame.open(path_corr_QCD_signal) as fTens: + hist_corr_QCDsignal = pickle.load(fTens)["fakeCorr"] + out_hist_closQCDsignal.values()[sel] = ( + hist_corr_QCDsignal[sel].values() + / hist_corr_QCDsv[sel].values() + ) + else: + logger.warning( + "File with TF correction on QCD (signal region) not found! Skipping..." + ) + out_hist_closQCDsignal = None + + resultDict = { + "fakeCorr": out_hist_nomi, + } + + if args.noSmoothing is False: + resultDict.update({"fakeCorr_altStat": out_hist_altStat}) + if out_hist_closQCDsv: + resultDict.update({"fakeCorr_closQCDsv": out_hist_closQCDsv}) + if out_hist_closQCDsignal: + resultDict.update({"fakeCorr_closQCDsignal": out_hist_closQCDsignal}) + + resultDict.update( + { + "meta_info": wums.output_tools.make_meta_info_dict( + args=args, wd=common.base_dir + ) + } ) - for ieta in idxs_eta: - etamu = "#eta^{#mu}" - etaleg = ( - f"{decorrBins_eta[etaID][0]} < {etamu} < {decorrBins_eta[etaID][1]}" - if len(idxs_eta) != 1 - else "" + + if args.plotdir is not None: + + outRootNomi = narf.hist_to_root(out_hist_nomi.copy()) + + plotdir_original = args.plotdir + plotdir = createPlotDirAndCopyPhp(plotdir_original, eoscp=args.eoscp) + hists_corr = [] + legEntries = [] + etaID = 0 + # for 1D plots + canvas1D = ROOT.TCanvas("canvas1D", "", 800, 900) + adjustSettings_CMS_lumi() + idxs_ch = [0] if args.nChargeBins == 1 else [1, 2] + idxs_eta = ( + [0] + if args.nEtaBins == 1 + else [(1 + int(48 * i / args.nEtaBins)) for i in range(args.nEtaBins)] ) - etaID += 1 if len(idxs_eta) != 1 else 0 - for icharge in idxs_ch: - chargeleg = "#it{q}^{#mu} = " + ( - ("-1" if icharge == 1 else "+1") if len(idxs_ch) != 1 else "#pm 1" + for ieta in idxs_eta: + etamu = "#eta^{#mu}" + etaleg = ( + f"{decorrBins_eta[etaID][0]} < {etamu} < {decorrBins_eta[etaID][1]}" + if len(idxs_eta) != 1 + else "" ) - hists_corr.append( - outRootNomi.ProjectionY( - f"projPt_{ieta}_{icharge}", ieta, ieta, icharge, icharge + etaID += 1 if len(idxs_eta) != 1 else 0 + for icharge in idxs_ch: + chargeleg = "#it{q}^{#mu} = " + ( + ("-1" if icharge == 1 else "+1") if len(idxs_ch) != 1 else "#pm 1" + ) + hists_corr.append( + outRootNomi.ProjectionY( + f"projPt_{ieta}_{icharge}", ieta, ieta, icharge, icharge + ) + ) + legInfo = f"{etaleg}, {chargeleg}".lstrip() + legEntries.append( + legInfo + if legInfo != "" + else "TF integrated on #eta^{#mu}-#it{q}^{#mu}" ) - ) - legInfo = f"{etaleg}, {chargeleg}".lstrip() - legEntries.append( - legInfo if legInfo != "" else "TF integrated on #eta^{#mu}-#it{q}^{#mu}" - ) - miny, maxy = getMinMaxMultiHisto(hists_corr) - if miny < 0: - miny = 0 - maxy = 1.4 * (maxy - miny) - plotfilename = "correction_uT_vs_pT_eta_charge" - if args.postfix: - plotfilename += f"_{args.postfix}" - drawNTH1( - hists_corr, - legEntries, - "#it{p}_{T}^{#mu}", - "Correction: #it{u}_{T}^{#mu} > 0 #rightarrow #it{u}_{T}^{#mu} < 0" - + f"::{miny},{maxy}", - plotfilename, - plotdir, - lowerPanelHeight=0.4, - legendCoords=( - "0.4,0.98,0.74,0.92" if len(idxs_ch) == 1 else "0.16,0.98,0.74,0.92;2" - ), - labelRatioTmp="Ratio to first::0.2,1.8", - topMargin=0.06, - rightMargin=0.02, - drawLumiLatex=True, - onlyLineColor=True, - useLineFirstHistogram=True, - drawErrorAll=True, - yAxisExtendConstant=1.0, - ) + miny, maxy = getMinMaxMultiHisto(hists_corr) + if miny < 0: + miny = 0 + maxy = 1.4 * (maxy - miny) + plotfilename = "correction_uT_vs_pT_eta_charge" + if args.postfix: + plotfilename += f"_{args.postfix}" + drawNTH1( + hists_corr, + legEntries, + "#it{p}_{T}^{#mu}", + "Correction: #it{u}_{T}^{#mu} > 0 #rightarrow #it{u}_{T}^{#mu} < 0" + + f"::{miny},{maxy}", + plotfilename, + plotdir, + lowerPanelHeight=0.4, + legendCoords=( + "0.4,0.98,0.74,0.92" if len(idxs_ch) == 1 else "0.16,0.98,0.74,0.92;2" + ), + labelRatioTmp="Ratio to first::0.2,1.8", + topMargin=0.06, + rightMargin=0.02, + drawLumiLatex=True, + onlyLineColor=True, + useLineFirstHistogram=True, + drawErrorAll=True, + yAxisExtendConstant=1.0, + ) + + copyOutputToEos(plotdir, plotdir_original, eoscp=args.eoscp) - copyOutputToEos(plotdir, plotdir_original, eoscp=args.eoscp) - - -outfileName = "fakeTransferTemplates" -if args.postfix: - outfileName += f"_{args.postfix}" -if args.doQCD: - outfileName += "_QCD" -# if args.noSmoothing: -# outfileName += "_noSmoothing" - -pklfileName = f"{args.outdir}/{outfileName}.pkl.lz4" -with lz4.frame.open(pklfileName, "wb") as fout: - pickle.dump(resultDict, fout, protocol=pickle.HIGHEST_PROTOCOL) -logger.info(f"Created file {pklfileName}") - -rootfileName = f"{args.outdir}/{outfileName}.root" -fout = safeOpenFile(rootfileName, mode="RECREATE") -ratio_h.Write() - -outRootNomi = narf.hist_to_root(out_hist_nomi.copy()[(1, slice(None), 1)]) -outRootNomi.SetName("fakeCorr_Nominal") -outRootNomi.Write() -outRootAltStat_all = narf.hist_to_root(out_hist_altStat.copy()[(0, slice(None), 0, 0)]) -outRootAltStat_all.SetName("fakeCorr_altStat_all") -outRootAltStat_all.Write() -if args.addClosure: - outClosSV = narf.hist_to_root(out_hist_closQCDsv.copy()[(0, slice(None), 0)]) - outClosSV.SetName("fakeCorr_closure_QCDsv") - outClosSV.Write() - outClosSignal = narf.hist_to_root( - out_hist_closQCDsignal.copy()[(0, slice(None), 0)] + outfileName = "fakeTransferTemplates" + if args.postfix: + outfileName += f"_{args.postfix}" + if args.doQCD: + outfileName += "_QCD" + # if args.noSmoothing: + # outfileName += "_noSmoothing" + + pklfileName = f"{args.outdir}/{outfileName}.pkl.lz4" + with lz4.frame.open(pklfileName, "wb") as fout: + pickle.dump(resultDict, fout, protocol=pickle.HIGHEST_PROTOCOL) + logger.info(f"Created file {pklfileName}") + + rootfileName = f"{args.outdir}/{outfileName}.root" + fout = safeOpenFile(rootfileName, mode="RECREATE") + ratio_h.Write() + + outRootNomi = narf.hist_to_root(out_hist_nomi.copy()[(1, slice(None), 1)]) + outRootNomi.SetName("fakeCorr_Nominal") + outRootNomi.Write() + outRootAltStat_all = narf.hist_to_root( + out_hist_altStat.copy()[(0, slice(None), 0, 0)] ) - outClosSignal.SetName("fakeCorr_closure_QCDsignal") - outClosSignal.Write() + outRootAltStat_all.SetName("fakeCorr_altStat_all") + outRootAltStat_all.Write() + if args.addClosure: + outClosSV = narf.hist_to_root(out_hist_closQCDsv.copy()[(0, slice(None), 0)]) + outClosSV.SetName("fakeCorr_closure_QCDsv") + outClosSV.Write() + outClosSignal = narf.hist_to_root( + out_hist_closQCDsignal.copy()[(0, slice(None), 0)] + ) + outClosSignal.SetName("fakeCorr_closure_QCDsignal") + outClosSignal.Write() -fout.Close() -logger.info(f"Created file {rootfileName}") + fout.Close() + logger.info(f"Created file {rootfileName}") diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 589def3fc..f8e9ef10c 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -475,6 +475,14 @@ axis_dphi_fakes = hist.axis.Regular( 8, 0.0, np.pi, name="DphiMuonMet", underflow=False, overflow=False ) +axis_dxybs = hist.axis.Regular( + int(args.dxybs / 0.002), + 0.0, + args.dxybs, + name="dxybs", + underflow=False, + overflow=True, +) axis_hasjet_fakes = hist.axis.Boolean( name="hasJets" ) # only need case with 0 jets or > 0 for now @@ -487,6 +495,22 @@ axis_hasjet_fakes, axis_dphi_fakes, ] +mTStudyForFakes_axes_dxybs = [ + axis_eta, + axis_pt, + axis_charge, + axis_dxybs, + axis_passIso, + axis_passMT, +] +mTStudyForFakes_axes_uTAngleCosine = [ + axis_eta, + axis_pt, + axis_charge, + axis_mt_fakes, + axis_passIso, + axis_uTAngleCosine, +] axis_met = hist.axis.Regular( 100, 0.0, 200.0, name="met", underflow=False, overflow=True @@ -1385,7 +1409,7 @@ def build_graph(df, dataset): ) df = df.Define( "smearMET_phi", - "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_phi, 1.0, 0.05)", + "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_phi, 1.0, 0.05, 1)", ) df = df.Define( "transverseMass_scaleMET_pt", @@ -1682,6 +1706,12 @@ def build_graph(df, dataset): # instead of passIso in mTStudyForFakes # df = df.Define("passIsoAlt", "(goodMuons_pfRelIso04_all0 * Muon_pt[goodMuons][0] / goodMuons_jetpt0) < 0.12") # df = df.Define("passIsoAlt", "(Muon_vtxAgnPfRelIso04_chg[goodMuons][0] * Muon_pt[goodMuons][0]) < 5.0") + # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 + # for convenience in the later study + df = df.Define( + "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" + ) + mTStudyForFakes = df.HistoBoost( "mTStudyForFakes", mTStudyForFakes_axes, @@ -1698,12 +1728,46 @@ def build_graph(df, dataset): ) results.append(mTStudyForFakes) + mTStudyForFakes_dxybs = df.HistoBoost( + "mTStudyForFakes_dxybs", + mTStudyForFakes_axes_dxybs, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_dxybs0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakes_dxybs) + + mTStudyForFakes_uTAngleCosine = df.HistoBoost( + "mTStudyForFakes_uTAngleCosine", + mTStudyForFakes_axes_uTAngleCosine, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "transverseMass", + "passIso", + "goodMuons_angleCosineUt0", + "nominal_weight", + ], + ) + results.append(mTStudyForFakes_uTAngleCosine) + if not dataset.is_data: # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) df = df.Define( "goodMuons_utGenMet0", "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", ) + df = df.Define( + "goodMuons_utReso0", + "(goodMuons_utGenMet0 != 0) ? (goodMuons_utReco0 / goodMuons_utGenMet0) : 0.0", + ) df = df.Define( "goodMuons_angleCosineUtGenMet0", "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", @@ -1720,6 +1784,9 @@ def build_graph(df, dataset): axis_ut_genMet = hist.axis.Variable( ut_bins, name="ut_genMet", underflow=True, overflow=True ) + axis_ut_reso = hist.axis.Regular( + 100, -2, 2, name="ut_reso", underflow=True, overflow=True + ) axis_uTAngleCosineGenMet = hist.axis.Regular( 20, -1, 1, name="uTAngleCosineGenMet", overflow=False, underflow=False ) @@ -1768,6 +1835,50 @@ def build_graph(df, dataset): ) results.append(etaPtUtAngleCosineGenUtAngleCosine) # + etaPtUtResoUt = df.HistoBoost( + "etaPtUtResoUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utReco0", + "goodMuons_utReso0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtResoUt) + # + etaPtUtResoGenUt = df.HistoBoost( + "etaPtUtResoGenUt", + [ + axis_eta, + axis_pt, + axis_ut_genMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utGenMet0", + "goodMuons_utReso0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtResoGenUt) + # # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 6639ddedd..e73e7f217 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -17,7 +17,8 @@ from wremnants.postprocessing.histselections import FakeSelectorSimpleABCD from wremnants.postprocessing.regression import Regressor from wremnants.postprocessing.syst_tools import ( - add_nonprompt_transfer_factor_variations, + fake_nonclosure_byAxis, + fake_transferFactor_ptSyst, scale_hist_up_down, scale_hist_up_down_corr_from_file, ) @@ -460,6 +461,24 @@ def make_parser(parser=None): help="Axes for the fakerate binning", default=["eta", "pt", "charge"], ) + parser.add_argument( + "--fakeTransferAxis", + type=str, + default="utAngleSign", + help=""" + Axis where the fake prediction on non-valid bins (i.e. where the A-Ax-B-Bx regions are empty) + is estimated by using the other 'valid' bins of this axis, via a normalization or shape reweighting.""", + ) + parser.add_argument( + "--fakeTransferCorrFileName", + type=str, + default="fakeTransferTemplates_smoothTF", + help=""" + Name of pkl.lz4 file (without extension) with pTmu correction for the shape of data-driven fakes. + Currently used only when utAngleSign is a fakerate axis (detected automatically), since the shape + at negative uTmu must be taken from positive bin, but a shape correction is needed versus pTmu. + """, + ) parser.add_argument( "--fakeEstimation", type=str, @@ -502,15 +521,11 @@ def make_parser(parser=None): help="Type of polynomial for the smoothing of the application region or full prediction, depending on the smoothing mode", ) parser.add_argument( - "--fakeTransferCorrFileName", - type=str, - default="fakeTransferTemplates_smoothTF", - help=""" - Name of pkl.lz4 file (without extension) with pTmu correction for the shape of data-driven fakes. - Currently used only when utAngleSign is a fakerate axis (detected automatically), since the shape - at negative uTmu must be taken from positive bin, but a shape correction is needed versus pTmu. - """, + "--addCustomRecoilSyst", + action="store_true", + help="Add custom recoil systematic uncertainties from smearing met pt/phi and scaling met pt", ) + parser.add_argument( "--ABCDedgesByAxis", type=str, @@ -1230,7 +1245,7 @@ def setup( if wmass and not datagroups.xnorm: datagroups.fakerate_axes = args.fakerateAxes - # datagroups.fakeTransferAxis = "utAngleSign" if "utAngleSign" in args.fakerateAxes else "" + # datagroups.fakeTransferAxis = args.fakeTransferAxis if args.fakeTransferAxis in args.fakerateAxes else "" # datagroups.fakeTransferCorrFileName = args.fakeTransferCorrFileName histselector_kwargs = dict( mode=args.fakeEstimation, @@ -1242,7 +1257,9 @@ def setup( forceGlobalScaleFakes=args.forceGlobalScaleFakes, abcdExplicitAxisEdges=abcdExplicitAxisEdges, fakeTransferAxis=( - "utAngleSign" if "utAngleSign" in args.fakerateAxes else "" + args.fakeTransferAxis + if args.fakeTransferAxis in args.fakerateAxes + else "" ), fakeTransferCorrFileName=args.fakeTransferCorrFileName, histAxesRemovedBeforeFakes=( @@ -2189,6 +2206,7 @@ def fake_nonclosure( param_idx=1, variation_size=0.5, normalize=False, + fakeselector=None, *args, **kwargs, ): @@ -2268,6 +2286,7 @@ def fake_nonclosure( axesToDecorrNames=axesToDecorrNames, param_idx=idx, variation_size=mag, + fakeselector=fakeselector, ), systAxes=( ["var"] @@ -2285,42 +2304,6 @@ def fake_nonclosure( for sel in ["utAngleSign 1 2", "utAngleSign 0 1"] ) ): - # TODO: extend and use previous function fake_nonclosure(...) - # TODO: move function elsewhere - def fake_nonclosure_byAxis( - h, - axesToDecorrNames=["eta"], - variation_size=0.1, - keepConstantAxisBin={}, - *args, - **kwargs, - ): - - # with keepConstantAxisBin one can keep a range of bins untouched by passing slice(start, stop) - # e.g. keepConstantAxisBin={"utAngleSign": slice(1, 2)}, maybe also by values with complex numbers - - logger.info( - f"Doing decorr nonclosure with keepConstantAxisBin={keepConstantAxisBin}" - ) - hnom = fakeselector.get_hist(h, *args, **kwargs) - hvar = (1 + variation_size) * hnom - if keepConstantAxisBin: - ax_names = [n for n in hvar.axes.name] - idxs = [slice(None)] * hvar.ndim - for name in keepConstantAxisBin.keys(): - if name not in ax_names: - raise ValueError( - f"In fake_nonclosure_byAxis(): axis '{name}' not found in hvar, valid names are {ax_names}" - ) - ax_index = ax_names.index(name) - idxs[ax_index] = keepConstantAxisBin[name] - hvar.values()[tuple(idxs)] = hnom.values()[tuple(idxs)] - - hvar = rabbit_helpers.decorrelateByAxes( - hvar, hnom, axesToDecorrNames - ) - - return hvar datagroups.addSystematic( inputBaseName, @@ -2337,59 +2320,11 @@ def fake_nonclosure_byAxis( axesToDecorrNames=["eta"], variation_size=0.1, keepConstantAxisBin={"utAngleSign": 1}, + fakeselector=fakeselector, ), systAxes=["eta_decorr"], ) - # TODO: move function elsewhere - def fake_transferFactor_ptSyst( - h, - axesToDecorrNames=[], - altHistName="fakeCorr_altStat", - varIdxs=[0], - correctionFile="", - *args, - **kwargs, - ): - hnom = fakeselector.get_hist(h, *args, **kwargs) - - ax_names = [n for n in hnom.axes.name] - sel_var = [slice(None)] * hnom.ndim - sel_const = [slice(None)] * hnom.ndim - sel_var[ax_names.index(datagroups.fakeTransferAxis)] = 0 - sel_const[ax_names.index(datagroups.fakeTransferAxis)] = 1 - - hvar = add_nonprompt_transfer_factor_variations( - hnom.copy(), - correctionFile, - altHistName, - sel_var, - varIdxs=varIdxs, - ) - - hvar_utPlus = hnom.copy()[tuple(sel_const)] - - if varIdxs[0] != -1: - hvar.values()[ - tuple([*sel_const, slice(None), slice(None)]) - ] = hvar_utPlus.values()[..., None, None] - else: - hvar.values()[ - tuple([*sel_const, slice(None)]) - ] = hvar_utPlus.values()[..., None] - - if len(axesToDecorrNames) > 0: - hvar = rabbit_helpers.decorrelateByAxes( - hvar, - hnom, - axesToDecorrNames, - newDecorrAxesNames=[ - f"{x}_decorr" for x in axesToDecorrNames - ], - ) - - return hvar - ## TODO: move the following systematics in an imported file, once this is finalized datagroups.addSystematic( inputBaseName, @@ -2406,6 +2341,8 @@ def fake_transferFactor_ptSyst( altHistName="fakeCorr_altStat", varIdxs=[0], correctionFile=f"{common.data_dir}/fakesWmass/{args.fakeTransferCorrFileName}.pkl.lz4", + fakeselector=fakeselector, + fakeTransferAxis=datagroups.fakeTransferAxis, ), systAxes=["varTF", "downUpVar"], labelsByAxis=["varTF", "downUpVar"], @@ -2427,6 +2364,8 @@ def fake_transferFactor_ptSyst( # altHistName="fakeCorr_closQCDsv", # varIdxs = [], # correctionFile=f"{common.data_dir}/fakesWmass/{args.fakeTransferCorrFileName}.pkl.lz4", + # fakeselector=fakeselector, + # fakeTransferAxis=datagroups.fakeTransferAxis, # ), # systAxes=["downUpVar"], # labelsByAxis=["downUpVar"], @@ -2448,6 +2387,8 @@ def fake_transferFactor_ptSyst( altHistName="fakeCorr_closQCDsignal", varIdxs=[], correctionFile=f"{common.data_dir}/fakesWmass/{args.fakeTransferCorrFileName}.pkl.lz4", + fakeselector=fakeselector, + fakeTransferAxis=datagroups.fakeTransferAxis, ), systAxes=["downUpVar"], labelsByAxis=["downUpVar"], @@ -3003,53 +2944,52 @@ def fake_transferFactor_ptSyst( passToFakes=passSystToFakes, ) - # ad-hoc uncertainties for recoil, scaling and smearing met - datagroups.addSystematic( - "scaleMET_pt", - mirror=True, - processes=datagroups.allMCProcesses(), - groups=[ - "recoil_syst_tmp", - "recoil", - "experiment", - "expNoLumi", - "expNoCalib", - ], - # scale=0.1, - systAxes=[], - passToFakes=passSystToFakes, - ) - datagroups.addSystematic( - "smearMET_pt", - mirror=True, - processes=datagroups.allMCProcesses(), - groups=[ - "recoil_syst_tmp", - "recoil", - "experiment", - "expNoLumi", - "expNoCalib", - ], - # scale=0.5, - systAxes=[], - passToFakes=passSystToFakes, - ) - datagroups.addSystematic( - "smearMET_phi", - mirror=True, - processes=datagroups.allMCProcesses(), - groups=[ - "recoil_syst_tmp", - "recoil", - "experiment", - "expNoLumi", - "expNoCalib", - ], - # scale=0.5, - systAxes=[], - passToFakes=passSystToFakes, - ) - #### + if args.addCustomRecoilSyst: + datagroups.addSystematic( + "scaleMET_pt", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + # scale=0.1, + systAxes=[], + passToFakes=passSystToFakes, + ) + datagroups.addSystematic( + "smearMET_pt", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + # scale=0.5, + systAxes=[], + passToFakes=passSystToFakes, + ) + datagroups.addSystematic( + "smearMET_phi", + mirror=True, + processes=datagroups.allMCProcesses(), + groups=[ + "recoil_syst_tmp", + "recoil", + "experiment", + "expNoLumi", + "expNoCalib", + ], + scale=0.4, # from 5% -> scale * 5% for test (see histmaker) + systAxes=[], + passToFakes=passSystToFakes, + ) ## decorrelated momentum scale and resolution, when requested if not dilepton and "ptscale" in args.decorrSystByVar and decorr_syst_var in fitvar: diff --git a/wremnants/postprocessing/rabbit_helpers.py b/wremnants/postprocessing/rabbit_helpers.py index 852a07c41..ef82d061d 100644 --- a/wremnants/postprocessing/rabbit_helpers.py +++ b/wremnants/postprocessing/rabbit_helpers.py @@ -166,6 +166,20 @@ def add_recoil_uncertainty( systAxes=["recoil_unc"], passToFakes=passSystToFakes, ) + datagroups.addSystematic( + "recoil_syst", + processes=samples, + mirror=True, + groups=[ + "recoil", + "recoil_syst", + "experiment", + "expNoCalib", + "expNoLumi", + ], + systAxes=["recoil_unc"], + passToFakes=passSystToFakes, + ) if pu_type == "lowPU": group_compact = False diff --git a/wremnants/postprocessing/syst_tools.py b/wremnants/postprocessing/syst_tools.py index 28dcc2b42..eb5b5cee8 100644 --- a/wremnants/postprocessing/syst_tools.py +++ b/wremnants/postprocessing/syst_tools.py @@ -6,7 +6,7 @@ import lz4.frame import numpy as np -from wremnants.postprocessing import pdf_tools +from wremnants.postprocessing import pdf_tools, rabbit_helpers from wremnants.utilities import binning, samples, theory_utils from wums import boostHistHelpers as hh from wums import logging @@ -971,6 +971,41 @@ def scale_hist_up_down_corr_from_file(h, corr_file=None, corr_hist=None): return hVar +def fake_nonclosure_byAxis( + h, + axesToDecorrNames=["eta"], + variation_size=0.1, + keepConstantAxisBin={}, + fakeselector=None, + *args, + **kwargs, +): + + # with keepConstantAxisBin one can keep a range of bins untouched by passing slice(start, stop) + # e.g. keepConstantAxisBin={"utAngleSign": slice(1, 2)}, maybe also by values with complex numbers + + logger.info( + f"Doing decorr nonclosure with keepConstantAxisBin={keepConstantAxisBin}" + ) + hnom = fakeselector.get_hist(h, *args, **kwargs) + hvar = (1 + variation_size) * hnom + if keepConstantAxisBin: + ax_names = [n for n in hvar.axes.name] + idxs = [slice(None)] * hvar.ndim + for name in keepConstantAxisBin.keys(): + if name not in ax_names: + raise ValueError( + f"In fake_nonclosure_byAxis(): axis '{name}' not found in hvar, valid names are {ax_names}" + ) + ax_index = ax_names.index(name) + idxs[ax_index] = keepConstantAxisBin[name] + hvar.values()[tuple(idxs)] = hnom.values()[tuple(idxs)] + + hvar = rabbit_helpers.decorrelateByAxes(hvar, hnom, axesToDecorrNames) + + return hvar + + def add_nonprompt_transfer_factor_variations( h, corr_file, corr_histName, selection, varIdxs=[0] ): @@ -984,7 +1019,7 @@ def add_nonprompt_transfer_factor_variations( len(varIdxs), -0.5, -0.5 + len(varIdxs), flow=False, name="varTF" ) axes = [*h.axes, varIDaxis, binning.down_up_axis] - selVar = selection[slice(None), slice(None)] + selVar = selection + [slice(None), slice(None)] else: axes = [*h.axes, binning.down_up_axis] varIdxs.append(-1) @@ -1016,3 +1051,52 @@ def add_nonprompt_transfer_factor_variations( ) return hVar + + +def fake_transferFactor_ptSyst( + h, + axesToDecorrNames=[], + altHistName="fakeCorr_altStat", + varIdxs=[0], + correctionFile="", + fakeselector=None, + fakeTransferAxis="", + *args, + **kwargs, +): + hnom = fakeselector.get_hist(h, *args, **kwargs) + + ax_names = [n for n in hnom.axes.name] + sel_var = [slice(None)] * hnom.ndim + sel_const = [slice(None)] * hnom.ndim + sel_var[ax_names.index(fakeTransferAxis)] = 0 + sel_const[ax_names.index(fakeTransferAxis)] = 1 + + hvar = add_nonprompt_transfer_factor_variations( + hnom.copy(), + correctionFile, + altHistName, + sel_var, + varIdxs=varIdxs, + ) + + hvar_utPlus = hnom.copy()[tuple(sel_const)] + + if varIdxs[0] != -1: + hvar.values()[ + tuple([*sel_const, slice(None), slice(None)]) + ] = hvar_utPlus.values()[..., None, None] + else: + hvar.values()[tuple([*sel_const, slice(None)])] = hvar_utPlus.values()[ + ..., None + ] + + if len(axesToDecorrNames) > 0: + hvar = rabbit_helpers.decorrelateByAxes( + hvar, + hnom, + axesToDecorrNames, + newDecorrAxesNames=[f"{x}_decorr" for x in axesToDecorrNames], + ) + + return hvar diff --git a/wremnants/production/include/utils.hpp b/wremnants/production/include/utils.hpp index c967cfe90..9bd79d039 100644 --- a/wremnants/production/include/utils.hpp +++ b/wremnants/production/include/utils.hpp @@ -1108,7 +1108,8 @@ double get_scaled_smeared_variable(const unsigned int run, const unsigned int lumi, const unsigned long long event, const double var, const double scale = 1.0, - const double smear = 0.1) { + const double smear = 0.1, + const bool isPhiAngle = false) { // use scale=1.1 and smear=0.2 for 10% larger mean value and 20% resolution // smearing @@ -1116,9 +1117,18 @@ double get_scaled_smeared_variable(const unsigned int run, std::mt19937 rng(seq); double scaled_var = var * scale; - if (smear <= 0) + if (smear <= 0) { + // 0 is valid and equivalent to a dirac delta, negative should never happen return scaled_var; - std::normal_distribution dis(scaled_var, scaled_var * smear); + } + + std::normal_distribution dis(scaled_var, + std::abs(scaled_var * smear)); + if (isPhiAngle) { + // deal with angle in -pi, pi + double phi = dis(rng); + return std::atan2(std::sin(phi), std::cos(phi)); + } return dis(rng); } diff --git a/wremnants/utilities/common.py b/wremnants/utilities/common.py index 465c111e8..52b4d6d08 100644 --- a/wremnants/utilities/common.py +++ b/wremnants/utilities/common.py @@ -16,7 +16,7 @@ BR_TAUToE = 0.1782 Z_TAU_TO_LEP_RATIO = 1.0 - (1.0 - BR_TAUToMU - BR_TAUToE) ** 2 -# cross sections in pb at sqrt(s)=13Tev (TODO: add source information) +# cross sections in pb at sqrt(s)=13TeV (TODO: add source information) xsec_DYJetsToLL = 2001.9 xsec_WplusJetsToLNu = 11765.9 xsec_WminusJetsToLNu = 8703.87 diff --git a/wremnants/utilities/styles/styles.py b/wremnants/utilities/styles/styles.py index b86e76d7e..9345d14e0 100644 --- a/wremnants/utilities/styles/styles.py +++ b/wremnants/utilities/styles/styles.py @@ -363,6 +363,7 @@ def translate_html_to_latex(n): "muonCalibration", "Fake", "recoil_stat", + "recoil_syst", "recoil_syst_tmp", ], "width": common_groups @@ -378,6 +379,7 @@ def translate_html_to_latex(n): "massShift", "recoil_stat", "recoil_syst_tmp", + "recoil_syst", ], "min": common_groups + [ @@ -600,6 +602,7 @@ def translate_html_to_latex(n): "CMS_background": "Other bkg.", "recoil_stat": "recoil stat.", "recoil_syst_tmp": "recoil syst.", + "recoil_syst": "recoil syst.", "FakeHighMT": "FakeHighMT", "FakeLowMT": "FakeLowMT", "rFake": "fakerate", From aed50a97edc76611161627a1ed7a51d3c19b3e36 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 26 Mar 2026 12:22:25 +0100 Subject: [PATCH 40/46] moving definition of mass and width systs to rabbit_helpers --- scripts/rabbit/setupRabbit.py | 266 ++----------- wremnants/postprocessing/rabbit_helpers.py | 431 ++++++++++++++++----- 2 files changed, 357 insertions(+), 340 deletions(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 1fe669f9c..525b17092 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -323,6 +323,7 @@ def make_parser(parser=None): "zmass", "sin2thetaW", "wwidth", + "zwidth", "xsec", "massdiffW", "widthdiffW", @@ -1521,94 +1522,20 @@ def setup( add_to_data_covariance=datagroups.isAbsorbedNuisance(name), ) - decorwidth = args.decorMassWidth or ("wwidth" in args.noi) + decorwidth = args.decorMassWidth or any(x in args.noi for x in ["wwidth", "zwidth"]) if not (stat_only and constrainMass) and args.massVariation != 0: massVariation = 2.1 if (not wmass and constrainMass) else args.massVariation - massWeightName = ( - f"massWeight_widthdecor{label}" if decorwidth else f"massWeight{label}" - ) - mass_info = dict( - processes=signal_samples_forMass, - group=f"massShift", - noi=not constrainMass, - skipEntries=theory_utils.massWeightNames(proc=label, exclude=massVariation), - mirror=False, - noConstraint=not constrainMass, - systAxes=["massShift"], - passToFakes=passSystToFakes, + rabbit_helpers.add_V_mass_uncertainty( + datagroups, + signal_samples_forMass, + args, + passSystToFakes=passSystToFakes, + label=label, + massVariation=massVariation, + constrainMass=constrainMass, + decorwidth=decorwidth, ) - if args.breitwignerWMassWeights and label == "W": - preOpMap = {} - for group in ["Wmunu", "Wtaunu"]: - if group not in datagroups.groups.keys(): - continue - for member in datagroups.groups[group].members: - h_ref = datagroups.readHist( - datagroups.nominalName, member, massWeightName - ) - preOpMap[member.name] = ( - lambda h, h_ref=h_ref: rabbit_helpers.correct_bw_xsec(h, h_ref) - ) - - datagroups.addSystematic( - histname=f"breitwigner_{massWeightName}", - name=f"massWeight{label}", - preOpMap=preOpMap, - **mass_info, - ) - else: - if len(args.fitMassDecorr) == 0: - datagroups.addSystematic( - massWeightName, - **mass_info, - ) - else: - suffix = "".join([a.capitalize() for a in args.fitMassDecorr]) - new_names = [f"{a}_decorr" for a in args.fitMassDecorr] - datagroups.addSystematic( - histname=massWeightName, - processes=signal_samples_forMass, - name=f"massDecorr{suffix}{label}", - group=f"massDecorr{label}", - # systNameReplace=[("Shift",f"Diff{suffix}")], - skipEntries=[ - (x, *[-1] * len(args.fitMassDecorr)) - for x in theory_utils.massWeightNames( - proc=label, exclude=args.massVariation - ) - ], - noi=not constrainMass, - noConstraint=not constrainMass, - mirror=False, - systAxes=["massShift", *new_names], - passToFakes=passSystToFakes, - # isPoiHistDecorr is a special flag to deal with how the massShift variations are internally formed - isPoiHistDecorr=len(args.fitMassDecorr), - actionRequiresNomi=True, - action=rabbit_helpers.decorrelateByAxes, - actionArgs=dict( - axesToDecorrNames=args.fitMassDecorr, - newDecorrAxesNames=new_names, - axlim=args.decorrAxlim, - rebin=args.decorrRebin, - absval=args.decorrAbsval, - ), - ) - - if "massdiffW" in args.noi: - suffix = "".join([a.capitalize() for a in args.massDiffWVar.split("-")]) - rabbit_helpers.add_mass_diff_variations( - datagroups, - args.massDiffWVar, - name=massWeightName, - processes=signal_samples_forMass, - constrain=constrainMass, - suffix=suffix, - label=label, - passSystToFakes=passSystToFakes, - ) - # this appears within doStatOnly because technically these nuisances should be part of it if isPoiAsNoi: if isTheoryAgnostic: @@ -1686,11 +1613,9 @@ def setup( passSystToFakes=passSystToFakes, ) - if ("wwidth" in args.noi and not wmass) or ( + if ("zwidth" in args.noi and not wmass) or ( not datagroups.xnorm and not stat_only and not args.noTheoryUnc ): - # Experimental range - # widthVars = (42, ['widthW2p043GeV', 'widthW2p127GeV']) if wmass else (2.3, ['widthZ2p4929GeV', 'widthZ2p4975GeV']) # Variation from EW fit (mostly driven by alphas unc.) datagroups.addSystematic( "widthWeightZ", @@ -1701,132 +1626,22 @@ def setup( ), groups=["ZmassAndWidth" if wmass else "widthZ", "theory"], mirror=False, - noi="wwidth" in args.noi if not wmass else False, - noConstraint="wwidth" in args.noi if not wmass else False, + noi="zwidth" in args.noi if not wmass else False, + noConstraint="zwidth" in args.noi if not wmass else False, systAxes=["width"], systNameReplace=[["2p49333GeV", "Down"], ["2p49493GeV", "Up"]], passToFakes=passSystToFakes, ) + # TODO: move closer to W mass uncertainty? if wmass and ("wwidth" in args.noi or (not stat_only and not args.noTheoryUnc)): - widthVarTag = "" - if ( - args.widthVariationW[0] == args.widthVariationW[1] - and args.widthVariationW[0] == "0.6" - ): - widthVarTag = "WidthW0p6MeV" - width_info = dict( - name=widthVarTag, - skipEntries=theory_utils.widthWeightNames( - proc="W", exclude=(2.09053, 2.09173) - ), - systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], - ) - else: - widthLowValues = { - "0.6": "2.09053", - "6": "2.085", - "48": "2.043", - } - widthHighValues = { - "0.6": "2.09173", - "36": "2.127", - } - widthVarDown = args.widthVariationW[0].replace(".", "p") - widthVarUp = args.widthVariationW[1].replace(".", "p") - widthVarTag = f"WidthWm{widthVarDown}p{widthVarUp}MeV" - wlv = widthLowValues[args.widthVariationW[0]] - whv = widthHighValues[args.widthVariationW[1]] - wlvStr = wlv.replace(".", "p") + "GeV" - whvStr = whv.replace(".", "p") + "GeV" - width_info = dict( - name=widthVarTag, - skipEntries=theory_utils.widthWeightNames( - proc="W", exclude=(float(wlv), float(whv)) - ), - systNameReplace=[[wlvStr, "Down"], [whvStr, "Up"]], - ) - - width_info.update( - dict( - processes=signal_samples_forMass, - groups=["widthW", "theory"], - mirror=False, - noi="wwidth" in args.noi, - noConstraint="wwidth" in args.noi, - systAxes=["width"], - passToFakes=passSystToFakes, - ) + rabbit_helpers.add_W_width_uncertainty( + datagroups, + signal_samples_forMass, + args, + passSystToFakes=passSystToFakes, + label=label, ) - widthWeightName = f"widthWeight{label}" - if args.breitwignerWMassWeights: - preOpMap = {} - for group in ["Wmunu", "Wtaunu"]: - if group not in datagroups.groups.keys(): - continue - for member in datagroups.groups[group].members: - h_ref = datagroups.readHist( - datagroups.nominalName, member, widthWeightName - ) - preOpMap[member.name] = ( - lambda h, h_ref=h_ref: rabbit_helpers.correct_bw_xsec(h, h_ref) - ) - datagroups.addSystematic( - histname=f"breitwigner_{widthWeightName}", - preOpMap=preOpMap, - **width_info, - ) - else: - if len(args.fitWidthDecorr) == 0: - datagroups.addSystematic( - widthWeightName, - **width_info, - ) - else: - suffix = "".join([a.capitalize() for a in args.fitWidthDecorr]) - new_names = [f"{a}_decorr" for a in args.fitWidthDecorr] - datagroups.addSystematic( - histname=widthWeightName, - processes=signal_samples_forMass, - name=f"widthDecorr{suffix}{label}", - groups=[f"widthDecorr{label}", "theory"], - skipEntries=[ - (x, *[-1] * len(args.fitWidthDecorr)) - for x in width_info["skipEntries"] - ], - noi="wwidth" in args.noi, - noConstraint="wwidth" in args.noi, - mirror=False, - systAxes=["width", *new_names], - systNameReplace=width_info["systNameReplace"], - passToFakes=passSystToFakes, - # isPoiHistDecorr is a special flag to deal with how the massShift variations are internally formed - isPoiHistDecorr=len(args.fitWidthDecorr), - actionRequiresNomi=True, - action=rabbit_helpers.decorrelateByAxes, - actionArgs=dict( - axesToDecorrNames=args.fitWidthDecorr, - newDecorrAxesNames=new_names, - axlim=args.decorrAxlim, - rebin=args.decorrRebin, - absval=args.decorrAbsval, - ), - ) - - if "widthdiffW" in args.noi: - suffix = "".join( - [a.capitalize() for a in args.widthDiffWVar.split("-")] - ) - rabbit_helpers.add_width_diff_variations( - datagroups, - args.widthDiffWVar, - name=widthWeightName, - processes=signal_samples_forMass, - constrain="wwidth" not in args.noi, - suffix=suffix, - label=label, - passSystToFakes=passSystToFakes, - ) if "sin2thetaW" in args.noi or (not stat_only and not args.noTheoryUnc): datagroups.addSystematic( @@ -1907,6 +1722,9 @@ def setup( massVariationZ = 2.1 if constrainMassZ else args.massVariation + # FIXME/TODO: + # does it make sense to define Z mass as unconstrained in the W fit? + # maybe for a simultaenous W and Z mass fit? datagroups.addSystematic( f"massWeightZ", processes=["single_v_nonsig_samples"], @@ -1921,19 +1739,6 @@ def setup( passToFakes=passSystToFakes, ) - if "massDiffZ" in args.noi: - suffix = "".join([a.capitalize() for a in args.massDiffZVar.split("-")]) - rabbit_helpers.add_mass_diff_variations( - datagroups, - args.massDiffZVar, - name=f"{massWeightName}Z", - processes=["single_v_nonsig_samples"], - constrain=constrainMass, - suffix=suffix, - label="Z", - passSystToFakes=passSystToFakes, - ) - if inputBaseName != "prefsr": # make prefsr and EW free definition rabbit_helpers.add_electroweak_uncertainty( @@ -2352,29 +2157,6 @@ def fake_nonclosure( labelsByAxis=["varTF", "downUpVar"], ) - ## syst for transfer factor difference between data and QCD MC in control region - # datagroups.addSystematic( - # inputBaseName, - # groups=[subgroup, "Fake", "experiment", "expNoCalib", "expNoLumi"], - # name=f"{datagroups.fakeName}TransferFactorClosQCD", - # baseName=f"{datagroups.fakeName}TransferFactorClosQCD", - # processes=datagroups.fakeName, - # noConstraint=False, - # mirror=False, - # scale=1, - # applySelection=False, # don't apply selection, external parameters need to be added - # action=fake_transferFactor_ptSyst, - # actionArgs=dict( - # altHistName="fakeCorr_closQCDsv", - # varIdxs = [], - # correctionFile=f"{common.data_dir}/fakesWmass/{args.fakeTransferCorrFileName}.pkl.lz4", - # fakeselector=fakeselector, - # fakeTransferAxis=datagroups.fakeTransferAxis, - # ), - # systAxes=["downUpVar"], - # labelsByAxis=["downUpVar"], - # ) - # syst for transfer factor difference between control and signal regions from MC datagroups.addSystematic( inputBaseName, diff --git a/wremnants/postprocessing/rabbit_helpers.py b/wremnants/postprocessing/rabbit_helpers.py index d671a2d95..b38046d64 100644 --- a/wremnants/postprocessing/rabbit_helpers.py +++ b/wremnants/postprocessing/rabbit_helpers.py @@ -10,6 +10,104 @@ logger = logging.child_logger(__name__) +def decorrelateByAxis( + hvar, + hnom, + axisToDecorrName, + newDecorrAxisName=None, + axlim=[], + rebin=[], + absval=False, +): + return decorrelateByAxes( + hvar, + hnom, + axesToDecorrNames=[axisToDecorrName], + newDecorrAxesNames=[newDecorrAxisName], + axlim=[axlim], + rebin=[rebin], + absval=[absval], + ) + + +def decorrelateByAxes( + hvar, hnom, axesToDecorrNames, newDecorrAxesNames=[], axlim=[], rebin=[], absval=[] +): + + commonMessage = f"Requested to decorrelate uncertainty in histogram {hvar.name} by {axesToDecorrNames} axes" + if any(a not in hvar.axes.name for a in axesToDecorrNames): + raise ValueError( + f"{commonMessage}, but available axes for histogram are {hvar.axes.name}" + ) + + if len(newDecorrAxesNames) == 0: + newDecorrAxesNames = [f"{n}_decorr" for n in axesToDecorrNames] + elif len(axesToDecorrNames) != len(newDecorrAxesNames): + raise ValueError( + f"If newDecorrAxisName are specified, they must have the same length than axisToDecorrName, but they are {newDecorrAxesNames} and {axesToDecorrNames}." + ) + + # subtract nominal hist to get variation only + hvar = hh.addHists(hvar, hnom, scale2=-1) + # expand edges for variations on diagonal elements + hvar = hh.expand_hist_by_duplicate_axes( + hvar, axesToDecorrNames, newDecorrAxesNames, put_trailing=True + ) + # rebin duplicated axes + if len(axlim) or len(rebin): + hvar = hh.rebinHistMultiAx( + hvar, newDecorrAxesNames, rebin, axlim[::2], axlim[1::2] + ) + + for ax, absval in zip(newDecorrAxesNames, absval): + if absval: + logger.info(f"Taking the absolute value of axis '{ax}'") + hvar = hh.makeAbsHist(hvar, ax, rename=False) + # add back nominal histogram while broadcasting + hvar = hh.addHists(hvar, hnom) + + # if there is a mirror axis, put it at the end, since CardTool.py requires it like that + if ( + "mirror" in hvar.axes.name + and hvar.axes.name.index("mirror") != len(hvar.shape) - 1 + ): + sortedAxes = [n for n in hvar.axes.name if n != "mirror"] + sortedAxes.append("mirror") + hvar = hvar.project(*sortedAxes) + + return hvar + + +def correct_bw_xsec(h, h_ref): + """ + Normalize the Breit-Wigner mass variation histograms + to the cross section from the MiNNLO mass variation histograms. + Assumes that the histograms have been filled with the same mass variations, in the same order. + """ + + if "massShift" in h.axes.name: + var = "massShift" + elif "width" in h.axes.name: + var = "width" + + h_axis_labels = [n for n in h.axes[var]] + h_ref_axis_labels = [n for n in h_ref.axes[var]] + if ( + len(h_axis_labels) != len(h_ref_axis_labels) + or h_axis_labels != h_ref_axis_labels + ): + logger.warning( + f"Breit-Wigner variations do not match MiNNLO variations: {h_axis_labels} vs {h_ref_axis_labels}." + "Cannot apply correction." + ) + return h + + h_corr = hh.divideHists(h.project(var), h_ref.project(var)) + h = hh.multiplyHists(h, h_corr) + + return h + + def add_mass_diff_variations( datagroups, mass_diff_var, @@ -138,6 +236,241 @@ def add_width_diff_variations( ) +def add_V_mass_uncertainty( + datagroups, + processes, + args, + passSystToFakes=True, + label="W", + massVariation=100, + constrainMass=False, + decorwidth=False, +): + + # This function is supposed to deal with the case where the mass is the fit NOI. + # If this is the mW fit, then the nuisance parameter controlling the uncertainty + # in mZ has to be defined elsewhere + + massWeightName = ( + f"massWeight_widthdecor{label}" if decorwidth else f"massWeight{label}" + ) + mass_info = dict( + processes=processes, + group=f"massShift", + noi=not constrainMass, + skipEntries=theory_utils.massWeightNames(proc=label, exclude=massVariation), + mirror=False, + noConstraint=not constrainMass, + systAxes=["massShift"], + passToFakes=passSystToFakes, + ) + + if args.breitwignerWMassWeights and label == "W": + preOpMap = {} + for group in ["Wmunu", "Wtaunu"]: + if group not in datagroups.groups.keys(): + continue + for member in datagroups.groups[group].members: + h_ref = datagroups.readHist( + datagroups.nominalName, member, massWeightName + ) + preOpMap[member.name] = lambda h, h_ref=h_ref: correct_bw_xsec(h, h_ref) + + datagroups.addSystematic( + histname=f"breitwigner_{massWeightName}", + name=f"massWeight{label}", + preOpMap=preOpMap, + **mass_info, + ) + else: + if len(args.fitMassDecorr) == 0: + datagroups.addSystematic( + massWeightName, + **mass_info, + ) + else: + suffix = "".join([a.capitalize() for a in args.fitMassDecorr]) + new_names = [f"{a}_decorr" for a in args.fitMassDecorr] + datagroups.addSystematic( + histname=massWeightName, + processes=processes, + name=f"massDecorr{suffix}{label}", + group=f"massDecorr{label}", + # systNameReplace=[("Shift",f"Diff{suffix}")], + skipEntries=[ + (x, *[-1] * len(args.fitMassDecorr)) + for x in theory_utils.massWeightNames( + proc=label, exclude=args.massVariation + ) + ], + noi=not constrainMass, + noConstraint=not constrainMass, + mirror=False, + systAxes=["massShift", *new_names], + passToFakes=passSystToFakes, + # isPoiHistDecorr is a special flag to deal with how the massShift variations are internally formed + isPoiHistDecorr=len(args.fitMassDecorr), + actionRequiresNomi=True, + action=decorrelateByAxes, + actionArgs=dict( + axesToDecorrNames=args.fitMassDecorr, + newDecorrAxesNames=new_names, + axlim=args.decorrAxlim, + rebin=args.decorrRebin, + absval=args.decorrAbsval, + ), + ) + + if "massdiffW" in args.noi: + suffix = "".join([a.capitalize() for a in args.massDiffWVar.split("-")]) + add_mass_diff_variations( + datagroups, + args.massDiffWVar, + name=massWeightName, + processes=processes, + constrain=constrainMass, + suffix=suffix, + label=label, + passSystToFakes=passSystToFakes, + ) + + elif "massdiffZ" in args.noi: + suffix = "".join([a.capitalize() for a in args.massDiffZVar.split("-")]) + add_mass_diff_variations( + datagroups, + args.massDiffZVar, + name=massWeightName, + processes=processes, + constrain=constrainMass, + suffix=suffix, + label=label, + passSystToFakes=passSystToFakes, # automatically False for Z + ) + + +def add_W_width_uncertainty( + datagroups, + processes, + args, + passSystToFakes=True, + label="W", +): + widthVarTag = "" + if ( + args.widthVariationW[0] == args.widthVariationW[1] + and args.widthVariationW[0] == "0.6" + ): + widthVarTag = "WidthW0p6MeV" + width_info = dict( + name=widthVarTag, + skipEntries=theory_utils.widthWeightNames( + proc="W", exclude=(2.09053, 2.09173) + ), + systNameReplace=[["2p09053GeV", "Down"], ["2p09173GeV", "Up"]], + ) + else: + widthLowValues = { + "0.6": "2.09053", + "6": "2.085", + "48": "2.043", + } + widthHighValues = { + "0.6": "2.09173", + "36": "2.127", + } + widthVarDown = args.widthVariationW[0].replace(".", "p") + widthVarUp = args.widthVariationW[1].replace(".", "p") + widthVarTag = f"WidthWm{widthVarDown}p{widthVarUp}MeV" + wlv = widthLowValues[args.widthVariationW[0]] + whv = widthHighValues[args.widthVariationW[1]] + wlvStr = wlv.replace(".", "p") + "GeV" + whvStr = whv.replace(".", "p") + "GeV" + width_info = dict( + name=widthVarTag, + skipEntries=theory_utils.widthWeightNames( + proc="W", exclude=(float(wlv), float(whv)) + ), + systNameReplace=[[wlvStr, "Down"], [whvStr, "Up"]], + ) + + width_info.update( + dict( + processes=processes, + groups=["widthW", "theory"], + mirror=False, + noi="wwidth" in args.noi, + noConstraint="wwidth" in args.noi, + systAxes=["width"], + passToFakes=passSystToFakes, + ) + ) + widthWeightName = f"widthWeight{label}" + if args.breitwignerWMassWeights: + preOpMap = {} + for group in ["Wmunu", "Wtaunu"]: + if group not in datagroups.groups.keys(): + continue + for member in datagroups.groups[group].members: + h_ref = datagroups.readHist( + datagroups.nominalName, member, widthWeightName + ) + preOpMap[member.name] = lambda h, h_ref=h_ref: correct_bw_xsec(h, h_ref) + datagroups.addSystematic( + histname=f"breitwigner_{widthWeightName}", + preOpMap=preOpMap, + **width_info, + ) + else: + if len(args.fitWidthDecorr) == 0: + datagroups.addSystematic( + widthWeightName, + **width_info, + ) + else: + suffix = "".join([a.capitalize() for a in args.fitWidthDecorr]) + new_names = [f"{a}_decorr" for a in args.fitWidthDecorr] + datagroups.addSystematic( + histname=widthWeightName, + processes=processes, + name=f"widthDecorr{suffix}{label}", + groups=[f"widthDecorr{label}", "theory"], + skipEntries=[ + (x, *[-1] * len(args.fitWidthDecorr)) + for x in width_info["skipEntries"] + ], + noi="wwidth" in args.noi, + noConstraint="wwidth" in args.noi, + mirror=False, + systAxes=["width", *new_names], + systNameReplace=width_info["systNameReplace"], + passToFakes=passSystToFakes, + # isPoiHistDecorr is a special flag to deal with how the massShift variations are internally formed + isPoiHistDecorr=len(args.fitWidthDecorr), + actionRequiresNomi=True, + action=decorrelateByAxes, + actionArgs=dict( + axesToDecorrNames=args.fitWidthDecorr, + newDecorrAxesNames=new_names, + axlim=args.decorrAxlim, + rebin=args.decorrRebin, + absval=args.decorrAbsval, + ), + ) + + if "widthdiffW" in args.noi: + suffix = "".join([a.capitalize() for a in args.widthDiffWVar.split("-")]) + add_width_diff_variations( + datagroups, + args.widthDiffWVar, + name=widthWeightName, + processes=processes, + constrain="wwidth" not in args.noi, + suffix=suffix, + label=label, + passSystToFakes=passSystToFakes, + ) + + def add_recoil_uncertainty( datagroups, samples, @@ -738,101 +1071,3 @@ def add_bsm_process( # scale BSM cross section to SM cross section for m in datagroups.groups[bsm_name].members: m.xsec = xsec - - -def decorrelateByAxis( - hvar, - hnom, - axisToDecorrName, - newDecorrAxisName=None, - axlim=[], - rebin=[], - absval=False, -): - return decorrelateByAxes( - hvar, - hnom, - axesToDecorrNames=[axisToDecorrName], - newDecorrAxesNames=[newDecorrAxisName], - axlim=[axlim], - rebin=[rebin], - absval=[absval], - ) - - -def decorrelateByAxes( - hvar, hnom, axesToDecorrNames, newDecorrAxesNames=[], axlim=[], rebin=[], absval=[] -): - - commonMessage = f"Requested to decorrelate uncertainty in histogram {hvar.name} by {axesToDecorrNames} axes" - if any(a not in hvar.axes.name for a in axesToDecorrNames): - raise ValueError( - f"{commonMessage}, but available axes for histogram are {hvar.axes.name}" - ) - - if len(newDecorrAxesNames) == 0: - newDecorrAxesNames = [f"{n}_decorr" for n in axesToDecorrNames] - elif len(axesToDecorrNames) != len(newDecorrAxesNames): - raise ValueError( - f"If newDecorrAxisName are specified, they must have the same length than axisToDecorrName, but they are {newDecorrAxesNames} and {axesToDecorrNames}." - ) - - # subtract nominal hist to get variation only - hvar = hh.addHists(hvar, hnom, scale2=-1) - # expand edges for variations on diagonal elements - hvar = hh.expand_hist_by_duplicate_axes( - hvar, axesToDecorrNames, newDecorrAxesNames, put_trailing=True - ) - # rebin duplicated axes - if len(axlim) or len(rebin): - hvar = hh.rebinHistMultiAx( - hvar, newDecorrAxesNames, rebin, axlim[::2], axlim[1::2] - ) - - for ax, absval in zip(newDecorrAxesNames, absval): - if absval: - logger.info(f"Taking the absolute value of axis '{ax}'") - hvar = hh.makeAbsHist(hvar, ax, rename=False) - # add back nominal histogram while broadcasting - hvar = hh.addHists(hvar, hnom) - - # if there is a mirror axis, put it at the end, since CardTool.py requires it like that - if ( - "mirror" in hvar.axes.name - and hvar.axes.name.index("mirror") != len(hvar.shape) - 1 - ): - sortedAxes = [n for n in hvar.axes.name if n != "mirror"] - sortedAxes.append("mirror") - hvar = hvar.project(*sortedAxes) - - return hvar - - -def correct_bw_xsec(h, h_ref): - """ - Normalize the Breit-Wigner mass variation histograms - to the cross section from the MiNNLO mass variation histograms. - Assumes that the histograms have been filled with the same mass variations, in the same order. - """ - - if "massShift" in h.axes.name: - var = "massShift" - elif "width" in h.axes.name: - var = "width" - - h_axis_labels = [n for n in h.axes[var]] - h_ref_axis_labels = [n for n in h_ref.axes[var]] - if ( - len(h_axis_labels) != len(h_ref_axis_labels) - or h_axis_labels != h_ref_axis_labels - ): - logger.warning( - f"Breit-Wigner variations do not match MiNNLO variations: {h_axis_labels} vs {h_ref_axis_labels}." - "Cannot apply correction." - ) - return h - - h_corr = hh.divideHists(h.project(var), h_ref.project(var)) - h = hh.multiplyHists(h, h_corr) - - return h From 642e8f159707aa103da476e6e75ecd4b864b2b7d Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 26 Mar 2026 17:20:44 +0100 Subject: [PATCH 41/46] fixing scripts/rabbit/setupRabbit.py --- scripts/rabbit/setupRabbit.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index d2e23eab8..257a39e9e 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -73,10 +73,10 @@ def _build_preselection_specs(selection_specs, fitvar): for axis, _, _ in parsed_specs: if axis in fitvar: raise ValueError( - f"--preselect only accepts non-fit axes. Axis '{axis}' is one of the fit variables {fitvar}" + f"--presel only accepts non-fit axes. Axis '{axis}' is one of the fit variables {fitvar}" ) if axis in seen_axes: - raise ValueError(f"Duplicate axis '{axis}' passed to --preselect") + raise ValueError(f"Duplicate axis '{axis}' passed to --presel") seen_axes.add(axis) return parsed_specs @@ -89,7 +89,7 @@ def _normalize_negative_imaginary_bounds(argv): token = argv[i] normalized_argv.append(token) - if token in {"--axlim", "--preselect"} and i + 3 < len(argv): + if token in {"--axlim", "--presel"} and i + 3 < len(argv): normalized_argv.append(argv[i + 1]) for value in (argv[i + 2], argv[i + 3]): if value.startswith("-") and value.endswith("j"): @@ -1116,7 +1116,7 @@ def apply_preselection(h, specs=tuple(preselection_specs)): for axis, low, high in specs: if axis not in h.axes.name: raise ValueError( - f"--preselect requested axis '{axis}', but histogram axes are {h.axes.name}" + f"--presel requested axis '{axis}', but histogram axes are {h.axes.name}" ) h = h[{axis: slice(low, hh.get_hist_slice_upper(h, axis, high))}] return h @@ -1341,7 +1341,7 @@ def apply_preselection(h, specs=tuple(preselection_specs)): ), fakeTransferCorrFileName=args.fakeTransferCorrFileName, histAxesRemovedBeforeFakes=( - [str(x.split()[0]) for x in args.selection] if args.selection else [] + [str(x.split()[0]) for x in args.presel] if args.presel else [] ), ) datagroups.set_histselectors( @@ -2183,14 +2183,10 @@ def fake_nonclosure( ), ) - # must skip this part when fitting only utPlus with --select 'utAngleSign 1 2' or --select 'utAngleSign 0 1' - # is there a better way to check whether the negative uT bi + # must skip this part when fitting only utPlus with '--presel utAngleSign 1 2' or '--presel utAngleSign 0 1' if "utAngleSign" in fitvar and ( - args.selection is None - or not any( - sel in args.selection - for sel in ["utAngleSign 1 2", "utAngleSign 0 1"] - ) + not args.presel + or not any(sel[0] == "utAngleSign" for sel in args.presel) ): datagroups.addSystematic( From c2a1062df3b1679c9b4b60c72b1fbb6de6159a7d Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 26 Mar 2026 23:56:28 +0100 Subject: [PATCH 42/46] fix --- scripts/rabbit/setupRabbit.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 257a39e9e..43bd0150d 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -1341,7 +1341,7 @@ def apply_preselection(h, specs=tuple(preselection_specs)): ), fakeTransferCorrFileName=args.fakeTransferCorrFileName, histAxesRemovedBeforeFakes=( - [str(x.split()[0]) for x in args.presel] if args.presel else [] + [str(x[0]) for x in args.presel] if args.presel else [] ), ) datagroups.set_histselectors( From 5d7d9de84a0389dbca54bc9863123d7c9d69e672 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 27 Mar 2026 09:39:54 +0100 Subject: [PATCH 43/46] fix --- scripts/rabbit/setupRabbit.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index 43bd0150d..f02097f62 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -71,13 +71,14 @@ def _build_preselection_specs(selection_specs, fitvar): parsed_specs = _parse_axis_range_specs(selection_specs) seen_axes = set() for axis, _, _ in parsed_specs: - if axis in fitvar: + axis_name = axis.split(":")[0] + if axis_name in fitvar: raise ValueError( - f"--presel only accepts non-fit axes. Axis '{axis}' is one of the fit variables {fitvar}" + f"--presel only accepts non-fit axes. Axis '{axis_name}' is one of the fit variables {fitvar}" ) - if axis in seen_axes: - raise ValueError(f"Duplicate axis '{axis}' passed to --presel") - seen_axes.add(axis) + if axis_name in seen_axes: + raise ValueError(f"Duplicate axis '{axis_name}' passed to --presel") + seen_axes.add(axis_name) return parsed_specs @@ -97,9 +98,8 @@ def _normalize_negative_imaginary_bounds(argv): else: normalized_argv.append(value) i += 4 - continue - - i += 1 + else: + i += 1 return normalized_argv @@ -1025,7 +1025,8 @@ def make_parser(parser=None, argv=None): help="Apply a strict preselection on a non-fit axis before downstream projections." " Repeat as '--presel AXIS LOW HIGH'." " LOW and HIGH must be pure real integers for bin indices or pure imaginary numbers for axis values." - " The command fails if a requested axis is missing from any loaded histogram.", + " The command fails if a requested axis is missing from any loaded histogram." + " One can use 'AXIS:sum' instead of just 'AXIS' to pass hist.sum to the slice", ) parser.add_argument( "--noTheoryCorrsViaHelicities", @@ -1114,11 +1115,16 @@ def setup( def apply_preselection(h, specs=tuple(preselection_specs)): for axis, low, high in specs: - if axis not in h.axes.name: + axis_name = axis.split(":")[0] + if axis_name not in h.axes.name: raise ValueError( - f"--presel requested axis '{axis}', but histogram axes are {h.axes.name}" + f"--presel requested axis '{axis_name}', but histogram axes are {h.axes.name}" ) - h = h[{axis: slice(low, hh.get_hist_slice_upper(h, axis, high))}] + h = h[ + {axis_name: slice(low, hh.get_hist_slice_upper(h, axis_name, high))} + ] + if ":sum" in axis: + h = h[{axis_name: hist.sum}] return h datagroups.setGlobalAction(apply_preselection) From 0c62ddb00448f879f609c1eab91ff2bbbcd3b013 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 27 Mar 2026 14:52:33 +0100 Subject: [PATCH 44/46] couple of fixes --- scripts/analysisTools/tests/testFakesVsMt.py | 7 +++++-- wremnants/production/histmaker_tools.py | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/analysisTools/tests/testFakesVsMt.py b/scripts/analysisTools/tests/testFakesVsMt.py index 4407d6bf7..e017a7e11 100644 --- a/scripts/analysisTools/tests/testFakesVsMt.py +++ b/scripts/analysisTools/tests/testFakesVsMt.py @@ -64,6 +64,7 @@ # sys.path.append(os.getcwd()) from scripts.analysisTools.tests.cropNegativeTemplateBins import cropNegativeContent from scripts.analysisTools.tests.testPlots1D import plotDistribution1D +from wremnants.production.histmaker_tools import writeMetaInfoToRootFile narf.clingutils.Declare('#include "histHelpers.hpp"') @@ -712,13 +713,14 @@ def runStudy(fname, charges, mainOutputFolder, args): histoChi2diffTest = None histoPullsPol1Slope = None + # TODO: WIP inputHistDict = { "mt": "mTStudyForFakes", "oneMinusCosdphi": "mTStudyForFakesAlt", "mtOverPt": "mTStudyForFakesAlt2", "altMt": "mTStudyForFakesAlt3", - "dxybs": "mTStudyForFakesAlt4", - "mtBinnedUt": "mTStudyForFakesAlt5", + "dxybs": "mTStudyForFakesAlt4", # "mTStudyForFakes_dxybs", + "mtBinnedUt": "mTStudyForFakesAlt5", # "mTStudyForFakes_uTAngleCosine", } etaLabel = "#eta^{#mu}" if not args.absEta else "|#eta^{#mu}|" @@ -2233,6 +2235,7 @@ def runStudy(fname, charges, mainOutputFolder, args): f"Saving FRF correction vs eta-pt in file\n{outFile}\nfor charge {charge}" ) logger.info("") + writeMetaInfoToRootFile(fout, args=args) fout.Close() logger.info("-" * 30) diff --git a/wremnants/production/histmaker_tools.py b/wremnants/production/histmaker_tools.py index e39645485..d688dd962 100644 --- a/wremnants/production/histmaker_tools.py +++ b/wremnants/production/histmaker_tools.py @@ -130,7 +130,9 @@ def aggregate_groups(datasets, result_dict, groups_to_aggregate): def writeMetaInfoToRootFile(rtfile, exclude_diff="notebooks", args=None): import ROOT - meta_dict = ioutils.make_meta_info_dict(exclude_diff, args=args, wd=common.base_dir) + meta_dict = output_tools.make_meta_info_dict( + exclude_diff, args=args, wd=common.base_dir + ) d = rtfile.mkdir("meta_info") d.cd() From c410b2a57f58357ecf056722e59cb81485b5f28d Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Fri, 27 Mar 2026 23:35:20 +0100 Subject: [PATCH 45/46] implement comments from PR --- scripts/histmakers/mw_with_mu_eta_pt.py | 309 +++++++++--------- scripts/rabbit/setupRabbit.py | 14 +- wremnants/postprocessing/histselections.py | 12 +- wremnants/postprocessing/rabbit_helpers.py | 4 +- wremnants/postprocessing/syst_tools.py | 6 +- wremnants/production/include/recoil_tools.hpp | 3 - wremnants/production/include/utils.hpp | 14 +- wremnants/production/recoil_tools.py | 2 - wremnants/utilities/styles/styles.py | 2 - 9 files changed, 187 insertions(+), 179 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index af1ee4de7..1aa195c89 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -1405,7 +1405,10 @@ def build_graph(df, dataset): "transverseMass", "wrem::mt_2(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", ) - # to define dedicated systematics for scale/smearing of met_pt + + # Define dedicated systematics from scaling/smearing met_pt and smearing met_phi. + # The used values are derived looking at template variations, but not optimized. + # Their size can be customized in setupRabbit.py with the 'scale' argument of datagroups.addSystematic() df = df.Define( "scaleMET_pt", "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_pt, 1.01, 0.0)", @@ -1416,7 +1419,7 @@ def build_graph(df, dataset): ) df = df.Define( "smearMET_phi", - "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_phi, 1.0, 0.05, 1)", + "wrem::get_scaled_smeared_variable(run, luminosityBlock, event, MET_corr_rec_phi, 1.0, 0.02, 1, 1)", ) df = df.Define( "transverseMass_scaleMET_pt", @@ -1442,7 +1445,7 @@ def build_graph(df, dataset): "goodMuons_angleSignUt_smearMET_phi0", "wrem::zqtproj0_angleSign(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, smearMET_phi)", ) - # + df = df.Define("hasCleanJet", "Sum(goodCleanJetsNoPt && Jet_pt > 30) >= 1") df = df.Define( "goodMuons_dphiMuMet0", @@ -1713,179 +1716,185 @@ def build_graph(df, dataset): # instead of passIso in mTStudyForFakes # df = df.Define("passIsoAlt", "(goodMuons_pfRelIso04_all0 * Muon_pt[goodMuons][0] / goodMuons_jetpt0) < 0.12") # df = df.Define("passIsoAlt", "(Muon_vtxAgnPfRelIso04_chg[goodMuons][0] * Muon_pt[goodMuons][0]) < 5.0") - # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 - # for convenience in the later study - df = df.Define( - "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" - ) - - mTStudyForFakes = df.HistoBoost( - "mTStudyForFakes", - mTStudyForFakes_axes, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "transverseMass", - "passIso", - "hasCleanJet", - "goodMuons_dphiMuMet0", - "nominal_weight", - ], - ) - results.append(mTStudyForFakes) - - mTStudyForFakes_dxybs = df.HistoBoost( - "mTStudyForFakes_dxybs", - mTStudyForFakes_axes_dxybs, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_dxybs0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(mTStudyForFakes_dxybs) - - mTStudyForFakes_uTAngleCosine = df.HistoBoost( - "mTStudyForFakes_uTAngleCosine", - mTStudyForFakes_axes_uTAngleCosine, - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_charge0", - "transverseMass", - "passIso", - "goodMuons_angleCosineUt0", - "nominal_weight", - ], - ) - results.append(mTStudyForFakes_uTAngleCosine) - - if not dataset.is_data: - # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) - df = df.Define( - "goodMuons_utGenMet0", - "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", - ) - df = df.Define( - "goodMuons_utReso0", - "(goodMuons_utGenMet0 != 0) ? (goodMuons_utReco0 / goodMuons_utGenMet0) : 0.0", - ) + if auxiliary_histograms: + # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 + # for convenience in the later study df = df.Define( - "goodMuons_angleCosineUtGenMet0", - "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", - ) - ut_bins = ( - *np.arange(-40, -19, 5), - *np.arange(-18, 21, 2), - *np.arange(25, 51, 5), - *np.arange(60, 101, 10), + "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" ) - axis_ut_recoMet = hist.axis.Variable( - ut_bins, name="ut_recoMet", underflow=True, overflow=True - ) - axis_ut_genMet = hist.axis.Variable( - ut_bins, name="ut_genMet", underflow=True, overflow=True - ) - axis_ut_reso = hist.axis.Regular( - 100, -2, 2, name="ut_reso", underflow=True, overflow=True - ) - axis_uTAngleCosineGenMet = hist.axis.Regular( - 20, -1, 1, name="uTAngleCosineGenMet", overflow=False, underflow=False - ) - # - etaPtUtGenUt = df.HistoBoost( - "etaPtUtGenUt", - [ - axis_eta, - axis_pt, - axis_ut_recoMet, - axis_ut_genMet, - axis_passIso, - axis_passMT, - ], + + mTStudyForFakes = df.HistoBoost( + "mTStudyForFakes", + mTStudyForFakes_axes, [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_utReco0", - "goodMuons_utGenMet0", + "goodMuons_charge0", + "transverseMass", "passIso", - "passMT", + "hasCleanJet", + "goodMuons_dphiMuMet0", "nominal_weight", ], ) - results.append(etaPtUtGenUt) - # - etaPtUtAngleCosineGenUtAngleCosine = df.HistoBoost( - "etaPtUtAngleCosineGenUtAngleCosine", - [ - axis_eta, - axis_pt, - axis_uTAngleCosine, - axis_uTAngleCosineGenMet, - axis_passIso, - axis_passMT, - ], + results.append(mTStudyForFakes) + + mTStudyForFakes_dxybs = df.HistoBoost( + "mTStudyForFakes_dxybs", + mTStudyForFakes_axes_dxybs, [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_angleCosineUt0", - "goodMuons_angleCosineUtGenMet0", + "goodMuons_charge0", + "goodMuons_dxybs0", "passIso", "passMT", "nominal_weight", ], ) - results.append(etaPtUtAngleCosineGenUtAngleCosine) - # - etaPtUtResoUt = df.HistoBoost( - "etaPtUtResoUt", - [ - axis_eta, - axis_pt, - axis_ut_recoMet, - axis_ut_reso, - axis_passIso, - axis_passMT, - ], + results.append(mTStudyForFakes_dxybs) + + mTStudyForFakes_uTAngleCosine = df.HistoBoost( + "mTStudyForFakes_uTAngleCosine", + mTStudyForFakes_axes_uTAngleCosine, [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_utReco0", - "goodMuons_utReso0", + "goodMuons_charge0", + "transverseMass", "passIso", - "passMT", + "goodMuons_angleCosineUt0", "nominal_weight", ], ) - results.append(etaPtUtResoUt) - # - etaPtUtResoGenUt = df.HistoBoost( - "etaPtUtResoGenUt", - [ - axis_eta, - axis_pt, - axis_ut_genMet, - axis_ut_reso, - axis_passIso, - axis_passMT, - ], - [ - "goodMuons_eta0", - "goodMuons_pt0", + results.append(mTStudyForFakes_uTAngleCosine) + + if not dataset.is_data: + # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) + df = df.Define( "goodMuons_utGenMet0", + "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", + ) + df = df.Define( "goodMuons_utReso0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(etaPtUtResoGenUt) - # + "(goodMuons_utGenMet0 != 0) ? (goodMuons_utReco0 / goodMuons_utGenMet0) : 0.0", + ) + df = df.Define( + "goodMuons_angleCosineUtGenMet0", + "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", + ) + ut_bins = ( + *np.arange(-40, -19, 5), + *np.arange(-18, 21, 2), + *np.arange(25, 51, 5), + *np.arange(60, 101, 10), + ) + axis_ut_recoMet = hist.axis.Variable( + ut_bins, name="ut_recoMet", underflow=True, overflow=True + ) + axis_ut_genMet = hist.axis.Variable( + ut_bins, name="ut_genMet", underflow=True, overflow=True + ) + axis_ut_reso = hist.axis.Regular( + 100, -2, 2, name="ut_reso", underflow=True, overflow=True + ) + axis_uTAngleCosineGenMet = hist.axis.Regular( + 20, + -1, + 1, + name="uTAngleCosineGenMet", + overflow=False, + underflow=False, + ) + # + etaPtUtGenUt = df.HistoBoost( + "etaPtUtGenUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_genMet, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utReco0", + "goodMuons_utGenMet0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtGenUt) + # + etaPtUtAngleCosineGenUtAngleCosine = df.HistoBoost( + "etaPtUtAngleCosineGenUtAngleCosine", + [ + axis_eta, + axis_pt, + axis_uTAngleCosine, + axis_uTAngleCosineGenMet, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_angleCosineUt0", + "goodMuons_angleCosineUtGenMet0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtAngleCosineGenUtAngleCosine) + # + etaPtUtResoUt = df.HistoBoost( + "etaPtUtResoUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utReco0", + "goodMuons_utReso0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtResoUt) + # + etaPtUtResoGenUt = df.HistoBoost( + "etaPtUtResoGenUt", + [ + axis_eta, + axis_pt, + axis_ut_genMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_utGenMet0", + "goodMuons_utReso0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtResoGenUt) + # # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: diff --git a/scripts/rabbit/setupRabbit.py b/scripts/rabbit/setupRabbit.py index f02097f62..29f8e29be 100644 --- a/scripts/rabbit/setupRabbit.py +++ b/scripts/rabbit/setupRabbit.py @@ -436,7 +436,7 @@ def make_parser(parser=None, argv=None): "eta-sign", "eta-range", ], - help="For use with --noi widthDiffW, select the variable to define the different mass differences", + help="For use with --noi widthDiffW, select the variable to define the different width differences", ) parser.add_argument( "--massDiffZVar", @@ -1026,7 +1026,7 @@ def make_parser(parser=None, argv=None): " Repeat as '--presel AXIS LOW HIGH'." " LOW and HIGH must be pure real integers for bin indices or pure imaginary numbers for axis values." " The command fails if a requested axis is missing from any loaded histogram." - " One can use 'AXIS:sum' instead of just 'AXIS' to pass hist.sum to the slice", + " Use AXIS:sum LOW HIGH to slice [LOW, HIGH] and then sum over the axis (removing it from the histogram).", ) parser.add_argument( "--noTheoryCorrsViaHelicities", @@ -2096,14 +2096,17 @@ def apply_preselection(h, specs=tuple(preselection_specs)): def fake_nonclosure( h, - axesToDecorrNames, + *args, + axesToDecorrNames=None, param_idx=1, variation_size=0.5, normalize=False, fakeselector=None, - *args, **kwargs, ): + # enforce expectation for optional arguments, extra positional arguments are rejected + if args: + raise TypeError(f"Unexpected positional arguments: {args}") # apply variation by adding parameter value (assumes log space, e.g. in full smoothing) fakeselector.spectrum_regressor.external_params = np.zeros( fakeSmoothingOrder + 1 @@ -2823,7 +2826,6 @@ def fake_nonclosure( "expNoLumi", "expNoCalib", ], - # scale=0.1, systAxes=[], passToFakes=passSystToFakes, ) @@ -2838,7 +2840,6 @@ def fake_nonclosure( "expNoLumi", "expNoCalib", ], - # scale=0.5, systAxes=[], passToFakes=passSystToFakes, ) @@ -2853,7 +2854,6 @@ def fake_nonclosure( "expNoLumi", "expNoCalib", ], - scale=0.4, # from 5% -> scale * 5% for test (see histmaker) systAxes=[], passToFakes=passSystToFakes, ) diff --git a/wremnants/postprocessing/histselections.py b/wremnants/postprocessing/histselections.py index 9bb9503ff..117e9a3a5 100644 --- a/wremnants/postprocessing/histselections.py +++ b/wremnants/postprocessing/histselections.py @@ -465,7 +465,7 @@ def __init__( trTensorPath = ( f"{data_dir}/fakesWmass/{self.fakeTransferCorrFileName}.pkl.lz4" ) - logger.warning(f"Loaded transfer tensor for fakes: {trTensorPath}") + logger.info(f"Loaded transfer tensor for fakes: {trTensorPath}") with lz4.frame.open(trTensorPath) as fTens: resultDict = pickle.load(fTens) self.fakeTransferTensor = resultDict["fakeCorr"] @@ -475,7 +475,7 @@ def __init__( self.rebin_smoothing_axis = None if hasattr(self, "fakerate_integration_axes"): - logger.warning( + logger.info( f"self.fakerate_integration_axes = {self.fakerate_integration_axes}" ) if smoothing_mode == "full" and len(self.fakerate_integration_axes): @@ -627,7 +627,7 @@ def get_hist( if not self.integrate_x and self.swap_regions: logger.warning( - f"Regions for fakerate estiamation can only be swapped if abcd-x axis is integrated" + f"Regions for fakerate estimation can only be swapped if abcd-x axis is integrated" ) if self.swap_regions and self.integrate_x: if type(self) == FakeSelectorSimpleABCD: @@ -664,7 +664,7 @@ def get_hist( elif variations_frf: dvar = cval[..., np.newaxis, np.newaxis] * y_frf_var[..., :, :] elif self.smoothing_mode in ["hybrid"]: - # noo bin by bin statistical uncertainty, all regions covered by smoothing + # no bin by bin statistical uncertainty, all regions covered by smoothing dvar = np.zeros_like(cvar) else: # only take bin by bin uncertainty from c region @@ -1199,7 +1199,7 @@ def calculate_fullABCD_smoothed( if fakeTransferAxis_idx < 0: logger.debug( - f"All ABCD values are zeros! Returning zero as Fake estimate." + f"All ABCD values are zeros! Returning zero as nonprompt estimate." ) logger.debug(f"Syst variations: {syst_variations}") sval_sliced = np.zeros_like(sval_sliced[..., 0]) @@ -1220,7 +1220,7 @@ def calculate_fullABCD_smoothed( else: logger.debug( - f"All ABCD values are zeros! Returning Fake estimate based on other bin, with an HARDCODED norm. factor" + f"All ABCD values are zeros! Returning nonprompt estimate obtained from another bin, with a correction factor" ) logger.debug(f"Syst variations: {syst_variations}") compl_mask = np.array( diff --git a/wremnants/postprocessing/rabbit_helpers.py b/wremnants/postprocessing/rabbit_helpers.py index b38046d64..002436d0d 100644 --- a/wremnants/postprocessing/rabbit_helpers.py +++ b/wremnants/postprocessing/rabbit_helpers.py @@ -133,7 +133,7 @@ def add_mass_diff_variations( ) # mass difference by swapping the +50MeV with the -50MeV variations for half of the bins args = ["massShift", f"massShift{label}50MeVUp", f"massShift{label}50MeVDown"] - if any(mass_diff_var == var for var in ["charge", "utAngleSign"]): + if mass_diff_var in ["charge", "utAngleSign"]: datagroups.addSystematic( **mass_diff_args, # # on gen level based on the sample, only possible for mW @@ -213,7 +213,7 @@ def add_width_diff_variations( ) # width difference by swapping the +0.6 MeV with the -0.6 MeV variations for half of the bins args = ["width", f"width{label}0p6MeVUp", f"width{label}0p6MeVDown"] - if any(width_diff_var == var for var in ["charge", "utAngleSign"]): + if width_diff_var in ["charge", "utAngleSign"]: datagroups.addSystematic( **width_diff_args, preOp=lambda h: hh.swap_histogram_bins(h, *args, width_diff_var, 0), diff --git a/wremnants/postprocessing/syst_tools.py b/wremnants/postprocessing/syst_tools.py index eb5b5cee8..13ad732a0 100644 --- a/wremnants/postprocessing/syst_tools.py +++ b/wremnants/postprocessing/syst_tools.py @@ -973,11 +973,11 @@ def scale_hist_up_down_corr_from_file(h, corr_file=None, corr_hist=None): def fake_nonclosure_byAxis( h, + *args, axesToDecorrNames=["eta"], variation_size=0.1, keepConstantAxisBin={}, fakeselector=None, - *args, **kwargs, ): @@ -987,6 +987,10 @@ def fake_nonclosure_byAxis( logger.info( f"Doing decorr nonclosure with keepConstantAxisBin={keepConstantAxisBin}" ) + # enforce expectation for optional arguments, extra positional arguments are rejected + if args: + raise TypeError(f"Unexpected positional arguments: {args}") + hnom = fakeselector.get_hist(h, *args, **kwargs) hvar = (1 + variation_size) * hnom if keepConstantAxisBin: diff --git a/wremnants/production/include/recoil_tools.hpp b/wremnants/production/include/recoil_tools.hpp index 1a5605e13..097dc20b0 100644 --- a/wremnants/production/include/recoil_tools.hpp +++ b/wremnants/production/include/recoil_tools.hpp @@ -40,9 +40,6 @@ TVector2 get_z_mom(const float pt1, const float phi1, const float pt2, TVector2 l1 = TVector2(); l1.SetMagPhi(pt1, phi1); - // TVector2 l2 = TVector2(); - // l2.SetMagPhi(pt2, phi2); - TVector2 z = TVector2(); z.SetMagPhi(pt2, phi2); z += l1; diff --git a/wremnants/production/include/utils.hpp b/wremnants/production/include/utils.hpp index 9bd79d039..672d9eca5 100644 --- a/wremnants/production/include/utils.hpp +++ b/wremnants/production/include/utils.hpp @@ -1109,27 +1109,29 @@ double get_scaled_smeared_variable(const unsigned int run, const unsigned long long event, const double var, const double scale = 1.0, const double smear = 0.1, - const bool isPhiAngle = false) { + const unsigned int seed_modifier = 0, + const bool is_phi_angle = false) { // use scale=1.1 and smear=0.2 for 10% larger mean value and 20% resolution // smearing - std::seed_seq seq{std::size_t(run), std::size_t(lumi), std::size_t(event)}; - std::mt19937 rng(seq); - double scaled_var = var * scale; if (smear <= 0) { // 0 is valid and equivalent to a dirac delta, negative should never happen return scaled_var; } + std::seed_seq seq{std::size_t(run), std::size_t(lumi), std::size_t(event), + std::size_t(seed_modifier)}; + std::mt19937 rng(seq); std::normal_distribution dis(scaled_var, std::abs(scaled_var * smear)); - if (isPhiAngle) { + if (is_phi_angle) { // deal with angle in -pi, pi double phi = dis(rng); return std::atan2(std::sin(phi), std::cos(phi)); + } else { + return dis(rng); } - return dis(rng); } } // namespace wrem diff --git a/wremnants/production/recoil_tools.py b/wremnants/production/recoil_tools.py index e38e02976..89a232e75 100644 --- a/wremnants/production/recoil_tools.py +++ b/wremnants/production/recoil_tools.py @@ -1463,7 +1463,6 @@ def add_recoil_unc_W( return df def setup_recoil_Z_unc(self): - # if not self.dataset.name in self.datasets_to_apply or not self.storeHists: if not self.dataset.name in self.datasets_to_apply: return @@ -1554,7 +1553,6 @@ def setup_recoil_Z_unc(self): ) def setup_recoil_W_unc(self): - # if not self.dataset.name in self.datasets_to_apply or not self.storeHists: if not self.dataset.name in self.datasets_to_apply: return diff --git a/wremnants/utilities/styles/styles.py b/wremnants/utilities/styles/styles.py index a371cadc7..1762481ec 100644 --- a/wremnants/utilities/styles/styles.py +++ b/wremnants/utilities/styles/styles.py @@ -182,8 +182,6 @@ def translate_html_to_latex(n): "MET_pt": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, "MET": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, "met": {"label": r"$\mathit{p}_{\mathrm{T}}^{miss}$", "unit": "GeV"}, - # "mt": {"label": r"$\mathit{m}_{T}^{\mu,MET}$", "unit": "GeV"}, - # "mt": {"label": r"$\mathit{m}_{T}^{W}$", "unit": "GeV"}, "mt": {"label": r"$\mathit{m}_{T}$", "unit": "GeV"}, "mtfix": {"label": r"$\mathit{m}_{T}^\mathrm{fix}$", "unit": "GeV"}, "etaPlus": r"$\mathit{\eta}^{\mu(+)}$", From fd8be87ac14a17d47a74dd3256c25d0ecb7002fa Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sat, 28 Mar 2026 15:53:06 +0100 Subject: [PATCH 46/46] make some utility histograms optional --- scripts/histmakers/mw_with_mu_eta_pt.py | 340 ++++++++++++------------ 1 file changed, 171 insertions(+), 169 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 1aa195c89..a2b85c2ac 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -1380,14 +1380,11 @@ def build_graph(df, dataset): df = df.Alias("MET_corr_rec_pt", f"{met}_pt") df = df.Alias("MET_corr_rec_phi", f"{met}_phi") - df = df.Define( - "goodMuons_utReco0", - "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", - ) df = df.Define( "goodMuons_angleSignUt0", "wrem::zqtproj0_angleSign(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", ) + df = df.Define( "goodMuons_angleCosineUt0", "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", @@ -1716,185 +1713,189 @@ def build_graph(df, dataset): # instead of passIso in mTStudyForFakes # df = df.Define("passIsoAlt", "(goodMuons_pfRelIso04_all0 * Muon_pt[goodMuons][0] / goodMuons_jetpt0) < 0.12") # df = df.Define("passIsoAlt", "(Muon_vtxAgnPfRelIso04_chg[goodMuons][0] * Muon_pt[goodMuons][0]) < 5.0") - if auxiliary_histograms: - # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 - # for convenience in the later study + + # Defined as Threshold - |dxybs| so that for signal it peaks at Threshold instead of 0 + # for convenience in the later study + df = df.Define( + "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" + ) + + mTStudyForFakes = df.HistoBoost( + "mTStudyForFakes", + mTStudyForFakes_axes, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "transverseMass", + "passIso", + "hasCleanJet", + "goodMuons_dphiMuMet0", + "nominal_weight", + ], + ) + results.append(mTStudyForFakes) + + mTStudyForFakes_dxybs = df.HistoBoost( + "mTStudyForFakes_dxybs", + mTStudyForFakes_axes_dxybs, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "goodMuons_dxybs0", + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(mTStudyForFakes_dxybs) + + mTStudyForFakes_uTAngleCosine = df.HistoBoost( + "mTStudyForFakes_uTAngleCosine", + mTStudyForFakes_axes_uTAngleCosine, + [ + "goodMuons_eta0", + "goodMuons_pt0", + "goodMuons_charge0", + "transverseMass", + "passIso", + "goodMuons_angleCosineUt0", + "nominal_weight", + ], + ) + results.append(mTStudyForFakes_uTAngleCosine) + + df = df.Define( + "goodMuons_utReco0", + "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, MET_corr_rec_pt, MET_corr_rec_phi)", + ) + if not dataset.is_data: + # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) df = df.Define( - "goodMuons_dxybs0", f"{args.dxybs} - abs(Muon_dxybs[goodMuons][0])" + "goodMuons_utGenMet0", + "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", ) - - mTStudyForFakes = df.HistoBoost( - "mTStudyForFakes", - mTStudyForFakes_axes, + df = df.Define( + "goodMuons_utReso0", + "(goodMuons_utGenMet0 != 0) ? (goodMuons_utReco0 / goodMuons_utGenMet0) : 0.0", + ) + df = df.Define( + "goodMuons_angleCosineUtGenMet0", + "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", + ) + ut_bins = ( + *np.arange(-40, -19, 5), + *np.arange(-18, 21, 2), + *np.arange(25, 51, 5), + *np.arange(60, 101, 10), + ) + axis_ut_recoMet = hist.axis.Variable( + ut_bins, name="ut_recoMet", underflow=True, overflow=True + ) + axis_ut_genMet = hist.axis.Variable( + ut_bins, name="ut_genMet", underflow=True, overflow=True + ) + axis_ut_reso = hist.axis.Regular( + 100, -2, 2, name="ut_reso", underflow=True, overflow=True + ) + axis_uTAngleCosineGenMet = hist.axis.Regular( + 20, + -1, + 1, + name="uTAngleCosineGenMet", + overflow=False, + underflow=False, + ) + # + etaPtUtGenUt = df.HistoBoost( + "etaPtUtGenUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_genMet, + axis_passIso, + axis_passMT, + ], [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_charge0", - "transverseMass", + "goodMuons_utReco0", + "goodMuons_utGenMet0", "passIso", - "hasCleanJet", - "goodMuons_dphiMuMet0", + "passMT", "nominal_weight", ], ) - results.append(mTStudyForFakes) - - mTStudyForFakes_dxybs = df.HistoBoost( - "mTStudyForFakes_dxybs", - mTStudyForFakes_axes_dxybs, + results.append(etaPtUtGenUt) + # + etaPtUtAngleCosineGenUtAngleCosine = df.HistoBoost( + "etaPtUtAngleCosineGenUtAngleCosine", + [ + axis_eta, + axis_pt, + axis_uTAngleCosine, + axis_uTAngleCosineGenMet, + axis_passIso, + axis_passMT, + ], [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_charge0", - "goodMuons_dxybs0", + "goodMuons_angleCosineUt0", + "goodMuons_angleCosineUtGenMet0", "passIso", "passMT", "nominal_weight", ], ) - results.append(mTStudyForFakes_dxybs) - - mTStudyForFakes_uTAngleCosine = df.HistoBoost( - "mTStudyForFakes_uTAngleCosine", - mTStudyForFakes_axes_uTAngleCosine, + results.append(etaPtUtAngleCosineGenUtAngleCosine) + # + etaPtUtResoUt = df.HistoBoost( + "etaPtUtResoUt", + [ + axis_eta, + axis_pt, + axis_ut_recoMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], [ "goodMuons_eta0", "goodMuons_pt0", - "goodMuons_charge0", - "transverseMass", + "goodMuons_utReco0", + "goodMuons_utReso0", "passIso", - "goodMuons_angleCosineUt0", + "passMT", "nominal_weight", ], ) - results.append(mTStudyForFakes_uTAngleCosine) - - if not dataset.is_data: - # the following can differ from goodMuons_uT0 which uses the gen boson (so both gen muon and neutrino) - df = df.Define( + results.append(etaPtUtResoUt) + # + etaPtUtResoGenUt = df.HistoBoost( + "etaPtUtResoGenUt", + [ + axis_eta, + axis_pt, + axis_ut_genMet, + axis_ut_reso, + axis_passIso, + axis_passMT, + ], + [ + "goodMuons_eta0", + "goodMuons_pt0", "goodMuons_utGenMet0", - "wrem::zqtproj0(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", - ) - df = df.Define( "goodMuons_utReso0", - "(goodMuons_utGenMet0 != 0) ? (goodMuons_utReco0 / goodMuons_utGenMet0) : 0.0", - ) - df = df.Define( - "goodMuons_angleCosineUtGenMet0", - "wrem::zqtproj0_angleCosine(goodMuons_pt0, goodMuons_phi0, GenMET_pt, GenMET_phi)", - ) - ut_bins = ( - *np.arange(-40, -19, 5), - *np.arange(-18, 21, 2), - *np.arange(25, 51, 5), - *np.arange(60, 101, 10), - ) - axis_ut_recoMet = hist.axis.Variable( - ut_bins, name="ut_recoMet", underflow=True, overflow=True - ) - axis_ut_genMet = hist.axis.Variable( - ut_bins, name="ut_genMet", underflow=True, overflow=True - ) - axis_ut_reso = hist.axis.Regular( - 100, -2, 2, name="ut_reso", underflow=True, overflow=True - ) - axis_uTAngleCosineGenMet = hist.axis.Regular( - 20, - -1, - 1, - name="uTAngleCosineGenMet", - overflow=False, - underflow=False, - ) - # - etaPtUtGenUt = df.HistoBoost( - "etaPtUtGenUt", - [ - axis_eta, - axis_pt, - axis_ut_recoMet, - axis_ut_genMet, - axis_passIso, - axis_passMT, - ], - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_utReco0", - "goodMuons_utGenMet0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(etaPtUtGenUt) - # - etaPtUtAngleCosineGenUtAngleCosine = df.HistoBoost( - "etaPtUtAngleCosineGenUtAngleCosine", - [ - axis_eta, - axis_pt, - axis_uTAngleCosine, - axis_uTAngleCosineGenMet, - axis_passIso, - axis_passMT, - ], - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_angleCosineUt0", - "goodMuons_angleCosineUtGenMet0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(etaPtUtAngleCosineGenUtAngleCosine) - # - etaPtUtResoUt = df.HistoBoost( - "etaPtUtResoUt", - [ - axis_eta, - axis_pt, - axis_ut_recoMet, - axis_ut_reso, - axis_passIso, - axis_passMT, - ], - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_utReco0", - "goodMuons_utReso0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(etaPtUtResoUt) - # - etaPtUtResoGenUt = df.HistoBoost( - "etaPtUtResoGenUt", - [ - axis_eta, - axis_pt, - axis_ut_genMet, - axis_ut_reso, - axis_passIso, - axis_passMT, - ], - [ - "goodMuons_eta0", - "goodMuons_pt0", - "goodMuons_utGenMet0", - "goodMuons_utReso0", - "passIso", - "passMT", - "nominal_weight", - ], - ) - results.append(etaPtUtResoGenUt) - # + "passIso", + "passMT", + "nominal_weight", + ], + ) + results.append(etaPtUtResoGenUt) + # # add filter of deltaPhi(muon,met) before other histograms (but after histogram mTStudyForFakes) if args.dphiMuonMetCut > 0.0 and not args.makeMCefficiency: @@ -2129,18 +2130,19 @@ def build_graph(df, dataset): unweighted = df.HistoBoost("unweighted", axes, cols) results.append(unweighted) - nominal_withUt = df.HistoBoost( - "nominal_withUt", - [*axes, axis_ut_fine], - [*cols, "goodMuons_utReco0", "nominal_weight"], - ) - results.append(nominal_withUt) - nominal_withUtAngleCosine = df.HistoBoost( - "nominal_withUtAngleCosine", - [*axes, axis_uTAngleCosine], - [*cols, "goodMuons_angleCosineUt0", "nominal_weight"], - ) - results.append(nominal_withUtAngleCosine) + if auxiliary_histograms: + nominal_withUt = df.HistoBoost( + "nominal_withUt", + [*axes, axis_ut_fine], + [*cols, "goodMuons_utReco0", "nominal_weight"], + ) + results.append(nominal_withUt) + nominal_withUtAngleCosine = df.HistoBoost( + "nominal_withUtAngleCosine", + [*axes, axis_uTAngleCosine], + [*cols, "goodMuons_angleCosineUt0", "nominal_weight"], + ) + results.append(nominal_withUtAngleCosine) if dataset.is_data: nominal = df.HistoBoost("nominal", axes, cols)