Skip to content

Commit

Permalink
ratio mass plot
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Apr 9, 2024
1 parent 20cedf3 commit 0321947
Show file tree
Hide file tree
Showing 16 changed files with 132 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/HHbbVV/postprocessing/TrainBDT.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ def plot_mass_shapes(train, test, sig_keys, model_dir, training_keys):
cuts,
"all",
weight_key,
ratio=True,
plot_dir=save_model_dir,
name=f"{label}_{key}_BDT{sig_key}Cuts_AllYears",
show=False,
Expand Down
10 changes: 5 additions & 5 deletions src/HHbbVV/postprocessing/bash_scripts/NonresTemplatesScan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ years=("2016APV" "2016" "2017" "2018")
MAIN_DIR="../../.."
data_dir="$MAIN_DIR/../data/skimmer/24Mar14UpdateData"
bdt_preds_dir="$data_dir/24_04_05_k2v0_training_eqsig_vbf_vars_rm_deta/inferences"
# sig_samples="HHbbVV qqHH_CV_1_C2V_0_kl_1_HHbbVV"
sig_samples="qqHH_CV_1_C2V_0_kl_1_HHbbVV"
sig_samples="HHbbVV"
# sig_samples="qqHH_CV_1_C2V_0_kl_1_HHbbVV"
TAG=""
lepton_veto=""
txbb_cut=""
Expand All @@ -27,11 +27,11 @@ while true; do
lepton_veto="--lepton-veto None Hbb HH"
;;
--bdt)
bdt_cut="--nonres-ggf-bdt-wp 0.99 0.997 0.998 0.999"
# bdt_cut="--nonres-bdt-wp 0.99 0.997 0.998 0.999 0.9997 0.9999"
bdt_cut="--nonres-bdt-wp 0.99 0.997 0.998 0.999 0.9997 0.9999"
;;
--txbb)
txbb_cut="--nonres-txbb-wp MP HP"
txbb_cut="--nonres-ggf-txbb-wp MP HP"
;;
--year)
shift
Expand Down Expand Up @@ -67,5 +67,5 @@ do
python -u postprocessing.py --year $year --data-dir "$data_dir" --bdt-preds-dir $bdt_preds_dir \
--templates --template-dir "templates/$TAG" --no-do-jshifts \
--plot-dir "${MAIN_DIR}/plots/PostProcessing/$TAG" --no-plot-shifts \
$lepton_veto $bdt_cut $txbb_cut --sig-samples $sig_samples --bdtv "vbf" # --bg-keys "" --no-data
$lepton_veto $bdt_cut $txbb_cut --sig-samples $sig_samples --nonres-regions "ggf" # --bg-keys "" --no-data
done
41 changes: 37 additions & 4 deletions src/HHbbVV/postprocessing/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -994,29 +994,44 @@ def cutsLinePlot(
bb_masks: dict[str, DataFrame] = None,
plot_dir: str = "",
name: str = "",
ratio: bool = False,
ax: plt.Axes = None,
show: bool = False,
):
"""Plot line plots of ``shape_var`` for different cuts on ``cut_var``."""
if ax is None:
fig, ax = plt.subplots(1, 1, figsize=(12, 12))
if ratio:
assert cuts[0] == 0, "First cut must be 0 for ratio plots."
fig, (ax, rax) = plt.subplots(
2,
1,
figsize=(12, 14),
gridspec_kw={"height_ratios": [3, 1], "hspace": 0},
sharex=True,
)
else:
fig, ax = plt.subplots(1, 1, figsize=(12, 12))
in_ax = False
else:
if ratio:
raise NotImplementedError("Ratio plots not implemented with input axes.")
in_ax = True

plt.rcParams.update({"font.size": 24})

for _i, cut in enumerate(cuts):
hists = OrderedDict()
for cut in cuts:
sel, _ = utils.make_selection({cut_var: [cut, CUT_MAX_VAL]}, events_dict, bb_masks)
h = utils.singleVarHist(
events_dict, shape_var, bb_masks, weight_key=weight_key, selection=sel
)

