Exemple #1
0
    def array2data(self,
                   data,
                   weights=None,
                   normed=False,
                   binning=1,
                   reBin=None):
        """
        Convert array of data to internal format
        - Designed for arrays of raw, un-binned data.
        - If you pass values here from an existing histogram ('weights' is not None
          and the 'data' param is just bin centers), it is possible to re-bin
          this histogram using the 'reBin' keyword
        """
        data, bins = np.histogram(data,
                                  bins=binning,
                                  weights=weights,
                                  normed=normed)

        results = Hist()
        results.content = data
        results.bins = bins
        results.center = tools.midpoints(bins)
        results.width = tools.widths(bins)

        results.error = np.sqrt(data)
        if weights is not None:
            # numpy digitize to get sumw2
            results.error = results.sumw2_1D(xdata=data, values=weights)

        if reBin is not None:
            results.Rebin(reBin)
            if normed: results.normalize()  # normalize after re-binning

        return results
Exemple #2
0
    def hist2data(self, histo, reBin=None, normed=False):
        """Convert ROOT histogram for internal use."""
        bin_contents, bin_edges = histo.numpy()

        results = Hist()
        results.content = bin_contents
        results.bins = bin_edges
        results.center = tools.midpoints(bin_edges)
        results.width = tools.widths(bin_edges)

        if len(histo.variances) > 0:
            results.error = histo.variances
        else:
            results.error = np.sqrt(bin_contents)

        if reBin is not None:
            results.Rebin(reBin)
        if normed: results.normalize()

        return results