skip to content
 
Swift Science Center Italian site Italian site U.K. site U.K. site


Simulating Swift data with XSPEC

The ability to analyze spectral data from the three Swift instruments simultaneously and with consistent methodology is clearly a mission requirement. Given the historical approach of high energy astronomy to maintain separate source data and calibration files during analysis, the most flexible approach has been to write a UVOT data format that conforms to high energy software requirements. However, note that UVOT spectral data formats will also be compatible with more traditional software packages such as iraf.

The following page provides step by step instructions for simulating BAT, XRT and UVOT data with the XSPEC software package. Under the assumption that high energy astronomers have some familarity with XSPEC, these instructions are biased towards, but not exclusive to, the analysis of UVOT data. It is expected that the software will be new to some optical afterglow researchers, while the application of XSPEC in the analysis of optical and UV data may be a novelty to many gamma-ray and X-ray researchers. The approach is, however, generic to the spectral analysis of data from all three instruments.

Before continuing, download the required calibration files to a single local directory. Please note that spectral files can also be generated using the WWW inteface webspec, while, if count rates are the only purpose of your feasibility study, pimms is the webtool of choice.

Here's a list of required reading (1), including the XSPEC User manual and installation instructions, and useful secondary material (2):

1 Required calibration files: ARFs, RMFs and RSPs
1 XSPEC: Download instructions, installation and user manual
2 The HEASARC spectral file format
2 ARF and RMF file formats
2 The WWW XSPEC interface webspec
2 The count rate simulation tool pimms



1. Simulating spectra

