def CMSPrelim(dataset, channel, lowX, lowY): cmsprel = TPaveText(lowX, lowY + 0.06, lowX + 0.30, lowY + 0.16, "NDC") cmsprel.SetBorderSize(0) cmsprel.SetFillStyle(0) cmsprel.SetTextAlign(12) cmsprel.SetTextSize(0.04) cmsprel.SetTextColor(1) cmsprel.SetTextFont(62) cmsprel.AddText(dataset) ## lumi = TPaveText(lowX+0.38, lowY+0.061, lowX+0.45, lowY+0.161, "NDC") ## lumi.SetBorderSize( 0 ) ## lumi.SetFillStyle( 0 ) ## lumi.SetTextAlign( 12 ) ## lumi.SetTextSize ( 0.04 ) ## lumi.SetTextColor( 1 ) ## lumi.SetTextFont ( 62 ) ## lumi.AddText(dataset) chan = TPaveText(lowX + 0.68, lowY + 0.061, lowX + 0.80, lowY + 0.161, "NDC") chan.SetBorderSize(0) chan.SetFillStyle(0) chan.SetTextAlign(12) chan.SetTextSize(0.05) chan.SetTextColor(1) chan.SetTextFont(62) chan.AddText(channel) return cmsprel, chan
def plot(obj, plot_name, plot_notes=[]): canvas = TCanvas('canvas' + plot_name, "Canvas", 450, 450) gPad.SetLeftMargin(.13) gPad.SetTopMargin(.05) gStyle.SetOptStat(11) gStyle.SetOptFit(1111) if 'TH2' in obj.ClassName(): gPad.SetRightMargin(.13) draw_options = 'COLZ' if 'profile' in obj.GetName(): gPad.SetRightMargin(.05) draw_options = '' if 'graph' in obj.GetName(): gPad.SetRightMargin(.05) draw_options = 'APE' obj.SetMarkerSize(.7) obj.SetMarkerStyle(21) note = TPaveText(.2, .7, .5, .9, "brNDC") note.SetFillStyle(0) note.SetFillColor(0) note.SetBorderSize(0) note.SetTextColor(1) note.SetTextFont(42) note.SetTextAlign(11) for note_text in plot_notes: note.AddText(note_text) obj.Draw(draw_options) note.Draw() canvas.Print('output/' + plot_name + '.pdf')
def makePage( algorithm , pagename , cdash = False, prefix=""): from ROOT import TCanvas,kBlue,kRed,gROOT,kGreen,kYellow gROOT.SetBatch(True) c=TCanvas( algorithm.output.name , algorithm.output.name ) c.Divide(1,2) from Interface import Result aColor = None if algorithm.output.result == Result.FAILED: aColor = kRed if algorithm.output.result == Result.NOTPASSED: aColor = kYellow if algorithm.output.result == Result.SUCCESS: aColor = kGreen if aColor: c.SetFillColor( aColor ) aPad = c.cd(1) from Utils import draw lims = () if "TH1" not in algorithm.test.dataset1.__class__.__name__: lims = ( 100, min( algorithm.test.dataset1.tolist() + algorithm.test.dataset2.tolist() ), max( algorithm.test.dataset1.tolist() + algorithm.test.dataset2.tolist() ) ) h1=draw( algorithm.test.dataset1 , kBlue , "" , lims , algorithm.output.name ) h1.SetName(h1.GetName()+"_new") aPad.Update() from ROOT import TPaveStats statBox = h1.GetListOfFunctions().FindObject("stats") statBox.SetName('new_stat') statBox.SetY1NDC(statBox.GetY1NDC()-.18) statBox.SetY2NDC(statBox.GetY2NDC()-.18) statBox.SetTextColor(kBlue) statBox.SetBorderSize(2) h2=draw( algorithm.test.dataset2 , kRed , "sames", lims , algorithm.output.name+"ref") h2.SetName(h2.GetName()+"_ref") aPad.Update() statBox2 = h2.GetListOfFunctions().FindObject("stats") statBox2.SetName('ref_stat') statBox2.SetTextColor(kRed) from ROOT import TPaveText pave=TPaveText(0.02,0.85,0.35,0.99,"NDC") pave.SetTextColor(aColor) pave.SetFillColor(1) pave.AddText(" %s "%algorithm.output.result) pave.AddText("(p-val: %s Test: %s)"%(algorithm.output.value, algorithm.test.__class__.__name__)) pave.Draw() c.cd(2) if 'residuals' in algorithm.test.__dict__: algorithm.test.residuals.Draw() else: from Utils import makeResiduals algorithm.test.residuals = makeResiduals( h1 , h2 ) algorithm.test.residuals.Draw() c.Print(pagename+prefix) # only print CDASH info if the test has failed (saves space on webserver) if cdash == True and not (algorithm.output.result == Result.SUCCESS): import os c.Print(os.path.dirname(pagename)+"/"+algorithm.output.name.replace('/','_')+".png") print " <DartMeasurementFile name=\"" + algorithm.output.name + "\" type=\"image/png\"> " + os.path.dirname(pagename) + "/" + algorithm.output.name.replace('/','_') + ".png" + " </DartMeasurementFile>"
def prelimLabel(): label = TPaveText( 0.2, 0.9, 0.27, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(31) label.AddText( "#font[62]{CMS} #font[52]{Preliminary}" ) label.SetTextSize(0.03) label.SetTextColor( 1 ) return label
def simLabel(): label = TPaveText( 0.12, 0.9, 0.18, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(11) label.AddText( "#font[62]{CMS} #font[52]{Simulation}" ) label.SetTextSize(0.035) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def selectionLabel(text): label = TPaveText( 0.15, 0.9, 0.23, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( text ) label.SetTextSize( 0.048 ) label.SetTextAlign(11) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def lumiLabel(): label = TPaveText( 0.72, 0.9, 0.8, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( "37.19 fb^{-1} (13 TeV)" ) label.SetTextSize( 0.03 ) label.SetTextAlign(11) label.SetTextFont( 42 ) label.SetTextColor( 1 ) return label
def condLabel(): label = TPaveText( 0.67, 0.9, 0.81, 0.93, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( "%s cond. (13 TeV)" % era ) label.SetTextSize( 0.034 ) label.SetTextAlign(11) label.SetTextFont( 42 ) label.SetTextColor( 1 ) return label
def condLabel(): label = TPaveText(0.63, 0.9, 0.8, 0.92, 'NB NDC') label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText("2017 PU cond. (13 TeV)") label.SetTextSize(0.034) label.SetTextAlign(11) label.SetTextFont(42) label.SetTextColor(1) return label
def selectionLabel(text,ratio,log,maximum): label = TPaveText( 0.1, 0.9, 0.18, 0.92, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( text ) if ratio: label.SetTextSize( 0.048 ) else: label.SetTextSize( 0.034 ) label.SetTextAlign(11) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def Overlay(scalestring): list_scale = scalestring.split(",") # Set up canvas, remove titles and stats boxes gStyle.SetOptTitle(0) gStyle.SetOptStat(0) c = TCanvas("c","c",1600,800) # Legend mylegend = TLegend(1.0,0.5,0.73,1.0,"Legend") mylegend.SetTextSize(0.04) maximumValue=0.0 dict_scale_hist= {} for i,scale in enumerate(list_scale): histname = "Higgs_"+scale+"_M" dict_scale_hist[scale] = file.Get(histname) h=dict_scale_hist[scale] h.SetLineColor(i+1) h.SetFillColorAlpha(i+1, 0.3) # I believe histograms are clearer with solid fill, now transparent if h.GetMaximum()>maximumValue: maximumValue = h.GetMaximum() # increase maximum by 10% to ensure histos fit canvas maximumValue *= 1.10 for i,scale in enumerate(list_scale): h=dict_scale_hist[scale] if i==0: h.SetMaximum(maximumValue) h.Draw() else: h.Draw("same") # Add legend entry mylegend.AddEntry(h,h.GetName(),"f") #Set Canvas Title pave = TPaveText(0.00,0.9,0.3,1.0,"tblrNDC") pave.SetTextColor(1) pave.SetTextSize(0.05) pave.AddText("Overlaid Histograms") pave.Draw("same") # Draw legend mylegend.Draw("same") c.Print("output/overlay.pdf")
def prelimLabel(): label = TPaveText( 0.14, 0.8, 0.2, 0.87, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(11) label.AddText( "#font[62]{CMS}" ) #label.AddText( "#scale[0.75]{#font[52]{Preliminary}}" ) label.AddText( "#scale[0.75]{#font[52]{Inteneral}}" ) label.SetTextSize(0.043) label.SetTextFont( 52 ) label.SetTextColor( 1 ) return label
def descriptionLabel(): label = TPaveText( 0.73, 0.65, 0.81, 0.8, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.AddText( "Elastic #gamma#gamma#rightarrow#gamma#gamma" ) label.AddText( "FPMC BSM pred." ) label.AddText( "#sigma_{bd} = 30 #murads" ) label.SetTextSize( 0.032 ) label.SetTextAlign(11) label.SetTextFont( 42 ) label.SetTextColor( 1 ) return label
def simLabel(): #label = TPaveText( 0.11, 0.9, 0.2, 0.92, 'NB NDC' ) label = TPaveText(0.8, 0.79, 0.87, 0.86, 'NB NDC') label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) #label.SetTextAlign(11) label.SetTextAlign(31) #label.AddText( "#font[62]{CMS} #font[52]{Simulation}" ) label.AddText("#font[62]{CMS}") label.AddText("#scale[0.75]{#font[52]{Simulation}}") label.SetTextSize(0.045) #label.SetTextFont( 52 ) label.SetTextColor(1) return label
def lumiLabel(): label = TPaveText( 0.7, 0.89, 0.8, 0.93, 'NB NDC' ) label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) if len(years) == 1 and years[0] == '2016': luminosity = '9.78' elif len(years) == 1 and years[0] == '2017': luminosity = '37.19' elif len(years) == 1 and years[0] == '2018': luminosity = '55.72' elif len(years) == 2: luminosity = '92.91' elif len(years) == 3: luminosity = '102.7' label.AddText( luminosity+" fb^{-1} (13 TeV)" ) label.SetTextSize( 0.033 ) label.SetTextAlign(11) label.SetTextFont( 42 ) label.SetTextColor( 1 ) return label
def prelimLabel(location, log): if location == 'left': label = TPaveText(0.135, 0.76, 0.2, 0.84, 'NB NDC') label.AddText("#font[62]{CMS}") label.AddText("#scale[0.75]{#font[52]{Preliminary}}") elif location == 'top': label = TPaveText(0.15, 0.9, 0.25, 0.92, 'NB NDC') label.AddText("#font[62]{CMS} #font[52]{Preliminary}") label.SetFillStyle(0) label.SetBorderSize(0) label.SetLineWidth(0) label.SetLineStyle(0) label.SetTextAlign(11) # Align bottom left if location == 'top': label.SetTextSize(0.04) else: label.SetTextSize(0.05) label.SetTextFont(52) label.SetTextColor(1) return label
class pdf_class: def __init__(self, filename): self._canvas = TCanvas("canvas", "canvas", 800, 450) self._canvas.cd() self._pad = TPad("pad", "", 0, 0, 1, 0.95) self._pdf = TPDF("%s.pdf" % filename) self._subCanvas = 0 self._nCanvasPerPage = 0 self._nx = 1 self._ny = 1 def newPage(self, headerText="", nx=1, ny=1, sameHeader=False): if self._subCanvas != 0: self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.NewPage() self._pad.Clear() self._canvas.cd() if not sameHeader: self._nx = nx self._ny = ny self._header = TPaveText(0, 0.95, 1, 1) self._header.SetFillColor(0) self._header.SetTextColor(1) self._header.SetTextFont(22) self._header.AddText(headerText) self._header.AddLine(0.0, 0.95, 1.0, 0.95) self._header.Draw() self._pad.cd() self._pad.Divide(self._nx, self._ny) self._pad.SetGrid(0, 0) self._nCanvasPerPage = self._nx * self._ny self._subCanvas = 0 def newLegend(self, header="", lx=0.8, ly=0.8, ux=0.9, uy=0.88): self._legend = TLegend(lx, ly, ux, uy) self._legend.SetFillColor(0) self._legend.SetBorderSize(0) self._legend.SetTextFont(132) self._legend.SetTextSize(0.035) if header != "": self._legend.SetHeader(header) def draw(self, hists, legend=False, drawOpt="", logx=False, logy=False, logz=False): if self._subCanvas + 1 > self._nCanvasPerPage: self.newPage(sameHeader=True) self._subCanvas += 1 self._pad.cd(self._subCanvas) first = 1 for h in hists: if first == 1: first = 0 h.Draw(drawOpt) else: h.Draw("same%s" % drawOpt) if legend: self._legend.AddEntry(h, h.GetTitle(), "LP") if legend: self._legend.Draw() if logx: self._pad.cd(self._subCanvas).SetLogx() if logy: self._pad.cd(self._subCanvas).SetLogy() if logz: self._pad.cd(self._subCanvas).SetLogz() self._canvas.cd() self._canvas.Update() self._pad.Draw() def close(self): self._pad.Draw() self._canvas.cd() self._canvas.Update() self._pdf.Close()
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)
tot_fit.Draw("same") if draw_side_band_fit: back_fit.SetLineColor(kGray + 1) back_fit.SetLineStyle(2) back_fit.Draw("same") #write info. pinfos = TPaveText(0.12, 0.7, 0.47, 0.89, "NDC") pinfos.SetBorderSize(0) pinfos.SetFillStyle(0) pinfos.SetTextAlign(11) pinfos.SetTextSize(0.03) pinfom = TPaveText(0.5, 0.7, 1., .89, "NDC") pinfom.SetTextAlign(11) pinfom.SetBorderSize(0) pinfom.SetFillStyle(0) pinfom.SetTextColor(kBlue) pinfom.SetTextSize(0.03) pinfom.AddText("%s = %.3f #pm %.3f" % (sig_fit.GetParName(1),\ sig_fit.GetParameter(1), sig_fit.GetParError(1))) pinfom.AddText("%s = %.3f #pm %.3f" % (sig_fit.GetParName(2),\ sig_fit.GetParameter(2), sig_fit.GetParError(2))) pinfom.Draw() pinfos.AddText("S = %.0f #pm %.0f " % (rawYield, rawYieldErr)) pinfos.AddText("B (%.0f#sigma) = %.0f #pm %.0f" % \ (nsigma, background, errbackground)) pinfos.AddText("S/B (%.0f#sigma) = %.4f " % (nsigma, sigOverback)) pinfos.AddText("Signif (%.0f#sigma) = %.1f #pm %.1f " %\ (nsigma, significance, errsignificance)) pinfos.Draw() c1.Update() c1.SaveAs("%s/fittedplot%s.eps" % (outputfolder, suffix))
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName): FNumber = int((high - low) / freq) print "************* -> initiating The ", Fname1, " and number of files exist= ", FNumber # xIntegral=[] # yIntegral=[] # xIntegral_RMS=[] # yIntegral_RMS=[] # LINK=[15] LINK = [15, 16, 17, 18, 19.20] # LINKkChannel=[0,1,2,3,4,5] LINKkChannel = [4] for linkChannel in LINKkChannel: for link in LINK: xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) num = -1 for iAmp in range(low, high, freq): num += 1 Fname = Fname1 + str(iAmp) + Fname2 print "************* -> initiating The ", Fname, " and number of files exist= ", FNumber print "--------------------> Now is doing .... ", low, " ____ ", Fname f = open(Fname) # data = getData(f) tdc = getTDCValues(f) M = TH1F(Fname, Fname, 200, 0, 100) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): tdcValue = 0 for BX in xrange(0, 40): if (iAmp <= 10 and BX == 20 and tdc[event][link][BX][linkChannel] != 31.5): tdcValue = tdc[event][link][BX][linkChannel] if (iAmp > 10 and BX == 21 and tdc[event][link][BX][linkChannel] != 31.5): tdcValue = tdc[event][link][BX][linkChannel] y[event] = tdcValue M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("can", "can", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = histMean if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4) integral_RMS = histRMS if round(FitParam[2], 4) < 2 * histRMS: integral_RMS = round(FitParam[2], 4) integralErr = round(mfit.GetParError(1), 4) integral_RMSErr = round(mfit.GetParError(2), 4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(0, 30) M.SetTitle("TDC v.s. Delay Setting (ns)") M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.AddText("Delay Setting =" + str(iAmp)) fitInfo.AddText("link =" + str(link) + " channel=" + str(linkChannel)) fitInfo.Draw() canvas.SaveAs("outHistoSingleRun_" + RootName + str(iAmp) + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") XVAL = low + num * freq xIntegral[num] = XVAL yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = XVAL yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr print "iAmp, integral= ", iAmp, " ", integral, " XVAL= ", XVAL # xRatio[num]=XVAL # yRatio[num]=integral_RMS/integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_TDC = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_TDCErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_TDCErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_TDC = MakeCanvas("can1", "can1", 800, 800) Graph_TDC.SetTitle("") Graph_TDC.SetMarkerStyle(22) Graph_TDC.SetMarkerColor(3) Graph_TDC.SetMarkerSize(2) Graph_TDC.GetXaxis().SetTitle(XaxisT) Graph_TDC.GetYaxis().SetRangeUser(0, 30) Graph_TDC.GetYaxis().SetTitle("TDC [ns]") Graph_TDC.Draw() Graph_TDCErUp.Draw("same") Graph_TDCErDown.Draw("same") canvas_TDC.SaveAs("outHisto_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") Graph_TDC_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_TDC_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_TDC_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_TDC_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_TDC_RMS.SetTitle("TDC RMS vs. Pulse " + Title) Graph_TDC_RMS.SetMarkerStyle(23) Graph_TDC_RMS.SetMarkerColor(2) Graph_TDC_RMS.SetMarkerSize(2) Graph_TDC_RMS.GetXaxis().SetTitle(XaxisT) Graph_TDC_RMS.GetYaxis().SetRangeUser(0, 2) Graph_TDC_RMS.Draw() Graph_TDC_RMSErUp.Draw("same") Graph_TDC_RMSErDown.Draw("same") canvas_TDC_RMS.SaveAs("outHistoRMS_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") OutFile = TFile( "outFile_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".root", "RECREATE") OutFile.WriteObject(Graph_TDC, "Graph_TDC") OutFile.WriteObject(Graph_TDC_RMS, "Graph_TDC_RMS") OutFile.Close()
def Measure_Integral(AllRuns, Title, RootName): FNumber=len(AllRuns) xIntegral=array("d",xrange(0,FNumber)) yIntegral=array("d",xrange(0,FNumber)) yIntegralErrUp=array("d",xrange(0,FNumber)) yIntegralErrDown=array("d",xrange(0,FNumber)) xIntegral_RMS=array("d",xrange(0,FNumber)) yIntegral_RMS=array("d",xrange(0,FNumber)) yIntegral_RMSErrUp=array("d",xrange(0,FNumber)) yIntegral_RMSErrDown=array("d",xrange(0,FNumber)) xRatio=array("d",xrange(0,FNumber)) yRatio=array("d",xrange(0,FNumber)) xSingleEv=array("d",xrange(0,40)) ySingleEv=array("d",xrange(0,40)) OutFile=TFile(RootName,"RECREATE") num=-1 iAmp=0 for Fname in AllRuns: num+=1 iAmp+=1 f = open(Fname) data = getData(f) M=TH1F(Fname,Fname,600,0,120000) x = array("d", xrange(0,1001)) y = array("d", xrange(0,1001)) for event in xrange(0,995): pedSum=0 sigSum=0 Signal=0 Pedestal=0 for BX in xrange(0, 40): adcValue=data[event][link][BX][linkChannel] if BX < 15 : pedSum += adcValue if BX > 19 and BX < 25: sigSum += adcValue xSingleEv[BX]=BX ySingleEv[BX]=adcValue scanvas = MakeCanvas("mm","nn",800,800) GrSingleEv=TGraph(len(xSingleEv),xSingleEv,ySingleEv) OutFile.WriteObject(GrSingleEv,"singleEv_"+str(iAmp)+"_"+str(event)) SFit=TF1("fit", "gaus", 19,23) SFit.SetParameter(0, 4000) SFit.SetParameter(1, 20.9) SFit.SetParLimits(1, 20, 22) SFit.SetParameter(2, 1.5) GrSingleEv.Draw("AC*") GrSingleEv.Fit("fit","R0") SFit.Draw("same") FitParam=SFit.GetParameters() print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4) scanvas.SaveAs("PLOT/singleEv_"+str(iAmp)+"_"+str(event)+".pdf") Pedestal=pedSum/15. y[event]= sigSum- Pedestal*5 M.Fill(y[event]) histMean= M.GetMean() histRMS= M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf","asdf",800,800) canvas.Update() MyGr= TGraph(len(x), x,y) mfit=TF1("fit", "gaus", lowVal,highVal) M.Fit(mfit, "R0","") FitParam=mfit.GetParameters() # FitParErr=mfit.GetParError() integral= round(FitParam[1],4) integral_RMS= round(FitParam[2],4) integralErr= round(mfit.GetParError(1),4) integral_RMSErr= round(mfit.GetParError(2),4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx,highValAx) M.SetTitle(Title+" = "+str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo =TPaveText(.20,0.7,.60,0.9, "NDC"); fitInfo.SetBorderSize( 0 ); fitInfo.SetFillStyle( 0 ); fitInfo.SetTextAlign( 12 ); fitInfo.SetTextSize ( 0.03 ); fitInfo.SetTextColor( 1 ); fitInfo.SetTextFont ( 62 ); fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1],1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2],1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_"+str(iAmp)+"_"+Title+RootName+".pdf") xIntegral[num]=iAmp yIntegral[num]=integral yIntegralErrUp[num]=integral+integralErr yIntegralErrDown[num]=integral-integralErr xIntegral_RMS[num]=iAmp yIntegral_RMS[num]=integral_RMS yIntegral_RMSErrUp[num]=integral_RMS+integral_RMSErr yIntegral_RMSErrDown[num]=integral_RMS-integral_RMSErr xRatio[num]=iAmp yRatio[num]=integral_RMS/integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_Integral= TGraph(len(xIntegral), xIntegral,yIntegral) Graph_IntegralErUp= TGraph(len(xIntegral), xIntegral,yIntegralErrUp) Graph_IntegralErDown= TGraph(len(xIntegral), xIntegral,yIntegralErrDown) canvas_Integral = MakeCanvas("can1","can1",800,800) # canvas_Integral.SetLogy() Graph_Integral.SetTitle("Pulse Integral Stability") Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral.GetYaxis().SetRangeUser(80000,85000) Graph_Integral.Draw() # Graph_IntegralErUp.Draw("same") # Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_"+Title+RootName+".pdf") Graph_Integral_RMS= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMS) Graph_Integral_RMSErUp= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrUp) Graph_Integral_RMSErDown= TGraph(len(xIntegral_RMS), xIntegral_RMS,yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2","can2",800,800) Graph_Integral_RMS.SetTitle("Pulse Integral RMS vs. Pulse "+Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral_RMS.Draw() # Graph_Integral_RMSErUp.Draw("same") # Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_"+Title+RootName+".pdf") Graph_Ratio= TGraph(len(xRatio), xRatio,yRatio) canvas_Ratio = MakeCanvas("can2","can2",800,800) Graph_Ratio.SetTitle("Ratio of Pulse Integral RMS and Pulse Integral "+Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(8) Graph_Ratio.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_"+Title+RootName+".pdf") # OutFile=TFile(RootName,"RECREATE") OutFile.WriteObject(Graph_Integral,"Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS,"Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio,"Graph_Ratio") OutFile.Close()
pv = TPaveText(0.64,0.35,0.94,0.65,"brNDC") pv.AddText("DATA:") pv.AddText("Z DCBmean = " + str(round(massFitDATA_dict[key],2)) + " GeV") pv.AddText("Z DCBwidth = " + str(round(widthFitDATA_dict[key],2)) + " GeV") pv.AddText("MC:") pv.AddText("Z DCBmean = " + str(round(massFitMC_dict[key],2)) + " GeV") pv.AddText("Z DCBwidth = " + str(round(widthFitMC_dict[key],2)) + " GeV") pv.SetFillColor(kWhite) pv.SetBorderSize(1) pv.SetTextFont(40) pv.SetTextSize(0.037) pv.SetTextFont(42) pv.SetTextAlign(12) #text left aligned # cange color of text if "ele" in nameList[i] : pv.SetTextColor(kBlue) elif "mu" in nameList[i] : pv.SetTextColor(kRed) else : pv.SetTextColor(kBlack) pv.Draw() # box with decay mode pv2 = TPaveText(0.19,0.75,0.35,0.85,"brNDC") if "ele" in nameList[i] : pv2.AddText("Z #rightarrow e^{+} e^{-}") pv2.SetTextColor(kBlue) elif "mu" in nameList[i] : pv2.AddText("Z #rightarrow #mu^{+} #mu^{-}") pv2.SetTextColor(kRed)
def Fitting(scalestring, Fit_id): list_scale = scalestring.split(",") # Set up canvas, remove titles and stats boxes gStyle.SetOptTitle(0) gStyle.SetOptStat(0) c = TCanvas("c", "c", 1600, 800) # Legend mylegend = TLegend(1.0, 0.3, 0.75, 1.0, "Legend") mylegend.SetTextSize(0.04) dict_scale_hist = {} dict_gaus_fit = {} dict_bukin_fit = {} colorcounter = 1 for scale in list_scale: histname = "Higgs_" + scale + "_M" dict_scale_hist[scale] = file.Get(histname) xmin = dict_scale_hist[scale].GetMean( ) - 3 * dict_scale_hist[scale].GetRMS() xmax = dict_scale_hist[scale].GetMean( ) + 3 * dict_scale_hist[scale].GetRMS() # If error here, check Bukin.py has: import math dict_gaus_fit[scale] = TF1("Gauss", Gauss(), xmin, xmax, 3) dict_bukin_fit[scale] = TF1( "Bukin", Bukin(), dict_scale_hist[scale].GetMean() - 3 * dict_scale_hist[scale].GetRMS(), dict_scale_hist[scale].GetMean() + 3 * dict_scale_hist[scale].GetRMS(), 6) for scale in list_scale: if Fit_id == 1: print print "The ROOT Gaussian fit produces: " dict_scale_hist[scale].Fit("gaus", "0 +") # zero option to not draw print print "The user defined Gaussian fit produces: " dict_gaus_fit[scale].SetParName(0, "User_Constant") dict_gaus_fit[scale].SetParName(1, "User_Mean") dict_gaus_fit[scale].SetParName(2, "User_Sigma") dict_gaus_fit[scale].SetLineColor(colorcounter) dict_gaus_fit[scale].SetParameters( 100, dict_scale_hist[scale].GetMean(), dict_scale_hist[scale].GetRMS()) dict_scale_hist[scale].Fit(dict_gaus_fit[scale], "+ R") # + option to not delete previous fit # Add legend entry for Gaussian mylegend.AddEntry(dict_gaus_fit[scale], scale + "_Gauss", "l") elif Fit_id == 2: print print "The Bukin fit produces: " dict_bukin_fit[scale].SetParameters( 0, dict_scale_hist[scale].GetMean(), dict_scale_hist[scale].GetRMS(), 0, 0, 0) dict_bukin_fit[scale].SetLineColor(colorcounter) DrawBothHistAndFit = False DrawJustFit = True if DrawBothHistAndFit: dict_scale_hist[scale].Fit(dict_bukin_fit[scale], "+ R") f = dict_scale_hist[scale].GetFunction("Bukin") f.SetLineColor(colorcounter) if DrawJustFit: dict_scale_hist[scale].Fit(dict_bukin_fit[scale], "RQ", "RO SAME", xmin, xmax) f = dict_scale_hist[scale].GetFunction("Bukin") f.SetLineColor(colorcounter) # Add legend entry mylegend.AddEntry(dict_bukin_fit[scale], scale + "_Bukin", "l") colorcounter += 1 for scale in list_scale: dict_scale_hist[scale].Draw( "func same") # using "func" here only plots fn for last fit #Set Canvas Title pave = TPaveText(0.00, 0.9, 0.3, 1.0, "tblrNDC") pave.SetTextColor(1) pave.SetTextSize(0.05) pave.AddText("Histogram Fits") pave.Draw("same") # Draw legend mylegend.Draw("same") c.Print("output/fitted.pdf")
## Display demo help. ## ## \macro_code ## ## \author Wim Lavrijsen import os from ROOT import TCanvas, TPaveText from ROOT import gROOT chelp = TCanvas('chelp', 'Help to run demos', 200, 10, 700, 500) welcome = TPaveText(.1, .8, .9, .97) welcome.AddText('Welcome to the ROOT demos') welcome.SetTextFont(32) welcome.SetTextColor(4) welcome.SetFillColor(24) welcome.Draw() hdemo = TPaveText(.05, .05, .95, .7) hdemo.SetTextAlign(12) hdemo.SetTextFont(52) text = """- Run demo hsimple.py first. Then in any order - Click left mouse button to execute one demo - Click right mouse button to see the title of the demo - Click on 'Close Bar' to exit from the demo menu - Select 'File/Print' to print a Postscript view of the canvas - You can execute a demo with the mouse or type commands - During the demo (try on this canvas) you can: .... Use left button to move/grow/etc objects
def Measure_Integral(AllRuns, Title, RootName, WID): FNumber = len(AllRuns) xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) OutFile = TFile(RootName, "RECREATE") num = -1 iAmp = 0 for Fname in AllRuns: num += 1 iAmp += 1 f = open(Fname) # data = getData(f) tdc = getTDCValues(f) M = TH1F(Fname, Fname, 200, 0, 100) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): pedSum = 0 sigSum = 0 Signal = 0 Pedestal = 0 for BX in xrange(0, 40): # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # print BX # print event # print "data=", data[event][link][BX][linkChannel] # print "TDC=", tdc[event][link][BX][linkChannel] # print "\n" # print "@@@@@@@@-------> [event] ", event tdcValue = tdc[event][link][BX][linkChannel] # print "@@@@@@@@-------> [event] ", event if (WID[num] < 10 and BX == 20 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue if (WID[num] > 10 and BX == 21 and tdc[event][link][BX][linkChannel] != 31.5): sigSum += tdcValue # print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", tdc[event][link][BX][linkChannel] # if BX > 19 and BX < 25: sigSum += adcValue # if BX > 18 and BX < 26: print "[event][link][BX][linkChannel] = ", event," " ,link," " , BX ," " ,linkChannel, "---->data[event][link][BX][linkChannel]", data[event][link][BX][linkChannel] # print "---------------------> sigSum= ",sigSum y[event] = sigSum M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf", "asdf", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = histMean if FitParam[1] < 1.5 * histMean: integral = round(FitParam[1], 4) integral_RMS = histRMS if round(FitParam[2], 4) < 2 * histRMS: integral_RMS = round(FitParam[2], 4) integralErr = round(mfit.GetParError(1), 4) integral_RMSErr = round(mfit.GetParError(2), 4) print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx, highValAx) # M.GetXaxis().SetRangeUser(lowValAx,highValAx) M.SetTitle(Title + " = " + str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title + "_TDC.pdf") XVAL = iAmp xIntegral[num] = XVAL yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = XVAL yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr print "iAmp, integral= ", iAmp, " ", integral, " XVAL= ", XVAL xRatio[num] = XVAL yRatio[num] = integral_RMS / integral # xIntegral.append(iAmp) # yIntegral.append(integral) # xIntegral_RMS.append(iAmp) # yIntegral_RMS.append(integral_RMS) Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_Integral = MakeCanvas("can1", "can1", 800, 800) # canvas_Integral.SetLogy() Graph_Integral.SetTitle("TDC Stability") Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle("Day") Graph_Integral.GetYaxis().SetRangeUser(0, 40) print "%%%%%%%% Graph_Integral.GetMaximum()= ", TMath.MaxElement( len(xIntegral_RMS), Graph_Integral.GetY()) # Graph_Integral.SetMaximum(1.5) Graph_Integral.Draw() # Graph_IntegralErUp.Draw("same") # Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_" + Title + "_TDC.pdf") Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_Integral_RMS.SetTitle("TDC RMS vs. Pulse " + Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral_RMS.GetXaxis().SetTitle("Day") Graph_Integral_RMS.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Integral_RMS.GetY()) * 1.5) Graph_Integral_RMS.Draw() # Graph_Integral_RMSErUp.Draw("same") # Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + "_TDC.pdf") Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio) canvas_Ratio = MakeCanvas("can2", "can2", 800, 800) Graph_Ratio.SetTitle("Ratio of TDC RMS and TDC " + Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(4) Graph_Ratio.SetMarkerSize(2) Graph_Ratio.GetXaxis().SetTitle("Day") Graph_Ratio.GetYaxis().SetRangeUser( TMath.MinElement(len(xIntegral_RMS), Graph_Ratio.GetY()) / 2, TMath.MaxElement(len(xIntegral_RMS), Graph_Ratio.GetY()) * 1.5) Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_" + Title + "_TDC.pdf") OutFile = TFile(RootName, "RECREATE") OutFile.WriteObject(Graph_Integral, "Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio, "Graph_Ratio") OutFile.Close()
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',22,-10.5,11.5,22,-10.5,11.5) hi=TH2I('hi',';X;Y',22,-10.5,11.5,22,-10.5,11.5) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC') ttM=TPaveText(-3+0.05, 7-4.45, 4.0, 8-4.51) tt2=TPaveText(-3+0.05, 7-5.45, 4.0, 8-5.51) ttX=TPaveText(-2, 7-8.00, 3, 8-8.00) ttY=TPaveText(-2, 7-9.00, 3, 8-9.00) ttZ=TPaveText(-2, 6-8.80, 3, 8-9.30) ttZ.AddText("positive = beam top/right") ttime=TPaveText(-10,-12.5,10,-11.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt2,ttM,ttime,tchan,ttX,ttY,ttZ]) ttM.SetTextColor(2) ttM.SetFillStyle(0) ttZ.SetFillStyle(0) tt2.SetFillStyle(0) tarrow=TText(-0.9,0.7,'Beam Right') tarrow.SetTextSizePixels(15) arrow=TArrow(-1.4,0.5,2.4,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(12.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.3,0.92,'FTC FADC SCALERS') bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-3.47,-1.47,4.47,2.46) bb.DrawBox(-1.47,-3.47,2.49,4.47) bb.DrawBox(-2.47,-2.47,3.49,3.47) cc.cd() for xx in [ttM,tt2,ttime,arrow,tarrow,ttX,ttY,ttZ]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() gPad.SetEditable(0) while True: for ch in ECAL.chans: loadPV(ch) ch=ch.vals xx,yy=ch['X'],ch['Y'] #if (ch['PVVAL']>10): # print xx,yy,ch['PVVAL'] # swap x to make it downstream view: xx=-xx #after, fix the fact x=0 / y=0 don't exists if xx<0: xx+=1 if yy<0: yy+=1 hh.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) hi.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) for xx in [ttime,tt2,ttM,ttX,ttY]: xx.Clear() [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans) tt2.AddText('Total: %.1f MHz'%(total/1000)) ttM.AddText('Max: %.0f kHz'%(maximum)) if total>1e2: xasy = (right-left)/total yasy = (top-bottom)/total ttX.AddText('X-Asy: %+.1f%%'%(100*xasy)) ttY.AddText('Y-Asy: %+.1f%%'%(100*yasy)) else: ttX.AddText('X-Asy: N/A') ttY.AddText('Y-Asy: N/A') ttime.AddText(makeTime()) if not gPad: sys.exit() if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(2)
def 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 Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName): FNumber = int((high - low) / freq) LINK = [3] # LINK=[15,16,17,18,19] LINKkChannel = [0, 1, 2, 3, 4, 5] # LINKkChannel=[0] for linkChannel in LINKkChannel: for link in LINK: xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) num = -1 for iAmp in range(low, high, freq): num += 1 Fname = Fname1 + str(iAmp) + Fname2 f = open(Fname) data = getData(f) M = TH1F(Fname, Fname, 200, 0.4, 1.4) HistoSergey = TH1F(Fname, Fname, 200, -10, 200) M.SetDefaultSumw2() x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 9): for BX in xrange(0, 40): xSingleEv[BX] = BX ySingleEv[BX] = data[event][link][BX][linkChannel] if BX < 16: HistoSergey.Fill(ySingleEv[BX]) if ySingleEv[BX] <= 0: ySingleEv[BX] = 0.1 if ySingleEv[BX] < 0.1: print "--->", ySingleEv[BX] scanvas = MakeCanvas("mm", "nn", 800, 800) scanvas.SetLogy() GrSingleEv = TGraph(len(xSingleEv), xSingleEv, ySingleEv) # SFit=TF1("fit", "gaus", 19,23) # SFit.SetParameter(0, 250) # SFit.SetParameter(1, 20.9) # SFit.SetParLimits(1, 20, 22) # SFit.SetParameter(2, 1) GrSingleEv.GetXaxis().SetRangeUser(0, 40) GrSingleEv.GetYaxis().SetRangeUser(0.05, 100000) GrSingleEv.Draw("AC*") # GrSingleEv.Fit("fit","R0") # SFit.Draw("same") # FitParam=SFit.GetParameters() # print "Gaus fit param 1, 2, 3= " , round(FitParam[0],4), round(FitParam[1],4), round(FitParam[2],4) fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("eventNumber_" + str(event) + "_link" + str(link) + "_ch_" + str(linkChannel)) fitInfo.Draw() scanvas.SaveAs("PLOT/singleEv_" + str(iAmp) + "_" + str(event) + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") sergeycanvas = MakeCanvas("mm", "nn", 800, 800) HistoSergey.Draw() sergeycanvas.SaveAs("SergeyHisto" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf")
def Measure_Integral(Fname1, Fname2, Title, XaxisT, low, high, freq, RootName): FNumber = int((high - low) / freq) LINK = [19] # LINK=[15,16,17,18,19] # LINKkChannel=[0,1,2,3,4,5] LINKkChannel = [2] for linkChannel in LINKkChannel: for link in LINK: xIntegral = array("d", xrange(0, FNumber)) yIntegral = array("d", xrange(0, FNumber)) yIntegralErrUp = array("d", xrange(0, FNumber)) yIntegralErrDown = array("d", xrange(0, FNumber)) xIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMS = array("d", xrange(0, FNumber)) yIntegral_RMSErrUp = array("d", xrange(0, FNumber)) yIntegral_RMSErrDown = array("d", xrange(0, FNumber)) xRatio = array("d", xrange(0, FNumber)) yRatio = array("d", xrange(0, FNumber)) xSingleEv = array("d", xrange(0, 40)) ySingleEv = array("d", xrange(0, 40)) num = -1 for iAmp in range(low, high, freq): num += 1 Fname = Fname1 + str(iAmp) + Fname2 print "************* -> initiating The ", Fname, " and number of files exist= ", FNumber print "--------------------> Now is doing .... ", low, " ____ ", Fname f = open(Fname) data = getData(f) # tdc = getTDCValues(f) M = TH1F(Fname, Fname, 10000, 0, 1000000) x = array("d", xrange(0, 1001)) y = array("d", xrange(0, 1001)) for event in xrange(0, 995): pedSum = 0 sigSum = 0 Signal = 0 Pedestal = 0 for BX in xrange(0, 40): adcValue = data[event][link][BX][linkChannel] if BX < 15: pedSum += adcValue if BX > 19 and BX < 27: sigSum += adcValue # if BX > 19 and BX < 25: sigSum += adcValue xSingleEv[BX] = BX ySingleEv[BX] = adcValue scanvas = MakeCanvas("mm", "nn", 800, 800) GrSingleEv = TGraph(len(xSingleEv), xSingleEv, ySingleEv) SFit = TF1("fit", "gaus", 19, 23) SFit.SetParameter(0, 4000) SFit.SetParameter(1, 20.9) SFit.SetParLimits(1, 20, 22) SFit.SetParameter(2, 1.5) GrSingleEv.Draw("AC*") GrSingleEv.Fit("fit", "R0") SFit.Draw("same") FitParam = SFit.GetParameters() print "Gaus fit param 1, 2, 3= ", round( FitParam[0], 4), round(FitParam[1], 4), round(FitParam[2], 4) # scanvas.SaveAs("singleEv_"+str(iAmp)+"_"+str(event)+".pdf") Pedestal = pedSum / 15. y[event] = sigSum - Pedestal * 7 # y[event]= sigSum- Pedestal*5 M.Fill(y[event]) histMean = M.GetMean() histRMS = M.GetStdDev() highVal = histMean + 4 * histRMS lowVal = histMean - 4 * histRMS highValAx = histMean + 6 * histRMS lowValAx = histMean - 6 * histRMS canvas = MakeCanvas("asdf", "asdf", 800, 800) canvas.Update() MyGr = TGraph(len(x), x, y) mfit = TF1("fit", "gaus", lowVal, highVal) M.Fit(mfit, "R0", "") FitParam = mfit.GetParameters() # FitParErr=mfit.GetParError() integral = round(FitParam[1], 4) integralErr = round(mfit.GetParError(1), 4) if FitParam[1] / histMean < 0.9 or FitParam[1] / histMean > 1.1: integral = histMean integralErr = 0 integral_RMS = round(FitParam[2], 4) integral_RMSErr = round(mfit.GetParError(2), 4) if round(FitParam[2], 4) / histRMS < 0.9 or round( FitParam[2], 4) / histRMS > 1.1: integral_RMS = histRMS integral_RMSErr = 0 print "iAmp=", iAmp, " integral= ", integral, " integral_RMS=", integral_RMS M.SetMarkerStyle(22) M.GetXaxis().SetRangeUser(lowValAx, highValAx) M.SetTitle(Title + " = " + str(iAmp)) M.Draw("pe") mfit.Draw("same") fitInfo = TPaveText(.20, 0.7, .60, 0.9, "NDC") fitInfo.SetBorderSize(0) fitInfo.SetFillStyle(0) fitInfo.SetTextAlign(12) fitInfo.SetTextSize(0.03) fitInfo.SetTextColor(1) fitInfo.SetTextFont(62) fitInfo.AddText("Mean of Fit=" + str(round(FitParam[1], 1))) fitInfo.AddText("RMS of Fit =" + str(round(FitParam[2], 1))) fitInfo.Draw() canvas.SaveAs("HistoSingleRun_" + str(iAmp) + "_" + Title + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") xIntegral[num] = iAmp yIntegral[num] = integral yIntegralErrUp[num] = integral + integralErr yIntegralErrDown[num] = integral - integralErr xIntegral_RMS[num] = iAmp yIntegral_RMS[num] = integral_RMS yIntegral_RMSErrUp[num] = integral_RMS + integral_RMSErr yIntegral_RMSErrDown[num] = integral_RMS - integral_RMSErr xRatio[num] = iAmp yRatio[num] = integral_RMS / integral Graph_Integral = TGraph(len(xIntegral), xIntegral, yIntegral) Graph_IntegralErUp = TGraph(len(xIntegral), xIntegral, yIntegralErrUp) Graph_IntegralErDown = TGraph(len(xIntegral), xIntegral, yIntegralErrDown) canvas_Integral = MakeCanvas("can1", "can1", 800, 800) Graph_Integral.SetTitle("Pulse Integral vs. Pulse " + Title) Graph_Integral.SetMarkerStyle(22) Graph_Integral.SetMarkerColor(3) Graph_Integral.SetMarkerSize(2) Graph_Integral.GetXaxis().SetTitle(XaxisT) Graph_Integral.Draw() Graph_IntegralErUp.Draw("same") Graph_IntegralErDown.Draw("same") canvas_Integral.SaveAs("Integral_" + Title + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") Graph_Integral_RMS = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMS) Graph_Integral_RMSErUp = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrUp) Graph_Integral_RMSErDown = TGraph(len(xIntegral_RMS), xIntegral_RMS, yIntegral_RMSErrDown) canvas_Integral_RMS = MakeCanvas("can2", "can2", 800, 800) Graph_Integral_RMS.SetTitle("Pulse Integral RMS vs. Pulse " + Title) Graph_Integral_RMS.SetMarkerStyle(23) Graph_Integral_RMS.SetMarkerColor(2) Graph_Integral_RMS.SetMarkerSize(2) Graph_Integral_RMS.GetXaxis().SetTitle(XaxisT) Graph_Integral_RMS.Draw() Graph_Integral_RMSErUp.Draw("same") Graph_Integral_RMSErDown.Draw("same") canvas_Integral_RMS.SaveAs("Integral_RMS_" + Title + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") Graph_Ratio = TGraph(len(xRatio), xRatio, yRatio) canvas_Ratio = MakeCanvas("can2", "can2", 800, 800) Graph_Ratio.SetTitle( "Ratio of Pulse Integral RMS and Pulse Integral " + Title) Graph_Ratio.SetMarkerStyle(21) Graph_Ratio.SetMarkerColor(8) Graph_Ratio.SetMarkerSize(2) Graph_Ratio.GetXaxis().SetTitle(XaxisT) Graph_Ratio.Draw() canvas_Ratio.SaveAs("Ratio_" + Title + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".pdf") OutFile = TFile( "outFile_" + RootName + "_link" + str(link) + "_ch_" + str(linkChannel) + ".root", "RECREATE") OutFile.WriteObject(Graph_Integral, "Graph_Integral") OutFile.WriteObject(Graph_Integral_RMS, "Graph_Integral_RMS") OutFile.WriteObject(Graph_Ratio, "Graph_Ratio") OutFile.Close()
def draw_fit(self, save_name, flag_plot_message=None, shade_regions=False): #Draw self.histo_to_fit.GetXaxis().SetTitle("Invariant Mass L_{c}^{+}(GeV/c^{2})") self.histo_to_fit.SetStats(0) c1 = TCanvas('c1', 'The Fit Canvas', 700, 700) c1.cd() gStyle.SetOptStat(0) gStyle.SetCanvasColor(0) gStyle.SetFrameFillColor(0) c1.cd() self.histo_to_fit.GetXaxis().SetRangeUser(self.fit_range_low, self.fit_range_up) # Adjust y-range for good readability histo_min = self.histo_to_fit.GetMinimum() * 0.9 histo_max = self.histo_to_fit.GetMaximum() + (self.histo_to_fit.GetMaximum() - histo_min) self.histo_to_fit.GetYaxis().SetRangeUser(histo_min, histo_max) self.histo_to_fit.SetMarkerStyle(20) self.histo_to_fit.SetMarkerSize(1) #histo.SetMinimum(0.) self.histo_to_fit.Draw("PE") self.bkg_tot_fit_func.Draw("same") self.tot_fit_func.Draw("same") c1.Update() # Shading sideband area sideband_fill_left = None sideband_fill_right = None sig_fill = None bkg_fill = None if shade_regions: sideband_fill_left = self.bkg_tot_fit_func.Clone("bkg_fit_fill_left") sideband_fill_left.SetRange(self.mean_fit - 9 * self.sigma_fit, self.mean_fit - self.nsigma_sideband * self.sigma_fit) sideband_fill_left.SetLineWidth(0) sideband_fill_left.SetFillColor(self.bkg_tot_fit_func.GetLineColor()) sideband_fill_left.SetFillStyle(3001) sideband_fill_left.Draw("same fc") sideband_fill_right = self.bkg_tot_fit_func.Clone("bkg_fit_fill_right") sideband_fill_right.SetRange(self.mean_fit + self.nsigma_sideband * self.sigma_fit, self.mean_fit + 9 * self.sigma_fit) sideband_fill_right.SetLineWidth(0) sideband_fill_right.SetFillColor(self.bkg_tot_fit_func.GetLineColor()) sideband_fill_right.SetFillStyle(3001) sideband_fill_right.Draw("same fc") # Shading bakground in signal region bkg_fill = self.bkg_tot_fit_func.Clone("bkg_fit_under_sig_fill") bkg_fill.SetRange(self.mean_fit - self.nsigma_sig * self.sigma_fit, self.mean_fit + self.nsigma_sig * self.sigma_fit) bkg_fill.SetLineWidth(0) bkg_fill.SetFillColor(kRed + 2) bkg_fill.SetFillStyle(3001) bkg_fill.Draw("same fc") # Shading signal above background n_points = 100 dx = (2 * self.nsigma_sig * self.sigma_fit) / n_points sig_fill = TGraph(2 * n_points) sig_fill.SetFillColor(kGreen + 2) sig_fill.SetFillStyle(3001) range_low = self.mean_fit - self.nsigma_sig * self.sigma_fit range_up = self.mean_fit + self.nsigma_sig * self.sigma_fit for ip in range(n_points): sig_fill.SetPoint(ip, range_low + ip * dx, self.tot_fit_func.Eval(range_low + ip * dx)) sig_fill.SetPoint(n_points + ip, range_up - ip * dx, self.bkg_tot_fit_func.Eval(range_up - ip * dx)) sig_fill.Draw("f") #write info. pinfos = TPaveText(0.12, 0.7, 0.47, 0.89, "NDC") pinfos.SetBorderSize(0) pinfos.SetFillStyle(0) pinfos.SetTextAlign(11) pinfos.SetTextSize(0.03) pinfom = TPaveText(0.5, 0.7, 1., .89, "NDC") pinfom.SetTextAlign(11) pinfom.SetBorderSize(0) pinfom.SetFillStyle(0) pinfom.SetTextColor(kBlue) pinfom.SetTextSize(0.03) chisquare_ndf = self.tot_fit_func.GetNDF() chisquare_ndf = self.tot_fit_func.GetChisquare() / chisquare_ndf if chisquare_ndf > 0. \ else 0. pinfom.AddText("#chi^{2}/NDF = %f" % (chisquare_ndf)) pinfom.AddText("%s = %.3f #pm %.3f" % (self.sig_fit_func.GetParName(1),\ self.sig_fit_func.GetParameter(1), self.sig_fit_func.GetParError(1))) pinfom.AddText("%s = %.3f #pm %.3f" % (self.sig_fit_func.GetParName(2),\ self.sig_fit_func.GetParameter(2), self.sig_fit_func.GetParError(2))) pinfom.Draw() flag_info = None if flag_plot_message is not None: flag_info = TPaveText(0.5, 0.5, 1., 0.68, "NDC") flag_info.SetBorderSize(0) flag_info.SetFillStyle(0) flag_info.SetTextAlign(11) flag_info.SetTextSize(0.03) for t in flag_plot_message: text = flag_info.AddText(t) text.SetTextColor(kRed + 2) flag_info.Draw() sig_text = pinfos.AddText("S = %.0f #pm %.0f " % (self.yield_sig, self.yield_sig_err)) sig_text.SetTextColor(kGreen + 2) bkg_text = pinfos.AddText("B (%.0f#sigma) = %.0f #pm %.0f" % \ (self.nsigma_sig, self.yield_bkg, self.yield_bkg_err)) bkg_text.SetTextColor(kRed + 2) sig_over_back = self.yield_sig / self.yield_bkg if self.yield_bkg > 0. else 0. pinfos.AddText("S/B (%.0f#sigma) = %.4f " % (self.nsigma_sig, sig_over_back)) pinfos.AddText("Signif (%.0f#sigma) = %.1f #pm %.1f " %\ (self.nsigma_sig, self.significance, self.errsignificance)) pinfos.Draw() c1.Update() c1.SaveAs(save_name) c1.Close()