Skip to content

Commit

Permalink
Improve cut diagnostics print outs, clean up dipho preselection
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-may committed Feb 4, 2021
1 parent d512d21 commit 2b96e7e
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 77 deletions.
14 changes: 14 additions & 0 deletions Preselection/data/samples.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"HH_ggTauTau" : {
"resonant" : true,
"fpo" : 1,
"process_id" : -1,
"2016" : {
Expand All @@ -17,6 +18,7 @@
}
},
"Data" : {
"resonant" : false,
"fpo" : 10,
"process_id" : 0,
"2016" : {
Expand All @@ -33,6 +35,7 @@
}
},
"ZGamma" : {
"resonant" : false,
"fpo" : 1,
"process_id" : 2,
"2016" : {
Expand All @@ -49,6 +52,7 @@
}
},
"DiPhoton" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 3,
"2016" : {
Expand All @@ -65,6 +69,7 @@
}
},
"WGamma" : {
"resonant" : false,
"fpo" : 1,
"process_id" : 4,
"2016" : {
Expand All @@ -81,6 +86,7 @@
}
},
"TTbar" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 5,
"2016" : {
Expand All @@ -97,6 +103,7 @@
}
},
"TTGamma" : {
"resonant" : false,
"fpo" : 1,
"process_id" : 6,
"2016" : {
Expand All @@ -113,6 +120,7 @@
}
},
"TTGG" : {
"resonant" : false,
"fpo" : 1,
"process_id" : 7,
"2016" : {
Expand All @@ -129,6 +137,7 @@
}
},
"GJets_HT40To100" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 8,
"2016" : {
Expand All @@ -145,6 +154,7 @@
}
},
"GJets_HT-100To200" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 8,
"2016" : {
Expand All @@ -161,6 +171,7 @@
}
},
"GJets_HT-200To400" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 8,
"2016" : {
Expand All @@ -177,6 +188,7 @@
}
},
"GJets_HT-400To600" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 8,
"2016" : {
Expand All @@ -193,6 +205,7 @@
}
},
"GJets_HT-600ToInf" : {
"resonant" : false,
"fpo" : 5,
"process_id" : 8,
"2016" : {
Expand All @@ -209,6 +222,7 @@
}
},
"VH" : {
"resonant" : true,
"fpo" : 1,
"process_id" : 9,
"2016" : {
Expand Down
42 changes: 28 additions & 14 deletions Preselection/data/samples_and_scale1fb.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
]
},
"fpo": 10,
"process_id": 0
"process_id": 0,
"resonant": false
},
"DiPhoton": {
"2016": {
Expand Down Expand Up @@ -70,7 +71,8 @@
]
},
"fpo": 5,
"process_id": 3
"process_id": 3,
"resonant": false
},
"GJets_HT-100To200": {
"2016": {
Expand Down Expand Up @@ -108,7 +110,8 @@
]
},
"fpo": 5,
"process_id": 8
"process_id": 8,
"resonant": false
},
"GJets_HT-200To400": {
"2016": {
Expand Down Expand Up @@ -146,7 +149,8 @@
]
},
"fpo": 5,
"process_id": 8
"process_id": 8,
"resonant": false
},
"GJets_HT-400To600": {
"2016": {
Expand Down Expand Up @@ -184,7 +188,8 @@
]
},
"fpo": 5,
"process_id": 8
"process_id": 8,
"resonant": false
},
"GJets_HT-600ToInf": {
"2016": {
Expand Down Expand Up @@ -222,7 +227,8 @@
]
},
"fpo": 5,
"process_id": 8
"process_id": 8,
"resonant": false
},
"GJets_HT40To100": {
"2016": {
Expand Down Expand Up @@ -260,7 +266,8 @@
]
},
"fpo": 5,
"process_id": 8
"process_id": 8,
"resonant": false
},
"HH_ggTauTau": {
"2016": {
Expand Down Expand Up @@ -298,7 +305,8 @@
]
},
"fpo": 1,
"process_id": -1
"process_id": -1,
"resonant": true
},
"TTGG": {
"2016": {
Expand Down Expand Up @@ -335,7 +343,8 @@
]
},
"fpo": 1,
"process_id": 7
"process_id": 7,
"resonant": false
},
"TTGamma": {
"2016": {
Expand Down Expand Up @@ -374,7 +383,8 @@
]
},
"fpo": 1,
"process_id": 6
"process_id": 6,
"resonant": false
},
"TTbar": {
"2016": {
Expand Down Expand Up @@ -411,7 +421,8 @@
]
},
"fpo": 5,
"process_id": 5
"process_id": 5,
"resonant": false
},
"VH": {
"2016": {
Expand Down Expand Up @@ -448,7 +459,8 @@
]
},
"fpo": 1,
"process_id": 9
"process_id": 9,
"resonant": true
},
"WGamma": {
"2016": {
Expand Down Expand Up @@ -487,7 +499,8 @@
]
},
"fpo": 1,
"process_id": 4
"process_id": 4,
"resonant": false
},
"ZGamma": {
"2016": {
Expand Down Expand Up @@ -526,6 +539,7 @@
]
},
"fpo": 1,
"process_id": 2
"process_id": 2,
"resonant": false
}
}
30 changes: 21 additions & 9 deletions Preselection/helpers/loop_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ def __init__(self, **kwargs):
self.options = kwargs.get("options")
self.systematics = kwargs.get("systematics")
self.years = kwargs.get("years").split(",")
self.select_samples = kwargs.get("select_samples")
if self.select_samples != "all":
self.select_samples = self.select_samples.split(",")

