Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved control in high-level interface for auxiliary plots #277

Merged
merged 3 commits into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions puma/hlplots/aux_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -227,6 +228,7 @@ def plot_var_vtx_perf(
xlabel: str = r"$p_{T}$ [GeV]",
perf_var: str = "pt",
incl_vertexing: bool = False,
vertex_match_requirement: dict | None = None,
**kwargs,
):
if vtx_flavours is None and no_vtx_flavours is None:
Expand All @@ -240,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
Expand All @@ -253,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)
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.")
Expand All @@ -270,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}$
Expand All @@ -280,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}$
Expand All @@ -290,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}$
Expand All @@ -300,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,
)

Expand Down
4 changes: 2 additions & 2 deletions puma/utils/vertexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading