histogram = histogram.strip('\n')
    histogramName = histogram.split("h_")[1].split("_pre")[0]
    print "  :: Plotting " + histogram + "\n"

    ## setup histogram
    hist = HepPlotter("histogram", 1)

    hist.ratio_plot = False  # plot a ratio of things [Data/MC]
    hist.ratio_type = "ratio"  # "ratio"
    hist.stacked = True  # stack plots
    hist.rebin = 10
    hist.logplot = False  # plot on log scale
    hist.x_label = x_labels[histogramName]["label"]
    hist.y_label = "Events"
    hist.y_ratio_label = ""
    hist.lumi = 'XY.Z'  # in /fb
    hist.format = 'png'  # file format for saving image
    hist.saveAs = outpath + "/hist_" + histogram  # save figure with name
    hist.ATLASlabel = 'top left'  # 'top left', 'top right'; hack code for something else
    hist.ATLASlabelStatus = 'Internal'  # ('Simulation')+'Internal' || 'Preliminary'
    #    hist.extra_text.Add("text here",coords=[x,y]) # see hepPlotter for exact use of extra_text (PlotText() objects)

    hist.initialize()

    ## Add the data from each file
    for fi, file in enumerate(files):
        file = file.rstrip("\n")
        f = ROOT.TFile.Open(file)
        filename = file.split("/")[-1].split(".")[0]

        print "     > Opening data from ", file
Example #2
0
    def drawSyst(self, name=[], symmetrized=None, one_sided=False):
        """
        Draw single systematic with nominal
        
        @param name         name(s) for histogram
        @param symmetrized  Values from symmetrized uncertainties
        @param one_sided    Boolean for one sided systematic or not
        """
        if name[0].endswith("up"):
            systname = name[0][:-2].replace("_", "-")
        elif name[0].endswith("down"):
            systname = name[0][:-4].replace("_", "-")

        systname = systname.split("xleptonicT-mmerged-boostedcomb-")[1]

        h_nominal = self.systData['nominal'][
            'data']  # data (histogram bins values)
        b_nominal = self.systData['nominal'][
            'center']  # dummy values to get binning right

        hist = HepPlotter("histogram", 1)

        hist.ratio_plot = True  # plot a ratio of things [Data/MC]
        hist.ratio_type = "ratio"  # "ratio"
        hist.stacked = False  # stack plots
        hist.rebin = self.rebin
        hist.logplot = False  # plot on log scale
        hist.x_label = self.x_labels[self.variable]['label']
        hist.y_label = "Events"
        hist.extra_text = systname + '\n ' + self.sampleName
        hist.binning = self.systData['nominal']['bins']
        hist.numLegendColumns = 1
        hist.y_ratio_label = "Syst/Nom"
        hist.lumi = '14.7'  # in /fb
        hist.format = 'png'  # file format for saving image
        hist.saveAs = self.outpath + "h_syst_" + self.sampleName + "_" + systname  # save figure with unique name
        hist.CMSlabel = 'top left'  # 'top left', 'top right'; hack code for something else
        hist.CMSlabelStatus = 'Simulation Internal'  # ('Simulation')+'Internal' || 'Preliminary'

        hist.initialize()

        ## Regular uncertainties
        up = self.systData[name[0]]['center']
        upData = self.systData[name[0]]['data']
        hist.Add(up,
                 weights=upData,
                 name=systname + " UP",
                 label="UP",
                 linecolor='r',
                 color='r',
                 linestyle='dotted',
                 draw='step',
                 ratio_num=True,
                 ratio_den=False,
                 ratio_partner="nominal")
        if not one_sided:
            down = self.systData[name[1]]['center']
            downData = self.systData[name[1]]['data']
            hist.Add(down,
                     weights=downData,
                     name=systname + " DOWN",
                     label="DOWN",
                     linecolor='b',
                     color='b',
                     linestyle='dotted',
                     draw='step',
                     ratio_num=True,
                     ratio_den=False,
                     ratio_partner="nominal")

        ## Symmetrized uncertainties
        if symmetrized is not None:
            # - same binning as 'up' systematic
            hist.Add(up,
                     weights=h_nominal + symmetrized,
                     name=systname + " UP Symm.",
                     label="UP Symm.",
                     linecolor='r',
                     linestyle='solid',
                     draw='step',
                     color='r',
                     ratio_num=True,
                     ratio_den=False,
                     ratio_partner="nominal")
            hist.Add(up,
                     weights=h_nominal - symmetrized,
                     name=systname + " DOWN Symm.",
                     label="DOWN Symm.",
                     linecolor='b',
                     linestyle='solid',
                     draw='step',
                     color='b',
                     ratio_num=True,
                     ratio_den=False,
                     ratio_partner="nominal")

        ## nominal
        uncertainty_hists = [
            systname + " UP", systname + " DOWN", systname + " UP Symm.",
            systname + " DOWN Symm."
        ]
        hist.Add(b_nominal,
                 weights=h_nominal,
                 name="nominal",
                 label="nominal",
                 linecolor='k',
                 draw='step',
                 linestyle='solid',
                 ratio_num=False,
                 ratio_den=True,
                 ratio_partner=uncertainty_hists)

        p = hist.execute()  # can do something with p, if needed
        hist.savefig()  # save and close the figure

        return