Commit 2624e24576d74de015a631e48028db2fd8f72147
1 parent
27c07aad
Add Xspec howto tutorial to User documentation (#2404).
Showing
5 changed files
with
224 additions
and
3 deletions
ChangeLog
| 1 | -2018-06-11 | 1 | +2018-06-12 |
| 2 | 2 | ||
| 3 | * Version 1.6.0 released | 3 | * Version 1.6.0 released |
| 4 | ======================== | 4 | ======================== |
| @@ -7,6 +7,7 @@ | @@ -7,6 +7,7 @@ | ||
| 7 | Remove ctools::is_valid_filename() method | 7 | Remove ctools::is_valid_filename() method |
| 8 | Fix bug when using precomputed model in csresspec (#2448) | 8 | Fix bug when using precomputed model in csresspec (#2448) |
| 9 | Keep existing library path in installation script on Mac OS X (#2420) | 9 | Keep existing library path in installation script on Mac OS X (#2420) |
| 10 | + csphagen produces Xspec compliant data (#2404) | ||
| 10 | Add show_rmf.py example script | 11 | Add show_rmf.py example script |
| 11 | Allow specifying of input sky map in ctskymap (#2311) | 12 | Allow specifying of input sky map in ctskymap (#2311) |
| 12 | Add ras() and decs() methods to csobsinfo (#2313) | 13 | Add ras() and decs() methods to csobsinfo (#2313) |
NEWS
| 1 | New Features and Important Changes in ctools 1.6.0 | 1 | New Features and Important Changes in ctools 1.6.0 |
| 2 | 2 | ||
| 3 | -7 June 2018 | 3 | +12 June 2018 |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | Introduction | 6 | Introduction |
| @@ -222,6 +222,9 @@ The true number of energy bins is now computed using | @@ -222,6 +222,9 @@ The true number of energy bins is now computed using | ||
| 222 | making sure in addition that the result is at least 1. This provides better | 222 | making sure in addition that the result is at least 1. This provides better |
| 223 | control over the number of energy bins (#2490). | 223 | control over the number of energy bins (#2490). |
| 224 | 224 | ||
| 225 | +The script now produces data that are compliant with Xspec. An Xspec howto | ||
| 226 | +tutorial was added to the user documentation (#2404). | ||
| 227 | + | ||
| 225 | 228 | ||
| 226 | csphasecrv - Generate phase curve | 229 | csphasecrv - Generate phase curve |
| 227 | --------------------------------- | 230 | --------------------------------- |
doc/source/admin/release_history/1.6.rst
| @@ -10,7 +10,7 @@ ctools 1.6 is a major release that adds significant functionality. | @@ -10,7 +10,7 @@ ctools 1.6 is a major release that adds significant functionality. | ||
| 10 | 10 | ||
| 11 | In particular, this release provides: | 11 | In particular, this release provides: |
| 12 | 12 | ||
| 13 | -* ... | 13 | +* Support for Xspec spectral analysis |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | Bug fixes | 16 | Bug fixes |
| @@ -27,6 +27,8 @@ Improvements | @@ -27,6 +27,8 @@ Improvements | ||
| 27 | 27 | ||
| 28 | * [`2490 <https://cta-redmine.irap.omp.eu/issues/2490>`_] - | 28 | * [`2490 <https://cta-redmine.irap.omp.eu/issues/2490>`_] - |
| 29 | Change formula for number of true energy bins in :ref:`csphagen` | 29 | Change formula for number of true energy bins in :ref:`csphagen` |
| 30 | +* [`2404 <https://cta-redmine.irap.omp.eu/issues/2404>`_] - | ||
| 31 | + :ref:`csphagen` produces Xspec compliant data | ||
| 30 | * Add ``show_rmf.py`` example script | 32 | * Add ``show_rmf.py`` example script |
| 31 | * [`2313 <https://cta-redmine.irap.omp.eu/issues/2313>`_] - | 33 | * [`2313 <https://cta-redmine.irap.omp.eu/issues/2313>`_] - |
| 32 | Add `ras()` and `decs()` methods to :ref:`csobsinfo` | 34 | Add `ras()` and `decs()` methods to :ref:`csobsinfo` |
doc/source/users/tutorials/howto/howto_xspec.rst
0 → 100644
| 1 | +.. _howto_xspec: | ||
| 2 | + | ||
| 3 | +How to perform spectral fitting using Xspec? | ||
| 4 | +-------------------------------------------- | ||
| 5 | + | ||
| 6 | + .. admonition:: What you will learn | ||
| 7 | + | ||
| 8 | + You will learn how to **use Xspec to perform a spectral fitting of On/Off | ||
| 9 | + data**. | ||
| 10 | + | ||
| 11 | + .. warning:: You can reproduce this tutorial only if you have | ||
| 12 | + `Xspec <https://heasarc.nasa.gov/xanadu/xspec/>`_ installed. | ||
| 13 | + You may | ||
| 14 | + `download Xspec here <https://heasarc.gsfc.nasa.gov/lheasoft/download.html>`_. | ||
| 15 | + | ||
| 16 | +If you are familiar with X-ray data analysis, or if you want to use a specific | ||
| 17 | +spectral model that is available in the | ||
| 18 | +`Xspec <https://heasarc.nasa.gov/xanadu/xspec/>`_ | ||
| 19 | +package, you can use that package to fit CTA data that were prepared for an | ||
| 20 | +On/Off analysis. | ||
| 21 | + | ||
| 22 | +To illustrate how you can do this, let's simulate an observation of the Crab | ||
| 23 | +nebula with a pointing direction that is offset by 1 deg: | ||
| 24 | + | ||
| 25 | +.. code-block:: bash | ||
| 26 | + | ||
| 27 | + $ ctobssim | ||
| 28 | + RA of pointing (degrees) (0-360) [83.63] | ||
| 29 | + Dec of pointing (degrees) (-90-90) [22.01] 21.01 | ||
| 30 | + Radius of FOV (degrees) (0-180) [5] | ||
| 31 | + Start time (UTC string, JD, MJD or MET in seconds) [2020-01-01T00:00:00] | ||
| 32 | + Stop time (UTC string, JD, MJD or MET in seconds) [2020-01-01T00:30:00] | ||
| 33 | + Lower energy limit (TeV) [0.1] | ||
| 34 | + Upper energy limit (TeV) [100.0] | ||
| 35 | + Calibration database [prod2] | ||
| 36 | + Instrument response function [South_0.5h] | ||
| 37 | + Input model definition XML file [$CTOOLS/share/models/crab.xml] | ||
| 38 | + Output event data file or observation definition XML file [events.fits] | ||
| 39 | + | ||
| 40 | +No use the :ref:`csphagen` script to generate the On/Off data using a On | ||
| 41 | +region radius of 0.2 deg and the reflected region model to determine the | ||
| 42 | +Off counts spectrum: | ||
| 43 | + | ||
| 44 | +.. code-block:: bash | ||
| 45 | + | ||
| 46 | + $ csphagen | ||
| 47 | + Input event list or observation definition XML file [obs.xml] events.fits | ||
| 48 | + Calibration database [prod2] | ||
| 49 | + Instrument response function [South_0.5h] | ||
| 50 | + Start value for first energy bin in TeV [0.1] | ||
| 51 | + Stop value for last energy bin in TeV [100] | ||
| 52 | + Radius of source region circle (deg) (0-180) [0.2] | ||
| 53 | + Input model definition XML file (if NONE, use point source) [NONE] | ||
| 54 | + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | ||
| 55 | + Number of energy bins [20] | ||
| 56 | + Stack multiple observations into single PHA, ARF and RMF files? [no] | ||
| 57 | + Output observation definition XML file [onoff_obs.xml] | ||
| 58 | + Method for background estimation (REFLECTED|CUSTOM) [REFLECTED] | ||
| 59 | + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] | ||
| 60 | + Right Ascension of source region centre (deg) (0-360) [83.63] | ||
| 61 | + Declination of source region centre (deg) (-90-90) [22.01] | ||
| 62 | + | ||
| 63 | +Now you can start | ||
| 64 | +`Xspec <https://heasarc.nasa.gov/xanadu/xspec/>`_ | ||
| 65 | +for model fitting. | ||
| 66 | + | ||
| 67 | +.. code-block:: bash | ||
| 68 | + | ||
| 69 | + $ xspec | ||
| 70 | + Creating a $HOME/.xspec directory for you | ||
| 71 | + | ||
| 72 | + XSPEC version: 12.10.0c | ||
| 73 | + Build Date/Time: Tue Jun 12 12:46:58 2018 | ||
| 74 | + | ||
| 75 | + XSPEC12> | ||
| 76 | + | ||
| 77 | +First load the On file ``onoff_pha_on.fits`` using the ``data`` command: | ||
| 78 | + | ||
| 79 | +.. code-block:: bash | ||
| 80 | + | ||
| 81 | + XSPEC12>data onoff_pha_on.fits | ||
| 82 | + ***Warning: Data file onoff_pha_on.fits has both POISSERR key set to 'true' and a STAT_ERR column. | ||
| 83 | + XSPEC will assume Poisson errors. | ||
| 84 | + ***Warning: Background file onoff_pha_off.fits has both POISSERR key set to 'true' and a STAT_ERR column. | ||
| 85 | + XSPEC will use assume Poisson errors. | ||
| 86 | + | ||
| 87 | + 1 spectrum in use | ||
| 88 | + | ||
| 89 | + Spectral Data File: onoff_pha_on.fits Spectrum 1 | ||
| 90 | + Net count rate (cts/s) for Spectrum:1 1.585e+00 +/- 3.099e-02 (94.0 % total) | ||
| 91 | + Assigned to Data Group 1 and Plot Group 1 | ||
| 92 | + Noticed Channels: 1-20 | ||
| 93 | + Telescope: unknown Instrument: unknown Channel Type: PI | ||
| 94 | + Exposure Time: 1764 sec | ||
| 95 | + Using fit statistic: chi | ||
| 96 | + Using test statistic: chi | ||
| 97 | + Using Background File onoff_pha_off.fits | ||
| 98 | + Background Exposure Time: 1764 sec | ||
| 99 | + Using Response (RMF) File onoff_rmf.fits for Source 1 | ||
| 100 | + Using Auxiliary Response (ARF) File onoff_arf.fits | ||
| 101 | + | ||
| 102 | +This will load the On ``PHA`` file as well as the Off ``PHA``file, the ``ARF`` | ||
| 103 | +file and the ``RMF`` file. While you specified the On file on the command line, | ||
| 104 | +the file names of the other files were extracted from ``backfile``, ``ancrfile`` | ||
| 105 | +and ``respfile`` header keywords in the On file that were setup by the | ||
| 106 | +:ref:`csphagen` script. | ||
| 107 | + | ||
| 108 | +Now set the fit statistic to ``cstat`` using | ||
| 109 | + | ||
| 110 | +.. code-block:: bash | ||
| 111 | + | ||
| 112 | + XSPEC12>statistic cstat | ||
| 113 | + Default fit statistic is set to: C-Statistic | ||
| 114 | + This will apply to all current and newly loaded spectra. | ||
| 115 | + | ||
| 116 | +and set the spectral model as well as the initial parameters of the spectral | ||
| 117 | +model using | ||
| 118 | + | ||
| 119 | +.. code-block:: bash | ||
| 120 | + | ||
| 121 | + XSPEC12>model powerlaw | ||
| 122 | + | ||
| 123 | + Input parameter value, delta, min, bot, top, and max values for ... | ||
| 124 | + 1 0.01( 0.01) -3 -2 9 10 | ||
| 125 | + 1:powerlaw:PhoIndex>2.5 | ||
| 126 | + 1 0.01( 0.01) 0 0 1e+20 1e+24 | ||
| 127 | + 2:powerlaw:norm>500.0 | ||
| 128 | + | ||
| 129 | + ======================================================================== | ||
| 130 | + Model powerlaw<1> Source No.: 1 Active/On | ||
| 131 | + Model Model Component Parameter Unit Value | ||
| 132 | + par comp | ||
| 133 | + 1 1 powerlaw PhoIndex 2.50000 +/- 0.0 | ||
| 134 | + 2 1 powerlaw norm 500.000 +/- 0.0 | ||
| 135 | + ________________________________________________________________________ | ||
| 136 | + | ||
| 137 | + | ||
| 138 | + Fit statistic : C-Statistic = 712.82 using 20 PHA bins and 18 degrees of freedom. | ||
| 139 | + | ||
| 140 | + Test statistic : Chi-Squared = 605.26 using 20 PHA bins. | ||
| 141 | + Reduced chi-squared = 33.625 for 18 degrees of freedom | ||
| 142 | + Null hypothesis probability = 6.662146e-117 | ||
| 143 | + | ||
| 144 | + ***Warning: Chi-square may not be valid due to bins with zero variance | ||
| 145 | + in spectrum number(s): 1 | ||
| 146 | + | ||
| 147 | + Current data and model not fit yet. | ||
| 148 | + | ||
| 149 | +Note that | ||
| 150 | +`Xspec <https://heasarc.nasa.gov/xanadu/xspec/>`_ | ||
| 151 | +energies are in keV, and the power law normalization is taken at a reference | ||
| 152 | +energy of 1 keV. | ||
| 153 | + | ||
| 154 | +Finally, you are ready to do the spectral fitting using the ``fit`` | ||
| 155 | +command: | ||
| 156 | + | ||
| 157 | +.. code-block:: bash | ||
| 158 | + | ||
| 159 | + XSPEC12>fit | ||
| 160 | + Parameters | ||
| 161 | + C-Statistic |beta|/N Lvl 1:PhoIndex 2:norm | ||
| 162 | + 85.7044 11239.1 -3 2.49284 654.424 | ||
| 163 | + 25.1265 3951.81 -4 2.48007 578.148 | ||
| 164 | + 23.0302 769.247 -5 2.47567 541.654 | ||
| 165 | + 22.9323 165.457 -6 2.47509 538.451 | ||
| 166 | + 22.9315 13.9094 -7 2.47503 538.072 | ||
| 167 | + ============================== | ||
| 168 | + Variances and Principal Axes | ||
| 169 | + 1 2 | ||
| 170 | + 8.8843E-07| -1.0000 0.0001 | ||
| 171 | + 2.8990E+04| -0.0001 -1.0000 | ||
| 172 | + ------------------------------ | ||
| 173 | + | ||
| 174 | + ======================== | ||
| 175 | + Covariance Matrix | ||
| 176 | + 1 2 | ||
| 177 | + 2.326e-04 2.592e+00 | ||
| 178 | + 2.592e+00 2.899e+04 | ||
| 179 | + ------------------------ | ||
| 180 | + | ||
| 181 | + ======================================================================== | ||
| 182 | + Model powerlaw<1> Source No.: 1 Active/On | ||
| 183 | + Model Model Component Parameter Unit Value | ||
| 184 | + par comp | ||
| 185 | + 1 1 powerlaw PhoIndex 2.47503 +/- 1.52504E-02 | ||
| 186 | + 2 1 powerlaw norm 538.072 +/- 170.265 | ||
| 187 | + ________________________________________________________________________ | ||
| 188 | + | ||
| 189 | + | ||
| 190 | + Fit statistic : C-Statistic = 22.93 using 20 PHA bins and 18 degrees of freedom. | ||
| 191 | + | ||
| 192 | + Test statistic : Chi-Squared = 437.54 using 20 PHA bins. | ||
| 193 | + Reduced chi-squared = 24.308 for 18 degrees of freedom | ||
| 194 | + Null hypothesis probability = 1.317221e-81 | ||
| 195 | + | ||
| 196 | + ***Warning: Chi-square may not be valid due to bins with zero variance | ||
| 197 | + in spectrum number(s): 1 | ||
| 198 | + | ||
| 199 | + XSPEC12> | ||
| 200 | + | ||
| 201 | +The fit results are compared in the table below to the simulated true values | ||
| 202 | +and the values obtained using :ref:`ctlike` using the same spectral model. | ||
| 203 | +The | ||
| 204 | +`Xspec <https://heasarc.nasa.gov/xanadu/xspec/>`_ | ||
| 205 | +results are compatible with the simulated values and very close to the values | ||
| 206 | +obtained using :ref:`ctlike`. | ||
| 207 | + | ||
| 208 | + +-----------+-------+-----------------+-----------------+ | ||
| 209 | + | Parameter | Truth | Xspec | ctlike | | ||
| 210 | + +===========+=======+=================+=================+ | ||
| 211 | + | Prefactor | 601.4 | 538.0 +/- 170.3 | 536.4 +/- 184.2 | | ||
| 212 | + +-----------+-------+-----------------+-----------------+ | ||
| 213 | + | Index | 2.48 | 2.475 +/- 0.015 | 2.475 +/- 0.017 | | ||
| 214 | + +-----------+-------+-----------------+-----------------+ |
doc/source/users/tutorials/howto/index.rst
| @@ -17,6 +17,7 @@ CTA data analysis | @@ -17,6 +17,7 @@ CTA data analysis | ||
| 17 | howto_advanced_python_fitting | 17 | howto_advanced_python_fitting |
| 18 | howto_connect_irfs | 18 | howto_connect_irfs |
| 19 | howto_connect_models | 19 | howto_connect_models |
| 20 | + howto_xspec | ||
| 20 | 21 | ||
| 21 | 22 | ||
| 22 | CTA first Data Challenge data analysis | 23 | CTA first Data Challenge data analysis |