Commit d83f3446ee8167014a31c15c8dbf8230dcc0cf1b

Authored by Jürgen Knödlseder
2 parents ac8d88a4 2ed111ce

Merge branch '1309-improveGCTAPsf2D-IO' into integration

inst/cta/include/GCTAPsf2D.hpp
1 1 /***************************************************************************
2 2 * GCTAPsf2D.hpp - CTA 2D point spread function class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012-2013 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -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/include/GCTAPsfKing.hpp
1 1 /***************************************************************************
2 2 * GCTAPsfKing.hpp - King profile CTA point spread function class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2013 by Michael Mayer *
  4 + * copyright (C) 2013-2014 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -82,6 +82,15 @@ public:
82 82 const bool& etrue = true) const;
83 83 std::string print(const GChatter& chatter = NORMAL) const;
84 84  
  85 + // Methods
  86 + const GCTAResponseTable& table(void) const;
  87 + void table(const GCTAResponseTable& table);
  88 + void read(const GFits& file);
  89 + void write(GFitsBinTable& hdu) const;
  90 + void save(const std::string& filename,
  91 + const bool& clobber = false) const;
  92 +
  93 +
85 94  
86 95 private:
87 96 // Methods
... ... @@ -117,4 +126,27 @@ std::string GCTAPsfKing::filename(void) const
117 126 return m_filename;
118 127 }
119 128  
  129 +/***********************************************************************//**
  130 + * @brief Return response table
  131 + *
  132 + * @return Response table.
  133 + ***************************************************************************/
  134 +inline
  135 +const GCTAResponseTable& GCTAPsfKing::table(void) const
  136 +{
  137 + return m_psf;
  138 +}
  139 +
  140 +/***********************************************************************//**
  141 + * @brief Assign response table
  142 + *
  143 + * @param[in] table Response table.
  144 + ***************************************************************************/
  145 +inline
  146 +void GCTAPsfKing::table(const GCTAResponseTable& table)
  147 +{
  148 + m_psf = table;
  149 +}
  150 +
  151 +
120 152 #endif /* GCTAPsfKing_HPP */
... ...
inst/cta/pyext/GCTAPsf2D.i
1 1 /***************************************************************************
2 2 * GCTAPsf2D.i - CTA 2D point spread function class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2012 by Juergen Knoedlseder *
  4 + * copyright (C) 2012-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -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/GCTAPsfKing.i
1 1 /***************************************************************************
2 2 * GCTAPsfKing.i - King profile CTA point spread function class *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2013 by Michael Mayer *
  4 + * copyright (C) 2013-2014 by Michael Mayer *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ...
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  
... ... @@ -268,23 +270,22 @@ GCTAPsf2D* GCTAPsf2D::clone(void) const
268 270  
269 271  
270 272 /***********************************************************************//**
271   - * @brief Load point spread function from performance table
  273 + * @brief Read PSF from FITS file
272 274 *
273   - * @param[in] filename Performance table file name.
  275 + * @param[in] fits FITS file pointer.
274 276 *
275   - * @exception GCTAExceptionHandler::file_open_error
276   - * File could not be opened for read access.
277   - *
278   - * This method loads the point spread function information from a PSF
279   - * response table.
  277 + * Reads the PSF from the FITS file extension "POINT SPREAD FUNCTION". The data
  278 + * are stored in m_psf which is of type GCTAResponseTable.
  279 + * The energy axis will be set to log10. The offset angle axis and
  280 + * sigma parameter columns will be set to radians.
280 281 ***************************************************************************/
281   -void GCTAPsf2D::load(const std::string& filename)
  282 +void GCTAPsf2D::read(const GFits& fits)
