def test_collection_2D(): coll = hist.HistogramCollection(dimensions=[pileup, multi], histogram_factory=dummy_factory) coll[-3, 4].fill(6) coll[11, 105].fill(49) assert_equal(coll[-20, 2].value, [6]) assert_equal(coll[13, 108].value, [49])
def test_find_bins(): coll = hist.HistogramCollection(dimensions=[pileup], histogram_factory=dummy_factory) assert_equal(coll._find_bins(-20), [(binning.Base.underflow, )]) assert_equal(coll._find_bins(13), [(1, )]) assert_equal(coll._find_bins(47), [(4, )]) assert_equal(coll._find_bins(9999), [(binning.Base.overflow, )])
def test_coll1D_root_Hist1D(): histogram_factory = HistFactory("Hist1D", 10, 0, 5) coll = hist.HistogramCollection(dimensions=[pileup], histogram_factory=histogram_factory) coll[13].fill(1) coll[11].fill(2) integral = sum([h.Integral() for h in coll[12]]) assert_equal(integral, 2)
def test_collection_1D(): coll = hist.HistogramCollection(dimensions=[pileup], histogram_factory=dummy_factory) coll[-3].fill(6) coll[11].fill(2) coll[42].fill(42) coll[10044].fill(49) assert_equal(coll[-20].value, [6]) assert_equal(coll[13].value, [2]) assert_equal(coll[47].value, [42]) assert_equal(coll[9999].value, [49])
def test_iteration_2D(): coll = hist.HistogramCollection(dimensions=[pileup, multi], histogram_factory=dummy_factory) all_bins = [] for i_first in coll: rows = [] for i_second in coll.get_bin_contents([i_first]): rows.append([i_first, i_second]) coll.get_bin_contents([i_first, i_second]).fill(1) all_bins.append(rows) all_bins = np.array(all_bins) total = 0 for i_first in coll: for i_second in coll.get_bin_contents([i_first]): total += coll.get_bin_contents([i_first, i_second]).value assert_equal(all_bins.shape, (len(pileup), len(multi), 2)) assert_equal(total, len(pileup) * len(multi)) assert_equal(coll[3, 13].value, [1])