def addMCStatError(self):
        histoData = filter(lambda x: x.isMC(), self.histos.getHistoDataList())
        if len(histoData) == 0:
            # Only data histograms
            return

        ROOT.gStyle.SetErrorX(0.5)
        hse = HistoTotalUncertainty(histoData, "MC Stat. Err.")
        hse.call(styles.getErrorStyle())
        self.histos.append(hse)
    def addMCStatError(self):
        histoData = filter(lambda x: x.isMC(), self.histos.getHistoDataList())
        if len(histoData) == 0:
            # Only data histograms
            return

        ROOT.gStyle.SetErrorX(0.5)
        hse = HistoTotalUncertainty(histoData, "MC Stat. Err.")
        hse.call(styles.getErrorStyle())
        self.histos.append(hse)
예제 #3
0
tauPts.setHistoLegendStyle("Data", "p")

# Apply the default styles (for all histograms, for MC histograms, for a single histogram)
# tauPts.forEachHisto(styles.generator())
# tauPts.forEachMCHisto(styles.generator(fill=True, fillStyle=3002)) # Example how to set non-default fill style
tauPts.forEachMCHisto(styles.generator(fill=True))  # Apply SetFillColor too, needed for histogram stacking
tauPts.forHisto("Data", styles.getDataStyle())
tauPts.setHistoDrawStyle("Data", "EP")


# Example how to stack all MC datasets
# Note: this MUST be done after all legend/style manipulation
tauPts.stackMCHistograms()

# Example how to add MC uncertainty
tauPts.addMCUncertainty(styles.getErrorStyle())
# tauPts.addMCUncertainty(styles.getErrorStyle(), "MC uncertainty")

# Create TCanvas and TH1F such that they cover all histograms
cf = histograms.CanvasFrame(tauPts, "taupt")
# cf = histograms.CanvasFrame(tauPts, "taupt", ymin=10, ymax=1e9) # for logy

# Set the frame options, e.g. axis labels
cf.frame.GetXaxis().SetTitle("Tau p_{T} (GeV/c)")
cf.frame.GetYaxis().SetTitle(ylabel)

# Legend
legend = histograms.createLegend(0.7, 0.5, 0.9, 0.8)
tauPts.addToLegend(legend)

