Commit 5540ec7488cd08eaf4cff1344d933b6d8395c46a
Merge branch '1323-write-tsmap' into integration
Showing
15 changed files
with
1275 additions
and
17 deletions
.gitignore
ChangeLog
| 1 | -2014-07-24 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 1 | +2014-10-06 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> | |
| 2 | 2 | |
| 3 | 3 | * Version 0.8.0 released |
| 4 | 4 | ======================== |
| ... | ... | @@ -10,6 +10,7 @@ |
| 10 | 10 | Add ctpsfcube tool (generates PSF cube) |
| 11 | 11 | Add ctbkgcube tool (generates background cube) |
| 12 | 12 | Add ctcubemask tool (masks event bins in event cube) |
| 13 | + Add cttsmap tool (generates TS map) | |
| 13 | 14 | Support energy dispersion in ctobssim, ctlike and ctmodel |
| 14 | 15 | Correct ctobssim for thread safety |
| 15 | 16 | Move obsutils to ctools namespace | ... | ... |
NEWS
| ... | ... | @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-08-00 |
| 2 | 2 | |
| 3 | 3 | Author(s) : Juergen Knoedlseder |
| 4 | 4 | |
| 5 | -24 July 2014 | |
| 5 | +6 October 2014 | |
| 6 | 6 | |
| 7 | 7 | |
| 8 | 8 | 1. Introduction |
| ... | ... | @@ -64,8 +64,8 @@ case of binning a single event list and using the usepnt=yes option |
| 64 | 64 | (or specifying the pointing manually as the xref and yref parameters). |
| 65 | 65 | |
| 66 | 66 | |
| 67 | -7. ctlike - CTA maximum likelihood fitting | |
| 68 | ------------------------------------------- | |
| 67 | +7. ctlike - Maximum likelihood fitting | |
| 68 | +-------------------------------------- | |
| 69 | 69 | ctlike now has full access to the calibration database, allowing |
| 70 | 70 | the use for 2D response functions in FITS files. |
| 71 | 71 | |
| ... | ... | @@ -73,13 +73,28 @@ ctlike now also supports the handling of energy dispersion. Energy |
| 73 | 73 | dispersion can be switched on or off using the hidden edisp parameter. |
| 74 | 74 | |
| 75 | 75 | |
| 76 | -8. ctskymap - CTA sky mapping | |
| 76 | +8. cttsmap - Generation of Test Statistics map | |
| 77 | +---------------------------------------------- | |
| 78 | +The cttsmap tool has been added that provides a test statistics map | |
| 79 | +for a given set of observations. This tool is not restricted to CTA | |
| 80 | +data and will work for all types of instruments. | |
| 81 | + | |
| 82 | +cttsmap will move a test sources over a specified grid of positions | |
| 83 | +and compute the likelihood difference between having the source at | |
| 84 | +a given position and having not the source. Twice the likelihood | |
| 85 | +difference is called the Test Statistic. The computation is done for | |
| 86 | +a grid of positions, and the results is saved into a FITS file as | |
| 87 | +TS map. Also the value of the fitted parameters are stored as | |
| 88 | +extension in the FITS file. | |
| 89 | + | |
| 90 | + | |
| 91 | +9. ctskymap - CTA sky mapping | |
| 77 | 92 | ----------------------------- |
| 78 | 93 | None |
| 79 | 94 | |
| 80 | 95 | |
| 81 | -9. ctmodel - CTA counts map modelling | |
| 82 | -------------------------------------- | |
| 96 | +10. ctmodel - CTA counts map modelling | |
| 97 | +-------------------------------------- | |
| 83 | 98 | ctmodel now has full access to the calibration database, allowing |
| 84 | 99 | the use for 2D response functions in FITS files. |
| 85 | 100 | |
| ... | ... | @@ -87,7 +102,7 @@ ctmodel now also supports the handling of energy dispersion. Energy |
| 87 | 102 | dispersion can be switched on or off using the hidden edisp parameter. |
| 88 | 103 | |
| 89 | 104 | |
| 90 | -10. ctexpcube - CTA exposure cube generation | |
| 105 | +11. ctexpcube - CTA exposure cube generation | |
| 91 | 106 | -------------------------------------------- |
| 92 | 107 | The first version of the ctexpcube tool is included in the release. |
| 93 | 108 | ctexpcube computes the exposure cube for an observation definition |
| ... | ... | @@ -95,7 +110,7 @@ file. The cube definition may be taken from a counts cube or may be |
| 95 | 110 | specified by user parameters. |
| 96 | 111 | |
| 97 | 112 | |
| 98 | -11. ctpsfcube - CTA point spread function cube generation | |
| 113 | +12. ctpsfcube - CTA point spread function cube generation | |
| 99 | 114 | --------------------------------------------------------- |
| 100 | 115 | The first version of the ctpsfcube tool is included in the release. |
| 101 | 116 | ctpsfcube computes the point spread function cube for an observation |
| ... | ... | @@ -103,7 +118,7 @@ definition file. The cube definition may be taken from a counts cube |
| 103 | 118 | or may be specified by user parameters. |
| 104 | 119 | |
| 105 | 120 | |
| 106 | -12. ctbkgcube - CTA background cube generation | |
| 121 | +13. ctbkgcube - CTA background cube generation | |
| 107 | 122 | ---------------------------------------------- |
| 108 | 123 | The first version of the ctbkgcube tool is included in the release. |
| 109 | 124 | ctbkgcube computes the background cube for an observation definition |
| ... | ... | @@ -111,7 +126,7 @@ file. The cube definition may be taken from a counts cube or may be |
| 111 | 126 | specified by user parameters. |
| 112 | 127 | |
| 113 | 128 | |
| 114 | -13. ctcubemask - CTA cube filtering | |
| 129 | +14. ctcubemask - CTA cube filtering | |
| 115 | 130 | ----------------------------------- |
| 116 | 131 | The first version of the ctcubemask tool is included in the release. |
| 117 | 132 | ctcubemask allows filtering of bins in a counts cube by setting the |
| ... | ... | @@ -119,12 +134,12 @@ bin content to -1. Filtering can be done by energy, for a circular |
| 119 | 134 | Region of Interest (ROI) or using ds9 exclusion regions. |
| 120 | 135 | |
| 121 | 136 | |
| 122 | -14. Examples | |
| 137 | +15. Examples | |
| 123 | 138 | ------------ |
| 124 | 139 | None |
| 125 | 140 | |
| 126 | 141 | |
| 127 | -15. Scripts | |
| 142 | +16. Scripts | |
| 128 | 143 | ----------- |
| 129 | 144 | Add logL and event statistics to cspull output file. |
| 130 | 145 | |
| ... | ... | @@ -144,11 +159,11 @@ The following functions have been added to obsutils: |
| 144 | 159 | specified energy bins. |
| 145 | 160 | |
| 146 | 161 | |
| 147 | -16. caldb | |
| 162 | +17. caldb | |
| 148 | 163 | --------- |
| 149 | 164 | None |
| 150 | 165 | |
| 151 | 166 | |
| 152 | -17. models | |
| 167 | +18. models | |
| 153 | 168 | ---------- |
| 154 | 169 | None | ... | ... |
configure.ac
pyext/ctools/ctools.i
pyext/cttsmap.i
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * cttsmap - TS map calculation tool * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2014 by Michael Mayer * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file cttsmap.i | |
| 23 | + * @brief TS map calculation tool interface definition | |
| 24 | + * @author Michael Mayer | |
| 25 | + */ | |
| 26 | +%{ | |
| 27 | +/* Put headers and other declarations here that are needed for compilation */ | |
| 28 | +#include "cttsmap.hpp" | |
| 29 | +#include "GTools.hpp" | |
| 30 | +%} | |
| 31 | + | |
| 32 | + | |
| 33 | +/***********************************************************************//** | |
| 34 | + * @class cttsmap | |
| 35 | + * | |
| 36 | + * @brief TS map calculation | |
| 37 | + ***************************************************************************/ | |
| 38 | +class cttsmap : public GApplication { | |
| 39 | +public: | |
| 40 | + // Constructors and destructors | |
| 41 | + cttsmap(void); | |
| 42 | + explicit cttsmap(const GObservations& obs); | |
| 43 | + cttsmap(int argc, char *argv[]); | |
| 44 | + cttsmap(const cttsmap& app); | |
| 45 | + virtual ~cttsmap(void); | |
| 46 | + | |
| 47 | + // Methods | |
| 48 | + void clear(void); | |
| 49 | + void execute(void); | |
| 50 | + void run(void); | |
| 51 | + void save(void); | |
| 52 | + const GObservations& obs(void) const; | |
| 53 | + const GSkymap& tsmap(void) const; | |
| 54 | +}; | |
| 55 | + | |
| 56 | + | |
| 57 | +/***********************************************************************//** | |
| 58 | + * @brief TS map calculation tool Python extensions | |
| 59 | + ***************************************************************************/ | |
| 60 | +%extend cttsmap { | |
| 61 | + cttsmap copy() { | |
| 62 | + return (*self); | |
| 63 | + } | |
| 64 | +} | ... | ... |
src/Makefile.am
| ... | ... | @@ -14,7 +14,8 @@ SUBDIRS = ctbin \ |
| 14 | 14 | ctexpcube \ |
| 15 | 15 | ctpsfcube \ |
| 16 | 16 | ctbkgcube \ |
| 17 | - ctcubemask | |
| 17 | + ctcubemask \ | |
| 18 | + cttsmap | |
| 18 | 19 | |
| 19 | 20 | # Scripts to be distributed |
| 20 | 21 | scripts = ctools-setup \ |
| ... | ... | @@ -35,7 +36,8 @@ libctools_la_LIBADD = ctbin/libctbin.la \ |
| 35 | 36 | ctexpcube/libctexpcube.la \ |
| 36 | 37 | ctpsfcube/libctpsfcube.la \ |
| 37 | 38 | ctbkgcube/libctbkgcube.la \ |
| 38 | - ctcubemask/libctcubemask.la | |
| 39 | + ctcubemask/libctcubemask.la \ | |
| 40 | + cttsmap/libcttsmap.la | |
| 39 | 41 | |
| 40 | 42 | # Distribute scripts |
| 41 | 43 | EXTRA_DIST = $(scripts) | ... | ... |
src/cttsmap/Makefile.am
0 → 100644
| 1 | +## Process this file with automake to produce Makefile.in | |
| 2 | + | |
| 3 | +# Program name | |
| 4 | +bin_PROGRAMS = cttsmap | |
| 5 | + | |
| 6 | +# Sources | |
| 7 | +sources = cttsmap.cpp | |
| 8 | + | |
| 9 | +# Libtool library | |
| 10 | +noinst_LTLIBRARIES = libcttsmap.la | |
| 11 | +libcttsmap_la_SOURCES = $(sources) | |
| 12 | + | |
| 13 | +# Program definition | |
| 14 | +cttsmap_SOURCES = main.cpp | |
| 15 | +cttsmap_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ | |
| 16 | +cttsmap_CPPFLAGS = @CPPFLAGS@ | |
| 17 | +cttsmap_LDADD = libcttsmap.la | |
| 18 | + | |
| 19 | +# Parameter files | |
| 20 | +pfilesdir = $(prefix)/syspfiles | |
| 21 | +pfiles_DATA = cttsmap.par | ... | ... |
src/cttsmap/cttsmap.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * cttsmap - TS map calculation tool * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2014 by Michael Mayer * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file cttsmap.hpp | |
| 23 | + * @brief TS map calculation tool interface implementation | |
| 24 | + * @author Michael Mayer | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include <cstdio> | |
| 32 | +#include "cttsmap.hpp" | |
| 33 | +#include "GTools.hpp" | |
| 34 | + | |
| 35 | +/* __ Method name definitions ____________________________________________ */ | |
| 36 | +#define G_GET_PARAMETERS "cttsmap::get_parameters()" | |
| 37 | + | |
| 38 | +/* __ Debug definitions __________________________________________________ */ | |
| 39 | + | |
| 40 | +/* __ Coding definitions _________________________________________________ */ | |
| 41 | + | |
| 42 | + | |
| 43 | +/*========================================================================== | |
| 44 | + = = | |
| 45 | + = Constructors/destructors = | |
| 46 | + = = | |
| 47 | + ==========================================================================*/ | |
| 48 | + | |
| 49 | +/***********************************************************************//** | |
| 50 | + * @brief Void constructor | |
| 51 | + ***************************************************************************/ | |
| 52 | +cttsmap::cttsmap(void) : GApplication(CTTSMAP_NAME, CTTSMAP_VERSION) | |
| 53 | +{ | |
| 54 | + // Initialise members | |
| 55 | + init_members(); | |
| 56 | + | |
| 57 | + // Write header into logger | |
| 58 | + log_header(); | |
| 59 | + | |
| 60 | + // Return | |
| 61 | + return; | |
| 62 | +} | |
| 63 | + | |
| 64 | + | |
| 65 | +/***********************************************************************//** | |
| 66 | + * @brief Observations constructor | |
| 67 | + * | |
| 68 | + * param[in] obs Observation container. | |
| 69 | + * | |
| 70 | + * This method creates an instance of the class by copying an existing | |
| 71 | + * observations container. | |
| 72 | + ***************************************************************************/ | |
| 73 | +cttsmap::cttsmap(const GObservations& obs) : | |
| 74 | + GApplication(CTTSMAP_NAME, CTTSMAP_VERSION) | |
| 75 | +{ | |
| 76 | + // Initialise members | |
| 77 | + init_members(); | |
| 78 | + | |
| 79 | + // Set observations | |
| 80 | + m_obs = obs; | |
| 81 | + | |
| 82 | + // Write header into logger | |
| 83 | + log_header(); | |
| 84 | + | |
| 85 | + // Return | |
| 86 | + return; | |
| 87 | +} | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | +/***********************************************************************//** | |
| 92 | + * @brief Command line constructor | |
| 93 | + * | |
| 94 | + * @param[in] argc Number of arguments in command line. | |
| 95 | + * @param[in] argv Array of command line arguments. | |
| 96 | + ***************************************************************************/ | |
| 97 | +cttsmap::cttsmap(int argc, char *argv[]) : | |
| 98 | + GApplication(CTTSMAP_NAME, CTTSMAP_VERSION, argc, argv) | |
| 99 | +{ | |
| 100 | + // Initialise members | |
| 101 | + init_members(); | |
| 102 | + | |
| 103 | + // Write header into logger | |
| 104 | + log_header(); | |
| 105 | + | |
| 106 | + // Return | |
| 107 | + return; | |
| 108 | +} | |
| 109 | + | |
| 110 | + | |
| 111 | +/***********************************************************************//** | |
| 112 | + * @brief Copy constructor | |
| 113 | + * | |
| 114 | + * @param[in] app Application. | |
| 115 | + ***************************************************************************/ | |
| 116 | +cttsmap::cttsmap(const cttsmap& app) : GApplication(app) | |
| 117 | +{ | |
| 118 | + // Initialise members | |
| 119 | + init_members(); | |
| 120 | + | |
| 121 | + // Copy members | |
| 122 | + copy_members(app); | |
| 123 | + | |
| 124 | + // Return | |
| 125 | + return; | |
| 126 | +} | |
| 127 | + | |
| 128 | + | |
| 129 | +/***********************************************************************//** | |
| 130 | + * @brief Destructor | |
| 131 | + ***************************************************************************/ | |
| 132 | +cttsmap::~cttsmap(void) | |
| 133 | +{ | |
| 134 | + // Free members | |
| 135 | + free_members(); | |
| 136 | + | |
| 137 | + // Return | |
| 138 | + return; | |
| 139 | +} | |
| 140 | + | |
| 141 | + | |
| 142 | +/*========================================================================== | |
| 143 | + = = | |
| 144 | + = Operators = | |
| 145 | + = = | |
| 146 | + ==========================================================================*/ | |
| 147 | + | |
| 148 | +/***********************************************************************//** | |
| 149 | + * @brief Assignment operator | |
| 150 | + * | |
| 151 | + * @param[in] app Application. | |
| 152 | + ***************************************************************************/ | |
| 153 | +cttsmap& cttsmap::operator=(const cttsmap& app) | |
| 154 | +{ | |
| 155 | + // Execute only if object is not identical | |
| 156 | + if (this != &app) { | |
| 157 | + | |
| 158 | + // Copy base class members | |
| 159 | + this->GApplication::operator=(app); | |
| 160 | + | |
| 161 | + // Free members | |
| 162 | + free_members(); | |
| 163 | + | |
| 164 | + // Initialise members | |
| 165 | + init_members(); | |
| 166 | + | |
| 167 | + // Copy members | |
| 168 | + copy_members(app); | |
| 169 | + | |
| 170 | + } // endif: object was not identical | |
| 171 | + | |
| 172 | + // Return this object | |
| 173 | + return *this; | |
| 174 | +} | |
| 175 | + | |
| 176 | + | |
| 177 | +/*========================================================================== | |
| 178 | + = = | |
| 179 | + = Public methods = | |
| 180 | + = = | |
| 181 | + ==========================================================================*/ | |
| 182 | + | |
| 183 | +/***********************************************************************//** | |
| 184 | + * @brief Clear instance | |
| 185 | + ***************************************************************************/ | |
| 186 | +void cttsmap::clear(void) | |
| 187 | +{ | |
| 188 | + // Free members | |
| 189 | + free_members(); | |
| 190 | + this->GApplication::free_members(); | |
| 191 | + | |
| 192 | + // Initialise members | |
| 193 | + this->GApplication::init_members(); | |
| 194 | + init_members(); | |
| 195 | + | |
| 196 | + // Return | |
| 197 | + return; | |
| 198 | +} | |
| 199 | + | |
| 200 | + | |
| 201 | +/***********************************************************************//** | |
| 202 | + * @brief Execute application | |
| 203 | + * | |
| 204 | + * This is the main execution method of the cttsmap class. It is invoked when | |
| 205 | + * the executable is called from command line. | |
| 206 | + * | |
| 207 | + * The method reads the task parameters, computes the TS values, stores the | |
| 208 | + * results into map(s), and writes the maps into a FITS file on disk. | |
| 209 | + ***************************************************************************/ | |
| 210 | +void cttsmap::execute(void) | |
| 211 | +{ | |
| 212 | + // Signal that some parameters should be read ahead | |
| 213 | + m_read_ahead = true; | |
| 214 | + | |
| 215 | + // Compute the maps | |
| 216 | + run(); | |
| 217 | + | |
| 218 | + // Save the maps into FITS file | |
| 219 | + save(); | |
| 220 | + | |
| 221 | + // Return | |
| 222 | + return; | |
| 223 | +} | |
| 224 | + | |
| 225 | + | |
| 226 | +/***********************************************************************//** | |
| 227 | + * @brief Computes the TS maps | |
| 228 | + * | |
| 229 | + * This method moves a source along a grid of coordinates and refits the | |
| 230 | + * given models including this additional source. The fit parameters of the | |
| 231 | + * source and its TS values are filled into respective position in the map. | |
| 232 | + ***************************************************************************/ | |
| 233 | +void cttsmap::run(void) | |
| 234 | +{ | |
| 235 | + // If we're in debug mode then all output is also dumped on the screen | |
| 236 | + if (logDebug()) { | |
| 237 | + log.cout(true); | |
| 238 | + } | |
| 239 | + | |
| 240 | + // Get task parameters | |
| 241 | + get_parameters(); | |
| 242 | + | |
| 243 | + // Write parameters into logger | |
| 244 | + if (logTerse()) { | |
| 245 | + log_parameters(); | |
| 246 | + log << std::endl; | |
| 247 | + } | |
| 248 | + | |
| 249 | + // Write observation(s) into logger | |
| 250 | + if (logTerse()) { | |
| 251 | + log << std::endl; | |
| 252 | + if (m_obs.size() > 1) { | |
| 253 | + log.header1("Observations"); | |
| 254 | + } | |
| 255 | + else { | |
| 256 | + log.header1("Observation"); | |
| 257 | + } | |
| 258 | + log << m_obs << std::endl; | |
| 259 | + } | |
| 260 | + | |
| 261 | + // Write header | |
| 262 | + if (logTerse()) { | |
| 263 | + log << std::endl; | |
| 264 | + log.header1("Initialise TS map"); | |
| 265 | + } | |
| 266 | + | |
| 267 | + // Initialise maps | |
| 268 | + init_maps(); | |
| 269 | + | |
| 270 | + // Get bins to be computed | |
| 271 | + // To split the computation on several jobs, | |
| 272 | + // the user is able to provide a subset of bins | |
| 273 | + // which should be computed | |
| 274 | + int binmin = (m_binmin == -1) ? 0 : m_binmin; | |
| 275 | + int binmax = (m_binmax == -1) ? m_tsmap.npix() : m_binmax; | |
| 276 | + | |
| 277 | + // Initialise optimizer | |
| 278 | + GOptimizerLM* opt = (logExplicit()) ? new GOptimizerLM(log) | |
| 279 | + : new GOptimizerLM(); | |
| 280 | + | |
| 281 | + // Store initial models | |
| 282 | + GModels models_orig = m_obs.models(); | |
| 283 | + | |
| 284 | + // Get model instance for further computations | |
| 285 | + GModels models = m_obs.models(); | |
| 286 | + | |
| 287 | + // Remove test source | |
| 288 | + models.remove(m_srcname); | |
| 289 | + | |
| 290 | + // Get likelihood of null hypothesis if not given before | |
| 291 | + if (m_logL0 == 0.0) { | |
| 292 | + | |
| 293 | + // Write header | |
| 294 | + if (logTerse()) { | |
| 295 | + log << std::endl; | |
| 296 | + log.header1("Compute NULL Hypothesis for TS computation"); | |
| 297 | + } | |
| 298 | + | |
| 299 | + // Compute likelihood without the test source | |
| 300 | + m_obs.models(models); | |
| 301 | + m_obs.optimize(*opt); | |
| 302 | + m_logL0 = -(opt->value()); | |
| 303 | + | |
| 304 | + } | |
| 305 | + | |
| 306 | + // Write header | |
| 307 | + if (logTerse()) { | |
| 308 | + log << std::endl; | |
| 309 | + log.header1("Generate TS map"); | |
| 310 | + } | |
| 311 | + | |
| 312 | + // Loop over grid positions | |
| 313 | + for (int i = binmin; i < binmax; ++i) { | |
| 314 | + | |
| 315 | + // Get the coordinate of current bin | |
| 316 | + GSkyDir bincentre = m_tsmap.inx2dir(i); | |
| 317 | + | |
| 318 | + // Header for verbose logging | |
| 319 | + if (logExplicit()) { | |
| 320 | + std::string msg = "Computing TS for bin number "+gammalib::str(i)+ | |
| 321 | + " at "+bincentre.print(); | |
| 322 | + log << std::endl; | |
| 323 | + log.header2(msg); | |
| 324 | + } | |
| 325 | + | |
| 326 | + // Add test source at current bin position | |
| 327 | + if (m_testsource != NULL) { | |
| 328 | + (*m_testsource)["RA"].value(bincentre.ra_deg()); | |
| 329 | + (*m_testsource)["DEC"].value(bincentre.dec_deg()); | |
| 330 | + models.append(*m_testsource); | |
| 331 | + } | |
| 332 | + | |
| 333 | + // Assign models to observations | |
| 334 | + m_obs.models(models); | |
| 335 | + | |
| 336 | + // Optimize observation container | |
| 337 | + m_obs.optimize(*opt); | |
| 338 | + | |
| 339 | + // Retrieve the Likelihood value | |
| 340 | + double logL1 = -(opt->value()); | |
| 341 | + | |
| 342 | + // Compute TS value | |
| 343 | + double ts = 2.0 * (logL1 - m_logL0); | |
| 344 | + | |
| 345 | + // Log information | |
| 346 | + if (logExplicit()) { | |
| 347 | + log << " TS value ....: "; | |
| 348 | + log << ts << std::endl; | |
| 349 | + } | |
| 350 | + else if (logTerse()) { | |
| 351 | + log << "TS for bin number "; | |
| 352 | + log << i; | |
| 353 | + log << " at "; | |
| 354 | + log << bincentre.print(); | |
| 355 | + log << ": "; | |
| 356 | + log << ts << std::endl; | |
| 357 | + } | |
| 358 | + | |
| 359 | + // Get test source model instance | |
| 360 | + GModels best_fit_model = m_obs.models(); | |
| 361 | + GModel* testsource = best_fit_model[m_srcname]; | |
| 362 | + | |
| 363 | + // Assign values to the maps | |
| 364 | + m_tsmap(i) = ts; | |
| 365 | + | |
| 366 | + // Extract fitted test source parameters | |
| 367 | + if (m_testsource != NULL) { | |
| 368 | + for (int j = 0; j < m_mapnames.size(); ++j) { | |
| 369 | + m_maps[j](i) = (*testsource)[m_mapnames[j]].value(); | |
| 370 | + } | |
| 371 | + } | |
| 372 | + | |
| 373 | + // Set status of bin to true | |
| 374 | + m_statusmap(i) = 1.0; | |
| 375 | + | |
| 376 | + // Remove model from container | |
| 377 | + models.remove(m_srcname); | |
| 378 | + | |
| 379 | + } // endfor: looped over grid positions | |
| 380 | + | |
| 381 | + // Bring models to initial state | |
| 382 | + m_obs.models(models_orig); | |
| 383 | + | |
| 384 | + // Return | |
| 385 | + return; | |
| 386 | +} | |
| 387 | + | |
| 388 | + | |
| 389 | +/***********************************************************************//** | |
| 390 | + * @brief Save maps | |
| 391 | + * | |
| 392 | + * This method saves the TS map and additional maps into a FITS file. | |
| 393 | + ***************************************************************************/ | |
| 394 | +void cttsmap::save(void) | |
| 395 | +{ | |
| 396 | + // Write header | |
| 397 | + if (logTerse()) { | |
| 398 | + log << std::endl; | |
| 399 | + log.header1("Save TS map"); | |
| 400 | + } | |
| 401 | + | |
| 402 | + // Get output filename | |
| 403 | + m_outfile = (*this)["outfile"].filename(); | |
| 404 | + | |
| 405 | + // Create fits file instance | |
| 406 | + GFits fitsfile = GFits(); | |
| 407 | + | |
| 408 | + // Write the sky maps to the FITS file | |
| 409 | + m_tsmap.write(fitsfile); | |
| 410 | + for (int i = 0; i < m_mapnames.size(); i++) { | |
| 411 | + m_maps[i].write(fitsfile); | |
| 412 | + } | |
| 413 | + | |
| 414 | + // Set extension name for all maps | |
| 415 | + for (int i = 0; i < m_mapnames.size(); i++) { | |
| 416 | + fitsfile[i+1]->extname(m_mapnames[i]); | |
| 417 | + } | |
| 418 | + | |
| 419 | + // Add computation log if not all bins are computed | |
| 420 | + if (m_binmin != -1 || m_binmax != -1) { | |
| 421 | + m_statusmap.write(fitsfile); | |
| 422 | + fitsfile[m_mapnames.size()+1]->extname("STATUS MAP"); | |
| 423 | + } | |
| 424 | + | |
| 425 | + // Save FITS file | |
| 426 | + fitsfile.saveto(m_outfile,true); | |
| 427 | + | |
| 428 | + // Return | |
| 429 | + return; | |
| 430 | +} | |
| 431 | + | |
| 432 | + | |
| 433 | +/*========================================================================== | |
| 434 | + = = | |
| 435 | + = Private methods = | |
| 436 | + = = | |
| 437 | + ==========================================================================*/ | |
| 438 | + | |
| 439 | +/***********************************************************************//** | |
| 440 | + * @brief Initialise class members | |
| 441 | + ***************************************************************************/ | |
| 442 | +void cttsmap::init_members(void) | |
| 443 | +{ | |
| 444 | + // Initialise members | |
| 445 | + m_infile.clear(); | |
| 446 | + m_caldb.clear(); | |
| 447 | + m_irf.clear(); | |
| 448 | + m_outfile.clear(); | |
| 449 | + m_proj.clear(); | |
| 450 | + m_coordsys.clear(); | |
| 451 | + m_xref = 0.0; | |
| 452 | + m_yref = 0.0; | |
| 453 | + m_binsz = 0.0; | |
| 454 | + m_nxpix = 0; | |
| 455 | + m_nypix = 0; | |
| 456 | + | |
| 457 | + // Initialise protected members | |
| 458 | + m_obs.clear(); | |
| 459 | + m_read_ahead = false; | |
| 460 | + m_binmin = -1; | |
| 461 | + m_binmax = -1; | |
| 462 | + m_logL0 = 0.0; | |
| 463 | + m_tsmap.clear(); | |
| 464 | + m_statusmap.clear(); | |
| 465 | + m_mapnames.clear(); | |
| 466 | + m_maps.clear(); | |
| 467 | + m_testsource = NULL; | |
| 468 | + | |
| 469 | + // Set logger properties | |
| 470 | + log.date(true); | |
| 471 | + | |
| 472 | + // Return | |
| 473 | + return; | |
| 474 | +} | |
| 475 | + | |
| 476 | + | |
| 477 | +/***********************************************************************//** | |
| 478 | + * @brief Copy class members | |
| 479 | + * | |
| 480 | + * @param[in] app Application. | |
| 481 | + ***************************************************************************/ | |
| 482 | +void cttsmap::copy_members(const cttsmap& app) | |
| 483 | +{ | |
| 484 | + // Copy attributes | |
| 485 | + m_infile = app.m_infile; | |
| 486 | + m_caldb = app.m_caldb; | |
| 487 | + m_irf = app.m_irf; | |
| 488 | + m_outfile = app.m_outfile; | |
| 489 | + m_proj = app.m_proj; | |
| 490 | + m_coordsys = app.m_coordsys; | |
| 491 | + m_xref = app.m_xref; | |
| 492 | + m_yref = app.m_yref; | |
| 493 | + m_binsz = app.m_binsz; | |
| 494 | + m_nxpix = app.m_nxpix; | |
| 495 | + m_nypix = app.m_nypix; | |
| 496 | + | |
| 497 | + // Copy protected members | |
| 498 | + m_binmin = app.m_binmin; | |
| 499 | + m_binmax = app.m_binmax; | |
| 500 | + m_logL0 = app.m_logL0; | |
| 501 | + m_obs = app.m_obs; | |
| 502 | + m_read_ahead = app.m_read_ahead; | |
| 503 | + m_tsmap = app.m_tsmap; | |
| 504 | + m_mapnames = app.m_mapnames; | |
| 505 | + m_maps = app.m_maps; | |
| 506 | + m_statusmap = app.m_statusmap; | |
| 507 | + | |
| 508 | + // Clone protected members | |
| 509 | + m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() : NULL; | |
| 510 | + | |
| 511 | + // Return | |
| 512 | + return; | |
| 513 | +} | |
| 514 | + | |
| 515 | + | |
| 516 | +/***********************************************************************//** | |
| 517 | + * @brief Delete class members | |
| 518 | + ***************************************************************************/ | |
| 519 | +void cttsmap::free_members(void) | |
| 520 | +{ | |
| 521 | + // Write separator into logger | |
| 522 | + if (logTerse()) { | |
| 523 | + log << std::endl; | |
| 524 | + } | |
| 525 | + | |
| 526 | + // Return | |
| 527 | + return; | |
| 528 | +} | |
| 529 | + | |
| 530 | + | |
| 531 | +/***********************************************************************//** | |
| 532 | + * @brief Get application parameters | |
| 533 | + * | |
| 534 | + * @exception GException::invalid_value | |
| 535 | + * Test source not found or no RA/DEC parameters found for test | |
| 536 | + * source. | |
| 537 | + * | |
| 538 | + * Get all task parameters from parameter file or (if required) by querying | |
| 539 | + * the user. Most parameters are only required if no observation exists so | |
| 540 | + * far in the observation container. In this case, a single CTA observation | |
| 541 | + * will be added to the container, using the definition provided in the | |
| 542 | + * parameter file. | |
| 543 | + ***************************************************************************/ | |
| 544 | +void cttsmap::get_parameters(void) | |
| 545 | +{ | |
| 546 | + // If there are no observations in container then add a single CTA | |
| 547 | + // observation using the parameters from the parameter file | |
| 548 | + if (m_obs.size() == 0) { | |
| 549 | + | |
| 550 | + // Allocate CTA observation | |
| 551 | + GCTAObservation obs; | |
| 552 | + | |
| 553 | + // Get event file name | |
| 554 | + std::string filename = (*this)["infile"].filename(); | |
| 555 | + | |
| 556 | + // Try first to open as FITS file | |
| 557 | + try { | |
| 558 | + | |
| 559 | + // Load data | |
| 560 | + obs.load(filename); | |
| 561 | + | |
| 562 | + // Get other task parameters | |
| 563 | + m_caldb = (*this)["caldb"].string(); | |
| 564 | + m_irf = (*this)["irf"].string(); | |
| 565 | + | |
| 566 | + // Set calibration database. If specified parameter is a | |
| 567 | + // directory then use this as the pathname to the calibration | |
| 568 | + // database. Otherwise interpret this as the instrument name, | |
| 569 | + // the mission being "cta" | |
| 570 | + GCaldb caldb; | |
| 571 | + if (gammalib::dir_exists(m_caldb)) { | |
| 572 | + caldb.rootdir(m_caldb); | |
| 573 | + } | |
| 574 | + else { | |
| 575 | + caldb.open("cta", m_caldb); | |
| 576 | + } | |
| 577 | + | |
| 578 | + // Set reponse | |
| 579 | + obs.response(m_irf, caldb); | |
| 580 | + | |
| 581 | + // Append observation to container | |
| 582 | + m_obs.append(obs); | |
| 583 | + | |
| 584 | + } | |
| 585 | + | |
| 586 | + // ... otherwise try to open as XML file | |
| 587 | + catch (GException::fits_open_error &e) { | |
| 588 | + | |
| 589 | + // Load observations from XML file | |
| 590 | + m_obs.load(filename); | |
| 591 | + | |
| 592 | + // Check if all observations have response information. If | |
| 593 | + // not, get the calibration database parameters and set | |
| 594 | + // the response properly | |
| 595 | + bool asked_for_response = false; | |
| 596 | + for (int i = 0; i < m_obs.size(); ++i) { | |
| 597 | + | |
| 598 | + // Get CTA observation | |
| 599 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | |
| 600 | + | |
| 601 | + // Continue only if observation is a CTA observation | |
| 602 | + if (obs != NULL) { | |
| 603 | + | |
| 604 | + // If response is not valid then set response from | |
| 605 | + // task parameters | |
| 606 | + if (!obs->has_response()) { | |
| 607 | + | |
| 608 | + // Get calibration parameters | |
| 609 | + if (!asked_for_response) { | |
| 610 | + m_caldb = (*this)["caldb"].string(); | |
| 611 | + m_irf = (*this)["irf"].string(); | |
| 612 | + asked_for_response = true; | |
| 613 | + } | |
| 614 | + | |
| 615 | + // Set response | |
| 616 | + GCaldb caldb; | |
| 617 | + if (gammalib::dir_exists(m_caldb)) { | |
| 618 | + caldb.rootdir(m_caldb); | |
| 619 | + } | |
| 620 | + else { | |
| 621 | + caldb.open("cta", m_caldb); | |
| 622 | + } | |
| 623 | + obs->response(m_irf, caldb); | |
| 624 | + | |
| 625 | + } // endif: there was no response | |
| 626 | + } // endif: observation was a CTA observation | |
| 627 | + | |
| 628 | + } // endfor: looped over observations | |
| 629 | + | |
| 630 | + } // endcatch: file was an XML file | |
| 631 | + | |
| 632 | + } // endif: there was no observation in the container | |
| 633 | + | |
| 634 | + // If there is are no models associated with the observations then | |
| 635 | + // load now the model definition | |
| 636 | + if (m_obs.models().size() == 0) { | |
| 637 | + | |
| 638 | + // Get models XML filename | |
| 639 | + std::string filename = (*this)["srcmdl"].filename(); | |
| 640 | + | |
| 641 | + // Setup models for optimizing. | |
| 642 | + m_obs.models(GModels(filename)); | |
| 643 | + | |
| 644 | + } // endif: no models were associated with observations | |
| 645 | + | |
| 646 | + // Get name of test source and check container for this name | |
| 647 | + m_srcname = (*this)["srcname"].string(); | |
| 648 | + if (!m_obs.models().contains(m_srcname)) { | |
| 649 | + std::string msg = "Source \""+m_srcname+"\" not found in model " | |
| 650 | + "container. Please add a source with that name " | |
| 651 | + "or check for a possible typos."; | |
| 652 | + throw GException::invalid_value(G_GET_PARAMETERS, msg); | |
| 653 | + } | |
| 654 | + | |
| 655 | + // Get Model and store it as protected member | |
| 656 | + m_testsource = m_obs.models()[m_srcname]->clone(); | |
| 657 | + | |
| 658 | + // Check if model has RA and DEC parameters which are necessary to | |
| 659 | + // continue | |
| 660 | + if (m_testsource != NULL) { | |
| 661 | + if (!m_testsource->has_par("RA") || !m_testsource->has_par("DEC")) { | |
| 662 | + std::string msg = "Source \""+m_srcname+"\" has no \"RA\" and " | |
| 663 | + "\"DEC\" parameters. Only sources with \"RA\" " | |
| 664 | + " and \"DEC\" parameters can be used as test " | |
| 665 | + "sources."; | |
| 666 | + throw GException::invalid_value(G_GET_PARAMETERS, msg); | |
| 667 | + } | |
| 668 | + } | |
| 669 | + | |
| 670 | + // Fix the spatial parameters of the test source | |
| 671 | + if (m_testsource != NULL) { | |
| 672 | + (*m_testsource)["RA"].fix(); | |
| 673 | + (*m_testsource)["DEC"].fix(); | |
| 674 | + } | |
| 675 | + | |
| 676 | + // Get map parameters | |
| 677 | + m_xref = (*this)["xref"].real(); | |
| 678 | + m_yref = (*this)["yref"].real(); | |
| 679 | + m_proj = (*this)["proj"].string(); | |
| 680 | + m_coordsys = (*this)["coordsys"].string(); | |
| 681 | + m_binsz = (*this)["binsz"].real(); | |
| 682 | + m_nxpix = (*this)["nxpix"].integer(); | |
| 683 | + m_nypix = (*this)["nypix"].integer(); | |
| 684 | + | |
| 685 | + // Get optional splitting parameters | |
| 686 | + m_binmin = (*this)["binmin"].integer(); | |
| 687 | + m_binmax = (*this)["binmax"].integer(); | |
| 688 | + m_logL0 = (*this)["logL0"].real(); | |
| 689 | + | |
| 690 | + // Optionally read ahead parameters so that they get correctly | |
| 691 | + // dumped into the log file | |
| 692 | + if (m_read_ahead) { | |
| 693 | + m_outfile = (*this)["outfile"].filename(); | |
| 694 | + } | |
| 695 | + | |
| 696 | + // Return | |
| 697 | + return; | |
| 698 | +} | |
| 699 | + | |
| 700 | + | |
| 701 | +/***********************************************************************//** | |
| 702 | + * @brief Initialise skymaps | |
| 703 | + * | |
| 704 | + * Initialises skymaps that will contain map information. | |
| 705 | + ***************************************************************************/ | |
| 706 | +void cttsmap::init_maps(void) | |
| 707 | +{ | |
| 708 | + // Initialise map information | |
| 709 | + m_tsmap.clear(); | |
| 710 | + | |
| 711 | + // Create skymap | |
| 712 | + m_tsmap = GSkymap(m_proj, m_coordsys, | |
| 713 | + m_xref, m_yref, -m_binsz, m_binsz, | |
| 714 | + m_nxpix, m_nypix, 1); | |
| 715 | + | |
| 716 | + // Initialise map information | |
| 717 | + m_statusmap.clear(); | |
| 718 | + | |
| 719 | + // Create status map | |
| 720 | + m_statusmap = GSkymap(m_proj, m_coordsys, | |
| 721 | + m_xref, m_yref, -m_binsz, m_binsz, | |
| 722 | + m_nxpix, m_nypix, 1); | |
| 723 | + | |
| 724 | + // Initialise maps of free parameters | |
| 725 | + if (m_testsource != NULL) { | |
| 726 | + | |
| 727 | + // Loop over all model parameters | |
| 728 | + for (int i = 0; i < m_testsource->size(); i++) { | |
| 729 | + | |
| 730 | + // Skip fixed parameters | |
| 731 | + if ((*m_testsource)[i].is_fixed()) { | |
| 732 | + continue; | |
| 733 | + } | |
| 734 | + | |
| 735 | + // Add sky map for free parameters. Note that push_back will | |
| 736 | + // create a copy. | |
| 737 | + m_maps.push_back(m_tsmap); | |
| 738 | + | |
| 739 | + // Store parameter name | |
| 740 | + m_mapnames.push_back((*m_testsource)[i].name()); | |
| 741 | + | |
| 742 | + } // endfor: looped over all model parameters | |
| 743 | + | |
| 744 | + } // endif: test source was valid | |
| 745 | + | |
| 746 | + // Return | |
| 747 | + return; | |
| 748 | +} | ... | ... |
src/cttsmap/cttsmap.hpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * cttsmap - TS map calculation tool * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2014 by Michael Mayer * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file cttsmap.hpp | |
| 23 | + * @brief TS map calculation tool interface definition | |
| 24 | + * @author Michael Mayer | |
| 25 | + */ | |
| 26 | + | |
| 27 | +#ifndef CTTSMAP_HPP | |
| 28 | +#define CTTSMAP_HPP | |
| 29 | + | |
| 30 | +/* __ Includes ___________________________________________________________ */ | |
| 31 | +#include "GammaLib.hpp" | |
| 32 | +#include "GCTALib.hpp" | |
| 33 | + | |
| 34 | +/* __Definitions _________________________________________________________ */ | |
| 35 | +#define CTTSMAP_NAME "cttsmap" | |
| 36 | +#define CTTSMAP_VERSION "00-01-00" | |
| 37 | + | |
| 38 | + | |
| 39 | +/***********************************************************************//** | |
| 40 | + * @class cttsmap | |
| 41 | + * | |
| 42 | + * @brief TS map calculation | |
| 43 | + * | |
| 44 | + * This class computes a set of maps from any kind of observations: | |
| 45 | + * | |
| 46 | + * - TS map | |
| 47 | + * - Flux map | |
| 48 | + * - Map of spectral index | |
| 49 | + * | |
| 50 | + * The class operates on predefined observation containers, an individual | |
| 51 | + * event list or an observation definition XML file. | |
| 52 | + * | |
| 53 | + * During the computation a putative point-like source is moved along a | |
| 54 | + * grid of coordinates. The best fit results (TS, flux, index) are stored in | |
| 55 | + * maps which are saved in the output FITS files. | |
| 56 | + ***************************************************************************/ | |
| 57 | +class cttsmap : public GApplication { | |
| 58 | +public: | |
| 59 | + // Constructors and destructors | |
| 60 | + cttsmap(void); | |
| 61 | + explicit cttsmap(const GObservations& obs); | |
| 62 | + cttsmap(int argc, char *argv[]); | |
| 63 | + cttsmap(const cttsmap& app); | |
| 64 | + virtual ~cttsmap(void); | |
| 65 | + | |
| 66 | + // Operators | |
| 67 | + cttsmap& operator=(const cttsmap& app); | |
| 68 | + | |
| 69 | + // Methods | |
| 70 | + void clear(void); | |
| 71 | + void execute(void); | |
| 72 | + void run(void); | |
| 73 | + void save(void); | |
| 74 | + const GObservations& obs(void) const; | |
| 75 | + const GSkymap& tsmap(void) const; | |
| 76 | + | |
| 77 | +protected: | |
| 78 | + // Protected methods | |
| 79 | + void init_members(void); | |
| 80 | + void copy_members(const cttsmap& app); | |
| 81 | + void free_members(void); | |
| 82 | + void get_parameters(void); | |
| 83 | + void init_maps(void); | |
| 84 | + | |
| 85 | + // User parameters | |
| 86 | + std::string m_infile; //!< Input file | |
| 87 | + std::string m_srcname; //!< Name of source which is moved around | |
| 88 | + std::string m_caldb; //!< Calibration database | |
| 89 | + std::string m_irf; //!< Instrument response functions | |
| 90 | + std::string m_outfile; //!< Output counts map or XML file | |
| 91 | + std::string m_proj; //!< WCS projection | |
| 92 | + std::string m_coordsys; //!< Coordinate system | |
| 93 | + double m_xref; //!< Longitude reference coordinate | |
| 94 | + double m_yref; //!< Latitude reference coordinate | |
| 95 | + double m_binsz; //!< Pixel size | |
| 96 | + int m_nxpix; //!< Number of pixels in longitude | |
| 97 | + int m_nypix; //!< Number of pixels in latitude | |
| 98 | + | |
| 99 | + // Parameters to control speed and job splitting | |
| 100 | + int m_binmin; //!< Map bin number from which computation should start | |
| 101 | + int m_binmax; //!< Map bin number where map computation should end | |
| 102 | + double m_logL0; //!< Likelihood value of null hypothesis | |
| 103 | + | |
| 104 | + // Protected members | |
| 105 | + GObservations m_obs; //!< Observation container | |
| 106 | + bool m_read_ahead; //!< Read ahead parameters | |
| 107 | + GSkymap m_tsmap; //!< TS map | |
| 108 | + GSkymap m_statusmap; //!< Map of computed bins | |
| 109 | + std::vector<std::string> m_mapnames; //!< Names of free parameters | |
| 110 | + std::vector<GSkymap> m_maps; //!< Sky maps for each free parameter | |
| 111 | + GModel* m_testsource; //!< Pointer to test source for TS computation | |
| 112 | +}; | |
| 113 | + | |
| 114 | + | |
| 115 | +/***********************************************************************//** | |
| 116 | + * @brief Return observation container | |
| 117 | + * | |
| 118 | + * @return Reference to observation container | |
| 119 | + ***************************************************************************/ | |
| 120 | +inline | |
| 121 | +const GObservations& cttsmap::obs(void) const | |
| 122 | +{ | |
| 123 | + return m_obs; | |
| 124 | +} | |
| 125 | + | |
| 126 | + | |
| 127 | +/***********************************************************************//** | |
| 128 | + * @brief Return TS skymap | |
| 129 | + * | |
| 130 | + * @return Reference to TS skymap | |
| 131 | + ***************************************************************************/ | |
| 132 | +inline | |
| 133 | +const GSkymap& cttsmap::tsmap(void) const | |
| 134 | +{ | |
| 135 | + return m_tsmap; | |
| 136 | +} | |
| 137 | + | |
| 138 | +#endif /* CTTSMAP_HPP */ | ... | ... |
src/cttsmap/cttsmap.par
0 → 100644
| 1 | +############################################################################# | |
| 2 | +# # | |
| 3 | +# CTA Science Analysis Tools # | |
| 4 | +# # | |
| 5 | +# ------------------------------------------------------------------------- # | |
| 6 | +# # | |
| 7 | +# File: cttsmap.par # | |
| 8 | +# Version: 00-01-00 # | |
| 9 | +# # | |
| 10 | +# Author: Michael Mayer # | |
| 11 | +# michael.mayer@desy.de # | |
| 12 | +# DESY # | |
| 13 | +# # | |
| 14 | +# Purpose: Parameter file for the cttsmap application # | |
| 15 | +# # | |
| 16 | +############################################################################# | |
| 17 | +# | |
| 18 | +# General parameters | |
| 19 | +#=================== | |
| 20 | +infile, f, a, "events.fits",,,"Input event list, cube or observation definition file" | |
| 21 | +srcmdl, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" | |
| 22 | +srcname, s, a, "TestSource",,,"Test source" | |
| 23 | +caldb, s, a, "dummy",,, "Calibration database" | |
| 24 | +irf, s, a, "cta_dummy_irf",,, "Instrument response function" | |
| 25 | +outfile, f, a, "tsmap.fits",,, "Output counts cube" | |
| 26 | + | |
| 27 | +# | |
| 28 | +# Spatial binning parameters | |
| 29 | +#=========================== | |
| 30 | +nxpix, i, a, 200,,, "Size of the X axis in pixels" | |
| 31 | +nypix, i, a, 200,,, "Size of the Y axis in pixels" | |
| 32 | +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)" | |
| 33 | +coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)" | |
| 34 | +xref, r, a, 83.63,,, "First coordinate of image center in degrees (RA or galactic l)" | |
| 35 | +yref, r, a, 22.01,,, "Second coordinate of image center in degrees (DEC or galactic b)" | |
| 36 | +proj, s, a, "CAR", AIT|AZP|CAR|MER|STG|TAN,, "Projection method e.g. AIT|AZP|CAR|MER|STG|TAN" | |
| 37 | + | |
| 38 | +# | |
| 39 | +# Parameters for splitting and speed purpose | |
| 40 | +#=========================== | |
| 41 | +binmin, i, h, -1,,, "First bin to compute" | |
| 42 | +binmax, i, h, -1,,, "Last bin to compute" | |
| 43 | +logL0, r, h, 0.0,,, "LogLikelihood value of null hypothesis" | |
| 44 | + | |
| 45 | + | |
| 46 | +# | |
| 47 | +# Standard parameters | |
| 48 | +#==================== | |
| 49 | +chatter, i, h, 2,0,4, "Chattiness of output" | |
| 50 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | |
| 51 | +debug, b, h, no,,, "Debugging mode activated" | |
| 52 | +mode, s, h, "ql",,, "Mode of automatic parameters" | |
| 53 | +logfile, f, h, "cttsmap.log",,, "Log filename" | ... | ... |
src/cttsmap/main.cpp
0 → 100644
| 1 | +/*************************************************************************** | |
| 2 | + * cttsmap - TS map calculation tool * | |
| 3 | + * ----------------------------------------------------------------------- * | |
| 4 | + * copyright (C) 2014 by Michael Mayer * | |
| 5 | + * ----------------------------------------------------------------------- * | |
| 6 | + * * | |
| 7 | + * This program is free software: you can redistribute it and/or modify * | |
| 8 | + * it under the terms of the GNU General Public License as published by * | |
| 9 | + * the Free Software Foundation, either version 3 of the License, or * | |
| 10 | + * (at your option) any later version. * | |
| 11 | + * * | |
| 12 | + * This program is distributed in the hope that it will be useful, * | |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
| 15 | + * GNU General Public License for more details. * | |
| 16 | + * * | |
| 17 | + * You should have received a copy of the GNU General Public License * | |
| 18 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. * | |
| 19 | + * * | |
| 20 | + ***************************************************************************/ | |
| 21 | +/** | |
| 22 | + * @file cttsmap/main.cpp | |
| 23 | + * @brief CTA TS map generation | |
| 24 | + * @author Michael Mayer | |
| 25 | + */ | |
| 26 | + | |
| 27 | +/* __ Includes ___________________________________________________________ */ | |
| 28 | +#ifdef HAVE_CONFIG_H | |
| 29 | +#include <config.h> | |
| 30 | +#endif | |
| 31 | +#include <cstdio> | |
| 32 | +#include "cttsmap.hpp" | |
| 33 | + | |
| 34 | + | |
| 35 | +/***********************************************************************//** | |
| 36 | + * @brief Main entry point of application | |
| 37 | + * | |
| 38 | + * @param[in] argc Number of command line arguments. | |
| 39 | + * @param[in] argv Command line arguments. | |
| 40 | + * | |
| 41 | + * This is the main entry point of the cttsmap application. It allocates a | |
| 42 | + * cttsmap object and runs the application. | |
| 43 | + ***************************************************************************/ | |
| 44 | +int main (int argc, char *argv[]) | |
| 45 | +{ | |
| 46 | + // Initialise return code | |
| 47 | + int rc = 1; | |
| 48 | + | |
| 49 | + // Create instance of application | |
| 50 | + cttsmap application(argc, argv); | |
| 51 | + | |
| 52 | + // Run application | |
| 53 | + try { | |
| 54 | + // Execute application | |
| 55 | + application.execute(); | |
| 56 | + | |
| 57 | + // Signal success | |
| 58 | + rc = 0; | |
| 59 | + } | |
| 60 | + catch (std::exception &e) { | |
| 61 | + | |
| 62 | + // Extract error message | |
| 63 | + std::string message = e.what(); | |
| 64 | + std::string signal = "*** ERROR encounterted in the execution of" | |
| 65 | + " cttsmap. Run aborted ..."; | |
| 66 | + | |
| 67 | + // Write error in logger | |
| 68 | + application.log << signal << std::endl; | |
| 69 | + application.log << message << std::endl; | |
| 70 | + | |
| 71 | + // Write error on standard output | |
| 72 | + std::cout << signal << std::endl; | |
| 73 | + std::cout << message << std::endl; | |
| 74 | + | |
| 75 | + } // endcatch: catched any application error | |
| 76 | + | |
| 77 | + // Return | |
| 78 | + return rc; | |
| 79 | +} | ... | ... |
test/test_ctools.sh
| ... | ... | @@ -36,6 +36,7 @@ $ECHO "***************" |
| 36 | 36 | # ================== |
| 37 | 37 | ctbin=../src/ctbin/ctbin |
| 38 | 38 | ctlike=../src/ctlike/ctlike |
| 39 | +cttsmap=../src/cttsmap/cttsmap | |
| 39 | 40 | ctmodel=../src/ctmodel/ctmodel |
| 40 | 41 | ctobssim=../src/ctobssim/ctobssim |
| 41 | 42 | ctselect=../src/ctselect/ctselect |
| ... | ... | @@ -347,6 +348,34 @@ $ECHO " ok" |
| 347 | 348 | |
| 348 | 349 | |
| 349 | 350 | # |
| 351 | +# Test cttsmap | |
| 352 | +# ============ | |
| 353 | +$ECHO -n "Test cttsmap: " | |
| 354 | +$cttsmap infile="selected_events.fits" \ | |
| 355 | + srcmdl="data/crab.xml" \ | |
| 356 | + srcname="Crab" \ | |
| 357 | + caldb="irf" \ | |
| 358 | + irf="cta_dummy_irf" \ | |
| 359 | + outfile="tsmap.fits" \ | |
| 360 | + nxpix=5 \ | |
| 361 | + nypix=5 \ | |
| 362 | + binsz=0.05 \ | |
| 363 | + coordsys="CEL" \ | |
| 364 | + xref=83.63 \ | |
| 365 | + yref=22.01 \ | |
| 366 | + proj="CAR" | |
| 367 | +$ECHO -n "." | |
| 368 | +if [ -s "tsmap.fits" ] | |
| 369 | +then | |
| 370 | + $ECHO -n "." | |
| 371 | +else | |
| 372 | + $ECHO " tsmap.fits file is not valid" | |
| 373 | + exit 1 | |
| 374 | +fi | |
| 375 | +$ECHO " ok" | |
| 376 | + | |
| 377 | + | |
| 378 | +# | |
| 350 | 379 | # Test ctexpcube |
| 351 | 380 | # ============== |
| 352 | 381 | $ECHO -n "Test ctexpcube: " | ... | ... |
test/test_cttsmap.py
0 → 100755
| 1 | +#! /usr/bin/env python | |
| 2 | +# ========================================================================== | |
| 3 | +# This scripts performs unit tests for the cttsmap tool. | |
| 4 | +# | |
| 5 | +# Copyright (C) 2014 Juergen Knoedlseder | |
| 6 | +# | |
| 7 | +# This program is free software: you can redistribute it and/or modify | |
| 8 | +# it under the terms of the GNU General Public License as published by | |
| 9 | +# the Free Software Foundation, either version 3 of the License, or | |
| 10 | +# (at your option) any later version. | |
| 11 | +# | |
| 12 | +# This program is distributed in the hope that it will be useful, | |
| 13 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 15 | +# GNU General Public License for more details. | |
| 16 | +# | |
| 17 | +# You should have received a copy of the GNU General Public License | |
| 18 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. | |
| 19 | +# | |
| 20 | +# ========================================================================== | |
| 21 | +import gammalib | |
| 22 | +import ctools | |
| 23 | + | |
| 24 | + | |
| 25 | +# ========================== # | |
| 26 | +# Test class for cttsmap tool # | |
| 27 | +# ========================== # | |
| 28 | +class Test(gammalib.GPythonTestSuite): | |
| 29 | + """ | |
| 30 | + Test class for cttsmap tool. | |
| 31 | + """ | |
| 32 | + # Constructor | |
| 33 | + def __init__(self): | |
| 34 | + """ | |
| 35 | + Constructor. | |
| 36 | + """ | |
| 37 | + # Call base class constructor | |
| 38 | + gammalib.GPythonTestSuite.__init__(self) | |
| 39 | + | |
| 40 | + # Set members | |
| 41 | + self.events_name = "data/crab_events.fits" | |
| 42 | + self.model_name = "data/crab.xml" | |
| 43 | + self.caldb = "irf" | |
| 44 | + self.irf = "cta_dummy_irf" | |
| 45 | + | |
| 46 | + # Return | |
| 47 | + return | |
| 48 | + | |
| 49 | + # Set test functions | |
| 50 | + def set(self): | |
| 51 | + """ | |
| 52 | + Set all test functions. | |
| 53 | + """ | |
| 54 | + # Set test name | |
| 55 | + self.name("cttsmap") | |
| 56 | + | |
| 57 | + # Append tests | |
| 58 | + self.append(self.test_functional, "Test cttsmap functionality") | |
| 59 | + | |
| 60 | + # Return | |
| 61 | + return | |
| 62 | + | |
| 63 | + # Test cttsmap functionnality | |
| 64 | + def test_functional(self): | |
| 65 | + """ | |
| 66 | + Test cttsmap functionnality. | |
| 67 | + """ | |
| 68 | + # Set-up cttsmap | |
| 69 | + tsmap = ctools.cttsmap() | |
| 70 | + tsmap["infile"].filename(self.events_name) | |
| 71 | + tsmap["srcmdl"].filename(self.model_name) | |
| 72 | + tsmap["srcname"].string("Crab") | |
| 73 | + tsmap["caldb"].string(self.caldb) | |
| 74 | + tsmap["irf"].string(self.irf) | |
| 75 | + tsmap["outfile"].filename("tsmap.fits") | |
| 76 | + tsmap["nxpix"].integer(5) | |
| 77 | + tsmap["nypix"].integer(5) | |
| 78 | + tsmap["binsz"].real(0.02) | |
| 79 | + tsmap["coordsys"].string("CEL") | |
| 80 | + tsmap["proj"].string("CAR") | |
| 81 | + tsmap["xref"].real(83.63) | |
| 82 | + tsmap["yref"].real(22.01) | |
| 83 | + | |
| 84 | + # Run tool | |
| 85 | + self.test_try("Run cttsmap") | |
| 86 | + try: | |
| 87 | + tsmap.run() | |
| 88 | + self.test_try_success() | |
| 89 | + except: | |
| 90 | + self.test_try_failure("Exception occured in cttsmap.") | |
| 91 | + | |
| 92 | + # Save results | |
| 93 | + self.test_try("Save results") | |
| 94 | + try: | |
| 95 | + tsmap.save() | |
| 96 | + self.test_try_success() | |
| 97 | + except: | |
| 98 | + self.test_try_failure("Exception occured in saving results.") | |
| 99 | + | |
| 100 | + # Return | |
| 101 | + return | ... | ... |
test/test_python.py
| ... | ... | @@ -26,6 +26,7 @@ import test_ctobssim |
| 26 | 26 | import test_ctselect |
| 27 | 27 | import test_ctbin |
| 28 | 28 | import test_ctlike |
| 29 | +import test_cttsmap | |
| 29 | 30 | import test_ctmodel |
| 30 | 31 | import test_ctskymap |
| 31 | 32 | import test_ctexpcube |
| ... | ... | @@ -50,6 +51,7 @@ if __name__ == '__main__': |
| 50 | 51 | suite_ctselect = test_ctselect.Test() |
| 51 | 52 | suite_ctbin = test_ctbin.Test() |
| 52 | 53 | suite_ctlike = test_ctlike.Test() |
| 54 | + suite_cttsmap = test_cttsmap.Test() | |
| 53 | 55 | suite_ctmodel = test_ctmodel.Test() |
| 54 | 56 | suite_ctskymap = test_ctskymap.Test() |
| 55 | 57 | suite_ctexpcube = test_ctexpcube.Test() |
| ... | ... | @@ -63,6 +65,7 @@ if __name__ == '__main__': |
| 63 | 65 | suite_ctselect.set() |
| 64 | 66 | suite_ctbin.set() |
| 65 | 67 | suite_ctlike.set() |
| 68 | + suite_cttsmap.set() | |
| 66 | 69 | suite_ctmodel.set() |
| 67 | 70 | suite_ctskymap.set() |
| 68 | 71 | suite_ctexpcube.set() |
| ... | ... | @@ -76,6 +79,7 @@ if __name__ == '__main__': |
| 76 | 79 | suites.append(suite_ctselect) |
| 77 | 80 | suites.append(suite_ctbin) |
| 78 | 81 | suites.append(suite_ctlike) |
| 82 | + suites.append(suite_cttsmap) | |
| 79 | 83 | suites.append(suite_ctmodel) |
| 80 | 84 | suites.append(suite_ctskymap) |
| 81 | 85 | suites.append(suite_ctexpcube) | ... | ... |