Skip to content

Commit

Permalink
fix conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
cmantill committed Oct 16, 2024
2 parents 2011389 + 7cd8c40 commit 3074137
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 32 deletions.
103 changes: 73 additions & 30 deletions src/HH4b/jsmr/jmsr_templates.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
import click
from __future__ import annotations

import logging
import os
import pandas as pd

import click
import numpy as np
import pandas as pd
import uproot

import logging
import HH4b.plotting as plotting
import HH4b.utils as utils
from HH4b.utils import ShapeVar
import HH4b.plotting as plotting

#logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
# logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)
logging.basicConfig(format="%(levelname)s:%(message)s", level=logging.INFO)
logger = logging.getLogger("JMSR_TEMPLATES")

# for plotting
Expand Down Expand Up @@ -38,7 +41,7 @@
"WtoLNu-2Jets_2J",
"DYto2L-2Jets_MLL-50_2J",
],
"qcd": [
"qcd": [
"QCD_HT-400to600",
"QCD_HT-600to800",
"QCD_HT-800to1000",
Expand Down Expand Up @@ -204,6 +207,7 @@
},
}


def save_to_file(out_file, hists_pass, hists_fail, save_variations=False):
"""
Save histograms to file
Expand All @@ -221,18 +225,18 @@ def save_to_file(out_file, hists_pass, hists_fail, save_variations=False):
# catp2 = matched
# catp1 = unmatched

f_out[f"data_obs_pass_nominal"] = hists_pass[var][{"Sample": "data"}]
f_out[f"data_obs_fail_nominal"] = hists_fail[var][{"Sample": "data"}]
f_out["data_obs_pass_nominal"] = hists_pass[var][{"Sample": "data"}]
f_out["data_obs_fail_nominal"] = hists_fail[var][{"Sample": "data"}]

# matched
f_out[f"catp2_pass_nominal"] = sum(
f_out["catp2_pass_nominal"] = sum(
[
hists_pass[var][{"Sample": sample}]
for sample in hists_pass[var].axes[0]
if sample in ["W_matched", "singletop"]
]
)
f_out[f"catp2_fail_nominal"] = sum(
f_out["catp2_fail_nominal"] = sum(
[
hists_fail[var][{"Sample": sample}]
for sample in hists_fail[var].axes[0]
Expand All @@ -241,14 +245,14 @@ def save_to_file(out_file, hists_pass, hists_fail, save_variations=False):
)

# unmatched
f_out[f"catp1_pass_nominal"] = sum(
f_out["catp1_pass_nominal"] = sum(
[
hists_pass[var][{"Sample": sample}]
for sample in hists_pass[var].axes[0]
if sample in ["top_matched", "unmatched"]
]
)
f_out[f"catp1_fail_nominal"] = sum(
f_out["catp1_fail_nominal"] = sum(
[
hists_fail[var][{"Sample": sample}]
for sample in hists_fail[var].axes[0]
Expand Down Expand Up @@ -303,12 +307,19 @@ def save_to_file(out_file, hists_pass, hists_fail, save_variations=False):

f_out.close()


def get_ev_dataframe(events_dict, mass, pt_mask):
"""
Get dataframe with W selection applied
"""

def get_wtagger(events):
return (events["ak8FatJetParTPXqq"][0] ) / (events["ak8FatJetParTPXqq"][0] + events["ak8FatJetParTPQCD0HF"][0] + events["ak8FatJetParTPQCD1HF"][0] + events["ak8FatJetParTPQCD2HF"][0])
return (events["ak8FatJetParTPXqq"][0]) / (
events["ak8FatJetParTPXqq"][0]
+ events["ak8FatJetParTPQCD0HF"][0]
+ events["ak8FatJetParTPQCD1HF"][0]
+ events["ak8FatJetParTPQCD2HF"][0]
)

ev_dict = {}
for key in events_dict:
Expand All @@ -322,8 +333,8 @@ def get_wtagger(events):
& (events[f"ak8FatJet{mass}"][0] >= 55)
& (events[f"ak8FatJet{mass}"][0] <= 200)
& (wlnu_pt >= 100)
& (events["ak8FatJetPt"][0] >= pt_mask[0])
& (events["ak8FatJetPt"][0] < pt_mask[1])
& (events["ak8FatJetPt"][0] >= pt_mask[0])
& (events["ak8FatJetPt"][0] < pt_mask[1])
]

# form event dataframe
Expand Down Expand Up @@ -381,7 +392,7 @@ def get_wtagger(events):
top_matched = ((has_2_daughter_qs) & (has_1_b))[:, 0]
W_matched = ((has_2_daughter_qs) & (~has_1_b))[:, 0]
W_matched_tight = W_matched & vpt_matched & vmass_matched
unmatched = ((~has_2_daughter_qs))[:, 0] | (W_matched & ~W_matched_tight)
unmatched = (~has_2_daughter_qs)[:, 0] | (W_matched & ~W_matched_tight)

ev_dict = {
**ev_dict,
Expand All @@ -392,7 +403,6 @@ def get_wtagger(events):
else:
ev_dict[key] = ev_dataframe


# create pass and fail regions
ev_dict_pass = {}
ev_dict_fail = {}
Expand All @@ -404,9 +414,13 @@ def get_wtagger(events):

return ev_dict, ev_dict_pass, ev_dict_fail


@click.command()
@click.option("--dir-name", help="directory name",
default="/eos/uscms/store/user/cmantill/bbbb/ttSkimmer/24Oct14_v12v2_private_signal/")
@click.option(
"--dir-name",
help="directory name",
default="/eos/uscms/store/user/cmantill/bbbb/ttSkimmer/24Oct14_v12v2_private_signal/",
)
@click.option("--year-group", default="2022All", type=click.Choice(["2022All", "2023All"]))
@click.option("--tag", required=True)
def jmsr_templates(dir_name, year_group, tag):
Expand Down Expand Up @@ -466,17 +480,45 @@ def jmsr_templates(dir_name, year_group, tag):
# 3.33 gev bins
ShapeVar(var="WMass", label=r"W Mass (GeV)", bins=[21, 55, 125], plot_args={"log": False}),
ShapeVar(var="WMsd", label=r"W Msd (GeV)", bins=[30, 50, 200], plot_args={"log": False}),
ShapeVar(var="WPt", label=r"W p$_{T}$ (GeV)", bins=[30, 300, 800], plot_args={"log": False}),
ShapeVar(
var="WPt", label=r"W p$_{T}$ (GeV)", bins=[30, 300, 800], plot_args={"log": False}
),
ShapeVar(var="WTagger", label=r"W discriminator", bins=[30, 0, 1], plot_args={"log": True}),
# plot extra discriminators
ShapeVar(var="WPXqq", label=r"ParT Xqq probability", bins=[30, 0, 1], plot_args={"log": True}),
ShapeVar(var="WPTopW", label=r"ParT TopW probability", bins=[30, 0, 1], plot_args={"log": True}),
ShapeVar(var="WPTopbW", label=r"ParT TopbW probability", bins=[30, 0, 1], plot_args={"log": True}),
ShapeVar(
var="WPXqq", label=r"ParT Xqq probability", bins=[30, 0, 1], plot_args={"log": True}
),
ShapeVar(
var="WPTopW", label=r"ParT TopW probability", bins=[30, 0, 1], plot_args={"log": True}
),
ShapeVar(
var="WPTopbW", label=r"ParT TopbW probability", bins=[30, 0, 1], plot_args={"log": True}
),
# variations
ShapeVar(var="WMass_JMS_down", label=r"W Mass JMS down (GeV)", bins=[21, 55, 125], plot_args={"log": False}),
ShapeVar(var="WMass_JMS_up", label=r"W Mass JMS up (GeV)", bins=[21, 55, 125], plot_args={"log": False}),
ShapeVar(var="WMass_JMR_down", label=r"W Mass JMR up (GeV)", bins=[21, 55, 125], plot_args={"log": False}),
ShapeVar(var="WMass_JMR_up", label=r"W Mass JMR up (GeV)", bins=[21, 55, 125], plot_args={"log": False}),
ShapeVar(
var="WMass_JMS_down",
label=r"W Mass JMS down (GeV)",
bins=[21, 55, 125],
plot_args={"log": False},
),
ShapeVar(
var="WMass_JMS_up",
label=r"W Mass JMS up (GeV)",
bins=[21, 55, 125],
plot_args={"log": False},
),
ShapeVar(
var="WMass_JMR_down",
label=r"W Mass JMR up (GeV)",
bins=[21, 55, 125],
plot_args={"log": False},
),
ShapeVar(
var="WMass_JMR_up",
label=r"W Mass JMR up (GeV)",
bins=[21, 55, 125],
plot_args={"log": False},
),
]

ev_dict = {}
Expand Down Expand Up @@ -566,7 +608,7 @@ def jmsr_templates(dir_name, year_group, tag):
bg_err_mcstat=True,
exclude_qcd_mcstat=False,
save_pdf=False,
**shape_var.plot_args
**shape_var.plot_args,
# ylim=1.2e4,
# ylim_low=0,
)
Expand All @@ -580,5 +622,6 @@ def jmsr_templates(dir_name, year_group, tag):
# TODO: save variations (e.g. WMass_JMS_down)
save_to_file(out_file, hists_pass, hists_fail)


if __name__ == "__main__":
jmsr_templates()
jmsr_templates()
2 changes: 1 addition & 1 deletion src/HH4b/processors/ttSkimmer.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def __init__(
"ParTPTopbW",
"ParTPXbb",
"ParTPXqq",
"ParTPXcc",
"ParTPXcc",
"ParTPXcs",
"ParTTXbb",
"ParTmassRes",
Expand Down
2 changes: 1 addition & 1 deletion src/HH4b/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ def load_samples(
logger.debug(f"Loading {sample}")
try:
events = pd.read_parquet(parquet_path, filters=filters, columns=load_columns)
except Exception as e:
except Exception:
warnings.warn(f"No events for {sample}!", stacklevel=1)
continue

Expand Down

0 comments on commit 3074137

Please sign in to comment.