Introduction and exampleThe table model file is used in xspec to provide grids of model calculations on which to interpolate when fitting a model to data. The table class can be used to create these files. The example code below sets up a grid with two parameters.
#include "table.h" using namespace std; using namespace heasp; int main(int argc, char* argv[]) { table test; // set table descriptors and the energy array test.setModelName("Test"); test.setModelUnits(" "); test.setisRedshift(true); test.setisAdditive(true); test.setisError(false); RealVector energy(100); for (size_t i=0; i<100; i++) energy[i] = 0.1+i*0.1; test.setEnergies(energy); test.setEnergyUnits("keV"); test.setNumIntParams(2); test.setNumAddParams(0); // define first parameter and give it 11 values ranging from // 0.0 to 2.0 in steps of 0.2. tableParameter testpar; testpar.setName("param1"); testpar.setInterpolationMethod(0); testpar.setInitialValue(1.0); testpar.setDelta(0.1); testpar.setMinimum(0.0); testpar.setBottom(0.0); testpar.setTop(2.0); testpar.setMaximum(2.0); RealVector tabVals(11); for (size_t i=0; i<11; i++) tabVals[i] = 0.2*i; testpar.setTabulatedValues(tabVals); // and push it onto the vector of parameters test.pushParameters(testpar); // define the second parameter and give it 5 values ranging from // 4.6 to 5.4 in steps of 0.2. Use the load constructor as an // illustration in this case tabVals.resize(5); for (size_t i=0; i<5; i++) tabVals[i] = 4.6+0.2*i; tableParameter testpar2("param2", 0, 5.0, 0.1, 4.6, 4.6, 5.4, 5.4, tabVals); // and push it onto the vector of parameters test.pushParameters(testpar); // now set up the spectra. these are arbitrarily calculated, in a real program // this step would read a file or call a routine. RealVector flux(99); tabVals.resize(2); for (size_t i1=0; i1<11; i1++) { for (size_t i2=0; i2<5; i2++) { tabVals[0] = 0.2*i1; tabVals[1] = 4.6+0.2*i2; for (size_t j=0; j<99; j++) { flux[j] = tabVals[0]+10*tabVals[1]; } tableSpectrum testspec(tabVals, flux); test.Spectra.push_back(testspec); } } // now write out the table. test.write("test.mod"); exit(0); }
HEASARC Home | Observatories | Archive | Calibration | Software | Tools | Students/Teachers/Public Last modified: Wednesday, 28-Aug-2024 16:49:31 EDT HEASARC Staff Scientist Position - Applications are now being accepted for a Staff Scientist with significant experience and interest in the technical aspects of astrophysics research, to work in the High Energy Astrophysics Science Archive Research Center (HEASARC) at NASA Goddard Space Flight Center (GSFC) in Greenbelt, MD. Refer to the AAS Job register for full details. |