def plotEA(h_selected,h_total,label_selected,label_total,fileOut): c = Canvas('c') pad1 = TPad('pad1', 'pad1', 0., 0.3, 1., 1.) pad1.SetBottomMargin(0.005) pad1.SetTicks(1,1) pad1.SetGrid(1,1) pad1.Draw() c.cd() pad2 = TPad('pad2', 'pad2', 0., 0.05, 1., 0.29) pad2.SetTopMargin(0.005) pad2.SetBottomMargin(0.3) pad2.SetTicks(1,1) pad2.Draw() pad1.cd() h_total.SetTitle('') h_total.GetYaxis().SetTitle('Events') h_total.SetLineColor(ROOT.kBlue) h_total.SetFillColorAlpha(ROOT.kBlue,0.2) h_total.Draw('HIST') h_selected.SetTitle('') h_selected.SetLineColor(ROOT.kRed) h_selected.SetFillColorAlpha(ROOT.kRed,0.2) h_selected.Draw('HIST same') legend = TLegend(0.12, 0.61, 0.28, 0.8) legend.SetBorderSize(0) legend.SetFillColor(0) legend.SetFillStyle(0) legend.SetTextFont(42) legend.SetTextSize(0.031) legend.AddEntry(h_selected,label_selected, 'f') legend.AddEntry(h_total,label_total, 'f') legend.Draw() cLabel, pLabel, dLabel = condLabel(), simLabel(), descriptionLabel() cLabel.SetTextSize(0.049), pLabel.SetTextSize(0.049) cLabel.Draw(), pLabel.Draw(), dLabel.Draw() pad2.cd() pad2.SetGrid(0,1) h_new = h_selected.Clone('h_new') h_new.Sumw2() h_new.Divide(h_total) h_new.SetMarkerStyle(20) h_new.SetMarkerSize(0.9) h_new.SetLineColor(ROOT.kBlack) h_new.GetXaxis().SetTitle('#xi' if 'xi' in fileOut else 'missing mass') h_new.SetMinimum(-0.01), h_new.SetMaximum(1.05) h_new.Draw('p same') Prettify(h_new) #h_new.GetXaxis().SetTitle('Generated #xi') h_new.GetYaxis().SetTitle('Red/Blue') c.SaveAs(fileOut)
def PlotFakeRatio(ratio): c = TCanvas("c", "canvas", 800, 800) gStyle.SetOptStat(0) gStyle.SetLegendBorderSize(0) pad = TPad("pad", "pad", 0.01, 0.01, 0.99, 0.99) pad.Draw() pad.cd() pad.SetGrid() pad.SetFillColor(0) pad.SetFrameBorderMode(0) pad.SetBorderMode(0) xaxis_title = "Photon P_{T} [GeV]" leg = getLegend(xmin=0.5, ymin=0.7, scale=0.75) fake_style(ratio) ratio.SetTitle("") ratio.GetYaxis().SetTitle("Fake Ratio") # ratio.GetYaxis().SetTitleOffset(0.5) ratio.GetXaxis().SetTitle(xaxis_title) # ratio.GetYaxis().SetRangeUser(0.75,1.2) print SetBounds([ratio], scale=1) ratio.Draw("p same") leg.AddEntry(ratio, "#frac{Data_{ISO}}{Data_{Non-ISO}}", "lp") leg.Draw() lumi_label = '%s' % float('%.3g' % (max(config.lumi.values()) / 1000.)) + " fb^{-1}" texLumi, texCMS = getCMSText(lumi_label, config.version, scale=0.8) SaveAs(c, "fake_ratio_%s" % parser.args.variable, year=config.version, sub="GammaPurity/FakeRatio/")
class EEG_Graph(object): def __init__(self, maxpoints=60): self.maxpoints = maxpoints self.gq = False self.canvas = TCanvas('c1', 'A Simple Graph Example', 200, 10, 700, 500) self.canvas_1 = TPad("c1_1", "c1_1", 0.01, 0.67, 0.99, 0.99) self.canvas_2 = TPad("c1_2", "c1_2", 0.01, 0.01, 0.99, 0.66) self.canvas_1.SetGrid() self.canvas_2.SetGridx() self.canvas_1.Draw() self.canvas_2.Draw() self.data = [0] self.data_time = [time.time()] n = 1 x = array('d') y = array('d') x.append(0) y.append(0) self.canvas_1.cd() self.graph = TGraph(n, x, y) self.graph.SetLineColor(2) self.graph.SetLineWidth(4) self.graph.SetMarkerColor(4) self.graph.SetMarkerStyle(2) self.graph.SetTitle('EEG Signal') self.graph.GetXaxis().SetTitle('Time') self.graph.GetYaxis().SetTitle('Amplitude') self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.graph.Draw('ACP') self.canvas_2.cd() TVirtualFFT.SetTransform(0) self.fft = TH1F("fft", "eeg_fft", 3, 0, 3) self.fft.SetTitle("EEG FFT") self.fft.Fill("1 Hz", 0) self.fft.Fill("2 Hz", 0) self.fft.SetMinimum(0) self.fft.SetMaximum(100000) self.fft.SetFillStyle(3001) self.fft.SetFillColor(30) self.fft.Draw("B HIST") self.ampmax = 100000 self.fft.SetStats(False) self.fft.GetXaxis().SetLabelSize(0.05) self.fft.GetYaxis().SetLabelSize(0.05) def setQuality(self, good): self.gq = good def append(self, timep, num): n = self.graph.GetN() if len(self.data) < 2048: self.data = self.data + [num] self.data_time = self.data_time + [time.time()] else: self.data = self.data[1:] + [num] self.data_time = self.data_time[1:] + [time.time()] if n < self.maxpoints: self.graph.Set(n + 1) self.graph.SetPoint(n, timep, num) else: self.graph.RemovePoint(0) self.graph.Set(n) self.graph.SetPoint(n - 1, timep, num) self.data_fft = np.abs(np.fft.fft(self.data)) self.fft.Reset() if len(self.data_fft) > 256: delta = self.data_time[-1] - self.data_time[0] for i in range(50): amp = np.sum(self.data_fft[round(i * delta):round(i * delta + delta)]) self.fft.Fill("%i Hz" % (i + 1, ), amp) if amp > self.ampmax: self.ampmax = amp self.fft.SetMaximum(amp) self.update() def update(self): self.canvas_1.cd() if self.gq: self.canvas_1.GetFrame().SetFillColor(30) else: self.canvas_1.GetFrame().SetFillColor(46) self.canvas.GetFrame().SetBorderSize(12) self.graph.GetYaxis().SetRangeUser(-2000, 2000) self.canvas_2.Modified() self.canvas.Modified() self.canvas.Update()
for j,slice in enumerate(track.slices): slice.ComputeSiPMsMatrix() algorithm = Transformer( Shrink(slice.SiPMsMatrix) ) algorithm.Compute(cut = 0.94) isources[j] = algorithm.sources[0] fsources[j] = algorithm.fsource signals [j] = slice.SiPMsMatrix imax = max( map( lambda x: Arrays.Max(x)[2], isources ) ) fmax = max( map( lambda x: Arrays.Max(x)[2], fsources ) ) for j in range(track.nslices): isources[j] = Arrays.FillHistogram( isources[j], 'Fourier method' , name = 'FM' + i + str(j) ) fsources[j] = Arrays.FillHistogram( fsources[j], 'Iterative method', name = 'IM' + i + str(j) ) signals [j] = Arrays.FillHistogram( signals [j], 'SiPMs signal' , name = 'S' + i + str(j) ).RebinX(5).RebinY(5) isources[j].SetMaximum(imax) fsources[j].SetMaximum(fmax) c = TCanvas() p1 = TPad( 'a', 'a', 0.00, 0.05, 0.66, 0.95 ); p1.SetGrid(); p1.Draw() p2 = TPad( 'b', 'b', 0.67, 0.50, 1.00, 1.00 ); p2.SetGrid(); p2.Draw() p3 = TPad( 'c', 'c', 0.67, 0.00, 1.00, 0.50 ); p3.SetGrid(); p3.Draw() p1.cd(); fsources[j].Draw('zcol') p2.cd(); isources[j].Draw('zcol') p3.cd(); signals [j].Draw('zcol') c.SaveAs( 'dump/track{0}slice{1}.png'.format(i,j) ) MakeGif( ['track{0}slice{1}'.format(i,j) for j in range(track.nslices) ], 'dump/', output = './dump/track{0}'.format(i) )
def compareMassRes(trackType): fileCB = open( "BoosteddefaultLeadingCB/MassResolutionVsPt_%s_BE16.pkl" % trackType, "rb") fileDCB = open( "BoosteddefaultLeading/MassResolutionVsPt_%s_BE16.pkl" % trackType, "rb") fileCruijff = open( "BoosteddefaultLeadingCruijff/MassResolutionVsPt_%s_BE16.pkl" % trackType, "rb") resultsCB = pickle.load(fileCB) resultsDCB = pickle.load(fileDCB) resultsCruijff = pickle.load(fileCruijff) graphCB = getGraph(resultsCB, "CB", Data=True) graphDCB = getGraph(resultsDCB, "DCB", Data=True) graphCruijff = getGraph(resultsCruijff, "Cruijff", Data=True) ratioCB = getRatio(resultsCB, resultsDCB, "ratioCB", Data=True) ratioCruijff = getRatio(resultsCruijff, resultsDCB, "ratioCruijff", Data=True) canv = TCanvas("c1", "c1", 800, 800) plotPad = TPad("plotPad", "plotPad", 0, 0, 1, 1) #~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() #~ ratioPad.UseCurrentStyle() plotPad.Draw() #~ ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) xMax = 20 if trackType == "Inner": xMax = 10 if trackType == "Outer": xMax = 20 plotPad.DrawFrame(0, 0, 452, xMax, ";p_{T} [GeV]; #chi^{2}/N_{dof}") graphCB.Draw("samepe") graphDCB.Draw("samepe") graphCruijff.Draw("samepe") graphDCB.SetLineColor(kRed) graphDCB.SetMarkerColor(kRed) graphCruijff.SetLineColor(kBlue) graphCruijff.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s BB" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graphCB, "Single-Sided CB", "l") leg.AddEntry(graphDCB, "Double-Sided CB", "l") leg.AddEntry(graphCruijff, "Cruijff", "l") leg.Draw() plotPad.RedrawAxis() #~ ratioPad.cd() #~ ratioBB.SetLineColor(kRed) #~ ratioPad.DrawFrame(0,0.5,6000,1.5,";;ratio") #~ ratioBB.Draw("samepe") canv.Print("chi2CompareVsPt_%s_BE16.pdf" % trackType)
def comparePtRes(trackType): file2016B = open("default2016Pt/PtResolutionVsPt_%s_B.pkl" % trackType, 'rb') file2016O = open("default2016Pt/PtResolutionVsPt_%s_O.pkl" % trackType, 'rb') file2016E = open("default2016Pt/PtResolutionVsPt_%s_E.pkl" % trackType, 'rb') file2017B = open("defaultPtSplit/PtResolutionVsPt_%s_B.pkl" % trackType, 'rb') file2017O = open("defaultPtSplit/PtResolutionVsPt_%s_O.pkl" % trackType, 'rb') file2017E = open("defaultPtSplit/PtResolutionVsPt_%s_E.pkl" % trackType, 'rb') file2018B = open("default2018Pt/PtResolutionVsPt_%s_B.pkl" % trackType, 'rb') file2018O = open("default2018Pt/PtResolutionVsPt_%s_O.pkl" % trackType, 'rb') file2018E = open("default2018Pt/PtResolutionVsPt_%s_E.pkl" % trackType, 'rb') results2016B = pickle.load(file2016B) results2016O = pickle.load(file2016O) results2016E = pickle.load(file2016E) results2017B = pickle.load(file2017B) results2017O = pickle.load(file2017O) results2017E = pickle.load(file2017E) results2018B = pickle.load(file2018B) results2018O = pickle.load(file2018O) results2018E = pickle.load(file2018E) graph2016B = getGraph(results2016B, "2016B") graph2016O = getGraph(results2016O, "2016O") graph2016E = getGraph(results2016E, "2016E") graph2017B = getGraph(results2017B, "2017B") graph2017O = getGraph(results2017O, "2017O") graph2017E = getGraph(results2017E, "2017E") graph2018B = getGraph(results2018B, "2018B") graph2018O = getGraph(results2018O, "2018O") graph2018E = getGraph(results2018E, "2018E") canv = TCanvas("c1", "c1", 800, 1200) plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1) # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() # ~ ratioPad.UseCurrentStyle() plotPad.Draw() # ~ ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) gStyle.SetTitleYOffset(1.55) xMax = 0.15 if trackType == "Inner": xMax = 0.3 if trackType == "Outer": xMax = 0.5 plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]") graph2016B.Draw("samepe") # ~ graph2016O.Draw("samepe") graph2016E.Draw("samepe") graph2016B.SetLineColor(kRed) graph2016B.SetMarkerColor(kRed) graph2016O.SetLineColor(kGreen) graph2016O.SetMarkerColor(kGreen) graph2016E.SetLineColor(kBlue) graph2016E.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2016" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graph2016B, "Barrel", "l") # ~ leg.AddEntry(graph2016O,"Overlap","l") leg.AddEntry(graph2016E, "Endcap", "l") leg.Draw() plotPad.RedrawAxis() canv.Print("PtResolutionCompare_%s_2016.pdf" % trackType) canv.Print("PtResolutionCompare_%s_2016.root" % trackType) canv = TCanvas("c1", "c1", 800, 1200) plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1) # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() # ~ ratioPad.UseCurrentStyle() plotPad.Draw() # ~ ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) gStyle.SetTitleYOffset(1.55) xMax = 0.15 if trackType == "Inner": xMax = 0.3 if trackType == "Outer": xMax = 0.5 plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]") graph2017B.Draw("samepe") # ~ graph2017O.Draw("samepe") graph2017E.Draw("samepe") graph2017B.SetLineColor(kRed) graph2017B.SetMarkerColor(kRed) graph2017O.SetLineColor(kGreen) graph2017O.SetMarkerColor(kGreen) graph2017E.SetLineColor(kBlue) graph2017E.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2017" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graph2017B, "Barrel", "l") # ~ leg.AddEntry(graph2017O,"Overlap","l") leg.AddEntry(graph2017E, "Endcap", "l") leg.Draw() plotPad.RedrawAxis() canv.Print("PtResolutionCompare_%s_2017.pdf" % trackType) canv.Print("PtResolutionCompare_%s_2017.root" % trackType) canv = TCanvas("c1", "c1", 800, 1200) plotPad = TPad("plotPad", "plotPad", 0, 0., 1, 1) # ~ ratioPad = TPad("ratioPad","ratioPad",0,0.,1,0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() # ~ ratioPad.UseCurrentStyle() plotPad.Draw() # ~ ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) gStyle.SetTitleYOffset(1.55) xMax = 0.15 if trackType == "Inner": xMax = 0.3 if trackType == "Outer": xMax = 0.5 plotPad.DrawFrame(0, 0, 2000, xMax, ";p_{T} [GeV]; p_{T} resolution [%]") graph2018B.Draw("samepe") # ~ graph2018O.Draw("samepe") graph2018E.Draw("samepe") graph2018B.SetLineColor(kRed) graph2018B.SetMarkerColor(kRed) graph2018O.SetLineColor(kGreen) graph2018O.SetMarkerColor(kGreen) graph2018E.SetLineColor(kBlue) graph2018E.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s 2018" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graph2018B, "Barrel", "l") # ~ leg.AddEntry(graph2018O,"Overlap","l") leg.AddEntry(graph2018E, "Endcap", "l") leg.Draw() plotPad.RedrawAxis() canv.Print("PtResolutionCompare_%s_2018.pdf" % trackType) canv.Print("PtResolutionCompare_%s_2018.root" % trackType)
isources[j] = Arrays.FillHistogram(isources[j], 'Fourier method', name='FM' + i + str(j)) fsources[j] = Arrays.FillHistogram(fsources[j], 'Iterative method', name='IM' + i + str(j)) signals[j] = Arrays.FillHistogram(signals[j], 'SiPMs signal', name='S' + i + str(j)).RebinX(5).RebinY(5) isources[j].SetMaximum(imax) fsources[j].SetMaximum(fmax) c = TCanvas() p1 = TPad('a', 'a', 0.00, 0.05, 0.66, 0.95) p1.SetGrid() p1.Draw() p2 = TPad('b', 'b', 0.67, 0.50, 1.00, 1.00) p2.SetGrid() p2.Draw() p3 = TPad('c', 'c', 0.67, 0.00, 1.00, 0.50) p3.SetGrid() p3.Draw() p1.cd() fsources[j].Draw('zcol') p2.cd() isources[j].Draw('zcol') p3.cd() signals[j].Draw('zcol') c.SaveAs('dump/track{0}slice{1}.png'.format(i, j))
def STACK(extension, OUTPUT_dir, network_name, luminosity, output_flag, output_mod, generator, extra_text, fudge, text, MC_list, Real_Data, var, wp=None): is_wp = False if wp is None else True ## The name of the histogram to be used hist_name = "{}_{}".format(var.name, wp.name) if is_wp else var.name ## Creating the canvas canvas = TCanvas("canvas" + hist_name, 'A basic canvas', 800, 800) ## Creating the first pad to contain the basic histogram plots histo_pad = TPad("histo_pad", "histo_pad", 0, 0.25, 1.0, 1.0) histo_pad.SetBottomMargin(0) histo_pad.Draw() histo_pad.cd() # if is_wp: histo_pad.SetLogy() ## Adding in the legend leg = Plotting.Create_Legend(0.70, 0.45, 0.95, 0.95, text_size=0.045) ## Creating a stack for the canvas stack = THStack("stack", var.name) hist_list = [] integral_list = [] for s, mc in enumerate(MC_list): rootfile_name = os.path.join(OUTPUT_dir, network_name, mc.file, "histograms.root") hist = Plotting.GetGraphFromFile(rootfile_name, hist_name) if hist == -1: continue hist.Scale(fudge * luminosity) hist.SetMarkerColor(mc.colour) hist.SetFillColor(mc.colour) hist.SetLineColor(1) hist.SetLineWidth(1) hist.SetMarkerStyle(0) leg.AddEntry(hist, mc.label, "f") integral_list.append(hist.Integral(0, hist.GetNbinsX() + 1)) hist.Scale(1, "width") hist_list.append(hist) if s == 0: MC_Total = hist.Clone() else: MC_Total.Add(hist.Clone()) del hist ## If the list is empty and no histograms were found then we skip the rest if not integral_list and is_wp: print("No MC histograms found for working point {}\n".format(wp.name)) return 0 ## Now we use the integrals to sort the histograms in descending order ord_idx = np.argsort(integral_list) ## Adding the histograms to the stack for i in ord_idx: # Draw the object on the stack stack.Add(hist_list[i]) stack.Draw("HIST") stack.GetYaxis().SetTitleOffset(1.2) ## Adding the MC Statistical, lumi and xsec uncertainty for i in range(1, MC_Total.GetNbinsX() + 1): if MC_Total.GetBinContent(i) > 0: e = MC_Total.GetBinError(i) h = MC_Total.GetBinContent(i) MC_Total.SetBinError(i, h * np.sqrt((e / h)**2 + 0.05**2 + 0.02**2)) MC_Total.SetMarkerSize(0.) MC_Total.SetFillStyle(3001) MC_Total.SetMarkerColor(1) MC_Total.SetFillColor(2) MC_Total.Draw("E2 SAME") ## Adding the data points rootfile_name = os.path.join(OUTPUT_dir, network_name, Real_Data.file, "histograms.root") real_hist = Plotting.GetGraphFromFile(rootfile_name, hist_name) real_hist.SetLineColor(1) real_hist.SetMarkerColor(Real_Data.colour) real_hist.SetMarkerStyle(20) real_hist.SetMarkerSize(1.2) real_int = real_hist.Integral(0, real_hist.GetNbinsX() + 1) leg.AddEntry(real_hist, Real_Data.label, "p") real_hist.Scale(1, "width") real_hist.Draw("e1p SAME") print("Real events = {:}".format(real_int)) print("MC events = {:}".format(sum(integral_list))) print("Fudge Factor = {:10.10}".format(real_int / sum(integral_list))) # print( "Z events = {:}".format( sum(integral_list[:3]) ) ) # print( "Non Z events = {:}".format( sum(integral_list[3:]) ) ) # print( "Z Factor = {:10.10}".format( ( real_int - sum(integral_list[3:]) ) / sum(integral_list[:3]) ) ) ## Adding in some text and the ATLAS Labels # if fudge != 1: text += " (#uparrow{:.2f}%)".format(fudge*100-100) s = 1.0 pos = 0.88 shift = 0.05 Plotting.Draw_ATLASLabel(0.20, pos, "work in progress", scale=1.0) pos -= shift + 0.01 Plotting.Draw_Lumi(0.20, pos, luminosity, scale=s) pos -= shift Plotting.Draw_Text(0.20, pos, text, scale=s) pos -= shift Plotting.Draw_Text(0.20, pos, generator, scale=s) Plotting.Draw_Text(0.55, 0.8, extra_text) leg.Draw() ## Plotting axis and limits stack.GetYaxis().SetTitle("Events per GeV") if var.ymin is not None: stack.SetMinimum(var.ymin) if var.ymax is not None: stack.SetMaximum(var.ymax) if var.xmin is not None and var.xmax is not None: stack.GetXaxis().SetLimits(var.xmin, var.xmax) ## Creating the ratio pad canvas.cd() ratio_pad = TPad("ratio_pad", "ratio_pad", 0, 0, 1.0, 0.25) ratio_pad.SetTopMargin(0.0) ratio_pad.SetBottomMargin(0.3) ratio_pad.Draw() ratio_pad.cd() ratio_pad.SetGrid(0, 1) ## Plotting the the MC error histogram MC_flat = MC_Total.Clone() for i in range(1, MC_Total.GetNbinsX() + 1): MC_flat.SetBinContent(i, 1) if MC_Total.GetBinContent(i) > 0: MC_flat.SetBinError( i, MC_Total.GetBinError(i) / MC_Total.GetBinContent(i)) MC_flat.SetMarkerSize(0.) MC_flat.SetFillStyle(3001) MC_flat.SetMarkerColor(1) MC_flat.SetFillColor(2) MC_flat.SetMaximum(1.6) MC_flat.SetMinimum(0.4) MC_flat.Draw("E2") leg.AddEntry(MC_flat, "MC stat unc", "f") ## Plotting the ratio of MC to Data ratio_hist = real_hist.Clone() mcratio_hist = MC_Total.Clone() mcratio_hist.SetError(arr.array('d', [0])) ratio_hist.Divide(mcratio_hist) ratio_hist.Draw("ep SAME") ## Plotting axis and limits if var.xmin is not None and var.xmax is not None: ratio_hist.GetXaxis().SetRange(var.xmin, var.xmax) x_title = wp.name + " " + var.x_label + " " + var.units if is_wp else var.x_label + " " + var.units MC_flat.GetXaxis().SetTitle(x_title) MC_flat.GetXaxis().SetTitleSize(25) MC_flat.GetXaxis().SetTitleFont(43) MC_flat.GetXaxis().SetTitleOffset(4) MC_flat.GetXaxis().SetLabelFont(43) MC_flat.GetXaxis().SetLabelSize(20) MC_flat.GetYaxis().SetTitle("Data/MC") MC_flat.GetYaxis().SetNdivisions(206, False) MC_flat.GetYaxis().ChangeLabel(-1, -1, -1, -1, -1, -1, " ") MC_flat.GetYaxis().ChangeLabel(1, -1, -1, -1, -1, -1, " ") MC_flat.GetYaxis().SetTitleSize(25) MC_flat.GetYaxis().SetTitleFont(43) MC_flat.GetYaxis().SetTitleOffset(1.55) MC_flat.GetYaxis().SetLabelFont(43) MC_flat.GetYaxis().SetLabelSize(20) ## Adding in a line on the x-axis line = TLine(ratio_hist.GetBinLowEdge(1), 1, ratio_hist.GetBinLowEdge(ratio_hist.GetNbinsX() + 1), 1) line.SetLineWidth(1) line.SetLineColor(1) line.SetLineStyle(9) line.Draw() ## Saving the canvas canvas.Update() out_folder = "{}/{}/Stack".format(OUTPUT_dir, network_name) if not os.path.exists(out_folder): os.system("mkdir -p {}".format(out_folder)) out_file = os.path.join(out_folder, "{}_{}".format(output_flag, var.name)) if is_wp: out_file += "_" + wp.name out_file += "_{}".format(generator) if "0 Jets" in extra_text: out_file += "_NOJETS" out_file += "{}.{}".format(output_mod, extension) canvas.Print(out_file)
tex2 = TLatex(0.54, 0.85, "#sqrt{s} = 13 TeV") tex2.SetNDC() tex2.SetTextFont(42) tex2.SetLineWidth(2) tex3 = TLatex(0.54, 0.93, "ATLAS Internal") tex3.SetNDC() tex3.SetTextFont(42) tex3.SetLineWidth(2) cc = TCanvas(var, var, 800, 750) # cc.SetLogy() pad1 = TPad("p1", "p1", 0, 0.25, 1, 1, 0, 0) pad1.SetMargin(0.15, 0.03, 0, 0.01) pad2 = TPad("p2", "p2", 0, 0, 1, 0.25, 0, 0) pad2.SetMargin(0.15, 0.03, 0.3, 0.01) pad2.SetGrid() pad1.Draw() pad2.Draw() pad1.cd() pad1.SetLogy() hs.SetMinimum(0.1) hs.Draw("HIST") # hs.GetXaxis().SetTitle(TITLE[var]) hs.GetYaxis().SetTitle("Events") hs.GetYaxis().SetTitleOffset(0.8) hs.GetYaxis().SetTitleSize(0.05) data_hist.Draw("same" "LPE") sig_hist.Draw("same" "LPE") leg.Draw() tex1.Draw()
def plot_limit(path, file_name, xslabel, typelabel, minx=200, maxx=2000): low_y = 0.001 hi_y = 5 #low_y = 0.5 #hi_y = 50 sigma = "#sigma_{" + xslabel + "}" unit = "95% CL limits on " + sigma + " #times BR(S#rightarrow ZZ) [pb]" #unit = "95% CL limits on "+sigma+" #times BR(S#rightarrow ZZ #rightarrow 4l) [fb]" x_axis_title = "m_{S} [GeV]" dummy = ROOT.TH2F("dummy", ";" + ";" + unit, 160, float(minx), float(maxx), 3000, low_y, hi_y) #dummy.GetXaxis().SetNdivisions(8); hist_obs, hist_exp, hist_1s, hist_2s = make_limit_graph( path + "DNNnop_v6_ggF.txt") hist_obs2, hist_exp2, hist_1s2, hist_2s2 = make_limit_graph( path + "DNN2020_v6_ggF.txt") for i in range(hist_exp.GetN()): hist_exp.GetY()[i] *= 1. / 4.52 hist_exp2.GetY()[i] *= 1. / 4.52 hist_obs.GetY()[i] *= 1. / 4.52 hist_obs2.GetY()[i] *= 1. / 4.52 canvas = ROOT.TCanvas("canvas2", " ", 600, 600) canvas.SetLogy() ##========================= add ratio pad =========================== ratio = 0.2 if ratio > 0: fraction = ratio + 0.2 Pad1 = TPad("p1", "p1", 0, fraction * 1.0 / (fraction + 1), 1, 1, 0, 0) # x1,y1,x2,y2 Pad1.SetMargin(0.15, 0.10, 0.03, 0.05) Pad1.SetLogy() Pad2 = TPad("p2", "p2", 0, 0, 1, fraction * 1.0 / (fraction + 1), 0, 0) Pad2.SetMargin(0.15, 0.10, 0.15 / fraction, 0.04) Pad2.SetGrid() Pad1.Draw() Pad2.Draw() hist_exp.SetLineWidth(3) hist_exp.SetMarkerStyle(20) hist_exp.SetMarkerSize(0.5) hist_exp.SetLineColor(1) hist_exp.SetLineStyle(1) hist_exp2.SetLineWidth(3) hist_exp2.SetMarkerStyle(20) hist_exp2.SetMarkerSize(0.5) hist_exp2.SetLineColor(2) if ratio > 0: Pad1.cd() else: canvas.cd() dummy.Draw() hist_exp.Draw("CP") hist_exp2.Draw("CP") legend = ROOT.myLegend(0.56, 0.70, 0.83, 0.90) legend.AddEntry(hist_exp, "Fix other POI", "l") legend.AddEntry(hist_exp2, "Float", "l") legend.Draw() lumi = 138.97 x_off_title = 0.20 ROOT.myText(x_off_title, 0.85, 1, "#bf{#it{ATLAS}} Internal") ROOT.myText(x_off_title, 0.80, 1, "13 TeV, {:.1f} fb^{{-1}}".format(lumi)) ROOT.myText(x_off_title, 0.75, 1, typelabel) #dummy.Draw("AXIS SAME") if ratio > 0: x1 = hist_exp.GetX() y1 = hist_exp.GetY() y2 = hist_exp2.GetY() hist_ratio2 = ROOT.TGraph(len(x1)) for i in range(len(x1)): hist_ratio2.SetPoint(i, x1[i], y2[i] / y1[i]) Pad2.cd() mg = ROOT.TMultiGraph() mg.GetXaxis().SetLimits(minx, maxx) mg.SetMinimum(0.8) mg.SetMaximum(1.2) hist_ratio2.SetMarkerSize(0.5) hist_ratio2.SetLineColor(2) hist_ratio2.SetLineStyle(2) hist_ratio2.SetLineWidth(2) mg.Add(hist_ratio2) mg.Draw("ALP") mg.GetYaxis().SetTitle("Ratio") mg.GetXaxis().SetTitle(x_axis_title) canvas.SaveAs("Pdf_plots/" + file_name + ".pdf")
class plotterBase: def __init__(self, cvs_type="default", leg_size="medium", logy=False, grid=False): # store information self.cvs_type = cvs_type self.leg_size = leg_size self.logy = logy self.grid = grid # set info and logo self.__set_info() self.__set_logo() # set canvas and legend self.__set_canvas(cvs_type, logy, grid) self.__set_legend(leg_size) # getter # this will be def cvs(self): return self.cvs def pad_up(self): return self.pad_up def pad_down(self): return self.pad_down def legend(self): return self.legend def info(self): return self.info def logo(self): return self.logo def extra_logo(self): return self.extra_logo # private methods def __set_info(self): self.info = TLatex() self.info.SetTextSize(0.035) self.info.SetTextFont(42) def __set_logo(self): self.logo = TLatex() self.extra_logo = TLatex() self.logo.SetTextSize(0.04) self.logo.SetTextFont(61) self.extra_logo.SetTextSize(0.035) self.extra_logo.SetTextFont(52) def __set_canvas(self, cvs_type="default", logy=False, grid=False): if cvs_type == "default": self.cvs = TCanvas("cvs", "", 500, 500) if grid: self.cvs.SetGrid() if logy: self.cvs.SetLogy() elif cvs_type == "ratio": self.cvs = TCanvas("cvs", "", 504, 560) self.pad_up = TPad("pad_up", "", 0, 0.25, 1, 1) self.pad_up.SetBottomMargin(0.02) if grid: self.pad_up.SetGrid() if logy: self.pad_up.SetLogy() self.pad_down = TPad("pad_down", "", 0, 0, 1, 0.25) self.pad_down.SetGrid(1) self.pad_down.SetTopMargin(0.08) self.pad_down.SetBottomMargin(0.3) else: print("WARNING: No matched canvas type %s", cvs_type) print("Set the canvas type as default") self.__set_canvas(self, cvs_type="default", logy=logy) def __set_legend(self, leg_size="medium"): if leg_size == "small": self.legend = TLegend(0.69, 0.70, 0.90, 0.90) elif leg_size == "medium": self.legend = TLegend(0.69, 0.60, 0.90, 0.90) elif leg_size == "large": self.legend = TLegend(0.50, 0.60, 0.90, 0.90) else: print("wrong legend size...modify leg_size") #print("Set the legend size as medium") #self.__legend(self, leg_size="medium") # methods def draw(self): self.cvs.Draw() def save(self, path): self.cvs.SaveAs(path) self.cvs.Close()
def drawMassRes(data, mc, output, rapidity, ptda, ptmc, trackType, funct, mcIsData, dataIsMC): style = setTDRStyle() pt_e = [0 for x in range(len(data))] pt_x = [0 for x in range(len(data))] for i, pt in enumerate(pt_x): pt_x[i] = ptbins[i] + (ptbins[i + 1] - ptbins[i]) / 2. pt_e[i] = (ptbins[i + 1] - ptbins[i]) / 2. if dataIsMC: (da_mean, da_meane, da_sig, da_sige, da_nChi2) = doFit(data, output, rapidity, "MC2", trackType, funct) else: (da_mean, da_meane, da_sig, da_sige, da_nChi2) = doFit(data, output, rapidity, "DATA", trackType, funct) if mcIsData: (mc_mean, mc_meane, mc_sig, mc_sige, mc_nChi2) = doFit(mc, output, rapidity, "DATA2", trackType, funct) else: (mc_mean, mc_meane, mc_sig, mc_sige, mc_nChi2) = doFit(mc, output, rapidity, "MC", trackType, funct) result = {} result["data_mean"] = da_mean result["data_meane"] = da_meane result["data_sig"] = da_sig result["data_sige"] = da_sige result["mc_mean"] = mc_mean result["mc_meane"] = mc_meane result["mc_sig"] = mc_sig result["mc_sige"] = mc_sige result["ptda"] = ptda result["ptmc"] = ptmc result["da_nChi2"] = da_nChi2 result["mc_nChi2"] = mc_nChi2 pklFile = open( output + "/MassResolutionVsPt_%s_%s.pkl" % (trackType, rapidity), "wb") pickle.dump(result, pklFile) pklFile.close() c2 = TCanvas("c2", "c2", 700, 700) c2.cd() # Upper plot will be in pad1 pad1 = TPad("pad1", "pad1", 0, 0.3, 1, 1.0) pad1.SetGrid() # Vertical grid pad1.SetBottomMargin(0.1) pad1.Draw() # Draw the upper pad: pad1 pad1.cd() # pad1 becomes the current pad pad1.SetTicks() res_data = TGraphAsymmErrors() res_data.SetName("res_data") res_mc = TGraphAsymmErrors() res_mc.SetName("res_mc") ratio = TGraphErrors() ratio.SetName("ratio") #~ print len(pt_x) for i, pt in enumerate(pt_x): res_data.SetPoint(i, ptda[i], da_sig[i]) res_data.SetPointError(i, ptda[i] - ptbins[i], ptbins[i + 1] - ptda[i], da_sige[i], da_sige[i]) res_mc.SetPoint(i, ptmc[i], mc_sig[i]) res_mc.SetPointError(i, ptmc[i] - ptbins[i], ptbins[i + 1] - ptmc[i], mc_sige[i], mc_sige[i]) if mc_sig[i] > 0: ratio.SetPoint(i, pt, da_sig[i] / mc_sig[i]) ratio.SetPointError(i, pt_e[i], (da_sig[i] / mc_sig[i]) * math.sqrt((da_sige[i] / da_sig[i])**2 + (mc_sige[i] / mc_sig[i])**2)) res_data.SetMarkerStyle(22) res_data.SetMarkerColor(kBlack) res_data.SetLineColor(kBlack) res_data.SetFillColor(0) res_data.SetTitle("Dimuon mass resolution vs pT for %s tracks" % trackType) res_data.GetYaxis().SetTitle("Mass resolution at Z peak [GeV]") res_data.GetXaxis().SetTitle("p_{T} (#mu^{#pm}) [GeV]") res_data.GetYaxis().SetTitleOffset(1.2) res_data.GetYaxis().SetRangeUser(0., 6.) if trackType == "Outer": res_data.GetYaxis().SetRangeUser(1., 20.) res_data.GetXaxis().SetRangeUser(ptbins[0], ptbins[len(ptda)]) res_data.Draw("AP E0") res_mc.SetMarkerStyle(22) res_mc.SetMarkerColor(kRed) res_mc.SetLineColor(kRed) res_mc.SetFillColor(0) res_mc.SetTitle("Dimuon mass resolution vs pT for %s tracks" % trackType) res_mc.GetYaxis().SetTitle("Mass resolution at Z peak [GeV]") res_mc.GetXaxis().SetTitle("p_{T} (#mu^{#pm}) [GeV]") res_mc.GetYaxis().SetTitleOffset(1.5) res_mc.Draw("P E0 SAME") if rapidity == "BB": leg = TLegend(0.25, 0.6, 0.50, 0.80, "both muons |#eta| < 1.2", "brNDC") else: leg = TLegend(0.25, 0.6, 0.5, 0.8, "at least one muon |#eta| > 1.2", "brNDC") if mcIsData: leg.AddEntry(res_data, "DATA 2017") leg.AddEntry(res_mc, "DATA 2016") elif dataIsMC: leg.AddEntry(res_data, "MC 2017") leg.AddEntry(res_mc, "MC 2016") else: leg.AddEntry(res_data, "DATA", "p") leg.AddEntry(res_mc, "Simulation") leg.SetTextFont(42) leg.SetBorderSize(0) leg.SetTextSize(.04) leg.Draw("SAME") latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055 / 0.7) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03 / 0.7) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "Preliminary" latexCMS.DrawLatex(0.78, 0.88, "CMS") yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.78, yLabelPos, "%s" % (cmsExtra)) c2.cd() # Go back to the main canvas before defining pad2 pad2 = TPad("pad2", "pad2", 0, 0.1, 1, 0.30) pad2.SetTopMargin(0) pad2.SetBottomMargin(0.3) pad2.SetGrid() pad2.Draw() pad2.cd() pad2.SetTicks() ratio.SetMarkerColor(kBlue - 4) ratio.SetFillColor(kBlue - 4) ratio.SetTitle("") ratio.GetYaxis().SetTitle("Data/MC") if mcIsData: ratio.GetYaxis().SetTitle("Data 2017 / Data 2016") elif dataIsMC: ratio.GetYaxis().SetTitle("MC 2017 / MC 2016") ratio.GetXaxis().SetTitle("p_{T} (#mu^{#pm}) [GeV]") ratio.GetYaxis().SetRangeUser(0.5, 1.5) ratio.GetXaxis().SetRangeUser(ptbins[0], ptbins[len(ptda)]) ratio.GetYaxis().SetTitleOffset(0.50) ratio.GetYaxis().SetTitleSize(0.14) ratio.GetYaxis().SetLabelSize(0.14) ratio.GetYaxis().SetNdivisions(506) ratio.GetXaxis().SetTitleSize(0.12) ratio.GetXaxis().SetTitleOffset(1.2) ratio.GetXaxis().SetLabelSize(0.20) ratio.Draw("A P E2") pad2.Update() line = TLine(ptbins[0], 1, ptbins[len(ptda)], 1) line.SetLineColor(kBlue + 1) line.SetLineWidth(2) line.Draw() saveas = "/MassResolutionVsPt_%s_%s" % (trackType, rapidity) c2.SaveAs(output + saveas + ".png") c2.SaveAs(output + saveas + ".pdf") c2.SaveAs(output + saveas + ".root") c2.SaveAs(output + saveas + ".C")
class pdf_class: def __init__(self, filename): self._canvas = TCanvas("canvas", "canvas", 800, 450) self._canvas.cd() self._pad = TPad("pad", "", 0, 0, 1, 0.95) self._pdf = TPDF("%s.pdf" % filename) self._subCanvas = 0 self._nCanvasPerPage = 0 self._nx = 1 self._ny = 1 def newPage(self, headerText="", nx=1, ny=1, sameHeader=False): if self._subCanvas != 0: self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.NewPage() self._pad.Clear() self._canvas.cd() if not sameHeader: self._nx = nx self._ny = ny self._header = TPaveText(0, 0.95, 1, 1) self._header.SetFillColor(0) self._header.SetTextColor(1) self._header.SetTextFont(22) self._header.AddText(headerText) self._header.AddLine(0.0, 0.95, 1.0, 0.95) self._header.Draw() self._pad.cd() self._pad.Divide(self._nx, self._ny) self._pad.SetGrid(0, 0) self._nCanvasPerPage = self._nx * self._ny self._subCanvas = 0 def newLegend(self, header="", lx=0.8, ly=0.8, ux=0.9, uy=0.88): self._legend = TLegend(lx, ly, ux, uy) self._legend.SetFillColor(0) self._legend.SetBorderSize(0) self._legend.SetTextFont(132) self._legend.SetTextSize(0.035) if header != "": self._legend.SetHeader(header) def draw(self, hists, legend=False, drawOpt="", logx=False, logy=False, logz=False): if self._subCanvas + 1 > self._nCanvasPerPage: self.newPage(sameHeader=True) self._subCanvas += 1 self._pad.cd(self._subCanvas) first = 1 for h in hists: if first == 1: first = 0 h.Draw(drawOpt) else: h.Draw("same%s" % drawOpt) if legend: self._legend.AddEntry(h, h.GetTitle(), "LP") if legend: self._legend.Draw() if logx: self._pad.cd(self._subCanvas).SetLogx() if logy: self._pad.cd(self._subCanvas).SetLogy() if logz: self._pad.cd(self._subCanvas).SetLogz() self._canvas.cd() self._canvas.Update() self._pad.Draw() def close(self): self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.Close()
def plot_limit(path, file_name, xslabel, typelabel, minx=200, maxx=2000): low_y = 0.001 hi_y = 5 sigma = "#sigma_{"+xslabel+"}" unit = "95% CL limits on "+sigma+" #times BR(S#rightarrow ZZ) [pb]" #unit = "95% CL limits on "+sigma+" #times BR(S#rightarrow ZZ #rightarrow 4l) [fb]" x_axis_title = "m_{S} [GeV]" #dummy=ROOT.TH2F("dummy",";"+x_axis_title+";"+unit, dummy=ROOT.TH2F("dummy",";"+";"+unit, 160, float(minx),float(maxx),3000,low_y,hi_y); #dummy.GetXaxis().SetNdivisions(8); hist_obs,hist_exp,hist_1s,hist_2s = make_limit_graph(path+"Cut_ggF.txt") hist_obs2,hist_exp2,hist_1s2,hist_2s2 = make_limit_graph(path+"c1_ggF.txt") hist_obs3,hist_exp3,hist_1s3,hist_2s3 = make_limit_graph(path+"4l_36to139_ggF.txt") #hist_obs4,hist_exp4,hist_1s4,hist_2s4 = make_limit_graph(path+"c2_ggF.txt") for i in range(hist_exp.GetN()): hist_exp.GetY()[i] *= 1./4.52 for i in range(hist_exp2.GetN()): hist_exp2.GetY()[i] *= 1./4.52 #for i in range(hist_exp3.GetN()): hist_exp3.GetY()[i] *= 1./1000. canvas = ROOT.TCanvas("canvas2", " ", 600, 600) canvas.SetLogy() ##========================= add ratio pad =========================== ratio=0.2 if ratio>0: fraction=ratio+0.2 Pad1 = TPad("p1","p1",0,fraction*1.0/(fraction+1),1,1,0,0) # x1,y1,x2,y2 Pad1.SetMargin(0.15,0.10,0.03,0.05) Pad1.SetLogy() Pad2 = TPad("p2","p2",0,0,1,fraction*1.0/(fraction+1),0,0) Pad2.SetMargin(0.15,0.10,0.15/fraction,0.04) Pad2.SetGrid() Pad1.Draw() Pad2.Draw() hist_exp.SetLineWidth(1) hist_exp.SetMarkerStyle(20) hist_exp.SetMarkerSize(0.5) hist_exp.SetLineColor(1) hist_exp2.SetLineWidth(1) hist_exp2.SetMarkerStyle(20) hist_exp2.SetMarkerSize(0.5) hist_exp2.SetLineColor(2) hist_exp3.SetLineWidth(1) hist_exp3.SetMarkerStyle(20) hist_exp3.SetMarkerSize(0.5) hist_exp3.SetLineColor(4) #hist_exp4.SetLineWidth(1) #hist_exp4.SetMarkerStyle(20) #hist_exp4.SetMarkerSize(0.5) #hist_exp4.SetLineColor(8) if ratio>0: Pad1.cd() else: canvas.cd() dummy.Draw() hist_exp. Draw("LP") hist_exp2. Draw("LP") hist_exp3. Draw("LP") #hist_exp4. Draw("LP") legend = ROOT.myLegend(0.56, 0.70, 0.83, 0.90) #legend.AddEntry(hist_exp, "4l DNN-based 1-muZZ", "l") #legend.AddEntry(hist_exp3, "4l DNN-based 2-muZZ", "l") #legend.AddEntry(hist_exp2, "4l DNN-based 3-muZZ", "l") legend.AddEntry(hist_exp, "New limits: Cut-based", "l") legend.AddEntry(hist_exp2, "New limits: DNN-based", "l") legend.AddEntry(hist_exp3, "2015-2016 scaled to 139 fb^{-1}", "l") #legend.AddEntry(hist_exp, "Cut-based", "l") #legend.AddEntry(hist_exp2, "C0", "l") #legend.AddEntry(hist_exp3, "C1", "l") #legend.AddEntry(hist_exp4, "C2", "l") legend.Draw() lumi = 138.97 x_off_title = 0.20 ROOT.myText(x_off_title, 0.85, 1, "#bf{#it{ATLAS}} Internal") ROOT.myText(x_off_title, 0.80, 1, "13 TeV, {:.1f} fb^{{-1}}".format(lumi)) ROOT.myText(x_off_title, 0.75, 1, typelabel) #dummy.Draw("AXIS SAME") if ratio>0: x1=hist_exp.GetX() y1=hist_exp.GetY() y2=hist_exp2.GetY() y3=hist_exp3.GetY() #y4=hist_exp4.GetY() hist_ratio1 = ROOT.TGraph(13) hist_ratio2 = ROOT.TGraph(13) hist_ratio3 = ROOT.TGraph(9) #hist_ratio4 = ROOT.TGraph(13) for i in range(13): hist_ratio1.SetPoint(i, x1[i], 1) for i in range(13): hist_ratio2.SetPoint(i, x1[i], y2[i]/y1[i]) for i in range(9): hist_ratio3.SetPoint(i, x1[i], y3[i]/y1[i]) #for i in range(13): # hist_ratio4.SetPoint(i, x1[i], y4[i]/y1[i]) Pad2.cd() mg = ROOT.TMultiGraph() mg.GetXaxis().SetLimits(200,2000) mg.SetMinimum(0.5) mg.SetMaximum(1.5) hist_ratio1.SetMarkerSize(0) hist_ratio1.SetLineColor(1) hist_ratio2.SetMarkerSize(0.5) hist_ratio2.SetLineColor(2) hist_ratio3.SetMarkerSize(0.5) hist_ratio3.SetLineColor(4) #hist_ratio4.SetMarkerSize(0.5) #hist_ratio4.SetLineColor(8) mg.Add(hist_ratio1) mg.Add(hist_ratio2) mg.Add(hist_ratio3) #mg.Add(hist_ratio4) mg.Draw("ALP") mg.GetYaxis().SetTitle("Ratio") mg.GetXaxis().SetTitle(x_axis_title) canvas.SaveAs("Pdf_plots/"+file_name+".pdf")
def compareMassRes(trackType): file2016BB = open("default/MassResolutionVsMass_%s_BB.pkl" % trackType, "rb") file2016BE = open("default/MassResolutionVsMass_%s_BE.pkl" % trackType, "rb") file2017BB = open("cruijff/MassResolutionVsMass_%s_BB.pkl" % trackType, "rb") file2017BE = open("cruijff/MassResolutionVsMass_%s_BE.pkl" % trackType, "rb") fileCBB = open("crystal/MassResolutionVsMass_%s_BB.pkl" % trackType, "rb") fileCBE = open("crystal/MassResolutionVsMass_%s_BE.pkl" % trackType, "rb") results2016BB = pickle.load(file2016BB) results2016BE = pickle.load(file2016BE) results2017BB = pickle.load(file2017BB) results2017BE = pickle.load(file2017BE) resultsCBB = pickle.load(fileCBB) resultsCBE = pickle.load(fileCBE) graph2016BB = getGraph(results2016BB, "DCBBB") graph2016BE = getGraph(results2016BE, "DCBBE") graph2017BB = getGraph(results2017BB, "CruijffBB") graph2017BE = getGraph(results2017BE, "CruijffBE") graphCBB = getGraph(resultsCBB, "CBB") graphCBE = getGraph(resultsCBE, "CBE") ratioBB = getRatio(results2016BB, results2017BB, "ratioBB") ratioBE = getRatio(results2016BE, results2017BE, "ratioBE") ratioCBB = getRatio(results2016BB, resultsCBB, "ratioCBB") ratioCBE = getRatio(results2016BE, resultsCBE, "ratioCBE") canv = TCanvas("c1", "c1", 800, 1200) plotPad = TPad("plotPad", "plotPad", 0, 0.3, 1, 1) ratioPad = TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() ratioPad.UseCurrentStyle() plotPad.Draw() ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) gStyle.SetTitleYOffset(1.55) xMax = 0.08 if trackType == "Inner": xMax = 0.2 if trackType == "Outer": xMax = 0.4 plotPad.DrawFrame(0, 0, 6000, xMax, ";M [GeV]; mass resolution") graph2016BB.Draw("samepe") graph2017BB.Draw("samepe") graphCBB.Draw("samepe") graph2017BB.SetLineColor(kRed) graph2017BB.SetMarkerColor(kRed) graphCBB.SetLineColor(kBlue) graphCBB.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s BB" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graph2016BB, "Cruijff", "l") leg.AddEntry(graph2017BB, "Double CB", "l") leg.AddEntry(graphCBB, "Crystal Ball", "l") leg.Draw() plotPad.RedrawAxis() ratioPad.cd() ratioBB.SetLineColor(kRed) ratioCBB.SetLineColor(kBlue) ratioPad.DrawFrame(0, 0.5, 6000, 1.5, ";ratio") ratioBB.Draw("samepe") ratioCBB.Draw("samepe") canv.Print("massResolutionCompareFunc_%s_BB.pdf" % trackType) canv = TCanvas("c1", "c1", 800, 1200) plotPad = TPad("plotPad", "plotPad", 0, 0.3, 1, 1) ratioPad = TPad("ratioPad", "ratioPad", 0, 0., 1, 0.3) style = setTDRStyle() gStyle.SetOptStat(0) plotPad.UseCurrentStyle() ratioPad.UseCurrentStyle() plotPad.Draw() ratioPad.Draw() plotPad.cd() plotPad.cd() plotPad.SetGrid() gStyle.SetTitleXOffset(1.45) gStyle.SetTitleYOffset(1.55) xMax = 0.08 if trackType == "Inner": xMax = 0.2 if trackType == "Outer": xMax = 0.4 plotPad.DrawFrame(0, 0, 6000, xMax, ";M [GeV]; mass resolution") graph2016BE.Draw("samepe") graph2017BE.Draw("samepe") graphCBE.Draw("samepe") graph2017BE.SetLineColor(kRed) graph2017BE.SetMarkerColor(kRed) graphCBE.SetLineColor(kBlue) graphCBE.SetMarkerColor(kBlue) latex = TLatex() latex.SetTextFont(42) latex.SetTextAlign(31) latex.SetTextSize(0.04) latex.SetNDC(True) latexCMS = TLatex() latexCMS.SetTextFont(61) latexCMS.SetTextSize(0.055) latexCMS.SetNDC(True) latexCMSExtra = TLatex() latexCMSExtra.SetTextFont(52) latexCMSExtra.SetTextSize(0.03) latexCMSExtra.SetNDC(True) latex.DrawLatex(0.95, 0.96, "(13 TeV)") cmsExtra = "#splitline{Preliminary}{}" latexCMS.DrawLatex(0.19, 0.88, "CMS") if "Simulation" in cmsExtra: yLabelPos = 0.81 else: yLabelPos = 0.84 latexCMSExtra.DrawLatex(0.19, yLabelPos, "%s" % (cmsExtra)) leg = TLegend(0.52, 0.76, 0.95, 0.91, "%s BE" % trackType, "brNDC") leg.SetFillColor(10) leg.SetFillStyle(0) leg.SetLineColor(10) leg.SetShadowColor(0) leg.SetBorderSize(1) leg.AddEntry(graph2016BE, "Cruijff", "l") leg.AddEntry(graph2017BE, "Double CB", "l") leg.AddEntry(graphCBE, "Crystal Ball", "l") leg.Draw() plotPad.RedrawAxis() ratioPad.cd() ratioBE.SetLineColor(kRed) ratioCBE.SetLineColor(kBlue) ratioPad.DrawFrame(0, 0.5, 6000, 1.5, ";;ratio") ratioBE.Draw("samepe") ratioCBE.Draw("samepe") canv.Print("massResolutionCompareFunc_%s_BE.pdf" % trackType)
c1 = TCanvas("c1,", "c1", 200, 10, 700, 900) c1.SetFillColor(18) pad1 = TPad("pad1", "pad1", 0.05, 0.50, 0.95, 0.95, 21) pad2 = TPad("pad2", "pad2", 0.05, 0.05, 0.95, 0.45, 21) pad1.Draw() pad2.Draw() gBenchmark.Start("fillrandom") form1 = TFormula("form1", "abs(sin(x)/x)") sqroot = TF1("sqroot", "x*gaus(0) + [3]*form1", 0, 10) sqroot.SetParameters(10, 4, 1, 20) #pad1.SetGridx() pad2.SetGridy() pad1.SetGrid() c1.Update() pad1.cd() sqroot.Draw() pad1.Modified() pad1.Update() pad2.cd() pad2.GetFrame().SetFillColor(42) pad2.GetFrame().SetBorderMode(-1) pad2.GetFrame().SetBorderSize(5) h1f = TH1F("h1f", "h1f", 200, 0, 10) h1f.FillRandom("sqroot", 10000) h1f.Draw() pad2.Update()
t.SetTextSize(0.026) t.DrawText(3, 17, r'>>> x, y = 5, 7') t.DrawText(3, 16, r'>>> import math; x*math.sqrt(y)') t.DrawText( 3, 14, r'>>> for i in range(2,7): print "sqrt(%d) = %f" % (i,math.sqrt(i))') t.DrawText(3, 10, r'>>> import ROOT; f1 = ROOT.TF1( "f1", "sin(x)/x", 0, 10 )') t.DrawText(3, 9, r'>>> f1.Draw()') t.SetTextFont(81) t.SetTextSize(0.018) t.DrawText(4, 15, '13.228756555322953') t.DrawText(4, 13.3, 'sqrt(2) = 1.414214') t.DrawText(4, 12.7, 'sqrt(3) = 1.732051') t.DrawText(4, 12.1, 'sqrt(4) = 2.000000') t.DrawText(4, 11.5, 'sqrt(5) = 2.236068') t.DrawText(4, 10.9, 'sqrt(6) = 2.449490') pad = TPad('pad', 'pad', .2, .05, .8, .35) pad.SetFillColor(42) pad.SetFrameFillColor(33) pad.SetBorderSize(10) pad.Draw() pad.cd() pad.SetGrid() f1 = TF1('f1', 'sin(x)/x', 0, 10) f1.Draw() nut.cd() nut.Update()
def calc_punzi_FOM_vs_ctau(cutlist, labellist=[],mass_point=40,additional_string="",n_sigma=1,FOM='punzi'): 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") # TODO: add with global variable for skimmed tree # nevt[s] = (file[s].Get('c_nEvents')).GetBinContent(1) # TODO: add with global variable for skimmed tree effs[s] = [0]*(ncuts+1) 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] + ")") 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]} #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) leg.SetTextSize(0.03) leg2.SetTextSize(0.03) leg.SetBorderSize(0) leg2.SetBorderSize(0) leg.SetHeader("m_{#pi}=" +str(mass_point)+" GeV") leg2.SetHeader("m_{#pi}=" +str(mass_point)+" GeV") #for background let's first consider the cut for j, c in enumerate(cutlist): print "cut: ", c #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") # TODO: add with global variable for skimmed tree #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) # TODO: add with global variable for skimmed tree chain[s].Add(NTUPLEDIR + ss + ".root") weight = "EventWeight" var = "nPV" # var = "nCHSJets" # TODO: add with global variable for skimmed tree 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 "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() 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 FOM=="punzi": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']/(n_sigma*0.5 + math.sqrt(back_int_weight[c]))} elif FOM=="signaleff": punzi_dict[c][s] = {'sign': eff_dict[c][s]['eff']*100} else: print "not punzi FOM, aborting!" exit() #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 = "VBFH_M"+str(mass_point)+"_ctau0" elif la==0.05 or la==0.1: st = "VBFH_M"+str(mass_point)+"_ctau"+str(str(la).replace("0.","0p")) else: st = "VBFH_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(21) graph[c].SetLineWidth(2) graph[c].SetMarkerSize(1.) 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') 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') #leg2.AddEntry(back_graph[c],labellist[j]+" bkg.",'PL') 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) leg2.AddEntry(dummy, 'cuts on bkg.','PL') cmg = TCanvas("cmg", "cmg", 2000, 800) cmg.cd() cmg.SetGrid() if FOM=="signaleff": cmg.SetLogx() pad1 = TPad("pad1", "pad1", 0, 0., 0.75, 1.0) pad1.SetGrid() pad1.SetLogx() if FOM=="signaleff": #print "LOL" pad1.SetLogy() pad1.Draw() pad1.cd() if FOM=="signaleff": mg.SetMaximum(101) #mg.SetMinimum(1.e-50) mg.Draw("APL") mg.GetXaxis().SetTitle('c#tau_{#pi} (mm)') mg.GetYaxis().SetTitleOffset(1.2); if FOM=="punzi": mg.GetYaxis().SetTitle('Punzi significance @ '+str(n_sigma)+' #sigma, VBF cuts') mg.GetYaxis().SetTitleOffset(1.5) elif FOM=="signaleff": mg.GetYaxis().SetTitle('Signal (background) efficiency, VBF cuts (%)') else: print "not punzi FOM, aborting" cmg.cd() pad2 = TPad("pad2", "pad2", 0.75, 0., 1, 1.0) pad2.SetGrid() pad2.SetLogx() pad2.Draw() pad2.cd() leg2.SetTextSize(0.07) leg.Clear()#????????? leg2.Draw() cmg.Update() if FOM=="punzi": cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/Punzi_m"+str(mass_point)+"_"+str(n_sigma)+"sigma"+additional_string+"_v0_pfXTag.pdf") cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/Punzi_m"+str(mass_point)+"_"+str(n_sigma)+"sigma"+additional_string+"_v0_pfXTag.png") elif FOM=="signaleff": cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/SignalEff_m"+str(mass_point)+additional_string+"_v0_pfXTag.pdf") cmg.Print("$CMSSW_BASE/src/Analyzer/LLP2018/macro/Efficiency/SignalEff_m"+str(mass_point)+additional_string+"_v0_pfXTag.png") else: print "not punzi FOM, aborting" if not options.bash: raw_input("Press Enter to continue...") cmg.Close()
# Test ratio plot for systematics import ROOT from ROOT import TCanvas, TColor, TGaxis, TH1F, TPad from ana_util import * fStd = ROOT.TFile('std.root') fSys = ROOT.TFile('syspid.root') c = ROOT.TCanvas('cMC','Systematics', 800, 800) pad1 = TPad("pad1", "pad1", 0, 0.3, 1, 1.0) pad1.SetBottomMargin(0) # joins upper and lower plot pad1.SetGrid() pad1.SetLogy() pad1.Draw() pad1.cd() lgd = ROOT.TLegend(0.5, 0.12, 0.85, 0.45) fStd.hJpsiEffPrompt.Draw('PE') lgd.AddEntry(fStd.hJpsiEffPrompt, 'Prompt (Std. exclude hadrons)') fStd.hJpsiEffBdecay.Draw('same') lgd.AddEntry(fStd.hJpsiEffBdecay, 'Non-prompt (Std. exclude hadrons)') hPsys = fSys.hJpsiEffPrompt.Clone('hPsys') hPsys.SetMarkerStyle(kRoundHollow) hPsys.Draw('same') lgd.AddEntry(hPsys, 'Prompt (compare)')
h_asym_data.SetMarkerStyle(20) h_asym_data.SetMarkerSize(0.9) h_asym_data.GetXaxis().SetTitle('Events') h_asym_data.GetXaxis().SetTitleSize(26) h_asym_data.Draw('p e2 same') # testing e2 h_aqgc.SetLineColor(92), h_aqgc.SetLineWidth(2), h_aqgc.SetFillColor( 0), h_aqgc.Scale( 100) #if year == '2017' else h_aqgc.Scale(100*94.91/37.2) # FIXME h_aqgc.Draw('HIST same') lLabel, pLabel = lumiLabel(True, years), prelimLabel() lLabel.Draw(), pLabel.Draw() leg = makeLegend(h_asym_data, v_hist, h_aqgc) leg.Draw() pad2.cd() pad2.SetGrid(0, 1) h_ratio = h_data.Clone('h_ratio') h_ratio.Sumw2() h_ratio.Divide(h_sum) h_ratio.SetMinimum(-0.4) h_ratio.SetMaximum(2.4) #h_ratio.SetMinimum(0.1) #h_ratio.SetMaximum(1.9) #h_ratio.GetYaxis().SetTickLength(0.5) h_ratio.SetMarkerStyle(20) h_ratio.SetMarkerSize(0.9) h_ratio.SetLineColor(ROOT.kBlack) h_ratio.Draw('p same') for i in range(len(selections)): h_ratio.GetXaxis().SetBinLabel(i + 1, selections[i][1]) denom_err, denom_err2 = h_mc_err.Clone(), h_mc_err.Clone()