diff --git a/pyext/ctexpcube.i b/pyext/ctexpcube.i index 927e15a..a2fe192 100644 --- a/pyext/ctexpcube.i +++ b/pyext/ctexpcube.i @@ -1,5 +1,5 @@ /*************************************************************************** - * ctexpcube - CTA exposure cube tool * + * ctexpcube - Exposure cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -20,23 +20,21 @@ ***************************************************************************/ /** * @file ctexpcube.i - * @brief CTA exposure cube tool definition + * @brief Exposure cube generation tool definition * @author Juergen Knoedlseder */ %{ /* Put headers and other declarations here that are needed for compilation */ #include "ctexpcube.hpp" -#include "GTools.hpp" %} /***********************************************************************//** * @class ctexpcube * - * @brief CTA exposure cube tool + * @brief Exposure cube generation tool ***************************************************************************/ -class ctexpcube : public GApplication { - +class ctexpcube : public ctool { public: // Constructors and destructors ctexpcube(void); @@ -55,7 +53,7 @@ public: /***********************************************************************//** - * @brief CTA exposure cube tool Python extension + * @brief Exposure cube generation tool Python extension ***************************************************************************/ %extend ctexpcube { ctexpcube copy() { diff --git a/src/ctexpcube/Makefile.am b/src/ctexpcube/Makefile.am index fc8f64e..f24f80d 100644 --- a/src/ctexpcube/Makefile.am +++ b/src/ctexpcube/Makefile.am @@ -1,5 +1,8 @@ ## Process this file with automake to produce Makefile.in +# Set include directories +INCLUDES = -I$(top_srcdir)/src/support + # Program name bin_PROGRAMS = ctexpcube @@ -14,7 +17,7 @@ libctexpcube_la_SOURCES = $(sources) ctexpcube_SOURCES = main.cpp ctexpcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ ctexpcube_CPPFLAGS = @CPPFLAGS@ -ctexpcube_LDADD = libctexpcube.la +ctexpcube_LDADD = libctexpcube.la $(top_srcdir)/src/support/libsupport.la # Parameter files pfilesdir = $(prefix)/syspfiles diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index a318e8f..9becd84 100644 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -1,5 +1,5 @@ /*************************************************************************** - * ctexpcube - CTA exposure cube tool * + * ctexpcube - Exposure cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -20,7 +20,7 @@ ***************************************************************************/ /** * @file ctexpcube.cpp - * @brief CTA exposure cube tool implementation + * @brief Exposure cube generation tool implementation * @author Juergen Knoedlseder */ @@ -34,7 +34,6 @@ #include "GWcs.hpp" /* __ Method name definitions ____________________________________________ */ -#define G_GET_EBOUNDS "ctexpcube::get_ebounds()" #define G_GET_PARAMETERS "ctexpcube::get_parameters()" #define G_SET_FROM_CNTMAP "ctexpcube::set_from_cntmap(std::string&)" @@ -52,7 +51,7 @@ /***********************************************************************//** * @brief Void constructor ***************************************************************************/ -ctexpcube::ctexpcube(void) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) +ctexpcube::ctexpcube(void) : ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) { // Initialise members init_members(); @@ -74,7 +73,7 @@ ctexpcube::ctexpcube(void) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) * observations container. ***************************************************************************/ ctexpcube::ctexpcube(const GObservations& obs) : - GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) + ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) { // Initialise members init_members(); @@ -98,7 +97,7 @@ ctexpcube::ctexpcube(const GObservations& obs) : * @param[in] argv Array of command line arguments. ***************************************************************************/ ctexpcube::ctexpcube(int argc, char *argv[]) : - GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION, argc, argv) + ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION, argc, argv) { // Initialise members init_members(); @@ -116,7 +115,7 @@ ctexpcube::ctexpcube(int argc, char *argv[]) : * * @param[in] app ctexpcube application. ***************************************************************************/ -ctexpcube::ctexpcube(const ctexpcube& app) : GApplication(app) +ctexpcube::ctexpcube(const ctexpcube& app) : ctool(app) { // Initialise members init_members(); @@ -160,7 +159,7 @@ ctexpcube& ctexpcube::operator=(const ctexpcube& app) if (this != &app) { // Copy base class members - this->GApplication::operator=(app); + this->ctool::operator=(app); // Free members free_members(); @@ -191,10 +190,12 @@ void ctexpcube::clear(void) { // Free members free_members(); + this->ctool::free_members(); this->GApplication::free_members(); // Initialise members this->GApplication::init_members(); + this->ctool::init_members(); init_members(); // Return @@ -372,11 +373,6 @@ void ctexpcube::copy_members(const ctexpcube& app) ***************************************************************************/ void ctexpcube::free_members(void) { - // Write separator into logger - if (logTerse()) { - log << std::endl; - } - // Return return; } @@ -419,7 +415,7 @@ void ctexpcube::get_parameters(void) int nypix = (*this)["nypix"].integer(); // Get energy definition - get_ebounds(); + m_ebounds = get_ebounds(); // Define exposure cube m_expcube = GCTAExposure(wcs, coordsys, xref, yref, @@ -499,29 +495,11 @@ void ctexpcube::set_response(void) // Yes ... if (obs != NULL) { - // Set response if we don't have one + // If the observation has no response, then set it from + // the task parameters if (!obs->has_response()) { - - // Load response information - std::string database = (*this)["caldb"].string(); - std::string irf = (*this)["irf"].string(); - - // Set calibration database. If specified parameter is a - // directory then use this as the pathname to the calibration - // database. Otherwise interpret this as the instrument name, - // the mission being "cta" - GCaldb caldb; - if (gammalib::dir_exists(database)) { - caldb.rootdir(database); - } - else { - caldb.open("cta", database); - } - - // Set reponse - obs->response(irf, caldb); - - } // endif: observation already has a response + set_obs_response(obs); + } } // endif: observation was a CTA observation @@ -533,76 +511,6 @@ void ctexpcube::set_response(void) /***********************************************************************//** - * @brief Get energy boundaries from parameters - * - * @exception GException::invalid_value - * Invalid extension name encountered. - * - * Get the energy boundaries from the user parameters. - ***************************************************************************/ -void ctexpcube::get_ebounds(void) -{ - // Determine the energy binning alogrithm - std::string ebinalg = (*this)["ebinalg"].string(); - - // If we have the binning given by a file then try to get the boundaries - // from that file - if (ebinalg == "FILE") { - - // Get filename - std::string filename = (*this)["ebinfile"].filename(); - - // Open fits file to check which extension is given - GFits file(filename); - - // Check first for EBOUNDS extension - if (file.contains("EBOUNDS")) { - file.close(); - m_ebounds.load(filename, "EBOUNDS"); - } - - // ... then check for ENERGYBINS extension - else if (file.contains("ENERGYBINS")) { - file.close(); - m_ebounds.load(filename, "ENERGYBINS"); - } - - // ... otherwise throw an exception - else { - file.close(); - std::string msg = "No extension with name \"EBOUNDS\" or" - " \"ENERGYBINS\" found in FITS file" - " \""+filename+"\".\n" - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" - " is required if the parameter \"ebinalg\"" - " is set to \"FILE\"."; - throw GException::invalid_value(G_GET_EBOUNDS, msg); - } - } - - // ... otherwise read emin, emax and nebins - else { - - // Get the relevant parameters - double emin = (*this)["emin"].real(); - double emax = (*this)["emax"].real(); - int enumbins = (*this)["enumbins"].integer(); - bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true; - - // Create energy boundaries - m_ebounds = GEbounds(enumbins, - GEnergy(emin, "TeV"), - GEnergy(emax, "TeV"), - log); - - } - - // Return - return; -} - - -/***********************************************************************//** * @brief Set exposure cube definition from counts map * * @exception GException::invalid_value diff --git a/src/ctexpcube/ctexpcube.hpp b/src/ctexpcube/ctexpcube.hpp index 9a074d3..9f78dc3 100644 --- a/src/ctexpcube/ctexpcube.hpp +++ b/src/ctexpcube/ctexpcube.hpp @@ -1,5 +1,5 @@ /*************************************************************************** - * ctexpcube - CTA exposure cube tool * + * ctexpcube - Exposure cube generation tool * * ----------------------------------------------------------------------- * * copyright (C) 2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * @@ -20,7 +20,7 @@ ***************************************************************************/ /** * @file ctexpcube.hpp - * @brief CTA exposure cube tool definition + * @brief Exposure cube generation tool definition * @author Juergen Knoedlseder */ @@ -30,6 +30,7 @@ /* __ Includes ___________________________________________________________ */ #include "GammaLib.hpp" #include "GCTALib.hpp" +#include "ctool.hpp" /* __Definitions _________________________________________________________ */ #define CTEXPCUBE_NAME "ctexpcube" @@ -39,9 +40,9 @@ /***********************************************************************//** * @class ctexpcube * - * @brief CTA exposure cube tool + * @brief Exposure cube generation tool ***************************************************************************/ -class ctexpcube : public GApplication { +class ctexpcube : public ctool { public: // Constructors and destructors @@ -69,7 +70,6 @@ protected: void get_parameters(void); void get_obs(void); void set_response(void); - void get_ebounds(void); void set_from_cntmap(const std::string& filename); // User parameters diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index b96bb4d..6da9b84 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -29,6 +29,7 @@ #include #endif #include "ctool.hpp" +#include "GTools.hpp" /* __ Method name definitions ____________________________________________ */ #define G_GET_EBOUNDS "ctool::get_ebounds()" @@ -299,3 +300,36 @@ GEbounds ctool::get_ebounds(void) // Return energy boundaries return ebounds; } + + +/***********************************************************************//** + * @brief Set response for CTA observation + * + * @param[in,out] obs CTA observation + * + * Set the response for a CTA observation using the "database" and "irf" + * task parameters. + ***************************************************************************/ +void ctool::set_obs_response(GCTAObservation* obs) +{ + // Load response information + std::string database = (*this)["caldb"].string(); + std::string irf = (*this)["irf"].string(); + + // Set calibration database. If "database" is a valid directory then use + // this as the pathname to the calibration database. Otherwise, interpret + // "database" as the instrument name, the mission being "cta" + GCaldb caldb; + if (gammalib::dir_exists(database)) { + caldb.rootdir(database); + } + else { + caldb.open("cta", database); + } + + // Set reponse + obs->response(irf, caldb); + + // Return + return; +} diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index a0321a4..b476d8a 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -60,6 +60,7 @@ protected: void copy_members(const ctool& app); void free_members(void); GEbounds get_ebounds(void); + void set_obs_response(GCTAObservation* obs); }; #endif /* CTOOL_HPP */