Beispiel #1
0
    def Add(self,
            data,
            name='',
            weights=None,
            sampleType='background',
            file=None,
            systematics=None):
        """
        Add histogram data for this figure.

        @param data        histogram or list/array of values to plot
        @param name        name of sample ('ttbar','wjets',etc.)
        @param weights     weights (if any) for histogram
        @param sampleType  Kind of sample ('background','signal', or 'data')
        @param file        The root file of histograms to get systematic uncertainties
        @param systematics The total systematic uncertainty for a given sample 
                           (histogram or array of bin content from histogram)
        """
        self.names.append(name)

        if isinstance(data, ROOT.TH1):
            self.hists2plot[name] = hpt.hist2list(data,
                                                  name=name,
                                                  reBin=self.rebin)
        else:
            self.hists2plot[name] = hpt.data2list(data)

        self.weights[name] = weights
        self.sampleTypes[sampleType].append(name)
        self.systematics[name] = systematics

        return
Beispiel #2
0
    def initialize(self, nominalHistogram, nominalWeights=None):
        """Setup some initial variables"""
        self.total = None  # hold the total systematic uncertainty
        self.systData = OrderedDict()  # hold data for individual systematics
        if isinstance(nominalHistogram, ROOT.TH1):
            self.systData['nominal'] = hpt.hist2list(nominalHistogram,
                                                     name="nominal")
        else:
            self.systData['nominal'] = hpt.data2list(nominalHistogram,
                                                     bins=self.binning,
                                                     weights=nominalWeights)

        return
Beispiel #3
0
    def Add(self, data, weights=None, name=''):
        """
        Turn data into a numpy array to combine and plot systematic uncertainties.

        @param data        histogram (also support list/array of values) to plot
        @param weights     weights for each event for making histogram
        @param name        name of systematic (JES,JER,etc.)
        """
        if not name:
            name = data.GetName()

        if isinstance(data, ROOT.TH1):
            self.systData[name] = hpt.hist2list(data, name=name)
        else:
            self.systData[name] = hpt.data2list(data,
                                                bins=self.binning,
                                                weights=weights)

        return
Beispiel #4
0
    def Add(self,
            data,
            name='',
            weights=None,
            linecolor='k',
            linestyle='solid',
            color='k',
            linewidth=2,
            draw='step',
            label='',
            ratio_den=False,
            ratio_num=False,
            ratio_partner=None,
            yerr=None,
            **kwargs):
        """
        Add histogram data for this figure.

        args   = data (1D) || x_data,y_data (2D)        array or ROOT hist
        kwargs = bins (int or list/np.array):           default = 10
                 weights (None or list/np.array):       default = None
                 uncertainties (None or list/np.array): default = None
                 linecolor 'black',etc:                 default = None
                 fillcolor 'blue',etc.
                 draw   step,stepfilled,errorbar
                 label "ttbar" or something
        """
        self.names.append(name)

        normed = False
        if 'normed' in kwargs.keys():
            normed = kwargs['normed']

        if self.typeOfPlot == "histogram" and isinstance(data, ROOT.TH1):
            if self.dimensions == 1:
                self.hists2plot[name] = hpt.hist2list(data,
                                                      name=name,
                                                      reBin=self.rebin,
                                                      normed=normed)
            else:
                self.hists2plot[name] = hpt.hist2list2D(data,
                                                        name=name,
                                                        reBin=self.rebin,
                                                        normed=normed)
        elif self.typeOfPlot == "efficiency" and isinstance(
                data, ROOT.TEfficiency):
            self.hists2plot[name] = hpt.TEfficiency2list(data)
        elif self.typeOfPlot == "efficiency" and isinstance(data, ROOT.TH1):
            total_data = data.Integral()
            data.Scale(1. /
                       total_data)  # normalize distribution to show on plot
            self.hists2plot[name] = hpt.hist2list(data,
                                                  name=name,
                                                  reBin=self.rebin,
                                                  normed=normed)
            self.drawEffDist = True
            self.effData.append(name)
        else:
            if self.dimensions == 1:
                self.hists2plot[name] = hpt.data2list(data,
                                                      weights=weights,
                                                      normed=normed,
                                                      binning=self.binning)
                if yerr is not None: self.hists2plot[name]['error'] = yerr
            else:
                self.hists2plot[name] = hpt.data2list2D(data,
                                                        weights=weights,
                                                        normed=normed,
                                                        binning=self.binning)

        self.kwargs[name] = kwargs  # pass normal matplotlib arguments
        self.colors[name] = color
        self.yerrors[name] = yerr  # method for drawing y-errors
        self.draw_types[name] = draw
        self.linecolors[name] = linecolor
        self.linestyles[name] = linestyle
        self.linewidths[name] = linewidth
        self.labels[name] = label
        self.weights[name] = weights
        self.ratio_den[name] = ratio_den  # denominator in ratio
        self.ratio_num[name] = ratio_num  # numerator in ratio
        self.ratio_partner[name] = ratio_partner

        if draw == 'errorbar':
            self.errorbarplot.append(name)
            if linestyle == 'solid':
                self.linestyles[name] = 'o'  # default setting for errorbar
            else:
                self.linestyles[name] = linestyle  # user custom option

        return