pipeline.utils.plotutils package#

A package that defines utilies for plotting.

pipeline.utils.plotutils.performance_mpl module#

Plot general performance metrics using matplotlib only.

pipeline.utils.plotutils.performance_mpl.get_auto_output_dir(path_or_config=None, step=None)[source]#
Return type:

Optional[str]

pipeline.utils.plotutils.performance_mpl.plot_edge_performance(model, edge_score_cuts, path_or_config=None, identifier=None, max_n_events=None, output_path=None, lhcb=False, edge_partitions=None)[source]#

Plot the triplet selection efficiency and purity.

Parameters:
  • edge_score_cuts (Sequence[float]) – Sequence of miminal edge scores to try

  • path_or_config (UnionType[str, dict, None]) – Configuration of the current pipeline

  • identifier (Optional[str]) – string to put in the name of the file

  • max_nevents – Maximal number of events to use for this evaluation

  • output_path (Optional[str]) – path where to save the plot

  • lhcb (bool) – whether to add the LHCb Simulation text

Returns:

Dictionary of pandas dataframes that provides the efficiency and purity as a function of the edge score cut.

pipeline.utils.plotutils.performance_mpl.plot_loss(metrics, output_path=None, path_or_config=None, step=None, lhcb=False)[source]#

Plot the training and validation loss on the same plot.

Parameters:
  • metrics – dataframe of metric values computed during training. It must contain the two columns train_loss and val_loss

  • path_or_config (UnionType[str, dict, None]) – pipeline configuration

  • step (Optional[str]) – Name of the step (e.g., gnn, embedding). If not given, and output_path is not given, the plot is not saved

  • lhcb (bool) – whether to add “LHCb Simulation” to the plot.

Return type:

Tuple[Figure, Axes]

Returns:

Figure and Axes of the plot

pipeline.utils.plotutils.performance_mpl.plot_metric_epochs(metric_name, metrics, metric_label=None, ax=None, marker='.', lhcb=False, path_or_config=None, step=None, output_path=None, **kwargs)[source]#

Plot a metric as a function of the epoch number

Parameters:
  • metric_name (str) – name of the metric to plot in the dataframe of metrics

  • metrics (pd.DataFrame) – dataframe of metric values computed during training. It must contain the two columns train_loss and val_loss

  • name – Name of the step (e.g., gnn, embedding). If not given, the plot is not saved.

  • metric_label (str | None) – Label of the metric. Used in the y-axis

  • marker (str) – Marker format used in the plot

  • ax (Axes | None) – Matplotlib Axes to plot on.

  • **kwargs – Other arguments passed to matplotlib.axes.Axes.plot()

Return type:

Tuple[Figure | None, Axes]

Returns:

Figure and Axes of the plot

pipeline.utils.plotutils.performance_mpl.plot_triplet_performance(model, edge_score_cut, triplet_score_cuts, path_or_config=None, identifier=None, max_n_events=None, output_path=None, lhcb=False)[source]#

Plot the triplet selection efficiency and purity.

Parameters:
  • edge_score_cut (float) – minimal edge score to require to build the triplets

  • triplet_score_cuts (Sequence[float]) – Sequence of miminal triplet scores to try

  • path_or_config (UnionType[str, dict, None]) – Configuration of the current pipeline

  • identifier (Optional[str]) – string to put in the name of the file

  • max_nevents – Maximal number of events to use for this evaluation

  • output_path (Optional[str]) – Path where to save the plot

  • lhcb (bool) – whether to add the LHCb Simulation text

Returns:

Dictionary of pandas dataframes that provides the efficiency and purity as a function of the triplet score cut.

pipeline.utils.plotutils.plotconfig module#

A module that defines common configurations for the plots.

pipeline.utils.plotutils.plotconfig.column_labels = {'distance_to_line': 'Distance to line [mm]', 'distance_to_z_axis': 'Distance to the $z$-axis [mm]', 'eta': '$\\eta$', 'n_repeated_planes': '\\# hits in same plane', 'n_shared_hits': '\\# shared hits', 'n_skipped_planes': '\\# skipped planes', 'n_unique_planes': '\\# unique planes', 'nhits_velo': '\\# hits', 'p': '$p$ [MeV/c]', 'phi': '$\\phi$', 'pl': '$\\sqrt{p^2 - p_T^2}$ [MeV/c]', 'pt': '$p_T$ [MeV/c]', 'px': '$p_x$ [MeV/c]', 'py': '$p_y$ [MeV/c]', 'pz': '$p_z$ [MeV/c]', 'quadratic_coeff': 'Quadratic coefficient', 'r_squared': '$R^2$', 'vz': '$v_z$ [mm]', 'xz_angle': 'Angle to $x$-$z$ plane [Degree]', 'yz_angle': 'Angle to $y$-$z$ plane [Degree]'}#

