def fitsToRoot(): # Create root file and tree f = TFile(path_root + "GRID_2008_2015.root", "RECREATE") tree = TTree("data_GRID", "data_GRID") obt = array('d', [0]) tree.Branch('obt', obt, 'obt/D') contact = array('I', [0]) tree.Branch('contact', contact, 'contact/I') filenames = filesInFolderAsList(path) c = 0 for name in filenames: c = c + 1 print str(c) + "/" + str(len(filenames)) # open fits file hdulist = fits.open(path + name) #hdulist.info() #print(hdulist['EVENTS'].columns) # Get table inside EVENTS event_data = Table(hdulist['EVENTS'].data) #print(event_data['TIME']) contact[0] = int(name[3:9]) print contact[0] #Iterate through tabel and append TIME to tree for row in event_data: obt[0] = (row['TIME']) #if (354153660 - 60) < obt[0] and obt[0] < (362102460 + 60): tree.Fill() hdulist.close() #tree.Scan("","","col=20.6f") tree.Print() tree.Show(0) #tree.Scan("obt","", "col=20.6f") tree.GetCurrentFile().Write() tree.GetCurrentFile().Close()
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 showENC(): fname1 = '/data/repos/Mic4Test_KC705/Software/Analysis/data/ENC/ENC_Chip5Col12_scan1.dat' 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' ) tree1.Show(500) p1 = TProfile('p1', 'p1;#DeltaU [V];Prob', 50, 0.12, 0.2) tree1.Draw("D:(vH-vL)>>p1", "", "profE") ### change it to tgraph g1 = TGraphErrors() for i in range(p1.GetNbinsX() + 2): N = p1.GetBinEntries(i) if N > 0: print i, N, p1.GetXaxis().GetBinCenter(i), p1.GetBinContent( i), p1.GetBinError(i) n = g1.GetN() g1.SetPoint(n, p1.GetXaxis().GetBinCenter(i), p1.GetBinContent(i)) g1.SetPointError(n, 0, p1.GetBinError(i)) # g1.SetMarkerColor(3) # g1.SetLineColor(3) p1.Draw("axis") g1.Draw('Psame') 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) g1.Fit(fun1) fun1a = g1.GetFunction('fun1') # 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()