コード例 #1
0
ファイル: twod2.py プロジェクト: alexhsamuel/pyhep
#-----------------------------------------------------------------------
# imports
#-----------------------------------------------------------------------

from   hep.hist import Histogram
from   hep.test import compare

#-----------------------------------------------------------------------
# tests
#-----------------------------------------------------------------------

histogram = Histogram((1, (0.0, 0.5)), (1, (0, 1)), bin_type=int)

compare(histogram.getBinContent(("underflow", "underflow")),    0)
compare(histogram.getBinContent((0          , "underflow")),    0)
compare(histogram.getBinContent(("overflow" , "underflow")),    0)
compare(histogram.getBinContent(("underflow", 0          )),    0)
compare(histogram.getBinContent((0          , 0          )),    0)
compare(histogram.getBinContent(("overflow" , 0          )),    0)
compare(histogram.getBinContent(("underflow", "overflow" )),    0)
compare(histogram.getBinContent((0          , "overflow" )),    0)
compare(histogram.getBinContent(("overflow" , "overflow" )),    0)

histogram.accumulate((-1, -1),    4)
histogram.accumulate(( 0, -1),    8)
histogram.accumulate(( 1, -1),   16)
histogram.accumulate((-1,  0),   32)
histogram.accumulate(( 0,  0),   64)
histogram.accumulate(( 1,  0),  128)
histogram.accumulate((-1,  1),  256)
histogram.accumulate(( 0,  1),  512)
コード例 #2
0
ファイル: twod1.py プロジェクト: alexhsamuel/pyhep
# Check that it's configured correctly.
compare(histogram.dimensions, 2)
compare(histogram.bin_type, float)
x_axis, y_axis = histogram.axes
compare(x_axis.number_of_bins, 10)
compare(x_axis.range, (0.0, 10.0))
compare(x_axis.type, float)
compare(y_axis.number_of_bins, 10)
compare(y_axis.range, (-1.0, 1.0))
compare(y_axis.type, float)

# Fill it.
histogram.accumulate((-10, -10), 42.0)
histogram.accumulate((-10, 0.1), 17.5)
histogram.accumulate((0.5, 10), -4.0)
histogram.accumulate((-10, 10), 3.33)

# Do some checks on the contents.
compare(histogram.number_of_samples, 2004)
total = 0
for i in xrange(0, 10):
    for j in xrange(0, 10):
        total += histogram.getBinContent((i, j))
compare(total, 2000)
compare(histogram.getBinContent(("underflow", "underflow")), 42.0)
compare(histogram.getBinContent(("underflow", 5)), 17.5)
compare(histogram.getBinContent((0, "overflow")), -4.0)
compare(histogram.getBinContent((1, "overflow")), 0)
compare(histogram.getBinContent(("underflow", "overflow")), 3.33, precision=1e-6)
compare(histogram.getBinContent(("overflow", "overflow")), 0)