From 65807540db99364f114e5ddf468504d140a3f27c Mon Sep 17 00:00:00 2001 From: Jan Eysermans Date: Thu, 30 Nov 2023 03:23:50 -0500 Subject: [PATCH 1/2] Add extra herapdf20 uncertainties --- wremnants/syst_tools.py | 2 +- wremnants/theory_tools.py | 28 +++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/wremnants/syst_tools.py b/wremnants/syst_tools.py index f7defc7e8..e9d2fcae7 100644 --- a/wremnants/syst_tools.py +++ b/wremnants/syst_tools.py @@ -350,7 +350,7 @@ def add_pdf_hists(results, df, dataset, axes, cols, pdfs, base_name="nominal", a tensorASName = f"{pdfName}ASWeights_tensor" npdf=pdfInfo["entries"] pdfHistName = Datagroups.histName(base_name, syst=pdfName) - names = getattr(theory_tools, f"pdfNames{'Sym' if pdfInfo['combine'] == 'symHessian' else 'Asym'}Hessian")(pdfInfo["entries"], pdfName) + names = getattr(theory_tools, f"pdfNames{'Sym' if pdfInfo['combine'] == 'symHessian' else 'Asym'}Hessian")(pdfInfo["entries"]+(pdfInfo["entriesExt"] if "entriesExt" in pdfInfo else 0), pdfName) pdf_ax = hist.axis.StrCategory(names, name="pdfVar") if tensorName not in df.GetColumnNames(): logger.warning(f"PDF {pdf} was not found for sample {dataset}. Skipping uncertainty hist!") diff --git a/wremnants/theory_tools.py b/wremnants/theory_tools.py index 769efd5a5..4bfd21f9e 100644 --- a/wremnants/theory_tools.py +++ b/wremnants/theory_tools.py @@ -127,11 +127,14 @@ "branch" : "LHEPdfWeightAltSet20", "combine" : "asymHessian", "entries" : 29, + "branchExt" : "LHEPdfWeightAltSet21", + "entriesExt": 13*2, "alphas" : ["LHEPdfWeightAltSet20[0]", "LHEPdfWeightAltSet22[0]", "LHEPdfWeightAltSet23[0]"], # alphas 116-120 "alphasRange" : "002", }, } + only_central_pdf_datasets = [ "Wplusmunu_bugfix", "Wminusmunu_bugfix", @@ -267,6 +270,9 @@ def define_pdf_columns(df, dataset_name, pdfs, noAltUnc): if pdfName == "pdfMSHT20": df = pdfBugfixMSHT20(df, tensorName) + if pdfName == "pdfHERAPDF20": + df = pdfHERAPDF20(df, tensorName, entries, pdfInfo["branchExt"], pdfInfo["entriesExt"]) + df = df.Define(tensorASName, f"Eigen::TensorFixedSize> res; " + \ " ".join([f"res({i}) = nominal_weight/central_pdf_weight*{p};" for i,p in enumerate(pdfInfo['alphas'])]) + \ "return wrem::clip_tensor(res, theory_weight_truncate)") @@ -558,4 +564,24 @@ def pdfBugfixMSHT20(df , tensorPDFName): f"auto& res = {tensorPDFName};" f"res(15) = {tensorPDFName}(0) - ({tensorPDFName}(15) - {tensorPDFName}(0));" "return res") - + +def pdfHERAPDF20(df , tensorPDFName, entriesMain, branchExt, entriesExt): + # extend HERA pdfs with extra variations which should be symmetrized + # remove the first from the VAR branch, equal to the nominal + start = 0 + entries_branch = 14 # total entries in the nano branch + df = df.Define(f"{tensorPDFName}_ext", f"auto res = wrem::clip_tensor(wrem::vec_to_tensor_t({branchExt}, {start}), theory_weight_truncate); res = nominal_weight/central_pdf_weight*res; return res;") + df = df.Define( + f"{tensorPDFName}_ext_sym", + (f"Eigen::TensorFixedSize> res;" + "for(int i=0; i Date: Fri, 1 Dec 2023 12:49:45 -0500 Subject: [PATCH 2/2] Treatment of extra HERA PDFs in setupCombine --- utilities/common.py | 2 ++ wremnants/combine_theory_helper.py | 12 +++++++++++ wremnants/syst_tools.py | 2 +- wremnants/theory_tools.py | 34 +++++++----------------------- 4 files changed, 23 insertions(+), 27 deletions(-) diff --git a/utilities/common.py b/utilities/common.py index a25f3c80f..d55bf7c2e 100644 --- a/utilities/common.py +++ b/utilities/common.py @@ -153,6 +153,8 @@ def common_parser(for_reco_highPU=False): class PDFFilterAction(argparse.Action): def __call__(self, parser, namespace, values, option_string=None): # Filter unique values, but keep first item in its position + if "herapdf20" in values: + values.append("herapdf20ext") unique_values = [values[0], *set([x for x in values[1:]])] setattr(namespace, self.dest, unique_values) diff --git a/wremnants/combine_theory_helper.py b/wremnants/combine_theory_helper.py index c1e37817c..b82035456 100644 --- a/wremnants/combine_theory_helper.py +++ b/wremnants/combine_theory_helper.py @@ -447,6 +447,18 @@ def add_pdf_uncertainty(self, action=None, from_corr=False, scale=1): skipEntries=[{pdf_ax : "^pdf0[a-z]*"}], **pdf_args ) + if pdfName == 'pdfHERAPDF20': + self.card_tool.addSystematic(pdf_hist+'ext', + skipEntries=[{pdf_ax : "^pdf0[a-z]*"}], + processes=['wtau_samples', 'single_v_nonsig_samples'] if self.skipFromSignal else ['single_v_samples'], + mirror=True, + group=pdfName, + splitGroup={f"{pdfName}NoAlphaS": '.*'}, + passToFakes=self.propagate_to_fakes, + actionMap=action, + scale=pdfInfo.get("scale", 1)*scale, + systAxes=[pdf_ax], + ) asRange = pdfInfo['alphasRange'] asname = f"{pdfName}alphaS{asRange}" if not from_corr else pdf_hist.replace("Vars", "_pdfas") diff --git a/wremnants/syst_tools.py b/wremnants/syst_tools.py index e9d2fcae7..f7defc7e8 100644 --- a/wremnants/syst_tools.py +++ b/wremnants/syst_tools.py @@ -350,7 +350,7 @@ def add_pdf_hists(results, df, dataset, axes, cols, pdfs, base_name="nominal", a tensorASName = f"{pdfName}ASWeights_tensor" npdf=pdfInfo["entries"] pdfHistName = Datagroups.histName(base_name, syst=pdfName) - names = getattr(theory_tools, f"pdfNames{'Sym' if pdfInfo['combine'] == 'symHessian' else 'Asym'}Hessian")(pdfInfo["entries"]+(pdfInfo["entriesExt"] if "entriesExt" in pdfInfo else 0), pdfName) + names = getattr(theory_tools, f"pdfNames{'Sym' if pdfInfo['combine'] == 'symHessian' else 'Asym'}Hessian")(pdfInfo["entries"], pdfName) pdf_ax = hist.axis.StrCategory(names, name="pdfVar") if tensorName not in df.GetColumnNames(): logger.warning(f"PDF {pdf} was not found for sample {dataset}. Skipping uncertainty hist!") diff --git a/wremnants/theory_tools.py b/wremnants/theory_tools.py index 4bfd21f9e..6bacb9135 100644 --- a/wremnants/theory_tools.py +++ b/wremnants/theory_tools.py @@ -127,11 +127,17 @@ "branch" : "LHEPdfWeightAltSet20", "combine" : "asymHessian", "entries" : 29, - "branchExt" : "LHEPdfWeightAltSet21", - "entriesExt": 13*2, "alphas" : ["LHEPdfWeightAltSet20[0]", "LHEPdfWeightAltSet22[0]", "LHEPdfWeightAltSet23[0]"], # alphas 116-120 "alphasRange" : "002", }, + "herapdf20ext" : { + "name" : "pdfHERAPDF20ext", + "branch" : "LHEPdfWeightAltSet21", + "combine" : "symHessian", + "entries" : 14, + "alphas" : ["LHEPdfWeightAltSet20[0]", "LHEPdfWeightAltSet22[0]", "LHEPdfWeightAltSet23[0]"], # dummy AS + "alphasRange" : "002", + }, } @@ -270,9 +276,6 @@ def define_pdf_columns(df, dataset_name, pdfs, noAltUnc): if pdfName == "pdfMSHT20": df = pdfBugfixMSHT20(df, tensorName) - if pdfName == "pdfHERAPDF20": - df = pdfHERAPDF20(df, tensorName, entries, pdfInfo["branchExt"], pdfInfo["entriesExt"]) - df = df.Define(tensorASName, f"Eigen::TensorFixedSize> res; " + \ " ".join([f"res({i}) = nominal_weight/central_pdf_weight*{p};" for i,p in enumerate(pdfInfo['alphas'])]) + \ "return wrem::clip_tensor(res, theory_weight_truncate)") @@ -564,24 +567,3 @@ def pdfBugfixMSHT20(df , tensorPDFName): f"auto& res = {tensorPDFName};" f"res(15) = {tensorPDFName}(0) - ({tensorPDFName}(15) - {tensorPDFName}(0));" "return res") - -def pdfHERAPDF20(df , tensorPDFName, entriesMain, branchExt, entriesExt): - # extend HERA pdfs with extra variations which should be symmetrized - # remove the first from the VAR branch, equal to the nominal - start = 0 - entries_branch = 14 # total entries in the nano branch - df = df.Define(f"{tensorPDFName}_ext", f"auto res = wrem::clip_tensor(wrem::vec_to_tensor_t({branchExt}, {start}), theory_weight_truncate); res = nominal_weight/central_pdf_weight*res; return res;") - df = df.Define( - f"{tensorPDFName}_ext_sym", - (f"Eigen::TensorFixedSize> res;" - "for(int i=0; i