API
Types
Functions
RadiationSpectra._interpolate_linearRadiationSpectra.calibrate_spectrumRadiationSpectra.determine_calibration_constant_through_peak_ratiosRadiationSpectra.get_example_spectrumRadiationSpectra.opt_fitRadiationSpectra.opt_fitRadiationSpectra.peakfinder
Documentation
RadiationSpectra._interpolate_linear — Method
_interpolate_linear(point1::Tuple{Real, Real}, point2::Tuple{Real, Real}; threshold::Real = 0.5)Interpolate a point between two points point1 and point2 using a linear interpolation.
RadiationSpectra.calibrate_spectrum — Method
calibrate_spectrum(h_uncal::Histogram, photon_lines::Vector{<:Real}; kwargs...)Calibrate the spectrum h_uncal with energy = c * position. Peaks are found with peakfinder and matched to the reference lines photon_lines through the ratios of their positions, then c is refined from the positions of Gaussian peaks on a linear background fitted to the matched lines.
Returns (h_cal, h_deconv, peak_positions, threshold, c, c_precal): the calibrated histogram, the deconvolved spectrum, the raw peak-finder positions at the selected threshold (strongest first), that threshold, the fitted calibration constant and its estimate from the peak ratios.
Keywords
σ::Real = 3.0: expected standard deviation of the peaks in bins.threshold::Real = 50.0: initial peak-finder threshold in percent, in(0, 100). It is lowered by a quarter per step and finally to 0.5 to find weaker peaks.min_n_peaks::Int: minimum number of peaks the peak finder has to report, at least 2. Defaults to 2 for two reference lines, 3 for three or four, and 4 for more. Also caps the defaultmin_n_matches.max_n_peaks::Int = 4 * length(photon_lines): only the strongestmax_n_peakspeaks (after the shape filter of two-match searches) take part in the matching. Must be at leastmin_n_matchesand does not truncate the returned positions.min_n_matches::Int: minimum number of reference lines that must be matched, at least 2. Defaults to the same values asmin_n_peaks, capped by it.min_match_span::Real = min_n_matches <= 2 ? 0.0 : 0.5: minimum energy range of the matched lines as a fraction of the range ofphoton_lines, in[0, 1].α::Real = 0.01: relative tolerance when comparing the ratio of two peak positions with the ratio of two reference lines.rtol::Real = 5e-3: maximum relative residualabs(c * position - line) / lineof a matched peak, in[0, 1). Keep it small to tell nearby lines apart.
Of the solutions found, the one with the most matched lines wins, then the one found at the highest threshold, then the one with the smallest residuals. With more than two required matches, a competing gain with comparable support at the selected threshold raises an error. Two-match searches stop at the first threshold at which the shape-filtered peaks yield a solution, with all peaks of that threshold competing for the gain, and fall back to all peaks of every threshold if the filtered peaks never yield one. Lines missing from the spectrum are tolerated as long as min_n_peaks, min_n_matches and min_match_span are met, so lower min_match_span when the lines expected in the spectrum cover only a small part of the range of photon_lines.
RadiationSpectra.determine_calibration_constant_through_peak_ratios — Method
determine_calibration_constant_through_peak_ratios(h::Histogram, photon_lines; kwargs...)Estimate the calibration constant c in energy = c * position from the ratios of the peak positions in h and of the reference lines photon_lines.
Returns (c, h_deconv, peak_positions, threshold): the calibration constant, the deconvolved spectrum, the raw peak-finder positions at the selected threshold (strongest first) and that threshold. Takes the keyword arguments of calibrate_spectrum, except that threshold defaults to 10 and max_n_peaks to 5 * length(photon_lines).
RadiationSpectra.get_example_spectrum — Method
get_example_spectrum()::HistogramReturns an uncalibrated radiation spectrum for testing and demonstrating purpose.
RadiationSpectra.opt_fit — Function
# opt_fit(DT::Type{<:UvSpectrumDensity}, h::Histogram{<:Any, 1},
p0::NamedTuple, lower_bounds::NamedTuple, upper_bounds::NamedTuple)Maximum Likelihood Estimation Fit of model density d on the histogram h.
RadiationSpectra.opt_fit — Function
# opt_fit(DT::Type{<:UvSpectrumDensity}, h::Histogram{<:Any, 1},
p0::AbstractVector, lower_bounds::AbstractVector, upper_bounds::AbstractVector)Maximum Likelihood Estimation Fit of model density d on the histogram h.
RadiationSpectra.peakfinder — Method
peakfinder(h::Histogram; <keyword arguments>)::Tuple{Histogram, Array{Float64, 1}}Returns a deconvoluted spectrum and an array of peak positions.
Keywords
σ::Real=2.0: The expected sigma of a peak in the spectrum. In units of bins.threshold::Real=10.0: Threshold for being identified as a peak in the deconvoluted spectrum. A single bin is identified as a peak when its weight exceeds thethresholdand the previous bin was not identified as an peak.backgroundRemove::Bool=truedeconIterations::Int=3markov::Bool=trueaverWindow::Int=3
Source
This function is basically a copy of TSpectrum::SearchHighRes from ROOT.
- M.A. Mariscotti: A method for identification of peaks in the presence of background and its application to spectrum analysis. NIM 50 (1967), 309-320.
- M. Morhac;, J. Kliman, V. Matouoek, M. Veselsky, I. Turzo.:Identification of peaks in multidimensional coincidence gamma-ray spectra. NIM, A443 (2000) 108-125.
- Z.K. Silagadze, A new algorithm for automatic photopeak searches. NIM A 376 (1996), 451.