Skip to content

Commit

Permalink
Merge pull request #519 from cippy/mainWMass_2024Aug08_11p30am_openPR
Browse files Browse the repository at this point in the history
Utility options for W histmaker to test veto SF
  • Loading branch information
davidwalter2 authored Aug 11, 2024
2 parents 696350d + e95e21e commit a8061c8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
2 changes: 1 addition & 1 deletion scripts/combine/setupCombine.py
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ def fake_nonclosure(h, axesToDecorrNames, *args, **kwargs):
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"]
Expand Down
34 changes: 22 additions & 12 deletions scripts/histmakers/mw_with_mu_eta_pt.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
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")
#

args = parser.parse_args()
Expand Down Expand Up @@ -193,10 +195,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}")

Expand Down Expand Up @@ -456,11 +459,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:
Expand Down Expand Up @@ -490,8 +494,14 @@ 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"])
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")
weight_expr += "*weight_DY"

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"
Expand Down Expand Up @@ -708,7 +718,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)
Expand Down

0 comments on commit a8061c8

Please sign in to comment.