Skip to content

Commit

Permalink
add check for energy res and increase bin width
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmarshall committed Apr 1, 2024
1 parent d138b30 commit 93381ca
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pygama/pargen/energy_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ def get_fwhms(self):
@staticmethod
def fit_energy_res_curve(fwhm_func, fwhm_peaks, fwhms, dfwhms):
try:
if len(fwhm_peaks) == 0:
raise RuntimeError
c_lin = cost.LeastSquares(fwhm_peaks, fwhms, dfwhms, fwhm_func.func)
# c_lin.loss = "soft_l1"
m = Minuit(c_lin, *fwhm_func.guess(fwhm_peaks, fwhms, dfwhms))
Expand Down Expand Up @@ -1192,7 +1194,7 @@ def fit_energy_res_curve(fwhm_func, fwhm_peaks, fwhms, dfwhms):
+ f"| {fwhm:.2f}+-{fwhme:.2f} ".ljust(5)
+ f"| {fwhm_func.func(peak, *results['parameters']):.2f}".ljust(5)
)
except RuntimeError:
except ValueError:
pars, errs, cov = return_nans(fwhm_func.func)
results = {
"function": fwhm_func,
Expand Down Expand Up @@ -1836,7 +1838,7 @@ def get_hpge_energy_peak_par_guess(
_, init_sigma, _ = pgh.get_gaussian_guess(init_hist, init_bins)
except IndexError:
init_sigma = np.nanstd(energy)
bin_width = (init_sigma) * len(energy) ** (-1 / 3)
bin_width = 2 * (init_sigma) * len(energy) ** (-1 / 3)

hist, bins, var = pgh.get_hist(energy, dx=bin_width, range=fit_range)

Expand Down Expand Up @@ -2096,7 +2098,7 @@ def unbinned_staged_energy_fit(
_, init_sigma, _ = pgh.get_gaussian_guess(init_hist, init_bins)
except IndexError:
init_sigma = np.nanstd(energy)
bin_width = (init_sigma) * len(energy) ** (-1 / 3)
bin_width = 2 * (init_sigma) * len(energy) ** (-1 / 3)

gof_hist, gof_bins, gof_var = pgh.get_hist(energy, range=gof_range, dx=bin_width)

Expand Down

0 comments on commit 93381ca

Please sign in to comment.