Introduction and example

Spectrum files can be manipulated using the pha and phaII classes. The latter is simply a vector of pha classes and is useful for handling type II PHA files. The grouping class and utility routines are also useful for some tasks. As an example the code below reads in a type II PHA file, bins up all the spectra by a factor of 2, then writes out the result. Note that the data types Integer and Real are defined in heasp.h.

#include "grouping.h"
#include "phaII.h"

using namespace std;

int main(int argc, char* argv[])
  const string infile("testin.pha");
  const string outfile("testout.pha");

  Integer Status(0);

  // read in all the spectra

  phaII inputSpectra(infile);

  Integer Nspectra = inputSpectra.getNumberSpectra();

  // loop round the spectra

  for (size_t i=0; i<(size_t)Nspectra; i++) {

    // set up the grouping object to rebin by a factor of 2

    grouping groupInfo;
    groupInfo.load(2, inputSpectra.phas[i].NumberChannels());

    // rebin this spectrum

    pha thisSpectrum = inputSpectra.get(i);
    Status = thisSpectrum.rebinChannels(groupInfo);
    Status = inputSpectra.setphasElement(i, thisSpectrum);


  // write the new spectra out copying the primary HDU, other HDUs,
  // keywords and columns
  Status = inputSpectra.write(outfile, infile);


HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public

Last modified: Wednesday, 23-Mar-2022 21:09:00 EDT