Iteratively improving the model
What you will learn
You will learn how to iteratively improve your source model by inspecting the fit residuals and by adjusting the model components as needed.
After doing the model fit you should investigate the residuals to verify that the model components properly describe the observed event distribution. You do this with the :ref:`csresmap` script by providing the output :ref:`model definition file <glossary_moddef>` results.xml produced by :ref:`ctlike` as input:
$ csresmap
Input event list, counts cube, or observation definition XML file [events.fits] cntcube.fits
Input model cube file (generated with ctmodel) [expcube.fits] NONE
Input exposure cube file (only needed for stacked analysis) [NONE] expcube.fits
Input PSF cube file (only needed for stacked analysis) [NONE] psfcube.fits
Input background cube file (only needed for stacked analysis) [NONE] bkgcube.fits
Input model definition XML file [$CTOOLS/share/models/crab.xml] stacked_results_cutoff.xml
Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT|SIGNIFICANCE) [SUBDIV] SIGNIFICANCE
Output residual map file [resmap.fits]
This produces the file resmap.fits that contains a residual map that you can display for example with ds9. The figure below shows the map, with the fitted source positions overlayed as green circles.
Residual sky map after subtraction of the fitted model
The subtraction of the fitted sources clearly leaves some emission holes at their locations, which means that the fitted sources picked up some of the underlying Galactic diffuse gamma-ray emission. To prevent this cross-talk, a diffuse emission model should be added to the :ref:`model definition file <glossary_moddef>`, as illustrated below:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<source_library title="source library">
<source name="Src001" type="PointSource">
<spectrum type="ExponentialCutoffPowerLaw">
<parameter name="Prefactor" scale="1e-18" value="5.7" min="1e-07" max="1000.0" free="1"/>
<parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/>
<parameter name="CutoffEnergy" scale="1e7" value="1.0" min="0.01" max="1000.0" free="1"/>
<parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/>
</spectrum>
<spatialModel type="PointSource">
<parameter name="RA" value="266.424004498437" error="0" scale="1" free="1" />
<parameter name="DEC" value="-29.0049010253548" error="0" scale="1" free="1" />
</spatialModel>
</source>
<source name="Src002" type="PointSource">
<spectrum type="PowerLaw">
<parameter name="Prefactor" value="1" error="0" scale="5.7e-18" min="0" free="1" />
<parameter name="Index" value="1" error="-0" scale="-2.48" min="-4.03225806451613" max="4.03225806451613" free="1" />
<parameter name="PivotEnergy" value="1" scale="300000" free="0" />
</spectrum>
<spatialModel type="PointSource">
<parameter name="RA" value="266.831945177213" error="0" scale="1" free="1" />
<parameter name="DEC" value="-28.1460284439951" error="0" scale="1" free="1" />
</spatialModel>
</source>
<source name="IEM" type="DiffuseSource">
<spectrum type="ConstantValue">
<parameter name="Value" value="1" scale="1" min="1e-05" max="100000" free="1" />
</spectrum>
<spatialModel type="MapCubeFunction" file="$CTADATA/models/cube_iem.fits.gz">
<parameter name="Normalization" value="1" scale="1" min="0.001" max="1000" free="0" />
</spatialModel>
</source>
<source name="BackgroundModel" type="CTACubeBackground">
<spectrum type="PowerLaw">
<parameter name="Prefactor" value="1" error="0" scale="1" min="0.01" max="100" free="1" />
<parameter name="Index" value="0" error="0" scale="1" min="-5" max="5" free="1" />
<parameter name="PivotEnergy" value="1" scale="1000000" free="0" />
</spectrum>
</source>
</source_library>
Repeating the fit with this model and producing a corresponding residual map produces the map shown below. Now, the residuals near the two point sources are flat and the diffuse emission has disappeared. Some additional sources now become clearly visible. It is left as an exercise to the User to include model components for these additional sources in the :ref:`model definition file <glossary_moddef>` in order to reduce the fit residuals. An example for such an exercise is shown :ref:`here <1dc_howto_extent>`.
Residual sky map after subtraction of the fitted model including a diffuse emission component