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

- A set of one or more observed spectra with background measurements where available
- The corresponding instrumental responses
- A set of model spectra

- Choose a parameterized model which is thought to represent the actual spectrum of the source.
- Choose values for the model parameters.
- Based on the parameter values given, predict the count spectrum that would be detected by the spectrometer in a given channel for such a model.
- Compare the predicted spectrum to the spectrum actually obtained by the instrument.
- Manipulate the values of the parameters of the model until the best fit between the theoretical model and the observed data is found.
- Then calculate the ``goodness'' of the fit to determine how well the model explains the observed data, and calculate the confidence intervals for the model's parameters.

This section describes how XSPEC performs these tasks.

**C(I): The Observed Spectrum**

To obtain each observed spectrum, , XSPEC uses two files: the
data (spectrum) file, containing , and the background file,
containing . 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 the set of background-subtracted
spectra C(I) in units of counts per second. The background-subtracted
count rate is given by, for each spectrum:

(2.3) |

where and are the counts in the data and background files; and are the exposure times in the data and background files; and , and are the background and area scaling values from the spectrum and background respectively, which together refer the background flux to the same area as the observation as necessary. When this is done, XSPEC has an observed spectrum to which the model spectrum can be fit.

**R(I,E): The Instrumental Response**

Before XSPEC can take a 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. Recall that for each spectrum the response is proportional to the probability that an incoming photon of energy will be detected in channel . As such, the response is a continuous function of . This continuous function is converted to a discrete function by the creator of a response matrix who defines the energy ranges such that:

(2.4) |

XSPEC reads both the energy ranges, , and the response matrix from a
response file in a compressed format that only stores non-zero
elements. XSPEC also includes an option to use an auxiliary response
file, which contains an array that is multiplied into as follows:

(2.5) |

This array is designed to represent the efficiency of the detector with the response file representing a normalized Redistribution Matrix Function, or RMF. Conventionally, the response is in units of cm.

**M(E): The Model Spectrum**

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

(2.6) |

and is in units of photons/cm/s. XSPEC allows the construction of composite models consisting of additive components representing X-ray sources (e.g., power-laws, blackbodies, and so forth), multiplicative components, which modify additive components by an energy-dependent factor (e.g., photoelectric absorption, edges, ...). Convolution and mixing models can then perform sophisticated operations on the result. Models are defined in algebraic notation.

For example, the following expression:

phabs (power + phabs (bbody))defines an absorbed blackbody, phabs(bbody), added to a power-law, power. The result then is modified by another absorption component, phabs. For a list of available models, see Chapter 6.