Commit c600f360f4296bb57cdaf70534a96f2cce31173c

Authored by Jürgen Knödlseder
1 parent fc6ccd39

ctlike now derives from ctool base class.

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