THE XMMNEWTON ABC GUIDE, STREAMLINED
Fit an RGS Spectrum with Xspec (via Hera)
Contents
Approaches to Spectral Fitting and the Cash Statistic (cstat)
Rebinning the Spectrum
Fitting a Model
While various ftools and Xspec can be run from the Hera Parameter Window, it is easier to do it from the Command Window, so we will demonstrate that here.
Before we get to fitting the spectrum, a few words are in order about different approaches to take. We will use for our example the RGS spectrum of Mkn 421 (ObsID 0153950701) that we reprocessed elsewhere, and assume that we have already logged into Hera.
Approaches to Spectral Fitting and the Cash Statistic (cstat)
For data sets of high signaltonoise and low background, where counting statistics are within the Gaussian regime, the data products above are suitable for analysis using the default fitting scheme in Xspec, χ^{2}minimization. However, for low count rates, in the Poisson regime, χ^{2}minimization is no longer suitable. With low count rates in individual channels, the error per channel can dominate over the count rate. Since channels are weighted by the inversesquare of the errors during χ^{2} model fitting, channels with the lowest count rates are given overlylarge weights in the Poisson regime. Spectral continua are consequently often fit incorrectly, with the model lying underneath the true continuum level. This will be a common problem with most RGS sources. Even if count rates are large, much of the flux from these sources can be contained within emission lines, rather than the continuum. Consequently, even obtaining correct equivalent widths for such sources is nontrivial.
The traditional way to increase the signaltonoise of a data set is to rebin or group the channels, since, if channels are grouped in sufficiently large numbers, the combined signaltonoise of the groups will jump into the Gaussian regime. However, this results in the loss of information. For example, sharp features like an absorption edge or emission line can be completely washed out. Further, in the Poisson regime, the background spectrum cannot simply be subtracted, as is commonly done in the Gaussian regime, since this could result in negative counts. Therefore, rebinning should be reserved for fast, preliminary analysis of spectra without sharp features, or for making plots for publication. When working on the final analysis for a lowcount data set, the (unbinned) background and source spectra should be fitted simultaneously using the Cash statistic. (If fitting with XSPEC, be sure you are running v11.1.0 or later. This is because RGS spectrum files have prompted a slight modification to the OGIP standard, since the RGS spatial extraction mask has a spatialwidth which is a varying function of wavelength. Thus, it has become necessary to characterize the BACKSCL and AREASCL parameters as vectors (i.e., one number for each wavelength channel), rather than scalar keywords as they are for data from the EPIC cameras and past missions. These quantities map the size of the source extraction region to the size of the background extraction region and are essential for accurate fits. Only Xspec v11.1.0, or later versions, are capable of reading these vectors, so be certain that you have an uptodate installation at your site.)
Finally, a caveat of using the Cash statistic in Xspec is that the scheme requires a "total" and "background" spectrum to be loaded into Xspec. This is in order to calculate parameter errors correctly. Consequently, be sure not to use the "net" spectra that were created as part of product packages by SAS v5.2 or earlier. To change schemes in Xspec before fitting the data, type in the Command Window:
XSPEC> statistic cstatA more indepth discussion on statistics in the Poissonian regime can be found in Humphreys et al. (2009). For our purposes, a quick, preliminary fit of the spectrum is sufficient, so we will rebin and use χ^{2} statistics.
Rebinning the Spectrum
There are two ways to rebin a spectrum: the FTOOL grppha, or the RGS pipeline. grppha can group channels using an algorithm which bins up consecutive channels until a count rate threshold is reached. This method conserves the resolution in emission lines above the threshold while improving statistics in the continuum. However, while channel errors are propagated through the binning process correctly, the errors column in the original spectrum product is not strictly accurate. The problem arises because there is no good way to treat the errors within channels containing no counts. To allow statistical fitting, these channels are arbitrarily given an error value of unity, which is subsequently propagated through the binning. Consequently, the errors are overestimated in the resulting spectra.To rebin the spectrum and set the RESPFILE keyword in the header to our response file, navigate to your working directory with the spectra in it, then enter in the Command Window:
grpphaand edit the parameters as needed:
>Please enter PHA filename[] P0153950701R1S001SRSPEC1001.FIT >Please enter output filename[] P0153950701R1S001SRSPEC1001.bin30.FIT >GRPPHA[] chkey RESPFILE P0153950701R1S001RSPMAT1001.FIT >GRPPHA[] group min 30 >GRPPHA[] exit
The other approach, which involves calling the RGS pipeline after it is complete, bins the data during spectral extraction. The following rebins the pipeline spectrum by a factor 3:
rgsproc rebin=3 rmfbins=5000 entrystage=4:spectra finalstage=5:fluxingwhere

rebin  wavelength rebinning factor
rmfbins  number of bins in the response file; this should be greater than 3000
entrystage  entry stage to the pipeline
finalstage  exit stage for the pipeline
One disadvantage of this approach is that you can only choose integer binning of the original channel size. To change the sampling of the events, the pipeline must be run from the second stage ("angles") or earlier:
rgsproc nbetabins=1133 rmfbins=5000 entrystage=2:angles finalstage=5:fluxingwhere the parameters are as defined previously, and

nbetabins  number of bins in the dispersion direction; the default is 3400
Fitting a Model
To fit the spectrum, invoke Xspec in the Command Window:
xspecEnter the data, background, and response file at the prompts, and edit the fitting parameters as needed. Please note that in this example, we are using the output from rgsproc, not the PPS data that came with the data set, so the names are slightly different. If we were using the PPS data, the input spectrum would be *SBSPEC*. Since we did not include background correction when we ran rgsproc, we can correct for it now.
When given the "plot" command, Hera will open a new tab in your web browser and display the plot as a GIF file.
XSPEC> data P0153950701R1S001SRSPEC1001.bin30.FIT ! input data XSPEC> back P0153950701R1S001BGSPEC1001.bin30.FIT ! input background XSPEC> ignore **0.4 ! set sensible limits XSPEC> model wabs*pow ! set spectral model to absorbed powerlaw 1:wabs:nH> 0.01 ! enter reasonable initial values 2:powerlaw:PhoIndex> 2.0 3:powerlaw:norm> 1.0 XSPEC> renorm XSPEC> fit XSPEC> setplot wave XSPEC> setplot command window all XSPEC> setplot command log x off XSPEC> plot data chi XSPEC> exit
Figure 1 shows the fit to the spectrum.

If you have any questions concerning XMMNewton send email to xmmhelp@lists.nasa.gov