コード例 #1
0
ファイル: eval_na.py プロジェクト: Bigben37/FP1
def evalNa():
    data = SzintData.fromPath('../data/na.TKA')
    data.prepare()

    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Z#ddot{a}hlrate / (1/s)')
    prepareGraph(g)
    g.SetMinimum(-0.008)
    g.GetXaxis().SetRangeUser(0, 8200)
    g.Draw('APX')

    c.Update()
    c.Print('../img/na_spectrum.pdf')

    fit1 = Fitter('f', 'pol1(0) + gaus(2)')
    fit1.function.SetLineWidth(2)
    fit1.setParam(0, 'a', 0)
    fit1.setParam(1, 'b', 0)
    fit1.setParam(2, 'A', 0.05)
    fit1.setParam(3, 'c', 1250)
    fit1.setParam(4, 's', 50)
    fit1.fit(g, 1200, 1390)
    fit1.saveData('../calc/na_peak1.txt', 'w')

    fit2 = Fitter('f', 'pol1(0) + gaus(2)')
    fit2.function.SetLineWidth(2)
    fit2.function.SetLineColor(4)
    fit2.setParam(0, 'a', 0)
    fit2.setParam(1, 'b', 0)
    fit2.setParam(2, 'A', 0.01)
    fit2.setParam(3, 'c', 3100)
    fit2.setParam(4, 's', 50)
    fit2.fit(g, 3000, 3300, '+')
    fit2.saveData('../calc/na_peak2.txt', 'w')

    with TxtFile('../calc/energy_na.txt', 'w') as f:
        f.writeline('\t', '511', str(fit1.params[3]['value']), str(fit1.params[3]['error']))
        f.writeline('\t', '1274', str(fit2.params[3]['value']), str(fit2.params[3]['error']))

    l = TLegend(0.635, 0.62, 0.87, 0.87)
    l.AddEntry('g', 'Messung', 'p')
    l.AddEntry(fit1.function, 'Fit des ersten Peaks', 'l')
    l.AddEntry(0, 'y = a1 + b1*x + gaus(x; A1, c1, s1)', '')
    l.AddEntry(fit2.function, 'Fit des zweiten Peaks', 'l')
    l.AddEntry(0, 'y = a2 + b2*x + gaus(x; A2, c2, s2)', '')
    l.AddEntry(0, 'Peaks:', '')
    l.AddEntry(0, 'c1 = %.2f #pm %.2f' % (fit1.params[3]['value'], fit1.params[3]['error']), '')
    l.AddEntry(0, 'c2 = %.2f #pm %.2f' % (fit2.params[3]['value'], fit2.params[3]['error']), '')
    l.Draw()

    g.GetXaxis().SetRangeUser(1000, 3600)
    g.SetMaximum(0.07)
    g.Draw('P')
    c.Update()
    c.Print('../img/na_peaks.pdf')
コード例 #2
0
ファイル: eval_eu.py プロジェクト: Bigben37/FP1
def evalEu():
    data = SzintData.fromPath('../data/eu.TKA')
    data.prepare()

    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Z#ddot{a}hlrate / (1/s)')
    prepareGraph(g)
    g.GetXaxis().SetRangeUser(0, 8200)
    g.Draw('APX')

    c.Update()
    c.Print('../img/eu_spectrum.pdf')

    fit1 = Fitter('f1', 'pol1(0)+gaus(2)')
    fit1.setParam(0, 'a', 0.5)
    fit1.setParam(1, 'b', 0)
    fit1.setParam(2, 'A', 2.5)
    fit1.setParam(3, 'c', 350)
    fit1.setParam(4, 's', 50)
    fit1.fit(g, 300, 400)
    fit1.saveData('../calc/eu_peak1.txt', 'w')

    fit2 = Fitter('f2', 'pol1(0)+gaus(2)')
    fit2.function.SetLineColor(4)
    fit2.setParam(0, 'a', 0.5)
    fit2.setParam(1, 'b', 0)
    fit2.setParam(2, 'A', 1.5)
    fit2.setParam(3, 'c', 900)
    fit2.setParam(4, 's', 75)
    fit2.fit(g, 800, 1000, '+')
    fit2.saveData('../calc/eu_peak2.txt', 'w')

    with TxtFile('../calc/energy_eu.txt', 'w') as f:
        f.writeline('\t', '122', str(fit1.params[3]['value']), str(fit1.params[3]['error']))
        f.writeline('\t', '344', str(fit2.params[3]['value']), str(fit2.params[3]['error']))

    l = TLegend(0.6, 0.575, 0.86, 0.85)
    l.AddEntry('g', 'Messwerte', 'p')
    l.AddEntry(fit1.function, 'Fit des ersten Peaks', 'l')
    l.AddEntry(0, 'y=a1 + b1*x + gaus(x; A1, c1, s1)', '')
    l.AddEntry(fit2.function, 'Fit des zweiten Peaks', 'l')
    l.AddEntry(0, 'y=a2 + b2*x + gaus(x; A2, c2, s2)', '')
    l.AddEntry(0, 'Peaks:', '')
    l.AddEntry(0, 'c1 = %.2f #pm %.2f' % (fit1.params[3]['value'], fit1.params[3]['error']), '')
    l.AddEntry(0, 'c1 = %.2f #pm %.2f' % (fit2.params[3]['value'], fit2.params[3]['error']), '')
    l.Draw()

    g.GetXaxis().SetRangeUser(250, 1050)
    g.SetMaximum(3.5)
    g.SetMinimum(0.25)
    g.Draw('P')
    c.Update()
    c.Print('../img/eu_peaks.pdf')
