Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/pygama/math/binned_fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def fit_binned(
if isinstance(bounds, dict):
for key, val in bounds.items():
m.limits[key] = val
log.debug(f"Set bound for {key} to {val}")
if fixed is not None:
for fix in fixed:
m.fixed[fix] = True
Expand Down Expand Up @@ -306,6 +307,9 @@ def gauss_mode_width_max(
amp_guess = hist[i_0]
i_0 -= int(np.floor(n_bins / 2))
i_n = i_0 + n_bins
if i_0 < 0 or i_n >= len(hist):
msg = f"Fit range exceeds histogram bounds: i_0={i_0}, i_n={i_n}, hist_len={len(hist)}"
raise ValueError(msg)
width_guess = bin_centers[i_n] - bin_centers[i_0]
vv = None if var is None else var[i_0:i_n]
guess = (mode_guess, width_guess, amp_guess)
Expand All @@ -316,6 +320,11 @@ def gauss_mode_width_max(
vv,
guess=guess,
cost_func=cost_func,
bounds={
"mu": (bins[i_0], bins[i_n + 1]),
"sigma": (0, None),
"a": (0, None),
},
)
if pars[1] < 0:
pars[1] = -pars[1]
Expand Down
Loading