Introduction and examples

Response files come in two varieties: RMFs and ARFs. The former contain the response matrices describing the probability of a photon of a given energy being registered in a given channel of the spectrum. The latter describes the effictive area versus energy. The rmf class is used for manipulating RMFs and the arf and arfII classes for manipulating ARFs. The arfII class is an analog of the phaII class and is useful for the case where an ARF file contains many individual effective area curves. The rmft class handles the transposed response matrix and is of limited use at present.

The example code below shows a program to read in an RMF file, to compress the matrix to remove any element below 1.0e-6, to multiply the result by an ARF, and write a new RMF file.

#include "rmf.h"
#ifndef HAVE_arf
#include "arf.h"

using namespace std;

int main(int argc, char* argv[])
  string rmffile("testin.rmf");
  string arffile("testin.arf");
  string outfile("testout.rmf");

  rmf inputRMF, outputRMF;
  arf inputARF;

  Integer Status(0);

  // read in the RMF and the ARF

  Status =;
  Status =;

  // remove elements from the RMF with values < 1.0e-6

  Real threshold(1.0e-6);

  // multiply the compressed RMF and the ARF to make an output RMF

  if ( inputRMF.checkCompatibility(inputARF) ) {

    outputRMF = inputRMF * inputARF;

    // and write out the result copying any extra HDUs and keywords from
    // the input RMF
    Status = outputRMF.write(outfile, rmffile);



The next example shows an example program to create an RMF file.

#include "rmf.h"
using namespace std;

int main(int argc, char* argv[])

  const size_t Nenergies(1024), Nchannels(1024);
  const Real responseThreshold(1.0e-6);

  rmf Response;



  // code to load the response energy ranges

  vector<Real> lowE(Nenergies), highE(Nenergies);
  for(size_t i=0; i<Nenergies; i++) {
    lowE[i] = 0.1 + i*0.01;
    highE[i] = 0.1 + (i+1)*0.01;
  // code to load the channel energy ranges. in this
  // case the channel energy ranges are identical to
  // the response energy ranges but they need not be

  vector<Real> chlowE(Nenergies), chhighE(Nenergies);
  for(size_t i=0; i<Nchannels; i++) {
    chlowE[i] = 0.1 + i*0.01;
    chhighE[i] = 0.1 + (i+1)*0.01;

  // loop over the energy ranges creating the response. In this
  // example the response is assumed to be a simple gaussian

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

    Real centroid = (lowE[i] + highE[i])/2.0;
    Real sigma = sqrt(centroid);

    vector<Real> work(Nchannels);
    calcGaussResp(sigma, centroid, responseThreshold, chlowE,
                  chhighE, work);

    // add to the response matrix
    Response.addRow(work, lowE[i], highE[i]);

  // Convert to correct units (not required in this particular example)
  Integer status = Response.convertUnits();

  // Check for errors
  string diagnostic = Response.check();

  // Write to an output FITS file
  status = Response.write("MyResponse.rsp");



The following example shows how to read in three type I ARFs and write out a single type II ARF.

#include "arf.h"

int main(int argc, char* argv[])

  arf arf1, arf2, arf3;
  arfII outarf;

  int status(0);

  // Read in the ARFs

  status =“first.arf”);
  status =“second.arf”);
  status =“third.arf”);

  // Load into the output type II ARF


  // Write to an output FITS file. Include any extra keywords
  // or extensions from the first arf file.
  status = outarf.write("output.arf", "first.arf");



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

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