예제 #1
0
    def _plot(self):
        if not self.loader:
            raise RuntimeError("templates are not loaded")

        class Container: pass
        containers = []

        for plot, channels in self.loader.plots.items():
            for channel, systematics in channels.items():
                obj = Container()
                obj.ratios = []
                obj.stack = ROOT.THStack()
                obj.axis_hist = None

                obj.legend = ROOT.TLegend(.67, .60, .89, .88)
                obj.legend.SetMargin(0.12);
                obj.legend.SetTextSize(0.03);
                obj.legend.SetFillColor(10);
                obj.legend.SetBorderSize(0);
                obj.legend.SetHeader("{0}: {1}".format(
                    self._systematic.capitalize(),
                    self.channel_names.get(channel, "Unknown Channel")))

                self.style(systematics)

                max_y = 0
                for channel in (systematics.nominal,
                                systematics.plus,
                                systematics.minus):
                    if not channel:
                        continue

                    if not obj.axis_hist:
                        obj.axis_hist = channel.hist.Clone()

                    channel_max_y = channel.hist.GetBinContent(
                            channel.hist.GetMaximumBin())

                    if channel_max_y > max_y:
                        max_y = channel_max_y

                obj.axis_hist.Reset()
                obj.axis_hist.SetMaximum(1.2 * max_y)

                if systematics.nominal:
                    obj.stack.Add(systematics.nominal.hist)
                    obj.legend.AddEntry(systematics.nominal.hist,
                                        "nominal",
                                        "lp")

                if systematics.plus:
                    obj.stack.Add(systematics.plus.hist)
                    obj.legend.AddEntry(systematics.plus.hist,
                                        "systematic plus",
                                        "lp")

                    if systematics.nominal:
                        obj.ratios.append(compare.ratio(
                                systematics.plus.hist,
                                systematics.nominal.hist,
                                title="#frac{plus}{nominal}"))

                if systematics.minus:
                    obj.stack.Add(systematics.minus.hist)
                    obj.legend.AddEntry(systematics.minus.hist,
                                        "systematic minus",
                                        "lp")

                    if systematics.nominal:
                        obj.ratios.append(compare.ratio(
                                systematics.minus.hist,
                                systematics.nominal.hist,
                                title="#frac{minus}{nominal}"))

                obj.canvas = ComparisonCanvas(len(obj.ratios) + 1)
                canvas = obj.canvas.canvas

                canvas.cd(1)

                obj.axis_hist.Draw("9")
                obj.stack.Draw("hist 9 nostack same")

                obj.labels = [root.label.CMSSimulationLabel()]

                for label in obj.labels:
                    label.draw()

                obj.legend.Draw("9")

                for pad, ratio in enumerate(obj.ratios, 2):
                    canvas.cd(pad)

                    ratio.GetYaxis().SetRangeUser(0, 2)
                    ratio.GetXaxis().SetTitle("")
                    ratio.Draw("9 e")

                canvas.Update()

                containers.append(obj)

        if containers and  not self._batch_mode:
            raw_input('enter')
예제 #2
0
    def _plot(self):
        class Canvas: pass

        canvases = []

        '''
        loop over plots and draw them:

            1. all background channels stacked (MC channels + QCD)
            2. background error band (MC + QCD)
            3. data with errors
            4. ratio of data over background
        '''

        # loop over plots
        for plot_name, channels in self.loader.plots.items():
            ttbar = channels["ttbar"]
            ttbar_powheg = channels["ttbar_powheg"]

            for hist in ttbar.hist, ttbar_powheg.hist:
                hist.SetFillStyle(0)

            obj = Canvas()
            obj.canvas_obj = ComparisonCanvas()
            obj.canvas = obj.canvas_obj.canvas

            obj.canvas.cd(2)

            obj.ratio = compare.ratio(ttbar.hist,
                                      ttbar_powheg.hist,
                                      title = "#frac{MADGRAPH}{POWHEG}")
            obj.ratio.SetMinimum(0)
            obj.ratio.SetMaximum(2)

            obj.ratio.GetXaxis().SetTitle("")
            obj.ratio.Draw("9 e")

            obj.canvas.SetName("canvas_" + plot_name.replace("/", "_"))
            obj.canvas.cd(1)

            ttbar.hist.Draw('9 hist')
            ttbar_powheg.hist.Draw('9 hist same')

            legend = ROOT.TLegend(.67, .60, .89, .75)
            legend.SetMargin(0.12);
            legend.SetTextSize(0.03);
            legend.SetFillColor(10);
            legend.SetBorderSize(0);
            legend.SetHeader("t#bar{t} comparison")

            legend.AddEntry(ttbar.hist, "MADGRAPH", "l")
            legend.AddEntry(ttbar_powheg.hist, "POWHEG", "l")

            obj.legend = legend
            obj.legend.Draw('9')

            obj.canvas.Update()
            canvases.append(obj)

            print("Powheg/Madgraph: {0:.2f}".format(
                ttbar_powheg.hist.Integral() / ttbar.hist.Integral()))

        return canvases