Skip to content

Commit 3e92f5b

Browse files
committed
[Python][UHI] Add test for infinite upper edge histograms
1 parent 60b6aef commit 3e92f5b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

bindings/pyroot/pythonizations/test/uhi_indexing.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Tests to verify that TH1 and derived histograms conform to the UHI Indexing interfaces (setting, accessing and slicing).
33
"""
44

5+
import numpy as np
56
import pytest
67
import ROOT
78
from ROOT._pythonization._uhi import _get_axis, _get_processed_slices, _overflow, _shape, _underflow
@@ -326,5 +327,35 @@ def test_list_iter(self, hist_setup):
326327
assert list(hist_setup) == expected.flatten().tolist()
327328

328329

330+
class TestInfiniteEdges:
331+
def setup_method(self):
332+
# create a 2D histogram with an infinite upper edge on the Y axis
333+
xedges = np.array([0.0, 1.0, 2.0], dtype="float64")
334+
yedges = np.array([0.0, 1.0, 2.0, np.inf], dtype="float64")
335+
self.h_inf = ROOT.TH2D("h_inf", "h_inf", len(xedges) - 1, xedges, len(yedges) - 1, yedges)
336+
337+
for i in range(1, self.h_inf.GetNbinsX() + 1):
338+
for j in range(1, self.h_inf.GetNbinsY() + 1):
339+
self.h_inf.SetBinContent(i, j, 10 * i + j)
340+
341+
def test_uhi_projection_preserves_content(self):
342+
"""check that UHI projection behaves like standard projection"""
343+
# projection on X axis
344+
proj_x_ref = self.h_inf.ProjectionX()
345+
proj_x_uhi = self.h_inf[:, ROOT.uhi.sum]
346+
ref_values = proj_x_ref.values()
347+
uhi_values = proj_x_uhi.values()
348+
349+
assert np.allclose(uhi_values, ref_values)
350+
351+
# projection on Y axis
352+
proj_y_ref = self.h_inf.ProjectionY()
353+
proj_y_uhi = self.h_inf[ROOT.uhi.sum, :]
354+
ref_values = proj_y_ref.values()
355+
uhi_values = proj_y_uhi.values()
356+
357+
assert np.allclose(uhi_values, ref_values)
358+
359+
329360
if __name__ == "__main__":
330361
raise SystemExit(pytest.main(args=[__file__]))

0 commit comments

Comments
 (0)