Make Background File

The make_background_file() function allows one to create an event file of a background for a particular instrument configuration. This event file can then be added as background to any source event file one creates using instrument_simulator(). make_background_file() also allows one to specify a particular set of point sources to make the point-source contribution to the background, or to create the point-source properties on the fly. In this example, we will show how to do the former using a point source table created by make_point_source_list().

First, import our modules:

import matplotlib

matplotlib.rc("font", size=18)
import soxs

Second, define our parameters:

exp_time = (100.0, "ks")  # in seconds
fov = 50.0  # in arcmin, used only for the point source generation
sky_center = [22.0, -27.0]  # in degrees

Now, use make_point_source_list() to create an ASCII table of point source properties that can be used when creating the background. We’ll set a random seed using the prng parameter to use a unique set of random numbers.

soxs.make_point_source_list("point_source_table.dat", fov, sky_center, prng=24)

We can use this table of point source properties as an input to make_point_sources_file() or to make_background_file() to control precisely the properties of the generated sources. Because in this example we want to create a background, we’ll use make_background_file(). We have to pass the name of the table we created to the input_sources parameter if we want to use it:

soxs : [INFO     ] 2024-05-02 19:35:41,885 Adding in point-source background.
soxs : [INFO     ] 2024-05-02 19:35:41,886 Reading in point-source properties from point_source_table.dat.
soxs : [INFO     ] 2024-05-02 19:35:53,322 Detecting events from source ptsrc_bkgnd.
soxs : [INFO     ] 2024-05-02 19:35:53,323 Applying energy-dependent effective area from aciss_aimpt_cy0.arf.
soxs : [INFO     ] 2024-05-02 19:35:53,366 Pixeling events.
soxs : [INFO     ] 2024-05-02 19:35:53,406 Scattering events with a multi_image-based PSF.
soxs : [INFO     ] 2024-05-02 19:35:53,497 40058 events were detected from the source.
soxs : [INFO     ] 2024-05-02 19:35:53,504 Scattering energies with RMF aciss_aimpt_cy0.rmf.
soxs : [INFO     ] 2024-05-02 19:35:53,644 Generated 40058 photons from the point-source background.
soxs : [INFO     ] 2024-05-02 19:35:53,645 Adding in astrophysical foreground.
soxs : [INFO     ] 2024-05-02 19:35:54,169 Adding in instrumental background.
soxs : [INFO     ] 2024-05-02 19:35:54,211 Making 37448 events from the galactic foreground.
soxs : [INFO     ] 2024-05-02 19:35:54,211 Making 462907 events from the instrumental background.
soxs : [INFO     ] 2024-05-02 19:35:54,234 Writing events to file bkgnd_evt.fits.

We can use the write_image() function in SOXS to bin the events into an image and write them to a file:

soxs.write_image("bkgnd_evt.fits", "bkgnd_img.fits", overwrite=True)

We can now show the resulting image:

fig, ax = soxs.plot_image(
    center=[22.0, -27.0],