Last modified: 16 Dec 2022


PHA Background File for XSPEC

CIAO 4.15 Science Threads



The grating threads create spectrum files that can 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.

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


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

Related Links:

Last Update: 16 Dec 2022 - Review for CIAO 4.14. No changes.


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

Download the sample data: 459 (HETG/ACIS-S, 3C 273)

unix% download_chandra_obsid 459 pha2

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  acisf0145N004_pha2.fits acisf0145N004_bkg_pha2.fits
tg_bkg  acisf0145N004_pha2.fits
tg_bkg  acisf0145N004_pha2.fits.gz acisf0145N004_bkg_pha2.fits
tg_bkg  acisf0145N004_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
12 Jan 2011 reviewed for CIAO 4.3: no changes
09 Jan 2012 reviewed for CIAO 4.4: no changes
13 Dec 2013 Reviewed for CIAO 4.6; no changes.
23 Dec 2014 Review for CIAO 4.7
16 Dec 2022 Review for CIAO 4.14. No changes.