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


Python Fitter.getCovMatrixElem方法代码示例

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


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

示例1: evalEnergyCalibration

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import getCovMatrixElem [as 别名]
def evalEnergyCalibration(peaks, percents):
    maxenergy = 1.95 * 0.87 * 84
    smaxenergy = maxenergy * sqrt((0.05/1.95) ** 2 + (0.01/0.87) ** 2 + (5/84) ** 2 )
    channels = list(list(zip(*peaks))[0])
    schannels = list(list(zip(*peaks))[1])
    energies = list(map(lambda x:x/100*maxenergy, percents))
    senergies = list(map(lambda x:x/100*smaxenergy, percents))
    print(energies)
    print(senergies)
    
    with TxtFile('../src/tab_energycalibration.tex', 'w') as f:
        f.write2DArrayToLatexTable(list(zip(*[percents, channels, schannels, energies, senergies])),
                                   ['\% energy', '$c$', '$s_c$', '$E$ / MeV', '$s_E$ / MeV'], 
                                   ['%d', '%.3f', '%.3f', '%.1f', '%.1f'], 
                                   "Channels of fitted peaks and their theoretical energy for the energy calibration.", "tab:ecal")
    
    data = DataErrors.fromLists(channels, energies, schannels, senergies)
    c = TCanvas('c_energycalibration', '', 1280, 720)
    g = data.makeGraph('g_energycalibration', 'channel c', 'energy E / MeV')
    g.Draw('AP')
    
    fit = Fitter('fit_energycalibration', 'pol1(0)')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1/3)
    fit.fit(g, 0, max(channels) + 5)
    fit.saveData('../fit/energyCalibration.txt')
    
    l = TLegend(0.15, 0.6, 0.575, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Peaks of flight through spectra / pedestal', 'p')
    l.AddEntry(fit.function, 'fit with E(c) = a + b * c', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f')), chisquareformat='%.2f', units=('MeV', 'MeV / channel'), lang='en')
    l.Draw()
    
    c.Update()
    c.Print('../img/energyCalibration.pdf', 'pdf')
    
    with TxtFile('../calc/energyCalibration.txt', 'w') as f:
        f.writeline('\t', str(fit.params[0]['value']), str(fit.params[0]['error']))
        f.writeline('\t', str(fit.params[1]['value']), str(fit.params[1]['error']))
        f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
开发者ID:Bigben37,项目名称:FP2,代码行数:44,代码来源:evalEnergyCalibration.py

示例2: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import getCovMatrixElem [as 别名]
def main():
    times = [2.4, 4.5, 6.25, 8.6]
    times_error = [0.02] * len(times)
    channels = [113, 223, 315.5, 441]
    channels_error = [0.5] * len(times)
    
    with TxtFile('../src/tab_timecalibration.tex', 'w') as f:
        f.write2DArrayToLatexTable(list(zip(*[times, times_error, channels, channels_error])),
                                   ["$t$ / \\textmu s", "$s_t$ / \\textmu s", "$c$", "$s_c$"], 
                                   ["%.2f", "%.2f", "%.1f", "%.1f"], 
                                   "Measured times and channels with errors for the time calibration.", "tab:tcal")

    data = DataErrors.fromLists(channels, times, channels_error, times_error)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'channel c', 'time t / #mus')
    g.Draw('APX')

    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 50)
    fit.fit(g, 100, 450)
    fit.saveData('../fit/timeCalibration.txt')

    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measurement', 'p')
    l.AddEntry(fit.function, 'fit with t(c) = a + b * c', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.5f', '%.5f')), chisquareformat='%.2f', units=('#mus', '#mus/channel'), lang='en')
    l.Draw()

    g.Draw('P')
    c.Update()
    c.Print('../img/timeCalibration.pdf', 'pdf')

    with TxtFile('../calc/timeCalibration.txt', 'w') as f:
        f.writeline('\t', str(fit.params[0]['value']), str(fit.params[0]['error']))
        f.writeline('\t', str(fit.params[1]['value']), str(fit.params[1]['error']))
        f.writeline('\t', str(fit.getCovMatrixElem(0, 1)))
开发者ID:Bigben37,项目名称:FP2,代码行数:40,代码来源:evalTimeCalibration.py


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