コード例 #3
0
ファイル: eval_underground.py プロジェクト: Bigben37/FP1
def evalUnderground():
    # load data
    data = SzintData.fromPath('../data/untergrund.TKA')
    data.convertToCountrate()
    gauge = funcs.loadCSVToList('../calc/energy_gauge_raw.txt')

    # make canvas and graph
    c = TCanvas('c', '', 1280, 720)
    c.SetLogy()
    g = data.makeGraph('g', 'Kanalnummer', 'Z#ddot{a}hlrate / (1/s)')
    prepareGraph(g)
    g.GetXaxis().SetRangeUser(0, 8200)
    g.Draw('APX')
    
    c.Update()
    c.Print('../img/underground_spectrum.pdf')

    # fit
    fit = Fitter('f', 'pol1(0) + gaus(2)')
    fit.setParam(0, 'a', 2e-3)
    fit.setParam(1, 'b', 0)
    fit.setParam(2, 'A1', 1e-2)
    fit.setParam(3, 'c1', 3500)
    fit.setParam(4, 's1', 200)
    fit.fit(g, 3250, 4050)
    fit.saveData('../calc/underground_peak.txt', 'w')

    p, sp = fit.params[3]['value'], fit.params[3]['error']
    E, sE = channelToEnergy(p, sp, gauge)
    with TxtFile('../calc/underground_peak_energy.txt', 'w') as f:
        f.writeline('\t', *map(lambda x: str(x), (p, sp, E, sE)))

    l = TLegend(0.6, 0.7, 0.85, 0.85)
    l.AddEntry('g', 'Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit y = a + b*x + gaus(x; A, c, s)', 'l')
    l.AddEntry(0, 'Peak: ', '')
    l.AddEntry(0, 'c1 = %.2f #pm %.2f' % (p, sp), '')
    l.Draw()

    c.SetLogy(False)
    g.GetXaxis().SetRangeUser(3200, 4100)
    g.SetMinimum(0.00025)
    g.SetMaximum(0.016)
    g.GetYaxis().SetTitleOffset(1.2)
    g.Draw('P')
    c.Update()
    c.Print('../img/underground_peaks.pdf')
