Skip to content

Commit

Permalink
Added missing try/except block
Browse files Browse the repository at this point in the history
Added a try/except block back to plot_lq_cut_fit
  • Loading branch information
erin717 authored May 8, 2024
1 parent a7e3686 commit c25b6e3
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/pygama/pargen/lq_cal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c25b6e3

Please sign in to comment.