Commit 4dd8af230bb7d6a5a7ce6a2a7f1bb37535c7cf5a
1 parent
118faba8
improve I/O interface for GCTAPsfKing
Showing
3 changed files
with
108 additions
and
6 deletions
inst/cta/include/GCTAPsfKing.hpp
| ... | ... | @@ -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/src/GCTAPsf2D.cpp
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 | |
| ... | ... | @@ -284,8 +286,36 @@ void GCTAPsfKing::load(const std::string& filename) |
| 284 | 286 | // Open PSF FITS file |
| 285 | 287 | GFits file(filename); |
| 286 | 288 | |
| 289 | + // Read fits file | |
| 290 | + read(file); | |
| 291 | + | |
| 292 | + // Close PSF FITS file | |
| 293 | + file.close(); | |
| 294 | + | |
| 295 | + // Store filename | |
| 296 | + m_filename = filename; | |
| 297 | + | |
| 298 | + // Return | |
| 299 | + return; | |
| 300 | +} | |
| 301 | + | |
| 302 | +/***********************************************************************//** | |
| 303 | + * @brief Read PSF from FITS file | |
| 304 | + * | |
| 305 | + * @param[in] fits FITS file pointer. | |
| 306 | + * | |
| 307 | + * Reads the PSF from the FITS file extension "POINT SPREAD FUNCTION". The data | |
| 308 | + * are stored in m_psf which is of type GCTAResponseTable. | |
| 309 | + * The energy axis will be set to log10. The offset angle axis and | |
| 310 | + * sigma parameter columns will be set to radians. | |
| 311 | + ***************************************************************************/ | |
| 312 | +void GCTAPsfKing::read(const GFits& fits) | |
| 313 | +{ | |
| 314 | + // Clear response table | |
| 315 | + m_psf.clear(); | |
| 316 | + | |
| 287 | 317 | // Get PSF table |
| 288 | - const GFitsTable& table = *file.table("POINT SPREAD FUNCTION"); | |
| 318 | + const GFitsTable& table = *fits.table("POINT SPREAD FUNCTION"); | |
| 289 | 319 | |
| 290 | 320 | // Read PSF table |
| 291 | 321 | m_psf.read(table); |
| ... | ... | @@ -296,20 +326,59 @@ void GCTAPsfKing::load(const std::string& filename) |
| 296 | 326 | // Set offset angle axis to radians |
| 297 | 327 | m_psf.axis_radians(1); |
| 298 | 328 | |
| 299 | - // Convert sigma parameter to radians | |
| 329 | + // Convert sigma parameters to radians | |
| 300 | 330 | m_psf.scale(1, gammalib::deg2rad); |
| 331 | + | |
| 332 | + // Return | |
| 333 | + return; | |
| 334 | +} | |
| 301 | 335 | |
| 302 | - // Close PSF FITS file | |
| 303 | - file.close(); | |
| 336 | +/***********************************************************************//** | |
| 337 | + * @brief Write CTA PSF table into FITS binary table object. | |
| 338 | + * | |
| 339 | + * @param[in] hdu FITS binary table. | |
| 340 | + * | |
| 341 | + * @todo Add necessary keywords. | |
| 342 | + ***************************************************************************/ | |
| 343 | +void GCTAPsfKing::write(GFitsBinTable& hdu) const | |
| 344 | +{ | |
| 345 | + // Write background table | |
| 346 | + m_psf.write(hdu); | |
| 304 | 347 | |
| 305 | - // Store filename | |
| 306 | - m_filename = filename; | |
| 348 | + // Return | |
| 349 | + return; | |
| 350 | +} | |
| 351 | + | |
| 352 | +/***********************************************************************//** | |
| 353 | + * @brief Save PSF table into FITS file | |
| 354 | + * | |
| 355 | + * @param[in] filename PSF table FITS file name. | |
| 356 | + * @param[in] clobber Overwrite existing file? (true=yes) | |
| 357 | + * | |
| 358 | + * Save the PSF table into a FITS file. | |
| 359 | + ***************************************************************************/ | |
| 360 | +void GCTAPsfKing::save(const std::string& filename, const bool& clobber) const | |
| 361 | +{ | |
| 362 | + // Create binary table | |
| 363 | + GFitsBinTable table; | |
| 364 | + table.extname("POINT SPREAD FUNCTION"); | |
| 365 | + | |
| 366 | + // Write the PSF table | |
| 367 | + write(table); | |
| 368 | + | |
| 369 | + // Create FITS file, append table, and write into the file | |
| 370 | + GFits fits; | |
| 371 | + fits.append(table); | |
| 372 | + fits.saveto(filename, clobber); | |
| 307 | 373 | |
| 308 | 374 | // Return |
| 309 | 375 | return; |
| 310 | 376 | } |
| 311 | 377 | |
| 312 | 378 | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 313 | 382 | /***********************************************************************//** |
| 314 | 383 | * @brief Simulate PSF offset (radians) |
| 315 | 384 | * | ... | ... |