Commit c600f360f4296bb57cdaf70534a96f2cce31173c
1 parent
fc6ccd39
ctlike now derives from ctool base class.
Showing
4 changed files
with
32 additions
and
77 deletions
pyext/ctlike.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctlike - CTA maximum likelihood tool * | |
| 2 | + * ctlike - Maximum likelihood fitting tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Jurgen Knodlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,13 +20,12 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctlike.i |
| 23 | - * @brief CTA maximum likelihood tool Python interface definition | |
| 24 | - * @author J. Knodlseder | |
| 23 | + * @brief Maximum likelihood fitting tool definition | |
| 24 | + * @author Juergen Knoedlseder | |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "ctlike.hpp" |
| 29 | -#include "GTools.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 32 | 31 | |
| ... | ... | @@ -35,8 +34,7 @@ |
| 35 | 34 | * |
| 36 | 35 | * @brief CTA maximum likelihood tool Python interface |
| 37 | 36 | ***************************************************************************/ |
| 38 | -class ctlike : public GApplication { | |
| 39 | - | |
| 37 | +class ctlike : public ctool { | |
| 40 | 38 | public: |
| 41 | 39 | // Constructors and destructors |
| 42 | 40 | ctlike(void); |
| ... | ... | @@ -56,7 +54,7 @@ public: |
| 56 | 54 | |
| 57 | 55 | |
| 58 | 56 | /***********************************************************************//** |
| 59 | - * @brief CTA maximum likelihood tool Python extension | |
| 57 | + * @brief Maximum likelihood fitting tool Python extension | |
| 60 | 58 | ***************************************************************************/ |
| 61 | 59 | %extend ctlike { |
| 62 | 60 | ctlike copy() { | ... | ... |
src/ctlike/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | |
| 3 | +# Set include directories | |
| 4 | +INCLUDES = -I$(top_srcdir)/src/support | |
| 5 | + | |
| 3 | 6 | # Program name |
| 4 | 7 | bin_PROGRAMS = ctlike |
| 5 | 8 | |
| ... | ... | @@ -14,7 +17,7 @@ libctlike_la_SOURCES = $(sources) |
| 14 | 17 | ctlike_SOURCES = main.cpp |
| 15 | 18 | ctlike_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ |
| 16 | 19 | ctlike_CPPFLAGS = @CPPFLAGS@ |
| 17 | -ctlike_LDADD = libctlike.la | |
| 20 | +ctlike_LDADD = libctlike.la $(top_srcdir)/src/support/libsupport.la | |
| 18 | 21 | |
| 19 | 22 | # Parameter files |
| 20 | 23 | pfilesdir = $(prefix)/syspfiles | ... | ... |
src/ctlike/ctlike.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctlike - CTA maximum likelihood tool * | |
| 2 | + * ctlike - Maximum likelihood fitting tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctlike.cpp |
| 23 | - * @brief CTA maximum likelihood tool implementation | |
| 23 | + * @brief Maximum likelihood fitting tool implementation | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -49,14 +49,11 @@ |
| 49 | 49 | /***********************************************************************//** |
| 50 | 50 | * @brief Void constructor |
| 51 | 51 | ***************************************************************************/ |
| 52 | -ctlike::ctlike(void) : GApplication(CTLIKE_NAME, CTLIKE_VERSION) | |
| 52 | +ctlike::ctlike(void) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | |
| 53 | 53 | { |
| 54 | 54 | // Initialise members |
| 55 | 55 | init_members(); |
| 56 | 56 | |
| 57 | - // Write header into logger | |
| 58 | - log_header(); | |
| 59 | - | |
| 60 | 57 | // Return |
| 61 | 58 | return; |
| 62 | 59 | } |
| ... | ... | @@ -70,8 +67,7 @@ ctlike::ctlike(void) : GApplication(CTLIKE_NAME, CTLIKE_VERSION) |
| 70 | 67 | * This method creates an instance of the class by copying an existing |
| 71 | 68 | * observations container. |
| 72 | 69 | ***************************************************************************/ |
| 73 | -ctlike::ctlike(const GObservations& obs) : | |
| 74 | - GApplication(CTLIKE_NAME, CTLIKE_VERSION) | |
| 70 | +ctlike::ctlike(const GObservations& obs) : ctool(CTLIKE_NAME, CTLIKE_VERSION) | |
| 75 | 71 | { |
| 76 | 72 | // Initialise members |
| 77 | 73 | init_members(); |
| ... | ... | @@ -79,9 +75,6 @@ ctlike::ctlike(const GObservations& obs) : |
| 79 | 75 | // Set observations |
| 80 | 76 | m_obs = obs; |
| 81 | 77 | |
| 82 | - // Write header into logger | |
| 83 | - log_header(); | |
| 84 | - | |
| 85 | 78 | // Return |
| 86 | 79 | return; |
| 87 | 80 | } |
| ... | ... | @@ -94,14 +87,11 @@ ctlike::ctlike(const GObservations& obs) : |
| 94 | 87 | * @param[in] argv Array of command line arguments. |
| 95 | 88 | ***************************************************************************/ |
| 96 | 89 | ctlike::ctlike(int argc, char *argv[]) : |
| 97 | - GApplication(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) | |
| 90 | + ctool(CTLIKE_NAME, CTLIKE_VERSION, argc, argv) | |
| 98 | 91 | { |
| 99 | 92 | // Initialise members |
| 100 | 93 | init_members(); |
| 101 | 94 | |
| 102 | - // Write header into logger | |
| 103 | - log_header(); | |
| 104 | - | |
| 105 | 95 | // Return |
| 106 | 96 | return; |
| 107 | 97 | } |
| ... | ... | @@ -112,7 +102,7 @@ ctlike::ctlike(int argc, char *argv[]) : |
| 112 | 102 | * |
| 113 | 103 | * @param[in] app Application. |
| 114 | 104 | ***************************************************************************/ |
| 115 | -ctlike::ctlike(const ctlike& app) : GApplication(app) | |
| 105 | +ctlike::ctlike(const ctlike& app) : ctool(app) | |
| 116 | 106 | { |
| 117 | 107 | // Initialise members |
| 118 | 108 | init_members(); |
| ... | ... | @@ -149,13 +139,13 @@ ctlike::~ctlike(void) |
| 149 | 139 | * |
| 150 | 140 | * @param[in] app Application. |
| 151 | 141 | ***************************************************************************/ |
| 152 | -ctlike& ctlike::operator= (const ctlike& app) | |
| 142 | +ctlike& ctlike::operator=(const ctlike& app) | |
| 153 | 143 | { |
| 154 | 144 | // Execute only if object is not identical |
| 155 | 145 | if (this != &app) { |
| 156 | 146 | |
| 157 | 147 | // Copy base class members |
| 158 | - this->GApplication::operator=(app); | |
| 148 | + this->ctool::operator=(app); | |
| 159 | 149 | |
| 160 | 150 | // Free members |
| 161 | 151 | free_members(); |
| ... | ... | @@ -186,10 +176,12 @@ void ctlike::clear(void) |
| 186 | 176 | { |
| 187 | 177 | // Free members |
| 188 | 178 | free_members(); |
| 179 | + this->ctool::free_members(); | |
| 189 | 180 | this->GApplication::free_members(); |
| 190 | 181 | |
| 191 | 182 | // Initialise members |
| 192 | 183 | this->GApplication::init_members(); |
| 184 | + this->ctool::init_members(); | |
| 193 | 185 | init_members(); |
| 194 | 186 | |
| 195 | 187 | // Return |
| ... | ... | @@ -404,27 +396,13 @@ void ctlike::get_parameters(void) |
| 404 | 396 | obs.load(filename); |
| 405 | 397 | |
| 406 | 398 | // Get other task parameters |
| 407 | - m_stat = gammalib::toupper((*this)["stat"].string()); | |
| 408 | - m_caldb = (*this)["caldb"].string(); | |
| 409 | - m_irf = (*this)["irf"].string(); | |
| 399 | + std::string statistics = gammalib::toupper((*this)["stat"].string()); | |
| 410 | 400 | |
| 411 | 401 | // Set statistics |
| 412 | - obs.statistics(m_stat); | |
| 413 | - | |
| 414 | - // Set calibration database. If specified parameter is a | |
| 415 | - // directory then use this as the pathname to the calibration | |
| 416 | - // database. Otherwise interpret this as the instrument name, | |
| 417 | - // the mission being "cta" | |
| 418 | - GCaldb caldb; | |
| 419 | - if (gammalib::dir_exists(m_caldb)) { | |
| 420 | - caldb.rootdir(m_caldb); | |
| 421 | - } | |
| 422 | - else { | |
| 423 | - caldb.open("cta", m_caldb); | |
| 424 | - } | |
| 402 | + obs.statistics(statistics); | |
| 425 | 403 | |
| 426 | - // Set reponse | |
| 427 | - obs.response(m_irf, caldb); | |
| 404 | + // Set response | |
| 405 | + set_obs_response(&obs); | |
| 428 | 406 | |
| 429 | 407 | // Append observation to container |
| 430 | 408 | m_obs.append(obs); |
| ... | ... | @@ -440,7 +418,6 @@ void ctlike::get_parameters(void) |
| 440 | 418 | // Check if all observations have response information. If |
| 441 | 419 | // not, get the calibration database parameters and set |
| 442 | 420 | // the response properly |
| 443 | - bool asked_for_response = false; | |
| 444 | 421 | for (int i = 0; i < m_obs.size(); ++i) { |
| 445 | 422 | |
| 446 | 423 | // Get CTA observation |
| ... | ... | @@ -452,25 +429,9 @@ void ctlike::get_parameters(void) |
| 452 | 429 | // If response is not valid then set response from |
| 453 | 430 | // task parameters |
| 454 | 431 | if (!obs->has_response()) { |
| 432 | + set_obs_response(obs); | |
| 433 | + } | |
| 455 | 434 | |
| 456 | - // Get calibration parameters | |
| 457 | - if (!asked_for_response) { | |
| 458 | - m_caldb = (*this)["caldb"].string(); | |
| 459 | - m_irf = (*this)["irf"].string(); | |
| 460 | - asked_for_response = true; | |
| 461 | - } | |
| 462 | - | |
| 463 | - // Set response | |
| 464 | - GCaldb caldb; | |
| 465 | - if (gammalib::dir_exists(m_caldb)) { | |
| 466 | - caldb.rootdir(m_caldb); | |
| 467 | - } | |
| 468 | - else { | |
| 469 | - caldb.open("cta", m_caldb); | |
| 470 | - } | |
| 471 | - obs->response(m_irf, caldb); | |
| 472 | - | |
| 473 | - } // endif: there was no response | |
| 474 | 435 | } // endif: observation was a CTA observation |
| 475 | 436 | |
| 476 | 437 | } // endfor: looped over observations |
| ... | ... | @@ -620,9 +581,6 @@ double ctlike::reoptimize_lm(void) |
| 620 | 581 | void ctlike::init_members(void) |
| 621 | 582 | { |
| 622 | 583 | // Initialise members |
| 623 | - m_stat.clear(); | |
| 624 | - m_caldb.clear(); | |
| 625 | - m_irf.clear(); | |
| 626 | 584 | m_outmdl.clear(); |
| 627 | 585 | m_obs.clear(); |
| 628 | 586 | m_refit = false; |
| ... | ... | @@ -650,11 +608,8 @@ void ctlike::init_members(void) |
| 650 | 608 | void ctlike::copy_members(const ctlike& app) |
| 651 | 609 | { |
| 652 | 610 | // Copy attributes |
| 653 | - m_stat = app.m_stat; | |
| 654 | 611 | m_refit = app.m_refit; |
| 655 | 612 | m_tscalc = app.m_tscalc; |
| 656 | - m_caldb = app.m_caldb; | |
| 657 | - m_irf = app.m_irf; | |
| 658 | 613 | m_outmdl = app.m_outmdl; |
| 659 | 614 | m_obs = app.m_obs; |
| 660 | 615 | m_max_iter = app.m_max_iter; | ... | ... |
src/ctlike/ctlike.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctlike - CTA maximum likelihood tool * | |
| 2 | + * ctlike - Maximum likelihood fitting tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctlike.hpp |
| 23 | - * @brief CTA maximum likelihood tool interface definition | |
| 23 | + * @brief Maximum likelihood fitting tool definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -31,6 +31,7 @@ |
| 31 | 31 | #include <string> |
| 32 | 32 | #include "GammaLib.hpp" |
| 33 | 33 | #include "GCTALib.hpp" |
| 34 | +#include "ctool.hpp" | |
| 34 | 35 | |
| 35 | 36 | /* __Definitions _________________________________________________________ */ |
| 36 | 37 | #define CTLIKE_NAME "ctlike" |
| ... | ... | @@ -40,9 +41,10 @@ |
| 40 | 41 | /***********************************************************************//** |
| 41 | 42 | * @class ctlike |
| 42 | 43 | * |
| 43 | - * @brief CTA maximum likelihood tool interface defintion. | |
| 44 | + * @brief Maximum likelihood fitting tool | |
| 44 | 45 | ***************************************************************************/ |
| 45 | -class ctlike : public GApplication { | |
| 46 | +class ctlike : public ctool { | |
| 47 | + | |
| 46 | 48 | public: |
| 47 | 49 | // Constructors and destructors |
| 48 | 50 | ctlike(void); |
| ... | ... | @@ -52,7 +54,7 @@ public: |
| 52 | 54 | virtual ~ctlike(void); |
| 53 | 55 | |
| 54 | 56 | // Operators |
| 55 | - ctlike& operator= (const ctlike& app); | |
| 57 | + ctlike& operator=(const ctlike& app); | |
| 56 | 58 | |
| 57 | 59 | // Methods |
| 58 | 60 | void clear(void); |
| ... | ... | @@ -72,11 +74,8 @@ protected: |
| 72 | 74 | double reoptimize_lm(void); |
| 73 | 75 | |
| 74 | 76 | // User parameters |
| 75 | - std::string m_stat; //!< Optimisation statistics (poisson/gaussian) | |
| 76 | 77 | bool m_refit; //!< Refitting |
| 77 | 78 | bool m_tscalc; //!< TS computation |
| 78 | - std::string m_caldb; //!< Calibration database | |
| 79 | - std::string m_irf; //!< Instrument response functions | |
| 80 | 79 | std::string m_outmdl; //!< Source model output XML file |
| 81 | 80 | bool m_apply_edisp; //!< Apply energy dispersion? |
| 82 | 81 | ... | ... |