Fake an Observation with ISIS

From Remeis-Wiki
Jump to navigation Jump to search

This little FAQ is taken from an eMail written by Jörn an 2013-02-10:

when faking spectra you will pretty much always have to do two things: a) simulate the spectrum based on a spectral model and including the appropriate background and b) simulate a background only. This is necessary because in most cases in an imaging instrument you will be measuring the background from a region in the observation itself. Usually the background will be taken from a previous longer observation that is available in a PHA file. If you're doing simulations with such a background you need to make sure that the extraction region for the background and the source (BACKSCAL) are identical,. By default, for faked data sets isis assumes BACKSCAL=1, i.e. you need to do a set_back_backscale(bla,1.) to ensure that the proper background countrate is faked (if you do not do this you will underestimate the background by A LOT - factors of 100000 are common...).

require("isisscripts");

variable f_rmf = "src_sd.rmf";
variable f_arf = "src_sd.arf";
variable f_bkg = "back_sd.pha";

% exposure time in seconds
variable expos=100000.;

%%%%% define your spectral model here!!!!!! (fit_fun ...)

%
% Fake source and background
%
variable iDat=1;

variable rmf = load_rmf(f_rmf;strict=0);
variable arf = load_arf(f_arf;strict=0);

% assign arf and rms
assign_arf(arf,iDat);
assign_rmf(rmf,iDat);

% set the exposure (in sec)
set_arf_exposure (arf,expos);
set_data_exposure (iDat,expos);
()=define_back(iDat,f_bkg);
set_data_backscale(iDat,1.);  
set_back_backscale(iDat,1.);  
  
fakeit();
set_fake(iDat,0); % mark as a normal data set

%
% fake background only
%
variable iBkg=2;
  

%%%% set all norms of your spectral model to zero here!!!!

% assing arf and rms
assign_arf(arf,iBkg);
assign_rmf(rmf,iBkg);

% set the exposure (in sec)
set_arf_exposure (arf,expos);
set_data_exposure(iBkg,expos);

()=define_back(iBkg, f_bkg);
set_back_backscale(iBkg,1.); 
set_data_backscale(iBkg,1.);
fakeit();

% assign faked background to the spectrum and ignore it
variable bkgdata=get_data_counts(iBkg);
()=_define_back(iDat,bkgdata.value);

delete_data(iBkg);

%%% write your spectrum to file, fit it, or whatever here...