diff --git a/higgs_dna/systematics/event_weight_systematics.py b/higgs_dna/systematics/event_weight_systematics.py index 4b98ba3bc2c805a4b095f8a48ddd94e64d6cb7f4..b734539222a38db039b9a755871cc8570e3ef880 100644 --- a/higgs_dna/systematics/event_weight_systematics.py +++ b/higgs_dna/systematics/event_weight_systematics.py @@ -1,7 +1,6 @@ import numpy as np import json import os -from scipy.interpolate import interp1d import correctionlib import awkward as ak from higgs_dna.utils.misc_utils import choose_jet @@ -609,41 +608,46 @@ def NNLOPS( json_file = os.path.join(os.path.dirname(__file__), "JSONs/NNLOPS_reweight.json") if is_correction: - if 'ggh' not in dataset_name.lower() and 'glugluh' not in dataset_name.lower(): - logger.info(f"\n WARNING: You specified NNLOPS reweighting for dataset with {dataset_name} but this does not appear like a ggF sample. Consider checking your runner JSON Proceed with caution.") - # Extract NNLOPS weights from json file - with open(json_file, "r") as jf: - nnlops_reweight = json.load(jf) - - # Load reweight factors for specific generator - nnlops_reweight = nnlops_reweight[generator] - - # Build linear splines for different njet bins - spline_0jet = interp1d( - nnlops_reweight["0jet"]["pt"], nnlops_reweight["0jet"]["weight"] - ) - spline_1jet = interp1d( - nnlops_reweight["1jet"]["pt"], nnlops_reweight["1jet"]["weight"] - ) - spline_2jet = interp1d( - nnlops_reweight["2jet"]["pt"], nnlops_reweight["2jet"]["weight"] - ) - spline_ge3jet = interp1d( - nnlops_reweight["3jet"]["pt"], nnlops_reweight["3jet"]["weight"] - ) + if ( + all(s not in dataset_name.lower() for s in ('glugluhh', 'gghh')) + and any(s in dataset_name.lower() for s in ("ggh", "glugluh")) + ): + # Extract NNLOPS weights from json file + with open(json_file, "r") as jf: + nnlops_reweight = json.load(jf) - # Load truth Higgs pt and njets (pt>30) from events - higgs_pt = events.HTXS.Higgs_pt - njets30 = events.HTXS.njets30 - - # Extract scale factors from splines and mask for different jet bins - # Define maximum pt values as interpolated splines only go up so far - sf = ( - (njets30 == 0) * spline_0jet(np.minimum(np.array(higgs_pt), 125.0)) - + (njets30 == 1) * spline_1jet(np.minimum(np.array(higgs_pt), 625.0)) - + (njets30 == 2) * spline_2jet(np.minimum(np.array(higgs_pt), 800.0)) - + (njets30 >= 3) * spline_ge3jet(np.minimum(np.array(higgs_pt), 925.0)) - ) + # Load reweight factors for specific generator + nnlops_reweight = nnlops_reweight[generator] + + # Build linear splines for different njet bins + spline_0jet = np.interp( + nnlops_reweight["0jet"]["pt"], nnlops_reweight["0jet"]["weight"] + ) + spline_1jet = np.interp( + nnlops_reweight["1jet"]["pt"], nnlops_reweight["1jet"]["weight"] + ) + spline_2jet = np.interp( + nnlops_reweight["2jet"]["pt"], nnlops_reweight["2jet"]["weight"] + ) + spline_ge3jet = np.interp( + nnlops_reweight["3jet"]["pt"], nnlops_reweight["3jet"]["weight"] + ) + + # Load truth Higgs pt and njets (pt>30) from events + higgs_pt = events.HTXS.Higgs_pt + njets30 = events.HTXS.njets30 + + # Extract scale factors from splines and mask for different jet bins + # Define maximum pt values as interpolated splines only go up so far + sf = ( + (njets30 == 0) * spline_0jet(np.minimum(np.array(higgs_pt), 125.0)) + + (njets30 == 1) * spline_1jet(np.minimum(np.array(higgs_pt), 625.0)) + + (njets30 == 2) * spline_2jet(np.minimum(np.array(higgs_pt), 800.0)) + + (njets30 >= 3) * spline_ge3jet(np.minimum(np.array(higgs_pt), 925.0)) + ) + + else: + logger.info(f"\n WARNING: You specified NNLOPS reweighting for dataset with {dataset_name} but this does not appear like a ggF to single Higgs sample. The reweighting in not applied.") else: raise RuntimeError(