hists[cut] = h[plot_key, ...] / np.sum(h[plot_key, ...].values())

hep.histplot(
h[plot_key, ...] / np.sum(h[plot_key, ...].values()),
hists[cut],
yerr=True,
label=f"BDTScore >= {cut}",
# density=True,
ax=ax,
linewidth=2,
alpha=0.8,
Expand All @@ -1026,6 +1041,24 @@ def cutsLinePlot(
ax.set_ylabel("Fraction of Events")
ax.legend()

if ratio:
rax.hlines(1, shape_var.axis.edges[0], shape_var.axis.edges[-1], linestyle="--", alpha=0.5)
vals_nocut = hists[0].values()

next(rax._get_lines.prop_cycler) # skip first
for cut in cuts[1:]:
hep.histplot(
hists[cut] / vals_nocut,
yerr=True,
label=f"BDTScore >= {cut}",
ax=rax,
histtype="errorbar",
)

rax.set_ylim([0.4, 2.2])
rax.set_ylabel("Ratio to Inclusive Shape")
# rax.legend()

if year == "all":
hep.cms.label(
"Preliminary",
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
,Pre-selection,QCD SF,LP SF,bbFatJetPt >= 300,VVFatJetPt >= 300,0.8 ≤ bbFatJetParticleNetMD_Txbb < 0.9737,0 ≤ nGoodElectronsHbb < 0.9,0 ≤ nGoodMuonsHbb < 0.9
HHbbVV,1.108127280079604,1.108127280079604,1.108127280079604,1.1005594143174928,1.0940812392241102,0.3689082675908363,0.36827657175589595,0.3664211447383801
QCD,900603.372757249,1219440.0804636534,1219440.0804636534,1208187.047601593,1199914.6854996895,968194.6958131382,966575.8329570786,963477.1843784222
TT,76537.02908224265,76537.02908224265,76537.02908224265,76036.67089183381,75504.25522211792,59756.04620421225,53581.011783496266,47369.53176682067
ST,6617.229257123121,6617.229257123121,6617.229257123121,6568.071623368754,6530.558860743446,5277.663381085969,4827.68892161338,4353.263702426815
W+Jets,12421.273275458932,12421.273275458932,12421.273275458932,12341.31450378544,12265.115729916284,10267.98041055657,10240.771375918208,10214.924023501666
Z+Jets,14717.02364266734,14717.02364266734,14717.02364266734,14601.426751424733,14517.101697865306,8391.373012782422,8370.619662623449,8331.43470986793
Diboson,703.6912877316817,703.6912877316817,703.6912877316817,699.1389217855917,695.3097641927543,427.8095451515573,408.6227711479913,391.3912666097881
ggFHbb,138.81856362723408,138.81856362723408,138.81856362723408,138.12124620347993,137.14696515108136,45.30216339603112,45.142460352433716,44.74304469717901
VBFHbb,40.60062332311162,40.60062332311162,40.60062332311162,40.47235839402518,40.3369080970762,12.910667691672323,12.88796377991545,12.781781795885522
ZHbb,38.56092725636813,38.56092725636813,38.56092725636813,38.30734801182328,38.14508043229702,11.799771340315372,11.748120919965892,11.666691037425696
WHbb,66.232275837835,66.232275837835,66.232275837835,65.79568909543664,65.5789510146088,22.935801367330377,22.891716198731135,22.762665877722227
ggZHbb,5.921431593700421,5.921431593700421,5.921431593700421,5.88900772329133,5.855043713430598,2.3432337853521314,2.337704288637104,2.3187157788024946
ttHbb,187.9810602386041,187.9810602386041,187.9810602386041,186.85674951555848,185.63841488932138,116.0286360102471,102.76848179845926,89.14805678548099
HWW,97.55810924622651,97.55810924622651,97.55810924622651,97.00857794271565,96.26976864081334,77.25306730184919,64.56532116288594,53.54802832202656
Data,1331012.0,1331012.0,1331012.0,1331012.0,1331012.0,1100458.0,1090240.0,1078427.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
,Pre-selection,QCD SF,LP SF,bbFatJetPt >= 300,VVFatJetPt >= 300,BDTScoreVBF < 0.999,BDTScore >= 0.998,bbFatJetParticleNetMD_Txbb >= 0.9737,0 ≤ nGoodElectronsHbb < 0.9,0 ≤ nGoodMuonsHbb < 0.9
HHbbVV,1.108127280079604,1.108127280079604,1.108127280079604,1.1005594143174928,1.0940812392241102,1.08307212221333,0.032150186264534114,0.021539992844881704,0.021505237207905842,0.02143890182956043
QCD,900603.372757249,1219440.0804636534,1219440.0804636534,1208187.047601593,1199914.6854996895,1199906.968442861,0.7076592044539373,0.0,0.0,0.0
TT,76537.02908224265,76537.02908224265,76537.02908224265,76036.67089183381,75504.25522211792,75501.22743606972,3.8996292824823975,0.7253598692165029,0.5984437097468674,0.5984437097468674
ST,6617.229257123121,6617.229257123121,6617.229257123121,6568.071623368754,6530.558860743446,6530.296016033862,0.43118812525090927,0.0,0.0,0.0
W+Jets,12421.273275458932,12421.273275458932,12421.273275458932,12341.31450378544,12265.115729916284,12264.238969325628,0.7713777928786704,0.0,0.0,0.0
Z+Jets,14717.02364266734,14717.02364266734,14717.02364266734,14601.426751424733,14517.101697865306,14517.037556219659,0.4863306763188757,0.15136874503853742,0.15136874503853742,0.15136874503853742
Diboson,703.6912877316817,703.6912877316817,703.6912877316817,699.1389217855917,695.3097641927543,695.3097641927543,0.0,0.0,0.0,0.0
ggFHbb,138.81856362723408,138.81856362723408,138.81856362723408,138.12124620347993,137.14696515108136,137.14696515108136,0.0,0.0,0.0,0.0
VBFHbb,40.60062332311162,40.60062332311162,40.60062332311162,40.47235839402518,40.3369080970762,40.3369080970762,0.0,0.0,0.0,0.0
ZHbb,38.56092725636813,38.56092725636813,38.56092725636813,38.30734801182328,38.14508043229702,38.14508043229702,0.002814064174337513,0.002814064174337513,0.002814064174337513,0.002814064174337513
WHbb,66.232275837835,66.232275837835,66.232275837835,65.79568909543664,65.5789510146088,65.5789510146088,0.002068149949222107,0.002068149949222107,0.002068149949222107,0.002068149949222107
ggZHbb,5.921431593700421,5.921431593700421,5.921431593700421,5.88900772329133,5.855043713430598,5.855043713430598,0.0,0.0,0.0,0.0
ttHbb,187.9810602386041,187.9810602386041,187.9810602386041,186.85674951555848,185.63841488932138,185.6322493149411,0.014000913268447868,0.0071061389585681655,0.0071061389585681655,0.005782190022058678
HWW,97.55810924622651,97.55810924622651,97.55810924622651,97.00857794271565,96.26976864081334,96.14411210086026,0.30462722598860975,0.08078793697996026,0.07649271797909662,0.07649271797909662
Data,1331012.0,1331012.0,1331012.0,1331012.0,1331012.0,1330979.0,36.0,7.0,7.0,7.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
,Pre-selection,QCD SF,LP SF,bbFatJetPt >= 300,VVFatJetPt >= 300,BDTScoreVBF < 0.999,BDTScore >= 0.997,bbFatJetParticleNetMD_Txbb >= 0.9737,0 ≤ nGoodElectronsHbb < 0.9,0 ≤ nGoodMuonsHbb < 0.9
HHbbVV,1.108127280079604,1.108127280079604,1.108127280079604,1.1005594143174928,1.0940812392241102,1.08307212221333,0.04846700247919388,0.03258074771977175,0.03253437433069089,0.032401810936984035
QCD,900603.372757249,1219440.0804636534,1219440.0804636534,1208187.047601593,1199914.6854996895,1199906.968442861,4.7747549543241306,0.0,0.0,0.0
TT,76537.02908224265,76537.02908224265,76537.02908224265,76036.67089183381,75504.25522211792,75501.22743606972,8.347223107060373,1.6068013177332772,1.4392225496547222,1.3433347468154562
ST,6617.229257123121,6617.229257123121,6617.229257123121,6568.071623368754,6530.558860743446,6530.296016033862,0.7217616923256962,0.0,0.0,0.0
W+Jets,12421.273275458932,12421.273275458932,12421.273275458932,12341.31450378544,12265.115729916284,12264.238969325628,1.5688897258105596,0.0,0.0,0.0
Z+Jets,14717.02364266734,14717.02364266734,14717.02364266734,14601.426751424733,14517.101697865306,14517.037556219659,0.9767908755627582,0.5896351605121364,0.5896351605121364,0.5896351605121364
Diboson,703.6912877316817,703.6912877316817,703.6912877316817,699.1389217855917,695.3097641927543,695.3097641927543,0.0,0.0,0.0,0.0
ggFHbb,138.81856362723408,138.81856362723408,138.81856362723408,138.12124620347993,137.14696515108136,137.14696515108136,0.0,0.0,0.0,0.0
VBFHbb,40.60062332311162,40.60062332311162,40.60062332311162,40.47235839402518,40.3369080970762,40.3369080970762,0.0,0.0,0.0,0.0
ZHbb,38.56092725636813,38.56092725636813,38.56092725636813,38.30734801182328,38.14508043229702,38.14508043229702,0.005879306153889316,0.005879306153889316,0.005879306153889316,0.005879306153889316
WHbb,66.232275837835,66.232275837835,66.232275837835,65.79568909543664,65.5789510146088,65.5789510146088,0.002068149949222107,0.002068149949222107,0.002068149949222107,0.002068149949222107
ggZHbb,5.921431593700421,5.921431593700421,5.921431593700421,5.88900772329133,5.855043713430598,5.855043713430598,0.00023700317884601128,0.00023700317884601128,0.00023700317884601128,0.00023700317884601128
ttHbb,187.9810602386041,187.9810602386041,187.9810602386041,186.85674951555848,185.63841488932138,185.6322493149411,0.02368282147260172,0.010365219522331702,0.010365219522331702,0.009041270585822214
HWW,97.55810924622651,97.55810924622651,97.55810924622651,97.00857794271565,96.26976864081334,96.14411210086026,0.47017424653213646,0.13960572231305798,0.13073511290164413,0.12572354776866823
Data,1331012.0,1331012.0,1331012.0,1331012.0,1331012.0,1330979.0,88.0,16.0,16.0,16.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,SF,sj_matching_unc,sj_pt_unc,stat_unc,syst_unc
HHbbVV,1.07 ± 0.22,0.1276315040823874,0.001277076486978498,0.053226998350776135,0.14706256318712713
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2016APV": {}, "HHbbVV": {"lp_sf": 1.070349831558295, "lp_sf_unc": 0.20187110393339447, "lp_sf_uncs": {"syst_unc": 0.14706256318712713, "stat_unc": 0.053226998350776135, "sj_pt_unc": 0.001277076486978498, "sj_matching_unc": 0.1276315040823874}}}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
,Pre-selection,QCD SF,LP SF,bbFatJetPt >= 300,VVFatJetPt >= 300,0.8 ≤ bbFatJetParticleNetMD_Txbb < 0.9737,0 ≤ nGoodElectronsHbb < 0.9,0 ≤ nGoodMuonsHbb < 0.9
HHbbVV,1.108127280079604,1.108127280079604,1.108127280079604,1.1005594143174928,1.0940812392241102,0.3689082675908363,0.36827657175589595,0.3664211447383801
QCD,900603.372757249,1219440.0804636534,1219440.0804636534,1208187.047601593,1199914.6854996895,968194.6958131382,966575.8329570786,963477.1843784222
TT,76537.02908224265,76537.02908224265,76537.02908224265,76036.67089183381,75504.25522211792,59756.04620421225,53581.011783496266,47369.53176682067
ST,6617.229257123121,6617.229257123121,6617.229257123121,6568.071623368754,6530.558860743446,5277.663381085969,4827.68892161338,4353.263702426815
W+Jets,12421.273275458932,12421.273275458932,12421.273275458932,12341.31450378544,12265.115729916284,10267.98041055657,10240.771375918208,10214.924023501666
Z+Jets,14717.02364266734,14717.02364266734,14717.02364266734,14601.426751424733,14517.101697865306,8391.373012782422,8370.619662623449,8331.43470986793
Diboson,703.6912877316817,703.6912877316817,703.6912877316817,699.1389217855917,695.3097641927543,427.8095451515573,408.6227711479913,391.3912666097881
ggFHbb,138.81856362723408,138.81856362723408,138.81856362723408,138.12124620347993,137.14696515108136,45.30216339603112,45.142460352433716,44.74304469717901
VBFHbb,40.60062332311162,40.60062332311162,40.60062332311162,40.47235839402518,40.3369080970762,12.910667691672323,12.88796377991545,12.781781795885522
ZHbb,38.56092725636813,38.56092725636813,38.56092725636813,38.30734801182328,38.14508043229702,11.799771340315372,11.748120919965892,11.666691037425696
WHbb,66.232275837835,66.232275837835,66.232275837835,65.79568909543664,65.5789510146088,22.935801367330377,22.891716198731135,22.762665877722227
ggZHbb,5.921431593700421,5.921431593700421,5.921431593700421,5.88900772329133,5.855043713430598,2.3432337853521314,2.337704288637104,2.3187157788024946
ttHbb,187.9810602386041,187.9810602386041,187.9810602386041,186.85674951555848,185.63841488932138,116.0286360102471,102.76848179845926,89.14805678548099
HWW,97.55810924622651,97.55810924622651,97.55810924622651,97.00857794271565,96.26976864081334,77.25306730184919,64.56532116288594,53.54802832202656
Data,1331012.0,1331012.0,1331012.0,1331012.0,1331012.0,1100458.0,1090240.0,1078427.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
,Pre-selection,QCD SF,LP SF,bbFatJetPt >= 300,VVFatJetPt >= 300,BDTScoreVBF < 0.999,BDTScore >= 0.99,bbFatJetParticleNetMD_Txbb >= 0.9737,0 ≤ nGoodElectronsHbb < 0.9,0 ≤ nGoodMuonsHbb < 0.9
HHbbVV,1.108127280079604,1.108127280079604,1.108127280079604,1.1005594143174928,1.0940812392241102,1.08307212221333,0.1274520847535977,0.08652865186879215,0.08640081355615145,0.08604077164186247
QCD,900603.372757249,1219440.0804636534,1219440.0804636534,1208187.047601593,1199914.6854996895,1199906.968442861,301.74567370698975,75.83910152678905,75.83910152678905,75.83910152678905
TT,76537.02908224265,76537.02908224265,76537.02908224265,76036.67089183381,75504.25522211792,75501.22743606972,62.324986689516564,11.448585216245407,10.28644980828107,9.243507323089165
ST,6617.229257123121,6617.229257123121,6617.229257123121,6568.071623368754,6530.558860743446,6530.296016033862,8.044291205279357,2.197605555952362,2.197605555952362,2.197605555952362
W+Jets,12421.273275458932,12421.273275458932,12421.273275458932,12341.31450378544,12265.115729916284,12264.238969325628,11.853962318831005,1.5175864377624777,1.5175864377624777,1.5175864377624777
Z+Jets,14717.02364266734,14717.02364266734,14717.02364266734,14601.426751424733,14517.101697865306,14517.037556219659,8.964267090267176,4.25311451832017,4.25311451832017,4.25311451832017
Diboson,703.6912877316817,703.6912877316817,703.6912877316817,699.1389217855917,695.3097641927543,695.3097641927543,0.4922720792291345,0.0,0.0,0.0
ggFHbb,138.81856362723408,138.81856362723408,138.81856362723408,138.12124620347993,137.14696515108136,137.14696515108136,0.04585751158550318,0.014320785061166675,0.014320785061166675,0.014320785061166675
VBFHbb,40.60062332311162,40.60062332311162,40.60062332311162,40.47235839402518,40.3369080970762,40.3369080970762,0.007598621229742675,0.007598621229742675,0.007598621229742675,0.007598621229742675
ZHbb,38.56092725636813,38.56092725636813,38.56092725636813,38.30734801182328,38.14508043229702,38.14508043229702,0.01968696519113477,0.012815213174361744,0.012815213174361744,0.012815213174361744
WHbb,66.232275837835,66.232275837835,66.232275837835,65.79568909543664,65.5789510146088,65.5789510146088,0.05398558021588891,0.040276710289686775,0.040276710289686775,0.040276710289686775
ggZHbb,5.921431593700421,5.921431593700421,5.921431593700421,5.88900772329133,5.855043713430598,5.855043713430598,0.0036358694120931984,0.0022844941214686656,0.0022844941214686656,0.0022844941214686656
ttHbb,187.9810602386041,187.9810602386041,187.9810602386041,186.85674951555848,185.63841488932138,185.6322493149411,0.19278911572718094,0.07874110655877793,0.07538985530158142,0.06626141168349274
HWW,97.55810924622651,97.55810924622651,97.55810924622651,97.00857794271565,96.26976864081334,96.14411210086026,1.3561809845005655,0.367908460906601,0.3467339759010756,0.3252424859345036
Data,1331012.0,1331012.0,1331012.0,1331012.0,1331012.0,1330979.0,814.0,142.0,142.0,141.0
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,SF,sj_matching_unc,sj_pt_unc,stat_unc,syst_unc
HHbbVV,1.06 ± 0.27,0.19282317159737467,0.0008033912485202273,0.03959316141647326,0.15927236637073452
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2016APV": {"pass": {"trig_total": 11222.674148724276, "trig_total_err": 95.7410435351886}, "fail": {"trig_total": 2039029.4499765574, "trig_total_err": 3343.171767487172}}, "HHbbVV": {"lp_sf": 1.0584695374301767, "lp_sf_unc": 0.2532128078566588, "lp_sf_uncs": {"syst_unc": 0.15927236637073452, "stat_unc": 0.03959316141647326, "sj_pt_unc": 0.0008033912485202273, "sj_matching_unc": 0.19282317159737467}}}
2 changes: 2 additions & 0 deletions src/HHbbVV/postprocessing/templates/24Apr9ggFScan/lpsfs.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
,SF,sj_matching_unc,sj_pt_unc,stat_unc,syst_unc
HHbbVV,1.06 ± 0.19,0.10923494841873838,0.0015758028076578723,0.0578618154954204,0.1241922213547457
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"2016APV": {"pass": {"trig_total": 2734.164668079122, "trig_total_err": 23.258443026187358}, "fail": {"trig_total": 2039029.4499765574, "trig_total_err": 3343.171767487172}}, "HHbbVV": {"lp_sf": 1.059896067882005, "lp_sf_unc": 0.17523257302221318, "lp_sf_uncs": {"syst_unc": 0.1241922213547457, "stat_unc": 0.0578618154954204, "sj_pt_unc": 0.0015758028076578723, "sj_matching_unc": 0.10923494841873838}}}

0 comments on commit 0321947

Please sign in to comment.