From 6ef5dfa3ac31ce3e5152e77c1b24471f7a834d4f Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 8 Aug 2024 19:47:31 +0200 Subject: [PATCH 1/4] additional options in W histmaker for tests with veto SF --- scripts/histmakers/mw_with_mu_eta_pt.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 98f91fdde..9da317e5a 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -39,6 +39,9 @@ parser.add_argument("--selectNonPromptFromLightMesonDecay", action="store_true", help="Test: define a non-prompt muon enriched control region with muons from light meson decays") parser.add_argument("--useGlobalOrTrackerVeto", action="store_true", help="Use global-or-tracker veto definition and scale factors instead of global only") parser.add_argument("--useRefinedVeto", action="store_true", help="Temporary option, it uses a different computation of the veto SF (only implemented for global muons)") +parser.add_argument("--noVetoSF", action="store_true", help="Don't use SF for the veto, for tests") +parser.add_argument("--scaleDYvetoFraction", type=float, default=-1.0, help="Scale fraction of DY background that should receive veto SF by this amount. Negative values do nothing") +parser.add_argument("--scaleDYfull", type=float, default=-1.0, help="Scale inclusive DY background (as if scaling the cross section). Negative values do nothing") # args = parser.parse_args() @@ -50,6 +53,9 @@ if args.selectNonPromptFromLightMesonDecay and args.selectNonPromptFromSV: raise ValueError("Options --selectNonPromptFromSV and --selectNonPromptFromLightMesonDecay cannot be used together.") +if args.scaleDYfull > 0.0 and args.scaleDYvetoFraction > 0.0: + raise ValueError("Options --scaleDYfull and --scaleDYvetoFraction cannot be used together.") + if args.useRefinedVeto and args.useGlobalOrTrackerVeto: raise NotImplementedError("Options --useGlobalOrTrackerVeto and --useRefinedVeto cannot be used together at the moment.") @@ -491,7 +497,15 @@ def build_graph(df, dataset): if isZveto and not args.noGenMatchMC: df = df.Define("weight_vetoSF_nominal", muon_efficiency_veto_helper, ["vetoMuons_pt0","vetoMuons_eta0","vetoMuons_charge0"]) - weight_expr += "*weight_vetoSF_nominal" + if args.scaleDYvetoFraction > 0.0: + # weight different from 1 only for events with >=2 gen muons in acceptance but only 1 reco muon + df = df.Define("weight_DY", f"(vetoMuons_charge0 > -99) ? {args.scaleDYvetoFraction} : 1.0") + elif args.scaleDYfull > 0.0: + df = df.DefinePerSample("weight_DY", f"{args.scaleDYfull}") + else: + df = df.DefinePerSample("weight_DY", f"1.0") + + weight_expr += "*weight_DY" if args.noVetoSF else "*weight_DY*weight_vetoSF_nominal" # prepare inputs for pixel multiplicity helpers cvhName = "cvhideal" From c41032bd9ae4ba06de240f22a88951a2a4c8d226 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 8 Aug 2024 22:11:45 +0200 Subject: [PATCH 2/4] updates for consistency --- scripts/combine/setupCombine.py | 2 +- scripts/histmakers/mw_with_mu_eta_pt.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/combine/setupCombine.py b/scripts/combine/setupCombine.py index 38198adb3..04f0f7dc2 100644 --- a/scripts/combine/setupCombine.py +++ b/scripts/combine/setupCombine.py @@ -842,7 +842,7 @@ def assertSample(name, startsWith=["W", "Z"], excludeMatch=[]): systNameReplace=[("effSystTnP", "effSyst"), ("etaDecorr0", "fullyCorr")], scale=scale, ) - if wmass or wlike_vetoValidation: + if (wmass and not input_tools.args_from_metadata(cardTool, "noVetoSF")) or wlike_vetoValidation: useGlobalOrTrackerVeto = input_tools.args_from_metadata(cardTool, "useGlobalOrTrackerVeto") useRefinedVeto = input_tools.args_from_metadata(cardTool, "useRefinedVeto") allEffTnP_veto = ["effStatTnP_veto_sf", "effSystTnP_veto"] diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index 9da317e5a..a6d8c8e72 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -722,7 +722,7 @@ def build_graph(df, dataset): for es in common.muonEfficiency_altBkgSyst_effSteps: df = syst_tools.add_muon_efficiency_unc_hists_altBkg(results, df, muon_efficiency_helper_syst_altBkg[es], axes, cols, what_analysis=thisAnalysis, step=es, storage_type=storage_type) - if isZveto and not args.noGenMatchMC: + if isZveto and not args.noGenMatchMC and not args.noVetoSF: df = syst_tools.add_muon_efficiency_veto_unc_hists(results, df, muon_efficiency_veto_helper_stat, muon_efficiency_veto_helper_syst, axes, cols, storage_type=storage_type) df = syst_tools.add_L1Prefire_unc_hists(results, df, muon_prefiring_helper_stat, muon_prefiring_helper_syst, axes, cols, storage_type=storage_type) From 95b2234cc7de592376dc1883f6acbbeff690a99b Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Thu, 8 Aug 2024 22:18:15 +0200 Subject: [PATCH 3/4] another consistency fix --- scripts/histmakers/mw_with_mu_eta_pt.py | 29 ++++++++++++++----------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index a6d8c8e72..bcd2fcfa5 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -199,10 +199,11 @@ else: logger.info("Using smoothed scale factors and uncertainties") muon_efficiency_helper, muon_efficiency_helper_syst, muon_efficiency_helper_stat = muon_efficiencies_smooth.make_muon_efficiency_helpers_smooth(filename = args.sfFile, era = era, what_analysis = thisAnalysis, max_pt = axis_pt.edges[-1], isoEfficiencySmoothing = args.isoEfficiencySmoothing, smooth3D=args.smooth3dsf, isoDefinition=args.isolationDefinition) - if args.useRefinedVeto: - muon_efficiency_veto_helper, muon_efficiency_veto_helper_syst, muon_efficiency_veto_helper_stat = wremnants.muon_efficiencies_newVeto.make_muon_efficiency_helpers_newVeto(antiveto=True) - else: - muon_efficiency_veto_helper, muon_efficiency_veto_helper_syst, muon_efficiency_veto_helper_stat = wremnants.muon_efficiencies_veto.make_muon_efficiency_helpers_veto(useGlobalOrTrackerVeto = useGlobalOrTrackerVeto, era = era) + if not args.noVetoSF: + if args.useRefinedVeto: + muon_efficiency_veto_helper, muon_efficiency_veto_helper_syst, muon_efficiency_veto_helper_stat = wremnants.muon_efficiencies_newVeto.make_muon_efficiency_helpers_newVeto(antiveto=True) + else: + muon_efficiency_veto_helper, muon_efficiency_veto_helper_syst, muon_efficiency_veto_helper_stat = wremnants.muon_efficiencies_veto.make_muon_efficiency_helpers_veto(useGlobalOrTrackerVeto = useGlobalOrTrackerVeto, era = era) logger.info(f"SF file: {args.sfFile}") @@ -462,11 +463,12 @@ 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") - df = df.Define("hasMatchDR2idx","wrem::hasMatchDR2idx_closest(goodMuons_eta0,goodMuons_phi0,GenPart_eta[postfsrMuons_inAcc],GenPart_phi[postfsrMuons_inAcc],0.09)") - df = df.Define("GenPart_charge","wrem::charge_from_pdgid(GenPart_pdgId[postfsrMuons_inAcc])") - df = df.Define(f"vetoMuons_pt0", "wrem::unmatched_postfsrMuon_var(GenPart_pt[postfsrMuons_inAcc], GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") - df = df.Define(f"vetoMuons_eta0", "wrem::unmatched_postfsrMuon_var(GenPart_eta[postfsrMuons_inAcc], GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") - df = df.Define(f"vetoMuons_charge0", "wrem::unmatched_postfsrMuon_var(GenPart_charge, GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") + if not args.noVetoSF: + df = df.Define("hasMatchDR2idx","wrem::hasMatchDR2idx_closest(goodMuons_eta0,goodMuons_phi0,GenPart_eta[postfsrMuons_inAcc],GenPart_phi[postfsrMuons_inAcc],0.09)") + df = df.Define("GenPart_charge","wrem::charge_from_pdgid(GenPart_pdgId[postfsrMuons_inAcc])") + df = df.Define(f"vetoMuons_pt0", "wrem::unmatched_postfsrMuon_var(GenPart_pt[postfsrMuons_inAcc], GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") + df = df.Define(f"vetoMuons_eta0", "wrem::unmatched_postfsrMuon_var(GenPart_eta[postfsrMuons_inAcc], GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") + df = df.Define(f"vetoMuons_charge0", "wrem::unmatched_postfsrMuon_var(GenPart_charge, GenPart_pt[postfsrMuons_inAcc], hasMatchDR2idx)") ######################################################################## # define event weights here since they are needed below for some helpers if dataset.is_data: @@ -496,16 +498,17 @@ def build_graph(df, dataset): weight_expr += "*weight_fullMuonSF_withTrackingReco" if isZveto and not args.noGenMatchMC: - df = df.Define("weight_vetoSF_nominal", muon_efficiency_veto_helper, ["vetoMuons_pt0","vetoMuons_eta0","vetoMuons_charge0"]) if args.scaleDYvetoFraction > 0.0: # weight different from 1 only for events with >=2 gen muons in acceptance but only 1 reco muon df = df.Define("weight_DY", f"(vetoMuons_charge0 > -99) ? {args.scaleDYvetoFraction} : 1.0") + weight_expr += "*weight_DY" elif args.scaleDYfull > 0.0: df = df.DefinePerSample("weight_DY", f"{args.scaleDYfull}") - else: - df = df.DefinePerSample("weight_DY", f"1.0") + weight_expr += "*weight_DY" - weight_expr += "*weight_DY" if args.noVetoSF else "*weight_DY*weight_vetoSF_nominal" + if not args.noVetoSF: + df = df.Define("weight_vetoSF_nominal", muon_efficiency_veto_helper, ["vetoMuons_pt0","vetoMuons_eta0","vetoMuons_charge0"]) + weight_expr += "*weight_vetoSF_nominal" # prepare inputs for pixel multiplicity helpers cvhName = "cvhideal" From e95e21e12e06818c5c1b8c93c8af0dfdd4adf380 Mon Sep 17 00:00:00 2001 From: Marco Cipriani Date: Sun, 11 Aug 2024 15:38:06 +0200 Subject: [PATCH 4/4] remove option to scale DY cross section from W histmaker --- scripts/histmakers/mw_with_mu_eta_pt.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/scripts/histmakers/mw_with_mu_eta_pt.py b/scripts/histmakers/mw_with_mu_eta_pt.py index bcd2fcfa5..18ba2cf2d 100644 --- a/scripts/histmakers/mw_with_mu_eta_pt.py +++ b/scripts/histmakers/mw_with_mu_eta_pt.py @@ -41,7 +41,6 @@ parser.add_argument("--useRefinedVeto", action="store_true", help="Temporary option, it uses a different computation of the veto SF (only implemented for global muons)") parser.add_argument("--noVetoSF", action="store_true", help="Don't use SF for the veto, for tests") parser.add_argument("--scaleDYvetoFraction", type=float, default=-1.0, help="Scale fraction of DY background that should receive veto SF by this amount. Negative values do nothing") -parser.add_argument("--scaleDYfull", type=float, default=-1.0, help="Scale inclusive DY background (as if scaling the cross section). Negative values do nothing") # args = parser.parse_args() @@ -53,9 +52,6 @@ if args.selectNonPromptFromLightMesonDecay and args.selectNonPromptFromSV: raise ValueError("Options --selectNonPromptFromSV and --selectNonPromptFromLightMesonDecay cannot be used together.") -if args.scaleDYfull > 0.0 and args.scaleDYvetoFraction > 0.0: - raise ValueError("Options --scaleDYfull and --scaleDYvetoFraction cannot be used together.") - if args.useRefinedVeto and args.useGlobalOrTrackerVeto: raise NotImplementedError("Options --useGlobalOrTrackerVeto and --useRefinedVeto cannot be used together at the moment.") @@ -502,9 +498,6 @@ def build_graph(df, dataset): # weight different from 1 only for events with >=2 gen muons in acceptance but only 1 reco muon df = df.Define("weight_DY", f"(vetoMuons_charge0 > -99) ? {args.scaleDYvetoFraction} : 1.0") weight_expr += "*weight_DY" - elif args.scaleDYfull > 0.0: - df = df.DefinePerSample("weight_DY", f"{args.scaleDYfull}") - weight_expr += "*weight_DY" if not args.noVetoSF: df = df.Define("weight_vetoSF_nominal", muon_efficiency_veto_helper, ["vetoMuons_pt0","vetoMuons_eta0","vetoMuons_charge0"])