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_box(boxList,xl,xr,yl,yr,opacity=1,color=1,style=1001,lstyle=1,lw=3): from ROOT import TBox b=TBox(xl,yl,xr,yr) b.SetBit(ROOT.kCanDelete) b.SetFillStyle(style) b.SetFillColorAlpha(color, opacity) b.SetLineColor(color) b.SetLineWidth(lw) b.SetLineStyle(lstyle) b.Draw() boxList.append(b)
def drawHcalBoxesHcalCoords(canvas): canvas.cd() boxes = [] for i in range(-15,15): for j in range(0,72): box = TBox(i,j,(i+1),(j+1)) box.SetFillStyle(0) box.SetLineColor(colorRwthMagenta) box.SetLineWidth(2) box.Draw() boxes.append(box) return boxes
def drawHoBoxes(canvas): canvas.cd() boxes = [] for i in range(1, 6): for j in range(1, 6): box = TBox(-2.5 + i - 1, -2.5 + j - 1, -2.5 + i, -2.5 + j) box.SetFillStyle(0) box.SetLineColor(ROOT.kBlack) box.SetLineWidth(2) box.Draw() boxes.append(box) return boxes
def drawHoBoxes(canvas): canvas.cd() boxes = [] for i in range(-1,2): for j in range(-1,2): box = TBox(i*0.087 - 0.0435,j*0.087 - 0.0435,(i*0.087+0.0435),(j*0.087+0.0435)) box.SetFillStyle(0) box.SetLineColor(colorRwthMagenta) box.SetLineWidth(3) box.Draw() boxes.append(box) return boxes
def drawHoBoxes(canvas): canvas.cd() boxes = [] for i in range(1, 8): for j in range(1, 8): box = TBox(-0.3045 + (i - 1) * 0.087, -0.3045 + (j - 1) * 0.087, -0.3045 + i * 0.087, -0.3045 + j * 0.087) box.SetFillStyle(0) box.SetLineColor(ROOT.kBlack) box.SetLineWidth(2) box.Draw() boxes.append(box) return boxes
def makeTimeVsEtaPlot(self, source, title=""): canvas = TCanvas(source) if title == "": title = source hist = TH2D(source, title + ";i#eta;Time / ns;#", 33, -16.5, 16.5, 201, -100.5, 100.5) graph = self.fileHandler.getGraph('graphs/timingSupport_' + source) fillGraphIn2DHist(graph, hist) hist.SetStats(0) hist.Draw('colz') canvas.Update() setupAxes(hist) label = self.drawLabel() canvas.Update() fractionGraph, counterDict = self.printFractionsPerIEta(graph) self.debug('Integral of plot %20s: %d' % (source, hist.Integral())) medianTofZero = (counterDict[9]['median'] + counterDict[11]['median']) / 2. tofFunction = TF1( 'f', '4*sqrt(1+ 1/(tan(2*atan(exp(-x*0.087/2.)))**2))/300000000.*1e9 - 13.3 + [0]', -10, 10) tofFunction.SetParameter(0, medianTofZero) tofFunction.Draw('same') ### # Draw Boxes for the Intervals ### intervalBoxes = [] for index, item in enumerate(counterDict): iEta = index - 10 # Skip iEta 0 if iEta == 0: continue box = TBox(iEta - 0.5, item['median'] - 12.5, iEta + 0.5, item['median'] + 12.5) box.SetFillStyle(0) box.SetLineColor(colorRwthMagenta) box.SetLineWidth(2) box.Draw() intervalBoxes.append(box) return canvas, hist, label, fractionGraph, intervalBoxes, tofFunction
def plot3x3MatchQualityCodesVsPt(self): c = TCanvas('cMatchQC3x3', 'Match QC 3x3', 0, 0, 900, 700) c.SetLogz() hist = self.fileHandler.getHistogram( 'qualityCode/L1Muon3x3Match_QcVsPt') hist.SetStats(0) hist.Scale(1, 'width') hist.Draw('colz') c.Update() setupPalette(hist) c.Update() label = self.drawLabel() c.Update() box = TBox(0, 6.5, 180, 7.5) box.SetLineColor(3) box.SetLineWidth(2) box.Draw() c.Update() return hist, c, label, box
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 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)
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 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...")
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 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 drawROIGeometry(geometry, is2016): outfn = "ROILayout%s.pdf" % ("2016" if is2016 else "2015") global box, c, h, leg gROOT.Reset() gStyle.SetOptStat(0) c = TCanvas('c', "MuCTPi Geometry %s" % "2016" if is2016 else "2015", 1400, 950) c.Draw() #h = TH2F("h","Muon Geometry",10,-2.6,2.6,10,-6.4,6.4) h = TH2F("h", "Muon 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) box.SetLineColor(3) text = TLatex() text.SetTextSize(0.005) text.SetTextFont(42) text.SetTextAlign(22) secLabel = TLatex() secLabel.SetTextSize(0.008) secLabel.SetTextFont(42) secLabel.SetTextAlign(22) leg = TLegend(0.7, 0.1, 0.9, 0.4) leg.SetEntrySeparation(0.05) leg.SetNColumns(2) #for MIOCT in geometry.getMIOCTs(): for colorIndex, MioctID in enumerate(drawOrder): MIOCT = geometry.getMIOCT(MioctID) firstBox = True color = colorMap[colorIndex % len(colorMap)] #print "Using color ",color box.SetLineColor(color) box.SetLineWidth(1) for Sector in MIOCT.Sectors: ymin = 10 ymax = -10 for ROI in Sector.ROIs: c1_x = float(ROI["etamin"]) c1_y = float(ROI["phimin"]) c2_x = float(ROI["etamax"]) c2_y = float(ROI["phimax"]) ymin = min(ymin, c1_y) ymax = max(ymax, c2_y) #print "eta [%f - %f], phi [%f - %f]" % (c1_x,c2_x,c1_y,c2_y) b = box.DrawBox(c1_x, c1_y, c2_x, c2_y) text.DrawText((c1_x + c2_x) / 2, (c1_y + c2_y) / 2, ROI["roiid"]) if firstBox: firstBox = False leg.AddEntry(b, "Slot %s" % MIOCT["slot"], "l") if Sector["name"].startswith("B"): if int(Sector["name"][1:]) < 32: xpos = -0.02 ypos = (ymin + ymax) / 2 - 0.05 else: xpos = 0.02 ypos = (ymin + ymax) / 2 + 0.03 secLabel.DrawText(xpos, ypos, Sector["name"]) leg.Draw() c.Update() c.SaveAs(outfn)
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 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
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 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)