From 80d8ec04d80e49d1cffef8912146ed3837d01759 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 19 Jul 2014 00:37:59 +0200 Subject: [PATCH] Add GCTAResponse::isvalid() method that checks if a response has been loaded. --- NEWS | 3 +++ gammalib.pc.in | 2 +- inst/cta/include/GCTAResponse.hpp | 3 +++ inst/cta/include/GCTAResponseCube.hpp | 42 ++++++++++++++++++++++++++++++++++++++++++ inst/cta/include/GCTAResponseIrf.hpp | 17 +++++++++++++++-- inst/cta/src/GCTAResponseCube.cpp | 90 +++++++++++++++++++----------------------------------------------------------------------- 6 files changed, 83 insertions(+), 74 deletions(-) diff --git a/NEWS b/NEWS index 356f96c..6516fe1 100644 --- a/NEWS +++ b/NEWS @@ -21,6 +21,9 @@ The following classes have been renamed: The GObservation::response() method now returns a pointer to GResponse instead of a reference. +The GCTAObservation::load(GFits&) and GCTAObservation::save(GFits&) +methods have been remaned to read() and write(). + 3. Configuration ----------------- diff --git a/gammalib.pc.in b/gammalib.pc.in index fc6a87c..9442f5f 100644 --- a/gammalib.pc.in +++ b/gammalib.pc.in @@ -6,7 +6,7 @@ includedir=${prefix}/include Name: GammaLib Description: Versatile toolbox for analysis of astronomical gamma-ray data URL: http://gammalib.sourceforge.net/ -Version: 0.8.1 +Version: 0.9.0 Requires: Requires.private: @CFITSIO@ Conflicts: diff --git a/inst/cta/include/GCTAResponse.hpp b/inst/cta/include/GCTAResponse.hpp index a5c8da7..e5c66a0 100644 --- a/inst/cta/include/GCTAResponse.hpp +++ b/inst/cta/include/GCTAResponse.hpp @@ -65,8 +65,11 @@ public: // Pure virtual methods virtual void clear(void) = 0; virtual GCTAResponse* clone(void) const = 0; + virtual bool isvalid(void) const = 0; virtual bool use_edisp(void) const = 0; virtual bool use_tdisp(void) const = 0; + virtual bool apply_edisp(void) const = 0; + virtual void apply_edisp(const bool& apply_edisp) const = 0; virtual double irf(const GEvent& event, const GPhoton& photon, const GObservation& obs) const = 0; diff --git a/inst/cta/include/GCTAResponseCube.hpp b/inst/cta/include/GCTAResponseCube.hpp index 9e61e73..e9ad527 100644 --- a/inst/cta/include/GCTAResponseCube.hpp +++ b/inst/cta/include/GCTAResponseCube.hpp @@ -63,8 +63,11 @@ public: // Implement pure virtual base class methods virtual void clear(void); virtual GCTAResponseCube* clone(void) const; + virtual bool isvalid(void) const; virtual bool use_edisp(void) const; virtual bool use_tdisp(void) const; + virtual bool apply_edisp(void) const; + virtual void apply_edisp(const bool& apply_edisp) const; virtual double irf(const GEvent& event, const GPhoton& photon, const GObservation& obs) const; @@ -89,10 +92,25 @@ private: // Private data members GCTAExposure m_exposure; //!< Exposure cube GCTAMeanPsf m_psf; //!< Mean point spread function + mutable bool m_apply_edisp; //!< Apply energy dispersion }; /***********************************************************************//** + * @brief Signal if response is valid + * + * @return True if response is valid + * + * @todo: To be implemented (check if GCTAExposure and GCTAMeanPsf is loaded) + ***************************************************************************/ +inline +bool GCTAResponseCube::isvalid(void) const +{ + return (true); +} + + +/***********************************************************************//** * @brief Signal if response uses energy dispersion * * @return True if response uses energy dispersion @@ -121,6 +139,30 @@ bool GCTAResponseCube::use_tdisp(void) const /***********************************************************************//** + * @brief Signal if energy dispersion should be applied + * + * @return True if energy dispersion should be applied + ***************************************************************************/ +inline +bool GCTAResponseCube::apply_edisp(void) const +{ + return m_apply_edisp; +} + +/***********************************************************************//** + * @brief Signal if energy dispersion should be applied + * + * @param[in] apply_edisp Set true if energy dispersion should be applied + ***************************************************************************/ +inline +void GCTAResponseCube::apply_edisp(const bool& apply_edisp) const +{ + m_apply_edisp = apply_edisp; + return; +} + + +/***********************************************************************//** * @brief Return exposure cube * * @return Reference to exposure cube. diff --git a/inst/cta/include/GCTAResponseIrf.hpp b/inst/cta/include/GCTAResponseIrf.hpp index 53a3e18..fc8ada1 100644 --- a/inst/cta/include/GCTAResponseIrf.hpp +++ b/inst/cta/include/GCTAResponseIrf.hpp @@ -74,8 +74,11 @@ public: // Implement pure virtual base class methods virtual void clear(void); virtual GCTAResponseIrf* clone(void) const; + virtual bool isvalid(void) const; virtual bool use_edisp(void) const; virtual bool use_tdisp(void) const; + virtual bool apply_edisp(void) const; + virtual void apply_edisp(const bool& apply_edisp) const; virtual double irf(const GEvent& event, const GPhoton& photon, const GObservation& obs) const; @@ -104,8 +107,6 @@ public: virtual GEbounds ebounds_src(const GEnergy& obsEnergy) const; // Other Methods - bool apply_edisp(void) const; - void apply_edisp(const bool& apply_edisp) const; GCTAEventAtom* mc(const double& area, const GPhoton& photon, const GObservation& obs, GRan& ran) const; void caldb(const GCaldb& caldb); @@ -196,6 +197,18 @@ private: /***********************************************************************//** + * @brief Signal if response is valid + * + * @return True if response is valid + ***************************************************************************/ +inline +bool GCTAResponseIrf::isvalid(void) const +{ + return ((m_aeff != NULL) && (m_psf != NULL)); +} + + +/***********************************************************************//** * @brief Signal if response uses energy dispersion * * @return True if response uses energy dispersion diff --git a/inst/cta/src/GCTAResponseCube.cpp b/inst/cta/src/GCTAResponseCube.cpp index 5ffd7ae..4c4137e 100644 --- a/inst/cta/src/GCTAResponseCube.cpp +++ b/inst/cta/src/GCTAResponseCube.cpp @@ -43,6 +43,7 @@ /* __ Method name definitions ____________________________________________ */ #define G_IRF "GCTAResponseCube::irf(GEvent&, GPhoton& GObservation&)" #define G_NPRED_DIFFUSE "GCTAResponseCube::npred(GPhoton&, GObservation&)" +#define G_READ "GCTAResponseCube::read(GXmlElement&)" /* __ Macros _____________________________________________________________ */ @@ -330,7 +331,6 @@ double GCTAResponseCube::npred(const GPhoton& photon, * * ***************************************************************************/ -#define G_READ "GCTAResponseCube::read(GXmlElement&)" void GCTAResponseCube::read(const GXmlElement& xml) { // Determine number of parameter nodes in XML element @@ -419,74 +419,6 @@ void GCTAResponseCube::write(GXmlElement& xml) const /***********************************************************************//** - * @brief Load CTA response - * - * @param[in] rspname CTA response name. - * - * Loads the CTA response with specified name @p rspname. The method first - * searchs for an appropriate response in the calibration database. If no - * appropriate response is found, the method takes the database root path - * and response name to build the full path to the response file, and tries - * to load the response from these paths. - ***************************************************************************/ -/* -void GCTAResponseCube::load(const std::string& rspname) -{ - // Clear instance but conserve calibration database - GCaldb caldb = m_caldb; - clear(); - m_caldb = caldb; - - // First attempt reading the response using the GCaldb interface - std::string expr = "NAME("+rspname+")"; - std::string aeffname = m_caldb.filename("","","EFF_AREA","","",expr); - std::string psfname = m_caldb.filename("","","RPSF","","",expr); - std::string edispname = m_caldb.filename("","","EDISP","","",expr); - std::string bgdname = m_caldb.filename("","","BGD","","",expr); - - // If filenames are empty then build filenames from CALDB root path and - // response name - if (aeffname.length() < 1) { - aeffname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); - } - if (psfname.length() < 1) { - psfname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); - } - if (edispname.length() < 1) { - edispname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); - } - if (bgdname.length() < 1) { - bgdname = irf_filename(gammalib::filepath(m_caldb.rootdir(), rspname)); - } - - // Load effective area - load_aeff(aeffname); - - // Load point spread function - load_psf(psfname); - - // Load energy dispersion - load_edisp(edispname); - - // Load background - load_background(bgdname); - - // Remove theta cut - GCTAAeffArf* arf = const_cast(dynamic_cast(m_aeff)); - if (arf != NULL) { - arf->remove_thetacut(*this); - } - - // Store response name - m_rspname = rspname; - - // Return - return; -} -*/ - - -/***********************************************************************//** * @brief Print CTA response information * * @param[in] chatter Chattiness (defaults to NORMAL). @@ -503,6 +435,20 @@ std::string GCTAResponseCube::print(const GChatter& chatter) const // Append header result.append("=== GCTAResponseCube ==="); + // Append response information + result.append("\n"+gammalib::parformat("Energy dispersion")); + if (use_edisp()) { + result.append("Used"); + } + else { + if (apply_edisp()) { + result.append("Not available"); + } + else { + result.append("Not used"); + } + } + // Append exposure cube information result.append("\n"+m_exposure.print(chatter)); @@ -544,6 +490,7 @@ void GCTAResponseCube::init_members(void) // Initialise members m_exposure.clear(); m_psf.clear(); + m_apply_edisp = false; // Return return; @@ -558,8 +505,9 @@ void GCTAResponseCube::init_members(void) void GCTAResponseCube::copy_members(const GCTAResponseCube& rsp) { // Copy members - m_exposure = rsp.m_exposure; - m_psf = rsp.m_psf; + m_exposure = rsp.m_exposure; + m_psf = rsp.m_psf; + m_apply_edisp = rsp.m_apply_edisp; // Return return; -- libgit2 0.21.4