diff --git a/src/peakstats.jl b/src/peakstats.jl index edcd4d3..4c625dc 100644 --- a/src/peakstats.jl +++ b/src/peakstats.jl @@ -1,5 +1,5 @@ """ - estimate_single_peak_stats(h::Histogram,; calib_type::Symbol=:th228) + estimate_single_peak_stats(h::Histogram; calib_type::Symbol=:th228) Estimate statistics/parameters for a single peak in the given histogram `h`. @@ -38,29 +38,7 @@ function estimate_single_peak_stats(args...; calib_type::Symbol=:th228) end export estimate_single_peak_stats -""" - estimate_single_peak_stats_th228(h::Histogram{T}) where T<:Real - -Estimate statistics/parameters for a single peak in the given histogram `h` for Th228 calibration. - -# Arguments - * 'h': Histogram data - -# Returns -`NamedTuple` with the fields - * `peak_pos`: estimated position of the peak (in the middle of the peak) - * `peak_fwhm`: full width at half maximum (FWHM) of the peak - * `peak_sigma`: estimated standard deviation of the peak - * `peak_counts`: estimated number of counts in the peak - * `mean_background`: estimated mean background value - * 'mean_background_step': estimated mean background step value - * 'mean_background_std': estimated mean background standard deviation -""" - -function estimate_single_peak_stats_th228(h::Histogram{T}) where T<:Real - W = h.weights - E = first(h.edges) - bin_width = step(E) +function _get_hist_peakpos_fwhm(E::AbstractVector, W::Vector{<:Real}) peak_amplitude, peak_idx = findmax(W) fwhm_idx_left = findfirst(w -> w >= (first(W) + peak_amplitude) / 2, W) fwhm_idx_right = findlast(w -> w >= (last(W) + peak_amplitude) / 2, W) @@ -96,6 +74,25 @@ function estimate_single_peak_stats_th228(e::Vector{<:Real}, bin_width::Real) estimate_single_peak_stats_th228(h) end + +""" + estimate_single_peak_stats_th228(h::Histogram{T}) where T<:Real + +Estimate statistics/parameters for a single peak in the given histogram `h` for Th228 calibration. + +# Arguments + * 'h': Histogram data + +# Returns +`NamedTuple` with the fields + * `peak_pos`: estimated position of the peak (in the middle of the peak) + * `peak_fwhm`: full width at half maximum (FWHM) of the peak + * `peak_sigma`: estimated standard deviation of the peak + * `peak_counts`: estimated number of counts in the peak + * `mean_background`: estimated mean background value + * 'mean_background_step': estimated mean background step value + * 'mean_background_std': estimated mean background standard deviation +""" function estimate_single_peak_stats_th228(h::Histogram{T}) where T<:Real W = h.weights E = first(h.edges) diff --git a/src/pseudo_prior.jl b/src/pseudo_prior.jl index 44bbdc0..f9311f4 100644 --- a/src/pseudo_prior.jl +++ b/src/pseudo_prior.jl @@ -1,6 +1,6 @@ """ - get_standard_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :mean_background, :mean_background_step, :mean_background_std), NTuple{7, T}}, fit_func::Symbol; low_e_tail::Bool=true, fixed_position::Bool=false) where T<:Real + get_standard_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :bin_width, :mean_background, :mean_background_step, :mean_background_std), NTuple{8, T}}, fit_func::Symbol; low_e_tail::Bool=true, fixed_position::Bool=false) where T<:Real Gets standard pseudo prior of given histogram. @@ -17,8 +17,11 @@ Gets standard pseudo prior of given histogram. TO DO: function description and arguments. """ - -function get_standard_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :mean_background, :mean_background_step, :mean_background_std), NTuple{7, T}}, fit_func::Symbol; low_e_tail::Bool=true, fixed_position::Bool=false) where T<:Real +function get_standard_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :bin_width, :mean_background, :mean_background_step, :mean_background_std), NTuple{8, T}}, fit_func::Symbol; low_e_tail::Bool=true, fixed_position::Bool=false) where T<:Real + # base priors common with all functions + window_left = ps.peak_pos - minimum(h.edges[1]) + window_right = maximum(h.edges[1]) - ps.peak_pos + # base priors common with all functions pprior_base = NamedTupleDist( μ = ifelse(fixed_position, ConstValueDist(ps.peak_pos), Normal(ps.peak_pos, 0.2*ps.peak_sigma)), σ = weibull_from_mx(ps.peak_sigma, 1.5*ps.peak_sigma), @@ -55,7 +58,7 @@ function get_standard_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :pea end """ - get_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :mean_background, :mean_background_step, :mean_background_std), NTuple{7, T}}, fit_func::Symbol; pseudo_prior::NamedTupleDist=NamedTupleDist(empty = true), kwargs...) where T<:Real + get_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :bin_width, :mean_background, :mean_background_step, :mean_background_std), NTuple{8, T}}, fit_func::Symbol; pseudo_prior::NamedTupleDist=NamedTupleDist(empty = true), kwargs...) where T<:Real Gets the pseudo prior of the histogram, which is @@ -73,7 +76,7 @@ Gets the pseudo prior of the histogram, which is TO DO: check argument descriptions and returns. """ -function get_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :mean_background, :mean_background_step, :mean_background_std), NTuple{7, T}}, fit_func::Symbol; pseudo_prior::NamedTupleDist=NamedTupleDist(empty = true), kwargs...) where T<:Real +function get_pseudo_prior(h::Histogram, ps::NamedTuple{(:peak_pos, :peak_fwhm, :peak_sigma, :peak_counts, :bin_width, :mean_background, :mean_background_step, :mean_background_std), NTuple{8, T}}, fit_func::Symbol; pseudo_prior::NamedTupleDist=NamedTupleDist(empty = true), kwargs...) where T<:Real standard_pseudo_prior = get_standard_pseudo_prior(h, ps, fit_func; kwargs...) # use standard priors in case of no overwrites given if !(:empty in keys(pseudo_prior)) diff --git a/src/utils.jl b/src/utils.jl index 281d2ed..14adb63 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -141,7 +141,7 @@ Return the bin width for the given data `x` using the Friedman-Diaconis rule. # Arguments * 'x': Given data """ -function get_friedman_diaconis_bin_width end # DELETE? +function get_friedman_diaconis_bin_width end function get_friedman_diaconis_bin_width(x::Vector{<:Real}) 2 * (quantile(x, 0.75) - quantile(x, 0.25)) / ∛(length(x))