def test2(): ch = 12 entry = 199 inRoot = '/data/Samples/TMSPlane/root_files/Jan08a_100mV_r30p0us.root' # s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5) # data1 = s1.generate_adcDataBuf() # fout1 = TFile(inRoot,'read') # tree1 = fout1.Get('tree1') # tree1.SetBranchAddress('adc',data1) # tree1.GetEntry(199) # # data3 = (s1.ANALYSIS_WAVEFORM_BASE_TYPE * s1.nSamples)() # s1.filters_trapezoidal(data1[ch], data3, [100,100,200,-1]) # # x1 = array('f',range(s1.nSamples)) # g1 = TGraph(s1.nSamples, x1, data3) g1 = get_tgraph(ch,entry,inRoot) g1.Draw('AP') g2 = get_tgraph(ch,entry,'/data/Samples/TMSPlane/root_files/Jan08a_100mV_r50p0us.root') g2.SetMarkerColor(2) g2.Draw('Psame') waitRootCmdX()
def test1a(fname='data/fpgaLin/dp02a_Mar04C1a_data_0.root'): add_fit_menu() t1 = TChain('reco') t1.Add(fname) t1.Show(0) V = 200 gr1 = TGraphErrors() for i in range(19): c1.cd(i+1) lt.DrawLatexNDC(0.2,0.4,'Ch={0:d}'.format(i)) t1.Draw('Q[{0:d}]>>hx{0:d}'.format(i),'tID!=7') hx = gPad.GetPrimitive('hx{0:d}'.format(i)) hx.Fit('gaus') fun1 = hx.GetFunction('gaus') encN = 7.40*V*fun1.GetParameter(2)/fun1.GetParameter(1) encE = 7.40*V*fun1.GetParError(2)/fun1.GetParameter(1) gr1.SetPoint(i,i,encN) gr1.SetPointError(i,0,encE) c1.cd(20) gr1.Draw('AP') c1.cd() waitRootCmdX()
def compareWaveform(dsx): ### dsx = [(tag, file, chan, entry)] for a in dsx: print(a[1]) fls = [TFile(a[1], 'read') for a in dsx] trs = [f.Get('tree1') for f in fls] grs = [None] * len(dsx) opt = '' for i in range(len(dsx)): # print('adc[{0:d}]:Iteration$'.format(dsx[i][2]), "Entry$=={0:d}".format(dsx[i][3]), '') # print(trs[i].GetEntries()) # print('adc[{0:d}]:Iteration$'.format(dsx[i][2]), "Entry$=={0:d}".format(dsx[i][3]), 'goff') # # trs[i].Draw('adc[{0:d}]:Iteration$'.format(dsx[i][2]), "Entry$=={0:d}".format(dsx[i][3]), 'goff') # # trs[i].Draw('adc[{0:d}]:Iteration$'.format(dsx[i][2]),"Entry$=={0:d}".format(dsx[i][3]), 'goff') # trs[i].Draw('adc[{0:d}]:Iteration$'.format(dsx[i][2]),"Entry$=={0:d}".format(dsx[i][3]), 'goff') print(i) trs[i].Draw('adc[{0:d}]:Iteration$'.format(dsx[i][2]), "Entry$=={0:d}".format(dsx[i][3]), opt) opt = 'same' print(i) # # grs[i] = gPad.GetPrimitive('Graph') # grs[i] = gDirectory.Get('Graph') # print(grs[i].GetN()) # waitRootCmdX() # grs[i] = gDirectory.Get('htemp') # grs[i].SetName('gr'+str(i)) # grs[0].Draw('AP') # for g in grs[1:]: # g.Draw('Psame PMC') waitRootCmdX()
def test3(): th2 = TH2F('th2', 'th2;#DeltaU [V];Prob', 100, 0, 0.3, 100, 0, 1) th2.Draw('axis') plist = [] threshold = [0] * 32 for i in range(7, 8): for j in range(32): r = 120 + i c = j p1 = pixelData((r, c)) p1.loadFromFile('May18_enc_scan_BlockRow15.dat') p1.ENC() p1.getGraph().Draw('Psame') fun1 = p1.getFitFun() fun1.Draw('same') fun1.SetLineColor(TColor.GetColorPalette(j * 8)) print p1.getFitChi2() plist.append(p1) threshold[j] = fun1.GetParameter(0) for i in range(len(threshold)): print i, threshold[i] waitRootCmdX()
def plotX1(files, info=None, fields='F1F/F:F2F/F'): t0 = None for f in glob.glob(files): z = os.path.getsize(f) if z < 100000: print 'skipping small file', f, 'with size', z continue elif z > 500000: print 'skipping BIG file', f, 'with size', z continue # checkFirstLine(f) # return print f if t0 is not None: t0.ReadFile(f) else: t0 = TTree() t0.ReadFile(f, fields) m1 = t0.GetMinimum('F1F') h1 = TH2D('h1', 'Waveform;t [ns]; V [V]', 20000, m1, m1 + 1000, 10000, 0.10, 0.4) t0.Draw("F2F:F1F>>h1", "", "colz") if info is not None: lt = TLatex() lt.DrawLatexNDC(0.2, 0.9, info) waitRootCmdX()
def test5(): dir1 = '../data/' ex1 = ENC_checkX(dir1 + 'ENC/May29_Chip7_enc_scan_row24To31_col0To32.dat') ex1.loadFile() ex1.showPix() ex1.getCorrTable() ex1.showCorrTable() # ex1.processAll() pix = (24, 6) ex1.showPix(pix) ex1.showCorrTable() ex1.applyCorrection(ex1.pixelData[pix]) ex1.showPix(pix) ex1.pixelData[pix].dropIllData() ex1.showPix(pix) return if gPad: waitRootCmdX(sDir + sTag + 'sCurve') stats1.show() return x1 = ex1.pixelData.values()[20] ex1.applyCorrection(x1) ex1.showPix() x1.ENC() x1.getGraph().Draw('APsame') fun1 = x1.getFitFun() fun1.SetLineColor(TColor.GetColorPalette(8)) fun1.Draw('same') waitRootCmdX()
def show_sample(self, fnameP='/data/Samples/TMSPlane/Dec26/sample_{0:d}.adc', Ns=10, ich=8): from ROOT import TGraph, gPad, TLatex s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5) data1 = s1.generate_adcDataBuf() data2 = s1.generate_sdmDataBuf() data3 = ((s1.ANALYSIS_WAVEFORM_BASE_TYPE * s1.nSamples) * Ns)() dataList = [] for i in range(Ns): fname = fnameP.format(i) s1.read_data([fname, ''], data1, data2) x = array.array('f', range(s1.nSamples)) # s1.filters_trapezoidal(data1[ich], data3[i], [100,100,200,-1]) s1.filters_trapezoidal(data1[ich], data3[i], [100, 100, 100, 0.000722]) g1 = TGraph(s1.nSamples, x, data3[i]) # g1 = TGraph(s1.nSamples, x, data1[ich]) opt = 'AP' if i == 0 else "PSame" g1.Draw(opt + ' PLC PMC') dataList.append(g1) lt = TLatex() lt.DrawLatexNDC(0.2, 0.8, "Chan={0:d}".format(ich)) gPad.Update() waitRootCmdX()
def testIthr(): lines = get_lines('DAC_scan_ithr_0x40to0xf0.dat') gr1 = TGraphErrors() gr2 = TGraphErrors() fUnit = 1000. / 0.7 yUnit = 'e^{-}' for line in lines: if len(line) == 0: continue if line[0] in ['#', '\n']: continue fs = line.rstrip().split() ix = int(fs[0]) gr1.SetPoint(ix, float(fs[1]), float(fs[2]) * fUnit) gr1.SetPointError(ix, 0, float(fs[3]) * fUnit) gr2.SetPoint(ix, float(fs[1]), float(fs[4]) * fUnit) gr2.SetPointError(ix, 0, float(fs[5]) * fUnit) useAtlasStyle() gStyle.SetMarkerStyle(20) gr1.SetMarkerStyle(20) gr1.Draw('AP') h1 = gr1.GetHistogram() h1.GetYaxis().SetTitle("Threshold [" + yUnit + "]") h1.GetXaxis().SetTitle("I_{Thre} code") # h1.GetYaxis().SetRangeUser(0,0.2) gPad.SetTicks(1, 0) gPad.SetRightMargin(0.16) y1b = 0 y2b = 15 x1 = h1.GetXaxis().GetXmax() y1 = h1.GetYaxis().GetXmin() y2 = h1.GetYaxis().GetXmax() raxis = TGaxis(x1, y1, x1, y2, y1b, y2b, 506, "+L") raxis.SetLineColor(2) raxis.SetLabelColor(2) raxis.SetTitleColor(2) raxis.SetTitle("ENC [" + yUnit + "]") raxis.Draw() nP = gr2.GetN() Ys = gr2.GetY() EYs = gr2.GetEY() Y = array( 'd', [y1 + (y2 - y1) / (y2b - y1b) * (Ys[i] - y1b) for i in range(nP)]) EY = array('d', [(y2 - y1) / (y2b - y1b) * EYs[i] for i in range(nP)]) gr2x = TGraphErrors(nP, gr2.GetX(), Y, gr2.GetEX(), EY) gr2x.SetMarkerStyle(24) gr2x.SetLineColor(2) gr2x.SetMarkerColor(2) gr2x.Draw('Psame') waitRootCmdX()
def showMore(self, data, info=None, info2=None): x = [0.2*i for i in range(len(data))] g0 = TGraph(len(data), array('d',x), array('d',data)) g0.Draw("AP") g0.GetHistogram().GetYaxis().SetTitle("V_{out} [V]") g0.GetHistogram().GetXaxis().SetTitle("t [#mus]") # g0.GetHistogram().GetYaxis().SetRangeUser(0.9, 1.4) if info: self.lt.DrawLatexNDC(0.2,0.8,info) if info2: self.lt.DrawLatexNDC(0.2,0.93,info2) ### add info n1=500; n2=2000; np=20 maxI, mx = max(enumerate(data[:-n2+np]), key=lambda p:p[1]) minI, mn = min(enumerate(data[:-n2+np]), key=lambda p:p[1]) dx = 0.5*(mx-mn) dn1 = sum(data[maxI+n1:maxI+n1+np])/np dn2 = sum(data[maxI+n2:maxI+n2+np])/np ## we want large dx, large #2 and small #3 # return (0.5*(mx+mn), dx, 1-(mx-dn1)/dx, 1-(mx-dn2)/dx, maxI-minI) ### A line for the mean fun1 = TF1("fun1",str(0.5*(mx+mn)), 0, 99999999) fun1.SetLineColor(3) fun1.SetLineStyle(2) fun1.Draw("same") ### Draw 2 circles for max and min gr1 = TGraph() gr1.SetPoint(0, maxI*0.2, mx) gr1.SetMarkerColor(2) gr1.SetMarkerStyle(24) gr1.Draw("Psame") gr2 = TGraph() gr2.SetPoint(0, minI*0.2, mn) gr2.SetMarkerColor(4) gr2.SetMarkerStyle(24) gr2.Draw("Psame") ### Add two arrows for the the n50 and n2000 gr3 = TGraph() gr3.SetPoint(0, (maxI+n1)*0.2, dn1) gr3.SetMarkerColor(2) gr3.SetMarkerStyle(23) gr3.Draw("Psame") gr4 = TGraph() gr4.SetPoint(0, (maxI+n2)*0.2, dn2) gr4.SetMarkerColor(4) gr4.SetMarkerStyle(23) gr4.Draw("Psame") global plot_count plot_count += 1 waitRootCmdX(self.sDir+self.sTag+str(plot_count), self.autoSave)
def checkTD(): '''Check the temperature dependence''' print "test" dir1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/' vC1 = VMeasure(dir1+'BandGap_test1a/temprature_test_b3c1.dat') ### the the graph gr2 = vC1.getGraph(5) gr2.gr.Draw("APL") waitRootCmdX()
def showDecay(): tree1 = TTree() tree1.ReadFile( '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan1.dat', 'idX/i:vL/F:vH:A:D/i:R:W') tree1.ReadFile( '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan2_mod.dat' ) # p1 = TProfile('p1','p1;#DeltaU [V];Prob',50,0.12,0.2) # tree1.Draw("W:(vH-vL)>>p1","","profE") tree1.Draw("W*0.0001:(vH-vL)>>p1", "", "profs") p1 = gPad.GetPrimitive('p1') p1.GetYaxis().SetTitle('<Width> [us]') # p1.GetYaxis().SetTitle('<Raising time> [us]') p1.GetXaxis().SetTitle('#Delta U [V]') # fun1 = TF1('fun1','0.5*(1+TMath::Erf((x-[0])/(TMath::Sqrt(2)*[1])))',0.05,0.3) # fun1.SetParameter(0,0.155); # fun1.SetParameter(1,0.005); # # p1.Fit(fun1) # fun1a = p1.GetFunction('fun1') # fun1a.SetLineColor(2) # # p1.Draw("Esame") # # v0 = fun1a.GetParameter(0) # e0 = fun1a.GetParError(0) # v1 = fun1a.GetParameter(1) # e1 = fun1a.GetParError(1) # # print v0, v1 # # fUnit = 1000. # lt = TLatex() # lt.DrawLatexNDC(0.185,0.89,'#mu = {0:.1f} #pm {1:.1f} mV'.format(v0*fUnit, e0*fUnit)) # lt.DrawLatexNDC(0.185,0.84,'#sigma = {0:.1f} #pm {1:.1f} mV'.format(v1*fUnit, e1*fUnit)) # # print 'TMath::Gaus(x,{0:.5f},{1:.5f})'.format(v0, v1) # fun2 = TF1('gaus1','TMath::Gaus(x,{0:.5f},{1:.5f})'.format(v0, v1)) # fun2.SetLineColor(4) # fun2.SetLineStyle(2) # fun2.Draw('same') # # lg = TLegend(0.7,0.4, 0.95, 0.5) # lg.SetFillStyle(0) # lg.AddEntry(p1,'Measurement','p') # lg.AddEntry(fun1a,'Fit','l') # lg.AddEntry(fun2,'Gaus','l') # lg.Draw() waitRootCmdX()
def checkLongScale(): dir1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/' sft = False VMeasure.y_scale = 1 lg = TLegend(0.7,0.8,0.9,0.95) lg.SetFillStyle(0) g1 = TGraphErrors() g2 = TGraphErrors() g3 = TGraphErrors() g2.SetLineColor(2) g2.SetMarkerColor(2) g2.SetMarkerStyle(24) g3.SetLineColor(4) g3.SetMarkerColor(4) g3.SetMarkerStyle(25) lg.AddEntry(g1,"V Source",'pl') lg.AddEntry(g2,"Board 3, Chip 1",'pl') lg.AddEntry(g3,"Board 3, Chip 2",'pl') ms = VMeasure(dir1+'BandGap_test1a/source.dat') ms.y_shift = 0.12 mC1 = VMeasure(dir1+'BandGap_test1a/b3c1.dat') mC2 = VMeasure(dir1+'BandGap_test1a/b3c2.dat') for idx0 in range(10): r1 = ms.getGraph (idx0, sft) r2 = mC1.getGraph(idx0, sft) r3 = mC2.getGraph(idx0, sft) g1.SetPoint(idx0, idx0+0.5, r1.mean) g1.SetPointError(idx0, 0, sqrt(r1.var2)) g2.SetPoint(idx0, idx0+0.5, r2.mean) g2.SetPointError(idx0, 0, sqrt(r2.var2)) g3.SetPoint(idx0, idx0+0.5, r3.mean) g3.SetPointError(idx0, 0, sqrt(r3.var2)) g1.Draw("APL") g2.Draw("PL") g3.Draw("PL") h1 = g1.GetHistogram() lg.Draw() h1.GetYaxis().SetTitle("V [V]") h1.GetXaxis().SetTitle("Sample index") # h1.GetYaxis().SetRangeUser(0.9*min([p.yMin for p in [g1,g2,g3]]),1.1*max([p.yMax for p in [g1,g2,g3]])) h1.GetYaxis().SetRangeUser(1.118,1.128) # lt = TLatex() # lt.DrawLatexNDC(0.2,0.9,") waitRootCmdX()
def test2(): add_fit_menu() t150 = TTree() t150.ReadFile('Jan05a_150mV.dat') t150.ReadFile('Jan05a_50mV.dat') # t150.ReadFile('Jan05a_100mV.dat') t150.ReadFile('tt2.dat') t150.ReadFile('Jan05a_250mV.dat') t150.Draw('A','ch==12') waitRootCmdX()
def test3a(): '''To test the event reconstruction''' data1 = array('f', [0] * (16384 * 20)) inRoot = 'data/fpgaLin/Feb27a_data_40.root' fout1 = TFile(inRoot, 'read') tree1 = fout1.Get('tree1') tree1.SetBranchAddress('adc', data1) i = 81 tree1.GetEntry(i) ### here comes the constructor sp1 = SignalProcessor() sp1.nAdcCh = 20 sp1.IO_adcData = data1 sp1.fltParam.clear() for x in [30, 100, 300, -1]: sp1.fltParam.push_back(x) thre = [0.001] * sp1.nAdcCh thre[19] = 0.02 sp1.ch_thre.clear() for x in thre: sp1.ch_thre.push_back(x) sp1.reco() Unit = 0.2 h3 = TH3F('h3', 'h3;x [cm];y [cm];t [ps]', 9, -1.8, 1.8, 9, -1.8, 1.8, 100, -1. * Unit * sp1.CF_uSize, Unit * sp1.CF_dSize) # for e in sp1.IO_evts: for e in sp1.get_events(): print e.trigID, len(e.sigs) h3.Reset() showEvent(e, h3, h2) h3.Draw('BOX2Z') waitRootCmdX() # for j in range(sp1.nAdcCh): print j, e.sigs[j].im # d = [e.sigs[j].Q for j in range(sp1.nAdcCh)] # print d # showA(d) e1 = sp1.IO_evts[0] print dir(e1) print dir(e1.sigs[0]) print '****', e1.sigs[0].im showEvents(sp1.IO_evts)
def check_event(self, rootfile, idxs): s1 = SigProc(nSamples=16384, nAdcCh=20, nSdmCh=19, adcSdmCycRatio=5) data1 = s1.generate_adcDataBuf() fout1 = TFile(rootfile, 'read') tree1 = fout1.Get('tree1') tree1.SetBranchAddress('adc', data1) for i in idxs: tree1.GetEntry(i) mx = s1.measure_pulse(data1, fltParam=[500, 150, 200, -1.]) d = [x[3] for x in mx] self.plot_data(d) waitRootCmdX()
def show(self, data, info=None, info2=None): x = [0.2*i for i in range(len(data))] g0 = TGraph(len(data), array('d',x), array('d',data)) g0.Draw("AP") g0.GetHistogram().GetYaxis().SetTitle("V_{out} [V]") g0.GetHistogram().GetXaxis().SetTitle("t [#mus]") # g0.GetHistogram().GetYaxis().SetRangeUser(0.9, 1.4) if info: self.lt.DrawLatexNDC(0.2,0.8,info) if info2: self.lt.DrawLatexNDC(0.2,0.93,info2) global plot_count plot_count += 1 waitRootCmdX(self.sDir+self.sTag+str(plot_count), self.autoSave)
def test1(): ch1 = getChain('/data/Samples/TMSPlane/root_files/Jan08a_100mV_r30p0us.root') ch2 = getChain('/data/Samples/TMSPlane/root_files/Jan08a_100mV_r50p0us.root') ch2.SetLineColor(2) ch2.SetMarkerColor(2) var = lambda x: '(adc[12]+{1:.4f}):(Iteration$-{0:d})*0.2'.format(x[0],x[2]) # var = lambda x: 'adc[12]:(Iteration$-{0:d})'.format(x[0],x[2]) cut = lambda x: '&&Iteration$>{0:d}&&Iteration$<{1:d}'.format(x[0],x[1]) reg1 = (3025,6525,0) reg2 = (4000,7500,0.004) ch1.Draw(var(reg1),'Entry$==199'+cut(reg1)) ch2.Draw(var(reg2),'Entry$==199'+cut(reg2),'same') waitRootCmdX()
def checkStablibity(isensor=8): qt1 = QuickTuner(mode=0) cd1 = qt1.sensorConfig.cd cd1.readBackPars(isensor) dataX = [] for i in range(10): time.sleep(1) cd1.fetch() dataX.append(cd1.adcData[isensor][:]) max1 = -1 min1 = 999 ndata = len(dataX[0]) gr0 = None option = 'AL' icolor = 1 grs = [] for x in dataX: max2 = max(x) if max2>max1: max1 = max2 min2 = min(x) if min2<min1: min1 = min2 gr1 = TGraph(ndata, array('d',[i*0.2*0.001 for i in range(ndata)]), array('d', x)) gr1.Draw(option) if gr0 == None: gr0 = gr1 option = 'L' gr1.SetLineColor(icolor) icolor += 1 grs.append(gr1) # waitRootCmdX() h1 = gr0.GetHistogram() print min1, max1 h1.GetYaxis().SetRangeUser(min1,max1) h1.GetYaxis().SetTitle("V") h1.GetXaxis().SetTitle("t [ms]") h1.Draw("axissame") lt = TLatex() lt.DrawLatexNDC(0.2,0.92, "C{0:d}: ".format(isensor)+' '.join(['{0:.3f}'.format(x) for x in cd1.inputVs])) waitRootCmdX() print len(dataX), len(grs)
def test1(): infiles = 'data/fpgaLin/Jan28b*.root' vx = [(int(os.path.basename(fname).split('_')[2][:-2]), fname) for fname in glob(infiles)] opt = '' c = 1 for v in sorted(vx, key=lambda x: x[0], reverse=True): print v[0], v[1] f1 = TFile(v[1], 'read') t1 = f1.Get('tree1') if not t1: continue t1.SetMarkerColor(c) n1 = t1.Draw("adc[19]:Iteration$", "Entry$==10", opt) opt = 'same' c += 1 waitRootCmdX()
def test(): from ROOT import TH1F, TGraph, TCanvas, TF1, Double from rootUtil import waitRootCmdX, useAtlasStyle useAtlasStyle() s1 = sampler((0.05, 0.8), 15) # s1.funX = lambda x:0.5*(1+math.erf((x-0.4)/0.04)) s1.funX = lambda x: 1. if random.random() < 0.5 * (1. + math.erf( (x - 0.4) / 0.04)) else 0. s1.funY = lambda x: math.sqrt(x * (1. - x)) # s1.funY = lambda x:x*(1.-x)/6. for i in range(10): print s1.funY(0.1 * i) print s1.next() s1.sFactor = 20 NEVT = 700 h1 = TH1F('h1', 'h1;x;Events', 100, 0., 1) # h1 = TH1F('h1','h1;x;Events',NEVT,0,NEVT) g1 = TGraph() for i in range(NEVT): # h1.Fill(s1.next()) h1.Fill(s1.generate()) # h1.Fill(s1.totalP()) g1.SetPoint(i, i, s1.totalP()) s1.show() c1 = TCanvas() c1.Divide(2) c1.cd(1) h1.Draw() mx, mn = Double(0), Double(0) h1.GetMinimumAndMaximum(mn, mx) print mx, mn fun1 = TF1('fun1', '{0:.1f}*TMath::Gaus(x,0.4,0.04/TMath::Sqrt(2))'.format(mx), 0, 1) fun1.SetLineColor(2) fun1.Draw('same') c1.cd(2) g1.Draw('AP') c1.cd() waitRootCmdX()
def test2(): infiles = 'data/fpgaLin/Jan28b*.root' vx = [(int(os.path.basename(fname).split('_')[2][:-2]), fname) for fname in glob(infiles)] opt = '' c = 1 gr = TGraphErrors() for v in sorted(vx, key=lambda x: x[0], reverse=True): a = getV(v[1]) if a is not None: n = gr.GetN() gr.SetPoint(n, v[0], a[0]) gr.SetPointError(n, 0, a[1]) # break fun0 = TF1('fun0', 'pol1', 0, 800) fun1 = TF1('fun1', 'pol1', 0, 295) fun2 = TF1('fun2', 'pol1', 295, 595) fun3 = TF1('fun3', 'pol1', 595, 800) fun0.SetLineColor(kGray) fun1.SetLineColor(2) fun2.SetLineColor(3) fun3.SetLineColor(4) gr.Fit(fun0, 'R') gr.Fit(fun1, 'R+') gr.Fit(fun2, 'R+') gr.Fit(fun3, 'R+') # gr.Fit('pol1') # fun1 = gr.GetFunction('pol1') # fun1.SetLineColor(2) # fun1.SetLineStyle(2) gStyle.SetOptFit(0) gr.Draw('AP') h1 = gr.GetHistogram() h1.GetXaxis().SetTitle("Input [mV]") h1.GetYaxis().SetTitle("Output [V]") waitRootCmdX()
def getFigures(self, files, cList=[5]): nChannels = 19 head = ':'.join(["F{0:d}F/F".format(x) for x in range(nChannels + 1)]) i = 0 for f in files: t1 = TTree() t1.ReadFile(f, head) for iC in cList: t1.Draw("F{0:d}F:Entry$*0.2*0.001".format(iC)) h1 = gPad.GetPrimitive('htemp') h1.GetYaxis().SetTitle("V_{out} [V]") h1.GetXaxis().SetTitle("t [ms]") h1.GetYaxis().SetRangeUser(0.8, 1.3) self.lt.DrawLatexNDC( 0.2, 0.92, "Chip {1:d}, t = {0:d} s".format(i * 10, iC)) waitRootCmdX( self.sDir + self.sTag + "C" + str(iC) + "_" + str(i) + self.pSuffix, self.autoSave) i += 1
def compareX(): # fl = ['Jan05a_100mV.dat', 'Jan08a_100mV_r30p0us.dat','Jan08a_100mV_r40p0us.dat','Jan08a_100mV_r50p0us.dat'] # fl = ['Jan05a_100mV.dat', 'Jan08a_100mV_r30p0us.dat','Jan08a_100mV_r40p0us.dat','Jan08a_100mV_r50p0us.dat'] fl = ['data/fpgaLin/Jan22a_C2_100mV_f{0:d}.dat'.format(x) for x in [100,200,500,1000]] fs = [TTree() for f in fl] opt = '' chx = TTree() for f in fl: chx.ReadFile(f) chx.Draw('A','ch==12','axis') opt = 'same' for i in range(len(fl)): fs[i].ReadFile(fl[i]) fs[i].SetFillStyle(0) fs[i].SetLineColor(i+1) fs[i].Draw('A','ch==12',opt) waitRootCmdX()
def test1(): p1 = pixelData((124, 26)) # p1.loadFromFile('/data/repos/Mic4Test_KC705/Software/Analysis/ENC/May18_enc_scan_BlockRow15.dat', lambda x: 0.019<x<0.06667) # p1.loadFromFile('/data/repos/Mic4Test_KC705/Software/Analysis/ENC/May18_enc_scan_BlockRow15.dat', lambda x:0.05<x<0.15) p1.loadFromFile('May18_enc_scan_BlockRow15.dat') p1.ENC() gr1 = p1.getGraph() gr1.Draw('AP') fun1 = p1.getFitFun(tryRecover=False) if math.isnan(p1.fitter.mean): fun1.SetParameter(0, p1.fitter.mean0) fun1.SetParameter(1, p1.fitter.sigma0) gr1.Fit(fun1) fun1.Draw('same') fun1.SetLineColor(2) print p1.getFitChi2() waitRootCmdX()
def plot_data(self, d): if len(d) < 19: print('Need 19 entries') return from ROOT import TH2Poly, gStyle gStyle.SetOptStat(0) cv1 = TCanvas('cv1', 'cv1', 600, 500) cv1.SetRightMargin(0.2) hc = TH2Poly() hc.SetTitle("TMS19Plane") hc.Honeycomb(-4.3, -4, 1, 5, 5) listA = [(0, 0), (2, 0), (1, 1.5), (-1, 1.5), (-2, 0), (-1, -1.5), (1, -1.5), (4, 0), (3, 2), (1, 3), (0, 3), (-1, 3), (-3, 2), (-4, 0), (-3, -2), (-1, -3), (0, -3), (1, -3), (3, -2)] for i in range(len(listA)): hc.Fill(listA[i][0], listA[i][1], d[i]) hc.Draw("text colz0") waitRootCmdX()
def checkSample(idx0=4): dir1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/' sft = True lg = TLegend(0.7,0.8,0.9,0.95) lg.SetFillStyle(0) ms = VMeasure(dir1+'BandGap_test1a/source.dat') g1 = ms.getGraph(idx0, sft) g1.gr.Draw('APL') h1 = g1.gr.GetHistogram() lg.AddEntry(g1.gr,"V Source",'pl') mC1 = VMeasure(dir1+'BandGap_test1a/b3c1.dat') g2 = mC1.getGraph(idx0, sft) g2.gr.SetLineColor(2) g2.gr.SetMarkerColor(2) g2.gr.SetMarkerStyle(24) g2.gr.Draw('PL') lg.AddEntry(g2.gr,"Board 3, Chip 1",'pl') mC2 = VMeasure(dir1+'BandGap_test1a/b3c2.dat') g3 = mC2.getGraph(idx0, sft) g3.gr.SetLineColor(4) g3.gr.SetMarkerColor(4) g3.gr.SetMarkerStyle(25) g3.gr.Draw('PL') lg.AddEntry(g3.gr,"Board 3, Chip 2",'pl') lg.Draw() h1.GetYaxis().SetTitle("#Delta V [mV]") h1.GetXaxis().SetTitle("t [s]") h1.GetYaxis().SetRangeUser(0.9*min([p.yMin for p in [g1,g2,g3]]+[-1]),1.1*max([p.yMax for p in [g1,g2,g3]]+[1])) # h1.GetYaxis().SetRangeUser(-1,1) lt = TLatex() lt.DrawLatexNDC(0.2,0.9,"Sample #{0:d}".format(idx0)) waitRootCmdX(sDir+sTag+str(idx0))
def checkHistos(): dir1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/' sft = False VMeasure.y_scale = 1 lg = TLegend(0.7,0.8,0.9,0.95) lg.SetFillStyle(0) h1 = TH1F("hS","hMeasV;Measured V [V];#Entries", 100,1.118,1.128) h2 = h1.Clone("hC1") h3 = h1.Clone("hC2") h2.SetLineColor(2) h2.SetMarkerColor(2) h2.SetMarkerStyle(24) h3.SetLineColor(4) h3.SetMarkerColor(4) h3.SetMarkerStyle(25) lg.AddEntry(h1,"V Source (shifted)",'pl') lg.AddEntry(h2,"Board 3, Chip 1",'pl') lg.AddEntry(h3,"Board 3, Chip 2",'pl') ms = VMeasure(dir1+'BandGap_test1a/source.dat') ms.y_shift = 0.12 mC1 = VMeasure(dir1+'BandGap_test1a/b3c1.dat') mC2 = VMeasure(dir1+'BandGap_test1a/b3c2.dat') for idx0 in range(10): ms.fillHist(idx0, h1) mC1.fillHist(idx0, h2) mC2.fillHist(idx0, h3) print h1.GetEntries() h1.Draw("hist") h2.Draw("same") h3.Draw("same") lg.Draw() waitRootCmdX()
def test1(fname='tt2.dat'): add_fit_menu() t1 = TTree() t1.ReadFile(fname) t1.Show(0) for i in range(18): c1.cd(i+1) lt.DrawLatexNDC(0.2,0.4,'Ch={0:d}'.format(i)) t1.Draw('A','ch=={0:d}'.format(i)) # t1.Draw('A>>h1','ch=={0:d}'.format(i),'goff') # h1 = gDirectory.Get('h1') # h1.SetName('ch'+str(i)) # # c1.cd(i) # h1.Draw() # if i>1: break c1.cd() waitRootCmdX()
def plotResults(en1, info=None, savename='temp_fig/test'): # p1 = TProfile('h1','h1;#DeltaU [V];Prob',100,en1.mean-8*en1.sigma, en1.mean+8*en1.sigma) fUnit = 1000./0.7 mean = en1.mean*fUnit sigma = en1.sigma*fUnit p1 = TProfile('h1','h1;N_{e^{-}};Prob',100,mean-8*sigma, mean+8*sigma) g1 = data2graph(en1.data1, p1, fUnit) p1.Draw('axis') fun1 = TF1('fun1',"0.5*(1+TMath::Erf((x-[0])/(TMath::Sqrt(2)*[1])))",0,1000) fun1.SetParameter(0,mean) fun1.SetParameter(1,sigma) fun1.SetLineColor(2) fun1.Draw('same') sUnit = 'e^{-}' lt = TLatex() lt.DrawLatexNDC(0.185,0.89,'#mu = {0:.1f} #pm {1:.1f} {2}'.format(en1.mean*fUnit, en1.meanErr*fUnit, sUnit)) lt.DrawLatexNDC(0.185,0.84,'#sigma = {0:.1f} #pm {1:.1f} {2}'.format(en1.sigma*fUnit, en1.sigmaErr*fUnit, sUnit)) if info: lt.DrawLatexNDC(0.185,0.75, info) print 'TMath::Gaus(x,{0:.5f},{1:.5f})'.format(mean, sigma) fun2 = TF1('gaus1','TMath::Gaus(x,{0:.5f},{1:.5f})'.format(mean, sigma),0,1000) fun2.SetLineColor(4) fun2.SetLineStyle(2) fun2.Draw('same') lg = TLegend(0.7,0.35, 0.95, 0.5) lg.SetFillStyle(0) lg.AddEntry(p1,'Measurement','p') lg.AddEntry(fun1,'Fit','l') lg.AddEntry(fun2,'Gaus','l') lg.Draw() g1.Draw("Psame") waitRootCmdX(savename)
def inspectCh(ds, chs): t = TTree() t.SetFillColor(0) t.SetFillStyle(0) for d in ds: t.ReadFile(d[1]) cv1 = TCanvas() cv1.Divide(2,4) icv = 1 for ch in chs: cv1.cd(icv) t.Draw('A','ch=={0:d}'.format(ch)) hx = gPad.GetPrimitive('htemp') hx.GetXaxis().SetTitle('U_{Out} [V]') hx.SetName('h{0:d}'.format(ch)) lt.DrawLatexNDC(0.7,0.9,"Ch {0:d}".format(ch)) icv += 1 cv1.cd(0) waitRootCmdX()