Skip to content

Commit

Permalink
residual paper fixes from the paper review (#304)
Browse files Browse the repository at this point in the history
* ensure the mask_visible is set to what was used to produce the samples in 2023
  • Loading branch information
jpata authored Mar 29, 2024
1 parent 4d35e51 commit cd2ed41
Show file tree
Hide file tree
Showing 6 changed files with 177 additions and 195 deletions.
71 changes: 15 additions & 56 deletions mlpf/plotting/plot_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ def plot_particles(yvals, epoch=None, cp_dir=None, comet_experiment=None, title=


def plot_jet_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=None, title=None):

pf_genjet_pt = yvals["jet_gen_to_cand_genpt"]
mlpf_genjet_pt = yvals["jet_gen_to_pred_genpt"]

Expand Down Expand Up @@ -1038,7 +1037,6 @@ def plot_jet_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No
plt.title(labels["gen_jet_range"].format(lim_low, lim_hi))
plt.yscale("log")

plt.tight_layout()
save_img(
"jet_response_binned.png",
epoch,
Expand All @@ -1051,22 +1049,12 @@ def plot_jet_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No
mlpf_vals = np.array(mlpf_vals)

# Plot median and IQR as a function of gen pt
fig, axs = plt.subplots(2, 1, sharex=True)
plt.sca(axs[0])
plt.plot(x_vals, pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 1], marker="o", label="MLPF")
plt.ylim(0.75, 1.25)
plt.axhline(1.0, color="black", ls="--")
plt.ylabel("Response median")
plt.legend(title=title)

plt.sca(axs[1])
plt.plot(x_vals, pf_vals[:, 2] - pf_vals[:, 0], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 2] - mlpf_vals[:, 0], marker="o", label="MLPF")
plt.ylabel("Response IQR")
plt.figure()
plt.plot(x_vals, (pf_vals[:, 2] - pf_vals[:, 0]) / pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, (mlpf_vals[:, 2] - mlpf_vals[:, 0]) / mlpf_vals[:, 1], marker="o", label="MLPF")
plt.legend(loc=1, title=title, fontsize=30)
plt.ylabel("Response IQR / median")
plt.xlabel(labels["gen_jet"])

plt.tight_layout()
save_img(
"jet_response_med_iqr.png",
epoch,
Expand All @@ -1076,7 +1064,6 @@ def plot_jet_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No


def plot_met_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=None, title=None):

genmet = yvals["gen_met"]

pf_response = yvals["ratio_cand"]
Expand Down Expand Up @@ -1131,7 +1118,6 @@ def plot_met_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No
plt.title(labels["gen_met_range"].format(lim_low, lim_hi))
plt.yscale("log")

plt.tight_layout()
save_img(
"met_response_binned.png",
epoch,
Expand All @@ -1144,27 +1130,12 @@ def plot_met_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No
mlpf_vals = np.array(mlpf_vals)

# Plot median and IQR as a function of gen pt
fig, axs = plt.subplots(2, 1, sharex=True)
plt.sca(axs[0])
plt.plot(x_vals, pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 1], marker="o", label="MLPF")
plt.ylim(0.75, 1.25)
plt.axhline(1.0, color="black", ls="--")
plt.ylabel("Response median")
if title:
plt.title(title)
plt.legend()

plt.sca(axs[1])
plt.plot(x_vals, pf_vals[:, 2] - pf_vals[:, 0], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 2] - mlpf_vals[:, 0], marker="o", label="MLPF")
plt.ylabel("Response IQR")
plt.legend()
if title:
plt.title(title)
plt.figure()
plt.plot(x_vals, (pf_vals[:, 2] - pf_vals[:, 0]) / pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, (mlpf_vals[:, 2] - mlpf_vals[:, 0]) / mlpf_vals[:, 1], marker="o", label="MLPF")
plt.ylabel("Response IQR / median")
plt.legend(loc=1, title=title, fontsize=30)
plt.xlabel(labels["gen_met"])

