Commit b37325c4f1afb762008b5eb425b8dae2e06513ba

Authored by Jürgen Knödlseder
1 parent 42d7a84c

Augment the H.E.S.S. tutorial

doc/source/users/tutorials/hess_dr1/fitting.rst
1 1 .. _hess_dr1_fitting:
2 2  
3   -Fitting the model components to the data
4   -----------------------------------------
  3 +Fitting a model to the data and inspecting fit residuals
  4 +--------------------------------------------------------
5 5  
6 6 .. admonition:: What you will learn
7 7  
8   - You will learn **how to fit a parametric model to the data**.
  8 + You will learn **how to fit a parametric model to the data** and
  9 + **how to inspect the fit residuals**.
9 10  
10   -Adjust source model name and set pivot energy to 1 TeV to bring it energy
11   -interval of data.
12   -Remove ``error`` attributes.
  11 +Now you are ready to fit the model to the data.
  12 +Since the :ref:`cssrcdetect` script sets some default spectral parameters,
  13 +we suggest that you slightly adjust the
  14 +:ref:`model definition file <glossary_moddef>`
  15 +so that the model fit runs seamlessly.
  16 +For example, the pivot energy of a power law model should be comprised
  17 +within the energy interval of the data, hence you should set
  18 +``PivotEnergy`` for example to 1 TeV.
  19 +The ``error`` attributes are also not needed (although they do not harm),
  20 +so we remove them.
  21 +And finally we rename ``Src001`` to ``Crab``.
  22 +After these little adjustments, your
  23 +:ref:`model definition file <glossary_moddef>`
  24 +should look like this:
13 25  
14 26 .. code-block:: xml
15 27  
... ... @@ -35,14 +47,21 @@ Remove ``error`` attributes.
35 47 </source>
36 48 </source_library>
37 49  
  50 +Now you are ready to do the model fit.
  51 +For this you will use :ref:`ctlike` that you will run as follows:
38 52  
39 53 .. code-block:: bash
40 54  
41   - $ ctlike debug=yes
  55 + $ ctlike
42 56 Input event list, counts cube or observation definition XML file [events.fits] obs_crab_selected.xml
43 57 Input model definition XML file [$CTOOLS/share/models/crab.xml] crab_models.xml
44 58 Output model definition XML file [crab_results.xml]
45 59  
  60 +After a few seconds the tool will have terminated and you can inspect the fit
  61 +results.
  62 +They can for example be found in the ``ctlike.log`` file for which an excerpt
  63 +is shown below.
  64 +