The steps in this example generate spectral data for the BAT, XRT and UVOT grism filters. Red text designates characters typed by you, green text desginates screen messages from the package.
  1. Execute the shell script that initialises XSPEC on your local machine by typing on the command line (where ${LHEASOFT} is the path to shell script):

    source ${LHEASOFT}/lhea-init.csh

  2. cd to your local directory containing the ARF, RMF and RSP files.

  3. Begin your xspec session by typing on the command line:

    xspec

    The following information will be printed to your screen:

    Xspec 11.2.0 12:24:48 03-Sep-2003

    For documentation, notes, and fixes see http://xspec.gsfc.nasa.gov/

    Plot device not set, use "cpd" to set it

    Type "help" or "?" for further information

    As you can see, extensive on-line help is available typing: help or: ? at any time when you are given the XSPEC command prompt.

  4. Open a plotting window, in this case, an xwindow:

    XSPEC>cpd /xw

  5. Build a spectral model. For this example we will use a simple powerlaw with an exponential high enery cutoff and an additional powerlaw at the highest energies. This appears to be an appropriate model for prompt gamma ray bursts at high energies (Band et al. 1993), although it remains to be seen during the Swift mission wheter this is appropriate for lower energies and during the the afterglow epoch. A full list of spectral models is availble by typing help models, but the one we are currently interested in is constructed by typing:

    XSPEC>model grbm

    The package will then prompt the user for values for each fit parameter, in this case there are four of them in this order, the low-energy powerlaw exponent (-1), the high energy powerlaw exponent (-2), the cutoff energy (150 keV) and the normalization (1):

    1:grbm:alpha>-1
    2:grbm:beta>-2
    3:grbm:tem>150
    4:grbm:norm>1

  6. Now we will add a component to the model to represent intrinsic hydrogen absorption from the host galaxy. In this case we need to adopt a redshift which we take as z = 0.1685, the distance to GRB030329. 'addc 1' defines the position in the model where the new component is placed. We will assume that the column density is NH = 5 x 1019 cm-2.

    XSPEC>addc 1 zphabs
    1:zphabs:nH>0.005
    2:zphabs:redshift>0.1685

  7. Finally we add galactic absorption to the model, where NH = 1 x 1020 cm-2:

    XSPEC>addc 1 wabs
    1:wabs:nH>0.01

    Note that the new model can be listed by typing show, model components can also be deleted using delc and the entire model could have been built with the one line command model wabs*zphabs*grbm.

    Also note that while we do not implement it here, the redden model characterizes galactic extinction at energies shortward of the Lyman limit and we expect it to be used extensively to model UVOT data with XSPEC.

  8. We're going to renormalize this spectrum appropriately to model GRB030329. By extrapolation, the XMM-Newton and RXTE study by Tiengo et al. (2003) infers that the 2-10 keV afterglow flux was between 10-8 and 10-9 erg s-1 cm-2 during the first hour after the burst. By typing the following:

    XSPEC>flux 2 10

    we see that the model normalization has to be multiplied appoximately by 1.3 x 10-3 to recreate this across the Swift instruments:

    XSPEC>newpar 7 0.0013

  9. Based on this model we generate fake data using the specrtral calibration files and the command:

    XSPEC>fakeit none
    For fake data, file # 1 needs response file: bat.rsp
    ... and ancillary response file: none
    Use counting statistics in creating fake data? (y) y
    Input optional fake file prefix (max 9 chars):
    Fake data filename (bat.fak) [/ to use default]:
    bat.fak
    Exposure time, correction norm (1, 1): 3500 1

    No ancillary response file (ARF) is required in this case because a RSP file was provided for the response file. However if an RMF file is provided instead, an ARF file is always required to provide the correct effective area for each instrument and/or filter. If counting statistics are used, the spectra will be randomized according to the count rate of each channel. In this example we chose an exposure of 3500 s, i.e. ~ 1 hr of accumulated exposures since the burst trigger.

    This step can be repeated using the XRT and UVOT optical and UV grism, providing four simulated data files: bat.fak, xrt.fak, ugrism.fak and vgrism.fak.

  10. Load all four spectral files, and their RSP files, into XSPEC.

    XSPEC>data 1:1 bat.fak 1:2 xrt.fak 1:3 ugrism.fak 1:4 vgrism.fak
    Error: cannot read background file _bkg.none for data file bat.fak
    Replacement file (enter 'none' to return to XSPEC> prompt):
    none
    Error: cannot read background file _bkg.none for data file xrt.fak
    Replacement file (enter 'none' to return to XSPEC> prompt):
    none
    Error: cannot read background file _bkg.none for data file ugrism.fak
    Replacement file (enter 'none' to return to XSPEC> prompt):
    none
    Error: cannot read background file _bkg.none for data file vgrism.fak
    Replacement file (enter 'none' to return to XSPEC> prompt):
    none

    These four error messages result because the package expects background spectrum files to be provided with the source spectra. Background files currently are not available. By typing none, XSPEC will no longer expect background files.

    In order to avoid these error messages each time simulated data is loaded into xspec, within a separate window, edit the header keywords of the spectrum file using the HEASoft tool grppha as follows:

    grppha
    Please enter PHA filename[]bat.fak
    Please enter output filename[]!bat.fak
    GRPPHA[]chkey BACKFILE none
    GRPPHA[]exit

  11. Set the characteristic energy unit for plotting to keV using:

    XSPEC>setplot energy

  12. Ignore specific channels in the response matrices for subsequent plotting and analysis:

    XSPEC>ignore 1:0.-15.,400.-** 2:0.-0.1,12.-**

    The units specified are those of the energy class just specified with the setplot command and specifying the decimal point is crucial in this instance.

  13. Rebin the data so that channels with low count rates are binned with neighbouring channels:

    XSPEC>setplot rebin 5 1000

  14. The effective areas of the instruments can be plotted with the command:

    XSPEC>plot efficien

    where the result is provided in Fig 1.1. The figure in your plotting window can be beautified to your own taste using the iplot function and then the PLT command language.

    effective   areas   of  Swift    insruments
    Figure 1.1: Effective areas of BAT, XRT and UVOT grism instruments.


  15. A logarithmic count rate spectra and χ2 fitting statistic (Fig 1.2) can be plotted thus:

    XSPEC>plot ldata delchi

    count rate representation of simulated Swift data
    Figure 1.2: Count rate spectrum of simulated BAT, XRT and UVOT grism data. A χ2 comparison between data and model is illustrated in the lower panel.


  16. A νFν version of the spectrum (Fig. 1.3) can be obtained using:

    XSPEC>plot eufspec

    νF<sub>ν</sub> representation o1f simulated Swift
