本文整理汇总了Python中fitter.Fitter.setParamLimits方法的典型用法代码示例。如果您正苦于以下问题:Python Fitter.setParamLimits方法的具体用法?Python Fitter.setParamLimits怎么用?Python Fitter.setParamLimits使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fitter.Fitter
的用法示例。
在下文中一共展示了Fitter.setParamLimits方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: evalPedestal
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParamLimits [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'])
示例2: makeFranzenFit
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParamLimits [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
示例3: makeCSGraph
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParamLimits [as 别名]
def makeCSGraph(ctype, startGammaEE=None):
data = loadCrossSection(ctype)
c = TCanvas('c_%s' % ctype, '', 1280, 720)
g = data.makeGraph('g_%s' % ctype, '#sqrt{s} / GeV', '#sigma / nb')
g.Draw('AP')
if not startGammaEE:
fit = Fitter('fit_%s' % ctype, '(12*pi / [0]^2) * (x^2 * [1]^2) / ((x^2-[0]^2)^2 + x^4 * [2]^2 / [0]^2) * 0.3894*10^6') # GeV^-2 = 0.3894 mb
fitfuncstring = "#frac{12#pi}{M_{Z}^{2}} #frac{s #Gamma_{%s}^{2}}{(s-M_{Z}^{2})^{2} + s^{2} #Gamma_{Z}^{2} / M_{Z}^{2}}" % ctype[0]
else:
fit = Fitter('fit_%s' % ctype, '(12*pi / [0]^2) * (x^2 * [1] * [2]) / ((x^2-[0]^2)^2 + x^4 * [3]^2 / [0]^2) * 0.3894*10^6')
fitfuncstring = "#frac{12#pi}{M_{Z}^{2}} #frac{s #Gamma_{m} #Gamma_{%s}}{(s-M_{Z}^{2})^{2} + s^{2} #Gamma_{Z}^{2} / M_{Z}^{2}}" % ctype[0]
fit.setParam(0, 'M_{Z}', 91.2)
fit.setParamLimits(0, 0, 1000)
if not startGammaEE:
fit.setParam(1, '#Gamma_{%s}' % ctype[0], 0.08)
fit.setParamLimits(1, 0, 1000)
fit.setParam(2, '#Gamma_{Z}', 2.5)
fit.setParamLimits(2, 0, 1000)
else:
fit.setParam(1, '#Gamma_{m}', startGammaEE, True)
fit.setParam(2, '#Gamma_{%s}' % ctype[0], 1.5)
fit.setParam(3, '#Gamma_{Z}', 2.5)
fit.setParamLimits(2, 0, 1000)
fit.fit(g, 88, 94, '')
fit.saveData('../fit/crosssections_%s.txt' % ctype)
l = TLegend(0.625, 0.6, 0.98, 0.975)
l.SetTextSize(0.03)
l.AddEntry(g, "%s Wirkungsquerschnitte" % ctype, 'p')
l.AddEntry(fit.function, "Fit mit #sigma(s) = %s" % fitfuncstring, 'l')
l.AddEntry(None, "", '')
if not startGammaEE:
fit.addParamsToLegend(l, [('%.3f', '%.3f'), ('%.4f', '%.4f'), ('%.3f', '%.3f')], chisquareformat='%f', units=['GeV / c^{2}', 'GeV', 'GeV'])
else:
fit.addParamsToLegend(l, [('%.3f', '%.3f'), '%.4f', ('%.3f', '%.3f'), ('%.3f', '%.3f')], chisquareformat='%f', units=['GeV/c^{2}', 'GeV', 'GeV', 'GeV'])
l.Draw()
c.Update()
if not DEBUG:
c.Print('../img/crosssections_%s.pdf' % ctype, 'pdf')
if not startGammaEE:
result = [(fit.params[0]['value'], fit.params[0]['error']),
(fit.params[1]['value'], fit.params[1]['error']),
(fit.params[2]['value'], fit.params[2]['error'])]
else:
result = [(fit.params[0]['value'], fit.params[0]['error']),
(fit.params[2]['value'], fit.params[2]['error']),
(fit.params[3]['value'], fit.params[3]['error'])]
return result
示例4: fitEtalonPeak
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParamLimits [as 别名]
def fitEtalonPeak(g, peakx, deltaX, i, name, isUp=True):
print('fit etalon peak %s: %.4f +- %.5f' % (name, peakx, deltaX))
fit = Fitter('%s-peak%d' % (name, i), '[0]+[1]*x+[2]*TMath::CauchyDist(x, [3], [4])')
fit.function.SetLineColor(getRootColor(i))
fit.setParam(0, 'a', 0)
b = 50
if isUp:
fit.setParam(1, 'b', b)
fit.setParamLimits(1, 0, 4 * b)
else:
fit.setParam(1, 'b', -b)
fit.setParamLimits(1, -b * 4, 0)
fit.setParam(2, 'A', 2e-5)
fit.setParamLimits(2, 0, 1)
fit.setParam(3, 'x', peakx)
fit.setParamLimits(3, peakx - deltaX, peakx + deltaX)
fit.setParam(4, 's', 1e-4)
fit.setParamLimits(4, 0, 5e-3)
fit.fit(g, peakx - deltaX, peakx + deltaX, '+')
fit.saveData('../fit/part2/%s-peak%d.txt' % (name, i))
return (fit.params[3]['value'], 0.2 * fit.params[4]['value']), fit.function
示例5: makeHFSGraph
# 需要导入模块: from fitter import Fitter [as 别名]
# 或者: from fitter.Fitter import setParamLimits [as 别名]
def makeHFSGraph(name, xmin, xmax):
ch2 = OPData.fromPath('../data/part2/04.16/%s.tab' % name, 2)
ch2.filterX(xmin, xmax)
deltaY = 0.05
c = TCanvas('c-%s' % name, '', 1280, 720)
g2 = ch2.makeGraph('g2-%s' % name, "Zeit t / s", "Spannung U_{ph} / V")
prepareGraph(g2, 2)
g2.GetXaxis().SetRangeUser(xmin, xmax)
g2.SetMinimum(ch2.getMinY() - deltaY)
g2.SetMaximum(ch2.getMaxY() + deltaY)
g2.Draw('APX')
fitStartParams = getHFSFitStartParams(name)
fitres = []
tablefitres = []
tablepeakcount = 0
legendInfo = []
isUp = name[:2] == 'up'
if fitStartParams:
print('got start params, starting to building fit functions')
peakNum = 0
offset = ch2.getY()[0] # approx offset of underground
slope = (ch2.getY()[-1] - ch2.getY()[0]) / (xmax - xmin) # approx slope of underground
for peakparams, xstartend in fitStartParams:
xstart, xend = xstartend
peakcount = len(peakparams)
print('peakNum: ', peakNum)
fitfunc = 'pol1(0)+gaus(2)'
dpc = 2 # delta param count
for i in range(1, peakcount):
fitfunc += '+gaus(%d)' % (i * 3 + dpc)
fit = Fitter('fitHFS%s_%d' % (name, peakNum), fitfunc)
fit.function.SetLineColor(getRootColor(peakNum))
fit.setParam(0, 'a', offset)
fit.setParamLimits(0, 0, offset * 2)
fit.setParam(1, 'b', slope)
if isUp:
fit.setParamLimits(1, 0, 2 * slope)
else:
fit.setParamLimits(1, 2 * slope, 0)
for i, params in enumerate(peakparams):
fit.setParam(i * 3 + dpc, 'A%d' % i, params[0])
fit.setParam(i * 3 + dpc + 1, 'c%d' % i, params[1])
fit.setParam(i * 3 + dpc + 2, 's%d' % i, params[2])
if params[0] < 0:
fit.setParamLimits(i * 3 + dpc, 3 * params[0], 0)
else:
fit.setParamLimits(i * 3 + dpc, 0, 2 * params[0])
fit.setParamLimits(i * 3 + dpc + 1, params[1] - 2 * params[2], params[1] + 2 * params[2])
fit.setParamLimits(i * 3 + dpc + 2, 0, 20 * params[2])
fit.fit(g2, xstart, xend, 'M+')
fit.saveData('../fit/part2/%s-%d.txt' % (name, peakNum))
legendpeaks = []
for i in range(len(peakparams)):
fitres.append((fit.params[i * 3 + dpc + 1]['value'], 0.2 * fit.params[i * 3 + dpc + 2]['value']))
tablepeakcount += 1
legendpeaks.append(tablepeakcount)
tablefitres.append((tablepeakcount, fit.params[i * 3 + dpc + 1]['value'] * 1e3, fit.params[i * 3 + dpc + 1]['error'] * 1e3,
fit.params[i * 3 + dpc + 2]['value'] * 1e6, fit.params[i * 3 + dpc + 2]['error'] * 1e6))
legendInfo.append((fit.function, tuple(legendpeaks)))
peakNum += 1
tablename = 'up' if isUp else 'down'
with TxtFile('../src/tab_part2_hfspeaks_%s.tex' % tablename, 'w') as f:
f.write2DArrayToLatexTable(tablefitres,
['Peak $i$', r'$\mu_i$ / ms', r'$s_{\mu_i}$ / ms', r'$\sigma_i$ / \textmu s', r'$s_{\sigma_i}$ / \textmu s'],
['%d', '%.5f', '%.5f', '%.1f', '%.1f'],
r"Erwartungswerte $\mu_i$ und Standardabweichungen $\sigma_i$ der gefitteten Peaks des HFS-Spektrums.",
"tab:hfs:peaks:%s" % tablename)
g2.Draw('P')
if isUp:
l = TLegend(0.725, 0.15, 0.99, 0.45)
else:
l = TLegend(0.725, 0.55, 0.99, 0.85)
l.SetTextSize(0.03)
l.AddEntry(g2, 'Photodiodenspannung U_{ph}', 'l')
for fitfunc, legendpeaks in legendInfo:
n = len(legendpeaks)
if n == 1:
lstring = '%d' % legendpeaks
elif n == 2:
lstring = '%d und %d' % legendpeaks
elif n == 3:
lstring = '%d, %d und %d' % legendpeaks
l.AddEntry(fitfunc, "Fit von Peak %s" % lstring, 'l')
l.Draw()
c.Update()
if not DEBUG:
c.Print('../img/part2/%s_fit.pdf' % name, 'pdf')
return fitres