plt.tight_layout()
save_img(
"met_response_med_iqr.png",
epoch,
Expand All @@ -1174,7 +1145,6 @@ def plot_met_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=No


def plot_3dmomentum_response_binned(yvals, epoch=None, cp_dir=None, comet_experiment=None, title=None):

genmet = yvals["gen_mom"]

pf_response = yvals["ratio_cand"]
Expand Down Expand Up @@ -1229,7 +1199,6 @@ def plot_3dmomentum_response_binned(yvals, epoch=None, cp_dir=None, comet_experi
plt.title(labels["gen_mom_range"].format(lim_low, lim_hi))
plt.yscale("log")

plt.tight_layout()
save_img(
"mom_response_binned.png",
epoch,
Expand All @@ -1242,22 +1211,12 @@ def plot_3dmomentum_response_binned(yvals, epoch=None, cp_dir=None, comet_experi
mlpf_vals = np.array(mlpf_vals)

# Plot median and IQR as a function of gen pt
fig, axs = plt.subplots(2, 1, sharex=True)
plt.sca(axs[0])
plt.plot(x_vals, pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 1], marker="o", label="MLPF")
plt.ylim(0.75, 1.25)
plt.axhline(1.0, color="black", ls="--")
plt.ylabel("Response median")
plt.legend(title=title)

plt.sca(axs[1])
plt.plot(x_vals, pf_vals[:, 2] - pf_vals[:, 0], marker="o", label="PF")
plt.plot(x_vals, mlpf_vals[:, 2] - mlpf_vals[:, 0], marker="o", label="MLPF")
plt.ylabel("Response IQR")
plt.figure()
plt.plot(x_vals, (pf_vals[:, 2] - pf_vals[:, 0]) / pf_vals[:, 1], marker="o", label="PF")
plt.plot(x_vals, (mlpf_vals[:, 2] - mlpf_vals[:, 0]) / mlpf_vals[:, 1], marker="o", label="MLPF")
plt.ylabel("Response IQR / median")
plt.xlabel(labels["gen_mom"])

plt.tight_layout()
plt.legend(loc=1, fontsize=30, title=title)
save_img(
"mom_response_med_iqr.png",
epoch,
Expand Down
2 changes: 1 addition & 1 deletion notebooks/clic/paper-2023-overlapping-lepton-jet.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
32 changes: 21 additions & 11 deletions notebooks/clic/paper-2023-single-particle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
" plt.savefig(\"{}/res_icls{}_ivar{}.pdf\".format(outpath, pid, ivar), bbox_inches=\"tight\")\n",
"\n",
"\n",
"def plot_eff_and_fake_rate(icls=1, ivar=4, ielem=1, bins=np.linspace(-3, 6, 100), xlabel=\"PFElement log[E/GeV]\", log=True, ylim_fake=1.5, legtitle=\"\"):\n",
"def plot_eff_and_fake_rate(icls=1, ivar=4, ielem=1, bins=np.linspace(-3, 6, 100), xlabel=\"PFElement log[E/GeV]\", log=True, ylim_eff=(0.0, 1.5), ylim_fake=(0.0, 1.5), legtitle=\"\"):\n",
"\n",
" #choose only events with a cluster\n",
" #this makes the definition of the single particle reconstruction efficiency straightforward\n",
Expand Down Expand Up @@ -266,7 +266,7 @@
" ax = plt.axes(sharex=ax)\n",
" mplhep.histplot(eff_pf, label=\"PF\")\n",
" mplhep.histplot(eff_mlpf, label=\"MLPF\")\n",
" plt.ylim(0, 1.5)\n",
" plt.ylim(ylim_eff[0], ylim_eff[1])\n",
" plt.ylabel(\"Efficiency\")\n",
" plt.xlabel(xlabel)\n",
" #cms_label(ax)\n",
Expand All @@ -281,7 +281,7 @@
" ax = plt.axes(sharex=ax)\n",
" mplhep.histplot(fake_pf, label=\"PF\")\n",
" mplhep.histplot(fake_mlpf, label=\"MLPF\")\n",
" plt.ylim(0, ylim_fake)\n",
" plt.ylim(ylim_fake[0], ylim_fake[1])\n",
" plt.ylabel(\"Fake rate\")\n",
" plt.xlabel(xlabel)\n",
" #cms_label(ax)\n",
Expand All @@ -308,7 +308,17 @@
"metadata": {},
"outputs": [],
"source": [
"!rm *.pdf"
"!ls *.pdf"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a09d8c1b-f55b-4c62-9bd2-e64de7124897",
"metadata": {},
"outputs": [],
"source": [
"nfiles = -1"
]
},
{
Expand All @@ -318,7 +328,7 @@
"metadata": {},
"outputs": [],
"source": [
"yvals, X, _ = load_eval_data(\"../../experiments/mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_pi_pf/*/*.parquet\", -1)"
"yvals, X, _ = load_eval_data(\"../../mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_pi_pf/*/*.parquet\", nfiles)"
]
},
{
Expand All @@ -328,7 +338,7 @@
"metadata": {},
"outputs": [],
"source": [
"plot_eff_and_fake_rate(icls=1, ivar=1, ielem=1, bins=np.logspace(0, 2, 41), xlabel=\"track $p_T$ [GeV]\", log=True, ylim_fake=0.1, legtitle=\"charged hadrons\")"
"plot_eff_and_fake_rate(icls=1, ivar=1, ielem=1, bins=np.logspace(0, 2, 21), xlabel=\"track $p_T$ [GeV]\", log=True, ylim_eff=(0.6, 1.1), ylim_fake=(0, 0.01), legtitle=\"charged hadrons\")"
]
},
{
Expand All @@ -349,7 +359,7 @@
"metadata": {},
"outputs": [],
"source": [
"yvals, X, _ = load_eval_data(\"../../experiments/mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_gamma_pf/*/*.parquet\", -1)"
"yvals, X, _ = load_eval_data(\"../../mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_gamma_pf/*/*.parquet\", nfiles)"
]
},
{
Expand All @@ -359,7 +369,7 @@
"metadata": {},
"outputs": [],
"source": [
"plot_eff_and_fake_rate(icls=3, ivar=5, ielem=2, bins=np.logspace(0, 2, 41), xlabel=\"cluster $E$ [GeV]\", log=True, ylim_fake=0.1, legtitle=\"$\\gamma$\")"
"plot_eff_and_fake_rate(icls=3, ivar=5, ielem=2, bins=np.logspace(0, 2, 21), xlabel=\"cluster $E$ [GeV]\", log=True, ylim_eff=(0.8, 1.1), ylim_fake=(0, 0.02), legtitle=\"$\\gamma$\")"
]
},
{
Expand All @@ -380,7 +390,7 @@
"metadata": {},
"outputs": [],
"source": [
"yvals, X, _ = load_eval_data(\"../../experiments/mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_kaon0l_pf/*/*.parquet\", -1)"
"yvals, X, _ = load_eval_data(\"../../mlpf-clic-2023-results/clusters_best_tuned_gnn_clic_v130/evaluation/epoch_96/clic_edm_single_kaon0l_pf/*/*.parquet\", nfiles)"
]
},
{
Expand All @@ -390,7 +400,7 @@
"metadata": {},
"outputs": [],
"source": [
"plot_eff_and_fake_rate(icls=2, ivar=5, ielem=2, bins=np.logspace(0, 2, 41), xlabel=\"cluster $E$ [GeV]\", log=True, ylim_fake=0.1, legtitle=\"neutral hadrons\")"
"plot_eff_and_fake_rate(icls=2, ivar=5, ielem=2, bins=np.logspace(0, 2, 21), xlabel=\"cluster $E$ [GeV]\", log=True, ylim_eff=(0.5, 1.1), ylim_fake=(0, 0.05), legtitle=\"neutral hadrons\")"
]
},
{
Expand Down Expand Up @@ -421,7 +431,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
"version": "3.10.13"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit cd2ed41

Please sign in to comment.