72 def __call__(self, root_file):
73 hist = find_histo(root_file, self.input)
74 if not hist:
75 if crash_on_error:
76 raise RuntimeError(f"Histogram '{self.input}' not found for rebinning.")
77 else:
78 logging.error(f"Histogram '{self.input}' not found for rebinning.")
79 return
80
82 *dir_parts, output_name = path_parts
83 directory_path = "/".join(dir_parts)
84 ensure_directory_exists(root_file, directory_path)
85 root_file.cd(directory_path)
86
87 if hist.GetDimension() == 1:
88 rebinned = hist.Rebin(self.rebin_factor, output_name)
89 rebinned.Write(output_name, ROOT.TObject.kOverwrite)
90 logging.info(f"Rebinned 1D histogram and saved as '{output_name}' in '{directory_path}'.")
91 elif hist.GetDimension() == 2:
92 hist.RebinX(self.rebin_factor)
93 hist.RebinY(self.rebin_factor)
94 hist.SetName(output_name)
95 hist.Write(output_name, ROOT.TObject.kOverwrite)
96 logging.info(f"Rebinned 2D histogram and saved as '{output_name}' in '{directory_path}'.")
97 if self.delete_original:
98 find_histo(root_file, self.input, should_delete=True)
99
std::vector< std::string > split(const std::string &s, const std::string &t=":")