Skip to content

Commit

Permalink
Revert solving merge conflicts modifying functions
Browse files Browse the repository at this point in the history
  • Loading branch information
fhagemann committed Oct 30, 2024
1 parent c001e7b commit 23f104a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 30 deletions.
45 changes: 21 additions & 24 deletions src/peakstats.jl
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 8 additions & 5 deletions src/pseudo_prior.jl
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 23f104a

Please sign in to comment.