SEE_ALSO

## NAME

fgauss -- Fit a Gaussian.

## USAGE

`fgauss infile`

## DESCRIPTION

This task fits a Gaussian function of the form:

Y = AMPL * EXP -((X-LOCN)**2 / (2*SIGMA**2)) + BASELINE

to two-column data in an ordinary text file.
If the input to this task is the output file from the `fsquares` task,
then Y has the units of the data squared, and X is refoc mirror position.
LOCN is the location of the focus (see the `locn` parameter below).

A plot of the input data and the fitted curve can be generated. It is not necessary to actually fit a curve in order to plot one. If all parameters are held fixed, the curve defined by the parameters given in the par file will be plotted.

The downhill simplex method is used to fit the curve.
The fitting is done by calling the Numerical Recipes AMOEBA subroutine
(renamed "FAMOEB" because of a change in the calling sequence).
See the help for the `fhyper` task for further information.

If you would like to modify the function to be fit or write code for another function, here are the files and routines that depend on the function.

fgauss.x: procedure fgauss This is the task itself. procedure f_4g_save This saves the parameter values (that were determined by the fit) in the task par file. fcsinit.x: procedure f_4g_init This gets the initial values for the parameters, either from the par file or from the data. procedure f_4g_range This gets an estimate of the range of values for each parameter. The range is not intended to be the maximum possible range but rather a guess as to a reasonable range. fcsfunk.x: real procedure fcs_gauss This evaluates the Gaussian at one point. It is called from f_gaus_funk and also by the plotting routine. real procedure f_gaus_funk This is the function to be minimized.

## PARAMETERS

- infile = "" [string]
- Name of input ASCII file. This file contains two columns, the independent variable values and the dependent variable values.

- (init = "data") [string, Allowed values: data | par]
- The initial values for the parameters can be taken either from the par file or estimated from the data. The values of parameters that are to be held fixed are always gotten from the par file.

- (fitlocn = yes) [boolean]
- Fit for the location of focus? Each of the parameters may either be held fixed at the value given in the par file or allowed to vary in order to find the best-fitting curve.

- (locn = 0.) [real]
- Initial estimate of location of focus.
If the location is to be held fixed, the value is taken from this parameter.
If the location is to be allowed to vary, the initial estimate will either
be gotten from the data (if
`init=data`) or from this parameter (if`init=par`). The first guess from the data is simply the X location of the largest Y value.

- (fitampl = yes) [boolean]
- Fit for the amplitude of the Gaussian?

- (ampl = 1.) [real]
- Initial estimate of amplitude. The first guess from the data is the difference between the largest and smallest Y values.

- (fitsigma = yes) [boolean]
- Fit for sigma?

- (sigma = 50.) [real]
- Initial estimate of sigma. The first guess from the data is one quarter of the difference between the largest and smallest X values.

- (fitbase = yes) [boolean]
- Fit for the baseline?

- (baseline = 0.) [real]
- Initial estimate of baseline. The first guess from the data is the smallest Y value.

- (option = "lsq") [string, Allowed values: lsq | minsum]
- The fit may be performed by minimizing the sum of squared deviations
(
`option=lsq`) between the data and the curve or by minimizing the sum of the absolute values of the deviations (`option=minsum`).

- (ftol = 1.e-5) [real]
- Fractional error allowed.
The fit is terminated either when the maximum allowed number of iterations
(currently 500) is reached or when the fractional error is less than
`ftol`. The fit is performed by minimizing a function, e.g., sum of squared deviations. The function is evaluated at the vertices of a simplex, and the fractional tolerance is ABS (YHIGH - YLOW) / ((ABS (YHIGH) + ABS (YLOW)) / 2.), where YHIGH and YLOW are the maximum and minimum values.

- (logfile = "") [string]
- Name of output file for info about fit.
A file will be created with this name (if it's not null) and information
will be written to it giving some details about the fit.
The values of the variable parameters (but not the fixed parameters)
and the value of the function to be minimized will be written to the file
for each vertex of the simplex.
These are written before each of the two calls to the amoeba routine,
i.e., for the initial estimates of the parameters and also after a minimum
has been found.
In each case the first line gives the parameter values (and function value)
for the vertex containing the current estimates of the parameters,
while the other lines give values for the other vertices,
which are the same except for one parameter at each vertex.
The number of iterations for each call to the amoeba routine is printed.
A line is also printed giving the final values of the variable parameters and
the value of the function to be minimized.
If the data and fitted curve are to be plotted (see the description of the

`device`parameter), the screen will be cleared after writing to the log file, so if`logfile="STDOUT"`the information will be lost.

- (title) [string]
- A title for the plot may be given with this parameter.

- (xlabel = "refoc position") [string]
- This is used as a label for the X axis.

- (ylabel = "sharpness") [string]
- This is used as a label for the Y axis.

- (xmin = -5.) [real]
- The plot range in X may be specified with
`xmin`and`xmax`. If either or both is INDEF then the plot limits will be determined by the input data.

- (xmax = 235.) [real]
- See
`xmin`.

- (device = "stdgraph") [string]
- Name of graphics device.
This parameter may be set to "stdgraph" or "stdplot" to plot the input
data and the fitted curve.
If device="" no plot will be generated.
If all the flags (i.e.,
`fitlocn`,`fitampl`,`fitsigma`,`fitbase`) are set to "no", a plot can still be made which will show the curve calculated with the parameters (`locn`,`ampl`,`sigma`,`baseline`) specified in the par file.

## EXAMPLES

## BUGS

## REFERENCES

This task was written by Phil Hodge. A slightly modified version of the Numerical Recipes AMOEBA subroutine is used to do the fit. Numerical Recipes was written by W.H. Press, B.P. Flannery, S.A. Teukolsky, and W.T. Vetterling.