#----------------------------------------------------------------------- # 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)
#----------------------------------------------------------------------- # imports #----------------------------------------------------------------------- from hep.hist import Histogram from hep.test import compare from math import sqrt #----------------------------------------------------------------------- # test #----------------------------------------------------------------------- # Create and fill a histogram. histogram = Histogram((10, (0.0, 10.0)), (10, (-1.0, 1.0)), bin_type=float) for i in xrange(0, 100): for j in xrange(-10, 10): histogram << (sqrt(i), 0.1 * j + 0.05) # 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.