Chandra X-Ray Observatory
Skip to the navigation links
Last modified: 17 Dec 2014


Examining Grating Spectra and Regions: PHA2 files

CIAO 4.9 Science Threads



An overview of displaying grating data Type II PHA files and the source and background extraction regions.

Related Links:

Last Update: 17 Dec 2014 - Review for CIAO 4.7. Minor edits only.


What is a PHA2 File?

A Type II PHA file is a standard FITS format in which each row contains several columns. The PHA file is a product of standard data processing and is identified by the pha2.fits extension; note that the "2" in the filename refers to the fact that it is a level=2 data product, not that it is a Type II file. In the case that the user has to manually reprocess an event file (e.g. when applying an updated order sorting table), the PHA2 spectrum file is obtained from the level 2 event file by tgextract; see the HETG/ACIS-S Grating Spectra for an example of this.

The SPECTRUM block of a PHA2 file has 13 columns of data:

     ColNo Name                  Description

     1     SPEC_NUM              Spectrum Number
     2     TG_M                  Diffraction order (m)
     3     TG_PART               Spectral component (HEG, MEG, LEG, HESF parts)
     4     TG_SRCID              Source ID, output by tgdetect
     5     X                     X sky coord of source
     6     Y                     Y sky coord of source
     7     CHANNEL[8192]         Vector of spectral bin numbers.
     8     COUNTS[8192]          Counts array (a spectrum)
     9     STAT_ERR[8192]        Statistical uncertainty (error) on counts colum
     10    BACKGROUND_UP[8192]   Upper Background count vector.
     11    BACKGROUND_DOWN[8192] Lower Background count vector.
     12    BIN_LO[8192]          Bin boundary, left edge
     13    BIN_HI[8192]          Bin boundary, right edge

There are two columns that are especially relevant when doing analysis:

  • TG_M indicates the order of the spectrum (+/- 1, +/-2, +/- 3)
  • TG_PART indicates the spectral component / grating arm (1 = HEG, 2 = MEG, 3 = LEG)

Examining the Files with Prism

Download the sample data: 459 (HETG/ACIS-S 3C 273); 460 (LETG/HRC-S, 3C 273); 1198 (LETG/ACIS-S, 3C 273); 1800 (LETG/HRC-I, PKS2155-304)

unix% download_chandra_obsid 459,460,1198,1800 evt2,pha2

ACIS-S HETG/LETG Observations

We can use prism to examine the PHA2 file for ObsID 459:

unix% prism acisf00459N004_pha2.fits &

as shown in Figure 1. In this example, there are twelve rows - all the +/- orders for both HEG and MEG - for the observation. The columns CHANNEL, COUNTS, BIN_LO, etc. are all so-called "vector columns"; each contains a vector of elements which, in this example, is 8192 elements long.

An ACIS-S/LETG observation (ObsID 1198) looks similar in prism (Figure 2) but only contains 6 rows (+/- orders for the LEG).

HRC-S/HRC-I LETG Observations

Examining an HRC-S/LETG observation (ObsID 460) is done in the same way as an ACIS grating observation:

unix% prism hrcf00460N005_pha2.fits &

but there is an important difference in the results. As seen in the prism display (Figure 3), there are only two rows for the LEG observation. HRC-S cannot resolve orders and the COUNTS in the +/- 1 order are in fact the total counts of all orders combined. Also, the BIN_LO and BIN_HI columns should be considered for reference only; they actually represent the boundary wavelength of the +/- 1 order alone, while photons from all orders are included in the spectra.

The same holds true for HRC-I/LETG observations, as seen Figure 4 in the example of ObsID 1800.

Displaying the Spectrum

With ChIPS

In order to display a spectrum with ChIPS, we need to split out the desired row(s) with dmtype2split. The +1 order (tg_m=1) HEG (tg_part=1) spectrum for the observation, chosen by the "[tg_part=1,tg_m=1]" filter:

unix% dmtype2split "acisf00459N004_pha2.fits[tg_part=1,tg_m=1]" heg_p1.fits

unix% chips
Welcome to ChIPS: CXC's Plotting Package

chips> make_figure("heg_p1.fits[cols bin_lo,counts]")

chips> set_curve("")
chips> set_plot_title("ACIS+HEG order=+1")

