-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
199 additions
and
16 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 |
---|---|---|
@@ -1,3 +1,22 @@ | ||
from .read import read | ||
from .histo1d_v2 import GROGU_HISTO1D_V2 as Histo1D_v2 | ||
|
||
|
||
__all__ = ["read"] | ||
|
||
|
||
# TODO same function for Hist1D in babyyoda.Histo1D_v2, but how pick backend? probably just yoda if yoda available | ||
def Histo1D(nbins: int, start: float, end: float, title=None, **kwargs): | ||
return Histo1D_v2( | ||
d_bins=[ | ||
Histo1D_v2.Bin( | ||
d_xmin=start + i * (end - start) / nbins, | ||
d_xmax=start + (i + 1) * (end - start) / nbins, | ||
) | ||
for i in range(nbins) | ||
], | ||
d_overflow=Histo1D_v2.Bin(), | ||
d_underflow=Histo1D_v2.Bin(), | ||
d_title=title, | ||
**kwargs, | ||
) |
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,49 @@ | ||
from babyyoda.Histo1D_v2 import HISTO1D_V2 | ||
import babyyoda.grogu as yoda | ||
from babyyoda.util import loc, overflow, underflow | ||
|
||
|
||
def get_histo1d(): | ||
h = yoda.Histo1D(10, 0, 10, title="test") | ||
for i in range(12): | ||
for _ in range(i): | ||
h.fill(i) | ||
h.underflow().fill(-1) | ||
h.overflow().fill(10) | ||
return HISTO1D_V2(h) | ||
|
||
|
||
def test_setting_index(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[1] = yuhi1d[2] | ||
yuhi1d[7] = yuhi1d[8] | ||
yuhi1d[3] = yuhi1d[5] | ||
assert yuhi1d[1].sumW() == yuhi1d[2].sumW() | ||
assert yuhi1d[7].sumW2() == yuhi1d[8].sumW2() | ||
assert yuhi1d[3].numEntries() == yuhi1d[5].numEntries() | ||
|
||
|
||
def test_setting_loc(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[loc(1)] = yuhi1d[2] | ||
yuhi1d[loc(7)] = yuhi1d[8] | ||
yuhi1d[loc(3)] = yuhi1d[5] | ||
assert yuhi1d[1].sumW() == yuhi1d[2].sumW() | ||
assert yuhi1d[7].sumW2() == yuhi1d[8].sumW2() | ||
assert yuhi1d[3].numEntries() == yuhi1d[5].numEntries() | ||
|
||
|
||
def test_setting_underflow(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[underflow] = yuhi1d[overflow] | ||
assert yuhi1d[underflow].sumW() == yuhi1d[overflow].sumW() | ||
assert yuhi1d[underflow].sumW2() == yuhi1d[overflow].sumW2() | ||
assert yuhi1d[underflow].numEntries() == yuhi1d[overflow].numEntries() | ||
|
||
|
||
def test_setting_overflow(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[overflow] = yuhi1d[1] | ||
assert yuhi1d[overflow].sumW() == yuhi1d[1].sumW() | ||
assert yuhi1d[overflow].sumW2() == yuhi1d[1].sumW2() | ||
assert yuhi1d[overflow].numEntries() == yuhi1d[1].numEntries() |
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,50 @@ | ||
from babyyoda.Histo1D_v2 import HISTO1D_V2 | ||
import yoda | ||
from babyyoda.util import loc, overflow, underflow | ||
|
||
|
||
def get_histo1d(): | ||
h = yoda.Histo1D(10, 0, 10, title="test") | ||
for i in range(12): | ||
for _ in range(i): | ||
h.fill(i) | ||
h = HISTO1D_V2(h) | ||
h.underflow().fill(-1) | ||
h.overflow().fill(10) | ||
return h | ||
|
||
|
||
def test_setting_index(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[1] = yuhi1d[2] | ||
yuhi1d[7] = yuhi1d[8] | ||
yuhi1d[3] = yuhi1d[5] | ||
assert yuhi1d[1].sumW() == yuhi1d[2].sumW() | ||
assert yuhi1d[7].sumW2() == yuhi1d[8].sumW2() | ||
assert yuhi1d[3].numEntries() == yuhi1d[5].numEntries() | ||
|
||
|
||
def test_setting_loc(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[loc(1)] = yuhi1d[2] | ||
yuhi1d[loc(7)] = yuhi1d[8] | ||
yuhi1d[loc(3)] = yuhi1d[5] | ||
assert yuhi1d[1].sumW() == yuhi1d[2].sumW() | ||
assert yuhi1d[7].sumW2() == yuhi1d[8].sumW2() | ||
assert yuhi1d[3].numEntries() == yuhi1d[5].numEntries() | ||
|
||
|
||
def test_setting_underflow(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[underflow] = yuhi1d[overflow] | ||
assert yuhi1d[underflow].sumW() == yuhi1d[overflow].sumW() | ||
assert yuhi1d[underflow].sumW2() == yuhi1d[overflow].sumW2() | ||
assert yuhi1d[underflow].numEntries() == yuhi1d[overflow].numEntries() | ||
|
||
|
||
def test_setting_overflow(): | ||
yuhi1d = get_histo1d() | ||
yuhi1d[overflow] = yuhi1d[1] | ||
assert yuhi1d[overflow].sumW() == yuhi1d[1].sumW() | ||
assert yuhi1d[overflow].sumW2() == yuhi1d[1].sumW2() | ||
assert yuhi1d[overflow].numEntries() == yuhi1d[1].numEntries() |