Exemple #1
0
def test_binheight() :
    h = Histogram(axis=Axis(100, -50., 50.))
    weight = 0.5
    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.binHeight(0) == weight
    assert h.binHeight(99) == weight
    assert h.binHeight(50) == 2*weight
Exemple #2
0
def test_multiply_histograms() :
    from random import gauss
    h0 = Histogram(axis=Axis(100, -50., 50.))
    h1 = Histogram(axis=Axis(100, -50., 50.))
    dist = [gauss(0.,20) for x in xrange(100)]
    h0.fill(dist)
    h1.fill(dist, 2.5)
    h2 = h0*h1
    for bin in xrange(h2.axis.nbins):
        assert h2.binHeight(bin) == h0.binHeight(bin) * h1.binHeight(bin)
Exemple #3
0
def test_divide_histograms() :
    from random import gauss
    h0 = Histogram(axis=Axis(100, -50., 50.))
    h1 = Histogram(axis=Axis(100, -50., 50.))
    dist = [gauss(0.,10) for x in xrange(100)]
    h0.fill(dist)
    h1.fill(dist, 5.)
    h2 = h0/h1
    for bin in xrange(h2.axis.nbins):
        if h1.binHeight(bin) != 0 :
            assert h2.binHeight(bin) == h0.binHeight(bin) / h1.binHeight(bin)
Exemple #4
0
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)