From ddd441440eb9c222437c440d1788dee6d46c883d Mon Sep 17 00:00:00 2001 From: ggmarshall <72088559+ggmarshall@users.noreply.github.com> Date: Fri, 31 May 2024 18:02:33 +0100 Subject: [PATCH] a/e and energy cal stuff (#585) * add check on fwhm plot nan lims * fix error prop and mean plot --- src/pygama/pargen/AoE_cal.py | 14 ++++++-------- src/pygama/pargen/energy_cal.py | 2 ++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pygama/pargen/AoE_cal.py b/src/pygama/pargen/AoE_cal.py index 8a531d2ee..f166f83d9 100644 --- a/src/pygama/pargen/AoE_cal.py +++ b/src/pygama/pargen/AoE_cal.py @@ -718,10 +718,9 @@ def get_survival_fraction( surv_err = surv_errs["n_sig"] pc_n = ct_n + surv_n - pc_err = np.sqrt(surv_err**2 + ct_err**2) sf = (surv_n / pc_n) * 100 - err = sf * np.sqrt((pc_err / pc_n) ** 2 + (surv_err / surv_n) ** 2) + err = sf * np.sqrt((ct_err / pc_n**2) ** 2 + (surv_err / pc_n**2) ** 2) return sf, err, cut_pars, surv_pars @@ -835,10 +834,9 @@ def compton_sf(cut_param, low_cut_val, high_cut_val=None, mode="greater", dt_mas surv_err = np.sqrt(len(cut_param[mask])) pc_n = ct_n + surv_n - pc_err = np.sqrt(surv_err**2 + ct_err**2) sf = (surv_n / pc_n) * 100 - err = sf * np.sqrt((pc_err / pc_n) ** 2 + (surv_err / surv_n) ** 2) + err = sf * np.sqrt((ct_err / pc_n**2) ** 2 + (surv_err / pc_n**2) ** 2) return { "low_cut": low_cut_val, @@ -1954,8 +1952,8 @@ def plot_aoe_mean_time( datetime.strptime(tstamp, "%Y%m%dT%H%M%SZ") for tstamp in aoe_class.cal_dicts ], - y1=np.array(grouped_means) - 0.2 * np.array(aoe_class.timecorr_df["res"]), - y2=np.array(grouped_means) + 0.2 * np.array(aoe_class.timecorr_df["res"]), + y1=np.array(grouped_means) - 0.2 * np.array(aoe_class.timecorr_df["sigma"]), + y2=np.array(grouped_means) + 0.2 * np.array(aoe_class.timecorr_df["sigma"]), color="green", alpha=0.2, ) @@ -1964,8 +1962,8 @@ def plot_aoe_mean_time( datetime.strptime(tstamp, "%Y%m%dT%H%M%SZ") for tstamp in aoe_class.cal_dicts ], - y1=np.array(grouped_means) - 0.4 * np.array(aoe_class.timecorr_df["res"]), - y2=np.array(grouped_means) + 0.4 * np.array(aoe_class.timecorr_df["res"]), + y1=np.array(grouped_means) - 0.4 * np.array(aoe_class.timecorr_df["sigma"]), + y2=np.array(grouped_means) + 0.4 * np.array(aoe_class.timecorr_df["sigma"]), color="yellow", alpha=0.2, ) diff --git a/src/pygama/pargen/energy_cal.py b/src/pygama/pargen/energy_cal.py index 804a66c66..7f89ed8a6 100644 --- a/src/pygama/pargen/energy_cal.py +++ b/src/pygama/pargen/energy_cal.py @@ -1719,6 +1719,8 @@ def plot_eres_fit(self, data, erange=(200, 2700), figsize=(12, 8), fontsize=12): ax1.plot(qbb_line_vx, qbb_line_vy, lw=1, c="r", ls="--") ax1.set_xlim(erange) + if np.isnan(low_lim): + low_lim = 0 ax1.set_ylim([low_lim, None]) ax1.set_ylabel("FWHM energy resolution (keV)") for _, fwhm_dict in fwhm_dicts.items():