def drawSave(h, updatePaletteStyle=False): h.draw() if updatePaletteStyle: histograms.updatePaletteStyle(h.histoMgr.getHistos()[0].getRootHisto()) histograms.addCmsPreliminaryText() histograms.addEnergyText() h.save()
def tauPhi(h, step="", rebin=5): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "#phi^{#tau jet}" ylabel = "Events / %.1f" % h.binWidth() opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 name = "tauPhiSimulateEmbedded_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def jetPt(h, prefix="", rebin=10): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "Jet p_{T} (GeV/c)" ylabel = "Number of jets / %.0f GeV/c" % h.binWidth() ptcut = 30 ymin = 1e-1 xmax = 400 h.stackMCHistograms() h.addMCUncertainty() h.createFrame(prefix+"jet_pt_log", xmax=xmax, ymin=ymin, yfactor=2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"jet_pt_log_cut%d"%ptcut, xmin=ptcut, xmax=xmax, ymin=ymin, yfactor=2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def tauCandPhi(h, step="", rebin=5): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "#phi^{#tau candidate}" ylabel = "Events / %.1f" % h.binWidth() opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.01 name = "tauCandidatePhi_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def deltaPhi(h, step="", rebin=5): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "R_{#tau}" ylabel = "Events / %.2f" % h.binWidth() opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 name = "deltaPhiSimulateEmbedded_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend(0.5, 0.3, 0.7, 0.6)) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def transverseMass(h, rebin=5, ratio=False, particle="#tau"): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "m_{T}(%s, MET) (GeV/c^{2})" % particle ylabel = "Events / %.2f GeV/c^{2}" % h.binWidth() opts = {"ymaxfactor": 2} if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 opts["xmax"] = 200 name = prefix + "_" + h.name h.createFrame(name, createRatio=ratio, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save() name += "_log" h.createFrame(name, createRatio=ratio, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def tauCandPt(h, step="", rebin=1): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) ylabel = "Events /%.0f GeV/c" % h.binWidth() xlabel = "p_{T}^{#tau candidate} (GeV/c)" opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 name = "tauCandidatePtSimulatedEmbedded_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def selectionFlow(h, name, rebin=1, ratio=False): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "Cut" ylabel = "Events" #h.stackMCSignalHistograms() h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) njets = 5 lastSelection = njets opts = {"xmax": lastSelection, "ymin": 0.1, "ymaxfactor": 2, "nbins": lastSelection} opts2 = {"ymin": 0.5, "ymax": 1.5} h.createFrame(name, opts=opts, createRatio=ratio, opts2=opts2) xaxis = h.getFrame().GetXaxis() xaxis.SetBinLabel(1, "Trigger") xaxis.SetBinLabel(2, "#tau ID+R_{#tau}") xaxis.SetBinLabel(3, "e veto") xaxis.SetBinLabel(4, "#mu veto") xaxis.SetBinLabel(5, "N_{jets}") h.getPad().SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.addLuminosityText() addMassBRText(x=0.4, y=0.87) h.save()
def common(h, xlabel, ylabel, cutLine=None, cutBox=None, function=None): # Add cut line and/or box if cutLine != None: lst = cutLine if not isinstance(lst, list): lst = [lst] for line in lst: h.addCutBoxAndLine(line, box=False, line=True) if cutBox != None: lst = cutBox if not isinstance(lst, list): lst = [lst] for box in lst: h.addCutBoxAndLine(**box) if function != None: function(h) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.addLuminosityText() h.save()
def muonPhi(h, prefix="", plotAll=False, rebin=1): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "Muon #phi" ylabel = "Number of muons / %.1f" % h.binWidth() h.stackMCHistograms() if plotAll: h.createFrame(prefix+"muon_phi", yfactor=1.4) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"muon_phi_log", yfactor=2, ymin=0.1) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy() h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def vertexCount(h, prefix="", postfix=""): xlabel = "Number of vertices" ylabel = "Number of events" h.stackMCHistograms() h.addMCUncertainty() h.createFrame(prefix+"vertices"+postfix) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"vertices"+postfix+"_log", ymin=0.1, factor=2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def transverseMass(h, name="transverseMass", rebin=2, log=True): # name = h.getRootHistoPath() h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "m_{T}(#tau jet, MET) (GeV/c^{2})" ylabel = "A.u." # h.stackMCHistograms() # h.addMCUncertainty() opts = {"xmax": 200} # opts = {"ymin": 0.0001,"xmax": 200, "ymaxfactor": 1.3} # opts2 = {"ymin": 0.5, "ymax": 1.5} # opts = {"xmax": 200} if log: name += "_log" opts["ymin"] = 1e-4 opts["ymaxfactor"] = 2 #h.createFrameFraction(name, opts=opts) h.createFrame(name, opts=opts) legend = histograms.createLegend() if log: h.getPad().SetLogy(True) histograms.moveLegend(legend, dx=-0.5, dy=-0.3) h.setLegend(legend) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # h.addLuminosityText() h.save()
def transverseMass(h, rebin=5, ratio=False, particle="#tau"): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "m_{T}(%s, MET) (GeV/c^{2})" % particle ylabel = "Events / %.2f GeV/c^{2}" % h.binWidth() opts = {"ymaxfactor": 2} if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 opts["xmax"] = 200 name = prefix+"_"+h.name h.createFrame(name, createRatio=ratio, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save() name += "_log" h.createFrame(name, createRatio=ratio, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def plotCommon(h, rebin, xlabel, log, opts={}, opts2={}, coverPadOpts={}): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) #h.histoMgr.forEachHisto(lambda h: h.getRootHisto().SetLineWidth(5)) #h.histoMgr.getHistos()[0].getRootHisto().SetLineStyle(3) ylabel = "A.u. / %.2f" % h.binWidth() xlabel = xlabel opts_ = {} opts_.update(opts) coverPadOpts_ = {} coverPadOpts_.update(coverPadOpts) if log: if not "ymaxfactor" in opts_: opts_["ymaxfactor"] = 2 if not "yminfactor" in opts_ and not "ymin" in opts_: opts_["yminfactor"] = 1e-4 if not "ymin" in coverPadOpts_: coverPadOpts_["ymin"] = 0.278 name = "TauEmbeddingTaus_%s" % (h.plotName) if log: name += "_log" h.createFrame(name, createRatio=True, opts=opts_, opts2=opts2, coverPadOpts=coverPadOpts_) h.getFrame2().GetYaxis().SetTitle(h.ratioLabel) h.getFrame2().GetYaxis().SetTitleSize(27) # Absolute size h.getFrame2().GetYaxis().SetTitleOffset(2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(createLegend()) if log: ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText(x=0.5, y=0.3) h.save()
def tauCandEta(h, step="", rebin=5): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "#eta^{#tau candidate}" ylabel = "Events / %.1f" % h.binWidth() opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 # opts = {"xmax": 2.5,"xmin":-2.5} # opts["xmin"] = -2.7 # opts["xmax"] = 2.7 name = "tauCandidateEta_%s_log" % step # h.createFrameFraction(name, opts=opts) h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend(0.5, 0.2, 0.7, 0.5)) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def tauCandPt(h, step="", rebin=2): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) ylabel = "Events /%.0f GeV/c" % h.binWidth() xlabel = "p_{T}^{#tau candidate} (GeV/c)" opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 name = "tauCandidatePt_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.setLegend(histograms.createLegend(0.7, 0.6, 0.9, 0.9)) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def transverseMass(h, prefix="", rebin=1, ratio=False): xlabel = "m_{T}(#mu, E_{T}^{miss}) (GeV)" ylabel = "Events / %.0f GeV" _optsLin = {} _optsLog = {"ymin": 0.1, "ymaxfactor": 2} _opts2 = {"ymin": 0, "ymax": 2} if rebin > 1: h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) ylabel = ylabel % h.binWidth() h.stackMCHistograms() h.addMCUncertainty() h.createFrame(prefix+"mt", opts=_optsLin) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"mt_log", createRatio=ratio, opts=_optsLog, opts2=_opts2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.moveLegend(histograms.createLegend())) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def distComparison(datasets): # Create a comparison plot of two distributions (must have the same binning) # Set the names of DatasetRootHisto objects in order to be able easily reference them later drh1 = datasets.getDataset("Data").getDatasetRootHisto(analysis+"/MET_BaseLineTauId") drh1.setName("Base") drh1.normalizeToOne() drh2 = datasets.getDataset("Data").getDatasetRootHisto(analysis+"/MET_InvertedTauId") drh2.setName("Inv") drh2.normalizeToOne() plot = plots.ComparisonPlot(drh1, drh2) # Set the styles st1 = styles.getDataStyle().clone() st2 = st1.clone() st2.append(styles.StyleLine(lineColor=ROOT.kRed)) plot.histoMgr.forHisto("Base", st1) plot.histoMgr.forHisto("Inv", st2) # Set the legend labels plot.histoMgr.setHistoLegendLabelMany({"Base": "Baseline Tau ID", "Inv": "Inverted Tau ID"}) # Set the legend styles plot.histoMgr.setHistoLegendStyleAll("L") plot.histoMgr.setHistoLegendStyle("Base", "P") # exception to the general rule # Set the drawing styles plot.histoMgr.setHistoDrawStyleAll("HIST") plot.histoMgr.setHistoDrawStyle("Base", "EP") # exception to the general rule # Rebin, if necessary plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) # Create frame with a ratio pad plot.createFrame("METbaseVSinvertedTauID", opts={"ymin":1e-5, "ymaxfactor": 1.5}, createRatio=True, opts2={"ymin": -10, "ymax": 50}, # bounds of the ratio plot ) # Set Y axis of the upper pad to logarithmic plot.getPad1().SetLogy(True) # Create legend to the default position plot.setLegend(histograms.createLegend()) # Set the X/Y axis labels plot.frame.GetXaxis().SetTitle("MET (GeV)") plot.frame.GetYaxis().SetTitle("Arbitrary units") # Draw the plot plot.draw() # Add the various texts to histograms.addCmsPreliminaryText() histograms.addEnergyText() histograms.addLuminosityText(x=None, y=None, lumi=datasets.getDataset("Data").getLuminosity()) # Save the plot to files plot.save()
def vertexCount(h, prefix="", postfix="", ratio=True): xlabel = "Number of good vertices" ylabel = "Number of events" if h.normalizeToOne: ylabel = "Arbitrary units." h.stackMCHistograms() stack = h.histoMgr.getHisto("StackedMC") #hsum = stack.getSumRootHisto() #total = hsum.Integral(0, hsum.GetNbinsX()+1) #for rh in stack.getAllRootHistos(): # dataset._normalizeToFactor(rh, 1/total) #dataset._normalizeToOne(h.histoMgr.getHisto("Data").getRootHisto()) h.addMCUncertainty() opts = {} opts_log = {"ymin": 1e-10, "ymaxfactor": 10, "xmax": 30} opts_log.update(opts) opts2 = {"ymin": 0.5, "ymax": 3} opts2_log = opts2 #opts2_log = {"ymin": 5e-2, "ymax": 5e2} h.createFrame(prefix + "vertices" + postfix, opts=opts, createRatio=ratio, opts2=opts2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() if h.normalizeToOne: histograms.addText(0.35, 0.9, "Normalized to unit area", 17) h.save() h.createFrame(prefix + "vertices" + postfix + "_log", opts=opts_log, createRatio=ratio, opts2=opts2_log) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.getPad1().SetLogy(True) #h.getPad2().SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() if h.normalizeToOne: histograms.addText(0.35, 0.9, "Normalized to unit area", 17) h.save()
def common(h, xlabel, ylabel): h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.addLuminosityText() h.save()
def _plotLinear(self, h, selection, met): h.createFrame(selection+"_"+met+self.postfix, ymax=self.ymax, xmax=self.xmax) h.frame.GetXaxis().SetTitle(self.xlabel(met)) h.frame.GetYaxis().SetTitle(self.ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def common(h, xlabel, ylabel, addLuminosityText=True, afterDraw=None): h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.draw() if afterDraw != None: afterDraw() histograms.addCmsPreliminaryText() histograms.addEnergyText() if addLuminosityText: h.addLuminosityText() h.save()
def common(h, xlabel, ylabel, addLuminosityText=True, textFunction=None): h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() if addLuminosityText: h.addLuminosityText() if textFunction != None: textFunction() h.save()
def _plotLog(self, h, selection, met): h.createFrame(selection+"_"+met+"_log"+self.postfix, ymin=0.1, yfactor=2, xmax=self.xmax) h.frame.GetXaxis().SetTitle(self.xlabel(met)) h.frame.GetYaxis().SetTitle(self.ylabel) h.setLegend((histograms.createLegend())) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def vertexCount(h, prefix="", postfix="", ratio=True): xlabel = "Number of good vertices" ylabel = "Number of events" if h.normalizeToOne: ylabel = "Arbitrary units." h.stackMCHistograms() stack = h.histoMgr.getHisto("StackedMC") #hsum = stack.getSumRootHisto() #total = hsum.Integral(0, hsum.GetNbinsX()+1) #for rh in stack.getAllRootHistos(): # dataset._normalizeToFactor(rh, 1/total) #dataset._normalizeToOne(h.histoMgr.getHisto("Data").getRootHisto()) h.addMCUncertainty() opts = {} opts_log = {"ymin": 1e-10, "ymaxfactor": 10, "xmax": 30} opts_log.update(opts) opts2 = {"ymin": 0.5, "ymax": 3} opts2_log = opts2 #opts2_log = {"ymin": 5e-2, "ymax": 5e2} h.createFrame(prefix+"vertices"+postfix, opts=opts, createRatio=ratio, opts2=opts2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() if h.normalizeToOne: histograms.addText(0.35, 0.9, "Normalized to unit area", 17) h.save() h.createFrame(prefix+"vertices"+postfix+"_log", opts=opts_log, createRatio=ratio, opts2=opts2_log) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.getPad1().SetLogy(True) #h.getPad2().SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() if h.normalizeToOne: histograms.addText(0.35, 0.9, "Normalized to unit area", 17) h.save()
def doPlot(datasets, analyses, path, name, rootFile=None, rootHistoName=None): histos = [] legends = {"Plus": "#tau-jet energy scale variated by +3 %", "Minus": "#tau-jet energy scale variated by -3 %"} for aname, analysis in analyses: p = None if isinstance(path, basestring): p = plots.DataMCPlot(datasets, analysis+"/"+path) else: p = plots.DataMCPlot(datasets, path.clone(tree=analysis+"/tree")) if normalize: tauEmbedding.scaleNormalization(p) h = p.histoMgr.getHisto("Data") h.setName(aname) h.setLegendLabel(legends.get(aname, aname)) histos.append(h) p = plots.ComparisonManyPlot(histos[0], histos[1:]) p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20)) if rootFile: baseline = histos[0].getRootHisto().Clone("EWKtau_"+rootHistoName) baseline.SetDirectory(rootFile) baseline.Write() plus = histos[1].getRootHisto().Clone("EWKtau_JESUp_"+rootHistoName) plus.SetDirectory(rootFile) plus.Write() minus = histos[2].getRootHisto().Clone("EWKtau_JESDown_"+rootHistoName) minus.SetDirectory(rootFile) minus.Write() styles.mcStyle(p.histoMgr.getHisto("Plus")) styles.mcStyle2(p.histoMgr.getHisto("Minus")) p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2) p.setLuminosity(datasets.getDataset("Data").getLuminosity()) p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 40}) yaxis = p.getFrame2().GetYaxis() yaxis.SetTitle("Ratio") #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8) p.setLegend(histograms.moveLegend(histograms.createLegend())) p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})") p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}") p.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() p.addLuminosityText() p.save()
def jetMultiplicity(h, prefix=""): h.stackMCHistograms() h.addMCUncertainty() h.createFrame(prefix+"njets_log", xmin=3, xmax=10, ymin=0.1, yfactor=2) h.frame.GetXaxis().SetTitle("Jet multiplicity") h.frame.GetYaxis().SetTitle("Number of events") h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def muonD0(): # Muon track ip w.r.t. beam spot h = Plot(datasets, lastSelection+"/muon_trackDB") h.stackMCHistograms() h.createFrame(lastSelection+"_muon_trackdb", xmin=0, xmax=0.2, ymin=0.1) h.frame.GetXaxis().SetTitle("Muon track d_{0}(Bsp) (cm)") h.frame.GetYaxis().SetTitle("Number of muons") h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def dataMCExample(datasets): # Create data-MC comparison plot, with the default # - legend labels (defined in plots._legendLabels) # - plot styles (defined in plots._plotStyles, and in styles) # - drawing styles ('HIST' for MC, 'EP' for data) # - legend styles ('L' for MC, 'P' for data) plot = plots.DataMCPlot(datasets, analysis + "/SelectedTau_pT_AfterTauID") # Example of how to rebin all histograms in a histogram manager of a plot plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) # Stack all MC histograms, except signal # The stacked histograms become filled plot.stackMCHistograms() # Add MC statistical uncertainty band, calculated as a total of # the stacked histograms plot.addMCUncertainty() # Create the cancas and the frame, with a file name of taupt #plot.createFrame("taupt") # give explicitly some of the boundaries, leave the rest to be the default plot.createFrame("taupt", opts={"ymin": 1e-1, "ymaxfactor": 10}) # give explicitly the x and y axis boundaries #plot.createFrame("taupt", opts={"xmin":40, "xmax":100, "ymin":1e-4, "ymaxfactor": 10}) # Set Y axis to logarithmic plot.getPad().SetLogy(True) # Create legend to the default position plot.setLegend(histograms.createLegend()) # to a fixed position #plot.setLegend(histograms.createLegend(0.7, 0.6, 0.9, 0.9)) # to the default position, move the legend after that, and change the width and height #plot.setLegend(histograms.moveLegend(histograms.createLegend(), dx=0.1, dy=-0.1, dw=0.1, dh=-0.1) # Set X/Y axis labels via TAxis plot.frame.GetXaxis().SetTitle("Tau p_{T} (GeV/c)") plot.frame.GetYaxis().SetTitle("Number of events") # Draw the plot plot.draw() # Add the various texts to histograms.addCmsPreliminaryText() histograms.addEnergyText() plot.addLuminosityText() # Save the plot to files plot.save()
def dataMCExample(datasets): # Create data-MC comparison plot, with the default # - legend labels (defined in plots._legendLabels) # - plot styles (defined in plots._plotStyles, and in styles) # - drawing styles ('HIST' for MC, 'EP' for data) # - legend styles ('L' for MC, 'P' for data) plot = plots.DataMCPlot(datasets, analysis+"/SelectedTau_pT_AfterTauID") # Example of how to rebin all histograms in a histogram manager of a plot plot.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) # Stack all MC histograms, except signal # The stacked histograms become filled plot.stackMCHistograms() # Add MC statistical uncertainty band, calculated as a total of # the stacked histograms plot.addMCUncertainty() # Create the cancas and the frame, with a file name of taupt #plot.createFrame("taupt") # give explicitly some of the boundaries, leave the rest to be the default plot.createFrame("taupt", opts={"ymin": 1e-1, "ymaxfactor": 10}) # give explicitly the x and y axis boundaries #plot.createFrame("taupt", opts={"xmin":40, "xmax":100, "ymin":1e-4, "ymaxfactor": 10}) # Set Y axis to logarithmic plot.getPad().SetLogy(True) # Create legend to the default position plot.setLegend(histograms.createLegend()) # to a fixed position #plot.setLegend(histograms.createLegend(0.7, 0.6, 0.9, 0.9)) # to the default position, move the legend after that, and change the width and height #plot.setLegend(histograms.moveLegend(histograms.createLegend(), dx=0.1, dy=-0.1, dw=0.1, dh=-0.1) # Set X/Y axis labels via TAxis plot.frame.GetXaxis().SetTitle("Tau p_{T} (GeV/c)") plot.frame.GetYaxis().SetTitle("Number of events") # Draw the plot plot.draw() # Add the various texts to histograms.addCmsPreliminaryText() histograms.addEnergyText() plot.addLuminosityText() # Save the plot to files plot.save()
def transverseMass(plot,name): plot.histoMgr.forHisto("EWK", styles.StyleFill(styles.ttStyle)) plot.stackMCHistograms() plot.setLegend(histograms.createLegend(0.7, 0.68, 0.9, 0.93)) plot.createFrame(name, opts={"ymin": 1e-1, "ymaxfactor": 10}) # Set Y axis to logarithmic plot.getPad().SetLogy(True) plot.frame.GetXaxis().SetTitle("MET (GeV)") plot.frame.GetYaxis().SetTitle("Events / %.0f GeV" % plot.binWidth()) plot.draw() # Add the various texts to histograms.addCmsPreliminaryText() histograms.addEnergyText() plot.addLuminosityText() plot.save()
def plotDataEwkDiff(mT, name): data = dataEwkDiff(mT, name) data.SetName("Data-EWK") # Draw the subtracted plot plot = plots.PlotBase([data]) plot.createFrame(name, opts={"ymin": 1e-1, "ymaxfactor": 10}) plot.frame.GetXaxis().SetTitle("MET (GeV)") plot.frame.GetYaxis().SetTitle("Data - EWK") # Set Y axis to logarithmic plot.getPad().SetLogy(True) plot.draw() # Add the various texts to histograms.addCmsPreliminaryText() histograms.addEnergyText() # plot.addLuminosityText() plot.save()
def muonPt(h, prefix="", rebin=1, ratio=False, cutBox=None): xlabel = "Muon p_{T} (GeV/c)" ylabel = "Events / %.0f GeV/c" #ylabel = "Number of events / 5.0 GeV/c" _optsLin = {} _optsLog = {"ymin": 0.1, "ymaxfactor": 2} _opts2 = {"ymin": 0, "ymax": 2} if rebin > 1: h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) ylabel = ylabel % h.binWidth() h.stackMCHistograms() h.addMCUncertainty() # tmp = h.histoMgr.getHisto("Data").getRootHisto() # dataEvents = tmp.Integral(0, tmp.GetNbinsX()+1) # tmp = h.histoMgr.getHisto("StackedMC").getSumRootHisto() # mcEvents = tmp.Integral(0, tmp.GetNbinsX()+1) # print "Muon pt Data/MC = %f/%f = %f" % (dataEvents, mcEvents, dataEvents/mcEvents) h.createFrame(prefix+"muon_pt", opts=_optsLin) if cutBox != None: h.addCutBoxAndLine(**cutBox) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"muon_pt_log", createRatio=ratio, opts=_optsLog, opts2=_opts2) if cutBox != None: h.addCutBoxAndLine(**cutBox) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.moveLegend(histograms.createLegend())) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def wTransMass(h, prefix="", rebin=10): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(10)) xlabel = "m_{T}(#mu, MET) (GeV/c)" ylabel = "Number of events / %.0f GeV/c^{2}" % h.binWidth() h.stackMCHistograms() h.addMCUncertainty() h.createFrame(prefix+"wtmass_log", ymin=0.1, xmax=350, yfactor=2) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.histoMgr.addLuminosityText() h.save()
def vertexCount(h, prefix="", postfix=""): xlabel = "Number of vertices" ylabel = "A.u." h.stackMCHistograms() stack = h.histoMgr.getHisto("StackedMC") #hsum = stack.getSumRootHisto() #total = hsum.Integral(0, hsum.GetNbinsX()+1) #for rh in stack.getAllRootHistos(): # dataset._normalizeToFactor(rh, 1/total) #dataset._normalizeToOne(h.histoMgr.getHisto("Data").getRootHisto()) h.addMCUncertainty() opts = {"xmax": 16} opts_log = {"ymin": 1e-10, "ymaxfactor": 10} opts_log.update(opts) h.createFrame(prefix+"vertices"+postfix, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix+"vertices"+postfix+"_log", opts=opts_log) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() h.save()
def vertexCount(h, prefix="", postfix=""): xlabel = "Number of vertices" ylabel = "A.u." h.stackMCHistograms() stack = h.histoMgr.getHisto("StackedMC") #hsum = stack.getSumRootHisto() #total = hsum.Integral(0, hsum.GetNbinsX()+1) #for rh in stack.getAllRootHistos(): # dataset._normalizeToFactor(rh, 1/total) #dataset._normalizeToOne(h.histoMgr.getHisto("Data").getRootHisto()) h.addMCUncertainty() opts = {"xmax": 16} opts_log = {"ymin": 1e-10, "ymaxfactor": 10} opts_log.update(opts) h.createFrame(prefix + "vertices" + postfix, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() h.save() h.createFrame(prefix + "vertices" + postfix + "_log", opts=opts_log) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) ROOT.gPad.SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() # histograms.addLuminosityText(x=None, y=None, lumi=191.) h.histoMgr.addLuminosityText() h.save()
def transverseMass(h, step="", rebin=5, particle="#tau"): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "m_{T}(%s, MET) (GeV/c^{2})" % particle ylabel = "Events / %.2f GeV/c^{2}" % h.binWidth() opts = {"ymaxfactor": 2} h.stackMCHistograms() h.addMCUncertainty() if h.normalizeToOne: ylabel = "A.u." opts["yminfactor"] = 1e-5 else: opts["ymin"] = 0.001 opts["xmax"] = 200 name = "transverseMassSimulateEmbedded_%s_log" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) ROOT.gPad.SetLogy(True) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save() name = "transverseMassSimulateEmbedded_%s" % step h.createFrameFraction(name, opts=opts) #h.createFrame(name, opts=opts) h.frame.GetXaxis().SetTitle(xlabel) h.frame.GetYaxis().SetTitle(ylabel) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
def doPlot(datasetsEmb, analyses, path, name, text): histos = [] legends = { "Plus": "#tau-jet energy scale variated by +3 %", "Minus": "#tau-jet energy scale variated by -3 %" } for aname, analysis in analyses: (rootHisto, tmp) = datasetsEmb.getHistogram("Data", analysis + "/" + path) h = histograms.Histo(rootHisto, aname) h.setLegendLabel(legends.get(aname, aname)) h.setDrawStyle("EP") h.setLegendStyle("p") histos.append(h) p = plots.ComparisonManyPlot(histos[0], histos[1:]) p.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(20)) styles.dataStyle(p.histoMgr.getHisto("Baseline")) styles.mcStyle(p.histoMgr.getHisto("Plus")) styles.mcStyle2(p.histoMgr.getHisto("Minus")) p.histoMgr.getHisto("Minus").getRootHisto().SetMarkerSize(2) p.setLuminosity(datasetsEmb.getLuminosity()) p.createFrame(name, createRatio=True, opts2={"ymax": 2}, opts={"ymax": 35}) yaxis = p.getFrame2().GetYaxis() yaxis.SetTitle("Ratio") #yaxis.SetTitleSize(yaxis.GetTitleSize()*0.8) p.setLegend(histograms.moveLegend(histograms.createLegend())) p.appendPlotObject(histograms.PlotText(0.5, 0.55, text, size=20)) p.frame.GetXaxis().SetTitle("m_{T}(#tau jet, E_{T}^{miss}) (GeV/c^{2})") p.frame.GetYaxis().SetTitle("Events / 20 GeV/c^{2}") p.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() p.addLuminosityText() p.save()
def plotHisto(self,histo,canvasName): plot = plots.PlotBase() plot.histoMgr.appendHisto(histograms.Histo(histo,histo.GetName())) plot.createFrame(canvasName+self.label, opts={"ymin": 0.1, "ymaxfactor": 2.}) histograms.addCmsPreliminaryText() histograms.addEnergyText() histograms.addLuminosityText(x=None, y=None, lumi=self.lumi) plot.getPad().SetLogy(True) integralValue = int(0.5 + histo.Integral(0,histo.GetNbinsX(),"width")) print histo.GetName(),"Integral",histo.Integral(0,histo.GetNbinsX(),"width") histograms.addText(0.4,0.7,"Integral = %s ev"% integralValue) match = re.search("aseline",histo.GetName()) if match: self.nBaseQCD = integralValue match = re.search("nverted",histo.GetName()) if match: self.nInvQCD = integralValue self.plotIntegral(plot, histo.GetName())
def selectionFlow(h, name, rebin=1, ratio=False): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "Cut" ylabel = "Events" #h.stackMCSignalHistograms() h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) njets = 5 lastSelection = njets opts = { "xmax": lastSelection, "ymin": 0.1, "ymaxfactor": 2, "nbins": lastSelection } opts2 = {"ymin": 0.5, "ymax": 1.5} h.createFrame(name, opts=opts, createRatio=ratio, opts2=opts2) xaxis = h.getFrame().GetXaxis() xaxis.SetBinLabel(1, "Trigger") xaxis.SetBinLabel(2, "#tau ID+R_{#tau}") xaxis.SetBinLabel(3, "e veto") xaxis.SetBinLabel(4, "#mu veto") xaxis.SetBinLabel(5, "N_{jets}") h.getPad().SetLogy(True) h.setLegend(histograms.createLegend()) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() h.addLuminosityText() addMassBRText(x=0.4, y=0.87) h.save()
def selectionFlow(h, name, rebin=1, ratio=False): h.histoMgr.forEachHisto(lambda h: h.getRootHisto().Rebin(rebin)) xlabel = "Cut" ylabel = "Events" h.stackMCHistograms() h.addMCUncertainty() scaleMCfromWmunu(h) opts = {"xmax": 7, "ymin": 0.01, "ymaxfactor": 2} opts2 = {"ymin": 0.5, "ymax": 1.5} if ratio: h.createFrameFraction(name, opts=opts, opts2=opts2) else: h.createFrame(name, opts=opts) h.getPad().SetLogy(True) h.setLegend(histograms.createLegend(0.7, 0.6, 0.9, 0.9)) h.draw() histograms.addCmsPreliminaryText() histograms.addEnergyText() #h.addLuminosityText() h.save()
h.addMCUncertainty() # Create canvas and frame for only the distributions h.createFrame("taupt_new") h.frame.GetXaxis().SetTitle("#tau p_T (GeV/c)") h.frame.GetYaxis().SetTitle("#tau cands / 1 GeV/c") # Create legend h.setLegend(histograms.createLegend()) # Draw the histograms and the legend h.draw() # Add the necessary pieces of text histograms.addCmsPreliminaryText() histograms.addEnergyText() h.addLuminosityText() # Save to .png, .eps and .C file h.save() # counters = "qcdMeasurementMethod2Part1Counters/weighted" # Same, but create two pads, one for the distributions and another for # the data/MC h = plots.DataMCPlot( datasets, "qcdMeasurementMethod2Part1Counters/TauSelection_all_tau_candidates_pt") h.stackMCHistograms() h.addMCUncertainty() h.createFrameFraction("taupt_new2", ) h.frame.GetXaxis().SetTitle("#tau p_{T} (GeV/c)")
def doPlots(table, onlyWjets, mcEvents, normalize, lumi): nrows = table.getNrows() function = ROOT.TF1("fitFunction", "[0]") function.SetParameter(0, 0) f2 = ROOT.TF1("fitG", "gaus") f2.SetLineColor(ROOT.kRed) f2.SetLineWidth(2) binning = { "Data": (8, 60, 100), "Diboson": (8, 0, 2), "DYJetsToLL": (8, 1, 5), "EWKMCsum": (8, 40, 120), "SingleTop": (8, 3, 6), "TTJets": (10, 25, 35), "W3Jets": (10, 6, 11), "WJets": (14, 10, 80), } if onlyWjets: binning["WJets"] = (24, 10, 90) if not normalize: binning["Data"] = (10, 70, 120) binning["EWKMCsum"] = (6, 60, 120) binning["SingleTop"] = (8, 4, 6) binning["TTJets"] = (10, 32, 42) binning["W3Jets"] = (12, 6, 12) if onlyWjets: binning["WJets"] = (10, 20, 60) if mcEvents: binning["TTJets"] = (12, 320, 440) binning["WJets"] = (24, 30, 90) for icol in xrange(table.getNcolumns()): name = table.getColumnNames()[icol] label = plots._legendLabels.get(name, name) if name != "Data": label += " simulation" h = ROOT.TH1F(name, name, nrows, 0, nrows) h2 = ROOT.TH1F(name+"_dist", name, *(binning.get(name, (10, 0, 100)))) mean = dataset.Count(0, 0) for irow in xrange(nrows): count = table.getCount(irow, icol) h.SetBinContent(irow+1, count.value()) h.SetBinError(irow+1, count.uncertainty()) h2.Fill(count.value()) mean.add(count) mean = dataset.Count(mean.value()/nrows, mean.uncertainty()/nrows) h.Fit("fitFunction") value = function.GetParameter(0) error = function.GetParError(0) # function.SetParameters(1., 40., 1.); # function.SetParLimits(0, 0.0, 1.0); # fitResult = graph.Fit(function, "NRSE+EX0"); # print "Fit status", fitResult.Status() # #fitResult.Print("V"); # #fitResult.GetCovarianceMatrix().Print(); # function.SetLineColor(graph.GetMarkerColor()); # function.SetLineWidth(2); function.Draw("same") ROOT.gPad.Update() stat = h.FindObject("stats") if stat: stat.SetX1NDC(0.2) stat.SetX2NDC(0.44) stat.SetY1NDC(0.2) stat.SetY2NDC(0.3) stat.SetTextColor(ROOT.kRed) stat.SetLineColor(ROOT.kRed) # return (function, fitResult) styles.dataStyle.apply(h) p = plots.PlotBase([h]) p.histoMgr.setHistoDrawStyle(name, "EP") p.createFrame("fluctuation_"+name, opts={"ymin": 0, "ymaxfactor": 1.2, "nbins": nrows}) p.frame.GetXaxis().SetTitle("Embedding trial number") ylabel = "Simulation" if name == "Data": ylabel = "Data" ylabel += " events" p.frame.GetYaxis().SetTitle(ylabel) step = 1 start = 0 if onlyWjets: start = 4 step = 5 for irow in xrange(start, nrows, step): p.frame.GetXaxis().SetBinLabel(irow+1, "%d"%(irow+1)) xmin = p.frame.GetXaxis().GetXmin() xmax = p.frame.GetXaxis().GetXmax() leg = histograms.moveLegend(histograms.createLegend(), dx=-0.07, dy=-0.6, dh=-0.15) leg.AddEntry(h, "Trial values", "P") def createLine(val, st=1, col=ROOT.kRed): l = ROOT.TLine(xmin, val, xmax, val) l.SetLineWidth(2) l.SetLineStyle(st) l.SetLineColor(col) return l fv = createLine(value) leg.AddEntry(fv, "Fitted value", "L") p.appendPlotObject(fv) # fe = createLine(value+error, ROOT.kDashed) # leg.AddEntry(fe, "Fit uncertainty", "L") # p.appendPlotObject(fe) # p.appendPlotObject(createLine(value-error, ROOT.kDashed)) v = createLine(mean.value(), col=ROOT.kBlue) leg.AddEntry(v, "Mean", "L") p.appendPlotObject(v) ve = createLine(mean.value()+mean.uncertainty(), st=ROOT.kDashed, col=ROOT.kBlue) leg.AddEntry(ve, "Mean uncertainty", "L") p.appendPlotObject(ve) p.appendPlotObject(createLine(mean.value()-mean.uncertainty(), st=ROOT.kDashed, col=ROOT.kBlue)) p.legend = leg p.appendPlotObject(histograms.PlotText(0.65, 0.33, label, size=20)) p.draw() if name != "Data": histograms.addCmsPreliminaryText(text="Simulation") histograms.addEnergyText() histograms.addLuminosityText(None, None, lumi) p.save() ############### f2.SetParameter(1, value) h2.Fit("fitG") # f2.Draw("same") ROOT.gPad.Update() stat = h2.FindObject("stats") if stat: stat.SetX1NDC(0.62) stat.SetX2NDC(0.9) stat.SetY1NDC(0.7) stat.SetY2NDC(0.85) stat.SetTextColor(ROOT.kRed) stat.SetLineColor(ROOT.kRed) styles.dataStyle.apply(h2) p = plots.PlotBase([h2]) p.histoMgr.setHistoDrawStyle(name+"_dist", "HIST") p.createFrame("fluctuation_"+name+"_dist", opts={"ymin": 0, "ymaxfactor": 1.4, "nbins": nrows}) p.frame.GetXaxis().SetTitle(ylabel) p.frame.GetYaxis().SetTitle("Occurrances") ymin = p.frame.GetYaxis().GetXmin() ymax = p.frame.GetYaxis().GetXmax() leg = histograms.moveLegend(histograms.createLegend(), dx=-0.07, dy=-0.25, dh=-0.15) leg.AddEntry(h2, "Trials", "F") leg.AddEntry(f2, "Gaussian fit", "L") def createLine2(val, st=1): l = ROOT.TLine(val, ymin, val, ymax) l.SetLineWidth(1) l.SetLineColor(ROOT.kBlue) l.SetLineStyle(st) return l p.appendPlotObject(h2, "FUNC") p.appendPlotObject(stat) p.appendPlotObject(histograms.PlotText(0.65, 0.88, label, size=20)) # fv = createLine2(value) # leg.AddEntry(fv, "Fit of values", "L") # p.appendPlotObject(fv) # fe = createLine2(value+error, ROOT.kDashed) # leg.AddEntry(fe, "Fit of values unc.", "L") # p.appendPlotObject(fe) # p.appendPlotObject(createLine2(value-error, ROOT.kDashed)) p.legend = leg p.draw() if name != "Data": histograms.addCmsPreliminaryText(text="Simulation") histograms.addEnergyText() histograms.addLuminosityText(None, None, lumi) p.save()