Extraction of MOS spectra from point-like sources taken in timing mode


This thread describes how to extract the spectrum of a point-like source observed with the MOS camera in timing mode using the command line.

Expected Outcome

The final outcome of this thread is the standard suite of spectral products required by spectral analysis packages such as XSPEC:

  • A source+background (commonly referred to as "source") spectrum
  • A background spectrum
  • A redistribution matrix (commonly referred to as a "RMF" file)
  • An effective area vector (commonly referred to as an "ARF" file)

SAS Tasks to Be Used


Useful Links


Last Reviewed: 25 MAY 2023, for SAS v21.0

Last Updated: 27 APRIL 2018




This thread contains a step-by-step recipe to extract MOS spectra of a point-like source observed in Timing mode and to create associated response matrices, starting from a calibrated, concatenated event list (either produced with emproc / emchain or available as PPS product; here it has been assumed that the name of the event file is MOS.fits).

All the analysis steps are performed with single SAS tasks started from the command line to explain the general method of generating spectral products and to show explicitly the usage and setting of task parameters. The users should note that the SAS meta-task xmmselect allows them to interactively define source and background regions (via ds9) and to run backscale on the fly. Especially the xmmselect: Spectral Products generation method creates source and background spectra as well as related ancillary and redistribution files in one go. However, notice that the source extraction region to be used should be standard. Check the Caveats section referring to the treatment of pile-up in timing mode before trying non-standard extraction regions as the ARF generation could not be valid. For example, with the extraction regions illustrated in Fig.1 the use of the xmmselect: Spectral Products generation would be valid.