data
    Figure 1.3: νFν spectrum of simulated BAT, XRT and UVOT grism data. The black line is the model, blue points the data.


  17. To make things a bit more interesting we can change the redshift of the model:

    XSPEC>newpar 3 3.0

    and rerun fakit to alter the data accordingly. Since all the response matrices are already loaded, this task is now less onerous:

    XSPEC>fakeit none
    For fake data, file # 1 needs response file: vgrism.rsp
    ... and ancillary response file:
    Use counting statistics in creating fake data? (y)
    Input optional fake file prefix (max 6 chars):
    Fake data filename (vgrism.fak) [/ to use default]:vgrism.fak
    File vgrism.fak exists - overwrite? (yY/) or (nN)
    Exposure time, correction norm (1, 1): 3500 1
    Fake data filename (ugrism.fak) [/ to use default]:ugrism.fak
    File ugrism.fak exists - overwrite? (yY/) or (nN)
    Exposure time, correction norm (3500, 1):
    Fake data filename (xrt.fa.fak) [/ to use default]: xrt.fak
    File xrt.fak exists - overwrite? (yY/) or (nN)
    Exposure time, correction norm (3500, 1):
    Fake data filename (bat.fa.fak) [/ to use default]: bat.fak
    File bat.fak exists - overwrite? (yY/) or (nN)
    Exposure time, correction norm (3500, 1):

    The redshift parameter can be fit after unfreezing the parameter in the model and a 90 percent confidence limit calculated thus:

    XSPEC>thaw 3
    XSPEC>fit
    XSPEC>uncer 3

    A quick alternative to the uncer function is the steppar command. The data and model are plotted in Fig. 1.4, where the redshift is measured as z = 3.000 ± 0.003 within 90 percent confidence. Here we chose to plot the UVOT spectra in wavelength units by typing:

    XSPEC>setplot wave
    XSPEC>setplot comm wind all
    XSPEC>setplot comm log x off
    XSPEC>plot data

    Simulated   grism spectra from  a  z  = 3   model
    Figure 1.4: Grism spectra simulated from an identical model which has been redshifted to z = 3.0 The Lyman limit of the host galaxy now resides in the UVOT band, enabling a redshift determination.


    Note, of course, that this is a slightly cheeky example since, by relocating GRB030329 to z = 3, the distance increases by a factor 18 and the source flux should decrease by factor 324!!


    2. Simulating broad band filters

    This example uses the same model as above to simulate data from the broad band filters UVW2, UVM2, UVW1, U, B and V. The response matrices in this case yield one data point per filter. Therefore the broad band filters must be combined with other filters or instruments in order to reveal spectral information.

    1. After setting up and starting your xspec environment, build the model:

      XSPEC>model wabs*zphabs*grbm
      1:wabs:nH>0.01
      2:zphabs:nH>0.005
      3:zphabs:redshift>0.1685
      4:grbm:alpha>-1
      5:grbm:beta>-2
      6:grbm:tem>150
      7:grbm:norm>0.0013

    2. simulate UVW2 data from this model:

      XSPEC>fakeit none
      For fake data, file # 1 needs response file: uvw2.rsp
      ... and ancillary response file:
      Use counting statistics in creating fake data? (y)
      Input optional fake file prefix (max 8 chars):
      Fake data filename (uvw2.fak) [/ to use default]:
      Exposure time, correction norm (1, 1):
      3500 1

      and repeat for the filters UVM2, UVW1, U, B and V.

    3. Load all 6 response matrices and simulated data files into the package:

      XSPEC>data 1:1 uvw2.fak 1:2 uvm2.fak 1:3 uvw1.fak 1:4 u.fak 1:5 b.fak 1:6 v.fak
      Error: cannot read background file _bkg.none for data file uvw2.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none
      Error: cannot read background file _bkg.none for data file uvm2.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none
      Error: cannot read background file _bkg.none for data file uvw1.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none
      Error: cannot read background file _bkg.none for data file u.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none
      Error: cannot read background file _bkg.none for data file b.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none
      Error: cannot read background file _bkg.none for data file v.fak
      Replacement file (enter 'none' to return to XSPEC> prompt):
      none

    4. Open a plotting window and set the plotting units to a wavelength scale:

      XSPEC>cpd /xw
      XSPEC>setplot wave
      XSPEC>setplot command window all
      XSPEC>setplot command log x off

    5. Plot the filter effective areas:

      XSPEC>plot efficien

      Effective areas of  the UVW2,  UVM2,  UVM1, U, B and  V UVOT
