def rooFit106(): print ">>> setup model..." x = RooRealVar("x", "x", -3, 3) mean = RooRealVar("mean", "mean of gaussian", 1, -10, 10) sigma = RooRealVar("sigma", "width of gaussian", 1, 0.1, 10) gauss = RooGaussian("gauss", "gauss", x, mean, sigma) data = gauss.generate(RooArgSet(x), 10000) # RooDataSet gauss.fitTo(data) print ">>> plot pdf and data..." frame = x.frame(Name("frame"), Title("RooPlot with decorations"), Bins(40)) # RooPlot data.plotOn(frame) gauss.plotOn(frame) print ">>> RooGaussian::paramOn - add box with pdf parameters..." # https://root.cern.ch/doc/master/classRooAbsPdf.html#aa43b2556a1b419bad2b020ba9b808c1b # Layout(Double_t xmin, Double_t xmax, Double_t ymax) # left edge of box starts at 20% of x-axis gauss.paramOn(frame, Layout(0.55)) print ">>> RooDataSet::statOn - add box with data statistics..." # https://root.cern.ch/doc/master/classRooAbsData.html#a538d58020b296a1623323a84d2bb8acb # x size of box is from 55% to 99% of x-axis range, top of box is at 80% of y-axis range) data.statOn(frame, Layout(0.20, 0.55, 0.8)) print ">>> add text and arrow..." text = TText(2, 100, "Signal") text.SetTextSize(0.04) text.SetTextColor(kRed) frame.addObject(text) arrow = TArrow(2, 100, -1, 50, 0.01, "|>") arrow.SetLineColor(kRed) arrow.SetFillColor(kRed) arrow.SetLineWidth(3) frame.addObject(arrow) print ">>> persist frame with all decorations in ROOT file..." file = TFile("rooFit106.root", "RECREATE") frame.Write() file.Close() # To read back and plot frame with all decorations in clean root session do # [0] TFile f("rooFit106.root") # [1] xframe->Draw() print ">>> draw functions and toy data on canvas..." canvas = TCanvas("canvas", "canvas", 100, 100, 800, 600) gPad.SetLeftMargin(0.15) gPad.SetRightMargin(0.05) frame.GetYaxis().SetTitleOffset(1.6) frame.GetYaxis().SetLabelOffset(0.010) frame.GetYaxis().SetTitleSize(0.045) frame.GetYaxis().SetLabelSize(0.042) frame.GetXaxis().SetTitleSize(0.045) frame.GetXaxis().SetLabelSize(0.042) frame.Draw() canvas.SaveAs("rooFit106.png")
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 prepare_canvas(c, channels, pad_label=None, x_label=None, y_label=None): pads = dict() # for axis labels c.Divide(1, 1, 0.03, 0.03) c.cd(1).Divide(*divide_square(len(channels))) for i, chans in enumerate(channels): ncol, nrow = divide_square(len(chans)) c.cd(1).cd(i + 1).Divide(nrow, ncol, 0., 0.) # share y axis in the sub-group ymax = 0 for j, ch in enumerate(chans): pads[ch] = c.cd(1).cd(i + 1).cd(j + 1) # labels c.cd(0) htext, vtext = TText(), TText() htext.SetTextSize(0.03) htext.SetTextAlign(22) vtext.SetTextSize(0.03) vtext.SetTextAlign(22) vtext.SetTextAngle(90) if pad_label: htext.DrawText(0.5, 0.982, pad_label) if x_label: htext.DrawText(0.5, 0.015, x_label) if y_label: vtext.DrawText(0.015, 0.5, y_label) return pads
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 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
from ROOT import TCanvas, TF1, TPaveLabel, TPad, TText from ROOT import gROOT nut = TCanvas('nut', 'FirstSession', 100, 10, 700, 900) nut.Range(0, 0, 20, 24) nut.SetFillColor(10) nut.SetBorderSize(2) pl = TPaveLabel(3, 22, 17, 23.7, 'My first PyROOT interactive session', 'br') pl.SetFillColor(18) pl.Draw() t = TText(0, 0, 'a') t.SetTextFont(62) t.SetTextSize(0.025) t.SetTextAlign(12) t.DrawText( 2, 20.3, 'PyROOT provides ROOT bindings for Python, a powerful interpreter.') t.DrawText(2, 19.3, 'Blocks of lines can be entered typographically.') t.DrawText(2, 18.3, 'Previous typed lines can be recalled.') t.SetTextFont(72) t.SetTextSize(0.026) t.DrawText(3, 17, r'>>> x, y = 5, 7') t.DrawText(3, 16, r'>>> import math; x*math.sqrt(y)') t.DrawText( 3, 14, r'>>> for i in range(2,7): print "sqrt(%d) = %f" % (i,math.sqrt(i))') t.DrawText(3, 10, r'>>> import ROOT; f1 = ROOT.TF1( "f1", "sin(x)/x", 0, 10 )')
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)
file.AddText('TFile') file.AddText('Header') arrow = TArrow(6, 20.5, 17, 20.5, 0.02, '|>') arrow.SetFillStyle(1001) arrow.SetLineWidth(2) arrow.Draw() free = TPaveText(8, 20, 11, 21) free.SetFillColor(18) free.Draw() free.AddText('First:Last') free2 = TPaveText(12, 20, 15, 21) free2.SetFillColor(18) free2.Draw() free2.AddText('First:Last') tfree = TText(6.2, 21.2, 'fFree = TList of free blocks') tfree.SetTextSize(0.02) tfree.Draw() tkeys = TText(5.2, 18.2, 'fKeys = TList of Keys') tkeys.SetTextSize(0.02) tkeys.Draw() tmemory = TText(3.2, 15.2, 'fListHead = TList of Objects in memory') tmemory.SetTextSize(0.02) tmemory.Draw() arrow.DrawArrow(5, 17, 17, 17, 0.02, '|>') line = TLine(5, 19, 5, 17) line.SetLineWidth(2) line.Draw() key0 = TPaveText(7, 16, 10, 18) key0.SetTextSize(0.04) key0.SetFillColor(keycolor)
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)
mg.GetYaxis().SetTitleSize(0.05) leg1 = TLegend(0.1, 0.65, 0.6, 0.9) leg1.SetFillColor(0) leg1.SetFillStyle(0) leg1.SetTextSize(0.05) leg1.SetBorderSize(0) leg1.SetTextFont(22) leg1.AddEntry(G1, "M(Z')=5TeV", "l") leg1.AddEntry(G2, "M(Z')=10TeV", "l") leg1.AddEntry(G3, "M(Z')=20TeV", "l") leg1.AddEntry(G4, "M(Z')=40TeV", "l") t = TText() t.SetTextAlign(20) t.SetTextSize(0.03) t.SetTextFont(22) t.SetTextColor(1) label = ["20*20", "5*5", "1*1"] for i in range(3): t.DrawText(i + 1, -0.03, label[i]) c.Draw() mg.Draw() leg.Draw() leg1.Draw() # c.Print("raw_"+str(cut_value)+"_tau21_summary_U_after_cut_25bins_no_UOF.pdf") c.Print("raw_" + str(cut_value) + "_tau21_summary_U_after_cut_25bins_no_UOF_new_75pa.eps") if (variable[k + 1] == "tau32"):
class photon_detector(object): #_____________________________________________________________________________ def __init__(self): #length, height and distance of the front side from the origin, all in m self.length = 8. self.height = 0.15 self.dist = 23.2 self.angle = -0.025 # rotation to be on electron beam axis #_____________________________________________________________________________ def rotate(self, theta): #rotate by angle theta about the origin self.angle += theta #_____________________________________________________________________________ def draw_2d(self): #make corner points vec = [] vec.append(TVector2(self.length / 2, -self.height / 2)) vec.append(TVector2(-self.length / 2, -self.height / 2)) vec.append(TVector2(-self.length / 2, self.height / 2)) vec.append(TVector2(self.length / 2, self.height / 2)) #rotate and translate along electron beam vtrans = TVector2(-1, 0).Rotate(self.angle) vtrans.SetMagPhi(self.dist + self.length / 2, vtrans.Phi()) for i in xrange(len(vec)): vec[i] = vec[i].Rotate(self.angle) vec[i] += vtrans #last point same as the first vec.append(vec[0]) self.geom = TGraph(len(vec)) self.geom.SetLineWidth(2) self.geom.SetLineColor(rt.kYellow + 1) self.geom.SetFillColor(rt.kYellow) for i in xrange(len(vec)): self.geom.SetPoint(i, vec[i].X(), vec[i].Y() * 100) self.geom.Draw("lfsame") #label self.label = TText(vtrans.X(), (vtrans.Y() - self.height / 2 - 0.11) * 100 - 3, "Lumi detector") self.label.SetTextSize(0.03) #self.label.SetTextAngle(90) #self.label.SetTextAlign(32) self.label.SetTextAlign(23) self.label.Draw("same") #label for low Q^2 tagger self.label_tag = TText(vtrans.X() + 2, (vtrans.Y() + 0.6) * 100 - 3, "Place for low-Q2 tagger") self.label_tag.SetTextSize(0.03) #self.label.SetTextAngle(90) #self.label.SetTextAlign(32) self.label_tag.SetTextAlign(23) self.label_tag.Draw("same")
class vmagnet(object): #_____________________________________________________________________________ def __init__(self): #set magnet from configuration dictionary self.name = "" self.center_z = 0. self.center_x = 0. self.length = 0. self.rad1 = 0. self.rad2 = 0. self.field = 0. #electron or hadron self.is_electron = True #initial angle self.theta_0 = 0. #parameters from MAD-X survey self.S = 0. self.L = 0. self.X = 0. self.Z = 0. self.THETA = 0. self.has_survey = False #drawing configuration self.fill_style = 1000 self.label_down = False self.label = "" self.no_label = False self.line_col = rt.kBlue self.fill_col = rt.kGreen - 2 #_____________________________________________________________________________ def read_survey(self, lin): #values from MAD-X survey self.S = float(lin["S"]) self.L = float(lin["L"]) self.X = float(lin["X"]) self.Z = float(lin["Z"]) self.THETA = float(lin["THETA"]) + self.theta_0 self.has_survey = True #_____________________________________________________________________________ def rotate_translateX(self, theta, xt): #combined rotation and translation self.rotate(theta) self.translateX(xt) #_____________________________________________________________________________ def translateX(self, xt): #translate the magnet along x self.center_x += xt #_____________________________________________________________________________ def rotate(self, theta): #rotate by angle theta about the origin #get new center_z and center_x by TVector2 rotation vec = TVector2(self.center_z, self.center_x).Rotate(theta) self.center_z = vec.X() self.center_x = vec.Y() #rotate along magnet center self.THETA = self.THETA - theta #_____________________________________________________________________________ def draw_2d(self): #draw only magnets with survey defined if not self.has_survey: return #self.draw_box() self.draw_graph() #_____________________________________________________________________________ def draw_graph(self): #inner and outer radius if self.center_z < 0: rad_right = self.rad1 rad_left = self.rad2 else: rad_right = self.rad2 rad_left = self.rad1 #edge points of the magnet vec = [] vec.append(TVector2(self.length / 2, rad_right)) vec.append(TVector2(self.length / 2, -rad_right)) vec.append(TVector2(-self.length / 2, -rad_left)) vec.append(TVector2(-self.length / 2, rad_left)) #rotate along magnet axis and move to magnet center vpos = TVector2(self.center_z, self.center_x) for i in xrange(len(vec)): vec[i] = vec[i].Rotate(-self.THETA) + vpos #export points to the graph self.gbox = TGraph(len(vec) + 1) self.gbox.SetLineColor(self.line_col) self.gbox.SetLineWidth(2) self.gbox.SetFillStyle(self.fill_style) self.gbox.SetFillColor(self.fill_col) for i in xrange(len(vec)): self.gbox.SetPoint(i, vec[i].X(), 100 * vec[i].Y()) #last point same as the first self.gbox.SetPoint(len(vec), vec[0].X(), 100 * vec[0].Y()) self.gbox.Draw("lfsame") #label if self.no_label: return #lx = (self.center_x + self.rad2)*100 + 4 lx = (self.center_x + (self.rad1 + self.rad2) / 2) * 100 + 4 if lx < 30: lx = 30 align = 12 #left down if (self.center_z < 0 and not self.is_electron) or self.label_down: lx = (self.center_x - self.rad2) * 100 - 4 align = 32 #right down if self.center_z > 0 and self.is_electron: lx = (self.center_x - self.rad2) * 100 - 4 if lx > -25: lx = -25 align = 32 #label above the magnet if self.center_x < -0.4: lx = (self.center_x + self.rad2) * 100 + 4 align = 12 if self.label == "": self.label = self.name #self.glabel = TText(self.center_z, lx, self.label) self.glabel = TLatex(self.center_z, lx, self.label) self.glabel.SetTextSize(0.03) #self.glabel.SetTextSize(0.02) self.glabel.SetTextAngle(90) self.glabel.SetTextAlign(align) self.glabel.Draw("same") #_____________________________________________________________________________ def draw_box(self): z1 = self.center_z - self.length / 2 z2 = z1 + self.length x1 = self.center_x - self.rad2 x2 = x1 + 2 * self.rad2 #to cm x1 *= 100 x2 *= 100 #representation as a box self.box = TFrame(z1, x1, z2, x2) self.box.SetBorderMode(0) self.box.SetFillColor(rt.kGray + 1) col = rt.kRed if self.is_electron == True: col = rt.kBlue self.box.SetLineColor(col) self.box.SetLineWidth(2) #self.box.Draw("same") #label lx = x2 + 2 align = 11 if lx < 0 and lx > -62: lx = x1 - 5 # negative lx align = 31 if self.center_z < 0 and self.center_x < 0.1: lx = x1 - 2 # negative z and x align = 31 if lx > 0 and lx < 22: lx = 22 # small positive lx self.label = TText(z2, lx, self.name) self.label.SetTextSize(0.03) self.label.SetTextAngle(90) self.label.SetTextAlign(align)
class exit_window(object): #photon exit window, part of electron beam pipe, rear side #_____________________________________________________________________________ def __init__(self, geom): #input points, in electron beamline frame if geom == "flat": self.pos = [(-21.7, -5), (-21.7, 5)] # flat geometry if geom == "tilt": self.pos = [(-18.8, -5), (-21.7, 5)] # tilted geometry #print the geometry self.print_position() #points in z and x, both in m self.zx_pos = [] for i in self.pos: # z at 0 and x at 1, converted to cm self.zx_pos.append(TVector2(i[0], 0.01 * i[1])) #angle of initial rotation self.rotate(-0.008) #_____________________________________________________________________________ def rotate(self, theta): #rotate by angle theta about the origin for i in xrange(len(self.zx_pos)): self.zx_pos[i] = self.zx_pos[i].Rotate(theta) #_____________________________________________________________________________ def draw_2d(self): #draw the exit window self.geom = TGraph(len(self.zx_pos)) self.geom.SetLineColor(rt.kGreen + 1) self.geom.SetLineWidth(4) ipoint = 0 for i in self.zx_pos: self.geom.SetPoint(ipoint, i.X(), 100 * i.Y()) ipoint += 1 self.geom.Draw("lsame") #label zpos = (self.zx_pos[0].X() + self.zx_pos[1].X()) / 2. self.label = TText(zpos, (self.zx_pos[0].Y()) * 100 - 6, "Exit window") self.label.SetTextSize(0.03) #self.label.SetTextAngle(90) #self.label.SetTextAlign(32) self.label.SetTextAlign(23) #self.label.Draw("same") #_____________________________________________________________________________ def print_position(self): #show position and angle of the exit window z1 = self.pos[0][0] * 1e3 # to mm z2 = self.pos[1][0] * 1e3 x1 = self.pos[0][1] * 10. # to mm x2 = self.pos[1][1] * 10. print "z_mid:", (z1 + z2) / 2., "mm" print "x_mid:", (x1 + x2) / 2., "mm" #length in x-z plane dl = math.sqrt((z1 - z2)**2 + (x1 - x2)**2) print "len:", dl, "mm" #angle in x-z plane dz = abs(z2 - z1) dx = abs(x2 - x1) #theta = math.atan( dx/dz ) theta = math.asin(dx / dl) print "dz:", dz, "mm" print "dx:", dx, "mm" print "theta:", theta, "rad" print "pi/2 - theta:", math.pi / 2. - theta, "rad"
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
# Integrated luminosity in fb-1s intlumi = 19.712 # ABCD # set root styles plotTools.SetBoostStyle() tdrstyle.setTDRStyle() ######################################################## # Make comparison of gen level W pt hname = "h_MR_jet1ptg200" htitle = "" xt = "M_{R} (GeV)" legd4 = plotTools.ConstructLDict(0.35, 0.9, 0.6, 0.87) text1 = TText(0.73, 0.55, "T1t1t model") text1.SetNDC() text1.SetTextSize(0.04) hdict_bg = plotTools.ConstructHDict(infile_bg.Get(hname), name="Total background", color=rt.kCyan - 8, fillstyle=3003, linewidth=0, title=htitle, xtitle=xt) hdict_T1t1t_600_225_50 = plotTools.ConstructHDict( infile_T1t1t_600_225_50.Get(hname), name= "m_{#tilde{g}} = 600 GeV, m_{#tilde{t}_{1}} = 225 GeV, m_{#tilde{#chi}_{1}^{0}} = 50 GeV", #name="#splitline{m_{#tilde{g}} = 600 GeV, m_{#tilde{t}_{1}} = 225 GeV,}{m_{#tilde{#chi}_{1}^{0}} = 50 GeV}", color=rt.kCyan + 2, title=htitle, xtitle=xt)
def MCSPlot(self, pname): #print self.fname f = TFile(self.fname) self.RMS = {} self.RMSErr = {} self.Chi2 = {} self.RMSsysdiff = {} self.RMSsyserr = {} # create a plot for each histvarname for histvar in self.histvarnames: self.RMS[histvar] = {} self.RMSErr[histvar] = {} self.RMSsysdiff[histvar] = {} self.RMSsyserr[histvar] = {} self.Chi2[histvar] = {} names = [histvar + '_' + x for x in self.histstatenames] print names hists = [f.Get(histvar + '_' + x) for x in self.histstatenames] print hists[0] hists[0].SetTitle("") # hists[3].Scale(norm) # self.formatHist(hist[0], 0) resplots = [x.Clone() for x in hists] resplots[0].SetTitle('') resplots[0].GetYaxis().SetTitle("Normalized Residuals") # if histvar == 'thetaScatt': leg = TLegend(0.55, 0.73, 0.89, 0.92) leg.SetLineColor(10) # else: # leg = TLegend(0.35,0.2,0.65,0.5) for i in range(len(self.histstatedesc)): hists[i].Sumw2() if histvar == 'theta2Scatt': hists[i].Rebin(8) resplots[i].Rebin(8) elif histvar == 'thetaScatt': hists[i].Rebin(1) resplots[i].Rebin(1) else: hists[i].Rebin(1) resplots[i].Rebin(1) self.formatHists(hists[i], i) self.formatHists(resplots[i], i) self.addToRMS(i, hists[i], hists[0], resplots[i], histvar) if histvar == 'theta2Scatt': hists[i].GetYaxis().SetTitle('Probability per ' + str( round(1000 * 1000 * hists[i].GetXaxis().GetBinWidth(4), 2)) + ' mrad^{2}') else: hists[i].GetYaxis().SetTitle('Probability per ' + str( round(1000 * hists[i].GetXaxis().GetBinWidth(4), 2)) + ' mrad') leg.AddEntry(hists[i], self.histstatedesc[i], self.histopts[i]) #print hists[0] self.calculateChi2(i, hists[i], hists[0], resplots[i], histvar, pname) c = TCanvas(self.fname[:-5] + '_' + histvar + '_c1') if self.desc[0] == 'XePion': t1 = TText(0.18, 0.885, "MICE ISIS cycle 2015/03") t2 = TText(0.18, 0.85, "Xe, " + self.desc[1][2:5] + ", MAUS v3.1.2") else: t1 = TText(0.18, 0.885, "MICE ISIS cycle 2015/04") t2 = TText(0.18, 0.85, "LiH, " + self.desc[1][2:5] + ", MAUS v3.1.2") t1.SetNDC(1) t1.SetTextSize(0.04) t1.SetTextFont(42) t2.SetNDC(1) t2.SetTextSize(0.03) t2.SetTextFont(42) hists[0].GetYaxis().SetRangeUser(4e-4, 2.0) hists[0].SetTitle(";" + hists[0].GetXaxis().GetTitle() + " (radians);" + hists[0].GetYaxis().GetTitle()) hists[0].Draw('ep') c.SetBottomMargin(0.15) c.SetTopMargin(0.075) for h in hists[1:len(self.histstatedesc)]: h.Draw('epsame') leg.SetTextSize(0.04) leg.Draw('same') t1.Draw() t2.Draw() c.SetLogy() c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar + '_sys.eps') c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar + '_sys.root') c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar + '_sys_pq.jpg') c.Clear() c.SetLogy(0) resplots[0].GetYaxis().SetRangeUser(-2, 2) resplots[0].SetTitle(";" + resplots[0].GetXaxis().GetTitle() + " (radians);" + resplots[0].GetYaxis().GetTitle()) leg.SetX1NDC(0.5) leg.SetX2NDC(0.89) leg.SetY1NDC(0.2) leg.SetY2NDC(0.4) resplots[0].Draw("p") for r in resplots: r.Draw('psame') leg.SetTextSize(0.04) leg.Draw('same') t1.Draw() t2.Draw() # pblock.Draw() c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar + '_sys_res_T.eps') c.SaveAs(pname + '_' + self.fname[:-5] + '_' + histvar + '_sys_res_pq.jpg') momhist = f.Get("cor_mom") #mom = [momhist.GetMean() + 19.468, momhist.GetMeanError()] #if self.fname.find("LiHMuon_03172") >= 0: # mom = [momhist.GetMean()*1.107 + 1.05, momhist.GetMeanError()] #elif self.fname.find("LiHMuon_03200") >= 0: # mom = [momhist.GetMean()*1.104 + 1.139, momhist.GetMeanError()] #elif self.fname.find("LiHMuon_03240") >= 0: # mom = [momhist.GetMean()*1.17 - 9.41, momhist.GetMeanError()] if self.fname.find("LiHMuon_03172") >= 0: mom = [momhist.GetMean(), momhist.GetMeanError()] elif self.fname.find("LiHMuon_03200") >= 0: mom = [momhist.GetMean(), momhist.GetMeanError()] elif self.fname.find("LiHMuon_03240") >= 0: mom = [momhist.GetMean(), momhist.GetMeanError()] rms = [momhist.GetRMS(), momhist.GetRMSError()] summary = [] syssummary = [] def sigfig(x): if math.fabs(x) > 1e-5: return int(math.ceil(math.fabs(math.log(math.fabs(x), 10)))) else: return 1 # syssummary.append("p (MeV/c) & "+self.histvarnames[0]+"&"+self.histvarnames[1]+"&"+self.histvarnames[3]+"\\\\") if pname != "Truth": for sys in self.sysFiles: # if sys[3] == 'Material': stindx = 1 # else: stindx = 0 # print sys[3], self.histstatenames[stindx] difference0 = self.RMSsysdiff[self.histvarnames[0]][ self.histstatenames[stindx]][sys[3]] difference1 = self.RMSsysdiff[self.histvarnames[1]][ self.histstatenames[stindx]][sys[3]] difference3 = self.RMSsysdiff[self.histvarnames[3]][ self.histstatenames[stindx]][sys[3]] syserr0 = self.RMSsyserr[self.histvarnames[0]][ self.histstatenames[stindx]][sys[3]] syserr1 = self.RMSsyserr[self.histvarnames[1]][ self.histstatenames[stindx]][sys[3]] syserr3 = self.RMSsyserr[self.histvarnames[3]][ self.histstatenames[stindx]][sys[3]] relerr0 = syserr0 / self.RMS[self.histvarnames[0]][ self.histstatenames[0]] relerr1 = syserr1 / self.RMS[self.histvarnames[1]][ self.histstatenames[0]] relerr3 = syserr3 / self.RMS[self.histvarnames[3]][ self.histstatenames[0]] syssummary.append(str(round(mom[0],sigfig(mom[1])))+"$\pm$"+str(round(mom[1],sigfig(mom[1])))+\ " & "+str(round(difference0,sigfig(difference0)))+\ " & "+str(round(syserr0,sigfig(syserr0)))+\ " & "+str(round(relerr0,sigfig(relerr0)))+\ " & "+str(round(difference1,sigfig(difference1)))+\ " & "+str(round(syserr1,sigfig(syserr1)))+\ " & "+str(round(relerr1,sigfig(relerr1)))+\ " & "+str(round(difference3,sigfig(difference3)))+\ " & "+str(round(syserr3,sigfig(syserr3)))+\ " & "+str(round(relerr3,sigfig(relerr3)))+"\\\\") # print syssummary[-1] syssummary.append(str(round(mom[0],2))+"$\pm$"+str(round(mom[1],2))+\ " & "+ str(round(rms[0],2))+"$\pm$"+str(round(rms[1],2))+\ " & "+str(round(self.RMSsysdiff[self.histvarnames[0]][self.histstatenames[0]]['Sum'],2))+\ " & "+str(round(self.RMSsyserr[self.histvarnames[0]][self.histstatenames[0]]['Sum'],2))+\ " & "+str(round(self.RMSsyserr[self.histvarnames[0]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[0]][self.histstatenames[0]],2))+\ " & "+str(round(self.RMSsysdiff[self.histvarnames[1]][self.histstatenames[0]]['Sum'],2))+\ " & "+str(round(self.RMSsyserr[self.histvarnames[1]][self.histstatenames[0]]['Sum'],2))+\ " & "+str(round(self.RMSsyserr[self.histvarnames[1]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[1]][self.histstatenames[0]],2))+\ " & "+str(round(self.RMSsysdiff[self.histvarnames[3]][self.histstatenames[0]]['Sum'],2))+ " & "+str(round(self.RMSsyserr[self.histvarnames[3]][self.histstatenames[0]]['Sum'],2))+ " & "+str(round(self.RMSsyserr[self.histvarnames[3]][self.histstatenames[0]]['Sum']/self.RMS[self.histvarnames[2]][self.histstatenames[0]],2))+"\\\\") # summary.append("p (MeV/c) & &"+str(self.histstatenames[0])+" & "+str(self.histstatenames[1])+" & $\chi^{2}$/ndf & "+ # +str(self.histstatenames[2])+" & $\chi^{2}$/ndf \\\\") # print mom, self.RMS, self.RMSErr, self.Chi2 for histvar in self.histvarnames: summary.append(str(round(mom[0],2))+"$\pm$"+str(round(mom[1],2))+\ "& $\ "+histvar+"$ & "+str(round(self.RMS[histvar][self.histstatenames[0]],2))+ \ "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[0]],2))+ \ "$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[0]]["Sum"],2))+ \ " & "+str(round(self.RMS[histvar][self.histstatenames[1]],2))+ \ "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[1]],2))+ \ # "$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[1]]["Sum"],2))+\ " & "+str(round(self.Chi2[histvar][self.histstatenames[1]][0],1))+ \ " / "+ str(self.Chi2[histvar][self.histstatenames[1]][1])+ \ " & "+str(round(self.RMS[histvar][self.histstatenames[2]],2))+ \ "$\pm$"+str(round(self.RMSErr[histvar][self.histstatenames[2]],2))+ \ #"$\pm$"+str(round(self.RMSsyserr[histvar][self.histstatenames[2]]["Sum"],2))+\ " & "+str(round(self.Chi2[histvar][self.histstatenames[2]][0],1))+ \ " / "+ str(self.Chi2[histvar][self.histstatenames[2]][1]) +"\\\\") # print summary[-1] f.Close() return [summary, syssummary]
arrow = TArrow( 7, 11.5, 7, 11.1, 0.01, '|>' ) arrow.SetFillStyle( 1001 ) arrow.Draw() line.DrawLine( 7, 8.5, 7, 8.0 ) line.DrawLine( 7, 8.0, 10.6, 8 ) arrow.DrawArrow( 10.6,8, 10.6, 8.4, 0.01, '|>' ) line.DrawLine( 10.6, 11, 10.6, 11.5 ) line.DrawLine( 10.6, 11.5, 14.6, 11.5 ) arrow.DrawArrow( 14.6, 11.5, 14.6, 11.1, 0.01, '|>' ) line.DrawLine( 14.6, 8.5, 14.6, 8.0 ) line.DrawLine( 14.6, 8.0, 16, 8 ) ldot.DrawLine( 16, 8, 19, 8 ) vert = TText( 1.5, 9.75, 'File' ) vert.SetTextAlign( 21 ) vert.SetTextAngle( 90 ) vert.SetTextSize( 0.025 ) vert.Draw() vert.DrawText( 2.0, 9.75, 'Header' ) vert.DrawText( 2.9, 9.75, 'Logical Record' ) vert.DrawText( 3.2, 9.75, 'Header' ) vert.DrawText( 7.3, 9.75, 'Logical Record' ) vert.DrawText( 7.6, 9.75, 'Header' ) vert.DrawText( 10.9, 9.75, 'Logical Record' ) vert.DrawText( 11.2, 9.75, 'Header' ) vert.DrawText( 14.9, 9.75, 'Logical Record' ) vert.DrawText( 15.2, 9.75, 'Header' ) hori = TText( 4.75, 10, 'Object' ) hori.SetTextAlign( 22 ) hori.SetTextSize( 0.035 ) hori.Draw() hori.DrawText( 4.75, 9.5, 'Data' )
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)
c1.SetLogy() h_1.Draw() t_task = TText(0.35,0.8,'Task '+ task + " SIGNET" ) t_task.SetNDC() t_task.Draw() #print time stamp t_time = datetime.now() t_label = 'SP ' + t_time.strftime("%Y-%m-%d") t = TText(0.905,0.6,t_label) t.SetNDC() t.SetTextAlign(21) # middle, bottom t.SetTextAngle(-90) t.SetTextSize(0.017) t.Draw() c1.Modified() c1.Update() # optional wait for keypress input = raw_input('Press Enter to continue, E to exit') if 'E' in input: c1.Close() h_2.SetFillColor(37) h_2.GetYaxis().SetTitleOffset(1.2) h_2.SetYTitle('Entries') h_2.SetXTitle('Time, min.')
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 setLHCbStyle(): global lhcbStyle global lhcbText global lhcbLatex lhcbStyle = TStyle("lhcbStyle", "Standard LHCb plots style") # use times new roman lhcbFont = 132 # line thickness lhcbWidth = 2 lhcbTSize = 0.06 #// use plain black on white colors lhcbStyle.SetFrameBorderMode(0) lhcbStyle.SetCanvasBorderMode(0) lhcbStyle.SetPadBorderMode(0) lhcbStyle.SetPadColor(0) lhcbStyle.SetCanvasColor(0) lhcbStyle.SetStatColor(0) lhcbStyle.SetPalette(1) lhcbStyle.SetLegendBorderSize(0) lhcbStyle.SetLegendFont(132) lhcbStyle.SetFillColor(1) lhcbStyle.SetFillStyle(1001) # set the paper & margin sizes lhcbStyle.SetPaperSize(20, 26) lhcbStyle.SetPadTopMargin(0.1) lhcbStyle.SetPadRightMargin(0.05) lhcbStyle.SetPadBottomMargin(0.16) lhcbStyle.SetPadLeftMargin(0.14) # use large fonts lhcbStyle.SetTextFont(lhcbFont) lhcbStyle.SetTextSize(lhcbTSize) # lhcbStyle.SetTextSize(0.08) lhcbStyle.SetLabelFont(lhcbFont, "x") lhcbStyle.SetLabelFont(lhcbFont, "y") lhcbStyle.SetLabelFont(lhcbFont, "z") lhcbStyle.SetLabelSize(lhcbTSize, "x") lhcbStyle.SetLabelSize(lhcbTSize, "y") lhcbStyle.SetLabelSize(lhcbTSize, "z") lhcbStyle.SetTitleFont(lhcbFont) lhcbStyle.SetTitleFont(lhcbFont, "x") lhcbStyle.SetTitleFont(lhcbFont, "y") lhcbStyle.SetTitleFont(lhcbFont, "z") lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "x") lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "y") lhcbStyle.SetTitleSize(1.2 * lhcbTSize, "z") # use bold lines and markers lhcbStyle.SetLineWidth(lhcbWidth) lhcbStyle.SetFrameLineWidth(lhcbWidth) lhcbStyle.SetHistLineWidth(lhcbWidth) lhcbStyle.SetFuncWidth(lhcbWidth) lhcbStyle.SetGridWidth(lhcbWidth) lhcbStyle.SetLineStyleString(2, "[12 12]") lhcbStyle.SetMarkerStyle(20) lhcbStyle.SetMarkerSize(1.0) # label offsets lhcbStyle.SetLabelOffset(0.010) #titles lhcbStyle.SetTitleOffset(0.95, "X") lhcbStyle.SetTitleOffset(0.95, "Y") lhcbStyle.SetTitleOffset(1.2, "Z") lhcbStyle.SetTitleFillColor(0) lhcbStyle.SetTitleStyle(0) lhcbStyle.SetTitleBorderSize(0) lhcbStyle.SetTitleFont(lhcbFont, "title") lhcbStyle.SetTitleX(0.0) lhcbStyle.SetTitleY(1.0) lhcbStyle.SetTitleW(1.0) lhcbStyle.SetTitleH(0.05) # by default, do not display histogram decorations: lhcbStyle.SetOptStat(0) #lhcbStyle.SetOptStat("emr") # show only nent -e , mean - m , rms -r #lhcbStyle.SetStatFormat("6.3g") # specified as c printf options lhcbStyle.SetOptTitle(0) lhcbStyle.SetOptFit(0) #lhcbStyle.SetOptFit(1011) # order is probability, Chi2, errors, parameters # look of the statistics box: lhcbStyle.SetStatBorderSize(0) lhcbStyle.SetStatFont(lhcbFont) lhcbStyle.SetStatFontSize(0.05) lhcbStyle.SetStatX(0.93) lhcbStyle.SetStatY(0.88) lhcbStyle.SetStatW(0.20) lhcbStyle.SetStatH(0.15) # put tick marks on top and RHS of plots lhcbStyle.SetPadTickX(1) lhcbStyle.SetPadTickY(1) # histogram divisions: only 5 in x to avoid label overlaps lhcbStyle.SetNdivisions(505, "x") lhcbStyle.SetNdivisions(505, "y") lhcbStyle.SetNdivisions(505, "z") # define style for text lhcbLabel = TText() lhcbLabel.SetTextFont(lhcbFont) lhcbLabel.SetTextColor(1) lhcbLabel.SetTextSize(0.04) lhcbLabel.SetTextAlign(12) # define style of latex text lhcbLatex = TLatex() lhcbLatex.SetTextFont(lhcbFont) lhcbLatex.SetTextColor(1) lhcbLatex.SetTextSize(0.04) lhcbLatex.SetTextAlign(12) # set this style gROOT.SetStyle("lhcbStyle") gROOT.ForceStyle() return
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)
ar1.DrawArrow(.70, .775, .79, .775, 0.015, '|>') ar1.DrawArrow(.50, .275, .59, .275, 0.015, '|>') ar1.DrawArrow(.70, .275, .79, .275, 0.015, '|>') ar1.DrawArrow(.45, .175, .54, .175, 0.015, '|>') ar1.DrawArrow(.43, .075, .54, .075, 0.015, '|>') ar1.DrawArrow(.41, -.025, .54, -.025, 0.015, '|>') ldot = TLine(.95, .92, .99, .92) ldot.SetLineStyle(3) ldot.Draw() ldot.DrawLine(.9, .775, .99, .775) ldot.DrawLine(.9, .275, .99, .275) ldot.DrawLine(.55, .05, .55, 0) ldot.DrawLine(.9, .05, .75, 0) pname = TText(.46, .21, 'fEventOffset') pname.SetTextFont(72) pname.SetTextSize(0.018) pname.Draw() pname.DrawText(.44, .11, 'fBuffer') pname.DrawText(.42, .01, 'fZipBuffer') pname.DrawText(.26, .81, 'fLeaves = TObjArray of TLeaf') pname.DrawText(.24, .40, 'fBasketEvent') pname.DrawText(.22, .31, 'fBaskets = TObjArray of TBasket') pname.DrawText(.20, 1.0, 'fBranches = TObjArray of TBranch') ntleaf = TPaveText(0.30, .42, .62, .7) ntleaf.SetTextSize(0.014) ntleaf.SetFillColor(leafcolor) ntleaf.SetTextAlign(12) ntleaf.AddText('fLen: number of fixed elements') ntleaf.AddText('fLenType: number of bytes of data type') ntleaf.AddText('fOffset: relative to Leaf0-fAddress') ntleaf.AddText('fNbytesIO: number of bytes used for I/O')
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)