From cf66c968c0fe8f0f7302faff73dd0f6253b92e02 Mon Sep 17 00:00:00 2001 From: knodlseder <> Date: Wed, 8 Dec 2010 20:04:56 +0000 Subject: [PATCH] add diffrsp(), clear() and print() methods --- include/GResponse.hpp | 28 ++++++++++++++++++++++------ pyext/GResponse.i | 27 +++++++++++++++++++++------ src/obs/GResponse.cpp | 80 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 112 insertions(+), 23 deletions(-) diff --git a/include/GResponse.hpp b/include/GResponse.hpp index 70fb3a0..407f176 100644 --- a/include/GResponse.hpp +++ b/include/GResponse.hpp @@ -20,6 +20,10 @@ #define GRESPONSE_HPP /* __ Includes ___________________________________________________________ */ +#include +#include +#include "GLog.hpp" +#include "GEvent.hpp" #include "GPointing.hpp" #include "GInstDir.hpp" #include "GRoi.hpp" @@ -29,6 +33,9 @@ #include "GEnergy.hpp" #include "GTime.hpp" +/* __ Forward declarations _______________________________________________ */ +class GModel; + /***********************************************************************//** * @class GResponse @@ -42,6 +49,10 @@ ***************************************************************************/ class GResponse { + // I/O friends + friend std::ostream& operator<< (std::ostream& os, const GResponse& rsp); + friend GLog& operator<< (GLog& log, const GResponse& rsp); + public: // Constructors and destructors GResponse(void); @@ -51,10 +62,21 @@ public: // Operators virtual GResponse& operator= (const GResponse& rsp); + // Pure virtual methods + virtual void clear(void) = 0; + virtual GResponse* clone(void) const = 0; + virtual void load(const std::string& irfname) = 0; + virtual bool hasedisp(void) const = 0; + virtual bool hastdisp(void) const = 0; + virtual std::string print(void) const = 0; + // Reponse function computation methods virtual double irf(const GInstDir& obsDir, const GEnergy& obsEng, const GTime& obsTime, const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt) const; + virtual double diffrsp(const GEvent& event, const GModel& model, + const GEnergy& srcEng, const GTime& srcTime, + const GPointing& pnt) const; virtual double live(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt) const = 0; virtual double aeff(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, @@ -78,12 +100,6 @@ public: virtual double ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt, const GGti& gti) const; - // Pure virtual methods - virtual GResponse* clone(void) const = 0; - virtual void load(const std::string& irfname) = 0; - virtual bool hasedisp(void) const = 0; - virtual bool hastdisp(void) const = 0; - // Other methods virtual void caldb(const std::string& caldb); virtual std::string caldb(void) const { return m_caldb; } diff --git a/pyext/GResponse.i b/pyext/GResponse.i index f3d5650..1e64197 100644 --- a/pyext/GResponse.i +++ b/pyext/GResponse.i @@ -33,10 +33,20 @@ public: GResponse(const GResponse& rsp); virtual ~GResponse(void); + // Pure virtual methods + virtual void clear(void) = 0; + virtual GResponse* clone(void) const = 0; + virtual void load(const std::string& irfname) = 0; + virtual bool hasedisp(void) const = 0; + virtual bool hastdisp(void) const = 0; + // Reponse function computation methods virtual double irf(const GInstDir& obsDir, const GEnergy& obsEng, const GTime& obsTime, const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt) const; + virtual double diffrsp(const GEvent& event, const GModel& model, + const GEnergy& srcEng, const GTime& srcTime, + const GPointing& pnt) const; virtual double live(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt) const = 0; virtual double aeff(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, @@ -60,13 +70,18 @@ public: virtual double ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt, const GGti& gti) const; - // Pure virtual methods - virtual GResponse* clone(void) const = 0; - virtual void load(const std::string& irfname) = 0; - virtual bool hasedisp(void) const = 0; - virtual bool hastdisp(void) const = 0; - // Other methods virtual void caldb(const std::string& caldb); virtual std::string caldb(void) const { return m_caldb; } }; + + +/***********************************************************************//** + * @brief GResponse class extension + ***************************************************************************/ +%extend GResponse { + char *__str__() { + static std::string result = self->print(); + return ((char*)result.c_str()); + } +}; diff --git a/src/obs/GResponse.cpp b/src/obs/GResponse.cpp index 5d7022c..037df90 100644 --- a/src/obs/GResponse.cpp +++ b/src/obs/GResponse.cpp @@ -15,11 +15,10 @@ #ifdef HAVE_CONFIG_H #include #endif -//#include #include #include // access() function -#include "GException.hpp" #include "GResponse.hpp" +#include "GException.hpp" /* __ Method name definitions ____________________________________________ */ #define G_CALDB "GResponse::caldb(std::string&)" @@ -39,7 +38,7 @@ ==========================================================================*/ /***********************************************************************//** - * @brief Constructor + * @brief Void constructor ***************************************************************************/ GResponse::GResponse(void) { @@ -121,15 +120,15 @@ GResponse& GResponse::operator= (const GResponse& rsp) ==========================================================================*/ /***********************************************************************//** - * @brief Return value of instrument response function. + * @brief Return value of point source instrument response function. * - * @param[in] obsDir Pointer to observed photon direction. + * @param[in] obsDir Observed photon direction. * @param[in] obsEng Observed energy of photon. * @param[in] obsTime Observed photon arrival time. * @param[in] srcDir True photon direction. * @param[in] srcEng True energy of photon. * @param[in] srcTime True photon arrival time. - * @param[in] pnt Pointer to instrument pointing information. + * @param[in] pnt Instrument pointing information. * * This method implements the default and complete instrument response * function (IRF). It may be overwritted by a specific method in the derived @@ -140,7 +139,7 @@ double GResponse::irf(const GInstDir& obsDir, const GEnergy& obsEng, const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, const GPointing& pnt) const { - // Get IRF components + // Get point source IRF components double irf = live(srcDir, srcEng, srcTime, pnt); irf *= aeff(srcDir, srcEng, srcTime, pnt); irf *= psf(obsDir, srcDir, srcEng, srcTime, pnt); @@ -153,12 +152,39 @@ double GResponse::irf(const GInstDir& obsDir, const GEnergy& obsEng, /***********************************************************************//** + * @brief Return value of diffuse instrument response function. + * + * @param[in] event Observed event. + * @param[in] model Source model. + * @param[in] srcEng True energy of photon. + * @param[in] srcTime True photon arrival time. + * @param[in] pnt Instrument pointing information. + * + * This method implements the default and complete diffuse instrument + * response function (IRF). It may be overwritted by a specific method in the + * derived class that drops response terms that are not used. + * + * @todo Not yet implemented + ***************************************************************************/ +double GResponse::diffrsp(const GEvent& event, const GModel& model, + const GEnergy& srcEng, const GTime& srcTime, + const GPointing& pnt) const +{ + // Get diffuse IRF components + double irf = 1.0; + + // Return IRF value + return irf; +} + + +/***********************************************************************//** * @brief Return integral of instrument response function. * * @param[in] srcDir True photon direction. * @param[in] srcEng True energy of photon. * @param[in] srcTime True photon arrival time. - * @param[in] pnt Pointer to instrument pointing information. + * @param[in] pnt Instrument pointing information. * @param[in] roi Region of interest of data selection. * @param[in] ebds Energy boundaries of data selection. * @param[in] gti Good Time Intervals of data selection. @@ -185,12 +211,13 @@ double GResponse::nirf(const GSkyDir& srcDir, const GEnergy& srcEng, /***********************************************************************//** - * @brief Return energy dispersion integral for the case of no energy dispersion + * @brief Return energy dispersion integral for the case of no energy + * dispersion * * @param[in] srcDir True photon direction. * @param[in] srcEng True energy of photon. * @param[in] srcTime True photon arrival time. - * @param[in] pnt Pointer to instrument pointing information. + * @param[in] pnt Instrument pointing information. * @param[in] ebds Energy boundaries of data selection. ***************************************************************************/ double GResponse::nedisp(const GSkyDir& srcDir, const GEnergy& srcEng, @@ -211,7 +238,7 @@ double GResponse::nedisp(const GSkyDir& srcDir, const GEnergy& srcEng, * @param[in] srcDir True photon direction. * @param[in] srcEng True energy of photon. * @param[in] srcTime True photon arrival time. - * @param[in] pnt Pointer to instrument pointing information. + * @param[in] pnt Instrument pointing information. * @param[in] gti Good Time Intervals of data selection. ***************************************************************************/ double GResponse::ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, @@ -300,3 +327,34 @@ void GResponse::free_members(void) = Friends = = = ==========================================================================*/ + +/***********************************************************************//** + * @brief Output operator + * + * @param[in] os Output stream. + * @param[in] rsp Response. + ***************************************************************************/ +std::ostream& operator<< (std::ostream& os, const GResponse& rsp) +{ + // Write response in output stream + os << rsp.print(); + + // Return output stream + return os; +} + + +/***********************************************************************//** + * @brief Log operator + * + * @param[in] log Logger. + * @param[in] rsp Response. + ***************************************************************************/ +GLog& operator<< (GLog& log, const GResponse& rsp) +{ + // Write response into logger + log << rsp.print(); + + // Return logger + return log; +} -- libgit2 0.21.4