Commit 118faba8a0718a96d6f4307fec111d39baea4462

Authored by chiachun
1 parent 9c966eb3

add read, write, save.. methods

inst/cta/include/GCTAPsf2D.hpp
... ... @@ -34,6 +34,9 @@
34 34 #include "GCTAPsf.hpp"
35 35 #include "GCTAResponseTable.hpp"
36 36  
  37 +/* __ Forward declarations _______________________________________________ */
  38 +class GFits;
  39 +class GFitsBinTable;
37 40  
38 41 /***********************************************************************//**
39 42 * @class GCTAPsf2D
... ... @@ -82,6 +85,15 @@ public:
82 85 const bool& etrue = true) const;
83 86 std::string print(const GChatter& chatter = NORMAL) const;
84 87  
  88 + // Methods
  89 + const GCTAResponseTable& table(void) const;
  90 + void table(const GCTAResponseTable& table);
  91 + void read(const GFits& file);
  92 + void write(GFitsBinTable& hdu) const;
  93 + void save(const std::string& filename,
  94 + const bool& clobber = false) const;
  95 +
  96 +
85 97 private:
86 98 // Methods
87 99 void init_members(void);
... ... @@ -119,4 +131,27 @@ std::string GCTAPsf2D::filename(void) const
119 131 return m_filename;
120 132 }
121 133  
  134 +/***********************************************************************//**
  135 + * @brief Return response table
  136 + *
  137 + * @return Response table.
  138 + ***************************************************************************/
  139 +inline
  140 +const GCTAResponseTable& GCTAPsf2D::table(void) const
  141 +{
  142 + return m_psf;
  143 +}
  144 +
  145 +/***********************************************************************//**
  146 + * @brief Assign response table
  147 + *
  148 + * @param[in] table Response table.
  149 + ***************************************************************************/
  150 +inline
  151 +void GCTAPsf2D::table(const GCTAResponseTable& table)
  152 +{
  153 + m_psf = table;
  154 +}
  155 +
  156 +
122 157 #endif /* GCTAPSF2D_HPP */
... ...
inst/cta/pyext/GCTAPsf2D.i
... ... @@ -71,6 +71,14 @@ public:
71 71 const double& zenith = 0.0,
72 72 const double& azimuth = 0.0,
73 73 const bool& etrue = true) const;
  74 + // Methods
  75 + const GCTAResponseTable& table(void) const;
  76 + void table(const GCTAResponseTable& table);
  77 + void read(const GFits& file);
  78 + void write(GFitsBinTable& hdu) const;
  79 + void save(const std::string& filename,
  80 + const bool& clobber = false) const;
  81 +
74 82 };
75 83  
76 84  
... ...
inst/cta/pyext/GCTAResponseCube.i
... ... @@ -50,6 +50,9 @@ public:
50 50 virtual double irf(const GEvent& event,
51 51 const GPhoton& photon,
52 52 const GObservation& obs) const;
  53 + virtual double irf(const GEvent& event,
  54 + const GSource& source,
  55 + const GObservation& obs) const;
53 56 virtual double npred(const GPhoton& photon,
54 57 const GObservation& obs) const;
55 58 virtual void read(const GXmlElement& xml);
... ...
inst/cta/src/GCTABackground3D.cpp
... ... @@ -305,7 +305,7 @@ GCTABackground3D* GCTABackground3D::clone(void) const
305 305 *
306 306 * @param[in] fits FITS file pointer.
307 307 *
308   - * Reads the background form the FITS file extension "BACKGROUND". The data
  308 + * Reads the background from the FITS file extension "BACKGROUND". The data
309 309 * are stored in m_background which is of type GCTAResponseTable. The DETX
310 310 * and DETY axes will be set to radians, the energy axis will be set to
311 311 * log10.
... ...
inst/cta/src/GCTAPsf2D.cpp
... ... @@ -31,6 +31,8 @@
31 31 #include <cmath>
32 32 #include "GTools.hpp"
33 33 #include "GMath.hpp"
  34 +#include "GFits.hpp"
  35 +#include "GFitsBinTable.hpp"
