def _read1DHistogram(self, rz_id): # Make sure this ID corresponds to a 1D histogram. kind = ext.hkind(rz_id) if kind != 1: raise TypeError, "ID %d is not a 1D histogram" % rz_id # Obtain histogram parameters. title, num_bins, min, max = ext.hgive(rz_id)[:4] # Construct the histogram. result = hep.hist.Histogram1D( num_bins, (min, max), bin_type=float, error_model="symmetric", title=title, rz_id=rz_id) # Get the bin contents. bin_contents = ext.hunpak(rz_id, " ", 0, num_bins) assert len(bin_contents) == num_bins # Get the bin errors. bin_errors = ext.hunpke(rz_id, " ", 0, num_bins) assert len(bin_errors) == num_bins # Store them in the histogram. for bin in xrange(0, num_bins): result.setBinContent(bin, bin_contents[bin]) result.setBinError(bin, bin_errors[bin]) # Store underflow and overflow too. result.setBinContent("underflow", ext.hi(rz_id, 0)) result.setBinContent("overflow", ext.hi(rz_id, num_bins + 1)) # Store the number of entries. result.number_of_samples = ext.hnoent(rz_id) return result
def _read2DHistogram(self, rz_id): # Make sure this ID corresponds to a 2D histogram. kind = ext.hkind(rz_id) if kind != 2: raise TypeError, "ID %d is not a 2D histogram" % rz_id # Obtain histogram parameters. title, num_x_bins, x_min, x_max, num_y_bins, y_min, y_max, loc = \ ext.hgive(rz_id) # Construct the histogram. result = hep.hist.Histogram( (num_x_bins, (x_min, x_max)), (num_y_bins, (y_min, y_max)), bin_type=float, error_model="symmetric", title=title, rz_id=rz_id) # Fill the bin contents and errors. for x in xrange(0, num_x_bins + 2): # Compute our bin number from the HBOOK bin number. if x == 0: x_bin_number = "underflow" elif x == num_x_bins + 1: x_bin_number = "overflow" else: x_bin_number = x - 1 for y in xrange(0, num_y_bins + 2): # Compute our bin number from the HBOOK bin number. if y == 0: y_bin_number = "underflow" elif y == num_y_bins + 1: y_bin_number = "overflow" else: y_bin_number = y - 1 content = ext.hij(rz_id, x, y) error = ext.hije(rz_id, x, y) result.setBinContent((x_bin_number, y_bin_number), content) result.setBinError((x_bin_number, y_bin_number), error) # Load the number of entries. result.number_of_samples = ext.hnoent(rz_id) return result