|
2 | 2 | Tests to verify that TH1 and derived histograms conform to the UHI Indexing interfaces (setting, accessing and slicing). |
3 | 3 | """ |
4 | 4 |
|
| 5 | +import numpy as np |
5 | 6 | import pytest |
6 | 7 | import ROOT |
7 | 8 | from ROOT._pythonization._uhi import _get_axis, _get_processed_slices, _overflow, _shape, _underflow |
@@ -326,5 +327,35 @@ def test_list_iter(self, hist_setup): |
326 | 327 | assert list(hist_setup) == expected.flatten().tolist() |
327 | 328 |
|
328 | 329 |
|
| 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 | + |
329 | 360 | if __name__ == "__main__": |
330 | 361 | raise SystemExit(pytest.main(args=[__file__])) |
0 commit comments