52def check(causes, result):
53 result["root_output_file"] = FILENAME
54
55 if not os.path.exists(FILENAME):
56 causes.append("missing histogram file")
57 return False
58
59 try:
60 import ROOT
61
62 f = ROOT.TFile.Open(FILENAME)
63
64
65 histos = []
66 for i in range(1, 4):
67 h = f.Get(f"Alg/h{i}")
68 if not h:
69 k = f.GetKey(f"Alg/h{i}")
70 if k:
71 h = k.ReadObj()
72
73 assert h, f"missing histogram Alg/h{i}"
74 histos.append(h)
75
76 h1, h2, h3 = histos
77
78 value = 0.0
79 expected = defaultdict(dict)
80 found = defaultdict(dict)
81 for x in [i - 0.5 for i in range(12)]:
82 value += 1
83 expected["h1"][x] = value
84 found["h1"][x] = h1.GetBinContent(h1.FindBin(x))
85 for y in [i - 0.5 for i in range(12)]:
86 value += 1
87 expected["h2"][(x, y)] = value
88 found["h2"][(x, y)] = h2.GetBinContent(h2.FindBin(x, y))
89 for z in [i - 0.5 for i in range(12)]:
90 value += 1
91 expected["h3"][(x, y, z)] = value
92 found["h3"][(x, y, z)] = h3.GetBinContent(h3.FindBin(x, y, z))
93
94
95 t = TestCase()
96 diffs = {}
97 for name in expected:
98 try:
99 t.assertEqual(expected[name], found[name])
100 except AssertionError as err:
101 diffs[name] = str(err).splitlines()[0]
102
103 if diffs:
104 causes.append("histograms content")
105 for name in diffs:
106 result[f"{name}_diff"] = diffs[name]
107
108 except AssertionError as err:
109 causes.append(str(err))
110 return False
111
112 except Exception:
113 causes.append("failure reading histogram file")
114 result["python_exception"] = result.Quote(format_exc())
115 return False
116
117 return True