Commit cf66c968c0fe8f0f7302faff73dd0f6253b92e02
1 parent
34241e62
add diffrsp(), clear() and print() methods
Showing
3 changed files
with
112 additions
and
23 deletions
include/GResponse.hpp
| ... | ... | @@ -20,6 +20,10 @@ |
| 20 | 20 | #define GRESPONSE_HPP |
| 21 | 21 | |
| 22 | 22 | /* __ Includes ___________________________________________________________ */ |
| 23 | +#include <string> | |
| 24 | +#include <iostream> | |
| 25 | +#include "GLog.hpp" | |
| 26 | +#include "GEvent.hpp" | |
| 23 | 27 | #include "GPointing.hpp" |
| 24 | 28 | #include "GInstDir.hpp" |
| 25 | 29 | #include "GRoi.hpp" |
| ... | ... | @@ -29,6 +33,9 @@ |
| 29 | 33 | #include "GEnergy.hpp" |
| 30 | 34 | #include "GTime.hpp" |
| 31 | 35 | |
| 36 | +/* __ Forward declarations _______________________________________________ */ | |
| 37 | +class GModel; | |
| 38 | + | |
| 32 | 39 | |
| 33 | 40 | /***********************************************************************//** |
| 34 | 41 | * @class GResponse |
| ... | ... | @@ -42,6 +49,10 @@ |
| 42 | 49 | ***************************************************************************/ |
| 43 | 50 | class GResponse { |
| 44 | 51 | |
| 52 | + // I/O friends | |
| 53 | + friend std::ostream& operator<< (std::ostream& os, const GResponse& rsp); | |
| 54 | + friend GLog& operator<< (GLog& log, const GResponse& rsp); | |
| 55 | + | |
| 45 | 56 | public: |
| 46 | 57 | // Constructors and destructors |
| 47 | 58 | GResponse(void); |
| ... | ... | @@ -51,10 +62,21 @@ public: |
| 51 | 62 | // Operators |
| 52 | 63 | virtual GResponse& operator= (const GResponse& rsp); |
| 53 | 64 | |
| 65 | + // Pure virtual methods | |
| 66 | + virtual void clear(void) = 0; | |
| 67 | + virtual GResponse* clone(void) const = 0; | |
| 68 | + virtual void load(const std::string& irfname) = 0; | |
| 69 | + virtual bool hasedisp(void) const = 0; | |
| 70 | + virtual bool hastdisp(void) const = 0; | |
| 71 | + virtual std::string print(void) const = 0; | |
| 72 | + | |
| 54 | 73 | // Reponse function computation methods |
| 55 | 74 | virtual double irf(const GInstDir& obsDir, const GEnergy& obsEng, const GTime& obsTime, |
| 56 | 75 | const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 57 | 76 | const GPointing& pnt) const; |
| 77 | + virtual double diffrsp(const GEvent& event, const GModel& model, | |
| 78 | + const GEnergy& srcEng, const GTime& srcTime, | |
| 79 | + const GPointing& pnt) const; | |
| 58 | 80 | virtual double live(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 59 | 81 | const GPointing& pnt) const = 0; |
| 60 | 82 | virtual double aeff(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| ... | ... | @@ -78,12 +100,6 @@ public: |
| 78 | 100 | virtual double ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 79 | 101 | const GPointing& pnt, const GGti& gti) const; |
| 80 | 102 | |
| 81 | - // Pure virtual methods | |
| 82 | - virtual GResponse* clone(void) const = 0; | |
| 83 | - virtual void load(const std::string& irfname) = 0; | |
| 84 | - virtual bool hasedisp(void) const = 0; | |
| 85 | - virtual bool hastdisp(void) const = 0; | |
| 86 | - | |
| 87 | 103 | // Other methods |
| 88 | 104 | virtual void caldb(const std::string& caldb); |
| 89 | 105 | virtual std::string caldb(void) const { return m_caldb; } | ... | ... |
pyext/GResponse.i
| ... | ... | @@ -33,10 +33,20 @@ public: |
| 33 | 33 | GResponse(const GResponse& rsp); |
| 34 | 34 | virtual ~GResponse(void); |
| 35 | 35 | |
| 36 | + // Pure virtual methods | |
| 37 | + virtual void clear(void) = 0; | |
| 38 | + virtual GResponse* clone(void) const = 0; | |
| 39 | + virtual void load(const std::string& irfname) = 0; | |
| 40 | + virtual bool hasedisp(void) const = 0; | |
| 41 | + virtual bool hastdisp(void) const = 0; | |
| 42 | + | |
| 36 | 43 | // Reponse function computation methods |
| 37 | 44 | virtual double irf(const GInstDir& obsDir, const GEnergy& obsEng, const GTime& obsTime, |
| 38 | 45 | const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 39 | 46 | const GPointing& pnt) const; |
| 47 | + virtual double diffrsp(const GEvent& event, const GModel& model, | |
| 48 | + const GEnergy& srcEng, const GTime& srcTime, | |
| 49 | + const GPointing& pnt) const; | |
| 40 | 50 | virtual double live(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 41 | 51 | const GPointing& pnt) const = 0; |
| 42 | 52 | virtual double aeff(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| ... | ... | @@ -60,13 +70,18 @@ public: |
| 60 | 70 | virtual double ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, const GTime& srcTime, |
| 61 | 71 | const GPointing& pnt, const GGti& gti) const; |
| 62 | 72 | |
| 63 | - // Pure virtual methods | |
| 64 | - virtual GResponse* clone(void) const = 0; | |
| 65 | - virtual void load(const std::string& irfname) = 0; | |
| 66 | - virtual bool hasedisp(void) const = 0; | |
| 67 | - virtual bool hastdisp(void) const = 0; | |
| 68 | - | |
| 69 | 73 | // Other methods |
| 70 | 74 | virtual void caldb(const std::string& caldb); |
| 71 | 75 | virtual std::string caldb(void) const { return m_caldb; } |
| 72 | 76 | }; |
| 77 | + | |
| 78 | + | |
| 79 | +/***********************************************************************//** | |
| 80 | + * @brief GResponse class extension | |
| 81 | + ***************************************************************************/ | |
| 82 | +%extend GResponse { | |
| 83 | + char *__str__() { | |
| 84 | + static std::string result = self->print(); | |
| 85 | + return ((char*)result.c_str()); | |
| 86 | + } | |
| 87 | +}; | ... | ... |
src/obs/GResponse.cpp
| ... | ... | @@ -15,11 +15,10 @@ |
| 15 | 15 | #ifdef HAVE_CONFIG_H |
| 16 | 16 | #include <config.h> |
| 17 | 17 | #endif |
| 18 | -//#include <iostream> | |
| 19 | 18 | #include <string> |
| 20 | 19 | #include <unistd.h> // access() function |
| 21 | -#include "GException.hpp" | |
| 22 | 20 | #include "GResponse.hpp" |
| 21 | +#include "GException.hpp" | |
| 23 | 22 | |
| 24 | 23 | /* __ Method name definitions ____________________________________________ */ |
| 25 | 24 | #define G_CALDB "GResponse::caldb(std::string&)" |
| ... | ... | @@ -39,7 +38,7 @@ |
| 39 | 38 | ==========================================================================*/ |
| 40 | 39 | |
| 41 | 40 | /***********************************************************************//** |
| 42 | - * @brief Constructor | |
| 41 | + * @brief Void constructor | |
| 43 | 42 | ***************************************************************************/ |
| 44 | 43 | GResponse::GResponse(void) |
| 45 | 44 | { |
| ... | ... | @@ -121,15 +120,15 @@ GResponse& GResponse::operator= (const GResponse& rsp) |
| 121 | 120 | ==========================================================================*/ |
| 122 | 121 | |
| 123 | 122 | /***********************************************************************//** |
| 124 | - * @brief Return value of instrument response function. | |
| 123 | + * @brief Return value of point source instrument response function. | |
| 125 | 124 | * |
| 126 | - * @param[in] obsDir Pointer to observed photon direction. | |
| 125 | + * @param[in] obsDir Observed photon direction. | |
| 127 | 126 | * @param[in] obsEng Observed energy of photon. |
| 128 | 127 | * @param[in] obsTime Observed photon arrival time. |
| 129 | 128 | * @param[in] srcDir True photon direction. |
| 130 | 129 | * @param[in] srcEng True energy of photon. |
| 131 | 130 | * @param[in] srcTime True photon arrival time. |
| 132 | - * @param[in] pnt Pointer to instrument pointing information. | |
| 131 | + * @param[in] pnt Instrument pointing information. | |
| 133 | 132 | * |
| 134 | 133 | * This method implements the default and complete instrument response |
| 135 | 134 | * 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, |
| 140 | 139 | const GSkyDir& srcDir, const GEnergy& srcEng, |
| 141 | 140 | const GTime& srcTime, const GPointing& pnt) const |
| 142 | 141 | { |
| 143 | - // Get IRF components | |
| 142 | + // Get point source IRF components | |
| 144 | 143 | double irf = live(srcDir, srcEng, srcTime, pnt); |
| 145 | 144 | irf *= aeff(srcDir, srcEng, srcTime, pnt); |
| 146 | 145 | irf *= psf(obsDir, srcDir, srcEng, srcTime, pnt); |
| ... | ... | @@ -153,12 +152,39 @@ double GResponse::irf(const GInstDir& obsDir, const GEnergy& obsEng, |
| 153 | 152 | |
| 154 | 153 | |
| 155 | 154 | /***********************************************************************//** |
| 155 | + * @brief Return value of diffuse instrument response function. | |
| 156 | + * | |
| 157 | + * @param[in] event Observed event. | |
| 158 | + * @param[in] model Source model. | |
| 159 | + * @param[in] srcEng True energy of photon. | |
| 160 | + * @param[in] srcTime True photon arrival time. | |
| 161 | + * @param[in] pnt Instrument pointing information. | |
| 162 | + * | |
| 163 | + * This method implements the default and complete diffuse instrument | |
| 164 | + * response function (IRF). It may be overwritted by a specific method in the | |
| 165 | + * derived class that drops response terms that are not used. | |
| 166 | + * | |
| 167 | + * @todo Not yet implemented | |
| 168 | + ***************************************************************************/ | |
| 169 | +double GResponse::diffrsp(const GEvent& event, const GModel& model, | |
| 170 | + const GEnergy& srcEng, const GTime& srcTime, | |
| 171 | + const GPointing& pnt) const | |
| 172 | +{ | |
| 173 | + // Get diffuse IRF components | |
| 174 | + double irf = 1.0; | |
| 175 | + | |
| 176 | + // Return IRF value | |
| 177 | + return irf; | |
| 178 | +} | |
| 179 | + | |
| 180 | + | |
| 181 | +/***********************************************************************//** | |
| 156 | 182 | * @brief Return integral of instrument response function. |
| 157 | 183 | * |
| 158 | 184 | * @param[in] srcDir True photon direction. |
| 159 | 185 | * @param[in] srcEng True energy of photon. |
| 160 | 186 | * @param[in] srcTime True photon arrival time. |
| 161 | - * @param[in] pnt Pointer to instrument pointing information. | |
| 187 | + * @param[in] pnt Instrument pointing information. | |
| 162 | 188 | * @param[in] roi Region of interest of data selection. |
| 163 | 189 | * @param[in] ebds Energy boundaries of data selection. |
| 164 | 190 | * @param[in] gti Good Time Intervals of data selection. |
| ... | ... | @@ -185,12 +211,13 @@ double GResponse::nirf(const GSkyDir& srcDir, const GEnergy& srcEng, |
| 185 | 211 | |
| 186 | 212 | |
| 187 | 213 | /***********************************************************************//** |
| 188 | - * @brief Return energy dispersion integral for the case of no energy dispersion | |
| 214 | + * @brief Return energy dispersion integral for the case of no energy | |
| 215 | + * dispersion | |
| 189 | 216 | * |
| 190 | 217 | * @param[in] srcDir True photon direction. |
| 191 | 218 | * @param[in] srcEng True energy of photon. |
| 192 | 219 | * @param[in] srcTime True photon arrival time. |
| 193 | - * @param[in] pnt Pointer to instrument pointing information. | |
| 220 | + * @param[in] pnt Instrument pointing information. | |
| 194 | 221 | * @param[in] ebds Energy boundaries of data selection. |
| 195 | 222 | ***************************************************************************/ |
| 196 | 223 | double GResponse::nedisp(const GSkyDir& srcDir, const GEnergy& srcEng, |
| ... | ... | @@ -211,7 +238,7 @@ double GResponse::nedisp(const GSkyDir& srcDir, const GEnergy& srcEng, |
| 211 | 238 | * @param[in] srcDir True photon direction. |
| 212 | 239 | * @param[in] srcEng True energy of photon. |
| 213 | 240 | * @param[in] srcTime True photon arrival time. |
| 214 | - * @param[in] pnt Pointer to instrument pointing information. | |
| 241 | + * @param[in] pnt Instrument pointing information. | |
| 215 | 242 | * @param[in] gti Good Time Intervals of data selection. |
| 216 | 243 | ***************************************************************************/ |
| 217 | 244 | double GResponse::ntdisp(const GSkyDir& srcDir, const GEnergy& srcEng, |
| ... | ... | @@ -300,3 +327,34 @@ void GResponse::free_members(void) |
| 300 | 327 | = Friends = |
| 301 | 328 | = = |
| 302 | 329 | ==========================================================================*/ |
| 330 | + | |
| 331 | +/***********************************************************************//** | |
| 332 | + * @brief Output operator | |
| 333 | + * | |
| 334 | + * @param[in] os Output stream. | |
| 335 | + * @param[in] rsp Response. | |
| 336 | + ***************************************************************************/ | |
| 337 | +std::ostream& operator<< (std::ostream& os, const GResponse& rsp) | |
| 338 | +{ | |
| 339 | + // Write response in output stream | |
| 340 | + os << rsp.print(); | |
| 341 | + | |
| 342 | + // Return output stream | |
| 343 | + return os; | |
| 344 | +} | |
| 345 | + | |
| 346 | + | |
| 347 | +/***********************************************************************//** | |
| 348 | + * @brief Log operator | |
| 349 | + * | |
| 350 | + * @param[in] log Logger. | |
| 351 | + * @param[in] rsp Response. | |
| 352 | + ***************************************************************************/ | |
| 353 | +GLog& operator<< (GLog& log, const GResponse& rsp) | |
| 354 | +{ | |
| 355 | + // Write response into logger | |
| 356 | + log << rsp.print(); | |
| 357 | + | |
| 358 | + // Return logger | |
| 359 | + return log; | |
| 360 | +} | ... | ... |