From 4b966ebb2240765986e99d7a8913be23954d137b Mon Sep 17 00:00:00 2001 From: Nikita I Pond Date: Fri, 9 Aug 2024 12:58:19 +0100 Subject: [PATCH 1/2] slightly more control over vert effs --- puma/hlplots/aux_results.py | 3 ++- puma/utils/vertexing.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/puma/hlplots/aux_results.py b/puma/hlplots/aux_results.py index 17ff85e70..fbec91242 100644 --- a/puma/hlplots/aux_results.py +++ b/puma/hlplots/aux_results.py @@ -226,6 +226,7 @@ def plot_var_vtx_perf( xlabel: str = r"$p_{T}$ [GeV]", perf_var: str = "pt", incl_vertexing: bool = False, + vertex_match_requirement={'eff_req' : 0.65, 'purity_req' : 0.5}, **kwargs, ): if vtx_flavours is None and no_vtx_flavours is None: @@ -252,7 +253,7 @@ def plot_var_vtx_perf( # get cleaned vertex indices and calculate vertexing metrics truth_indices, reco_indices = tagger.vertex_indices(incl_vertexing=incl_vertexing) - vtx_metrics[tagger.name] = calculate_vertex_metrics(reco_indices, truth_indices) + vtx_metrics[tagger.name] = calculate_vertex_metrics(reco_indices, truth_indices, **vertex_match_requirement) if not vtx_metrics: raise ValueError("No taggers with vertexing aux task added.") diff --git a/puma/utils/vertexing.py b/puma/utils/vertexing.py index 08601c508..b94a09848 100644 --- a/puma/utils/vertexing.py +++ b/puma/utils/vertexing.py @@ -130,8 +130,8 @@ def associate_vertices(test_vertices, ref_vertices, eff_req, purity_req): associations[common_tracks == 0] = False # remove leftover pairs with zero matches # enforce purity and efficiency requirements - eff_cut = common_tracks * inv_ref_size > eff_req - purity_cut = common_tracks * inv_test_size > purity_req + eff_cut = common_tracks * inv_ref_size >= eff_req + purity_cut = common_tracks * inv_test_size >= purity_req associations = np.logical_and.reduce((associations, eff_cut, purity_cut)) return associations, common_tracks From 13a80181d457379bb385367956646fefa5bfc741 Mon Sep 17 00:00:00 2001 From: Nikita I Pond Date: Sat, 17 Aug 2024 10:16:33 +0100 Subject: [PATCH 2/2] more informsative info string for vertex plots --- puma/hlplots/aux_results.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/puma/hlplots/aux_results.py b/puma/hlplots/aux_results.py index d8b05db28..8aa3030cf 100644 --- a/puma/hlplots/aux_results.py +++ b/puma/hlplots/aux_results.py @@ -38,6 +38,7 @@ class AuxResults: def __post_init__(self): if isinstance(self.output_dir, str): self.output_dir = Path(self.output_dir) + self.output_dir.mkdir(parents=True, exist_ok=True) if isinstance(self.perf_vars, str): self.perf_vars = [self.perf_vars] if self.atlas_second_tag is not None and self.atlas_third_tag is not None: @@ -227,7 +228,7 @@ def plot_var_vtx_perf( xlabel: str = r"$p_{T}$ [GeV]", perf_var: str = "pt", incl_vertexing: bool = False, - vertex_match_requirement={'eff_req' : 0.65, 'purity_req' : 0.5}, + vertex_match_requirement: dict | None = None, **kwargs, ): if vtx_flavours is None and no_vtx_flavours is None: @@ -241,6 +242,12 @@ def plot_var_vtx_perf( if incl_vertexing: suffix = "incl" if not suffix else f"{suffix}_incl" + + if vertex_match_requirement is None: + vertex_match_requirement = {"eff_req": 0.65, "purity_req": 0.5} + eff_req = round(vertex_match_requirement["eff_req"] * 100, 1) + purity_req = round(vertex_match_requirement["purity_req"] * 100, 1) + vtx_match_str = rf"Recall $\geq {eff_req}%$, Purity $\geq {purity_req}%$" vtx_string = "\nInclusive vertexing" if incl_vertexing else "\nExclusive vertexing" atlas_second_tag = self.atlas_second_tag if self.atlas_second_tag else "" atlas_second_tag += vtx_string @@ -254,7 +261,9 @@ def plot_var_vtx_perf( # get cleaned vertex indices and calculate vertexing metrics truth_indices, reco_indices = tagger.vertex_indices(incl_vertexing=incl_vertexing) - vtx_metrics[tagger.name] = calculate_vertex_metrics(reco_indices, truth_indices, **vertex_match_requirement) + vtx_metrics[tagger.name] = calculate_vertex_metrics( + reco_indices, truth_indices, **vertex_match_requirement + ) if not vtx_metrics: raise ValueError("No taggers with vertexing aux task added.") @@ -271,7 +280,7 @@ def plot_var_vtx_perf( xlabel=xlabel, logy=False, atlas_first_tag=self.atlas_first_tag, - atlas_second_tag=atlas_second_tag + f", {flav.label}", + atlas_second_tag=atlas_second_tag + f", {flav.label}\n{vtx_match_str}", y_scale=1.4, ) # $n_{vtx}^{match}/n_{vtx}^{reco}$ @@ -281,7 +290,7 @@ def plot_var_vtx_perf( xlabel=xlabel, logy=False, atlas_first_tag=self.atlas_first_tag, - atlas_second_tag=atlas_second_tag + f", {flav.label}", + atlas_second_tag=atlas_second_tag + f", {flav.label}\n{vtx_match_str}", y_scale=1.4, ) # $n_{trk}^{match}/n_{trk}^{true}$ @@ -291,7 +300,7 @@ def plot_var_vtx_perf( xlabel=xlabel, logy=False, atlas_first_tag=self.atlas_first_tag, - atlas_second_tag=atlas_second_tag + f", {flav.label}", + atlas_second_tag=atlas_second_tag + f", {flav.label}\n{vtx_match_str}", y_scale=1.4, ) # $n_{trk}^{match}/n_{trk}^{reco}$ @@ -301,7 +310,7 @@ def plot_var_vtx_perf( xlabel=xlabel, logy=False, atlas_first_tag=self.atlas_first_tag, - atlas_second_tag=atlas_second_tag + f", {flav.label}", + atlas_second_tag=atlas_second_tag + f", {flav.label}\n{vtx_match_str}", y_scale=1.4, )