Commit 2aa78ba1527bfa6c047c4c422d744ca2923bac4e
1 parent
a35f9317
Introduce ctlikelihood base class for likelihood ctools (#1828)
All likelihood ctools now derive from the ctlikelihood base class. This avoids code duplication and provides all likelihood tools with a uniform interface.
Showing
26 changed files
with
660 additions
and
397 deletions
ChangeLog
| @@ -3,6 +3,7 @@ | @@ -3,6 +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 | Remove ctselect::time_reference() method | 7 | Remove ctselect::time_reference() method |
| 7 | Add ctool and cscript pars() methods (#1838) | 8 | Add ctool and cscript pars() methods (#1838) |
| 8 | Fix ctbin::save() bug for empty observation container (#1835) | 9 | Fix ctbin::save() bug for empty observation container (#1835) |
NEWS
| @@ -24,7 +24,10 @@ all parameters in a dictionary (#1838). | @@ -24,7 +24,10 @@ all parameters in a dictionary (#1838). | ||
| 24 | 24 | ||
| 25 | Support model | 25 | Support model |
| 26 | ------------- | 26 | ------------- |
| 27 | -None | 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). | ||
| 28 | 31 | ||
| 29 | 32 | ||
| 30 | ctobssim - CTA observation simulation | 33 | ctobssim - CTA observation simulation |
| @@ -57,12 +60,16 @@ ctlike - Maximum likelihood fitting | @@ -57,12 +60,16 @@ ctlike - Maximum likelihood fitting | ||
| 57 | The clear() method now calls GApplication::clear() to conserve the properties | 60 | The clear() method now calls GApplication::clear() to conserve the properties |
| 58 | of the tool (#1835). | 61 | of the tool (#1835). |
| 59 | 62 | ||
| 63 | +The class now derives from ctlikelihood (#1828). | ||
| 64 | + | ||
| 60 | 65 | ||
| 61 | cttsmap - Generation of Test Statistic map | 66 | cttsmap - Generation of Test Statistic map |
| 62 | ------------------------------------------ | 67 | ------------------------------------------ |
| 63 | The clear() method now calls GApplication::clear() to conserve the properties | 68 | The clear() method now calls GApplication::clear() to conserve the properties |
| 64 | of the tool (#1835). | 69 | of the tool (#1835). |
| 65 | 70 | ||
| 71 | +The class now derives from ctlikelihood (#1828). | ||
| 72 | + | ||
| 66 | 73 | ||
| 67 | ctskymap - CTA sky mapping | 74 | ctskymap - CTA sky mapping |
| 68 | -------------------------- | 75 | -------------------------- |
| @@ -134,12 +141,16 @@ of the tool (#1835). | @@ -134,12 +141,16 @@ of the tool (#1835). | ||
| 134 | The tool now also supports spectral models with the new naming conventions, and | 141 | The tool now also supports spectral models with the new naming conventions, and |
| 135 | in particular the "PhotonFlux" and "EnergyFlux" names (#1832). | 142 | in particular the "PhotonFlux" and "EnergyFlux" names (#1832). |
| 136 | 143 | ||
| 144 | +The class now derives from ctlikelihood (#1828). | ||
| 145 | + | ||
| 137 | 146 | ||
| 138 | cterror - Likelihood profile error computation | 147 | cterror - Likelihood profile error computation |
| 139 | ---------------------------------------------- | 148 | ---------------------------------------------- |
| 140 | The clear() method now calls GApplication::clear() to conserve the properties | 149 | The clear() method now calls GApplication::clear() to conserve the properties |
| 141 | of the tool (#1835). | 150 | of the tool (#1835). |
| 142 | 151 | ||
| 152 | +The class now derives from ctlikelihood (#1828). | ||
| 153 | + | ||
| 143 | 154 | ||
| 144 | cscripts | 155 | cscripts |
| 145 | -------- | 156 | -------- |
pyext/Makefile.am
| @@ -168,8 +168,8 @@ CLEANFILES = $(CLEAN_FILES) $(DEPFILES) | @@ -168,8 +168,8 @@ CLEANFILES = $(CLEAN_FILES) $(DEPFILES) | ||
| 168 | # Files to be removed in build directory | 168 | # Files to be removed in build directory |
| 169 | clean-local: | 169 | clean-local: |
| 170 | rm -rf build | 170 | rm -rf build |
| 171 | - rm -rf $(builddir)/ctools/*.py | ||
| 172 | - rm -rf $(builddir)/ctools/*.pyc | 171 | + rm -rf $(builddir)/ctools/c*.py |
| 172 | + rm -rf $(builddir)/ctools/c*.pyc | ||
| 173 | rm -rf $(builddir)/ctools/*_wrap.cpp | 173 | rm -rf $(builddir)/ctools/*_wrap.cpp |
| 174 | rm -rf $(builddir)/ctools/_tools.so | 174 | rm -rf $(builddir)/ctools/_tools.so |
| 175 | rm -rf $(builddir)/ctools/__pycache__ | 175 | rm -rf $(builddir)/ctools/__pycache__ |
pyext/cterror.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * cterror - Parameter error calculation tool * | 2 | * cterror - Parameter error calculation tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Florent Forest * | 4 | + * copyright (C) 2015-2016 by Florent Forest * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -34,9 +34,8 @@ | @@ -34,9 +34,8 @@ | ||
| 34 | * @class cterror | 34 | * @class cterror |
| 35 | * | 35 | * |
| 36 | * @brief Parameter error calculation tool | 36 | * @brief Parameter error calculation tool |
| 37 | - * | ||
| 38 | ***************************************************************************/ | 37 | ***************************************************************************/ |
| 39 | -class cterror : public ctool { | 38 | +class cterror : public ctlikelihood { |
| 40 | 39 | ||
| 41 | public: | 40 | public: |
| 42 | // Constructors and destructors | 41 | // Constructors and destructors |
| @@ -47,11 +46,9 @@ public: | @@ -47,11 +46,9 @@ public: | ||
| 47 | virtual ~cterror(void); | 46 | virtual ~cterror(void); |
| 48 | 47 | ||
| 49 | // Methods | 48 | // Methods |
| 50 | - void clear(void); | ||
| 51 | - void run(void); | ||
| 52 | - void save(void); | ||
| 53 | - const GObservations& obs(void) const; | ||
| 54 | - const GOptimizer* opt(void) const; | 49 | + void clear(void); |
| 50 | + void run(void); | ||
| 51 | + void save(void); | ||
| 55 | }; | 52 | }; |
| 56 | 53 | ||
| 57 | 54 |
pyext/ctlike.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * ctlike - Maximum likelihood fitting tool * | 2 | * ctlike - Maximum likelihood fitting tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2010-2014 by Jurgen Knodlseder * | 4 | + * copyright (C) 2010-2016 by Jurgen Knodlseder * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
| 34 | * | 34 | * |
| 35 | * @brief Maximum likelihood fitting tool | 35 | * @brief Maximum likelihood fitting tool |
| 36 | ***************************************************************************/ | 36 | ***************************************************************************/ |
| 37 | -class ctlike : public ctool { | 37 | +class ctlike : public ctlikelihood { |
| 38 | public: | 38 | public: |
| 39 | // Constructors and destructors | 39 | // Constructors and destructors |
| 40 | ctlike(void); | 40 | ctlike(void); |
| @@ -44,11 +44,9 @@ public: | @@ -44,11 +44,9 @@ public: | ||
| 44 | virtual ~ctlike(void); | 44 | virtual ~ctlike(void); |
| 45 | 45 | ||
| 46 | // Methods | 46 | // Methods |
| 47 | - void clear(void); | ||
| 48 | - void run(void); | ||
| 49 | - void save(void); | ||
| 50 | - const GObservations& obs(void) const; | ||
| 51 | - const GOptimizer* opt(void) const; | 47 | + void clear(void); |
| 48 | + void run(void); | ||
| 49 | + void save(void); | ||
| 52 | }; | 50 | }; |
| 53 | 51 | ||
| 54 | 52 |
pyext/ctlikelihood.i
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctlikelihood - Base class for likelihood 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 ctlikelihood.i | ||
| 23 | + * @brief Likelihood 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 "ctlikelihood.hpp" | ||
| 30 | +%} | ||
| 31 | + | ||
| 32 | + | ||
| 33 | +/***********************************************************************//** | ||
| 34 | + * @class ctlikelihood | ||
| 35 | + * | ||
| 36 | + * @brief Base class for likelihood tools | ||
| 37 | + ***************************************************************************/ | ||
| 38 | +class ctlikelihood : public ctool { | ||
| 39 | + | ||
| 40 | +public: | ||
| 41 | + // Constructors and destructors | ||
| 42 | + ctlikelihood(void); | ||
| 43 | + ctlikelihood(const std::string& name, const std::string& version); | ||
| 44 | + ctlikelihood(const std::string& name, const std::string& version, | ||
| 45 | + const GObservations& obs); | ||
| 46 | + ctlikelihood(const std::string& name, const std::string& version, | ||
| 47 | + int argc, char* argv[]); | ||
| 48 | + ctlikelihood(const ctlikelihood& app); | ||
| 49 | + virtual ~ctlikelihood(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 | + const GOptimizer* opt(void) const; | ||
| 59 | +}; | ||
| 60 | + | ||
| 61 | + | ||
| 62 | +/***********************************************************************//** | ||
| 63 | + * @brief Likelihood tool Python extensions | ||
| 64 | + ***************************************************************************/ | ||
| 65 | +%extend ctlikelihood { | ||
| 66 | +} |
pyext/ctool.i
| @@ -62,7 +62,7 @@ public: | @@ -62,7 +62,7 @@ public: | ||
| 62 | /***********************************************************************//** | 62 | /***********************************************************************//** |
| 63 | * @class ctool | 63 | * @class ctool |
| 64 | * | 64 | * |
| 65 | - * @brief ctool base class | 65 | + * @brief Base class for ctools |
| 66 | ***************************************************************************/ | 66 | ***************************************************************************/ |
| 67 | class ctool : public GApplication { | 67 | class ctool : public GApplication { |
| 68 | public: | 68 | public: |
pyext/ctools/tools.i
| @@ -44,8 +44,11 @@ | @@ -44,8 +44,11 @@ | ||
| 44 | %import(module="gammalib.base") "GBase.i"; | 44 | %import(module="gammalib.base") "GBase.i"; |
| 45 | %import(module="gammalib.app") "GApplication.i"; | 45 | %import(module="gammalib.app") "GApplication.i"; |
| 46 | 46 | ||
| 47 | -/* __ ctools _____________________________________________________________ */ | 47 | +/* __ ctools base classes ________________________________________________ */ |
| 48 | %include "ctool.i" | 48 | %include "ctool.i" |
| 49 | +%include "ctlikelihood.i" | ||
| 50 | + | ||
| 51 | +/* __ ctools _____________________________________________________________ */ | ||
| 49 | %include "ctbin.i" | 52 | %include "ctbin.i" |
| 50 | %include "ctobssim.i" | 53 | %include "ctobssim.i" |
| 51 | %include "ctlike.i" | 54 | %include "ctlike.i" |
pyext/cttsmap.i
| @@ -34,7 +34,8 @@ | @@ -34,7 +34,8 @@ | ||
| 34 | * | 34 | * |
| 35 | * @brief TS map calculation tool | 35 | * @brief TS map calculation tool |
| 36 | ***************************************************************************/ | 36 | ***************************************************************************/ |
| 37 | -class cttsmap : public ctool { | 37 | +class cttsmap : public ctlikelihood { |
| 38 | + | ||
| 38 | public: | 39 | public: |
| 39 | // Constructors and destructors | 40 | // Constructors and destructors |
| 40 | cttsmap(void); | 41 | cttsmap(void); |
| @@ -44,12 +45,11 @@ public: | @@ -44,12 +45,11 @@ public: | ||
| 44 | virtual ~cttsmap(void); | 45 | virtual ~cttsmap(void); |
| 45 | 46 | ||
| 46 | // Methods | 47 | // Methods |
| 47 | - void clear(void); | ||
| 48 | - void run(void); | ||
| 49 | - void save(void); | ||
| 50 | - void publish(const std::string& name = ""); | ||
| 51 | - const GObservations& obs(void) const; | ||
| 52 | - const GSkyMap& tsmap(void) const; | 48 | + void clear(void); |
| 49 | + void run(void); | ||
| 50 | + void save(void); | ||
| 51 | + void publish(const std::string& name = ""); | ||
| 52 | + const GSkyMap& tsmap(void) const; | ||
| 53 | }; | 53 | }; |
| 54 | 54 | ||
| 55 | 55 |
pyext/ctulimit.i
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * ctulimit - Upper limit calculation tool * | 2 | * ctulimit - Upper limit calculation tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Michael Mayer * | 4 | + * copyright (C) 2015-2016 by Michael Mayer * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -34,7 +34,7 @@ | @@ -34,7 +34,7 @@ | ||
| 34 | * | 34 | * |
| 35 | * @brief Upper limit calculation tool | 35 | * @brief Upper limit calculation tool |
| 36 | ***************************************************************************/ | 36 | ***************************************************************************/ |
| 37 | -class ctulimit : public ctool { | 37 | +class ctulimit : public ctlikelihood { |
| 38 | public: | 38 | public: |
| 39 | // Constructors and destructors | 39 | // Constructors and destructors |
| 40 | ctulimit(void); | 40 | ctulimit(void); |
| @@ -44,14 +44,12 @@ public: | @@ -44,14 +44,12 @@ public: | ||
| 44 | virtual ~ctulimit(void); | 44 | virtual ~ctulimit(void); |
| 45 | 45 | ||
| 46 | // Methods | 46 | // Methods |
| 47 | - void clear(void); | ||
| 48 | - void run(void); | ||
| 49 | - void save(void); | ||
| 50 | - const GObservations& obs(void) const; | ||
| 51 | - const GOptimizer* opt(void) const; | ||
| 52 | - const double& diff_ulimit(void) const; | ||
| 53 | - const double& flux_ulimit(void) const; | ||
| 54 | - const double& eflux_ulimit(void) const; | 47 | + void clear(void); |
| 48 | + void run(void); | ||
| 49 | + void save(void); | ||
| 50 | + const double& diff_ulimit(void) const; | ||
| 51 | + const double& flux_ulimit(void) const; | ||
| 52 | + const double& eflux_ulimit(void) const; | ||
| 55 | }; | 53 | }; |
| 56 | 54 | ||
| 57 | 55 |
src/cterror/cterror.cpp
| @@ -35,7 +35,6 @@ | @@ -35,7 +35,6 @@ | ||
| 35 | 35 | ||
| 36 | /* __ Method name definitions ____________________________________________ */ | 36 | /* __ Method name definitions ____________________________________________ */ |
| 37 | #define G_ERR_BISECTION "cterror::error_bisection(double&, double&)" | 37 | #define G_ERR_BISECTION "cterror::error_bisection(double&, double&)" |
| 38 | -#define G_EVALUATE "cterror::evaluate(double&)" | ||
| 39 | 38 | ||
| 40 | /* __ Debug definitions __________________________________________________ */ | 39 | /* __ Debug definitions __________________________________________________ */ |
| 41 | 40 | ||
| @@ -53,7 +52,7 @@ | @@ -53,7 +52,7 @@ | ||
| 53 | * | 52 | * |
| 54 | * Constructs an empty cterror tool. | 53 | * Constructs an empty cterror tool. |
| 55 | ***************************************************************************/ | 54 | ***************************************************************************/ |
| 56 | -cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | 55 | +cterror::cterror(void) : ctlikelihood(CTERROR_NAME, CTERROR_VERSION) |
| 57 | { | 56 | { |
| 58 | // Initialise members | 57 | // Initialise members |
| 59 | init_members(); | 58 | init_members(); |
| @@ -68,24 +67,19 @@ cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | @@ -68,24 +67,19 @@ cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | ||
| 68 | * | 67 | * |
| 69 | * param[in] obs Observation container. | 68 | * param[in] obs Observation container. |
| 70 | * | 69 | * |
| 71 | - * Constructs an instance of the cterror tool that will operate on the | ||
| 72 | - * provided observation container. | 70 | + * Constructs cterror tool from an observations container. |
| 73 | ***************************************************************************/ | 71 | ***************************************************************************/ |
| 74 | cterror::cterror(const GObservations& obs) : | 72 | cterror::cterror(const GObservations& obs) : |
| 75 | - ctool(CTERROR_NAME, CTERROR_VERSION) | 73 | + ctlikelihood(CTERROR_NAME, CTERROR_VERSION, obs) |
| 76 | { | 74 | { |
| 77 | // Initialise members | 75 | // Initialise members |
| 78 | init_members(); | 76 | init_members(); |
| 79 | 77 | ||
| 80 | - // Set observations | ||
| 81 | - m_obs = obs; | ||
| 82 | - | ||
| 83 | // Return | 78 | // Return |
| 84 | return; | 79 | return; |
| 85 | } | 80 | } |
| 86 | 81 | ||
| 87 | 82 | ||
| 88 | - | ||
| 89 | /***********************************************************************//** | 83 | /***********************************************************************//** |
| 90 | * @brief Command line constructor | 84 | * @brief Command line constructor |
| 91 | * | 85 | * |
| @@ -96,7 +90,7 @@ cterror::cterror(const GObservations& obs) : | @@ -96,7 +90,7 @@ cterror::cterror(const GObservations& obs) : | ||
| 96 | * parameters that are provided as command line arguments. | 90 | * parameters that are provided as command line arguments. |
| 97 | ***************************************************************************/ | 91 | ***************************************************************************/ |
| 98 | cterror::cterror(int argc, char *argv[]) : | 92 | cterror::cterror(int argc, char *argv[]) : |
| 99 | - ctool(CTERROR_NAME, CTERROR_VERSION, argc, argv) | 93 | + ctlikelihood(CTERROR_NAME, CTERROR_VERSION, argc, argv) |
| 100 | { | 94 | { |
| 101 | // Initialise members | 95 | // Initialise members |
| 102 | init_members(); | 96 | init_members(); |
| @@ -114,7 +108,7 @@ cterror::cterror(int argc, char *argv[]) : | @@ -114,7 +108,7 @@ cterror::cterror(int argc, char *argv[]) : | ||
| 114 | * Constructs an instance of the cterror tool by copying information from | 108 | * Constructs an instance of the cterror tool by copying information from |
| 115 | * another ctulimit tool. | 109 | * another ctulimit tool. |
| 116 | ***************************************************************************/ | 110 | ***************************************************************************/ |
| 117 | -cterror::cterror(const cterror& app) : ctool(app) | 111 | +cterror::cterror(const cterror& app) : ctlikelihood(app) |
| 118 | { | 112 | { |
| 119 | // Initialise members | 113 | // Initialise members |
| 120 | init_members(); | 114 | init_members(); |
| @@ -162,7 +156,7 @@ cterror& cterror::operator=(const cterror& app) | @@ -162,7 +156,7 @@ cterror& cterror::operator=(const cterror& app) | ||
| 162 | if (this != &app) { | 156 | if (this != &app) { |
| 163 | 157 | ||
| 164 | // Copy base class members | 158 | // Copy base class members |
| 165 | - this->ctool::operator=(app); | 159 | + this->ctlikelihood::operator=(app); |
| 166 | 160 | ||
| 167 | // Free members | 161 | // Free members |
| 168 | free_members(); | 162 | free_members(); |
| @@ -195,6 +189,7 @@ void cterror::clear(void) | @@ -195,6 +189,7 @@ void cterror::clear(void) | ||
| 195 | { | 189 | { |
| 196 | // Free members | 190 | // Free members |
| 197 | free_members(); | 191 | free_members(); |
| 192 | + this->ctlikelihood::free_members(); | ||
| 198 | this->ctool::free_members(); | 193 | this->ctool::free_members(); |
| 199 | 194 | ||
| 200 | // Clear base class (needed to conserve tool name and version) | 195 | // Clear base class (needed to conserve tool name and version) |
| @@ -202,6 +197,7 @@ void cterror::clear(void) | @@ -202,6 +197,7 @@ void cterror::clear(void) | ||
| 202 | 197 | ||
| 203 | // Initialise members | 198 | // Initialise members |
| 204 | this->ctool::init_members(); | 199 | this->ctool::init_members(); |
| 200 | + this->ctlikelihood::init_members(); | ||
| 205 | init_members(); | 201 | init_members(); |
| 206 | 202 | ||
| 207 | // Write header into logger | 203 | // Write header into logger |
| @@ -384,19 +380,17 @@ void cterror::init_members(void) | @@ -384,19 +380,17 @@ void cterror::init_members(void) | ||
| 384 | // Initialise user parameters | 380 | // Initialise user parameters |
| 385 | m_srcname.clear(); | 381 | m_srcname.clear(); |
| 386 | m_outmodel.clear(); | 382 | m_outmodel.clear(); |
| 387 | - m_confidence = 0.68; | ||
| 388 | - m_tol = 1.0e-3; | ||
| 389 | - m_max_iter = 50; | ||
| 390 | - m_value = 0.0; | ||
| 391 | - m_chatter = static_cast<GChatter>(2); | 383 | + m_confidence = 0.68; |
| 384 | + m_tol = 1.0e-3; | ||
| 385 | + m_max_iter = 50; | ||
| 386 | + m_apply_edisp = false; | ||
| 387 | + m_chatter = static_cast<GChatter>(2); | ||
| 392 | 388 | ||
| 393 | // Initialise protected members | 389 | // Initialise protected members |
| 394 | - m_obs.clear(); | ||
| 395 | - m_opt.clear(); | 390 | + m_value = 0.0; |
| 396 | m_dlogL = 0.0; | 391 | m_dlogL = 0.0; |
| 397 | m_best_logL = 0.0; | 392 | m_best_logL = 0.0; |
| 398 | m_model_par = NULL; | 393 | m_model_par = NULL; |
| 399 | - m_apply_edisp = false; | ||
| 400 | 394 | ||
| 401 | // Set optimizer parameters | 395 | // Set optimizer parameters |
| 402 | m_opt.max_iter(m_max_iter); | 396 | m_opt.max_iter(m_max_iter); |
| @@ -424,10 +418,9 @@ void cterror::copy_members(const cterror& app) | @@ -424,10 +418,9 @@ void cterror::copy_members(const cterror& app) | ||
| 424 | m_chatter = app.m_chatter; | 418 | m_chatter = app.m_chatter; |
| 425 | 419 | ||
| 426 | // Copy protected members | 420 | // Copy protected members |
| 427 | - m_obs = app.m_obs; | 421 | + m_value = app.m_value; |
| 428 | m_dlogL = app.m_dlogL; | 422 | m_dlogL = app.m_dlogL; |
| 429 | m_best_logL = app.m_best_logL; | 423 | m_best_logL = app.m_best_logL; |
| 430 | - m_opt = app.m_opt; | ||
| 431 | m_model_par = NULL; | 424 | m_model_par = NULL; |
| 432 | 425 | ||
| 433 | // Return | 426 | // Return |
| @@ -548,7 +541,7 @@ double cterror::error_bisection(const double& min, const double& max) | @@ -548,7 +541,7 @@ double cterror::error_bisection(const double& min, const double& max) | ||
| 548 | mid = (wrk_min + wrk_max) / 2.0; | 541 | mid = (wrk_min + wrk_max) / 2.0; |
| 549 | 542 | ||
| 550 | // Calculate function value | 543 | // Calculate function value |
| 551 | - double eval_mid = evaluate(mid); | 544 | + double eval_mid = evaluate(*m_model_par, mid) - (m_best_logL + m_dlogL); |
| 552 | 545 | ||
| 553 | // Write interval into logger | 546 | // Write interval into logger |
| 554 | log_value(EXPLICIT, " Iteration "+gammalib::str(iter), | 547 | log_value(EXPLICIT, " Iteration "+gammalib::str(iter), |
| @@ -597,53 +590,3 @@ double cterror::error_bisection(const double& min, const double& max) | @@ -597,53 +590,3 @@ double cterror::error_bisection(const double& min, const double& max) | ||
| 597 | return mid; | 590 | return mid; |
| 598 | 591 | ||
| 599 | } | 592 | } |
| 600 | - | ||
| 601 | - | ||
| 602 | -/***********************************************************************//** | ||
| 603 | - * @brief Evaluates the log-likelihood | ||
| 604 | - * | ||
| 605 | - * @param[in] value Parameter factor value | ||
| 606 | - * @return Log-likelihood value | ||
| 607 | - * | ||
| 608 | - * Evaluates the log-likelihood as a function of the parameter of interest. | ||
| 609 | - ***************************************************************************/ | ||
| 610 | -double cterror::evaluate(const double& value) | ||
| 611 | -{ | ||
| 612 | - // Initialise log-likelihood value | ||
| 613 | - double logL = 0.0; | ||
| 614 | - | ||
| 615 | - // Check if given parameter is within boundaries | ||
| 616 | - if (value > m_model_par->factor_min() && value < m_model_par->factor_max()) { | ||
| 617 | - | ||
| 618 | - // Change parameter factor | ||
| 619 | - m_model_par->factor_value(value); | ||
| 620 | - | ||
| 621 | - // Fix parameter | ||
| 622 | - m_model_par->fix(); | ||
| 623 | - | ||
| 624 | - // Re-optimize | ||
| 625 | - m_obs.optimize(m_opt); | ||
| 626 | - | ||
| 627 | - // Retrieve likelihood | ||
| 628 | - logL = m_obs.logL(); | ||
| 629 | - | ||
| 630 | - // Free parameter | ||
| 631 | - m_model_par->free(); | ||
| 632 | - | ||
| 633 | - } // endif: value was inside allowed range | ||
| 634 | - | ||
| 635 | - // ... otherwise signal that the parameter went outside the boundaries | ||
| 636 | - else { | ||
| 637 | - std::string msg = "Value of parameter \""+m_model_par->name()+"\" " | ||
| 638 | - "outside of validity range requested. To omit " | ||
| 639 | - "this error please enlarge the parameter range " | ||
| 640 | - "in the model XML file."; | ||
| 641 | - throw GException::invalid_value(G_EVALUATE, msg); | ||
| 642 | - } | ||
| 643 | - | ||
| 644 | - // Compute function value | ||
| 645 | - double logL_difference = logL - m_best_logL - m_dlogL; | ||
| 646 | - | ||
| 647 | - // Return | ||
| 648 | - return logL_difference; | ||
| 649 | -} |
src/cterror/cterror.hpp
| @@ -28,10 +28,7 @@ | @@ -28,10 +28,7 @@ | ||
| 28 | #define CTERROR_HPP | 28 | #define CTERROR_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | -#include <string> | ||
| 32 | -#include "GammaLib.hpp" | ||
| 33 | -#include "GCTALib.hpp" | ||
| 34 | -#include "ctool.hpp" | 31 | +#include "ctlikelihood.hpp" |
| 35 | 32 | ||
| 36 | /* __Definitions _________________________________________________________ */ | 33 | /* __Definitions _________________________________________________________ */ |
| 37 | #define CTERROR_NAME "cterror" | 34 | #define CTERROR_NAME "cterror" |
| @@ -43,7 +40,7 @@ | @@ -43,7 +40,7 @@ | ||
| 43 | * | 40 | * |
| 44 | * @brief Parameter error calculation tool | 41 | * @brief Parameter error calculation tool |
| 45 | ***************************************************************************/ | 42 | ***************************************************************************/ |
| 46 | -class cterror : public ctool { | 43 | +class cterror : public ctlikelihood { |
| 47 | 44 | ||
| 48 | public: | 45 | public: |
| 49 | // Constructors and destructors | 46 | // Constructors and destructors |
| @@ -57,11 +54,9 @@ public: | @@ -57,11 +54,9 @@ public: | ||
| 57 | cterror& operator=(const cterror& app); | 54 | cterror& operator=(const cterror& app); |
| 58 | 55 | ||
| 59 | // Methods | 56 | // Methods |
| 60 | - void clear(void); | ||
| 61 | - void run(void); | ||
| 62 | - void save(void); | ||
| 63 | - const GObservations& obs(void) const; | ||
| 64 | - const GOptimizer* opt(void) const; | 57 | + void clear(void); |
| 58 | + void run(void); | ||
| 59 | + void save(void); | ||
| 65 | 60 | ||
| 66 | protected: | 61 | protected: |
| 67 | // Protected methods | 62 | // Protected methods |
| @@ -69,7 +64,6 @@ protected: | @@ -69,7 +64,6 @@ protected: | ||
| 69 | void copy_members(const cterror& app); | 64 | void copy_members(const cterror& app); |
| 70 | void free_members(void); | 65 | void free_members(void); |
| 71 | void get_parameters(void); | 66 | void get_parameters(void); |
| 72 | - double evaluate(const double& value); | ||
| 73 | double error_bisection(const double& min, const double& max); | 67 | double error_bisection(const double& min, const double& max); |
| 74 | 68 | ||
| 75 | // User parameters | 69 | // User parameters |
| @@ -78,40 +72,14 @@ protected: | @@ -78,40 +72,14 @@ protected: | ||
| 78 | double m_confidence; //!< Confidence level | 72 | double m_confidence; //!< Confidence level |
| 79 | double m_tol; //!< Tolerance for limit determination | 73 | double m_tol; //!< Tolerance for limit determination |
| 80 | int m_max_iter; //!< Maximum number of iterations | 74 | int m_max_iter; //!< Maximum number of iterations |
| 81 | - double m_value; //!< Parameter value | ||
| 82 | bool m_apply_edisp; //!< Apply energy dispersion? | 75 | bool m_apply_edisp; //!< Apply energy dispersion? |
| 83 | GChatter m_chatter; //!< Chattiness | 76 | GChatter m_chatter; //!< Chattiness |
| 84 | 77 | ||
| 85 | // Protected members | 78 | // Protected members |
| 86 | - GObservations m_obs; //!< Observation container | 79 | + double m_value; //!< Parameter value |
| 87 | double m_dlogL; //!< Likelihood difference for upper limit computation | 80 | double m_dlogL; //!< Likelihood difference for upper limit computation |
| 88 | GModelPar* m_model_par; //!< Pointer to model parameter | 81 | GModelPar* m_model_par; //!< Pointer to model parameter |
| 89 | double m_best_logL; //!< Best fit log likelihood of given model | 82 | double m_best_logL; //!< Best fit log likelihood of given model |
| 90 | - GOptimizerLM m_opt; //!< Optimizer | ||
| 91 | }; | 83 | }; |
| 92 | 84 | ||
| 93 | - | ||
| 94 | -/***********************************************************************//** | ||
| 95 | - * @brief Return observation container | ||
| 96 | - * | ||
| 97 | - * @return Reference to observation container. | ||
| 98 | - ***************************************************************************/ | ||
| 99 | -inline | ||
| 100 | -const GObservations& cterror::obs(void) const | ||
| 101 | -{ | ||
| 102 | - return m_obs; | ||
| 103 | -} | ||
| 104 | - | ||
| 105 | - | ||
| 106 | -/***********************************************************************//** | ||
| 107 | - * @brief Return optimizer | ||
| 108 | - * | ||
| 109 | - * @return Pointer to optimizer. | ||
| 110 | - ***************************************************************************/ | ||
| 111 | -inline | ||
| 112 | -const GOptimizer* cterror::opt(void) const | ||
| 113 | -{ | ||
| 114 | - return &m_opt; | ||
| 115 | -} | ||
| 116 | - | ||
| 117 | #endif /* CTERROR_HPP */ | 85 | #endif /* CTERROR_HPP */ |
src/ctlike/ctlike.cpp
| @@ -48,7 +48,7 @@ | @@ -48,7 +48,7 @@ | ||
| 48 | /***********************************************************************//** | 48 | /***********************************************************************//** |
| 49 | * @brief Void constructor | 49 | * @brief Void constructor |
| 50 | ***************************************************************************/ | 50 | ***************************************************************************/ |
| 51 | -ctlike::ctlike(void) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | 51 | +ctlike::ctlike(void) : ctlikelihood(CTLIKE_NAME, CTLIKE_VERSION) |
| 52 | { | 52 | { |
| 53 | // Initialise members | 53 | // Initialise members |
| 54 | init_members(); | 54 | init_members(); |
| @@ -63,17 +63,14 @@ ctlike::ctlike(void) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | @@ -63,17 +63,14 @@ ctlike::ctlike(void) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | ||
| 63 | * | 63 | * |
| 64 | * param[in] obs Observation container. | 64 | * param[in] obs Observation container. |
| 65 | * | 65 | * |
| 66 | - * This method creates an instance of the class by copying an existing | ||
| 67 | - * observations container. | 66 | + * Constructs ctlike tool from an observations container. |
| 68 | ***************************************************************************/ | 67 | ***************************************************************************/ |
| 69 | -ctlike::ctlike(const GObservations& obs) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | 68 | +ctlike::ctlike(const GObservations& obs) : |
| 69 | + ctlikelihood(CTLIKE_NAME, CTLIKE_VERSION, obs) | ||
| 70 | { | 70 | { |
| 71 | // Initialise members | 71 | // Initialise members |
| 72 | init_members(); | 72 | init_members(); |
| 73 | 73 | ||
| 74 | - // Set observations | ||
| 75 | - m_obs = obs; | ||
| 76 | - | ||
| 77 | // Return | 74 | // Return |
| 78 | return; | 75 | return; |
| 79 | } | 76 | } |
| @@ -84,9 +81,12 @@ ctlike::ctlike(const GObservations& obs) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | @@ -84,9 +81,12 @@ ctlike::ctlike(const GObservations& obs) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | ||
| 84 | * | 81 | * |
| 85 | * @param[in] argc Number of arguments in command line. | 82 | * @param[in] argc Number of arguments in command line. |
| 86 | * @param[in] argv Array of command line arguments. | 83 | * @param[in] argv Array of command line arguments. |
| 84 | + * | ||
| 85 | + * Constructs an instance of the ctlike tool that will parse user parameters | ||
| 86 | + * that are provided as command line arguments. | ||
| 87 | ***************************************************************************/ | 87 | ***************************************************************************/ |
| 88 | ctlike::ctlike(int argc, char *argv[]) : | 88 | ctlike::ctlike(int argc, char *argv[]) : |
| 89 | - ctool(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) | 89 | + ctlikelihood(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) |
| 90 | { | 90 | { |
| 91 | // Initialise members | 91 | // Initialise members |
| 92 | init_members(); | 92 | init_members(); |
| @@ -101,7 +101,7 @@ ctlike::ctlike(int argc, char *argv[]) : | @@ -101,7 +101,7 @@ ctlike::ctlike(int argc, char *argv[]) : | ||
| 101 | * | 101 | * |
| 102 | * @param[in] app Application. | 102 | * @param[in] app Application. |
| 103 | ***************************************************************************/ | 103 | ***************************************************************************/ |
| 104 | -ctlike::ctlike(const ctlike& app) : ctool(app) | 104 | +ctlike::ctlike(const ctlike& app) : ctlikelihood(app) |
| 105 | { | 105 | { |
| 106 | // Initialise members | 106 | // Initialise members |
| 107 | init_members(); | 107 | init_members(); |
| @@ -145,7 +145,7 @@ ctlike& ctlike::operator=(const ctlike& app) | @@ -145,7 +145,7 @@ ctlike& ctlike::operator=(const ctlike& app) | ||
| 145 | if (this != &app) { | 145 | if (this != &app) { |
| 146 | 146 | ||
| 147 | // Copy base class members | 147 | // Copy base class members |
| 148 | - this->ctool::operator=(app); | 148 | + this->ctlikelihood::operator=(app); |
| 149 | 149 | ||
| 150 | // Free members | 150 | // Free members |
| 151 | free_members(); | 151 | free_members(); |
| @@ -178,6 +178,7 @@ void ctlike::clear(void) | @@ -178,6 +178,7 @@ void ctlike::clear(void) | ||
| 178 | { | 178 | { |
| 179 | // Free members | 179 | // Free members |
| 180 | free_members(); | 180 | free_members(); |
| 181 | + this->ctlikelihood::free_members(); | ||
| 181 | this->ctool::free_members(); | 182 | this->ctool::free_members(); |
| 182 | 183 | ||
| 183 | // Clear base class (needed to conserve tool name and version) | 184 | // Clear base class (needed to conserve tool name and version) |
| @@ -185,6 +186,7 @@ void ctlike::clear(void) | @@ -185,6 +186,7 @@ void ctlike::clear(void) | ||
| 185 | 186 | ||
| 186 | // Initialise members | 187 | // Initialise members |
| 187 | this->ctool::init_members(); | 188 | this->ctool::init_members(); |
| 189 | + this->ctlikelihood::init_members(); | ||
| 188 | init_members(); | 190 | init_members(); |
| 189 | 191 | ||
| 190 | // Write header into logger | 192 | // Write header into logger |
| @@ -291,7 +293,7 @@ void ctlike::run(void) | @@ -291,7 +293,7 @@ void ctlike::run(void) | ||
| 291 | 293 | ||
| 292 | // Write results into logger | 294 | // Write results into logger |
| 293 | log_header1(NORMAL, "Maximum likelihood optimisation results"); | 295 | log_header1(NORMAL, "Maximum likelihood optimisation results"); |
| 294 | - log_string(NORMAL, m_opt->print(m_chatter)); | 296 | + log_string(NORMAL, m_opt.print(m_chatter)); |
| 295 | log_value(NORMAL, "Maximum log likelihood", gammalib::str(m_logL,3)); | 297 | log_value(NORMAL, "Maximum log likelihood", gammalib::str(m_logL,3)); |
| 296 | log_value(NORMAL, "Observed events (Nobs)", gammalib::str(num_events,3)); | 298 | log_value(NORMAL, "Observed events (Nobs)", gammalib::str(num_events,3)); |
| 297 | log_value(NORMAL, "Predicted events (Npred)", gammalib::str(npred,3)+ | 299 | log_value(NORMAL, "Predicted events (Npred)", gammalib::str(npred,3)+ |
| @@ -398,10 +400,10 @@ void ctlike::get_parameters(void) | @@ -398,10 +400,10 @@ void ctlike::get_parameters(void) | ||
| 398 | 400 | ||
| 399 | // Set optimizer logger | 401 | // Set optimizer logger |
| 400 | if (logNormal()) { | 402 | if (logNormal()) { |
| 401 | - static_cast<GOptimizerLM*>(m_opt)->logger(&log); | 403 | + static_cast<GOptimizerLM*>(&m_opt)->logger(&log); |
| 402 | } | 404 | } |
| 403 | else { | 405 | else { |
| 404 | - static_cast<GOptimizerLM*>(m_opt)->logger(NULL); | 406 | + static_cast<GOptimizerLM*>(&m_opt)->logger(NULL); |
| 405 | } | 407 | } |
| 406 | 408 | ||
| 407 | // Write parameters into logger | 409 | // Write parameters into logger |
| @@ -442,7 +444,7 @@ void ctlike::optimize_lm(void) | @@ -442,7 +444,7 @@ void ctlike::optimize_lm(void) | ||
| 442 | } | 444 | } |
| 443 | 445 | ||
| 444 | // Perform LM optimization | 446 | // Perform LM optimization |
| 445 | - m_obs.optimize(*m_opt); | 447 | + m_obs.optimize(m_opt); |
| 446 | 448 | ||
| 447 | // Optionally refit | 449 | // Optionally refit |
| 448 | if (m_refit) { | 450 | if (m_refit) { |
| @@ -453,7 +455,7 @@ void ctlike::optimize_lm(void) | @@ -453,7 +455,7 @@ void ctlike::optimize_lm(void) | ||
| 453 | log.indent(1); | 455 | log.indent(1); |
| 454 | 456 | ||
| 455 | // Optimise again | 457 | // Optimise again |
| 456 | - m_obs.optimize(*m_opt); | 458 | + m_obs.optimize(m_opt); |
| 457 | 459 | ||
| 458 | } | 460 | } |
| 459 | 461 | ||
| @@ -464,10 +466,10 @@ void ctlike::optimize_lm(void) | @@ -464,10 +466,10 @@ void ctlike::optimize_lm(void) | ||
| 464 | (m_obs.function()).curvature())->print()); | 466 | (m_obs.function()).curvature())->print()); |
| 465 | 467 | ||
| 466 | // Compute errors | 468 | // Compute errors |
| 467 | - m_obs.errors(*m_opt); | 469 | + m_obs.errors(m_opt); |
| 468 | 470 | ||
| 469 | // Store maximum log likelihood value | 471 | // Store maximum log likelihood value |
| 470 | - m_logL = -(m_opt->value()); | 472 | + m_logL = -(m_opt.value()); |
| 471 | 473 | ||
| 472 | // Remove indent | 474 | // Remove indent |
| 473 | log.indent(0); | 475 | log.indent(0); |
| @@ -490,7 +492,7 @@ double ctlike::reoptimize_lm(void) | @@ -490,7 +492,7 @@ double ctlike::reoptimize_lm(void) | ||
| 490 | log.indent(1); | 492 | log.indent(1); |
| 491 | 493 | ||
| 492 | // Create a clone of the optimizer for the re-optimisation | 494 | // Create a clone of the optimizer for the re-optimisation |
| 493 | - GOptimizer* opt = m_opt->clone(); | 495 | + GOptimizer* opt = m_opt.clone(); |
| 494 | 496 | ||
| 495 | // Perform LM optimization | 497 | // Perform LM optimization |
| 496 | m_obs.optimize(*opt); | 498 | m_obs.optimize(*opt); |
| @@ -526,12 +528,10 @@ void ctlike::init_members(void) | @@ -526,12 +528,10 @@ void ctlike::init_members(void) | ||
| 526 | { | 528 | { |
| 527 | // Initialise members | 529 | // Initialise members |
| 528 | m_outmodel.clear(); | 530 | m_outmodel.clear(); |
| 529 | - m_obs.clear(); | ||
| 530 | m_refit = false; | 531 | m_refit = false; |
| 531 | m_max_iter = 100; // Set maximum number of iterations | 532 | m_max_iter = 100; // Set maximum number of iterations |
| 532 | m_max_stall = 10; // Set maximum number of stalls | 533 | m_max_stall = 10; // Set maximum number of stalls |
| 533 | m_logL = 0.0; | 534 | m_logL = 0.0; |
| 534 | - m_opt = NULL; | ||
| 535 | m_apply_edisp = false; | 535 | m_apply_edisp = false; |
| 536 | m_fix_spat_for_ts = false; | 536 | m_fix_spat_for_ts = false; |
| 537 | m_chatter = static_cast<GChatter>(2); | 537 | m_chatter = static_cast<GChatter>(2); |
| @@ -539,15 +539,9 @@ void ctlike::init_members(void) | @@ -539,15 +539,9 @@ void ctlike::init_members(void) | ||
| 539 | // Set logger properties | 539 | // Set logger properties |
| 540 | log.date(true); | 540 | log.date(true); |
| 541 | 541 | ||
| 542 | - // Allocate LM optimizer | ||
| 543 | - GOptimizerLM* opt = new GOptimizerLM(); | ||
| 544 | - | ||
| 545 | // Set optimizer parameters | 542 | // Set optimizer parameters |
| 546 | - opt->max_iter(m_max_iter); | ||
| 547 | - opt->max_stalls(m_max_stall); | ||
| 548 | - | ||
| 549 | - // Set optimizer pointer | ||
| 550 | - m_opt = opt; | 543 | + m_opt.max_iter(m_max_iter); |
| 544 | + m_opt.max_stalls(m_max_stall); | ||
| 551 | 545 | ||
| 552 | // Return | 546 | // Return |
| 553 | return; | 547 | return; |
| @@ -564,11 +558,9 @@ void ctlike::copy_members(const ctlike& app) | @@ -564,11 +558,9 @@ void ctlike::copy_members(const ctlike& app) | ||
| 564 | // Copy attributes | 558 | // Copy attributes |
| 565 | m_refit = app.m_refit; | 559 | m_refit = app.m_refit; |
| 566 | m_outmodel = app.m_outmodel; | 560 | m_outmodel = app.m_outmodel; |
| 567 | - m_obs = app.m_obs; | ||
| 568 | m_max_iter = app.m_max_iter; | 561 | m_max_iter = app.m_max_iter; |
| 569 | m_max_stall = app.m_max_stall; | 562 | m_max_stall = app.m_max_stall; |
| 570 | m_logL = app.m_logL; | 563 | m_logL = app.m_logL; |
| 571 | - m_opt = app.m_opt->clone(); | ||
| 572 | m_apply_edisp = app.m_apply_edisp; | 564 | m_apply_edisp = app.m_apply_edisp; |
| 573 | m_fix_spat_for_ts = app.m_fix_spat_for_ts; | 565 | m_fix_spat_for_ts = app.m_fix_spat_for_ts; |
| 574 | m_chatter = app.m_chatter; | 566 | m_chatter = app.m_chatter; |
| @@ -583,12 +575,6 @@ void ctlike::copy_members(const ctlike& app) | @@ -583,12 +575,6 @@ void ctlike::copy_members(const ctlike& app) | ||
| 583 | ***************************************************************************/ | 575 | ***************************************************************************/ |
| 584 | void ctlike::free_members(void) | 576 | void ctlike::free_members(void) |
| 585 | { | 577 | { |
| 586 | - // Free members | ||
| 587 | - if (m_opt != NULL) delete m_opt; | ||
| 588 | - | ||
| 589 | - // Mark pointers as free | ||
| 590 | - m_opt = NULL; | ||
| 591 | - | ||
| 592 | // Return | 578 | // Return |
| 593 | return; | 579 | return; |
| 594 | } | 580 | } |
src/ctlike/ctlike.hpp
| @@ -28,14 +28,11 @@ | @@ -28,14 +28,11 @@ | ||
| 28 | #define CTLIKE_HPP | 28 | #define CTLIKE_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | -#include <string> | ||
| 32 | -#include "GammaLib.hpp" | ||
| 33 | -#include "GCTALib.hpp" | ||
| 34 | -#include "ctool.hpp" | 31 | +#include "ctlikelihood.hpp" |
| 35 | 32 | ||
| 36 | /* __Definitions _________________________________________________________ */ | 33 | /* __Definitions _________________________________________________________ */ |
| 37 | #define CTLIKE_NAME "ctlike" | 34 | #define CTLIKE_NAME "ctlike" |
| 38 | -#define CTLIKE_VERSION "1.1.0" | 35 | +#define CTLIKE_VERSION "1.2.0" |
| 39 | 36 | ||
| 40 | 37 | ||
| 41 | /***********************************************************************//** | 38 | /***********************************************************************//** |
| @@ -43,7 +40,7 @@ | @@ -43,7 +40,7 @@ | ||
| 43 | * | 40 | * |
| 44 | * @brief Maximum likelihood fitting tool | 41 | * @brief Maximum likelihood fitting tool |
| 45 | ***************************************************************************/ | 42 | ***************************************************************************/ |
| 46 | -class ctlike : public ctool { | 43 | +class ctlike : public ctlikelihood { |
| 47 | 44 | ||
| 48 | public: | 45 | public: |
| 49 | // Constructors and destructors | 46 | // Constructors and destructors |
| @@ -57,11 +54,9 @@ public: | @@ -57,11 +54,9 @@ public: | ||
| 57 | ctlike& operator=(const ctlike& app); | 54 | ctlike& operator=(const ctlike& app); |
| 58 | 55 | ||
| 59 | // Methods | 56 | // Methods |
| 60 | - void clear(void); | ||
| 61 | - void run(void); | ||
| 62 | - void save(void); | ||
| 63 | - const GObservations& obs(void) const; | ||
| 64 | - const GOptimizer* opt(void) const; | 57 | + void clear(void); |
| 58 | + void run(void); | ||
| 59 | + void save(void); | ||
| 65 | 60 | ||
| 66 | protected: | 61 | protected: |
| 67 | // Protected methods | 62 | // Protected methods |
| @@ -80,35 +75,9 @@ protected: | @@ -80,35 +75,9 @@ protected: | ||
| 80 | GChatter m_chatter; //!< Chattiness | 75 | GChatter m_chatter; //!< Chattiness |
| 81 | 76 | ||
| 82 | // Members | 77 | // Members |
| 83 | - GObservations m_obs; //!< Observations | ||
| 84 | int m_max_iter; //!< Maximum number of iterations | 78 | int m_max_iter; //!< Maximum number of iterations |
| 85 | int m_max_stall; //!< Maximum number of stalls | 79 | int m_max_stall; //!< Maximum number of stalls |
| 86 | double m_logL; //!< Maximum log likelihood | 80 | double m_logL; //!< Maximum log likelihood |
| 87 | - GOptimizer* m_opt; //!< Optimizer | ||
| 88 | }; | 81 | }; |
| 89 | 82 | ||
| 90 | - | ||
| 91 | -/***********************************************************************//** | ||
| 92 | - * @brief Return observation container | ||
| 93 | - * | ||
| 94 | - * @return Reference to observation container | ||
| 95 | - ***************************************************************************/ | ||
| 96 | -inline | ||
| 97 | -const GObservations& ctlike::obs(void) const | ||
| 98 | -{ | ||
| 99 | - return m_obs; | ||
| 100 | -} | ||
| 101 | - | ||
| 102 | - | ||
| 103 | -/***********************************************************************//** | ||
| 104 | - * @brief Return optimizer | ||
| 105 | - * | ||
| 106 | - * @return Pointer to optimizer | ||
| 107 | - ***************************************************************************/ | ||
| 108 | -inline | ||
| 109 | -const GOptimizer* ctlike::opt(void) const | ||
| 110 | -{ | ||
| 111 | - return m_opt; | ||
| 112 | -} | ||
| 113 | - | ||
| 114 | #endif /* CTLIKE_HPP */ | 83 | #endif /* CTLIKE_HPP */ |
src/ctmodel/ctmodel.cpp
| @@ -598,7 +598,7 @@ void ctmodel::get_parameters(void) | @@ -598,7 +598,7 @@ void ctmodel::get_parameters(void) | ||
| 598 | * "expcube", "psfcube", and "bkgcube" parameters). In that case, it appended | 598 | * "expcube", "psfcube", and "bkgcube" parameters). In that case, it appended |
| 599 | * a dummy event cube to the observation. | 599 | * a dummy event cube to the observation. |
| 600 | * | 600 | * |
| 601 | - * @TODO Support stacked energy dispersion | 601 | + * @todo Support stacked energy dispersion |
| 602 | ***************************************************************************/ | 602 | ***************************************************************************/ |
| 603 | void ctmodel::get_obs(void) | 603 | void ctmodel::get_obs(void) |
| 604 | { | 604 | { |
src/ctobssim/ctobssim.cpp
| @@ -1039,10 +1039,11 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | @@ -1039,10 +1039,11 @@ void ctobssim::simulate_interval(GCTAObservation* obs, | ||
| 1039 | * @brief Simulate source events for a time slice | 1039 | * @brief Simulate source events for a time slice |
| 1040 | * | 1040 | * |
| 1041 | * @param[in] obs Pointer on CTA observation. | 1041 | * @param[in] obs Pointer on CTA observation. |
| 1042 | + * @param[in] rsp Pointer on CTA response. | ||
| 1042 | * @param[in,out] events Pointer on CTA event list. | 1043 | * @param[in,out] events Pointer on CTA event list. |
| 1043 | - * @param[in] models Model list. | ||
| 1044 | - * @param[in] tmin Start time. | ||
| 1045 | - * @param[in] tmax Stop time. | 1044 | + * @param[in] model Model. |
| 1045 | + * @param[in] tstart Start time. | ||
| 1046 | + * @param[in] tstop Stop time. | ||
| 1046 | * @param[in] etrue_min Minimum true energy. | 1047 | * @param[in] etrue_min Minimum true energy. |
| 1047 | * @param[in] etrue_max Maximum true energy. | 1048 | * @param[in] etrue_max Maximum true energy. |
| 1048 | * @param[in] ereco_min Minimum reconstructed energy. | 1049 | * @param[in] ereco_min Minimum reconstructed energy. |
src/cttsmap/cttsmap.cpp
| @@ -48,8 +48,10 @@ | @@ -48,8 +48,10 @@ | ||
| 48 | 48 | ||
| 49 | /***********************************************************************//** | 49 | /***********************************************************************//** |
| 50 | * @brief Void constructor | 50 | * @brief Void constructor |
| 51 | + * | ||
| 52 | + * Constructs an empty cttsmap tool. | ||
| 51 | ***************************************************************************/ | 53 | ***************************************************************************/ |
| 52 | -cttsmap::cttsmap(void) : ctool(CTTSMAP_NAME, CTTSMAP_VERSION) | 54 | +cttsmap::cttsmap(void) : ctlikelihood(CTTSMAP_NAME, CTTSMAP_VERSION) |
| 53 | { | 55 | { |
| 54 | // Initialise members | 56 | // Initialise members |
| 55 | init_members(); | 57 | init_members(); |
| @@ -64,32 +66,30 @@ cttsmap::cttsmap(void) : ctool(CTTSMAP_NAME, CTTSMAP_VERSION) | @@ -64,32 +66,30 @@ cttsmap::cttsmap(void) : ctool(CTTSMAP_NAME, CTTSMAP_VERSION) | ||
| 64 | * | 66 | * |
| 65 | * param[in] obs Observation container. | 67 | * param[in] obs Observation container. |
| 66 | * | 68 | * |
| 67 | - * This method creates an instance of the class by copying an existing | ||
| 68 | - * observations container. | 69 | + * Constructs cttsmap tool from an observations container. |
| 69 | ***************************************************************************/ | 70 | ***************************************************************************/ |
| 70 | cttsmap::cttsmap(const GObservations& obs) : | 71 | cttsmap::cttsmap(const GObservations& obs) : |
| 71 | - ctool(CTTSMAP_NAME, CTTSMAP_VERSION) | 72 | + ctlikelihood(CTTSMAP_NAME, CTTSMAP_VERSION, obs) |
| 72 | { | 73 | { |
| 73 | // Initialise members | 74 | // Initialise members |
| 74 | init_members(); | 75 | init_members(); |
| 75 | 76 | ||
| 76 | - // Set observations | ||
| 77 | - m_obs = obs; | ||
| 78 | - | ||
| 79 | // Return | 77 | // Return |
| 80 | return; | 78 | return; |
| 81 | } | 79 | } |
| 82 | 80 | ||
| 83 | 81 | ||
| 84 | - | ||
| 85 | /***********************************************************************//** | 82 | /***********************************************************************//** |
| 86 | * @brief Command line constructor | 83 | * @brief Command line constructor |
| 87 | * | 84 | * |
| 88 | * @param[in] argc Number of arguments in command line. | 85 | * @param[in] argc Number of arguments in command line. |
| 89 | * @param[in] argv Array of command line arguments. | 86 | * @param[in] argv Array of command line arguments. |
| 87 | + * | ||
| 88 | + * Constructs an instance of the cttsmap tool that will parse user parameters | ||
| 89 | + * that are provided as command line arguments. | ||
| 90 | ***************************************************************************/ | 90 | ***************************************************************************/ |
| 91 | cttsmap::cttsmap(int argc, char *argv[]) : | 91 | cttsmap::cttsmap(int argc, char *argv[]) : |
| 92 | - ctool(CTTSMAP_NAME, CTTSMAP_VERSION, argc, argv) | 92 | + ctlikelihood(CTTSMAP_NAME, CTTSMAP_VERSION, argc, argv) |
| 93 | { | 93 | { |
| 94 | // Initialise members | 94 | // Initialise members |
| 95 | init_members(); | 95 | init_members(); |
| @@ -104,7 +104,7 @@ cttsmap::cttsmap(int argc, char *argv[]) : | @@ -104,7 +104,7 @@ cttsmap::cttsmap(int argc, char *argv[]) : | ||
| 104 | * | 104 | * |
| 105 | * @param[in] app Application. | 105 | * @param[in] app Application. |
| 106 | ***************************************************************************/ | 106 | ***************************************************************************/ |
| 107 | -cttsmap::cttsmap(const cttsmap& app) : ctool(app) | 107 | +cttsmap::cttsmap(const cttsmap& app) : ctlikelihood(app) |
| 108 | { | 108 | { |
| 109 | // Initialise members | 109 | // Initialise members |
| 110 | init_members(); | 110 | init_members(); |
| @@ -148,7 +148,7 @@ cttsmap& cttsmap::operator=(const cttsmap& app) | @@ -148,7 +148,7 @@ cttsmap& cttsmap::operator=(const cttsmap& app) | ||
| 148 | if (this != &app) { | 148 | if (this != &app) { |
| 149 | 149 | ||
| 150 | // Copy base class members | 150 | // Copy base class members |
| 151 | - this->ctool::operator=(app); | 151 | + this->ctlikelihood::operator=(app); |
| 152 | 152 | ||
| 153 | // Free members | 153 | // Free members |
| 154 | free_members(); | 154 | free_members(); |
| @@ -181,6 +181,7 @@ void cttsmap::clear(void) | @@ -181,6 +181,7 @@ void cttsmap::clear(void) | ||
| 181 | { | 181 | { |
| 182 | // Free members | 182 | // Free members |
| 183 | free_members(); | 183 | free_members(); |
| 184 | + this->ctlikelihood::free_members(); | ||
| 184 | this->ctool::free_members(); | 185 | this->ctool::free_members(); |
| 185 | 186 | ||
| 186 | // Clear base class (needed to conserve tool name and version) | 187 | // Clear base class (needed to conserve tool name and version) |
| @@ -188,6 +189,7 @@ void cttsmap::clear(void) | @@ -188,6 +189,7 @@ void cttsmap::clear(void) | ||
| 188 | 189 | ||
| 189 | // Initialise members | 190 | // Initialise members |
| 190 | this->ctool::init_members(); | 191 | this->ctool::init_members(); |
| 192 | + this->ctlikelihood::init_members(); | ||
| 191 | init_members(); | 193 | init_members(); |
| 192 | 194 | ||
| 193 | // Write header into logger | 195 | // Write header into logger |
| @@ -232,9 +234,13 @@ void cttsmap::run(void) | @@ -232,9 +234,13 @@ void cttsmap::run(void) | ||
| 232 | int binmin = (m_binmin == -1) ? 0 : m_binmin; | 234 | int binmin = (m_binmin == -1) ? 0 : m_binmin; |
| 233 | int binmax = (m_binmax == -1) ? m_tsmap.npix() : m_binmax; | 235 | int binmax = (m_binmax == -1) ? m_tsmap.npix() : m_binmax; |
| 234 | 236 | ||
| 235 | - // Initialise optimizer | ||
| 236 | - GOptimizerLM* opt = (logExplicit()) ? new GOptimizerLM(&log) | ||
| 237 | - : new GOptimizerLM(); | 237 | + // Set optimizer logger |
| 238 | + if (logExplicit()) { | ||
| 239 | + static_cast<GOptimizerLM*>(&m_opt)->logger(&log); | ||
| 240 | + } | ||
| 241 | + else { | ||
| 242 | + static_cast<GOptimizerLM*>(&m_opt)->logger(NULL); | ||
| 243 | + } | ||
| 238 | 244 | ||
| 239 | // Store initial models | 245 | // Store initial models |
| 240 | GModels models_orig = m_obs.models(); | 246 | GModels models_orig = m_obs.models(); |
| @@ -253,8 +259,8 @@ void cttsmap::run(void) | @@ -253,8 +259,8 @@ void cttsmap::run(void) | ||
| 253 | 259 | ||
| 254 | // Compute likelihood without the test source | 260 | // Compute likelihood without the test source |
| 255 | m_obs.models(models); | 261 | m_obs.models(models); |
| 256 | - m_obs.optimize(*opt); | ||
| 257 | - m_logL0 = -(opt->value()); | 262 | + m_obs.optimize(m_opt); |
| 263 | + m_logL0 = -(m_opt.value()); | ||
| 258 | 264 | ||
| 259 | } | 265 | } |
| 260 | 266 | ||
| @@ -280,10 +286,10 @@ void cttsmap::run(void) | @@ -280,10 +286,10 @@ void cttsmap::run(void) | ||
| 280 | m_obs.models(models); | 286 | m_obs.models(models); |
| 281 | 287 | ||
| 282 | // Optimize observation container | 288 | // Optimize observation container |
| 283 | - m_obs.optimize(*opt); | 289 | + m_obs.optimize(m_opt); |
| 284 | 290 | ||
| 285 | // Retrieve the Likelihood value | 291 | // Retrieve the Likelihood value |
| 286 | - double logL1 = -(opt->value()); | 292 | + double logL1 = -(m_opt.value()); |
| 287 | 293 | ||
| 288 | // Compute TS value | 294 | // Compute TS value |
| 289 | double ts = 2.0 * (logL1 - m_logL0); | 295 | double ts = 2.0 * (logL1 - m_logL0); |
| @@ -431,7 +437,6 @@ void cttsmap::init_members(void) | @@ -431,7 +437,6 @@ void cttsmap::init_members(void) | ||
| 431 | m_publish = false; | 437 | m_publish = false; |
| 432 | 438 | ||
| 433 | // Initialise protected members | 439 | // Initialise protected members |
| 434 | - m_obs.clear(); | ||
| 435 | m_binmin = -1; | 440 | m_binmin = -1; |
| 436 | m_binmax = -1; | 441 | m_binmax = -1; |
| 437 | m_logL0 = 0.0; | 442 | m_logL0 = 0.0; |
| @@ -463,11 +468,10 @@ void cttsmap::copy_members(const cttsmap& app) | @@ -463,11 +468,10 @@ void cttsmap::copy_members(const cttsmap& app) | ||
| 463 | m_binmin = app.m_binmin; | 468 | m_binmin = app.m_binmin; |
| 464 | m_binmax = app.m_binmax; | 469 | m_binmax = app.m_binmax; |
| 465 | m_logL0 = app.m_logL0; | 470 | m_logL0 = app.m_logL0; |
| 466 | - m_obs = app.m_obs; | ||
| 467 | m_tsmap = app.m_tsmap; | 471 | m_tsmap = app.m_tsmap; |
| 472 | + m_statusmap = app.m_statusmap; | ||
| 468 | m_mapnames = app.m_mapnames; | 473 | m_mapnames = app.m_mapnames; |
| 469 | m_maps = app.m_maps; | 474 | m_maps = app.m_maps; |
| 470 | - m_statusmap = app.m_statusmap; | ||
| 471 | 475 | ||
| 472 | // Clone protected members | 476 | // Clone protected members |
| 473 | m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() | 477 | m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() |
src/cttsmap/cttsmap.hpp
| @@ -28,9 +28,7 @@ | @@ -28,9 +28,7 @@ | ||
| 28 | #define CTTSMAP_HPP | 28 | #define CTTSMAP_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | -#include "GammaLib.hpp" | ||
| 32 | -#include "GCTALib.hpp" | ||
| 33 | -#include "ctool.hpp" | 31 | +#include "ctlikelihood.hpp" |
| 34 | 32 | ||
| 35 | /* __Definitions _________________________________________________________ */ | 33 | /* __Definitions _________________________________________________________ */ |
| 36 | #define CTTSMAP_NAME "cttsmap" | 34 | #define CTTSMAP_NAME "cttsmap" |
| @@ -55,7 +53,7 @@ | @@ -55,7 +53,7 @@ | ||
| 55 | * grid of coordinates. The best fit results (TS, flux, index) are stored in | 53 | * grid of coordinates. The best fit results (TS, flux, index) are stored in |
| 56 | * maps which are saved in the output FITS files. | 54 | * maps which are saved in the output FITS files. |
| 57 | ***************************************************************************/ | 55 | ***************************************************************************/ |
| 58 | -class cttsmap : public ctool { | 56 | +class cttsmap : public ctlikelihood { |
| 59 | 57 | ||
| 60 | public: | 58 | public: |
| 61 | // Constructors and destructors | 59 | // Constructors and destructors |
| @@ -69,12 +67,11 @@ public: | @@ -69,12 +67,11 @@ public: | ||
| 69 | cttsmap& operator=(const cttsmap& app); | 67 | cttsmap& operator=(const cttsmap& app); |
| 70 | 68 | ||
| 71 | // Methods | 69 | // Methods |
| 72 | - void clear(void); | ||
| 73 | - void run(void); | ||
| 74 | - void save(void); | ||
| 75 | - void publish(const std::string& name = ""); | ||
| 76 | - const GObservations& obs(void) const; | ||
| 77 | - const GSkyMap& tsmap(void) const; | 70 | + void clear(void); |
| 71 | + void run(void); | ||
| 72 | + void save(void); | ||
| 73 | + void publish(const std::string& name = ""); | ||
| 74 | + const GSkyMap& tsmap(void) const; | ||
| 78 | 75 | ||
| 79 | protected: | 76 | protected: |
| 80 | // Protected methods | 77 | // Protected methods |
| @@ -96,7 +93,6 @@ protected: | @@ -96,7 +93,6 @@ protected: | ||
| 96 | double m_logL0; //!< Likelihood value of null hypothesis | 93 | double m_logL0; //!< Likelihood value of null hypothesis |
| 97 | 94 | ||
| 98 | // Protected members | 95 | // Protected members |
| 99 | - GObservations m_obs; //!< Observation container | ||
| 100 | GSkyMap m_tsmap; //!< TS map | 96 | GSkyMap m_tsmap; //!< TS map |
| 101 | GSkyMap m_statusmap; //!< Map of computed bins | 97 | GSkyMap m_statusmap; //!< Map of computed bins |
| 102 | std::vector<std::string> m_mapnames; //!< Names of free parameters | 98 | std::vector<std::string> m_mapnames; //!< Names of free parameters |
| @@ -106,18 +102,6 @@ protected: | @@ -106,18 +102,6 @@ protected: | ||
| 106 | 102 | ||
| 107 | 103 | ||
| 108 | /***********************************************************************//** | 104 | /***********************************************************************//** |
| 109 | - * @brief Return observation container | ||
| 110 | - * | ||
| 111 | - * @return Reference to observation container | ||
| 112 | - ***************************************************************************/ | ||
| 113 | -inline | ||
| 114 | -const GObservations& cttsmap::obs(void) const | ||
| 115 | -{ | ||
| 116 | - return m_obs; | ||
| 117 | -} | ||
| 118 | - | ||
| 119 | - | ||
| 120 | -/***********************************************************************//** | ||
| 121 | * @brief Return TS skymap | 105 | * @brief Return TS skymap |
| 122 | * | 106 | * |
| 123 | * @return Reference to TS skymap | 107 | * @return Reference to TS skymap |
src/ctulimit/ctulimit.cpp
| @@ -36,7 +36,6 @@ | @@ -36,7 +36,6 @@ | ||
| 36 | /* __ Method name definitions ____________________________________________ */ | 36 | /* __ Method name definitions ____________________________________________ */ |
| 37 | #define G_GET_MODEL_PARAMETER "ctulimit::get_model_parameter()" | 37 | #define G_GET_MODEL_PARAMETER "ctulimit::get_model_parameter()" |
| 38 | #define G_UL_BISECTION "ctulimit::ul_bisection(double&, double&)" | 38 | #define G_UL_BISECTION "ctulimit::ul_bisection(double&, double&)" |
| 39 | -#define G_EVALUATE "ctulimit::evaluate(double&)" | ||
| 40 | 39 | ||
| 41 | /* __ Debug definitions __________________________________________________ */ | 40 | /* __ Debug definitions __________________________________________________ */ |
| 42 | 41 | ||
| @@ -54,7 +53,7 @@ | @@ -54,7 +53,7 @@ | ||
| 54 | * | 53 | * |
| 55 | * Constructs an empty ctulimit tool. | 54 | * Constructs an empty ctulimit tool. |
| 56 | ***************************************************************************/ | 55 | ***************************************************************************/ |
| 57 | -ctulimit::ctulimit(void) : ctool(CTULIMIT_NAME, CTULIMIT_VERSION) | 56 | +ctulimit::ctulimit(void) : ctlikelihood(CTULIMIT_NAME, CTULIMIT_VERSION) |
| 58 | { | 57 | { |
| 59 | // Initialise members | 58 | // Initialise members |
| 60 | init_members(); | 59 | init_members(); |
| @@ -69,18 +68,14 @@ ctulimit::ctulimit(void) : ctool(CTULIMIT_NAME, CTULIMIT_VERSION) | @@ -69,18 +68,14 @@ ctulimit::ctulimit(void) : ctool(CTULIMIT_NAME, CTULIMIT_VERSION) | ||
| 69 | * | 68 | * |
| 70 | * param[in] obs Observation container. | 69 | * param[in] obs Observation container. |
| 71 | * | 70 | * |
| 72 | - * Constructs an instance of the ctulimit tool that will operate on the | ||
| 73 | - * provided observation container. | 71 | + * Constructs ctulimit tool from an observations container. |
| 74 | ***************************************************************************/ | 72 | ***************************************************************************/ |
| 75 | ctulimit::ctulimit(const GObservations& obs) : | 73 | ctulimit::ctulimit(const GObservations& obs) : |
| 76 | - ctool(CTULIMIT_NAME, CTULIMIT_VERSION) | 74 | + ctlikelihood(CTULIMIT_NAME, CTULIMIT_VERSION, obs) |
| 77 | { | 75 | { |
| 78 | // Initialise members | 76 | // Initialise members |
| 79 | init_members(); | 77 | init_members(); |
| 80 | 78 | ||
| 81 | - // Set observations | ||
| 82 | - m_obs = obs; | ||
| 83 | - | ||
| 84 | // Return | 79 | // Return |
| 85 | return; | 80 | return; |
| 86 | } | 81 | } |
| @@ -97,7 +92,7 @@ ctulimit::ctulimit(const GObservations& obs) : | @@ -97,7 +92,7 @@ ctulimit::ctulimit(const GObservations& obs) : | ||
| 97 | * parameters that are provided as command line arguments. | 92 | * parameters that are provided as command line arguments. |
| 98 | ***************************************************************************/ | 93 | ***************************************************************************/ |
| 99 | ctulimit::ctulimit(int argc, char *argv[]) : | 94 | ctulimit::ctulimit(int argc, char *argv[]) : |
| 100 | - ctool(CTULIMIT_NAME, CTULIMIT_VERSION, argc, argv) | 95 | + ctlikelihood(CTULIMIT_NAME, CTULIMIT_VERSION, argc, argv) |
| 101 | { | 96 | { |
| 102 | // Initialise members | 97 | // Initialise members |
| 103 | init_members(); | 98 | init_members(); |
| @@ -115,7 +110,7 @@ ctulimit::ctulimit(int argc, char *argv[]) : | @@ -115,7 +110,7 @@ ctulimit::ctulimit(int argc, char *argv[]) : | ||
| 115 | * Constructs an instance of the ctulimit tool by copying information from | 110 | * Constructs an instance of the ctulimit tool by copying information from |
| 116 | * another ctulimit tool. | 111 | * another ctulimit tool. |
| 117 | ***************************************************************************/ | 112 | ***************************************************************************/ |
| 118 | -ctulimit::ctulimit(const ctulimit& app) : ctool(app) | 113 | +ctulimit::ctulimit(const ctulimit& app) : ctlikelihood(app) |
| 119 | { | 114 | { |
| 120 | // Initialise members | 115 | // Initialise members |
| 121 | init_members(); | 116 | init_members(); |
| @@ -163,7 +158,7 @@ ctulimit& ctulimit::operator=(const ctulimit& app) | @@ -163,7 +158,7 @@ ctulimit& ctulimit::operator=(const ctulimit& app) | ||
| 163 | if (this != &app) { | 158 | if (this != &app) { |
| 164 | 159 | ||
| 165 | // Copy base class members | 160 | // Copy base class members |
| 166 | - this->ctool::operator=(app); | 161 | + this->ctlikelihood::operator=(app); |
| 167 | 162 | ||
| 168 | // Free members | 163 | // Free members |
| 169 | free_members(); | 164 | free_members(); |
| @@ -196,6 +191,7 @@ void ctulimit::clear(void) | @@ -196,6 +191,7 @@ void ctulimit::clear(void) | ||
| 196 | { | 191 | { |
| 197 | // Free members | 192 | // Free members |
| 198 | free_members(); | 193 | free_members(); |
| 194 | + this->ctlikelihood::free_members(); | ||
| 199 | this->ctool::free_members(); | 195 | this->ctool::free_members(); |
| 200 | 196 | ||
| 201 | // Clear base class (needed to conserve tool name and version) | 197 | // Clear base class (needed to conserve tool name and version) |
| @@ -203,6 +199,7 @@ void ctulimit::clear(void) | @@ -203,6 +199,7 @@ void ctulimit::clear(void) | ||
| 203 | 199 | ||
| 204 | // Initialise members | 200 | // Initialise members |
| 205 | this->ctool::init_members(); | 201 | this->ctool::init_members(); |
| 202 | + this->ctlikelihood::init_members(); | ||
| 206 | init_members(); | 203 | init_members(); |
| 207 | 204 | ||
| 208 | // Write header into logger | 205 | // Write header into logger |
| @@ -378,8 +375,6 @@ void ctulimit::init_members(void) | @@ -378,8 +375,6 @@ void ctulimit::init_members(void) | ||
| 378 | m_chatter = static_cast<GChatter>(2); | 375 | m_chatter = static_cast<GChatter>(2); |
| 379 | 376 | ||
| 380 | // Initialise protected members | 377 | // Initialise protected members |
| 381 | - m_obs.clear(); | ||
| 382 | - m_opt.clear(); | ||
| 383 | m_dlogL = 0.0; | 378 | m_dlogL = 0.0; |
| 384 | m_skymodel = NULL; | 379 | m_skymodel = NULL; |
| 385 | m_model_par = NULL; | 380 | m_model_par = NULL; |
| @@ -418,13 +413,11 @@ void ctulimit::copy_members(const ctulimit& app) | @@ -418,13 +413,11 @@ void ctulimit::copy_members(const ctulimit& app) | ||
| 418 | m_chatter = app.m_chatter; | 413 | m_chatter = app.m_chatter; |
| 419 | 414 | ||
| 420 | // Copy protected members | 415 | // Copy protected members |
| 421 | - m_obs = app.m_obs; | ||
| 422 | m_dlogL = app.m_dlogL; | 416 | m_dlogL = app.m_dlogL; |
| 423 | m_best_logL = app.m_best_logL; | 417 | m_best_logL = app.m_best_logL; |
| 424 | m_diff_ulimit = app.m_diff_ulimit; | 418 | m_diff_ulimit = app.m_diff_ulimit; |
| 425 | m_flux_ulimit = app.m_flux_ulimit; | 419 | m_flux_ulimit = app.m_flux_ulimit; |
| 426 | m_eflux_ulimit = app.m_eflux_ulimit; | 420 | m_eflux_ulimit = app.m_eflux_ulimit; |
| 427 | - m_opt = app.m_opt; | ||
| 428 | 421 | ||
| 429 | // Extract model parameter | 422 | // Extract model parameter |
| 430 | get_model_parameter(); | 423 | get_model_parameter(); |
| @@ -609,7 +602,7 @@ void ctulimit::ulimit_bisection(const double& min, const double& max) | @@ -609,7 +602,7 @@ void ctulimit::ulimit_bisection(const double& min, const double& max) | ||
| 609 | double mid = (wrk_min + wrk_max) / 2.0; | 602 | double mid = (wrk_min + wrk_max) / 2.0; |
| 610 | 603 | ||
| 611 | // Calculate function value | 604 | // Calculate function value |
| 612 | - double eval_mid = evaluate(mid); | 605 | + double eval_mid = evaluate(*m_model_par, mid) - (m_best_logL + m_dlogL); |
| 613 | 606 | ||
| 614 | // Check for convergence inside tolerance | 607 | // Check for convergence inside tolerance |
| 615 | if (std::abs(eval_mid) < m_tol) { | 608 | if (std::abs(eval_mid) < m_tol) { |
| @@ -633,53 +626,3 @@ void ctulimit::ulimit_bisection(const double& min, const double& max) | @@ -633,53 +626,3 @@ void ctulimit::ulimit_bisection(const double& min, const double& max) | ||
| 633 | return; | 626 | return; |
| 634 | 627 | ||
| 635 | } | 628 | } |
| 636 | - | ||
| 637 | - | ||
| 638 | -/***********************************************************************//** | ||
| 639 | - * @brief Evaluates the log-likelihood | ||
| 640 | - * | ||
| 641 | - * @param[in] value Parameter factor value | ||
| 642 | - * @return Log-likelihood value | ||
| 643 | - * | ||
| 644 | - * Evaluates the log-likelihood as a function of the parameter of interest. | ||
| 645 | - ***************************************************************************/ | ||
| 646 | -double ctulimit::evaluate(const double& value) | ||
| 647 | -{ | ||
| 648 | - // Initialise log-likelihood value | ||
| 649 | - double logL = 0.0; | ||
| 650 | - | ||
| 651 | - // Check if given parameter is within boundaries | ||
| 652 | - if (value > m_model_par->factor_min() && value < m_model_par->factor_max()) { | ||
| 653 | - | ||
| 654 | - // Change parameter factor | ||
| 655 | - m_model_par->factor_value(value); | ||
| 656 | - | ||
| 657 | - // Fix parameter | ||
| 658 | - m_model_par->fix(); | ||
| 659 | - | ||
| 660 | - // Re-optimize | ||
| 661 | - m_obs.optimize(m_opt); | ||
| 662 | - | ||
| 663 | - // Retrieve likelihood | ||
| 664 | - logL = m_obs.logL(); | ||
| 665 | - | ||
| 666 | - // Free parameter | ||
| 667 | - m_model_par->free(); | ||
| 668 | - | ||
| 669 | - } // endif: value was inside allowed range | ||
| 670 | - | ||
| 671 | - // ... otherwise signal that the parameter went outside the boundaries | ||
| 672 | - else { | ||
| 673 | - std::string msg = "Value of parameter \""+m_model_par->name()+"\" " | ||
| 674 | - "outside of validity range requested. To omit " | ||
| 675 | - "this error please enlarge the parameter range " | ||
| 676 | - "in the model XML file."; | ||
| 677 | - throw GException::invalid_value(G_EVALUATE, msg); | ||
| 678 | - } | ||
| 679 | - | ||
| 680 | - // Compute function value | ||
| 681 | - double logL_difference = logL - m_best_logL - m_dlogL; | ||
| 682 | - | ||
| 683 | - // Return | ||
| 684 | - return logL_difference; | ||
| 685 | -} |
src/ctulimit/ctulimit.hpp
| @@ -28,9 +28,7 @@ | @@ -28,9 +28,7 @@ | ||
| 28 | #define CTULIMIT_HPP | 28 | #define CTULIMIT_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | -#include "GammaLib.hpp" | ||
| 32 | -#include "GCTALib.hpp" | ||
| 33 | -#include "ctool.hpp" | 31 | +#include "ctlikelihood.hpp" |
| 34 | 32 | ||
| 35 | /* __Definitions _________________________________________________________ */ | 33 | /* __Definitions _________________________________________________________ */ |
| 36 | #define CTULIMIT_NAME "ctulimit" | 34 | #define CTULIMIT_NAME "ctulimit" |
| @@ -50,7 +48,7 @@ | @@ -50,7 +48,7 @@ | ||
| 50 | * During the computation the likelihood function is inspected to find the | 48 | * During the computation the likelihood function is inspected to find the |
| 51 | * best value for the upper limit. | 49 | * best value for the upper limit. |
| 52 | ***************************************************************************/ | 50 | ***************************************************************************/ |
| 53 | -class ctulimit : public ctool { | 51 | +class ctulimit : public ctlikelihood { |
| 54 | 52 | ||
| 55 | public: | 53 | public: |
| 56 | // Constructors and destructors | 54 | // Constructors and destructors |
| @@ -64,14 +62,12 @@ public: | @@ -64,14 +62,12 @@ public: | ||
| 64 | ctulimit& operator=(const ctulimit& app); | 62 | ctulimit& operator=(const ctulimit& app); |
| 65 | 63 | ||
| 66 | // Methods | 64 | // Methods |
| 67 | - void clear(void); | ||
| 68 | - void run(void); | ||
| 69 | - void save(void); | ||
| 70 | - const GObservations& obs(void) const; | ||
| 71 | - const GOptimizer* opt(void) const; | ||
| 72 | - const double& diff_ulimit(void) const; | ||
| 73 | - const double& flux_ulimit(void) const; | ||
| 74 | - const double& eflux_ulimit(void) const; | 65 | + void clear(void); |
| 66 | + void run(void); | ||
| 67 | + void save(void); | ||
| 68 | + const double& diff_ulimit(void) const; | ||
| 69 | + const double& flux_ulimit(void) const; | ||
| 70 | + const double& eflux_ulimit(void) const; | ||
| 75 | 71 | ||
| 76 | protected: | 72 | protected: |
| 77 | // Protected methods | 73 | // Protected methods |
| @@ -81,7 +77,6 @@ protected: | @@ -81,7 +77,6 @@ protected: | ||
| 81 | void get_parameters(void); | 77 | void get_parameters(void); |
| 82 | void get_model_parameter(void); | 78 | void get_model_parameter(void); |
| 83 | void ulimit_bisection(const double& parmin, const double& parmax); | 79 | void ulimit_bisection(const double& parmin, const double& parmax); |
| 84 | - double evaluate(const double& value); | ||
| 85 | 80 | ||
| 86 | // User parameters | 81 | // User parameters |
| 87 | std::string m_srcname; //!< Name of source which is moved around | 82 | std::string m_srcname; //!< Name of source which is moved around |
| @@ -97,7 +92,6 @@ protected: | @@ -97,7 +92,6 @@ protected: | ||
| 97 | GChatter m_chatter; //!< Chattiness | 92 | GChatter m_chatter; //!< Chattiness |
| 98 | 93 | ||
| 99 | // Protected members | 94 | // Protected members |
| 100 | - GObservations m_obs; //!< Observation container | ||
| 101 | double m_dlogL; //!< Likelihood difference for upper limit computation | 95 | double m_dlogL; //!< Likelihood difference for upper limit computation |
| 102 | GModelSky* m_skymodel; //!< Pointer to sky model | 96 | GModelSky* m_skymodel; //!< Pointer to sky model |
| 103 | GModelPar* m_model_par; //!< Pointer to model parameter | 97 | GModelPar* m_model_par; //!< Pointer to model parameter |
| @@ -105,35 +99,10 @@ protected: | @@ -105,35 +99,10 @@ protected: | ||
| 105 | double m_diff_ulimit; //!< Differential upper limit value | 99 | double m_diff_ulimit; //!< Differential upper limit value |
| 106 | double m_flux_ulimit; //!< Flux upper limit value | 100 | double m_flux_ulimit; //!< Flux upper limit value |
| 107 | double m_eflux_ulimit; //!< Energy flux upper limits | 101 | double m_eflux_ulimit; //!< Energy flux upper limits |
| 108 | - GOptimizerLM m_opt; //!< Optimizer | ||
| 109 | }; | 102 | }; |
| 110 | 103 | ||
| 111 | 104 | ||
| 112 | /***********************************************************************//** | 105 | /***********************************************************************//** |
| 113 | - * @brief Return observation container | ||
| 114 | - * | ||
| 115 | - * @return Reference to observation container. | ||
| 116 | - ***************************************************************************/ | ||
| 117 | -inline | ||
| 118 | -const GObservations& ctulimit::obs(void) const | ||
| 119 | -{ | ||
| 120 | - return m_obs; | ||
| 121 | -} | ||
| 122 | - | ||
| 123 | - | ||
| 124 | -/***********************************************************************//** | ||
| 125 | - * @brief Return optimizer | ||
| 126 | - * | ||
| 127 | - * @return Pointer to optimizer. | ||
| 128 | - ***************************************************************************/ | ||
| 129 | -inline | ||
| 130 | -const GOptimizer* ctulimit::opt(void) const | ||
| 131 | -{ | ||
| 132 | - return &m_opt; | ||
| 133 | -} | ||
| 134 | - | ||
| 135 | - | ||
| 136 | -/***********************************************************************//** | ||
| 137 | * @brief Return differential upper limit | 106 | * @brief Return differential upper limit |
| 138 | * | 107 | * |
| 139 | * @return Differential upper flux limit. | 108 | * @return Differential upper flux limit. |
src/support/Makefile.am
| @@ -20,7 +20,7 @@ | @@ -20,7 +20,7 @@ | ||
| 20 | ############################################################################# | 20 | ############################################################################# |
| 21 | 21 | ||
| 22 | # Define sources for this directory | 22 | # Define sources for this directory |
| 23 | -sources = ctool.cpp ctool.hpp | 23 | +sources = ctool.cpp ctool.hpp ctlikelihood.cpp ctlikelihood.hpp |
| 24 | 24 | ||
| 25 | # Build libtool library | 25 | # Build libtool library |
| 26 | noinst_LTLIBRARIES = libsupport.la | 26 | noinst_LTLIBRARIES = libsupport.la |
src/support/ctlikelihood.cpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctlikelihood - Base class for likelihood 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 ctlikelihood.cpp | ||
| 23 | + * @brief Likelihood 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 "GammaLib.hpp" | ||
| 32 | +#include "GCTALib.hpp" | ||
| 33 | +#include "ctlikelihood.hpp" | ||
| 34 | + | ||
| 35 | +//#include <iostream> | ||
| 36 | +//#include "ctlikelihood.hpp" | ||
| 37 | +//#include "GTools.hpp" | ||
| 38 | +//#include "GOptimizer.hpp" | ||
| 39 | + | ||
| 40 | +/* __ Method name definitions ____________________________________________ */ | ||
| 41 | +#define G_EVALUATE "ctlikelihood::evaluate(GModelPar&, double&)" | ||
| 42 | + | ||
| 43 | +/* __ Debug definitions __________________________________________________ */ | ||
| 44 | + | ||
| 45 | +/* __ Coding definitions _________________________________________________ */ | ||
| 46 | + | ||
| 47 | + | ||
| 48 | +/*========================================================================== | ||
| 49 | + = = | ||
| 50 | + = Constructors/destructors = | ||
| 51 | + = = | ||
| 52 | + ==========================================================================*/ | ||
| 53 | + | ||
| 54 | +/***********************************************************************//** | ||
| 55 | + * @brief Void constructor | ||
| 56 | + * | ||
| 57 | + * Constructs an empty likelihood tool. | ||
| 58 | + ***************************************************************************/ | ||
| 59 | +ctlikelihood::ctlikelihood(void) : ctool() | ||
| 60 | +{ | ||
| 61 | + // Initialise members | ||
| 62 | + init_members(); | ||
| 63 | + | ||
| 64 | + // Return | ||
| 65 | + return; | ||
| 66 | +} | ||
| 67 | + | ||
| 68 | + | ||
| 69 | +/***********************************************************************//** | ||
| 70 | + * @brief Name constructor | ||
| 71 | + * | ||
| 72 | + * @param[in] name Application name. | ||
| 73 | + * @param[in] version Application version. | ||
| 74 | + * | ||
| 75 | + * Constructs a likelihood tool from the @p name and @p version. See the | ||
| 76 | + * equivalent ctool constructor for details. | ||
| 77 | + ***************************************************************************/ | ||
| 78 | +ctlikelihood::ctlikelihood(const std::string& name, | ||
| 79 | + const std::string& version) : ctool(name, version) | ||
| 80 | +{ | ||
| 81 | + // Initialise members | ||
| 82 | + init_members(); | ||
| 83 | + | ||
| 84 | + // Return | ||
| 85 | + return; | ||
| 86 | +} | ||
| 87 | + | ||
| 88 | + | ||
| 89 | +/***********************************************************************//** | ||
| 90 | + * @brief Observations constructor | ||
| 91 | + * | ||
| 92 | + * @param[in] name Application name. | ||
| 93 | + * @param[in] version Application version. | ||
| 94 | + * param[in] obs Observation container. | ||
| 95 | + * | ||
| 96 | + * Constructs a likelihood tool from the @p name, @p version and an | ||
| 97 | + * observation container. | ||
| 98 | + ***************************************************************************/ | ||
| 99 | +ctlikelihood::ctlikelihood(const std::string& name, | ||
| 100 | + const std::string& version, | ||
| 101 | + const GObservations& obs) : ctool(name, version) | ||
| 102 | +{ | ||
| 103 | + // Initialise members | ||
| 104 | + init_members(); | ||
| 105 | + | ||
| 106 | + // Set observations | ||
| 107 | + m_obs = obs; | ||
| 108 | + | ||
| 109 | + // Return | ||
| 110 | + return; | ||
| 111 | +} | ||
| 112 | + | ||
| 113 | + | ||
| 114 | +/***********************************************************************//** | ||
| 115 | + * @brief Command line constructor | ||
| 116 | + * | ||
| 117 | + * @param[in] name Application name. | ||
| 118 | + * @param[in] version Application version. | ||
| 119 | + * @param[in] argc Number of arguments in command line. | ||
| 120 | + * @param[in] argv Array of command line arguments. | ||
| 121 | + * | ||
| 122 | + * Constructs a likelihood tool from the @p name, @p version and command | ||
| 123 | + * line arguments. See the equivalent ctool constructor for details. | ||
| 124 | + ***************************************************************************/ | ||
| 125 | +ctlikelihood::ctlikelihood(const std::string& name, | ||
| 126 | + const std::string& version, | ||
| 127 | + int argc, | ||
| 128 | + char *argv[]) : ctool(name, version, argc, argv) | ||
| 129 | +{ | ||
| 130 | + // Initialise members | ||
| 131 | + init_members(); | ||
| 132 | + | ||
| 133 | + // Return | ||
| 134 | + return; | ||
| 135 | +} | ||
| 136 | + | ||
| 137 | + | ||
| 138 | +/***********************************************************************//** | ||
| 139 | + * @brief Copy constructor | ||
| 140 | + * | ||
| 141 | + * @param[in] app Application. | ||
| 142 | + * | ||
| 143 | + * Constructs an instance of a likelihood tool by copying information from | ||
| 144 | + * another likelihood tool. | ||
| 145 | + ***************************************************************************/ | ||
| 146 | +ctlikelihood::ctlikelihood(const ctlikelihood& app) : ctool(app) | ||
| 147 | +{ | ||
| 148 | + // Initialise members | ||
| 149 | + init_members(); | ||
| 150 | + | ||
| 151 | + // Copy members | ||
| 152 | + copy_members(app); | ||
| 153 | + | ||
| 154 | + // Return | ||
| 155 | + return; | ||
| 156 | +} | ||
| 157 | + | ||
| 158 | + | ||
| 159 | +/***********************************************************************//** | ||
| 160 | + * @brief Destructor | ||
| 161 | + * | ||
| 162 | + * Destructs the ctlikelihood tool. | ||
| 163 | + ***************************************************************************/ | ||
| 164 | +ctlikelihood::~ctlikelihood(void) | ||
| 165 | +{ | ||
| 166 | + // Free members | ||
| 167 | + free_members(); | ||
| 168 | + | ||
| 169 | + // Return | ||
| 170 | + return; | ||
| 171 | +} | ||
| 172 | + | ||
| 173 | + | ||
| 174 | +/*========================================================================== | ||
| 175 | + = = | ||
| 176 | + = Operators = | ||
| 177 | + = = | ||
| 178 | + ==========================================================================*/ | ||
| 179 | + | ||
| 180 | +/***********************************************************************//** | ||
| 181 | + * @brief Assignment operator | ||
| 182 | + * | ||
| 183 | + * @param[in] app Application. | ||
| 184 | + * @return Application. | ||
| 185 | + * | ||
| 186 | + * Assigns a likelihood tool. | ||
| 187 | + ***************************************************************************/ | ||
| 188 | +ctlikelihood& ctlikelihood::operator=(const ctlikelihood& app) | ||
| 189 | +{ | ||
| 190 | + // Execute only if object is not identical | ||
| 191 | + if (this != &app) { | ||
| 192 | + | ||
| 193 | + // Copy base class members | ||
| 194 | + this->ctool::operator=(app); | ||
| 195 | + | ||
| 196 | + // Free members | ||
| 197 | + free_members(); | ||
| 198 | + | ||
| 199 | + // Initialise members | ||
| 200 | + init_members(); | ||
| 201 | + | ||
| 202 | + // Copy members | ||
| 203 | + copy_members(app); | ||
| 204 | + | ||
| 205 | + } // endif: object was not identical | ||
| 206 | + | ||
| 207 | + // Return this object | ||
| 208 | + return *this; | ||
| 209 | +} | ||
| 210 | + | ||
| 211 | + | ||
| 212 | +/*========================================================================== | ||
| 213 | + = = | ||
| 214 | + = Public methods = | ||
| 215 | + = = | ||
| 216 | + ==========================================================================*/ | ||
| 217 | + | ||
| 218 | + | ||
| 219 | +/*========================================================================== | ||
| 220 | + = = | ||
| 221 | + = Private methods = | ||
| 222 | + = = | ||
| 223 | + ==========================================================================*/ | ||
| 224 | + | ||
| 225 | +/***********************************************************************//** | ||
| 226 | + * @brief Initialise class members | ||
| 227 | + ***************************************************************************/ | ||
| 228 | +void ctlikelihood::init_members(void) | ||
| 229 | +{ | ||
| 230 | + // Initialise members | ||
| 231 | + m_obs.clear(); | ||
| 232 | + m_opt.clear(); | ||
| 233 | + | ||
| 234 | + // Return | ||
| 235 | + return; | ||
| 236 | +} | ||
| 237 | + | ||
| 238 | + | ||
| 239 | +/***********************************************************************//** | ||
| 240 | + * @brief Copy class members | ||
| 241 | + * | ||
| 242 | + * @param[in] app Application. | ||
| 243 | + ***************************************************************************/ | ||
| 244 | +void ctlikelihood::copy_members(const ctlikelihood& app) | ||
| 245 | +{ | ||
| 246 | + // Copy members | ||
| 247 | + m_obs = app.m_obs; | ||
| 248 | + m_opt = app.m_opt; | ||
| 249 | + | ||
| 250 | + // Return | ||
| 251 | + return; | ||
| 252 | +} | ||
| 253 | + | ||
| 254 | + | ||
| 255 | +/***********************************************************************//** | ||
| 256 | + * @brief Delete class members | ||
| 257 | + ***************************************************************************/ | ||
| 258 | +void ctlikelihood::free_members(void) | ||
| 259 | +{ | ||
| 260 | + // Return | ||
| 261 | + return; | ||
| 262 | +} | ||
| 263 | + | ||
| 264 | + | ||
| 265 | +/***********************************************************************//** | ||
| 266 | + * @brief Evaluates the log-likelihood function | ||
| 267 | + * | ||
| 268 | + * @param[in] par Model parameter | ||
| 269 | + * @param[in] value Model parameter factor value | ||
| 270 | + * @return Log-likelihood function | ||
| 271 | + * | ||
| 272 | + * Evaluates the log-likelihood function at a given @p value. | ||
| 273 | + ***************************************************************************/ | ||
| 274 | +double ctlikelihood::evaluate(GModelPar& par, const double& value) | ||
| 275 | +{ | ||
| 276 | + // Initialise log-likelihood value | ||
| 277 | + double logL = 0.0; | ||
| 278 | + | ||
| 279 | + // Throw an exception if the parameter is below the minimum boundary | ||
| 280 | + if (value < par.factor_min()) { | ||
| 281 | + std::string msg = "Value "+gammalib::str(value)+" of parameter \""+ | ||
| 282 | + par.name()+"\" is below its minimum boundary "+ | ||
| 283 | + gammalib::str(par.factor_min())+". To omit this " | ||
| 284 | + "error please lower the minimum parameter boundary."; | ||
| 285 | + throw GException::invalid_value(G_EVALUATE, msg); | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + // Throw an exception if the parameter is above the maximum boundary | ||
| 289 | + if (value > par.factor_max()) { | ||
| 290 | + std::string msg = "Value "+gammalib::str(value)+" of parameter \""+ | ||
| 291 | + par.name()+"\" is above its maximum boundary "+ | ||
| 292 | + gammalib::str(par.factor_max())+". To omit this " | ||
| 293 | + "error please raise the maximum parameter boundary."; | ||
| 294 | + throw GException::invalid_value(G_EVALUATE, msg); | ||
| 295 | + } | ||
| 296 | + | ||
| 297 | + // Change parameter factor | ||
| 298 | + par.factor_value(value); | ||
| 299 | + | ||
| 300 | + // Fix parameter | ||
| 301 | + par.fix(); | ||
| 302 | + | ||
| 303 | + // Re-optimize log-likelihood | ||
| 304 | + m_obs.optimize(m_opt); | ||
| 305 | + | ||
| 306 | + // Free parameter | ||
| 307 | + par.free(); | ||
| 308 | + | ||
| 309 | + // Retrieve log-likelihood | ||
| 310 | + logL = m_obs.logL(); | ||
| 311 | + | ||
| 312 | + // Return log-likelihood | ||
| 313 | + return logL; | ||
| 314 | +} |
src/support/ctlikelihood.hpp
0 → 100644
| 1 | +/*************************************************************************** | ||
| 2 | + * ctlikelihood - Base class for likelihood 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 ctlikelihood.hpp | ||
| 23 | + * @brief Likelihood tool base class interface definition | ||
| 24 | + * @author Juergen Knoedlseder | ||
| 25 | + */ | ||
| 26 | + | ||
| 27 | +#ifndef CTLIKELIHOOD_HPP | ||
| 28 | +#define CTLIKELIHOOD_HPP | ||
| 29 | + | ||
| 30 | +/* __ Includes ___________________________________________________________ */ | ||
| 31 | +#include "ctool.hpp" | ||
| 32 | + | ||
| 33 | +/* __Definitions _________________________________________________________ */ | ||
| 34 | + | ||
| 35 | + | ||
| 36 | +/***********************************************************************//** | ||
| 37 | + * @class ctlikelihood | ||
| 38 | + * | ||
| 39 | + * @brief Base class for likelihood tools | ||
| 40 | + ***************************************************************************/ | ||
| 41 | +class ctlikelihood : public ctool { | ||
| 42 | + | ||
| 43 | +public: | ||
| 44 | + // Constructors and destructors | ||
| 45 | + ctlikelihood(void); | ||
| 46 | + ctlikelihood(const std::string& name, const std::string& version); | ||
| 47 | + ctlikelihood(const std::string& name, const std::string& version, | ||
| 48 | + const GObservations& obs); | ||
| 49 | + ctlikelihood(const std::string& name, const std::string& version, | ||
| 50 | + int argc, char* argv[]); | ||
| 51 | + ctlikelihood(const ctlikelihood& app); | ||
| 52 | + virtual ~ctlikelihood(void); | ||
| 53 | + | ||
| 54 | + // Operators | ||
| 55 | + ctlikelihood& operator=(const ctlikelihood& app); | ||
| 56 | + | ||
| 57 | + // Pure virtual methods | ||
| 58 | + virtual void clear(void) = 0; | ||
| 59 | + virtual void run(void) = 0; | ||
| 60 | + virtual void save(void) = 0; | ||
| 61 | + | ||
| 62 | + // Methods | ||
| 63 | + const GObservations& obs(void) const; | ||
| 64 | + const GOptimizer* opt(void) const; | ||
| 65 | + | ||
| 66 | +protected: | ||
| 67 | + // Protected methods | ||
| 68 | + void init_members(void); | ||
| 69 | + void copy_members(const ctlikelihood& app); | ||
| 70 | + void free_members(void); | ||
| 71 | + double evaluate(GModelPar& par, const double& value); | ||
| 72 | + | ||
| 73 | + // Protected members | ||
| 74 | + GObservations m_obs; //!< Observation container | ||
| 75 | + GOptimizerLM m_opt; //!< Optimizer | ||
| 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& ctlikelihood::obs(void) const | ||
| 88 | +{ | ||
| 89 | + return m_obs; | ||
| 90 | +} | ||
| 91 | + | ||
| 92 | + | ||
| 93 | +/***********************************************************************//** | ||
| 94 | + * @brief Return optimizer | ||
| 95 | + * | ||
| 96 | + * @return Pointer to optimizer. | ||
| 97 | + * | ||
| 98 | + * Returns a pointer to the optimizer. | ||
| 99 | + ***************************************************************************/ | ||
| 100 | +inline | ||
| 101 | +const GOptimizer* ctlikelihood::opt(void) const | ||
| 102 | +{ | ||
| 103 | + return &m_opt; | ||
| 104 | +} | ||
| 105 | + | ||
| 106 | +#endif /* CTLIKELIHOOD_HPP */ |
src/support/ctool.cpp
| @@ -1655,8 +1655,8 @@ GEnergies ctool::insert_energy_boundaries(const GEnergies& energies, | @@ -1655,8 +1655,8 @@ GEnergies ctool::insert_energy_boundaries(const GEnergies& energies, | ||
| 1655 | /***********************************************************************//** | 1655 | /***********************************************************************//** |
| 1656 | * @brief Determine the counts cube layer usage. | 1656 | * @brief Determine the counts cube layer usage. |
| 1657 | * | 1657 | * |
| 1658 | - * @param[in] ebounds_cube Energy boundaries of the counts cube. | ||
| 1659 | - * @param[in] ebounds_list Energy boundaries of the event list. | 1658 | + * @param[in] cube_ebounds Energy boundaries of the counts cube. |
| 1659 | + * @param[in] list_ebounds Energy boundaries of the event list. | ||
| 1660 | * @return Vector of usage flags. | 1660 | * @return Vector of usage flags. |
| 1661 | * | 1661 | * |
| 1662 | * Determines a vector of counts cube layer usage flags that signal whether | 1662 | * Determines a vector of counts cube layer usage flags that signal whether |
src/support/ctool.hpp
| @@ -37,7 +37,13 @@ | @@ -37,7 +37,13 @@ | ||
| 37 | /***********************************************************************//** | 37 | /***********************************************************************//** |
| 38 | * @class ctool | 38 | * @class ctool |
| 39 | * | 39 | * |
| 40 | - * @brief ctool base class | 40 | + * @brief Base class for ctools |
| 41 | + * | ||
| 42 | + * This class is the generic base class for all ctools. It enforces | ||
| 43 | + * implementation of the clear(), run() and save() methods by all ctools, | ||
| 44 | + * and it implements the execute() method. | ||
| 45 | + * | ||
| 46 | + * The class also provides a number of helper methods for ctools. | ||
| 41 | ***************************************************************************/ | 47 | ***************************************************************************/ |
| 42 | class ctool : public GApplication { | 48 | class ctool : public GApplication { |
| 43 | public: | 49 | public: |
test/test_ctulimit.py
| @@ -103,9 +103,9 @@ class Test(test): | @@ -103,9 +103,9 @@ class Test(test): | ||
| 103 | ulimit = ctools.ctulimit() | 103 | ulimit = ctools.ctulimit() |
| 104 | 104 | ||
| 105 | # Check that empty ctulimit tool holds zero upper limits | 105 | # Check that empty ctulimit tool holds zero upper limits |
| 106 | - self.test_value(ulimit.diff_ulimit(), 0.0, 1.0e-23, | 106 | + self.test_value(ulimit.diff_ulimit(), 0.0, 1.0e-21, |
| 107 | 'Check differential upper limit') | 107 | 'Check differential upper limit') |
| 108 | - self.test_value(ulimit.flux_ulimit(), 0.0, 1.0e-17, | 108 | + self.test_value(ulimit.flux_ulimit(), 0.0, 1.0e-16, |
| 109 | 'Check upper limit on photon flux') | 109 | 'Check upper limit on photon flux') |
| 110 | self.test_value(ulimit.eflux_ulimit(), 0.0, 1.0e-16, | 110 | self.test_value(ulimit.eflux_ulimit(), 0.0, 1.0e-16, |
| 111 | 'Check upper limit on energy flux') | 111 | 'Check upper limit on energy flux') |
| @@ -132,9 +132,9 @@ class Test(test): | @@ -132,9 +132,9 @@ class Test(test): | ||
| 132 | ulimit.save() | 132 | ulimit.save() |
| 133 | 133 | ||
| 134 | # Check results | 134 | # Check results |
| 135 | - self.test_value(ulimit.diff_ulimit(), 8.86803e-18, 1.0e-23, | 135 | + self.test_value(ulimit.diff_ulimit(), 8.86803e-18, 1.0e-21, |
| 136 | 'Check differential upper limit') | 136 | 'Check differential upper limit') |
| 137 | - self.test_value(ulimit.flux_ulimit(), 6.10509e-12, 1.0e-17, | 137 | + self.test_value(ulimit.flux_ulimit(), 6.10509e-12, 1.0e-16, |
| 138 | 'Check upper limit on photon flux') | 138 | 'Check upper limit on photon flux') |
| 139 | self.test_value(ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, | 139 | self.test_value(ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, |
| 140 | 'Check upper limit on energy flux') | 140 | 'Check upper limit on energy flux') |
| @@ -150,10 +150,10 @@ class Test(test): | @@ -150,10 +150,10 @@ class Test(test): | ||
| 150 | cpy_ulimit = ulimit.copy() | 150 | cpy_ulimit = ulimit.copy() |
| 151 | 151 | ||
| 152 | # Check results of copy | 152 | # Check results of copy |
| 153 | - self.test_value(cpy_ulimit.diff_ulimit(), 8.86803e-18, 1.0e-23, | 153 | + self.test_value(cpy_ulimit.diff_ulimit(), 8.86803e-18, 1.0e-21, |
| 154 | 'Check differential upper limit') | 154 | 'Check differential upper limit') |
| 155 | - self.test_value(cpy_ulimit.flux_ulimit(), 6.10509e-12, 1.0e-17, | ||
| 156 | - 'ulimit upper limit on photon flux') | 155 | + self.test_value(cpy_ulimit.flux_ulimit(), 6.10509e-12, 1.0e-16, |
| 156 | + 'Check upper limit on photon flux') | ||
| 157 | self.test_value(cpy_ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, | 157 | self.test_value(cpy_ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, |
| 158 | 'Check upper limit on energy flux') | 158 | 'Check upper limit on energy flux') |
| 159 | 159 | ||
| @@ -165,10 +165,10 @@ class Test(test): | @@ -165,10 +165,10 @@ class Test(test): | ||
| 165 | cpy_ulimit.execute() | 165 | cpy_ulimit.execute() |
| 166 | 166 | ||
| 167 | # Check results | 167 | # Check results |
| 168 | - self.test_value(cpy_ulimit.diff_ulimit(), 8.86803e-18, 1.0e-23, | 168 | + self.test_value(cpy_ulimit.diff_ulimit(), 8.86803e-18, 1.0e-21, |
| 169 | 'Check differential upper limit') | 169 | 'Check differential upper limit') |
| 170 | - self.test_value(cpy_ulimit.flux_ulimit(), 6.10509e-12, 1.0e-17, | ||
| 171 | - 'ulimit upper limit on photon flux') | 170 | + self.test_value(cpy_ulimit.flux_ulimit(), 6.10509e-12, 1.0e-16, |
| 171 | + 'Check upper limit on photon flux') | ||
| 172 | self.test_value(cpy_ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, | 172 | self.test_value(cpy_ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, |
| 173 | 'Check upper limit on energy flux') | 173 | 'Check upper limit on energy flux') |
| 174 | 174 | ||
| @@ -179,9 +179,9 @@ class Test(test): | @@ -179,9 +179,9 @@ class Test(test): | ||
| 179 | cpy_ulimit.clear() | 179 | cpy_ulimit.clear() |
| 180 | 180 | ||
| 181 | # Check that empty ctulimit tool holds zero upper limits | 181 | # Check that empty ctulimit tool holds zero upper limits |
| 182 | - self.test_value(cpy_ulimit.diff_ulimit(), 0.0, 1.0e-23, | 182 | + self.test_value(cpy_ulimit.diff_ulimit(), 0.0, 1.0e-21, |
| 183 | 'Check differential upper limit') | 183 | 'Check differential upper limit') |
| 184 | - self.test_value(cpy_ulimit.flux_ulimit(), 0.0, 1.0e-17, | 184 | + self.test_value(cpy_ulimit.flux_ulimit(), 0.0, 1.0e-16, |
| 185 | 'Check upper limit on photon flux') | 185 | 'Check upper limit on photon flux') |
| 186 | self.test_value(cpy_ulimit.eflux_ulimit(), 0.0, 1.0e-16, | 186 | self.test_value(cpy_ulimit.eflux_ulimit(), 0.0, 1.0e-16, |
| 187 | 'Check upper limit on energy flux') | 187 | 'Check upper limit on energy flux') |
| @@ -190,11 +190,7 @@ class Test(test): | @@ -190,11 +190,7 @@ class Test(test): | ||
| 190 | # time. This should avoid the necessity to recompute the maximum | 190 | # time. This should avoid the necessity to recompute the maximum |
| 191 | # likelihood | 191 | # likelihood |
| 192 | ulimit = ctools.ctulimit(obs) | 192 | ulimit = ctools.ctulimit(obs) |
| 193 | - #ulimit['inobs'] = self._events | ||
| 194 | - #ulimit['inmodel'] = self._model | ||
| 195 | ulimit['srcname'] = 'Crab' | 193 | ulimit['srcname'] = 'Crab' |
| 196 | - #ulimit['caldb'] = self._caldb | ||
| 197 | - #ulimit['irf'] = self._irf | ||
| 198 | ulimit['logfile'] = 'ctulimit_py3.log' | 194 | ulimit['logfile'] = 'ctulimit_py3.log' |
| 199 | ulimit['chatter'] = 4 | 195 | ulimit['chatter'] = 4 |
| 200 | 196 | ||
| @@ -203,10 +199,10 @@ class Test(test): | @@ -203,10 +199,10 @@ class Test(test): | ||
| 203 | ulimit.execute() | 199 | ulimit.execute() |
| 204 | 200 | ||
| 205 | # Check results | 201 | # Check results |
| 206 | - self.test_value(ulimit.diff_ulimit(), 8.86803e-18, 1.0e-23, | 202 | + self.test_value(ulimit.diff_ulimit(), 8.86803e-18, 1.0e-21, |
| 207 | 'Check differential upper limit') | 203 | 'Check differential upper limit') |
| 208 | - self.test_value(ulimit.flux_ulimit(), 6.10509e-12, 1.0e-17, | ||
| 209 | - 'ulimit upper limit on photon flux') | 204 | + self.test_value(ulimit.flux_ulimit(), 6.10509e-12, 1.0e-16, |
| 205 | + 'Check upper limit on photon flux') | ||
| 210 | self.test_value(ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, | 206 | self.test_value(ulimit.eflux_ulimit(), 2.75669e-11, 1.0e-16, |
| 211 | 'Check upper limit on energy flux') | 207 | 'Check upper limit on energy flux') |
| 212 | 208 |