From 9eabfd897a4a58420504d4d901646e20871fe866 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 21 Nov 2020 13:29:44 +0100 Subject: [PATCH] Add GModels::eval() vector evaluation method (#3455) --- ChangeLog | 3 ++- NEWS | 13 +++++++++---- README.md | 2 +- doc/source/admin/release_history/2.0.rst | 4 +++- include/GModels.hpp | 4 ++++ pyext/GModels.i | 2 ++ src/model/GModels.cpp | 36 ++++++++++++++++++++++++++++++++++++ 7 files changed, 57 insertions(+), 7 deletions(-) diff --git a/ChangeLog b/ChangeLog index d5cec08..57a5b2e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2020-11-18 +2020-11-21 * Version 2.0.0 released ======================== + Add GModels::eval() vector evaluation method (#3455) Fix GSkyMap::stack_maps() method for WCS maps Add GCTAModelSkyCube class (#3442) Add GSkyModel flux() and eflux() methods (#3439) diff --git a/NEWS b/NEWS index 09b22c5..6a80056 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 2.0.0 -18 November 2020 +21 November 2020 1. Introduction @@ -25,12 +25,14 @@ The following classes have been renamed: - none The following methods have been added: -- GModel::eval(GObservation&, GMatrixSparse*) -- GModelSky::eval(GObservation&, GMatrixSparse*) - GResponse::convolve(GModelSky&, GObservation&, GMatrixSparse*) - GResponse::irf_spatial(GModelSky&, GObservation&, GMatrix*) - GObservation::model(GModels&, GMatrixSparse*) - GObservation::model_grad(GModel&, GModelPar&) +- GModels::eval(GObservation&, GMatrixSparse*) +- GModel::eval(GObservation&, GMatrixSparse*) +- GModelSky::eval(GObservation&, GMatrixSparse*) +- GModelData::eval(GObservation&, GMatrixSparse*) - GModelSky::flux(GEnergy&, GEnergy&) - GModelSky::flux(GSkyRegion&, GEnergy&, GEnergy&) - GModelSky::eflux(GEnergy&, GEnergy&) @@ -59,9 +61,9 @@ The following methods have been renamed: - none The arguments for the following methods have been changed: -- GCOMObservation::drm(GSkyModel&) was GCOMObservation::drm(GSource&) - GModelSpatial::flux(GSkyRegion&, GEnergy&, GTime&) was GModelSpatial::flux(GSkyRegion*, GEnergy&, GTime&) +- GCOMObservation::drm(GSkyModel&) was GCOMObservation::drm(GSource&) The return value of the following methods has been changed: - none @@ -96,6 +98,9 @@ Implemented GMatrixSparse::row() and GMatrixSparse::add_to_row() methods. 8. Model module --------------- +Added GModels::eval() vector evaluation method to compute the model values for +all events within a given observation (#3455). + Added methods to GSkyModel to compute the photon flux and energy flux as well as their errors (#3439, #3074). diff --git a/README.md b/README.md index d210a51..3e4ad0d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ GammaLib information ==================== -* Version: 2.0.0.dev (18 November 2020) +* Version: 2.0.0.dev (21 November 2020) [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=gammalib-integrate-os)](https://cta-jenkins.irap.omp.eu/job/gammalib-integrate-os/) diff --git a/doc/source/admin/release_history/2.0.rst b/doc/source/admin/release_history/2.0.rst index b58212f..6965e69 100644 --- a/doc/source/admin/release_history/2.0.rst +++ b/doc/source/admin/release_history/2.0.rst @@ -1,6 +1,6 @@ .. _2.0: -GammaLib 2.0 release (18 November 2020) +GammaLib 2.0 release (21 November 2020) ======================================= Overview @@ -40,6 +40,8 @@ Improvements New features ------------ +* [`3455 `_] - + Add ``GModels::eval()`` vector evaluation method * [`3442 `_] - Add ``GCTAModelSkyCube`` class * [`3439 `_] - diff --git a/include/GModels.hpp b/include/GModels.hpp index 253ed01..837bca5 100644 --- a/include/GModels.hpp +++ b/include/GModels.hpp @@ -36,6 +36,8 @@ class GEvent; class GObservation; class GModel; class GFilename; +class GVector; +class GMatrixSparse; class GOptimizerPars; class GXml; @@ -190,6 +192,8 @@ public: double eval(const GEvent& event, const GObservation& obs, const bool& gradients = false) const; + GVector eval(const GObservation& obs, + GMatrixSparse* gradients = NULL) const; std::string print(const GChatter& chatter = NORMAL) const; protected: diff --git a/pyext/GModels.i b/pyext/GModels.i index ea869d5..9a37223 100644 --- a/pyext/GModels.i +++ b/pyext/GModels.i @@ -71,6 +71,8 @@ public: double eval(const GEvent& event, const GObservation& obs, const bool& gradients = false) const; + GVector eval(const GObservation& obs, + GMatrixSparse* gradients = NULL) const; }; diff --git a/src/model/GModels.cpp b/src/model/GModels.cpp index 6aa549e..fc2c6a9 100644 --- a/src/model/GModels.cpp +++ b/src/model/GModels.cpp @@ -35,6 +35,8 @@ #include "GModel.hpp" #include "GModelRegistry.hpp" #include "GObservation.hpp" +#include "GVector.hpp" +#include "GMatrixSparse.hpp" #include "GXml.hpp" #include "GXmlElement.hpp" #include "GOptimizerPars.hpp" @@ -909,6 +911,40 @@ double GModels::eval(const GEvent& event, /***********************************************************************//** + * @brief Evaluate sum vector of all models + * + * @param[in] obs Observation. + * @param[in] gradients Pointer to gradients matrix. + * @return Vector of model values. + * + * Evaluates the sum vector of all models for all events in the observation. + * Only valid models are considered in this evaluation. + * + * If the @p gradients pointer is not NULL the method will fill the + * corresponding matrix with the parameter gradients of the model. + ***************************************************************************/ +GVector GModels::eval(const GObservation& obs, + GMatrixSparse* gradients) const +{ + // Get number of events + int nevents = obs.events()->size(); + + // Initialise model sum + GVector values(nevents); + + // Evaluate function for all models + for (int i = 0; i < size(); ++i) { + if (m_models[i]->is_valid(obs.instrument(), obs.id())) { + values += m_models[i]->eval(obs, gradients); + } + } + + // Return model values + return values; +} + + +/***********************************************************************//** * @brief Print models * * @param[in] chatter Chattiness. -- libgit2 0.21.4