コード例 #4
0
ファイル: eval_co.py プロジェクト: Bigben37/FP1
def evalCo():
    data = SzintData.fromPath('../data/co.TKA')
    data.prepare()

    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Z#ddot{a}hlrate / (1/s)')
    prepareGraph(g)
    g.SetMinimum(-0.01)
    g.GetXaxis().SetRangeUser(0, 8200)
    g.Draw('APX')

    c.Update()
    c.Print('../img/co_spectrum.pdf')

    fit = Fitter('f', 'pol1(0) + gaus(2) + gaus(5)')
    fit.function.SetLineWidth(2)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 0)
    fit.setParam(2, 'A1', 0.1)
    fit.setParam(3, 'c1', 2800)
    fit.setParam(4, 's1', 50)
    fit.setParam(5, 'A2', 0.1)
    fit.setParam(6, 'c2', 3250)
    fit.setParam(7, 's2', 75)
    fit.fit(g, 2650, 3500)
    fit.saveData('../calc/co_peaks.txt', 'w')

    with TxtFile('../calc/energy_co.txt', 'w') as f:
        f.writeline('\t', '1172', str(fit.params[3]['value']), str(fit.params[3]['error']))
        f.writeline('\t', '1332', str(fit.params[6]['value']), str(fit.params[6]['error']))

    l = TLegend(0.635, 0.62, 0.87, 0.87)
    l.AddEntry('g', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit y = a + b*x + gaus(x; A1, c1, s1)', 'l')
    l.AddEntry(fit.function, '                  + gaus(x; A2, c2, s2)', '')
    l.AddEntry(0, '#chi^{2} / DoF : %f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Peaks:', '')
    l.AddEntry(0, 'c1 = %.2f #pm %.2f' % (fit.params[3]['value'], fit.params[3]['error']), '')
    l.AddEntry(0, 'c2 = %.2f #pm %.2f' % (fit.params[6]['value'], fit.params[6]['error']), '')
    l.Draw()

    g.GetXaxis().SetRangeUser(2400, 3800)
    g.Draw('P')
    c.Update()
    c.Print('../img/co_peaks.pdf')
コード例 #5
0
ファイル: eval_th.py プロジェクト: Bigben37/FP1
def evalTh():
    # load data
    data = SzintData.fromPath('../data/th.TKA')
    data.prepare()
    gauge = funcs.loadCSVToList('../calc/energy_gauge_raw.txt')

    # prepare canvas and graph
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Z#ddot{a}hlrate / (1/s)')
    prepareGraph(g)

    printGraph(c, g, '../img/th_energyspectrum.pdf', 0, 6711, 1e-4, 2, 'APX', True)

    params = singlePeakFit(g)  # single peak fit

    # calculate energies for single peaks
    energies = []
    for param in params:
        energies.append(channelToEnergy(param[1], param[2], gauge))

    # save peak and energy data from single peaks
    with TxtFile('../calc/th_peaks_single.txt', 'w') as f:
        for i, param in enumerate(params):
            f.writeline('\t', 'Peak% 2d' % (i + 1), str(param[1]), str(param[2]), str(energies[i][0]), str(energies[i][1]))

    # save peak data as latex file
    peaknames = map(lambda i: '% 2d' % i, xrange(1, 11))
    with TxtFile('../src/th_peaks_single.tex', 'w') as f:
        f.write2DArrayToLatexTable(zip(*([peaknames] + zip(*params)[1:3] + zip(*energies))),
                                   ['Peak', 'Kanal $c$', '$s_c$', 'Energie $E$ / keV', '$s_E$ / keV'],
                                   ['%s', '%.3f', '%.3f', '%.2f', '%.2f'],
                                   'Kan\\"ale und Energien von \\th, bestimmt mit separaten Fits.', 'tab:th:single')

    # make graphs for single peaks
    peaklegend = zip(zip(*params)[4], map(lambda i: "Peak % 2d" % i, xrange(1, 11)))
    printGraph(c, g, '../img/th_peaks_single_01-10.pdf', 0, 6711, 1e-4, 2, isLog=True)

    l = makeLegend(0.6, 0.6, 0.85, 0.85, peaklegend[:6])
    l.Draw()
    printGraph(c, g, '../img/th_peaks_single_01-06.pdf', 150, 1175, 0.05, 1.15)

    l = makeLegend(0.15, 0.6, 0.3, 0.85, peaklegend[6:9])
    l.Draw()
    printGraph(c, g, '../img/th_peaks_single_07-09.pdf', 1200, 2250, 0.005, 0.075)

    l = makeLegend(0.7, 0.7, 0.85, 0.85, peaklegend[9:10])
    l.Draw()
    g.GetYaxis().SetTitleOffset(1.2)
    printGraph(c, g, '../img/th_peaks_single_10.pdf', 6100, 6700, 0.0001, 0.006)
    g.GetYaxis().SetTitleOffset(1)

    multichannels = []
    # make multi peak fit -- 1 to 6
    fit = multiPeakFit(g, 'pol2(0)', [0.1, 0, 0], params[:6], 190, 1150)
    fit.saveData('../calc/th_peaks_multi_01-06.txt', 'w')
    l = makeLegend(0.7, 0.7, 0.85, 0.85, [[fit.function, 'Peaks 1 bis 6']])
    l.Draw()
    printGraph(c, g, '../img/th_peaks_multi_01-06.pdf', 150, 1175, 0.05, 1.15)
    for i in xrange(4, 20, 3):
        multichannels.append([fit.params[i]['value'], fit.params[i]['error']])
    # make multi peak fit -- 7 to 8
    fit = multiPeakFit(g, 'pol2(0)', [0.02, 0, 0], params[6:8], 1250, 1650)
    fit.saveData('../calc/th_peaks_multi_07-08.txt', 'w')
    l = makeLegend(0.7, 0.7, 0.85, 0.85, [[fit.function, 'Peaks 7 und 8']])
    l.Draw()
    g.GetYaxis().SetTitleOffset(1.2)
    printGraph(c, g, '../img/th_peaks_multi_07-08.pdf', 1225, 1675, 0.01, 0.05)
    for i in xrange(4, 8, 3):
        multichannels.append([fit.params[i]['value'], fit.params[i]['error']])

    # calculate energies for multi peaks
    energies = []
    for channel in multichannels:
        energies.append(channelToEnergy(channel[0], channel[1], gauge))
        
    # save multi peak data to latex table
    with TxtFile('../src/th_peaks_multi.tex', 'w') as f:
        f.write2DArrayToLatexTable(zip(*([peaknames[:8]] + zip(*multichannels)+ zip(*energies))),
                                   ['Peak', 'Kanal $c$', '$s_c$', 'Energie $E$ / keV', '$s_E$ / keV'],
                                   ['%s', '%.3f', '%.3f', '%.2f', '%.2f'],
                                   'Kan\\"ale und Energien von \\th, bestimmt mit gemeinsamen Fits.', 'tab:th:multi')

    # save peak and energy data from multi peaks
    with TxtFile('../calc/th_peaks_multi.txt', 'w') as f:
        for i, channel in enumerate(multichannels):
            f.writeline('\t', 'Peak% 2d' % (i + 1), str(channel[0]), str(channel[1]), str(energies[i][0]), str(energies[i][1]))