Fit and integration

The quantitative analysis of spectra is interested in position,
volume, or shape of the observed lines. It must comprise a proper
description of the background. Since the background has a more global
structure whereas the lines in a gamma spectrum are local structures
the former can be usually approximated by a polynom, e.g. a straight
line. In contrast, particle spectra contain very broad lines.
Therefore it is neccessary to use a more physical description of the
background which is provided by an exponential term beside the polynom
(see fit function background definition). This background function may
be useful in the upper part of a Ge-Detector spectrum too since the
exponential term reproduces approximately the detector efficiency.

For the further analysis of the lines three methods are available:

* integration

* peaksearch

* decomposition by a fit

The results of peaksearch and fit for each spectrum are merged into
the peaklist (see peaklist). Here all fitted peaks are displayed
whereas peaks found by the peaksearch are only shown when they are not
situated in any fitted region.


Integration

The main advantage of integration is that no hypothesis on the line
shape is neccessary. @emph{tv} calculates volume, center of mass,
width (corrected by a factor 2*sqrt(2*ln(2)) to obtain the FWHM), and
skewness. If there exists a valid background fit @emph{tv} takes this
into account and calculates background corrected values too. If
background regions are defined but not fitted @emph{tv} determines the
mean background amplitude and uses this for background correction.
The integration results depend increasingly from volume to skewness on
a good description of the background. Applications for the integration
are gamma spectra where line shapes are not well determined, or time
spectra where the assymmetry (skewness) can be used for life time
analysis.

The main disadvantage of integration is that only well separated lines
can be evaluated in this way. Otherwise it is neccessary to make
asumptions on the line shape and to use a fit for decomposition of the
overlapping lines. Furthermore it is connected with some effort to
integrate a larger number of lines.


Peaksearch

To obtain easily a survey of the lines in a spectrum @emph{tv}
supplies an automatic peaksearch. As fit function a simple gaussian
with a constant background is used, where the width of the gaussian
must be determined by a width calibration. A simple algorithm fits the
two amplitudes of gaussian and background at each channel. Then the
probability integral is evaluated if it exceeds a given limit (default
99.99 %). In this case the position is iterated to a precision of 1/10
channel and the peak is added to a list. A typical application for the
peak search was the analysis of gate spectra created from a matrix.
Meanwhile the high peak density even in these spectra normally leads
to huge numbers of multipletts. Therefore each result must be checked
if it is a multiplett in which case a decomposition by a fit must be
done. Since the fit function of the peak search is only a crude
approximation and facing the effort of the result checking it is
recommendable to invest this effort directly in an analysis of the
spectrum by fitting.

The peaksearch takes place in the region defined by the peaksearch
markers or these are not set in the whole spectrum.


Decomposition by a fit

For the decomposition of multipletts or the determination of line
shape parameters only a fit can be used. For these goals an adequate
description of the observed line shapes is neccessary. Otherwise it is
impossible to find the correct number of overlapping lines respectivly
to obtain a good description of the spectrum. @emph{tv} uses currently
a modified gaussian with left tail, right tail, and an underlying
step. Parameters are position, volume, and width (FWHM) of the
gaussian, a left and a right tail parameter, and finally width and
height of the step (see fit function peak definition). These 6
parameters are associated with each fitted peak. To reduce the number
of parameters it is possible to use calibrations for single parameters
or to correlate them, e.g. equal left tails. Step and tail parameters
sometimes can be dropped. The background parameters can be fitted
simultaneously with the peaks or can be fixed in advance by a fit in
separate background regions.

A critical decision is the choice of the optimization procedure for
the parameters. It is assumed that the optimal fit function gives the
expectation value for the contents of each fitted channel. Since the
measured contents follow some probability distribution for each
channel the probability of the measured value with respect to the
expected function value is known. For a certain set of parameters a
total probability can be calculated as product of these channel
probabilities. The optimal set of parameter is assumed to be most
likely. It can be obtained by searching the maximum of this
probability product in dependence of the free parameters (maximum
likelihood).

Normally a Gaussian distribution is assumed for the channel contents.
In this case maximum likelihood is equivalent to the commonly used
chi-square minimization (see fit measure definition dy-chi-square).
Unfortunately this is @strong{not} applicable if the expectation
values for the contents of single channels are of the order of 1. In
this case the contents follow only a Poisson distribution. The
resulting problem is evident since apparently the fit function
systematically underestimates the contents of the spectrum. This
depends not on the integral of the fitted data but only on the
amplitudes, i.e. it does not matter how large the fitted region is.

To overcome this defect in @emph{tv} beside the chi-square
minimization furthermore the maximization of a Poisson distribution is
implemented (see fit measure definition poisson). Which leads always
to correct results as long as it deals with simply incremented or
added spectra. For subtraction or normalization the variance of
Poisson distributed data is no longer well defined. Therefore in
subtracted or normalized spectra this optimization method is
@strong{not} applicable. In contrast the for Gaussian distributed data
these operations are possible.

Summarizing, the advantage of maximizing the Poisson distribution is
the validity of the results even for low statistics, the advantage of
the chi-square minimization lies in the applicability to spectra which
have been subject to more complex modifications. But at least none of
both gives correct results if one for example subtracts low statistics
gate spectra.

