Commit f34baf13068bfd68b42b24ac8e81313d75f9e6e0
1 parent
0d9c23cf
Create initial version of ctexpcube tool.
Showing
8 changed files
with
783 additions
and
2 deletions
configure.ac
| @@ -882,6 +882,7 @@ AC_CONFIG_FILES([Makefile | @@ -882,6 +882,7 @@ AC_CONFIG_FILES([Makefile | ||
| 882 | src/ctobssim/Makefile | 882 | src/ctobssim/Makefile |
| 883 | src/ctskymap/Makefile | 883 | src/ctskymap/Makefile |
| 884 | src/ctselect/Makefile | 884 | src/ctselect/Makefile |
| 885 | + src/ctexpcube/Makefile | ||
| 885 | src/ctools-setup | 886 | src/ctools-setup |
| 886 | test/Makefile | 887 | test/Makefile |
| 887 | test/test_cscripts.sh | 888 | test/test_cscripts.sh |
src/Makefile.am
| @@ -10,7 +10,8 @@ SUBDIRS = ctbin \ | @@ -10,7 +10,8 @@ SUBDIRS = ctbin \ | ||
| 10 | ctmodel \ | 10 | ctmodel \ |
| 11 | ctobssim \ | 11 | ctobssim \ |
| 12 | ctselect \ | 12 | ctselect \ |
| 13 | - ctskymap | 13 | + ctskymap \ |
| 14 | + ctexpcube | ||
| 14 | 15 | ||
| 15 | # Scripts to be distributed | 16 | # Scripts to be distributed |
| 16 | scripts = ctools-setup \ | 17 | scripts = ctools-setup \ |
| @@ -27,7 +28,8 @@ libctools_la_LIBADD = ctbin/libctbin.la \ | @@ -27,7 +28,8 @@ libctools_la_LIBADD = ctbin/libctbin.la \ | ||
| 27 | ctmodel/libctmodel.la \ | 28 | ctmodel/libctmodel.la \ |
| 28 | ctobssim/libctobssim.la \ | 29 | ctobssim/libctobssim.la \ |
| 29 | ctselect/libctselect.la \ | 30 | ctselect/libctselect.la \ |
| 30 | - ctskymap/libctskymap.la | 31 | + ctskymap/libctskymap.la \ |
| 32 | + ctexpcube/libctexpcube.la | ||
| 31 | 33 | ||
| 32 | # Distribute scripts | 34 | # Distribute scripts |
| 33 | EXTRA_DIST = $(scripts) | 35 | EXTRA_DIST = $(scripts) |
src/ctexpcube/Makefile.am
0 → 100644
| 1 | +## Process this file with automake to produce Makefile.in | ||
| 2 | + | ||
| 3 | +# Program name | ||
| 4 | +bin_PROGRAMS = ctexpcube | ||
| 5 | + | ||
| 6 | +# Sources | ||
| 7 | +sources = ctexpcube.cpp | ||
| 8 | + | ||
| 9 | +# Libtool library | ||
| 10 | +noinst_LTLIBRARIES = libctexpcube.la | ||
| 11 | +libctexpcube_la_SOURCES = $(sources) | ||
| 12 | + | ||
| 13 | +# Program definition | ||
| 14 | +ctexpcube_SOURCES = main.cpp | ||
| 15 | +ctexpcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ | ||
| 16 | +ctexpcube_CPPFLAGS = @CPPFLAGS@ | ||
| 17 | +ctexpcube_LDADD = libctexpcube.la | ||
| 18 | + | ||
| 19 | +# Parameter files | ||
| 20 | +pfilesdir = $(prefix)/syspfiles | ||
| 21 | +pfiles_DATA = ctexpcube.par |
src/ctexpcube/ctexpcube
0 → 100755
No preview for this file type
src/ctexpcube/ctexpcube.cpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctexpcube - CTA exposure cube tool * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2014 by Juergen Knoedlseder * | ||
| 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 ctexpcube.cpp | ||
| 23 | + * @brief CTA exposure cube tool implementation | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +/* __ Includes ___________________________________________________________ */ | ||
| 28 | +#ifdef HAVE_CONFIG_H | ||
| 29 | +#include <config.h> | ||
| 30 | +#endif | ||
| 31 | +#include <cstdio> | ||
| 32 | +#include "ctexpcube.hpp" | ||
| 33 | +#include "GTools.hpp" | ||
| 34 | + | ||
| 35 | +/* __ Method name definitions ____________________________________________ */ | ||
| 36 | +#define G_GET_EBOUNDS "ctexpcube::get_ebounds()" | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +#define G_SETUP_OBS "ctexpcube::setup_obs()" | ||
| 40 | +#define G_MODEL_MAP "ctexpcube::model_map(GCTAObservation*)" | ||
| 41 | + | ||
| 42 | +/* __ Debug definitions __________________________________________________ */ | ||
| 43 | + | ||
| 44 | +/* __ Coding definitions _________________________________________________ */ | ||
| 45 | + | ||
| 46 | + | ||
| 47 | +/*========================================================================== | ||
| 48 | + = = | ||
| 49 | + = Constructors/destructors = | ||
| 50 | + = = | ||
| 51 | + ==========================================================================*/ | ||
| 52 | + | ||
| 53 | +/***********************************************************************//** | ||
| 54 | + * @brief Void constructor | ||
| 55 | + ***************************************************************************/ | ||
| 56 | +ctexpcube::ctexpcube(void) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | ||
| 57 | +{ | ||
| 58 | + // Initialise members | ||
| 59 | + init_members(); | ||
| 60 | + | ||
| 61 | + // Write header into logger | ||
| 62 | + log_header(); | ||
| 63 | + | ||
| 64 | + // Return | ||
| 65 | + return; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | + | ||
| 69 | +/***********************************************************************//** | ||
| 70 | + * @brief Observations constructor | ||
| 71 | + * | ||
| 72 | + * This method creates an instance of the class by copying an existing | ||
| 73 | + * observations container. | ||
| 74 | + ***************************************************************************/ | ||
| 75 | +ctexpcube::ctexpcube(GObservations obs) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | ||
| 76 | +{ | ||
| 77 | + // Initialise members | ||
| 78 | + init_members(); | ||
| 79 | + | ||
| 80 | + // Set observations | ||
| 81 | + m_obs = obs; | ||
| 82 | + | ||
| 83 | + // Write header into logger | ||
| 84 | + log_header(); | ||
| 85 | + | ||
| 86 | + // Return | ||
| 87 | + return; | ||
| 88 | +} | ||
| 89 | + | ||
| 90 | + | ||
| 91 | + | ||
| 92 | +/***********************************************************************//** | ||
| 93 | + * @brief Command line constructor | ||
| 94 | + * | ||
| 95 | + * @param[in] argc Number of arguments in command line. | ||
| 96 | + * @param[in] argv Array of command line arguments. | ||
| 97 | + ***************************************************************************/ | ||
| 98 | +ctexpcube::ctexpcube(int argc, char *argv[]) : | ||
| 99 | + GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION, argc, argv) | ||
| 100 | +{ | ||
| 101 | + // Initialise members | ||
| 102 | + init_members(); | ||
| 103 | + | ||
| 104 | + // Write header into logger | ||
| 105 | + log_header(); | ||
| 106 | + | ||
| 107 | + // Return | ||
| 108 | + return; | ||
| 109 | +} | ||
| 110 | + | ||
| 111 | + | ||
| 112 | +/***********************************************************************//** | ||
| 113 | + * @brief Copy constructor | ||
| 114 | + * | ||
| 115 | + * @param[in] app ctexpcube application. | ||
| 116 | + ***************************************************************************/ | ||
| 117 | +ctexpcube::ctexpcube(const ctexpcube& app) : GApplication(app) | ||
| 118 | +{ | ||
| 119 | + // Initialise members | ||
| 120 | + init_members(); | ||
| 121 | + | ||
| 122 | + // Copy members | ||
| 123 | + copy_members(app); | ||
| 124 | + | ||
| 125 | + // Return | ||
| 126 | + return; | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | + | ||
| 130 | +/***********************************************************************//** | ||
| 131 | + * @brief Destructor | ||
| 132 | + ***************************************************************************/ | ||
| 133 | +ctexpcube::~ctexpcube(void) | ||
| 134 | +{ | ||
| 135 | + // Free members | ||
| 136 | + free_members(); | ||
| 137 | + | ||
| 138 | + // Return | ||
| 139 | + return; | ||
| 140 | +} | ||
| 141 | + | ||
| 142 | + | ||
| 143 | +/*========================================================================== | ||
| 144 | + = = | ||
| 145 | + = Operators = | ||
| 146 | + = = | ||
| 147 | + ==========================================================================*/ | ||
| 148 | + | ||
| 149 | +/***********************************************************************//** | ||
| 150 | + * @brief Assignment operator | ||
| 151 | + * | ||
| 152 | + * @param[in] app ctexpcube application. | ||
| 153 | + * @return Returns ctexpcube application. | ||
| 154 | + ***************************************************************************/ | ||
| 155 | +ctexpcube& ctexpcube::operator=(const ctexpcube& app) | ||
| 156 | +{ | ||
| 157 | + // Execute only if object is not identical | ||
| 158 | + if (this != &app) { | ||
| 159 | + | ||
| 160 | + // Copy base class members | ||
| 161 | + this->GApplication::operator=(app); | ||
| 162 | + | ||
| 163 | + // Free members | ||
| 164 | + free_members(); | ||
| 165 | + | ||
| 166 | + // Initialise members | ||
| 167 | + init_members(); | ||
| 168 | + | ||
| 169 | + // Copy members | ||
| 170 | + copy_members(app); | ||
| 171 | + | ||
| 172 | + } // endif: object was not identical | ||
| 173 | + | ||
| 174 | + // Return this object | ||
| 175 | + return *this; | ||
| 176 | +} | ||
| 177 | + | ||
| 178 | + | ||
| 179 | +/*========================================================================== | ||
| 180 | + = = | ||
| 181 | + = Public methods = | ||
| 182 | + = = | ||
| 183 | + ==========================================================================*/ | ||
| 184 | + | ||
| 185 | +/***********************************************************************//** | ||
| 186 | + * @brief Clear instance | ||
| 187 | + ***************************************************************************/ | ||
| 188 | +void ctexpcube::clear(void) | ||
| 189 | +{ | ||
| 190 | + // Free members | ||
| 191 | + free_members(); | ||
| 192 | + this->GApplication::free_members(); | ||
| 193 | + | ||
| 194 | + // Initialise members | ||
| 195 | + this->GApplication::init_members(); | ||
| 196 | + init_members(); | ||
| 197 | + | ||
| 198 | + // Return | ||
| 199 | + return; | ||
| 200 | +} | ||
| 201 | + | ||
| 202 | + | ||
| 203 | +/***********************************************************************//** | ||
| 204 | + * @brief Execute application | ||
| 205 | + * | ||
| 206 | + * This is the main execution method of the ctexpcube class. It is invoked | ||
| 207 | + * when the executable is called from command line. The method generates | ||
| 208 | + * the exposure cube and saves the result. | ||
| 209 | + ***************************************************************************/ | ||
| 210 | +void ctexpcube::execute(void) | ||
| 211 | +{ | ||
| 212 | + // Signal that some parameters should be read ahead | ||
| 213 | + m_read_ahead = true; | ||
| 214 | + | ||
| 215 | + // Create the exposure cube | ||
| 216 | + run(); | ||
| 217 | + | ||
| 218 | + // Save the exposure cube into the output FITS file | ||
| 219 | + save(); | ||
| 220 | + | ||
| 221 | + // Return | ||
| 222 | + return; | ||
| 223 | +} | ||
| 224 | + | ||
| 225 | + | ||
| 226 | +/***********************************************************************//** | ||
| 227 | + * @brief Generate the model map(s) | ||
| 228 | + * | ||
| 229 | + * This method reads the task parameters from the parfile, sets up the | ||
| 230 | + * observation container, loops over all CTA observations in the container | ||
| 231 | + * and generates an exposure cube from the CTA observations. | ||
| 232 | + ***************************************************************************/ | ||
| 233 | +void ctexpcube::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 | + // Set energy dispersion flag for all CTA observations and save old | ||
| 250 | + // values in save_edisp vector | ||
| 251 | + std::vector<bool> save_edisp; | ||
| 252 | + save_edisp.assign(m_obs.size(), false); | ||
| 253 | + for (int i = 0; i < m_obs.size(); ++i) { | ||
| 254 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | ||
| 255 | + if (obs != NULL) { | ||
| 256 | + save_edisp[i] = obs->response().apply_edisp(); | ||
| 257 | + obs->response().apply_edisp(m_apply_edisp); | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + | ||
| 261 | + // Write observation(s) into logger | ||
| 262 | + if (logTerse()) { | ||
| 263 | + log << std::endl; | ||
| 264 | + if (m_obs.size() > 1) { | ||
| 265 | + log.header1("Observations"); | ||
| 266 | + } | ||
| 267 | + else { | ||
| 268 | + log.header1("Observation"); | ||
| 269 | + } | ||
| 270 | + log << m_obs << std::endl; | ||
| 271 | + } | ||
| 272 | + | ||
| 273 | + // Write header | ||
| 274 | + if (logTerse()) { | ||
| 275 | + log << std::endl; | ||
| 276 | + log.header1("Generate exposure cube"); | ||
| 277 | + } | ||
| 278 | + | ||
| 279 | + // Initialise observation counter | ||
| 280 | + int n_observations = 0; | ||
| 281 | + | ||
| 282 | + // Loop over all observations in the container | ||
| 283 | + for (int i = 0; i < m_obs.size(); ++i) { | ||
| 284 | + | ||
| 285 | + // Get CTA observation | ||
| 286 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | ||
| 287 | + | ||
| 288 | + // Continue only if observation is a CTA observation | ||
| 289 | + if (obs != NULL) { | ||
| 290 | + | ||
| 291 | + // Write header for observation | ||
| 292 | + if (logTerse()) { | ||
| 293 | + if (obs->name().length() > 1) { | ||
| 294 | + log.header3("Observation "+obs->name()); | ||
| 295 | + } | ||
| 296 | + else { | ||
| 297 | + log.header3("Observation"); | ||
| 298 | + } | ||
| 299 | + } | ||
| 300 | + | ||
| 301 | + // Increment number of observations | ||
| 302 | + n_observations++; | ||
| 303 | + | ||
| 304 | + // Generate exposure cube | ||
| 305 | + //model_map(obs, m_obs.models()); | ||
| 306 | + | ||
| 307 | + } // endif: CTA observation found | ||
| 308 | + | ||
| 309 | + } // endfor: looped over observations | ||
| 310 | + | ||
| 311 | + // Restore energy dispersion flag for all CTA observations | ||
| 312 | + for (int i = 0; i < m_obs.size(); ++i) { | ||
| 313 | + GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]); | ||
| 314 | + if (obs != NULL) { | ||
| 315 | + obs->response().apply_edisp(save_edisp[i]); | ||
| 316 | + } | ||
| 317 | + } | ||
| 318 | + | ||
| 319 | + // Return | ||
| 320 | + return; | ||
| 321 | +} | ||
| 322 | + | ||
| 323 | + | ||
| 324 | +/***********************************************************************//** | ||
| 325 | + * @brief Save exposure cube | ||
| 326 | + * | ||
| 327 | + ***************************************************************************/ | ||
| 328 | +void ctexpcube::save(void) | ||
| 329 | +{ | ||
| 330 | + // Write header | ||
| 331 | + if (logTerse()) { | ||
| 332 | + log << std::endl; | ||
| 333 | + log.header1("Save exposure cube"); | ||
| 334 | + } | ||
| 335 | + | ||
| 336 | + // Get output filename | ||
| 337 | + m_outfile = (*this)["outfile"].filename(); | ||
| 338 | + | ||
| 339 | + // Save exposure cube | ||
| 340 | + m_expcube.save(m_outfile, clobber()); | ||
| 341 | + | ||
| 342 | + // Return | ||
| 343 | + return; | ||
| 344 | +} | ||
| 345 | + | ||
| 346 | + | ||
| 347 | +/***********************************************************************//** | ||
| 348 | + * @brief Get application parameters | ||
| 349 | + * | ||
| 350 | + * Get all task parameters from parameter file or (if required) by querying | ||
| 351 | + * the user. The parameters are read in the correct order. | ||
| 352 | + ***************************************************************************/ | ||
| 353 | +void ctexpcube::get_parameters(void) | ||
| 354 | +{ | ||
| 355 | + // If we do not have any observations in the container then get an | ||
| 356 | + // input file name or observation descriptor file | ||
| 357 | + if (m_obs.size() == 0) { | ||
| 358 | + m_infile = (*this)["infile"].filename(); | ||
| 359 | + } | ||
| 360 | + | ||
| 361 | + // Read response parameters | ||
| 362 | + m_caldb = (*this)["caldb"].string(); | ||
| 363 | + m_irf = (*this)["irf"].string(); | ||
| 364 | + m_apply_edisp = (*this)["edisp"].boolean(); | ||
| 365 | + | ||
| 366 | + // If no counts map is specified then setup the exposure cube from | ||
| 367 | + // the user parameters | ||
| 368 | + m_cntmap = (*this)["cntmap"].filename(); | ||
| 369 | + if ((m_cntmap == "NONE") || (gammalib::strip_whitespace(m_cntmap) == "")) { | ||
| 370 | + | ||
| 371 | + // Get user parameters for counts map definition | ||
| 372 | + std::string wcs = (*this)["proj"].string(); | ||
| 373 | + std::string coordsys = (*this)["coordsys"].string(); | ||
| 374 | + double xref = (*this)["xref"].real(); | ||
| 375 | + double yref = (*this)["yref"].real(); | ||
| 376 | + double binsz = (*this)["binsz"].real(); | ||
| 377 | + int nxpix = (*this)["nxpix"].integer(); | ||
| 378 | + int nypix = (*this)["nypix"].integer(); | ||
| 379 | + | ||
| 380 | + // Get energy definition | ||
| 381 | + get_ebounds(); | ||
| 382 | + | ||
| 383 | + // Define exposure cube | ||
| 384 | + m_expcube = GCTAExposure(wcs, coordsys, xref, yref, | ||
| 385 | + -binsz, binsz, nxpix, nypix, | ||
| 386 | + m_ebounds); | ||
| 387 | + } | ||
| 388 | + | ||
| 389 | + // ... otherwise setup the exposure cube from the counts map | ||
| 390 | + else { | ||
| 391 | + } | ||
| 392 | + | ||
| 393 | + // Read output filename (if needed) | ||
| 394 | + if (m_read_ahead) { | ||
| 395 | + m_outfile = (*this)["outfile"].filename(); | ||
| 396 | + } | ||
| 397 | + | ||
| 398 | + // Return | ||
| 399 | + return; | ||
| 400 | +} | ||
| 401 | + | ||
| 402 | + | ||
| 403 | +/***********************************************************************//** | ||
| 404 | + * @brief Get energy boundaries from parameters | ||
| 405 | + * | ||
| 406 | + * Get the energy boundaries from the user parameters. | ||
| 407 | + ***************************************************************************/ | ||
| 408 | +void ctexpcube::get_ebounds(void) | ||
| 409 | +{ | ||
| 410 | + // Determine the energy binning alogrithm | ||
| 411 | + std::string ebinalg = (*this)["ebinalg"].string(); | ||
| 412 | + | ||
| 413 | + // If we have the binning given by a file then try to get the boundaries | ||
| 414 | + // from that file | ||
| 415 | + if (ebinalg == "FILE") { | ||
| 416 | + | ||
| 417 | + // Get filename | ||
| 418 | + std::string filename = (*this)["ebinfile"].filename(); | ||
| 419 | + | ||
| 420 | + // Open fits file to check which extension is given | ||
| 421 | + GFits file(filename); | ||
| 422 | + | ||
| 423 | + // Check first for EBOUNDS extension | ||
| 424 | + if (file.contains("EBOUNDS")) { | ||
| 425 | + file.close(); | ||
| 426 | + m_ebounds.load(filename, "EBOUNDS"); | ||
| 427 | + } | ||
| 428 | + | ||
| 429 | + // ... then check for ENERGYBINS extension | ||
| 430 | + else if (file.contains("ENERGYBINS")) { | ||
| 431 | + file.close(); | ||
| 432 | + m_ebounds.load(filename, "ENERGYBINS"); | ||
| 433 | + } | ||
| 434 | + | ||
| 435 | + // ... otherwise throw an exception | ||
| 436 | + else { | ||
| 437 | + file.close(); | ||
| 438 | + std::string msg = "No extension with name \"EBOUNDS\" or" | ||
| 439 | + " \"ENERGYBINS\" found in FITS file" | ||
| 440 | + " \""+filename+"\".\n" | ||
| 441 | + "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | ||
| 442 | + " is required if the parameter \"ebinalg\"" | ||
| 443 | + " is set to \"FILE\"."; | ||
| 444 | + throw GException::invalid_value(G_GET_EBOUNDS, msg); | ||
| 445 | + } | ||
| 446 | + } | ||
| 447 | + | ||
| 448 | + // ... otherwise read emin, emax and nebins | ||
| 449 | + else { | ||
| 450 | + | ||
| 451 | + // Get the relevant parameters | ||
| 452 | + double emin = (*this)["emin"].real(); | ||
| 453 | + double emax = (*this)["emax"].real(); | ||
| 454 | + int enumbins = (*this)["enumbins"].integer(); | ||
| 455 | + bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true; | ||
| 456 | + | ||
| 457 | + // Create energy boundaries | ||
| 458 | + m_ebounds = GEbounds(enumbins, | ||
| 459 | + GEnergy(emin, "TeV"), | ||
| 460 | + GEnergy(emax, "TeV"), | ||
| 461 | + log); | ||
| 462 | + | ||
| 463 | + } | ||
| 464 | + | ||
| 465 | + // Return | ||
| 466 | + return; | ||
| 467 | +} | ||
| 468 | + | ||
| 469 | + | ||
| 470 | +/*========================================================================== | ||
| 471 | + = = | ||
| 472 | + = Private methods = | ||
| 473 | + = = | ||
| 474 | + ==========================================================================*/ | ||
| 475 | + | ||
| 476 | +/***********************************************************************//** | ||
| 477 | + * @brief Initialise class members | ||
| 478 | + ***************************************************************************/ | ||
| 479 | +void ctexpcube::init_members(void) | ||
| 480 | +{ | ||
| 481 | + // Initialise members | ||
| 482 | + m_infile.clear(); | ||
| 483 | + m_outfile.clear(); | ||
| 484 | + m_caldb.clear(); | ||
| 485 | + m_irf.clear(); | ||
| 486 | + m_apply_edisp = false; | ||
| 487 | + | ||
| 488 | + // Initialise protected members | ||
| 489 | + m_read_ahead = false; | ||
| 490 | + m_obs.clear(); | ||
| 491 | + m_expcube.clear(); | ||
| 492 | + m_ebounds.clear(); | ||
| 493 | + | ||
| 494 | + // Set logger properties | ||
| 495 | + log.date(true); | ||
| 496 | + | ||
| 497 | + // Return | ||
| 498 | + return; | ||
| 499 | +} | ||
| 500 | + | ||
| 501 | + | ||
| 502 | +/***********************************************************************//** | ||
| 503 | + * @brief Copy class members | ||
| 504 | + * | ||
| 505 | + * @param[in] app Application. | ||
| 506 | + ***************************************************************************/ | ||
| 507 | +void ctexpcube::copy_members(const ctexpcube& app) | ||
| 508 | +{ | ||
| 509 | + // Copy attributes | ||
| 510 | + m_infile = app.m_infile; | ||
| 511 | + m_outfile = app.m_outfile; | ||
| 512 | + m_caldb = app.m_caldb; | ||
| 513 | + m_irf = app.m_irf; | ||
| 514 | + m_apply_edisp = app.m_apply_edisp; | ||
| 515 | + | ||
| 516 | + // Copy protected members | ||
| 517 | + m_read_ahead = app.m_read_ahead; | ||
| 518 | + m_obs = app.m_obs; | ||
| 519 | + m_expcube = app.m_expcube; | ||
| 520 | + m_ebounds = app.m_ebounds; | ||
| 521 | + | ||
| 522 | + // Return | ||
| 523 | + return; | ||
| 524 | +} | ||
| 525 | + | ||
| 526 | + | ||
| 527 | +/***********************************************************************//** | ||
| 528 | + * @brief Delete class members | ||
| 529 | + ***************************************************************************/ | ||
| 530 | +void ctexpcube::free_members(void) | ||
| 531 | +{ | ||
| 532 | + // Write separator into logger | ||
| 533 | + if (logTerse()) { | ||
| 534 | + log << std::endl; | ||
| 535 | + } | ||
| 536 | + | ||
| 537 | + // Return | ||
| 538 | + return; | ||
| 539 | +} |
src/ctexpcube/ctexpcube.hpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctexpcube - CTA exposure cube tool * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2014 by Juergen Knoedlseder * | ||
| 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 ctexpcube.hpp | ||
| 23 | + * @brief CTA exposure cube tool definition | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +#ifndef CTEXPCUBE_HPP | ||
| 28 | +#define CTEXPCUBE_HPP | ||
| 29 | + | ||
| 30 | +/* __ Includes ___________________________________________________________ */ | ||
| 31 | +#include "GammaLib.hpp" | ||
| 32 | +#include "GCTALib.hpp" | ||
| 33 | + | ||
| 34 | +/* __Definitions _________________________________________________________ */ | ||
| 35 | +#define CTEXPCUBE_NAME "ctexpcube" | ||
| 36 | +#define CTEXPCUBE_VERSION "00-01-00" | ||
| 37 | + | ||
| 38 | + | ||
| 39 | +/***********************************************************************//** | ||
| 40 | + * @class ctexpcube | ||
| 41 | + * | ||
| 42 | + * @brief CTA exposure cube tool | ||
| 43 | + ***************************************************************************/ | ||
| 44 | +class ctexpcube : public GApplication { | ||
| 45 | + | ||
| 46 | +public: | ||
| 47 | + // Constructors and destructors | ||
| 48 | + ctexpcube(void); | ||
| 49 | + explicit ctexpcube(GObservations obs); | ||
| 50 | + ctexpcube(int argc, char *argv[]); | ||
| 51 | + ctexpcube(const ctexpcube& app); | ||
| 52 | + virtual ~ctexpcube(void); | ||
| 53 | + | ||
| 54 | + // Operators | ||
| 55 | + ctexpcube& operator=(const ctexpcube& app); | ||
| 56 | + | ||
| 57 | + // Methods | ||
| 58 | + void clear(void); | ||
| 59 | + void execute(void); | ||
| 60 | + void run(void); | ||
| 61 | + void save(void); | ||
| 62 | + GObservations& obs(void) { return m_obs; } | ||
| 63 | + void get_parameters(void); | ||
| 64 | + void get_ebounds(void); | ||
| 65 | + | ||
| 66 | +protected: | ||
| 67 | + // Protected methods | ||
| 68 | + void init_members(void); | ||
| 69 | + void copy_members(const ctexpcube& app); | ||
| 70 | + void free_members(void); | ||
| 71 | + | ||
| 72 | + // User parameters | ||
| 73 | + std::string m_infile; //!< Input counts map or XML file | ||
| 74 | + std::string m_cntmap; //!< Counts map for exposure cube definition | ||
| 75 | + std::string m_outfile; //!< Output exposure cube file | ||
| 76 | + std::string m_caldb; //!< Calibration database | ||
| 77 | + std::string m_irf; //!< Instrument response functions | ||
| 78 | + bool m_apply_edisp; //!< Apply energy dispersion? | ||
| 79 | + | ||
| 80 | + // Protected members | ||
| 81 | + bool m_read_ahead; //!< Read ahead parameters | ||
| 82 | + GObservations m_obs; //!< Observation container | ||
| 83 | + GCTAExposure m_expcube; //!< Exposure cube | ||
| 84 | + GEbounds m_ebounds; //!< Energy boundaries | ||
| 85 | +}; | ||
| 86 | + | ||
| 87 | +#endif /* CTEXPCUBE_HPP */ |
src/ctexpcube/ctexpcube.par
0 → 100644
| 1 | +############################################################################# | ||
| 2 | +# # | ||
| 3 | +# CTA Science Analysis Tools # | ||
| 4 | +# # | ||
| 5 | +# ------------------------------------------------------------------------- # | ||
| 6 | +# # | ||
| 7 | +# File: ctexpcube.par # | ||
| 8 | +# Version: 00-01-00 # | ||
| 9 | +# # | ||
| 10 | +# Author: Juergen Knoedlseder # | ||
| 11 | +# Jurgen.Knodlseder@irap.omp.eu # | ||
| 12 | +# IRAP # | ||
| 13 | +# # | ||
| 14 | +# Purpose: Parameter file for the ctexpcube application # | ||
| 15 | +# # | ||
| 16 | +############################################################################# | ||
| 17 | +# | ||
| 18 | +# General parameters | ||
| 19 | +#=================== | ||
| 20 | +infile, f, a, "NONE",,, "Input event list, counts map or observation definition file" | ||
| 21 | +cntmap, f, a, "NONE",,, "Counts map for exposure cube definition" | ||
| 22 | +outfile, f, a, "expcube.fits",,, "Output exposure cube file" | ||
| 23 | +caldb, s, a, "dummy",,, "Calibration database" | ||
| 24 | +irf, s, a, "cta_dummy_irf",,, "Instrument response function" | ||
| 25 | +edisp, b, h, no,,, "Apply energy dispersion?" | ||
| 26 | +# | ||
| 27 | +# Energy binning parameters | ||
| 28 | +#========================== | ||
| 29 | +ebinalg, s, h, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins" | ||
| 30 | +emin, r, a, 0.1,,,"Start value for first energy bin in TeV" | ||
| 31 | +emax, r, a, 100.0,,,"Stop value for last energy bin in TeV" | ||
| 32 | +enumbins, i, a, 20,,,"Number of energy bins" | ||
| 33 | +ebinfile, f, h, "NONE",,,"Name of the file containing the energy bin definition" | ||
| 34 | +# | ||
| 35 | +# Spatial binning parameters | ||
| 36 | +#=========================== | ||
| 37 | +nxpix, i, a, 200,,, "Size of the X axis in pixels" | ||
| 38 | +nypix, i, a, 200,,, "Size of the Y axis in pixels" | ||
| 39 | +binsz, r, a, 0.02,,, "Image scale (in degrees/pixel)" | ||
| 40 | +coordsys, s, a, "CEL", CEL|GAL,,"Coordinate system (CEL - celestial, GAL - galactic)" | ||
| 41 | +xref, r, a, 83.63,,, "First coordinate of image center in degrees (RA or galactic l)" | ||
| 42 | +yref, r, a, 22.01,,, "Second coordinate of image center in degrees (DEC or galactic b)" | ||
| 43 | +axisrot, r, h, 0.0,,, "Rotation angle of image axis, in degrees" | ||
| 44 | +proj, s, a, "CAR", AIT|AZP|CAR|MER|STG|TAN,, "Projection method e.g. AIT|AZP|CAR|MER|STG|TAN" | ||
| 45 | +# | ||
| 46 | +# Standard parameters | ||
| 47 | +#==================== | ||
| 48 | +chatter, i, h, 2,0,4, "Chattiness of output" | ||
| 49 | +clobber, b, h, yes,,, "Overwrite existing output files with new output files?" | ||
| 50 | +debug, b, h, no,,, "Debugging mode activated" | ||
| 51 | +mode, s, h, "ql",,, "Mode of automatic parameters" | ||
| 52 | +logfile, f, h, "ctexpcube.log",,, "Log filename" |
src/ctexpcube/main.cpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctexpcube - CTA exposure cube tool * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2014 by Juergen Knoedlseder * | ||
| 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 ctexpcube/main.cpp | ||
| 23 | + * @brief CTA exposure cube tool main code | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +/* __ Includes ___________________________________________________________ */ | ||
| 28 | +#ifdef HAVE_CONFIG_H | ||
| 29 | +#include <config.h> | ||
| 30 | +#endif | ||
| 31 | +#include <cstdio> | ||
| 32 | +#include "ctexpcube.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 ctexpcube application. It allocates a | ||
| 42 | + * ctexpcube 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 | + ctexpcube 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 | + " ctexpcube. 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 | +} |