Commit 4f92d5e4904d5ee0b2cd6705f55b8605d7a62353
1 parent
2aa78ba1
Introduce ctobservation base class
Showing
14 changed files
with
469 additions
and
59 deletions
ChangeLog
| @@ -3,7 +3,7 @@ | @@ -3,7 +3,7 @@ | ||
| 3 | * Version 1.2.0 released | 3 | * Version 1.2.0 released |
| 4 | ======================== | 4 | ======================== |
| 5 | 5 | ||
| 6 | - Introduce ctlikelihood base class (#1828) | 6 | + Introduce ctobservation and ctlikelihood base classes (#1828) |
| 7 | Remove ctselect::time_reference() method | 7 | Remove ctselect::time_reference() method |
| 8 | Add ctool and cscript pars() methods (#1838) | 8 | Add ctool and cscript pars() methods (#1838) |
| 9 | Fix ctbin::save() bug for empty observation container (#1835) | 9 | Fix ctbin::save() bug for empty observation container (#1835) |
NEWS
| @@ -24,10 +24,26 @@ all parameters in a dictionary (#1838). | @@ -24,10 +24,26 @@ all parameters in a dictionary (#1838). | ||
| 24 | 24 | ||
| 25 | Support model | 25 | Support model |
| 26 | ------------- | 26 | ------------- |
| 27 | -The ctlikelihood base class was introduced from which all likelihood ctools | ||
| 28 | -now derive (ctlike, cttsmap, cterror, ctulimit). This avoids code duplication | ||
| 29 | -and provides all tools with a standard interface. All tools now have the | ||
| 30 | -obs() and opt() method (#1828). | 27 | +The ctobservation base class that derives from the ctool base class was |
| 28 | +introduced to provide a common base class for all ctools that hold an | ||
| 29 | +observation container. The class implements the following methods: | ||
| 30 | +- obs() Returns reference to observation container | ||
| 31 | +- first_unbinned_observation() First unbinned CTA observation in container | ||
| 32 | +- next_unbinned_observation() Next unbinned CTA observation in container | ||
| 33 | + | ||
| 34 | +The ctlikelihood base class that derives from the ctobservation base class | ||
| 35 | +was introduced to provide a common base class for all ctools that perform | ||
| 36 | +maximum likelihood optimisations. The class holds an optimizer member. The | ||
| 37 | +class implements the following methods: | ||
| 38 | +- opt() Returns pointer to optimizer | ||
| 39 | +- evaluate() Evaluates log-likelihood at a given parameter value | ||
| 40 | +The following ctools derive from the class: | ||
| 41 | +- cterror | ||
| 42 | +- ctlike | ||
| 43 | +- cttsmap | ||
| 44 | +- ctulimit | ||
| 45 | + | ||
| 46 | +The introduction of these base classes avoids code duplication. | ||
| 31 | 47 | ||
| 32 | 48 | ||
| 33 | ctobssim - CTA observation simulation | 49 | ctobssim - CTA observation simulation |
pyext/ctlikelihood.i
| @@ -35,7 +35,7 @@ | @@ -35,7 +35,7 @@ | ||
| 35 | * | 35 | * |
| 36 | * @brief Base class for likelihood tools | 36 | * @brief Base class for likelihood tools |
| 37 | ***************************************************************************/ | 37 | ***************************************************************************/ |
| 38 | -class ctlikelihood : public ctool { | 38 | +class ctlikelihood : public ctobservation { |
| 39 | 39 | ||
| 40 | public: | 40 | public: |
| 41 | // Constructors and destructors | 41 | // Constructors and destructors |
| @@ -54,8 +54,7 @@ public: | @@ -54,8 +54,7 @@ public: | ||
| 54 | virtual void save(void) = 0; | 54 | virtual void save(void) = 0; |
| 55 | 55 | ||
| 56 | // Methods | 56 | // Methods |
| 57 | - const GObservations& obs(void) const; | ||
| 58 | - const GOptimizer* opt(void) const; | 57 | + const GOptimizer* opt(void) const; |
| 59 | }; | 58 | }; |
| 60 | 59 | ||
| 61 | 60 |
pyext/ctobservation.i
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctobservation - Base class for observation tools * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2016 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 ctobservation.i | ||
| 23 | + * @brief Observation tool base class interface definition | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +%{ | ||
| 28 | +/* Put headers and other declarations here that are needed for compilation */ | ||
| 29 | +#include "ctobservation.hpp" | ||
| 30 | +%} | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +/***********************************************************************//** | ||
| 34 | + * @class ctobservation | ||
| 35 | + * | ||
| 36 | + * @brief Base class for likelihood tools | ||
| 37 | + ***************************************************************************/ | ||
| 38 | +class ctobservation : public ctool { | ||
| 39 | + | ||
| 40 | +public: | ||
| 41 | + // Constructors and destructors | ||
| 42 | + ctobservation(void); | ||
| 43 | + ctobservation(const std::string& name, const std::string& version); | ||
| 44 | + ctobservation(const std::string& name, const std::string& version, | ||
| 45 | + const GObservations& obs); | ||
| 46 | + ctobservation(const std::string& name, const std::string& version, | ||
| 47 | + int argc, char* argv[]); | ||
| 48 | + ctobservation(const ctobservation& app); | ||
| 49 | + virtual ~ctobservation(void); | ||
| 50 | + | ||
| 51 | + // Pure virtual methods | ||
| 52 | + virtual void clear(void) = 0; | ||
| 53 | + virtual void run(void) = 0; | ||
| 54 | + virtual void save(void) = 0; | ||
| 55 | + | ||
| 56 | + // Methods | ||
| 57 | + const GObservations& obs(void) const; | ||
| 58 | +}; | ||
| 59 | + | ||
| 60 | + | ||
| 61 | +/***********************************************************************//** | ||
| 62 | + * @brief Likelihood tool Python extensions | ||
| 63 | + ***************************************************************************/ | ||
| 64 | +%extend ctobservation { | ||
| 65 | +} |
pyext/ctools/tools.i
| @@ -46,6 +46,7 @@ | @@ -46,6 +46,7 @@ | ||
| 46 | 46 | ||
| 47 | /* __ ctools base classes ________________________________________________ */ | 47 | /* __ ctools base classes ________________________________________________ */ |
| 48 | %include "ctool.i" | 48 | %include "ctool.i" |
| 49 | +%include "ctobservation.i" | ||
| 49 | %include "ctlikelihood.i" | 50 | %include "ctlikelihood.i" |
| 50 | 51 | ||
| 51 | /* __ ctools _____________________________________________________________ */ | 52 | /* __ ctools _____________________________________________________________ */ |
src/cterror/cterror.cpp
| @@ -190,6 +190,7 @@ void cterror::clear(void) | @@ -190,6 +190,7 @@ void cterror::clear(void) | ||
| 190 | // Free members | 190 | // Free members |
| 191 | free_members(); | 191 | free_members(); |
| 192 | this->ctlikelihood::free_members(); | 192 | this->ctlikelihood::free_members(); |
| 193 | + this->ctobservation::free_members(); | ||
| 193 | this->ctool::free_members(); | 194 | this->ctool::free_members(); |
| 194 | 195 | ||
| 195 | // Clear base class (needed to conserve tool name and version) | 196 | // Clear base class (needed to conserve tool name and version) |
| @@ -197,6 +198,7 @@ void cterror::clear(void) | @@ -197,6 +198,7 @@ void cterror::clear(void) | ||
| 197 | 198 | ||
| 198 | // Initialise members | 199 | // Initialise members |
| 199 | this->ctool::init_members(); | 200 | this->ctool::init_members(); |
| 201 | + this->ctobservation::init_members(); | ||
| 200 | this->ctlikelihood::init_members(); | 202 | this->ctlikelihood::init_members(); |
| 201 | init_members(); | 203 | init_members(); |
| 202 | 204 |
src/ctlike/ctlike.cpp
| @@ -179,6 +179,7 @@ void ctlike::clear(void) | @@ -179,6 +179,7 @@ void ctlike::clear(void) | ||
| 179 | // Free members | 179 | // Free members |
| 180 | free_members(); | 180 | free_members(); |
| 181 | this->ctlikelihood::free_members(); | 181 | this->ctlikelihood::free_members(); |
| 182 | + this->ctobservation::free_members(); | ||
| 182 | this->ctool::free_members(); | 183 | this->ctool::free_members(); |
| 183 | 184 | ||
| 184 | // Clear base class (needed to conserve tool name and version) | 185 | // Clear base class (needed to conserve tool name and version) |
| @@ -186,6 +187,7 @@ void ctlike::clear(void) | @@ -186,6 +187,7 @@ void ctlike::clear(void) | ||
| 186 | 187 | ||
| 187 | // Initialise members | 188 | // Initialise members |
| 188 | this->ctool::init_members(); | 189 | this->ctool::init_members(); |
| 190 | + this->ctobservation::init_members(); | ||
| 189 | this->ctlikelihood::init_members(); | 191 | this->ctlikelihood::init_members(); |
| 190 | init_members(); | 192 | init_members(); |
| 191 | 193 |
src/cttsmap/cttsmap.cpp
| @@ -182,6 +182,7 @@ void cttsmap::clear(void) | @@ -182,6 +182,7 @@ void cttsmap::clear(void) | ||
| 182 | // Free members | 182 | // Free members |
| 183 | free_members(); | 183 | free_members(); |
| 184 | this->ctlikelihood::free_members(); | 184 | this->ctlikelihood::free_members(); |
| 185 | + this->ctobservation::free_members(); | ||
| 185 | this->ctool::free_members(); | 186 | this->ctool::free_members(); |
| 186 | 187 | ||
| 187 | // Clear base class (needed to conserve tool name and version) | 188 | // Clear base class (needed to conserve tool name and version) |
| @@ -189,6 +190,7 @@ void cttsmap::clear(void) | @@ -189,6 +190,7 @@ void cttsmap::clear(void) | ||
| 189 | 190 | ||
| 190 | // Initialise members | 191 | // Initialise members |
| 191 | this->ctool::init_members(); | 192 | this->ctool::init_members(); |
| 193 | + this->ctobservation::init_members(); | ||
| 192 | this->ctlikelihood::init_members(); | 194 | this->ctlikelihood::init_members(); |
| 193 | init_members(); | 195 | init_members(); |
| 194 | 196 |
src/ctulimit/ctulimit.cpp
| @@ -192,6 +192,7 @@ void ctulimit::clear(void) | @@ -192,6 +192,7 @@ void ctulimit::clear(void) | ||
| 192 | // Free members | 192 | // Free members |
| 193 | free_members(); | 193 | free_members(); |
| 194 | this->ctlikelihood::free_members(); | 194 | this->ctlikelihood::free_members(); |
| 195 | + this->ctobservation::free_members(); | ||
| 195 | this->ctool::free_members(); | 196 | this->ctool::free_members(); |
| 196 | 197 | ||
| 197 | // Clear base class (needed to conserve tool name and version) | 198 | // Clear base class (needed to conserve tool name and version) |
| @@ -199,6 +200,7 @@ void ctulimit::clear(void) | @@ -199,6 +200,7 @@ void ctulimit::clear(void) | ||
| 199 | 200 | ||
| 200 | // Initialise members | 201 | // Initialise members |
| 201 | this->ctool::init_members(); | 202 | this->ctool::init_members(); |
| 203 | + this->ctobservation::init_members(); | ||
| 202 | this->ctlikelihood::init_members(); | 204 | this->ctlikelihood::init_members(); |
| 203 | init_members(); | 205 | init_members(); |
| 204 | 206 |
src/support/Makefile.am
| 1 | ############################################################################# | 1 | ############################################################################# |
| 2 | -# Makefile.am for ctool base class # | 2 | +# Makefile.am for ctool base classes # |
| 3 | # ------------------------------------------------------------------------- # | 3 | # ------------------------------------------------------------------------- # |
| 4 | # Copyright (C) 2016 Juergen Knoedlseder # | 4 | # Copyright (C) 2016 Juergen Knoedlseder # |
| 5 | # ------------------------------------------------------------------------- # | 5 | # ------------------------------------------------------------------------- # |
| @@ -20,7 +20,9 @@ | @@ -20,7 +20,9 @@ | ||
| 20 | ############################################################################# | 20 | ############################################################################# |
| 21 | 21 | ||
| 22 | # Define sources for this directory | 22 | # Define sources for this directory |
| 23 | -sources = ctool.cpp ctool.hpp ctlikelihood.cpp ctlikelihood.hpp | 23 | +sources = ctool.cpp ctool.hpp \ |
| 24 | + ctobservation.cpp ctobservation.hpp \ | ||
| 25 | + ctlikelihood.cpp ctlikelihood.hpp | ||
| 24 | 26 | ||
| 25 | # Build libtool library | 27 | # Build libtool library |
| 26 | noinst_LTLIBRARIES = libsupport.la | 28 | noinst_LTLIBRARIES = libsupport.la |
src/support/ctlikelihood.cpp
| @@ -28,15 +28,8 @@ | @@ -28,15 +28,8 @@ | ||
| 28 | #ifdef HAVE_CONFIG_H | 28 | #ifdef HAVE_CONFIG_H |
| 29 | #include <config.h> | 29 | #include <config.h> |
| 30 | #endif | 30 | #endif |
| 31 | -#include "GammaLib.hpp" | ||
| 32 | -#include "GCTALib.hpp" | ||
| 33 | #include "ctlikelihood.hpp" | 31 | #include "ctlikelihood.hpp" |
| 34 | 32 | ||
| 35 | -//#include <iostream> | ||
| 36 | -//#include "ctlikelihood.hpp" | ||
| 37 | -//#include "GTools.hpp" | ||
| 38 | -//#include "GOptimizer.hpp" | ||
| 39 | - | ||
| 40 | /* __ Method name definitions ____________________________________________ */ | 33 | /* __ Method name definitions ____________________________________________ */ |
| 41 | #define G_EVALUATE "ctlikelihood::evaluate(GModelPar&, double&)" | 34 | #define G_EVALUATE "ctlikelihood::evaluate(GModelPar&, double&)" |
| 42 | 35 | ||
| @@ -56,7 +49,7 @@ | @@ -56,7 +49,7 @@ | ||
| 56 | * | 49 | * |
| 57 | * Constructs an empty likelihood tool. | 50 | * Constructs an empty likelihood tool. |
| 58 | ***************************************************************************/ | 51 | ***************************************************************************/ |
| 59 | -ctlikelihood::ctlikelihood(void) : ctool() | 52 | +ctlikelihood::ctlikelihood(void) : ctobservation() |
| 60 | { | 53 | { |
| 61 | // Initialise members | 54 | // Initialise members |
| 62 | init_members(); | 55 | init_members(); |
| @@ -69,14 +62,15 @@ ctlikelihood::ctlikelihood(void) : ctool() | @@ -69,14 +62,15 @@ ctlikelihood::ctlikelihood(void) : ctool() | ||
| 69 | /***********************************************************************//** | 62 | /***********************************************************************//** |
| 70 | * @brief Name constructor | 63 | * @brief Name constructor |
| 71 | * | 64 | * |
| 72 | - * @param[in] name Application name. | ||
| 73 | - * @param[in] version Application version. | 65 | + * @param[in] name Likelihood tool name. |
| 66 | + * @param[in] version Likelihood tool version. | ||
| 74 | * | 67 | * |
| 75 | * Constructs a likelihood tool from the @p name and @p version. See the | 68 | * Constructs a likelihood tool from the @p name and @p version. See the |
| 76 | * equivalent ctool constructor for details. | 69 | * equivalent ctool constructor for details. |
| 77 | ***************************************************************************/ | 70 | ***************************************************************************/ |
| 78 | ctlikelihood::ctlikelihood(const std::string& name, | 71 | ctlikelihood::ctlikelihood(const std::string& name, |
| 79 | - const std::string& version) : ctool(name, version) | 72 | + const std::string& version) : |
| 73 | + ctobservation(name, version) | ||
| 80 | { | 74 | { |
| 81 | // Initialise members | 75 | // Initialise members |
| 82 | init_members(); | 76 | init_members(); |
| @@ -89,8 +83,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | @@ -89,8 +83,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | ||
| 89 | /***********************************************************************//** | 83 | /***********************************************************************//** |
| 90 | * @brief Observations constructor | 84 | * @brief Observations constructor |
| 91 | * | 85 | * |
| 92 | - * @param[in] name Application name. | ||
| 93 | - * @param[in] version Application version. | 86 | + * @param[in] name Likelihood tool name. |
| 87 | + * @param[in] version Likelihood tool version. | ||
| 94 | * param[in] obs Observation container. | 88 | * param[in] obs Observation container. |
| 95 | * | 89 | * |
| 96 | * Constructs a likelihood tool from the @p name, @p version and an | 90 | * Constructs a likelihood tool from the @p name, @p version and an |
| @@ -98,14 +92,12 @@ ctlikelihood::ctlikelihood(const std::string& name, | @@ -98,14 +92,12 @@ ctlikelihood::ctlikelihood(const std::string& name, | ||
| 98 | ***************************************************************************/ | 92 | ***************************************************************************/ |
| 99 | ctlikelihood::ctlikelihood(const std::string& name, | 93 | ctlikelihood::ctlikelihood(const std::string& name, |
| 100 | const std::string& version, | 94 | const std::string& version, |
| 101 | - const GObservations& obs) : ctool(name, version) | 95 | + const GObservations& obs) : |
| 96 | + ctobservation(name, version, obs) | ||
| 102 | { | 97 | { |
| 103 | // Initialise members | 98 | // Initialise members |
| 104 | init_members(); | 99 | init_members(); |
| 105 | 100 | ||
| 106 | - // Set observations | ||
| 107 | - m_obs = obs; | ||
| 108 | - | ||
| 109 | // Return | 101 | // Return |
| 110 | return; | 102 | return; |
| 111 | } | 103 | } |
| @@ -114,8 +106,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | @@ -114,8 +106,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | ||
| 114 | /***********************************************************************//** | 106 | /***********************************************************************//** |
| 115 | * @brief Command line constructor | 107 | * @brief Command line constructor |
| 116 | * | 108 | * |
| 117 | - * @param[in] name Application name. | ||
| 118 | - * @param[in] version Application version. | 109 | + * @param[in] name Likelihood tool name. |
| 110 | + * @param[in] version Likelihood tool version. | ||
| 119 | * @param[in] argc Number of arguments in command line. | 111 | * @param[in] argc Number of arguments in command line. |
| 120 | * @param[in] argv Array of command line arguments. | 112 | * @param[in] argv Array of command line arguments. |
| 121 | * | 113 | * |
| @@ -125,7 +117,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | @@ -125,7 +117,8 @@ ctlikelihood::ctlikelihood(const std::string& name, | ||
| 125 | ctlikelihood::ctlikelihood(const std::string& name, | 117 | ctlikelihood::ctlikelihood(const std::string& name, |
| 126 | const std::string& version, | 118 | const std::string& version, |
| 127 | int argc, | 119 | int argc, |
| 128 | - char *argv[]) : ctool(name, version, argc, argv) | 120 | + char *argv[]) : |
| 121 | + ctobservation(name, version, argc, argv) | ||
| 129 | { | 122 | { |
| 130 | // Initialise members | 123 | // Initialise members |
| 131 | init_members(); | 124 | init_members(); |
| @@ -138,12 +131,12 @@ ctlikelihood::ctlikelihood(const std::string& name, | @@ -138,12 +131,12 @@ ctlikelihood::ctlikelihood(const std::string& name, | ||
| 138 | /***********************************************************************//** | 131 | /***********************************************************************//** |
| 139 | * @brief Copy constructor | 132 | * @brief Copy constructor |
| 140 | * | 133 | * |
| 141 | - * @param[in] app Application. | 134 | + * @param[in] app Likelihood tool. |
| 142 | * | 135 | * |
| 143 | * Constructs an instance of a likelihood tool by copying information from | 136 | * Constructs an instance of a likelihood tool by copying information from |
| 144 | * another likelihood tool. | 137 | * another likelihood tool. |
| 145 | ***************************************************************************/ | 138 | ***************************************************************************/ |
| 146 | -ctlikelihood::ctlikelihood(const ctlikelihood& app) : ctool(app) | 139 | +ctlikelihood::ctlikelihood(const ctlikelihood& app) : ctobservation(app) |
| 147 | { | 140 | { |
| 148 | // Initialise members | 141 | // Initialise members |
| 149 | init_members(); | 142 | init_members(); |
| @@ -159,7 +152,7 @@ ctlikelihood::ctlikelihood(const ctlikelihood& app) : ctool(app) | @@ -159,7 +152,7 @@ ctlikelihood::ctlikelihood(const ctlikelihood& app) : ctool(app) | ||
| 159 | /***********************************************************************//** | 152 | /***********************************************************************//** |
| 160 | * @brief Destructor | 153 | * @brief Destructor |
| 161 | * | 154 | * |
| 162 | - * Destructs the ctlikelihood tool. | 155 | + * Destructs the likelihood tool. |
| 163 | ***************************************************************************/ | 156 | ***************************************************************************/ |
| 164 | ctlikelihood::~ctlikelihood(void) | 157 | ctlikelihood::~ctlikelihood(void) |
| 165 | { | 158 | { |
| @@ -180,8 +173,8 @@ ctlikelihood::~ctlikelihood(void) | @@ -180,8 +173,8 @@ ctlikelihood::~ctlikelihood(void) | ||
| 180 | /***********************************************************************//** | 173 | /***********************************************************************//** |
| 181 | * @brief Assignment operator | 174 | * @brief Assignment operator |
| 182 | * | 175 | * |
| 183 | - * @param[in] app Application. | ||
| 184 | - * @return Application. | 176 | + * @param[in] app Likelihood tool. |
| 177 | + * @return Likelihood tool. | ||
| 185 | * | 178 | * |
| 186 | * Assigns a likelihood tool. | 179 | * Assigns a likelihood tool. |
| 187 | ***************************************************************************/ | 180 | ***************************************************************************/ |
| @@ -191,7 +184,7 @@ ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) | @@ -191,7 +184,7 @@ ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) | ||
| 191 | if (this != &app) { | 184 | if (this != &app) { |
| 192 | 185 | ||
| 193 | // Copy base class members | 186 | // Copy base class members |
| 194 | - this->ctool::operator=(app); | 187 | + this->ctobservation::operator=(app); |
| 195 | 188 | ||
| 196 | // Free members | 189 | // Free members |
| 197 | free_members(); | 190 | free_members(); |
| @@ -228,7 +221,6 @@ ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) | @@ -228,7 +221,6 @@ ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) | ||
| 228 | void ctlikelihood::init_members(void) | 221 | void ctlikelihood::init_members(void) |
| 229 | { | 222 | { |
| 230 | // Initialise members | 223 | // Initialise members |
| 231 | - m_obs.clear(); | ||
| 232 | m_opt.clear(); | 224 | m_opt.clear(); |
| 233 | 225 | ||
| 234 | // Return | 226 | // Return |
| @@ -239,12 +231,11 @@ void ctlikelihood::init_members(void) | @@ -239,12 +231,11 @@ void ctlikelihood::init_members(void) | ||
| 239 | /***********************************************************************//** | 231 | /***********************************************************************//** |
| 240 | * @brief Copy class members | 232 | * @brief Copy class members |
| 241 | * | 233 | * |
| 242 | - * @param[in] app Application. | 234 | + * @param[in] app Likelihood tool. |
| 243 | ***************************************************************************/ | 235 | ***************************************************************************/ |
| 244 | void ctlikelihood::copy_members(const ctlikelihood& app) | 236 | void ctlikelihood::copy_members(const ctlikelihood& app) |
| 245 | { | 237 | { |
| 246 | // Copy members | 238 | // Copy members |
| 247 | - m_obs = app.m_obs; | ||
| 248 | m_opt = app.m_opt; | 239 | m_opt = app.m_opt; |
| 249 | 240 | ||
| 250 | // Return | 241 | // Return |
src/support/ctlikelihood.hpp
| @@ -28,7 +28,7 @@ | @@ -28,7 +28,7 @@ | ||
| 28 | #define CTLIKELIHOOD_HPP | 28 | #define CTLIKELIHOOD_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | -#include "ctool.hpp" | 31 | +#include "ctobservation.hpp" |
| 32 | 32 | ||
| 33 | /* __Definitions _________________________________________________________ */ | 33 | /* __Definitions _________________________________________________________ */ |
| 34 | 34 | ||
| @@ -38,7 +38,7 @@ | @@ -38,7 +38,7 @@ | ||
| 38 | * | 38 | * |
| 39 | * @brief Base class for likelihood tools | 39 | * @brief Base class for likelihood tools |
| 40 | ***************************************************************************/ | 40 | ***************************************************************************/ |
| 41 | -class ctlikelihood : public ctool { | 41 | +class ctlikelihood : public ctobservation { |
| 42 | 42 | ||
| 43 | public: | 43 | public: |
| 44 | // Constructors and destructors | 44 | // Constructors and destructors |
| @@ -60,8 +60,7 @@ public: | @@ -60,8 +60,7 @@ public: | ||
| 60 | virtual void save(void) = 0; | 60 | virtual void save(void) = 0; |
| 61 | 61 | ||
| 62 | // Methods | 62 | // Methods |
| 63 | - const GObservations& obs(void) const; | ||
| 64 | - const GOptimizer* opt(void) const; | 63 | + const GOptimizer* opt(void) const; |
| 65 | 64 | ||
| 66 | protected: | 65 | protected: |
| 67 | // Protected methods | 66 | // Protected methods |
| @@ -71,26 +70,11 @@ protected: | @@ -71,26 +70,11 @@ protected: | ||
| 71 | double evaluate(GModelPar& par, const double& value); | 70 | double evaluate(GModelPar& par, const double& value); |
| 72 | 71 | ||
| 73 | // Protected members | 72 | // Protected members |
| 74 | - GObservations m_obs; //!< Observation container | ||
| 75 | - GOptimizerLM m_opt; //!< Optimizer | 73 | + GOptimizerLM m_opt; //!< Optimizer |
| 76 | }; | 74 | }; |
| 77 | 75 | ||
| 78 | 76 | ||
| 79 | /***********************************************************************//** | 77 | /***********************************************************************//** |
| 80 | - * @brief Return observation container | ||
| 81 | - * | ||
| 82 | - * @return Reference to observation container. | ||
| 83 | - * | ||
| 84 | - * Returns a reference to the observation container. | ||
| 85 | - ***************************************************************************/ | ||
| 86 | -inline | ||
| 87 | -const GObservations& ctlikelihood::obs(void) const | ||
| 88 | -{ | ||
| 89 | - return m_obs; | ||
| 90 | -} | ||
| 91 | - | ||
| 92 | - | ||
| 93 | -/***********************************************************************//** | ||
| 94 | * @brief Return optimizer | 78 | * @brief Return optimizer |
| 95 | * | 79 | * |
| 96 | * @return Pointer to optimizer. | 80 | * @return Pointer to optimizer. |
src/support/ctobservation.cpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctobservation - Base class for observation tools * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2016 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 ctobservation.cpp | ||
| 23 | + * @brief Observation tool base class implementation | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +/* __ Includes ___________________________________________________________ */ | ||
| 28 | +#ifdef HAVE_CONFIG_H | ||
| 29 | +#include <config.h> | ||
| 30 | +#endif | ||
| 31 | +#include "ctobservation.hpp" | ||
| 32 | + | ||
| 33 | +/* __ Method name definitions ____________________________________________ */ | ||
| 34 | + | ||
| 35 | +/* __ Debug definitions __________________________________________________ */ | ||
| 36 | + | ||
| 37 | +/* __ Coding definitions _________________________________________________ */ | ||
| 38 | + | ||
| 39 | + | ||
| 40 | +/*========================================================================== | ||
| 41 | + = = | ||
| 42 | + = Constructors/destructors = | ||
| 43 | + = = | ||
| 44 | + ==========================================================================*/ | ||
| 45 | + | ||
| 46 | +/***********************************************************************//** | ||
| 47 | + * @brief Void constructor | ||
| 48 | + * | ||
| 49 | + * Constructs an empty observation tool. | ||
| 50 | + ***************************************************************************/ | ||
| 51 | +ctobservation::ctobservation(void) : ctool() | ||
| 52 | +{ | ||
| 53 | + // Initialise members | ||
| 54 | + init_members(); | ||
| 55 | + | ||
| 56 | + // Return | ||
| 57 | + return; | ||
| 58 | +} | ||
| 59 | + | ||
| 60 | + | ||
| 61 | +/***********************************************************************//** | ||
| 62 | + * @brief Name constructor | ||
| 63 | + * | ||
| 64 | + * @param[in] name Observation tool name. | ||
| 65 | + * @param[in] version Observation tool version. | ||
| 66 | + * | ||
| 67 | + * Constructs a observation tool from the @p name and @p version. See the | ||
| 68 | + * equivalent ctool constructor for details. | ||
| 69 | + ***************************************************************************/ | ||
| 70 | +ctobservation::ctobservation(const std::string& name, | ||
| 71 | + const std::string& version) : ctool(name, version) | ||
| 72 | +{ | ||
| 73 | + // Initialise members | ||
| 74 | + init_members(); | ||
| 75 | + | ||
| 76 | + // Return | ||
| 77 | + return; | ||
| 78 | +} | ||
| 79 | + | ||
| 80 | + | ||
| 81 | +/***********************************************************************//** | ||
| 82 | + * @brief Observations constructor | ||
| 83 | + * | ||
| 84 | + * @param[in] name Observation tool name. | ||
| 85 | + * @param[in] version Observation tool version. | ||
| 86 | + * param[in] obs Observation container. | ||
| 87 | + * | ||
| 88 | + * Constructs a observation tool from the @p name, @p version and an | ||
| 89 | + * observation container. | ||
| 90 | + ***************************************************************************/ | ||
| 91 | +ctobservation::ctobservation(const std::string& name, | ||
| 92 | + const std::string& version, | ||
| 93 | + const GObservations& obs) : ctool(name, version) | ||
| 94 | +{ | ||
| 95 | + // Initialise members | ||
| 96 | + init_members(); | ||
| 97 | + | ||
| 98 | + // Set observations | ||
| 99 | + m_obs = obs; | ||
| 100 | + | ||
| 101 | + // Return | ||
| 102 | + return; | ||
| 103 | +} | ||
| 104 | + | ||
| 105 | + | ||
| 106 | +/***********************************************************************//** | ||
| 107 | + * @brief Command line constructor | ||
| 108 | + * | ||
| 109 | + * @param[in] name Observation tool name. | ||
| 110 | + * @param[in] version Observation tool version. | ||
| 111 | + * @param[in] argc Number of arguments in command line. | ||
| 112 | + * @param[in] argv Array of command line arguments. | ||
| 113 | + * | ||
| 114 | + * Constructs a observation tool from the @p name, @p version and command | ||
| 115 | + * line arguments. See the equivalent ctool constructor for details. | ||
| 116 | + ***************************************************************************/ | ||
| 117 | +ctobservation::ctobservation(const std::string& name, | ||
| 118 | + const std::string& version, | ||
| 119 | + int argc, | ||
| 120 | + char *argv[]) : ctool(name, version, argc, argv) | ||
| 121 | +{ | ||
| 122 | + // Initialise members | ||
| 123 | + init_members(); | ||
| 124 | + | ||
| 125 | + // Return | ||
| 126 | + return; | ||
| 127 | +} | ||
| 128 | + | ||
| 129 | + | ||
| 130 | +/***********************************************************************//** | ||
| 131 | + * @brief Copy constructor | ||
| 132 | + * | ||
| 133 | + * @param[in] app Observation tool. | ||
| 134 | + * | ||
| 135 | + * Constructs an instance of a observation tool by copying information from | ||
| 136 | + * another observation tool. | ||
| 137 | + ***************************************************************************/ | ||
| 138 | +ctobservation::ctobservation(const ctobservation& app) : ctool(app) | ||
| 139 | +{ | ||
| 140 | + // Initialise members | ||
| 141 | + init_members(); | ||
| 142 | + | ||
| 143 | + // Copy members | ||
| 144 | + copy_members(app); | ||
| 145 | + | ||
| 146 | + // Return | ||
| 147 | + return; | ||
| 148 | +} | ||
| 149 | + | ||
| 150 | + | ||
| 151 | +/***********************************************************************//** | ||
| 152 | + * @brief Destructor | ||
| 153 | + * | ||
| 154 | + * Destructs the observation tool. | ||
| 155 | + ***************************************************************************/ | ||
| 156 | +ctobservation::~ctobservation(void) | ||
| 157 | +{ | ||
| 158 | + // Free members | ||
| 159 | + free_members(); | ||
| 160 | + | ||
| 161 | + // Return | ||
| 162 | + return; | ||
| 163 | +} | ||
| 164 | + | ||
| 165 | + | ||
| 166 | +/*========================================================================== | ||
| 167 | + = = | ||
| 168 | + = Operators = | ||
| 169 | + = = | ||
| 170 | + ==========================================================================*/ | ||
| 171 | + | ||
| 172 | +/***********************************************************************//** | ||
| 173 | + * @brief Assignment operator | ||
| 174 | + * | ||
| 175 | + * @param[in] app Observation tool. | ||
| 176 | + * @return Observation tool. | ||
| 177 | + * | ||
| 178 | + * Assigns a observation tool. | ||
| 179 | + ***************************************************************************/ | ||
| 180 | +ctobservation& ctobservation::operator=(const ctobservation& app) | ||
| 181 | +{ | ||
| 182 | + // Execute only if object is not identical | ||
| 183 | + if (this != &app) { | ||
| 184 | + | ||
| 185 | + // Copy base class members | ||
| 186 | + this->ctool::operator=(app); | ||
| 187 | + | ||
| 188 | + // Free members | ||
| 189 | + free_members(); | ||
| 190 | + | ||
| 191 | + // Initialise members | ||
| 192 | + init_members(); | ||
| 193 | + | ||
| 194 | + // Copy members | ||
| 195 | + copy_members(app); | ||
| 196 | + | ||
| 197 | + } // endif: object was not identical | ||
| 198 | + | ||
| 199 | + // Return this object | ||
| 200 | + return *this; | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | + | ||
| 204 | +/*========================================================================== | ||
| 205 | + = = | ||
| 206 | + = Public methods = | ||
| 207 | + = = | ||
| 208 | + ==========================================================================*/ | ||
| 209 | + | ||
| 210 | + | ||
| 211 | +/*========================================================================== | ||
| 212 | + = = | ||
| 213 | + = Private methods = | ||
| 214 | + = = | ||
| 215 | + ==========================================================================*/ | ||
| 216 | + | ||
| 217 | +/***********************************************************************//** | ||
| 218 | + * @brief Initialise class members | ||
| 219 | + ***************************************************************************/ | ||
| 220 | +void ctobservation::init_members(void) | ||
| 221 | +{ | ||
| 222 | + // Initialise members | ||
| 223 | + m_obs.clear(); | ||
| 224 | + | ||
| 225 | + // Return | ||
| 226 | + return; | ||
| 227 | +} | ||
| 228 | + | ||
| 229 | + | ||
| 230 | +/***********************************************************************//** | ||
| 231 | + * @brief Copy class members | ||
| 232 | + * | ||
| 233 | + * @param[in] app Observation tool. | ||
| 234 | + ***************************************************************************/ | ||
| 235 | +void ctobservation::copy_members(const ctobservation& app) | ||
| 236 | +{ | ||
| 237 | + // Copy members | ||
| 238 | + m_obs = app.m_obs; | ||
| 239 | + | ||
| 240 | + // Return | ||
| 241 | + return; | ||
| 242 | +} | ||
| 243 | + | ||
| 244 | + | ||
| 245 | +/***********************************************************************//** | ||
| 246 | + * @brief Delete class members | ||
| 247 | + ***************************************************************************/ | ||
| 248 | +void ctobservation::free_members(void) | ||
| 249 | +{ | ||
| 250 | + // Return | ||
| 251 | + return; | ||
| 252 | +} |
src/support/ctobservation.hpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctobservation - Base class for observation tools * | ||
| 3 | + * ----------------------------------------------------------------------- * | ||
| 4 | + * copyright (C) 2016 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 ctobservation.hpp | ||
| 23 | + * @brief Observation tool base class interface definition | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +#ifndef CTOBSERVATION_HPP | ||
| 28 | +#define CTOBSERVATION_HPP | ||
| 29 | + | ||
| 30 | +/* __ Includes ___________________________________________________________ */ | ||
| 31 | +#include "ctool.hpp" | ||
| 32 | + | ||
| 33 | +/* __Definitions _________________________________________________________ */ | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +/***********************************************************************//** | ||
| 37 | + * @class ctobservation | ||
| 38 | + * | ||
| 39 | + * @brief Base class for observation tools | ||
| 40 | + * | ||
| 41 | + * This is the baseclass for observation tools. Observation tools are ctools | ||
| 42 | + * that hold an observation container. | ||
| 43 | + ***************************************************************************/ | ||
| 44 | +class ctobservation : public ctool { | ||
| 45 | + | ||
| 46 | +public: | ||
| 47 | + // Constructors and destructors | ||
| 48 | + ctobservation(void); | ||
| 49 | + ctobservation(const std::string& name, const std::string& version); | ||
| 50 | + ctobservation(const std::string& name, const std::string& version, | ||
| 51 | + const GObservations& obs); | ||
| 52 | + ctobservation(const std::string& name, const std::string& version, | ||
| 53 | + int argc, char* argv[]); | ||
| 54 | + ctobservation(const ctobservation& app); | ||
| 55 | + virtual ~ctobservation(void); | ||
| 56 | + | ||
| 57 | + // Operators | ||
| 58 | + ctobservation& operator=(const ctobservation& app); | ||
| 59 | + | ||
| 60 | + // Pure virtual methods | ||
| 61 | + virtual void clear(void) = 0; | ||
| 62 | + virtual void run(void) = 0; | ||
| 63 | + virtual void save(void) = 0; | ||
| 64 | + | ||
| 65 | + // Methods | ||
| 66 | + const GObservations& obs(void) const; | ||
| 67 | + | ||
| 68 | +protected: | ||
| 69 | + // Protected methods | ||
| 70 | + void init_members(void); | ||
| 71 | + void copy_members(const ctobservation& app); | ||
| 72 | + void free_members(void); | ||
| 73 | + | ||
| 74 | + // Protected members | ||
| 75 | + GObservations m_obs; //!< Observation container | ||
| 76 | +}; | ||
| 77 | + | ||
| 78 | + | ||
| 79 | +/***********************************************************************//** | ||
| 80 | + * @brief Return observation container | ||
| 81 | + * | ||
| 82 | + * @return Reference to observation container. | ||
| 83 | + * | ||
| 84 | + * Returns a reference to the observation container. | ||
| 85 | + ***************************************************************************/ | ||
| 86 | +inline | ||
| 87 | +const GObservations& ctobservation::obs(void) const | ||
| 88 | +{ | ||
| 89 | + return m_obs; | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | +#endif /* CTOBSERVATION_HPP */ |