53def main(file1_path: str, file2_path: str, use_ks_test: bool, significance_threshold: float) -> bool:
54 """Compare histograms in two ROOT files.
55
56 Returns True if every histogram is present in both files and identical,
57 False otherwise (so the caller can propagate a non-zero exit status).
58 """
59 file1 = ROOT.TFile.Open(file1_path)
60 file2 = ROOT.TFile.Open(file2_path)
61 all_match = True
62
63 histograms1 = {}
64 for key in file1.GetListOfKeys():
65 cls = ROOT.TClass.GetClass(key.GetClassName())
66 if cls and cls.InheritsFrom("TH1"):
67 histograms1[key.GetName()] = file1.Get(key.GetName())
68
69 histograms2 = {}
70 for key in file2.GetListOfKeys():
71 cls = ROOT.TClass.GetClass(key.GetClassName())
72 if cls and cls.InheritsFrom("TH1"):
73 histograms2[key.GetName()] = file2.Get(key.GetName())
74
75 for hist_name in histograms1:
76 if hist_name in histograms2:
77 if not compare_histograms(
78 histograms1[hist_name], histograms2[hist_name], use_ks_test, significance_threshold
79 ):
80 all_match = False
81 else:
82 print(f"Histogram '{hist_name}' not found in file2.")
83 all_match = False
84
85 for hist_name in histograms2:
86 if hist_name not in histograms1:
87 print(f"Histogram '{hist_name}' not found in file1.")
88 all_match = False
89
90 return all_match
91
92