Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minuit fixes #3

Merged
2 commits merged into from
Feb 24, 2011
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 18 additions & 6 deletions widgets/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,30 @@ def chi2(params):
m.migrad()

# do some error analysis
chi2.runningFit = False
m.hesse()
m.minos()
try:
chi2.runningFit = False
m.hesse()
m.minos()
have_err = True
except MinuitError as e:
if str(e).startswith('Discovered a new minimum'):
# the initial fit really failed
raise
have_err = False

# print the results
retchi2 = m.fval
dof = len(yvals) - len(params)
redchi2 = retchi2 / dof

print 'Fit results:\n', "\n".join([
u" %s = %g \u00b1 %g (+%g / -%g)"
% (n, m.values[n], m.errors[n], m.merrors[(n, 1.0)], m.merrors[(n, -1.0)]) for n in names])
if have_err:
print 'Fit results:\n', "\n".join([
u" %s = %g \u00b1 %g (+%g / %g)"
% (n, m.values[n], m.errors[n], m.merrors[(n, 1.0)], m.merrors[(n, -1.0)]) for n in names])
else:
print 'Fit results:\n', "\n".join([' %s = %g' % (n, m.values[n]) for n in names])
print 'No error analysis available: fit probably bad'

print "chi^2 = %g, dof = %i, reduced-chi^2 = %g" % (retchi2, dof, redchi2)

vals = m.values
Expand Down