def drawTopoGeometry(geometry, is2016): outfn = "TopoLayout%s.pdf" % ("2016" if is2016 else "2015") global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950) c.Draw() h = TH2F("h", "Muon Topo Geometry %s" % "2016" if is2016 else "2015", 10, -2.6, 2.6, 10, -0.15, 6.4) h.SetXTitle("#eta") h.SetYTitle("#phi") h.Draw() box = TBox() box.SetFillStyle(0) box.SetLineColor(3) circle = TArc() for colorIndex, MioctID in enumerate(drawOrder): MIOCT = geometry.getMIOCT(MioctID) color = colorMap[colorIndex % len(colorMap)] box.SetLineColor(color) box.SetFillColor(color) circle.SetLineColor(color) circle.SetFillColor(color) fillStyle = 3004 for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells): # corner 1 c1_x = float(TopoCell["etamin"]) c1_y = float(TopoCell["phimin"]) # corner 2 c2_x = float(TopoCell["etamax"]) c2_y = float(TopoCell["phimax"]) # center rounded c_x = float(TopoCell["ieta"]) c_y = float(TopoCell["iphi"]) #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y) if fillStyle == 3004: fillStyle = 3012 else: fillStyle = 3004 box.SetFillStyle(fillStyle) box.DrawBox(c1_x, c1_y, c2_x, c2_y) box.SetFillStyle(0) box.DrawBox(c1_x, c1_y, c2_x, c2_y) circle.DrawArc(c_x / 10., c_y / 10., 0.02) c.Update() c.SaveAs(outfn)
def drawFilledBox(ieta, iphi, canvas): canvas.cd() box = TBox(ieta - 0.5, iphi - 0.5, ieta + 0.5, iphi + 0.5) box.SetLineColor(ROOT.kBlack) box.SetFillStyle(3013) box.SetFillColor(ROOT.kBlack) box.Draw() return box
def draw(plot, channel='MuMu', plotprefix=None, SetLogy=0): # print plot Stack.STAT_ERRORS = True blindxmin = None blindxmax = None titles = xtitles if channel == 'TauEle': titles = xtitles_TauEle xtitle = titles.get(plot.varName, None) if xtitle is None: xtitle = '' global can, pad, padr, ratio if pad is None: can, pad, padr = buildCanvas() pad.cd() pad.SetLogy(SetLogy) plot.DrawStack('HIST') h = plot.supportHist h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) gevperbin = h.GetXaxis().GetBinWidth(1) h.GetYaxis().SetTitle('Events') h.GetYaxis().SetTitleOffset(1.4) padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = False ratio.DrawRatioStack('HIST', ymin=0.4, ymax=1.6) hr = ratio.stack.totalHist # hr.weighted.Fit('pol1') hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitle('Exp./Obs.') hr.GetYaxis().SetTitleSize(0.1) hr.GetYaxis().SetTitleOffset(0.5) hr.GetXaxis().SetTitle('{xtitle}'.format(xtitle=xtitle)) hr.GetXaxis().SetTitleSize(0.13) hr.GetXaxis().SetTitleOffset(0.9) rls = 0.075 hr.GetYaxis().SetLabelSize(rls) hr.GetXaxis().SetLabelSize(rls) hr.GetYaxis().SetRangeUser(0.5, 1.5) padr.Update() # blinding if plot.blindminx: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(plot.blindminx, 0, plot.blindmaxx, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() # import pdb; pdb.set_trace() keeper.append(box) print channel if channel == 'MuMu': CMSPrelim(plot, pad, '#mu#mu') can.cd() if plotprefix == None: plotname = plot.varName else: plotname = plotprefix + '_' + plot.varName can.SaveAs(plotname + '.png') pad.SetLogy(0)
def drawBox(x1, y1, x2, y2, t=""): box = TBox(x1, y1, x2, y2) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() if not t == "": text = TLatex() text.SetTextColor(1) text.SetTextFont(42) text.SetTextAlign(23) text.SetTextSize(0.04) text.DrawLatex((x1 + x2) / 2., y2 / 1.15, t) text.Draw() return box
def drawOfficial(plot, doBlind=False, channel='TauMu', plotprefix = None, ymin = 0.1): global ocan print plot Stack.STAT_ERRORS = False blindxmin = None blindxmax = None doBlind = (plot.varName == 'svfitMass') and doBlind if doBlind: blindxmin = 100 blindxmax = 160 plot.Blind(blindxmin, blindxmax, False) titles = xtitles if channel=='TauEle': titles = xtitles_TauEle xtitle = titles.get( plot.varName, None ) if xtitle is None: xtitle = '' global ocan if ocan is None: ocan = buildCanvasOfficial() ocan.cd() plot.DrawStack('HIST', ymin=ymin) h = plot.supportHist h.GetXaxis().SetTitle('{xtitle}'.format(xtitle=xtitle)) # blinding if plot.blindminx: ocan.cd() max = plot.stack.totalHist.GetMaximum() box = TBox( plot.blindminx, 0, plot.blindmaxx, max ) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() # import pdb; pdb.set_trace() keeper.append(box) year, lumi, energy = datasetInfo( plot ) datasetStr = "CMS Preliminary, #sqrt{{s}} = {energy} TeV, L = {lumi:3.2f} fb^{{-1}}".format(energy=energy, lumi=lumi) if channel == 'TauMu' : a,b = CMSPrelimOfficial( datasetStr, '#tau_{#mu}#tau_{h}',0.15,0.835) elif channel == 'TauEle' : a,b = CMSPrelimOfficial( datasetStr, '#tau_{e}#tau_{h}', 0.15, 0.835) a.Draw() b.Draw() save.extend([a,b]) ocan.Modified() ocan.Update() ocan.cd() if plotprefix == None : plotname = plot.varName else : plotname = plotprefix + '_' + plot.varName ocan.SaveAs( plotname + '.png') ocan.SetLogy() ocan.SaveAs( plotname + '_log.png') ocan.SetLogy(0)
var.setConstant(True) model.fitTo(dataset) nll_profscan.SetBinContent(binIdx,(nll.getVal()-fitres.minNll())*2.) mesg='nll: {0}, minNLL= {1}'.format(nll.getVal(),fitres.minNll()) recTime(mesg) var.setConstant(False) nll_scan.SetStats(False) nll_scan.SetLineWidth(2) nll_scan.GetXaxis().SetTitle(varInfo['var']) nll_profscan.Draw('axis') canv.Update() box=TBox() box.SetFillColor(7) bestVal=fitres.floatParsFinal().find(varInfo['var']) box.DrawBox( bestVal.getVal()+bestVal.getErrorLo(),canv.GetUymin(), bestVal.getVal()+bestVal.getErrorHi(),canv.GetUymax() ) nll_scan.Draw('csame') nll_profscan.SetLineWidth(2) nll_profscan.SetLineColor(2) nll_profscan.Draw('csame') outFile.cd() nll_scan.Write() nll_profscan.Write() canv.SaveAs(tMPfIG)
RM = Xa*(rm/(lm+rm)) BM = Ya*(bm/(bm+to)) TM = Ya*(to/(bm+to)) null = TPad("null","",0,0,1,1) null.SetFillStyle(0) null.SetFrameFillStyle(0) null.Draw() null.cd() null.Range(x1-LM,yf-BM,x2+RM,y2+TM) tri=TPolyLine(3,xx,yy) tri.SetFillColor(0) box1=TBox(-0.2,-0.2,1.05,0) box2=TBox(-0.2,-0.2,0,1.05) box1.SetFillColor(0) box2.SetFillColor(0) #p.Draw('atext') tri.Draw('f') box1.Draw('f') box2.Draw('f') tri.Draw('f') if tipo in ['obs','exp']: bm = c.GetBottomMargin() lm = c.GetLeftMargin() rm = c.GetRightMargin() to = c.GetTopMargin() x1 = p.GetXaxis().GetXmin() yf = p.GetYaxis().GetXmin() x2 = p.GetXaxis().GetXmax()
def drawColorTable(clist=range(0, 50), nrow=None, ncol=None, cmax=10, tag="", label=False, RBG=False, newRBG=True, div=2): # https://root.cern.ch/doc/master/src_2TPad_8cxx_source.html#l01611 if not ncol: ncol = min(cmax, len(clist)) if not nrow: nrow = 1 if len(clist) <= cmax else int(ceil(len(clist) / float(cmax))) x1 = y1 = 0. x2 = y2 = 20. hs = (y2 - y1) / nrow ws = (x2 - x1) / ncol if label or RBG: width = 170 * ncol height = 80 * nrow else: width = 110 * ncol height = 80 * nrow scale = 400. / height if 400. < height: scale = sqrt(scale) canvas = TCanvas("c", "Fill Area colors", 0, 0, width, height) canvas.SetFillColor(0) canvas.Clear() canvas.Range(x1, y1, x2, y2) text = TText(0, 0, "") text.SetTextFont(61) text.SetTextSize(0.07 * scale) text.SetTextAlign(22) box = TBox() for r in range(0, nrow): ylow = y2 - hs * (r + 0.1) yup = y2 - hs * (r + 0.9) for c in range(0, ncol): i = ncol * r + c if i >= len(clist): break xlow = x1 + ws * (c + 0.1) xup = x1 + ws * (c + 0.9) color = clist[ncol * r + c] box.SetFillStyle(1001) box.SetFillColor(color) box.DrawBox(xlow, ylow, xup, yup) box.SetFillStyle(0) box.SetLineColor(1) box.DrawBox(xlow, ylow, xup, yup) if color == 1: text.SetTextColor(0) else: text.SetTextColor(1) name = "%d" % color if (isinstance(label, int) and i % div == label) or label: name = getColorString(color) if (not isinstance(RBG, bool) and isinstance(RBG, int) and i % div == RBG) or (RBG and not isinstance(label, int)): name = getRGBString(color) elif newRBG and color >= 924: name = getRGBString(color) text.DrawText(0.5 * (xlow + xup), 0.5 * (ylow + yup), name) if i >= len(clist): break canvas.SaveAs("TColorTable%s.png" % tag) canvas.SaveAs("TColorTable%s.pdf" % tag)
nmeModel, ga) / CLHEP.year ihMinTHalf_y = SensClass.GetTHalf(ihMaxMbb_meV * CLHEP.meV, isotope, nmeModel, ga) / CLHEP.year ihMaxTHalf_y = SensClass.GetTHalf(ihMinMbb_meV * CLHEP.meV, isotope, nmeModel, ga) / CLHEP.year ihMaxMaxTHalf_y = SensClass.GetTHalf(ihMinMinMbb_meV * CLHEP.meV, isotope, nmeModel, ga) / CLHEP.year bInvHierOut = TBox(expMin_ty, ihMinMinTHalf_y, 0.98 * expMax_ty, ihMaxMaxTHalf_y) bInvHierIn = TBox(expMin_ty, ihMinTHalf_y, 0.98 * expMax_ty, ihMaxTHalf_y) if options.useShellModel: ihText += "(SM" else: ihText += "(QRPA" ihText += ", g_{A}=" + str(ga) + ")" lInvHier = TLatex(2. * expMin_ty, math.sqrt(ihMinTHalf_y * ihMaxTHalf_y), ihText) bInvHierOut.SetFillColor(TColor.GetColor(0.8, 1.0, 0.8)) bInvHierOut.Draw() bInvHierIn.SetFillColor(TColor.GetColor(0.7, 0.95, 0.7)) bInvHierIn.Draw() lInvHier.SetTextAlign(12) lInvHier.SetTextColor(TColor.GetColor(0.1, 0.4, 0.1)) lInvHier.SetTextSize(0.04) lInvHier.Draw() if drawKKDC: hvkkTHalfLo_y = (2.23 - 3. * 0.31) * 1e25 hvkkTHalfHi_y = (2.23 + 3. * 0.44) * 1e25 hvkkMbbLo_meV = SensClass.GetMbb(hvkkTHalfHi_y * CLHEP.year, isotope, nmeModel, ga) / (1.e-3 * CLHEP.eV) hvkkMbbHi_meV = SensClass.GetMbb(hvkkTHalfLo_y * CLHEP.year, isotope, nmeModel, ga) / (1.e-3 * CLHEP.eV)
def draw(plot, do_ratio=True, channel='e#mu#mu', plot_dir='/plots/', plot_name=None, SetLogy=0, blindxmin=None, blindxmax=None, unit=None): print plot Stack.STAT_ERRORS = True can = pad = padr = None if do_ratio: can, pad, padr = HistDrawer.buildCanvas() else: can = HistDrawer.buildCanvasSingle() pad.cd() pad.SetLogy(SetLogy) plot.DrawStack('HIST', print_norm=plot.name == '_norm_', ymin=0.1) # magic word to print integrals in legend h = plot.supportHist h.GetXaxis().SetLabelColor(1) # h.GetXaxis().SetLabelSize(1) unitsperbin = h.GetXaxis().GetBinWidth(1) ytitle = 'Events' if unit: round_to_n = lambda x, n: round( x, -int(floor(log10(abs(x)))) + (n - 1)) ytitle += round_to_n(unitsperbin, 3) h.GetYaxis().SetTitle('Events') h.GetYaxis().SetTitleOffset(1.0) h.GetXaxis().SetTitleOffset(2.0) if do_ratio: padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = False if blindxmin or blindxmax: if not blindxmin: blindxmin = 0 if not blindxmax: blindxmax = plot.stack.totalHist.GetXaxis().GetXmax() if do_ratio: ratio.Blind(blindxmin, blindxmax, True) plot.Blind(blindxmin, blindxmax, False) if do_ratio: ratio.DrawDataOverMCMinus1(-0.5, 0.5) hr = ratio.dataOverMCHist # Gymnastics to get same label sizes etc in ratio and main plot ytp_ratio = 2. xtp_ratio = 2. # hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitleSize(h.GetYaxis().GetTitleSize() * xtp_ratio) hr.GetXaxis().SetTitleSize(h.GetXaxis().GetTitleSize() * ytp_ratio) hr.GetYaxis().SetTitleOffset(h.GetYaxis().GetTitleOffset() / xtp_ratio) hr.GetXaxis().SetTitleOffset(h.GetXaxis().GetTitleOffset() / ytp_ratio) hr.GetYaxis().SetLabelSize(h.GetYaxis().GetLabelSize() * xtp_ratio) hr.GetXaxis().SetLabelSize(h.GetXaxis().GetLabelSize() * ytp_ratio) h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) padr.Update() # blinding if blindxmin or blindxmax: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(blindxmin, 0, blindxmax, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() HistDrawer.keeper.append(box) HistDrawer.CMSPrelim(plot, pad, channel, legend=plot.legendPos) can.cd() plotname = plot_dir + '/' ensureDir(plot_dir) plotname += plot_name if plot_name else plot.name can.SaveAs(plotname + '.png') can.SaveAs(plotname + '.pdf') can.SaveAs(plotname + '.root') # Also save with log y h.GetYaxis().SetRangeUser(pad.GetUymax() * 5. / 1000000., pad.GetUymax() * 5.) pad.SetLogy(True) can.SaveAs(plotname + '_log.png') can.SaveAs(plotname + '_log.pdf') pad.SetLogy(0)
def oneDim_matching(blinded): c1 = Canvas("c1") c2 = Canvas("c2") h_mass = ROOT.TH1F('h_mass', '', 40, -20, 20) h_rap = ROOT.TH1F('h_rap', '', 40, -20, 20) x, y = ROOT.Double(0), ROOT.Double(0) for i, year in enumerate(years): g = getGraph(year) for j in range(g.GetN()): g.GetPoint(j,x,y) ex = g.GetErrorX(j) ey = g.GetErrorY(j) h_mass.Fill(x) h_rap.Fill(y) c1.cd() c1.SetTicks(1,1) h_mass.GetXaxis().SetTitle('(m_{pp}-m_{#gamma#gamma})/#sigma(m_{pp}-m_{#gamma#gamma}}') h_mass.GetYaxis().SetTitle('Events') h_mass.SetMarkerStyle(24) h_mass.SetLineColor( ROOT.kBlack ) h_mass.Sumw2() min, max = h_mass.GetMinimum(), h_mass.GetMaximum()+3 h_mass.SetMaximum(max) h_mass.Draw('p') ''' l1 = TLine(-2,h_mass.GetMinimum(),-2,max) l1.SetLineColor( ROOT.kRed+1 ) l1.SetLineStyle(2) l1.SetLineWidth(2) l2 = TLine(2,h_mass.GetMinimum(),2,max) l2.SetLineColor( ROOT.kRed+1 ) l2.SetLineStyle(2) l2.SetLineWidth(2) l3 = TLine(-3,h_mass.GetMinimum(),-3,max) l3.SetLineColor( ROOT.kRed+1 ) l3.SetLineStyle(1) l3.SetLineWidth(2) l4 = TLine(3,h_mass.GetMinimum(),3,max) l4.SetLineColor( ROOT.kRed+1 ) l4.SetLineStyle(1) l4.SetLineWidth(2) ''' b2 = TBox(-3, min, 3, max-0.05) if not blinded: b2.SetFillStyle(3001) # transparent b2.SetFillColor(5) b2.SetLineColor(1) b2.Draw() b1 = TBox(-2, min, 2, max-0.05) if not blinded: b1.SetFillStyle(3001) # transparent b1.SetFillColor(3) b1.SetLineColor(1) b1.Draw() pLabel, sLabel, lLabel = prelimLabel(), selectionLabel("#xi^{#pm}_{#gamma#gamma} #in PPS"), lumiLabel() pLabel.Draw(), sLabel.Draw(), lLabel.Draw() legend = TLegend(0.7,0.8,0.9,0.9) legend.AddEntry(b1,"2#sigma matching",'f') legend.AddEntry(b2,"3#sigma matching",'f') legend.Draw() c1.SaveAs('plots/matching/h_mass_1d.%s' % extension) c2.cd() c2.SetTicks(1,1) h_rap.GetXaxis().SetTitle('(y_{pp}-y_{#gamma#gamma})/#sigma(y_{pp}-y_{#gamma#gamma}}') h_rap.GetYaxis().SetTitle('Events') h_rap.SetMarkerStyle(24) h_rap.SetLineColor( ROOT.kBlack ) h_rap.Sumw2() h_rap.SetMaximum(max) h_rap.Draw('p') b2.Draw() b1.Draw() pLabel, sLabel, lLabel = prelimLabel(), selectionLabel("#xi^{#pm}_{#gamma#gamma} #in PPS"), lumiLabel() pLabel.Draw(), sLabel.Draw(), lLabel.Draw() legend = TLegend(0.7,0.8,0.9,0.9) legend.AddEntry(b1,"2#sigma matching",'f') legend.AddEntry(b2,"3#sigma matching",'f') legend.Draw() c2.SaveAs('plots/matching/h_rap_1d.%s' % extension)
def draw(plot, do_ratio=True, channel='e#mu#mu', plot_dir='/plots/', plot_name=None, SetLogy=0, blindxmin=None, blindxmax=None, unit=None, server='starseeker', region='DY', channel_dir='mmm', dataset='2017'): print(plot) Stack.STAT_ERRORS = True can = pad = padr = None if do_ratio: can, pad, padr = HistDrawer.buildCanvas() pad.cd() pad.SetLogy(SetLogy) else: can = HistDrawer.buildCanvasSingle() pad = can pad.cd() pad.SetLogy(SetLogy) # plot.DrawStack('HIST', print_norm=plot.name=='_norm_', ymin=0.1) # magic word to print integrals in legend plot.DrawStack('HIST', print_norm=('_norm_' in plot.name), ymin=0.1) # magic word to print integrals in legend h = plot.supportHist h.GetXaxis().SetLabelColor(1) # h.GetXaxis().SetLabelSize(1) unitsperbin = h.GetXaxis().GetBinWidth(1) ytitle = 'Events' if unit: round_to_n = lambda x, n: round( x, -int(floor(log10(abs(x)))) + (n - 1)) ytitle += round_to_n(unitsperbin, 3) h.GetYaxis().SetTitle('Events') h.GetYaxis().SetTitleOffset(1.4) h.GetXaxis().SetTitleOffset(2.0) if do_ratio: padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = True ratio.STAT_ERRORS = True if blindxmin or blindxmax: if not blindxmin: blindxmin = 0 if not blindxmax: blindxmax = plot.stack.totalHist.GetXaxis().GetXmax() if do_ratio: ratio.Blind(blindxmin, blindxmax, True) plot.Blind(blindxmin, blindxmax, False) if do_ratio: # ratio.DrawDataOverMCMinus1(-0.5, 0.5) ratio.DrawDataOverMCMinus1(-0.9, 0.9) hr = ratio.dataOverMCHist # Gymnastics to get same label sizes etc in ratio and main plot ytp_ratio = 2. xtp_ratio = 2. # hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitleSize(h.GetYaxis().GetTitleSize() * xtp_ratio) hr.GetXaxis().SetTitleSize(h.GetXaxis().GetTitleSize() * ytp_ratio) hr.GetYaxis().SetTitleOffset(h.GetYaxis().GetTitleOffset() / xtp_ratio) hr.GetXaxis().SetTitleOffset(h.GetXaxis().GetTitleOffset() / ytp_ratio) hr.GetYaxis().SetLabelSize(h.GetYaxis().GetLabelSize() * xtp_ratio) hr.GetXaxis().SetLabelSize(h.GetXaxis().GetLabelSize() * ytp_ratio) h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) padr.Update() # blinding if blindxmin or blindxmax: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(blindxmin, 0, blindxmax, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() HistDrawer.keeper.append(box) HistDrawer.CMSPrelim(plot, pad, channel, legend=plot.legendPos) can.cd() gErrorIgnoreLevel = kWarning h.GetYaxis().SetRangeUser(0, pad.GetUymax() * 1.) plotname = plot_name if plot_name else plot.name if ('dz' in plotname) or ('logx' in plotname): pad.SetLogx(True) try: padr.SetLogx(True) except: pass if not os.path.exists(plot_dir + '/pdf/'): os.mkdir(plot_dir + '/pdf/') os.mkdir(plot_dir + '/pdf/linear/') os.mkdir(plot_dir + '/pdf/log/') if not os.path.exists(plot_dir + '/root/'): os.mkdir(plot_dir + '/root/') os.mkdir(plot_dir + '/root/linear/') os.mkdir(plot_dir + '/root/log') if not os.path.exists(plot_dir + '/png/'): os.mkdir(plot_dir + '/png/') os.mkdir(plot_dir + '/png/linear/') os.mkdir(plot_dir + '/png/log/') if not os.path.exists(plot_dir + '/datacards/'): os.mkdir(plot_dir + '/datacards/') can.SaveAs(plot_dir + '/pdf/linear/' + plotname + '.pdf') can.SaveAs(plot_dir + '/root/linear/' + plotname + '.root') can.SaveAs(plot_dir + '/png/linear/' + plotname + '.png') if server == "starseeker": if dataset == '2017': t3_dir = '/home/dehuazhu/t3work/3_figures/1_DataMC/FinalStates/' + channel_dir + '/' + region.name if dataset == '2018': t3_dir = '/home/dehuazhu/t3work/3_figures/1_DataMC/FinalStates/2018/' + channel_dir + '/' + region.name can.SaveAs(t3_dir + '/pdf/linear/' + plotname + '.pdf') can.SaveAs(t3_dir + '/root/linear/' + plotname + '.root') can.SaveAs(t3_dir + '/png/linear/' + plotname + '.png') # Also save with log y h.GetYaxis().SetRangeUser(pad.GetUymax() * 5. / 1000000., pad.GetUymax() * 1000.) pad.SetLogy(True) can.SaveAs(plot_dir + '/png/log/' + plotname + '_log.png') can.SaveAs(plot_dir + '/root/log/' + plotname + '_log.root') can.SaveAs(plot_dir + '/pdf/log/' + plotname + '_log.pdf') if server == "starseeker": can.SaveAs(t3_dir + '/pdf/log/' + plotname + '_log.pdf') can.SaveAs(t3_dir + '/root/log/' + plotname + '_log.root') can.SaveAs(t3_dir + '/png/log/' + plotname + '_log.png') pad.SetLogy(0) # if 'dz' in plotname: if ('dz' in plotname) or ('logx' in plotname): pad.SetLogx(False) try: padr.SetLogx(False) except: pass
def pullsVertical(fileName): content = filterPullFile(fileName) nbins, off = len(content), 0.10 b_pulls = TH1F("b_pulls", ";;Pulls", nbins, 0. - off, nbins - off) s_pulls = TH1F("s_pulls", ";;Pulls", nbins, 0. + off, nbins + off) # for i, s in enumerate(content): l = s.split() b_pulls.GetXaxis().SetBinLabel(i + 1, l[0]) s_pulls.GetXaxis().SetBinLabel(i + 1, l[0]) b_pulls.SetBinContent(i + 1, float(l[1])) b_pulls.SetBinError(i + 1, float(l[2])) s_pulls.SetBinContent(i + 1, float(l[3])) s_pulls.SetBinError(i + 1, float(l[4])) b_pulls.SetFillStyle(3005) b_pulls.SetFillColor(923) b_pulls.SetLineColor(923) b_pulls.SetLineWidth(1) b_pulls.SetMarkerStyle(20) b_pulls.SetMarkerSize(1.25) s_pulls.SetLineColor(602) s_pulls.SetMarkerColor(602) s_pulls.SetMarkerStyle(24) #24 s_pulls.SetLineWidth(1) b_pulls.GetYaxis().SetRangeUser(-2.5, 2.5) # Graphs h_pulls = TH2F("pulls", "", 6, -3., 3., nbins, 0, nbins) B_pulls = TGraphAsymmErrors(nbins) S_pulls = TGraphAsymmErrors(nbins) boxes = [] canvas = TCanvas("canvas", "Pulls", 600, 150 + nbins * 10) #nbins*20) canvas.cd() canvas.SetGrid(0, 1) canvas.GetPad(0).SetTopMargin(0.01) canvas.GetPad(0).SetRightMargin(0.01) canvas.GetPad(0).SetBottomMargin(0.05) canvas.GetPad(0).SetLeftMargin(0.25) #(0.25)#(0.065) canvas.GetPad(0).SetTicks(1, 1) for i, s in enumerate(content): l = s.split() if "1034h" in l[0]: l[0] = "CMS_PDF_13TeV" h_pulls.GetYaxis().SetBinLabel(i + 1, l[0].replace('CMS2016_', '')) #C #y1 = gStyle.GetPadBottomMargin() #y2 = 1. - gStyle.GetPadTopMargin() #h = (y2 - y1) / float(nbins) #y1 = y1 + float(i) * h #y2 = y1 + h #box = TPaveText(0, y1, 1, y2, 'NDC') #box.SetFillColor(0) #box.SetTextSize(0.02) #box.SetBorderSize(0) #box.SetTextAlign(12) #box.SetMargin(0.005) #if i % 2 == 0: # box.SetFillColor(18) #box.Draw() #boxes.append(box) B_pulls.SetPoint(i + 1, float(l[1]), float(i + 1) - 0.3) #C B_pulls.SetPointError(i + 1, float(l[2]), float(l[2]), 0., 0.) #C for i, s in enumerate(content): l = s.split() S_pulls.SetPoint(i + 1, float(l[3]), float(i + 1) - 0.7) #C S_pulls.SetPointError(i + 1, float(l[4]), float(l[4]), 0., 0.) #C h_pulls.GetXaxis().SetTitle("(#hat{#theta} - #theta_{0}) / #Delta#theta") h_pulls.GetXaxis().SetLabelOffset(-0.01) h_pulls.GetXaxis().SetTitleOffset(.6) h_pulls.GetYaxis().SetNdivisions(nbins, 0, 0) B_pulls.SetFillColor(1) B_pulls.SetLineColor(1) B_pulls.SetLineStyle(1) B_pulls.SetLineWidth(2) B_pulls.SetMarkerColor(1) B_pulls.SetMarkerStyle(20) B_pulls.SetMarkerSize(1) #(0.75) S_pulls.SetFillColor(629) S_pulls.SetLineColor(629) S_pulls.SetMarkerColor(629) S_pulls.SetLineWidth(2) S_pulls.SetMarkerStyle(20) S_pulls.SetMarkerSize(1) box1 = TBox(-1., 0., 1., nbins) box1.SetFillStyle(3001) #box1.SetFillStyle(0) box1.SetFillColor(417) box1.SetLineWidth(2) box1.SetLineStyle(2) box1.SetLineColor(417) box2 = TBox(-2., 0., 2., nbins) box2.SetFillStyle(3001) #box2.SetFillStyle(0) box2.SetFillColor(800) box2.SetLineWidth(2) box2.SetLineStyle(2) box2.SetLineColor(800) leg = TLegend(0.1, -0.05, 0.7, 0.08) leg.SetBorderSize(0) leg.SetFillStyle(0) leg.SetFillColor(0) leg.SetNColumns(2) leg.AddEntry(B_pulls, "B-only fit", "lp") leg.AddEntry(S_pulls, "S+B fit", "lp") if text: leg.AddEntry(0, text, "") h_pulls.Draw("") box2.Draw() box1.Draw() B_pulls.Draw("P6SAME") S_pulls.Draw("P6SAME") leg.Draw() # drawCMS(35867, "Preliminary") # drawAnalysis("VH") # drawRegion(outName) canvas.Print(outName + ".png") canvas.Print(outName + ".pdf") if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
pull1.Draw('ap') pull1.SetName(vName1 + "_pull") cp1.SetGridy() cp1.Update() pull1.GetXaxis().SetLimits(pars.varRanges[pars.var[0]][1], pars.varRanges[pars.var[0]][2]) pull1.GetXaxis().SetTitle(fitter.ws.var(vName1).getTitle(True).Data()) pull1.GetYaxis().SetTitle("pull (#sigma)") blinder = plot1.findObject('TBox') blinder2 = None if blinder: blinder2 = TBox(pars.exclude[pars.var[0]][0], pull1.GetYaxis().GetXmin(), pars.exclude[pars.var[0]][1], pull1.GetYaxis().GetXmax()) blinder2.SetFillColor(kBlack) blinder2.SetFillStyle(1001) if blinder2: #blinder2.Print() blinder2.Draw() cp1.Update() if opts.toyOut: outFile = open(opts.toyOut, 'a', 1) fitter.ws.loadSnapshot("genPars") line = '%s %.6g %.6g %.6g ' outFile.write('nll %f covQual %i edm %.4g ' % (fr.minNll(), fr.covQual(), fr.edm()))
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',22,-10.5,11.5,22,-10.5,11.5) hi=TH2I('hi',';X;Y',22,-10.5,11.5,22,-10.5,11.5) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC') ttM=TPaveText(-3+0.05, 7-4.45, 4.0, 8-4.51) tt2=TPaveText(-3+0.05, 7-5.45, 4.0, 8-5.51) ttX=TPaveText(-2, 7-8.00, 3, 8-8.00) ttY=TPaveText(-2, 7-9.00, 3, 8-9.00) ttZ=TPaveText(-2, 6-8.80, 3, 8-9.30) ttZ.AddText("positive = beam top/right") ttime=TPaveText(-10,-12.5,10,-11.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt2,ttM,ttime,tchan,ttX,ttY,ttZ]) ttM.SetTextColor(2) ttM.SetFillStyle(0) ttZ.SetFillStyle(0) tt2.SetFillStyle(0) tarrow=TText(-0.9,0.7,'Beam Right') tarrow.SetTextSizePixels(15) arrow=TArrow(-1.4,0.5,2.4,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(12.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.3,0.92,'FTC FADC SCALERS') bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-3.47,-1.47,4.47,2.46) bb.DrawBox(-1.47,-3.47,2.49,4.47) bb.DrawBox(-2.47,-2.47,3.49,3.47) cc.cd() for xx in [ttM,tt2,ttime,arrow,tarrow,ttX,ttY,ttZ]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() gPad.SetEditable(0) while True: for ch in ECAL.chans: loadPV(ch) ch=ch.vals xx,yy=ch['X'],ch['Y'] #if (ch['PVVAL']>10): # print xx,yy,ch['PVVAL'] # swap x to make it downstream view: xx=-xx #after, fix the fact x=0 / y=0 don't exists if xx<0: xx+=1 if yy<0: yy+=1 hh.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) hi.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) for xx in [ttime,tt2,ttM,ttX,ttY]: xx.Clear() [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans) tt2.AddText('Total: %.1f MHz'%(total/1000)) ttM.AddText('Max: %.0f kHz'%(maximum)) if total>1e2: xasy = (right-left)/total yasy = (top-bottom)/total ttX.AddText('X-Asy: %+.1f%%'%(100*xasy)) ttY.AddText('Y-Asy: %+.1f%%'%(100*yasy)) else: ttX.AddText('X-Asy: N/A') ttY.AddText('Y-Asy: N/A') ttime.AddText(makeTime()) if not gPad: sys.exit() if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(2)
def stackedPlot(self, var, logy = False, pdfName = None, Silent = False): if not pdfName: pdfName = 'total' xvar = self.ws.var(var) nbins = xvar.getBins() if hasattr(self.pars, 'plotRanges'): xvar.setRange('plotRange', self.pars.plotRanges[var][1], self.pars.plotRanges[var][2]) xvar.setBins(self.pars.plotRanges[var][0], 'plotBins') else: xvar.setRange('plotRange', xvar.getMin(), xvar.getMax()) xvar.setBins(nbins, 'plotBins') sframe = xvar.frame() sframe.SetName("%s_stacked" % var) pdf = self.ws.pdf(pdfName) if isinstance(pdf, RooAddPdf): compList = RooArgList(pdf.pdfList()) else: compList = None data = self.ws.data('data_obs') nexp = pdf.expectedEvents(self.ws.set('obsSet')) if not Silent: print pdf.GetName(),'expected: %.0f' % (nexp) print 'data events: %.0f' % (data.sumEntries()) if nexp < 1: nexp = data.sumEntries() theComponents = [] if self.pars.includeSignal: theComponents += self.pars.signals theComponents += self.pars.backgrounds data.plotOn(sframe, RooFit.Invisible(), RooFit.Binning('plotBins')) # dataHist = RooAbsData.createHistogram(data,'dataHist_%s' % var, xvar, # RooFit.Binning('%sBinning' % var)) # #dataHist.Scale(1., 'width') # invData = RooHist(dataHist, 1., 1, RooAbsData.SumW2, 1.0, False) # #invData.Print('v') # sframe.addPlotable(invData, 'pe', True, True) for (idx,component) in enumerate(theComponents): if not Silent: print 'plotting',component,'...', if hasattr(self.pars, '%sPlotting' % (component)): plotCharacteristics = getattr(self.pars, '%sPlotting' % \ (component)) else: plotCharacteristics = {'color' : colorwheel[idx%6], 'title' : component } compCmd = RooCmdArg.none() if compList: compSet = RooArgSet(compList) if compSet.getSize() > 0: compCmd = RooFit.Components(compSet) removals = compList.selectByName('%s*' % component) compList.remove(removals) if not Silent: print 'events', self.ws.function('f_%s_norm' % component).getVal() sys.stdout.flush() if abs(self.ws.function('f_%s_norm' % component).getVal()) >= 1.: pdf.plotOn(sframe, #RooFit.ProjWData(data), RooFit.DrawOption('LF'), RooFit.FillStyle(1001), RooFit.FillColor(plotCharacteristics['color']), RooFit.LineColor(plotCharacteristics['color']), RooFit.VLines(), RooFit.Range('plotRange'), RooFit.NormRange('plotRange'), RooFit.Normalization(nexp, RooAbsReal.NumEvent), compCmd ) tmpCurve = sframe.getCurve() tmpCurve.SetName(component) tmpCurve.SetTitle(plotCharacteristics['title']) if 'visible' in plotCharacteristics: sframe.setInvisible(component, plotCharacteristics['visible']) data.plotOn(sframe, RooFit.Name('theData'), RooFit.Binning('plotBins')) sframe.getHist('theData').SetTitle('data') # theData = RooHist(dataHist, 1., 1, RooAbsData.SumW2, 1.0, True) # theData.SetName('theData') # theData.SetTitle('data') # sframe.addPlotable(theData, 'pe') if (logy): sframe.SetMinimum(0.01) sframe.SetMaximum(1.0e6) else: sframe.SetMaximum(sframe.GetMaximum()*1.35) pass excluded = (var in self.pars.exclude) bname = var if not excluded: for v in self.pars.exclude: if hasattr(self.pars, 'varNames') and \ (self.pars.varNames[v] == var): excluded = True bname = v if excluded: blinder = TBox(self.pars.exclude[bname][0], sframe.GetMinimum(), self.pars.exclude[bname][1], sframe.GetMaximum()) # blinder.SetName('blinder') # blinder.SetTitle('signal region') blinder.SetFillColor(kBlack) if self.pars.blind: blinder.SetFillStyle(1001) else: blinder.SetFillStyle(0) blinder.SetLineStyle(2) sframe.addObject(blinder) elif self.pars.blind: if not Silent: print "blind but can't find exclusion region for", var print 'excluded',excluded,self.pars.exclude print 'hiding data points' sframe.setInvisible('theData', True) #sframe.GetYaxis().SetTitle('Events / GeV') # dataHist.IsA().Destructor(dataHist) if not Silent: print xvar.setBins(nbins) return sframe
def draw(plot, do_ratio=True, channel='TauMu', plot_dir='plots', plot_name=None, SetLogy=0, mssm=False, blindxmin=None, blindxmax=None, unit=None): print plot Stack.STAT_ERRORS = True can = pad = padr = None if do_ratio: can, pad, padr = HistDrawer.buildCanvas() else: can = HistDrawer.buildCanvasSingle() pad.cd() pad.SetLogy(SetLogy) plot.DrawStack('HIST') h = plot.supportHist h.GetXaxis().SetLabelColor(1) # h.GetXaxis().SetLabelSize(1) unitsperbin = h.GetXaxis().GetBinWidth(1) ytitle = 'Events' if unit: round_to_n = lambda x, n: round( x, -int(floor(log10(abs(x)))) + (n - 1)) ytitle += round_to_n(unitsperbin, 3) h.GetYaxis().SetTitle('Events') h.GetYaxis().SetTitleOffset(1.0) h.GetXaxis().SetTitleOffset(2.0) if do_ratio: padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = False if blindxmin or blindxmax: if not blindxmin: blindxmin = 0 if not blindxmax: blindxmax = plot.GetXaxis().GetXmax() if do_ratio: ratio.Blind(blindxmin, blindxmax, True) plot.Blind(blindxmin, blindxmax, False) if do_ratio: ratio.DrawDataOverMCMinus1(-0.5, 0.5) hr = ratio.dataOverMCHist # ytp_ratio = float(pad.YtoPixel(0.)/padr.YtoPixel(0)) # print 'YTP ratio', ytp_ratio # xtp_ratio = float(pad.XtoPixel(0.)/padr.XtoPixel(0)) # print 'XTP ratio', xtp_ratio ytp_ratio = 2. xtp_ratio = 2. # hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitleSize(h.GetYaxis().GetTitleSize() * xtp_ratio) hr.GetXaxis().SetTitleSize(h.GetXaxis().GetTitleSize() * ytp_ratio) hr.GetYaxis().SetTitleOffset(h.GetYaxis().GetTitleOffset() / xtp_ratio) hr.GetXaxis().SetTitleOffset(h.GetXaxis().GetTitleOffset() / ytp_ratio) hr.GetYaxis().SetLabelSize(h.GetYaxis().GetLabelSize() * xtp_ratio) hr.GetXaxis().SetLabelSize(h.GetXaxis().GetLabelSize() * ytp_ratio) h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) padr.Update() # blinding if blindxmin or blindxmax: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(blindxmin, 0, blindxmax, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() HistDrawer.keeper.append(box) print channel if channel == 'TauMu': HistDrawer.CMSPrelim(plot, pad, '#tau_{#mu}#tau_{h}', legend=plot.legendPos) elif channel == 'TauEle': HistDrawer.CMSPrelim(plot, pad, '#tau_{e}#tau_{h}', legend=plot.legendPos) can.cd() plotname = plot_dir + '/' ensureDir(plot_dir) plotname += plot_name if plot_name else plot.name can.SaveAs(plotname + '.png') pad.SetLogy(0) return ratio
def massrap_matching(blinded): c = Canvas("c") c.cd() c.SetTicks(1,1) gr = ROOT.TGraphErrors('gr') gr.SetName('gr') count_20, count_5, count_3, count_2, x, y = 0, 0, 0, 0, ROOT.Double(0), ROOT.Double(0) for i, year in enumerate(years): g = getGraph(year) n_gr = gr.GetN() if i > 0 else 0 for j in range(g.GetN()): g.GetPoint(j,x,y) #print 'm:', x, 'y:', y ex = g.GetErrorX(j) ey = g.GetErrorY(j) gr.SetPoint(n_gr+j,x,y) gr.SetPointError(n_gr+j,ex,ey) if abs(x) < 20 and abs(y) < 20: count_20 += 1 if abs(x) < 5 and abs(y) < 5: count_5 += 1 if abs(x) < 3 and abs(y) < 3: count_3 += 1 if abs(x) < 2 and abs(y) < 2: count_2 += 1 print 'Total events:', gr.GetN(), '20sig:', count_20, '5sig:', count_5, '3sig:', count_3, '2sig:', count_2 gr.SetLineColor(ROOT.kBlack) gr.SetTitle('') gr.GetXaxis().SetTitle("(m_{pp}-m_{#gamma#gamma})/#sigma(m_{pp}-m_{#gamma#gamma})") gr.GetYaxis().SetTitle("(y_{pp} - y_{#gamma#gamma})/#sigma(y_{pp} - y_{#gamma#gamma})") gr.GetXaxis().SetLimits(-20,20) gr.GetYaxis().SetRangeUser(-20,20) gr.SetMarkerSize(0.5) gr.SetMarkerStyle(24) gr.Draw("AP") b3 = TBox(-5, -5, 5, 5) b3.SetLineColor(ROOT.kRed) b3.SetFillStyle(0) #b3.Draw() b2 = TBox(-3, -3, 3, 3) if not blinded: b2.SetFillStyle(3001) # transparent b2.SetFillColor(5) b2.SetLineColor(1) b2.Draw() b1 = TBox(-2, -2, 2, 2) if not blinded: b1.SetFillStyle(3001) # transparent b1.SetFillColor(3) b1.SetLineColor(1) b1.Draw() legend = TLegend(0.7,0.8,0.9,0.9) legend.AddEntry(b1,"2#sigma matching",'f') legend.AddEntry(b2,"3#sigma matching",'f') #legend.AddEntry(b3,"5#sigma matching",'l') legend.Draw() c.Update() pLabel = prelimLabel() pLabel.Draw() sLabel = selectionLabel("#xi^{#pm}_{#gamma#gamma} #in PPS") #sLabel = selectionLabel("Reverse acop. selection") sLabel.Draw() lLabel = lumiLabel() lLabel.Draw() s_blind = '_blinded' if blinded else '' c.SaveAs("plots/matching/massrap_matching_"+s_years+"_multiRP%s.%s" % (s_blind,extension))
def draw(plot, do_ratio=True, channel='#mu#tau_{h}', plot_dir='plots', plot_name=None, SetLogy=0, blindxmin=None, blindxmax=None, unit=None): print plot Stack.STAT_ERRORS = True can = pad = padr = None if do_ratio: can, pad, padr = HistDrawer.buildCanvas() else: can = HistDrawer.buildCanvasSingle() pad.cd() pad.SetLogy(SetLogy) # print "about to DrawStack" # plot.DrawNormalized() # plot.DrawNormalizedRatioStack('HIST', ymin=0.1) # , dataAsPoisson=True plot.DrawStack( 'HIST', print_norm=plot.name == '_norm_', ymin=0.1, scale_signal='') # magic word to print integrals in legend h = plot.supportHist h.GetXaxis().SetLabelColor(1) # h.GetXaxis().SetLabelSize(1) unitsperbin = h.GetXaxis().GetBinWidth(1) ytitle = 'Events' if unit: round_to_n = lambda x, n: round( x, -int(floor(log10(abs(x)))) + (n - 1)) ytitle += round_to_n(unitsperbin, 3) h.GetYaxis().SetTitle('Events') # if axis labels and title overlap, change offset here h.GetYaxis().SetTitleOffset(1.3) h.GetXaxis().SetTitleOffset(2.0) if do_ratio: padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = False if blindxmin or blindxmax: if not blindxmin: blindxmin = 0 if not blindxmax: blindxmax = plot.GetXaxis().GetXmax() if do_ratio: ratio.Blind(blindxmin, blindxmax, True) plot.Blind(blindxmin, blindxmax, False) if do_ratio: ratio.DrawDataOverMCMinus1(-0.5, 0.5) hr = ratio.dataOverMCHist # Gymnastics to get same label sizes etc in ratio and main plot ytp_ratio = 2. xtp_ratio = 2. # hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitleSize(h.GetYaxis().GetTitleSize() * xtp_ratio) hr.GetXaxis().SetTitleSize(h.GetXaxis().GetTitleSize() * ytp_ratio) hr.GetYaxis().SetTitleOffset(h.GetYaxis().GetTitleOffset() / xtp_ratio) hr.GetXaxis().SetTitleOffset(h.GetXaxis().GetTitleOffset() / ytp_ratio) hr.GetYaxis().SetLabelSize(h.GetYaxis().GetLabelSize() * xtp_ratio) hr.GetXaxis().SetLabelSize(h.GetXaxis().GetLabelSize() * ytp_ratio) h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) padr.Update() # blinding if blindxmin or blindxmax: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(blindxmin, 0, blindxmax, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() HistDrawer.keeper.append(box) HistDrawer.CMSPrelim(plot, pad, channel, legend=plot.legendPos) can.cd() plotname = plot_dir + '/' ensureDir(plot_dir) plotname += plot_name if plot_name else plot.name can.SaveAs(plotname + '.png') can.SaveAs(plotname + '.pdf') # Also save with log y if plot.legendPos == 'right': h.GetYaxis().SetRangeUser(0.1001, pad.GetUymax() * 5.) else: # minimum is set to 2 orders of magnitude lower than maximum minRange = pow(10, floor(log10(pad.GetUymax() / 100.))) h.GetYaxis().SetRangeUser(minRange + minRange * 1e-4, pad.GetUymax() * 5.e3) pad.SetLogy(True) can.SaveAs(plotname + '_log.png') can.SaveAs(plotname + '_log.pdf') pad.SetLogy(0) return ratio
def draw(plot, doBlind=True, channel='TauMu', plotprefix=None, SetLogy=0, mssm=False): print plot Stack.STAT_ERRORS = True blindxmin = None blindxmax = None if doBlind: if plot.varName == 'svfitMass': blindxmin = 100 if mssm: blindxmax = 1000. else: blindxmax = 160 elif plot.varName == 'visMass': blindxmin = 70 blindxmax = 100 titles = xtitles if channel == 'TauEle': titles = xtitles_TauEle xtitle = titles.get(plot.varName, None) if xtitle is None: xtitle = '' global can, pad, padr, ratio #if pad is None: if not pad: can, pad, padr = buildCanvas() pad.cd() pad.SetLogy(SetLogy) plot.DrawStack('HIST') h = plot.supportHist h.GetXaxis().SetLabelColor(1) h.GetXaxis().SetLabelSize(1) gevperbin = h.GetXaxis().GetBinWidth(1) h.GetYaxis().SetTitle('Events') h.GetYaxis().SetTitleOffset(1.4) padr.cd() ratio = copy.deepcopy(plot) ratio.legendOn = False if doBlind: ratio.Blind(blindxmin, blindxmax, True) plot.Blind(blindxmin, blindxmax, False) ratio.DrawDataOverMCMinus1(-0.2, 0.2) hr = ratio.dataOverMCHist hr.GetYaxis().SetNdivisions(4) hr.GetYaxis().SetTitleSize(0.1) hr.GetYaxis().SetTitleOffset(0.7) hr.GetXaxis().SetTitle('{xtitle}'.format(xtitle=xtitle)) hr.GetXaxis().SetTitleSize(0.13) hr.GetXaxis().SetTitleOffset(0.9) rls = 0.1 hr.GetYaxis().SetLabelSize(rls) hr.GetXaxis().SetLabelSize(rls) h.GetXaxis().SetLabelColor(0) h.GetXaxis().SetLabelSize(0) padr.Update() # blinding if doBlind: pad.cd() max = plot.stack.totalHist.GetMaximum() box = TBox(blindxmin, 0, blindxmax, max) box.SetFillColor(1) box.SetFillStyle(3004) box.Draw() # import pdb; pdb.set_trace() keeper.append(box) print channel if channel == 'TauMu': CMSPrelim(plot, pad, '#tau_{#mu}#tau_{h}') elif channel == 'TauEle': CMSPrelim(plot, pad, '#tau_{e}#tau_{h}') can.cd() if plotprefix == None: plotname = plot.varName else: plotname = plotprefix + '_' + plot.varName can.SaveAs(plotname + '.png') pad.SetLogy(0) return ratio
def plot_rocs(plotObjects, kwargs): from ROOT import kCyan, kRed, kGreen, kBlue, kBlack, kMagenta, kGray, kWhite, kYellow Colors = [kBlue, kRed, kMagenta, kBlack, kCyan, kGreen] from RingerCore import StdPair as std_pair from util import line, minmax dset = kwargs['set'] ref = kwargs['reference'] refVal = kwargs['refVal'] eps = kwargs['eps'] savename = kwargs['cname'] + '.pdf' #Some protection if not ('operation' in dset or 'tst' in dset): raise ValueError('Option set must be: tst (test) or val (validation)') if not ('SP' in ref or 'Pd' in ref or 'Pf' in ref): raise ValueError('Option reference must be: SP, Pd or Pf') #Create dict to hold all list plots curves = dict() #list of dicts to dict of lists for name in plotObjects.keys(): curves[name] = plotObjects.tolist(name) paintIdx = kwargs['paintListIdx'] # [best, worst] paintCurves = [ std_pair(plotObjects.index_correction(paintIdx[0]), kBlack), std_pair(plotObjects.index_correction(paintIdx[1]), kRed) ] curves['roc'] = curves['roc_' + dset] #Start to build all ROOT objects from ROOT import TCanvas, gROOT, kTRUE gROOT.SetBatch(kTRUE) canvas = TCanvas('canvas', 'canvas', 1600, 1300) x_limits = [0.00, 0.40] y_limits = [0.6, 1.03] #create dummy graph dummy = curves['roc'][0] dummy.SetTitle('Receive Operation Curve') dummy.GetXaxis().SetTitle('False Alarm') dummy.GetYaxis().SetTitle('Detection') dummy.GetHistogram().SetAxisRange(y_limits[0], y_limits[1], 'Y') dummy.GetHistogram().SetAxisRange(x_limits[0], x_limits[1], 'X') dummy.Draw('AL') corredor = None target = None from ROOT import TBox if ref == 'Pf': corredor = TBox(refVal - eps, y_limits[0], refVal + eps, y_limits[1]) target = line(refVal, y_limits[0], refVal, y_limits[1], kBlack, 2, 1, '') elif ref == 'Pd': corredor = TBox(x_limits[0], refVal - eps, x_limits[1], refVal + eps) target = line(x_limits[0], refVal, x_limits[1], refVal, kBlack, 2, 1, '') if ref != 'SP': corredor.SetFillColor(kYellow - 9) corredor.Draw('same') target.Draw('same') canvas.Modified() canvas.Update() #Plot curves for c in curves['roc']: c.SetLineColor(kGray + 1) #c.SetMarkerStyle(7) #c.SetMarkerColor(kBlue) c.SetLineWidth(1) c.SetLineStyle(3) #c.Draw('PLsame') c.Draw('same') marker = list() #Paint a specifical curve for pair in paintCurves: curves['roc'][pair.first].SetLineWidth(1) curves['roc'][pair.first].SetLineStyle(1) #curves['roc'][pair.first].SetMarkerStyle(7) #curves['roc'][pair.first].SetMarkerColor(kBlue) curves['roc'][pair.first].SetLineColor(pair.second) #curves['roc'][pair.first].Draw('PLsame') curves['roc'][pair.first].Draw('same') if ref == 'SP': faVec = curves['roc'][pair.first].GetX() detVec = curves['roc'][pair.first].GetY() from RingerCore import calcSP spVec = [ calcSP(detVec[i], 1 - faVec[i]) for i in range(curves['roc'][pair.first].GetN()) ] imax = spVec.index(max(spVec)) from ROOT import TMarker marker.append(TMarker(faVec[imax], detVec[imax], 4)) marker[-1].SetMarkerColor(pair.second) marker[-1].Draw('same') #Update Canvas canvas.Modified() canvas.Update() canvas.SaveAs(savename) del canvas return savename
def drawTopoGeometryEtaPhi(geometry, colorBy, is2016): if colorBy < ETACODE or colorBy > IPHI: return global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi to Topo Geometry", 1400, 950) c.Draw() h = TH2F("h", "Muon Topo Geometry %i" % (2016 if is2016 else 2015), 10, -2.6, 2.6, 10, -0.15, 6.4) h.SetXTitle("#eta") h.SetYTitle("#phi") h.Draw() box = TBox() box.SetFillStyle(0) box.SetLineColor(3) circle = TArc() if colorBy == IPHI: leg = TLegend(0.9, 0.1, 0.98, 0.9) else: leg = TLegend(0.8, 0.1, 0.9, 0.35) #leg.SetEntrySeparation(0.05) #leg.SetNColumns(2) codeInLegend = [] for MioctID in drawOrder: #for MioctID in [3,4,5,6,7]: MIOCT = geometry.getMIOCT(MioctID) fillStyle = 3004 for cellIdx, TopoCell in enumerate(MIOCT.Decode.TopoCells): if colorBy == ETACODE: code = int(TopoCell["etacode"], 16) elif colorBy == PHICODE: code = int(TopoCell["phicode"], 16) elif colorBy == IETA: code = abs(int(TopoCell["ieta"])) elif colorBy == IPHI: code = int(TopoCell["iphi"]) else: raise RuntimeError( "Don't know how to color the eta-phi map (%r)" % colorBy) color = colorMap2[code % len(colorMap2)] fillStyle = fillStyleMap2[code % 4] box.SetLineColor(color) box.SetFillColor(color) circle.SetLineColor(color) circle.SetFillColor(color) # corner 1 c1_x = float(TopoCell["etamin"]) c1_y = float(TopoCell["phimin"]) # corner 2 c2_x = float(TopoCell["etamax"]) c2_y = float(TopoCell["phimax"]) # center c_x = float(TopoCell["ieta"]) c_y = float(TopoCell["iphi"]) #if code>63: # continue #print "cell %i : eta [%f - %f], phi [%f - %f]" % (cellIdx, c1_x, c2_x, c1_y, c2_y) box.SetFillStyle(fillStyle) b = box.DrawBox(c1_x, c1_y, c2_x, c2_y) box.SetFillStyle(0) box.DrawBox(c1_x, c1_y, c2_x, c2_y) circle.DrawArc(c_x / 10., c_y / 10., 0.02) if not code in codeInLegend: codeInLegend += [code] if colorBy == ETACODE: leg.AddEntry(b, "etacode %i" % code, "lf") elif colorBy == PHICODE: leg.AddEntry(b, "phicode %i" % code, "f") elif colorBy == IETA: leg.AddEntry(b, "|ieta| %i" % code, "f") elif colorBy == IPHI: leg.AddEntry(b, "iphi %i" % code, "f") leg.Draw() c.Update() if colorBy == ETACODE: ext = "EtaCode" elif colorBy == PHICODE: ext = "PhiCode" elif colorBy == IETA: ext = "Eta" elif colorBy == IPHI: ext = "Phi" c.SaveAs("TopoLayout%s%s.pdf" % ("2016" if is2016 else "2015", ext))
def main(): if True: mf=TGMainFrame(gClient.GetRoot(),1500,475) gvf=TGVerticalFrame(mf,1500,475) rec=TRootEmbeddedCanvas("ccc",gvf,1500,450) rec2=TRootEmbeddedCanvas("ccc2",gvf,1500,25) gvf.AddFrame(rec,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsTop)) gvf.AddFrame(rec2,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsBottom)) mf.AddFrame(gvf,TGLayoutHints(ROOT.kLHintsExpandX)) cc=rec.GetCanvas() cc2=rec2.GetCanvas() mf.SetEditable(0) mf.SetWindowName('HPS ECAL FADC SCALERS') mf.MapSubwindows() mf.Resize(1501,476)# resize to get proper frame placement mf.MapWindow() else: cc=TCanvas('cc','',1500,450) cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',46,-22,24,11,-5,6) hi=TH2I('hi',';X;Y',46,-22,24,11,-5,6) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.05) tt1=TPaveText(0.1,0.9,0.3,1.0,'NDC') tt2=TPaveText(0.7,0.91,0.9,0.99,'NDC') ttT=TPaveText(-22+13+0.05,6-5,-22+22,7-5-0.05) ttB=TPaveText(-22+13+0.05,4-5+0.05,-22+22,5-5) ttM=TPaveText(-22+0+0.05,5-5+0.05,-22+13,6-5.01) ttime=TPaveText(-10,-6.5,10,-5.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt1,tt2,ttT,ttB,ttM,ttime,tchan]) ttM.SetTextColor(2) bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-9+0.05,-1,0,1.97) bb.DrawBox(-24,0,24.05,0.97) tarrow=TText(14.5,0.3,'Beam Left') arrow=TArrow(19,0.5,23,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.08) tt.DrawText(25.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(2) tt.DrawTextNDC(0.3,0.92,'ECAL FADC SCALERS') cc.cd() for xx in [tt2,ttT,ttB,ttM,arrow,tarrow,ttime]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() ll=TLine() ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmax(),yax.GetXmin()) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmax(),yax.GetXmax()) ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmin(),0) ll.DrawLine(xax.GetXmax(),yax.GetXmin(),xax.GetXmax(),0) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmin(),1) ll.DrawLine(xax.GetXmax(),yax.GetXmax(),xax.GetXmax(),1) ll.DrawLine(xax.GetXmax(),0,0,0) ll.DrawLine(xax.GetXmax(),1,0,1) ll.DrawLine(xax.GetXmin(),0,-9,0) ll.DrawLine(xax.GetXmin(),1,-9,1) ll.DrawLine(-9,-1,0,-1) ll.DrawLine(-9,2,0,2) ll.DrawLine(-9,1,-9,2) ll.DrawLine(-9,-1,-9,0) ll.DrawLine(0,-1,0,0) ll.DrawLine(0,1,0,2) gPad.SetEditable(0) while True: # try: zvals=getPVS() for ii in range(len(zvals)): hh.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) hi.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) for xx in [ttime,tt2,ttT,ttB,ttM]: xx.Clear() [top,bottom,maximum]=calcRates(zvals) tt2.AddText('Total: %.1f MHz'%((top+bottom)/1000)) ttT.AddText('%.1f MHz'%(top/1000)) ttB.AddText('%.1f MHz'%(bottom/1000)) ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz'%(maximum)) ttime.AddText(makeTime()) if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(1)
def xi_matching(sector): c = Canvas("c") c.cd() c.SetTicks(1,1) gr = ROOT.TGraphErrors('gr') gr_m = ROOT.TGraphErrors('gr_m') gr.SetName('gr') gr_m.SetName('gr_m') x, y = ROOT.Double(0), ROOT.Double(0) for i, year in enumerate(years): g = getGraph(year,'xi'+sector) n_grm = gr_m.GetN() if i > 0 else 0 n_gr = gr.GetN() if i > 0 else 0 for j in range(g.GetN()): g.GetPoint(j,x,y) ex = g.GetErrorX(j) # FIXME? ey = g.GetErrorY(j) diff = abs(y-x) if diff < 0.003: #if diff < 0.02 * x: # only using relative PPS xi error gr_m.SetPoint(n_grm+j,x,y) gr_m.SetPointError(n_grm+j,ex,ey) else: gr.SetPoint(n_gr+j,x,y) gr.SetPointError(n_gr+j,ex,ey) gr.SetMarkerSize(0.6) gr.SetMarkerStyle(24) gr_m.SetMarkerSize(0.6) gr_m.SetMarkerStyle(24) gr_m.SetMarkerColor(ROOT.kRed) gr_multi = ROOT.TMultiGraph('gr_multi','') gr_multi.Add(gr,'AP') gr_multi.Add(gr_m,'AP') c.SetGrid() min, max = 0.0001, 0.25 c.DrawFrame(min,min,max,max) gr_multi.Draw() gr_multi.GetXaxis().SetTitleOffset(1.3) gr_multi.GetYaxis().SetTitleOffset(1.3) if sector == 'm': gr_multi.GetXaxis().SetTitle("#xi(p)"+"^{-}") gr_multi.GetYaxis().SetTitle("#xi(#gamma#gamma)"+"^{-}") elif sector == 'p': gr_multi.GetXaxis().SetTitle("#xi(p)"+"^{+}") gr_multi.GetYaxis().SetTitle("#xi(#gamma#gamma)"+"^{+}") # Draw y = x line l = TLine(min, min, max, max) l.SetLineStyle(2) l.SetLineWidth(2) l.Draw() # Draw shaded region for no acceptance b = TBox(min, min, 0.015, max) b.SetFillStyle(3001) b.SetFillColor(ROOT.kGray) b.SetLineColor(1) b.Draw() # Make legend legend = TLegend(0.65,0.45,0.8,0.6) legend.SetBorderSize(0) legend.SetTextFont(42) legend.SetTextSize(0.038) legend.AddEntry(b,"No acceptance",'f') legend.AddEntry(gr,"Not matching",'p') legend.AddEntry(gr_m,"Matching at 2#sigma",'p') legend.Draw() pLabel, sLabel, lLabel = prelimLabel(), selectionLabel("Tight #xi selection"), lumiLabel() pLabel.Draw(), sLabel.Draw(), lLabel.Draw() #c.SaveAs("plots/matching/xi"+sector+"_matching_"+s_years+".pdf") c.SaveAs("plots/matching/xi%s_matching_%s.%s" % (sector,s_years,extension))
def pullsVertical_noBonly(fileName): content = filterPullFile(fileName) nbins, off = len(content), 0.10 # Graphs h_pulls = TH2F("pulls", "", 6, -3., 3., nbins, 0, nbins) S_pulls = TGraphAsymmErrors(nbins) boxes = [] canvas = TCanvas("canvas", "Pulls", 720, 300 + nbins * 18) #nbins*20) canvas.cd() canvas.SetGrid(0, 1) canvas.SetTopMargin(0.01) canvas.SetRightMargin(0.01) canvas.SetBottomMargin(0.10) canvas.SetLeftMargin(0.40) canvas.SetTicks(1, 1) for i, s in enumerate(content): l = s.split() h_pulls.GetYaxis().SetBinLabel(i + 1, l[0]) S_pulls.SetPoint(i, float(l[3]), float(i + 1) - 0.5) S_pulls.SetPointError(i, float(l[4]), float(l[4]), 0., 0.) h_pulls.GetXaxis().SetTitle("(#hat{#theta} - #theta_{0}) / #Delta#theta") h_pulls.GetXaxis().SetLabelOffset(0.0) h_pulls.GetXaxis().SetTitleOffset(0.8) h_pulls.GetXaxis().SetLabelSize(0.045) h_pulls.GetXaxis().SetTitleSize(0.050) h_pulls.GetYaxis().SetLabelSize(0.046) h_pulls.GetYaxis().SetNdivisions(nbins, 0, 0) S_pulls.SetFillColor(kBlack) S_pulls.SetLineColor(kBlack) S_pulls.SetMarkerColor(kBlack) S_pulls.SetLineWidth(2) S_pulls.SetMarkerStyle(20) S_pulls.SetMarkerSize(1) box1 = TBox(-1., 0., 1., nbins) #box1.SetFillStyle(3001) # 3001 checkered #box1.SetFillStyle(0) box1.SetFillColor(kGreen + 1) # 417 box1.SetLineWidth(2) box1.SetLineStyle(2) box1.SetLineColor(kGreen + 1) # 417 box2 = TBox(-2., 0., 2., nbins) #box2.SetFillStyle(3001) # 3001 checkered #box2.SetFillStyle(0) box2.SetFillColor(kOrange) # 800 box2.SetLineWidth(2) box2.SetLineStyle(2) box2.SetLineColor(kOrange) # 800 leg = TLegend(0.01, 0.01, 0.3, 0.15) leg.SetTextSize(0.05) leg.SetBorderSize(0) leg.SetFillStyle(0) leg.SetFillColor(0) #leg.SetNColumns(2) leg.AddEntry(S_pulls, "S+B fit", "lp") if text: leg.AddEntry(0, text, "") h_pulls.Draw("") box2.Draw() box1.Draw() S_pulls.Draw("P6SAME") leg.Draw() canvas.RedrawAxis() canvas.Print(outName + ".png") canvas.Print(outName + ".pdf") if not gROOT.IsBatch(): raw_input("Press Enter to continue...")
def makeCombinedEtaPlot(self, tight=False): hist = self.makeL1TimeVsEtaPlot(('tight_' if tight else '') + 'dtOnly_bxidVsEta')[2] countsInL1 = [] for x in np.arange(-.95, 1.05, 0.1): totalCounter = 0 zeroCount = 0 for y in range(-2, 3): totalCounter += hist.GetBinContent(hist.FindBin(x, y)) if y == 0: zeroCount = hist.GetBinContent(hist.FindBin(x, y)) countsInL1.append({ 'total': totalCounter, 'zero': zeroCount, 'eta': x }) #Graph for results graph1 = TEfficiency(hist.GetName(), "", 8, -9.195, -.5) graph2 = TEfficiency(hist.GetName(), "", 8, .5, 9.195) for item in countsInL1: if item['total'] == 0: continue print item['total'], item['zero'], item['eta'] if item['eta'] < 0: graph1.SetTotalEvents( graph1.FindFixBin(-0.5 + item['eta'] / 0.087), int(item['total'])) graph1.SetPassedEvents( graph1.FindFixBin(-0.5 + item['eta'] / 0.087), int(item['zero'])) else: graph2.SetTotalEvents( graph2.FindFixBin(0.5 + item['eta'] / 0.087), int(item['total'])) graph2.SetPassedEvents( graph2.FindFixBin(0.5 + item['eta'] / 0.087), int(item['zero'])) histHo = None if tight: histHo = self.plotTightHoTimeVsEta()[3][1] else: histHo = self.plotHoTimeVsEta()[3][1] histHo.SetTitle(('Tight ' if tight else '') + 'Unmatched DT + HO') canvas = TCanvas( 'combinedPlot' + ('Tight ' if tight else '') + hist.GetName(), 'combinedPlot') canvas.cd().SetTopMargin(.15) histHo.Draw('ap') canvas.Update() canvas.cd().SetTicks(0, 0) histHo.SetMarkerStyle(2) histHo.SetLineColor(colorRwthDarkBlue) histHo.SetMarkerColor(colorRwthDarkBlue) histHo.GetPaintedGraph().GetXaxis().SetRangeUser(-12, 12) histHo.GetPaintedGraph().GetXaxis().SetLabelColor(colorRwthDarkBlue) histHo.GetPaintedGraph().GetXaxis().SetTitleColor(colorRwthDarkBlue) histHo.GetPaintedGraph().GetXaxis().SetAxisColor(colorRwthDarkBlue) yMax = gPad.GetFrame().GetY2() yMin = gPad.GetFrame().GetY1() #Print average Fraction excluding iEta +/-2 x = Double(0) y = Double(0) mean = 0 var = 0 for i in range(0, histHo.GetPaintedGraph().GetN()): histHo.GetPaintedGraph().GetPoint(i, x, y) if abs(x) == 2: continue mean += y var += histHo.GetPaintedGraph().GetErrorY( i) * histHo.GetPaintedGraph().GetErrorY(i) mean /= histHo.GetPaintedGraph().GetN() - 2 sigma = sqrt(var / (histHo.GetPaintedGraph().GetN() - 2)) self.debug( "Average fraction excluding iEta +/- 2 %s: %5.2f%% +/- %5.2f%%" % ('[Tight]' if tight else '', mean * 100, sigma * 100)) nTotal = 0 nPassed = 0 for item in countsInL1: if fabs(item['eta']) == 2 or fabs(item['eta'] == 0): continue nTotal += item['total'] nPassed += item['zero'] #Print again with ClopperPearson uncertainty, the counts are for L1!!! mean = nPassed / nTotal * 100 sigmaPlus = TEfficiency.ClopperPearson(int(nTotal), int(nPassed), .68, 1) * 100 - mean sigmaMinus = mean - TEfficiency.ClopperPearson( int(nTotal), int(nPassed), .68, 0) * 100 #self.debug("Average fraction excluding iEta +/- 2 %s with Clop.Pear.: %5.2f%% +%5.2f%% -%5.2f%%" # % ('[Tight]' if tight else '',mean,sigmaPlus,sigmaMinus)) #Left axis part f1 = TF1("f1", "x", -0.87, 0) A1 = TGaxis(-10, yMax, -0.5, yMax, "f1", 010, "-") A1.SetLineColor(colorRwthRot) A1.SetLabelColor(colorRwthRot) A1.Draw() #Right axis part f2 = TF1("f2", "x", 0, 0.87) A2 = TGaxis(0.5, yMax, 10, yMax, "f2", 010, "-") A2.SetLineColor(colorRwthRot) A2.SetLabelColor(colorRwthRot) A2.Draw() #Box for shading out 0 box = TBox(-.5, yMin, 0.5, yMax) box.SetLineColor(colorRwthDarkGray) box.SetFillColor(colorRwthDarkGray) box.SetFillStyle(3013) box.Draw('same') #Left L1 eta graph1.SetMarkerColor(colorRwthRot) graph1.SetLineColor(colorRwthRot) graph1.SetMarkerStyle(20) graph1.Draw('same,p') #Right L1Eta graph2.SetMarkerColor(colorRwthRot) graph2.SetLineColor(colorRwthRot) graph2.SetMarkerStyle(20) graph2.Draw('same,p') #Label for extra axis axisLabel = TPaveText(0.83, 0.85, 0.89, 0.9, "NDC") axisLabel.AddText('#eta_{L1}') axisLabel.SetBorderSize(0) axisLabel.SetFillStyle(0) axisLabel.SetTextColor(colorRwthRot) axisLabel.SetTextSize(0.05) axisLabel.Draw() #Legend legend = getLegend(x1=0.1, y1=0.1, x2=0.4, y2=.35) legend.AddEntry(histHo, 'HO #in #pm12.5 ns', 'pe') legend.AddEntry(graph1, ('Tight ' if tight else '') + 'L1 BXID = 0', 'pe') legend.Draw() canvas.Update() self.storeCanvas(canvas, "combinedFractionL1AndHo" + ('Tight' if tight else ''), drawMark=False) return histHo, graph1, canvas, A1, f1, A2, f2, box, graph2, axisLabel, legend