diff --git a/simulations/airshower_beacon_simulation/lib/figlib.py b/simulations/airshower_beacon_simulation/lib/figlib.py index 2c53b8c..9bfc25e 100644 --- a/simulations/airshower_beacon_simulation/lib/figlib.py +++ b/simulations/airshower_beacon_simulation/lib/figlib.py @@ -98,6 +98,7 @@ def phase_comparison_figure( def fitted_histogram_figure( amplitudes, fit_distr = None, + calc_chisq = True, text_kwargs={}, hist_kwargs={}, mean_snr = None, @@ -169,6 +170,14 @@ def fitted_histogram_figure( ax.plot(xs, fit_ys*scale, label=label) + chisq_strs = [] + if calc_chisq: + ct = np.diff(distr_func.cdf(bins, *fit_params))*np.sum(counts) + c2t = stats.chisquare(counts, ct, ddof=len(fit_params)) + chisq_strs = [ + f"$\\chi^2$/dof = {c2t[0]: .2g}/{len(fit_params)}" + ] + # change parameters if needed text_fit_params = fit_params2text_params(fit_params) @@ -176,6 +185,8 @@ def fitted_histogram_figure( [label] + [ f"{param} = {value: .2e}" for param, value in zip_longest(param_names, text_fit_params, fillvalue='?') ] + + + chisq_strs ) this_info = { @@ -185,6 +196,10 @@ def fitted_histogram_figure( 'text_str': text_str, } + if chisq_strs: + this_info['chisq'] = c2t[0] + this_info['dof'] = len(fit_params) + fit_info.append(this_info) loc = (0.02, 0.95)