418 def __call__(self, root_file):
419 histo1 = find_histo(root_file, self.histo1)
420 histo2 = find_histo(root_file, self.histo2)
421 if not histo1 or not histo2:
422 if crash_on_error:
423 raise RuntimeError(f"Missing histograms: {self.histo1} or {self.histo2}")
424 else:
425 logging.error(f"Missing histograms: {self.histo1} or {self.histo2}")
426 return
427
428 path_parts = self.output.
strip(
"/").
split(
"/")
429 *dir_path, output_name = path_parts
430 directory_path = "/".join(dir_path)
431 summed = histo1.Clone(output_name)
432 summed.Add(histo2)
433 ensure_directory_exists(root_file, directory_path)
434 root_file.cd(directory_path)
435 summed.Write(output_name, ROOT.TObject.kOverwrite)
436 logging.info(f"Saved added histogram '{output_name}' in '{directory_path}'.")
437 if self.delete_inputs:
438
439 find_histo(root_file, self.histo1, should_delete=True)
440 find_histo(root_file, self.histo2, should_delete=True)
441
std::vector< std::string > split(const std::string &s, const std::string &t=":")