297 def __call__(self, root_file):
298 hist = find_histo(root_file, self.input_hist)
299 if not hist:
300 if crash_on_error:
301 raise RuntimeError(f"Histogram '{self.input_hist}' not found.")
302 else:
303 logging.error(f"Histogram '{self.input_hist}' not found.")
304 return
305
306 b1, b2 = hist.GetYaxis().FindBin(self.bins_x[0]), hist.GetYaxis().FindBin(self.bins_x[1])
307 b3, b4 = hist.GetXaxis().FindBin(self.bins_y[0]), hist.GetXaxis().FindBin(self.bins_y[1])
308
309 path_parts = self.output.
strip(
"/").
split(
"/")
310 *dir_path, output_name = path_parts
311 directory_path = "/".join(dir_path)
312 ensure_directory_exists(root_file, directory_path)
313 root_file.cd(directory_path)
314
315 if self.x_proj:
316 proj_x = hist.ProjectionX(output_name, b1, b2).Clone(output_name)
317 self.project(proj_x, hist.GetXaxis().GetTitle(), "X")
318 if self.y_proj:
319 proj_y = hist.ProjectionY(output_name, b3, b4).Clone(output_name)
320 self.project(proj_y, hist.GetYaxis().GetTitle(), "Y")
321
std::vector< std::string > split(const std::string &s, const std::string &t=":")