def _plot_response_matrix_with_ROOT( name: str, x_label: str, y_label: str, output_name: str, hist: Hist, plot_errors_hist: bool, output_info: analysis_objects.PlottingOutputWrapper) -> None: """ Underlying function to actually plot a response matrix with ROOT. Args: name: Name of the histogram. x_label: X axis label. y_label: Y axis label. output_name: Output name of the histogram. hist: The response matrix related 2D hist. errors_hist: True if the hist is the response matrix errors hist. output_info: Output information. Returns: None """ # Setup canvas = ROOT.TCanvas("canvas", "canvas") canvas.SetLogz(True) # Plot the histogram hist.SetTitle(name) hist.GetXaxis().SetTitle(labels.use_label_with_root(x_label)) hist.GetYaxis().SetTitle(labels.use_label_with_root(y_label)) hist.Draw("colz") # Set the final axis ranges. # Z axis min_val = ctypes.c_double(0) max_val = ctypes.c_double(0) hist.GetMinimumAndMaximum(min_val, max_val) # * 1.1 to put it slightly above the max value # min_val doesn't work here, because there are some entries at 0 hist.GetZaxis().SetRangeUser(10e-7, max_val.value * 1.1) # Save output_name += "_ROOT" plot_base.save_plot(output_info, canvas, output_name)
def _calculate_bin_width_scale_factor(hist: Hist, additional_scale_factor: float = 1.0 ) -> float: """ Calculate the bin width scale factor of a histogram. Args: hist: Hist to use for calculating the scale factor. additional_scale_factor: An additional scale factor to include in the calculation. Returns: The bin width scale factor for the hist. """ # The first bin should always exist! bin_width_scale_factor: float = hist.GetXaxis().GetBinWidth(1) # Because of a ROOT quirk, even a TH1* hist has a Y and Z axis, with 1 bin # each. This bin has bin width 1, so it doesn't change anything if we multiply # by that bin width. So we just do it for all histograms. # This has the benefit that we don't need explicit dependence on an imported # ROOT package. bin_width_scale_factor *= hist.GetYaxis().GetBinWidth(1) bin_width_scale_factor *= hist.GetZaxis().GetBinWidth(1) final_scale_factor = additional_scale_factor / bin_width_scale_factor return final_scale_factor