当前位置: 首页>>代码示例>>Python>>正文


Python Fitter.getCorrMatrixElem方法代码示例

本文整理汇总了Python中fitter.Fitter.getCorrMatrixElem方法的典型用法代码示例。如果您正苦于以下问题:Python Fitter.getCorrMatrixElem方法的具体用法?Python Fitter.getCorrMatrixElem怎么用?Python Fitter.getCorrMatrixElem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fitter.Fitter的用法示例。


在下文中一共展示了Fitter.getCorrMatrixElem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: makeMassFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import getCorrMatrixElem [as 别名]
def makeMassFit():
    # config files
    # file = [mass, path]
    files = []
    files.append([2.0123, "../data/11_K_m9_3200_t420.txt", 420])
    files.append([2.0123, "../data/11b_K_m9_3200_t420.txt", 420])
    files.append([1.9047, "../data/13_K_m8_3200_t420.txt", 420])
    files.append([1.6812, "../data/15_K_m7_3200_t420.txt", 420])
    files.append([1.4827, "../data/17_K_m6_3200_t420.txt", 420])
    files.append([1.2952, "../data/19_K_m5_3200_t480.txt", 480])
    files.append([1.0993, "../data/21_K_m4_3200_t480.txt", 480])
    files.append([0.8086, "../data/23_K_m3_3200_t540.txt", 540])
    files.append([0.6954, "../data/25_K_m2_3200_t540.txt", 540])
    files.append([0.5007, "../data/27_K_m1_3200_t660.txt", 660])
    files.append([0.3030, "../data/29_K_m0_3200_t780.txt", 780])
    u = 0.760
    tu = 50

    d = DataErrors()

    for file in files:
        n = readSingleEntryFile(file[1])
        d.addPoint(file[0], n - u, 0.001, np.sqrt(n / file[2] + u / tu))

    d.saveDataToLaTeX(['Masse $m /$g', '$s_m /$g', 'Z\"ahlrate $n / (1/\\text{s})$', '$s_n / (1/\\text{s})$'],
                      ['%.3f', '%.3f', '%.3f', '%.3f'], 
                      'Z\"ahlraten von \\kalium\,f\"ur verschiedene Massen mit Fehlern', 'tab:data:kalium', '../src/data_kalium.tex', 'w')

    c = TCanvas('c2', '', 800, 600)
    g = d.makeGraph('g', 'Masse m / g', 'Z#ddot{a}hlrate n / (1/s)')
    g.SetMaximum(6)
    g.SetMinimum(2)
    g.Draw('AP')

    fit = Fitter('f', '[0]*(1-exp(-[1]*x))')
    fit.setParam(0, 'a')
    fit.setParam(1, 'b')
    fit.fit(g, 0.1, 2.5)
    fit.saveData('../fit/kalium.txt')
    
    a = fit.params[0]['value']
    sa = fit.params[0]['error']
    b = fit.params[1]['value']
    sb = fit.params[1]['error']

    l = TLegend(0.4, 0.15, 0.85, 0.5)
    l.AddEntry('g', '{}^{40} Kalium ohne Untergrund', 'p')  # TODO with error bar? (options +'e')
    l.AddEntry(fit.function, 'Fit mit n(m)=a(1-exp(-b*m))', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Paramter:', '') 
    l.AddEntry(0, 'a: %e #pm %e' % (a, sa), '')
    l.AddEntry(0, 'b: %e #pm %e' % (b, sb), '')   
    l.SetTextSize(0.03)
    l.Draw()

    NA = 6.02214129e23
    hrel = 0.000118
    mrel = 39.0983 + 35.45
    f = 1.29
    rho = fit.getCorrMatrixElem(1, 0)
    thalf = (np.log(2) * NA * hrel * f) / (1.12 * mrel * 2 * a * b) / (3600 * 24 * 365.242)
    sthalf = thalf * np.sqrt((sa / a) ** 2 + (sb / b) ** 2 + 2 * rho * (sa / a) * (sb / b))

    with TxtFile.fromRelPath('../fit/kalium.txt', 'a') as f:
        f.writeline()
        f.writeline('calculations')
        f.writeline('============')
        f.writeline('\t', 'half-life of Kalium:', '%e' % thalf, TxtFile.PM, '%e' % sthalf)

    c.Update()
    c.Print('../img/Kalium40_Massenabhaengigkeit.pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:73,代码来源:eval_k.py

示例2: evalEnergyGauge

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import getCorrMatrixElem [as 别名]
def evalEnergyGauge():
    # get data
    datalist  = funcs.loadCSVToList('../calc/energy_na.txt')
    datalist += funcs.loadCSVToList('../calc/energy_co.txt')
    datalist += funcs.loadCSVToList('../calc/energy_eu.txt')
    
    #make latex table
    elems = ['Na', 'Na', 'Co', 'Co', 'Eu', 'Eu']
    with TxtFile('../src/energygauge.tex', 'w') as f:
        f.write2DArrayToLatexTable(zip(*([elems] + zip(*datalist))), ['Element', 'Literaturwert / keV', 'Kanal', 'Fehler auf Kanal'], 
                                   ['%s', '%.0f', '%.2f', '%.2f'], 'Referenzpeaks mit Literaturwerten', 'tab:energygauge')
    
    #convert do DataErrors
    datalist = zip(*datalist)
    data = DataErrors.fromLists(datalist[1], datalist[0], datalist[2], [0] * len(datalist[0]))
    
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanalnummer', 'Energie / keV')
    g.GetXaxis().SetRangeUser(0, 3500)
    g.Draw('AP')
    
    fit = Fitter('f', 'pol1(0)')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 0.4)
    fit.fit(g, 0, 3500)
    fit.saveData('../calc/energy_gauge_lin.txt', 'w')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.AddEntry('g', 'Referenzpeaks', 'p')
    l.AddEntry(fit.function, 'Fit mit y = a + b*x', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %.0f' % fit.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Parameter:', '')
    l.AddEntry(0, 'a = %.2f #pm %.2f' % (fit.params[0]['value'], fit.params[0]['error']), '')
    l.AddEntry(0, 'b = %.5f #pm %.5f' % (fit.params[1]['value'], fit.params[1]['error']), '')
    l.Draw()

    c.Update()
    c.Print('../img/energy_gauge_lin.pdf', 'pdf')
    
    fit2 = Fitter('f', 'pol2(0)')
    fit2.function.SetNpx(1000)
    fit2.setParam(0, 'a', 0)
    fit2.setParam(1, 'b', fit.params[1]['value'])
    fit2.setParam(2, 'c', 0)
    fit2.fit(g, 0, 3500)
    fit2.saveData('../calc/energy_gauge_lin.txt')
    
    l = TLegend(0.15, 0.575, 0.5, 0.85)
    l.AddEntry('g', 'Referenzpeaks', 'p')
    l.AddEntry(fit2.function, 'Fit mit y = a + b*x + c*x^2', 'l')
    l.AddEntry(0, '#chi^{2} / DoF : %.0f' % fit2.getChisquareOverDoF(), '')
    l.AddEntry(0, 'Parameter:', '')
    l.AddEntry(0, 'a = %.2f #pm %.2f' % (fit2.params[0]['value'], fit2.params[0]['error']), '')
    l.AddEntry(0, 'b = %.5f #pm %.5f' % (fit2.params[1]['value'], fit2.params[1]['error']), '')
    l.AddEntry(0, 'c = %.8f #pm %.8f' % (fit2.params[2]['value'], fit2.params[2]['error']), '')
    l.Draw()
    
    c.Update()
    c.Print('../img/energy_gauge_quad.pdf', 'pdf')
    
    #write raw data for reuse
    with TxtFile('../calc/energy_gauge_raw.txt', 'w') as f:
        f.writeline('\t', str(fit2.params[0]['value']), str(fit2.params[0]['error']))
        f.writeline('\t', str(fit2.params[1]['value']), str(fit2.params[1]['error']))
        f.writeline('\t', str(fit2.params[2]['value']), str(fit2.params[2]['error']))
        f.writeline(str(fit2.getCorrMatrixElem(0, 1))) #a, b
        f.writeline(str(fit2.getCorrMatrixElem(0, 2))) #a, c
        f.writeline(str(fit2.getCorrMatrixElem(1, 2))) #b, c
开发者ID:Bigben37,项目名称:FP1,代码行数:71,代码来源:eval_energy_gauge.py


注:本文中的fitter.Fitter.getCorrMatrixElem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。