From 0fcbdc49857bc7cc3c30f68ba4640b18fc014eec Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Mon, 12 Jan 2026 13:26:13 +0200 Subject: [PATCH 1/6] update for FR, use Raw PUPPI MET --- mlpf/plotting/data_preparation.py | 2 ++ mlpf/plotting/plot_met_validation.py | 35 +++++++++++++++++----------- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/mlpf/plotting/data_preparation.py b/mlpf/plotting/data_preparation.py index 14def83a5..bacf6bbd9 100644 --- a/mlpf/plotting/data_preparation.py +++ b/mlpf/plotting/data_preparation.py @@ -45,6 +45,8 @@ def load_nano(fn): "PuppiMET_phi", "RawPFMET_pt", "RawPFMET_phi", + "RawPuppiMET_pt", + "RawPuppiMET_phi", "Pileup_nPU", "Pileup_nTrueInt", "GenVtx_z", diff --git a/mlpf/plotting/plot_met_validation.py b/mlpf/plotting/plot_met_validation.py index 7f93fa235..c494b69dc 100644 --- a/mlpf/plotting/plot_met_validation.py +++ b/mlpf/plotting/plot_met_validation.py @@ -24,6 +24,13 @@ def to_bh(data, bins): return h1 +# def sample_label(ax, sample, additional_text="", x=0.05, y=0.95, fontsize=35, color="black"): +# text = EVALUATION_DATASET_NAMES[sample] +# plt.text(x, y, text + additional_text, ha="left", va="top", transform=ax.transAxes, fontsize=fontsize, color=color) + +# def cms_label(ax): +# mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) + def plot_met_distribution( data_pf, data_mlpf, @@ -52,10 +59,10 @@ def plot_met_distribution( h0 = to_bh(data_pf["GenMET_pt"], bins) # PF MET (Puppi) - h1 = to_bh(data_pf["PuppiMET_pt"], bins) + h1 = to_bh(data_pf["RawPuppiMET_pt"], bins) # MLPF MET - h2 = to_bh(data_mlpf["PuppiMET_pt"], bins) + h2 = to_bh(data_mlpf["RawPuppiMET_pt"], bins) plt.sca(a0) x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen.", ls="--", color=gen_color) @@ -66,7 +73,7 @@ def plot_met_distribution( plt.yscale("log") a0.set_ylim(bottom=1, top=a0.get_ylim()[1] * 1000) - mplhep.cms.label("", data=False, com=tev, year="Run 3", ax=a0) + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=a0) a0.text( sample_label_coords[0], sample_label_coords[1], @@ -127,7 +134,7 @@ def met_response_plot( ax = plt.axes() b = np.linspace(0, 5, 101) - mplhep.cms.label("", data=False, com=tev, year="Run 3", ax=ax) + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], @@ -325,7 +332,7 @@ def plot_met_response_vs_pu(resp_pf, resp_mlpf, data_pf, data_mlpf, output_dir, ax.set_xlabel("True $N_{PV}$") ax.set_ylabel("MET response resolution (IQR/med.)") ax.set_ylim(0, 1.5) - mplhep.cms.label(ax=ax, data=False, com=tev, year="Run 3") + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) ax.text( kwargs["sample_label_coords"][0], kwargs["sample_label_coords"][1], @@ -371,13 +378,13 @@ def make_plots(input_pf_parquet, input_mlpf_parquet, output_dir, sample_name, te legend_loc = (0.5, 0.55) legend_loc_scalereso = (0.50, 0.65) legend_loc_met_response = (0.3, 0.45) - sample_label_fontsize = 30 + sample_label_fontsize = 35 addtext_fontsize = 25 jet_label_coords_single = 0.02, 0.88 - sample_label_coords = 0.02, 0.96 - gen_color = "#648df4" - pf_color = "#f3a041" - mlpf_color = "#d23b3d" + sample_label_coords = 0.05, 0.95 + gen_color = "#9C9CA1" + pf_color = "#5790FC" + mlpf_color = "#E42536" pf_linestyle = "-." mlpf_linestyle = "-" pf_label = "PF-PUPPI" @@ -454,12 +461,12 @@ def varbins(*args): msk = genmet_pt_pf != 0 resp_pf = { - "response": np.divide(data_pf["PuppiMET_pt"][msk], genmet_pt_pf[msk]), + "response": np.divide(data_pf["RawPuppiMET_pt"][msk], genmet_pt_pf[msk]), "GenMET_pt": genmet_pt_pf, } msk = genmet_pt_mlpf != 0 resp_mlpf = { - "response": np.divide(data_mlpf["PuppiMET_pt"][msk], genmet_pt_mlpf[msk]), + "response": np.divide(data_mlpf["RawPuppiMET_pt"][msk], genmet_pt_mlpf[msk]), "GenMET_pt": genmet_pt_mlpf, } @@ -511,7 +518,7 @@ def varbins(*args): ax.set_xscale("log") ax.set_ylim(0.0, 4.0) plt.axhline(1.0, color="black", ls="--") - mplhep.cms.label(ax=ax, data=False, com=tev, year="Run 3") + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], plot_sample_name, transform=ax.transAxes, fontsize=sample_label_fontsize, ha="left", va="top" ) @@ -533,7 +540,7 @@ def varbins(*args): ax.legend(fontsize=legend_fontsize, loc=legend_loc_scalereso) ax.set_xscale("log") ax.set_ylim(0.0, 2.0) - mplhep.cms.label(ax=ax, data=False, com=tev, year="Run 3") + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], plot_sample_name, transform=ax.transAxes, fontsize=sample_label_fontsize, ha="left", va="top" ) From b63f3069d1c925d6cd71448bf58048f8f57a56f9 Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Mon, 12 Jan 2026 13:27:40 +0200 Subject: [PATCH 2/6] remove --- mlpf/plotting/plot_met_validation.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/mlpf/plotting/plot_met_validation.py b/mlpf/plotting/plot_met_validation.py index c494b69dc..7b452ebac 100644 --- a/mlpf/plotting/plot_met_validation.py +++ b/mlpf/plotting/plot_met_validation.py @@ -24,13 +24,6 @@ def to_bh(data, bins): return h1 -# def sample_label(ax, sample, additional_text="", x=0.05, y=0.95, fontsize=35, color="black"): -# text = EVALUATION_DATASET_NAMES[sample] -# plt.text(x, y, text + additional_text, ha="left", va="top", transform=ax.transAxes, fontsize=fontsize, color=color) - -# def cms_label(ax): -# mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) - def plot_met_distribution( data_pf, data_mlpf, From 40a7749c59f01fc23b619cd914974634965b162b Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Mon, 12 Jan 2026 13:30:35 +0200 Subject: [PATCH 3/6] fix gen --- mlpf/plotting/plot_met_validation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mlpf/plotting/plot_met_validation.py b/mlpf/plotting/plot_met_validation.py index 7b452ebac..1dfff30f1 100644 --- a/mlpf/plotting/plot_met_validation.py +++ b/mlpf/plotting/plot_met_validation.py @@ -58,7 +58,7 @@ def plot_met_distribution( h2 = to_bh(data_mlpf["RawPuppiMET_pt"], bins) plt.sca(a0) - x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen.", ls="--", color=gen_color) + x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen", ls="--", color=gen_color) x1 = mplhep.histplot(h1, histtype="step", lw=2, label="PF-PUPPI", ls=pf_linestyle, color=pf_color) x2 = mplhep.histplot(h2, histtype="step", lw=2, label=mlpf_label, ls=mlpf_linestyle, color=mlpf_color) @@ -368,7 +368,7 @@ def make_plots(input_pf_parquet, input_mlpf_parquet, output_dir, sample_name, te # plotting style variables legend_fontsize = 30 - legend_loc = (0.5, 0.55) + legend_loc = (0.5, 0.5) legend_loc_scalereso = (0.50, 0.65) legend_loc_met_response = (0.3, 0.45) sample_label_fontsize = 35 From c3a07cfdbb305c6af0186808371f74f48015dd8e Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Mon, 12 Jan 2026 15:32:37 +0200 Subject: [PATCH 4/6] update plos --- mlpf/plotting/plot_loss_curves.py | 42 ++--- mlpf/plotting/plot_met_validation.py | 10 +- mlpf/plotting/plot_validation.py | 20 +-- .../cms-validate-root-vs-postprocessing.ipynb | 39 ++--- notebooks/cms/cmssw-runtimes.ipynb | 26 ++-- scripts/joosep-desktop/cms-plots.sh | 147 +++++++++--------- 6 files changed, 142 insertions(+), 142 deletions(-) diff --git a/mlpf/plotting/plot_loss_curves.py b/mlpf/plotting/plot_loss_curves.py index 28120eb17..1459f064b 100644 --- a/mlpf/plotting/plot_loss_curves.py +++ b/mlpf/plotting/plot_loss_curves.py @@ -65,8 +65,8 @@ def loss_plot(epochs, train, test, margin=0.05, smoothing=False, ylabel="", titl l0 = "Training" l1 = "Validation" - p0 = plt.plot(epochs, train, alpha=alpha, label=l0, marker="o", ls="--") - p1 = plt.plot(epochs, test, alpha=alpha, label=l1, marker="x") + p0 = plt.plot(epochs, train, alpha=alpha, label=l0, marker="o", ls="--", lw=3, ms=10) + p1 = plt.plot(epochs, test, alpha=alpha, label=l1, marker="x", lw=3, ms=10) if smoothing: train_smooth = np.convolve(train[~np.isnan(train)], np.ones(5) / 5, mode="valid") @@ -82,17 +82,17 @@ def loss_plot(epochs, train, test, margin=0.05, smoothing=False, ylabel="", titl if last_valid_loss is not np.nan: plt.ylim(last_valid_loss * (1.0 - margin), last_valid_loss * (1.0 + margin)) - plt.legend(loc=3, frameon=False, fontsize=30) - plt.xlabel("epoch") + plt.legend(loc=3, frameon=False, fontsize=35) + plt.xlabel("Epoch") plt.ylabel(ylabel) - mplhep.cms.label("", data=False, rlabel="Run 3 configuration") + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (14 TeV)') return fig, ax @click.command() -@click.option("--input-dirs", "-i", multiple=True, required=True, help="Input directories containing history/epoch_*.json files.") -@click.option("--labels", "-l", multiple=True, help="Labels for each input directory. Must be the same number as input-dirs.") -@click.option("--output-dir", "-o", required=True, type=str, help="Output directory for plots.") +@click.option("--input-dirs", "-i", multiple=True, help="Input directories containing history/epoch_*.json files.", default=["/mnt/work/huggingface/particleflow/cms/v2.6.0pre1/pyg-cms_20250722_101813_274478"]) +@click.option("--labels", "-l", multiple=True, help="Labels for each input directory. Must be the same number as input-dirs.", default=["v2.6.0pre1"]) +@click.option("--output-dir", "-o", type=str, help="Output directory for plots.", default="plots") def main(input_dirs, labels, output_dir): """ Generates loss curve plots from training history files. @@ -123,7 +123,7 @@ def main(input_dirs, labels, output_dir): # Total loss fig, ax = loss_plot( - history.index + 1, history["train_Total"].values, history["valid_Total"].values, margin=0.1, ylabel="Total loss", title=label + history.index + 1, history["train_Total"].values, history["valid_Total"].values, margin=0.15, ylabel="Total Loss [a.u.]", title=label ) plt.xticks(range(1, len(history) + 1)) plt.savefig(output_path / f"{label}_loss.pdf") @@ -136,7 +136,7 @@ def main(input_dirs, labels, output_dir): history["train_Classification"].values * 100, history["valid_Classification"].values * 100, margin=0.05, - ylabel="Particle ID loss x100", + ylabel="Particle ID Loss x100 [a.u.]", title=label, ) plt.xticks(range(1, len(history) + 1)) @@ -149,8 +149,8 @@ def main(input_dirs, labels, output_dir): history.index + 1, history["train_Classification_binary"].values, history["valid_Classification_binary"].values, - margin=0.1, - ylabel="Binary classification loss", + margin=0.15, + ylabel="Binary Classification Loss [a.u.]", title=label, ) plt.xticks(range(1, len(history) + 1)) @@ -162,7 +162,7 @@ def main(input_dirs, labels, output_dir): if all([f"train_{loss}" in history.columns for loss in reg_losses]): reg_loss = sum([history[f"train_{loss}"].values for loss in reg_losses]) val_reg_loss = sum([history[f"valid_{loss}"].values for loss in reg_losses]) - fig, ax = loss_plot(history.index + 1, reg_loss, val_reg_loss, margin=0.2, ylabel="Regression loss", title=label) + fig, ax = loss_plot(history.index + 1, reg_loss, val_reg_loss, margin=0.2, ylabel="Regression Loss [a.u.]", title=label) plt.xticks(range(1, len(history) + 1)) plt.savefig(output_path / f"{label}_reg_loss.pdf") plt.close(fig) @@ -174,7 +174,7 @@ def main(input_dirs, labels, output_dir): history["train_ispu"].values, history["valid_ispu"].values, margin=0.5, - ylabel="PU classification loss", + ylabel="PU Classification Loss [a.u.]", title=label, ) plt.xticks(range(1, len(history) + 1)) @@ -186,10 +186,10 @@ def main(input_dirs, labels, output_dir): # fig.suptitle(label, fontsize=35) loss_info = [ - {"name": "Total", "label": "Total Loss"}, - {"name": "Classification", "label": "PID Classification Loss"}, - {"name": "Classification_binary", "label": "Binary Classification Loss"}, - {"name": "Regression", "label": "Regression Loss"}, + {"name": "Total", "label": "Total Loss [a.u.]"}, + {"name": "Classification", "label": "PID Classification Loss [a.u.]"}, + {"name": "Classification_binary", "label": "Binary Classification Loss [a.u.]"}, + {"name": "Regression", "label": "Regression Loss [a.u.]"}, ] for i, (ax, info) in enumerate(zip(axs, loss_info)): @@ -238,10 +238,10 @@ def main(input_dirs, labels, output_dir): continue label = labels[i] if labels else Path(input_dirs[i]).name plt.plot(history.index + 1, history["valid_Total"], marker="o", label=label) - plt.ylabel("Total valid. loss") - plt.xlabel("epoch") + plt.ylabel("Total Valid. Loss [a.u.]") + plt.xlabel("Epoch") plt.legend(loc="best") - mplhep.cms.label("", data=False, rlabel="Run 3 configuration") + mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (14 TeV)') plt.savefig(output_path / "loss_comparison.pdf") plt.close() diff --git a/mlpf/plotting/plot_met_validation.py b/mlpf/plotting/plot_met_validation.py index 1dfff30f1..883a07bab 100644 --- a/mlpf/plotting/plot_met_validation.py +++ b/mlpf/plotting/plot_met_validation.py @@ -52,10 +52,10 @@ def plot_met_distribution( h0 = to_bh(data_pf["GenMET_pt"], bins) # PF MET (Puppi) - h1 = to_bh(data_pf["RawPuppiMET_pt"], bins) + h1 = to_bh(data_pf["PuppiMET_pt"], bins) # MLPF MET - h2 = to_bh(data_mlpf["RawPuppiMET_pt"], bins) + h2 = to_bh(data_mlpf["PuppiMET_pt"], bins) plt.sca(a0) x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen", ls="--", color=gen_color) @@ -373,7 +373,7 @@ def make_plots(input_pf_parquet, input_mlpf_parquet, output_dir, sample_name, te legend_loc_met_response = (0.3, 0.45) sample_label_fontsize = 35 addtext_fontsize = 25 - jet_label_coords_single = 0.02, 0.88 + jet_label_coords_single = 0.05, 0.88 sample_label_coords = 0.05, 0.95 gen_color = "#9C9CA1" pf_color = "#5790FC" @@ -454,12 +454,12 @@ def varbins(*args): msk = genmet_pt_pf != 0 resp_pf = { - "response": np.divide(data_pf["RawPuppiMET_pt"][msk], genmet_pt_pf[msk]), + "response": np.divide(data_pf["PuppiMET_pt"][msk], genmet_pt_pf[msk]), "GenMET_pt": genmet_pt_pf, } msk = genmet_pt_mlpf != 0 resp_mlpf = { - "response": np.divide(data_mlpf["RawPuppiMET_pt"][msk], genmet_pt_mlpf[msk]), + "response": np.divide(data_mlpf["PuppiMET_pt"][msk], genmet_pt_mlpf[msk]), "GenMET_pt": genmet_pt_mlpf, } diff --git a/mlpf/plotting/plot_validation.py b/mlpf/plotting/plot_validation.py index 50aaf7eda..c9607129a 100644 --- a/mlpf/plotting/plot_validation.py +++ b/mlpf/plotting/plot_validation.py @@ -67,14 +67,14 @@ def make_plots(input_pf_parquet, input_mlpf_parquet, corrections_file, output_di legend_loc_effpur = (0.5, 0.68) legend_loc_scalereso = (0.40, 0.50) legend_loc_jet_response = (0.05, 0.55) - sample_label_fontsize = 30 + sample_label_fontsize = 35 addtext_fontsize = 25 - jet_label_coords = 0.02, 0.86 - jet_label_coords_single = 0.02, 0.88 - sample_label_coords = 0.02, 0.96 - gen_color = "#648df4" - pf_color = "#f3a041" - mlpf_color = "#d23b3d" + jet_label_coords = 0.05, 0.85 + jet_label_coords_single = 0.05, 0.87 + sample_label_coords = 0.05, 0.95 + gen_color = "#9C9CA1" + pf_color = "#5790FC" + mlpf_color = "#E42536" gen_linestyle = "--" pf_linestyle = "-." mlpf_linestyle = "-" @@ -184,9 +184,9 @@ def plot_kinematic_distribution( h2 = to_bh(awkward.flatten(data_mlpf[f"{jet_prefix}_{variable_reco}"][mlpf_jet_mask]), bins) plt.sca(a0) - x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen.", ls=gen_linestyle) - x1 = mplhep.histplot(h1, histtype="step", lw=2, label=pf_label, ls=pf_linestyle) - x2 = mplhep.histplot(h2, histtype="step", lw=2, label=mlpf_label, ls=mlpf_linestyle) + x0 = mplhep.histplot(h0, histtype="step", lw=2, label="Gen", ls=gen_linestyle, color=gen_color) + x1 = mplhep.histplot(h1, histtype="step", lw=2, label=pf_label, ls=pf_linestyle, color=pf_color) + x2 = mplhep.histplot(h2, histtype="step", lw=2, label=mlpf_label, ls=mlpf_linestyle, color=mlpf_color) if logy: plt.yscale("log") diff --git a/notebooks/cms/cms-validate-root-vs-postprocessing.ipynb b/notebooks/cms/cms-validate-root-vs-postprocessing.ipynb index 0e3da93ba..f73202ac4 100644 --- a/notebooks/cms/cms-validate-root-vs-postprocessing.ipynb +++ b/notebooks/cms/cms-validate-root-vs-postprocessing.ipynb @@ -53,20 +53,21 @@ "outputs": [], "source": [ "matplotlib.rcParams['axes.labelsize'] = 35\n", - "legend_fontsize = 30\n", + "legend_fontsize = 35\n", "sample_label_fontsize = 30\n", - "addtext_fontsize = 25\n", + "addtext_fontsize = 30\n", "\n", - "jet_label_coords = 0.02, 0.82\n", - "jet_label_coords_single = 0.02, 0.86\n", - "sample_label_coords = 0.02, 0.96\n", + "jet_label_coords = 0.05, 0.80\n", + "jet_label_coords_single = 0.05, 0.86\n", + "sample_label_coords = 0.05, 0.95\n", "jet_label_ak4 = \"AK4 ref. jets, $p_T$ > 3 GeV\"\n", "particle_label = \"$p_T$ > 0.5 GeV, $|\\eta|$ < 5\"\n", + "legend_loc = (0.54, 0.48)\n", "\n", "default_cycler = plt.rcParams['axes.prop_cycle']\n", "\n", - "pythia_color = \"#648df4\"\n", - "target_color = \"#944b8a\"\n", + "pythia_color = \"#9C9CA1\"\n", + "target_color = \"#964A8B\"\n", "\n", "pythia_linestyle = \"--\"\n", "target_linestyle = \"-\"" @@ -104,7 +105,7 @@ "outputs": [], "source": [ "#files = [pickle.load(open(fn, \"rb\")) for fn in glob.glob(\"/local/joosep/mlpf/cms/20250508_cmssw_15_0_5_d3c6d1/validation_plots/out*.pkl\")]\n", - "files = [pickle.load(open(fn, \"rb\")) for fn in glob.glob(\"/mnt/work/particleflow/20250508_cmssw_15_0_5_d3c6d1/validation_plots/out*.pkl\")]\n", + "files = [pickle.load(open(fn, \"rb\")) for fn in glob.glob(\"/mnt/work/particleflow/CMSSW_15_0_5_mlpf_v2.6.0pre1_puppi_2372e2/validation_plots/out*.pkl\")]\n", "ret = reduce(add_results, files, {})\n", "\n", "sample_keys = sorted(set([\"/\".join(k.split(\"/\")[0:2]) for k in ret.keys() if not k.startswith(\"combined\")]))\n", @@ -139,7 +140,7 @@ "}\n", "\n", "def sample_label(ax, sample, additional_text=\"\"):\n", - " plt.text(sample_label_coords[0], sample_label_coords[1], EVALUATION_DATASET_NAMES[sample_labels[sample.replace(\"combined/\", \"\")]] + \"\\n\" + additional_text, ha=\"left\", va=\"top\", transform=ax.transAxes)" + " plt.text(sample_label_coords[0], sample_label_coords[1], EVALUATION_DATASET_NAMES[sample_labels[sample.replace(\"combined/\", \"\")]] + \"\\n\" + additional_text, ha=\"left\", va=\"top\", transform=ax.transAxes, fontsize=sample_label_fontsize)" ] }, { @@ -167,16 +168,6 @@ " plt.savefig(\"{}_particle_met_2d.pdf\".format(sample.replace(\"/\", \"_\")), bbox_inches=\"tight\")" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "44a895d1-f5f9-4f09-8134-126c34da6422", - "metadata": {}, - "outputs": [], - "source": [ - "sample_keys_combined" - ] - }, { "cell_type": "code", "execution_count": null, @@ -195,7 +186,7 @@ " mplhep.histplot(h1, label=\"Target\", lw=2, color=target_color, ls=target_linestyle)\n", " plt.xscale(\"log\")\n", " plt.yscale(\"log\")\n", - " plt.legend(loc=(0.65, 0.7), fontsize=legend_fontsize)\n", + " plt.legend(loc=legend_loc, fontsize=legend_fontsize)\n", " plt.ylim(1, 1e8)\n", " mplhep.cms.label(\"\", data=False, com=14, year='Run 3')\n", " sample_label(a0, sample)\n", @@ -272,13 +263,13 @@ " mplhep.histplot(h0, label=\"Pythia\", lw=2, color=pythia_color, ls=pythia_linestyle)\n", " mplhep.histplot(h1, label=\"Target\", lw=2, color=target_color, ls=target_linestyle)\n", " plt.xscale(\"log\")\n", - " plt.legend(fontsize=legend_fontsize)\n", + " plt.legend(fontsize=legend_fontsize, loc=legend_loc)\n", " mplhep.cms.label(\"\", data=False, com=14, year='Run 3')\n", " sample_label(a0, sample)\n", " a0.text(jet_label_coords[0], jet_label_coords[1], jet_label_ak4, transform=a0.transAxes, fontsize=addtext_fontsize)\n", " plt.yscale(\"log\")\n", " plt.ylabel(\"Count\")\n", - " plt.ylim(1,1e8)\n", + " plt.ylim(100,1e8)\n", "\n", " plt.sca(a1)\n", " \n", @@ -311,7 +302,7 @@ " plt.figure()\n", " ax = plt.axes()\n", " mplhep.histplot(ret[f\"{sample}/jets_pt_ratio_target_pumask\"][bh.rebin(rebin)], yerr=False, label=\"Target\", lw=2, color=target_color, ls=target_linestyle)\n", - " plt.legend(fontsize=legend_fontsize)\n", + " plt.legend(loc=legend_loc, fontsize=legend_fontsize)\n", " mplhep.cms.label(\"\", data=False, com=14, year='Run 3')\n", " sample_label(ax, sample, jet_label_ak4)\n", " a0.text(jet_label_coords_single[0], jet_label_coords_single[1], jet_label_ak4, transform=a0.transAxes, fontsize=addtext_fontsize)\n", @@ -336,7 +327,7 @@ " plt.sca(a0)\n", " mplhep.histplot(ret[f\"{sample}/met_pythia\"][bh.rebin(rebin)], yerr=False, label=\"Pythia\", lw=2, color=pythia_color, ls=pythia_linestyle)\n", " mplhep.histplot(ret[f\"{sample}/met_target_pumask\"][bh.rebin(rebin)], yerr=False, label=\"Target\", lw=2, color=target_color, ls=target_linestyle)\n", - " plt.legend(loc=(0.65, 0.7), fontsize=legend_fontsize)\n", + " plt.legend(loc=legend_loc, fontsize=legend_fontsize)\n", " plt.yscale(\"log\")\n", " plt.xscale(\"log\")\n", " mplhep.cms.label(\"\", data=False, com=14, year='Run 3')\n", diff --git a/notebooks/cms/cmssw-runtimes.ipynb b/notebooks/cms/cmssw-runtimes.ipynb index bcf96b49e..d34782379 100644 --- a/notebooks/cms/cmssw-runtimes.ipynb +++ b/notebooks/cms/cmssw-runtimes.ipynb @@ -36,12 +36,12 @@ "sample_label_fontsize = 30\n", "addtext_fontsize = 25\n", "\n", - "jet_label_coords = 0.02, 0.82\n", - "jet_label_coords_single = 0.02, 0.86\n", - "sample_label_coords = 0.02, 0.96\n", + "jet_label_coords = 0.05, 0.82\n", + "jet_label_coords_single = 0.05, 0.86\n", + "sample_label_coords = 0.05, 0.96\n", "\n", - "pf_color = \"#f3a041\"\n", - "mlpf_color = \"#d23b3d\"\n", + "pf_color = \"#5790FC\"\n", + "mlpf_color = \"#E42536\"\n", "\n", "pf_linestyle = \"-.\"\n", "mlpf_linestyle = \"-\"" @@ -55,7 +55,7 @@ "outputs": [], "source": [ "def cms_label(ax):\n", - " mplhep.cms.label(\"\", data=False, rlabel='Run 3 configuration')" + " mplhep.cms.label(\"\", data=False, rlabel='Run 3 (13.6 TeV)')" ] }, { @@ -233,6 +233,7 @@ " norm=matplotlib.colors.LogNorm(vmin=1),\n", " cmap=\"viridis\", edgecolor=\"face\"\n", ");\n", + "plt.plot([0,0.5],[0,0.5], ls=\"--\", color=\"black\")\n", "plt.xlabel(\"PF, $t^{CPU}_{ev}$ [s]\")\n", "plt.ylabel(\"MLPF, $t^{GPU}_{ev}$ [s]\")\n", "cms_label(ax)\n", @@ -255,18 +256,17 @@ "ax = plt.axes()\n", "b = np.linspace(0, 0.5, 81)\n", "\n", - "plt.plot([], [])\n", "x = (times_pf_event_good[\"PFBlockProducer\"]+times_pf_event_good[\"PFProducer\"]).drop(index=bad_evs.index)\n", "m = np.mean(x)\n", "plt.hist(\n", " x,\n", - " bins=b, histtype=\"step\", lw=2, label=\"PF, $\\\\bar{t}^{CPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=pf_linestyle\n", + " bins=b, histtype=\"step\", lw=2, label=\"PF, $\\\\bar{t}^{CPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=pf_linestyle, color=pf_color\n", ");\n", "\n", "x = times_mlpf_event_good[\"MLPFProducer\"].drop(index=bad_evs.index)\n", "m = np.mean(x)\n", "plt.hist(\n", - " x, bins=b, histtype=\"step\", lw=2, label=\"MLPF, $\\\\bar{t}^{GPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=mlpf_linestyle\n", + " x, bins=b, histtype=\"step\", lw=2, label=\"MLPF, $\\\\bar{t}^{GPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=mlpf_linestyle, color=mlpf_color\n", ")\n", "cms_label(ax)\n", "sample_label(ax, \"cms_pf_qcd\", x=sample_label_coords[0], y=sample_label_coords[1], fontsize=sample_label_fontsize)\n", @@ -317,6 +317,14 @@ "a0.text(sample_label_coords[0], 0.60, \"Nvidia L4, CMSSW_15_0_5\\nnative ONNXRuntime\\n8 jobs, 8 threads per job\", fontsize=legend_fontsize, transform=a0.transAxes)\n", "plt.savefig(\"{}/gpu_util.pdf\".format(outpath), bbox_inches=\"tight\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "20d8a469-63cf-465d-aad0-a3eb4ac377e9", + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/scripts/joosep-desktop/cms-plots.sh b/scripts/joosep-desktop/cms-plots.sh index 72d71b7af..cfc29edaf 100755 --- a/scripts/joosep-desktop/cms-plots.sh +++ b/scripts/joosep-desktop/cms-plots.sh @@ -3,22 +3,22 @@ export PYTHONPATH=`pwd` export QT_QPA_PLATFORM=offscreen IMG=~/HEP-KBFI/singularity/pytorch.simg\:2025-09-01 -NANO_PATH=/mnt/work/particleflow/CMSSW_15_0_5_mlpf_v2.6.0pre1_puppi_117d32/cuda_False +NANO_PATH=/mnt/work/particleflow/CMSSW_15_0_5_mlpf_v2.6.0pre1_puppi_2372e2/cuda_False/ -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/data_preparation.py \ - --input-dir $NANO_PATH \ - --sample QCD_PU & +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/data_preparation.py \ +# --input-dir $NANO_PATH \ +# --sample QCD_PU & -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/data_preparation.py \ - --input-dir $NANO_PATH \ - --sample QCD_PU_13p6 & +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/data_preparation.py \ +# --input-dir $NANO_PATH \ +# --sample QCD_PU_13p6 & -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/data_preparation.py \ - --input-dir $NANO_PATH \ - --sample QCD_PU_13p6_v3 & +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/data_preparation.py \ +# --input-dir $NANO_PATH \ +# --sample QCD_PU_13p6_v3 & # singularity exec -B /mnt/work/ $IMG \ # python3 mlpf/plotting/data_preparation.py \ @@ -55,35 +55,25 @@ wait # Exctract jet corrections -sample=QCD_PU -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/corrections.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --corrections-file jec_ak4_${sample}.npz \ - --output-dir ./plots/${sample}/ak4/jec \ - --jet-type ak4 \ - --sample-name ${sample} & - -sample=QCD_PU_13p6 -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/corrections.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --corrections-file jec_ak4_${sample}.npz \ - --output-dir ./plots/${sample}/ak4/jec \ - --jet-type ak4 \ - --sample-name ${sample} & - -sample=QCD_PU_13p6_v3 -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/corrections.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --corrections-file jec_ak4_${sample}.npz \ - --output-dir ./plots/${sample}/ak4/jec \ - --jet-type ak4 \ - --sample-name ${sample} & +# sample=QCD_PU +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/corrections.py \ +# --input-pf-parquet ${sample}_pf.parquet \ +# --input-mlpf-parquet ${sample}_mlpf.parquet \ +# --corrections-file jec_ak4_${sample}.npz \ +# --output-dir ./plots/${sample}/ak4/jec \ +# --jet-type ak4 \ +# --sample-name ${sample} & + +# sample=QCD_PU_13p6 +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/corrections.py \ +# --input-pf-parquet ${sample}_pf.parquet \ +# --input-mlpf-parquet ${sample}_mlpf.parquet \ +# --corrections-file jec_ak4_${sample}.npz \ +# --output-dir ./plots/${sample}/ak4/jec \ +# --jet-type ak4 \ +# --sample-name ${sample} & # singularity exec -B /mnt/work/ $IMG \ # python3 mlpf/plotting/corrections.py \ @@ -93,32 +83,43 @@ singularity exec -B /mnt/work/ $IMG \ # --output-dir ./plots/${sample}/ak8/jec \ # --jet-type ak8 \ # --sample-name ${sample} & -wait -sample=QCD_PU -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/plot_validation.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --corrections-file jec_ak4_${sample}.npz \ - --output-dir ./plots \ - --jet-type ak4 \ - --sample-name ${sample} \ - --fiducial-cuts eta_0_2p5 \ - --tev 14 & - -singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/plot_met_validation.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --sample-name ${sample} \ - --output-dir ./plots \ - --tev 14 & -wait +# sample=QCD_PU_13p6_v3 +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/corrections.py \ +# --input-pf-parquet ${sample}_pf.parquet \ +# --input-mlpf-parquet ${sample}_mlpf.parquet \ +# --corrections-file jec_ak4_${sample}.npz \ +# --output-dir ./plots/${sample}/ak4/jec \ +# --jet-type ak4 \ +# --sample-name ${sample} & + +# wait + +# sample=QCD_PU +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/plot_validation.py \ +# --input-pf-parquet ${sample}_pf.parquet \ +# --input-mlpf-parquet ${sample}_mlpf.parquet \ +# --corrections-file jec_ak4_${sample}.npz \ +# --output-dir ./plots \ +# --jet-type ak4 \ +# --sample-name ${sample} \ +# --fiducial-cuts eta_0_2p5 \ +# --tev 14 & + +# singularity exec -B /mnt/work/ $IMG \ +# python3 mlpf/plotting/plot_met_validation.py \ +# --input-pf-parquet ${sample}_pf.parquet \ +# --input-mlpf-parquet ${sample}_mlpf.parquet \ +# --sample-name ${sample} \ +# --output-dir ./plots \ +# --tev 14 & +# wait #Do jet-level plots -# for sample in QCD_noPU_13p6 QCD_PU_13p6 TTbar_PU_13p6 TTbar_noPU_13p6 PhotonJet_noPU_13p6 PhotonJet_PU_13p6; do -for sample in QCD_PU_13p6 QCD_PU_13p6_v3; do +#for sample in QCD_noPU_13p6 QCD_PU_13p6 TTbar_PU_13p6 TTbar_noPU_13p6 PhotonJet_noPU_13p6 PhotonJet_PU_13p6; do +for sample in QCD_PU_13p6 TTbar_PU_13p6; do # singularity exec -B /mnt/work/ $IMG \ # python3 mlpf/plotting/plot_validation.py \ # --input-pf-parquet ${sample}_pf.parquet \ @@ -133,7 +134,7 @@ for sample in QCD_PU_13p6 QCD_PU_13p6_v3; do python3 mlpf/plotting/plot_validation.py \ --input-pf-parquet ${sample}_pf.parquet \ --input-mlpf-parquet ${sample}_mlpf.parquet \ - --corrections-file jec_ak4_${sample}.npz \ + --corrections-file jec_ak4_QCD_PU_13p6.npz \ --output-dir ./plots \ --jet-type ak4 \ --sample-name ${sample} \ @@ -170,13 +171,13 @@ for sample in QCD_PU_13p6 QCD_PU_13p6_v3; do # --sample-name ${sample} \ # --fiducial-cuts inclusive & - singularity exec -B /mnt/work/ $IMG \ - python3 mlpf/plotting/plot_met_validation.py \ - --input-pf-parquet ${sample}_pf.parquet \ - --input-mlpf-parquet ${sample}_mlpf.parquet \ - --sample-name ${sample} \ - --output-dir ./plots \ - --tev 13.6 & + # singularity exec -B /mnt/work/ $IMG \ + # python3 mlpf/plotting/plot_met_validation.py \ + # --input-pf-parquet ${sample}_pf.parquet \ + # --input-mlpf-parquet ${sample}_mlpf.parquet \ + # --sample-name ${sample} \ + # --output-dir ./plots \ + # --tev 13.6 & wait done From 635c2c5c2927e6dd580e478e0f7d5d7155ec8a53 Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Mon, 12 Jan 2026 17:35:06 +0200 Subject: [PATCH 5/6] format --- mlpf/plotting/plot_loss_curves.py | 12 +++++++++--- mlpf/plotting/plot_met_validation.py | 10 +++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/mlpf/plotting/plot_loss_curves.py b/mlpf/plotting/plot_loss_curves.py index 1459f064b..e7d39b1e6 100644 --- a/mlpf/plotting/plot_loss_curves.py +++ b/mlpf/plotting/plot_loss_curves.py @@ -85,12 +85,18 @@ def loss_plot(epochs, train, test, margin=0.05, smoothing=False, ylabel="", titl plt.legend(loc=3, frameon=False, fontsize=35) plt.xlabel("Epoch") plt.ylabel(ylabel) - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (14 TeV)') + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (14 TeV)") return fig, ax @click.command() -@click.option("--input-dirs", "-i", multiple=True, help="Input directories containing history/epoch_*.json files.", default=["/mnt/work/huggingface/particleflow/cms/v2.6.0pre1/pyg-cms_20250722_101813_274478"]) +@click.option( + "--input-dirs", + "-i", + multiple=True, + help="Input directories containing history/epoch_*.json files.", + default=["/mnt/work/huggingface/particleflow/cms/v2.6.0pre1/pyg-cms_20250722_101813_274478"], +) @click.option("--labels", "-l", multiple=True, help="Labels for each input directory. Must be the same number as input-dirs.", default=["v2.6.0pre1"]) @click.option("--output-dir", "-o", type=str, help="Output directory for plots.", default="plots") def main(input_dirs, labels, output_dir): @@ -241,7 +247,7 @@ def main(input_dirs, labels, output_dir): plt.ylabel("Total Valid. Loss [a.u.]") plt.xlabel("Epoch") plt.legend(loc="best") - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (14 TeV)') + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (14 TeV)") plt.savefig(output_path / "loss_comparison.pdf") plt.close() diff --git a/mlpf/plotting/plot_met_validation.py b/mlpf/plotting/plot_met_validation.py index 883a07bab..74a8157c0 100644 --- a/mlpf/plotting/plot_met_validation.py +++ b/mlpf/plotting/plot_met_validation.py @@ -66,7 +66,7 @@ def plot_met_distribution( plt.yscale("log") a0.set_ylim(bottom=1, top=a0.get_ylim()[1] * 1000) - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=a0) + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (13.6 TeV)", ax=a0) a0.text( sample_label_coords[0], sample_label_coords[1], @@ -127,7 +127,7 @@ def met_response_plot( ax = plt.axes() b = np.linspace(0, 5, 101) - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (13.6 TeV)", ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], @@ -325,7 +325,7 @@ def plot_met_response_vs_pu(resp_pf, resp_mlpf, data_pf, data_mlpf, output_dir, ax.set_xlabel("True $N_{PV}$") ax.set_ylabel("MET response resolution (IQR/med.)") ax.set_ylim(0, 1.5) - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (13.6 TeV)", ax=ax) ax.text( kwargs["sample_label_coords"][0], kwargs["sample_label_coords"][1], @@ -511,7 +511,7 @@ def varbins(*args): ax.set_xscale("log") ax.set_ylim(0.0, 4.0) plt.axhline(1.0, color="black", ls="--") - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (13.6 TeV)", ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], plot_sample_name, transform=ax.transAxes, fontsize=sample_label_fontsize, ha="left", va="top" ) @@ -533,7 +533,7 @@ def varbins(*args): ax.legend(fontsize=legend_fontsize, loc=legend_loc_scalereso) ax.set_xscale("log") ax.set_ylim(0.0, 2.0) - mplhep.cms.label(llabel='Simulation', rlabel='Run 3 (13.6 TeV)', ax=ax) + mplhep.cms.label(llabel="Simulation", rlabel="Run 3 (13.6 TeV)", ax=ax) ax.text( sample_label_coords[0], sample_label_coords[1], plot_sample_name, transform=ax.transAxes, fontsize=sample_label_fontsize, ha="left", va="top" ) From f3bded78c343fe8949e04c8cbf507805ead09471 Mon Sep 17 00:00:00 2001 From: Joosep Pata Date: Wed, 14 Jan 2026 13:21:19 +0200 Subject: [PATCH 6/6] fix legend on runtime plot --- notebooks/cms/cmssw-runtimes.ipynb | 31 ++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/notebooks/cms/cmssw-runtimes.ipynb b/notebooks/cms/cmssw-runtimes.ipynb index d34782379..e0fa39d3d 100644 --- a/notebooks/cms/cmssw-runtimes.ipynb +++ b/notebooks/cms/cmssw-runtimes.ipynb @@ -252,26 +252,49 @@ "metadata": {}, "outputs": [], "source": [ + "from matplotlib.lines import Line2D # <--- 1. Import this\n", + "\n", "fig = plt.figure()\n", "ax = plt.axes()\n", "b = np.linspace(0, 0.5, 81)\n", "\n", + "# --- PF Plotting ---\n", "x = (times_pf_event_good[\"PFBlockProducer\"]+times_pf_event_good[\"PFProducer\"]).drop(index=bad_evs.index)\n", "m = np.mean(x)\n", + "# Save the label to a variable for later use\n", + "pf_label = \"PF, $\\\\bar{t}^{CPU}_{ev}$=\" +\"{:.2f}s\".format(m)\n", + "\n", "plt.hist(\n", " x,\n", - " bins=b, histtype=\"step\", lw=2, label=\"PF, $\\\\bar{t}^{CPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=pf_linestyle, color=pf_color\n", - ");\n", + " bins=b, histtype=\"step\", lw=2, ls=pf_linestyle, color=pf_color\n", + " # label=pf_label <--- No longer strictly needed inside hist()\n", + ")\n", "\n", + "# --- MLPF Plotting ---\n", "x = times_mlpf_event_good[\"MLPFProducer\"].drop(index=bad_evs.index)\n", "m = np.mean(x)\n", + "# Save the label to a variable\n", + "mlpf_label = \"MLPF, $\\\\bar{t}^{GPU}_{ev}$=\" +\"{:.2f}s\".format(m)\n", + "\n", "plt.hist(\n", - " x, bins=b, histtype=\"step\", lw=2, label=\"MLPF, $\\\\bar{t}^{GPU}_{ev}$=\" +\"{:.2f}s\".format(m), ls=mlpf_linestyle, color=mlpf_color\n", + " x, bins=b, histtype=\"step\", lw=2, ls=mlpf_linestyle, color=mlpf_color\n", ")\n", + "\n", + "# ... (Your text labels and axis setup remain the same) ...\n", "cms_label(ax)\n", "sample_label(ax, \"cms_pf_qcd\", x=sample_label_coords[0], y=sample_label_coords[1], fontsize=sample_label_fontsize)\n", "plt.text(sample_label_coords[0], 0.74, \"CMSSW_15_0_5\\nnative ONNXRuntime\\n8 jobs, 8 threads per job\", fontsize=legend_fontsize, transform=ax.transAxes)\n", - "plt.legend(loc=(0.38, 0.48), fontsize=legend_fontsize)\n", + "\n", + "# --- 2. Custom Legend with Lines ---\n", + "# Create lines that match your histograms\n", + "custom_lines = [\n", + " Line2D([0], [0], color=pf_color, lw=2, ls=pf_linestyle),\n", + " Line2D([0], [0], color=mlpf_color, lw=2, ls=mlpf_linestyle)\n", + "]\n", + "\n", + "# Pass the custom lines and the saved labels to the legend\n", + "plt.legend(custom_lines, [pf_label, mlpf_label], loc=(0.38, 0.48), fontsize=legend_fontsize)\n", + "\n", "plt.xlabel(\"Runtime per event [s]\")\n", "plt.ylabel(\"Counts\")\n", "plt.yscale(\"log\")\n",