34 36 #include "GCTAPsf2D.hpp"
35 37 #include "GCTAException.hpp"
36 38  
... ... @@ -266,25 +268,23 @@ GCTAPsf2D* GCTAPsf2D::clone(void) const
266 268 return new GCTAPsf2D(*this);
267 269 }
268 270  
269   -
270 271 /***********************************************************************//**
271   - * @brief Load point spread function from performance table
272   - *
273   - * @param[in] filename Performance table file name.
  272 + * @brief Read PSF from FITS file
274 273 *
275   - * @exception GCTAExceptionHandler::file_open_error
276   - * File could not be opened for read access.
  274 + * @param[in] fits FITS file pointer.
277 275 *
278   - * This method loads the point spread function information from a PSF
279   - * response table.
  276 + * Reads the PSF from the FITS file extension "POINT SPREAD FUNCTION". The data
  277 + * are stored in m_psf which is of type GCTAResponseTable.
  278 + * The energy axis will be set to log10. The offset angle axis and
  279 + * sigma parameter columns will be set to radians.
280 280 ***************************************************************************/
281   -void GCTAPsf2D::load(const std::string& filename)
  281 +void GCTAPsf2D::read(const GFits& fits)
282 282 {
283   - // Open PSF FITS file
284   - GFits file(filename);
  283 + // Clear response table
  284 + m_psf.clear();
285 285  
286 286 // Get PSF table
287   - const GFitsTable& table = *file.table("POINT SPREAD FUNCTION");
  287 + const GFitsTable& table = *fits.table("POINT SPREAD FUNCTION");
288 288  
289 289 // Read PSF table
290 290 m_psf.read(table);
... ... @@ -300,8 +300,34 @@ void GCTAPsf2D::load(const std::string&amp; filename)
300 300 m_psf.scale(3, gammalib::deg2rad);
301 301 m_psf.scale(5, gammalib::deg2rad);
302 302  
  303 + // Return
  304 + return;
  305 +}
  306 +
  307 +
  308 +
  309 +
  310 +
  311 +/***********************************************************************//**
  312 + * @brief Load point spread function from performance table
  313 + *
  314 + * @param[in] filename Performance table file name.
  315 + *
  316 + * @exception GCTAExceptionHandler::file_open_error
  317 + * File could not be opened for read access.
  318 + *
  319 + * This method loads the point spread function information from a PSF
  320 + * response table.
  321 + ***************************************************************************/
  322 +void GCTAPsf2D::load(const std::string& filename)
  323 +{
  324 + // Open PSF FITS file
  325 + GFits fits(filename);
  326 +
  327 + read(fits);
  328 +
303 329 // Close PSF FITS file
304   - file.close();
  330 + fits.close();
305 331  
306 332 // Store filename
307 333 m_filename = filename;
... ... @@ -310,6 +336,48 @@ void GCTAPsf2D::load(const std::string&amp; filename)
310 336 return;
311 337 }
312 338  
  339 +/***********************************************************************//**
  340 + * @brief Write CTA PSF table into FITS binary table object.
  341 + *
  342 + * @param[in] hdu FITS binary table.
  343 + *
  344 + * @todo Add necessary keywords.
  345 + ***************************************************************************/
  346 +void GCTAPsf2D::write(GFitsBinTable& hdu) const
  347 +{
  348 + // Write background table
  349 + m_psf.write(hdu);
  350 +
  351 + // Return
  352 + return;
  353 +}
  354 +
  355 +/***********************************************************************//**
  356 + * @brief Save PSF table into FITS file
  357 + *
  358 + * @param[in] filename PSF table FITS file name.
  359 + * @param[in] clobber Overwrite existing file? (true=yes)
  360 + *
  361 + * Save the PSF table into a FITS file.
  362 + ***************************************************************************/
  363 +void GCTAPsf2D::save(const std::string& filename, const bool& clobber) const
  364 +{
  365 + // Create binary table
  366 + GFitsBinTable table;
  367 + table.extname("POINT SPREAD FUNCTION");
  368 +
  369 + // Write the PSF table
  370 + write(table);
  371 +
  372 + // Create FITS file, append table, and write into the file
  373 + GFits fits;
  374 + fits.append(table);
  375 + fits.saveto(filename, clobber);
  376 +
  377 + // Return
  378 + return;
  379 +}
  380 +
313 381  
314 382 /***********************************************************************//**
315 383 * @brief Simulate PSF offset (radians)
... ...