def malujWykresyOdchylen(sigmy, ileKanalow, czas, katalog): gStyle.SetOptStat(0) wykresKoncowyNar=TH2I("Odchylenia standardowe (zb. narastajace)","Wykres odchylen standardowych", ileKanalow-1,1,ileKanalow,ileKanalow-1,0,ileKanalow-1) wykresKoncowyOp=TH2I("Odchylenia standardowe (zb. opadajace)","Wykres odchylen standardowych",ileKanalow-1,1,ileKanalow,ileKanalow-1,0,ileKanalow-1) #wypełnianie wykresu zbiorczego odchyleń dla zbocz opadających wypelnijWykresZbiorczy(wykresKoncowyOp, ileKanalow, sigmy, 0) #wypełnianie wykresu zbiorczego odchyleń dla zbocz narastających wypelnijWykresZbiorczy(wykresKoncowyNar, ileKanalow, sigmy, 1) #malowanie wykresu zbiorczego odchyleń dla zbocz narastających malowanieWykresuZbiorczego(wykresKoncowyNar, "narastajace", czas, katalog) #malowanie wykresu zbiorczego odchyleń dla zbocz opadających malowanieWykresuZbiorczego(wykresKoncowyOp, "opadajace", czas, katalog)
def plotNSamples(cls, npatterns, etBins, etaBins, outname='nPatterns.pdf'): """Plot number of samples per bin""" logger = Logger.getModuleLogger("PlotNSamples") from ROOT import TCanvas, gROOT, kTRUE, kFALSE, TH2I, TText gROOT.SetBatch(kTRUE) c1 = TCanvas("plot_patterns_signal", "a", 0, 0, 800, 400) c1.Draw() shape = [len(etBins) - 1, len(etaBins) - 1] histo1 = TH2I( "text_stats", "#color[4]{Signal}/#color[2]{Background} available statistics", shape[0], 0, shape[0], shape[1], 0, shape[1]) #histo1 = TH2I("text_stats", "Signal/Background available statistics", shape[0], 0, shape[0], shape[1], 0, shape[1]) histo1.SetStats(kFALSE) histo1.Draw("TEXT") histo1.SetXTitle("E_{T}") histo1.SetYTitle("#eta") histo1.GetXaxis().SetTitleSize(0.04) histo1.GetYaxis().SetTitleSize(0.04) histo1.GetXaxis().SetLabelSize(0.04) histo1.GetYaxis().SetLabelSize(0.04) histo1.GetXaxis().SetTickSize(0) histo1.GetYaxis().SetTickSize(0) ttest = TText() ttest.SetTextAlign(22) for etBin in range(shape[0]): for etaBin in range(shape[1]): key = 'et%d_eta%d' % (etBin, etaBin) ttest.SetTextColor(4) ttest.DrawText(.5 + etBin, .75 + etaBin, 's: ' + str(npatterns['sgnPattern_' + key])) ttest.SetTextColor(2) ttest.DrawText(.5 + etBin, .25 + etaBin, 'b: ' + str(npatterns['bkgPattern_' + key])) try: histo1.GetYaxis().SetBinLabel( etaBin + 1, '#bf{%d} : %.2f->%.2f' % (etaBin, etaBins[etaBin], etaBins[etaBin + 1])) except Exception: logger.error("Couldn't retrieve eta bin %d bounderies.", etaBin) histo1.GetYaxis().SetBinLabel(etaBin + 1, str(etaBin)) try: histo1.GetXaxis().SetBinLabel( etBin + 1, '#bf{%d} : %d->%d [GeV]' % (etBin, etBins[etBin], etBins[etBin + 1])) except Exception: logger.error("Couldn't retrieve et bin %d bounderies.", etBin) histo1.GetXaxis().SetBinLabel(etBin + 1, str(etaBin)) c1.SetGrid() c1.Update() c1.SaveAs(outname)
def RunAnalysis(inputName, outputName="", source="", CT_StS=0.0, CT_StBP=0.0): if outputName == 0: outputName = inputName.split("_")[0] + "_analysed.root" print("INPUT:", inputName, "\nOUTPUT:", outputName) rootFile = TFile("data/raw/" + inputName) writeFile = TFile("data/" + outputName, "recreate") (thrStartFC, thrEndFC, thrStepFC) = (0.3, 8, 0.1) effTitle = "Efficiency" effHist = TH1F(effTitle, effTitle, 200, thrStartFC, thrEndFC) clusTitle = "Average_cluster_size" clusHist = TH2I(clusTitle, clusTitle, 200, thrStartFC, thrEndFC, 400, 0, 10) if source == "athena": hitTree = rootFile.Get("SCT_RDOAnalysis").Get("SCT_RDOAna") nOfStrips = 1280 nOfParts = 0 for event in hitTree: if len(list(event.charge)) > 0: nOfParts += 1 elif source == "allpix": hitTree = rootFile.PixelCharge nOfStrips = int( str(rootFile.models.Get("atlas17_dut").Get( "number_of_pixels")).split(" ")[1]) nOfParts = int( str(rootFile.config.Get("Allpix").Get("number_of_events"))) else: print("Unknown source.") return 1 print("CONFIG: Source:", source, ", Events:", nOfParts, ", CT_StS:", CT_StS, ", CT_StBP:", CT_StBP) # charge_sum = 0 for thr in np.arange(thrStartFC, thrEndFC, thrStepFC): thrE = thr * 6242.2 print("Current threshold [fC]:", round(thr, 1), end="\r") for event in hitTree: # iterating over all events cluster = GetCluster(event, thrE, source, CT_StS, CT_StBP, nOfStrips) if cluster > 0: effHist.Fill(thr) clusHist.Fill(thr, cluster) effHist.Scale(1 / nOfParts) clusHistOrig = clusHist clusHist = clusHist.ProfileX() print("Analysis done. \n") rootFile.Close() writeFile.Write() writeFile.Close()
def draw_hitmap(self, cluster=False, vcal=None, fid=False): h = TH2I('hhm{}'.format(cluster), '{} Map'.format('Cluster' if cluster else 'Hit'), *self.Bins) x = self.get_x(fid, cluster) if vcal is None else self.get_x( fid, cluster)[where(self.get_vcal_values(fid) < vcal)] y = self.get_y(fid, cluster) if vcal is None else self.get_y( fid, cluster)[where(self.get_vcal_values(fid) < vcal)] h.FillN(x.size, x.astype('d'), y.astype('d'), full(x.size, 1, 'd')) format_histo(h, x_tit='column', y_tit='row', y_off=1.2, z_tit='Number of Entries', z_off=1.6) self.Plotter.format_statbox(entries=True, x=.8) self.Plotter.draw_histo(h, lm=.13, rm=.18, draw_opt='colz', x=1.17)
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh = TH2D('hh', ';Y;X', 2, 2, 4, 14, 2, 16) hi = TH2I('hi', ';Y;X', 2, 2, 4, 14, 2, 16) setupHists([hh, hi]) xax, yax = hh.GetXaxis(), hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1, 1) gPad.SetLeftMargin(0.05) gPad.SetRightMargin(0.12) tt1 = TPaveText(0.05, 0.94, 0.22, 1.0, 'NDC') ttL = TPaveText(0.05, 0.905, 0.2, 0.93, 'NDC') ttR = TPaveText(0.75, 0.905, 0.9, 0.93, 'NDC') ttLM = TPaveText(2, 0.5, 2.5, 1) ttRM = TPaveText(3.5, 0.5, 4, 1) ttM = TPaveText(0.6, 0.94, 0.9, 1, 'NDC') ttime = TPaveText(2.8, 1.5, 3.3, 1.9) tchan = TPaveText(0, 0, 0.9, 1) setupPaveTexts([tt1, ttM, ttime, tchan, ttL, ttR, ttLM, ttRM]) ttM.SetTextColor(2) tarrow = TText(2.9, 0.25, 'Beam Left') arrow = TArrow(2.85, 0.5, 2.75, 0.5, 0.02, '|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt = TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(4.07, 9, 'kHz') tt.SetTextAngle(0) tt.SetTextColor(2) tt.DrawTextNDC(0.23, 0.905, 'SHMS PCAL FADC SCALERS') ttL.AddText('Left+') ttR.AddText('-Right') cc.cd() for xx in [ttM, tt1, ttL, ttR, arrow, tarrow, ttime, ttLM, ttRM]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() xmin, xmax = xax.GetXmin(), xax.GetXmax() ymin, ymax = yax.GetXmin(), yax.GetXmax() gPad.SetEditable(0) while True: zvals = getScalars() for ii in range(len(zvals)): hh.SetBinContent(xax.FindBin(XVALS[ii] + 1), yax.FindBin(16 - YVALS[ii]), zvals[ii]) hi.SetBinContent(xax.FindBin(XVALS[ii] + 1), yax.FindBin(16 - YVALS[ii]), zvals[ii]) for xx in [ttime, ttM, tt1, ttLM, ttRM]: xx.Clear() [left, right, maximum] = calcRates(zvals) tt1.AddText('Total: %.1f MHz' % ((left + right) / 1000)) ttLM.AddText('Left total: %.1f MHz' % (left / 1000)) ttRM.AddText('Right total: %.1f MHz' % (right / 1000)) ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz' % (maximum)) ttime.AddText(makeTime()) if not gPad: sys.exit() #if gPad.GetEvent()==11: # xy=pix2xy(gPad) #ee=ECAL.findChannelXY(xy[0],xy[1]) #if ee: # tchan.Clear() #tchan.AddText(printChannel(ee)) # cc2.Modified() # cc2.Update() #elif gPad.GetEvent()==12: # tchan.Clear() # cc2.Modified() # cc2.Update() cc.Modified() cc.Update() time.sleep(1)
def read_file(arr, meas_type, mapsa_fitter_inst, path): if not os.path.isfile(str(path + arr[0])): print "Root file not found at", str(path + arr[0]) #sys.exit(1) return f = TFile(str(path + arr[0]), 'READ') if (f.IsZombie()): print "Error opening file" return else: print "Reading File ", arr[0] #f.ls() tree = f.Get('tree') f_GlobalData_Map = ROOT.TMap() f_GlobalData_Map.Add(ROOT.TObjString("tree"), tree) #tree.Print() outfile = TString(arr[0]) outfile.ReplaceAll(".root", "") outfile.ReplaceAll(" ", "") # print outfile if (meas_type == 0): outfile = "pedestal" if (not g.FindKey(str(outfile))): g.mkdir(str(outfile)) g.cd(str(outfile)) else: return channels = 288 if (arr[2] == 'inv'): channels = 96 mapsa_mat = [[1, 0, 0], [1, 0, 0]] elif (arr[2] == 'norm'): channels = 288 mapsa_mat = [[1, 1, 1], [1, 0, 1]] #print "channels", channels #print "mapsa_mat", mapsa_mat c1 = TCanvas('c1', 'Pixel Monitor ', 700, 900) c2 = TCanvas('c2', 'Pixel Monitor ', 500, 500) c3 = TCanvas('c3', 'Pixel Monitor ', 1280, 720) c4 = TCanvas('c4', 'Pixel Monitor ', 500, 500) c5 = TCanvas('c5', 'Pixel Monitor ', 500, 500) f_GlobalData_Map.Add(ROOT.TObjString("c1"), c1) f_GlobalData_Map.Add(ROOT.TObjString("c2"), c2) f_GlobalData_Map.Add(ROOT.TObjString("c3"), c3) f_GlobalData_Map.Add(ROOT.TObjString("c4"), c4) f_GlobalData_Map.Add(ROOT.TObjString("c5"), c5) # c2.Divide(2,1) #c2.cd(0) c1.Divide(3, 2) for i in range(1, 7): c1.cd(i) ROOT.gPad.SetGridx() ROOT.gPad.SetGridy() # channelcounts = TH2I('HitMap','Counts; Channel; DAC Value (1.456 mV)', 288, .5,288.5,256, .5, 256.5) channelcounts = TH2I('HitMap', 'Counts; Channel; DAC Value (a.u.)', 288, .5, 288.5, 256, .5, 256.5) channelcounts_norm = TH2F('HitMap_norm', 'Occupancy ; Channel; DAC Value (a.u.)', 288, .5, 288.5, 256, .5, 256.5) f_GlobalData_Map.Add(ROOT.TObjString("HitMap"), channelcounts) f_GlobalData_Map.Add(ROOT.TObjString("HitMap"), channelcounts_norm) norm_2d = TH2F('Norm2D', 'Normalization; Column; Row', 48, .5, 48.5, 6, .5, 6.5) mean_2d = TH2F('Mean2D', 'Mean; Column; Row', 48, .5, 48.5, 6, .5, 6.5) sigma_2d = TH2F('Sigma2D', 'Sigma; Column; Row', 48, .5, 48.5, 6, .5, 6.5) chisquare = TH2F('Chisquare2D', 'Chisquare; Column; Row', 48, .5, 48.5, 6, .5, 6.5) f_GlobalData_Map.Add(ROOT.TObjString("Norm2D"), norm_2d) f_GlobalData_Map.Add(ROOT.TObjString("Mean2D"), mean_2d) f_GlobalData_Map.Add(ROOT.TObjString("Sigma2D"), sigma_2d) f_GlobalData_Map.Add(ROOT.TObjString("Chisquare2D"), chisquare) objarr2d = [] objarr2d.append(norm_2d) objarr2d.append(mean_2d) objarr2d.append(sigma_2d) objarr2d.append(chisquare) normgraph = TGraphErrors() meangraph = TGraphErrors() sigmagraph = TGraphErrors() chisquaregraph = TGraphErrors() mean_corrgraph = TGraphErrors() f_GlobalData_Map.Add(ROOT.TObjString("normgraph "), normgraph) f_GlobalData_Map.Add(ROOT.TObjString("meangraph "), meangraph) f_GlobalData_Map.Add(ROOT.TObjString("sigmagraph "), sigmagraph) f_GlobalData_Map.Add(ROOT.TObjString("chisquaregraph"), chisquaregraph) f_GlobalData_Map.Add(ROOT.TObjString("mean_corrgraph"), mean_corrgraph) meanhist = TH1F('meanhist', 'Mean DAC; DAC Value (a.u.); counts', 2560, 0, 255) sigmahist = TH1F('sigmahist', 'Sigma DAC; DAC Value (a.u.); counts', 100, 0, 10) meanhist_std = TH1F('meanhist_std', 'Mean DAC Standard; DAC Value (a.u.); counts', 2560, 0, 255) sigmahist_std = TH1F('sigmahist_std', 'Sigma DAC Standard; DAC Value (a.u.); counts', 100, 0, 10) meanhist_double = TH1F('meanhist_double', 'Mean DAC Double; DAC Value (a.u.); counts', 2560, 0, 255) sigmahist_double = TH1F('sigmahist_double', 'Sigma DAC Double; DAC Value (a.u.); counts', 100, 0, 10) meanhist_double_neighbour = TH1F( 'meanhist_double_neighbour', 'Mean DAC Double Neighbour; DAC Value (a.u.); counts', 2560, 0, 255) sigmahist_double_neighbour = TH1F( 'sigmahist_double_neighbour', 'Sigma DAC Double Neighbour; DAC Value (a.u.); counts', 100, 0, 10) objarr = [] objarr.append(normgraph) objarr.append(meangraph) objarr.append(sigmagraph) objarr.append(chisquaregraph) objarr.append(mean_corrgraph) f_GlobalData_Map.Add(ROOT.TObjString('meanhist'), meanhist) f_GlobalData_Map.Add(ROOT.TObjString('sigmahist'), sigmahist) f_GlobalData_Map.Add(ROOT.TObjString('meanhist_std'), meanhist_std) f_GlobalData_Map.Add(ROOT.TObjString('sigmahist_std'), sigmahist_std) f_GlobalData_Map.Add(ROOT.TObjString('meanhist_double'), meanhist_double) f_GlobalData_Map.Add(ROOT.TObjString('sigmahist_double'), sigmahist_double) f_GlobalData_Map.Add(ROOT.TObjString('meanhist_double_neighbour'), meanhist_double_neighbour) f_GlobalData_Map.Add(ROOT.TObjString('sigmahist_double_neighbour'), sigmahist_double_neighbour) objarr.append(meanhist) objarr.append(sigmahist) objarr.append(meanhist_std) objarr.append(sigmahist_std) objarr.append(meanhist_double) objarr.append(sigmahist_double) objarr.append(meanhist_double_neighbour) objarr.append(sigmahist_double_neighbour) for objs in objarr: objs.SetMarkerColor(2) objs.SetMarkerStyle(20) objs.SetMarkerSize(1) normgraph.SetName('normgraph') meangraph.SetName('meangraph') sigmagraph.SetName('sigmagraph') chisquaregraph.SetName('chisquare') mean_corrgraph.SetName('mean_corr') normgraph.SetTitle('Normalization; Channel; Normalization') meangraph.SetTitle('Mean; Channel; DAC Value (a.u.)') sigmagraph.SetTitle('Sigma; Channel; DAC Value (a.u.)') chisquaregraph.SetTitle('Chisquared/NDF_gr; Channel; Chisquared/NDF ') ROOT.gStyle.SetOptFit(1111) stack = THStack('a', ';DAC Value (a.u.); Occupancy') f_GlobalData_Map.Add(ROOT.TObjString("stack"), stack) fitfuncs = [] fitparams = [] gr1 = [] for pixel in range(0, channels): gr1.append( TH1D( str(pixel).zfill(3), str(pixel + 1).zfill(3) + ';DAC Value (a.u.); Occupancy ', 256, 0.5, 256.5)) f_GlobalData_Map.Add(ROOT.TObjString(str(pixel).zfill(3)), gr1[pixel]) #gr2.append(TH1F('th1f_'+str(pixel).zfill(3),str(pixel+1).zfill(3)+';DAC Value (a.u.); Occupancy',256,0.5,256.5)) color = pixel % 8 + 1 formating_th1(gr1[pixel], color) if (meas_type == 0): fitfuncs.append( TF1('gauss' + str(pixel + 1).zfill(3), 'gaus(0)', 0, 256)) fitfuncs[pixel].SetNpx(256) fitfuncs[pixel].SetLineColor(color) f_GlobalData_Map.Add( ROOT.TObjString('gauss' + str(pixel).zfill(3)), fitfuncs[pixel]) #Here we read the data and fill the histogram for event in tree: eventstr = [] for counter, vals in enumerate(tree.AR_MPA): #eventstr.append(vals) channelcounts.Fill(counter, tree.THRESHOLD, vals) if (counter < channels): gr1[counter].Fill(tree.THRESHOLD, vals) #if tree.THRESHOLD%20==0 and tree.REPETITION==0: #print eventstr #print ("Threshold %d Repetion %d" % (tree.THRESHOLD,tree.REPETITION)) #print tree.AR_MPA #now we make a small analysis of the curves fitting different functions to it: print "Finished Reading the Tree\n Normalization of Histograms\n" for pixel in range(0, channels): #gr1[pixel].ResetStats() for j in range(0, gr1[pixel].GetXaxis().GetNbins() + 1): gr1[pixel].SetBinError( gr1[pixel].GetBin(j), TMath.Sqrt(gr1[pixel].GetBinContent(gr1[pixel].GetBin(j)))) #if(pixel==0): #gr1[pixel].Print("all") #gr1[pixel].Sumw2(ROOT.kTRUE) gr1[pixel].Scale(1 / arr[1]) #if(pixel==0): #gr1[pixel].Print("all") stack.Add(gr1[pixel]) #first create a THStack with histograms: iterator = stack.GetHists() if (meas_type == 0): for idx, it in enumerate(iterator): fitparams.append([]) if (it.Integral() > 0): if (idx < channels): #fitfuncs.append(TF1('combined'+str(idx),combined, 0,256,5)) #fitfuncs.append(TF1('combined_same_mean'+str(idx),combined_mean, 0,256,4)) #fitfuncs.append(TF1('double_gauss'+str(idx),'gaus(0)+gaus(3)',0,256)) #fitfuncs.append(TF1('gauss'+str(idx),'gaus(0)',0,256)) #fitfuncs.append(TF1('double_gauss_same_mean'+str(idx),double_gauss, 0,256,5)) #print it.GetName(), idx #fitfuncs[idx].SetParameters(it.GetMaximum(),it.GetMean()+1,it.GetRMS(),it.GetMean()-1,it.GetRMS()); #fitfuncs[idx].SetParameters(it.GetMaximum(),it.GetMean(),it.GetRMS()*0.1,it.GetRMS()*0.1); #print ("Channels %f\t%f\t%f\n" % (it.GetMaximum(),it.GetMean(),it.GetRMS())) fitfuncs[idx].SetParameters(it.GetMaximum(), it.GetMean(), it.GetRMS()) #fitfuncs[idx].SetParameters(0.999*it.GetMaximum(),it.GetMean(),.7*it.GetRMS(),0.001*it.GetMaximum(),it.GetMean(),10*it.GetRMS()); #fitfuncs[idx].SetParameters(0.999*it.GetMaximum(),it.GetMean(),.7*it.GetRMS(),0.001*it.GetMaximum(),10*it.GetRMS()); #it.Fit(fitfuncs[idx],'lr0 rob=0.95','same',0,256) #it.Fit(fitfuncs[idx],'lr0q ','',0,256) it.Fit(fitfuncs[idx], 'r0q ', '', 0, 256) fitparams[idx].append(fitfuncs[idx].GetParameter(0)) fitparams[idx].append(fitfuncs[idx].GetParameter(1)) fitparams[idx].append(fitfuncs[idx].GetParameter(2)) fitparams[idx].append(fitfuncs[idx].GetParError(0)) fitparams[idx].append(fitfuncs[idx].GetParError(1)) fitparams[idx].append(fitfuncs[idx].GetParError(2)) if (fitfuncs[idx].GetNDF() > 0): fitparams[idx].append(fitfuncs[idx].GetChisquare() / fitfuncs[idx].GetNDF()) else: for kk in range(0, 7): fitparams[idx].append(0) #print "fitparamarray" fitarray = np.array(fitparams) ## print fitarray for pointno, it in enumerate(fitarray): if (fitarray[pointno][0] > 0): normgraph.SetPoint(pointno, pointno + 1, fitarray[pointno][0]) normgraph.SetPointError(pointno, 0, fitarray[pointno][3]) meangraph.SetPoint(pointno, pointno + 1, fitarray[pointno][1]) meangraph.SetPointError(pointno, 0, fitarray[pointno][4]) meanhist.Fill(fitarray[pointno][1]) sigmagraph.SetPoint(pointno, pointno + 1, fitarray[pointno][2]) sigmagraph.SetPointError(pointno, 0, fitarray[pointno][5]) sigmahist.Fill(fitarray[pointno][2]) chisquaregraph.SetPoint(pointno, pointno + 1, fitarray[pointno][6]) chisquaregraph.SetPointError(pointno, 0, 0) ## iterator.ls() # Map the data to the pixel layout: tmp_objarr = [] tmp_objarr.extend( [meanhist_std, meanhist_double, meanhist_double_neighbour]) tmp_objarr.extend( [sigmahist_std, sigmahist_double, sigmahist_double_neighbour]) for i in tmp_objarr: print str(i.GetName()) fill2d(fitarray[:, 0], mapsa_mat, objarr2d[0]) fill2d(fitarray[:, 1], mapsa_mat, objarr2d[1]) fill2d(fitarray[:, 2], mapsa_mat, objarr2d[2]) fill2d(fitarray[:, 6], mapsa_mat, objarr2d[3]) fill1d_edges(objarr2d[1], tmp_objarr[0:3]) fill1d_edges(objarr2d[2], tmp_objarr[3:]) g.cd(str(outfile)) mapsa_fitter_inst.Make_dirs() mapsa_fitter_inst.Set_run_no(outfile) if (meas_type == 1): for idx, it in enumerate(iterator): if (it.Integral() > 0): if (idx < channels): mapsa_fitter_inst.Find_signal(it, idx, 0.0025, 3) g.cd() #g.mkdir(str(outfile)+"/Channels") #g.cd(str(outfile)+"/Channels") #iterator.Write() g.cd(str(outfile)) g.mkdir(str(outfile) + "/Overview") ## iterator.First().Print("all") Maximum = TMath.Power(10, (round(TMath.Log10(stack.GetMaximum())) - 1)) #Minimum = TMath.Power(10,(round(TMath.Log10(stack.GetMinimum()))+1)) Minimum = .1 ROOT.gStyle.SetLabelSize(0.06, "xyz") ROOT.gStyle.SetTitleSize(0.06, "xyz") ROOT.gStyle.SetTitleOffset(1.2, "y") ROOT.gStyle.SetTitleOffset(.825, "x") ROOT.gStyle.SetPadGridX(1) ROOT.gStyle.SetPadGridY(1) ROOT.gStyle.SetOptStat(0) # ROOT.gStyle.SetPadLeftMargin(.2); # ROOT.gStyle.SetPadRightMargin(.1); c1.cd(1) stack.Draw("nostack hist e1 x0") stack.GetXaxis().SetRangeUser(0, 256) stack.SetMinimum(Minimum) stack.SetMaximum(Maximum) ROOT.gPad.SetLogy() c2.cd(0) stack.Draw("nostack hist e1 x0") #if(outfile.Contains("SR_90_on_top")): #stack.GetXaxis().SetRangeUser(0,256) #else: #stack.GetXaxis().SetRangeUser(0,100) stack.SetMinimum(Minimum) stack.SetMaximum(Maximum) ROOT.gPad.SetLeftMargin(.15) ROOT.gPad.SetRightMargin(.05) ROOT.gPad.SetLogy() ROOT.gPad.Update() #for idx, it in enumerate(fitfuncs): ## if idx>0 and idx<7: #c1.cd(1) #fitfuncs[idx].Draw("same") #c2.cd(0) #fitfuncs[idx].DrawCopy("psame") ## it.SetLineColor(idx%9+1) ## it.Draw("same") #g.cd(str(outfile)+"/Channels") #it.Write("HitMap_py_"+str(idx+1)+"_fit") g.cd(str(outfile) + "/Overview") c1.cd(2) chisquaregraph.Draw("ap") c1.cd(3) normgraph.Draw("ap") c1.cd(4) sigmagraph.Draw("ap") sigmagraph.GetYaxis().SetRangeUser(0, 5) sigmagraph.GetXaxis().SetRangeUser(0, channels + 1) c2.cd(2) sigmagraph.Draw("ap") ROOT.gPad.SetLeftMargin(.15) ROOT.gPad.SetRightMargin(.05) c1.cd(5) meangraph.Draw("ap") c1.cd(6) channelcounts.Draw("colz") channelcounts.GetXaxis().SetRangeUser(0, channels + 1) # c2.cd(3) c3.cd(0) ROOT.gStyle.SetOptStat(0) ROOT.gPad.SetRightMargin(.15) ROOT.gPad.SetLeftMargin(.15) ROOT.gPad.SetGrid(0) copy = channelcounts.DrawCopy("colz") #f_GlobalData_Map.Add(ROOT.TObjString("copy"),copy) #if(outfile.Contains("SR_90_on_top")): #copy.SetMaximum(100) #copy.SetMinimum(1) copy.GetYaxis().SetTitle("DAC Value (a.u.)") c4.cd(0) ROOT.gStyle.SetOptStat(0) ROOT.gPad.SetRightMargin(.15) ROOT.gPad.SetLeftMargin(.15) ROOT.gPad.SetGrid(0) copy1 = sigma_2d.DrawCopy("colz") #f_GlobalData_Map.Add(ROOT.TObjString("copy1"),copy1) copy1.GetZaxis().SetTitle("Sigma (a.u.)") copy1.GetZaxis().SetTitleOffset(1.2) ROOT.gPad.SetRightMargin(.2) if (arr[2] == 'inv'): copy1.GetXaxis().SetRangeUser(.5, 16.5) copy1.SetMaximum(5) copy1.SetMinimum(0) c5.cd(0) ROOT.gStyle.SetOptStat(0) ROOT.gPad.SetRightMargin(.15) ROOT.gPad.SetLeftMargin(.15) ROOT.gPad.SetGrid(0) #copy1 = chisquare.DrawCopy("colz") #f_GlobalData_Map.Add(ROOT.TObjString("copy2"),copy1) copy1 = sigma_2d.DrawCopy("colz") #f_GlobalData_Map.Add(ROOT.TObjString("copy2"),copy1) copy1.GetZaxis().SetTitle("sigma (a.u.)") if (arr[2] == 'inv'): copy1.GetXaxis().SetRangeUser(.5, 16.5) copy1.SetMaximum(5) copy1.SetMinimum(0) c1.Update() c1.Modified() c2.Update() c2.Modified() c3.Update() c3.Modified() c4.Update() c4.Modified() c5.Update() c5.Modified() ## c1.SaveAs("double_gauss_same_mean.pdf") ## time.sleep(2) g.cd(str(outfile) + "/Overview") #for objs in objarr: #objs.Write(objs.GetName()) #norm_2d.GetZaxis().SetRangeUser(1E5,2E6) #mean_2d.GetZaxis().SetRangeUser(54,64) ## norm_2d.GetZaxis().SetRangeUser(TMath.Power(10,(round(TMath.Log10(norm_2d.GetStdDev(3))-2)), TMath.Power(10,(round(TMath.Log10(norm_2d.GetStdDev(3)))-1))) ## mean_2d.GetZaxis().SetRangeUser(TMath.Power(10,(round(TMath.Log10(mean_2d.mean_2d.GetStdDev(3)))-1))-5,TMath.Power(10,(round(TMath.Log10(mean_2d.GetStdDev(3)))-1))+5) #sigma_2d.GetZaxis().SetRangeUser(0,5) #chisquare.GetZaxis().SetRangeUser(0,10000 ) #for objs in objarr2d: #objs.Write(objs.GetName()) #c1.Write("c1") #outfile1=outfile+TString(".pdf") #c2.SaveAs(str(outfile1)) #c2.Write("c2") #c3.SaveAs("c3"+str(outfile1)) #c3.Write("c3") #c4.SaveAs("c4"+str(outfile1)) #c4.Write("c4") ## while (TObject(iterator.Next())): ## print iterator.Next().Title() #stack.Write("stack") #g.cd(str(outfile)) #channelcounts.Write(str(outfile)) #f.Close() c1.Close() c2.Close() c3.Close() c4.Close() c5.Close() f_GlobalData_Map.DeleteAll() f.Close()
frameSN = bfifoSN.event_frame_number() print 'SN stream event {} frame {}'.format(eventSN, frameSN) if eventSN == maxUInt or frameSN == maxUInt: print '\tIgnoring event/frame!' continue # 2-D histogram depicting planes modPerCrate = 15 #maxTime = 12800 maxTime = 3200 #ignore for now the four-frames hU = TH2I( "hU", "Plane U Crate %d Run %d Frame %d; Rel. Channel; Time (#times 0.5 #mus)" % (crate, run, frameSN), 16 * modPerCrate, 0, 16 * modPerCrate, maxTime, 0, maxTime) hV = TH2I( "hV", "Plane V Crate %d Run %d Frame %d; Rel. Channel; Time (#times 0.5 #mus)" % (crate, run, frameSN), 16 * modPerCrate, 0, 16 * modPerCrate, maxTime, 0, maxTime) hY = TH2I( "hY", "Plane Y Crate %d Run %d Frame %d; Rel. Channel; Time (#times 0.5 #mus)" % (crate, run, frameSN), 32 * modPerCrate, 0, 32 * modPerCrate, maxTime, 0, maxTime) last_ch = 0 # last channel used modId = 0 # placeholder until decoder is able to handle this
ROOT.gPad.SetGridx() ROOT.gPad.SetGridy() f = TFile(files, 'READ') f.ls() tree = f.Get('tree') # tree.ls() # tree.Print() outfile = TString(files) outfile.ReplaceAll(".root", "") outfile.ReplaceAll(" ", "") # print outfile g.mkdir(str(outfile)) g.cd(str(outfile)) # channelcounts = TH2I('HitMap','Counts; Channel; DAC Value (1.456 mV)', 288, .5,288.5,256, .5, 256.5) channelcounts = TH2I('HitMap', 'Counts; Channel; DAC Value (a.u.)', 288, .5, 288.5, 256, .5, 256.5) norm_2d = TH2F('Norm2D', 'Normalization; Column; Row', 48, .5, 48.5, 6, .5, 6.5) mean_2d = TH2F('Mean2D', 'Mean; Column; Row', 48, .5, 48.5, 6, .5, 6.5) sigma_2d = TH2F('Sigma2D', '; Column; Row; Sigma (a.u.)', 48, .5, 48.5, 6, .5, 6.5) # sigma_2d = TH2F('Sigma2D','Sigma; Column; Row' , 48, .5,48.5,6, .5, 6.5) chisquare = TH2F('Chisquare2D', 'Chisquare; Column; Row', 48, .5, 48.5, 6, .5, 6.5) objarr2d = [] objarr2d.append(norm_2d) objarr2d.append(mean_2d) objarr2d.append(sigma_2d) objarr2d.append(chisquare) normgraph = TGraphErrors()
def AnalyseWaveforms(topology, PATH, PMT_data_filenames, root_filename, pre_PULSE_region, waveform_length): try: # Will not create a new file if one exists already waveformfile = open(root_filename, "r") print(">>> File exists") except IOError: print(">>> File not found") print(">>> Creating .root file with the Average Waveforms") root_file = TFile(root_filename, 'RECREATE') # First create all the conatiners for the histograms map_HT = TH2I("Mapping_HT", "Mapping_HT", topology[0], 0, topology[0], topology[1], 0, topology[1]) map_LTO = TH2I("Mapping_LTO", "Mapping_LTO", topology[0], 0, topology[0], topology[1], 0, topology[1]) map = TH2I("Mapping", "Mapping", topology[0], 0, topology[0], topology[1], 0, topology[1]) Spectra_hist_vector = [] Spectra_cal_hist_vector = [] Peak_Cell_hist_vector = [] Rise_Time_hist_vector = [] Amplitude_hist_vector = [] Ratio_hist_vector = [] amp_shape_vector = [] Average_Waveform_hist_vector = [] # Create a blank waveform for each OM average_pulse_trace_vector = [] average_pulse_counter_vector = [] event_num_HT_vector = [] event_num_LTO_vector = [] blank_num_vector = [] # Fill the containers with the objects for each OM in this Loop for slot_num in range(topology[0]): Spectra_hist_vector.append([]) Spectra_cal_hist_vector.append([]) Peak_Cell_hist_vector.append([]) Rise_Time_hist_vector.append([]) Amplitude_hist_vector.append([]) Ratio_hist_vector.append([]) Average_Waveform_hist_vector.append([]) average_pulse_trace_vector.append([]) average_pulse_counter_vector.append([]) event_num_HT_vector.append([]) event_num_LTO_vector.append([]) amp_shape_vector.append([]) blank_num_vector.append([]) for channel_num in range(topology[1]): Spectra_hist = TH1F( "Spectra_" + str(slot_num) + "_" + str(channel_num), "Spectra_" + str(slot_num) + "_" + str(channel_num), 200, 0, 200000) Spectra_hist.GetXaxis().SetTitle("Raw Charge") Spectra_hist_vector[slot_num].append(Spectra_hist) Spectra_cal_hist = TH1F( "Spectra_cal_" + str(slot_num) + "_" + str(channel_num), "Spectra_cal_" + str(slot_num) + "_" + str(channel_num), 200, 0, 200000) Spectra_cal_hist.GetXaxis().SetTitle("Raw Charge") Spectra_cal_hist_vector[slot_num].append(Spectra_cal_hist) Peak_Cell_hist = TH1F( "Peak_Cell_" + str(slot_num) + "_" + str(channel_num), "Peak_Cell_" + str(slot_num) + "_" + str(channel_num), waveform_length, 0, waveform_length) Peak_Cell_hist.GetXaxis().SetTitle( "Peak Cell Position /Sample Number") Peak_Cell_hist_vector[slot_num].append(Peak_Cell_hist) Rise_Time_hist = TH1F( "Rise_Time_" + str(slot_num) + "_" + str(channel_num), "Rise_Time_" + str(slot_num) + "_" + str(channel_num), 200, 50, 200) Rise_Time_hist.GetXaxis().SetTitle("Rise Time") Rise_Time_hist_vector[slot_num].append(Rise_Time_hist) Amplitude_hist = TH1F( "Amplitudes_" + str(slot_num) + "_" + str(channel_num), "Amplitudes_" + str(slot_num) + "_" + str(channel_num), 200, 0, 2100) Amplitude_hist.GetXaxis().SetTitle("Amplitude /ADC Counts") Amplitude_hist_vector[slot_num].append(Amplitude_hist) Ratio_hist = TH1F( "Ratio_" + str(slot_num) + "_" + str(channel_num), "Ratio_" + str(slot_num) + "_" + str(channel_num), 200, 0, 0.05) Ratio_hist.GetXaxis().SetTitle("Amplitude/Raw Charge") Ratio_hist_vector[slot_num].append(Ratio_hist) amp_shape_hist = TH2F( "amp_shape" + str(slot_num) + "_" + str(channel_num), "amp_shape" + str(slot_num) + "_" + str(channel_num), 100, 0, 2000, 100, 0, 1) amp_shape_hist.GetXaxis().SetTitle("Amplitude /mV") amp_shape_hist.GetYaxis().SetTitle("Shape") amp_shape_vector[slot_num].append(amp_shape_hist) average_pulse_trace_vector[slot_num].append([0] * waveform_length) average_pulse_counter_vector[slot_num].append(0) event_num_HT_vector[slot_num].append(0) event_num_LTO_vector[slot_num].append(0) blank_num_vector[slot_num].append(0) average_pulse_trace_hist = TH1F( "Waveform_" + str(slot_num) + "_" + str(channel_num) + "_average", "Waveform_" + str(slot_num) + "_" + str(channel_num) + "_average", waveform_length, 0, waveform_length) average_pulse_trace_hist.GetXaxis().SetTitle("Sample Number") average_pulse_trace_hist.GetYaxis().SetTitle( "Averaged ADC Counts /AU") Average_Waveform_hist_vector[slot_num].append( average_pulse_trace_hist) del Spectra_hist del Spectra_cal_hist del Peak_Cell_hist del Rise_Time_hist del Amplitude_hist del Ratio_hist del average_pulse_trace_hist print(">>> Create Templates... ") template = createTemplate(PATH + PMT_data_filenames[0].rstrip(), topology, waveform_length, pre_PULSE_region) # Now run ove the files print(">>> Reading Data Files... ") processing_start = time.time() temp_start = processing_start for file_num in range(len(PMT_data_filenames)): print(">>> File: ", PATH + PMT_data_filenames[file_num].rstrip()) Read_Data(PATH + PMT_data_filenames[file_num].rstrip(), pre_PULSE_region, average_pulse_counter_vector, event_num_HT_vector, event_num_LTO_vector, average_pulse_trace_vector, Spectra_hist_vector, Spectra_cal_hist_vector, Rise_Time_hist_vector, Peak_Cell_hist_vector, Amplitude_hist_vector, Ratio_hist_vector, amp_shape_vector, blank_num_vector, waveform_length, template) intermidiate = time.time() time_length = intermidiate - processing_start print(">>>\n>>> %.3f seconds.\n" % (intermidiate - temp_start)) temp_start = intermidiate print("Processed %.2f of data..." % (float(file_num + 1) / float(len(PMT_data_filenames)) * 100)) Estimate = (time_length / float(file_num + 1)) * ( len(PMT_data_filenames) - file_num - 1) print(">>> Estimated time till termination %.3f seconds\n\n" % Estimate) for slot_num in range(topology[0]): root_file.mkdir("Slot" + str(slot_num)) root_file.GetDirectory("Slot" + str(slot_num)).cd() Channel_Check = topology[1] for channel_num in range(topology[1]): root_file.GetDirectory("Slot" + str(slot_num)).mkdir("Channel" + str(channel_num)) root_file.GetDirectory("Slot" + str(slot_num)).GetDirectory( "Channel" + str(channel_num)).cd() Spectra_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) Spectra_cal_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) Rise_Time_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) Amplitude_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) Peak_Cell_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) Ratio_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) amp_shape_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) for bin in range( len(average_pulse_trace_vector[slot_num] [channel_num])): # Avoid dividing by zero if average_pulse_counter_vector[slot_num][ channel_num] == 0: average_pulse_counter_vector[slot_num][channel_num] = 1 Average_Waveform_hist_vector[ slot_num][channel_num].SetBinContent( bin, (average_pulse_trace_vector[slot_num][channel_num] [bin] / average_pulse_counter_vector[slot_num] [channel_num]) * 1000.0) Average_Waveform_hist_vector[slot_num][ channel_num].SetBinError(bin, 1.0) Average_Waveform_hist_vector[slot_num][channel_num].Write( "", TFile.kOverwrite) map.Fill( slot_num, channel_num, event_num_HT_vector[slot_num][channel_num] + event_num_LTO_vector[slot_num][channel_num]) map_HT.Fill(slot_num, channel_num, event_num_HT_vector[slot_num][channel_num]) map_LTO.Fill(slot_num, channel_num, event_num_LTO_vector[slot_num][channel_num]) if event_num_HT_vector[slot_num][ channel_num] + event_num_LTO_vector[slot_num][ channel_num] + blank_num_vector[slot_num][ channel_num] == 0: root_file.GetDirectory("Slot" + str(slot_num)).Delete( "Channel" + str(channel_num) + ";1") #print("\n>>> Deleted Slot: ",slot_num, " Channel: ", channel_num, " as there were no events\n") Channel_Check = Channel_Check - 1 if Channel_Check == 0: root_file.Delete("Slot" + str(slot_num) + ";1") print('\n>>> Deleted Slot: ', slot_num, ' as there were no events\n') root_file.cd() map.Write("", TFile.kOverwrite) map_HT.Write("", TFile.kOverwrite) map_LTO.Write("", TFile.kOverwrite) root_file.Close() print(">>>")
def draw_occupancy(self, roc=0, show=True): h = TH2I('h_oc', 'Occupancy ROC {n}'.format(n=roc), *self.Bins2D) self.Tree.Draw('row:col >> h_oc', '', 'goff') format_histo(h, x_tit='col', y_tit='row', z_tit='Number of Entries', y_off=1.3, z_off=1.6, stats=0) self.Drawer.draw_histo(h, draw_opt='colz', lm=.13, rm=0.17, show=show)
def main(): if True: mf=TGMainFrame(gClient.GetRoot(),1500,475) gvf=TGVerticalFrame(mf,1500,475) rec=TRootEmbeddedCanvas("ccc",gvf,1500,450) rec2=TRootEmbeddedCanvas("ccc2",gvf,1500,25) gvf.AddFrame(rec,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsTop)) gvf.AddFrame(rec2,TGLayoutHints(ROOT.kLHintsExpandX|ROOT.kLHintsBottom)) mf.AddFrame(gvf,TGLayoutHints(ROOT.kLHintsExpandX)) cc=rec.GetCanvas() cc2=rec2.GetCanvas() mf.SetEditable(0) mf.SetWindowName('HPS ECAL FADC SCALERS') mf.MapSubwindows() mf.Resize(1501,476)# resize to get proper frame placement mf.MapWindow() else: cc=TCanvas('cc','',1500,450) cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',46,-22,24,11,-5,6) hi=TH2I('hi',';X;Y',46,-22,24,11,-5,6) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.05) tt1=TPaveText(0.1,0.9,0.3,1.0,'NDC') tt2=TPaveText(0.7,0.91,0.9,0.99,'NDC') ttT=TPaveText(-22+13+0.05,6-5,-22+22,7-5-0.05) ttB=TPaveText(-22+13+0.05,4-5+0.05,-22+22,5-5) ttM=TPaveText(-22+0+0.05,5-5+0.05,-22+13,6-5.01) ttime=TPaveText(-10,-6.5,10,-5.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt1,tt2,ttT,ttB,ttM,ttime,tchan]) ttM.SetTextColor(2) bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-9+0.05,-1,0,1.97) bb.DrawBox(-24,0,24.05,0.97) tarrow=TText(14.5,0.3,'Beam Left') arrow=TArrow(19,0.5,23,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.08) tt.DrawText(25.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(2) tt.DrawTextNDC(0.3,0.92,'ECAL FADC SCALERS') cc.cd() for xx in [tt2,ttT,ttB,ttM,arrow,tarrow,ttime]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() ll=TLine() ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmax(),yax.GetXmin()) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmax(),yax.GetXmax()) ll.DrawLine(xax.GetXmin(),yax.GetXmin(),xax.GetXmin(),0) ll.DrawLine(xax.GetXmax(),yax.GetXmin(),xax.GetXmax(),0) ll.DrawLine(xax.GetXmin(),yax.GetXmax(),xax.GetXmin(),1) ll.DrawLine(xax.GetXmax(),yax.GetXmax(),xax.GetXmax(),1) ll.DrawLine(xax.GetXmax(),0,0,0) ll.DrawLine(xax.GetXmax(),1,0,1) ll.DrawLine(xax.GetXmin(),0,-9,0) ll.DrawLine(xax.GetXmin(),1,-9,1) ll.DrawLine(-9,-1,0,-1) ll.DrawLine(-9,2,0,2) ll.DrawLine(-9,1,-9,2) ll.DrawLine(-9,-1,-9,0) ll.DrawLine(0,-1,0,0) ll.DrawLine(0,1,0,2) gPad.SetEditable(0) while True: # try: zvals=getPVS() for ii in range(len(zvals)): hh.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) hi.SetBinContent(xax.FindBin(XVALS[ii]),yax.FindBin(YVALS[ii]),zvals[ii]) for xx in [ttime,tt2,ttT,ttB,ttM]: xx.Clear() [top,bottom,maximum]=calcRates(zvals) tt2.AddText('Total: %.1f MHz'%((top+bottom)/1000)) ttT.AddText('%.1f MHz'%(top/1000)) ttB.AddText('%.1f MHz'%(bottom/1000)) ttM.AddText('MAX SINGLE CRYSTAL = %.0f kHz'%(maximum)) ttime.AddText(makeTime()) if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(1)
def main(): cc.cd() cc.SetBorderMode(0) cc.SetFixedAspectRatio(1) cc.FeedbackMode(1) gStyle.SetOptStat(0) gStyle.SetGridStyle(1) gStyle.SetGridColor(11) hh=TH2D('hh',';X;Y',22,-10.5,11.5,22,-10.5,11.5) hi=TH2I('hi',';X;Y',22,-10.5,11.5,22,-10.5,11.5) setupHists([hh,hi]) xax,yax=hh.GetXaxis(),hh.GetYaxis() hh.Draw('COLZ') hi.Draw('TEXTSAME') gPad.SetLogz() gPad.SetGrid(1,1) gPad.SetLeftMargin(0.09) gPad.SetRightMargin(0.11) #tt2=TPaveText(0.7,0.96,0.9,0.99,'NDC') ttM=TPaveText(-3+0.05, 7-4.45, 4.0, 8-4.51) tt2=TPaveText(-3+0.05, 7-5.45, 4.0, 8-5.51) ttX=TPaveText(-2, 7-8.00, 3, 8-8.00) ttY=TPaveText(-2, 7-9.00, 3, 8-9.00) ttZ=TPaveText(-2, 6-8.80, 3, 8-9.30) ttZ.AddText("positive = beam top/right") ttime=TPaveText(-10,-12.5,10,-11.8) tchan=TPaveText(0,0,0.9,1) setupPaveTexts([tt2,ttM,ttime,tchan,ttX,ttY,ttZ]) ttM.SetTextColor(2) ttM.SetFillStyle(0) ttZ.SetFillStyle(0) tt2.SetFillStyle(0) tarrow=TText(-0.9,0.7,'Beam Right') tarrow.SetTextSizePixels(15) arrow=TArrow(-1.4,0.5,2.4,0.5,0.02,'|>') arrow.SetAngle(40) arrow.SetFillColor(1) arrow.SetLineWidth(2) tt=TText() tt.SetTextColor(1) tt.SetTextAngle(90) tt.SetTextSize(0.04) tt.DrawText(12.4,0,'kHz') tt.SetTextAngle(0) tt.SetTextColor(1) tt.DrawTextNDC(0.3,0.92,'FTC FADC SCALERS') bb=TBox() bb.SetFillStyle(1001) bb.SetFillColor(0) bb.SetLineWidth(1) bb.SetLineColor(1) bb.DrawBox(-3.47,-1.47,4.47,2.46) bb.DrawBox(-1.47,-3.47,2.49,4.47) bb.DrawBox(-2.47,-2.47,3.49,3.47) cc.cd() for xx in [ttM,tt2,ttime,arrow,tarrow,ttX,ttY,ttZ]: xx.Draw() cc2.cd() tchan.Draw('NDC') cc.cd() gPad.SetEditable(0) while True: for ch in ECAL.chans: loadPV(ch) ch=ch.vals xx,yy=ch['X'],ch['Y'] #if (ch['PVVAL']>10): # print xx,yy,ch['PVVAL'] # swap x to make it downstream view: xx=-xx #after, fix the fact x=0 / y=0 don't exists if xx<0: xx+=1 if yy<0: yy+=1 hh.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) hi.SetBinContent(xax.FindBin(xx),yax.FindBin(yy),ch['PVVAL']) for xx in [ttime,tt2,ttM,ttX,ttY]: xx.Clear() [total,maximum,top,bottom,left,right]=calcRates(ECAL.chans) tt2.AddText('Total: %.1f MHz'%(total/1000)) ttM.AddText('Max: %.0f kHz'%(maximum)) if total>1e2: xasy = (right-left)/total yasy = (top-bottom)/total ttX.AddText('X-Asy: %+.1f%%'%(100*xasy)) ttY.AddText('Y-Asy: %+.1f%%'%(100*yasy)) else: ttX.AddText('X-Asy: N/A') ttY.AddText('Y-Asy: N/A') ttime.AddText(makeTime()) if not gPad: sys.exit() if gPad.GetEvent()==11: xy=pix2xy(gPad) ee=ECAL.findChannelXY(xy[0],xy[1]) if ee: tchan.Clear() tchan.AddText(printChannel(ee)) cc2.Modified() cc2.Update() elif gPad.GetEvent()==12: tchan.Clear() cc2.Modified() cc2.Update() cc.Modified() cc.Update() time.sleep(2)
def main(): #gROOT.SetBatch(True) gROOT.SetBatch(False) gStyle.SetOptTitle(1) # Title for histograms gStyle.SetPadRightMargin(0.15) gStyle.SetCanvasDefW(800) gStyle.SetTickLength(0, "X") gStyle.SetTickLength(0, "Y") maxUInt = 4294967295 # Maximum integer to be used. Default value when the decoder cannot decode anything #maxTime = 12800 maxTime = 3200 # Maximum time to be displayed: ignore for now the four-frames # MicroBooNE channel map ChMap = ubmap.ChannelMap( "/home/jcrespo/MicroBooNE/ubelec01/MicroBooNEChannelMap/MicroBooNEChannelMap.txt" ) crateChain = [] # List holding the TChain from each crate for f in xrange(1, len(sys.argv)): crateChain.append(TChain("tpcfifo_tpcfifo_tree")) crateChain[-1].AddFile(sys.argv[f]) print 'SN stream file ', crateChain[-1].GetFile().GetName() # Get crate number from file name crate = int(re.findall("\d+", sys.argv[f])[0]) print 'Crate ', crate if f != crate: print 'ERROR: Expected crate {} but got crate {}'.format(f, crate) sys.exit() # Get run number from file name run = int(re.findall("\d+", sys.argv[f])[-2]) print 'Run ', run # Add check so all files have same run number # Canvas for event display. It will be renamed later canvas = TCanvas("c", "c") canvas.Divide(1, 3) # 2-D histograms depicting planes hU = TH2I("hU", "hU", 2400, 0, 2400, maxTime, 0, maxTime) hV = TH2I("hV", "hV", 2400, 0, 2400, maxTime, 0, maxTime) hY = TH2I("hY", "hY", 3456, 0, 3456, maxTime, 0, maxTime) # Color scale maxima and minima. Roughly based on typical baseline +/- 100 ADC hU.SetMaximum(2148) hU.SetMinimum(1948) hV.SetMaximum(2148) hV.SetMinimum(1948) hY.SetMaximum(575) hY.SetMinimum(375) # List holding the current entry index for each crate crateEntry = [0] * len(crateChain) # Align all crates to show this frame first frameReference = 0 # While TChains have entries while WithinLimits(crateEntry, crateChain): hU.Reset() hV.Reset() hY.Reset() for crate, chain in enumerate(crateChain): frame = -1 frameMissing = False while frame != frameReference: chain.GetEntry(crateEntry[crate]) fifo = chain.tpcfifo_tpcfifo_branch frame = fifo.event_frame_number() event = fifo.event_number() if ((frame < frameReference) or (event == maxUInt) or (frame == maxUInt)): crateEntry[crate] += 1 if frame > frameReference: frameMissing = True break if frameMissing: continue crate += 1 # enumerate starts from 0 print 'SN stream crate {} event {} frame {}'.format( crate, event, frame) last_ch = 0 # last channel used xmitAddr = 3 # XMIT address # First and last TPC crates have the XMIT in a different slot if crate == 1: xmitAddr = 7 elif crate == 9: xmitAddr = 4 modId = xmitAddr + 1 # placeholder until decoder is able to handle this modAddr = xmitAddr + 1 # placeholder until decoder is able to handle this # tpcfifo is a vector of ROIs without channel separation for roi in fifo: # roi is a fifo object (defined at core/DataFormat) ch = roi.channel_number() # Hack: detect module change when there is a negative difference between channel numbers if ch - last_ch < 0: # Not completely safe modId += 1 modAddr += 1 last_ch = ch t0SN = roi.readout_sample_number_RAW() #modId = roi.module_id() # decoder does not decode this yet #modAddr = roi.module_address() # decoder does not decode this yet # print 'ROI found in crate {}, module {}/slot {}, channel {} at time {} with {} samples'.format( # crate, modId, modAddr, ch, t0SN, roi.size() # ) plane, larch = ChMap.CrateFEMCh2PlaneWire(crate, modAddr, ch) # Correct for offset due to presamples + lost ADC in NU stream due to channel header? presamples = 7 # Hardcoded t0SN = t0SN - presamples - 1 for s in xrange(roi.size()): tdc = t0SN + s adc = roi[s] if plane == "Y": hY.Fill(larch, tdc, adc) elif plane == "U": hU.Fill(larch, tdc, adc) elif plane == "V": hV.Fill(larch, tdc, adc) #if crate != 9: # continue # If crate counter did not reach 9, it means one or more crates were bad. canvasNameTitle = "canvas_run%d_frame%d" % (run, frame) canvas.SetName(canvasNameTitle) canvas.SetTitle(canvasNameTitle) canvas.cd(1) hU.SetTitle( "Plane U Run %d Frame %d; Channel; Time (#times 0.5 #mus)" % (run, frame)) hU.Draw("colz") canvas.Update() canvas.cd(2) hV.SetTitle( "Plane V Run %d Frame %d; Channel; Time (#times 0.5 #mus)" % (run, frame)) hV.Draw("colz") canvas.Update() canvas.cd(3) hY.SetTitle( "Plane Y Run %d Frame %d; Channel; Time (#times 0.5 #mus)" % (run, frame)) hY.Draw("colz") canvas.Update() print "Enter any key to go to next frame" dummy = sys.stdin.readline() frameReference += 1 # End of loop over SN events sys.exit()
def take_data(resolution, low, up, config, rangeval, mapsa, buffnum, daq, strobe_sets, sdur, smode, savestr, singlepixel): direction = 1 if ((up - low) > 0) else -1 steps = int(round(abs(low - up) / resolution)) + 1 c1 = TCanvas('c1', 'Source Monitor ', 700, 900) c1.Divide(2, 2) totalcounts = TH1I('Totalcounts', 'Totalcounts; DAC Value (1.456 mV); Counts (1/1.456)', steps, low - .5, up + .5) channelcounts = TH2I( 'Totalcounts_pixel', 'Totalcounts; DAC Value (1.456 mV); Counts (1/1.456)', 288, .5, 288.5, steps, low - .5, up + .5) totalcounts.SetDirectory(0) channelcounts.SetDirectory(0) # f = TFile( 'sourcetest'+savestr+'.root', 'RECREATE' ) f = TFile(savestr + '.root', 'RECREATE') tree_vars = {} tree_vars["TIMESTAMP"] = array('i', [0]) tree_vars["SEQ_PAR"] = array('i', [0]) tree_vars["TRIG_COUNTS_SHUTTER"] = array('i', [0]) tree_vars["THRESHOLD"] = array('i', [0]) tree_vars["REPETITION"] = array('i', [0]) tree_vars["AR_MPA"] = array('i', [0] * 288) tree_vars["MEM_MPA"] = array('i', [0] * (96 * no_mpa_light)) tree = TTree('datatree', 'datatree') for key in tree_vars.keys(): # if "SR" in key: # tree.Branch(key,tree_vars[key],key+"[96]/i") if "AR" in key: tree.Branch(key, tree_vars[key], key + "[288]/i") if "MEM" in key: tree.Branch(key, tree_vars[key], key + "[384]/i") if "TRIG_COUNTS" in key: tree.Branch(key, tree_vars[key], key + "[1]/i") if "THRESHOLD" in key: tree.Branch(key, tree_vars[key], key + "[1]/i") if "REPETITION" in key: tree.Branch(key, tree_vars[key], key + "[1]/i") # daq.Strobe_settings(strobe_sets[0],strobe_sets[1],strobe_sets[2],strobe_sets[3],strobe_sets[4]) mapsa.daq().Strobe_settings(snum, sdel, slen, sdist, CE) if (singlepixel == True): tree_vars["SEQ_PAR"][0] = 1 for iy1 in range(0, 50): if iy1 % 2 == 0: config.modifypixel((iy1) / 2 + 1, 'PML', pmmask) if iy1 % 2 == 1: config.modifypixel((iy1 + 1) / 2, 'PMR', pmmask) if (singlepixel == False): tree_vars["SEQ_PAR"][0] = 0 for z in range(0, rangeval): for xx in range(0, steps): x = xx * resolution * direction + low if (x < 0): x = 0 if (x > 255): x = 255 if (singlepixel == False and x % 10 == 0): print "THDAC " + str(x) if (singlepixel == True): print "THDAC " + str(x) # tstamp = str(datetime.datetime.now().time().isoformat().replace(":","").replace(".","")) # print "Timestamp: " + tstamp tree_vars["REPETITION"][0] = z tree_vars["THRESHOLD"][0] = x config.modifyperiphery('THDAC', [x] * 6) tree_vars["AR_MPA"][:] = array('i', 48 * no_mpa_light * [0]) if (singlepixel == False): config.upload() config.write() # print tree_vars["REPETITION"] # print 'sdur', hex(sdur) mapsa.daq().Sequencer_init(smode, sdur) time.sleep(0.002) pix, mem = mapsa.daq().read_data(buffnum) time.sleep(0.002) # print "pix", pix ipix = 0 # treevars["MEM"][0,384]=array('i',mem[:]) # print mem for p in pix: p.pop(0) p.pop(0) tree_vars["AR_MPA"][ipix * 48:(ipix + 1) * 48] = array( 'i', p[:]) # print 'p ', p[:] # print 'ipix, p ', ipix, p[:] ipix += 1 sum_hits = np.sum(tree_vars["AR_MPA"][:]) # totalcounts.Fill(x,sum_hits) # print tree_vars["AR_MPA"][:] # print len(tree_vars["AR_MPA"][:]) # for counter,hits in enumerate(tree_vars["AR_MPA"]): # channelcounts.Fill(counter+1,x,hits) if (singlepixel == True): count_arr = np.zeros((no_mpa_light, 48)) for iy1 in range(2, 50): if iy1 % 2 == 1: config.modifypixel((iy1 - 1) / 2, 'PML', pmmaskon) config.modifypixel((iy1 - 1) / 2, 'PMR', pmmask) if iy1 % 2 == 0: if iy1 != 2: config.modifypixel(iy1 / 2 - 1, 'PML', pmmask) config.modifypixel(iy1 / 2, 'PMR', pmmaskon) else: config.modifypixel(24, 'PML', pmmask) config.modifypixel(24, 'PMR', pmmask) config.modifypixel(1, 'PML', pmmask) config.modifypixel(1, 'PMR', pmmaskon) config.upload() config.write() mapsa.daq().Sequencer_init(smode, sdur) time.sleep(0.002) pix, mem = mapsa.daq().read_data(buffnum) time.sleep(0.002) ipix = 0 # treevars["MEM"][0,384]=array('i',mem[:]) # print mem for pixcounter, p in enumerate(pix): p.pop(0) p.pop(0) count_arr[ipix] = count_arr[ipix] + np.array( array('i', p)) # print 'p ', p[:] ipix += 1 tree_vars["AR_MPA"][:] = array( 'i', count_arr.astype(int).flatten().tolist()[:]) # print tree_vars["AR_MPA"][:] # print len(tree_vars["AR_MPA"][:]) for counter, hits in enumerate(tree_vars["AR_MPA"]): channelcounts.Fill(counter + 1, x, hits) sum_hits = np.sum(tree_vars["AR_MPA"][:]) totalcounts.Fill(x, sum_hits) tree.Fill() tree.Write('tree', ROOT.TObject.kOverwrite) c1.cd(1) totalcounts.Draw('hist e1') c1.cd(2) channelcounts.Draw('colz') c1.Modified() c1.Update() # c1.Write("test") # time.sleep(2) channelcounts.Write("channelcounts") totalcounts.Write("totalcounts") f.Close()
def report(): global freed_file print' HeapMonReport.report(): heapmon_file=', freed_file #findStaticHoles() tfile = TFile(freed_file, "READ") print " root compression factor = ", tfile.GetCompressionFactor() mem_canvas = TCanvas("HeapMon_report", "Memory Holes Statistics", 10, 10, 800, 1034); mem_canvas.SetFillColor(17); mem_canvas.cd() pad1 = TPad("pad1","pad1",0.01,0.57,0.50,0.93,33); pad2 = TPad("pad2","pad2",0.51,0.57,0.99,0.93,33); pad3 = TPad("pad3","pad3",0.01,0.01,0.99,0.50,33); pad3.SetPhi(210); pad3.SetTheta(25); pad1.Draw(); pad2.Draw(); pad3.Draw(); memTree = tfile.Get("holeTree") infoTree = tfile.Get("infoTree") mallocTree = tfile.Get("mallocTree") #holesm_th1i = TH1I('holesm_th1i', 'Holes size evolution', fcount, 0, fcount) #holesn_th1i = TH1I('holesn_th1i', 'Holes number evolution', fcount, 0, fcount) #total_th1i = TH1I('total_th1i', 'Total memory size evolution', fcount, 0, fcount) max_hole_size = memTree.GetMaximum("hole_size") print " max_hole_size=", max_hole_size, " min_hole_size", memTree.GetMinimum("hole_size") max_scan_number = memTree.GetMaximum("scan_number") print " max_scan_number=", max_scan_number memHist1 = TH2I("mem2d","Hole-sizes distribution evolution", 128, -0.5, max_hole_size - 0.5, 50, 0, max_scan_number) memTree.Project("mem2d", "scan_number:hole_size"); multiGraph1 = TMultiGraph(); multiGraph2 = TMultiGraph(); print " memHist.GetMaximum() = ", memHist1.GetMaximum(); # Working on a Report gStyle.SetOptStat(0); gStyle.SetPalette(1); gStyle.SetCanvasColor(33); gStyle.SetFrameFillColor(18); memHist1.SetFillColor(30); memHist1.SetFillStyle(0); memHist1.GetXaxis().SetTitle("Size of holes, kb"); memHist1.GetXaxis().SetLabelOffset(0.02); memHist1.GetXaxis().SetLabelSize(0.02); memHist1.GetXaxis().SetTitleSize(0.04); memHist1.GetXaxis().SetTitleColor(2); memHist1.GetYaxis().SetTitle("Event number"); memHist1.GetYaxis().SetLabelSize(0.04); memHist1.GetXaxis().SetLabelOffset(0.04); memHist1.GetYaxis().SetTitleSize(0.04); memHist1.GetYaxis().SetTitleColor(2); memHist1.GetZaxis().SetTitle("Number of holes"); memHist1.GetZaxis().SetLabelSize(0.02); memHist1.GetZaxis().SetTitleSize(0.04); memHist1.GetZaxis().SetTitleColor(2); title = TPaveLabel(0.1,0.95,0.9,0.99, "Job Memory Usage Plots"); title.SetFillColor(42); title.SetTextFont(42); title.Draw(); text_box = TPaveText(0.1,0.51,0.9,0.54); text_box.AddText("Malloc freed ('marked') Heap Memory Profile"); text_box.SetFillColor(42); text_box.SetTextAlign(12); text_box.SetTextFont(42); text_box.Draw(); x1=0.2; y1=0.91; x2=0.8; y2=0.98; #Drawing upper-left corner Pad1 of the report pad1.cd(); pad1.SetGridx();pad1.SetGridy(); infoTree.Draw("total_maps_memory:scan_number","", "goff") mapsGraph=TGraph(int(infoTree.GetSelectedRows()), infoTree.GetV2(), infoTree.GetV1()); mapsGraph.SetLineColor(1); mapsGraph.SetLineWidth(1); #mapsGraph.SetFillStyle(3001); mapsGraph.SetFillColor(2); mapsGraph.SetName("total_maps_memory"); #VmSize, VmLck, VmRSS, VmData, VmStk, VmExe, VmLib; infoTree.Draw("VmSize:scan_number", "","goff"); vmsizeGraph=TGraph(int(infoTree.GetSelectedRows()), infoTree.GetV2(), infoTree.GetV1()); vmsizeGraph.SetLineColor(2); vmsizeGraph.SetLineWidth(1); #vmsizeGraph.SetFillStyle(3002); vmsizeGraph.SetFillColor(3); vmsizeGraph.SetName("VmSize"); infoTree.Draw("VmRSS:scan_number", "", "goff"); vmrssGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmrssGraph.SetLineColor(3); vmrssGraph.SetLineWidth(1); #vmrssGraph.SetFillStyle(3003); vmrssGraph.SetFillColor(4); vmrssGraph.SetName("VmRSS"); infoTree.Draw("VmData:scan_number", "", "goff"); vmdataGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmdataGraph.SetLineColor(4); vmdataGraph.SetLineWidth(1); #vmdataGraph.SetFillStyle(3004); vmdataGraph.SetFillColor(4); vmdataGraph.SetName("VmData"); infoTree.Draw("VmStk:scan_number", "", "goff"); vmstkGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmstkGraph.SetLineColor(5); vmstkGraph.SetLineWidth(1); #vmstkGraph.SetFillStyle(3005); vmstkGraph.SetFillColor(4); vmstkGraph.SetName("VmStk") infoTree.Draw("VmExe:scan_number", "", "goff"); vmexeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmexeGraph.SetLineColor(6); vmexeGraph.SetLineWidth(1); #vmexeGraph.SetFillStyle(3003); vmexeGraph.SetFillColor(4); vmexeGraph.SetName("VmExe"); infoTree.Draw("VmLib:scan_number", "", "goff"); vmlibGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmlibGraph.SetLineColor(7); vmlibGraph.SetLineWidth(1); #vmlibGraph.SetFillStyle(3003); vmlibGraph.SetFillColor(4); vmlibGraph.SetName("VmLib"); infoTree.Draw("VmLck:scan_number", "", "goff"); vmlckGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()); vmlckGraph.SetLineColor(8); vmlckGraph.SetLineWidth(1); #vmlckGraph.SetFillStyle(3003); vmlckGraph.SetFillColor(4); vmlckGraph.SetName("VmLck"); infoTree.Draw("total_hole_memory:scan_number", "", "goff"); holeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()) holeGraph.SetLineColor(9); holeGraph.SetLineWidth(1); #holeGraph.SetFillStyle(3004); holeGraph.SetFillColor(5); holeGraph.SetName("HolesSize"); mallocTree.Draw("malloc_free:scan_number", "", "goff"); freeGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1()) freeGraph.SetLineColor(11); freeGraph.SetLineWidth(1); freeGraph.SetFillStyle(3003); freeGraph.SetFillColor(4); freeGraph.SetName("malloc_free"); mallocTree.Draw("malloc_inuse:scan_number", "", "goff"); inuseGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1()) inuseGraph.SetLineColor(21); inuseGraph.SetLineWidth(1); inuseGraph.SetFillStyle(3003); inuseGraph.SetFillColor(4); inuseGraph.SetName("malloc_inuse"); mallocTree.Draw("malloc_sbrk:scan_number", "", "goff"); sbrkGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1()) sbrkGraph.SetLineColor(31); sbrkGraph.SetLineWidth(1); sbrkGraph.SetFillStyle(3003); sbrkGraph.SetFillColor(4); sbrkGraph.SetName("malloc_sbrk"); mallocTree.Draw("malloc_mmap:scan_number", "", "goff"); mmapGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1()) mmapGraph.SetLineColor(41); mmapGraph.SetLineWidth(1); mmapGraph.SetFillStyle(3003); mmapGraph.SetFillColor(4); mmapGraph.SetName("malloc_mmap"); pad1.cd(); multiGraph1.Add(mapsGraph);multiGraph1.Add(vmsizeGraph); multiGraph1.Add(vmrssGraph);multiGraph1.Add(vmdataGraph); multiGraph1.Add(vmlckGraph);multiGraph1.Add(vmexeGraph); multiGraph1.Add(vmstkGraph);#multiGraph1.Add(vmlibGraph); multiGraph1.Add(inuseGraph); multiGraph1.Add(sbrkGraph);multiGraph1.Add(mmapGraph); multiGraph1.Add(holeGraph);multiGraph1.Add(freeGraph); #multiGraph1.SetTitle("PROCESS VM and Malloc MEMORY USAGE"); title.DrawPaveLabel(x1,y1,x2,y2,"PROCESS VM and Malloc MEMORY USAGE","brNDC"); multiGraph1.Draw("ALg") hist = multiGraph1.GetHistogram(); hist.SetXTitle("Event Number"); hist.SetYTitle("Memory, kb"); legend1 = TLegend(0.84,0.20,0.99,0.90); legend1.AddEntry(mapsGraph, "Maps", "l"); legend1.AddEntry(vmsizeGraph,"VmSize", "l"); legend1.AddEntry(vmrssGraph, "VmRSS", "l"); legend1.AddEntry(vmdataGraph,"VmData", "l"); legend1.AddEntry(sbrkGraph, "MallocSbrk", "l"); legend1.AddEntry(inuseGraph, "MallocInuse", "l"); #legend1.AddEntry(vmlibGraph, "VmLib", "l"); legend1.AddEntry(mmapGraph, "MallocMmap", "l"); legend1.AddEntry(freeGraph, "MallocFree", "l"); legend1.AddEntry(holeGraph, "Freed-Holes", "l"); legend1.AddEntry(vmstkGraph, "VmStk", "l"); legend1.AddEntry(vmexeGraph, "VmExe", "l"); legend1.AddEntry(vmlckGraph, "VmLck", "l"); legend1.Draw(); #multiGraph1.Draw("ALg") #title.DrawPaveLabel(x1,y1,x2,y2,"Process Memory Usage Charts","brNDC"); #Drawing upper-left corner Pad1 of the report pad2.cd(); pad2.SetGridx(); pad2.SetGridy(); infoTree.Draw("total_hole_memory:scan_number", "", "goff"); holeGraph=TGraph(infoTree.GetSelectedRows(), infoTree.GetV2(), infoTree.GetV1()) holeGraph.SetLineColor(9); holeGraph.SetLineWidth(1); holeGraph.SetFillStyle(3004); holeGraph.SetFillColor(5); holeGraph.SetName("total_hole_memory"); mallocTree.Draw("malloc_free:scan_number", "", "goff"); freeGraph=TGraph(mallocTree.GetSelectedRows(), mallocTree.GetV2(), mallocTree.GetV1()) freeGraph.SetLineColor(11); freeGraph.SetLineWidth(1); freeGraph.SetFillStyle(3004); freeGraph.SetFillColor(5); freeGraph.SetName("malloc_free"); pad2.cd(); multiGraph2.Add(holeGraph); multiGraph2.Add(freeGraph); #multiGraph2.Add(sbrkGraph); #multiGraph2.Add(mmapGraph); #multiGraph2.SetTitle("Free and Marked Holes Memory Graph"); title.DrawPaveLabel(x1,y1,x2,y2,"Malloc Free and Marked Holes Memory","brNDC"); multiGraph2.Draw("ALg") hist = multiGraph2.GetHistogram(); hist.SetXTitle("Event Number"); hist.SetYTitle("Memory, kb"); legend2 = TLegend(0.9,0.30,0.99,0.90); legend2.AddEntry(freeGraph, "Free", "l"); legend2.AddEntry(holeGraph, "Holes", "l"); #legend2.AddEntry(inuseGraph, "Inuse", "l"); #legend2.AddEntry(mmapGraph, "Mmap", "l"); #legend2.AddEntry(sbrkGraph, "Sbrk", "l"); legend2.Draw() #multiGraph2.Draw("ALg") #title.DrawPaveLabel(x1,y1,x2,y2,"Malloc Memory Usage and Deallocation Charts","brNDC"); #PAD3 pad3.cd() pad3.SetLogz() memHist1.Draw("lego2"); #title.DrawPaveLabel(x1,y1,x2,y2,"TH2I-LEGO2","brNDC"); mem_canvas.SetBorderSize(1); #mem_canvas.Modified() mem_canvas.Update() mem_canvas.Print(".pdf") mem_canvas.Print(".C")
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)