Skip to content
Snippets Groups Projects
Commit d4f3cf9f authored by Felix Metzner's avatar Felix Metzner
Browse files

Minor style changes to shape sys evaluation plot.

parent ffed379a
Branches
No related tags found
No related merge requests found
......@@ -21,8 +21,15 @@ from rdstar.utilities.logging import log_to_default
from rdstar.offline_analysis.fitting.dedicated_fit_approach.dedicated_sys_handler import SystematicsInfo
from rdstar.offline_analysis.fitting.dedicated_fit_approach.fit_result_container import RDStarFitResultContainer
from rdstar.offline_analysis.fitting.dedicated_fit_approach.fit_setups.fit_setup_utilities import FitSetupTriplet
from rdstar.offline_analysis.fitting.dedicated_fit_approach.systematics_manager.shape_sys_evaluater import FitSetupBinningPerRecoChInfo
from rdstar.offline_analysis.fitting.dedicated_fit_approach.fit_info_container import ComponentInfo, FitSetupInfoContainer, FitObservableInfo, RecoChannelInfo
from rdstar.offline_analysis.fitting.dedicated_fit_approach.systematics_manager.shape_sys_evaluater import (
FitSetupBinningPerRecoChInfo,
)
from rdstar.offline_analysis.fitting.dedicated_fit_approach.fit_info_container import (
ComponentInfo,
FitSetupInfoContainer,
FitObservableInfo,
RecoChannelInfo,
)
__all__ = [
......@@ -157,6 +164,7 @@ class NuisancePullPlotter:
# region systematics shape plotter
@dataclass(frozen=True)
class ShapePlotInfoContainer:
name: str
......@@ -188,12 +196,11 @@ class ShapePlotInfoContainer:
@property
def relative_stat_error(self) -> np.ndarray:
norm: np.ndarray = np.where(
self.normed_base_shape > 0,
self.normed_base_shape,
np.ones_like(self.normed_base_shape),
)
# norm: np.ndarray = np.where(
# self.normed_base_shape > 0,
# self.normed_base_shape,
# np.ones_like(self.normed_base_shape),
# )
return np.sqrt(self.pure_bin_counts)
......@@ -312,7 +319,8 @@ class SystematicsShapePlotter:
(
(rel_err * _2d_normed_base_shape).sum(axis=1),
(rel_err * _2d_normed_base_shape).sum(axis=0),
) for rel_err in _2d_relative_shape_error_splits
)
for rel_err in _2d_relative_shape_error_splits
)
sum_of_2d_relative_shape_error_splits: np.ndarray = np.sum(_2d_relative_shape_error_splits, axis=0)
......@@ -440,21 +448,23 @@ class SystematicsShapePlotter:
final_target_dir_path: PathType = os.path.join(target_dir_path, spec_sys_shape_info.observable.col_name)
os.makedirs(final_target_dir_path, exist_ok=True)
fn_subset_str: str = "All" if spec_sys_shape_info.subset_index == -1 else f"SubSet{spec_sys_shape_info.subset_index}"
fn_subset_str: str = (
"All" if spec_sys_shape_info.subset_index == -1 else f"SubSet{spec_sys_shape_info.subset_index}"
)
plot_file_name: str = f"{self.plot_name_prefix}"
plot_file_name += f"_{spec_sys_shape_info.observable.col_name}"
plot_file_name += f"_comp{spec_sys_shape_info.component_info.name}_ch{spec_sys_shape_info.reco_ch_info.name}"
plot_file_name += f"_{spec_sys_shape_info.name}_{fn_subset_str}"
fig, axes = plt.subplots( # type: FigureType, Sequence[AxesType]
fig, axes = plt.subplots(
nrows=2,
ncols=1,
figsize=self.fig_size,
dpi=300,
sharex="all",
gridspec_kw={"height_ratios": [self.height_ratio[0], self.height_ratio[1]]},
)
) # type: FigureType, Sequence[AxesType]
assert len(axes) == 2, len(axes)
ax1: AxesType = axes[0]
......@@ -476,16 +486,18 @@ class SystematicsShapePlotter:
norm_bin_count: np.ndarray = spec_sys_shape_info.normed_base_shape
u_bin_shape_uncert: np.ndarray = spec_sys_shape_info.normed_base_shape * spec_sys_shape_info.relative_shape_error
d_bin_shape_uncert: np.ndarray = spec_sys_shape_info.normed_base_shape * (-1.0 * spec_sys_shape_info.relative_shape_error)
d_bin_shape_uncert: np.ndarray = spec_sys_shape_info.normed_base_shape * (
-1.0 * spec_sys_shape_info.relative_shape_error
)
bin_stat_uncert: np.ndarray = spec_sys_shape_info.relative_stat_error
assert np.all(u_bin_shape_uncert * d_bin_shape_uncert <= 0.0), (
np.sum(u_bin_shape_uncert * d_bin_shape_uncert > 0.0),
u_bin_shape_uncert * d_bin_shape_uncert,
np.sum(u_bin_shape_uncert * d_bin_shape_uncert > 0.0),
u_bin_shape_uncert * d_bin_shape_uncert,
)
bin_shape_uncert_height: np.ndarray = np.abs(u_bin_shape_uncert) + np.abs(d_bin_shape_uncert)
# bin_shape_uncert_height: np.ndarray = np.abs(u_bin_shape_uncert) + np.abs(d_bin_shape_uncert)
bin_shape_uncert_lower_value: np.ndarray = np.minimum(u_bin_shape_uncert, d_bin_shape_uncert)
assert np.all(bin_shape_uncert_lower_value <= 0.0), (
np.sum(bin_shape_uncert_lower_value > 0.0),
......@@ -520,7 +532,8 @@ class SystematicsShapePlotter:
x=bin_mids,
height=scale_factor * np.abs(u_bin_shape_uncert),
width=bin_widths,
bottom=norm_bin_count + scale_factor * np.where(u_bin_shape_uncert < 0., u_bin_shape_uncert, np.zeros_like(u_bin_shape_uncert)),
bottom=norm_bin_count
+ scale_factor * np.where(u_bin_shape_uncert < 0.0, u_bin_shape_uncert, np.zeros_like(u_bin_shape_uncert)),
color=KITColors.kit_black,
hatch="//////",
fill=False,
......@@ -531,7 +544,8 @@ class SystematicsShapePlotter:
x=bin_mids,
height=scale_factor * np.abs(d_bin_shape_uncert),
width=bin_widths,
bottom=norm_bin_count + scale_factor * np.where(d_bin_shape_uncert < 0., d_bin_shape_uncert, np.zeros_like(d_bin_shape_uncert)),
bottom=norm_bin_count
+ scale_factor * np.where(d_bin_shape_uncert < 0.0, d_bin_shape_uncert, np.zeros_like(d_bin_shape_uncert)),
color=KITColors.kit_black,
hatch="\\\\\\\\\\\\",
fill=False,
......@@ -545,11 +559,11 @@ class SystematicsShapePlotter:
height=2 * bin_stat_uncert,
width=bin_widths,
bottom=-1.0 * bin_stat_uncert,
color=KITColors.dark_grey,
alpha=0.5,
color=KITColors.grey,
alpha=0.4,
fill=True,
lw=0,
label=f"stat.",
label="stat.",
)
ax2.hist(
x=[bin_mids, bin_mids],
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment