本文整理汇总了Python中fitter.Fitter.setParam方法的典型用法代码示例。如果您正苦于以下问题:Python Fitter.setParam方法的具体用法?Python Fitter.setParam怎么用?Python Fitter.setParam使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fitter.Fitter
的用法示例。
在下文中一共展示了Fitter.setParam方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fitX0
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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'])]
示例2: fitT
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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'])]
示例3: main
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例4: compareSpectrum
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例5: energyGauge
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例6: makeSigmaFit
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例7: fitSigma
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例8: makeBFit
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例9: fitLambda
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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')
示例10: fitSpectrum
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [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
示例11: fitLaserVoltage
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [as 别名]
def fitLaserVoltage(g, xmin, xmax, file):
fit = Fitter('%s-laser' % file[:-4], 'pol1(0)')
fit.function.SetLineColor(92)
fit.function.SetLineWidth(2)
fit.setParam(0, 'a', 0)
fit.setParam(1, 'b', 100)
fit.fit(g, xmin, xmax, '+')
fit.saveData('../fit/part2/%s-laser.txt' % file)
return (fit.params[1]['value'], fit.params[1]['error'], fit.function)
示例12: main
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [as 别名]
def main():
snu = ERRORS["nu"] # TODO get error
sB = ERRORS["B"]
sgyrorel = 0
files = ["H", "Glycol", "Teflon"]
for file in files:
datalist = loadCSVToList("../data/03-%s.txt" % file)
if len(datalist) == 1:
B, nu = datalist[0]
gyro, sgyro = calcGyro(nu, snu, B, sB)
if not sgyrorel == 0:
sgyro = gyro * sgyrorel
with TxtFile("../calc/%s.txt" % file, "w") as f:
f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))
else:
x, y = zip(*datalist)
sx = [0] * len(x)
sy = [snu] * len(y)
data = DataErrors.fromLists(x, y, sx, sy)
data.setXErrorAbs(sB)
c = TCanvas("c%s" % file, "", 1280, 720)
g = data.makeGraph("g%s" % file, "Magnetfeld B / mT", "Resonanzfrequenz #nu / MHz")
g.Draw("AP")
fit = Fitter("fit%s" % file, "[0]*x")
fit.setParam(0, "m", 0.002)
fit.fit(g, datalist[0][0] * 0.95, datalist[-1][0] * 1.05)
fit.saveData("../calc/fit-%s.txt" % file, "w")
l = TLegend(0.15, 0.60, 0.475, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g, "Messdaten", "p")
l.AddEntry(fit.function, "Fit mit #nu(B) = m*B", "l")
l.AddEntry(0, "", "")
fit.addParamsToLegend(
l,
[("%.5f", "%.5f"), ("%.2f", "%.2f")],
chisquareformat="%.2f",
advancedchi=True,
units=["MHz / mT", "MHz"],
)
l.Draw()
gyro = 2 * np.pi * fit.params[0]["value"] * 1e9 # in Hz / T
sgyro = 2 * np.pi * fit.params[0]["error"] * 1e9 # in Hz / T
sgyrorel = sgyro / gyro
with TxtFile("../calc/%s.txt" % file, "w") as f:
f.writeline("\t", "gyro", *map(str, (gyro, sgyro)))
f.writeline("\t", "sgyrorel", str(sgyrorel))
f.writeline("\t", "mu", *map(str, calcMu(gyro, sgyro)))
f.writeline("\t", "gI", *map(str, calcNucGFactor(gyro, sgyro)))
c.Update()
c.Print("../img/03-%s.pdf" % file, "pdf")
示例13: evalDiode
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [as 别名]
def evalDiode():
datalist = loadCSVToList('../data/part1/Kennlinie.txt')
data = DataErrors()
U0 = datalist[0][1]
sU0 = 0.05 + 0.01 * U0
for I, u in datalist:
U = u - U0
su = 5 + 0.01 * u
sU = sqrt(su ** 2 + sU0 ** 2)
data.addPoint(I, U, 0.1, sU)
xmin, xmax = 53, 71.5
c = TCanvas('c_diode', '', 1280, 720)
g = data.makeGraph('g_diode', "Laserstrom I_{L} / mA", "Photodiodenspannung U_{ph} / mV")
g.GetXaxis().SetRangeUser(-5, 90)
g.SetMinimum(-50)
g.SetMaximum(1400)
g.Draw('APX')
# y=0 line
line = TLine(-5, 0, 90, 0)
line.SetLineColor(OPData.CH2ECOLOR)
line.Draw()
data.filterX(xmin, xmax)
g2 = data.makeGraph('g_diode_2', "Laserstrom I_{L} / mA", "Photodiodenspannung U_{ph} / mV")
g2.SetMarkerColor(OPData.CH1COLOR)
g2.SetLineColor(OPData.CH1COLOR)
fit = Fitter('fit_diode', '[0] * (x-[1])')
fit.function.SetNpx(1000)
fit.setParam(0, 'a', 1)
fit.setParam(1, 'I_{th}', 50)
fit.fit(g2, 40, 77)
fit.saveData('../fit/part1/kennlinie.txt')
l = TLegend(0.15, 0.55, 0.4, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g, 'Laserdiodenkennlinie', 'p')
l.AddEntry(g2, 'Ausschnitt zum Fitten', 'p')
l.AddEntry(fit.function, 'Fit mit U_{ph} = a (I_{ L} - I_{ th} )', 'l')
fit.addParamsToLegend(l, (('%.1f', '%.1f'), ('%.2f', '%.2f')), chisquareformat='%.2f', units=['mV/mA', 'mA'])
l.Draw()
g.Draw('P')
g2.Draw('P')
c.Update()
c.Print('../img/part1/diodenkennlinie.pdf', 'pdf')
示例14: printGraph
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [as 别名]
def printGraph(datas, phi, name='', fit=False):
"""make graph with measured taus for one specific angle phi
Arguments:
datas -- datalists (sorted by series in dictonary)
phi -- angle
name -- additional name for file name
fit -- if true fit data with linear model (default=False)
"""
# setup canvas and legend
c = TCanvas('c_%d' % phi, '', 1280, 720)
if fit:
l = TLegend(0.6, 0.15, 0.85, 0.5)
else:
l = TLegend(0.65, 0.15, 0.85, 0.35)
l.SetTextSize(0.03)
# make and draw graphs, graphs are organized by TMultiGraph
graphs = TMultiGraph()
for s, datalist in datas.iteritems():
data = DataErrors.fromLists(*zip(*datalist))
g = data.makeGraph('g_%d_%d' % (phi, s))
g.SetMarkerColor(seriescolors[s])
g.SetLineColor(seriescolors[s])
l.AddEntry(g, serieslabels[s], 'p')
graphs.Add(g)
graphs.Draw('AP')
gPad.Update()
setMultiGraphTitle(graphs, 'Druck p / mPa', '#tau / ns')
# fit data with linear fit
if fit:
fit = Fitter('fit_%d' % phi, 'pol1(0)')
fit.function.SetNpx(1000)
fit.setParam(0, '#tau_{0}', 119)
fit.setParam(1, 'm', 0.5)
fit.fit(graphs, 0, 225, 'M')
fit.saveData('../calc/fit_tau_%02d%s.txt' % (phi, name), 'w')
l.AddEntry(fit.function, 'Fit mit #tau(p) = #tau_{0} + m * p', 'l')
fit.addParamsToLegend(l, [('%.1f', '%.1f'), ('%.2f', '%.2f')], chisquareformat='%.2f',
advancedchi=True, units=['ns', 'ns / mPa'])
# draw legend and print canvas to file
l.Draw()
c.Update()
c.Print('../img/taus_%02d%s.pdf' % (phi, name), 'pdf')
# return required fit parameter
if fit:
return fit.params[0]['value'], fit.params[0]['error']
示例15: makeFranzenFit
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParam [as 别名]
def makeFranzenFit(n, plotParams):
data = OPData.fromPath(DIR + '%02d.tab' % n, 1)
xmin, xmax = plotParams[:2]
fitparams = plotParams[2:]
c = TCanvas('c_%d' % n, '', 1280, 720)
g = data.makeGraph('g_%d' % n, 'Zeit t / s', 'U_{ph} / V')
prepareGraph(g, 2)
g.GetXaxis().SetRangeUser(xmin, xmax)
g.Draw('APX')
fit = Fitter('fit%d' % n, franzenFunc, (xmin, xmax, 6))
fit.function.SetNpx(1000)
paramnames = ["A", "u", "#mu", "#sigma", "B", "#lambda"]
for i in range(6):
fit.setParam(i, paramnames[i], fitparams[3 * i])
fit.setParamLimits(i, fitparams[3 * i + 1], fitparams[3 * i + 2])
print(fitparams[3 * i], fitparams[3 * i + 1], fitparams[3 * i + 2])
fit.fit(g, xmin, xmax)
fit.saveData('../fit/part6/%02d.txt' % n)
fermi = TF1('func', fermiFunc, xmin, xmax, 5)
fermi.SetNpx(1000)
fermi.SetLineColor(getRootColor(0))
fermi.SetLineWidth(1)
for i in range(5):
fermi.SetParameter(i, fit.params[i]['value'])
fermi.Draw('SAME')
g.Draw('P')
l = TLegend(0.4, 0.15, 0.85, 0.65)
l.SetTextSize(0.03)
l.AddEntry(g, "Spannung Photodiode U_{ph}", 'l')
l.AddEntry(fit.function, 'Fit mit U_{ph}(t) = U_{F}(t; A, u, #mu, #sigma) + U_{E}(t; #mu, B, #lambda)', 'l')
l.AddEntry(fermi, 'Fermi-Verteilung', 'l')
fit.addParamsToLegend(l, [('%.4f', '%.4f'), ('%.4f', '%.4f'), ('%.5f', '%.5f'), ('%.2f', '%.2f'), ('%.4f', '%.4f'), ('%.3f', '%.3f')],
chisquareformat='%.2f', units=["V", "V", "ms", "#mus", "V", "1/ms"])
l.Draw()
c.Update()
c.Print('../img/part6/%02d.pdf' % n, 'pdf')
result = []
exportvals = [2, 3, 4] # mu, sigma, B
for e in exportvals:
result.append((fit.params[e]['value'], fit.params[e]['error']))
return result