These commands produce the plot shown in Figure 5. Quit ChIPS before continuing:

chips> quit

With Sherpa

Sherpa can also be used to plot a PHA2 spectrum. Sherpa reads all the rows and allows you to specify individual ones for plotting or fitting purposes:

unix% sherpa
Welcome to Sherpa: CXC's Modeling and Fitting Package

sherpa> load_pha("acisf00459N004_pha2.fits")
statistical errors were found in file 'acisf00459N004_pha2.fits'
but not used; to use them, re-read with use_errors=True
read background_up into a dataset from file acisf00459N004_pha2.fits
read background_down into a dataset from file acisf00459N004_pha2.fits
Multiple data sets have been input: 1-12

sherpa> set_analysis("energy")
sherpa> plot_data(3)
sherpa> add_plot()
sherpa> grid_objects(1,2,0.18,0.18)
sherpa> plot_data(4, overplot=True)

sherpa> current_plot("all")
sherpa> limits(X_AXIS, AUTO, 5)

Figure 6 shows the plot of the HEG -1 order (row 3, upper drawing area) and +1 order (row 4, lower drawing area) that is created.

[Thumbnail image: Line plots of energy (keV) vs counts/s/keV.]

[Version: full-size, PNG]

[Print media version: Line plots of energy (keV) vs counts/s/keV.]

Figure 6: +/-1 order plot in Sherpa: count rate per keV

The HEG -1 order (row 3) is in the upper plot and the HEG +1 order (row 4) is in the lower plot.

To plot the data in CHANNEL vs. COUNTS:

sherpa> clear

sherpa> set_analysis("channel",type="rate")

sherpa> plot_data(3)
sherpa> add_plot()
sherpa> grid_objects(1,2,0.18,0.18)
sherpa> plot_data(4, overplot=True)

These commands create Figure 7.

[Thumbnail image: Line plots of channel vs counts.]

[Version: full-size, PNG]

[Print media version: Line plots of channel vs counts.]

Figure 7: +/-1 order plot in Sherpa: counts

The HEG -1 order (row 3) is in the upper plot and the HEG +1 order (row 4) is in the lower plot.

sherpa> quit

Displaying ACIS and HRC Extraction Regions

Each pha2 file has a second block, named REGION, which stores the regions used by tgextract to extract the source and background spectra.

There are three regions associated with each order: source, upper background, and lower background. For an ACIS/HETG observation, this gives 36 regions: 12 spectral components (+/- 3, +/- 2, and +/- 1 for HEG and MEG) times 3 regions apiece (source and two backgrounds).

To look at the columns of a REGION block:

unix% dmlist "acisf00459N004_pha2.fits[REGION]" cols

Columns for Table Block REGION
ColNo  Name                 Unit        Type             Range
   1   SPEC_NUM                          Int2           1:32767              Spectrum number
   2   ROWID                             String[64]                          Source or a background
   3   SHAPE                             String[16]                          Shape of region
   4   TG_LAM               angstrom     Real4          0:      400.0        Dispersion coordinate 
   5   TG_D                 degrees      Real4          -2.0:        2.0     Cross-dispersion coordinate 
   6   R[2]                 (angstrom , degrees) Real4(2)       -Inf:+Inf    Raduis vector for SHAPE
   7   ROTANG               degrees      Real4          -360.0:      360.0   Rotation angle for SHAPE
   8   TG_PART                           Int2           0:9                  Grating part index (HEG=1, MEG=2, LEG=3)
   9   TG_SRCID                          Int2           1:32767              Source identification number
  10   TG_M                              Int2           -62:62               Diffraction order
  11   COMPONENT                         Int2           -                    Component number

ds9 cannot display these regions as they are written in the pha2 file. In order to view them, we need to rename the (TG_LAM,TG_D) columns to (X,Y) so that ds9 knows how to interpret them. We will also need to create images in (TG_LAM,TG_D) coordinates, on which we can display the regions.

The following dmcopy commands create image and region files for the 1st and 3rd orders of the MEG arm:

unix% dmcopy \
      "acisf00459N004_evt2.fits[bin tg_lam=0:30:0.08,tg_d=-0.01:0.01:0.00008][tg_m=-1,1,tg_part=2]" \
      459_order1.fits opt=all

