- C(I): The Observed Spectrum
- R(I,E): The Instrumental Response
- f(E): The Model Spectrum
- Fits and Confidence Intervals

To summarize the preceding section, the main components of spectral fitting are as follows:

- 1.
- The observed spectrum (C(I))
- 2.
- The instrumental response (R(I,E))
- 3.
- A model spectrum (f(E))

These components are used in the following manner:

- 1.
- A parameterized model is created that one feels represents the actual spectrum of the source.
- 2.
- One then gives values to the model parameters.
- 3.
- Based on the parameter values given, one predicts the count spectrum that would be detected by the spectrometer in a given channel for such a model.
- 4.
- Then, one compares the predicted spectrum to the spectrum actually obtained by the instrument.
- 5.
- The values of the parameters of the model are manipulated until one finds the best fit between the theoretical model and the observed data.
- 6.
- One then calculates the ``goodness" of the fit to determine how well the model explains the observed data, and calculates the confidence intervals for the model's parameters.

This section describes how XSPEC performs these tasks.

To obtain the observed spectrum (C(I)), for a given observation,
XSPEC uses two files: the data file, and the background file (for
FITS file format see Arnaud, George & Tennant 1992^{2.2}).
The data file tells XSPEC how many total photon counts were detected
by the instrument in a given channel. XSPEC then uses the background file
to derive a background-subtracted C(I) in units of counts per second.
The background is scaled to the data by the ratio of the BACKSCAL
values in the data and background files. It also is scaled for
exposure times (EXPOSURE keyword) and AREASCAL values.
The background-subtracted count rate is given by :

where

When this is done XSPEC has an observed spectrum to which the model spectrum can be fit.

Before XSPEC can take a given set of parameter values and predict the
spectrum that would be detected by a given instrument, XSPEC must know
the specific characteristics of the instrument. This information is
known as the **detector response**. The response (R(I,E)), if you
recall, is proportional to the probability that an incoming photon of
energy E will be detected in channel I. As such, the response is a
continuous function of E. This continuous function is converted to a
discrete function by the creator of a **response matrix** who
defines the energy ranges (*E*_{J}) such that:

XSPEC reads both the energy ranges, *E*_{J}, and the response matrix
(*R*_{D}(*I*,*J*)) from a **response file** (for FITS file format see
George et al 1992^{2.3}) in a
compressed format that only stores non-zero
elements. XSPEC also includes an option to use an **auxiliary response file**
(George et al 1992^{2.4}), which contains an array *A*_{D}(*J*) that XSPEC
multiplies into *R*_{D}(*I*,*J*) as follows:

Conventionally, the response is in units of cm

The model spectrum, f(E), is calculated within XSPEC using the energy ranges defined by the response file :

and is in units of photons/cm

defines an absorbed blackbody (phabs (bbody)) added to a power-law (power). The result then is modified by another absorption component (phabs).

For a more detailed explanation of models, see Chapter 6.

Once data have been read in and a model defined, XSPEC uses a modified Levenberg-Marquardt algorithm (based on CURFIT from Bevington, 1969) to find the best-fit values of the model parameters. The algorithm used is a local one, so the user should be aware that it is possible for the fitting process to get stuck in a local minimum and not find the global best-fit. The process also goes much faster (and is more likely to find the true minimum) if the initial model parameters are set to sensible values.

At the end of a fit, XSPEC will write out the best-fit parameter values, along with estimated confidence intervals. These confidence intervals are one sigma and are calculated from the derivatives of the fit statistic with respect to the model parameters. However, the confidence intervals are not reliable and should be used for indicative purposes only.

XSPEC has a separate command (`error` or `uncertainty`) to derive
confidence intervals for one interesting parameter, which it does by
fixing the parameter of interest at a particular value
and fitting for all the other parameters. New values of the parameter
of interest are chosen until the appropriate delta-statistic value
is obtained. XSPEC uses a bracketing algorithm followed by an
iterative cubic interpolation to find the parameter value at each
end of the confidence interval.

To compute confidence regions for several parameters at a time XSPEC runs a grid on these parameters. XSPEC also will display a contour plot of the confidence regions of any two parameters.