self.output_tag = kwargs.get("output_tag")
self.output_dir = kwargs.get("output_dir")
Expand Down Expand Up @@ -98,6 +101,10 @@ def prepare_jobs(self):
self.jobs_manager = []

for sample, info in self.samples_dict.items():
if self.select_samples != "all":
if sample not in self.select_samples:
continue

if self.debug > 0:
print("[LoopHelper] Running over sample: %s" % sample)
print("[LoopHelper] details: ", info)
Expand All @@ -117,7 +124,8 @@ def prepare_jobs(self):
"process_id" : info["process_id"],
"year" : year,
"scale1fb" : 1 if sample == "Data" else year_info["metadata"]["scale1fb"],
"lumi" : lumi_map[year]
"lumi" : lumi_map[year],
"resonant" : info["resonant"]
}

file_splits = self.chunks(files, info["fpo"])
Expand Down Expand Up @@ -207,21 +215,21 @@ def write_summary(self):
### Physics: selections, etc ###
################################

def select_events(self, events):
def select_events(self, events, metadata):
# Dipho preselection
events = photon_selections.diphoton_preselection(events, self.debug)
events = photon_selections.diphoton_preselection(events, metadata["resonant"], self.debug)
events.Photon = events.Photon[photon_selections.select_photons(events, self.debug)]

if self.selections == "HHggTauTau_InclusivePresel":
events = analysis_selections.ggTauTau_inclusive_preselection(events, self.debug)
events.Electron = events.Electron[lepton_selections.select_electrons(events, self.debug)]
events.Muon = events.Muon[lepton_selections.select_muons(events, self.debug)]
events.Tau = events.Tau[tau_selections.select_taus(events, self.debug)]
events.Electron = events.Electron[lepton_selections.select_electrons(events, events.Photon, self.debug)]
events.Muon = events.Muon[lepton_selections.select_muons(events, events.Photon, self.debug)]
events.Tau = events.Tau[tau_selections.select_taus(events, events.Photon, events.Muon, events.Electron, self.debug)]

elif self.selections == "ttH_LeptonicPresel":
events = analysis_selections.tth_leptonic_preselection(events, self.debug)
events.Electron = events.Electron[lepton_selections.select_electrons(events, self.debug)]
events.Muon = events.Muon[lepton_selections.select_muons(events, self.debug)]
events.Electron = events.Electron[lepton_selections.select_electrons(events, events.Photon, self.debug)]
events.Muon = events.Muon[lepton_selections.select_muons(events, events.Photon, self.debug)]

return events

Expand All @@ -243,6 +251,10 @@ def loop_sample(self, job):
files = job["files"]
output = job["output"]

selection_metadata = {
"resonant" : info["resonant"]
}

if self.debug > 0:
print("[LoopHelper] Running job with parameters", job)

