Skip to content

Commit

Permalink
weighted LP
Browse files Browse the repository at this point in the history
  • Loading branch information
rkansal47 committed Jul 30, 2024
1 parent 8fa8ec6 commit 6d68b05
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 24 deletions.
84 changes: 60 additions & 24 deletions src/HHbbVV/postprocessing/TopAnalysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
"plot_dir = Path(\"../../../plots/ttsfs/24Jul28Distortion\")\n",
"plot_dir = Path(\"../../../plots/ttsfs/24Jul29Distortion\")\n",
"plot_dir.mkdir(parents=True, exist_ok=True)"
]
},
Expand Down Expand Up @@ -373,8 +373,11 @@
"source": [
"import uproot\n",
"from tqdm import tqdm\n",
"import pickle\n",
"\n",
"for dist_year in tqdm(years[1:]):\n",
"package_path = Path(\"../\")\n",
"\n",
"for dist_year in tqdm(years[-1:]):\n",
" f = uproot.open(package_path / f\"corrections/lp_ratios/ratio_{dist_year}.root\")\n",
"\n",
" # 3D histogram: [subjet_pt, ln(0.8/Delta), ln(kT/GeV)]\n",
Expand All @@ -390,27 +393,67 @@
"\n",
" # ratio_nom = f[\"ratio_nom\"].to_numpy()[0]\n",
"\n",
" for sig in [\"GluGluToHHTobbVV_node_cHHH1\", \"VBF_HHTobbVV_CV_1_C2V_2_C3_1\"]:\n",
" for sig in [\"GluGluToHHTobbVV_node_cHHH1\", \"VBF_HHTobbVV_CV_1_C2V_2_C3_1\", \"TTToSemiLeptonic\"]:\n",
" if sig == \"TTToSemiLeptonic\" and dist_year != \"2018\":\n",
" continue\n",
"\n",
" with (package_path / f\"corrections/lp_ratios/signals/{dist_year}_{sig}.hist\").open(\n",
" \"rb\"\n",
" ) as f:\n",
" sig_lp_hist = pickle.load(f)\n",
" sig_tot_pt = np.sum(sig_lp_hist.values(), axis=(1, 2), keepdims=True)\n",
" sig_density = sig_lp_hist.values() / sig_tot_pt\n",
"\n",
" mc_sig_ratio = np.nan_to_num(mc_density / sig_density, nan=1.0)\n",
" mc_sig_ratio[mc_sig_ratio == 0] = 1.0\n",
" mc_sig_ratio = np.clip(mc_sig_ratio, 0.2, 5.0)\n",
" sig_tot_pt = np.sum(sig_lp_hist.values(), axis=(1, 2), keepdims=True)\n",
" sig_density = sig_lp_hist.values() / sig_tot_pt\n",
"\n",
" plotting.plot_lund_plane_six(\n",
" sig_density, ratio_edges, name=f\"{plot_dir}/{dist_year}_{sig}.pdf\", show=False\n",
" )\n",
" plotting.plot_lund_plane_six(\n",
" mc_sig_ratio,\n",
" ratio_edges,\n",
" name=f\"{plot_dir}/{dist_year}_{sig}_ratio.pdf\",\n",
" show=False,\n",
" )"
" mc_sig_ratio = np.nan_to_num(mc_density / sig_density, nan=1.0)\n",
" mc_sig_ratio[mc_sig_ratio == 0] = 1.0\n",
" mc_sig_ratio = np.clip(mc_sig_ratio, 0.2, 5.0)\n",
"\n",
" plotting.plot_lund_plane_six(\n",
" sig_density, ratio_edges, name=f\"{plot_dir}/{dist_year}_{sig}.pdf\", show=False\n",
" )\n",
" plotting.plot_lund_plane_six(\n",
" mc_sig_ratio,\n",
" ratio_edges,\n",
" name=f\"{plot_dir}/{dist_year}_{sig}_ratio.pdf\",\n",
" show=False,\n",
" )\n",
"\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"sig_lp_hist.values()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import hist\n",
"\n",
"h = hist.Hist(\n",
" hist.axis.Variable(ratio_edges[0], name=\"subjet_pt\", label=\"Subjet pT [GeV]\"),\n",
" hist.axis.Variable(ratio_edges[1], name=\"logD\", label=\"ln(0.8/Delta)\"),\n",
" hist.axis.Variable(ratio_edges[2], name=\"logkt\", label=\"ln(kT/GeV)\"),\n",
" storage=hist.storage.Weight(),\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"h.variances()"
]
},
{
Expand Down Expand Up @@ -466,13 +509,6 @@
"plt.imshow(mc_sig_old_ratio_pt[0])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
1 change: 1 addition & 0 deletions src/HHbbVV/processors/corrections.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,6 +1100,7 @@ def get_lund_SFs(
hist.axis.Variable(ratio_edges[0], name="subjet_pt", label="Subjet pT [GeV]"),
hist.axis.Variable(ratio_edges[1], name="logD", label="ln(0.8/Delta)"),
hist.axis.Variable(ratio_edges[2], name="logkt", label="ln(kT/GeV)"),
storage=hist.storage.Weight(),
)

# repeat weights for each LP splitting
Expand Down

0 comments on commit 6d68b05

Please sign in to comment.