# Draw the plots
예제 #4
0
    def Save(self, name):

        if len(self.histogramsNotFound) > 0:
            for name in self.histogramsNotFound:
                print "Histo", name, "not found"
            self.histogramsNotFound = []
            return

        hObserved = self.histograms[self.FindHistoIndex(
            self.dataHistos[0].name)].Clone("Data")
        hObserved.Reset()
        for histo in self.dataHistos:
            hObserved.Add(self.histograms[self.FindHistoIndex(histo.label)])
        print "    Data:    ", hObserved.Integral(
            0, hObserved.GetNbinsX()), "events"
        hEstimatedEWKfake = self.histograms[self.FindHistoIndex(
            "EWKfake")].Clone("hEstimatedEWKfake")
        print "    EWKfake: ", hEstimatedEWKfake.Integral(
            0, hEstimatedEWKfake.GetNbinsX()), "events"
        hEstimatedEWK = self.histograms[self.FindHistoIndex("EWK")].Clone(
            "hEstimatedEWK")
        print "    EWK:     ", hEstimatedEWK.Integral(
            0, hEstimatedEWK.GetNbinsX()), "events"
        hEstimatedEWK.Add(hEstimatedEWKfake)
        hEstimatedQCD = self.histograms[self.FindHistoIndex("QCD")].Clone(
            "hEstimatedQCD")
        print "    QCD:     ", hEstimatedQCD.Integral(
            0, hEstimatedQCD.GetNbinsX()), "events"
        hEstimatedQCD.Add(hEstimatedEWK)
        hUncertainty = hEstimatedQCD.Clone("BackgrUncertainty")
        hUncertainty.SetFillColor(1)
        hUncertainty.SetFillStyle(3354)
        hUncertainty.SetLineColor(0)
        hUncertainty.SetLineStyle(0)
        hUncertainty.SetLineWidth(0)
        hUncertainty.SetMarkerColor(0)
        hUncertainty.SetMarkerSize(0)
        hSignal = self.histograms[self.FindHistoIndex("Signal")].Clone(
            "hSignal")
        print "    Signal:  ", hSignal.Integral(0,
                                                hSignal.GetNbinsX()), "events"
        hSignal.Add(hEstimatedQCD)

        style = tdrstyle.TDRStyle()

        plot = plots.ComparisonManyPlot(histograms.Histo(hObserved, "Data"), [
            histograms.Histo(hUncertainty, "Backgr.Uncertainty"),
            histograms.Histo(hEstimatedEWKfake, "EWKfake"),
            histograms.Histo(hEstimatedEWK, "EWK"),
            histograms.Histo(hEstimatedQCD, "QCD"),
            histograms.Histo(hSignal, "Signal")
        ])

        plot.histoMgr.forHisto("Data", styles.getDataStyle())

        plot.histoMgr.forHisto("EWK", styles.getEWKStyle())
        plot.histoMgr.forHisto("EWKfake", styles.getEWKFakeStyle())
        plot.histoMgr.forHisto("QCD", styles.getQCDStyle())
        plot.histoMgr.forHisto("Signal", styles.getSignalStyle())
        plot.histoMgr.forHisto("Backgr.Uncertainty", styles.getErrorStyle())

        plot.histoMgr.setHistoDrawStyleAll("HIST")
        plot.histoMgr.setHistoDrawStyle("Data", "EP")
        plot.histoMgr.setHistoDrawStyle("Backgr.Uncertainty", "E2")

        plot.histoMgr.setHistoLegendStyleAll("F")
        plot.histoMgr.setHistoLegendStyle("Data", "P")
        plot.histoMgr.setHistoLegendStyle("Signal", "L")

        plot.createFrame(name, opts={"ymin": 0, "ymaxfactor": 1.2})
        plot.frame.GetXaxis().SetTitle(self.xtitle)
        plot.frame.GetYaxis().SetTitle(self.ytitle)

        plot.histoMgr.reorderLegend(
            ["Data", "Signal", "QCD", "EWK", "EWKfake", "Backgr.Uncertainty"])
        self.setLegendLabels(plot)
        plot.setLegend(histograms.createLegend(0.55, 0.68, 0.9, 0.93))

        histograms.addCmsPreliminaryText()
        histograms.addEnergyText()
        histograms.addLuminosityText(x=None, y=None, lumi=self.lumi)

        plot.draw()
        plot.save()
예제 #5
0
tauPts.setHistoLegendStyle("Data", "p")

# Apply the default styles (for all histograms, for MC histograms, for a single histogram)
#tauPts.forEachHisto(styles.generator())
#tauPts.forEachMCHisto(styles.generator(fill=True, fillStyle=3002)) # Example how to set non-default fill style
tauPts.forEachMCHisto(styles.generator(fill=True)) # Apply SetFillColor too, needed for histogram stacking
tauPts.forHisto("Data", styles.getDataStyle())
tauPts.setHistoDrawStyle("Data", "EP")


# Example how to stack all MC datasets
# Note: this MUST be done after all legend/style manipulation
tauPts.stackMCHistograms()

# Example how to add MC uncertainty
tauPts.addMCUncertainty(styles.getErrorStyle())
#tauPts.addMCUncertainty(styles.getErrorStyle(), "MC uncertainty")

# Create TCanvas and TH1F such that they cover all histograms
cf = histograms.CanvasFrame(tauPts, "taupt")
#cf = histograms.CanvasFrame(tauPts, "taupt", ymin=10, ymax=1e9) # for logy

# Set the frame options, e.g. axis labels
cf.frame.GetXaxis().SetTitle("Tau p_{T} (GeV/c)")
cf.frame.GetYaxis().SetTitle(ylabel)

# Legend
legend = histograms.createLegend(0.7, 0.5, 0.9, 0.8)
tauPts.addToLegend(legend)