Associates a column name with its label for the plots

pipeline.utils.plotutils.plotconfig.column_ranges = {'distance_to_line': (0.0, 0.15), 'distance_to_z_axis': (0.0, 0.1), 'eta': (2.0, 5.0), 'p': (0, 50000), 'pt': (0, 2000), 'vz': (-200, 650)}#

Associates a column name with its range for the plots

pipeline.utils.plotutils.plotconfig.configure_matplotlib()[source]#

Set up rcParams matplotlib object to configure font, fontsizes, etc.

pipeline.utils.plotutils.plotconfig.partition_to_color = {'test': 'green', 'train': 'blue', 'val': 'purple'}#

Associates a partition name with a color

pipeline.utils.plotutils.plotconfig.partition_to_label = {'test': 'Test', 'train': 'Training', 'val': 'Validation'}#

Associates a partition name with a label

pipeline.utils.plotutils.plotools module#

Define some global utilies for plots.

pipeline.utils.plotutils.plotools.add_text(ax, ha=None, va=None, x=None, y=None, text='LHCb Run 3 Simulation', fontsize=20, **kwargs)[source]#

Add text inside a matplotlib figure.

Parameters:
  • ax (Axes) – matplotlib ax

  • ha (Optional[str]) – Horizontal alignment: left, center or right

  • va (Optional[str]) – vertical alignment: top, center or bottom

  • x (Optional[float]) – Relative position along x

  • y (Optional[float]) – Relative position along y

Return type:

Text

pipeline.utils.plotutils.plotools.get_figs_axes_on_grid(nrows, ncols, same_fig=True, figsize=(8, 6), **kwargs)[source]#
Return type:

Tuple[Figure | npt.NDArray, npt.NDArray]

pipeline.utils.plotutils.plotools.hide_repetitive_labels_in_grid(axes)[source]#
pipeline.utils.plotutils.plotools.pad_on_top(ax, factor=1.09)[source]#

Pad add a figure on its top by a multiplicative factor.

pipeline.utils.plotutils.plotools.save_fig(fig, path, exts=['.pdf', '.png'], bbox_inches='tight', **kwargs)[source]#

Save a figure.

Parameters:
  • fig (Figure) – Matplotlib figure to save

  • path (str) – path where to save the figure

pipeline.utils.plotutils.plotools.set_same_y_lim_for_all_axes(axes, ymin=None, ymax=None)[source]#

Set the same (most extended) y limit for all the axes given as input.

Parameters:
  • axes (Iterable[Axes]) – an iterable of axes

  • ymin (Optional[float]) – Enforced min value of the y-axis

  • ymin – Enforced max value of the y-axis

pipeline.utils.plotutils.tracks module#

A module that contains utilies to plot tracks.

pipeline.utils.plotutils.tracks.plot_tracks(df_hits_particles, df_edges, particle_ids, list_axes=None, lhcb=False)[source]#

Plots tracks given their track IDs.

Parameters:
  • df_hits_particles (DataFrame) – dataframe of hits-particles with columns hit_idx and particle_id, and the coordinates x, y and z

  • df_edges (DataFrame) – dataframe of edges-particles with columns hit_idx_left, hit_idx_right and particle_id

  • particle_ids (Union[_SupportsArray[dtype[Any]], _NestedSequence[_SupportsArray[dtype[Any]]], bool, int, float, complex, str, bytes, _NestedSequence[Union[bool, int, float, complex, str, bytes]]]) – list of particle IDs to plot

  • list_axes (Optional[List[Tuple[str, str]]]) – list of 2-tuples corresponding to the x- and y-axes of each figure.

Return type:

Tuple[Figure, ndarray[Any, dtype[TypeVar(_ScalarType_co, bound= generic, covariant=True)]]]

Returns:

Maplotlib figure and axes.