API

Types

Functions

Documentation

RadiationSpectra.FitFunctionType
mutable struct FitFunction{T, ND, NP} <: AbstractFitFunction{T, ND, NP}

T: Precision type

ND: Dimensionality

NP: NP parameters

Fields:

  • model::Function: Function of the fit model.
  • fitranges::NTuple{N, Vector{T}}: Range on which the fit is performed.
  • parameter_names::Vector{Symbol}: Parameters names.
  • fitted_parameters::Vector{T}: Fitted parameters.
  • initial_parameters::Vector{T}: Initial parameters.
source
RadiationSpectra.calibrate_spectrumMethod
calibrate_spectrum(h_uncal::Histogram, photon_lines::Array{Real, 1}; <keyword arguments>)

Returns the calibrated histogram, the deconvoluted spectrum, the found (uncalibrated) peak positions and the final threshold value.

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 the threshold and the previous bin was not identified as an peak.
  • min_n_peaks::Int = 0: If the number of found peaks is smaller than min_n_peaks the functions lowers the parameter threshold until enough peaks are found.
  • max_n_peaks::Int = 50: Use only the first (strongest) max_n_peaks peaks for peak identification.
  • α::Real = 0.005: = 0.5%. Acceptance level in the comparison of the peak position ratios in the peak indentification step. When the difference between the ratio of two found peak positions and the ratio of two photon lines (photon_lines) is smaller than α, the found peaks are identified as the two photon lines.
  • rtol::Real = 5e-3: = 5e-3. Acceptance level for tolerance of the absolute difference between true and found line position.

Calibrate the spectrum h_uncal. This is done by:

  1. finding peaks through devoncolution
  2. identifying them through comparison of the ratios of their positions with the ratios of the known lines
  3. fitting all identified peaks (with a gaussian plus first order polynomial) to get their position more precisely
  4. performe a linear fit (offset forced to 0) of these positions vs the true positions (lines) to get the calibration constant
source
RadiationSpectra.fit_single_peak_histogramMethod
fit_single_peak_histogram(h::StatsBase.Histogram, fitrange::Union{Tuple{T,T}, Missing} = missing; fit_function = :Gauss, weights = missing )::FitFunction{T, 1, NP} where {T <: AbstractFloat, NP}

This method is meant for quick and stable fitting. The estimation of initial parameters is done automatically, this allows and easy fit with just one line of code. The user is expected to pass a histogram containing only one peak or specify corresponding fitrange. The method performs a least square fit with the model specified under fit_function = .... Currently supported are :Gauss (default), :Gauss_pol1, Cauchy.

source
RadiationSpectra.fit_single_peak_histogram_refinedMethod
fit_single_peak_histogram_refined(h::StatsBase.Histogram, fitrange::Union{Tuple{T,T}, Missing} = missing; n_sig = 3.0, fit_function = :Gauss, weights = missing )::FitFunction{T, 1, NP} where {T <: AbstractFloat, NP}

This method is meant for quick and stable fitting. The estimation of initial parameters is done automatically, this allows and easy fit with just one line of code. The user is expected to pass a histogram containing only one peak or specify corresponding fitrange. The method performs a least square fit with the model specified under fit_function = .... Currently supported are :Gauss (default), :Gausspol1, Cauchy. It then fits again using the results of the first fit as initial parameters. The fitrange for the second fit can be customized using the `nsig = ...` keyword.

source
RadiationSpectra.llhfit!Method
llhfit!(fit::FitFunction{T, 1, NP}, h::Histogram)::Nothing where {T <: AbstractFloat, NP}

Performs a log-likelihood fit of the model function fit.model and the initial parameters fit.initial_parameters on the histogram h in the range fit.fitranges[1]. The determined parameters are stored in fit.fitted_parameters.

The likelihood for each individual bin is the Poission distribution.

source
RadiationSpectra.lsqfit!Method
lsqfit!(fit::FitFunction{T, 1, NP}, h::Histogram)::Nothing where {T <: AbstractFloat, NP}

Performs a least square fit with the model fit.model and the initial parameters fit.initial_parameters on the histogram h in the range fit.fitranges[1]. The determined parameters are stored in fit.fitted_parameters.

source
RadiationSpectra.peakfinderMethod
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 the threshold and the previous bin was not identified as an peak.
  • backgroundRemove::Bool=true
  • deconIterations::Int=3
  • markov::Bool=true
  • averWindow::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.
source