def test_fill(): h = Histogram(axis=Axis(100, -50, 50)) weight = 0.25 for i in xrange(-50,50) : h.fill(i+0.5, weight) assert h.entries() == 100 assert h.integral() == 100*weight
def test_empty_histogram() : h = Histogram(axis=Axis(100,-50, 50)) assert h.entries() == 0. assert h.sigma() == 0 assert h.mean() == 0 assert h.overflow() == 0 assert h.underflow() ==0
def test_entries() : h = Histogram(axis=Axis(100, -50., 50.)) weight = 0.5 for x in xrange(10) : h.fill(-49.99, weight) # should be 0th bin h.fill(49.99, weight) # should be 100th bin, ie index 99 h.fill(0.1, 2*weight) assert h.entries() == 30
def test_subtract_histograms() : h0 = Histogram(axis=Axis(100, -50., 50.)) weight = 0.5 h0.fill([-49.99,49.99,-48.99,48.99], weight) # should be 0th bin h0.fill(0.1, 4*weight) h0.fill(-75., 32.) h0.fill(100., 55) h1 = Histogram(axis=Axis(100, -50., 50.)) h1.fill([-48.99,48.99], weight) # should be 0th bin h1.fill(0.1, 2*weight) h1.fill(-101.) h1.fill(200.,2) h2 = h0 - h1 assert h2.axis == h0.axis assert h2.entries() == h0.entries() - h1.entries() assert h2.overflow() == h0.overflow() - h1.overflow() assert h2.underflow() == h0.underflow() - h1.underflow() for bin in xrange(h2.axis.nbins): assert h2.binHeight(bin) == h0.binHeight(bin) - h1.binHeight(bin)
def test_fill_from_list(): h = Histogram(axis=Axis(100, -50, 50)) x = [float(i) for i in xrange(-49,50)] h.fill(x) assert h.entries() == 99
def test_entries_does_not_count_out_of_range_entries() : h = Histogram(axis=Axis(100, -50., 50.)) h.fill(45.5, 10.) h.fill(100.) h.fill(-100) assert h.entries() == 3.