def DrawScatYLine(graph, title, fname, xcoord): #, grid): c = TCanvas("c", "c", 800, 600) graph.SetTitle(title) graph.GetXaxis().SetTitleSize(.04) graph.GetYaxis().SetTitleSize(.04) graph.GetXaxis().SetTitleOffset(1.2) graph.GetYaxis().SetTitleOffset(1.25) graph.GetXaxis().CenterTitle(1) graph.GetYaxis().CenterTitle(1) graph.GetYaxis().SetMaxDigits(4) graph.SetMarkerStyle(20) # Full circle graph.Draw() gPad.Update() # line = TLine(gPad.GetUxmin(),ycoord,gPad.GetUxmax(),ycoord) line = TLine(xcoord, gPad.GetUymin(), xcoord, gPad.GetUymax()) # print(gPad.GetUymin(),gPad.GetUymax()) line.SetLineStyle(2) line.SetLineColor(2) line.SetLineWidth(3) graph.Draw("AP") line.Draw("same") c.SaveAs(fname + ".C") c.SaveAs(fname + ".pdf") return
def get_rank_section(directory): # do Rank histo png imgname = "RankSummary.png" gStyle.SetPadTickY(0) c = TCanvas("ranks", "ranks", 500, 400) #gStyle.SetOptStat(0) c.cd() h = directory.rank_histo rank_histof = TH1F(h.GetName(), "", h.GetNbinsX(), h.GetXaxis().GetXmin(), h.GetXaxis().GetXmax()) rank_histof.SetLineWidth(2) for i in xrange(0, h.GetNbinsX() + 1): rank_histof.SetBinContent(i, h.GetBinContent(i)) h.SetTitle("Ranks Summary;Rank;Frequency") h.Draw("Hist") c.Update() rank_histof.ComputeIntegral() integral = rank_histof.GetIntegral() rank_histof.SetContent(integral) rightmax = 1.1 * rank_histof.GetMaximum() scale = gPad.GetUymax() / rightmax rank_histof.SetLineColor(kRed) rank_histof.Scale(scale) rank_histof.Draw("same") #draw an axis on the right side axis = TGaxis(gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymax(), 0, rightmax, 510, "+L") axis.SetTitle("Cumulative") axis.SetTitleColor(kRed) axis.SetLineColor(kRed) axis.SetLabelColor(kRed) axis.Draw() rank_histof.Draw("Same") c.Print(imgname) page_html = '<div class="span-20"><h2 class="alt"><a name="rank_summary">Ranks Summary</a></h2>' page_html += '<div class="span-19"><img src="%s"></div>' % imgname page_html += '</div> <a href="#top">Top...</a><hr>' return page_html
def __call__(self): h = gPad.GetSelected() if not h: return if not isinstance(h, TH2): return gPad.GetCanvas().FeedbackMode(kTRUE) # erase old position and draw a line at current position px = gPad.GetEventX() py = gPad.GetEventY() uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax() uymin, uymax = gPad.GetUymin(), gPad.GetUymax() pxmin, pxmax = gPad.XtoAbsPixel(uxmin), gPad.XtoAbsPixel(uxmax) pymin, pymax = gPad.YtoAbsPixel(uymin), gPad.YtoAbsPixel(uymax) if self._old != None: gVirtualX.DrawLine(pxmin, self._old[1], pxmax, self._old[1]) gVirtualX.DrawLine(self._old[0], pymin, self._old[0], pymax) gVirtualX.DrawLine(pxmin, py, pxmax, py) gVirtualX.DrawLine(px, pymin, px, pymax) self._old = px, py upx = gPad.AbsPixeltoX(px) x = gPad.PadtoX(upx) upy = gPad.AbsPixeltoY(py) y = gPad.PadtoY(upy) padsav = gPad # create or set the display canvases if not self._cX: self._cX = TCanvas('c2', 'Projection Canvas in X', 730, 10, 700, 500) else: self._DestroyPrimitive('X') if not self._cY: self._cY = TCanvas('c3', 'Projection Canvas in Y', 10, 550, 700, 500) else: self._DestroyPrimitive('Y') self.DrawSlice(h, y, 'Y') self.DrawSlice(h, x, 'X') padsav.cd()
#h_ttLepFinal.Draw("histsame") h_sumWJetsFinal.Draw("histsame") h_sumDiboson.Draw("histsame") h_MET.Draw("e1same") leg.Draw() lt = TLatex() lt.DrawLatexNDC(0.24, 0.85, "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}") lt.DrawLatexNDC(0.24, 0.8, "#scale[0.7]{#bf{t#bar{t} CR (#mu)}}") lt.DrawLatexNDC(0.24, 0.75, "#scale[0.5]{#bf{2-prong (bq) enriched}}") lt.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}") padRatio.cd() gPad.GetUymax() ratio = dataPredRatio(data_=h_MET, totalBkg_=h_TopMatchFinal) ratio.SetLineColor(1) ratio.SetLineWidth(3) ratio.SetMarkerSize(1.5) ratio.GetXaxis().SetLabelSize(0.13) ratio.GetXaxis().SetTitleOffset(1) ratio.GetXaxis().SetTitleSize(0.13) ratio.GetXaxis().SetTickLength(0.1) ratio.GetYaxis().SetLabelSize(0.12) ratio.GetYaxis().SetTitleOffset(0.5) ratio.GetYaxis().SetTitleSize(0.13) ratio.GetYaxis().SetNdivisions(405) ratio.GetYaxis().SetTitle("#frac{Data-Pred}{Pred}") ratio.GetXaxis().SetTitle("Double b score")
def myStack(fname_, region_, isSR, prefitbackgroundlist_, legendname_, colorlist_, regionName_, dirName_, isMerged, pad1ymax_): nbins = 4 edges = arr.array('f') openfile = TFile(fname_) print " " print "*************************" print region_, "for", dirName_ print " " prefit_path = "shapes_prefit/" + region_ + "/" postfit_path = "shapes_fit_b/" + region_ + "/" #get the histograms from prefit directory print "get histograms from", prefit_path print " " backgroundlist_ = [] for j in prefitbackgroundlist_: jh = openfile.Get(prefit_path + j) backgroundlist_.append(jh) if isSR: signal_ = openfile.Get(prefit_path + "signal") edges = arr.array('f') for i in range(nbins): low = backgroundlist_[0].GetXaxis().GetBinLowEdge(i + 1) edges.append(low) up = backgroundlist_[0].GetXaxis().GetBinUpEdge(nbins) edges.append(up) data = openfile.Get(prefit_path + "data") data_ = TH1F("data_", "", nbins, edges) nPoints = data.GetN() for i in range(nPoints): x = ROOT.Double(0) y = ROOT.Double(0) data.GetPoint(i, x, y) k = data_.FindFixBin(x) data_.SetBinContent(k, y) data_.SetBinError(i + 1, data.GetErrorY(i)) prefit_ = openfile.Get(prefit_path + "total_background") #get the histogram from post fit directory print "get histograms from", postfit_path print " " postfit_ = openfile.Get(postfit_path + "total_background") # draw the histograms # leg = myLegend(ncol=2) pad = myPad() pad[1].cd() gPad.SetLogy() data_.SetLineColor(1) data_.SetLineWidth(3) data_.SetMarkerStyle(20) data_.SetMarkerColor(1) data_.SetMarkerSize(1.5) data_.GetXaxis().SetLabelSize(0) data_.GetYaxis().SetLabelSize(0.05) data_.GetYaxis().SetTitleOffset(1.2) data_.GetYaxis().SetTitleSize(0.05) data_.GetYaxis().SetNdivisions(510) data_.SetMaximum(pad1ymax_) data_.GetYaxis().SetTitle("Events/GeV") data_.Draw("e1") hs = THStack("hs", "") for j in range(len(colorlist_)): h = backgroundlist_[j] h.SetFillColor(colorlist_[j]) h.SetLineColor(colorlist_[j]) hs.Add(h, "") leg.AddEntry(h, legendname_[j], "f") hs.Draw("histsame") postfit_.SetLineColor(634) postfit_.SetLineWidth(4) leg.AddEntry(postfit_, "Post-fit", "l") postfit_.Draw("histsame") if isSR: signal_.SetLineColor(416) signal_.SetLineWidth(4) signal_.SetMarkerStyle(21) #signal_.SetMarkerColor(824) leg.AddEntry(signal_, "Signal", "l") signal_.Draw("histsame") leg.AddEntry(data_, "Data", "lep") data_.Draw("e1same") leg.Draw() drawE = drawenergy() for i in drawE: i.Draw() pt4 = TPaveText(0.2577181, 0.815, 0.5580537, 0.875, "brNDC") pt4.SetBorderSize(0) pt4.SetTextAlign(12) pt4.SetFillStyle(0) pt4.SetTextFont(52) pt4.AddText(regionName_) pt4.Draw() pad[2].cd() gPad.GetUymax() leg1 = myLegend(coordinate=[0.5, 0.80, 0.87, 0.95]) leg1.SetTextSize(0.1) prefithist = dataPredRatio(data_=data_, totalBkg_=prefit_) prefithist.SetLineColor(1) prefithist.SetLineWidth(3) prefithist.SetMarkerSize(1.5) prefithist.GetXaxis().SetLabelSize(0.13) prefithist.GetXaxis().SetTitleOffset(1) prefithist.GetXaxis().SetTitleSize(0.13) prefithist.GetXaxis().SetTickLength(0.1) prefithist.GetYaxis().SetLabelSize(0.12) prefithist.GetYaxis().SetRangeUser(-0.5, 0.5) prefithist.GetYaxis().SetTitleOffset(0.5) prefithist.GetYaxis().SetTitleSize(0.13) prefithist.GetYaxis().SetNdivisions(505) prefithist.GetYaxis().SetTitle("#frac{Data-Pred}{Pred}") prefithist.GetXaxis().SetTitle("Recoil (GeV)") leg1.AddEntry(prefithist, "Prefit", "lep") prefithist.Draw("e1") postfithist = dataPredRatio(data_=data_, totalBkg_=postfit_) postfithist.SetLineColor(634) postfithist.SetLineWidth(3) postfithist.SetMarkerSize(1.5) postfithist.SetMarkerColor(634) postfithist.GetYaxis().SetTitle("#frac{Data-Pred}{Pred}") postfithist.GetXaxis().SetTitle("Recoil (GeV)") leg1.AddEntry(postfithist, "Postfit", "lep") postfithist.Draw("e1same") leg1.Draw() if not os.path.exists(dirName_): os.mkdir(dirName_) pad[0].Modified() pad[0].Update() if isMerged: pad[0].SaveAs(dirName_ + region_ + "_merged_2017.pdf") pad[0].SaveAs(dirName_ + region_ + "_merged_2017.png") if not isMerged: pad[0].SaveAs(dirName_ + region_ + "_resolved_2017.pdf") pad[0].SaveAs(dirName_ + region_ + "_resolved_2017.png")
def mistagSFtopEMu(year_, ana_): if year_ == 2017: dir = "monohbb.v06.00.05.2017_NCU/withSingleTop/" + ana_ + "/" if year_ == 2018: dir = "monohbb.v06.00.05.2018_NCU/withSingleTop/" + ana_ + "/" print "Top Electron Region" print " " openfile1 = TFile(dir + "TopE.root") # topmatchTopE = openfile1.Get("h_TopMatch") WmatchTopE = openfile1.Get("h_Wmatch") unmatchTopE = openfile1.Get("h_unmatch") wjetsTopE = openfile1.Get("h_sumWJets") dibosonTopE = openfile1.Get("h_sumDiboson") unsubtractedDataTopE = openfile1.Get("h_Data") failMCsubtractTopE = openfile1.Get("h_ttFailed") passMCsubtractTopE = openfile1.Get("h_ttPassed") subtractedDataTopE = openfile1.Get("SubtractedData") datafailTopE = openfile1.Get("SubtractedDataFailed") datapassTopE = openfile1.Get("SubtractedDataPassed") # totaldataTopE = openfile1.Get("h_totaldata") totalMCtopE = openfile1.Get("h_tt") passedTopEdataBfrSubtract = openfile1.Get("h_Data_Passed") wjetsTopEpassed = openfile1.Get("h_sumWJetsPassed") dibosonTopEpassed = openfile1.Get("h_sumDibosonPassed") failedTopEdataBfrSubtract = openfile1.Get("h_Data_Failed") wjetsTopEfailed = openfile1.Get("h_sumWJetsFailed") dibosonTopEfailed = openfile1.Get("h_sumDibosonFailed") stTopE = openfile1.Get("h_sumST") stTopEpassed = openfile1.Get("h_sumSTPassed") stTopEfailed = openfile1.Get("h_sumSTFailed") print "Top Muon Region" print " " openfile2 = TFile(dir + "TopMu.root") # topmatchTopMu = openfile2.Get("h_TopMatch") WmatchTopMu = openfile2.Get("h_Wmatch") unmatchTopMu = openfile2.Get("h_unmatch") wjetsTopMu = openfile2.Get("h_sumWJets") dibosonTopMu = openfile2.Get("h_sumDiboson") unsubtractedDataTopMu = openfile2.Get("h_Data") failMCsubtractTopMu = openfile2.Get("h_ttFailed") passMCsubtractTopMu = openfile2.Get("h_ttPassed") subtractedDataTopMu = openfile2.Get("SubtractedData") datafailTopMu = openfile2.Get("SubtractedDataFailed") datapassTopMu = openfile2.Get("SubtractedDataPassed") # totaldataTopMu = openfile2.Get("h_totaldata") totalMCtopMu = openfile2.Get("h_tt") passedTopMudataBfrSubtract = openfile2.Get("h_Data_Passed") wjetsTopMupassed = openfile2.Get("h_sumWJetsPassed") dibosonTopMupassed = openfile2.Get("h_sumDibosonPassed") failedTopMudataBfrSubtract = openfile2.Get("h_Data_Failed") wjetsTopMufailed = openfile2.Get("h_sumWJetsFailed") dibosonTopMufailed = openfile2.Get("h_sumDibosonFailed") stTopMu = openfile2.Get("h_sumST") stTopMupassed = openfile2.Get("h_sumSTPassed") stTopMufailed = openfile2.Get("h_sumSTFailed") print "get histograms from root files: done" print " " SubtractedDataPassedTopE = datapassTopE.Clone("SubtractedDataPassedTopE") SubtractedDataPassedTopMu = datapassTopMu.Clone( "SubtractedDataPassedTopMu") #merge histogram" print "merge histograms" print " " topmatchMerge = topmatchTopE + topmatchTopMu WmatchMerge = WmatchTopE + WmatchTopMu unmatchMerge = unmatchTopE + unmatchTopMu wjetsMerge = wjetsTopE + wjetsTopMu stMerge = stTopE + stTopMu dibosonMerge = dibosonTopE + dibosonTopMu unsubtractedDataMerge = unsubtractedDataTopE + unsubtractedDataTopMu failMCsubtractMerge = failMCsubtractTopE.Clone("failMCsubtractMerge") failMCsubtractMerge = failMCsubtractMerge + failMCsubtractTopMu passMCsubtractMerge = passMCsubtractTopE.Clone("passMCsubtractMerge") passMCsubtractMerge = passMCsubtractMerge + passMCsubtractTopMu subtractedDataMerge = subtractedDataTopE + subtractedDataTopMu ttData_fraction = arr.array('d') ttData_error = arr.array('d') totaldataMerge = totaldataTopE + totaldataTopMu totaldata = totaldataMerge.Integral() totaldataMerge.Rebin(14) datafailMerge = datafailTopE + datafailTopMu faildata = datafailMerge.Integral() datafailMerge.Rebin(14) datafailMerge.Sumw2() datafailMerge.Divide(totaldataMerge) frac_ttData_fail = datafailMerge.Integral() ttData_fraction.append(frac_ttData_fail) ttData_error.append(datafailMerge.GetBinError(1)) datapassMerge = datapassTopE + datapassTopMu passdata = datapassMerge.Integral() datapassMerge.Rebin(14) datapassMerge.Sumw2() datapassMerge.Divide(totaldataMerge) frac_ttData_pass = datapassMerge.Integral() ttData_fraction.append(frac_ttData_pass) ttData_error.append(datapassMerge.GetBinError(1)) ttMC_fraction = arr.array('d') ttMC_error = arr.array('d') totalMCmerge = totalMCtopE + totalMCtopMu totalMCmerge.Rebin(14) MCfailTopE = failMCsubtractTopE.Clone("MCfailTopE") MCfailTopMu = failMCsubtractTopMu.Clone("MCfailTopMu") MCfailMerge = MCfailTopE + MCfailTopMu MCfailMerge.Rebin(14) MCfailMerge.Sumw2() MCfailMerge.Divide(totalMCmerge) frac_Failed_fin = MCfailMerge.Integral() ttMC_fraction.append(frac_Failed_fin) ttMC_error.append(MCfailMerge.GetBinError(1)) MCpassTopE = passMCsubtractTopE.Clone("MCpassTopE") MCpassTopMu = passMCsubtractTopMu.Clone("MCpassTopMu") MCpassMerge = MCpassTopE + MCpassTopMu MCpassMerge.Rebin(14) MCpassMerge.Sumw2() MCpassMerge.Divide(totalMCmerge) frac_Passed_fin = MCpassMerge.Integral() ttMC_fraction.append(frac_Passed_fin) ttMC_error.append(MCpassMerge.GetBinError(1)) #print "\nttMC_fraction:", ttMC_fraction #print "ttMC_error:", ttMC_error sfMerge = datapassMerge.Clone("sfMerge") sfMerge.Sumw2() sfMerge.Divide(MCpassMerge) stacklist = [] stacklist.append(dibosonMerge) stacklist.append(stMerge) stacklist.append(wjetsMerge) stacklist.append(unmatchMerge) stacklist.append(WmatchMerge) stacklist.append(topmatchMerge) print "merge histograms: done" print " " print "draw histograms" print " " #----------------------- canvas 1 -----------------------# c1 = TCanvas("c1", "", 800, 900) #width-height c1.SetTopMargin(0.4) c1.SetBottomMargin(0.05) c1.SetRightMargin(0.1) c1.SetLeftMargin(0.15) gStyle.SetOptStat(0) binvalues1 = [] for i in range(14): binvalue = unsubtractedDataMerge.GetBinContent(i) binvalues1.append(binvalue) totalmax = max(binvalues1) + 100 padMain = TPad("padMain", "", 0.0, 0.25, 1.0, 0.97) padMain.SetTopMargin(0.4) padMain.SetRightMargin(0.05) padMain.SetLeftMargin(0.17) padMain.SetBottomMargin(0.03) padMain.SetTopMargin(0.1) padRatio = TPad("padRatio", "", 0.0, 0.0, 1.0, 0.25) padRatio.SetRightMargin(0.05) padRatio.SetLeftMargin(0.17) padRatio.SetTopMargin(0.05) padRatio.SetBottomMargin(0.3) padMain.Draw() padRatio.Draw() padMain.cd() gPad.GetUymax() leg1 = myLegend(coordinate=[0.45, 0.57, 0.65, 0.6]) unsubtractedDataMerge.SetMaximum(totalmax) unsubtractedDataMerge.SetLineColor(1) unsubtractedDataMerge.SetMarkerStyle(20) unsubtractedDataMerge.SetMarkerSize(1.5) unsubtractedDataMerge.GetXaxis().SetLabelSize(0) unsubtractedDataMerge.GetXaxis().SetTitleSize(0) unsubtractedDataMerge.GetXaxis().SetTitle("DDB") unsubtractedDataMerge.GetYaxis().SetTitle("Events/Bin") leg1.AddEntry(unsubtractedDataMerge, "Data", "lep") unsubtractedDataMerge.Draw("e1") stackhisto = myStack(colorlist_=[627, 800, 854, 813, 822, 821], backgroundlist_=stacklist, legendname_=[ "Diboson", "Single Top", "W+Jets", "Top (unmtch.)", "Top (W-mtch.)", "Top (mtch.)" ]) stackhisto[0].Draw("histsame") unsubtractedDataMerge.Draw("e1same") stackhisto[1].Draw() leg1.Draw() lt = TLatex() lt.DrawLatexNDC(0.23, 0.85, "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}") if ana_ == "Inclusive": lt.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}") if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000": words = ana_.split("-") if words[2] == "2000": lt.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}") else: lt.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" + words[2] + " GeV}}") else: words = ana_.split("-") lt.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" + words[2] + " GeV}}") lt.DrawLatexNDC(0.23, 0.8, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}") lt.DrawLatexNDC(0.23, 0.75, "#scale[0.5]{#bf{2-prong (bq) enriched}}") if year_ == 2017: lt.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}") if year_ == 2018: lt.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}") padRatio.cd() gPad.GetUymax() h_totalBkg = topmatchMerge.Clone("h_totalBkg") h_totalBkg = h_totalBkg + WmatchMerge + unmatchMerge + wjetsMerge + dibosonMerge ratio = dataPredRatio(data_=unsubtractedDataMerge, totalBkg_=h_totalBkg) ratio.SetLineColor(1) ratio.SetLineWidth(3) ratio.SetMarkerSize(1.5) ratio.GetXaxis().SetLabelSize(0.13) ratio.GetXaxis().SetTitleOffset(1) ratio.GetXaxis().SetTitleSize(0.13) ratio.GetXaxis().SetTickLength(0.1) ratio.GetYaxis().SetLabelSize(0.12) ratio.GetYaxis().SetTitleOffset(0.5) ratio.GetYaxis().SetTitleSize(0.13) ratio.GetYaxis().SetNdivisions(405) ratio.GetYaxis().SetTitle("#frac{Data-Pred}{Pred}") ratio.GetXaxis().SetTitle("DDB") ratio.Draw("e1") c1.SaveAs(dir + "Merge_all.pdf") # #----------------------- canvas 2 -----------------------# c2 = myCanvas(c="c2") gPad.GetUymax() leg2 = myLegend() binvalues2 = [] for i in range(14): binvalue = subtractedDataMerge.GetBinContent(i) binvalues2.append(binvalue) ttmax = max(binvalues2) + 50 failMCsubtractMerge.SetMaximum(ttmax) failMCsubtractMerge.SetFillColor(821) failMCsubtractMerge.SetLineColor(821) #922 failMCsubtractMerge.GetXaxis().SetTitle("DDB") failMCsubtractMerge.GetYaxis().SetTitle("Events/Bin") leg2.AddEntry(failMCsubtractMerge, "t#bar{t}", "f") passMCsubtractMerge.SetFillColor(622) passMCsubtractMerge.SetLineColor(622) #passMCsubtractMerge.GetXaxis().SetTitle("DDB") #passMCsubtractMerge.GetYaxis().SetTitle("Events/Bin") leg2.AddEntry(passMCsubtractMerge, "t#bar{t} mistag", "f") subtractedDataMerge.SetLineColor(1) subtractedDataMerge.SetMarkerStyle(20) subtractedDataMerge.SetMarkerSize(1.5) #subtractedDataMerge.GetXaxis().SetTitle("DDB") #subtractedDataMerge.GetYaxis().SetTitle("Events/Bin") leg2.AddEntry(subtractedDataMerge, "Subtracted Data", "lep") failMCsubtractMerge.Draw("hist") passMCsubtractMerge.Draw("histsame") subtractedDataMerge.Draw("e1same") leg2.Draw() lt2 = TLatex() if ana_ == "Inclusive": lt2.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}") if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000": words = ana_.split("-") if words[2] == "2000": lt2.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}") else: lt2.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" + words[2] + " GeV}}") else: words = ana_.split("-") lt2.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" + words[2] + " GeV}}") lt2.DrawLatexNDC(0.23, 0.85, "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}") lt2.DrawLatexNDC(0.23, 0.8, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}") lt2.DrawLatexNDC(0.23, 0.75, "#scale[0.5]{#bf{2-prong (bq) enriched}}") if year_ == 2017: lt2.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}") if year_ == 2018: lt2.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}") c2.SaveAs(dir + "Merged_subtrac.pdf") # #----------------------- canvas 3 -----------------------# c3 = myCanvas(c="c3", size=[700, 900]) pad1 = TPad("pad1", "", 0.01, 0.25, 0.93, 1.0) pad1.SetTopMargin(0.1) pad1.SetRightMargin(0.05) pad1.SetLeftMargin(0.17) pad1.SetBottomMargin(0.05) pad2 = TPad("pad2", "", 0.0, 0.0, 0.375, 0.24) pad2.SetTopMargin(0.0) pad2.SetRightMargin(0.0) pad2.SetLeftMargin(0.0) pad2.SetBottomMargin(0.0) pad3 = TPad("pad3", "", 0.38, 0.025, 0.94, 0.25) pad2.SetTopMargin(0.05) pad2.SetRightMargin(0.0) pad2.SetLeftMargin(0.45) pad2.SetBottomMargin(0.2) pad1.Draw() pad2.Draw() pad3.Draw() #* Pad 1 *# pad1.cd() leg3 = myLegend(coordinate=[0.65, 0.4, 0.75, 0.5]) xaxisname = arr.array('d', [1, 2]) zero1 = np.zeros(2) gPad.Modified() gPad.SetGridy() gr1 = TGraphErrors(2, xaxisname, ttMC_fraction, zero1, ttMC_error) gr1.SetTitle("t#bar{t}") gr1.SetLineColor(870) gr1.SetLineWidth(3) gr1.SetMarkerStyle(20) gr1.SetMarkerColor(870) leg3.AddEntry(gr1, "t#bar{t}", "lep") gr2 = TGraphErrors(2, xaxisname, ttData_fraction, zero1, ttData_error) gr2.SetTitle("t#bar{t} Data") gr2.SetLineColor(1) gr2.SetLineWidth(2) gr2.SetMarkerStyle(20) gr2.SetMarkerColor(1) leg3.AddEntry(gr2, "t#bar{t} Data", "lep") mg = TMultiGraph("mg", "") mg.Add(gr1) mg.Add(gr2) mg.GetHistogram().SetMaximum(1.5) mg.GetHistogram().SetMinimum(0) mg.GetYaxis().SetTitle("Fraction") mg.GetXaxis().SetLimits(0, 3) mg.GetXaxis().SetTickLength(0.03) mg.GetXaxis().SetNdivisions(103) mg.GetXaxis().ChangeLabel(2, -1, -1, -1, -1, -1, "Fail") mg.GetXaxis().ChangeLabel(1, -1, 0) mg.GetXaxis().ChangeLabel(-1, -1, 0) mg.GetXaxis().ChangeLabel(3, -1, -1, -1, -1, -1, "Pass") mg.Draw("AP") leg3.Draw() lt3 = TLatex() if ana_ == "Inclusive": lt3.DrawLatexNDC(0.17, 0.92, "#scale[0.7]{#bf{" + ana_ + "}}") if ana_ == "PT-200-350" or ana_ == "PT-350-500" or ana_ == "PT-500-2000": words = ana_.split("-") if words[2] == "2000": lt3.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-Inf GeV}}") else: lt3.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{p_{T} " + words[1] + "-" + words[2] + " GeV}}") else: words = ana_.split("-") lt3.DrawLatexNDC( 0.17, 0.92, "#scale[0.7]{#bf{" + words[0] + " " + words[1] + "-" + words[2] + " GeV}}") lt3.DrawLatexNDC(0.19, 0.855, "#scale[0.8]{CMS} #scale[0.65]{#bf{#it{Internal}}}") lt3.DrawLatexNDC(0.19, 0.805, "#scale[0.7]{#bf{t#bar{t} CR (e+#mu)}}") lt3.DrawLatexNDC(0.19, 0.755, "#scale[0.5]{#bf{2-prong (bq) enriched}}") if year_ == 2017: lt3.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{41.5 fb^{-1} (13 TeV)}}") if year_ == 2018: lt3.DrawLatexNDC(0.71, 0.92, "#scale[0.7]{#bf{58.827 fb^{-1} (13 TeV)}}") lt3.Draw() pad1.Update() #* Pad 2 *# pad2.cd() MCpassMerge.SetFillColor(0) MCpassMerge.SetLineColor(870) MCpassMerge.SetLineWidth(3) MCpassMerge.SetMarkerColor(870) MCpassMerge.SetMarkerStyle(20) MCpassMerge.GetYaxis().SetTitle("Fraction") MCpassMerge.GetYaxis().SetTitleSize(0.09) MCpassMerge.GetYaxis().SetLabelSize(0.1) MCpassMerge.GetYaxis().SetNdivisions(404) MCpassMerge.SetMaximum(0.3) MCpassMerge.SetMinimum(0.0) MCpassMerge.GetXaxis().SetTitle("") MCpassMerge.GetXaxis().SetLabelOffset(0.02) MCpassMerge.GetXaxis().SetLabelSize(0.09) MCpassMerge.GetXaxis().SetNdivisions(104) MCpassMerge.GetXaxis().ChangeLabel(2, -1, -1, -1, -1, -1, "Pass") MCpassMerge.GetXaxis().ChangeLabel(1, -1, 0) MCpassMerge.GetXaxis().ChangeLabel(-1, -1, 0) datapassMerge.SetFillColor(0) datapassMerge.SetLineColor(1) datapassMerge.SetLineWidth(2) datapassMerge.SetMarkerColor(1) datapassMerge.SetMarkerStyle(20) MCpassMerge.Draw("e1") datapassMerge.Draw("e1histsame") #* Pad 3 *# pad3.cd() SF = sfMerge.Integral() print "******" print "mistag SF:", SF SFfinal = round(SF, 3) SFtext = "SF = " + str(SFfinal) mistagSFmax = SF + 0.2 mistagSFmin = SF - 0.2 sfMerge.SetLineColor(797) sfMerge.SetMarkerColor(797) sfMerge.SetLineWidth(3) sfMerge.SetMaximum(mistagSFmax) sfMerge.SetMinimum(mistagSFmin) sfMerge.GetXaxis().SetTitle(" ") sfMerge.GetXaxis().SetLabelOffset(999) sfMerge.GetXaxis().SetLabelSize(0) sfMerge.GetXaxis().SetTickLength(0) sfMerge.GetYaxis().SetLabelSize(0.1) sfMerge.GetYaxis().SetNdivisions(404) sfMerge.GetYaxis().SetTitle(" ") sfMerge.Draw("e1hist") pt = TPaveText(0.21, 0.72, 0.31, 0.8, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(42) pt.SetTextSize(0.1) pt.AddText(SFtext) pt.Draw() c3.SaveAs(dir + "Merge_SF.pdf") # passedBfrSubtactDataMerge = (passedTopEdataBfrSubtract + passedTopMudataBfrSubtract).Integral() failedBfrSubtractDataMerge = (failedTopEdataBfrSubtract + failedTopMudataBfrSubtract).Integral() passbackground = (wjetsTopEpassed + wjetsTopMupassed + dibosonTopEpassed + dibosonTopMupassed + stTopEpassed + stTopMupassed).Integral() failbackground = (wjetsTopEfailed + wjetsTopMufailed + dibosonTopEfailed + dibosonTopMufailed + stTopEfailed + stTopMufailed).Integral() totalbackground = (wjetsMerge + dibosonMerge + stMerge).Integral() #get the statistical uncertainty# dx = ttData_error[1] print "data efficiency error", dx dy = ttMC_error[1] print "MC efficiency error", dy x = datapassMerge.Integral() y = MCpassMerge.Integral() statUnc = TMath.Sqrt(((dx**2) / (y**2)) + ((x**2) * (dy**2) / (y**4))) #print "statistical Uncertainty in Top (e+muon) CR", statUnc #print " " print "relative statistical Uncertainty in Top (e+muon) CR", statUnc / SF * 100, " %" print " " print "DDB Mistag SF and stat: ", round(SF, 3), " +- ", round(statUnc, 3), " (stat)" #print "theoretical statistical uncertainty of data efficiency", TMath.Sqrt((x*(1-x))/(subtractedDataMerge.Integral())) #print "theoretical statistical uncertainty of MC efficiency", TMath.Sqrt((y*(1-y))/(totalMCmerge.Integral())) #print " " header = ["Process", "Number of Events", "Top (e+muon)"] row1 = [ " ", "DDB mistag SF", str(SFfinal) + " +- " + str(round(statUnc, 3)) + " (stat)" ] row2 = ["tt MC", "Pass (not normalized)", ""] row3 = [ " ", "Pass (normalized)", str(round(passMCsubtractMerge.Integral(), 2)) ] row4 = [" ", "Fail (not normalized)", ""] row5 = [ " ", "Fail (normalized)", str(round(failMCsubtractMerge.Integral(), 2)) ] row6 = [" ", "Total (not normalized)", ""] row7 = [" ", "Total (normalized)", str(round(totalMCmerge.Integral(), 2))] inforMC = [row2, row3, row4, row5, row6, row7] row8 = [ "tt DATA", "Pass (before subtraction)", str(round(passedBfrSubtactDataMerge, 2)) ] row9 = [" ", "Pass (after subtraction)", str(round(passdata, 2))] row10 = [ " ", "Fail (before subtraction)", str(round(failedBfrSubtractDataMerge, 2)) ] row11 = [" ", "Fail (after subtraction)", str(round(faildata, 2))] row12 = [ " ", "Total (before subtraction)", str(round(unsubtractedDataMerge.Integral(), 2)) ] row13 = [" ", "Total (after subtraction)", str(round(totaldata, 2))] inforDATA = [row8, row9, row10, row11, row12, row13] row14 = ["Background", "Pass (normalized)", str(round(passbackground, 2))] row15 = [" ", "Fail (normalized)", str(round(failbackground, 2))] row16 = [" ", "Total (normalized)", str(round(totalbackground, 2))] inforBKG = [row14, row15, row16] DDB_mistagSF.makeTable(header, row1, inforMC, inforDATA, inforBKG)
def __call__( self ): h = self.hname if not h: return if not isinstance( h, TH2 ): return gPad.GetCanvas().FeedbackMode( kTRUE ) event = gPad.GetEvent() if (event==1): # left mouse click self.projection = not self.projection elif (event==12): # middle mouse click self.logy = not self.logy # erase old position and draw a line at current position #(gPad coordinate system) px = gPad.GetEventX() py = gPad.GetEventY() # min/max x values visible on the pad (xmin and xmax of the x-axis) uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax() uymin, uymax = gPad.GetUymin(), gPad.GetUymax() # same in pixels pxmin, pxmax = gPad.XtoAbsPixel( uxmin ), gPad.XtoAbsPixel( uxmax ) pymin, pymax = gPad.YtoAbsPixel( uymin ), gPad.YtoAbsPixel( uymax ) # if self.projection: # axis = h.GetYaxis() # else: # axis = h.GetXaxis() scaleY = abs((pymax-pymin) / (uymax-uymin)) scaleX = abs((pxmax-pxmin) / (uxmax-uxmin)) width = 0.0 # arbitrary default value [cm] if self._old: width = self.range[1] - self.range[0] ywidth = int(width * scaleY) xwidth = int(width * scaleX) if self._old != None: if self.projection: # gVirtualX.DrawBox( pxmin, self._old[1]-ywidth, pxmax, self._old[1], kSolid) gVirtualX.DrawLine( pxmin, self._old[1], pxmax, self._old[1]) gVirtualX.DrawLine( pxmin, self._old[1]-ywidth, pxmax, self._old[1]-ywidth) else: # gVirtualX.DrawBox( self._old[0], pymin, self._old[0]+ywidth, pymax, kSolid ) gVirtualX.DrawLine( self._old[0], pymin, self._old[0], pymax) gVirtualX.DrawLine( self._old[0]+xwidth, pymin, self._old[0]+xwidth, pymax) # Normally these calls remove old lines, but we do not need them since we update the pad in the end of DrawSlice # BUG: the lines disappear when the mouse does not move. This happens if this gPad.Update() is called. TODO: How to fix it? # if self.projection: # gVirtualX.DrawLine( pxmin, py, pxmax, py ) # gVirtualX.DrawLine( pxmin, py-ywidth, pxmax, py-ywidth ) # else: # gVirtualX.DrawLine( px, pymin, px, pymax) # gVirtualX.DrawLine( px+xwidth, pymin, px+xwidth, pymax) if self.projection: gPad.SetUniqueID(py) else: gPad.SetUniqueID(px) self._old = px, py upx = gPad.AbsPixeltoX( px ) x = gPad.PadtoX( upx ) upy = gPad.AbsPixeltoY( py ) y = gPad.PadtoY( upy ) padsav = gPad # create or set the display canvases if not self._cX: self._cX = gPad.GetCanvas().GetPad(2) else: self._DestroyPrimitive( 'X' ) if not self._cY: self._cY = gPad.GetCanvas().GetPad(2) else: self._DestroyPrimitive( 'Y' ) if self.projection: self.range = self.DrawSlice( h, y, 'Y' ) else: self.range = self.DrawSlice( h, x, 'X' ) padsav.cd()
def PlotNpv(inputTXT, lumiInp): canvas = makeCMSCanvas(str(random.random()),"Npv",900,700) canvas.Divide(1,2) canvas.cd(2) Npv = [] error = [] lumi = [] lumi_err = [] noerr = [] with open(inputTXT, "r") as Inp: print("Opening " + inputTXT + ".") for line in Inp: cleared_line = line.split(" ") Npv.append(float(cleared_line[0])) error.append(float(cleared_line[1])) sumLumi = 0 for i in range(0,len(lumiInp)): sumLumi += float(lumiInp[i]) lumi.append(sumLumi - float(lumiInp[i])/2) lumi_err.append(float(lumiInp[i])/2) noerr.append(0.) graph1 = TGraphErrors(len(lumiInp),array('d',lumi),array('d',Npv),array('d',lumi_err),array('d',error)) graph2 = TGraphErrors(len(lumiInp),array('d',lumi),array('d',Npv),array('d',lumi_err),array('d',noerr)) graph1.SetTitle("") graph1.GetXaxis().SetTitle("Lumi [fb^{-1}]") graph1.GetXaxis().SetLimits(0.,40.) graph1.GetYaxis().SetTitle("Npv") graph1.SetMarkerStyle(20) graph1.SetMarkerSize(1) graph1.Draw("AP") canvas.cd(1) graph2.SetTitle("") graph2.GetXaxis().SetTitle("Lumi [fb^{-1}]") graph2.GetXaxis().SetLimits(0.,35.) graph2.GetYaxis().SetTitle("Npv") graph2.SetMarkerStyle(20) graph2.SetMarkerSize(1) graph2.Draw("AP") canvas.Update() canvas.cd(2) down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(5.57,down,5.57, up) lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(8.58,down,8.58,up) lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(12.9,down,12.9,up) lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(16.57,down,16.57,up) lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() lineF = TLine(19.7,down,19.7,up) lineF.SetLineColor(kBlack) lineF.SetLineStyle(2) lineF.Draw() lineG = TLine(26.9,down,26.9,up) lineG.SetLineColor(kBlack) lineG.SetLineStyle(2) lineG.Draw() canvas.SaveAs("Npv.pdf") return;
def TwoFileSAME2VsLumi(F1graph1, F1graph2, F2graph1, F2graph2, title, type): canvas = makeCMSCanvas(str(random.random()),"canvas",900,700) canvas.cd() F1graph1.SetMarkerColor(kBlue)#electrons F1graph2.SetMarkerColor(kRed)#muons F2graph1.SetMarkerColor(kBlue)#electrons F2graph2.SetMarkerColor(kRed)#muons F2graph1.SetMarkerStyle(kOpenStar) F2graph2.SetMarkerStyle(kOpenStar) multigraph = TMultiGraph() multigraph.Add(F1graph1,"AP") multigraph.Add(F1graph2,"AP") multigraph.Add(F2graph1,"AP") multigraph.Add(F2graph2,"AP") multigraph.Draw("AP") multigraph.GetXaxis().SetLimits(0.,40.) #TGaxis.SetMaxDigits(2) #TGaxis.SetExponentOffset(-0.06, 0.02, "y") multigraph.GetXaxis().SetTitle("L [fb^{-1}]") multigraph.GetYaxis().SetTitleOffset(1.4) if(type == "ISO"): multigraph.GetYaxis().SetTitle("Isolation") gPad.Modified() multigraph.SetMinimum(0.5*gPad.GetUymin()) multigraph.SetMaximum(1.5*gPad.GetUymax()) elif(type == "SIP"): multigraph.GetYaxis().SetTitle("SIP") printLumiPrelOut(canvas) canvas.Update() down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(5.57,down,5.57, up) lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(8.58,down,8.58,up) lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(12.9,down,12.9,up) lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(16.57,down,16.57,up) lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() lineF = TLine(19.7,down,19.7,up) lineF.SetLineColor(kBlack) lineF.SetLineStyle(2) lineF.Draw() lineG = TLine(26.9,down,26.9,up) lineG.SetLineColor(kBlack) lineG.SetLineStyle(2) lineG.Draw() legend = TLegend(0.80,0.75,0.965,0.93) legend.AddEntry(F1graph1,"e^{+}e^{-}","P") legend.AddEntry(F1graph2,"#mu^{+}#mu^{-}","P") legend.AddEntry(F2graph1,"e^{+}e^{-} ICHEP","P") legend.AddEntry(F2graph2,"#mu^{+}#mu^{-} ICHEP","P") legend.SetTextFont(32) legend.Draw() canvas.SaveAs(title + ".pdf") canvas.SaveAs(title + ".png") return;
def TwoFileSAME3VsLumi(F1graph1, F1graph2, F1graph3, F2graph1, F2graph2, F2graph3, title, type, DoInclusive): canvas = makeCMSCanvas(str(random.random()),"canvas",900,700) canvas.cd() F1graph1.SetMarkerColor(kBlack)#electrons F1graph2.SetMarkerColor(kBlue)#electrons F1graph3.SetMarkerColor(kRed)#muons F2graph1.SetMarkerColor(kBlack)#electrons F2graph2.SetMarkerColor(kBlue)#electrons F2graph3.SetMarkerColor(kRed)#muons F2graph1.SetMarkerStyle(kOpenStar)#inclusive F2graph2.SetMarkerStyle(kOpenStar)#electrons F2graph3.SetMarkerStyle(kOpenStar)#muons multigraph = TMultiGraph() if(DoInclusive or type == "ZmassBARELL" or type == "ZwidthBARELL" or type == "ZmultBARELL"): multigraph.Add(F1graph1,"AP") multigraph.Add(F2graph1,"AP") multigraph.Add(F1graph2,"AP") multigraph.Add(F1graph3,"AP") multigraph.Add(F2graph2,"AP") multigraph.Add(F2graph3,"AP") multigraph.Draw("AP") multigraph.GetXaxis().SetTitle("L [fb^{-1}]") multigraph.GetXaxis().SetLimits(0.,40.) multigraph.GetYaxis().SetTitleOffset(1.4) gPad.Modified() if(type == "Zmass" or type == "ZmassBARELL"): multigraph.SetMaximum(1.008*gPad.GetUymax()) multigraph.GetYaxis().SetTitle("M_{l^{+}l^{-}} [GeV]") elif(type == "Zwidth" or type == "ZwidthBARELL"): multigraph.SetMaximum(1.1*gPad.GetUymax()) multigraph.GetYaxis().SetTitle("#Gamma [GeV]") elif(type == "Zmult" or type == "ZmultBARELL"): multigraph.SetMaximum(1.2*gPad.GetUymax()) multigraph.GetYaxis().SetTitle("#Z") elif(type == "SIP"): multigraph.GetYaxis().SetTitle("SIP") multigraph.SetMaximum(1.1*gPad.GetUymax()) printLumiPrelOut(canvas) canvas.Update() down = gPad.GetUymin() up = gPad.GetUymax() MC_muMass = 90.92 MC_eleMass = 90.63 Data_muMass = 90.95 Data_eleMass = 90.68 lineB = TLine(5.57,down,5.57, up) lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(8.58,down,8.58,up) lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(12.9,down,12.9,up) lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(16.57,down,16.57,up) lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() lineF = TLine(19.7,down,19.7,up) lineF.SetLineColor(kBlack) lineF.SetLineStyle(2) lineF.Draw() lineG = TLine(26.9,down,26.9,up) lineG.SetLineColor(kBlack) lineG.SetLineStyle(2) lineG.Draw() if(type == "Zmass"): lineMC_ele = TLine(0.,MC_eleMass,40., MC_eleMass) lineMC_ele.SetLineColor(kBlue) lineMC_ele.SetLineStyle(1) lineMC_ele.Draw() lineMC_mu = TLine(0.,MC_muMass,40., MC_muMass) lineMC_mu.SetLineColor(kRed) lineMC_mu.SetLineStyle(1) lineMC_mu.Draw() lineData_ele = TLine(0.,Data_eleMass,40., Data_eleMass) lineData_ele.SetLineColor(kBlue) lineData_ele.SetLineStyle(2) lineData_ele.Draw() lineData_mu = TLine(0.,Data_muMass,40., Data_muMass) lineData_mu.SetLineColor(kRed) lineData_mu.SetLineStyle(2) lineData_mu.Draw() legend = TLegend(0.80,0.75,0.965,0.93) if(type == "Zmass" or type == "Zwidth" or type == "Zmult"): legend.AddEntry(F1graph2,"e^{+}e^{-}","P") legend.AddEntry(F1graph3,"#mu^{+}#mu^{-}","P") legend.AddEntry(F2graph2,"e^{+}e^{-} ICHEP","P") legend.AddEntry(F2graph3,"#mu^{+}#mu^{-} ICHEP","P") else: legend.AddEntry(F1graph1,"EBEB","P") legend.AddEntry(F2graph1,"EBEB ICHEP","P") legend.AddEntry(F1graph2,"EBEE","P") legend.AddEntry(F1graph3,"EEEE","P") legend.AddEntry(F2graph2,"EBEE ICHEP","P") legend.AddEntry(F2graph3,"EEEE ICHEP","P") legend.SetTextFont(32) legend.Draw() canvas.SaveAs(title + ".pdf") canvas.SaveAs(title + ".png") return;
def SAME2VsLumi(g1, g2,title, ptype, dataPeriod): canvas = makeCMSCanvas(str(random.random()),"canvas",900,700) canvas.cd() graph1=copy.deepcopy(g1) graph2=copy.deepcopy(g2) graph1.SetMarkerColor(kBlue)#electrons graph2.SetMarkerColor(kRed)#muons multigraph = TMultiGraph() multigraph.Add(graph1,"AP") multigraph.Add(graph2,"AP") multigraph.Draw("AP") TGaxis.SetMaxDigits(2) TGaxis.SetExponentOffset(-0.06, 0.02, "y") multigraph.GetXaxis().SetTitle("L [fb^{-1}]") multigraph.GetYaxis().SetTitleOffset(1.4) if(ptype == "ISO"): multigraph.GetYaxis().SetTitle("Isolation") gPad.Modified() multigraph.SetMinimum(0.5*gPad.GetUymin()) multigraph.SetMaximum(1.5*gPad.GetUymax()) elif(ptype == "SIP"): multigraph.GetYaxis().SetTitle("SIP") multigraph.SetMinimum(min(multigraph.GetHistogram().GetMinimum(),1.)) multigraph.SetMaximum(max(multigraph.GetHistogram().GetMinimum(),2.2)) min(multigraph.GetHistogram().GetMinimum(),1.) printLumiPrelOut(canvas) # Draw legend legend = TLegend(0.93,0.84,0.99,0.93) legend.AddEntry(graph1,"e^{+}e^{-}","P") legend.AddEntry(graph2,"#mu^{+}#mu^{-}","P") legend.SetFillColor(kWhite) legend.SetLineColor(kBlack) legend.SetTextFont(43) legend.SetTextSize(20) legend.Draw() canvas.Update() # Draw letters for data-taking periods if(dataPeriod == "data2017"): textLetters = TLatex() textLetters.SetTextColor(kGray+1) textLetters.SetTextSize(0.03) if(ptype == "ISO"): textLetters.DrawLatex(2., 0.8*gPad.GetUymax(),"B") textLetters.DrawLatex(9.5, 0.8*gPad.GetUymax(),"C") textLetters.DrawLatex(16., 0.8*gPad.GetUymax(),"D") textLetters.DrawLatex(23., 0.8*gPad.GetUymax(),"E") textLetters.DrawLatex(36., 0.8*gPad.GetUymax(),"F") elif(ptype == "SIP"): textLetters.DrawLatex(2., 1.5,"B") textLetters.DrawLatex(9.5, 1.5,"C") textLetters.DrawLatex(16., 1.5,"D") textLetters.DrawLatex(23., 1.5,"E") textLetters.DrawLatex(36., 1.5,"F") if(dataPeriod == "data2018"): textLetters = TLatex() textLetters.SetTextColor(kGray+1) textLetters.SetTextSize(0.03) if(ptype == "ISO"): textLetters.DrawLatex(6., 0.8*gPad.GetUymax(), "A") textLetters.DrawLatex(16., 0.8*gPad.GetUymax(), "B") textLetters.DrawLatex(23., 0.8*gPad.GetUymax(), "C") textLetters.DrawLatex(43., 0.8*gPad.GetUymax(), "D") elif(ptype == "SIP"): textLetters.DrawLatex(6., 1.5, "A") textLetters.DrawLatex(16., 1.5, "B") textLetters.DrawLatex(23., 1.5, "C") textLetters.DrawLatex(43., 1.5, "D") # **** if(dataPeriod == "data2018"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineA = TLine(13.48, down, 13.48, up) # Run2018A up to 13.48 fb-1 lineA.SetLineColor(kBlack) lineA.SetLineStyle(2) lineA.Draw() lineB = TLine(20.265, down, 20.265, up) # Run2018B up to 20.265 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(26.877, down, 26.877, up) # Run2018C up to 26.877 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() # **** if(dataPeriod == "data2017"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(4.793, down, 4.793, up) # Run2017B up to 4.793 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(14.549, down, 14.549, up) # Run2017C up to 14.549 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(18.868, down, 18.868, up) # Run2017D up to 18.868 fb-1 lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(28.293, down, 28.293, up) # Run2017E up to 28.293 fb-1 lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() # **** if(dataPeriod == "data2016"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(5.789, down, 5.789, up) # Run2016B up to 5.789 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(8.366, down, 8.366, up) # Run2016C up to 8.366 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(12.616, down, 12.616, up) # Run2016D up to 12.616 fb-1 lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(16.624, down, 16.624, up) # Run2016E up to 16.624 fb-1 lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() lineF = TLine(19.725, down, 19.725, up) # Run2016F up to 19.725 fb-1 lineF.SetLineColor(kBlack) lineF.SetLineStyle(2) lineF.Draw() lineG = TLine(27.268, down, 27.268, up) # Run2016G up to 27.268 fb-1 lineG.SetLineColor(kBlack) lineG.SetLineStyle(2) lineG.Draw() # **** canvas.SaveAs(title + ".root") canvas.SaveAs(title + ".pdf") canvas.SaveAs(title + ".png") return;
def SAME3VsLumi(g1, g2, g3, title, ptype, lineMC1, lineDATA1, lineMC2, lineDATA2, lineMC3, lineDATA3, DoInclusive, dataPeriod): canvas = makeCMSCanvas(str(random.random()),"canvas",900,700) canvas.cd() graph2=copy.deepcopy(g2) graph3=copy.deepcopy(g3) graph2.SetMarkerColor(kBlue)#electrons graph3.SetMarkerColor(kRed)#muons multigraph = TMultiGraph() if(DoInclusive): graph1=copy.deepcopy(g1) multigraph.Add(graph1,"AP") multigraph.Add(graph2,"AP") multigraph.Add(graph3,"AP") multigraph.Draw("AP") TGaxis.SetMaxDigits(2) TGaxis.SetExponentOffset(-0.05, 0.02, "y") multigraph.GetXaxis().SetTitle("L [fb^{-1}]") multigraph.GetYaxis().SetTitleOffset(1.4) if(ptype == "Zmass"): multigraph.GetYaxis().SetTitle("M_{Z} [GeV]") # multigraph.GetYaxis().SetTitle("M_{l^{+}l^{-}} [GeV]") multigraph.SetMaximum(max(multigraph.GetHistogram().GetMaximum(),91.4)) multigraph.SetMinimum(min(multigraph.GetHistogram().GetMinimum(),89.6)) elif(ptype == "Zwidth"): multigraph.GetYaxis().SetTitle("#Gamma_{Z} [GeV]") elif(ptype == "Zmult"): multigraph.GetYaxis().SetTitle("#Z / fb^{-1}") if(not DoInclusive) : multigraph.SetMaximum(max(multigraph.GetHistogram().GetMaximum(),60000.)) # set y axis minimum at 60000. multigraph.SetMinimum(0.) # set y axis minimum at 0. # multigraph.SetMaximum(60000.) #second type: vs 2016 plots # multigraph.SetMinimum(25000.) printLumiPrelOut(canvas) # Draw legend legend = TLegend(0.93,0.84,0.99,0.93) if(DoInclusive): #legend.AddEntry(graph1,"inclusive","P") legend.AddEntry(graph1,"BB","P") legend.AddEntry(graph2,"BE","P") legend.AddEntry(graph3,"EE","P") else : legend.AddEntry(graph2,"e^{+}e^{-}","P") legend.AddEntry(graph3,"#mu^{+}#mu^{-}","P") legend.SetFillColor(kWhite) legend.SetLineColor(kBlack) legend.SetTextFont(43) legend.SetTextSize(20) legend.Draw() canvas.Update() # Draw letters for data-taking periods if(dataPeriod == "data2017"): textLetters = TLatex() textLetters.SetTextColor(kGray+1) textLetters.SetTextSize(0.03) if(ptype == "Zmass"): textLetters.DrawLatex(2., gPad.GetUymin()+0.2,"B") textLetters.DrawLatex(9.5, gPad.GetUymin()+0.2,"C") textLetters.DrawLatex(16., gPad.GetUymin()+0.2,"D") textLetters.DrawLatex(23., gPad.GetUymin()+0.2,"E") textLetters.DrawLatex(36., gPad.GetUymin()+0.2,"F") elif(ptype == "Zwidth"): textLetters.DrawLatex(2., gPad.GetUymin()+0.3,"B") textLetters.DrawLatex(9.5, gPad.GetUymin()+0.3,"C") textLetters.DrawLatex(16., gPad.GetUymin()+0.3,"D") textLetters.DrawLatex(23., gPad.GetUymin()+0.3,"E") textLetters.DrawLatex(36., gPad.GetUymin()+0.3,"F") elif(ptype == "Zmult") : textLetters.DrawLatex(2., 260000,"B") textLetters.DrawLatex(9.5, 260000,"C") textLetters.DrawLatex(16., 260000,"D") textLetters.DrawLatex(23., 260000,"E") textLetters.DrawLatex(36., 260000,"F") if(dataPeriod == "data2018"): textLetters = TLatex() textLetters.SetTextColor(kGray+1) textLetters.SetTextSize(0.03) if(ptype == "Zmass"): textLetters.DrawLatex(6., gPad.GetUymin() + 0.6,"A") textLetters.DrawLatex(16., gPad.GetUymin() + 0.6,"B") textLetters.DrawLatex(23., gPad.GetUymin() + 0.6,"C") textLetters.DrawLatex(43., gPad.GetUymin() + 0.6,"D") elif(ptype == "Zwidth"): textLetters.DrawLatex(6., gPad.GetUymin() +0.3,"A") textLetters.DrawLatex(16., gPad.GetUymin() +0.3,"B") textLetters.DrawLatex(23., gPad.GetUymin() +0.3,"C") textLetters.DrawLatex(43., gPad.GetUymin() +0.3,"D") elif(ptype == "Zmult") : textLetters.DrawLatex(6., 260000,"A") textLetters.DrawLatex(16., 260000,"B") textLetters.DrawLatex(23., 260000,"C") textLetters.DrawLatex(43., 260000,"D") # **** if(dataPeriod == "data2018"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineA = TLine(13.48, down, 13.48, up) # Run2018A up to 13.48 fb-1 lineA.SetLineColor(kBlack) lineA.SetLineStyle(2) lineA.Draw() lineB = TLine(20.265, down, 20.265, up) # Run2018B up to 20.265 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(26.877, down, 26.877, up) # Run2018C up to 26.877 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() if(dataPeriod == "data2017"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(4.793, down, 4.793, up) # Run2017B up to 4.793 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(14.549, down, 14.549, up) # Run2017C up to 14.549 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(18.868, down, 18.868, up) # Run2017D up to 18.868 fb-1 lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(28.293, down, 28.293, up) # Run2017E up to 28.293 fb-1 lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() if(dataPeriod == "data2016"): # draw vertical lines that divide different data taking periods down = gPad.GetUymin() up = gPad.GetUymax() lineB = TLine(5.789, down, 5.789, up) # Run2016B up to 5.789 fb-1 lineB.SetLineColor(kBlack) lineB.SetLineStyle(2) lineB.Draw() lineC = TLine(8.366, down, 8.366, up) # Run2016C up to 8.366 fb-1 lineC.SetLineColor(kBlack) lineC.SetLineStyle(2) lineC.Draw() lineD = TLine(12.616, down, 12.616, up) # Run2016D up to 12.616 fb-1 lineD.SetLineColor(kBlack) lineD.SetLineStyle(2) lineD.Draw() lineE = TLine(16.624, down, 16.624, up) # Run2016E up to 16.624 fb-1 lineE.SetLineColor(kBlack) lineE.SetLineStyle(2) lineE.Draw() lineF = TLine(19.725, down, 19.725, up) # Run2016F up to 19.725 fb-1 lineF.SetLineColor(kBlack) lineF.SetLineStyle(2) lineF.Draw() lineG = TLine(27.268, down, 27.268, up) # Run2016G up to 27.268 fb-1 lineG.SetLineColor(kBlack) lineG.SetLineStyle(2) lineG.Draw() # **** # draw orizontal lines for MC and DATA fit if(ptype == "Zmass" or ptype == "Zwidth") : leftEnd = gPad.GetUxmin() rightEnd = gPad.GetUxmax() if(DoInclusive): line1 = TLine(leftEnd,lineMC1,rightEnd,lineMC1) line1.SetLineColor(kBlack) line1.SetLineStyle(1) line1.Draw() line2 = TLine(leftEnd,lineDATA1,rightEnd,lineDATA1) line2.SetLineColor(kBlack) line2.SetLineStyle(2) line2.Draw() # line for graph 2: color blue line3 = TLine(leftEnd,lineMC2,rightEnd,lineMC2) line3.SetLineColor(kBlue) line3.SetLineStyle(1) line3.Draw() line4 = TLine(leftEnd,lineDATA2,rightEnd,lineDATA2) line4.SetLineColor(kBlue) line4.SetLineStyle(2) line4.Draw() # line for graph 3: color red line5 = TLine(leftEnd,lineMC3,rightEnd,lineMC3) line5.SetLineColor(kRed) line5.SetLineStyle(1) line5.Draw() line6 = TLine(leftEnd,lineDATA3,rightEnd,lineDATA3) line6.SetLineColor(kRed) line6.SetLineStyle(2) line6.Draw() # *** canvas.SaveAs(title + ".root") canvas.SaveAs(title + ".pdf") canvas.SaveAs(title + ".png") return;
def drawhist(isMET, reg, dirPath): path_before = "analysis_histogram/2018_old/" path_after = "analysis_histogram/2018_hem_cut_updated/" if isMET: openfcomb = TFile(path_before + "combined_data_MET.root") openfAB = TFile(path_before + "combined_data_MET_AB.root") openfCD_bfr = TFile(path_before + "combined_data_MET_CD.root") openfCD = TFile(path_after + "combined_data_MET_CD.root") h_jet1phi_1b = [] jet1phi_comb_top1b = openfcomb.Get("h_reg_TopmunuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_comb_top1b) jet1phi_AB_top1b = openfAB.Get("h_reg_TopmunuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_AB_top1b) jet1phi_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopmunuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_CD_bfr_top1b) jet1phi_CD_top1b = openfCD.Get("h_reg_TopmunuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_CD_top1b) h_jet1eta_1b = [] jet1eta_comb_top1b = openfcomb.Get("h_reg_TopmunuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_comb_top1b) jet1eta_AB_top1b = openfAB.Get("h_reg_TopmunuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_AB_top1b) jet1eta_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopmunuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_CD_bfr_top1b) jet1eta_CD_top1b = openfCD.Get("h_reg_TopmunuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_CD_top1b) #h_MET_1b = [] #MET_comb_top1b = openfcomb.Get("h_reg_TopmunuCR_1b_MET") #h_MET_1b.append(MET_comb_top1b) #MET_AB_top1b = openfAB.Get("h_reg_TopmunuCR_1b_MET") #h_MET_1b.append(MET_AB_top1b) #MET_CD_top1b = openfCD.Get("h_reg_TopmunuCR_1b_MET") #h_MET_1b.append(MET_CD_top1b) h_METphi_1b = [] METphi_comb_top1b = openfcomb.Get("h_reg_TopmunuCR_1b_METPhi") h_METphi_1b.append(METphi_comb_top1b) METphi_AB_top1b = openfAB.Get("h_reg_TopmunuCR_1b_METPhi") h_METphi_1b.append(METphi_AB_top1b) METphi_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopmunuCR_1b_METPhi") h_METphi_1b.append(METphi_CD_bfr_top1b) METphi_CD_top1b = openfCD.Get("h_reg_TopmunuCR_1b_METPhi") h_METphi_1b.append(METphi_CD_top1b) h_RecoilPhi_1b = [] RecoilPhi_comb_top1b = openfcomb.Get("h_reg_TopmunuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_comb_top1b) RecoilPhi_AB_top1b = openfAB.Get("h_reg_TopmunuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_AB_top1b) RecoilPhi_CD_bfr_top1b = openfCD_bfr.Get( "h_reg_TopmunuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_CD_bfr_top1b) RecoilPhi_CD_top1b = openfCD.Get("h_reg_TopmunuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_CD_top1b) h_jet1phi_2b = [] jet1phi_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_comb_top2b) jet1phi_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_AB_top2b) jet1phi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopmunuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_CD_bfr_top2b) jet1phi_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_CD_top2b) h_jet2phi_2b = [] jet2phi_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_comb_top2b) jet2phi_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_AB_top2b) jet2phi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopmunuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_CD_bfr_top2b) jet2phi_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_CD_top2b) h_jet1eta_2b = [] jet1eta_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_comb_top2b) jet1eta_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_AB_top2b) jet1eta_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopmunuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_CD_bfr_top2b) jet1eta_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_CD_top2b) h_jet2eta_2b = [] jet2eta_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_comb_top2b) jet2eta_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_AB_top2b) jet2eta_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopmunuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_CD_bfr_top2b) jet2eta_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_CD_top2b) #h_MET_2b = [] #MET_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_MET") #h_MET_2b.append(MET_comb_top2b) #MET_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_MET") #h_MET_2b.append(MET_AB_top2b) #MET_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_MET") #h_MET_2b.append(MET_CD_top2b) h_METphi_2b = [] METphi_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_METPhi") h_METphi_2b.append(METphi_comb_top2b) METphi_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_METPhi") h_METphi_2b.append(METphi_AB_top2b) METphi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopmunuCR_2b_METPhi") h_METphi_2b.append(METphi_CD_bfr_top2b) METphi_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_METPhi") h_METphi_2b.append(METphi_CD_top2b) #h_RecoilPhi_2b = [] #RecoilPhi_comb_top2b = openfcomb.Get("h_reg_TopmunuCR_2b_RecoilPhi") #h_RecoilPhi_2b.append(RecoilPhi_comb_top2b) #RecoilPhi_AB_top2b = openfAB.Get("h_reg_TopmunuCR_2b_RecoilPhi") #h_RecoilPhi_2b.append(RecoilPhi_AB_top2b) #RecoilPhi_CD_top2b = openfCD.Get("h_reg_TopmunuCR_2b_RecoilPhi") #h_RecoilPhi_2b.append(RecoilPhi_CD_top2b) alllist = [] alllist.append(h_jet1phi_1b) #alllist.append(h_jet2phi_1b) alllist.append(h_jet1eta_1b) #alllist.append(h_jet2eta_1b) #alllist.append(h_MET_1b) alllist.append(h_METphi_1b) alllist.append(h_RecoilPhi_1b) alllist.append(h_jet1phi_2b) alllist.append(h_jet2phi_2b) alllist.append(h_jet1eta_2b) alllist.append(h_jet2eta_2b) #alllist.append(h_MET_2b) alllist.append(h_METphi_2b) #alllist.append(h_RecoilPhi_2b) #print "1", alllist, len(alllist) if not isMET: openfcomb = TFile(path_before + "combined_data_SE.root") openfcomb_aftr = TFile(path_after + "combined_data_SE.root") openfAB = TFile(path_before + "combined_data_SE_AB.root") openfAB_aftr = TFile(path_after + "combined_data_SE_AB.root") openfCD_bfr = TFile(path_before + "combined_data_SE_CD.root") openfCD = TFile(path_after + "combined_data_SE_CD.root") h_jet1phi_1b = [] jet1phi_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_comb_top1b) jet1phi_comb_aftr_top1b = openfcomb_aftr.Get( "h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_comb_aftr_top1b) jet1phi_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_AB_top1b) jet1phi_AB_aftr_top1b = openfAB_aftr.Get("h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_AB_aftr_top1b) jet1phi_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_CD_bfr_top1b) jet1phi_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_Jet1Phi") h_jet1phi_1b.append(jet1phi_CD_top1b) h_jet1eta_1b = [] jet1eta_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_comb_top1b) jet1eta_comb_aftr_top1b = openfcomb_aftr.Get( "h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_comb_aftr_top1b) jet1eta_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_AB_top1b) jet1eta_AB_aftr_top1b = openfAB_aftr.Get("h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_AB_aftr_top1b) jet1eta_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_CD_bfr_top1b) jet1eta_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_Jet1Eta") h_jet1eta_1b.append(jet1eta_CD_top1b) h_MET_1b = [] MET_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_comb_top1b) MET_comb_aftr_top1b = openfcomb_aftr.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_comb_aftr_top1b) MET_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_AB_top1b) MET_AB_aftr_top1b = openfAB_aftr.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_AB_aftr_top1b) MET_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_CD_bfr_top1b) MET_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_MET") h_MET_1b.append(MET_CD_top1b) h_METphi_1b = [] METphi_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_comb_top1b) METphi_comb_aftr_top1b = openfcomb_aftr.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_comb_aftr_top1b) METphi_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_AB_top1b) METphi_AB_aftr_top1b = openfAB_aftr.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_AB_aftr_top1b) METphi_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_CD_bfr_top1b) METphi_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_METPhi") h_METphi_1b.append(METphi_CD_top1b) h_Recoil_1b = [] Recoil_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_comb_top1b) Recoil_comb_aftr_top1b = openfcomb_aftr.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_comb_aftr_top1b) Recoil_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_AB_top1b) Recoil_AB_aftr_top1b = openfAB_aftr.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_AB_aftr_top1b) Recoil_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_CD_bfr_top1b) Recoil_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_Recoil") h_Recoil_1b.append(Recoil_CD_top1b) h_RecoilPhi_1b = [] RecoilPhi_comb_top1b = openfcomb.Get("h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_comb_top1b) RecoilPhi_comb_aftr_top1b = openfcomb_aftr.Get( "h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_comb_aftr_top1b) RecoilPhi_AB_top1b = openfAB.Get("h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_AB_top1b) RecoilPhi_AB_aftr_top1b = openfAB_aftr.Get( "h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_AB_aftr_top1b) RecoilPhi_CD_bfr_top1b = openfCD_bfr.Get("h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_CD_bfr_top1b) RecoilPhi_CD_top1b = openfCD.Get("h_reg_TopenuCR_1b_RecoilPhi") h_RecoilPhi_1b.append(RecoilPhi_CD_top1b) h_jet1phi_2b = [] jet1phi_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_comb_top2b) jet1phi_comb_aftr_top2b = openfcomb_aftr.Get( "h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_comb_aftr_top2b) jet1phi_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_AB_top2b) jet1phi_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_AB_aftr_top2b) jet1phi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_CD_bfr_top2b) jet1phi_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_Jet1Phi") h_jet1phi_2b.append(jet1phi_CD_top2b) h_jet2phi_2b = [] jet2phi_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_comb_top2b) jet2phi_comb_aftr_top2b = openfcomb_aftr.Get( "h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_comb_aftr_top2b) jet2phi_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_AB_top2b) jet2phi_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_AB_aftr_top2b) jet2phi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_CD_bfr_top2b) jet2phi_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_Jet2Phi") h_jet2phi_2b.append(jet2phi_CD_top2b) h_jet1eta_2b = [] jet1eta_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_comb_top2b) jet1eta_comb_aftr_top2b = openfcomb_aftr.Get( "h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_comb_aftr_top2b) jet1eta_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_AB_top2b) jet1eta_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_AB_aftr_top2b) jet1eta_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_CD_bfr_top2b) jet1eta_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_Jet1Eta") h_jet1eta_2b.append(jet1eta_CD_top2b) h_jet2eta_2b = [] jet2eta_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_comb_top2b) jet2eta_comb_aftr_top2b = openfcomb_aftr.Get( "h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_comb_aftr_top2b) jet2eta_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_AB_top2b) jet2eta_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_AB_aftr_top2b) jet2eta_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_CD_bfr_top2b) jet2eta_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_Jet2Eta") h_jet2eta_2b.append(jet2eta_CD_top2b) h_MET_2b = [] MET_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_comb_top2b) MET_comb_aftr_top2b = openfcomb_aftr.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_comb_aftr_top2b) MET_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_AB_top2b) MET_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_AB_aftr_top2b) MET_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_CD_bfr_top2b) MET_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_MET") h_MET_2b.append(MET_CD_top2b) h_METphi_2b = [] METphi_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_comb_top2b) METphi_comb_aftr_top2b = openfcomb_aftr.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_comb_aftr_top2b) METphi_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_AB_top2b) METphi_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_AB_aftr_top2b) METphi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_CD_bfr_top2b) METphi_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_METPhi") h_METphi_2b.append(METphi_CD_top2b) h_Recoil_2b = [] Recoil_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_comb_top2b) Recoil_comb_aftr_top2b = openfcomb_aftr.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_comb_aftr_top2b) Recoil_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_AB_top2b) Recoil_AB_aftr_top2b = openfAB_aftr.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_AB_aftr_top2b) Recoil_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_CD_bfr_top2b) Recoil_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_Recoil") h_Recoil_2b.append(Recoil_CD_top2b) h_RecoilPhi_2b = [] RecoilPhi_comb_top2b = openfcomb.Get("h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_comb_top2b) RecoilPhi_comb_aftr_top2b = openfcomb_aftr.Get( "h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_comb_aftr_top2b) RecoilPhi_AB_top2b = openfAB.Get("h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_AB_top2b) RecoilPhi_AB_aftr_top2b = openfAB_aftr.Get( "h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_AB_aftr_top2b) RecoilPhi_CD_bfr_top2b = openfCD_bfr.Get("h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_CD_bfr_top2b) RecoilPhi_CD_top2b = openfCD.Get("h_reg_TopenuCR_2b_RecoilPhi") h_RecoilPhi_2b.append(RecoilPhi_CD_top2b) alllist = [] alllist.append(h_jet1phi_1b) alllist.append(h_jet1eta_1b) alllist.append(h_MET_1b) alllist.append(h_METphi_1b) alllist.append(h_Recoil_1b) alllist.append(h_RecoilPhi_1b) alllist.append(h_jet1phi_2b) alllist.append(h_jet2phi_2b) alllist.append(h_jet1eta_2b) alllist.append(h_jet2eta_2b) alllist.append(h_MET_2b) alllist.append(h_METphi_2b) alllist.append(h_Recoil_2b) alllist.append(h_RecoilPhi_2b) #print "2", alllist, len(alllist) effectMET_ABCD_1b = effect(h_Pre=MET_comb_top1b, h_Post=MET_comb_aftr_top1b) print "HEM effect on MET of Topenu 1b ABCD:", effectMET_ABCD_1b, "%" print " " effectMET_AB_1b = effect(h_Pre=MET_AB_top1b, h_Post=MET_AB_aftr_top1b) print "HEM effect on MET of Topenu 1b AB:", effectMET_AB_1b, "%" print " " effectMET_CD_1b = effect(h_Pre=MET_CD_bfr_top1b, h_Post=MET_CD_top1b) print "HEM effect on MET of Topenu 1b CD:", effectMET_CD_1b, "%" print " " c = PlotTemplates.myCanvas() gPad.GetUymax() gPad.SetLogy() gStyle.SetOptStat(0) gStyle.SetOptTitle(0) leg = PlotTemplates.SetLegend(coordinate_=[.37, .76, .78, .9], ncol=2) leg.SetTextSize(0.017) xAxisName = [ "Jet1 #phi", "Jet1 #eta", "MET (GeV)", "MET #phi", "Recoil (GeV)", "Recoil #phi", "Jet1 #phi", "Jet2 #phi", "Jet1 #eta", "Jet2 #eta", "MET (GeV)", "MET #phi", "Recoil (GeV)", "Recoil #phi" ] color = [1, 2, 4, 3, 6, 28] color_bfr = [1, 4, 6] legendName = [ "2018 ABCD (Before HEM Veto)", "2018 ABCD (After HEM Veto)", "2018 AB (Before HEM Veto)", "2018 AB (After HEM Veto)", "2018 CD (Before HEM Veto)", "2018 CD (After HEM Veto)" ] legendName_bfr = ["2018 ABCD", "2018 AB", "2018 CD"] for i in range(len(alllist)): leg.Clear() if (i == 2) or (i == 4) or (i == 10) or (i == 12): h = alllist[i] for j in range(len(h)): h[j].SetLineWidth(3) #h[j].SetMarkerStyle(20) #h[j].SetMarkerSize(0.5) h[j].SetLineColor(color[j]) #h[j].SetMarkerColor(color[j]) h[j].GetXaxis().SetTitle(xAxisName[i]) h[j].GetYaxis().SetTitle("Events/Bin") leg.AddEntry(h[j], legendName[j]) #h[j].Draw("histsame") #leg.Draw() else: h = alllist[i] #print i, "x-axis :", h[0].GetNbinsX(), h[0].GetXaxis().GetBinLowEdge(1) for j in range(len(h)): h[j].Scale(1 / h[j].Integral()) h[j].SetLineWidth(3) #h[j].SetMarkerStyle(20) #h[j].SetMarkerSize(0.5) h[j].SetLineColor(color[j]) #h[j].SetMarkerColor(color[j]) h[j].GetXaxis().SetTitle(xAxisName[i]) h[j].GetYaxis().SetTitle("Events/Bin") leg.AddEntry(h[j], legendName[j]) #h[j].Draw("histsame") #leg.Draw() h[0].Draw("hist") h[1].Draw("histsame") h[2].Draw("histsame") h[3].Draw("histsame") h[4].Draw("histsame") h[5].Draw("histsame") leg.Draw() energy = PlotTemplates.drawenergy(is2017=False) for k in energy: k.Draw() pavetxt = [ "Top (e#nu) + 1b CR", "Top (e#nu) + 1b CR", "Top (e#nu) + 1b CR", "Top (e#nu) + 1b CR", "Top (e#nu) + 1b CR", "Top (e#nu) + 1b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR", "Top (e#nu) + 2b CR" ] pt = TPaveText(0.2177181, 0.855, 0.4540537, 0.885, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(52) pt.AddText(pavetxt[i]) pt.Draw() name = [ "_1b_jet1phi", "_1b_jet1eta", "_1b_MET", "_1b_METphi", "_1b_Recoil", "_1b_Recoilphi", "_2b_jet1phi", "_2b_jet2phi", "_2b_jet1eta", "_2b_jet2eta", "_2b_MET", "_2b_METphi", "_2b_Recoil", "_2b_RecoilPhi" ] c.Update() dt = datetime.now() dt_str = dt.strftime("%Y%m%d_%H%M") subdirPath = dirPath + "/" + reg + "_" + dt_str if not (os.path.exists(subdirPath)): os.mkdir(subdirPath) dirPDF = subdirPath + "/pdf" dirPNG = subdirPath + "/png" if not (os.path.exists(dirPDF)): os.mkdir(dirPDF) if not (os.path.exists(dirPNG)): os.mkdir(dirPNG) c.SaveAs(dirPDF + "/" + reg + name[i] + "_new.pdf") c.SaveAs(dirPNG + "/" + reg + name[i] + "_new.png")
def __call__(self): h = self.hname if not h: return if not isinstance(h, TH2): return gPad.GetCanvas().FeedbackMode(kTRUE) event = gPad.GetEvent() if (event == 1): # left mouse click self.projection = not self.projection elif (event == 12): # middle mouse click self.logy = not self.logy # erase old position and draw a line at current position #(gPad coordinate system) px = gPad.GetEventX() py = gPad.GetEventY() uxmin, uxmax = gPad.GetUxmin(), gPad.GetUxmax() uymin, uymax = gPad.GetUymin(), gPad.GetUymax() pxmin, pxmax = gPad.XtoAbsPixel(uxmin), gPad.XtoAbsPixel(uxmax) pymin, pymax = gPad.YtoAbsPixel(uymin), gPad.YtoAbsPixel(uymax) # if self.projection: # axis = h.GetYaxis() # else: # axis = h.GetXaxis() width = 1 if self._old != None: if self.projection: gVirtualX.DrawBox(pxmin, self._old[1] - width, pxmax, self._old[1], kSolid) else: gVirtualX.DrawBox(self._old[0], pymin, self._old[0] + width, pymax, kSolid) if self.projection: gVirtualX.DrawBox(pxmin, py, pxmax, py + width, kSolid) else: gVirtualX.DrawBox(px, pymin, px, pymax + width, kSolid) self._old = px, py upx = gPad.AbsPixeltoX(px) x = gPad.PadtoX(upx) upy = gPad.AbsPixeltoY(py) y = gPad.PadtoY(upy) padsav = gPad # create or set the display canvases if not self._cX: self._cX = gPad.GetCanvas().GetPad(2) else: self._DestroyPrimitive('X') if not self._cY: self._cY = gPad.GetCanvas().GetPad(2) else: self._DestroyPrimitive('Y') if self.projection: self.DrawSlice(h, y, 'Y') else: self.DrawSlice(h, x, 'X') padsav.cd()
inFileMT.Get(f'hRawYield_pT_{ptMin*10:.0f}-{ptMax*10:.0f}')) rms = hRawYieldDistr[-1].GetRMS() / hRawYieldDistr[-1].GetMean() * 100 shift = TMath.Abs( hRawYields.GetBinContent(iPt) - hRawYieldDistr[-1].GetMean()) / hRawYieldDistr[-1].GetMean() * 100 syst = TMath.Sqrt(rms**2 + shift**2) hRMS.SetBinContent(iPt, rms) hMeanShift.SetBinContent(iPt, shift) hSyst.SetBinContent(iPt, syst) cRMS = TCanvas('cRMS', '', 800, 800) cRMS.DrawFrame(hRMS.GetBinLowEdge(1), 0.1, ptMax, 20., ';#it{p}_{T} (GeV/#it{c});RMS (%)') hRMS.DrawCopy('same') axisSoverB = TGaxis(gPad.GetUxmax(), gPad.GetUymin(), gPad.GetUxmax(), gPad.GetUymax(), 0.01, 20., 510, "+LG") axisSoverB.SetLineColor(kRed + 1) axisSoverB.SetLabelColor(kRed + 1) axisSoverB.SetLabelFont(42) axisSoverB.SetLabelSize(0.045) axisSoverB.SetTitle('S/B (3#sigma)') axisSoverB.SetTitleOffset(1.2) axisSoverB.SetLabelOffset(0.012) axisSoverB.SetTitleColor(kRed + 1) axisSoverB.SetTitleFont(42) axisSoverB.SetTitleSize(0.05) axisSoverB.SetMaxDigits(3) axisSoverB.Draw() hSoverB.DrawCopy('same') cRMS.Update()
def overlayhisto(dR_histo1, dR_histo2, dR_histo3, is1b, dirPath="plots"): c = PlotTemplates.myCanvas() gPad.GetUymax() #gPad.SetLogy() gStyle.SetOptStat(0) gStyle.SetOptTitle(0) leg = PlotTemplates.SetLegend(coordinate_=[.47, .73, .79, .88]) dR_histo1.SetLineWidth(3) dR_histo1.SetMarkerStyle(20) dR_histo1.SetMarkerSize(0.5) dR_histo1.SetLineColor(1) dR_histo1.SetMarkerColor(1) dR_histo1.GetXaxis().SetTitle("Delta R") dR_histo1.GetYaxis().SetTitle("Events/Bin") leg.AddEntry(dR_histo1, "Total (Before Cut)") dR_histo2.SetLineWidth(3) dR_histo2.SetMarkerStyle(21) dR_histo2.SetMarkerSize(0.5) dR_histo2.SetLineColor(2) dR_histo2.SetMarkerColor(2) leg.AddEntry(dR_histo2, "AB (Before Cut)") dR_histo3.SetLineWidth(3) dR_histo3.SetMarkerStyle(22) dR_histo3.SetMarkerSize(0.5) dR_histo3.SetLineColor(4) dR_histo3.SetMarkerColor(4) leg.AddEntry(dR_histo3, "CD (Before Cut)") #dR_histo4.SetLineWidth(3) #dR_histo4.SetMarkerStyle(23) #dR_histo4.SetMarkerSize(0.5) #dR_histo4.SetLineColor(3) #dR_histo4.SetMarkerColor(3) #dR_histo4.GetXaxis().SetTitle(xAxisName[i]) #leg.AddEntry(dR_histo4, "CD (After Cut)") dR_histo1.Draw("hist") dR_histo2.Draw("histsame") dR_histo3.Draw("histsame") #dR_histo4.Draw("histsame") leg.Draw() energy = PlotTemplates.drawenergy(is2017=False) for e in energy: e.Draw() if is1b: nb = "1b" nb_ext = "1b_dR_jet1_ele" if not is1b: nb = "2b" nb_ext = "2b_dR_jet1_ele" pt = TPaveText(0.1577181, 0.815, 0.3580537, 0.875, "brNDC") pt.SetBorderSize(0) pt.SetTextAlign(12) pt.SetFillStyle(0) pt.SetTextFont(52) pt.AddText("Top (e#nu) + " + nb + " CR") pt.Draw() dt = datetime.now() dt_str = dt.strftime("%Y%m%d_%H%M") subdirPath = dirPath + "/deltaR" subsubdirPath = subdirPath + "/TopenuCR_" + dt_str dirPDF = subsubdirPath + "/pdf" dirPNG = subsubdirPath + "/png" if not (os.path.exists(subdirPath)): os.mkdir(subdirPath) if not (os.path.exists(subsubdirPath)): os.mkdir(subsubdirPath) if not (os.path.exists(dirPDF)): os.mkdir(dirPDF) if not (os.path.exists(dirPNG)): os.mkdir(dirPNG) c.Update() c.Modified() c.SaveAs(dirPDF + "/TopenuCR_" + nb_ext + ".pdf") c.SaveAs(dirPNG + "/TopenuCR_" + nb_ext + ".png")