Skip to the navigation links
Last modified: 28 Jan 2010
Where are the PDFs?

PHA Background File for XSPEC

CIAO 4.2 Science Threads


Last Update: 28 Jan 2010 - updated for CIAO 4.2: updated file versions to N004 and contrib date


The grating threads show how to create a PHA spectrum file for grating observations. The files can then be read into Sherpa, and analyzed as desired. However, if you wish to use XSPEC, the file needs to be in a format that it can read.


Run the tg_bkg script to take the output from the grating threads and produce a PHA background file suitable for use in XSPEC.

Read this thread if:

you prefer to do your grating analysis in XSPEC. If you do all your fitting and modeling in Sherpa, you DO NOT need to complete this thread.

Related Links:


Background Information

tg_bkg makes a background file that is compatible with XSPEC. Sherpa will be able to use it, but it can already read the arrays directly from the PHA file. The script sums the BACKGROUND_UP and BACKGROUND_DOWN columns and adjusts the scale factor keyword (BACKSCAL) accordingly. Since it is designed to keep the same format as the PHA file, i.e. the rows in both files correspond to one another, it is a more convenient way of inspecting the background.

It is important to note that these are estimates to the background. Since they are binned adjacent to the spectrum source region, they will have a contribution from the wings of the PSF. They also have a contribution from signal aliased in chipy during the frame shift at the level of (usually) 41 ms frame shift / 3200 ms integration / 1024 rows, or 1.25e-5 times the source rate (HEG+MEG or LEG, all orders). The source count rate at that diffraction angle gets smeared during the frame shift.

Get Started

Sample ObsID used: 459 (HETG/ACIS-S, 3C 273)

File types needed: pha2

This thread uses the tg_bkg script, which is part of the CIAO Scripts distribution. The CIAO scripts package should be the following version or newer:

14 Dec 2009

Please check that you have at least this version of the scripts package installed before continuing. If you do not have the scripts installed or need to update to a newer version, refer to the Scripts page.

It is assumed that you have already completed the HETG/ACIS-S, LETG/ACIS-S, LETG/HRC-S, or LETG/HRC-I grating spectra thread and therefore have a PHA spectrum file.

Run the tg_bkg Script

The only input required is the PHA file, so we are now ready to run tg_bkg. Executing the script without any input shows the syntax:

unix% tg_bkg

USAGE: /soft/ciao/contrib/bin/tg_bkg  tg_pha_in  [tg_bkg_pha_out]

    Write out background PHA file (of same type as input)
     Adjust BACKSCAL

  Input file may be compressed.  Output is never compressed.
  If output filename is omitted, the ouput file has the input name with _bkg appended.


tg_bkg  acisf0145N003_pha2.fits acisf0145N003_bkg_pha2.fits
tg_bkg  acisf0145N003_pha2.fits
tg_bkg  acisf0145N003_pha2.fits.gz acisf0145N003_bkg_pha2.fits
tg_bkg  acisf0145N003_pha2.fits.gz

 (This is a shell script; you can alter it to suit your own tastes.)

First, make sure the input file has write permission (since the script updates the BACKFILE keyword), then run the script:

unix% chmod u+w acisf00459N004_pha2.fits

unix% tg_bkg acisf00459N004_pha2.fits 
Input file has been changed, BACKFILE keyword has been added

The newly created file may be examined with dmlist:

unix% dmlist acisf00459N004_pha2.fits_bkg cols
Columns for Table Block SPECTRUM
ColNo  Name                 Unit        Type             Range
   1   SPEC_NUM                          Int2           1:32767              Spectrum Number
   2   TG_M                              Int2           -62:62               Diffraction order (m)
   3   TG_PART                           Int2           0:99                 Spectral component (HEG, MEG, LEG, HESF parts)
   4   TG_SRCID                          Int2           1:32767              Source ID, output by detect
   5   X                    pixel        Real4          0.50:    65534.50    X sky coord of source
   6   Y                    pixel        Real4          0.50:    65534.50    Y sky coord of source
   7   CHANNEL[8192]                     Int2(8192)     1:32767              Vector of spectral bin numbers.
   8   BIN_LO[8192]         angstrom     Real8(8192)    0:      400.0        Bin boundry, left edge
   9   BIN_HI[8192]         angstrom     Real8(8192)    0:      400.0        Bin boundry, right edge
  10   COUNTS[8192]                      Int2(8192)     -                    User defined column

The COUNTS column is the sum of the BACKGROUND_UP and BACKGROUND_DOWN columns from the original pha2.fits file.


This thread is now complete; the file can be read into XSPEC and used for grating analysis.


04 Jan 2005 reviewed for CIAO 3.2: no changes
28 Jul 2005 tg_bkg script updated to v1.1: fixed Mac OS X awk syntax problem
06 Dec 2005 reviewed for CIAO 3.3: no changes
01 Dec 2006 updated for CIAO 3.4: corrected a filename
22 Jan 2008 reviewed for CIAO 4.0: no changes
07 Jan 2009 reviewed for CIAO 4.1: no changes
06 May 2009 check the version of the CIAO scripts package instead of the individual script
28 Jan 2010 updated for CIAO 4.2: updated file versions to N004 and contrib date

Return to Threads Page: Top | All | Grating

Where are the PDFs?
Last modified: 28 Jan 2010