filters.
      Figure 2.1: Effective areas of the UVW2, UVM2, UVM1, U, B and V UVOT filters.


    6. Plot the count rate spectrum, with model and χ2:

      XSPEC>plot data delchi

      Simulated count rate spectra for the  UVW2, UVM2, UVM1, U, B
and V UVOT filters.
      Figure 2.2: Simulated count rate spectrum, model and χ2 from the UVW2, UVM2, UVM1, U, B and V UVOT filters.


    7. If we now repeat this exercise after moving the model to a redshift of z = 3.0:

      XSPEC>newpar 3 3.0
      XSPEC>fake none
      For fake data, file # 1 needs response file: uvw2.rsp
      ... and ancillary response file:
      Use counting statistics in creating fake data? (y)
      Input optional fake file prefix (max 8 chars):
      Fake data filename (uvw2.fak) [/ to use default]:
      uvw2.fak
      File uvw2.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (1, 1):
      3500 1
      Fake data filename (uvm2.fak) [/ to use default]: uvm2.fak
      File uvm2.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (3500, 1):
      Fake data filename (uvw1.fak) [/ to use default]:
      uvw1.fak
      File uvw1.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (3500, 1):
      Fake data filename (u.fa.fak) [/ to use default]:
      u.fak
      File u.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (3500, 1):
      Fake data filename (b.fa.fak) [/ to use default]:
      b.fak
      File b.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (3500, 1):
      Fake data filename (v.fa.fak) [/ to use default]:
      v.fak
      File v.fak exists - overwrite? (yY/) or (nN)
      Exposure time, correction norm (3500, 1):

      we arrive at the following spectrum plot:

      Simulated z = 3 count rate spectra for the UVW2, UVM2, UVM1,