# Draw the plots
예제 #6
0
    def Save(self, name):

	if len(self.histogramsNotFound) > 0:
	    for name in self.histogramsNotFound:
		print "Histo",name,"not found"
	    self.histogramsNotFound = []
	    return
	    

	hObserved = self.histograms[self.FindHistoIndex(self.dataHistos[0].name)].Clone("Data")
        hObserved.Reset()
	for histo in self.dataHistos:
            hObserved.Add(self.histograms[self.FindHistoIndex(histo.label)])
	print "    Data:    ", hObserved.Integral(0,hObserved.GetNbinsX()),"events"
	hEstimatedEWKfake = self.histograms[self.FindHistoIndex("EWKfake")].Clone("hEstimatedEWKfake")
	print "    EWKfake: ",hEstimatedEWKfake.Integral(0,hEstimatedEWKfake.GetNbinsX()),"events"
	hEstimatedEWK     = self.histograms[self.FindHistoIndex("EWK")].Clone("hEstimatedEWK")
	print "    EWK:     ",hEstimatedEWK.Integral(0,hEstimatedEWK.GetNbinsX()),"events"
	hEstimatedEWK.Add(hEstimatedEWKfake)
	hEstimatedQCD     = self.histograms[self.FindHistoIndex("QCD")].Clone("hEstimatedQCD")
	print "    QCD:     ",hEstimatedQCD.Integral(0,hEstimatedQCD.GetNbinsX()),"events"
	hEstimatedQCD.Add(hEstimatedEWK)
	hUncertainty = hEstimatedQCD.Clone("BackgrUncertainty")
	hUncertainty.SetFillColor(1)
	hUncertainty.SetFillStyle(3354)
	hUncertainty.SetLineColor(0)
	hUncertainty.SetLineStyle(0)
	hUncertainty.SetLineWidth(0)
	hUncertainty.SetMarkerColor(0)
	hUncertainty.SetMarkerSize(0)
	hSignal           = self.histograms[self.FindHistoIndex("Signal")].Clone("hSignal")
	print "    Signal:  ",hSignal.Integral(0,hSignal.GetNbinsX()),"events"
	hSignal.Add(hEstimatedQCD)


	style = tdrstyle.TDRStyle()


	plot = plots.ComparisonManyPlot(
	    histograms.Histo(hObserved, "Data"),
	    [
	     histograms.Histo(hUncertainty, "Backgr.Uncertainty"),
	     histograms.Histo(hEstimatedEWKfake, "EWKfake"),
             histograms.Histo(hEstimatedEWK, "EWK"),
             histograms.Histo(hEstimatedQCD, "QCD"),
             histograms.Histo(hSignal, "Signal")
             ]
	)

        plot.histoMgr.forHisto("Data", styles.getDataStyle())

	plot.histoMgr.forHisto("EWK",styles.getEWKStyle())
	plot.histoMgr.forHisto("EWKfake",styles.getEWKFakeStyle())
	plot.histoMgr.forHisto("QCD",styles.getQCDStyle())
	plot.histoMgr.forHisto("Signal",styles.getSignalStyle())
	plot.histoMgr.forHisto("Backgr.Uncertainty",styles.getErrorStyle())

	plot.histoMgr.setHistoDrawStyleAll("HIST")
	plot.histoMgr.setHistoDrawStyle("Data", "EP")
	plot.histoMgr.setHistoDrawStyle("Backgr.Uncertainty", "E2")

	plot.histoMgr.setHistoLegendStyleAll("F")
	plot.histoMgr.setHistoLegendStyle("Data", "P")
	plot.histoMgr.setHistoLegendStyle("Signal", "L")

        plot.createFrame(name, opts={"ymin":0, "ymaxfactor": 1.2})
	plot.frame.GetXaxis().SetTitle(self.xtitle)
	plot.frame.GetYaxis().SetTitle(self.ytitle)

	plot.histoMgr.reorderLegend(["Data", "Signal", "QCD", "EWK", "EWKfake", "Backgr.Uncertainty"])
	self.setLegendLabels(plot)
	plot.setLegend(histograms.createLegend(0.55,0.68,0.9,0.93))
	
        histograms.addCmsPreliminaryText()
        histograms.addEnergyText()
        histograms.addLuminosityText(x=None, y=None, lumi=self.lumi)
        
        plot.draw()
        plot.save()