From 5fba3818bb7c930f5c28735bd82d0902ca9c587d Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 21 Nov 2014 15:58:56 +0100 Subject: [PATCH] added two constructors to GCTAMeanPsf and GCTAExposure --- inst/cta/include/GCTAExposure.hpp | 2 ++ inst/cta/include/GCTAMeanPsf.hpp | 3 ++- inst/cta/pyext/GCTAExposure.i | 1 + inst/cta/pyext/GCTAMeanPsf.i | 1 + inst/cta/src/GCTAExposure.cpp | 19 +++++++++++++++++++ inst/cta/src/GCTAMeanPsf.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- 6 files changed, 74 insertions(+), 2 deletions(-) diff --git a/inst/cta/include/GCTAExposure.hpp b/inst/cta/include/GCTAExposure.hpp index 3a8496f..c6b890d 100644 --- a/inst/cta/include/GCTAExposure.hpp +++ b/inst/cta/include/GCTAExposure.hpp @@ -34,6 +34,7 @@ #include "GSkymap.hpp" #include "GObservations.hpp" #include "GCTAObservation.hpp" +#include "GCTAEventCube.hpp" /***********************************************************************//** @@ -53,6 +54,7 @@ public: GCTAExposure(void); GCTAExposure(const GCTAExposure& cube); explicit GCTAExposure(const std::string& filename); + GCTAExposure(const GCTAEventCube& cube); GCTAExposure(const std::string& wcs, const std::string& coords, const double& x, diff --git a/inst/cta/include/GCTAMeanPsf.hpp b/inst/cta/include/GCTAMeanPsf.hpp index 2aaf8d3..202b94e 100644 --- a/inst/cta/include/GCTAMeanPsf.hpp +++ b/inst/cta/include/GCTAMeanPsf.hpp @@ -35,7 +35,7 @@ #include "GObservations.hpp" #include "GCTAObservation.hpp" #include "GNodeArray.hpp" - +#include "GCTAEventCube.hpp" /***********************************************************************//** * @class GCTAMeanPsf @@ -55,6 +55,7 @@ public: GCTAMeanPsf(void); GCTAMeanPsf(const GCTAMeanPsf& cube); explicit GCTAMeanPsf(const std::string& filename); + GCTAMeanPsf(const GCTAEventCube& cube, const double& dmax, const int& ndbins); GCTAMeanPsf(const std::string& wcs, const std::string& coords, const double& x, diff --git a/inst/cta/pyext/GCTAExposure.i b/inst/cta/pyext/GCTAExposure.i index 42f45ea..faff826 100644 --- a/inst/cta/pyext/GCTAExposure.i +++ b/inst/cta/pyext/GCTAExposure.i @@ -46,6 +46,7 @@ public: GCTAExposure(void); GCTAExposure(const GCTAExposure& cube); explicit GCTAExposure(const std::string& filename); + GCTAExposure(const GCTAEventCube& cube); GCTAExposure(const std::string& wcs, const std::string& coords, const double& x, diff --git a/inst/cta/pyext/GCTAMeanPsf.i b/inst/cta/pyext/GCTAMeanPsf.i index 13d16e6..9d2321c 100644 --- a/inst/cta/pyext/GCTAMeanPsf.i +++ b/inst/cta/pyext/GCTAMeanPsf.i @@ -49,6 +49,7 @@ public: GCTAMeanPsf(void); GCTAMeanPsf(const GCTAMeanPsf& cube); explicit GCTAMeanPsf(const std::string& filename); + GCTAMeanPsf(const GCTAEventCube& cube, const double& dmax, const int& ndbins); GCTAMeanPsf(const std::string& wcs, const std::string& coords, const double& x, diff --git a/inst/cta/src/GCTAExposure.cpp b/inst/cta/src/GCTAExposure.cpp index 1ebc8c3..7a70f24 100644 --- a/inst/cta/src/GCTAExposure.cpp +++ b/inst/cta/src/GCTAExposure.cpp @@ -104,6 +104,25 @@ GCTAExposure::GCTAExposure(const std::string& filename) return; } +GCTAExposure::GCTAExposure(const GCTAEventCube& cube) +{ + // Initialise class members + init_members(); + + // Store energy boundaries + m_ebounds = cube.ebounds(); + + // Set GNodeArray used for interpolation + set_eng_axis(); + + // Get sky map + m_cube = cube.map(); + + // Return + return; + +} + /***********************************************************************//** * @brief Exposure cube constructor diff --git a/inst/cta/src/GCTAMeanPsf.cpp b/inst/cta/src/GCTAMeanPsf.cpp index 37d1b36..e54631b 100644 --- a/inst/cta/src/GCTAMeanPsf.cpp +++ b/inst/cta/src/GCTAMeanPsf.cpp @@ -35,6 +35,8 @@ #include "GCTAExposure.hpp" #include "GMath.hpp" #include "GTools.hpp" +#include "GWcsRegistry.hpp" +#include "GWcs.hpp" /* __ Method name definitions ____________________________________________ */ #define G_SET "GCTAMeanPsf::set(GCTAObservation&)" @@ -106,6 +108,52 @@ GCTAMeanPsf::GCTAMeanPsf(const std::string& filename) return; } +GCTAMeanPsf::GCTAMeanPsf(const GCTAEventCube& cube, const double& dmax, const int& ndbins) +{ + // Initialise class members + init_members(); + + // Store energy boundaries + m_ebounds = cube.ebounds(); + + // Set GNodeArray used for interpolation + set_eng_axis(); + + // Set delta node array + + m_deltas.clear(); + for (int i = 0; i < ndbins; ++i) { + #if defined(G_QUADRATIC_BINNING) + double binsize = std::sqrt(dmax) / double(ndbins); + double delta = binsize * (double(i) + 0.5); // avoid central singularity + delta *= delta; + #else + double binsize = dmax / double(ndbins); + double delta = binsize * (double(i) + 0.5); // avoid central singularity + #endif + m_deltas.append(delta); + } + + // Compute number of sky maps + int nmaps = m_ebounds.size() * m_deltas.size(); + + + // Create sky map + const GWcs* wcs = dynamic_cast(cube.map().projection());// reg.alloc(cube.map().projection()->code()); + + std::string coordsys = wcs->coordsys(); + std::string proj = wcs->code(); + double xref = wcs->crval(0); + double yref = wcs->crval(1); + double xbinsz = wcs->cdelt(0); + double ybinsz = wcs->cdelt(1); + m_cube = GSkymap(proj, coordsys, xref, yref, xbinsz, ybinsz, cube.map().nx(), cube.map().ny(), nmaps); + + // Return + return; + +} + /***********************************************************************//** * @brief Mean PSF cube constructor @@ -431,7 +479,7 @@ void GCTAMeanPsf::fill(const GObservations& obs) // Set map index int imap = offset(idelta, iebin); - + // Add on PSF cube m_cube(pixel, imap) += rsp->psf(delta, theta, 0.0, 0.0, 0.0, logE) * weight; -- libgit2 0.21.4