From 118faba8a0718a96d6f4307fec111d39baea4462 Mon Sep 17 00:00:00 2001 From: chiachun Date: Sun, 3 Aug 2014 12:37:27 +0200 Subject: [PATCH] add read, write, save.. methods --- inst/cta/include/GCTAPsf2D.hpp | 35 +++++++++++++++++++++++++++++++++++ inst/cta/pyext/GCTAPsf2D.i | 8 ++++++++ inst/cta/pyext/GCTAResponseCube.i | 3 +++ inst/cta/src/GCTABackground3D.cpp | 2 +- inst/cta/src/GCTAPsf2D.cpp | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------- 5 files changed, 128 insertions(+), 14 deletions(-) diff --git a/inst/cta/include/GCTAPsf2D.hpp b/inst/cta/include/GCTAPsf2D.hpp index 14888fe..1f15085 100644 --- a/inst/cta/include/GCTAPsf2D.hpp +++ b/inst/cta/include/GCTAPsf2D.hpp @@ -34,6 +34,9 @@ #include "GCTAPsf.hpp" #include "GCTAResponseTable.hpp" +/* __ Forward declarations _______________________________________________ */ +class GFits; +class GFitsBinTable; /***********************************************************************//** * @class GCTAPsf2D @@ -82,6 +85,15 @@ public: const bool& etrue = true) const; std::string print(const GChatter& chatter = NORMAL) const; + // Methods + const GCTAResponseTable& table(void) const; + void table(const GCTAResponseTable& table); + void read(const GFits& file); + void write(GFitsBinTable& hdu) const; + void save(const std::string& filename, + const bool& clobber = false) const; + + private: // Methods void init_members(void); @@ -119,4 +131,27 @@ std::string GCTAPsf2D::filename(void) const return m_filename; } +/***********************************************************************//** + * @brief Return response table + * + * @return Response table. + ***************************************************************************/ +inline +const GCTAResponseTable& GCTAPsf2D::table(void) const +{ + return m_psf; +} + +/***********************************************************************//** + * @brief Assign response table + * + * @param[in] table Response table. + ***************************************************************************/ +inline +void GCTAPsf2D::table(const GCTAResponseTable& table) +{ + m_psf = table; +} + + #endif /* GCTAPSF2D_HPP */ diff --git a/inst/cta/pyext/GCTAPsf2D.i b/inst/cta/pyext/GCTAPsf2D.i index f9faabd..5f287b2 100644 --- a/inst/cta/pyext/GCTAPsf2D.i +++ b/inst/cta/pyext/GCTAPsf2D.i @@ -71,6 +71,14 @@ public: const double& zenith = 0.0, const double& azimuth = 0.0, const bool& etrue = true) const; + // Methods + const GCTAResponseTable& table(void) const; + void table(const GCTAResponseTable& table); + void read(const GFits& file); + void write(GFitsBinTable& hdu) const; + void save(const std::string& filename, + const bool& clobber = false) const; + }; diff --git a/inst/cta/pyext/GCTAResponseCube.i b/inst/cta/pyext/GCTAResponseCube.i index 54a32a1..ab3cc16 100644 --- a/inst/cta/pyext/GCTAResponseCube.i +++ b/inst/cta/pyext/GCTAResponseCube.i @@ -50,6 +50,9 @@ public: virtual double irf(const GEvent& event, const GPhoton& photon, const GObservation& obs) const; + virtual double irf(const GEvent& event, + const GSource& source, + const GObservation& obs) const; virtual double npred(const GPhoton& photon, const GObservation& obs) const; virtual void read(const GXmlElement& xml); diff --git a/inst/cta/src/GCTABackground3D.cpp b/inst/cta/src/GCTABackground3D.cpp index 52a42d9..b5810ee 100644 --- a/inst/cta/src/GCTABackground3D.cpp +++ b/inst/cta/src/GCTABackground3D.cpp @@ -305,7 +305,7 @@ GCTABackground3D* GCTABackground3D::clone(void) const * * @param[in] fits FITS file pointer. * - * Reads the background form the FITS file extension "BACKGROUND". The data + * Reads the background from the FITS file extension "BACKGROUND". The data * are stored in m_background which is of type GCTAResponseTable. The DETX * and DETY axes will be set to radians, the energy axis will be set to * log10. diff --git a/inst/cta/src/GCTAPsf2D.cpp b/inst/cta/src/GCTAPsf2D.cpp index 0b18bcf..7e34a88 100644 --- a/inst/cta/src/GCTAPsf2D.cpp +++ b/inst/cta/src/GCTAPsf2D.cpp @@ -31,6 +31,8 @@ #include #include "GTools.hpp" #include "GMath.hpp" +#include "GFits.hpp" +#include "GFitsBinTable.hpp" #include "GCTAPsf2D.hpp" #include "GCTAException.hpp" @@ -266,25 +268,23 @@ GCTAPsf2D* GCTAPsf2D::clone(void) const return new GCTAPsf2D(*this); } - /***********************************************************************//** - * @brief Load point spread function from performance table - * - * @param[in] filename Performance table file name. + * @brief Read PSF from FITS file * - * @exception GCTAExceptionHandler::file_open_error - * File could not be opened for read access. + * @param[in] fits FITS file pointer. * - * This method loads the point spread function information from a PSF - * response table. + * Reads the PSF from the FITS file extension "POINT SPREAD FUNCTION". The data + * are stored in m_psf which is of type GCTAResponseTable. + * The energy axis will be set to log10. The offset angle axis and + * sigma parameter columns will be set to radians. ***************************************************************************/ -void GCTAPsf2D::load(const std::string& filename) +void GCTAPsf2D::read(const GFits& fits) { - // Open PSF FITS file - GFits file(filename); + // Clear response table + m_psf.clear(); // Get PSF table - const GFitsTable& table = *file.table("POINT SPREAD FUNCTION"); + const GFitsTable& table = *fits.table("POINT SPREAD FUNCTION"); // Read PSF table m_psf.read(table); @@ -300,8 +300,34 @@ void GCTAPsf2D::load(const std::string& filename) m_psf.scale(3, gammalib::deg2rad); m_psf.scale(5, gammalib::deg2rad); + // Return + return; +} + + + + + +/***********************************************************************//** + * @brief Load point spread function from performance table + * + * @param[in] filename Performance table file name. + * + * @exception GCTAExceptionHandler::file_open_error + * File could not be opened for read access. + * + * This method loads the point spread function information from a PSF + * response table. + ***************************************************************************/ +void GCTAPsf2D::load(const std::string& filename) +{ + // Open PSF FITS file + GFits fits(filename); + + read(fits); + // Close PSF FITS file - file.close(); + fits.close(); // Store filename m_filename = filename; @@ -310,6 +336,48 @@ void GCTAPsf2D::load(const std::string& filename) return; } +/***********************************************************************//** + * @brief Write CTA PSF table into FITS binary table object. + * + * @param[in] hdu FITS binary table. + * + * @todo Add necessary keywords. + ***************************************************************************/ +void GCTAPsf2D::write(GFitsBinTable& hdu) const +{ + // Write background table + m_psf.write(hdu); + + // Return + return; +} + +/***********************************************************************//** + * @brief Save PSF table into FITS file + * + * @param[in] filename PSF table FITS file name. + * @param[in] clobber Overwrite existing file? (true=yes) + * + * Save the PSF table into a FITS file. + ***************************************************************************/ +void GCTAPsf2D::save(const std::string& filename, const bool& clobber) const +{ + // Create binary table + GFitsBinTable table; + table.extname("POINT SPREAD FUNCTION"); + + // Write the PSF table + write(table); + + // Create FITS file, append table, and write into the file + GFits fits; + fits.append(table); + fits.saveto(filename, clobber); + + // Return + return; +} + /***********************************************************************//** * @brief Simulate PSF offset (radians) -- libgit2 0.21.4