def customizePlot(logY, addLuminosityText, ratio, ratioInvert, ratioYlabel, yMin, yMax, yMaxFactor, yMinRatio, yMaxRatio, yMinLog, yMaxFactorLog): # Customise the plot. Use custom y-axis range only if defined in the HistoTemplate creation if yMin == None or yMax == None: drawPlot = plots.PlotDrawer(log=logY, addLuminosityText=True, opts={"ymaxfactor": yMaxFactor}, opts2={"ymin": yMinRatio, "ymax": yMaxRatio}, optsLog={"ymin": yMinLog, "ymaxfactor": yMaxFactorLog}) else: drawPlot = plots.PlotDrawer(log=logY, addLuminosityText=True, opts={"ymin": yMin, "ymax": yMax}, opts2={"ymin": yMinRatio, "ymax": yMaxRatio}, optsLog={"ymin": yMin, "ymax": yMax}) return drawPlot
def doPlot(name, dset, errorlevel, optimizationMode, lumi): print shellStyles.HighlightStyle()+"Generating plots for dataset '%s'"%name+shellStyles.NormalStyle() s = optimizationMode.split("BjetDiscrWorkingPoint") discrName = s[0].replace("OptBjetDiscr","") discrWP = s[1] myPartons = ["B", "C", "G", "Light"] myPartonLabels = ["b#rightarrowb", "c#rightarrowb", "g#rightarrowb", "uds#rightarrowb"] histoObjects = [] results = [] for i in range(len(myPartons)): n = "All%sjets"%myPartons[i] dsetHisto = dset.getDatasetRootHisto(n) dsetHisto.normalizeToLuminosity(lumi) hAll = dsetHisto.getHistogram() #(hAll, hAllName) = dset.getRootHisto(n) if hAll == None: raise Exception("Error: could not find histogram '%s'!"%n) treatNegativeBins(hAll) n = "Selected%sjets"%myPartons[i] dsetHisto = dset.getDatasetRootHisto(n) dsetHisto.normalizeToLuminosity(lumi) hPassed = dsetHisto.getHistogram() #(hPassed, hPassedName) = dset.getRootHisto(n) if hPassed == None: raise Exception("Error: could not find histogram '%s'!"%n) treatNegativeBins(hPassed) # Find proper binning myBinEdges = [] for k in range(1, hPassed.GetNbinsX()+1): if len(myBinEdges) > 0 or hPassed.GetBinContent(k) > 0: myBinEdges.append(hPassed.GetXaxis().GetBinLowEdge(k)) myBinEdges.append(hPassed.GetXaxis().GetBinUpEdge(hPassed.GetNbinsX())) myArray = array.array("d", myBinEdges) hAllNew = hAll.Rebin(len(myArray)-1, "", myArray) hPassedNew = hPassed.Rebin(len(myArray)-1, "", myArray) (hPassed, hAll) = findProperBinning(hPassedNew, hAllNew, myBinEdges, errorlevel) #print myBinEdges # Treat fluctuations for k in range(hPassed.GetNbinsX()+2): if hPassed.GetBinContent(k) > hAll.GetBinContent(k): hPassed.SetBinContent(k, hAll.GetBinContent(k)) # Construct efficiency plot eff = ROOT.TEfficiency(hPassed, hAll) eff.SetStatisticOption(ROOT.TEfficiency.kFNormal) for k in range(hPassed.GetNbinsX()): resultObject = {} resultObject["flavor"] = myPartons[i] resultObject["ptMin"] = hPassed.GetXaxis().GetBinLowEdge(k+1) resultObject["ptMax"] = hPassed.GetXaxis().GetBinUpEdge(k+1) resultObject["eff"] = eff.GetEfficiency(k+1) resultObject["effUp"] = eff.GetEfficiencyErrorUp(k+1) resultObject["effDown"] = eff.GetEfficiencyErrorLow(k+1) resultObject["discr"] = discrName resultObject["workingPoint"] = discrWP results.append(resultObject) #gEff = eff.CreateGraph() styles.styles[i].apply(eff) hobj = histograms.HistoEfficiency(eff, myPartonLabels[i], legendStyle="P", drawStyle="") #hobj = histograms.HistoGraph(gEff, myPartonLabels[i], legendStyle="P", drawStyle="") hobj.setIsDataMC(False, True) histoObjects.append(hobj) myPlot = plots.PlotBase(histoObjects) #myPlot.setLuminosity(-1) # Do not set myPlot.setEnergy("13") #myPlot.setDefaultStyles() myParams = {} myParams["xlabel"] = "Jet p_{T}, GeV" myParams["ylabel"] = "Probability for passing b tagging" myParams["log"] = True myParams["cmsExtraText"] = "Simulation" myParams["cmsTextPosition"] = "outframe" # options: left, right, outframe myParams["opts"] = {"ymin": 1e-3, "ymax": 1.0} #myParams["opts2"] = {"ymin": 0.5, "ymax":1.5} #myParams["moveLegend"] = {"dx": -0.08, "dy": -0.12, "dh": 0.1} # for MC EWK+tt #myParams["moveLegend"] = {"dx": -0.15, "dy": -0.12, "dh":0.05} # for data-driven myParams["moveLegend"] = {"dx": 0.0, "dy": -0.46} # for data-driven drawPlot = plots.PlotDrawer(ratio=False, #stackMCHistograms=False, addMCUncertainty=True, addLuminosityText=False, cmsTextPosition="outframe") drawPlot(myPlot, "%s_%s"%(dset.name, name), **myParams) return results
print "-----" print "nyt tehdaan controlliplotteja jee!" print "-----" _legendLabelQCD = "QCD" _legendLabelQCDdata = "Mis-ID. #tau_{h} (data)" _legendLabelEmbedding = "EWK+t#bar{t} with #tau_{h} (data)" _legendLabelEWKFakes = "EWK+t#bar{t} no #tau_{h} (sim.)" #_legendLabelEWKFakes = "EWK+tt with e/#mu/jet#rightarrow#tau_{h} (sim.)" #print "testataanpas: "******"Data/Bkg. ", ratioCreateLegend=True, ratioType="errorScale", ratioErrorOptions={"numeratorStatSyst": False}, stackMCHistograms=True, addMCUncertainty=True, addLuminosityText=True, cmsTextPosition="outframe") drawPlot2D = plots.PlotDrawer(opts2={"ymin": 0.5, "ymax": 1.5}, ratio=False, #ratioYlabel="Data/Bkg.", ratioCreateLegend=True, #ratioType="errorScale", ratioErrorOptions={"numeratorStatSyst": False}, #stackMCHistograms=True, addMCUncertainty=True, addLuminosityText=True, cmsTextPosition="outframe") ## class ControlPlotMaker: ## Constructor def __init__(self, opts, config, dirname, luminosity, observation, datasetGroups): plots._legendLabels["MCStatError"] = "Bkg. stat." plots._legendLabels["MCStatSystError"] = "Bkg. stat.#oplussyst." plots._legendLabels["BackgroundStatError"] = "Bkg. stat. unc"
def doPlot(name, genuineBDataset, fakeBDataset, errorlevel, optimizationMode, lumi): btagWP = "CSVv2-" + name.split("_")[-1] Verbose("Generating efficiency for discriminator WP \"%s\"" % (btagWP), True) # Definitions s = optimizationMode.split("BjetDiscrWorkingPoint") discrName = s[0].replace("OptBjetDiscr", "") discrWP = s[1] myPartons = ["B", "C", "Light"] myPartonLabels = ["b#rightarrowb", "c#rightarrowb", "guds#rightarrowb"] histoObjects = [] results = [] # For-loop: All partons for i, parton in enumerate(myPartons, 0): counter = i+1 msg = "{:<9} {:>3} {:<1} {:<3} {:<50}".format("Histogram", "%d" % counter, "/", "%s:" % (len(myPartons)), "%s->b for %s" % (parton.lower(), btagWP)) Print(ShellStyles.SuccessStyle() + msg + ShellStyles.NormalStyle(), counter==1) n = "All%sjets" % parton if parton == "B": dsetHisto = genuineBDataset.getDatasetRootHisto(n) elif (parton == "C" or parton == "Light"): dsetHisto = fakeBDataset.getDatasetRootHisto(n) else: raise Exception("This should never be reached") dsetHisto.normalizeToLuminosity(lumi) hAll = dsetHisto.getHistogram() if hAll == None: raise Exception("Error: could not find histogram '%s'!"%n) treatNegativeBins(hAll) n = "Selected%sjets" % parton if parton == "B": dsetHisto = genuineBDataset.getDatasetRootHisto(n) if (parton == "C" or parton == "G" or parton == "Light"): dsetHisto = fakeBDataset.getDatasetRootHisto(n) # Normalise to luminosity dsetHisto.normalizeToLuminosity(lumi) # Get Numerator. Treate -ve bins hPassed = dsetHisto.getHistogram() if hPassed == None: raise Exception("Error: could not find histogram '%s'!"%n) treatNegativeBins(hPassed) # Find proper binning myBinEdges = [] for k in range(1, hPassed.GetNbinsX()+1): if len(myBinEdges) > 0 or hPassed.GetBinContent(k) > 0: myBinEdges.append(hPassed.GetXaxis().GetBinLowEdge(k)) myBinEdges.append(hPassed.GetXaxis().GetBinUpEdge(hPassed.GetNbinsX())) myArray = array.array("d", myBinEdges) hAllNew = hAll.Rebin(len(myArray)-1, "", myArray) hPassedNew = hPassed.Rebin(len(myArray)-1, "", myArray) (hPassed, hAll) = findProperBinning(hPassedNew, hAllNew, myBinEdges, errorlevel) # For-loop: All x-axis bins for k in range(hPassed.GetNbinsX()+2): # Treat fluctuations if hPassed.GetBinContent(k) > hAll.GetBinContent(k): hPassed.SetBinContent(k, hAll.GetBinContent(k)) # Construct efficiency plot eff = ROOT.TEfficiency(hPassed, hAll) eff.SetStatisticOption(ROOT.TEfficiency.kFNormal) # For-loop: All x-axis bins for k in range(hPassed.GetNbinsX()): resultObject = {} resultObject["flavor"] = parton resultObject["ptMin"] = hPassed.GetXaxis().GetBinLowEdge(k+1) resultObject["ptMax"] = hPassed.GetXaxis().GetBinUpEdge(k+1) resultObject["eff"] = eff.GetEfficiency(k+1) resultObject["effUp"] = eff.GetEfficiencyErrorUp(k+1) resultObject["effDown"] = eff.GetEfficiencyErrorLow(k+1) resultObject["discr"] = discrName resultObject["workingPoint"] = discrWP results.append(resultObject) # Apply style styles.styles[i].apply(eff) hobj = histograms.HistoEfficiency(eff, myPartonLabels[i], legendStyle="P", drawStyle="P") hobj.setIsDataMC(False, True) histoObjects.append(hobj) # Create the plot myPlot = plots.PlotBase(histoObjects, saveFormats=[]) myPlot.setLuminosity(lumi) myPlot.setEnergy("13") #myPlot.setDefaultStyles() # Add btag WP to canvas myPlot.appendPlotObject(histograms.PlotText(0.70, 0.48-0.16, btagWP, bold=True, size=20)) # Create the plotting object drawPlot = plots.PlotDrawer(ratio=False, addLuminosityText=False, cmsTextPosition="outframe") # Create the plotting object drawPlot(myPlot, "%s_%s" % ("Hybrid", name), **GetKwargs(name, btagWP, opts)) # Save the plot in custom formats SavePlot(myPlot, name, opts.saveDir, saveFormats = [".C", ".png", ".pdf"]) return results
def makeVariationPlotDetailed(self, prefix, hNominal, hFit, hFitUncertaintyUp, hFitUncertaintyDown): # Make plot plot = plots.PlotBase() hNominalClone = aux.Clone(hNominal) hNominalClone.SetLineColor(ROOT.kBlack) hNominalClone.SetLineWidth(2) hNominalClone.SetMarkerStyle(22) hNominalClone.SetMarkerSize(1.5) # Remove fit line before drawing myFunctions = hNominalClone.GetListOfFunctions() for i in range(0, myFunctions.GetEntries()): myFunctions.Delete() plot.histoMgr.appendHisto( histograms.Histo(hNominalClone, "nominal", drawStyle="e")) hFitClone = aux.Clone(hFit) hFitClone.SetLineColor(ROOT.kMagenta) hFitClone.SetLineWidth(2) plot.histoMgr.appendHisto(histograms.Histo(hFitClone, "fit")) #for j in range(1, self._hFitFineBinning.GetNbinsX()+1): # print "fit: %d: %f"%(j,self._hFitFineBinning.GetBinContent(j)) myColor = 2 for i in range(0, len(hFitUncertaintyUp)): hUpClone = aux.Clone(hFitUncertaintyUp[i]) hUpClone.SetLineStyle(myColor) hUpClone.SetLineColor(ROOT.kBlue) hUpClone.SetLineWidth(2) myColor += 1 plot.histoMgr.appendHisto( histograms.Histo(hUpClone, "Par%d up" % (i))) myColor = 2 for i in range(0, len(hFitUncertaintyDown)): hDownClone = aux.Clone(hFitUncertaintyDown[i]) hDownClone.SetLineStyle(myColor) hDownClone.SetLineColor(ROOT.kRed) hDownClone.SetLineWidth(2) myColor += 1 plot.histoMgr.appendHisto( histograms.Histo(hDownClone, "Par%d down" % (i))) # ugly hardcoding... fitStart = 180 nominal = "Nominal" if "QCD" in self._label: nominal += " multijets" elif "EWK_Tau" in self._label: nominal += " EWK+t#bar{t} with #tau_{h}" elif "MC_faketau" in self._label: nominal += " EWK+t#bar{t} no #tau_{h}" plot.histoMgr.setHistoLegendLabelMany({ "nominal": nominal, "fit": "With fit for m_{T} > %d GeV" % fitStart, "Par0 up": "+1#sigma uncertainty on par.0", "Par0 down": "-1#sigma uncertainty on par.0", "Par1 up": "+1#sigma uncertainty on par.1", "Par1 down": "-1#sigma uncertainty on par.1" }) if self._luminosity is not None: plot.setLuminosity(self._luminosity) myName = "tailfit_detailed_%s_%s" % (self._label, prefix) #plot.createFrame("tailfit_%s_%s"%(self._label,name), opts={"ymin": 1e-5, "ymaxfactor": 2.}) #plot.getPad().SetLogy(True) #histograms.addStandardTexts(lumi=self.lumi) myParams = {} myParams["ylabel"] = "Events / %.0f GeV" myParams["log"] = True myParams["opts"] = {"ymin": 20 * 1e-5} # compensate for the bin width #myParams["divideByBinWidth"] = True myParams["cmsTextPosition"] = "right" myParams["moveLegend"] = { "dx": -0.215, "dy": -0.1, "dh": -0.1, "dw": -0.05 } myParams["xlabel"] = "m_{T} (GeV)" myDrawer = plots.PlotDrawer() myDrawer(plot, myName, **myParams)
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, #"ForDataDrivenCtrlPlots/SelectedTau_pT_AfterStandardSelections" "tauPt", # Since the data datasets were removed, we have to set the luminosity by hand # normalizeToLumi=20000 ) # Same as below, but more compact plots.drawPlot(plot, "taupt", xlabel="Tau p_{T} (GeV/c)", ylabel="Number of events", rebin=10, stackMCHistograms=True, addMCUncertainty=False, addLuminosityText=True, opts={ "ymin": 1e-1, "ymaxfactor": 10 }, log=True, ratio=True) drawPlot = plots.PlotDrawer(stackMCHistograms=True, addMCUncertainty=False, addLuminosityText=True, opts={ "ymin": 1e-1, "ymaxfactor": 1 }) def createDrawPlot(name, **kwargs): drawPlot(plots.DataMCPlot(datasets, name), name, **kwargs) createDrawPlot("tauSelection_/tauEtaTriggerMatched", xlabel="#eta^{#tau jet}", ylabel="Number of events", rebin=2, log=False) createDrawPlot("tauEta", xlabel="#eta^{#tau jet}", ylabel="Number of events", rebin=2, log=False, ratio=True) # createDrawPlot("tauPhi", xlabel="#phi^{#tau jet}", ylabel="Number of events", rebin=2, log=False) # createDrawPlot("Rtau", xlabel="p_{T}^{leading track}/p_{T}^{#tau jet}", ylabel="Number of events", rebin=1, log=True) createDrawPlot("Met", xlabel="E_{T}^{miss} (GeV)", ylabel="Number of events", rebin=5, log=True, ratio=True, opts={ "ymin": 1e-1, "ymaxfactor": 10 }) createDrawPlot("tauPt", xlabel="p_{T}^{#tau jet} (GeV/c)", ylabel="Number of events", rebin=2, log=True) if False: createDrawPlot("electronPt", xlabel="p_{T}^{electron} (GeV/c)", ylabel="Number of events", rebin=2, log=True) createDrawPlot("electronEta", xlabel="#eta^{electron}", ylabel="Number of events", rebin=2, log=False) createDrawPlot("muonPt", xlabel="p_{T}^{muon} (GeV/c)", ylabel="Number of events", rebin=2, log=True) createDrawPlot("muonEta", xlabel="#eta^{muon}", ylabel="Number of events", rebin=2, log=False) createDrawPlot("Nelectrons", xlabel="N_{electrons}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("Nmuons", xlabel="N_{muons}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("bJetPt", xlabel="p_{T}^{b-jet} (GeV/c)", ylabel="Number of events", rebin=1, log=True) createDrawPlot("bjetEta", xlabel="#eta^{b-jet}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("realBJetPt", xlabel="p_{T}^{b-jet} (GeV/c)", ylabel="Number of events", rebin=1, log=True) createDrawPlot("realBJetEta", xlabel="#eta^{b-jet}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("realMaxBJetPt", xlabel="p_{T}^{b-jet} (GeV/c)", ylabel="Number of events", rebin=1, log=True) createDrawPlot("realMaxBJetEta", xlabel="#eta^{b-jet}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("jetEta", xlabel="#eta^{jet}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("jetPhi", xlabel="#phi^{jet}", ylabel="Number of events", rebin=1, log=False) createDrawPlot("SelectedJets", xlabel="Number All Jets", ylabel="Number of events", rebin=1, log=False, ratio=True) createDrawPlot("SelectedBJets", xlabel="Number of B-jets", ylabel="Number of events", rebin=1, log=False) createDrawPlot("SelectedNonBJets", xlabel="Number of Light Jets", ylabel="Number of events", rebin=1, log=False) createDrawPlot("DeltaPhiTauMet", xlabel="#Delta#Phi(#tau,MET)", ylabel="Number of events", rebin=2, log=False, opts={ "ymin": 0, "xmin": 0 }) createDrawPlot("M3jetsVSM2jetsCut", xlabel="p_{T}^{3jets} (GeV/c)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("Pt3Jets", xlabel="p_{T}^{3jets} (GeV/c)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("M3Jets", xlabel="M^{3jets} (GeV)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("Pt2Jets", xlabel="p_{T}^{2jets} (GeV/c)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("M2Jets", xlabel="M^{2jets} (GeV)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("TheeJetPtcut", xlabel="ThreeJetPtcut (GeV/c)", ylabel="Number of events", rebin=4, log=True, opts={ "xmax": 450, "xmin": 0 }) createDrawPlot("DPhi3JetsMet", xlabel="#Delta#phi(3 jets, MET)", ylabel="Number of events", rebin=2, log=True) createDrawPlot("DrTau3Jets", xlabel="#DeltaR(3 jets, #tau jet)", ylabel="Number of events", rebin=2, log=True) createDrawPlot("DphiMinus3jetcut", xlabel="#DeltaR(3 jets, #tau jet)", ylabel="Number of events", rebin=10, log=False, opts={"xmax": 200}) createDrawPlot("JetTauEtSum", xlabel="#Sigma(Jets,#tau jet) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("JetEtSum", xlabel="#Sigma(Jets) (GeV)", ylabel="Number of events", rebin=5, log=False) createDrawPlot("JetTauMetEtSum", xlabel="#Sigma(Jets,#tau jet, MET) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("JetEtSumVsJetTauMetEtSum3JetCut", xlabel="#Sigma(E_{T}) cut (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("JetTauMetEtSum", xlabel="#Sigma(E_{T}) cut (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("PtMaxJet", xlabel="p_{T}^{max jet} (GeV)", ylabel="Number of events", rebin=2, log=False) # createDrawPlot("transverseMass", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=1, log=False, opts={"ymin": 0, "xmin":5, "ymaxfactor": 0.1}) createDrawPlot("transverseMass", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassTriangleCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMass3JetCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMass1Tau", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassGenuineTau", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMass3Jet150", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassDeltaPhiVsMaxPtCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassDeltaR3JetsTauCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassDeltaRCorrCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassWith3JetAndJetSumCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassWith3TopPtVSDrCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassTopMtCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMass3jetsMtCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassTopAndWMassCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassTopMassCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassTopMass3jetsMtCut", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassWCandFound", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("transverseMassDeltaPhi3jetPtCutDiff", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("mt_top_met", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("mt_3jets_met", xlabel="m_{T}(#tau,MET) (GeV)", ylabel="Number of events", rebin=5, log=True) createDrawPlot("TopPtVSDrCut", xlabel="TopPtVSDrCut", ylabel="Number of events", rebin=2, log=False) createDrawPlot("deltaPhiVSmaxPtCut", xlabel="deltaPhiVSmaxPt", ylabel="Number of events", rebin=2, log=False) createDrawPlot("topPt", xlabel="p_{T}^{top}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("topEta", xlabel="#eta^{top}) ", ylabel="Number of events", rebin=2, log=False) createDrawPlot("topMass", xlabel="M_{top}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("topMassIdAllJets", xlabel="M_{top}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("topMassIdBjet", xlabel="M_{top}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("WPt", xlabel="p_{T}^{W}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("WEta", xlabel="#eta^{W}) ", ylabel="Number of events", rebin=2, log=False) createDrawPlot("WMass", xlabel="M_{W}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("WCandMass", xlabel="M_{W}) (GeV)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("deltaR_W_tau", xlabel="#DeltaR(W,tau)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("deltaR_Wb", xlabel="#DeltaR(W,b)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("deltaR_top_tau", xlabel="#DeltaR(top,tau)", ylabel="Number of events", rebin=2, log=False) createDrawPlot("deltaR_jets", xlabel="#DeltaR(jet,jet)", ylabel="Number of events", rebin=2, log=False)
def makeVariationPlotWithSeparateUncertainties(self, prefix, hNominal, hFit, hFitUncertaintyUp, hFitUncertaintyDown, fitmin=180): # Make plot plot = plots.PlotBase() hNominalClone = aux.Clone(hNominal) hNominalClone.SetLineColor(ROOT.kBlack) hNominalClone.SetLineWidth(2) hNominalClone.SetMarkerStyle(22) hNominalClone.SetMarkerSize(1.5) # Remove fit line before drawing myFunctions = hNominalClone.GetListOfFunctions() for i in range(0, myFunctions.GetEntries()): myFunctions.Delete() plot.histoMgr.appendHisto( histograms.Histo(hNominalClone, "nominal", drawStyle="e")) hFitClone = aux.Clone(hFit) hFitClone.SetLineColor(ROOT.kMagenta) hFitClone.SetLineWidth(2) plot.histoMgr.appendHisto(histograms.Histo(hFitClone, "fit")) myColor = 2 for i in range(0, len(hFitUncertaintyUp)): hUpClone = aux.Clone(hFitUncertaintyUp[i]) hUpClone.SetLineStyle(myColor) hUpClone.SetLineColor(ROOT.kBlue) hUpClone.SetLineWidth(2) myColor += 1 plot.histoMgr.appendHisto( histograms.Histo(hUpClone, "Par%d up" % (i))) myColor = 2 for i in range(0, len(hFitUncertaintyDown)): hDownClone = aux.Clone(hFitUncertaintyDown[i]) hDownClone.SetLineStyle(myColor) hDownClone.SetLineColor(ROOT.kRed) hDownClone.SetLineWidth(2) myColor += 1 plot.histoMgr.appendHisto( histograms.Histo(hDownClone, "Par%d down" % (i))) fitStart = fitmin nominal = "Nominal" for key in self._datasetNames: if key in self._label: nominal += ", %s" % self._datasetNames[key] plot.histoMgr.setHistoLegendLabelMany({ "nominal": nominal, "fit": "With fit for m_{T} > %d GeV" % fitStart, "Par0 up": "+1#sigma uncertainty on par.0", "Par0 down": "-1#sigma uncertainty on par.0", "Par1 up": "+1#sigma uncertainty on par.1", "Par1 down": "-1#sigma uncertainty on par.1" }) if self._luminosity is not None: plot.setLuminosity(self._luminosity) myName = "tailfit_detailed_%s%s" % (self._label, prefix) myParams = {} myParams["ylabel"] = "Events / %.0f GeV" myParams["log"] = True myParams["opts"] = { "ymin": 2 * 1e-5, "xmax": 800 } # compensate for the bin width myParams["divideByBinWidth"] = True myParams["cmsTextPosition"] = "right" myParams["moveLegend"] = { "dx": -0.215, "dy": -0.1, "dh": -0.1, "dw": -0.05 } myParams["xlabel"] = "m_{T} (GeV)" myDrawer = plots.PlotDrawer() myDrawer(plot, myName, **myParams)
def makeVariationPlotWithTotalUncertainties(self, prefix, hNominal, hFit, hUp, hDown, fitmin=180): # Make plot plot = plots.PlotBase() hNominalClone = aux.Clone(hNominal) hNominalClone.SetLineColor(ROOT.kBlack) hNominalClone.SetLineWidth(2) hNominalClone.SetMarkerStyle(22) hNominalClone.SetMarkerSize(1.5) # Remove fit line before drawing myFunctions = hNominalClone.GetListOfFunctions() for i in range(0, myFunctions.GetEntries()): myFunctions.Delete() plot.histoMgr.appendHisto( histograms.Histo(hNominalClone, "nominal", drawStyle="pe", legendStyle="pe")) hFitClone = aux.Clone(hFit) hFitClone.SetLineColor(ROOT.kMagenta) hFitClone.SetLineWidth(2) plot.histoMgr.appendHisto(histograms.Histo(hFitClone, "fit")) #for j in range(1, self._hFitFineBinning.GetNbinsX()+1): # print "fit: %d: %f"%(j,self._hFitFineBinning.GetBinContent(j)) hUpClone = aux.Clone(hUp) hUpClone.SetLineStyle(2) hUpClone.SetLineColor(ROOT.kBlue) hUpClone.SetLineWidth(2) plot.histoMgr.appendHisto(histograms.Histo(hUpClone, "Total up")) hDownClone = aux.Clone(hDown) hDownClone.SetLineStyle(2) hDownClone.SetLineColor(ROOT.kRed) hDownClone.SetLineWidth(2) plot.histoMgr.appendHisto(histograms.Histo(hDownClone, "Total down")) fitStart = fitmin nominal = "Nominal" for key in self._datasetNames: if key in self._label: nominal += ", %s" % self._datasetNames[key] plot.histoMgr.setHistoLegendLabelMany({ "nominal": nominal, "fit": "With fit for m_{T} > %d GeV" % fitStart, "Total up": "+1#sigma uncertainty", "Total down": "-1#sigma uncertainty" }) if self._luminosity is not None: plot.setLuminosity(self._luminosity) myName = "tailfit_total_uncertainty_%s%s" % (self._label, prefix) myParams = {} #myParams["ylabel"] = "Events/#Deltabin / %.0f-%.0f GeV" myParams["ylabel"] = "Events / %.0f GeV" myParams["log"] = True myParams["opts"] = { "ymin": 2 * 1e-5, "xmax": 800 } # compensate for the bin width myParams["divideByBinWidth"] = True myParams["cmsTextPosition"] = "right" myParams["moveLegend"] = { "dx": -0.215, "dy": -0.1, "dh": -0.1, "dw": -0.05 } myParams["xlabel"] = "m_{T} (GeV)" myDrawer = plots.PlotDrawer() myDrawer(plot, myName, **myParams)
lumi = None if os.path.exists("limits.json"): f = open("limits.json") data = json.load(f) f.close() lumi = float(data["luminosity"]) # Apply TDR style style = tdrstyle.TDRStyle() histograms.createLegend.moveDefaults(dh=-0.4, dy=-0.2) doPlot(opts, signif, lumi) doPlot(opts, signif, lumi, pvalue=True) drawPlot = plots.PlotDrawer(xlabel="m_{H^{+}} (GeV)", cmsTextPosition="outFrame") def doPlot(opts, signif, lumi, pvalue=False): grObs = None histos = [] if opts.unblinded: grObs = signif.observedGraph(pvalue) histos.append(histograms.HistoGraph(grObs, "Observed", drawStyle="LP")) grExp = signif.expectedGraph(pvalue) histos.append(histograms.HistoGraph(grExp, "Expected", drawStyle="L")) expData = "#it{B}#times#it{B}=%s %%" % signif.lightExpectedSignal() if signif.isHeavyStatus(): expData = "#sigma#times#it{B}=%s pb" % signif.heavyExpectedSignal()