(OBSOLETE) Creating NICER Spectra with XSELECT


This tutorial illustrates the process of producing a NICER spectrum. In this tutorial we will assume that you wish to produce PHA spectral files to be used with XSPEC. This thread is now obsolete.

Read this thread if you want to: See obsolete information about creating PHA spectral files from NICER event data

Last update: 2022-10-26


Please note: this thread is obsolete. Please see the Manually Extracting a NICER Spectrum thread for updated information.

NICER scientific analysis ultimately leads to light curve (timing) analysis and spectral analysis. For spectral analysis, the user will create a NICER spectrum and then perform spectral modeling. NICER spectra typically have 1500 bins, and each bin covers 10 eV (see Gain Calibration for more information about NICER spectra details). For all spectral analysis, use the NICER "PI" channel, which is the default.

After running the standard processing pipeline nicerl2, a cleaned, MPU-merged event file is produced. This output product is the "cl" file, and this is the event file which you will use for spectral analysis. We will use the tool "xselect" for spectral extraction. Following this, XSPEC can be used for spectral analysis and modeling.

The tool we use to bin the data is the HEASoft XSELECT package and the output data type is a PHA file. For the purposes of this tutorial we will assume that you wish to make a spectrum from a single, MPU-merged, cleaned event data file from a single OBSID.


This thread assumes you have the following prerequisites:

  • An MPU-mergd, cleaned event file, e.g. ni1234567890_0mpu7_cl.evt (the "cl" file)
  • The HEASoft software package including XSELECT installed (see Setting Up a NICER Analysis Environment thread for more information)

Using XSELECT to Generate Spectra

The process for creating a spectrum from merged, cleaned data is straightforward. In this example we are running XSELECT from a directory which contains the data from OBSID 1010080110, an observation of Cas A. Once XSELECT is called, the process is staright forward. Below is an example:

First, start xselect: prompt> xselect xselect is a data processing environment where you type interactive commands. We will type the commands to extract a spectrum.

If your "cl" file is not in the current directory, you can set the data directory for the file like this. XSEL> set datadir 1010080110/xti/event_cl where 1010080110/xti/event_cl is the observation directory name where the "cl" file is stored. Next, read the events with this statement, XSEL> read event ni1010080110_0mpu7_cl.evt where the file name listed is an example. You would use your actuale "cl" event file name. You may be prompted to change to a new mission name, which you can reply "Y"es to.

Finally, we can extract a spectrum. XSEL> set phaname PI XSEL> extract spectrum The "set phaname" command ensures that the NICER "PI" spectral channel is used, and "PI" is the default. The "extract spectrum" command will extract a spectrum from the event files you have read into xselect, and save it to a temporary file. By default, this temporary spectrum will not be saved and you must manually save it.

Save the extracted spectrum using the command, XSEL> save spectrum myspectrum.pha where myspectrum.pha is the desired name of your spectrum file. While it can be any legal file name, you should use the ".pha" or ".pi" suffix to indicate that it is a spectrum.

You can plot your extracted spectrum within XSELECT:

XSEL> set device /xs XSEL> plot spectrum PLT> log PLT> rescale x 10 1501

where each line of input is:

  • Set the output device to an /xs. If you wish a different device, a list of device options can be found by giving a "?" in place of XTERM.
  • Plot the spectrum in the X window.
  • Set both axes to be logarithmic.
  • Set the x axis range to 10-1501.

The resulting spectrum should look like this:

NICER spectrum of Cas A

Please note that the X-axis is in units of "PI" channel bins (1 bin = 10 eV), so channel 100 = 1.0 keV. For more information on how to use the QDP plotting environment, please see the QDP/PLT User's Guide. For example, you can relabel axes, change from logarithmic to linear, etc. However, please be aware that xselect's plotting environment is not for spectral analysis. It is purely for display purposes.

When you are done plotting, use the EXIT command to exit the plotting environment. PLT> exit

When you are done extracting and examining the spectrum, you can exit XSELECT using the QUIT command. XSEL> quit You may be prompted if you wish to save session files, and you can answer no.

When this process is complete, you will have an output spectrum file (named myspectrum.pha in this example), which you can use for further spectral analysis.


It should be noted that XSELECT is a powerful tool that the user can use to perform many actions on their data. The user, for instance, may wish to use XSELECT to filter their events using the pha_cut parameter to restrict the energy range of the data for light curves. By default, such settings will carry forward to later extractions, which are undesirable.

If a spectrum is then extracted without resetting this parameter, the resulting spectrum will have less than the standard 1501 channels which are present in NICER response matrices. Spectra should always be extracted for the entire range of 1501 channels. Use the XSELECT command CLEAR to remove any pha_cut filters. XSEL> clear pha_cut If you do want to ignore certain energy channels, it is better to do this with the IGNORE command within XSPEC instead.

Next Steps: Response and Background Generation

The process desccribed above produces the XSPEC compatible spectral spectrum file for your event data. In order to perform spectral analysis in XSPEC, one must then also create detector response and background files for that data. Analysis threads for the procedures to generate these files are given here:


  • 2022-06-08 - proofread
  • 2022-04-15 - initial draft
  • 2022-10-20 - marked obsolete