\section fit function background definition

There are two alternative functions to approximate the background:

* fit function background definition polynom

* fit function background definition exponential

The background in a gamma spectrum has a more global structure in
comparison to the lines. It usually can be described by a polynom,
e.g. a straight line. Since particle spectra contain very broad lines
a polynomial approximation of the background is not sufficient.  A
more physical description of the background is provided by an
exponential term beside the polynom. This extended background function
may be useful in the upper part of a Ge-Detector spectrum too where
the exponential term reproduces approximately the detector efficiency.

\?section fit function background definition polynom
definition of background function as simple polynom

  BG(x)= SUM(n=0..degree, Bn * (x-x0)**n)
    Bn  :  background coefficient (parameter)
    x0  :  offset for numerical optimization during fit

\?section fit function background definition exponential
definition of background function with polynom and exponential

  BG(x)= SUM(n=0..degree, Bn * (x-x0)**n)
         + FAC * exp(-(x-x0) * EXP
    Bn  :  background coefficient (parameter)
    x0  :  offset for numerical optimization during fit
    FAC :  factor of exponential term
    EXP :  scaling of exponential term

\section fit function peak definition

There are two alternative parametrizations for the peaks:

* fit function definition continuous-exp-tail/arctan-step

* fit function definition additive-tail/erf-step

Both have proven to yield comparable results.  The latter reduces the
correlation between step and tails since the erf step approximates the
asymptotic value quite fast in comparison with the arctan. Furthermore
the step width of the erf can be fixed to 1.0 (in units of sigma)
which reduces the number of parameters by one.  Finally the latter
function is analytically integrable whereas the integration of the
former has to be done numerical.

In both functions the volume but not the amplitude of the peaks is
fitted. The volume is the parameter of interest normally and in this
way it is not neccessary to integrate the resulting function and to
estimate the error bars of the obtained volume.


\?section fit function definition continuous-exp-tail/arctan-step

  F(x) =  BG(x) + SUM(i=0..peaknumber, PEAKi(x))
  BG(x)   : background function (see fit function background definition)

peak function of i-th peak
  PEAKi(x)= Vi / NORMi * (GAUSMi(x-Pi) + STEPi(x-Pi))
    Pi    :  position of i-th peak (parameter)
    Vi    :  volume of i-th peak (parameter)
    NORMi :  numeric INTEGRAL(GAUSMi)

modified gauss function of i-th peak
               / exp(SLi / Si**2 * (dx + SLi/2)  for dx<SLi
  GAUSMi(dx)= {  exp(-dx**2 / (2 * Si**2))          for SLi<dx<SRi
               \ exp(-SRi / Si**2 * (dx - SRi/2) for SRi<dx
    Si    :  sigma of gaussian part of i-th peak (parameter)
    SLi   :  TLi * Si**ELi
    SRi   :  TRi * Si**ERi
    TLi   :  left tail of i-th peak (parameter)
    TRi   :  right tail of i-th peak (parameter)
    ELi   :  exponent of sigma-weight of TLi [0..2]
    ERi   :  exponent of sigma-weight of TRi [0..2]

step function of i-th peak
  STEPi(dx)= SHi * (pi/2 + arctan(SWi * dx / (Si * sqrt(2))))
    SHi   :  step height of i-th peak (parameter)
    SWi   :  step width of i-th peak (parameter)


\?section fit function definition additive-tail/erf-step

  F(x) =  BG(x) + SUM(i=0..peaknumber, PEAKi(x))
  BG(x)   : background function (see fit function background definition)

peak function of i-th peak
  PEAKi(x)= Vi / NORMi
            * (  (1 + TAILi(x-Pi)) * GAUSSi(x-Pi)))
               + STEPi(x-Pi)))  )
    Pi    :  position of i-th peak (parameter)
    Vi    :  volume of i-th peak (parameter)
    NORMi :  Si * (SQRT(2 * PI) + TLi + TRi)

gauss function of i-th peak
  GAUSSi(dx)= exp(-dx**2 / (2 * Si**2))
    Si    :  sigma of gaussian part of i-th peak (parameter)

additional tail factor of i-th peak
              / TLi * (|dx| / Si)**ELi / (FACFAC(ELi)  for dx<0
  TAILi(dx)= {
              \ TRi * (|dx| / Si)**ERi / (FACFAC(ERi)  for dx>=0
    TLi   :  left tail of i-th peak (parameter)
    TRi   :  right tail of i-th peak (parameter)
    ELi   :  exponent of left tail [2..16]
    ERi   :  exponent of right tail [2..16]

for simplification of integral
              / (n-1)!!                 for n= 3,5,7,...
  FACFAC(n)= {
              \ (n-1)!! * sqrt(pi / 2)  for n= 2,4,6,...

step function of i-th peak
  STEPi(dx)= 1/2 * SHi * (1 - erf(dx / (SWi * Si * sqrt(2))))
    SHi   :  step height of i-th peak (parameter)
    SWi   :  step width of i-th peak (parameter)
