Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: conversion of ROOT histograms to PlottableHistogram (#27)
- Loading branch information
1 parent
74562b6
commit c2e481e
Showing
5 changed files
with
264 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name: uhi | ||
channels: | ||
- conda-forge | ||
dependencies: | ||
- pip | ||
- pytest | ||
- root | ||
- pytest | ||
- boost-histogram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import numpy as np | ||
import pytest | ||
from pytest import approx | ||
|
||
from uhi.numpy_plottable import ensure_plottable_histogram | ||
|
||
ROOT = pytest.importorskip("ROOT") | ||
|
||
|
||
def test_root_imported() -> None: | ||
assert ROOT.TString("hi") == "hi" | ||
|
||
|
||
def test_root_th1f_convert() -> None: | ||
th = ROOT.TH1F("h1", "h1", 50, -2.5, 2.5) | ||
th.FillRandom("gaus", 10000) | ||
h = ensure_plottable_histogram(th) | ||
assert all(th.GetBinContent(i + 1) == approx(iv) for i, iv in enumerate(h.values())) | ||
assert all( | ||
th.GetBinError(i + 1) == approx(ie) | ||
for i, ie in enumerate(np.sqrt(h.variances())) # type: ignore | ||
) | ||
|
||
|
||
def test_root_th2f_convert() -> None: | ||
th = ROOT.TH2F("h2", "h2", 50, -2.5, 2.5, 50, -2.5, 2.5) | ||
_ = ROOT.TF2("xyg", "xygaus", -2.5, 2.5, -2.5, 2.5) | ||
th.FillRandom("xyg", 10000) | ||
h = ensure_plottable_histogram(th) | ||
assert all( | ||
th.GetBinContent(i + 1, j + 1) == approx(iv) | ||
for i, row in enumerate(h.values()) | ||
for j, iv in enumerate(row) | ||
) | ||
assert all( | ||
th.GetBinError(i + 1, j + 1) == approx(ie) | ||
for i, row in enumerate(np.sqrt(h.variances())) # type: ignore | ||
for j, ie in enumerate(row) | ||
) |