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 D1H_txt_to_root(filename, outputpath=''): from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText from inspect import currentframe, getframeinfo #gStyle.SetOptStat(0) can = TCanvas("can", "can", 200, 10, 500, 500) fileroot = filename.replace(".txt", "") fileroot = fileroot + "_F.root" f = open(filename, "r") lineList = f.readlines() Nbin = (len(lineList)) # get number of bins Line_string = str(lineList[0]) _, bin_init, _, _ = Line_string.split() bin_init = float(bin_init) # get initial bin Line_string = str(lineList[len(lineList) - 1]) _, _, bin_final, _ = Line_string.split() bin_final = float(bin_final) # get final bin f.seek(0) # reset python read line hist = TH1D("h1f", "h1f", Nbin, bin_init, bin_final) total_e = 0 for i in range(1, Nbin + 1): Line_string = str(f.readline()) _, _, _, bin_c = Line_string.split() bin_c = float(bin_c) hist.SetBinContent(i, bin_c) total_e = total_e + bin_c total_e = int(total_e) hist.Draw() text = TText(hist.GetXaxis().GetBinCenter(2), hist.GetYaxis().GetBinCenter(1), "Recycled. Total Entry : %i" % total_e) text.SetTextFont(10) text.Draw() gPad.Update() can.Update() if (outputpath == ''): wf = TFile(fileroot, "RECREATE") print(fileroot, " root file is generated !!!") else: fileroot = outputpath + "/_processed.root" wf = TFile(fileroot, "RECREATE") print(fileroot, " root file is generated !!!") hist.Write() wf.Close() return fileroot
def D1H_txt_to_roothist(filename, outputpath=''): from ROOT import TFile, TCanvas, TPad, TH1D, TLatex, TStyle, gStyle, TText, gPad, TPaveText from inspect import currentframe, getframeinfo import os #gStyle.SetOptStat(0) can = TCanvas("can", "can", 200, 10, 500, 500) if (filename[0] == "/"): filename = filename else: filename = os.getcwd( ) + "/" + filename # get the path included filename loca = len(filename) for i in range(1, len(filename) + 1): # find the "/" location if (filename[-i] == "/"): loca = i - 1 break FILENAME = filename.replace(filename[:-loca], "") # this is the shorten filename # print(FILENAME, "******") fileroot = filename.replace(".txt", "_F.root") fileroot = fileroot.replace("//", "/") f = open(filename, "r") lineList = f.readlines() Nbin = (len(lineList)) # get number of bins Line_string = str(lineList[0]) _, bin_init, _, _ = Line_string.split() bin_init = float(bin_init) # get initial bin Line_string = str(lineList[len(lineList) - 1]) _, _, bin_final, _ = Line_string.split() bin_final = float(bin_final) # get final bin f.seek(0) # reset python read line hist = TH1D("hist", "hist", Nbin, bin_init, bin_final) total_e = 0 for i in range(1, Nbin + 1): Line_string = str(f.readline()) _, _, _, bin_c = Line_string.split() bin_c = float(bin_c) hist.SetBinContent(i, bin_c) total_e = total_e + bin_c total_e = int(total_e) hist.Draw() text = TText(hist.GetXaxis().GetBinCenter(2), hist.GetYaxis().GetBinCenter(1), "Recycled. Total Entry : %i" % total_e) text.SetTextFont(10) text.Draw() gPad.Update() can.Update() if (outputpath == ''): wf = TFile(fileroot, "RECREATE") print(fileroot, " root file is generated !!!") else: if (outputpath[0] == "/"): fileroot = outputpath + "/" + FILENAME.replace(".txt", "_F.root") fileroot = fileroot.replace("//", "/") elif (outputpath[0] == "~"): fileroot = outputpath.replace( "~", os.environ['HOME']) + "/" + FILENAME.replace( ".txt", "_F.root") fileroot = fileroot.replace("//", "/") else: fileroot = os.getcwd() + "/" + outputpath + "/" + FILENAME.replace( ".txt", "_F.root") fileroot = fileroot.replace("//", "/") wf = TFile(fileroot, "RECREATE") print(fileroot, " root file is generated !!!") hist.Write() wf.Close() fileroot = fileroot.replace("//", "/") # print(fileroot) return fileroot
ar1.DrawArrow(.50, .775, .59, .775, 0.015, '|>') 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')
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
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 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 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]
#c1.Range() hs= THStack("hs","") 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
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"): f1 = ROOT.TFile.Open(
_,bin_final,_ = Line_string.split(); bin_final = float(bin_final) # get final bin f.seek(0) # reset python read line hist = TH1D("h1f","h1f",Nbin,bin_init,bin_final) total_e = 0 for i in range(1,Nbin+1): Line_string = str(f.readline()) _,_,bin_c = Line_string.split(); bin_c = float(bin_c) hist.SetBinContent(i,bin_c) total_e = total_e + bin_c total_e = int(total_e) hist.Draw() print(hist.GetMaximumBin()) text = TText(hist.GetXaxis().GetBinCenter(2), hist.GetYaxis().GetBinCenter(1), "Recycled. Total Entry : %i" %total_e) text.SetTextFont(10) text.Draw() gPad.Update() can.Update() ''' pave1 = TPaveText(0.1,0.1,0.9,0.98); pave1.SetFillColor(42); pave1.AddText("Recycled") pave1.Draw() gPad.Update() can.Update() ''' ''' ## I have tried to modified and upload the stats box, but failed.. is this differenct from C++??