Commit 939f76c5a41fc4b616f795c1142e6ad76c030b41

Authored by Jürgen Knödlseder
1 parent 9d6081b7

Add GCTAResponseCache class (#2715)

The GCTAResponseCache implements a generic response cache for CTA. The commit includes extensive unit tests of the generic response class.
ChangeLog
1   -2018-11-01
  1 +2018-11-06
2 2  
3 3 * Version 1.6.0 released
4 4 ========================
5 5  
  6 + Add generic CTA response cache (#2715)
6 7 Fix precision issue with GCTABackground3D Monte-Carlo simulations (#2708)
7 8 Revise GCTAEdisp class interface (#2704)
8 9 GCTAEdisp returns now energy dispersion values per MeV (#2704)
... ...
... ... @@ -14,6 +14,7 @@ made since the last release of GammaLib.
14 14 The following classes have been added:
15 15 - GModelSpectralExponential
16 16 - GWcsARC
  17 +- GCTAResponseCache
17 18 - GCTAModelBackground
18 19 - GCTAModelSpatial
19 20 - GCTAModelSpatialMultiplicative
... ... @@ -310,6 +311,9 @@ None
310 311  
311 312 20. CTA interface
312 313 -----------------
  314 +The GCTAResponseCache class was added to implement a general response cache for
  315 +CTA (#2715).
  316 +
313 317 GCTABackground3D::init_mc_cache now pre-computes the Monte Carlo cache at energy
314 318 nodes of the background cube, and in addition, inserts 8 logarithmically spaced
315 319 nodes between each pair of nodes. This assures that the energy variations of the
... ...
dev/codegen.py
... ... @@ -225,7 +225,7 @@ def set_container_tokens(classname, author, what, object):
225 225  
226 226 # Set tokens
227 227 tokens = [{'pattern': 'GTPLContainer', 'string': classname},
228   - {'pattern': 'GTPLContainer', 'string': classname.upper()},
  228 + {'pattern': 'GTPLCONTAINER', 'string': classname.upper()},
229 229 {'pattern': '[WHAT]', 'string': what},
230 230 {'pattern': '[AUTHOR]', 'string': author},
231 231 {'pattern': 'TPL_CONTAINER', 'string': object.lower()},
... ...
doc/source/admin/release_history/1.6.rst
... ... @@ -47,6 +47,8 @@ Bug fixes
47 47 Improvements
48 48 ------------
49 49  
  50 +* [`2715 <https://cta-redmine.irap.omp.eu/issues/2715>`_] -
  51 + Add generic CTA response cache
50 52 * [`2704 <https://cta-redmine.irap.omp.eu/issues/2704>`_] -
51 53 ``GCTAEdisp`` returns now energy dispersion values per MeV.
52 54 The ``GCTAEdisp`` interface was revised.
... ...
inst/cta/Makefile.am
... ... @@ -47,6 +47,7 @@ sources = src/GCTASupport.cpp \
47 47 src/GCTAResponseCube.cpp \
48 48 src/GCTAResponse_helpers.cpp \
49 49 src/GCTAResponseTable.cpp \
  50 + src/GCTAResponseCache.cpp \
50 51 src/GCTAAeff.cpp \
51 52 src/GCTAAeffPerfTable.cpp \
52 53 src/GCTAAeffArf.cpp \
... ... @@ -105,6 +106,7 @@ pkginclude_HEADERS = include/GCTATypemaps.hpp \
105 106 include/GCTAResponseIrf.hpp \
106 107 include/GCTAResponseCube.hpp \
107 108 include/GCTAResponseTable.hpp \
  109 + include/GCTAResponseCache.hpp \
108 110 include/GCTAAeff.hpp \
109 111 include/GCTAAeffPerfTable.hpp \
110 112 include/GCTAAeffArf.hpp \
... ...
inst/cta/include/GCTALib.hpp
... ... @@ -48,6 +48,7 @@
48 48 #include "GCTAResponseIrf.hpp"
49 49 #include "GCTAResponseCube.hpp"
50 50 #include "GCTAResponseTable.hpp"
  51 +#include "GCTAResponseCache.hpp"
51 52 #include "GCTAAeff.hpp"
52 53 #include "GCTAAeffPerfTable.hpp"
53 54 #include "GCTAAeffArf.hpp"
... ...
inst/cta/include/GCTAResponseCache.hpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCTAResponseCache.hpp - CTA response cache class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2018 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCTAResponseCache.hpp
  23 + * @brief CTA response cache class definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +#ifndef GCTARESPONSECACHE_HPP
  28 +#define GCTARESPONSECACHE_HPP
  29 +
  30 +/* __ Includes ___________________________________________________________ */
  31 +#include <string>
  32 +#include <map>
  33 +#include "GBase.hpp"
  34 +#include "GEnergy.hpp"
  35 +
  36 +/* __ Forward declarations _______________________________________________ */
  37 +
  38 +/* __ Constants __________________________________________________________ */
  39 +
  40 +/* __ Typedefs ___________________________________________________________ */
  41 +typedef std::map<GEnergy,double> GCTAResponseCacheEtrue;
  42 +typedef std::map<GEnergy,GCTAResponseCacheEtrue> GCTAResponseCacheEreco;
  43 +typedef std::map<std::string,GCTAResponseCacheEreco> GCTAResponseCacheName;
  44 +
  45 +
  46 +/***********************************************************************//**
  47 + * @class GCTAResponseCache
  48 + *
  49 + * @brief CTA response cache class
  50 + *
  51 + * @todo Add class description.
  52 + ***************************************************************************/
  53 +class GCTAResponseCache : public GBase {
  54 +
  55 +public:
  56 + // Constructors and destructors
  57 + GCTAResponseCache(void);
  58 + GCTAResponseCache(const GCTAResponseCache& cache);
  59 + virtual ~GCTAResponseCache(void);
  60 +
  61 + // Operators
  62 + GCTAResponseCache& operator=(const GCTAResponseCache& cache);
  63 +
  64 + // Methods
  65 + void clear(void);
  66 + GCTAResponseCache* clone(void) const;
  67 + std::string classname(void) const;
  68 + int size(void) const;
  69 + bool is_empty(void) const;
  70 + int nerecos(void) const;
  71 + int netrues(void) const;
  72 + void set(const std::string& name,
  73 + const GEnergy& ereco,
  74 + const GEnergy& etrue,
  75 + const double& value);
  76 + bool contains(const std::string& name,
  77 + const GEnergy& ereco,
  78 + const GEnergy& etrue,
  79 + double* value = NULL) const;
  80 + std::string print(const GChatter& chatter = NORMAL) const;
  81 +
  82 +protected:
  83 + // Protected methods
  84 + void init_members(void);
  85 + void copy_members(const GCTAResponseCache& cache);
  86 + void free_members(void);
  87 +
  88 + // Protected members
  89 + GCTAResponseCacheName m_cache;
  90 +};
  91 +
  92 +
  93 +/***********************************************************************//**
  94 + * @brief Return class name
  95 + *
  96 + * @return String containing the class name ("GCTAResponseCache").
  97 + ***************************************************************************/
  98 +inline
  99 +std::string GCTAResponseCache::classname(void) const
  100 +{
  101 + return ("GCTAResponseCache");
  102 +}
  103 +
  104 +
  105 +/***********************************************************************//**
  106 + * @brief Checks whether the cache is empty
  107 + *
  108 + * @return True if cache is empty, false otherwise.
  109 + *
  110 + * Checks whether the response cache is empty.
  111 + ***************************************************************************/
  112 +inline
  113 +bool GCTAResponseCache::is_empty(void) const
  114 +{
  115 + return (m_cache.empty());
  116 +}
  117 +
  118 +#endif /* GCTARESPONSECACHE_HPP */
... ...
inst/cta/pyext/GCTAResponseCache.i 0 → 100644
  1 +/***************************************************************************
  2 + * GCTAResponseCache.i - CTA response cache class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2018 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCTAResponseCache.i
  23 + * @brief CTA response cache class definition
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +%{
  27 +/* Put headers and other declarations here that are needed for compilation */
  28 +#include "GCTAResponseCache.hpp"
  29 +%}
  30 +
  31 +/* __ Typemaps ___________________________________________________________ */
  32 +/*
  33 + * Typemap so that the contains() method returns two values, first the
  34 + * flag indicating whether the value exists or not, and second the
  35 + * value, i.e.
  36 + *
  37 + * flag, value = cache.contains('Crab', GEnergy(1.0,'TeV'), GEnergy(1.0,'TeV'))
  38 + *
  39 + */
  40 +%include "typemaps.i"
  41 +%apply double *OUTPUT { double* value };
  42 +
  43 +
  44 +/***********************************************************************//**
  45 + * @class GCTAResponseCache
  46 + *
  47 + * @brief CTA response cache class
  48 + ***************************************************************************/
  49 +class GCTAResponseCache : public GBase {
  50 +
  51 +public:
  52 + // Constructors and destructors
  53 + GCTAResponseCache(void);
  54 + GCTAResponseCache(const GCTAResponseCache& cache);
  55 + virtual ~GCTAResponseCache(void);
  56 +
  57 + // Methods
  58 + void clear(void);
  59 + GCTAResponseCache* clone(void) const;
  60 + std::string classname(void) const;
  61 + int size(void) const;
  62 + bool is_empty(void) const;
  63 + int nerecos(void) const;
  64 + int netrues(void) const;
  65 + void set(const std::string& name,
  66 + const GEnergy& ereco,
  67 + const GEnergy& etrue,
  68 + const double& value);
  69 + bool contains(const std::string& name,
  70 + const GEnergy& ereco,
  71 + const GEnergy& etrue,
  72 + double* value) const;
  73 +};
  74 +
  75 +
  76 +/***********************************************************************//**
  77 + * @brief GCTAResponseCache class extension
  78 + ***************************************************************************/
  79 +%extend GCTAResponseCache {
  80 + GCTAResponseCache copy() {
  81 + return (*self);
  82 + }
  83 +};
... ...
inst/cta/pyext/cta.i
... ... @@ -281,6 +281,7 @@
281 281 %include "GCTAResponseIrf.i"
282 282 %include "GCTAResponseCube.i"
283 283 %include "GCTAResponseTable.i"
  284 +%include "GCTAResponseCache.i"
284 285 %include "GCTAAeff.i"
285 286 %include "GCTAAeffPerfTable.i"
286 287 %include "GCTAAeffArf.i"
... ... @@ -316,4 +317,3 @@
316 317 %include "GCTAModelRadialPolynom.i"
317 318 %include "GCTAModelRadialProfile.i"
318 319 %include "GCTAModelRadialAcceptance.i"
319   -
... ...
inst/cta/src/GCTAResponseCache.cpp 0 → 100644
  1 +/***************************************************************************
  2 + * GCTAResponseCache.cpp - CTA response cache class *
  3 + * ----------------------------------------------------------------------- *
  4 + * copyright (C) 2018 by Juergen Knoedlseder *
  5 + * ----------------------------------------------------------------------- *
  6 + * *
  7 + * This program is free software: you can redistribute it and/or modify *
  8 + * it under the terms of the GNU General Public License as published by *
  9 + * the Free Software Foundation, either version 3 of the License, or *
  10 + * (at your option) any later version. *
  11 + * *
  12 + * This program is distributed in the hope that it will be useful, *
  13 + * but WITHOUT ANY WARRANTY; without even the implied warranty of *
  14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
  15 + * GNU General Public License for more details. *
  16 + * *
  17 + * You should have received a copy of the GNU General Public License *
  18 + * along with this program. If not, see <http://www.gnu.org/licenses/>. *
  19 + * *
  20 + ***************************************************************************/
  21 +/**
  22 + * @file GCTAResponseCache.cpp
  23 + * @brief CTA response cache class implementation
  24 + * @author Juergen Knoedlseder
  25 + */
  26 +
  27 +/* __ Includes ___________________________________________________________ */
  28 +#ifdef HAVE_CONFIG_H
  29 +#include <config.h>
  30 +#endif
  31 +#include "GTools.hpp"
  32 +#include "GCTAResponseCache.hpp"
  33 +
  34 +/* __ Method name definitions ____________________________________________ */
  35 +
  36 +/* __ Macros _____________________________________________________________ */
  37 +
  38 +/* __ Coding definitions _________________________________________________ */
  39 +
  40 +/* __ Debug definitions __________________________________________________ */
  41 +
  42 +
  43 +
  44 +/*==========================================================================
  45 + = =
  46 + = Constructors/destructors =
  47 + = =
  48 + ==========================================================================*/
  49 +
  50 +/***********************************************************************//**
  51 + * @brief Void constructor
  52 + ***************************************************************************/
  53 +GCTAResponseCache::GCTAResponseCache(void)
  54 +{
  55 + // Initialise class members
  56 + init_members();
  57 +
  58 + // Return
  59 + return;
  60 +}
  61 +
  62 +
  63 +/***********************************************************************//**
  64 + * @brief Copy constructor
  65 + *
  66 + * @param[in] cache CTA response cache.
  67 + ***************************************************************************/
  68 +GCTAResponseCache::GCTAResponseCache(const GCTAResponseCache& cache)
  69 +{
  70 + // Initialise class members
  71 + init_members();
  72 +
  73 + // Copy members
  74 + copy_members(cache);
  75 +
  76 + // Return
  77 + return;
  78 +}
  79 +
  80 +
  81 +/***********************************************************************//**
  82 + * @brief Destructor
  83 + ***************************************************************************/
  84 +GCTAResponseCache::~GCTAResponseCache(void)
  85 +{
  86 + // Free members
  87 + free_members();
  88 +
  89 + // Return
  90 + return;
  91 +}
  92 +
  93 +
  94 +/*==========================================================================
  95 + = =
  96 + = Operators =
  97 + = =
  98 + ==========================================================================*/
  99 +
  100 +/***********************************************************************//**
  101 + * @brief Assignment operator
  102 + *
  103 + * @param[in] cache CTA response cache.
  104 + * @return CTA response cache.
  105 + ***************************************************************************/
  106 +GCTAResponseCache& GCTAResponseCache::operator=(const GCTAResponseCache& cache)
  107 +{
  108 + // Execute only if object is not identical
  109 + if (this != &cache) {
  110 +
  111 + // Free members
  112 + free_members();
  113 +
  114 + // Initialise private members
  115 + init_members();
  116 +
  117 + // Copy members
  118 + copy_members(cache);
  119 +
  120 + } // endif: object was not identical
  121 +
  122 + // Return this object
  123 + return *this;
  124 +}
  125 +
  126 +
  127 +/*==========================================================================
  128 + = =
  129 + = Public methods =
  130 + = =
  131 + ==========================================================================*/
  132 +
  133 +/***********************************************************************//**
  134 + * @brief Clear CTA response cache
  135 + ***************************************************************************/
  136 +void GCTAResponseCache::clear(void)
  137 +{
  138 + // Free members
  139 + free_members();
  140 +
  141 + // Initialise private members
  142 + init_members();
  143 +
  144 + // Return
  145 + return;
  146 +}
  147 +
  148 +
  149 +/***********************************************************************//**
  150 + * @brief Return number of elements in cache
  151 + *
  152 + * @return Number of elements in cache
  153 + *
  154 + * Returns the number of elements in the response cache.
  155 + ***************************************************************************/
  156 +int GCTAResponseCache::size(void) const
  157 +{
  158 + // Initialize size
  159 + int size = 0;
  160 +
  161 + // Compute size
  162 + for (GCTAResponseCacheName::const_iterator it_name = m_cache.begin();
  163 + it_name != m_cache.end(); ++it_name) {
  164 + for (GCTAResponseCacheEreco::const_iterator it_ereco = it_name->second.begin();
  165 + it_ereco != it_name->second.end(); ++it_ereco) {
  166 + size += it_ereco->second.size();
  167 + }
  168 + }
  169 +
  170 + // Return size
  171 + return size;
  172 +}
  173 +
  174 +
  175 +/***********************************************************************//**
  176 + * @brief Return number of reconstructed energies in cache
  177 + *
  178 + * @return Number of reconstructed energies in cache
  179 + *
  180 + * Returns the number of reconstructed energies in the response cache.
  181 + ***************************************************************************/
  182 +int GCTAResponseCache::nerecos(void) const
  183 +{
  184 + // Initialize number of reconstructed energies
  185 + int nerecos = 0;
  186 +
  187 + // Compute number of elements
  188 + for (GCTAResponseCacheName::const_iterator it_name = m_cache.begin();
  189 + it_name != m_cache.end(); ++it_name) {
  190 + for (GCTAResponseCacheEreco::const_iterator it_ereco = it_name->second.begin();
  191 + it_ereco != it_name->second.end(); ++it_ereco) {
  192 + nerecos++;
  193 + }
  194 + }
  195 +
  196 + // Return number of reconstructed energies
  197 + return nerecos;
  198 +}
  199 +
  200 +
  201 +/***********************************************************************//**
  202 + * @brief Return number of true energies in cache
  203 + *
  204 + * @return Number of true energies in cache
  205 + *
  206 + * Returns the number of true energies in the response cache.
  207 + ***************************************************************************/
  208 +int GCTAResponseCache::netrues(void) const
  209 +{
  210 + // Initialize number of true energies
  211 + int netrues = 0;
  212 +
  213 + // Compute number of elements
  214 + for (GCTAResponseCacheName::const_iterator it_name = m_cache.begin();
  215 + it_name != m_cache.end(); ++it_name) {
  216 + for (GCTAResponseCacheEreco::const_iterator it_ereco = it_name->second.begin();
  217 + it_ereco != it_name->second.end(); ++it_ereco) {
  218 + netrues += it_ereco->second.size();
  219 + }
  220 + }
  221 +
  222 + // Return number of true energies
  223 + return netrues;
  224 +}
  225 +
  226 +
  227 +/***********************************************************************//**
  228 + * @brief Set cache value
  229 + *
  230 + * @param[in] name Cache name.
  231 + * @param[in] ereco Reconstructed energy.
  232 + * @param[in] etrue True energy.
  233 + * @param[in] value Cache value.
  234 + *
  235 + * Set cache value for a given @p name, reconstructed energy @p ereco, and
  236 + * true energy @p etrue.
  237 + ***************************************************************************/
  238 +void GCTAResponseCache::set(const std::string& name,
  239 + const GEnergy& ereco,
  240 + const GEnergy& etrue,
  241 + const double& value)
  242 +{
  243 + // Set cache value
  244 + m_cache[name][ereco][etrue] = value;
  245 +
  246 + // Return
  247 + return;
  248 +}
  249 +
  250 +
  251 +/***********************************************************************//**
  252 + * @brief Check if cache contains a value for specific parameters
  253 + *
  254 + * @param[in] name Cache name.
  255 + * @param[in] ereco Reconstructed energy.
  256 + * @param[in] etrue True energy.
  257 + * @param[out] value Pointer to cached value (only if found).
  258 + * @return True if cached value was found, otherwise false.
  259 + *
  260 + * Check if the cache contains a value for a specific set of parameters, and
  261 + * optionally returns that value through the @p value pointer argument. If
  262 + * @p value is set to NULL, no cached value is returned.
  263 + ***************************************************************************/
  264 +bool GCTAResponseCache::contains(const std::string& name,
  265 + const GEnergy& ereco,
  266 + const GEnergy& etrue,
  267 + double* value) const
  268 +{
  269 + // Initialise containment flag
  270 + bool contains = false;
  271 +
  272 + // Search for name in cache
  273 + GCTAResponseCacheName::const_iterator it_name = m_cache.find(name);
  274 + if (it_name != m_cache.end()) {
  275 +
  276 + // Search for reconstructed energy in cache
  277 + GCTAResponseCacheEreco::const_iterator it_ereco;
  278 + it_ereco = it_name->second.find(ereco);
  279 + if (it_ereco != it_name->second.end()) {
  280 +
  281 + // Search for true energy in cache
  282 + GCTAResponseCacheEtrue::const_iterator it_etrue = it_ereco->second.find(etrue);
  283 + if (it_etrue != it_ereco->second.end()) {
  284 + contains = true;
  285 + if (value != NULL) {
  286 + *value = it_etrue->second;
  287 + }
  288 + } // endif: true energy found
  289 +
  290 + } // endif: reconstructed energy found
  291 +
  292 + } // endif: name found
  293 +
  294 + // Return containment flag
  295 + return contains;
  296 +}
  297 +
  298 +
  299 +/***********************************************************************//**
  300 + * @brief Clone CTA response cache
  301 + *
  302 + * @return Pointer to deep copy of CTA response cache.
  303 + ***************************************************************************/
  304 +GCTAResponseCache* GCTAResponseCache::clone(void) const
  305 +{
  306 + return new GCTAResponseCache(*this);
  307 +}
  308 +
  309 +
  310 +/***********************************************************************//**
  311 + * @brief Print CTA response cache
  312 + *
  313 + * @param[in] chatter Chattiness.
  314 + * @return String containing CTA response cache information.
  315 + *
  316 + * @todo Implement method.
  317 + ***************************************************************************/
  318 +std::string GCTAResponseCache::print(const GChatter& chatter) const
  319 +{
  320 + // Initialise result string
  321 + std::string result;
  322 +
  323 + // Continue only if chatter is not silent
  324 + if (chatter != SILENT) {
  325 +
  326 + // Append header
  327 + result.append("=== GCTAResponseCache ===");
  328 +
  329 + // Append total cache size
  330 + result.append("\n"+gammalib::parformat("Number of cached values"));
  331 + result.append(gammalib::str(m_cache.size()));
  332 +
  333 + // Append information
  334 + for (GCTAResponseCacheName::const_iterator it_name = m_cache.begin();
  335 + it_name != m_cache.end(); ++it_name) {
  336 +
  337 + // Append name
  338 + result.append("\n"+gammalib::parformat("Name")+it_name->first);
  339 +
  340 + // Compute number of reconstructed and true energies
  341 + int nereco = 0;
  342 + int netrue = 0;
  343 + for (GCTAResponseCacheEreco::const_iterator it_ereco = it_name->second.begin();
  344 + it_ereco != it_name->second.end(); ++it_ereco) {
  345 + nereco++;
  346 + netrue += it_ereco->second.size();
  347 + }
  348 +
  349 + // Append number of reconstructed and true energies
  350 + result.append("\n"+gammalib::parformat("Reconstructed energies"));
  351 + result.append(gammalib::str(nereco));
  352 + result.append("\n"+gammalib::parformat("True energies"));
  353 + result.append(gammalib::str(netrue));
  354 +
  355 + } // endfor: looped over names
  356 +
  357 + } // endif: chatter was not silent
  358 +
  359 + // Return result
  360 + return result;
  361 +}
  362 +
  363 +
  364 +/*==========================================================================
  365 + = =
  366 + = Private methods =
  367 + = =
  368 + ==========================================================================*/
  369 +
  370 +/***********************************************************************//**
  371 + * @brief Initialise class members
  372 + ***************************************************************************/
  373 +void GCTAResponseCache::init_members(void)
  374 +{
  375 + // Initialise members
  376 + m_cache.clear();
  377 +
  378 + // Return
  379 + return;
  380 +}
  381 +
  382 +
  383 +/***********************************************************************//**
  384 + * @brief Copy class members
  385 + *
  386 + * @param[in] cache CTA response cache.
  387 + ***************************************************************************/
  388 +void GCTAResponseCache::copy_members(const GCTAResponseCache& cache)
  389 +{
  390 + // Copy members
  391 + m_cache = cache.m_cache;
  392 +
  393 + // Return
  394 + return;
  395 +}
  396 +
  397 +
  398 +/***********************************************************************//**
  399 + * @brief Delete class members
  400 + ***************************************************************************/
  401 +void GCTAResponseCache::free_members(void)
  402 +{
  403 + // Return
  404 + return;
  405 +}
... ...
inst/cta/test/test_CTA.cpp
... ... @@ -1409,6 +1409,119 @@ void TestGCTAResponse::test_response_edispcube(void)
1409 1409  
1410 1410  
1411 1411 /***********************************************************************//**
  1412 + * @brief Test response cache handling
  1413 + ***************************************************************************/
  1414 +void TestGCTAResponse::test_response_cache(void)
  1415 +{
  1416 + // Set some energies
  1417 + const GEnergy eng1(1.0, "TeV");
  1418 + const GEnergy eng2(2.0, "TeV");
  1419 + const GEnergy eng3(3.0, "TeV");
  1420 +
  1421 + // Initialise results
  1422 + double value = 0.0;
  1423 + bool flag = false;
  1424 +
  1425 + // Test empty response cache
  1426 + GCTAResponseCache cache1;
  1427 + test_assert(cache1.is_empty(), "Test is_empty() method for empty cache");
  1428 + test_value(cache1.size(), 0, "Test size() method for empty cache");
  1429 + test_value(cache1.nerecos(), 0, "Test nerecos() method for empty cache");
  1430 + test_value(cache1.netrues(), 0, "Test netrues() method for empty cache");
  1431 + flag = cache1.contains("Crab", eng1, eng1, &value);
  1432 + test_assert(!flag, "Test contains() method flag for empty cache");
  1433 +
  1434 + // Test filled response cube (one model, two ereco=etrue)
  1435 + GCTAResponseCache cache2;
  1436 + cache2.set("Crab", eng1, eng1, 1.0);
  1437 + cache2.set("Crab", eng2, eng2, 2.0);
  1438 + test_assert(!cache2.is_empty(), "Test is_empty() method for filled cache");
  1439 + test_value(cache2.size(), 2, "Test size() method for filled cache");
  1440 + test_value(cache2.nerecos(), 2, "Test nerecos() method for filled cache");
  1441 + test_value(cache2.netrues(), 2, "Test netrues() method for filled cache");
  1442 + flag = cache2.contains("Crab", eng1, eng1, &value);
  1443 + test_assert(flag, "Test contains() method flag for filled cache");
  1444 + test_value(value, 1.0, "Test contains() method value for filled cache");
  1445 + flag = cache2.contains("Crab", eng2, eng2, &value);
  1446 + test_assert(flag, "Test contains() method flag for filled cache");
  1447 + test_value(value, 2.0, "Test contains() method value for filled cache");
  1448 + flag = cache2.contains("Crab", eng2, eng1, &value);
  1449 + test_assert(!flag, "Test contains() method flag for non-existing true energy");
  1450 + flag = cache2.contains("Crab", eng1, eng2, &value);
  1451 + test_assert(!flag, "Test contains() method flag for non-existing reco. energy");
  1452 + flag = cache2.contains("Vela", eng2, eng2, &value);
  1453 + test_assert(!flag, "Test contains() method flag for non-existing name");
  1454 +
  1455 + // Test clearing of cache
  1456 + cache2.clear();
  1457 + test_assert(cache2.is_empty(), "Test is_empty() method for cleared cache");
  1458 + test_value(cache2.size(), 0, "Test size() method for cleared cache");
  1459 + test_value(cache2.nerecos(), 0, "Test nerecos() method for cleared cache");
  1460 + test_value(cache2.netrues(), 0, "Test netrues() method for cleared cache");
  1461 + flag = cache2.contains("Crab", eng1, eng1, &value);
  1462 + test_assert(!flag, "Test contains() method flag for cleared cache");
  1463 +
  1464 + // Test filled response cube (two models, two ereco, two etrue per ereco)
  1465 + GCTAResponseCache cache3;
  1466 + cache3.set("Crab", eng1, eng1, 1.0);
  1467 + cache3.set("Crab", eng1, eng2, 2.0);
  1468 + cache3.set("Crab", eng2, eng1, 3.0);
  1469 + cache3.set("Crab", eng2, eng2, 4.0);
  1470 + cache3.set("Vela", eng1, eng1, 10.0);
  1471 + cache3.set("Vela", eng1, eng2, 11.0);
  1472 + cache3.set("Vela", eng2, eng1, 12.0);
  1473 + cache3.set("Vela", eng2, eng2, 13.0);
  1474 + test_assert(!cache3.is_empty(), "Test is_empty() method for filled cache");
  1475 + test_value(cache3.size(), 8, "Test size() method for filled cache");
  1476 + test_value(cache3.nerecos(), 4, "Test nerecos() method for filled cache");
  1477 + test_value(cache3.netrues(), 8, "Test netrues() method for filled cache");
  1478 +
  1479 + // Test Crab cache
  1480 + flag = cache3.contains("Crab", eng1, eng1, &value);
  1481 + test_assert(flag, "Test contains() method flag for filled cache");
  1482 + test_value(value, 1.0, "Test contains() method value for filled cache");
  1483 + flag = cache3.contains("Crab", eng1, eng2, &value);
  1484 + test_assert(flag, "Test contains() method flag for filled cache");
  1485 + test_value(value, 2.0, "Test contains() method value for filled cache");
  1486 + flag = cache3.contains("Crab", eng2, eng1, &value);
  1487 + test_assert(flag, "Test contains() method flag for filled cache");
  1488 + test_value(value, 3.0, "Test contains() method value for filled cache");
  1489 + flag = cache3.contains("Crab", eng2, eng2, &value);
  1490 + test_assert(flag, "Test contains() method flag for filled cache");
  1491 + test_value(value, 4.0, "Test contains() method value for filled cache");
  1492 + flag = cache3.contains("Crab", eng3, eng1, &value);
  1493 + test_assert(!flag, "Test contains() method flag for non-existing true energy");
  1494 + flag = cache3.contains("Crab", eng1, eng3, &value);
  1495 + test_assert(!flag, "Test contains() method flag for non-existing reco. energy");
  1496 +
  1497 + // Test Vela cache
  1498 + flag = cache3.contains("Vela", eng1, eng1, &value);
  1499 + test_assert(flag, "Test contains() method flag for filled cache");
  1500 + test_value(value, 10.0, "Test contains() method value for filled cache");
  1501 + flag = cache3.contains("Vela", eng1, eng2, &value);
  1502 + test_assert(flag, "Test contains() method flag for filled cache");
  1503 + test_value(value, 11.0, "Test contains() method value for filled cache");
  1504 + flag = cache3.contains("Vela", eng2, eng1, &value);
  1505 + test_assert(flag, "Test contains() method flag for filled cache");
  1506 + test_value(value, 12.0, "Test contains() method value for filled cache");
  1507 + flag = cache3.contains("Vela", eng2, eng2, &value);
  1508 + test_assert(flag, "Test contains() method flag for filled cache");
  1509 + test_value(value, 13.0, "Test contains() method value for filled cache");
  1510 + flag = cache3.contains("Vela", eng3, eng1, &value);
  1511 + test_assert(!flag, "Test contains() method flag for non-existing true energy");
  1512 + flag = cache3.contains("Vela", eng1, eng3, &value);
  1513 + test_assert(!flag, "Test contains() method flag for non-existing reco. energy");
  1514 +
  1515 + // Test non-existing name
  1516 + flag = cache3.contains("Orion", eng1, eng1, &value);
  1517 + test_assert(!flag, "Test contains() method flag for non-existing name");
  1518 +
  1519 + // Return
  1520 + return;
  1521 +}
  1522 +
  1523 +
  1524 +/***********************************************************************//**
1412 1525 * @brief Utility function for energy dispersion tests
1413 1526 *
1414 1527 * @param[in] rsp Response.
... ...
inst/cta/test/test_CTA.hpp
... ... @@ -90,6 +90,7 @@ public:
90 90 void test_response_psfcube(void);
91 91 void test_response_bkgcube(void);
92 92 void test_response_edispcube(void);
  93 + void test_response_cache(void);
93 94  
94 95 // Utility methods
95 96 void test_response_edisp_integration(const GCTAResponseIrf& rsp,
... ...