Commit 7ecbd97fa13ec983c088b1da51a2ea82b405131b
1 parent
3e80f463
Add How-to for joint analysis (#1868)
Showing
4 changed files
with
242 additions
and
23 deletions
cscripts/csspec.py
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | # ========================================================================== |
| 3 | 3 | # Generates a spectrum. |
| 4 | 4 | # |
| 5 | -# Copyright (C) 2014-2017 Michael Mayer | |
| 5 | +# Copyright (C) 2014-2018 Michael Mayer | |
| 6 | 6 | # |
| 7 | 7 | # This program is free software: you can redistribute it and/or modify |
| 8 | 8 | # it under the terms of the GNU General Public License as published by |
| ... | ... | @@ -100,26 +100,29 @@ class csspec(ctools.csobservation): |
| 100 | 100 | n_other = self.obs().size() - n_cta |
| 101 | 101 | |
| 102 | 102 | # If spectrum method is not "NODES" then set spectrum method and |
| 103 | - # script mode according to type of CTA observations | |
| 103 | + # script mode according to type of observations | |
| 104 | 104 | if self._method != 'NODES': |
| 105 | - if n_unbinned == 0 and n_binned != 0 and n_onoff == 0: | |
| 106 | - self._binned_mode = True | |
| 107 | - self._method = 'SLICE' | |
| 108 | - elif n_unbinned == 0 and n_binned == 0 and n_onoff != 0: | |
| 109 | - self._onoff_mode = True | |
| 110 | - self._method = 'SLICE' | |
| 111 | - elif n_unbinned == 0 and n_binned != 0 and n_onoff != 0: | |
| 112 | - msg = 'Mix of binned and On/Off CTA observations found in ' \ | |
| 113 | - 'observation container. csscript does not support this ' \ | |
| 114 | - 'mix.' | |
| 115 | - raise RuntimeError(msg) | |
| 116 | - elif n_unbinned != 0 and (n_binned != 0 or n_onoff != 0): | |
| 117 | - msg = 'Mix of unbinned and binned or On/Off CTA observations ' \ | |
| 118 | - 'found in observation container. csscript does not support ' \ | |
| 119 | - 'this mix.' | |
| 120 | - raise RuntimeError(msg) | |
| 121 | - elif n_unbinned != 0: | |
| 122 | - self._method = 'SLICE' | |
| 105 | + if n_other > 0: | |
| 106 | + self._method = 'NODES' | |
| 107 | + else: | |
| 108 | + if n_unbinned == 0 and n_binned != 0 and n_onoff == 0: | |
| 109 | + self._binned_mode = True | |
| 110 | + self._method = 'SLICE' | |
| 111 | + elif n_unbinned == 0 and n_binned == 0 and n_onoff != 0: | |
| 112 | + self._onoff_mode = True | |
| 113 | + self._method = 'SLICE' | |
| 114 | + elif n_unbinned == 0 and n_binned != 0 and n_onoff != 0: | |
| 115 | + msg = 'Mix of binned and On/Off CTA observations found ' \ | |
| 116 | + 'in observation container. csscript does not support ' \ | |
| 117 | + 'this mix.' | |
| 118 | + raise RuntimeError(msg) | |
| 119 | + elif n_unbinned != 0 and (n_binned != 0 or n_onoff != 0): | |
| 120 | + msg = 'Mix of unbinned and binned or On/Off CTA observations ' \ | |
| 121 | + 'found in observation container. csscript does not ' \ | |
| 122 | + 'support this mix.' | |
| 123 | + raise RuntimeError(msg) | |
| 124 | + elif n_unbinned != 0: | |
| 125 | + self._method = 'SLICE' | |
| 123 | 126 | |
| 124 | 127 | # Set ebounds |
| 125 | 128 | self._set_ebounds() |
| ... | ... | @@ -148,10 +151,9 @@ class csspec(ctools.csobservation): |
| 148 | 151 | # If there are a mix of CTA and non-CTA observations and the method |
| 149 | 152 | # is 'SLICE' then log a warning that non-CTA observations will be |
| 150 | 153 | # ignored |
| 154 | + warning = False | |
| 151 | 155 | if n_cta > 0 and n_other > 0 and self._method == 'SLICE': |
| 152 | - self._log_string(gammalib.TERSE, '\nWARNING: Only CTA observation ' | |
| 153 | - 'can be handled with the "SLICE" method, all ' | |
| 154 | - 'non-CTA observation will be ignored.') | |
| 156 | + warning = True | |
| 155 | 157 | |
| 156 | 158 | # If there are only non-CTA observations and the method is 'SLICE' |
| 157 | 159 | # then stop now |
| ... | ... | @@ -167,6 +169,12 @@ class csspec(ctools.csobservation): |
| 167 | 169 | # Log selected spectrum method |
| 168 | 170 | self._log_value(gammalib.TERSE, 'Selected spectrum method', self._method) |
| 169 | 171 | |
| 172 | + # Signal warning | |
| 173 | + if warning: | |
| 174 | + self._log_string(gammalib.TERSE, ' WARNING: Only CTA observation ' | |
| 175 | + 'can be handled with the "SLICE" method, all ' | |
| 176 | + 'non-CTA observation will be ignored.') | |
| 177 | + | |
| 170 | 178 | # Return |
| 171 | 179 | return |
| 172 | 180 | ... | ... |
doc/source/users/tutorials/howto/howto_combine_instruments.png
0 → 100644
29.8 KB
doc/source/users/tutorials/howto/howto_combine_instruments.rst
0 → 100644
| 1 | +.. _howto_combine_instrument: | |
| 2 | + | |
| 3 | +How to jointly analyse data from different instruments? | |
| 4 | +------------------------------------------------------- | |
| 5 | + | |
| 6 | + .. admonition:: What you will learn | |
| 7 | + | |
| 8 | + You will learn how to **jointly analyse data from different instruments**. | |
| 9 | + | |
| 10 | +In this tutorial you will learn how to jointly analyse data observed with | |
| 11 | +Fermi-LAT and simulated data for CTA for the Vela pulsar and pulsar wind | |
| 12 | +nebula. | |
| 13 | + | |
| 14 | +Prepare Fermi-LAT data | |
| 15 | +^^^^^^^^^^^^^^^^^^^^^^ | |
| 16 | + | |
| 17 | +The preparation of Fermi-LAT data will follow the one | |
| 18 | +`described in this section <howto_fermi_prepare>`_. | |
| 19 | + | |
| 20 | + | |
| 21 | +Prepare CTA data | |
| 22 | +^^^^^^^^^^^^^^^^ | |
| 23 | + | |
| 24 | +For CTA the simulations of the Galactic Plane Scan from the first Data Challenge | |
| 25 | +will be used, but if you do not have these data at hand you can create your own | |
| 26 | +simulated CTA dataset by | |
| 27 | +`following the description here <start_simulating>`_. | |
| 28 | + | |
| 29 | +First, bin the simulated data into a counts cube | |
| 30 | + | |
| 31 | +.. code-block:: bash | |
| 32 | + | |
| 33 | + $ ctbin | |
| 34 | + Input event list or observation definition XML file [events.fits] obs.xml | |
| 35 | + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] 128.838 | |
| 36 | + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.51] -45.178 | |
| 37 | + Projection method (AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN) [CAR] | |
| 38 | + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] | |
| 39 | + Image scale (in degrees/pixel) [0.02] | |
| 40 | + Size of the X axis in pixels [200] | |
| 41 | + Size of the Y axis in pixels [200] | |
| 42 | + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | |
| 43 | + Lower energy limit (TeV) [0.1] 0.03 | |
| 44 | + Upper energy limit (TeV) [100.0] 150.0 | |
| 45 | + Number of energy bins (1-200) [20] 40 | |
| 46 | + Output counts cube file [cntcube.fits] | |
| 47 | + | |
| 48 | +Then compute the response cubes as follows | |
| 49 | + | |
| 50 | +.. code-block:: bash | |
| 51 | + | |
| 52 | + $ ctexpcube | |
| 53 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 54 | + Input counts cube file to extract exposure cube definition [NONE] cntcube.fits | |
| 55 | + Output exposure cube file [expcube.fits] | |
| 56 | + | |
| 57 | +.. code-block:: bash | |
| 58 | + | |
| 59 | + $ ctpsfcube | |
| 60 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 61 | + Input counts cube file to extract PSF cube definition [NONE] | |
| 62 | + First coordinate of image center in degrees (RA or galactic l) (0-360) [83.63] 128.838 | |
| 63 | + Second coordinate of image center in degrees (DEC or galactic b) (-90-90) [22.51] -45.178 | |
| 64 | + Projection method (AIT|AZP|CAR|GLS|MER|MOL|SFL|SIN|STG|TAN) [CAR] | |
| 65 | + Coordinate system (CEL - celestial, GAL - galactic) (CEL|GAL) [CEL] | |
| 66 | + Image scale (in degrees/pixel) [1.0] | |
| 67 | + Size of the X axis in pixels [10] | |
| 68 | + Size of the Y axis in pixels [10] | |
| 69 | + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | |
| 70 | + Lower energy limit (TeV) [0.1] 0.03 | |
| 71 | + Upper energy limit (TeV) [100.0] 150.0 | |
| 72 | + Number of energy bins (1-200) [20] 40 | |
| 73 | + Output PSF cube file [psfcube.fits] | |
| 74 | + | |
| 75 | +.. code-block:: bash | |
| 76 | + | |
| 77 | + $ ctbkgcube | |
| 78 | + Input event list or observation definition XML file [NONE] obs.xml | |
| 79 | + Input counts cube file to extract background cube definition [NONE] cntcube.fits | |
| 80 | + Input model definition XML file [NONE] $CTOOLS/share/models/bkg_irf.xml | |
| 81 | + Output background cube file [bkgcube.fits] | |
| 82 | + Output model definition XML file [NONE] bkgcube.xml | |
| 83 | + | |
| 84 | + | |
| 85 | +Combining the observations | |
| 86 | +^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 87 | + | |
| 88 | +Now you have all the data and hand. You have to create an | |
| 89 | +:ref:`observation definition file <glossary_obsdef>` | |
| 90 | +to combine the data for an analysis: | |
| 91 | + | |
| 92 | +.. code-block:: xml | |
| 93 | + | |
| 94 | + <?xml version="1.0" standalone="no"?> | |
| 95 | + <observation_list title="observation library"> | |
| 96 | + <observation name="Vela" id="000001" instrument="CTA"> | |
| 97 | + <parameter name="CountsCube" file="cntcube.fits"/> | |
| 98 | + <parameter name="ExposureCube" file="expcube.fits"/> | |
| 99 | + <parameter name="PsfCube" file="psfcube.fits"/> | |
| 100 | + <parameter name="BkgCube" file="bkgcube.fits"/> | |
| 101 | + </observation> | |
| 102 | + <observation name="Vela" id="000001" instrument="LAT"> | |
| 103 | + <parameter name="CountsMap" file="srcmaps.fits"/> | |
| 104 | + <parameter name="ExposureMap" file="expmap.fits"/> | |
| 105 | + <parameter name="LiveTimeCube" file="ltcube.fits"/> | |
| 106 | + <parameter name="IRF" value="P8R2_SOURCE_V6"/> | |
| 107 | + </observation> | |
| 108 | + </observation_list> | |
| 109 | + | |
| 110 | +The | |
| 111 | +:ref:`observation definition file <glossary_obsdef>` | |
| 112 | +contains two observations of the Vela pulsar, a first done with CTA and a | |
| 113 | +second done with Fermi-LAT. The ``instrument`` attribute distinguishes between | |
| 114 | +both instruments. | |
| 115 | + | |
| 116 | + | |
| 117 | +Generate a spectral energy distribution | |
| 118 | +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
| 119 | + | |
| 120 | +Before being able to generate a spectral energy distribution (SED) you have | |
| 121 | +to define a | |
| 122 | +:ref:`model definition file <glossary_moddef>` | |
| 123 | +that will be used to model the events for both observations. | |
| 124 | +The model that will be used in this analysis is shown below: | |
| 125 | + | |
| 126 | +.. code-block:: xml | |
| 127 | + | |
| 128 | + <?xml version="1.0" standalone="no"?> | |
| 129 | + <source_library title="source library"> | |
| 130 | + <source type="PointSource" name="Vela"> | |
| 131 | + <spectrum type="PowerLaw"> | |
| 132 | + <parameter name="Prefactor" scale="1e-16" value="5.7" min="1e-07" max="1000.0" free="1"/> | |
| 133 | + <parameter name="Index" scale="-1" value="2.48" min="0.0" max="+5.0" free="1"/> | |
| 134 | + <parameter name="PivotEnergy" scale="1e6" value="0.3" min="0.01" max="1000.0" free="0"/> | |
| 135 | + </spectrum> | |
| 136 | + <spatialModel type="PointSource"> | |
| 137 | + <parameter name="RA" scale="1.0" value="128.84" min="-360" max="360" free="1"/> | |
| 138 | + <parameter name="DEC" scale="1.0" value="-45.18" min="-90" max="90" free="1"/> | |
| 139 | + </spatialModel> | |
| 140 | + </source> | |
| 141 | + <source type="DiffuseSource" name="Galactic_diffuse" instrument="LAT"> | |
| 142 | + <spectrum type="Constant"> | |
| 143 | + <parameter name="Normalization" scale="1.0" value="1.0" min="0.1" max="1000.0" free="1"/> | |
| 144 | + </spectrum> | |
| 145 | + <spatialModel type="DiffuseMapCube" file="gll_iem_v06.fits"> | |
| 146 | + <parameter name="Normalization" scale="1.0" value="1.0" min="0.1" max="10.0" free="0"/> | |
| 147 | + </spatialModel> | |
| 148 | + </source> | |
| 149 | + <source type="DiffuseSource" name="Extragalactic_diffuse" instrument="LAT"> | |
| 150 | + <spectrum type="FileFunction" file="iso_P8R2_SOURCE_V6_v06.txt"> | |
| 151 | + <parameter name="Normalization" scale="1.0" value="1.0" min="0.0" max="1000.0" free="0"/> | |
| 152 | + </spectrum> | |
| 153 | + <spatialModel type="DiffuseIsotropic"> | |
| 154 | + <parameter name="Value" scale="1.0" value="1.0" min="0.0" max="10.0" free="0"/> | |
| 155 | + </spatialModel> | |
| 156 | + </source> | |
| 157 | + <source name="Background" type="CTACubeBackground" instrument="CTA"> | |
| 158 | + <spectrum type="PowerLaw"> | |
| 159 | + <parameter name="Prefactor" scale="1.0" value="1.0" min="1e-3" max="1e+3" free="1"/> | |
| 160 | + <parameter name="Index" scale="1.0" value="0.0" min="-5.0" max="+5.0" free="1"/> | |
| 161 | + <parameter name="PivotEnergy" scale="1e6" value="1.0" min="0.01" max="1000.0" free="0"/> | |
| 162 | + </spectrum> | |
| 163 | + </source> | |
| 164 | + </source_library> | |
| 165 | + | |
| 166 | +The model contains a point source located at the position of the Vela pulsar | |
| 167 | +with a power law spectrum. In addition, it contains two ``DiffuseSource`` | |
| 168 | +components that are only applied for Fermi-LAT observations, which is indicated | |
| 169 | +by their ``instrument="LAT"`` attribute. Both components model the diffuse | |
| 170 | +background that prevails at GeV energies. Finally, the model contains a | |
| 171 | +``CTACubeBackground`` component that applies to CTA. You may have noticed that | |
| 172 | +the point source is the only component that has no ``instrument`` attribute, | |
| 173 | +meaning that this component applies to both instruments. | |
| 174 | + | |
| 175 | +Now you are ready to generate the spectral energy distribution for the | |
| 176 | +combined data set. You do this using the :ref:`csspec` script as follows | |
| 177 | + | |
| 178 | +.. code-block:: bash | |
| 179 | + | |
| 180 | + $ csspec | |
| 181 | + Input event list, counts cube, or observation definition XML file [events.fits] obs.xml | |
| 182 | + Input model definition XML file [$CTOOLS/share/models/crab.xml] models.xml | |
| 183 | + Source name [Crab] Vela | |
| 184 | + Spectrum generation method (SLICE|NODES|AUTO) [AUTO] | |
| 185 | + Algorithm for defining energy bins (FILE|LIN|LOG) [LOG] | |
| 186 | + Start value for first energy bin in TeV [0.1] 0.0001 | |
| 187 | + Stop value for last energy bin in TeV [100.0] 150.0 | |
| 188 | + Number of energy bins (1-200) [20] | |
| 189 | + Output spectrum file [spectrum.fits] | |
| 190 | + | |
| 191 | +This will generate a logarithmically spaced spectrum composed of 20 energy bins | |
| 192 | +comprised within 100 MeV and 150 TeV. The :ref:`csspec` tool is run in the ``AUTO`` | |
| 193 | +mode, which for different instruments corresponds to the ``NODES`` method. | |
| 194 | +The resulting spectral energy distribution is shown below: | |
| 195 | + | |
| 196 | +.. figure:: howto_combine_instruments.png | |
| 197 | + :width: 600px | |
| 198 | + :align: center | |
| 199 | + | |
| 200 | + *Vela spectrum derived using csspec from real Fermi-LAT and simulated CTA data* | |
| 201 | + | |
| 202 | +.. note:: | |
| 203 | + The figure was created using the ``show_spectrum.py`` script that is | |
| 204 | + located in the ctools example folder. The example script requires the | |
| 205 | + `matplotlib <http://matplotlib.org>`_ Python module for display. | |
| 206 | + You may reproduce the plot by typing | |
| 207 | + | |
| 208 | + .. code-block:: bash | |
| 209 | + | |
| 210 | + $ $CTOOLS/share/examples/python/show_spectrum.py spectrum.fits | ... | ... |
doc/source/users/tutorials/howto/index.rst