46 65 .. code-block:: none
47 66  
48 67 2018-09-11T21:17:31: +=========================================+
... ... @@ -93,3 +112,104 @@ Remove ``error`` attributes.
93 112 2018-09-11T21:17:31: PivotEnergy ..............: 1000000 MeV (fixed,scale=1000000,gradient)
94 113 2018-09-11T21:17:31: Number of temporal par's ..: 1
95 114 2018-09-11T21:17:31: Normalization ............: 1 (relative value) (fixed,scale=1,gradient)
  115 +
  116 +The fit has converged and the source was fitted at a position of
  117 +:math:`83.623 \pm 0.002` degrees in Right Ascension and
  118 +:math:`22.025 \pm 0.002` degrees in Declination.
  119 +The statistical :math:`1\sigma` positional uncertainty corresponds to 0.12 arcmin.
  120 +Systematic uncertainties are not computed.
  121 +
  122 +According to
  123 +`SIMBAD <http://cdsportal.u-strasbg.fr/?target=Crab%20nebula>`_,
  124 +the Crab nebula is situated at a Right Ascension of 83.633 degrees and a
  125 +Declination of 22.015 degrees, which is 0.013 degrees (0.82 arcmin) away
  126 +from the fitted position.
  127 +
  128 +The intensity at 1 TeV of the Crab was fitted to
  129 +:math:`(4.81 \pm 0.26) \times 10^{-11}\,{\rm photons}\,{\rm cm}^{-2}\,{\rm s}^{-1}\,{\rm TeV}^{-1}`
  130 +the spectral index of the power law is
  131 +:math:`-2.58 \pm 0.01`.
  132 +This can be compared to the values of
  133 +:math:`(3.45 \pm 0.05) \times 10^{-11}\,{\rm photons}\,{\rm cm}^{-2}\,{\rm s}^{-1}\,{\rm TeV}^{-1}`
  134 +and
  135 +:math:`-2.63 \pm 0.01`
  136 +reported in
  137 +`Aharonian et al. (2016), A&A, 457, 899 <https://www.aanda.org/articles/aa/abs/2006/39/aa5351-06/aa5351-06.html>`_.
  138 +
  139 +Following a model fit, **you should always inspect the fit residuals.**
  140 +First let's inspect the spectral residuals.
  141 +You can do this using the :ref:`csresspec` script as follows:
  142 +
  143 +.. code-block:: bash
  144 +
  145 + $ csresspec components=yes
  146 + Input event list, counts cube, or observation definition XML file [events.fits] obs_crab_selected.xml
  147 + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG]
  148 + Start value for first energy bin in TeV [0.1] 0.66
  149 + Stop value for last energy bin in TeV [100.0]
  150 + Number of energy bins (1-200) [20]
  151 + Stack observations? [no] yes
  152 + Coordinate System (CEL|GAL) [CEL]
  153 + Projection method (AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN) [CAR]
  154 + First coordinate of image/source region center in degrees (RA or galactic l) (0-360) [83.63]
  155 + Second coordinate of image/source region center in degrees (DEC or galactic b) (-90-90) [22.51] 22.01
  156 + Size of the X axis in pixels [200]
  157 + Size of the Y axis in pixels [200]
  158 + Pixel size (deg/pixel) [0.02]
  159 + Input model definition XML file [$CTOOLS/share/models/crab.xml] crab_results.xml
  160 + Mask data to calculate residuals in ROI? [no]
  161 + Residuals computation algorithm (SUB|SUBDIV|SUBDIVSQRT|SIGNIFICANCE) [SIGNIFICANCE]
  162 + Output residual spectrum file [resspec.fits]
  163 +
  164 +The script will produce the FITS file ``resspec.fits`` that contains the
  165 +spectral residuals for each of the model components.
  166 +To display the residuals you can use the ``show_residuals.py`` script in the
  167 +example folder.
  168 +Apparently there as still significant spectral residuals that cannot be
  169 +explained by the model, yet overall, the model provides a reasonable first order
  170 +approximation of the data.
  171 +
  172 +.. code-block:: bash
  173 +
  174 + $CTOOLS/share/examples/python/show_residuals.py resspec.fits
  175 +
  176 +.. figure:: fitting_resspec.png
  177 + :width: 600px
  178 + :align: center
  179 +
  180 + *Residual spectrum*
  181 +
  182 +Finally you should also inspect the spatial residuals.
  183 +You do this using the :ref:`csresmap` script as follows:
  184 +
  185 +.. code-block:: bash
  186 +
  187 + $ csresmap
  188 + Input event list, counts cube, or observation definition XML file [events.fits] obs_crab_selected.xml
  189 + Input model definition XML file [$CTOOLS/share/models/crab.xml] crab_results.xml
  190 + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63]
  191 + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.51] 22.01
  192 + Coordinate System (CEL|GAL) [CEL]
  193 + Projection method (AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN) [CAR]
  194 + Size of the X axis in pixels [200]
  195 + Size of the Y axis in pixels [200]
  196 + Pixel size (deg/pixel) [0.02]
  197 + Lower energy limit (TeV) [0.1] 0.66
  198 + Upper energy limit (TeV) [100.0]
  199 + Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT|SIGNIFICANCE) [SIGNIFICANCE]
  200 + Output residual map file [resmap.fits]
  201 +
  202 +The script will produce the FITS file ``resmap.fits`` that contains a map of
  203 +the spatial residuals.
  204 +You can display this map using
  205 +`ds9 <http://ds9.si.edu>`_.
  206 +The resulting residual map with a linear color scaling and a slight Gaussian
  207 +smoothing applied is shown below.
  208 +The map is relatively clean, although there are some small residuals
  209 +south-east of the fitted Crab nebula position.
  210 +
  211 +.. figure:: fitting_resmap.png
  212 + :width: 400px
  213 + :align: center
  214 +
  215 + *Residual map with a slight Gaussian smoothing applied*
... ...
doc/source/users/tutorials/hess_dr1/fitting_resmap.png 0 → 100644

210 KB

doc/source/users/tutorials/hess_dr1/fitting_resspec.png 0 → 100644

35.5 KB

doc/source/users/tutorials/hess_dr1/skymap.rst
1 1 .. _hess_dr1_sky_map:
2 2  
3   -Generating a sky map from the events
4   -------------------------------------
  3 +Generating a sky map and finding sources
  4 +----------------------------------------
5 5  
6 6 .. admonition:: What you will learn
7 7  
... ...
examples/show_residuals.py
... ... @@ -298,7 +298,7 @@ def plot_residuals(filename, plotfile, hdu):
298 298 axarr[0].step(ebounds, component, zorder=0, label=table[s].name())
299 299  
300 300 # Add legend
301   - axarr[0].legend(loc='best')
  301 + axarr[0].legend(loc='best', prop={'size': 10})
302 302  
303 303 # Show figure
304 304 if len(plotfile) > 0:
... ...