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


Python Fitter.fit方法代码示例

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


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

示例1: fitLambda

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitLambda():
    data = Data()
    data.addPoint(500, 1.000279)
    data.addPoint(540, 1.000278)
    data.addPoint(600, 1.000277)
    data.addPoint(682, 1.000276)

    c = TCanvas('c1', '', 1280, 720)
    g = data.makeGraph('g', 'wavelength #lambda / nm', 'refraction index n')
    g.GetYaxis().SetLabelSize(0.03)
    g.GetYaxis().SetTitleOffset(1.39)
    g.Draw('AP')

    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 2)
    fit.setParam(1, 'b', -1)
    fit.fit(g, 450, 700)
    fit.saveData('../calc/fit_lambda.txt', 'w')

    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.6, 0.87, 0.87)
    l.AddEntry('g', 'refraction index n as a function of wavelength #lambda', 'p')
    l.AddEntry(fit.function, 'fit with n(#lambda)= a+b*#lambda', 'l')
    fit.addParamsToLegend(l)
    l.SetTextSize(0.03)
    l.Draw()

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

示例2: fitX0

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitX0(period):
    # get data and make graph
    data = X0Data.fromPath('../data/T_%dms.txt' % period)
    c = TCanvas('c_%d' % period, '', 1280, 720)
    g = data.makeGraph('g_%d' % period, 'Differenzenfrequenz #Delta#nu / kHz', 'Auftreffpunkt x_{0}\' / mm')
    g.Draw('AP')

    # axis cross
    vline = TLine(0, 33, 0, 60)
    vline.Draw()

    # fit
    fit = Fitter('fit_%d' % period, 'pol1(0)')
    fit.setParam(0, 'x_{m}', 47)
    fit.setParam(1, 'm')
    fit.fit(g, min(data.getX()) - 3, max(data.getX()) + 3)
    fit.saveData('../calc/fit_T_%dms.txt' % period, 'w')

    # legend
    l = TLegend(0.15, 0.65, 0.425, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Messreihe bei T = %d ms' % period, 'p')
    l.AddEntry(fit.function, 'Fit mit x_{0}\'(#Delta#nu) = x_{m} + m * #Delta#nu', 'l')
    fit.addParamsToLegend(l, [('%.3f', '%.3f'), ('%.4f', '%.4f')], chisquareformat='%.2f')
    l.Draw()

    # print
    c.Update()
    c.Print('../img/fit_T_%dms.pdf' % period, 'pdf')

    return [(fit.params[0]['value'], fit.params[0]['error']), (fit.params[1]['value'], fit.params[1]['error'])]
开发者ID:Bigben37,项目名称:FP1,代码行数:33,代码来源:eval_X0.py

示例3: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def main():
    x, y, sy = zip(*loadCSVToList('../calc/part3/Co-Si_mergedbins.txt'))
    data = DataErrors.fromLists(x, y, [0]*len(x), sy)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'Kanal k', 'Counts N')
    g.SetMarkerStyle(8)
    g.SetMarkerSize(0.5)
    g.SetLineColor(15)
    g.SetLineWidth(0)
    g.Draw('AP')
    
    fit = Fitter('f', '1/(sqrt(2*pi*[2]^2))*gaus(0)')
    fit.setParam(0, 'A', 50)
    fit.setParam(1, 'x_{c}', 690)
    fit.setParam(2, 's', 20)
    fit.fit(g, 672, 712)
    fit.saveData('../calc/part3/fit_Co-Si_01_mergedbins.txt', 'w')
    with TxtFile('../calc/part3/fit_Co-Si_01_mergedbins_raw.txt', 'w') as f:
        for key, param in fit.params.iteritems():
            f.writeline('\t', *map(str, [param['value'], param['error']]))
    
    l = TLegend(0.7, 0.5, 0.95, 0.85)
    l.SetTextSize(0.0225)
    l.AddEntry(g, 'Gemittelte Messwerte', 'p')
    l.AddEntry(fit.function, 'Fit mit', 'l')
    l.AddEntry(0, 'N(k) = #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{x-x_{c}}{#sigma})^{2})', '')
    l.AddEntry(0, '', '')
    fit.addParamsToLegend(l, chisquareformat='%.2f')
    l.Draw()
    
    c.Update()
    c.Print('../img/part3/Co-Si_01_mergedbins.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:34,代码来源:eval_part3_co_si_smallpeak.py

示例4: compareSpectrum

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def compareSpectrum(prefix, spectrum, litvals):
    xlist = list(zip(*spectrum))[0]
    sxlist = list(zip(*spectrum))[1]

    compData = DataErrors.fromLists(xlist, litvals, sxlist, [0] * len(litvals))

    c = TCanvas('c_%s_compspectrum' % prefix, '', 1280, 720)
    g = compData.makeGraph('g_%s_compspectrum' % prefix,
                           'experimentell bestimmte HFS-Aufspaltung #Delta#nu^{exp}_{%s} / GHz' % prefix,
                           'theoretische HFS-Aufspaltung #Delta#nu^{theo} / GHz')
    g.Draw('AP')

    fit = Fitter('fit_%s_compspectum' % prefix, 'pol1(0)')
    fit.setParam(0, 'a_{%s}' % prefix, 0)
    fit.setParam(1, 'b_{%s}' % prefix, 1)
    fit.fit(g, compData.getMinX() - 0.5, compData.getMaxX() + 0.5)

    if prefix == "up":
        l = TLegend(0.15, 0.6, 0.45, 0.85)
    else:
        l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Spektrum', 'p')
    l.AddEntry(fit.function, 'Fit mit #Delta#nu^{theo} = a_{%s} + b_{%s} #Delta#nu^{exp}_{%s}' % (prefix, prefix, prefix), 'l')
    fit.addParamsToLegend(l, [('%.2f', '%.2f'), ('%.3f', '%.3f')], chisquareformat='%.2f', units=['GHz', ''])
    l.Draw()

    c.Update()
    if not DEBUG:
        c.Print('../img/part2/%s-spectrum.pdf' % prefix, 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:32,代码来源:part2.py

示例5: multiPeakFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def multiPeakFit(g, ufunc, uparams, params, xstart, xend):
    """fits all peaks with one function

    Arguments:
    g      -- graph
    ufunc     -- underground function
    uparams     -- start parameter for underground function
    params -- params for peaks
    xstart -- start x value
    xend   -- end x value
    """
    # build fit function
    fitfunc = ufunc
    pstart = len(uparams)
    for i in xrange(len(params)):
        fitfunc += ' + gaus(%d)' % (pstart + 3 * i)
    # create fitter, change npx to high value
    fit = Fitter('f', fitfunc)
    fit.function.SetNpx(10000)
    # set underground params
    for i, param in enumerate(uparams):
        fit.setParam(i, chr(97 + i), param)  # params of underground are enumerated with a, b, c, ...
    # set peak params
    for i, param in enumerate(params):
        fit.setParam(3 * i + pstart + 0, 'A%d' % (i + 1), param[0])
        fit.setParam(3 * i + pstart + 1, 'c%d' % (i + 1), param[1])
        fit.setParam(3 * i + pstart + 2, 's%d' % (i + 1), param[3])
    # fit
    fit.fit(g, xstart, xend)
    return fit
开发者ID:Bigben37,项目名称:FP1,代码行数:32,代码来源:eval_th.py

示例6: evalPedestal

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def evalPedestal():
    name = 'pedestal'
    data = MyonData.fromPath('../data/%s.TKA' % name)
    data.convertToCountrate()
    c = TCanvas('c_ped', '', 1280, 720)
    g = data.makeGraph('g_ped', 'channel c', 'countrate n / (1/s)')
    g.SetLineColor(1)
    g.SetLineWidth(1)
    g.GetXaxis().SetRangeUser(0, 20)
    g.Draw('APX')
    
    fit = Fitter('fit_%s' % name, 'gaus(0)')
    fit.setParam(0, 'A', 30)
    fit.setParam(1, 'x', 6)
    fit.setParam(2, '#sigma', 3)
    fit.setParamLimits(2, 0, 100)
    fit.fit(g, 3.5, 10.5)
    fit.saveData('../fit/%s.txt' % name)
    
    l = TLegend(0.55, 0.6, 0.85, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'pedestal', 'p')
    l.AddEntry(fit.function, 'fit with n(c) = A gaus(c; x, #sigma)', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.3f', '%.3f'), ('%.3f', '%.3f')), chisquareformat='%.2f', units=('1/s', '', ''), lang='en')
    l.Draw()

    g.Draw('P')
    c.Update()
    c.Print('../img/%s.pdf' % name, 'pdf')
    
    return (fit.params[1]['value'], fit.params[1]['error'])
开发者ID:Bigben37,项目名称:FP2,代码行数:33,代码来源:evalEnergyCalibration.py

示例7: fitT

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitT(x0):
    # get data and make graph
    data = TData.fromPath('../data/x0_%dmm.txt' % x0)
    c = TCanvas('c_%d' % x0, '', 1280, 720)
    g = data.makeGraph('g_%d' % x0, 'Kreisfrequenz #omega / (rad/ms)', 'Differenzenfrequenz #Delta#nu / kHz')
    g.Draw('AP')

    # fit
    fit = Fitter('fit_%d' % x0, 'pol1(0)')
    fit.setParam(0, 'a')
    fit.setParam(1, 'b')
    fit.fit(g, min(data.getX()) - 3, max(data.getX()) + 3)
    fit.saveData('../calc/fit_x0_%dmm.txt' % x0, 'w')

    # legend
    l = TLegend(0.15, 0.625, 0.425, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Messreihe bei x_{0}\' = %d mm' % x0, 'p')
    l.AddEntry(fit.function, 'Fit mit #Delta#nu (#omega) = a + b*#omega', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.0f', '%.0f')], chisquareformat='%.2f')
    l.Draw()

    # print
    c.Update()
    c.Print('../img/fit_x0_%dmm.pdf' % x0, 'pdf')

    return [(fit.params[0]['value'], fit.params[0]['error']), (fit.params[1]['value'], fit.params[1]['error'])]
开发者ID:Bigben37,项目名称:FP1,代码行数:29,代码来源:eval_T.py

示例8: makeBFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def makeBFit(darkTimes, Bs):
    dt, sdt = list(zip(*darkTimes))
    b, sb = list(zip(*Bs))
    data = DataErrors.fromLists(dt, b, sdt, sb)

    c = TCanvas('c_B', '', 1280, 720)
    g = data.makeGraph('g_B', 'Dunkelzeit t_{D} / ms', 'Fitparameter B / V')
    g.Draw('APX')

    fit = Fitter('fit_B', '[0] + [1] * (1 - exp(-x/[2]))')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'a', 0.1)
    fit.setParam(1, 'b', 0.1)
    fit.setParam(2, 'T_{R_{F}}', 6)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/B.txt')

    l = TLegend(0.55, 0.15, 0.85, 0.6)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Fitparameter B', 'p')
    l.AddEntry(fit.function, 'Fit mit B(t_{D}) = a + b (1 - e^{-x/T_{R_{F}}})', 'l')
    fit.addParamsToLegend(l, (('%.3f', '%.3f'), ('%.3f', '%.3f'), ('%.1f', '%.1f')), chisquareformat='%.2f', units=['V', 'V', 'ms'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/BFit.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:28,代码来源:part6.py

示例9: fitSigma

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitSigma(sigs, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*sigs)
    listy = map(abs, listy)   # fits can yield negative sigma, because it only occurse to
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cSigma', '', 1280, 720)
    g = data.makeGraph('Sigma', 'Zeit t / s', 'Standardabweichung #sigma / cm')
    g.Draw('AP')

    fit = Fitter('fitS', 'sqrt(2*[0]*(x + [1]))')
    fit.setParam(0, 'D_{n}', 100)
    fit.setParam(1, 't_{0}', 0)
    fit.fit(g, 1e-6, 21e-6)
    fit.saveData('../calc/part2/dist_fit_sigma.txt')

    l = TLegend(0.15, 0.625, 0.45, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('Sigma', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit #sigma(t) = #sqrt{2*D_{n}*(t + t_{0})}', 'l')
    fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2e', '%.2e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/dist_fitSigma.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:28,代码来源:eval_part2_dist.py

示例10: makeSigmaFit

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def makeSigmaFit(darkTimes, sigmas):
    dt, sdt = list(zip(*darkTimes))
    s, ss = list(zip(*sigmas))
    data = DataErrors.fromLists(dt, s, sdt, ss)

    c = TCanvas('c_sigma', '', 1280, 720)
    g = data.makeGraph('g_sigma', 'Dunkelzeit t_{D} / ms', 'Verschmierung #sigma / #mus')
    g.Draw('APX')

    fit = Fitter('fit_sigma', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 0, 25)
    fit.saveData('../fit/sigma.txt')

    l = TLegend(0.6, 0.15, 0.85, 0.5)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Verschmierung #sigma', 'p')
    l.AddEntry(None, 'der Fermi-Verteilung', '')
    l.AddEntry(fit.function, 'Fit mit #sigma(t_{D}) = a + b t_{D}', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['#mus', '10^{-3}'])
    l.Draw()

    g.Draw('P')
    c.Print('../img/part6/sigmaFit.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:27,代码来源:part6.py

示例11: fitA

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitA(amps, times):
    listx, listsx = zip(*times)
    listy, listsy = zip(*amps)
    slaser_rel = 0.05
    listsy = list(listsy)
    for i, y in enumerate(listy):
        listsy[i] = y * np.sqrt(listsy[i] ** 2 + slaser_rel ** 2)
    data = DataErrors.fromLists(listx, listy, listsx, listsy)

    c = TCanvas('cA', '', 1280, 720)
    g = data.makeGraph('A', 'Zeit t / s', 'Amplitude A / V')
    g.GetYaxis().SetTitleOffset(1.2)
    g.Draw('AP')

    fit = Fitter('A', '[0]*exp(-(x)/[1])+[2]')
    fit.function.SetNpx(1000)
    fit.setParam(0, 'C', 5e-8)
    fit.setParam(1, '#tau_{n}', 45e-6)
    fit.setParam(2, 'a', 0)
    fit.fit(g, 7.5e-6, 18e-6)
    fit.saveData('../calc/part2/volt_fit_A.txt')

    l = TLegend(0.625, 0.625, 0.85, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry('A', 'Messung', 'p')
    l.AddEntry(fit.function, 'Fit mit A(t) = C*e^{- #frac{t}{#tau_{n}}} + a', 'l')
    fit.addParamsToLegend(l, [('%.2e', '%.1e'), ('%.2e', '%.1e'), ('%.2e', '%.1e')], chisquareformat='%.2f')
    l.Draw()

    if PRINTGRAPHS or True:
        c.Update()
        c.Print('../img/part2/volt_fitA.pdf', 'pdf')
        c.SetLogy()
        c.Update()
        c.Print('../img/part2/volt_fitA_log.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:37,代码来源:eval_part2_volt.py

示例12: main

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def main():
    z, sz = 840, 40
    d = [210, 106, 75]
    sd = [10, 4, 4]
    calc = list(map(lambda x:-20 * log10(x/z), d))
    scalc = list(map(lambda x:20 * sqrt((x[1]/x[0]) ** 2 + (sz/z)**2) / log(10), zip(*[d, sd])))
    
    data = DataErrors.fromLists(calc, [12, 18, 21], scalc, [0]*3)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured attenuation m / dB', 'nominal value n / dB')
    g.Draw('AP')
    
    fit = Fitter('fit', 'pol1(0)')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 11, 22)
    fit.saveData('../fit/attenuator.txt')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'measured att. vs. nominal value', 'p')
    l.AddEntry(fit.function, 'fit with n = a + b m', 'l')
    fit.addParamsToLegend(l, (('%.2f', '%.2f'), ('%.2f', '%.2f')), chisquareformat='%.4f', units=['dB', ''], lang='en')
    l.Draw()
    
    c.Update()
    c.Print('../img/attenuator.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP2,代码行数:29,代码来源:evalAttenuator.py

示例13: energyGauge

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def energyGauge():
    dataList = readFileToList('../calc/hg_lines.txt')
    elemNames = ['Hg'] * len(dataList)
    dataList += readFileToList('../calc/na_lines.txt')
    elemNames += ['Na'] * (len(dataList) - len(elemNames))
    litVals = readFileToList('../data/hg_litvals.txt')
    litVals += readFileToList('../data/na_litvals.txt')

    data = DataErrors()
    for val, litval in zip(dataList, litVals):
        data.addPoint(val, litval, I2Data.ERRORBIN, 0)
        
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g', 'measured wavelength #lambda_{exp} / nm', 'literature value #lambda_{lit} / nm')
    g.Draw('AP')
    
    fit = Fitter('f', '[0]+[1]*x')
    fit.setParam(0, 'a', 0)
    fit.setParam(1, 'b', 1)
    fit.fit(g, 420, 600)
    fit.saveData('../calc/fit_energy_gauge.txt', 'w')
    
    l = TLegend(0.15, 0.6, 0.5, 0.85)
    l.AddEntry(fit.function, 'y = a + b*x', 'l')
    fit.addParamsToLegend(l)
    l.SetTextSize(0.03)
    l.Draw()
    
    c.Update()
    c.Print('../img/energy_gauge.pdf', 'pdf')
开发者ID:Bigben37,项目名称:FP1,代码行数:32,代码来源:eval_energy_gauge.py

示例14: fitTransmissionSignal

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitTransmissionSignal(name):
    data = OPData.fromPath(DIR + name + '.tab', 2)
    c = TCanvas('c', '', 1280, 720)
    g = data.makeGraph('g_%s' % name, 'Zeit t / s', 'Spannung der Photodiode U_{ph} / V')
    prepareGraph(g, 2)
    g.GetXaxis().SetRangeUser(0.004, 0.019)
    g.Draw('APX')

    xmin, xmax = 0.0054, 0.015

    fit = Fitter('fit_%s' % name[-2:], '[0] - [1] * exp(-x/[2])')
    fit.setParam(0, 'a', 0.01)
    fit.setParam(1, 'b', 100)
    fit.setParam(2, '#tau', 0.001)
    fit.fit(g, xmin, xmax, 'M')
    fit.saveData('../fit/part5/%s.txt' % name)

    g.Draw('P')

    l = TLegend(0.35, 0.2, 0.65, 0.525)
    l.SetTextSize(0.03)
    l.AddEntry(g, 'Spannung der Photodiode', 'p')
    l.AddEntry(fit.function, 'Fit mit U_{ph}(t) = a - b e^{-t/#tau}', 'l')
    fit.addParamsToLegend(l, [('%.6f', '%.6f'), ('%.2f', '%.2f'), ('%.6f', '%.6f')], chisquareformat='%.2f', units=['V', 'V', 's'])
    l.Draw()

    c.Update()
    c.Print('../img/part5/%s.pdf' % name.replace('.', '-'), 'pdf')

    return fit.params[2]['value'], fit.params[2]['error']
开发者ID:Bigben37,项目名称:FP2,代码行数:32,代码来源:part5.py

示例15: fitSpectrum

# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import fit [as 别名]
def fitSpectrum(detector, element, params, logy=True):
    data = P3SemiCon.fromPath('../data/part3/%s-%s.mca' % (element, detector))
    printTotalSpectrum(data, element, detector, logy)

    fitresults = []
    for i, peak in enumerate(params):
        c = TCanvas('cpeakl_%s-%s_%d' % (element, detector, i), '', 1280, 720)
        g = data.makeGraph('g%s-%s_%d' % (element, detector, i), 'Kanal k', 'Counts N')
        prepareGraph(g)
        g.GetXaxis().SetRangeUser(peak[2][0], peak[2][1])
        g.SetMinimum(peak[3][0])
        g.SetMaximum(peak[3][1])
        g.Draw('AP')

        fit = None
        paramnames = []
        if len(peak[0]) == 5:
            fit = Fitter('fit%d' % i, 'pol1(0) + 1/(sqrt(2*pi*[4]^2))*gaus(2)')
            paramnames = ['a', 'b', 'A', 'k_{c}', 's']
        elif len(peak[0]) == 4:
            fit = Fitter('fit%d' % i, '[0] + 1/(sqrt(2*pi*[3]^2))*gaus(1)')
            paramnames = ['a', 'A', 'k_{c}', 's']
        elif len(peak[0]) == 3:
            fit = Fitter('fit%d' % i, '1/(sqrt(2*pi*[2]^2))*gaus(0)')
            paramnames = ['A', 'k_{c}', 's']

        l = None
        if len(peak[0]) > 0:
            for j, param in enumerate(peak[0]):
                fit.setParam(j, paramnames[j], param)
            fit.fit(g, *peak[1])

            fitname = ''
            if len(peak[0]) == 5:
                fitname = 'N(k) = a + b*k + #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            elif len(peak[0]) == 4:
                fitname = 'N(k) = a + #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            elif len(peak[0]) == 3:
                fitname = 'N(k) = #frac{A}{#sqrt{2#pi*#sigma^{2}}} exp(- #frac{1}{2} (#frac{k-k_{c}}{#sigma})^{2})'
            fit.saveData('../calc/part3/fit_%s-%s_%02d.txt' % (element, detector, i), 'w')
            results = []
            for j, param in fit.params.iteritems():
                results.append((param['value'], param['error']))
            fitresults.append(results)

            # legend
            l = TLegend(0.675, 0.5, 0.995, 0.85)
            l.SetTextSize(0.025)
            l.AddEntry(g, 'Messwerte', 'p')
            l.AddEntry(fit.function, 'Fit mit', 'l')
            l.AddEntry(0, fitname, '')
            l.AddEntry(0, '', '')
            fit.addParamsToLegend(l, chisquareformat='%.2f')
            l.Draw()

        c.Update()
        if PRINTGRAPHS:
            c.Print('../img/part3/%s-%s_%02d.pdf' % (element, detector, i), 'pdf')
    return fitresults
开发者ID:Bigben37,项目名称:FP1,代码行数:61,代码来源:eval_part3.py


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