Set output filenames: srcspec, bckspec, arfset, rmf_set depending on values of <withfilestem> and related params. Create a source spectrum expression = <srcexp> + PATTERN + FLAG selections evselect table=<table> expression=<expression> withspectrumset=yes spectrumset=srcspec Create a background spectrum expression = <backexp> + PATTERN + FLAG selections evselect table=<table> expression=<expression>...... withspectrumset=yes spectrumset=bckspec Create an ARF for the source spectrum, if requested, and calculate the source box area if <witharfset> { arfgen spectrumset=<srcspec> arfset=<arfset> withrmfset=<withrmfset> rmfset=<rmfset> extendedsource=<extendedsource> withbadpixcorr=<withbadpixcorr> badpixlocation=<table> setbackscale=yes keeparfset=<witharfset> useodfatt=<useodfatt> Use arfgen to calculate the background box area arfgen spectrumset=<backspec> arfset=temparf.arf setbackscale=yes keeparfset=no withbadpixcorr=<withbadpixcorr> badpixlocation=<table> useodfatt=<useodfatt> } Create an RMF if not supplied if (! <withrmfset>) { rmfgen spectrumset=<srcspec> rmfset=rmf_set extendedsource=<extendedsource> } else if (<rmfset> has not been set) { rmfset = name of relevant canned matrix } Set the values of BACKFILE, RESPFILE and ANCRFILE in header of srcspec.