Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/rkansal47/HHbbVV into vbf_t…
Browse files Browse the repository at this point in the history
…emplate
  • Loading branch information
rkansal47 committed Sep 21, 2023
2 parents 79b090b + 65c4156 commit 1b22f63
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
12 changes: 11 additions & 1 deletion src/HHbbVV/postprocessing/postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ def get_res_selection_regions(
]


plot_sig_keys_nonres = [
"HHbbVV",
"VBFHHbbVV",
"qqHH_CV_1_C2V_0_kl_1_HHbbVV",
"qqHH_CV_1_C2V_2_kl_1_HHbbVV",
]


def main(args):
shape_vars, scan, scan_cuts, scan_wps = _init(args)
sig_keys, sig_samples, bg_keys, bg_samples = _process_samples(args)
Expand Down Expand Up @@ -1109,6 +1117,9 @@ def lpsfs(
- Does it for all years once if args.lp_sf_all_years or just for the given year
2) Saves them to ``systs_file`` and CSV for posterity
"""
if not all_years:
warnings.warn(f"LP SF only calculated from single year's samples", RuntimeWarning)

for sig_key in sig_keys:
if sig_key not in systematics or "lp_sf" not in systematics[sig_key]:
print(f"\nGetting LP SFs for {sig_key}")
Expand All @@ -1127,7 +1138,6 @@ def lpsfs(
)
# Only for testing, can do just for a single year
else:
warnings.warn(f"LP SF only calculated from single year's samples", RuntimeWarning)
# calculate only for current year
events_dict[sig_key] = postprocess_lpsfs(events_dict[sig_key])
sel, cf = utils.make_selection(
Expand Down
19 changes: 11 additions & 8 deletions src/HHbbVV/postprocessing/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ def _hem_cleaning(sample, events):
if sample.endswith("2018C") or sample.endswith("2018D"):
hem_cut = np.any(
(events["ak8FatJetEta"] > -3.2)
* (events["ak8FatJetEta"] < -1.3)
* (events["ak8FatJetPhi"] > -1.57)
* (events["ak8FatJetPhi"] < -0.87),
& (events["ak8FatJetEta"] < -1.3)
& (events["ak8FatJetPhi"] > -1.57)
& (events["ak8FatJetPhi"] < -0.87),
axis=1,
)
print(f"Removing {np.sum(hem_cut)} events")
Expand All @@ -192,11 +192,11 @@ def _hem_cleaning(sample, events):
else:
hem_cut = np.any(
(events["ak8FatJetEta"] > -3.2)
* (events["ak8FatJetEta"] < -1.3)
* (events["ak8FatJetPhi"] > -1.57)
* (events["ak8FatJetPhi"] < -0.87),
& (events["ak8FatJetEta"] < -1.3)
& (events["ak8FatJetPhi"] > -1.57)
& (events["ak8FatJetPhi"] < -0.87),
axis=1,
) * (np.random.rand(len(events)) < 0.632)
) & (np.random.rand(len(events)) < 0.632)
print(f"Removing {np.sum(hem_cut)} events")
return events[~hem_cut]

Expand All @@ -207,6 +207,7 @@ def load_samples(
year: str,
filters: List = None,
columns: List = None,
hem_cleaning: bool = True,
) -> Dict[str, pd.DataFrame]:
"""
Loads events with an optional filter.
Expand All @@ -217,6 +218,8 @@ def load_samples(
samples (Dict[str, str]): dictionary of samples and selectors to load.
year (str): year.
filters (List): Optional filters when loading data.
columns (List): Optional columns to load.
hem_cleaning (bool): Whether to apply HEM cleaning to 2018 data.
Returns:
Dict[str, pd.DataFrame]: ``events_dict`` dictionary of events dataframe for each sample.
Expand Down Expand Up @@ -272,7 +275,7 @@ def load_samples(
else:
events["finalWeight"] = events["weight"]

if year == "2018":
if year == "2018" and hem_cleaning:
events = _hem_cleaning(sample, events)

if not_empty:
Expand Down

0 comments on commit 1b22f63

Please sign in to comment.