unix% dmcopy \
      "acisf00459N004_evt2.fits[bin tg_lam=0:15:0.08,tg_d=-0.01:0.01:0.00008][tg_m=-3,3,tg_part=2]" \
      459_order3.fits opt=all

unix% dmcopy \
      "acisf00459N004_pha2.fits[region][tg_m=1,tg_part=2][cols x=tg_lam,y=tg_d,*]" \
      region_order1.fits opt=all

unix% dmcopy \
      "acisf00459N004_pha2.fits[region][tg_m=3,tg_part=2][cols x=tg_lam,y=tg_d,*]" \
      region_order3.fits opt=all

In creating the images, the filter includes + and - orders to obtain more events in the image. Since the regions are the same for +/- orders, it is only necessary to copy one (the + orders were used here). The image limits are typical for ACIS/HETG observations, but will need to be adjusted for other configurations.

To display the event files with the regions overlaid:

unix% ds9 -tile 459_order1.fits -region region_order1.fits -cmap a -scale log \
      459_order3.fits -region region_order3.fits -cmap a -scale log 

which produces Figure 8. We can see that all events are contained within at least one extraction region.

[Thumbnail image: The images in wavelength coordinates are displayed side-by-side in ds9.]

[Version: full-size]

[Print media version: The images in wavelength coordinates are displayed side-by-side in ds9.]

Figure 8: ACIS/HETG data with source and background regions overlaid

The first order (left) and third order (right) images with extraction regions overlaid.

For HRC/LETG data, a bow-tie extraction region is used. Using similar dmcopy commands as for the ACIS data:

unix% dmcopy \
      "hrcf00460N005_evt2.fits[bin tg_lam=0:210:0.25,tg_d=-2:2:0.0008][tg_m=-1,1,tg_part=3]" \
      hrc_order1_img.fits opt=all

unix% dmcopy \
      "hrcf00460N005_pha2.fits[REGION][tg_m=1,tg_part=3][cols x=tg_lam,y=tg_d,*]" \
      hrc_region_order1.fits  opt=all

To display the file and regions:

unix% ds9 hrc_order1_img.fits -region hrc_region_order1.fits -cmap b -scale log

which produces Figure 9.

[Thumbnail image: The image in wavelength coordinates is displayed in ds9.]

[Version: full-size]

[Print media version: The image in wavelength coordinates is displayed in ds9.]

Figure 9: HRC-S/LETG data with bow-tie extraction region

The scale parameters have been adjusted to highlight the source counts along the center of the display. A pixel distribution of 19:404 is used.


01 Jun 2004 reviewed for CIAO 3.2: no changes
06 Dec 2005 updated for CIAO 3.3: version numbers
01 Dec 2006 updated for CIAO 3.4: ChIPS and Sherpa versions
24 Jan 2008 updated for CIAO 4.0: updated ChIPS and Sherpa syntax
06 Jun 2008 added "opt=all" to dmcopy commands so all blocks are kept in the grating files
06 Feb 2009 updated for CIAO 4.1: prism was rewritten in GTK, so some cosmetic changes (updated all thread images); images are inline; Python and S-Lang syntax included for ChIPS and Sherpa plotting
14 Jan 2009 updated for CIAO 4.2: ObsID 459 file versions
19 Jul 2010 the S-Lang syntax has been removed from this thread as it is not supported in CIAO 4.2 Sherpa v2.
12 Jan 2011 reviewed for CIAO 4.3: no changes
01 Mar 2012 reviewed for CIAO 4.4: use dmtype2split to split a type II spectrum file before displaying it with ChIPS
03 Dec 2012 Review for CIAO 4.5; updated dmtype2split syntax, need to review crates changes.
14 Jan 2013 Completed CIAO 4.5 review, minor edits only.
26 Nov 2013 Reviewed for CIAO 4.6; no changes.
17 Dec 2014 Review for CIAO 4.7. Minor edits only.

Last modified: 17 Dec 2014
Smithsonian Institute Smithsonian Institute

The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory. 60 Garden Street, Cambridge, MA 02138 USA.   Email: Smithsonian Institution, Copyright © 1998-2017. All rights reserved.