U,  B   and  V  UVOT filters.
      Figure 2.2: Count rate spectrum, model and χ2 from the UVW2, UVM2, UVM1, U, B and V UVOT filters after the model has been moved to a redshift of z = 3.0


      The UVW2, UVM2 and UVW1 count rates are reduced significantly compared to the z = 0.1685 model, whereas the B and V count rates are largely unchanged. We can infer with this data that the Lyman break occurs somewhere in the U band.

    8. In principle, if the intrinsic spectrum is well constrained, the broad band filters can provide excellent constraints for z. Fitting for z, as follows:

      XSPEC>thaw 3
      XSPEC>freeze 1,2,5,6
      XSPEC>fit

      we obtain z = 3.000 ± 0.003 with 90 percent confidence. Of course, this requires BAT and XRT measurements in order to assume a spectral shape. However we must also consider extinction and the strengh of the Lyman series and other possible line features close to the break in order before making a redshift measurement with the broad band filters. Consequently, for bright sources, the grism data is a superior resource. For fainter sources, of which the grism filters are not useful and the intrinsic spectrum is more uncertain, the shape of the spectrum is less of an issue because event statistics yield a poorer quality fit. For example if we reduce the flux of the source appropriately for a distance of z = 3.0:

      XSPEC>newpar 7 4.E-6
      XSPEC>fakeit none etc...
      XSPEC>fit
      XSPEC>uncer 3

      Our solution is z = 3.3 ± 0.4 with 90 percent confidence. Clearly the details of the spectral shape near the Lyman limit are less of an issue in these faint cases.

    9. Note that the UVOT bandpass extends down to 1700 Å and, consequently, the Lyman limit cannot be detected by UVOT at distances of z < 1. However an accurate redshift may be determined possibly from narrow lines, perhaps in the grism or XRT data (Reeves et al. 2002).

    3. Simulating XRT spectra

    As a final exercise we look at a model of GRB 030329 where the flux has been extrapolated back to 2 hours after the burst (Tiengo et al. 2003). We also assume that emission lines have developed in the spectrum and that the line equivalent widths are identical to those measured from GRB 011211 by Reeves et al. (2002).

    1. Build the model and create a spectrum:

      XSPEC>mo (powerlaw+zgauss+zgauss+zgauss+zgauss+zgauss)*wabs
      1:powerlaw:PhoIndex>2.084
      2:powerlaw:norm>0.126
      3:gaussian:LineE>1.35
      4:gaussian:Sigma>1.0000E-02
      5:gaussian:norm>3.6900E-02
      6:zgauss:Redshift>0.0685
      7:gaussian:LineE>2.01
      8:gaussian:Sigma>1.0000E-02
      9:gaussian:norm>3.3500E-02
      10:zgauss:Redshift>0.0685
      11:gaussian:LineE>2.62
      12:gaussian:Sigma>1.0000E-02
      13:gaussian:norm>2.5600E-02
      14:zgauss:Redshift>0.0685
      15:gaussian:LineE>3.32
      16:gaussian:Sigma>1.0000E-02
      17:gaussian:norm>1.3200E-02
      18:zgauss:Redshift>0.0685
      19:gaussian:LineE>4.07
      20:gaussian:Sigma>1.0000E-02
      21:gaussian:norm>6.4400E-03
      22:zgauss:Redshift>0.0685
      23:wabs:nH>4.2000E-02
      XSPEC>newpar 9 = 5
      XSPEC>newpar 13 = 5
      XSPEC>newpar 17 = 5
      XSPEC>newpar 21 = 5
      XSPEC>fakeit none
      For fake data, file # 1 needs response file:xrt.rsp
      ... and ancillary response file: Use counting statistics in creating fake data? (y)
      Input optional fake file prefix (max 9 chars):
      Fake data filename (xrt.fak) [/ to use default]: xrt.fak
      Exposure time, correction norm (1, 1):3500 1
      XSPEC>ignore 0.0-0.1,12.0-**
      XSPEC>setplot rebin 5 1000
      XSPEC>plot ldata del

      Simulated count rate spectra for a bright source with the XRT.
      Figure 2.2: Simulated count rate spectrum, model and χ2 for a bright source with the XRT.


    2. Lines are clearly resolved in this instance. The uncertainty for the redshift is found by:

      XSPEC>uncer 5

      The redshift is found be between z = 0-0.063 with 90 percent confidence. Note again that we have modelled this as a combination of cosmological redshift and hypernova expansion, so the redshift is ~ 0.


    If you have a question about Swift, please contact us via the Feedback form.

    This page was last modified on Thursday, 06-Nov-2003 14:51:14 EST.

Science Mission Directorate Universe Division
Beyond Einstein | Origins

  • Questions/Comments/Feedback
  • Find helper applications like Adobe Acrobat
  • Learn about black holes, astronomy & more!
  • A service of the Astrophysics Science Division at NASA/ GSFC

    Swift PI: Neil Gehrels,
    Responsible NASA Official: Phil Newman
    Web Curator: J.D. Myers
    PAO Contact: Susan Hendrix (301-286-1707)
    Privacy Policy and Important Notices.