diff --git a/src/pygama/pargen/lq_cal.py b/src/pygama/pargen/lq_cal.py index 1dfe1d865..2593a557f 100644 --- a/src/pygama/pargen/lq_cal.py +++ b/src/pygama/pargen/lq_cal.py @@ -739,43 +739,46 @@ def plot_lq_cut_fit(lq_class, data, figsize=(12, 8), fontsize=12) -> plt.figure: plt.rcParams["figure.figsize"] = figsize plt.rcParams["font.size"] = fontsize fig, (ax1, ax2) = plt.subplots(2, 1) - - hist, bins = lq_class.fit_hist - fit_pars = lq_class.cut_fit_pars - - x_low = bins[0] - x_high = bins[-1] - - ax1.stairs(hist, bins, label="data") - xs = np.linspace(round(bins[0], 3), round(bins[-1], 3), len(bins) - 1) - ls = np.sum(hist) - dx = np.diff(bins) - ax1.plot( - xs, - gaussian.pdf_norm(xs, x_low, x_high, fit_pars[0], fit_pars[1]) * dx * ls, - label="Gaussian Fit", - ) - - # ax1.set_xlabel('LQ') - ax1.set_title("Fit of LQ events in DEP") - ax1.legend() - - bin_centers = (bins[:-1] + bins[1:]) / 2 - reses = ( - hist - - ( + try: + hist, bins = lq_class.fit_hist + fit_pars = lq_class.cut_fit_pars + + x_low = bins[0] + x_high = bins[-1] + + ax1.stairs(hist, bins, label="data") + xs = np.linspace(round(bins[0], 3), round(bins[-1], 3), len(bins) - 1) + ls = np.sum(hist) + dx = np.diff(bins) + ax1.plot( + xs, + gaussian.pdf_norm(xs, x_low, x_high, fit_pars[0], fit_pars[1]) * dx * ls, + label="Gaussian Fit", + ) + + # ax1.set_xlabel('LQ') + ax1.set_title("Fit of LQ events in DEP") + ax1.legend() + + bin_centers = (bins[:-1] + bins[1:]) / 2 + reses = ( + hist + - ( + gaussian.pdf_norm(bin_centers, x_low, x_high, fit_pars[0], fit_pars[1]) + * dx + * ls + ) + ) / ( gaussian.pdf_norm(bin_centers, x_low, x_high, fit_pars[0], fit_pars[1]) * dx * ls ) - ) / ( - gaussian.pdf_norm(bin_centers, x_low, x_high, fit_pars[0], fit_pars[1]) - * dx - * ls - ) - ax2.plot(bin_centers, reses, marker="s", linestyle="") - ax2.set_xlabel("LQ") - ax2.set_ylabel("residuals") + ax2.plot(bin_centers, reses, marker="s", linestyle="") + ax2.set_xlabel("LQ") + ax2.set_ylabel("residuals") + + except Exception: + pass plt.tight_layout() plt.close()