def makeNoisePlot(outputdir, allgraphs, groups_to_plot, namegroups_to_plot, suffix, whats_to_plot, names_to_plot, xtitle): # gROOT.ProcessLine('.L ~/CMS_style/tdrstyle.C') # gROOT.ProcessLine('setTDRStyle()') c1=TCanvas('c1', 'c1', 600,600) leg=defaultLegend(x1=0.35,y1=0.6,x2=0.5,y2=0.90) mg=TMultiGraph() for k,group in enumerate(groups_to_plot): for i,what in enumerate(whats_to_plot): mg.Add(allgraphs[group][what], 'P') leg.AddEntry(allgraphs[group][what], namegroups_to_plot[k] + ' ' + names_to_plot[i], 'LP') mg.Draw('a') mg.GetXaxis().SetTitle(xtitle) mg.GetYaxis().SetTitle('Noise (GeV)') mg.GetXaxis().SetTitle(xtitle) if 'EB' in groups_to_plot[0]: mg.GetYaxis().SetRangeUser(0., 1.0) elif 'EE' in groups_to_plot[0]: mg.GetYaxis().SetRangeUser(0., 15.) leg.Draw('same') #c1.SetLogy() c1.SaveAs('{}/Noise_{}{}.pdf'.format(outputdir,groups_to_plot[0][:2],suffix)) c1.SaveAs('{}/Noise_{}{}.png'.format(outputdir,groups_to_plot[0][:2],suffix)) c1.SaveAs('{}/Noise_{}{}.C'.format(outputdir,groups_to_plot[0][:2],suffix)) c1.SaveAs('{}/Noise_{}{}.root'.format(outputdir,groups_to_plot[0][:2],suffix))
def evaluateResolutionVariation(model, bcid, prefix, suffix, vtxres, scaling, \ legend=False): from array import array from ROOT import TFile, TMultiGraph, TGraphErrors, gStyle, TCanvas, \ TLegend, TLatex names = [pre+'_'+model+'_'+bcid+'_'+suf for (pre, suf) in zip(prefix, \ suffix)] xVal = {name: array('d', [0.0]*len(vtxres)) for name in names} xErr = {name: array('d', [0.0]*len(vtxres)) for name in names} yVal = {name: array('d', [0.0]*len(vtxres)) for name in names} yErr = {name: array('d', [0.0]*len(vtxres)) for name in names} for name, scale in zip(names, scaling): for i, vr in enumerate(vtxres): f = TFile('results/'+name+'_'+vr+'.root') yVal[name][i] = f.Get('h_overlapInt').GetMean() * 100.0 yErr[name][i] = f.Get('h_integ').GetMeanError() * 100.0 xVal[name][i] = f.Get('h_vtxRes').GetMean() * scale * 1.0e4 multi = TMultiGraph('overlapIntegralBcid'+bcid, '') graphs = [] for i, name in enumerate(names): graph = TGraphErrors(len(vtxres), xVal[name], yVal[name], xErr[name], \ yErr[name]) graph.SetName(name) graph.SetMarkerStyle(20) graph.SetMarkerColor(1+i) multi.Add(graph) graphs.append(graph) gStyle.SetOptStat(0) canvas = TCanvas(model+'_'+bcid, '', 600, 600) multi.Draw('AP') canvas.Update() multi.GetXaxis().SetTitle('vertex resolution [#mum]') multi.GetXaxis().SetLabelSize(0.025) multi.GetXaxis().SetRangeUser(11, 69) multi.GetYaxis().SetTitle('overlap integral [a.u.]') multi.GetYaxis().SetLabelSize(0.025) multi.GetYaxis().SetRangeUser(0.77, 1.43) if legend: leg = TLegend(0.55, 0.15, 0.88, 0.3) leg.SetBorderSize(0) for i, name in enumerate(names): entry = leg.AddEntry(name, legend[i], 'P') entry.SetMarkerStyle(20) entry.SetMarkerColor(1+i) leg.Draw() drawCMS(wip=True) text = TLatex() text.SetNDC() text.SetTextFont(62) text.SetTextSize(0.04) text.SetTextAlign(21) text.DrawLatex(0.5, 0.92, 'Vertex Resolution Study: '+model+', BCID '+bcid) canvas.Modified() canvas.Update() canvas.SaveAs('plots/'+canvas.GetName()+'.pdf') canvas.SaveAs('plots/'+canvas.GetName()+'.C')
def write_imposedattenuationgraphs(ordered_graphslinearity): if len(ordered_graphslinearity) == 40: sectors = [1, 2, 3, 4, 5] else: sectors = [6, 7, 8] colors = [1, 2, 3, 4, 5, 6, 7, 8, 9] for c, s in enumerate(sectors): plots = [x for x in ordered_graphslinearity if str(s) in x.filename[8]] mgraph = TMultiGraph() for counter, p in enumerate(plots): x = array('d', p.setattenvalues) y = array('d', p.normalizedsetmeancurrents) n = len(x) graph = TGraph(n, x, y) graph.SetMarkerColor(colors[counter]) graph.SetLineColor(colors[counter]) graph.SetMarkerStyle(20) graph.SetMarkerSize(1) mgraph.Add(graph) mgraph.SetTitle("PCBs type " + str(s)) mgraph.GetXaxis().SetRangeUser(0.0, 1.2) mgraph.GetXaxis().SetTitle("1/attenuation") mgraph.GetYaxis().SetTitle("i/area (uA/cm^{2})") mgraph.GetYaxis().SetTitleOffset(1.2) mgraph.Draw("APL") gPad.SaveAs("Overimposed_" + str(s) + ".pdf") gPad.Close()
def MakePlot(PlotList, Mode): colors = [ ROOT.kRed, ROOT.kBlue, ROOT.kGreen, ROOT.kOrange, ROOT.kCyan, ROOT.kMagenta ] MG = TMultiGraph() MG.SetTitle( "Varying {};Center of Mass Angle in Degrees;Cross Section in mb/sr". format(Mode)) MG.SetTitle("MG_{}".format(Mode)) MG.SetName("MG_{}".format(Mode)) legend = ROOT.TLegend(0.65, .65, .9, .9) Zipper = zip(PlotList, colors) for plot, color in Zipper: plot.SetMarkerColor(ROOT.kWhite) plot.SetLineColor(color) plot.SetFillColor(ROOT.kWhite) plot.SetLineWidth(2) MG.Add(plot, "L") legend.AddEntry(plot, plot.GetName()) MG.Draw("AL") canvas.SetLogy() MG.GetXaxis().SetTitle("Center of Mass Angle in Degrees") MG.GetYaxis().SetTitle("Cross Section in mb/sr") MG.Draw() legend.Draw() canvas.SaveAs("vary_{}.png".format(Mode))
def doSuperTGraph( data, canvas, obj): xmin=-1.8 xmax=1.8 gStyle.SetOptFit(0) gStyle.SetOptStat(0) gROOT.SetBatch(1) color=[601,417,920,633,910,433,400,619,1,922] mg = TMultiGraph(); leg = TLegend(0.58,0.75,0.89,0.89); i=0 for ivar in data['var']: if not os.path.exists(data['fold']+"/"+ivar+"_ll.root"): continue print '>>> Opening File :' , data['fold']+"/"+ivar+"_ll.root" inFile = TFile.Open ( data['fold']+"/"+ivar+"_ll.root" ," READ ") c1 = inFile.Get(canvas); gr = c1.GetListOfPrimitives().FindObject(obj) xaxis = gr.GetXaxis().GetTitle() yaxis = gr.GetYaxis().GetTitle() gr.SetLineColor(color[i]) mg.Add(gr) leg.AddEntry(gr,ivar,"l") i=i+1 print i c = TCanvas() c.cd() c.SetGrid() mg.Draw("al") line1 = TF1("line1","pol0",-100,100) line1.FixParameter(0,1.) line1.SetLineWidth(2) line1.SetLineStyle(2) line1.SetLineColor(2) line1.Draw("same") line2 = TF1("line2","pol0",-100,100) line2.FixParameter(0,3.84) line2.SetLineWidth(2) line2.SetLineStyle(2) line2.SetLineColor(2) line2.Draw("same") mg.SetTitle(";" +xaxis+";" +yaxis) mg.GetYaxis().SetRangeUser(0,10) leg.SetNColumns(2) leg.SetBorderSize(0) leg.Draw("same") c.SaveAs(data['fold']+"combined10.png") c.SaveAs(data['fold']+"combined10.pdf") c.SaveAs(data['fold']+"combined10.root")
def DivideGraphs(self, g1, g2, interpolationMethod="lin"): """ Divide 2 graphs g1 and g2, by each other applying an interpolation between the points for the denominator @param g1: graph 1 @param g2: graph 2 @param interpolationMethod: method used for interpolation between the two graphs @return: The ratio graphs """ #calculate x range xmin = max(g1.GetX()[0], g2.GetX()[0]) xmax = min(g1.GetX()[g1.GetN() - 1], g2.GetX()[g2.GetN() - 1]) # create new TGraphErors for result1 result1 = self.MakeGraphDivision(g1, g2, xmin, xmax, interpolationMethod) result1.SetMarkerColor(1) result1.SetMarkerStyle(20) # create new TGraphErors for result2 result2 = self.MakeGraphDivision(g2, g1, xmin, xmax, interpolationMethod) result2.SetMarkerColor(2) result2.SetMarkerStyle(20) result = TMultiGraph("result", " ") result.Add(result1) result.Add(result2) result.Draw("AP") result.GetXaxis().SetRangeUser(xmin, xmax) result.GetXaxis().SetTitle("p_{T} [Gev/c]") result.GetXaxis().SetTitleOffset(1.2) result.GetYaxis().SetTitleOffset(1.2) return result
def doSuperTGraphAll( file_list, canvas, obj, output): gStyle.SetOptFit(0) gStyle.SetOptStat(0) gROOT.SetBatch(1) mg = TMultiGraph(); leg = TLegend(0.58,0.75,0.89,0.89); for iFile in file_list: if not os.path.exists(iFile['path']): print '>>> This File does not exist --> '+iFile['path']+'... check path ... ' continue print '>>> Opening File :' , iFile['path'] inFile = TFile.Open ( iFile['path'] ," READ ") c1 = inFile.Get(canvas); gr = c1.GetListOfPrimitives().FindObject(obj) xaxis = gr.GetXaxis().GetTitle() yaxis = gr.GetYaxis().GetTitle() gr.SetLineColor(iFile['color']) mg.Add(gr) leg.AddEntry(gr,iFile['legend'],"l") c = TCanvas() c.cd() c.SetGrid() mg.Draw("al") line1 = TF1("line1","pol0",-100,100) line1.FixParameter(0,1.) line1.SetLineWidth(2) line1.SetLineStyle(2) line1.SetLineColor(2) line1.Draw("same") line2 = TF1("line2","pol0",-100,100) line2.FixParameter(0,3.84) line2.SetLineWidth(2) line2.SetLineStyle(2) line2.SetLineColor(2) line2.Draw("same") mg.SetTitle(";" +xaxis+";" +yaxis) mg.GetYaxis().SetRangeUser(0,10) leg.SetNColumns(2) leg.SetBorderSize(0) leg.Draw("same") c.SaveAs(output+"10.png") c.SaveAs(output+"10.pdf") c.SaveAs(output+"10.root")
def plotMultiGraph(dataReadings, vals, title, xTitle, yTitle, outF): """ Plots several TGraphs using TMultiGraph """ mg = TMultiGraph() cv = TCanvas(outF, "cv", 1200, 1200) l = TLegend(0.9, 0.7, 1.0, 0.9) pad = TPad("p", "p", 0.05, 0.05, 1.0, 1.0) pad.cd() for a in xrange(len(vals)): print "vals[a] = {0}".format(vals[a]) l.AddEntry(vals[a], "Value %d" % (a + 1), "pl") mg.Add(vals[a]) mg.Draw("alp") pad.Update() mg.SetTitle(title + ";" + xTitle + ";" + yTitle) l.Draw() cv.cd() pad.Draw() mg.GetXaxis().SetNdivisions(len(dataReadings)) date = "" nReadings = len(dataReadings) divisor = nReadings / 10 + 1 # use to label no more than 10 bins, include first and last bins always for i in xrange(nReadings): if i % divisor == 0 or i == nReadings - 1: # If new date, print date and time if date != dataReadings[i]["date"]: date = dataReadings[i]["date"] mg.GetXaxis().SetBinLabel( mg.GetXaxis().FindBin(i), "#splitline{%s}{%s}" % (date, dataReadings[i]["time"])) else: mg.GetXaxis().SetBinLabel(mg.GetXaxis().FindBin(i), dataReadings[i]["time"]) mg.GetXaxis().SetTitleOffset(2.1) mg.GetYaxis().SetTitleOffset(2.1) pad.Update() cv.SaveAs(outF)
def plotMultiGraph(dataReadings, vals, title, xTitle, yTitle, outF): """ Plots several TGraphs using TMultiGraph """ mg = TMultiGraph() cv = TCanvas(outF, "cv", 1200, 1200) l = TLegend(0.9, 0.7, 1.0, 0.9) pad = TPad("p", "p", 0.05, 0.05, 1.0, 1.0) pad.cd() for rm in range(len(vals)): l.AddEntry(vals[rm], "RM%d" % (rm + 1), "pl") mg.Add(vals[rm]) mg.Draw("alp") pad.Update() mg.SetTitle(title + ";" + xTitle + ";" + yTitle) l.Draw() cv.cd() pad.Draw() mg.GetXaxis().SetNdivisions(len(dataReadings)) date = "" for i in range(len(dataReadings)): # If new date, print date and time if date != dataReadings[i]["date"]: date = dataReadings[i]["date"] mg.GetXaxis().SetBinLabel( mg.GetXaxis().FindBin(i), "#splitline{%s}{%s}" % (date, dataReadings[i]["time"])) else: mg.GetXaxis().SetBinLabel(mg.GetXaxis().FindBin(i), dataReadings[i]["time"]) mg.GetXaxis().SetTitleOffset(2.1) mg.GetYaxis().SetTitleOffset(2.1) pad.Update() cv.SaveAs(outF)
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 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 plotOtherCoordinate(datafile, crossings, scans): gStyle.SetOptStat(0) f = TFile.Open(datafile) for bx in crossings: for coord in ('X', 'Y'): if 'X' in coord: other = 'Y' else: other = 'X' meanGraphs = [] rmsGraphs = [] for scan in scans: meanVal = array('d') meanErr = array('d') rmsVal = array('d') rmsErr = array('d') stepVal = array('d', [1.0 * a for a in range(1, 20)]) stepErr = array('d', 19 * [0.0]) for i in range(1, 20): hist = f.Get('scan' + coord + scan + 'Move_b' + bx + '_' + str(i)) funcGaus = TF1('funcGaus' + coord + scan, 'gaus', -10, 10) getattr(hist, 'Projection' + other)().Fit('funcGaus' + coord + scan) meanVal.append(funcGaus.GetParameter('Mean') * scaling) meanErr.append(funcGaus.GetParError(1) * scaling) rmsVal.append(funcGaus.GetParameter('Sigma') * scaling) rmsErr.append(funcGaus.GetParError(2) * scaling) meanGraph = TGraphErrors(19, stepVal, meanVal, stepErr, meanErr) rmsGraph = TGraphErrors(19, stepVal, rmsVal, stepErr, rmsErr) meanGraph.SetName('graph' + coord + scan + 'MeanBX' + bx) rmsGraph.SetName('graph' + coord + scan + 'RmsBX' + bx) meanGraphs.append(meanGraph) rmsGraphs.append(rmsGraph) meanMulti = TMultiGraph('multi' + coord + scan + 'MeanBX' + bx, '') rmsMulti = TMultiGraph('multi' + coord + scan + 'RmsBX' + bx, '') for i, gr in enumerate(meanGraphs): gr.SetMarkerStyle(3 + 19 * i) gr.SetMarkerSize(1) gr.SetMarkerColor(2 + i) meanMulti.Add(gr) for i, gr in enumerate(rmsGraphs): gr.SetMarkerStyle(3 + 19 * i) gr.SetMarkerSize(1) gr.SetMarkerColor(2 + i) rmsMulti.Add(gr) meanCanvas = TCanvas('canvasMean' + coord + 'ScanBX' + bx, '', 1000, 600) meanMulti.Draw('APE') meanCanvas.Update() meanMulti.GetYaxis().SetTitle('luminous region ' + other.lower() + '-mean [cm]') meanMulti.GetXaxis().SetTitle('scan point') meanMulti.GetYaxis().SetTitleOffset(1.3) meanMulti.GetYaxis().SetRangeUser(-0.01, 0.01) meanMulti.GetYaxis().SetTickLength(0.02) meanLeg = TLegend(0.4, 0.13, 0.6, 0.28) meanLeg.SetHeader(coord + ' Scan (BCID ' + bx + ')') meanLeg.SetBorderSize(0) meanLeg.SetNColumns(2) for i, gr in enumerate(meanGraphs): entry = meanLeg.AddEntry(gr.GetName(), 'Scan ' + scans[i], 'lep') entry.SetMarkerStyle(3 + 19 * i) entry.SetMarkerColor(2 + i) meanLeg.Draw() drawCMS() meanCanvas.Modified() meanCanvas.Update() meanCanvas.SaveAs('summaryPlots/' + meanCanvas.GetName() + '.pdf') meanCanvas.SaveAs('summaryPlots/' + meanCanvas.GetName() + '.C') rmsCanvas = TCanvas('canvasRms' + coord + 'ScanBX' + bx, '', 1000, 600) rmsMulti.Draw('APE') rmsCanvas.Update() rmsMulti.GetYaxis().SetTitle('luminous region ' + other.lower() + '-width [cm]') rmsMulti.GetXaxis().SetTitle('scan point') rmsMulti.GetYaxis().SetTitleOffset(1.3) rmsMulti.GetYaxis().SetRangeUser(-0.01, 0.04) rmsMulti.GetYaxis().SetTickLength(0.02) rmsLeg = TLegend(0.4, 0.13, 0.6, 0.28) rmsLeg.SetHeader(coord + ' Scan (BCID ' + bx + ')') rmsLeg.SetBorderSize(0) rmsLeg.SetNColumns(2) for i, gr in enumerate(rmsGraphs): entry = rmsLeg.AddEntry(gr.GetName(), 'Scan ' + scans[i], 'lep') entry.SetMarkerStyle(3 + 19 * i) entry.SetMarkerColor(2 + i) rmsLeg.Draw() drawCMS() rmsCanvas.Modified() rmsCanvas.Update() rmsCanvas.SaveAs('summaryPlots/' + rmsCanvas.GetName() + '.pdf') rmsCanvas.SaveAs('summaryPlots/' + rmsCanvas.GetName() + '.C')
class PlotGraphs: def __init__(self, data, xlow, xhigh, ylow, yhigh, xlabel = "", ylabel = "", xLegend = .45, yLegend = .60, legendWidth = 0.20, legendHeight = 0.45, fillStyle = 3395, drawOption = 'APL3', make_tfile = False): self.graph_index = {} self.ngraphs = 0 self.data = data self.drawOption = drawOption self.xlow=xlow self.xhigh=xhigh self.ylow=ylow self.yhigh=yhigh self.xlabel = xlabel self.ylabel = ylabel self.multigraph=TMultiGraph("MultiGraph", "") self.legend_type = {} if make_tfile: self.tfile = TFile('tgraphs.root', 'recreate') self.legend = TLegend(xLegend, yLegend, xLegend + legendWidth, yLegend + legendHeight) self.g_ = {} self.g2_ = {} self.g3_ = {} for cat in data.cat: if data.type[cat] == 'observed': #self.g_[cat] = TGraph(len(data.x[cat]), data.x[cat], data.y[cat]) self.g_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl[cat], data.exh[cat], data.eyl[cat], data.eyh[cat]) self.g_[cat].SetName(cat) if make_tfile: _gcopy = self.g_[cat].Clone() self.tfile.Append(_gcopy) if data.dofit[cat]: #self.g_[cat].Fit("pol3", "M", "", data.fit_min[cat], data.fit_max[cat]) f1 = TF1("f1", "[0]+[1]*(x-1000.0)/1000.0+[2]*(x-1000.0)*(x-1000.0)/1000000.0+[3]*(x-1000.0)*(x-1000.0)*(x-1000.0)/1000000000.0", data.fit_min[cat], data.fit_max[cat]) f2 = TF1("f2", "[0]+[1]*(x-1000.0)/1000.0+[2]*(x-1000.0)*(x-1000.0)/1000000.0", data.fit_min[cat], data.fit_max[cat]) f3 = TF1("f3", "[0]+[1]*(x-1000.0)/1000.0", data.fit_min[cat], data.fit_max[cat]) _fr = self.g_[cat].Fit("f2", "MEWS", "", data.fit_min[cat], data.fit_max[cat]) _fr.Print() elif data.type[cat] == 'expected': self.g_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl[cat], data.exh[cat], data.eyl[cat], data.eyh[cat]) self.g2_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl2[cat], data.exh2[cat], data.eyl2[cat], data.eyh2[cat]) self.g3_[cat] = TGraphAsymmErrors(len(data.x[cat]), data.x[cat], data.y[cat], data.exl2[cat], data.exh2[cat], data.y[cat], data.exl2[cat]) self.g3_[cat].SetFillStyle(1002) #self.g3_[cat].SetFillStyle(3008) # 95% quantile self.g2_[cat].SetMarkerColor(data.fill2_color[cat]) self.g2_[cat].SetMarkerStyle(data.marker_style[cat]) self.g2_[cat].SetMarkerSize(data.marker_size[cat]) self.g2_[cat].SetLineColor(data.fill2_color[cat]) self.g2_[cat].SetLineStyle(data.line_style[cat]) self.g2_[cat].SetLineWidth(data.line_width[cat]) #self.g2_[cat].SetFillColor(data.marker_color[cat]+2) self.g2_[cat].SetFillColor(data.fill2_color[cat]) #self.g2_[cat].SetFillStyle(3008) #self.g2_[cat].SetFillStyle(3003) self.g2_[cat].SetFillStyle(data.fill2_style[cat]) self.g_[cat].SetMarkerColor(data.marker_color[cat]) self.g_[cat].SetMarkerStyle(data.marker_style[cat]) self.g_[cat].SetMarkerSize(data.marker_size[cat]) self.g_[cat].SetLineColor(data.line_color[cat]) self.g_[cat].SetLineStyle(data.line_style[cat]) self.g_[cat].SetLineWidth(data.line_width[cat]) self.g_[cat].SetFillColor(data.fill_color[cat]) if data.fill_style[cat] == None: self.g_[cat].SetFillStyle(fillStyle) else: self.g_[cat].SetFillStyle(data.fill_style[cat]) if data.type[cat] == 'observed': # only the main observed limit is a line, # everything else is a filled area if cat[0:3] == 'obs': _legend_type = 'lp' if 'PC' in drawOption: _draw_option = 'PC' else: _draw_option = 'PL' self.multigraph.Add(self.g_[cat], _draw_option) elif cat[0:3] == 'SSM': _legend_type = 'lp' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) # print theory curve #self.g_[cat].Print() elif cat[0:3] == 'Psi': _legend_type = 'lp' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) elif cat[0:2] == 'RS': _legend_type = 'f' _draw_option = '3' self.multigraph.Add(self.g_[cat], _draw_option) else: _legend_type = 'f' self.multigraph.Add(self.g_[cat]) #self.multigraph.Add(self.g_[cat]) self.graph_index[cat] = self.ngraphs self.ngraphs += 1 #self.legend . AddEntry( self.g_[cat], data.tlegend[cat], _legend_type); self.legend_type[cat] = _legend_type elif data.type[cat] == 'expected': self.g3_[cat].SetFillColor(0) self.g3_[cat].SetMinimum(self.ylow) self.g3_[cat].SetMaximum(self.yhigh) self.g3_[cat].GetXaxis().SetLimits(self.xlow, self.xhigh) self.multigraph.Add(self.g3_[cat], 'C3') self.ngraphs += 1 # 95 expected band self.multigraph.Add(self.g2_[cat]) self.ngraphs += 1 self.multigraph.Add(self.g_[cat], 'C3L') self.graph_index[cat] = self.ngraphs self.ngraphs += 1 # median line gline = self.g_[cat].Clone() gline.SetLineWidth(3) gline.SetLineColor(ROOT.kBlue) gline.SetLineStyle(2) # print graph contents #gline.Print() #self.multigraph.Add(gline, 'LXC') self.multigraph.Add(gline, 'C3X') self.legend . AddEntry( gline, 'median expected', "l"); self.ngraphs += 1 #self.legend . AddEntry( self.g_[cat], data.tlegend[cat], "f"); self.legend . AddEntry( self.g_[cat], '68% expected', "f"); # 95% expected band legend self.legend . AddEntry( self.g2_[cat], '95% expected', "f"); keylist = data.legend_index.keys() # keys are indices keylist.sort() for key in keylist: self.legend . AddEntry( self.g_[data.legend_index[key]], data.tlegend[data.legend_index[key]], self.legend_type[data.legend_index[key]]); self.legend . SetShadowColor(0) self.legend . SetFillColor(0) self.legend . SetLineColor(0) if make_tfile: self.tfile.Write() self.tfile.Close() def draw(self, yLabelSize = 0.045): self.multigraph.SetMinimum(self.ylow) self.multigraph.SetMaximum(self.yhigh) self.multigraph . Draw(self.drawOption) self.multigraph.GetXaxis().SetNdivisions(405) self.multigraph.GetYaxis().SetNdivisions(405) self.multigraph.GetXaxis().SetLimits(self.xlow, self.xhigh) #self.multigraph.GetYaxis().SetTitle("") #self.multigraph.GetYaxis().SetLabelSize(yLabelSize) #self.multigraph.GetXaxis().SetLabelSize(yLabelSize) # axis labels #latex = TLatex() #latex.SetNDC() ##latex.SetTextSize(0.04) #latex.SetTextSize(yLabelSize) #latex.SetTextAlign(31) # align right #latex.DrawLatex(0.95,0.01, self.xlabel) #latex.SetTextAngle(90) #latex.DrawLatex(0.04,0.95, self.ylabel) XLabel(self.xlabel, 0.95, 0.03, text_size = 0.07) YLabel(self.ylabel, 0.04,0.9, text_size = 0.07) self.legend.SetFillStyle(0) self.legend.SetBorderSize(0) #self.legend.SetTextSize(0.04) self.legend.SetTextSize(yLabelSize) self.legend.SetTextFont(22) self.legend . Draw() return self.multigraph def draw_line(self, xline, ymin = -0.02, ymax = 0.20): if xline == None: return #print 'XXXX', xline _x = array('d') _y = array('d') _x.append(xline) _y.append(ymin) _x.append(float(xline)) _y.append(ymax) g_ = TGraph(len(_x), _x, _y) self.multigraph.Add(g_, 'L') def print_values(self, cat1, cat2): legend = 'PlotGraphs::print_values():' if cat1 in self.data.cat: graph1 = self.multigraph.GetListOfGraphs().At(self.graph_index[cat1]) else: return None if cat2 in self.data.cat: graph2 = self.multigraph.GetListOfGraphs().At(self.graph_index[cat2]) else: return None for x in range (750, 1150, 50): dmax = 0.0 drelmax = 0.0 v1 = graph1.Eval(x) v2 = graph2.Eval(x) d = math.fabs(v2-v1) drel = math.fabs((v2-v1)/v1) if d>dmax: dmax = d if drel>drelmax: drelmax = drel print legend, 'x =', x print legend, cat1, 'value =', v1 print legend, cat2, 'value =', v2 print legend, 'abs diff =', d print legend, 'abs relative diff =', drel print legend, 'max abs diff =', dmax print legend, 'max abs relative diff =', drelmax def find_intersection(self, cat1, cat2, xmin = 250, xmax = 2500, precision = 0.00001): legend = 'PlotGraphs::find_intersection():' if cat1 in self.data.cat: graph1 = self.multigraph.GetListOfGraphs().At(self.graph_index[cat1]) else: return None if cat2 in self.data.cat: graph2 = self.multigraph.GetListOfGraphs().At(self.graph_index[cat2]) #graph2.Print() else: return None _x = xmin print legend, graph1.Eval(_x) - graph2.Eval(_x) _d = graph1.Eval(_x) - graph2.Eval(_x) _step = xmax - xmin while abs(_d) > precision: _x += _step if _x > xmax or _x < xmin: return None _d2 = graph1.Eval(_x) - graph2.Eval(_x) _sign1 = _d > 0 _sign2 = _d2 > 0 if _sign1 != _sign2: _step = -0.5*_step _d = _d2 if abs(_d2) < precision: return _x
def eta_plot(X0W, Y0W, X1W, Y1W, X2W, Y2W, X3W, Y3W, X4W, Y4W, X5W, Y5W, X6W, Y6W, X7W, Y7W, X8W, Y8W, X9W, Y9W, X10W, Y10W, X11W, Y11W, X12W, Y12W, X13W, Y13W, X0E, Y0E, X1E, Y1E, X2E, Y2E, X3E, Y3E, X4E, Y4E, X5E, Y5E, X6E, Y6E, X7E, Y7E, X8E, Y8E, X9E, Y9E, X10E, Y10E, X11E, Y11E, X12E, Y12E, X13E, Y13E): print "------ Setting Up Format ----------" tdrstyle.setTDRStyle() #change the CMS_lumi variables (see CMS_lumi.py) CMS_lumi.writeExtraText = 1 CMS_lumi.extraText = "Preliminary" CMS_lumi.extraText2 = "2018 pp data" CMS_lumi.lumi_sqrtS = "13 TeV" # used with iPeriod = 0, e.g. for simulation-only plots (default is an empty string) CMS_lumi.writeTitle = 1 CMS_lumi.textTitle = 'title' iPos = 11 if (iPos == 0): CMS_lumi.relPosX = 0.12 H_ref = 600 W_ref = 800 W = W_ref H = H_ref iPeriod = 0 # references for T, B, L, R T = 0.08 * H_ref B = 0.12 * H_ref L = 0.12 * W_ref R = 0.04 * W_ref print "------ Creating Wheel TGraph ----------" n0W = len(X0W) gr0W = TGraph(n0W, X0W, Y0W) gr0W.SetMarkerColor(kRed) gr0W.SetMarkerStyle(20) gr0W.SetMarkerSize(1.5) gr0W.SetTitle('RB1 in') gr0W.GetXaxis().SetTitle('#eta') gr0W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n1W = len(X1W) gr1W = TGraph(n1W, X1W, Y1W) gr1W.SetLineColor(2) gr1W.SetLineWidth(4) gr1W.SetMarkerColor(kBlue) gr1W.SetMarkerStyle(29) gr1W.SetMarkerSize(1.7) gr1W.SetTitle('Layer 1 Wheel') gr1W.GetXaxis().SetTitle('#eta') gr1W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n2W = len(X2W) gr2W = TGraph(n2W, X2W, Y2W) gr2W.SetLineColor(3) gr2W.SetLineWidth(5) gr2W.SetMarkerColor(kRed + 2) gr2W.SetMarkerStyle(21) gr2W.SetMarkerSize(1.5) gr2W.SetTitle('Layer 2 Wheel') gr2W.GetXaxis().SetTitle('#eta') gr2W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n3W = len(X3W) gr3W = TGraph(n3W, X3W, Y3W) gr3W.SetLineColor(4) gr3W.SetLineWidth(6) gr3W.SetMarkerColor(kRed) gr3W.SetMarkerStyle(21) gr3W.SetMarkerSize(1.5) gr3W.SetTitle('Layer 3 Wheel') gr3W.GetXaxis().SetTitle('#eta') gr3W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n4W = len(X4W) gr4W = TGraph(n4W, X4W, Y4W) gr4W.SetLineColor(5) gr4W.SetLineWidth(7) gr4W.SetMarkerColor(kBlue) gr4W.SetMarkerStyle(23) gr4W.SetMarkerSize(1.5) gr4W.SetTitle('Layer 4 Wheel') gr4W.GetXaxis().SetTitle('#eta') gr4W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') print "------ Creating Endcap TGraph ----------" n0E = len(X0E) gr0E = TGraph(n0E, X0E, Y0E) gr0E.SetLineColor(2) gr0E.SetLineWidth(4) gr0E.SetMarkerColor(kRed) gr0E.SetMarkerStyle(24) gr0E.SetMarkerSize(1.5) gr0E.SetTitle('Layer 1 Endcap') gr0E.GetXaxis().SetTitle('#eta') gr0E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n1E = len(X1E) gr1E = TGraph(n1E, X1E, Y1E) gr1E.SetLineColor(2) gr1E.SetLineWidth(4) gr1E.SetMarkerColor(kBlue) gr1E.SetMarkerStyle(30) gr1E.SetMarkerSize(1.5) gr1E.SetTitle('Layer 1 Endcap') gr1E.GetXaxis().SetTitle('#eta') gr1E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n2E = len(X2E) gr2E = TGraph(n2E, X2E, Y2E) gr2E.SetLineColor(3) gr2E.SetLineWidth(5) gr2E.SetMarkerColor(kRed + 2) gr2E.SetMarkerStyle(25) gr2E.SetMarkerSize(1.5) gr2E.SetTitle('Layer 2 Endcap') gr2E.GetXaxis().SetTitle('#eta') gr2E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n3E = len(X3E) gr3E = TGraph(n3E, X3E, Y3E) gr3E.SetLineColor(4) gr3E.SetLineWidth(6) gr3E.SetMarkerColor(kRed) gr3E.SetMarkerStyle(25) gr3E.SetMarkerSize(1.5) gr3E.SetTitle('Layer 3 Endcap') gr3E.GetXaxis().SetTitle('#eta') gr3E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n4E = len(X4E) gr4E = TGraph(n4E, X4E, Y4E) gr4E.SetLineColor(5) gr4E.SetLineWidth(7) gr4E.SetMarkerColor(kBlue) gr4E.SetMarkerStyle(32) gr4E.SetMarkerSize(1.5) gr4E.SetTitle('Layer 4 Endcap') gr4E.GetXaxis().SetTitle('#eta') gr4E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') print "------ Creating Wheel TGraph ----------" n5W = len(X5W) gr5W = TGraph(n5W, X5W, Y5W) gr5W.SetLineColor(2) gr5W.SetLineWidth(4) gr5W.SetMarkerColor(6) gr5W.SetMarkerStyle(22) gr5W.SetMarkerSize(1.5) gr5W.SetTitle('Layer 1 Wheel') gr5W.GetXaxis().SetTitle('#eta') gr5W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n6W = len(X6W) gr6W = TGraph(n6W, X6W, Y6W) gr6W.SetLineColor(3) gr6W.SetLineWidth(5) gr6W.SetMarkerColor(28) gr6W.SetMarkerStyle(23) gr6W.SetMarkerSize(1.7) gr6W.SetTitle('Layer 2 Wheel') gr6W.GetXaxis().SetTitle('#eta') gr6W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n7W = len(X7W) gr7W = TGraph(n7W, X7W, Y7W) gr7W.SetLineColor(4) gr7W.SetLineWidth(6) gr7W.SetMarkerColor(kRed) gr7W.SetMarkerStyle(20) gr7W.SetMarkerSize(1.5) gr7W.SetTitle('Layer 3 Wheel') gr7W.GetXaxis().SetTitle('#eta') gr7W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n8W = len(X8W) gr8W = TGraph(n8W, X8W, Y8W) gr8W.SetLineColor(5) gr8W.SetLineWidth(7) gr8W.SetMarkerColor(kBlue) gr8W.SetMarkerStyle(29) gr8W.SetMarkerSize(1.5) gr8W.SetTitle('Layer 4 Wheel') gr8W.GetXaxis().SetTitle('#eta') gr8W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n9W = len(X9W) gr9W = TGraph(n9W, X9W, Y9W) gr9W.SetLineColor(5) gr9W.SetLineWidth(7) gr9W.SetMarkerColor(kRed + 2) gr9W.SetMarkerStyle(21) gr9W.SetMarkerSize(1.5) gr9W.SetTitle('Layer 4 Wheel') gr9W.GetXaxis().SetTitle('#eta') gr9W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n10W = len(X10W) gr10W = TGraph(n10W, X10W, Y10W) gr10W.SetLineColor(5) gr10W.SetLineWidth(7) gr10W.SetMarkerColor(kRed) gr10W.SetMarkerStyle(21) gr10W.SetMarkerSize(1.5) gr10W.SetTitle('Layer 4 Wheel') gr10W.GetXaxis().SetTitle('#eta') gr10W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n11W = len(X11W) gr11W = TGraph(n11W, X11W, Y11W) gr11W.SetLineColor(5) gr11W.SetLineWidth(7) gr11W.SetMarkerColor(kBlue) gr11W.SetMarkerStyle(23) gr11W.SetMarkerSize(1.5) gr11W.SetTitle('Layer 4 Wheel') gr11W.GetXaxis().SetTitle('#eta') gr11W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n12W = len(X12W) gr12W = TGraph(n12W, X12W, Y12W) gr12W.SetLineColor(5) gr12W.SetLineWidth(7) gr12W.SetMarkerColor(6) gr12W.SetMarkerStyle(22) gr12W.SetMarkerSize(1.5) gr12W.SetTitle('Layer 4 Wheel') gr12W.GetXaxis().SetTitle('#eta') gr12W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n13W = len(X13W) gr13W = TGraph(n13W, X13W, Y13W) gr13W.SetLineColor(5) gr13W.SetLineWidth(7) gr13W.SetMarkerColor(28) gr13W.SetMarkerStyle(23) gr13W.SetMarkerSize(1.5) gr13W.SetTitle('Layer 4 Wheel') gr13W.GetXaxis().SetTitle('#eta') gr13W.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') print "------ Creating Endcap TGraph ----------" n5E = len(X5E) gr5E = TGraph(n5E, X5E, Y5E) gr5E.SetLineColor(2) gr5E.SetLineWidth(4) gr5E.SetMarkerColor(6) gr5E.SetMarkerStyle(26) gr5E.SetMarkerSize(1.5) gr5E.SetTitle('Layer 1 Endcap') gr5E.GetXaxis().SetTitle('#eta') gr5E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n6E = len(X6E) gr6E = TGraph(n6E, X6E, Y6E) gr6E.SetLineColor(3) gr6E.SetLineWidth(5) gr6E.SetMarkerColor(28) gr6E.SetMarkerStyle(32) gr6E.SetMarkerSize(1.5) gr6E.SetTitle('Layer 2 Endcap') gr6E.GetXaxis().SetTitle('#eta') gr6E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n7E = len(X7E) gr7E = TGraph(n7E, X7E, Y7E) gr7E.SetLineColor(4) gr7E.SetLineWidth(6) gr7E.SetMarkerColor(kRed) gr7E.SetMarkerStyle(24) gr7E.SetMarkerSize(1.5) gr7E.SetTitle('Layer 3 Endcap') gr7E.GetXaxis().SetTitle('#eta') gr7E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n8E = len(X8E) gr8E = TGraph(n8E, X8E, Y8E) gr8E.SetLineColor(5) gr8E.SetLineWidth(7) gr8E.SetMarkerColor(kBlue) gr8E.SetMarkerStyle(30) gr8E.SetMarkerSize(1.5) gr8E.SetTitle('Layer 4 Endcap') gr8E.GetXaxis().SetTitle('#eta') gr8E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n9E = len(X9E) gr9E = TGraph(n9E, X9E, Y9E) gr9E.SetLineColor(5) gr9E.SetLineWidth(7) gr9E.SetMarkerColor(kRed + 2) gr9E.SetMarkerStyle(25) gr9E.SetMarkerSize(1.5) gr9E.SetTitle('Layer 4 Endcap') gr9E.GetXaxis().SetTitle('#eta') gr9E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n10E = len(X10E) gr10E = TGraph(n10E, X10E, Y10E) gr10E.SetLineColor(5) gr10E.SetLineWidth(7) gr10E.SetMarkerColor(kRed) gr10E.SetMarkerStyle(25) gr10E.SetMarkerSize(1.5) gr10E.SetTitle('Layer 4 Endcap') gr10E.GetXaxis().SetTitle('#eta') gr10E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n11E = len(X11E) gr11E = TGraph(n11E, X11E, Y11E) gr11E.SetLineColor(5) gr11E.SetLineWidth(7) gr11E.SetMarkerColor(kBlue) gr11E.SetMarkerStyle(32) gr11E.SetMarkerSize(1.5) gr11E.SetTitle('Layer 4 Endcap') gr11E.GetXaxis().SetTitle('#eta') gr11E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n12E = len(X12E) gr12E = TGraph(n12E, X12E, Y12E) gr12E.SetLineColor(5) gr12E.SetLineWidth(7) gr12E.SetMarkerColor(6) gr12E.SetMarkerStyle(26) gr12E.SetMarkerSize(1.5) gr12E.SetTitle('Layer 4 Endcap') gr12E.GetXaxis().SetTitle('#eta') gr12E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') n13E = len(X13E) gr13E = TGraph(n13E, X13E, Y13E) gr13E.SetLineColor(5) gr13E.SetLineWidth(7) gr13E.SetMarkerColor(28) gr13E.SetMarkerStyle(32) gr13E.SetMarkerSize(1.5) gr13E.SetTitle('Layer 4 Endcap') gr13E.GetXaxis().SetTitle('#eta') gr13E.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') print "----- Reading Fluka Info -----" f = TFile.Open("../FlukaEta.root") flukaRB1 = f.RB1 flukaRB1.SetMarkerColor(2) flukaRB1.SetMarkerStyle(20) flukaRB2 = f.RB2 flukaRB2.SetMarkerColor(2) flukaRB2.SetMarkerStyle(20) flukaRB3 = f.RB3 flukaRB3.SetMarkerColor(2) flukaRB3.SetMarkerStyle(20) flukaRB4 = f.RB4 flukaRB4.SetMarkerColor(2) flukaRB4.SetMarkerStyle(20) flukaRE1 = f.RE1 flukaRE1.SetMarkerColor(2) flukaRE1.SetMarkerStyle(4) flukaRE2 = f.RE2 flukaRE2.SetMarkerColor(2) flukaRE2.SetMarkerStyle(4) flukaRE3 = f.RE3 flukaRE3.SetMarkerColor(2) flukaRE3.SetMarkerStyle(4) flukaRE4 = f.RE4 flukaRE4.SetMarkerColor(2) flukaRE4.SetMarkerStyle(4) print "I did open the file" print flukaRB1, flukaRE4 print "----- Creating TCanvas -----" H = 800 W = 1600 canv = TCanvas("c1", "Canvas", 50, 50, W, H) canv.SetFillColor(0) canv.SetBorderMode(0) canv.SetFrameFillStyle(0) canv.SetFrameBorderMode(0) canv.SetLeftMargin(L / W) canv.SetRightMargin(R / W) canv.SetTopMargin(T / H) canv.SetBottomMargin(B / H) canv.SetTickx(0) canv.SetTicky(0) canv.Divide(3, 2, 0.001, 0.001) CMS_lumi.CMS_lumi(canv, iPeriod, iPos) canv.cd() canv.Update() maxY = 1000 canv.cd(1) gPad.SetLogy() print " ------------ Creating TMultiGraph -----------" mg1 = TMultiGraph() gr0E.SetMarkerColor(4) gr0W.SetMarkerColor(4) gr7E.SetMarkerColor(4) gr7W.SetMarkerColor(4) mg1.Add(gr0E, "AP") mg1.Add(gr0W, "AP") mg1.Add(gr7E, "AP") mg1.Add(gr7W, "AP") mg1.Add(flukaRB1, "AP") mg1.Add(flukaRE1, "AP") mg1.Draw("a") mg1.SetTitle('RB1in') mg1.GetXaxis().SetTitle('#eta') mg1.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg1.SetMaximum(maxY) mg1.GetXaxis().SetLabelFont(42) mg1.GetXaxis().SetLabelOffset(0.007) mg1.GetXaxis().SetLabelSize(0.043) mg1.GetXaxis().SetTitleSize(0.05) mg1.GetXaxis().SetTitleOffset(1.06) mg1.GetXaxis().SetTitleFont(42) mg1.GetYaxis().SetLabelFont(42) mg1.GetYaxis().SetLabelOffset(0.008) mg1.GetYaxis().SetLabelSize(0.05) mg1.GetYaxis().SetTitleSize(0.06) mg1.GetYaxis().SetTitleOffset(0.87) mg1.GetYaxis().SetTitleFont(42) pvtxt = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvtxt.AddText('CMS Preliminary') pvtxt.SetFillStyle(0) pvtxt.SetBorderSize(0) pvtxt.SetTextSize(0.03) pvtxt.Draw() pvtxt100 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvtxt100.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvtxt100.SetFillStyle(0) pvtxt100.SetBorderSize(0) pvtxt100.SetTextSize(0.03) pvtxt100.Draw() canv.cd(2) gPad.SetLogy() gr00 = TGraph() gr00.SetMarkerColor(kBlack) gr00.SetMarkerStyle(20) gr00.SetMarkerSize(1.5) gr01 = TGraph() gr01.SetMarkerColor(kBlack) gr01.SetMarkerStyle(24) gr01.SetMarkerSize(1.5) legend0 = TLegend(0.2, 0.75, .8, .95) legend0.SetNColumns(1) legend0.AddEntry(gr00, "Barrel", "p") legend0.AddEntry(gr01, "Endcaps", "p") legend0.Draw("a same") legendi = TLegend(0.2, 0.15, .8, .69) legendi.SetNColumns(1) legendi.AddEntry(gr7W, "RB1in + RE1", "p") legendi.AddEntry(gr8W, "RB1out + RE1", "p") legendi.AddEntry(gr9W, "RB2 + RE2", "p") # legendi.AddEntry(gr10W, "RB2in + RE2" , "p") # legendi.AddEntry(gr11W, "RB2out + RE2" , "p") legendi.AddEntry(gr12W, "RB3 + RE3", "p") legendi.AddEntry(gr13W, "RB4 + RE4", "p") legendi.AddEntry(flukaRB1, "Fluka Simulation", "p") legendi.SetTextSize(0.05) legendi.Draw("a") canv.cd(3) gPad.SetLogy() mg2 = TMultiGraph() gr1E.SetMarkerColor(4) gr1W.SetMarkerColor(4) gr8E.SetMarkerColor(4) gr8W.SetMarkerColor(4) mg2.Add(gr1E, "AP") mg2.Add(gr1W, "AP") mg2.Add(gr8E, "AP") mg2.Add(gr8W, "AP") mg2.Add(flukaRB1, "AP") mg2.Add(flukaRE1, "AP") mg2.Draw("a") mg2.SetTitle('RB1out') mg2.GetXaxis().SetTitle('#eta') mg2.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg2.SetMaximum(maxY) mg2.GetXaxis().SetLabelFont(42) mg2.GetXaxis().SetLabelOffset(0.007) mg2.GetXaxis().SetLabelSize(0.043) mg2.GetXaxis().SetTitleSize(0.05) mg2.GetXaxis().SetTitleOffset(1.06) mg2.GetXaxis().SetTitleFont(42) mg2.GetYaxis().SetLabelFont(42) mg2.GetYaxis().SetLabelOffset(0.008) mg2.GetYaxis().SetLabelSize(0.05) mg2.GetYaxis().SetTitleSize(0.06) mg2.GetYaxis().SetTitleOffset(0.87) mg2.GetYaxis().SetTitleFont(42) pvtxt3 = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvtxt3.AddText('CMS Preliminary') pvtxt3.SetFillStyle(0) pvtxt3.SetBorderSize(0) pvtxt3.SetTextSize(0.03) pvtxt3.Draw() pvtxt4 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvtxt4.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvtxt4.SetFillStyle(0) pvtxt4.SetBorderSize(0) pvtxt4.SetTextSize(0.03) pvtxt4.Draw() canv.cd(4) gPad.SetLogy() mg3 = TMultiGraph() #graphAxis(mg3) gr2E.SetMarkerColor(4) gr2W.SetMarkerColor(4) gr9E.SetMarkerColor(4) gr9W.SetMarkerColor(4) mg3.Add(gr2E, "AP") mg3.Add(gr2W, "AP") mg3.Add(gr9E, "AP") mg3.Add(gr9W, "AP") mg3.Add(flukaRB2, "AP") mg3.Add(flukaRE2, "AP") mg3.Draw("a") mg3.SetTitle('RB2') mg3.GetXaxis().SetTitle('#eta') mg3.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg3.SetMaximum(maxY) mg3.GetXaxis().SetLabelFont(42) mg3.GetXaxis().SetLabelOffset(0.007) mg3.GetXaxis().SetLabelSize(0.043) mg3.GetXaxis().SetTitleSize(0.05) mg3.GetXaxis().SetTitleOffset(1.06) mg3.GetXaxis().SetTitleFont(42) mg3.GetYaxis().SetLabelFont(42) mg3.GetYaxis().SetLabelOffset(0.008) mg3.GetYaxis().SetLabelSize(0.05) mg3.GetYaxis().SetTitleSize(0.06) mg3.GetYaxis().SetTitleOffset(0.87) mg3.GetYaxis().SetTitleFont(42) pvtxt5 = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvtxt5.AddText('CMS Preliminary') pvtxt5.SetFillStyle(0) pvtxt5.SetBorderSize(0) pvtxt5.SetTextSize(0.03) pvtxt5.Draw() pvtxt6 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvtxt6.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvtxt6.SetFillStyle(0) pvtxt6.SetBorderSize(0) pvtxt6.SetTextSize(0.03) pvtxt6.Draw() canv.cd(5) gPad.SetLogy() mg4 = TMultiGraph() #graphAxis(mg4) gr5E.SetMarkerColor(4) gr5W.SetMarkerColor(4) gr12E.SetMarkerColor(4) gr12W.SetMarkerColor(4) mg4.Add(gr5E, "AP") mg4.Add(gr5W, "AP") mg4.Add(gr12E, "AP") mg4.Add(gr12W, "AP") mg4.Add(flukaRB3, "AP") mg4.Add(flukaRE3, "AP") mg4.Draw("a") mg4.SetTitle('RB3') mg4.GetXaxis().SetTitle('#eta') mg4.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg4.SetMaximum(maxY) mg4.GetXaxis().SetLabelFont(42) mg4.GetXaxis().SetLabelOffset(0.007) mg4.GetXaxis().SetLabelSize(0.043) mg4.GetXaxis().SetTitleSize(0.05) mg4.GetXaxis().SetTitleOffset(1.06) mg4.GetXaxis().SetTitleFont(42) mg4.GetYaxis().SetLabelFont(42) mg4.GetYaxis().SetLabelOffset(0.008) mg4.GetYaxis().SetLabelSize(0.05) mg4.GetYaxis().SetTitleSize(0.06) mg4.GetYaxis().SetTitleOffset(0.87) mg4.GetYaxis().SetTitleFont(42) pvtxt7 = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvtxt7.AddText('CMS Preliminary') pvtxt7.SetFillStyle(0) pvtxt7.SetBorderSize(0) pvtxt7.SetTextSize(0.03) pvtxt7.Draw() pvtxt8 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvtxt8.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvtxt8.SetFillStyle(0) pvtxt8.SetBorderSize(0) pvtxt8.SetTextSize(0.03) pvtxt8.Draw() canv.cd(6) gPad.SetLogy() mg5 = TMultiGraph() #graphAxis(mg5) gr6E.SetMarkerColor(4) gr6W.SetMarkerColor(4) gr13E.SetMarkerColor(4) gr13W.SetMarkerColor(4) mg5.Add(gr6E, "AP") mg5.Add(gr6W, "AP") mg5.Add(gr13E, "AP") mg5.Add(gr13W, "AP") mg5.Add(flukaRB4, "AP") mg5.Add(flukaRE4, "AP") mg5.Draw("a") mg5.SetTitle('RB4') mg5.GetXaxis().SetTitle('#eta') mg5.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg5.SetMaximum(maxY) mg5.GetXaxis().SetLabelFont(42) mg5.GetXaxis().SetLabelOffset(0.007) mg5.GetXaxis().SetLabelSize(0.043) mg5.GetXaxis().SetTitleSize(0.05) mg5.GetXaxis().SetTitleOffset(1.06) mg5.GetXaxis().SetTitleFont(42) mg5.GetYaxis().SetLabelFont(42) mg5.GetYaxis().SetLabelOffset(0.008) mg5.GetYaxis().SetLabelSize(0.05) mg5.GetYaxis().SetTitleSize(0.06) mg5.GetYaxis().SetTitleOffset(0.87) mg5.GetYaxis().SetTitleFont(42) pvtxt10 = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvtxt10.AddText('CMS Preliminary') pvtxt10.SetFillStyle(0) pvtxt10.SetBorderSize(0) pvtxt10.SetTextSize(0.03) pvtxt10.Draw() pvtxt9 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvtxt9.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvtxt9.SetFillStyle(0) pvtxt9.SetBorderSize(0) pvtxt9.SetTextSize(0.03) pvtxt9.Draw() canv.SaveAs("etaDistro.gif") canv.SaveAs("etaDistro.png") canv.SaveAs("etaDistro.pdf") canv.SaveAs("etaDistro.C") canv.Close() print "----- Creating Second TCanvas -----" H = 800 W = 800 c = TCanvas("c1", "Canvas", 50, 50, W, H) c.SetFillColor(0) c.SetBorderMode(0) c.SetFrameFillStyle(0) c.SetFrameBorderMode(0) c.SetLeftMargin(L / W) c.SetRightMargin(R / W) c.SetTopMargin(T / H) c.SetBottomMargin(B / H) c.SetTickx(0) c.SetTicky(0) gPad.SetLogy() print " ------------ Creating TMultiGraph -----------" mg = TMultiGraph() mg.Add(gr0E, "AP") mg.Add(gr0W, "AP") mg.Add(gr7E, "AP") mg.Add(gr7W, "AP") mg.Add(gr1W, "AP") mg.Add(gr8W, "AP") mg.Add(flukaRB1, "AP") mg.Add(flukaRE1, "AP") mg.Draw("a") mg.SetTitle('RB1in') mg.GetXaxis().SetTitle('#eta') mg.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mg.SetMaximum(maxY) mg.GetXaxis().SetLabelFont(42) mg.GetXaxis().SetLabelOffset(0.007) mg.GetXaxis().SetLabelSize(0.043) mg.GetXaxis().SetTitleSize(0.05) mg.GetXaxis().SetTitleOffset(1.06) mg.GetXaxis().SetTitleFont(42) mg.GetYaxis().SetLabelFont(42) mg.GetYaxis().SetLabelOffset(0.008) mg.GetYaxis().SetLabelSize(0.05) mg.GetYaxis().SetTitleSize(0.06) mg.GetYaxis().SetTitleOffset(0.87) mg.GetYaxis().SetTitleFont(42) pvt = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pvt.AddText('CMS Preliminary') pvt.SetFillStyle(0) pvt.SetBorderSize(0) pvt.SetTextSize(0.03) pvt.Draw() pvt1 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pvt1.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pvt1.SetFillStyle(0) pvt1.SetBorderSize(0) pvt1.SetTextSize(0.03) pvt1.Draw() legenda = TLegend(0.4, 0.7, .7, .9) legenda.SetNColumns(1) legenda.AddEntry(gr0E, "RE1", "p") legenda.AddEntry(gr0W, "RB1in", "p") legenda.AddEntry(gr1W, "RB1out", "p") legenda.AddEntry(flukaRB1, "Fluka Simulation", "p") legenda.SetTextSize(0.05) legenda.Draw("a") c.SaveAs("etaDistroDetailRB1.png") c.SaveAs("etaDistroDetailRB1.gif") c.SaveAs("etaDistroDetailRB1.pdf") c.SaveAs("etaDistroDetailRB1.C") c.Close() print "----- Creating Second TCanvas -----" c1 = TCanvas("c1", "Canvas", 50, 50, W, H) c1.SetFillColor(0) c1.SetBorderMode(0) c1.SetFrameFillStyle(0) c1.SetFrameBorderMode(0) c1.SetLeftMargin(L / W) c1.SetRightMargin(R / W) c1.SetTopMargin(T / H) c1.SetBottomMargin(B / H) c1.SetTickx(0) c1.SetTicky(0) gPad.SetLogy() print " ------------ Creating TMultiGraph -----------" mgd2 = TMultiGraph() gr3E.SetMarkerColor(4) gr3W.SetMarkerColor(4) gr10E.SetMarkerColor(4) gr10W.SetMarkerColor(4) gr4W.SetMarkerColor(4) gr11W.SetMarkerColor(4) mgd2.Add(gr3E, "AP") mgd2.Add(gr3W, "AP") mgd2.Add(gr10E, "AP") mgd2.Add(gr10W, "AP") mgd2.Add(gr4W, "AP") mgd2.Add(gr11W, "AP") mgd2.Add(flukaRB2, "AP") mgd2.Add(flukaRE2, "AP") mgd2.Draw("a") mgd2.SetTitle('RB1in') mgd2.GetXaxis().SetTitle('#eta') mgd2.GetYaxis().SetTitle('RPC single hit rate (Hz/cm^{2})') mgd2.SetMaximum(maxY) mgd2.GetXaxis().SetLabelFont(42) mgd2.GetXaxis().SetLabelOffset(0.007) mgd2.GetXaxis().SetLabelSize(0.043) mgd2.GetXaxis().SetTitleSize(0.05) mgd2.GetXaxis().SetTitleOffset(1.06) mgd2.GetXaxis().SetTitleFont(42) mgd2.GetYaxis().SetLabelFont(42) mgd2.GetYaxis().SetLabelOffset(0.008) mgd2.GetYaxis().SetLabelSize(0.05) mgd2.GetYaxis().SetTitleSize(0.06) mgd2.GetYaxis().SetTitleOffset(0.87) mgd2.GetYaxis().SetTitleFont(42) pv = TPaveText(.1, 0.97, .55, 0.97, "NDC") #(.06,.4,.55,.73) pv.AddText('CMS Preliminary') pv.SetFillStyle(0) pv.SetBorderSize(0) pv.SetTextSize(0.03) pv.Draw() pv1 = TPaveText(.7, 0.97, .9, 0.97, "NDC") pv1.AddText('1.5 #times 10^{34} Hz/cm^{2} (13 TeV)') pv1.SetFillStyle(0) pv1.SetBorderSize(0) pv1.SetTextSize(0.03) pv1.Draw() legendd2 = TLegend(0.4, 0.6, .7, .8) legendd2.SetNColumns(1) legendd2.AddEntry(gr3E, "RE2", "p") legendd2.AddEntry(gr3W, "RB2in", "p") legendd2.AddEntry(gr4W, "RB2out", "p") legendd2.AddEntry(flukaRB2, "Fluka Simulation", "p") legendd2.SetTextSize(0.05) legendd2.Draw("a") c1.SaveAs("etaDistroDetailRB2.png") c1.SaveAs("etaDistroDetailRB2.pdf") c1.SaveAs("etaDistroDetailRB2.gif") c1.SaveAs("etaDistroDetailRB2.C")
def draw_syst_unc_envelope(unc_type, added): print "Drawing uncertainty vs mass" with open(OUT + "signal_" + unc_type + "_unc" + added + ".yaml", "r") as f: results = yaml.load(f, Loader=yaml.Loader) f.close() samp = results.keys() masses = [] ctaus = [] for s in samp: masses.append(samples[s]['mass']) ctaus.append(samples[s]['ctau']) masses = np.unique(np.sort(np.array(masses))) ctaus = np.unique(np.sort(np.array(ctaus))) print masses print ctaus mg = TMultiGraph() leg1 = TLegend(0.6, 0.2, 0.9, 0.5) #leg1 = TLegend(0.15+0.5, 0.6+0.2, 0.3+0.5, 0.9) colors = [2, 418, 801, 856, 602, 920, 881] diff_up = {} diff_down = {} count_c = 0 print "$c \\tau$ (m) & $m_{\chi}$ (GeV) & uncertainty (\%)" + "\\" + "\\" for m in masses: string = "" nt = 0 for c in ctaus: for s in samp: if "mh" + str(m) + "_ctau" + str(c) in s: string += str(c / 1000.) + " & " + str(m) + " & " + str( "%.1f" % results[s]['diff_y2_up']) if nt == 0: string += " & " nt += 1 print string + "\\" + "\\" for c in ctaus: diff_up[c] = TGraph() n = 0 for m in masses: for s in samp: if "mh" + str(m) + "_ctau" + str(c) in s: diff_up[c].SetPoint(n, m, results[s]['diff_y2_up']) n += 1 diff_up[c].SetMarkerStyle(24) diff_up[c].SetMarkerColor(colors[count_c]) diff_up[c].SetLineColor(colors[count_c]) diff_up[c].SetLineWidth(2) diff_up[c].GetXaxis().SetTitle("m_{#chi} (GeV)") diff_up[c].GetYaxis().SetTitle("Uncertainty (%)") diff_up[c].GetYaxis().SetTitleSize(0.05) diff_up[c].SetMinimum(0) if unc_type == "PDF": leg1.AddEntry(diff_up[c], "c_{#tau} = " + str(c / 1000.) + " m; PDF envelope", "PL") if unc_type == "QCD_scales": leg1.AddEntry( diff_up[c], "c_{#tau} = " + str(c / 1000.) + " m; QCD scales envelope", "PL") mg.Add(diff_up[c]) count_c += 1 c1 = TCanvas("c1", "c1", 800, 600) c1.SetGrid() c1.SetTopMargin(0.06) c1.SetBottomMargin(0.12) c1.SetRightMargin(0.05) c1.SetLeftMargin(0.12) c1.SetTicks(1, 1) mg.GetXaxis().SetTitle("m_{#chi} (GeV)") mg.GetYaxis().SetTitle("Uncertainty (%)") mg.GetXaxis().SetTitleSize(0.05) mg.GetYaxis().SetTitleSize(0.05) mg.SetMinimum(0.) mg.SetMaximum(16.) mg.Draw("APL") leg1.Draw() drawCMS_simple(LUMI, "Preliminary", ERA=ERA, onTop=True) #drawAnalysis("LL"+CHAN) drawRegion(SEL) #c1.SetLogx() c1.Print(OUT + "signal_" + unc_type + "_uncertainty" + added + ".pdf") c1.Print(OUT + "signal_" + unc_type + "_uncertainty" + added + ".png") c1.Close()
def main(): from optparse import OptionParser parser = OptionParser() parser.add_option("-i", "--inputfile", dest="inputfile") parser.add_option("-m", "--model", dest="model", type="string") (options, args) = parser.parse_args() from ROOT import TFile, TMultiGraph, TCanvas, TLegend from Styles import formatXsecCL import configurations as config from ROOT import gStyle gStyle.SetPadTopMargin(0.05) gStyle.SetPadRightMargin(0.05) infile = TFile(options.inputfile, "READ") infile_xsec = TFile(config.bh_xsec, "READ") store = [] for n in config.extraDim_list: c = TCanvas("%s-n%d" % (options.model,n),\ "%s-n%d" % (options.model,n),\ 500, 500) store.append(c) graphs = TMultiGraph() store.append(graphs) legend = TLegend(0.5266129, 0.5360169, 0.9476613, 0.9364407) legend.SetTextSize(0.02966102) legend.SetFillColor(0) legend.SetLineColor(0) legend.SetHeader("n = %d" % n) store.append(legend) for i, MD in enumerate(config.MD_list): gCL95 = infile.Get("%s-MD%.1f_n%d-CL95" % (options.model, MD, n)) gXsec = infile_xsec.Get("%s-MD%.1f_n%d" % (options.model, MD, n)) if gCL95 and gXsec: legend.AddEntry(gCL95, "M_{D} = %.1f TeV Observed" % MD, "l") formatXsecCL(gCL95, i, 1) graphs.Add(gCL95, "l") legend.AddEntry(gXsec, "M_{D} = %.1f TeV Theoretical" % MD, "l") formatXsecCL(gXsec, i, 2) graphs.Add(gXsec, "c") graphs.Draw("a") graphs.GetXaxis().SetTitle("M_{BH}^{ min} (TeV)") graphs.GetYaxis().SetTitle("#sigma (pb)") graphs.GetYaxis().SetTitleOffset(1.2) graphs.GetXaxis().SetRangeUser(4.5, 7.5) graphs.SetMinimum(1e-4) graphs.SetMaximum(1) c.SetLogy() legend.Draw("plain") c.Print("MassLimit_%s_n%d.pdf" % (options.model, n)) c.Print("MassLimit_%s_n%d.png" % (options.model, n)) c.Update() raw_input("Press Enter to continue...")
norm_graphs = [] for i in range(n_samples): graphs_vy_array = numpy.asarray(graphs_vy[i]) norm_graphs.append(ROOT.TGraph(len(graphs_vx), graphs_vx, graphs_vy_array)) # convert lists to arrays norm_graphs[i].GetXaxis().SetTitle('bdt cut') norm_graphs[i].GetYaxis().SetTitle('S/#sqrt{S+B} a.u.') norm_graphs[i].SetTitle('') norm_graphs[i].SetMarkerStyle(8) norm_graphs[i].SetName('graph_sample%s' % i) norm_graphs[i].SetMarkerColor(ROOT.kViolet + i) norm_graphs[i].SetMarkerStyle(20 + i) mg = TMultiGraph() for i in range(n_samples): mg.Add(norm_graphs[i]) canv = ROOT.TCanvas() mg.Draw('AP') mg.GetXaxis().SetTitle('BDT score') mg.GetYaxis().SetTitle('S/#sqrt{S+B}') leg = ROOT.TLegend(0.4, 0.16, 0.7, 0.46) for i in range(11): leg.AddEntry(norm_graphs[i], 'BDT %s' % i, 'p') leg.SetBorderSize(0) leg.Draw() canv.SaveAs('bdt_wps_MassFlatten_onlyRT_noB0PsiCut_scale%s.pdf' % scale)
colorset(gr = gr6, color = 1) leg.AddEntry(gr6, options.label6, 'Lp') entries += 1 #canv.Update() #mg.GetXaxis().SetTitle("#kappa_t (no kinematics)") #mg.GetYaxis().SetTitle("-2#Delta lnL") #gPad.Modified() #mg.GetYaxis().SetRangeUser(0.,3.) mg.SetTitle("Multi-graph Title; X-axis Title; Y-axis Title"); mg.Draw('apl, same') canv.Update() mg.GetXaxis().SetTitle("#kappa_t (no kinematics)") mg.GetYaxis().SetTitle("-2#Delta lnL") gPad.Modified() mg.GetYaxis().SetRangeUser(0.,55.) xmin = mg.GetXaxis().GetXmin() xmax = mg.GetXaxis().GetXmax() mg.GetXaxis().SetRangeUser(xmin,xmax) #mg.Draw('ap') lat = TLatex() lat.SetNDC() lat.SetTextFont(43) lat.SetTextSize(32) lat.DrawLatex(0.12, 0.92, "#bf{CMS} #it{Internal}")
def plot(tgr, n): #(List, layer, tgrDict): H = 1600 W = 800 #print "----- Creating Third TCanvas -----" c = TCanvas("c", "Canvas", W, H) ymax = 0.0 c.SetLeftMargin(0.15) c.SetRightMargin(0.06) c.SetTopMargin(0.09) c.SetBottomMargin(0.14) #gPad.SetGrid() gPad.SetTicks() #gPad.SetLogy() mg = TMultiGraph() tgr.SetMarkerColor(kGreen + 3) tgr.SetMarkerStyle(21) tgr.SetMarkerSize(1.5) mg.Add(tgr, 'AP') mg.Draw("a") l = TLegend(0.42, 0.15, 0.82, 0.35) l.SetFillColor(0) l.SetBorderSize(0) l.SetTextSize(0.03) l.SetNColumns(1) l.AddEntry(tgr, "CMS (13TeV)", "p") mg.SetTitle('') #mg.SetMaximum(ymax*1.1) mg.GetXaxis().SetTitle('Instantaneous Luminosity 10^{34} cm^{-2} s^{-1}') mg.GetXaxis().SetLabelFont(42) mg.GetXaxis().SetLabelOffset(0.007) mg.GetXaxis().SetLabelSize(0.043) mg.GetXaxis().SetTitleSize(0.03) mg.GetXaxis().SetTitleOffset(1.56) mg.GetXaxis().SetTitleFont(42) mg.GetYaxis().SetTitle('rate (Hz/cm^{2})') mg.GetYaxis().SetLabelFont(42) mg.GetYaxis().SetLabelOffset(0.008) mg.GetYaxis().SetLabelSize(0.02) mg.GetYaxis().SetTitleSize(0.03) mg.GetYaxis().SetTitleOffset(1.37) mg.GetYaxis().SetTitleFont(42) pv = TPaveText(.08, 0.94, .45, 0.94, "NDC") pv.AddText('CMS Preliminary Rack {}'.format(n)) pv.SetFillStyle(0) pv.SetBorderSize(0) pv.SetTextSize(0.04) pv.Draw() fun1 = TF1("fun1", "pol1", 6000, 16000) fit1 = tgr.Fit("fun1", "R") # "FQ") offset1 = fun1.GetParameter(0) slope1 = fun1.GetParameter(1) l.AddEntry(tgr, 'The p0 value is {0:.6f}'.format(offset1)) l.AddEntry(tgr, 'The p1 value is {0:.6f}'.format(slope1)) l.Draw("a") c.SaveAs("rack{}.png".format(n)) c.SaveAs("rack{}.pdf".format(n)) c.SaveAs("rack{}.C".format(n)) return
canvas.Print("metEfficiencyPlotWithRate_ff_W_munu_1000events.pdf", "pdf") metEfficiencyPlotWithRate = TMultiGraph("metEfficiencyPlotWithRate", "") metEfficiencyPlotWithRate.Add(efficiencyPlotWithRate_ff_H_WW_enuenu_1000events) efficiencyPlotWithRate_ff_H_WW_enuenu_1000events.SetMarkerColor(6) metEfficiencyPlotWithRate.Add(efficiencyPlotWithRate_ff_H_WW_munumunu_1000events) efficiencyPlotWithRate_ff_H_WW_munumunu_1000events.SetMarkerColor(2) metEfficiencyPlotWithRate.Add(efficiencyPlotWithRate_ff_W_enu_1000events) efficiencyPlotWithRate_ff_W_enu_1000events.SetMarkerColor(3) metEfficiencyPlotWithRate.Add(efficiencyPlotWithRate_ff_W_munu_1000events) efficiencyPlotWithRate_ff_W_munu_1000events.SetMarkerColor(4) efficiencyPlotWithRate_ff_W_munu_1000events.SetLineColor(1) metEfficiencyPlotWithRate.Draw("AP") metEfficiencyPlotWithRate.GetXaxis().SetTitle("Rate [Hz]") metEfficiencyPlotWithRate.GetXaxis().SetTitleOffset(1.2) metEfficiencyPlotWithRate.GetYaxis().SetTitle("% accepted events") metEfficiencyPlotWithRate.GetYaxis().SetTitleOffset(1.2) metEfficiencyPlotWithRate.GetYaxis().SetRangeUser(0, 1.1) line_200kHz.Draw() label_200kHz.Draw() metEfficiencyPlotWithRate_legend = TLegend(0.58 , 0.13, 0.9, 0.317) metEfficiencyPlotWithRate_legend.SetHeader("Physical process") metEfficiencyPlotWithRate_legend.AddEntry(efficiencyPlotWithRate_ff_H_WW_munumunu_1000events, "H #rightarrow WW #rightarrow #mu#nu_{#mu}#mu#nu_{#mu}", "P") metEfficiencyPlotWithRate_legend.AddEntry(efficiencyPlotWithRate_ff_H_WW_enuenu_1000events, "H #rightarrow WW #rightarrow e#nu_{e}e#nu_{e}", "P") metEfficiencyPlotWithRate_legend.AddEntry(efficiencyPlotWithRate_ff_W_munu_1000events, "W #rightarrow #mu#nu_{#mu}", "P") metEfficiencyPlotWithRate_legend.AddEntry(efficiencyPlotWithRate_ff_W_enu_1000events, "W #rightarrow e#nu_{e}", "P") metEfficiencyPlotWithRate_legend.Draw() text.Draw() canvas.Update() canvas.Print("metEfficiencyPlotWithRate.svg", "svg") canvas.Print("metEfficiencyPlotWithRate.png", "png")
# X Axis Style mg.GetXaxis().SetTitle("Current Drawn (#mu A)") mg.GetXaxis().SetTitleSize(0.06) mg.GetXaxis().SetLabelSize(0.05) mg.GetXaxis().SetNdivisions(508) mg.GetXaxis().SetLabelOffset(0.007) mg.GetXaxis().SetLabelFont(42) mg.GetXaxis().SetLabelColor(1) mg.GetXaxis().SetTitleOffset(0.9) mg.GetXaxis().SetAxisColor(1) r.TStyle().SetStripDecimals(r.kTRUE) mg.GetXaxis().SetTickLength(0.03) r.TStyle().SetPadTickX(1) # Y Axis Style mg.GetYaxis().SetTitle("Spurious Signal R_{SS} (Hz)") mg.GetYaxis().SetRangeUser(0, 50) mg.GetYaxis().SetLabelSize(0.05) mg.GetYaxis().SetLabelOffset(0.007) mg.GetYaxis().SetLabelFont(42) mg.GetYaxis().SetLabelColor(1) mg.GetYaxis().SetTitleSize(0.06) mg.GetYaxis().SetTitleOffset(1) mg.GetYaxis().SetNdivisions(510) r.TStyle().SetPadTickY(1) mg.GetYaxis().SetAxisColor(1) mg.GetYaxis().SetTickLength(0.03) r.TStyle().SetPadTickY(1) # For the Pad r.TStyle().SetPadBorderMode(0)
def plotROCfromgraph(graphs, xlabel, ylabel, legendNames, destination, year, xlog=False, ylog=False, additionalInformation=None): GeneralSettings() #Make sure single curves also pass try: len(graphs) except: graphs = [graphs] #Create Canvas Canv = TCanvas("Canv" + destination, "Canv" + destination, 1000, 1000) tdr.setTDRStyle() #Create TGraph mgraph = TMultiGraph() for i, graph in enumerate(graphs): graph.SetMarkerSize(1.5) graph.SetLineColor(TColor.GetColor(GetLineColor(graphs.index(graph)))) graph.SetMarkerColor(TColor.GetColor(GetLineColor( graphs.index(graph)))) graph.SetMarkerStyle(GetMarker(graphs.index(graph))) mgraph.Add(graph) mgraph.Draw("APLine") mgraph.SetTitle(";" + xlabel + ";" + ylabel) cl.CMS_lumi(Canv, 4, 11, year, 'Simulation', False) xmax = GetXMax(graphs) xmin = GetXMin(graphs) ymax = GetYMax(graphs) ymin = GetYMin(graphs) if xlog: Canv.SetLogx() mgraph.GetXaxis().SetRangeUser(0.3 * xmin, 30 * xmax) else: mgraph.GetXaxis().SetRangeUser(0.7 * xmin, 1.3 * xmax) if ylog: Canv.SetLogy() mgraph.GetYaxis().SetRangeUser(0.3 * ymin, 10 * ymax) else: mgraph.GetYaxis().SetRangeUser(0.5 * ymin, 1.2 * ymax) #Write extra text if additionalInformation is not None: lastYpos = 0.8 lastCorrectedYpos = None extraText = TLatex() for info in additionalInformation: try: extraTextString = info[0] extraTextXpos = info[1] extraTextYpos = info[2] extraTextSize = info[3] except: print("Wrong Format for additionalInformation. Stopping") pass if extraTextSize is None: extraTextSize = 0.03 if extraTextXpos is None: extraTextXpos = 0.2 if extraTextYpos is None: if lastYpos is None: extraTextYpos = lastCorrectedYpos - 0.05 else: extraTextYpos = 0.8 extraText.SetNDC() extraText.SetTextAlign(12) extraText.SetTextSize(extraTextSize) extraText.DrawLatex(extraTextXpos, extraTextYpos, extraTextString) lastYpos = info[2] lastCorrectedYpos = extraTextYpos if legendNames: legend = TLegend(0.7, .7, .9, .9) for g, n in zip(graphs, legendNames): legend.AddEntry(g, n) legend.SetFillStyle(0) legend.SetBorderSize(0) legend.Draw() #Save everything savePlots(Canv, destination)
def calc_punzi_FOM_vs_ctau(cutlist, labellist=[],mass_point=40,additional_string="",alpha=2,CL=5,FOM='punzi',header=""): file = {} nevt = {} tree = {} effs = {} chain = {} hist = {} eff_dict = { k:{} for k in cutlist} back_int = { k:{} for k in cutlist} back_int_weight = { k:{} for k in cutlist} back_eff = { k:{} for k in cutlist} punzi_dict = { k:{} for k in cutlist} graph = {} back_graph = {} ncuts = len(cutlist) if labellist == []: labellist=cutlist print NTUPLEDIR print "............." #prepare ctau ordered array for 1D plot mass_array = [] ctau_array = [] #for signal we have the normal efficiency for i, s in enumerate(sign): file[s] = TFile(NTUPLEDIR + samples[s]['files'][0] + ".root", "READ") # Read TFile tree[s] = file[s].Get("ntuple/tree") # Read TTree nevt[s] = (file[s].Get('counter/c_nEvents')).GetBinContent(1)# all gen events before cuts! #tree[s] = file[s].Get("skim") # Read TTree #nevt[s] = tree[s].GetEntries("")#if the tree is skimmed, this becomes a relative denominator #nevt[s] = (file[s].Get('c_nEvents')).GetBinContent(1)# all gen events before cuts! filename = TFile(NTUPLEDIR + samples[s]['files'][0] + ".root", "READ") if verbose_add: print '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~' if verbose_add: print filename if verbose_add: print "x-check: n gen events in counter, first bin:" if verbose_add: print (filename.Get('c_nEvents')).GetBinContent(1) if verbose_add: print "x-check: n entries in counter:" if verbose_add: print (filename.Get('c_nEvents')).GetEntries() effs[s] = [0]*(ncuts+1) effs[s] = [0]*(ncuts+1) weight = "1"#"EventWeight" var = "isMC" if samples[s]['mass'] not in mass_array: mass_array.append(samples[s]['mass']) if samples[s]['ctau'] not in ctau_array: ctau_array.append(samples[s]['ctau']) for j, c in enumerate(cutlist): tot_gen = nevt[s] n = tree[s].GetEntries("(" + cutlist[j] + ")") #wat?#test_op = cutlist[j] + " && number_of_matched_Jets>=1" #wat?#n = tree[s].GetEntries("(" + test_op + ")") ###BUGFIX: efficiency should be computed w.r.t. histo integral #hist[s+"_cut"+str(j)] = TH1F(s+"_cut"+str(j), ";"+variable[var]['title'], variable[var]['nbins'], variable[var]['min'], variable[var]['max']) #hist[s+"_cut"+str(j)].Sumw2() #cutstring = "("+weight+")" + ("*("+cutlist[j]+")" if len(cutlist[j])>0 else "") #tree[s].Project(s+"_cut"+str(j), var, cutstring) #hist[s+"_cut"+str(j)].SetOption("%s" % tree[s].GetTree().GetEntriesFast()) if verbose_add: print '\n' if verbose_add: print '**********************************************' if verbose_add: print "cut: ", c if verbose_add: print 'over signal ', s if verbose_add: print '\n' if verbose_add: print "signal num: ", n if verbose_add: print "signal den: ", tot_gen #if verbose_add: print "BUGFIX!!!!!!!!!!!" #if verbose: print "BUGFIX!!!!!!!!!!!" #if verbose_add: print "signal num from integral: ", hist[s+"_cut"+str(j)].Integral() #if verbose_add: print "signal den from generator: ", tot_gen #if verbose: print "BUGFIX!!!!!!!!!!!" if verbose_add: print ("signal eff %.2f") % (float(n)/(tot_gen)*100) if tot_gen==0: effs[s][j] = float(0.) else: effs[s][j] = (float(n)/(tot_gen)) eff_dict[c][s] = {'mass' : samples[s]['mass'], 'ctau' : samples[s]['ctau'], 'eff' :effs[s][j], 'nevents' : n} #sort mass array masses = np.array(mass_array) masses.sort() ctaus = np.array(ctau_array) ctaus.sort() #define multigraph mg = TMultiGraph() #leg = TLegend(0.78, 0.7, 0.98, 0.98) #leg2 = TLegend(0., 0.4, 0.98, 0.98) #leg2 = TLegend(0.3, 0.11, 0.65, 0.45)#DCMS,gen matching leg2 = TLegend(0.4, 0.11, 0.85, 0.45)#DCMS,summary plot leg2 = TLegend(0.4-0.3, 0.11+0.43, 0.85+0.05-0.3, 0.45+0.43)#EXO,summary plot leg2 = TLegend(0.4, 0.11, 0.85+0.05, 0.45)#EXO,summary plot leg3 = TLegend(0., 0.5, 0.5, 1.)#2 plots leg = TLegend(0., 0.4, 0.98, 0.98) leg.SetTextSize(0.03) leg2.SetTextSize(0.03) leg2.SetTextSize(0.025) leg.SetBorderSize(0) leg2.SetBorderSize(0) leg.SetHeader("Signal: m_{#pi}=" +str(mass_point)+" GeV") leg2.SetHeader("Signal: m_{#pi}=" +str(mass_point)+" GeV") leg3.SetTextSize(0.03) leg3.SetTextSize(0.025) leg3.SetBorderSize(0) leg3.SetHeader("Signal: m_{#pi}=" +str(mass_point)+" GeV") #for background let's first consider the cut for j, c in enumerate(cutlist): print '\n' print "cut: ", c print 'over background' print '\n' #then loop over background integral = 0 weighted_integral = 0 back_tot_events = 0 for i, s in enumerate(back): chain[s] = TChain("ntuple/tree") #chain[s] = TChain("skim") #print "back: ", s back_file = {} for p, ss in enumerate(samples[s]['files']): back_file[ss] = TFile(NTUPLEDIR + ss + ".root", "READ") # Read TFile #?#if verbose: print "file: ", ss #?#if verbose: print "gen events: ", (back_file[ss].Get('counter/c_nEvents')).GetBinContent(1) #?#if verbose: print "tree events: ", (back_file[ss].Get('ntuple/tree')).GetEntries() back_tot_events += (back_file[ss].Get('counter/c_nEvents')).GetBinContent(1) #back_tot_events += (back_file[ss].Get('c_nEvents')).GetBinContent(1) chain[s].Add(NTUPLEDIR + ss + ".root") #print "MODIFIED WEIGHT!!!!!!" #weight = ("EventWeight*%s/5000." % str(back_tot_events)) weight = "EventWeight" #var = "nCHSJets" var = "isMC" hist[s] = TH1F(s, ";"+variable[var]['title'], variable[var]['nbins'], variable[var]['min'], variable[var]['max']) hist[s].Sumw2() cutstring = "("+weight+")" + ("*("+cutlist[j]+")" if len(cutlist[j])>0 else "") chain[s].Project(s, var, "")#"1*"+"("+weight+")") hist[s].SetOption("%s" % chain[s].GetTree().GetEntriesFast()) #if verbose: print "Hist content, no cut:" #if verbose: print hist[s].Print() #?#if verbose: print "events in the histo with get entries with empty project: ", hist[s].GetEntries() #?#if verbose: print "area under histo with empty project: ", hist[s].Integral() chain[s].Project(s, var, cutstring)#"1*"+"("+weight+")") hist[s].SetOption("%s" % chain[s].GetTree().GetEntriesFast()) hist[s].Scale(samples[s]['weight'] if hist[s].Integral() >= 0 else 0) #?#if verbose: print "events in the histo with get entries after project: ", hist[s].GetEntries() #?#if verbose: print "area under histo after project: ", hist[s].Integral() if verbose: print "Hist content, with cut:" if verbose: print hist[s].Print() integral += hist[s].GetEntries() weighted_integral += hist[s].Integral() back_int[c] = integral back_int_weight[c] = weighted_integral if back_tot_events==0: back_eff[c] = float(0.) else: back_eff[c] = float(integral)/float(back_tot_events) if verbose: print "cut: ", c if verbose: print "back tot events (unweighted):", back_tot_events if verbose: print "back integral (unweighted): ", back_int[c] if verbose: print "back integral (weighted): ", back_int_weight[c] if verbose: print "back eff (unweighted): ", back_eff[c]*100 if FOM=="signaleff": punzi_dict[c]['back'] = {'back' : back_eff[c]*100} for i, s in enumerate(sign): if verbose: print "signal efficiency: ", eff_dict[c][s]['eff']*100 if FOM=="punzi": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']/(CL**2/2. + alpha*math.sqrt(back_int_weight[c]) + (CL/2.)*math.sqrt(CL**2 + 4*alpha*math.sqrt(back_int_weight[c]) + 4*back_int_weight[c]))} elif FOM=="signaleff": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']*100} elif FOM=="entries": punzi_dict[c][s] = {'sign': eff_dict[c][s]['nevents']} else: print "not punzi FOM, aborting!" exit() if FOM=="signaleff": dummy = TGraph()#len(ct),ct, np.array(ct)) dummy.SetMarkerStyle(0) dummy.SetLineWidth(2) dummy.SetMarkerSize(1.) dummy.SetLineColor(15) dummy.SetLineStyle(2) if header!="": leg2.AddEntry(dummy, header,'') leg3.AddEntry(dummy, header,'') #for each cut, we need a graph for j, c in enumerate(cutlist): #first let's build the ordered punzi vector w.r.t. masses, for a chosen ctau punzi_array = [] back_array = [] for la in ctaus: #la = str(a) if la== 0.001: st = CHANNEL+"_M"+str(mass_point)+"_ctau0" elif la==0.05 or la==0.1: st = CHANNEL+"_M"+str(mass_point)+"_ctau"+str(str(la).replace("0.","0p")) else: st = CHANNEL+"_M"+str(mass_point)+"_ctau"+str(int(la)) #st = "VBFH_M"+str(mass_point)+"_ctau"+str(a) punzi_array.append(punzi_dict[c][st]['sign']) mass = array('d', masses) ct = array('d', ctaus) p_array = array('d',punzi_array) #graph[c] = TGraph(len(mass),mass, np.array(p_array)) graph[c] = TGraph(len(ct),ct, np.array(p_array)) graph[c].SetMarkerStyle(markers[j])#21 graph[c].SetLineWidth(3) graph[c].SetMarkerSize(1.2) graph[c].SetMarkerColor(colors[j]) graph[c].SetLineColor(colors[j]) graph[c].SetFillColor(colors[j]) #graph[c].SetLogx() leg.AddEntry(graph[c],labellist[j],'PL') leg2.AddEntry(graph[c],labellist[j],'PL') leg3.AddEntry(graph[c],labellist[j],'PL') mg.Add(graph[c]) if FOM=="signaleff": #add plot for background for a in ctaus: back_array.append(punzi_dict[c]['back']['back']) mass = array('d', masses) ct = array('d', ctaus) e_array = array('d',back_array) #back_graph[c] = TGraph(len(mass),mass, np.array(e_array)) back_graph[c] = TGraph(len(ct),ct, np.array(e_array)) back_graph[c].SetMarkerStyle(0) back_graph[c].SetLineWidth(2) back_graph[c].SetMarkerSize(1.) back_graph[c].SetMarkerColor(colors[j]) back_graph[c].SetLineColor(colors[j]) back_graph[c].SetLineStyle(2) back_graph[c].SetFillColor(colors[j]) #back_graph[c].SetLogx() #leg.AddEntry(back_graph[c],labellist[j]+" bkg.",'PL') #w#leg2.AddEntry(back_graph[c],labellist[j]+" bkg.",'PL') #w#mg.Add(back_graph[c]) if FOM=="signaleff": dummy = TGraph(len(ct),ct, np.array(e_array)) dummy.SetMarkerStyle(0) dummy.SetLineWidth(2) dummy.SetMarkerSize(1.) dummy.SetLineColor(15) dummy.SetLineStyle(2) #w#leg2.AddEntry(dummy, 'cuts on bkg.','PL') #cmg = TCanvas("cmg", "cmg", 2000, 1400) #cmg = TCanvas("cmg", "cmg", 2000, 800)#best #cmg = TCanvas("cmg", "cmg", 1200, 1000) cmg = TCanvas("cmg", "cmg", 1300, 800)#DCMS cmg.cd() cmg.SetGrid() cmg.SetLogx() #if FOM=="signaleff": # cmg.SetLogx() #pad1 = TPad("pad1", "pad1", 0, 0., 0.85, 1.0) #pad1 = TPad("pad1", "pad1", 0, 0., 0.7, 1.0) #pad1.SetGrid() #pad1.SetLogx() if FOM=="signaleff": print "LOL" #pad1.SetLogy() #pad1.SetLogy() #pad1.Draw() #pad1.cd() #W#if FOM=="signaleff": #w#mg.SetMaximum(101) #mg.SetMinimum(1.e-50) mg.SetMinimum(0.)#!! mg.Draw("APL") mg.GetXaxis().SetTitleSize(0.05) mg.GetYaxis().SetTitleSize(0.05) mg.GetXaxis().SetTitle('c#tau_{#pi} (mm)') mg.GetYaxis().SetTitleOffset(0.9); if FOM=="punzi": mg.GetYaxis().SetTitle('Punzi significance @ '+str(alpha)+' #sigma, '+CHANNEL+' cuts') #mg.GetYaxis().SetTitleOffset(1.5) elif FOM=="signaleff": #mg.GetYaxis().SetTitle('Signal efficiency, '+CHANNEL+' cuts (%)') mg.GetYaxis().SetTitle('Signal gen-matching efficiency, '+CHANNEL+' (%)') elif FOM=="entries": mg.GetYaxis().SetTitle('Signal entries surviving cuts') else: print "not punzi FOM, aborting" latex = TLatex() latex.SetNDC() latex.SetTextSize(0.05) latex.SetTextColor(1) latex.SetTextFont(42) latex.SetTextAlign(33) latex.SetTextFont(62) latex.DrawLatex(0.25, 0.96, "CMS") latex.SetTextFont(52) latex.DrawLatex(0.66, 0.96, "Simulation Preliminary") cmg.Update() cmg.cd() leg2.SetTextSize(0.04) #leg.Clear()#????????? #w#leg2.Draw() cmgL = TCanvas("cmgL", "cmgL", 2000, 800)#DCMS cmgL.cd() #pad2 = TPad("pad2", "pad2", 0.85, 0., 1, 1.0) #pad2 = TPad("pad2", "pad2", 0.7, 0., 1, 1.0) #pad2.SetGrid() #pad2.SetLogx()macro/VBF_punzi_LLP_AOD.py #pad2.Draw() #pad2.cd() leg3.SetTextSize(0.04) #leg.Clear()#????????? leg3.Draw() cmgL.Update() if FOM=="punzi": cmg.Print(OUTPUTDIR + "Punzi_correct_"+CHANNEL+"_m"+str(mass_point)+"_"+str(alpha)+"sigma"+additional_string+".pdf") cmg.Print(OUTPUTDIR + "Punzi_correct_"+CHANNEL+"_m"+str(mass_point)+"_"+str(alpha)+"sigma"+additional_string+".png") cmgL.Print(OUTPUTDIR + "Punzi_correct_"+CHANNEL+"_m"+str(mass_point)+"_"+str(alpha)+"sigma"+additional_string+"_L.pdf") cmgL.Print(OUTPUTDIR + "Punzi_correct_"+CHANNEL+"_m"+str(mass_point)+"_"+str(alpha)+"sigma"+additional_string+"_L.png") elif FOM=="signaleff": cmg.Print(OUTPUTDIR + "SignalEff_"+CHANNEL+"_m"+str(mass_point)+additional_string+".pdf") cmg.Print(OUTPUTDIR + "SignalEff_"+CHANNEL+"_m"+str(mass_point)+additional_string+".png") cmgL.Print(OUTPUTDIR + "SignalEff_"+CHANNEL+"_m"+str(mass_point)+additional_string+"_L.pdf") cmgL.Print(OUTPUTDIR + "SignalEff_"+CHANNEL+"_m"+str(mass_point)+additional_string+"_L.png") elif FOM=="entries": cmg.Print(OUTPUTDIR + "SignalEntries_"+CHANNEL+"_m"+str(mass_point)+additional_string+".pdf") cmg.Print(OUTPUTDIR + "SignalEntries_"+CHANNEL+"_m"+str(mass_point)+additional_string+".png") cmgL.Print(OUTPUTDIR + "SignalEntries_"+CHANNEL+"_m"+str(mass_point)+additional_string+"_L.pdf") cmgL.Print(OUTPUTDIR + "SignalEntries_"+CHANNEL+"_m"+str(mass_point)+additional_string+"_L.png") else: print "not punzi FOM, aborting" if not options.bash: raw_input("Press Enter to continue...") cmg.Close()
#tgs[0].SetTitle(";Recursion Steps;#left|I^{std::boost::math}_{2} - I^{recursion}_{2}#right|") for t in tgs: t.GetYaxis().SetRangeUser(pow(10, -16), pow(10, 4)) t.GetXaxis().SetRangeUser(0, 50) t.SetLineColor(co) tmg.Add(t) co += 1 tgs[9].SetLineColor(11) tl = TLegend(0.5, 0.3, 0.6, 0.8, "x value", "nbNDC") for k in xrange(1, 11): tl.AddEntry(tgs[k - 1], "x = %d" % k, "l") c1.SetLogy() tmg.Draw("AL") tmg.GetYaxis().SetRangeUser(pow(10, -16), pow(10, 4)) tmg.GetXaxis().SetRangeUser(0, 50) tmg.GetXaxis().SetTitle("Recursion Steps") tmg.GetYaxis().SetTitle( "#left|I^{boost::math}_{2}(x) - I^{recursion}_{2}(x)#right|") tmg.GetXaxis().CenterTitle() tmg.GetYaxis().CenterTitle() tl.Draw() c1.Update() c1.Modified() raw_input('')
def plotROC(xdata, ydata, xlabel, ylabel, legendNames, destination, year, xerror=None, yerror=None, xlog=False, ylog=False, additionalInformation=None): GeneralSettings() #Make sure single curves also pass try: len(xdata[0]) except: xdata = [xdata] ydata = [ydata] legendNames = [legendNames] xerror = [xerror] yerror = [yerror] #Create Canvas Canv = TCanvas("Canv" + destination, "Canv" + destination, 1000, 1000) tdr.setTDRStyle() #Create TGraph graphs = [] for x, y, xe, ye in zip(xdata, ydata, xerror, yerror): tmpgraph = None if xe is None and ye is None: tmpgraph = TGraph(len(x), x, y) elif xe is None or ye is None: NullErrors = np.zeros(len(x)) if xe is not None: tmpgraph = TGraphErrors(len(x), x, y, xe, NullErrors) if ye is not None: tmpgraph = TGraphErrors(len(x), x, y, NullErrors, ye) else: tmpgraph = TGraphErrors(len(x), x, y, xe, ye) graphs.append(tmpgraph) mgraph = TMultiGraph() for i, graph in enumerate(graphs): graph.SetMarkerSize(1.5) graph.SetLineColor(TColor.GetColor(GetLineColor(graphs.index(graph)))) graph.SetMarkerColor(TColor.GetColor(GetLineColor( graphs.index(graph)))) graph.SetMarkerStyle(GetMarker(graphs.index(graph))) mgraph.Add(graph) mgraph.Draw("APLine") mgraph.SetTitle(";" + xlabel + ";" + ylabel) cl.CMS_lumi(Canv, 4, 11, 'Simulation', False) if xlog: Canv.SetLogx() mgraph.GetXaxis().SetRangeUser(0.3 * GetNestedMin(xdata), 30 * GetNestedMax(xdata)) else: mgraph.GetXaxis().SetRangeUser(0.7 * GetNestedMin(xdata[0]), 1.3 * GetNestedMax(xdata)) if ylog: Canv.SetLogy() mgraph.GetYaxis().SetRangeUser(0.3 * GetNestedMin(ydata), 10 * GetNestedMax(ydata)) else: mgraph.GetYaxis().SetRangeUser(0.5 * GetNestedMin(ydata), 1.2 * GetNestedMax(ydata)) #Write extra text if additionalInformation is not None: lastYpos = 0.8 lastCorrectedYpos = None extraText = TLatex() for info in additionalInformation: try: extraTextString = info[0] extraTextXpos = info[1] extraTextYpos = info[2] extraTextSize = info[3] except: print("Wrong Format for additionalInformation. Stopping") pass if extraTextSize is None: extraTextSize = 0.03 if extraTextXpos is None: extraTextXpos = 0.2 if extraTextYpos is None: if lastYpos is None: extraTextYpos = lastCorrectedYpos - 0.05 else: extraTextYpos = 0.8 extraText.SetNDC() extraText.SetTextAlign(12) extraText.SetTextSize(extraTextSize) extraText.DrawLatex(extraTextXpos, extraTextYpos, extraTextString) lastYpos = info[2] lastCorrectedYpos = extraTextYpos if legendNames: legend = TLegend(0.7, .7, .9, .9) for g, n in zip(graphs, legendNames): legend.AddEntry(g, n) legend.SetFillStyle(0) legend.SetBorderSize(0) legend.Draw() #Save everything savePlots(Canv, destination)
jetToElectronRatePlot.SetLineWidth(2) jetToElectronRatePlot.SetLineStyle(1) # ratePlot.Add(jetToPhotonRatePlot, "A3") # jetToPhotonRatePlot.SetFillStyle(1001) # jetToPhotonRatePlot.SetLineWidth(2) # jetToPhotonRatePlot.SetLineStyle(1) ratePlot.Add(jetToMETRatePlot, "A3") jetToMETRatePlot.SetFillStyle(1001) jetToMETRatePlot.SetLineWidth(2) jetToMETRatePlot.SetLineStyle(1) ratePlot.Draw("A3") # Plot labels ratePlot.SetTitle("Zero pile-up event rate simulation") ratePlot.GetXaxis().SetTitle("p_{t} [GeV]") ratePlot.GetYaxis().SetTitle("Rate [Hz]") leg.Draw() # Plot ranges ratePlot.GetYaxis().SetRangeUser(1e2, 1e10) ratePlot.GetXaxis().SetRangeUser(30, 370) # Lumi and energy info text = TPaveText(0.2, 0.84, 0.6, 0.9, "NDC") text.AddText("L_{inst} = 3 #times 10^{35} cm^{-2} s^{-1} #sqrt{s} = 100 TeV") text.Draw() # Adding a reference line at 1 MHz mhzLine = TLine(30, mySettings.yScale, 160, mySettings.yScale)
def Draw_2D_Comp(rootfile_name, var_x, var_y, min, max, WP_list, leg, isTgraph=False): gStyle.SetErrorX(0.5) ## Creating a multigraph for the canvas if we are looking at TGraphs if isTgraph: stack = TMultiGraph() args = "AP" ## Creating a stack for the canvas if we are looking at TPofiles else: stack = THStack("stack", var_x.name + var_y.name) args = "nostack " stack.SetMinimum(min) stack.SetMaximum(max) for wp in WP_list: ## Generating the graph name graph_name = "{}_vs_{}_{}".format(var_x.name, var_y.name, wp.name) if isTgraph: graph_name += "_res" ## Loading the graph using its name and file location graph = GetGraphFromFile(rootfile_name, graph_name) if graph == -1: continue ## Setting the colors specific to the working point graph.SetLineColor(wp.colour) graph.SetMarkerColor(wp.colour) graph.SetMarkerStyle(wp.marker) ## Adding the legend entry leg.AddEntry(graph, wp.name, "p") ## Adding the object to the stack stack.Add(graph) del graph ## Checking to see if any graphs were found for this variable nhists = stack.GetListOfGraphs().GetSize( ) if isTgraph else stack.GetNhists() if nhists == 0: print("\n\n\nNo graphs found for working point {}\n\n\n".format( wp.name)) return -1 ## Drawing the stack on the currrent canvas stack.Draw(args) leg.Draw() ## Setting axis labels stack.GetXaxis().SetTitle(var_x.x_label + " " + var_x.units) stack.GetYaxis().SetTitle(var_y.x_label + " " + var_y.units) ## Moving axis tick marks stack.GetYaxis().SetMaxDigits(3) stack.GetXaxis().SetLabelOffset(0.017) return stack
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;