def _make1DHistogram(self, hist, title, rz_id): assert hist.dimensions == 1 axis = hist.axis num_bins = axis.number_of_bins range_lo, range_hi = map(float, axis.range) # Create the HBOOK histogram. ext.hbook1(rz_id, title, num_bins, range_lo, range_hi, 0) # Activate storage of per-bin errors for this histogam. ext.hbarx(rz_id) # Construct a C array containing the bin contents as floats. bin_contents = [ hist.getBinContent(n) for n in xrange(0, num_bins) ] pack_array = array.array("f", bin_contents) # Stuff the bin contents into the HBOOK histogram. ext.hpak(rz_id, pack_array.buffer_info()[0]) # Construct a C array containing the bin errors as floats. bin_errors = \ [ max(*hist.getBinError(bin)) for bin in xrange(num_bins) ] pack_array = array.array("f", bin_errors) # Stuff the bin errors into the HBOOK histogram. ext.hpake(rz_id, pack_array.buffer_info()[0]) # Set the underflow and overflow contents. # FIXME: This is hackish, but I can't find any other way in the API # to do this. ext.hf1(rz_id, range_lo - 1, hist.getBinContent("underflow")) ext.hf1(rz_id, range_hi + 1, hist.getBinContent("overflow")) # Set the number of entries. ext.hfnoent(rz_id, hist.number_of_samples)
def _make2DHistogram(self, hist, title, rz_id): assert hist.dimensions == 2 x_axis, y_axis = hist.axes num_x_bins = x_axis.number_of_bins num_y_bins = y_axis.number_of_bins x_min, x_max = map(float, x_axis.range) y_min, y_max = map(float, y_axis.range) # Create the HBOOK histogram. ext.hbook2(rz_id, title, num_x_bins, x_min, x_max, num_y_bins, y_min, y_max, 0) # Activate storage of per-bin errors for this histogam. ext.hbarx(rz_id) # Construct a C array containing the bin contents as floats. pack_array = array.array("f") for y in xrange(0, num_y_bins): for x in xrange(0, num_x_bins): pack_array.append(hist.getBinContent((x, y))) # Fill the bin contents. ext.hpak(rz_id, pack_array.buffer_info()[0]) # Now fill the C array with bin errors. for y in xrange(0, num_y_bins): for x in xrange(0, num_x_bins): pack_array[y * num_x_bins + x] = max(*hist.getBinError((x, y))) # Fill the bin errors. ext.hpake(rz_id, pack_array.buffer_info()[0]) # Set the underflow and overflow bins. This is kind of hackish; # using 'hfcxy' here depends on our having called 'hpak' or 'hpake' # directly before. for x in xrange(0, num_x_bins): ext.hfcxy(x + 1, 0, hist.getBinContent((x, "underflow"))) ext.hfcxy(x + 1, num_y_bins + 1, hist.getBinContent((x, "overflow"))) for y in xrange(0, num_y_bins): ext.hfcxy(0, y + 1, hist.getBinContent(("underflow", y))) ext.hfcxy(num_x_bins + 1, y + 1, hist.getBinContent(("overflow", y))) ext.hfcxy(0, 0, hist.getBinContent(("underflow", "underflow"))) ext.hfcxy(num_x_bins + 1, 0, hist.getBinContent(("overflow", "underflow"))) ext.hfcxy(0, num_y_bins + 1, hist.getBinContent(("underflow", "overflow"))) ext.hfcxy(num_x_bins + 1, num_y_bins + 1, hist.getBinContent(("overflow", "overflow"))) # FIXME: Set underflow and overflow errors. (Is this supported?) # Set the number of entries. ext.hfnoent(rz_id, hist.number_of_samples)