Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ nobackup/
fitting/results/
fitting/templates/
plots/
*.txt
*.ipynb_checkpoints/
78 changes: 42 additions & 36 deletions fitting/make_hists.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,35 @@
from __future__ import annotations

import argparse
import json
import os
from pathlib import Path

import hist
import json
import os
import uproot

from hbb import utils


def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true):

h = hist.Hist(hist.axis.Regular(obs_cfg["nbins"], obs_cfg["min"], obs_cfg["max"], name=obs_cfg["name"], label=obs_cfg["name"]))
h = hist.Hist(
hist.axis.Regular(
obs_cfg["nbins"],
obs_cfg["min"],
obs_cfg["max"],
name=obs_cfg["name"],
label=obs_cfg["name"],
)
)

bins_list = reg_cfg["bins"]
bin_pname = reg_cfg["bin_pname"]
str_bin_br = reg_cfg["branch_name"]

for _process_name, data in events.items():

#TODO add in systematics functionality
# TODO add in systematics functionality
weight_val = data["finalWeight"].astype(float)
s = "nominal"

Expand All @@ -37,17 +45,17 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true):
pre_selection = (obs_br > obs_cfg["min"]) & (obs_br < obs_cfg["max"])

selection_dict = {
"pass_bb": pre_selection & (Txbbxcc > 0.95) & (Txbb > Txcc),
"pass_cc": pre_selection & (Txbbxcc > 0.95) & (Txcc > Txbb),
"pass_bb": pre_selection & (Txbbxcc > 0.95) & (Txbb > Txcc),
"pass_cc": pre_selection & (Txbbxcc > 0.95) & (Txcc > Txbb),
"fail": pre_selection & (Txbbxcc <= 0.95),
"pass": pre_selection & (Txbbxcc > 0.95)
"pass": pre_selection & (Txbbxcc > 0.95),
}

cut_bb = (genf == 3)
cut_bb = genf == 3
cut_qq = (genf > 0) & (genf < 3)

for i in range(len(bins_list) - 1):
bin_cut = (bin_br > bins_list[i]) & (bin_br < bins_list[i+1]) & pre_selection
bin_cut = (bin_br > bins_list[i]) & (bin_br < bins_list[i + 1]) & pre_selection

for category, selection in selection_dict.items():
if qq_true:
Expand All @@ -57,7 +65,7 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true):
obs_br[selection & bin_cut & cut_qq],
weight=weight_val[selection & bin_cut & cut_qq],
)
if not name in outdict:
if name not in outdict:
outdict[name] = h.copy()
else:
outdict[name] += h.copy()
Expand All @@ -68,7 +76,7 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true):
obs_br[selection & bin_cut & cut_bb],
weight=weight_val[selection & bin_cut & cut_bb],
)
if not name in outdict:
if name not in outdict:
outdict[name] = h.copy()
else:
outdict[name] += h.copy()
Expand All @@ -80,20 +88,22 @@ def fill_hists(outdict, events, region, reg_cfg, obs_cfg, qq_true):
obs_br[selection & bin_cut],
weight=weight_val[selection & bin_cut],
)
if not name in outdict:
if name not in outdict:
outdict[name] = h.copy()
else:
outdict[name] += h.copy()
return outdict


def main(args):
year = args.year
tag = args.tag

path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/skims/{tag}"

samples_qq = ['Wjets','Zjets','EWKW','EWKZ','EWKV']

# path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/skims/{tag}"
path_to_dir = f"/eos/uscms/store/group/lpchbbrun3/gmachado/{tag}"

samples_qq = ["Wjets", "Zjets", "EWKW", "EWKZ", "EWKV"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that you need to change samples_qq so that you process the samples that you need for Z+Gamma (this should be everything including G+Jets?)


columns = [
"weight",
"FatJet0_pt",
Expand All @@ -110,31 +120,31 @@ def main(args):
out_path = f"results/{tag}/{year}"
output_file = f"{out_path}/signalregion.root"

if not os.path.exists(out_path):
os.makedirs(out_path)
if not Path(out_path).exists():
Path(out_path).mkdir(parents=True)

if os.path.isfile(output_file):
os.remove(output_file)
if Path(output_file).is_file():
Path(output_file).unlink()
fout = uproot.create(output_file)

# So I can remember the settings I used for each set of results produced
os.popen(f'cp setup.json {out_path}')
with open('setup.json') as f:
os.popen(f"cp setup.json {out_path}")
with Path("setup.json").open() as f:
setup = json.load(f)
cats = setup["categories"]
obs_cfg = setup["observable"]

with open('pmap_run3.json') as f:
with Path("pmap_run3.json").open() as f:
pmap = json.load(f)

filters = [
("FatJet0_pt", ">", 450),
("FatJet0_pt", "<", 1200),
("VBFPair_mjj", ">", -2),
("VBFPair_mjj", "<", 13000),
("FatJet0_pt", ">", 450),
("FatJet0_pt", "<", 1200),
("VBFPair_mjj", ">", -2),
("VBFPair_mjj", "<", 13000),
]

if not obs_cfg["branch_name"] in columns:
if obs_cfg["branch_name"] not in columns:
columns.append(obs_cfg["branch_name"])

out_hists = {}
Expand All @@ -148,7 +158,7 @@ def main(args):
{process: [dataset]},
columns=columns,
region=cfg["name"],
filters=filters
filters=filters,
)

if not events:
Expand All @@ -161,6 +171,7 @@ def main(args):

print(f"Histograms saved to {output_file}")


if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Make histograms for a given year.")
parser.add_argument(
Expand All @@ -170,12 +181,7 @@ def main(args):
required=True,
choices=["2022", "2022EE", "2023", "2023BPix"],
)
parser.add_argument(
"--tag",
help="tag",
type=str,
required=True
)
parser.add_argument("--tag", help="tag", type=str, required=True)
args = parser.parse_args()

main(args)
12 changes: 10 additions & 2 deletions fitting/setup.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"observable" : {
"name" : "msd",
"min" : 40,
"min" : 40,
"max" : 201,
"nbins" : 23,
"title" : "m_{sd} [GeV]",
Expand Down Expand Up @@ -40,6 +40,14 @@
"bin_pname" : "pt",
"branch_name" : "FatJet0_pt",
"bin_title" : "p_{T}"
},
"zgcr": {
"name" : "control-zgamma",
"bins" : [200,1200],
"bin_name" : "pt1",
"bin_pname" : "pt",
"branch_name" : "FatJet0_pt",
"bin_title" : "p_{T}"
}
}
}
}