The method described below follows the command line method. For more details on how to use xmmselect for the generation of EPIC spectra, the reader is referred to the User Guide to the XMM-Newton Science Analysis System.

  1. Set up your SAS environment (following the SAS Startup Thread)

  2. If necessary, create a MOS cleaned and filtered for particle background event file for your observation (see the How to filter EPIC event lists for flaring particle background Thread). Let's assume that a filtered file has been created from the file MOS.fits, with name: MOSclean.fits

  3. Extract an image using the RAWX coordinates and TIME (no RAWY values are available for MOS)

     evselect table=MOSclean.fits imagebinning=binSize imageset=MOSimage.fits withimageset=yes \
       xcolumn=RAWX ycolumn=TIME ximagebinsize=1 yimagebinsize=1

  4. Display the image (Fig.1., left). Note that in timing mode, the Y-coordinate is not giving spatial but timing information and hence, the source is visible as a bright strip when plotting RAWX against TIME.

     imgdisplay withimagefile=true imagefile=MOSimage.fits

    This command is equivalent to the following:

     ds9 MOSimage.fits


    Fig.1: Left, a slice of the RAWX vs. TIME image. The source extraction region has been overlaid for illustration purposes (solid green line). Top right, DETX vs DETY image of the outer MOS CCDs that operate in imaging mode, where the background can be extracted (solid green line). Bottom right, distribution of RAWX values corresponding to the image on the left.
  5. Select the region, from which the spectrum shall be accumulated. The selection of source and background extraction regions is somewhat arbitrary. In general terms, the source extraction region should be centered in the RAWX column with the highest number of counts. This information can be extracted from the distribution of the RAWX values (Fig.1, bottom right). For this particular example, the source extraction region is centered in RAWX=308 with a width of 61 pixels.

    Other useful information on the selection of source and background extraction regions can be found in the Caveats section and in the SAS User Guide (EPIC chapter, section titled Generating spectra). Also, have a look at the "EPIC status of calibration and data analysis" document (XMM-SOC-CAL-TN-0018) for latest recommendations on how to select source and background regions.

  6. Extract a source spectrum, using the region highlighted in Fig.1., left, and restricting the patterns to single events. It is important to check withspecranges and use the following spectral bin range, specchannelmin=0 and specchannelmax=11999, to accumulate the spectrum (see caveats).

      evselect table=MOSclean.fits withspectrumset=yes spectrumset=MOSsource_spectrum.fits \
        energycolumn=PI spectralbinsize=5 withspecranges=yes specchannelmin=0 specchannelmax=11999 \
        expression='(FLAG==0) && (PATTERN<=0) && (RAWX>=278) && (RAWX<=338)'


  7. Extract a background spectrum, using the region highlighted in Fig.1., top right. In case of the MOS cameras, the timing strip is only 100 pixels wide, so if a background spectrum is required, it is advised to extract it from the outer CCDs which are collecting data in imaging mode. Assuming a background spectra is needed, and assuming that the background is extracted from a source-free region.

     evselect table=MOSclean_imaging.fits withspectrumset=yes spectrumset=MOSbackground_spectrum.fits \
       energycolumn=PI spectralbinsize=5 withspecranges=yes specchannelmin=0 specchannelmax=11999 \
       expression='(FLAG==0) && (PATTERN<=1 || PATTERN==3) && ((DETX,DETY) in BOX(7551.98,-10844.26,3205,1513,0))'


    NOTE: Notice that the event file used for the background extraction is different (here called, MOSclean_imaging.fits) than that used to extract the source spectrum (MOSclean.fits). The file MOSclean_imaging.fits is equivalent to the file MOSclean.fits but corresponds to the imaging part of the MOS Timing observation, and is also produced by emproc / emchain (the imaging event file produced by either of these two tasks will contain the string ImagingEvts in the file name). The file MOSclean_imaging.fits should also be cleaned using the same procedure as that followed for the file MOSclean.fits.

  8. Calculate the area of source and background region used to make the spectral files. The area is written into the header of the SPECTRUM table of the file as keyword BACKSCAL (if the spectrum is created via xmmselect, backscale will run automatically).

     backscale spectrumset=MOSsource_spectrum.fits badpixlocation=MOSclean.fits
     backscale spectrumset=MOSbackground_spectrum.fits badpixlocation=MOSclean_imaging.fits


  9. Generate a redistribution matrix. Currently there are two possible approaches:


    a) use the SAS task rmfgen to create a redistribution matrix for your previously extracted spectrum:

     rmfgen spectrumset=MOSsource_spectrum.fits rmfset=MOS.rmf

    b) use the ready-made (canned) response matrix.

  10. Generate an ancillary file


      arfgen spectrumset=MOSsource_spectrum.fits arfset=MOS.arf withrmfset=yes rmfset=MOS.rmf \
        badpixlocation=MOSclean.fits detmaptype=psf

  11. Rebin the spectrum and populate the header keywords with the names of the required response and background files. In the following example the spectrum is rebinned in order to have at least 25 counts for each background-subtracted spectral channel and not to oversample the intrinsic energy resolution by a factor larger then 3.

      specgroup spectrumset=MOSsource_spectrum.fits mincounts=25 oversample=3 rmfset=MOS.rmf \
        arfset=MOS.arf backgndset=MOSbackground_spectrum.fits groupedset=MOS_spectrum_grp.fits

    The rebinning options shown in the example above, are by no means the only possible binning available, or the recommended one, more binning options are available in the description of the task specgroup.


  12. Fit the grouped spectrum: MOS_spectrum_grp.fits



To extract a spectrum, withspecranges must be checked (set to yes), with specchannelmin set to 0, and specchannelmax set to 11999 for the MOS. It is important to use this PI range. Selecting a spectrum with a non-standard PI range results in wrong response matrices with an impact on any spectral results derived when using them. If a spectrum needs to be generated within a given energy range, this must be done through the selection expression and not by changing the PI range through specchannelmin and specchannelmax.

If your observation is affected by pile-up, check the corresponding section of the SAS User Guide (EPIC chapter, section How to analyse a piled-up Timing mode observation) for information on the analysis of piled-up Timing mode observations. Of especial relevance is the recipe on how to deal with the generation of an ARF file using the SAS task arfgen. See also the thread on How to evaluate the pile-up fraction in an EPIC source.