def drawCut(hist): #drawCut(80, 140, 0., hist['BkgSum'].GetMaximum()) line1 = TLine(80, 0, 80, hist['BkgSum'].GetMaximum()) line1.SetLineWidth(2) line1.SetLineStyle(7) line1.SetLineColor(1) line1.Draw() line2 = TLine(140, 0, 140, hist['BkgSum'].GetMaximum()) line2.SetLineWidth(2) line2.SetLineStyle(7) line2.SetLineColor(1) line2.Draw() line1 = TLine(0.841, 0, 0.841, 15) line1.SetLineWidth(2) line1.SetLineStyle(7) line1.SetLineColor(1) line1.Draw() line1 = TLine(100, 0, 100, hist['BkgSum'].GetMaximum()) line1.SetLineWidth(2) line1.SetLineStyle(7) line1.SetLineColor(1) line1.Draw()
def plot_sector_beam(canvas, histos, title_formatter, label, save_name): canvas.Clear() canvas.Divide(3, 2) vert = TLine(0, -1.2, 0, 1.2) hori = TLine(-1.2, 0, 1.2, 0) vert.SetLineStyle(8) vert.SetLineStyle(1) vert.SetLineWidth(1) hori.SetLineStyle(8) hori.SetLineStyle(1) hori.SetLineWidth(1) xtitle = '#Delta E_{beam} (#theta_{e}, p_{e})' ytitle = '#Delta E_{beam} (#theta_{e}, #theta_{p})' for i in range(1, 7): canvas.cd(i) histos[title_formatter.format(i)].GetXaxis().SetRangeUser(-1.2, 1.2) histos[title_formatter.format(i)].GetYaxis().SetRangeUser(-1.2, 1.2) histos[title_formatter.format(i)].Draw('colz') vert.Draw() hori.Draw() label.DrawLatex(0.1, 0.925, '#Delta E_{beam} = E_{beam} - E_{pred}') label.DrawLatex(0.5, 0.015, xtitle) label.SetTextAngle(90) label.DrawLatex(0.045, 0.5, ytitle) label.SetTextAngle(0) canvas.Print(save_name)
def DrawScat2XLine(graph, title, fname, ycoord1, ycoord2): #, grid): c = TCanvas("c", "c", 800, 600) graph.SetTitle(title) graph.GetXaxis().SetTitleSize(.04) graph.GetYaxis().SetTitleSize(.04) graph.GetXaxis().SetTitleOffset(1.2) graph.GetYaxis().SetTitleOffset(1.25) graph.GetXaxis().CenterTitle(1) graph.GetYaxis().CenterTitle(1) graph.GetYaxis().SetMaxDigits(4) graph.SetMarkerStyle(20) # Full circle graph.Draw() gPad.Update() line1 = TLine(gPad.GetUxmin(), ycoord1, gPad.GetUxmax(), ycoord1) line2 = TLine(gPad.GetUxmin(), ycoord2, gPad.GetUxmax(), ycoord2) # print(gPad.GetUymin(),gPad.GetUymax()) line1.SetLineStyle(2) line1.SetLineColor(2) line1.SetLineWidth(3) line2.SetLineStyle(2) line2.SetLineColor(2) line2.SetLineWidth(3) graph.Draw("AP") line1.Draw("same") line2.Draw("same") c.SaveAs(fname + ".C") c.SaveAs(fname + ".pdf") return
def draw2d(hist, xtitle, ytitle, number=False, nxbins=0, nybins=0): """Draw 2D histogram.""" tsize = 0.045 lines = [] xmin, xmax = hist.GetXaxis().GetXmin(), hist.GetXaxis().GetXmax() ymin, ymax = hist.GetYaxis().GetXmin(), hist.GetYaxis().GetXmax() canvas = TCanvas('canvas', 'canvas', 100, 100, 900, 800) canvas.SetMargin(0.11, 0.16, 0.10, 0.02) # LRBT canvas.SetLogz() hist.GetXaxis().SetTitle(xtitle) hist.GetYaxis().SetTitle(ytitle) hist.GetZaxis().SetTitle("Events") hist.GetXaxis().SetTitleSize(tsize) hist.GetYaxis().SetTitleSize(tsize) hist.GetZaxis().SetTitleSize(tsize) hist.GetXaxis().SetLabelSize(0.9 * tsize) hist.GetYaxis().SetLabelSize(0.9 * tsize) hist.GetZaxis().SetLabelSize(0.9 * tsize) hist.GetXaxis().SetTitleOffset(1.04) hist.GetYaxis().SetTitleOffset(1.14) hist.GetZaxis().SetTitleOffset(1.08) hist.Draw('COLZ') if number: latex = TLatex() latex.SetTextSize(0.8 * tsize) latex.SetTextAlign(22) latex.SetTextFont(62) latex.SetTextColor(kRed) for ix in range(1, hist.GetXaxis().GetNbins() + 1): x = hist.GetXaxis().GetBinCenter(ix) for iy in range(1, hist.GetYaxis().GetNbins() + 1): y = hist.GetYaxis().GetBinCenter(iy) latex.DrawLatex(x, y, str(Unroll.GetBin(x, y))) if nxbins > 0: # divide with nlines for i in range(1, nxbins): x = xmin + (xmax - xmin) * i / nxbins line = TLine(x, ymin, x, ymax) line.SetLineColor(kRed) line.SetLineStyle(kDashed) line.SetLineWidth(1) line.Draw() lines.append(line) if nybins > 0: # divide with nlines for i in range(1, nybins): y = ymin + (ymax - ymin) * i / nybins line = TLine(xmin, y, xmax, y) line.SetLineColor(kRed) line.SetLineStyle(kDashed) line.SetLineWidth(2) line.Draw() lines.append(line) canvas.RedrawAxis() canvas.SaveAs(hist.GetName() + ".png") #canvas.SaveAs(hist.GetName()+".pdf") canvas.Close()
def plot_event_selection(canvas, histos, save_name, label): canvas.Clear() canvas.Divide(2, 1) histos['histos_w_in_ctof'].SetLineColor(1) histos['histos_w_pass_angle_in_ctof'].SetLineColor(1) histos['histos_w_pass_angle_in_ctof'].SetFillColorAlpha(64, 1.0) histos['histos_angle_ep'].SetLineColor(1) histos['histos_angle_ep_pass_w_in_ctof'].SetLineColor(1) histos['histos_angle_ep_pass_w_in_ctof'].SetFillColorAlpha(64, 1.0) histos['histos_w_in_ctof'].SetMinimum(0) histos['histos_w_pass_angle_in_ctof'].SetMinimum(0) # Fix missing bins histos['histos_w_in_ctof'].GetXaxis().SetRangeUser(0.7, 1.3) histos['histos_w_pass_angle_in_ctof'].GetXaxis().SetRangeUser(0.7, 1.3) wleft = TLine(0.8, histos['histos_w_in_ctof'].GetMinimum(), 0.8, 0.8 * histos['histos_w_in_ctof'].GetMaximum()) wright = TLine(1.08, histos['histos_w_in_ctof'].GetMinimum(), 1.08, 0.8 * histos['histos_w_in_ctof'].GetMaximum()) wleft.SetLineColor(99) wleft.SetLineWidth(1) wright.SetLineColor(99) wright.SetLineWidth(1) canvas.cd(1) histos['histos_w_in_ctof'].Draw() histos['histos_w_pass_angle_in_ctof'].Draw('same') wleft.Draw() wright.Draw() label.DrawLatex(0.1, 0.925, 'Electron (forward) and Proton (central)') label.DrawLatex(0.5, 0.015, 'W (GeV/c^{2})') label.DrawLatex(0.67, 0.86, '#color[64]{#phi_{ep} > 174}') canvas.cd(2) histos['histos_angle_ep'].Draw() histos['histos_angle_ep_pass_w_in_ctof'].Draw('same') left = TLine(174, 0.0, 174, 0.8 * histos['histos_angle_ep'].GetMaximum()) left.SetLineColor(99) left.SetLineWidth(1) left.Draw() label.DrawLatex(0.1, 0.925, 'Electron (forward) and Proton (central)') label.DrawLatex(0.5, 0.015, '#phi_{ep}') label.DrawLatex(0.57, 0.86, '#color[64]{W \in [0.8, 1.08]}') canvas.Print(save_name)
def draw_limits_per_category(nchannels, xmin, xmax, obs, expect, upper1sig, lower1sig, upper2sig, lower2sig): channel = np.array( [3. * nchannels - 1.5 - 3. * i for i in range(0, nchannels)]) ey = np.array([0.8 for i in range(0, nchannels)]) zero = np.zeros(nchannels) gexpect1sig = TGraphAsymmErrors(nchannels, expect, channel, lower1sig, upper1sig, ey, ey) gexpect1sig.SetFillColor(kGreen) gexpect1sig.SetLineWidth(2) gexpect1sig.SetLineStyle(2) gexpect2sig = TGraphAsymmErrors(nchannels, expect, channel, lower2sig, upper2sig, ey, ey) gexpect2sig.SetFillColor(kYellow) gexpect2sig.SetLineWidth(2) gexpect2sig.SetLineStyle(2) gexpect2sig.Draw("2") gexpect1sig.Draw("2") gobs = TGraphErrors(nchannels, obs, channel, zero, ey) gobs.SetMarkerStyle(21) gobs.SetMarkerSize(1.5) gobs.SetLineWidth(2) gobs.Draw("pz") # dashed line at median expected limits l = TLine() l.SetLineStyle(2) l.SetLineWidth(2) for bin in range(nchannels): l.DrawLine(expect[bin], channel[bin] - ey[bin], expect[bin], channel[bin] + ey[bin]) # line to separate individual and combined limits l.SetLineStyle(1) l.SetLineWidth(1) l.DrawLine(xmin, 0, xmax, 0) # legend x1 = gStyle.GetPadLeftMargin() + 0.01 y2 = 1 - gStyle.GetPadTopMargin() - 0.01 leg = TLegend(x1, y2 - 0.17, x1 + 0.25, y2) leg.SetFillColor(4000) leg.AddEntry(gexpect1sig, "Expected #pm1#sigma", "FL") leg.AddEntry(gexpect2sig, "Expected #pm2#sigma", "FL") leg.AddEntry(gobs, "Observed", "pl") leg.Draw() return gobs, gexpect1sig, gexpect2sig, leg
def draw_limits_per_category(nchannels, xmin, xmax, obs, expect, upper1sig, lower1sig, upper2sig, lower2sig): channel = np.array( [nchannels - 1.5 - float(i) for i in range(0, nchannels)]) ey = np.full(nchannels, 0.494) zero = np.zeros(nchannels) gexpect1sig = TGraphAsymmErrors(nchannels, expect, channel, lower1sig, upper1sig, ey, ey) gexpect1sig.SetFillColor(kGreen) gexpect1sig.SetLineWidth(2) gexpect1sig.SetLineStyle(2) gexpect2sig = TGraphAsymmErrors(nchannels, expect, channel, lower2sig, upper2sig, ey, ey) gexpect2sig.SetFillColor(kYellow) gexpect2sig.SetLineWidth(2) gexpect2sig.SetLineStyle(2) gexpect2sig.Draw("2") gexpect1sig.Draw("2") gobs = TGraphErrors(nchannels, obs, channel, zero, ey) gobs.SetMarkerStyle(21) gobs.SetMarkerSize(1.5) gobs.SetLineWidth(2) #gobs.Draw("pz") # dashed line at median expected limits l = TLine() l.SetLineStyle(2) l.SetLineWidth(2) for bin in range(nchannels): l.DrawLine(expect[bin], channel[bin] - ey[bin], expect[bin], channel[bin] + ey[bin]) # line to separate individual and combined limits l.SetLineStyle(1) l.SetLineWidth(1) l.DrawLine(xmin, 0, xmax, 0) # legend leg = TLegend(0.75, 0.75, 0.95, 0.9) leg.SetFillColor(4000) leg.AddEntry(gexpect1sig, "Expected #pm1#sigma", "FL") leg.AddEntry(gexpect2sig, "Expected #pm2#sigma", "FL") #leg.AddEntry( gobs, "Observed", "pl" ) leg.Draw() return gobs, gexpect1sig, gexpect2sig, leg
def addLine(self, x1, y1, x2, y2, color, thickness=0.): line = TLine(x1, y1, x2, y2) line.SetLineColor(color) line.SetLineStyle(2) if thickness: line.SetLineWidth(thickness) self.lines.append(line)
def CheckToysTempFiles(sample='tW', histo='dnn'): path = baseoutpath%(year, ms, ml) f = TFile.Open(path+sample+ ('.root' if not sample.endswith('.root') else '')) hnom = f.Get(histo) nom = hnom.Integral() h = TH1F('h', 'h', 20, 0.24, 0.26) for i in range(nToys): ht = f.Get(histo+'_NormToy%i'%i) h.Fill(ht.Integral()) c = TCanvas('c', 'c', 10, 10, 1200, 800) h.SetStats(0) h.SetTitle('') h.GetXaxis().SetTitle("Yield %s"%sample) h.GetYaxis().SetTitle("Number of toys") h.SetLineWidth(2); h.SetLineColor(kOrange+1) h.SetFillColor(0) h.Draw('hist') l = TLine(nom, 0, nom, h.GetMaximum()) l.SetLineColor(kGray+3); l.SetLineWidth(2); l.SetLineStyle(2) l.Draw("same") name = 'toys_%s_%s'%(sample, histo) for form in ['png', 'pdf']: c.SaveAs(webpath+name+'.'+form)
def drawLine(x1, y1, x2, y2, color=1): line = TLine(x1, y1, x2, y2) line.SetLineStyle(2) line.SetLineWidth(2) line.SetLineColor(color) line.Draw() return line
def myLineBoxTextBorder(x, y, lcolor, lstyle, bcolor, bstyle, bsize, tsize, text): l = TLatex() l.SetTextAlign(12) l.SetTextSize(tsize/2.5) l.SetNDC() l.DrawLatex(x,y,text) yl1 = y-0.25*bsize yl2 = y+0.25*bsize xl1 = x-0.25*bsize-0.4*bsize xl2 = x+0.25*bsize-0.4*bsize #print("line = ",xl1,yl1,xl2,yl2) mline = TLine(xl1,yl1,xl2,yl2) mline.SetLineColor(lcolor) mline.SetLineStyle(lstyle) mline.SetLineWidth(2) y_new=(yl1+yl2)/2. mline.DrawLineNDC(xl1,y_new,xl2,y_new) yb1 = y-0.15*bsize yb2 = y+0.15*bsize xb1 = x-0.25*bsize-0.4*bsize xb2 = x+0.25*bsize-0.4*bsize #print("box = ",xb1,yb1,xb2,yb2) mbox = TPave(xb1,yb1,xb2,yb2,1,"NDC") mbox.SetLineWidth(2) mbox.SetLineColor(1) mbox.SetFillColor(bcolor) mbox.SetFillStyle(bstyle) mbox.Draw("l") return mbox
def drawLine(xlow, ylow, xup, yup, lineWidth, lineStyle, lineColor): L1 = TLine(xlow, ylow, xup, yup) L1.SetLineWidth(lineWidth) L1.SetLineColor(lineColor) L1.SetLineStyle(lineStyle) L1.Draw("same") return L1
def overlayProfile(l_prof, l_axis, l_histo, l_legend, l_text, l_legInfo, saveAs, saveString): aString, xLabel, yLabel, xOffset, yOffset, aLabSize, aTextSize = l_axis hString, c_x, c_y, yMin, yMax, hBins, hFile = l_histo lString, l_x1, l_y1, l_x2, l_y2, l_textSize = l_legend t_str, plotText, t_textSize, t_alignment, t_start, t_gap, t_x = l_text l_bins = PythonUtils.makeListFromString(hBins, ';') gROOT.SetBatch(1) c = TCanvas('c', 'c', int(c_x), int(c_y)) gStyle.SetOptStat(0) c.SetTicks(1, 1) for i in xrange(len(l_prof)): if i == 0: l_prof[i].Draw('eps') setupAxes(l_prof[i], xLabel, yLabel, xOffset, yOffset, aTextSize, l_bins[0], l_bins[len(l_bins) -1], 1) l_prof[i].SetMinimum(float(yMin)) l_prof[i].SetMaximum(float(yMax)) l_prof[i].SetTitle('') hLine = TLine(l_prof[i].GetXaxis().GetXmin(), 1, l_prof[i].GetXaxis().GetXmax(), 1) hLine.SetLineWidth(2) hLine.SetLineColor(1) hLine.SetLineStyle(2) hLine.Draw('same') else: l_prof[i].Draw('eps same') setupTextOnPlot(plotText, t_textSize, t_alignment, t_x, t_start, t_gap) setupLegend(l_legInfo, l_x1, l_y1, l_x2, l_y2, l_textSize) savePlots(c, saveString, saveAs)
def plot_GOF(hist, obs, critical, p_value, alpha="0.05"): # canvas canv = TCanvas("canv", "canv", 600, 600) canv.SetBottomMargin(0.10) canv.SetLeftMargin(0.15) canv.SetRightMargin(0.12) # histograms hist.SetMarkerColor(0) hist.SetTitle("GOF test - toys {}".format(int(hist.GetEntries()))) hist.GetXaxis().SetTitleFont(43) hist.GetYaxis().SetTitleFont(43) hist.GetXaxis().SetTitleSize(20) hist.GetYaxis().SetTitleSize(20) hist.GetXaxis().SetTitleOffset(0.8) hist.GetYaxis().SetTitleOffset(1.5) hist.GetXaxis().SetTitle("Statistics") hist.GetYaxis().SetTitle("Probability") hist.Draw("hist") up = hist.GetMaximum() hist.GetYaxis().SetRangeUser(0, 1.2 * up) # lines c_line = TLine(critical, 0, critical, 1.2 * up) c_line.SetLineColor(2) c_line.SetLineWidth(4) c_line.SetLineStyle(2) c_line.Draw("L same") obs_line = TLine(obs, 0, obs, 1.2 * up) obs_line.SetLineColor(1) obs_line.SetLineWidth(4) obs_line.Draw("L same") # legend leg = TLegend(0.6, 0.65, .95, .95) leg.SetFillColor(0) leg.SetShadowColor(0) leg.SetLineColor(0) leg.SetTextFont(43) leg.SetTextSize(18) leg.AddEntry(c_line, "alpha = {}".format(alpha), 'L') leg.AddEntry(obs_line, "data (p-value={0:.2f})".format(p_value), 'L') leg.AddEntry(hist, "toys", "L") leg.Draw("same") # save canvas canv.SaveAs("{}.pdf".format(saveout)) canv.SaveAs("{}.png".format(saveout)) canv.SaveAs("{}.root".format(saveout)) return canv
def GetLine(x1,y1,x2,y2,color,style,width, text=''): from ROOT import TLine l = TLine(x1,y1,x2,y2) l.SetNDC(False) l.SetLineColor(color) l.SetLineWidth(width) l.SetLineStyle(style) return l
def col_lin(col, w=4, st=rt.kSolid): #create line of a given color lin = TLine() lin.SetLineColor(col) lin.SetLineWidth(w) lin.SetLineStyle(st) return lin
def draw_line(lineList,x1,x2,y1,y2,width=1,style=1,color=1): from ROOT import TLine l=TLine(x1,y1,x2,y2) l.SetBit(ROOT.kCanDelete) l.SetLineWidth(width) l.SetLineStyle(style) l.SetLineColor(color) l.Draw() lineList.append(l)
def ratioplot(): # create required parts leg = getLegend() latex = getLatex() c = TCanvas() c.SetLogy() #Draw input histograms hists = ['h_frac_recoil_', 'h_full_recoil_'] label = ['recoil with MET triggers', 'recoil without MET triggers'] combineHist(hists, label, leg) #leg.Draw() #c.SaveAs("Combinehists_D.pdf") ratio = [] h1 = f.Get('h_frac_recoil_') #h1=setHistStyle(h1,bins) h2 = f.Get('h_full_recoil_') #h2=setHistStyle(h2,bins) h3 = createRatio(h1, h2) gr = TGraphAsymmErrors(h1, h2) gr.GetXaxis().SetRangeUser(0, 1500) gr.GetYaxis().SetRangeUser(0, 1.2) gr.SetMarkerStyle(20) gr.SetMarkerSize(0.5) gr.SetLineColor(1) gr.GetYaxis().SetTitle("Trigger Efficiency") gr.GetXaxis().SetTitle("Recoil [GeV]") gr.SetTitle("") # print ("ratio",ratio ) # c, pad1, pad2 = createCanvasPads() # # # draw everything # pad1.cd() # h1.Draw() # h2.Draw("same") # to avoid clipping the bottom zero, redraw a small axis # h1.GetYaxis().SetLabelSize(0.0) # axis = TGaxis(-5, 20, -5, 220, 20, 220, 510, "") # axis.SetLabelFont(43) # axis.SetLabelSize(15) # axis.Draw() # pad2.cd() gr.Draw() latex.DrawLatex(0.41, 0.93, "Trigger Efficincy in MET Run2017E") xmin = 0.0 line = TLine(max(xmin, gr.GetXaxis().GetXmin()), 1, 1500, 1) line.SetLineColor(1) line.SetLineWidth(1) line.SetLineStyle(7) line.Draw() #h3.Draw('pl') c.SaveAs("test.pdf")
def makePlot(mds, ds, pdf): """ Mass fit plot """ frame = mds.frame() ds.plotOn(frame, DataError(RooAbsData.SumW2), MarkerSize(1)) pdf.plotOn(frame, LineWidth(2)) # pull histogram pullHist = frame.pullHist() pullFrame = mds.frame(Title('')) pullFrame.addPlotable(pullHist, 'P') pullFrame.GetYaxis().SetRangeUser(-5, 5) canvas = TCanvas('m(Ds)', 'm(Ds)', 600, 700) canvas.cd() pad1 = TPad('pad1', 'pad1', .01, .20, .99, .99) pad2 = TPad('pad2', 'pad2', .01, .01, .99, .20) pad1.Draw() pad2.Draw() pad1.cd() pad1.SetLeftMargin(0.15) pad1.SetFillColor(0) frame.GetXaxis().SetTitleSize(0.05) frame.GetXaxis().SetTitleOffset(0.85) frame.GetXaxis().SetLabelSize(0.04) frame.GetYaxis().SetTitleOffset(1.6) frame.Draw() pad2.cd() pad2.SetLeftMargin(0.15) pad2.SetFillColor(0) pullFrame.SetMarkerSize(0.05) pullFrame.Draw() mdsRange = fitRange()['mDs'] lineUp = TLine(mdsRange[0], 3, mdsRange[1], 3) lineUp.SetLineColor(kBlue) lineUp.SetLineStyle(2) lineUp.Draw() lineCe = TLine(mdsRange[0], 0, mdsRange[1], 0) lineCe.SetLineColor(kBlue) lineCe.SetLineStyle(1) lineCe.SetLineWidth(2) lineCe.Draw() lineD0 = TLine(mdsRange[0], -3, mdsRange[0], -3) lineD0.SetLineColor(kBlue) lineD0.SetLineStyle(2) lineD0.Draw() canvas.Update()
def myMarkerTextSmall2(x, y, lcolor, lstyle, mcolor, mstyle, msize, size, text): l = TLatex() l.SetTextAlign(12) l.SetTextSize(size / 2.5) l.SetNDC() l.DrawLatex(x, y, text) yb1 = y - 0.15 * size yb2 = y + 0.15 * size xb1 = x - 0.28 * size - 0.45 * size xb2 = x + 0.28 * size - 0.45 * size print "box = ", xb1, yb1, xb2, yb2 #print "line = ",xl1,yl1,xl2,yl2 mline1 = TLine(xb1, yb1, xb2, yb2) mline1.SetLineColor(lcolor) mline1.SetLineStyle(lstyle) mline1.SetLineWidth(2) y_new = (yb1 + yb2) / 2. mline1.DrawLineNDC(xb1, y_new, xb2, y_new) mline2 = TLine(xb1, yb1, xb2, yb2) mline2.SetLineColor(lcolor) mline2.SetLineStyle(lstyle) mline2.SetLineWidth(2) x_new = (xb1 + xb2) / 2. mline2.DrawLineNDC(x_new, yb1, x_new, yb2) marker = TMarker((xb1 + xb2) / 2.0, y, mstyle) marker.SetNDC() marker.SetMarkerColor(mcolor) marker.SetMarkerStyle(mstyle) marker.SetMarkerSize(msize) marker.Draw() return marker
def plot_correction( h2, slope, offset, x_points, y_points, error_points, outname, xlabel='', etBinIdx=None, etaBinIdx=None, etBins=None, etaBins=None, label='Internal', ref_value=None, pd_value=None, palette=kBlackBody): def toStrBin(etlist = None, etalist = None, etidx = None, etaidx = None): if etlist and etidx is not None: etlist=copy(etlist) if etlist[-1]>9999: etlist[-1]='#infty' binEt = (str(etlist[etidx]) + ' < E_{T} [GeV] < ' + str(etlist[etidx+1]) if etidx+1 < len(etlist) else 'E_{T} > ' + str(etlist[etidx]) + ' GeV') return binEt if etalist and etaidx is not None: binEta = (str(etalist[etaidx]) + ' < |#eta| < ' + str(etalist[etaidx+1]) if etaidx+1 < len(etalist) else str(etalist[etaidx]) + ' <|#eta| < 2.47') return binEta canvas = TCanvas("canvas","canvas",500,500) rpl.set_figure(canvas) gStyle.SetPalette(palette) canvas.SetRightMargin(0.15) canvas.SetTopMargin(0.15) canvas.SetLogz() h2.GetXaxis().SetTitle('Neural Network output (Discriminant)') h2.GetYaxis().SetTitle(xlabel) h2.GetZaxis().SetTitle('Count') h2.Draw('colz') g = TGraphErrors(len(x_points), array.array('d',x_points), array.array('d',y_points), array.array('d',error_points), array.array('d',[0]*len(x_points))) g.SetMarkerColor(kBlue) g.SetMarkerStyle(8) g.SetMarkerSize(1) g.Draw("P same") line = TLine(slope*h2.GetYaxis().GetXmin()+offset,h2.GetYaxis().GetXmin(), slope*h2.GetYaxis().GetXmax()+offset, h2.GetYaxis().GetXmax()) line.SetLineColor(kBlack) line.SetLineWidth(2) line.Draw() # Add text labels into the canvas text = toStrBin(etlist=etBins, etidx=etBinIdx) text+= ', '+toStrBin(etalist=etaBins, etaidx=etaBinIdx) if ref_value and pd_value: text+=', P_{D} = %1.2f (%1.2f) [%%]'%(pd_value*100, ref_value*100) rpl.add_text(0.15, 0.885, text, textsize=.03) rpl.set_atlas_label(0.15, 0.94, label) rpl.format_canvas_axes(XLabelSize=16, YLabelSize=16, XTitleOffset=0.87, ZLabelSize=16,ZTitleSize=16, YTitleOffset=0.87, ZTitleOffset=1.1) canvas.SaveAs(outname)
def addLine(self, x1, y1, x2, y2, arrow="", arrowsize=0.1): if arrow == "": tl = TLine(x1, y1, x2, y2) elif arrow == "<->": tl = TArrow(x1, y1, x2, y2, arrowsize, "<|>") elif arrow == "->": print x2, y2, arrowsize tl = TArrow(x1, y1, x2, y2, arrowsize, "|>") tl.SetAngle(40) tl.SetLineWidth(1) tl.SetFillColor(1) tl.Draw("same") self.tlines.append(tl) return tl
def BuildTLine(xmin_in, ymin_in, xmax_in, ymax_in, Properties): xmin = Properties.get('xmin_tline', xmin_in) xmax = Properties.get('xmax_tline', xmax_in) ymin = Properties.get('ymin_tline', ymin_in) ymax = Properties.get('ymax_tline', ymax_in) linewidth = Properties.get('lineWidth_tline', 1) linestyle = Properties.get('lineStyle_tline', 1) linecolor = Properties.get('lineColor_tline', 1) line = TLine(xmin, ymin, xmax, ymax) line.SetLineWidth(linewidth) line.SetLineStyle(linestyle) line.SetLineColor(linecolor) return line
def Plot2DHist( th2, slope, offset, x_points, y_points, error_points, outname, xlabel='', etBinIdx=None, etaBinIdx=None, etBins=None,etaBins=None): from ROOT import TCanvas, gStyle, TLegend, kRed, kBlue, kBlack,TLine,kBird, kOrange,kGray from ROOT import TGraphErrors,TF1,TColor import array def AddTopLabels(can, etlist = None, etalist = None, etidx = None, etaidx = None, logger=None): extraText = [GetAtlasInternalText()] if etlist and etidx is not None: etlist=copy(etlist) if etlist[-1]>9999: etlist[-1]='#infty' binEt = (str(etlist[etidx]) + ' < E_{T} [GeV] < ' + str(etlist[etidx+1]) if etidx+1 < len(etlist) else 'E_{T} > ' + str(etlist[etidx]) + ' GeV') extraText.append(binEt) if etalist and etaidx is not None: binEta = (str(etalist[etaidx]) + ' < #eta < ' + str(etalist[etaidx+1]) if etaidx+1 < len(etalist) else str(etalist[etaidx]) + ' < #eta < 2.47') extraText.append(binEta) DrawText(can,extraText,.14,.68,.35,.93,totalentries=4) gStyle.SetPalette(kBird) drawopt='lpE2' canvas = TCanvas('canvas','canvas',500, 500) canvas.SetRightMargin(0.15) th2.GetXaxis().SetTitle('Neural Network output (Discriminant)') th2.GetYaxis().SetTitle(xlabel) th2.GetZaxis().SetTitle('Count') th2.Draw('colz') canvas.SetLogz() g = TGraphErrors(len(x_points), array.array('d',x_points), array.array('d',y_points), array.array('d',error_points), array.array('d',[0]*len(x_points))) g.SetLineWidth(1) g.SetLineColor(kBlue) g.SetMarkerColor(kBlue) g.Draw("P same") line = TLine(slope*th2.GetYaxis().GetXmin()+offset,th2.GetYaxis().GetXmin(), slope*th2.GetYaxis().GetXmax()+offset, th2.GetYaxis().GetXmax()) line.SetLineColor(kBlack) line.SetLineWidth(2) line.Draw() AddTopLabels( canvas, etlist=etBins,etalist=etaBins,etidx=etBinIdx,etaidx=etaBinIdx) FormatCanvasAxes(canvas, XLabelSize=16, YLabelSize=16, XTitleOffset=0.87, ZLabelSize=14,ZTitleSize=14, YTitleOffset=0.87, ZTitleOffset=1.1) SetAxisLabels(canvas,'Neural Network output (Discriminant)',xlabel) canvas.SaveAs(outname+'.pdf') canvas.SaveAs(outname+'.C') return outname+'.pdf'
def plot_phi_vz(canvas, histos, label, save_name): canvas.Clear() # Start by styling the histograms histos['histos_phi_electron_delta_vz'].Draw('colz') line = TLine(-30, 0, 330, 0) line.SetLineColor(1) line.SetLineWidth(1) line.Draw() label.DrawLatex(0.45, 0.02, '#phi_{e}') #label.DrawLatex(0.35, 0.925, 'Elastic Vertex Difference') label.SetTextAngle(90) label.DrawLatex(0.04, 0.35, '#Delta v_{z} = v_{z} (e) - v_{z} (p) (cm)') label.SetTextAngle(0) canvas.Print(save_name)
def myLineText(x, y, lsize, lcolor, lstyle, tsize, text): l = TLatex() l.SetTextAlign(12) l.SetTextSize(tsize) l.SetNDC() l.DrawLatex(x,y,text) y1 = y-0.25*lsize y2 = y+0.25*lsize x2 = x-0.3*lsize x1 = x2-lsize mline = TLine() mline.SetLineWidth(2) mline.SetLineColor(lcolor) mline.SetLineStyle(lstyle) y_new=(y1+y2)/2. mline.DrawLineNDC(x1,y_new,x2,y_new)
def cut_line(cut_val, yl, hx, logy=False): #vertical line representing a cut value if logy == False: tsel_pos = yl * hx.GetMaximum() else: if hx.GetMinimum() > 0.: tsel_pos = TMath.Log10(hx.GetMinimum()) + yl * ( TMath.Log10(hx.GetMaximum()) - TMath.Log10(hx.GetMinimum())) else: tsel_pos = yl * TMath.Log10(hx.GetMaximum()) tsel_pos = TMath.Power(10, tsel_pos) lin = TLine(cut_val, 0., cut_val, tsel_pos) lin.SetLineColor(rt.kViolet) lin.SetLineStyle(rt.kDashed) lin.SetLineWidth(4) return lin
def draw(hist, xtitle, nbins=0): """Draw 1D histogram.""" tsize = 0.045 lines = [] canvas = TCanvas('canvas', 'canvas', 100, 100, 1200, 800) canvas.SetMargin(0.09, 0.02, 0.11, 0.02) # LRBT canvas.SetLogy() hist.SetMaximum(1.8 * hist.GetMaximum()) hist.SetMinimum(2) hist.GetXaxis().SetTitle(xtitle) hist.GetYaxis().SetTitle("Events") hist.GetXaxis().SetTitleSize(tsize) hist.GetYaxis().SetTitleSize(tsize) hist.GetXaxis().SetLabelSize(0.9 * tsize) hist.GetYaxis().SetLabelSize(0.9 * tsize) hist.GetXaxis().SetTitleOffset(1.05) hist.GetYaxis().SetTitleOffset(1.00) #hist.SetMinimum(ymin) #hist.SetMaximum(ymax) hist.SetLineColor(kBlue) hist.SetLineWidth(2) #hist.SetMarkerSize(size) #hist.SetMarkerColor(color) #hist.SetMarkerStyle(8) hist.Draw('HIST') if nbins > 0: # divide with nlines xmin, xmax = hist.GetXaxis().GetXmin(), hist.GetXaxis().GetXmax() ymin, ymax = hist.GetMinimum(), hist.GetMaximum() for i in range(1, nbins): x = xmin + (xmax - xmin) * i / nbins line = TLine(x, ymin, x, ymax) line.SetLineColor(kRed) line.SetLineStyle(kDashed) line.SetLineWidth(1) line.Draw() lines.append(line) canvas.SaveAs(hist.GetName() + ".png") #canvas.SaveAs(hist.GetName()+".pdf") canvas.Close()
def myBoxText(x,y,boxsize,mcolor,text): tsize=0.06; l=TLatex(); l.SetTextAlign(12); l.SetNDC(); l.DrawLatex(x,y,text); y1=y-0.25*tsize; y2=y+0.25*tsize; x2=x-0.3*tsize; x1=x2-boxsize; mbox= TPave(x1,y1,x2,y2,0,"NDC"); mbox.SetFillColor(mcolor); mbox.SetFillStyle(1001); mbox.Draw(); mline=TLine() mline.SetLineWidth(4) mline.SetLineColor(1) mline.SetLineStyle(1) y=(y1+y2)/2. mline.DrawLineNDC(x1,y,x2,y)
def plotDeltaPhiVsL1Phi(self): canvas = TCanvas('cDeltaPhiVsL1Phi', 'DeltaPhiVsL1Phi', 1200, 1200) hist = self.fileHandler.getHistogram( 'correlation/shiftCheckDeltaPhiVsPhi') hist.GetYaxis().SetRangeUser(-1, 1) hist.GetXaxis().SetRangeUser(-.5, .5) hist.GetXaxis().SetTitle('L1 #phi') hist.GetZaxis().SetTitle('#') hist.SetStats(0) hist.SetTitle('#Delta#phi vs. L1#phi') setupAxes(hist) hist.Draw('colz') phiBorderLines = [] HO_BIN = math.pi / 36. for i in range(-31, 32): line = TLine(HO_BIN * i - HO_BIN / 2., -.6, HO_BIN * i - HO_BIN / 2., .6) line.SetLineWidth(2) # line.Draw() phiBorderLines.append(line) legend = TLegend(0.6, 0.8, 0.9, 0.85) legend.AddEntry(phiBorderLines[0], "HO Tile center", "e") #legend.Draw() label = self.drawLabel() canvas.Update() setupPalette(hist) canvas.Update() canvas.SaveAs('plots/deltaPhiVsL1Phi.pdf') return canvas, hist, label, phiBorderLines, legend