From cb7d2b8bd58c63e0f549edb4bea0cf9a2ad1a1f0 Mon Sep 17 00:00:00 2001
From: Felix Metzner <felixmetzner@outlook.com>
Date: Thu, 18 Apr 2024 20:27:27 +0200
Subject: [PATCH] Further improvements in shape sys effect overview plots.

---
 .../dedicated_fit_approach/plotting_tools.py  | 29 ++++++++++++++-----
 1 file changed, 22 insertions(+), 7 deletions(-)

diff --git a/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py b/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py
index a15643663..f31f51100 100644
--- a/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py
+++ b/rdstar/offline_analysis/fitting/dedicated_fit_approach/plotting_tools.py
@@ -574,9 +574,9 @@ class SystematicsShapePlotter:
             nrows=n_plot_rows,
             ncols=4,
             figsize=fig_size,
-            dpi=300,
-            sharex="none",
-            sharey="row",
+            dpi=200,
+            sharex="all",
+            sharey="all",
         )  # type: FigureType, np.ndarray
 
         assert isinstance(axes, np.ndarray), type(axes)
@@ -594,6 +594,12 @@ class SystematicsShapePlotter:
             shape_error: np.ndarray = sys_shape_info.relative_shape_error[:, comp_id, subset_id]
             stat_error: np.ndarray = sys_shape_info.relative_stat_error[:, comp_id]
 
+            assert len(normed_base_shape.shape) == 1, normed_base_shape.shape
+            assert len(shape_error.shape) == 1, shape_error.shape
+            assert len(stat_error.shape) == 1, stat_error.shape
+            assert normed_base_shape.shape == shape_error.shape, (normed_base_shape.shape, shape_error.shape)
+            assert normed_base_shape.shape == stat_error.shape, (normed_base_shape.shape, stat_error.shape)
+
             _shape_plot_info = SpecificShapePlotInfoEntry(
                 name=f"{sys_shape_info.name}_{subset_id}",
                 latex_str=sys_shape_info.latex_str + f" ({subset_id})",
@@ -615,13 +621,13 @@ class SystematicsShapePlotter:
 
             self._plot_shape_overview(
                 ax=this_axis,
+                axis_position=axis_index_pair,
+                is_last_row=n_plot_rows - 1 == axis_index_pair[0],
                 shape_plot_info=_shape_plot_info,
             )
 
-            # TODO: Fix problem that is caused by histogram starting at y = 0.0
-            # TODO: Add plot title
-            # TODO: Add x axis label
-            # TODO: Add y axis label
+            title_str: str = sys_shape_info.latex_str + " Sys. Shape Effect in " + reco_ch_info.latex_label
+            fig.suptitle(title_str, fontsize=18)
 
             _shape_plot_infos.append(_shape_plot_info)
 
@@ -630,6 +636,8 @@ class SystematicsShapePlotter:
     @staticmethod
     def _plot_shape_overview(
         ax: AxesType,
+        axis_position: Tuple[int, int],
+        is_last_row: bool,
         shape_plot_info: SpecificShapePlotInfoEntry,
     ) -> None:
         assert len(shape_plot_info.shape_error.shape) == 1, shape_plot_info.shape_error.shape
@@ -657,6 +665,13 @@ class SystematicsShapePlotter:
                 histtype="step",
             )
 
+        ax.set_title(shape_plot_info.component_info.latex_label, fontsize=14)
+
+        if axis_position[1] == 0:
+            ax.set_ylabel("Relative Variations", fontsize=12)
+        if is_last_row:
+            ax.set_xlabel("bins", fontsize=12)
+
 
 @dataclass(frozen=True)
 class SpecificShapeProjectionPlotInfoContainer:
-- 
GitLab