Commit 90577754fd4e6e8ab52e58d21f6b10b297033622
1 parent
721eb80b
Enhance 1DC tutorial
Showing
5 changed files
with
134 additions
and
25 deletions
doc/source/users/tutorials/1dc/first_detect.rst
| ... | ... | @@ -30,6 +30,7 @@ iteratively finds all peaks in the sky map above a given threshold. |
| 30 | 30 | The detection threshold was set here to ``10.0`` which means that only peaks |
| 31 | 31 | are considered that are ten standard deviations above the mean value of the |
| 32 | 32 | sky map pixels. |
| 33 | + | |
| 33 | 34 | The script generated also a `ds9 <http://ds9.si.edu>`_ region file that can |
| 34 | 35 | be overlaid on the sky map. |
| 35 | 36 | Due to the relatively high threshold of ten standard deviations, only two |
| ... | ... | @@ -44,10 +45,13 @@ sources were detected. |
| 44 | 45 | Below is the content of the |
| 45 | 46 | :ref:`model definition XML file <glossary_moddef>` |
| 46 | 47 | that was generated by :ref:`cssrcdetect`. |
| 47 | -In addition to the two point sources the file also contains a background model | |
| 48 | -component of type ``CTAIrfBackground``. | |
| 49 | -This component was added since the background model type was set to ``IRF`` | |
| 50 | -in the :ref:`cssrcdetect` run. | |
| 48 | +There are three model components in the file and each model component is | |
| 49 | +identified using a unique ``name`` attribute. | |
| 50 | +The first two components, ``"Src001"`` and ``"Src002"`` are the two point sources | |
| 51 | +detected by :ref:`cssrcdetect`, the third component ``"Background"`` is a | |
| 52 | +background model component of type ``"CTAIrfBackground"``. | |
| 53 | +The latter component was added because the background model type was set to | |
| 54 | +``IRF`` in the :ref:`cssrcdetect` run. | |
| 51 | 55 | Having a background model component added allows to directly use the |
| 52 | 56 | :ref:`model definition XML file <glossary_moddef>` |
| 53 | 57 | for a model fitting with :ref:`ctlike`. | ... | ... |
doc/source/users/tutorials/1dc/first_fitting.rst
| ... | ... | @@ -3,13 +3,75 @@ |
| 3 | 3 | Fitting the model components to the data |
| 4 | 4 | ---------------------------------------- |
| 5 | 5 | |
| 6 | +Now you are ready to fit the model to the data and to determine its maximum | |
| 7 | +likelihood parameters. | |
| 8 | +You do this with the :ref:`ctlike` tool that adjusts all parameters in the | |
| 9 | +:ref:`model definition XML file <glossary_moddef>` | |
| 10 | +that have the attribute ``free`` set to ``"1"``. | |
| 11 | +In the current example, the free model parameters are the positions and spectral | |
| 12 | +parameters of the two point sources and the spectral normalisation of the | |
| 13 | +background component. | |
| 14 | +You run the :ref:`ctlike` tool as follows: | |
| 15 | + | |
| 6 | 16 | .. code-block:: bash |
| 7 | 17 | |
| 8 | 18 | $ ctlike |
| 9 | 19 | Input event list, counts cube or observation definition XML file [events.fits] obs.xml |
| 10 | - Input model XML file [$CTOOLS/share/models/crab.xml] models.xml | |
| 11 | - Output model XML file [crab_results.xml] results.xml | |
| 20 | + Input model definition XML file [$CTOOLS/share/models/crab.xml] models.xml | |
| 21 | + Output model definition XML file [crab_results.xml] results.xml | |
| 22 | + | |
| 23 | +The tool will take a few minutes to perform the model fitting, and will write | |
| 24 | +the results into an updated | |
| 25 | +:ref:`model definition XML file <glossary_moddef>` | |
| 26 | +containing the fitted model parameters and their statistical uncertainties. | |
| 27 | +You may inspect the log file ``ctlike.log`` to verify that the model fit | |
| 28 | +converged properly, as illustrated in the example below: | |
| 29 | + | |
| 30 | +.. code-block:: bash | |
| 31 | + | |
| 32 | + 2016-12-02T12:06:03: +=================================+ | |
| 33 | + 2016-12-02T12:06:03: | Maximum likelihood optimisation | | |
| 34 | + 2016-12-02T12:06:03: +=================================+ | |
| 35 | + 2016-12-02T12:06:19: >Iteration 0: -logL=13460292.282, Lambda=1.0e-03 | |
| 36 | + 2016-12-02T12:06:34: >Iteration 1: -logL=13447430.338, Lambda=1.0e-03, delta=12861.944, max(|grad|)=38643.139247 [Index:13] | |
| 37 | + 2016-12-02T12:06:49: >Iteration 2: -logL=13444219.743, Lambda=1.0e-04, delta=3210.595, max(|grad|)=18223.630095 [RA:0] | |
| 38 | + 2016-12-02T12:07:05: >Iteration 3: -logL=13442740.130, Lambda=1.0e-05, delta=1479.613, max(|grad|)=12560.528406 [RA:0] | |
| 39 | + 2016-12-02T12:07:20: >Iteration 4: -logL=13442178.499, Lambda=1.0e-06, delta=561.631, max(|grad|)=5836.127526 [RA:0] | |
| 40 | + 2016-12-02T12:07:35: >Iteration 5: -logL=13442096.088, Lambda=1.0e-07, delta=82.411, max(|grad|)=1183.057138 [RA:0] | |
| 41 | + 2016-12-02T12:07:50: >Iteration 6: -logL=13442094.149, Lambda=1.0e-08, delta=1.939, max(|grad|)=55.233391 [RA:0] | |
| 42 | + 2016-12-02T12:08:06: >Iteration 7: -logL=13442094.147, Lambda=1.0e-09, delta=0.002, max(|grad|)=-3.893441 [RA:6] | |
| 43 | + 2016-12-02T12:08:21: | |
| 44 | + 2016-12-02T12:08:21: +=========================================+ | |
| 45 | + 2016-12-02T12:08:21: | Maximum likelihood optimisation results | | |
| 46 | + 2016-12-02T12:08:21: +=========================================+ | |
| 47 | + 2016-12-02T12:08:21: === GOptimizerLM === | |
| 48 | + 2016-12-02T12:08:21: Optimized function value ..: 13442094.147 | |
| 49 | + 2016-12-02T12:08:21: Absolute precision ........: 0.005 | |
| 50 | + 2016-12-02T12:08:21: Acceptable value decrease .: 2 | |
| 51 | + 2016-12-02T12:08:21: Optimization status .......: converged | |
| 52 | + 2016-12-02T12:08:21: Number of parameters ......: 16 | |
| 53 | + 2016-12-02T12:08:21: Number of free parameters .: 10 | |
| 54 | + 2016-12-02T12:08:21: Number of iterations ......: 7 | |
| 55 | + 2016-12-02T12:08:21: Lambda ....................: 1e-10 | |
| 56 | + 2016-12-02T12:08:21: Maximum log likelihood ....: -13442094.147 | |
| 57 | + 2016-12-02T12:08:21: Observed events (Nobs) ...: 1899265.000 | |
| 58 | + 2016-12-02T12:08:21: Predicted events (Npred) ..: 1899225.997 (Nobs - Npred = 39.0025871018879) | |
| 59 | + | |
| 60 | +You may also convert the fitted model positions into a `ds9 <http://ds9.si.edu>`_ | |
| 61 | +region file using the :ref:`csmodelinfo` script so that you can overlay the | |
| 62 | +fit results over a sky map: | |
| 12 | 63 | |
| 64 | +.. code-block:: bash | |
| 65 | + | |
| 66 | + $ csmodelinfo | |
| 67 | + Input model definition XML file [model.xml] results.xml | |
| 68 | + Output DS9 region file [ds9.reg] positions.reg | |
| 69 | + | |
| 70 | +The following image shows a zoom of the sky map that comprises both point | |
| 71 | +sources, with the initial source positions determined by :ref:`cssrcdetect` | |
| 72 | +as green crosses and the positions fitted by :ref:`ctlike` as blue circles. | |
| 73 | +Obviously, the initial positions were already nearby the fitted position, | |
| 74 | +which is required to assure the proper convergence of the fit. | |
| 13 | 75 | |
| 14 | 76 | .. figure:: first_skymap_fitted.png |
| 15 | 77 | :width: 600px |
| ... | ... | @@ -17,21 +79,41 @@ Fitting the model components to the data |
| 17 | 79 | |
| 18 | 80 | *Background subtracted sky map of the events recorded during the Galactic Plane Survey around the Galactic Centre with the fitted positions of the sources shown as blue circles* |
| 19 | 81 | |
| 82 | +You can also convert the spectral parameters of the point sources into a | |
| 83 | +butterfly diagram for each source using the :ref:`ctbutterfly` tool. | |
| 84 | +The butterfly diagram shows the envelope of all power laws that are | |
| 85 | +statistically compatible with the data. | |
| 86 | +You create the butterfly diagram for the first source using: | |
| 87 | + | |
| 20 | 88 | .. code-block:: bash |
| 21 | 89 | |
| 22 | 90 | $ ctbutterfly |
| 23 | 91 | Input event list, counts cube or observation definition XML file [events.fits] obs.xml |
| 24 | 92 | Source of interest [Crab] Src001 |
| 25 | - Input model XML file [$CTOOLS/share/models/crab.xml] ctlike_unbinned_bkg_3ptsrc.xml | |
| 93 | + Input model definition XML file [$CTOOLS/share/models/crab.xml] results.xml | |
| 26 | 94 | Start value for first energy bin in TeV [0.1] |
| 27 | 95 | Stop value for last energy bin in TeV [100.0] |
| 28 | 96 | Output ASCII file [butterfly.txt] butterfly_src001.txt |
| 29 | 97 | |
| 98 | +You create the butterfly diagram for the second source by selecting ``Src002`` | |
| 99 | +as ``"Source of interest"``. | |
| 100 | +The butterfly diagrams for both sources are displayed in the figure below: | |
| 101 | + | |
| 102 | +.. figure:: first_spectrum.png | |
| 103 | + :width: 600px | |
| 104 | + :align: center | |
| 105 | + | |
| 106 | + *Butterfly diagrams determined with ctbutterfly and spectral points determined with csspec for Src001 (top) and Src002 (bottom)* | |
| 107 | + | |
| 108 | +The figure also shows spectral points for each source that were determined | |
| 109 | +using the :ref:`csspec` script. | |
| 110 | +You create the spectrum for the first source using: | |
| 111 | + | |
| 30 | 112 | .. code-block:: bash |
| 31 | 113 | |
| 32 | 114 | $ csspec |
| 33 | 115 | Input event list, counts cube, or observation definition XML file [events.fits] obs.xml |
| 34 | - Input model XML file [results.xml] ctlike_unbinned_bkg_3ptsrc.xml | |
| 116 | + Input model definition XML file [results.xml] results.xml | |
| 35 | 117 | Source name [Crab] Src001 |
| 36 | 118 | Binning algorithm (LIN|LOG|FILE) [LOG] |
| 37 | 119 | Lower energy limit (TeV) [0.1] |
| ... | ... | @@ -39,9 +121,9 @@ Fitting the model components to the data |
| 39 | 121 | Number of energy bins (0=unbinned) [10] |
| 40 | 122 | Output spectrum file [spectrum.fits] spectrum_src001.fits |
| 41 | 123 | |
| 42 | -.. figure:: first_spectrum.png | |
| 43 | - :width: 600px | |
| 44 | - :align: center | |
| 45 | - | |
| 46 | - *Butterfly diagrams determined with ctbutterfly and spectral points determined with csspec for Src001 (top) and Src002 (bottom)* | |
| 47 | - | |
| 124 | +Alike the :ref:`ctbutterfly` tool, you have to run the :ref:`csspec` script | |
| 125 | +for each source for which you want to obtain spectral points. | |
| 126 | +The script will divide the data into a number of logarithmically spaced energy | |
| 127 | +bins and determine the flux in each of the bins using a maximum likelihood | |
| 128 | +model fit. | |
| 129 | +Ten energy bins were used in this example. | ... | ... |
doc/source/users/tutorials/1dc/first_residuals.rst
| 1 | 1 | .. _1dc_first_residuals: |
| 2 | 2 | |
| 3 | -Inspecting the residuals | |
| 4 | ------------------------- | |
| 3 | +Inspecting the fit residuals | |
| 4 | +---------------------------- | |
| 5 | + | |
| 6 | +After doing the model fit you should investigate the residuals to verify that | |
| 7 | +the model components properly describe the observed event distribution. | |
| 8 | +You do this with the :ref:`csresmap` script by providing the output | |
| 9 | +:ref:`model definition XML file <glossary_moddef>` | |
| 10 | +``results.xml`` produced by :ref:`ctlike` as input: | |
| 5 | 11 | |
| 6 | 12 | .. code-block:: bash |
| 7 | 13 | |
| 8 | 14 | $ csresmap |
| 9 | - Input event list, counts cube, or observation definition XML file [obs.xml] | |
| 10 | - Input model XML file [results.xml] | |
| 11 | - First coordinate of image center in degrees (RA or galactic l) (0-360) [0.0] | |
| 12 | - Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [0.0] | |
| 15 | + Input event list, counts cube, or observation definition XML file [events.fits] obs.xml | |
| 16 | + Input model definition XML file [$CTOOLS/share/models/crab.xml] results.xml | |
| 17 | + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] 0.0 | |
| 18 | + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.01] 0.0 | |
| 13 | 19 | Lower energy limit (TeV) [0.1] |
| 14 | 20 | Upper energy limit (TeV) [100.0] |
| 15 | - Coordinate System (CEL|GAL) [GAL] | |
| 21 | + Coordinate System (CEL|GAL) [CEL] GAL | |
| 16 | 22 | Projection method (AIT|AZP|CAR|MER|MOL|STG|TAN) [CAR] |
| 17 | - Size of the X axis in pixels [200] | |
| 18 | - Size of the Y axis in pixels [200] 100 | |
| 19 | - Pixel size (deg/pixel) [0.1] 0.05 | |
| 20 | - Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT) [SUB] | |
| 23 | + Size of the X axis in pixels [200] 500 | |
| 24 | + Size of the Y axis in pixels [200] 250 | |
| 25 | + Pixel size (deg/pixel) [0.02] 0.02 | |
| 26 | + Residual map computation algorithm (SUB|SUBDIV|SUBDIVSQRT) [SUBDIV] SUB | |
| 21 | 27 | Output residual map file [resmap.fits] |
| 28 | + | |
| 29 | +This produces a residual map that you can display for example with | |
| 30 | +`ds9 <http://ds9.si.edu>`_. | |
| 31 | +The figure below shows the result, with the fitted source positions indicated | |
| 32 | +by white circles. | |
| 33 | +The residuals near the positions of both point sources are relatively flat, | |
| 34 | +demonstrating that both excesses are well described by point sources. | |
| 35 | +Residuals along the Galactic plane indicate that not all sources that are | |
| 36 | +present in the data are described by the model, which is explained by the | |
| 37 | +relatively high detection threshold that you used in the source detection | |
| 38 | +step. | |
| 39 | + | |
| 40 | +.. figure:: first_skymap_residual.png | |
| 41 | + :width: 600px | |
| 42 | + :align: center | |
| 43 | + | |
| 44 | + *Residual sky map after subtraction of the fitted model* | ... | ... |
doc/source/users/tutorials/1dc/first_skymap_fitted.png
doc/source/users/tutorials/1dc/first_skymap_residual.png
0 → 100644
427 KB