Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated docstrings #80

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

Updated docstrings #80

wants to merge 2 commits into from

Conversation

apearsonn
Copy link

@apearsonn apearsonn commented Oct 16, 2024

Updated docstrings in the following format:

"""
function()
Description of function.
 Arguments
- 'x'
- 'y'
- 'z'

 Keywords
- 'x'

 Returns
- 'x'

"""

There are still functions that need arguments, keywords, returns or a description added. All of the missing descriptions are found in this Google Doc.
https://docs.google.com/document/d/1-clJFUV2ZZ8kklChEZ_7bfOK89VDA-6_WGYy7SodkRs/edit?usp=sharing

@theHenks theHenks self-requested a review October 16, 2024 12:13
@theHenks theHenks added the documentation Improvements or additions to documentation label Oct 16, 2024
src/peakstats.jl Outdated
@@ -28,7 +38,29 @@ function estimate_single_peak_stats(args...; calib_type::Symbol=:th228)
end
export estimate_single_peak_stats

function _get_hist_peakpos_fwhm(E::AbstractVector, W::Vector{<:Real})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolving the merge conflicts, something went wrong here.
_get_hist_peakpos_fwhm disappeared..

Copy link
Contributor

@fhagemann fhagemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR seems to (re)introduce two functions (not sure if we want them out):
f_optimize_ctc and get_n_after_aoe_cut. Do we need/want them?

Comment on lines 2 to +30
"""
ctc_energy(e::Array{T}, qdrift::Array{T}, peak::T, window::T) where T<:Real
f_optimize_ctc(fct, e, qdrift, bin_width)

Calculate the ratio of the FWHM and the peak height of the peak around `peak` in
`e` with a cut window of `window`. The drift time dependence is given by
`e_ctc` = `e` + `fct` * `qdrift`.

# Arguments
* 'fct': Correction factor
* 'e': Calibrated energies
* 'qdrift': Charge drift
* 'bin_width': Width of histogram bins

# Returns
* `fwhm / p_height`: FWHM of the peak divided by peak height
"""
function f_optimize_ctc(fct, e, qdrift, bin_width)
# calculate drift time corrected energy
e_ctc = e .+ fct .* qdrift
# fit peak
h = fit(Histogram, e_ctc, minimum(e_ctc):bin_width:maximum(e_ctc))
ps = estimate_single_peak_stats(h)
result_peak, report_peak = fit_single_peak_th228(h, ps; uncertainty=false)
# get fwhm and peak height
fwhm = mvalue(result_peak.fwhm)
p_height = maximum(report_peak.f_fit.(mvalue(result_peak.μ-0.2*result_peak.σ):0.01:mvalue(result_peak.μ+0.2*result_peak.σ)))
# use ratio of fwhm and peak height as optimization functional
return log(fwhm/p_height)
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is (re)introduced: f_optimize_ctc

Comment on lines +39 to +77
"""
get_n_after_aoe_cut(aoe_cut::Unitful.RealOrRealQuantity, aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, bin_width::T, result_before::NamedTuple, peakstats::NamedTuple; uncertainty::Bool=true, fixed_position::Bool=true) where T<:Unitful.Energy{<:Real}

Get the number of counts after a AoE cut value `aoe_cut` for a given `peak` and `window` size while performing a peak fit with fixed position. The number of counts is determined by fitting the peak with a pseudo prior for the peak position.

# Arguments
* 'aoe_cut': A/E cut value
* 'aoe': A/E
* 'e': Calibrated energies
* 'peak': Data peak
* 'window': histogram window size of counts used
* 'bin_width': Histogram bin widths
* 'result_before':
* 'peakstats': Peak statistics

# Keywords
* 'uncertainty': Data uncertainty
* 'fixed_position': Position of peak

# Returns
* `n`: Number of counts after the cut

"""
function get_n_after_aoe_cut(aoe_cut::Unitful.RealOrRealQuantity, aoe::Vector{<:Unitful.RealOrRealQuantity}, e::Vector{<:T}, peak::T, window::Vector{T}, bin_width::T, result_before::NamedTuple, peakstats::NamedTuple; uncertainty::Bool=true, fixed_position::Bool=true) where T<:Unitful.Energy{<:Real}
# get energy after cut and create histogram
peakhist = fit(Histogram, ustrip.(e[aoe .> aoe_cut]), ustrip(peak-first(window):bin_width:peak+last(window)))
# create pseudo_prior with known peak sigma in signal for more stable fit
pseudo_prior = if fixed_position
NamedTupleDist(σ = Normal(result_before.σ, 0.1), μ = ConstValueDist(result_before.μ))
else
NamedTupleDist(σ = Normal(result_before.σ, 0.1), )
end
# fit peak and return number of signal counts
result, _ = fit_single_peak_th228(peakhist, peakstats,; uncertainty=uncertainty, low_e_tail=false, pseudo_prior=pseudo_prior)
return result.n
end
export get_n_after_aoe_cut


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is (re)introduced: get_n_after_aoe_cut

@fhagemann
Copy link
Contributor

The failing tests seem to be unrelated (can we fix that??)

Copy link

codecov bot commented Nov 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 18 lines in your changes missing coverage. Please review.

Please upload report for BASE (dev@2575f47). Learn more about missing BASE report.
Report is 8 commits behind head on dev.

Files with missing lines Patch % Lines
src/ctc.jl 0.00% 8 Missing ⚠️
src/aoe_cut.jl 0.00% 7 Missing ⚠️
src/peakshapes.jl 0.00% 3 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff           @@
##             dev      #80   +/-   ##
======================================
  Coverage       ?   21.52%           
======================================
  Files          ?       33           
  Lines          ?     2983           
  Branches       ?        0           
======================================
  Hits           ?      642           
  Misses         ?     2341           
  Partials       ?        0           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants