def drawSignature(signature): """Write an unique identifier in the lower left canvas corner""" l = TText() l.SetTextAlign(11) l.SetTextSize(0.02) l.SetTextFont(82) l.DrawTextNDC(0.01, 0.01, signature)
def timeStampCanvas(canvas): import rootpy from rootpy.plotting import Canvas from ROOT import TText import datetime # apply time stamp: text = TText() canvas.cd(0) #select canvas text.SetTextSize(0.015) text.DrawTextNDC(.7, 0.008, datetime.datetime.now().strftime("%A, %d. %B %Y %I:%M%p"))
def markPad(text, x=0.14, y=0.007, size=0.013, color=1, canvas=None, npad=-1): """ Puts a line of text on a specific canvas and pad. If none are specified, the current pad is used """ import rootpy from rootpy.plotting import Canvas from ROOT import TText t = TText() if npad >= 0 and canvas: canvas.cd(npad) #select pad (0 = whole canvas) t.SetTextSize(size) t.SetTextColor(color) t.DrawTextNDC(x, y, text)
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', ';Y;X', 2, 2, 4, 14, 2, 16) hi = TH2I('hi', ';Y;X', 2, 2, 4, 14, 2, 16) 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) gPad.SetRightMargin(0.12) tt1 = TPaveText(0.05, 0.94, 0.22, 1.0, 'NDC') ttL = TPaveText(0.05, 0.905, 0.2, 0.93, 'NDC') ttR = TPaveText(0.75, 0.905, 0.9, 0.93, 'NDC') ttLM = TPaveText(2, 0.5, 2.5, 1) ttRM = TPaveText(3.5, 0.5, 4, 1) ttM = TPaveText(0.6, 0.94, 0.9, 1, 'NDC') ttime = TPaveText(2.8, 1.5, 3.3, 1.9) tchan = TPaveText(0, 0, 0.9, 1) setupPaveTexts([tt1, ttM, ttime, tchan, ttL, ttR, ttLM, ttRM]) ttM.SetTextColor(2) tarrow = TText(2.9, 0.25, 'Beam Left') arrow = TArrow(2.85, 0.5, 2.75, 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(4.07, 9, 'kHz') tt.SetTextAngle(0) tt.SetTextColor(2) tt.DrawTextNDC(0.23, 0.905, 'SHMS PCAL FADC SCALERS') ttL.AddText('Left+') ttR.AddText('-Right') cc.cd() for xx in [ttM, tt1, ttL, ttR, arrow, tarrow, ttime, ttLM, ttRM]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() xmin, xmax = xax.GetXmin(), xax.GetXmax() ymin, ymax = yax.GetXmin(), yax.GetXmax() gPad.SetEditable(0) while True: zvals = getScalars() for ii in range(len(zvals)): hh.SetBinContent(xax.FindBin(XVALS[ii] + 1), yax.FindBin(16 - YVALS[ii]), zvals[ii]) hi.SetBinContent(xax.FindBin(XVALS[ii] + 1), yax.FindBin(16 - YVALS[ii]), zvals[ii]) for xx in [ttime, ttM, tt1, ttLM, ttRM]: xx.Clear() [left, right, maximum] = calcRates(zvals) tt1.AddText('Total: %.1f MHz' % ((left + right) / 1000)) ttLM.AddText('Left total: %.1f MHz' % (left / 1000)) ttRM.AddText('Right total: %.1f MHz' % (right / 1000)) ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz' % (maximum)) 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(1)
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(0) gStyle.SetGridColor(18) nbinsX = 0 for ix in range(len(SECTORSPERREGION)): nbinsX += SECTORSPERREGION[ix] hh = TH2D('hh', ';Strip;Sector', STRIPSPERSECTOR, 0, STRIPSPERSECTOR, nbinsX, 0, nbinsX) setupHists([hh]) hh.Draw('COLZ') gPad.SetLogz() gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) tt2 = TPaveText(240, 43, 500, 45) ttime = TPaveText(100, -5.5, 412, -3) setupPaveTexts([tt2, ttime]) tt2.SetTextSize(0.03) lll = TLine() lll.SetLineColor(15) y1 = SECTORSPERREGION[0] y2 = SECTORSPERREGION[0] + SECTORSPERREGION[1] lll.DrawLine(0, y1, STRIPSPERSECTOR, y1) lll.DrawLine(0, y2, STRIPSPERSECTOR, y2) tt = TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(532, 22, 'Hz') tt.SetTextSize(0.06) tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.1, 0.93, 'SVT Scalers') tt.SetTextSize(0.03) tt.DrawText(-42, 4, 'R1') tt.DrawText(-42, 16, 'R2') tt.DrawText(-42, 32, 'R3') cc.cd() for xx in [ttime, tt2]: xx.Draw() cc.cd() gPad.SetEditable(0) while True: iy = 0 for ch in SVT.chans: loadPV(ch) ch = ch.vals data = ch['PVVAL'] time2 = ch['PVTIMEVAL'] if time2 > 10: print 'More than 10 seconds since message: ' + ch['PVNAME'] for ii in range(512): data[ii] = 0 if iy < SECTORSPERREGION[0]: region = 1 sector = iy elif iy < SECTORSPERREGION[0] + SECTORSPERREGION[1]: region = 2 sector = iy - SECTORSPERREGION[0] else: region = 3 sector = iy - SECTORSPERREGION[0] - SECTORSPERREGION[1] if data == None or len(data) != STRIPSPERSECTOR: print 'Error Reading ' + ch['PVNAME'] continue for ix in range(STRIPSPERSECTOR): hh.SetBinContent(ix, iy + 1, data[ix]) iy += 1 for xx in [ttime, tt2]: xx.Clear() [r1, r2, r3] = calcRates(SVT.chans) tt2.AddText('Sums: R1 / R2 / R3 = %.2E / %.2E / %.2E Hz' % (r1, r2, r3)) ttime.AddText(makeTime()) if not gPad: sys.exit() cc.Modified() cc.Update() time.sleep(POLLPERIOD)
def plotL1AndTightL1Counters(self): hEvent = self.fileHandler.getHistogram('count/Events_Count') hAllL1 = self.fileHandler.getHistogram('count/L1Muon_Count') hAllL13x3 = self.fileHandler.getHistogram('count/L1Muon3x3_Count') hTightL1 = self.fileHandler.getHistogram('count/L1TightMuons_Count') hTightL13x3 = self.fileHandler.getHistogram( 'count/L1TightMuons3x3_Count') hL1 = self.fileHandler.getHistogram('count/energyDeposit_L1_Count') hL1Reco = self.fileHandler.getHistogram( 'count/energyDeposit_L1Reco_Count') hL1RecoHo = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHo_Count') hL1RecoHoTight = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHoTight_Count') hL1RecoTight = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoTight_Count') hL1RecoTightHo = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoTightHo_Count') hL1RecoHoNoThr = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoHoNoThr_Count') hL1RecoGaHoNoThr = self.fileHandler.getHistogram( 'count/energyDeposit_L1RecoGaHoNoThr_Count') histogramList = [ hEvent, hL1, hL1Reco, hL1RecoHo, hL1RecoHoTight, hL1RecoTight, hL1RecoTightHo, hL1RecoHoNoThr, hL1RecoGaHoNoThr ] names = [ 'hEvent', 'hL1', 'hL1Reco', 'hL1RecoHo', 'hL1RecoHoTight', 'hL1RecoTight', 'hL1RecoTightHo', 'hL1RecoHoNoThr', 'hL1RecoGaHoNoThr' ] nL1 = hL1.GetBinContent(2) self.commandLine.output( '###############################################') for i, h in enumerate(histogramList): self.commandLine.output('%-20s:%8d\t=> %6.2f%% +/- %5.2f%%' % (names[i], h.GetBinContent(2), calcPercent(h.GetBinContent(2), nL1), calcSigma(h.GetBinContent(2), nL1) * 100)) self.commandLine.output( '###############################################') nL1Reco = hL1Reco.GetBinContent(2) nL1RecoHo = hL1RecoHo.GetBinContent(2) nL1RecoHoTight = hL1RecoHoTight.GetBinContent(2) nL1RecoTight = hL1RecoTight.GetBinContent(2) nL1RecoTightHo = hL1RecoTightHo.GetBinContent(2) N_BINS = 4 binContents = [nL1, nL1Reco, nL1RecoHo, nL1RecoHoTight] binLabels = [ 'L1', 'L1 -> Reco', 'L1 + R -> HO', 'L1 + R + HO -> tight' ] binContentsInverted = [nL1, nL1Reco, nL1RecoTight, nL1RecoTightHo] binLabelsInverted = [ 'L1', 'L1 -> Reco', 'L1 + R -> tight', 'L1 + R + tight -> HO' ] c = TCanvas('cL1AndTightL1Count', 'L1AndTightL1Count') h = TH1D('hL1AndTightL1Count', 'L1 Cutflow', 4, -0.5, N_BINS - .5) hInverted = TH1D('hL1AndTightL1CountInverted', 'L1 Efficiency', 4, -0.5, N_BINS - .5) hInverted.SetFillStyle(3002) hInverted.SetFillColor(colorRwthOrange) hInverted.SetLineColor(colorRwthOrange) hInverted.SetLineStyle(3) hL13x3Alone = TH1D('hL1And3x3Alone', '', 1, 1.5, 2.5) hL13x3Alone.SetBinContent(1, nL1RecoHo / nL1Reco) hL13x3Alone.SetBinError(1, calcSigma(nL1RecoHo, nL1Reco)) hL13x3Alone.SetLineColor(colorRwthMagenta) hTightL13x3Alone = TH1D('hTightL1And3x3Alone', '', 1, 2.5, 3.5) hTightL13x3Alone.SetBinContent(1, nL1RecoHoTight / nL1RecoHo) hTightL13x3Alone.SetBinError(1, calcSigma(nL1RecoHoTight, nL1RecoHo)) hTightL13x3Alone.SetLineColor(colorRwthTuerkis) for i in range(2, N_BINS + 1): h.SetBinContent(i, binContents[i - 1] / binContents[1]) h.GetXaxis().SetBinLabel(i, binLabels[i - 1]) hInverted.SetBinContent( i, binContentsInverted[i - 1] / binContentsInverted[1]) hInverted.GetXaxis().SetBinLabel(i, binLabelsInverted[i - 1]) h.GetXaxis().SetBinLabel(1, 'L1') h.SetBinContent(1, 1) hInverted.GetXaxis().SetBinLabel(1, 'L1') hInverted.SetBinContent(1, 1) h.SetLineColor(colorRwthDarkBlue) h.SetStats(0) h.GetYaxis().SetTitle('rel. fraction') h.Draw() # hL13x3Alone.Draw('same e') # hTightL13x3Alone.Draw('same e') hInverted.Draw('same') hInverted.GetXaxis().Draw('same') setupAxes(h) legend = getLegend(y2=.9, x1=.55) legend.AddEntry(h, 'First match HO then use tight', 'l') # legend.AddEntry(hL13x3Alone,'3x3 matching normed to # L1 + R','le') # legend.AddEntry(hTightL13x3Alone,'Normed to # L1 + R + HO','l') legend.AddEntry(hInverted, 'Inverted order for HO and tight', 'f') legend.Draw() label = self.drawLabel() textObjects = [] #for (Int_t i=1;i<=30;i++) t.DrawText(h->GetBinCenter(i),yt,Form("%d",i%10)); for i in range(1, 4): t = TText() t.SetTextSize(0.025) t.SetTextAlign(22) t.SetTextColor(colorRwthOrange) t.DrawTextNDC(getXinNDC(hInverted.GetBinCenter(i + 1)), 0.05, binLabelsInverted[i]) # Double_t yt = - h->GetMaximum()/15.; textObjects.append(t) c.Update() self.storeCanvas(c, 'l1AndTightL1Counters') return h, c, hL13x3Alone, hTightL13x3Alone, label, legend, hInverted, textObjects
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 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)
hs.Add(h1) hs.Add(h2) h1.SetLineColor(ROOT.kBlue) h2.SetLineColor(ROOT.kRed) h1.SetTitle(file1Name.replace(".root","")) h2.SetTitle(file2Name.replace(".root","")) #h1.Draw() #h2.Draw("same") hs.Draw() T = TText() T.SetTextFont(42) T.SetTextAlign(21) T.DrawTextNDC(.5,.95,var) c1.BuildLegend(0.66, 0.87, 0.93, 0.77, "") c1.SetTitle(var) #c.cd() #Tl = ROOT.TLatex(0.5,0.9,var) #Tl.SetTextSize(0.04) #Tl.SetTextAlign(13) #Tl.Draw() pdfName=var+"_"+file1Name.replace(".root","")+"_vs_"+file2Name.replace(".root","") c1.SaveAs("plots/"+pdfName+".pdf") #/lstore/cms/cbeiraod/Stop4Body/puWeights #/lstore/cms/dbastos/Stop4Body/nTuples_v2018-04-03/ #puWeights_stop675.json.root
QCD = fNVert.Get("QCD") QCD.Scale(1 / QCD.Integral()) QCD.SetLineColor(ROOT.kOrange) hs.Add(QCD) ttx = fNVert.Get("ttx") ttx.Scale(1 / ttx.Integral()) ttx.SetLineColor(ROOT.kSpring) hs.Add(ttx) hs.Draw() T = TText() T.SetTextFont(42) T.SetTextAlign(21) T.DrawTextNDC(.5, .95, "nVert") c1.BuildLegend(0.66, 0.85, 0.87, 0.65, "") c1.SetTitle("nVert") pdfName = "PU_Test" c1.SaveAs("plots/" + pdfName + ".pdf") ''' path="/lstore/cms/dbastos/Stop4Body/nTuples_v2018-08-24/" nTuple1="ZJetsToNuNu_HT600to800.root" nTuple2="Data_2017B_MetHT.root" f1=ROOT.TFile(path+nTuple1,"READ") f2=ROOT.TFile(path+nTuple2,"READ") t1=f1.Get("bdttree") t2=f2.Get("bdttree")
def makePlot(resname): os.system("sort -k 1 pre_" + resname + " > sorted_pre_" + resname) os.system("sort -k 1 post_" + resname + " > sorted_post_" + resname) pre_fres = open("sorted_pre_" + resname, "r") post_fres = open("sorted_post_" + resname, "r") ll_pre = pre_fres.readlines() ll_post = post_fres.readlines() n = len(ll_pre) hres_pre = {} hres_post = {} for trigger in trigger_list: print " ... trigger = ", trigger hres_pre[trigger] = TH1F("hres_pre_" + trigger, " ;run number; pre-firing " + trigger, n, 0, n) hres_post[trigger] = TH1F("hres_post_" + trigger, " ;run number; post-firing " + trigger, n, 0, n) i = 0 for al in ll_pre: l = al.split() i = i + 1 run = l[0] for trigger in trigger_list: itrig = trigger_list.index(trigger) hres_pre[trigger].GetXaxis().SetBinLabel(i, "Run " + str(run)) hres_pre[trigger].SetBinContent(i, float(l[1 + 2 * itrig])) hres_pre[trigger].SetBinError(i, float(l[1 + 2 * itrig + 1])) i = 0 for al in ll_post: l = al.split() i = i + 1 run = l[0] for trigger in trigger_list: itrig = trigger_list.index(trigger) hres_post[trigger].GetXaxis().SetBinLabel(i, "Run " + str(run)) hres_post[trigger].SetBinContent(i, float(l[1 + 2 * itrig])) hres_post[trigger].SetBinError(i, float(l[1 + 2 * itrig + 1])) pre_fres.close() post_fres.close() # -- do the plots : gStyle.SetOptStat(0) leg = TLegend(0.6, 0.75, 0.95, 0.92, "", "brNDC") leg.SetBorderSize(0) leg.SetLineColor(1) leg.SetLineStyle(1) leg.SetLineWidth(1) leg.SetFillColor(0) leg.SetFillStyle(0) leg.SetTextFont(42) tt = TText() tt.SetTextSize(0.06) for trigger in trigger_list: hres_pre[trigger].SetMinimum(0) hres_post[trigger].SetMinimum(0) hres_post[trigger].SetMarkerColor(2) hres_post[trigger].SetLineColor(2) c = TCanvas("c_" + trigger, "c_" + trigger) hres_pre[trigger].GetYaxis().SetTitle( "post/" + hres_pre[trigger].GetYaxis().GetTitle()) hres_pre[trigger].Draw("pe") hres_post[trigger].Draw("same,pe") if trigger_list.index(trigger) == 0: leg.AddEntry(hres_pre[trigger], "pre-firing", "pe") leg.AddEntry(hres_post[trigger], "post-firing", "pe") leg.Draw() tt.DrawTextNDC(0.25, 0.88, trigger) c.SaveAs(trigger + ".gif") # --- store the histograms hres = ROOT.TFile("all_hres.root", "update") for trigger in trigger_list: hres_pre[trigger].Write() hres_post[trigger].Write() hres.Close() return
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(18) hh = TH2D('hh', ';X;Y', 8 * 28, 0, 28, 8 * 23, 0, 23) hi = TH2I('hi', ';X;Y', 8 * 28, 0, 28, 8 * 23, 0, 23) setupHists([hh, hi]) xax, yax = hh.GetXaxis(), hh.GetYaxis() hh.Draw('COLZ') hh.SetMinimum(1) hh.SetMaximum(1.5e3) #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) ttime = TPaveText(8, -2, 20, -1) tchan = TPaveText(0, 0, 0.9, 1) setupPaveTexts([tt2, ttM, ttime, tchan, ttX, ttY]) ttM.SetTextColor(2) ttM.SetFillStyle(0) tt2.SetFillStyle(0) tt = TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(29.5, 10, 'kHz') tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.3, 0.92, 'RICH SSP 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 [ttime]: xx.Draw() #ttM,tt2,ttime,ttX,ttY]: 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'] data = ch['PVVAL'] for ix in range(8): for iy in range(8): ii = ix * 8 + iy #print ch['PVNAME'],data[ii] xoff = float(ix) / 8 yoff = float(iy) / 8 hh.SetBinContent(xax.FindBin(xx + xoff), yax.FindBin(yy + yoff), data[ii]) # hi.SetBinContent(xax.FindBin(xx+xoff),yax.FindBin(yy+yoff),data[ii]) # for xx in [ttime]: ttime.Clear() # xx.,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(1)