Splitting and Grouping the PHA2 file for XSPEC Analysis
The procedure used here for splitting and grouping the spectrum is taken from the Grouping a Grating Spectrum CIAO thread.
The PHA2 file contains the negative and postive first through third order spectra for the LETG, stored in the following order: -3/-2/-1/+1/+2/+3. We can extract the -1 and +1 orders into individual type 1 PHA files using the CIAO tool dmtype2split:
unix% dmtype2split "pha2[#row=3]" "leg_-1.pha[SPECTRUM]" unix% dmtype2split "pha2[#row=4]" "leg_1.pha[SPECTRUM]"
It is customary to rebin the spectra so that each energy channel contains sufficient counts such that gaussian statistics approximately applies. This can be accomplished with the CIAO tool dmgroup, setting the grouptype to NUM_CTS and the grouptypeval parameter to 20 counts per bin.
unix% dmgroup infile="leg_-1.pha[SPECTRUM]" outfile=leg_-1_bin20.pha \
binspec="" grouptypeval=20 grouptype=NUM_CTS \
ycolumn="counts" xcolumn="channel"
unix% dmgroup infile="leg_1.pha[SPECTRUM]" outfile=leg_1_bin20.pha \
binspec="" grouptypeval=20 grouptype=NUM_CTS \
ycolumn="counts" xcolumn="channel"
The dmgroup command does not actually alter the data columns for CHANNEL, COUNTS, or STAT_ERR (the statistical error in each channel). Rather it adds a new column, GROUPING, which indicates to programs such as XSPEC which sets of channels are to be considered part of the same rebinned channel. When XSPEC performs this grouping internally, it sums the COUNTS from the relevant channels, and adds the STAT_ERR values in quadrature.
The statistical error in the orignal type 1 PHA file is presumed to be given by the Gehrels estimate of the error, i.e., 1+sqrt(N+0.75), where N is the number of counts in that channel. XSPEC will add this error column in quadrature when creating the binned energy spectra. If one instead wishes the final binned spectra to conform to Poisson statistics, i.e., sqrt(N), then the STAT_ERR column needs to be altered in the original PHA file. We do this by applying the CIAO tool dmtcalc. Specifically, we overwrite the STAT_ERR column with the square root of the COUNTS column. The syntax "stat_err=sqrt((float)counts)" ensures that this new STAT_ERR column is treated as a real number (i.e., not as an integer).
unix% dmtcalc leg_-1_bin20.pha leg_-1_bin20.pha \
expression="stat_err=sqrt((float)counts)" clobber=yes
unix% dmtcalc leg_1_bin20.pha leg_1_bin20.pha \
expression="stat_err=sqrt((float)counts)" clobber=yes
These files are now ready for analysis in XSPEC.