From 73335a433746712851aeaba6de75ade5d23d02df Mon Sep 17 00:00:00 2001
From: Jie Xiao <jie.xiao@cern.ch>
Date: Mon, 27 May 2024 11:18:52 +0200
Subject: [PATCH] Add a flag to veto events with jets in the EE+ Leakage region

---
 higgs_dna/selections/jet_selections.py | 17 +++++++++++------
 higgs_dna/workflows/base.py            |  2 +-
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/higgs_dna/selections/jet_selections.py b/higgs_dna/selections/jet_selections.py
index ceed7673..44a336a7 100755
--- a/higgs_dna/selections/jet_selections.py
+++ b/higgs_dna/selections/jet_selections.py
@@ -242,6 +242,9 @@ def jetvetomap(events, logger, dataset_name, year="2022preEE"):
     vetomap = cset[key_map[year]].evaluate(*(inputs))
 
     if not year == "2022postEE":
+        flag_eep_jet = (
+            awkward.zeros_like(jets.pt) > 1
+        )  # flag_eep_jet always False for non-2022postEE
         sel_obj.add("vetomap", np.abs(vetomap) > 0)
     else:
         # ref: https://twiki.cern.ch/twiki/bin/viewauth/CMS/PdmVRun3Analysis#From_JME
@@ -251,17 +254,19 @@ def jetvetomap(events, logger, dataset_name, year="2022preEE"):
         input_dict["type"] = "jetvetomap_eep"
         inputs = [input_dict[input.name] for input in cset[key_map[year]].inputs]
         vetomap_eep = cset[key_map[year]].evaluate(*(inputs))
-        sel_obj.add(
-            "vetomap",
-            (np.abs(vetomap) > 0) | ((np.abs(vetomap_eep) > 0) & (jets.pt > 30)),
-        )
-
+        flag_eep_jet = (np.abs(vetomap_eep) > 0) & (jets.pt > 30)
+        sel_obj.add("vetomap", (np.abs(vetomap) > 0) | (flag_eep_jet))
     sel_veto_jet = sel_obj.all(*(sel_obj.names))
     sel_good_jet = ~awkward.Array(sel_veto_jet)
     logger.debug(
         f"[{systematic}] total: {len(sel_good_jet)}, pass: {awkward.sum(sel_good_jet)}"
     )
     sel_good_jet_jagged = awkward.unflatten(sel_good_jet, count)
+    flag_eep_jet_jagged = awkward.unflatten(flag_eep_jet, count)
     events.Jet = jets_jagged[sel_good_jet_jagged]
+    sel_event_veto = ~awkward.any(flag_eep_jet_jagged, axis=1)
+    logger.debug(
+        f"[{systematic}] total event: {len(sel_event_veto)}, pass event: {awkward.sum(sel_event_veto)}"
+    )
 
-    return events
+    return events[sel_event_veto]
diff --git a/higgs_dna/workflows/base.py b/higgs_dna/workflows/base.py
index 8c6e75b8..21d3a4d1 100644
--- a/higgs_dna/workflows/base.py
+++ b/higgs_dna/workflows/base.py
@@ -288,7 +288,7 @@ class HggBaseProcessor(processor.ProcessorABC):  # type: ignore
                 logger.info(
                     f"[ lumimask ] Skip now! Unable to find year info of {dataset_name}"
                 )
-        # apply jetvetomap
+        # apply jetvetomap: only retain events that without any jets in the EE leakage region
         if not self.skipJetVetoMap:
             events = jetvetomap(
                 events, logger, dataset_name, year=self.year[dataset_name][0]
-- 
GitLab