Expand All @@ -262,7 +274,7 @@ def loop_sample(self, job):
if events is None:
self.outputs.pop(output)
return
events = self.select_events(events)
events = self.select_events(events, selection_metadata)

events["process_id"] = numpy.ones(len(events)) * process_id
if data:
Expand Down
6 changes: 6 additions & 0 deletions Preselection/loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
type = str,
default = "2016,2017,2018"
)
parser.add_argument(
"--select_samples",
help = "csv list of samples to run over (should be a subset of samples in args.samples)",
type = str,
default = "all"
)

# --options points to a json file containing options for looping
# this could include things like additional scaling of bkg samples,
Expand Down
2 changes: 2 additions & 0 deletions Preselection/scripts/scale1fb.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ def calculate_metadata(files, xs, debug):
for sample, info in output.items():
if sample in original_output.keys():
for year, year_info in original_output[sample].items():
if "201" not in year:
continue
if "metadata" in year_info.keys():
if "scale1fb" in year_info["metadata"].keys():
output[sample][year] = original_output[sample][year]
Expand Down
31 changes: 22 additions & 9 deletions Preselection/selections/analysis_selections.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,37 @@
import selections.photon_selections as photon_selections

def ggTauTau_inclusive_preselection(events, debug):
cut_diagnostics = utils.CutDiagnostics(n_events_initial = len(events), debug = debug, cut_set = "[analysis_selections.py : ggTauTau_inclusive_preselection]")
cut_diagnostics = utils.CutDiagnostics(events = events, debug = debug, cut_set = "[analysis_selections.py : ggTauTau_inclusive_preselection]")

# Get number of electrons, muons, taus
n_electrons = awkward.num(events.Electron[lepton_selections.select_electrons(events, debug)])
n_muons = awkward.num(events.Muon[lepton_selections.select_muons(events, debug)])
electron_selection = lepton_selections.select_electrons(events, events.Photon, debug)
muon_selection = lepton_selections.select_muons(events, events.Photon, debug)
tau_selection = tau_selections.select_taus(events, events.Photon, events.Muon[muon_selection], events.Electron[electron_selection], debug)

n_electrons = awkward.num(events.Electron[electron_selection])
n_muons = awkward.num(events.Muon[muon_selection])
n_taus = awkward.num(events.Tau[tau_selection])

# Require >= 1 lep/tau
n_leptons_and_taus = n_electrons + n_muons + n_taus
lep_tau_cut = n_leptons_and_taus >= 1

n_taus = awkward.num(events.Tau[tau_selections.select_taus(events, debug)])
# Require OS leptons/taus for events with 2 leptons/taus
sum_charge = awkward.sum(events.Electron[electron_selection].charge, axis=1) + awkward.sum(events.Muon[muon_selection].charge, axis=1) + awkward.sum(events.Tau[tau_selection].charge, axis=1)
charge_cut = sum_charge == 0
n_lep_cut = n_leptons_and_taus == 2
not_two_leptons = n_leptons_and_taus != 2
os_cut = (n_lep_cut & charge_cut) | not_two_leptons # only require 2 OS leptons if there are ==2 leptons in the event

n_leptons_and_taus = n_electrons + n_muons + n_taus
all_cuts = lep_tau_cut & os_cut
cut_diagnostics.add_cuts([lep_tau_cut, os_cut, all_cuts], ["N_leptons + N_taus >= 1", "OS dileptons", "all"])

lep_tau_cut = n_leptons_and_taus >= 1
events = events[lep_tau_cut]
cut_diagnostics.add_cut(len(events), cut_name = "leptons and taus >= 1 cut")
events = events[all_cuts]

return events

def tth_leptonic_preselection(events, debug):
cut_diagnostics = utils.CutDiagnostics(n_events_initial = len(events), debug = debug, cut_set = "[analysis_selections.py : tth_leptonic_preselection]")
cut_diagnostics = utils.CutDiagnostics(events = events, debug = debug, cut_set = "[analysis_selections.py : tth_leptonic_preselection]")

# Get number of electrons, muons
n_electrons = awkward.num(events.Electron[lepton_selections.select_electrons(events, debug)])
Expand Down
Loading

0 comments on commit 2b96e7e

Please sign in to comment.