282 283 {
283   - // Open PSF FITS file
284   - GFits file(filename);
  284 + // Clear response table
  285 + m_psf.clear();
285 286  
286 287 // Get PSF table
287   - const GFitsTable& table = *file.table("POINT SPREAD FUNCTION");
  288 + const GFitsTable& table = *fits.table("POINT SPREAD FUNCTION");
288 289  
289 290 // Read PSF table
290 291 m_psf.read(table);
... ... @@ -300,8 +301,49 @@ void GCTAPsf2D::load(const std::string&amp; filename)
300 301 m_psf.scale(3, gammalib::deg2rad);
301 302 m_psf.scale(5, gammalib::deg2rad);
302 303  
  304 + // Return
  305 + return;
  306 +}
  307 +
  308 +
  309 +/***********************************************************************//**
  310 + * @brief Write CTA PSF table into FITS binary table object.
  311 + *
  312 + * @param[in] hdu FITS binary table.
  313 + *
  314 + * @todo Add necessary keywords.
  315 + ***************************************************************************/
  316 +void GCTAPsf2D::write(GFitsBinTable& hdu) const
  317 +{
  318 + // Write background table
  319 + m_psf.write(hdu);
  320 +
  321 + // Return
  322 + return;
  323 +}
  324 +
  325 +
  326 +/***********************************************************************//**
  327 + * @brief Load point spread function from performance table
  328 + *
  329 + * @param[in] filename Performance table file name.
  330 + *
  331 + * @exception GCTAExceptionHandler::file_open_error
  332 + * File could not be opened for read access.
  333 + *
  334 + * This method loads the point spread function information from a PSF
  335 + * response table.
  336 + ***************************************************************************/
  337 +void GCTAPsf2D::load(const std::string& filename)
  338 +{
  339 + // Open PSF FITS file
  340 + GFits fits(filename);
  341 +
  342 + // Read fits file
  343 + read(fits);
  344 +
303 345 // Close PSF FITS file
304   - file.close();
  346 + fits.close();
305 347  
306 348 // Store filename
307 349 m_filename = filename;
... ... @@ -312,6 +354,33 @@ void GCTAPsf2D::load(const std::string&amp; filename)
312 354  
313 355  
314 356 /***********************************************************************//**
  357 + * @brief Save PSF table into FITS file
  358 + *
  359 + * @param[in] filename PSF table FITS file name.
  360 + * @param[in] clobber Overwrite existing file? (true=yes)
  361 + *
  362 + * Save the PSF table into a FITS file.
  363 + ***************************************************************************/
  364 +void GCTAPsf2D::save(const std::string& filename, const bool& clobber) const
  365 +{
  366 + // Create binary table
  367 + GFitsBinTable table;
  368 + table.extname("POINT SPREAD FUNCTION");
  369 +
  370 + // Write the PSF table
  371 + write(table);
  372 +
  373 + // Create FITS file, append table, and write into the file
  374 + GFits fits;
  375 + fits.append(table);
  376 + fits.saveto(filename, clobber);
  377 +
  378 + // Return
  379 + return;
  380 +}
  381 +
  382 +
  383 +/***********************************************************************//**
315 384 * @brief Simulate PSF offset (radians)
316 385 *
317 386 * @param[in] ran Random number generator.
... ...
inst/cta/src/GCTAPsfKing.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 "GCTAPsfKing.hpp"
35 37 #include "GCTAException.hpp"
36 38  
... ... @@ -269,23 +271,22 @@ GCTAPsfKing* GCTAPsfKing::clone(void) const
269 271  
270 272  
271 273 /***********************************************************************//**
272   - * @brief Load point spread function from binary table
  274 + * @brief Read PSF from FITS file
273 275 *
274   - * @param[in] filename Performance table file name.
  276 + * @param[in] fits FITS file pointer.
275 277 *
276   - * @exception GCTAExceptionHandler::file_open_error
277   - * File could not be opened for read access.
278   - *
279   - * This method loads the point spread function information from a PSF
280   - * response table.
  278 + * Reads the PSF from the FITS file extension "POINT SPREAD FUNCTION". The data
  279 + * are stored in m_psf which is of type GCTAResponseTable.
  280 + * The energy axis will be set to log10. The offset angle axis and
  281 + * sigma parameter columns will be set to radians.
281 282 ***************************************************************************/
282   -void GCTAPsfKing::load(const std::string& filename)
  283 +void GCTAPsfKing::read(const GFits& fits)
283 284 {
284   - // Open PSF FITS file
285   - GFits file(filename);
  285 + // Clear response table
  286 + m_psf.clear();
286 287  
287 288 // Get PSF table
288   - const GFitsTable& table = *file.table("POINT SPREAD FUNCTION");
  289 + const GFitsTable& table = *fits.table("POINT SPREAD FUNCTION");
289 290  
290 291 // Read PSF table
291 292 m_psf.read(table);
... ... @@ -296,8 +297,49 @@ void GCTAPsfKing::load(const std::string&amp; filename)
296 297 // Set offset angle axis to radians
297 298 m_psf.axis_radians(1);
298 299  
299   - // Convert sigma parameter to radians
  300 + // Convert sigma parameters to radians
300 301 m_psf.scale(1, gammalib::deg2rad);
  302 +
  303 + // Return
  304 + return;
  305 +}
  306 +
  307 +
  308 +/***********************************************************************//**
  309 + * @brief Write CTA PSF table into FITS binary table object.
  310 + *
  311 + * @param[in] hdu FITS binary table.
  312 + *
  313 + * @todo Add necessary keywords.
  314 + ***************************************************************************/
  315 +void GCTAPsfKing::write(GFitsBinTable& hdu) const
  316 +{
  317 + // Write background table
  318 + m_psf.write(hdu);
  319 +
  320 + // Return
  321 + return;
  322 +}
  323 +
  324 +
  325 +/***********************************************************************//**
  326 + * @brief Load point spread function from binary table
  327 + *
  328 + * @param[in] filename Performance table file name.
  329 + *
  330 + * @exception GCTAExceptionHandler::file_open_error
  331 + * File could not be opened for read access.
  332 + *
  333 + * This method loads the point spread function information from a PSF
  334 + * response table.
  335 + ***************************************************************************/
  336 +void GCTAPsfKing::load(const std::string& filename)
  337 +{
  338 + // Open PSF FITS file
  339 + GFits file(filename);
  340 +
  341 + // Read fits file
  342 + read(file);
301 343  
302 344 // Close PSF FITS file
303 345 file.close();
... ... @@ -309,6 +351,32 @@ void GCTAPsfKing::load(const std::string&amp; filename)
309 351 return;
310 352 }
311 353  
  354 +/***********************************************************************//**
  355 + * @brief Save PSF table into FITS file
  356 + *
  357 + * @param[in] filename PSF table FITS file name.
  358 + * @param[in] clobber Overwrite existing file? (true=yes)
  359 + *
  360 + * Save the PSF table into a FITS file.
  361 + ***************************************************************************/
  362 +void GCTAPsfKing::save(const std::string& filename, const bool& clobber) const
  363 +{
  364 + // Create binary table
  365 + GFitsBinTable table;
  366 + table.extname("POINT SPREAD FUNCTION");
  367 +
  368 + // Write the PSF table
  369 + write(table);
  370 +
  371 + // Create FITS file, append table, and write into the file
  372 + GFits fits;
  373 + fits.append(table);
  374 + fits.saveto(filename, clobber);
  375 +
  376 + // Return
  377 + return;
  378 +}
  379 +
312 380  
313 381 /***********************************************************************//**
314 382 * @brief Simulate PSF offset (radians)
... ...