Commit 8f4e5b3e112eb2cdaed1010e47e89be2ce07092e

Authored by Jürgen Knödlseder
1 parent 6ec18d45

ctmodel now derives from ctool. Add ctool::set_response() method that sets the r…

…esponse for all CTA observation in the container that have not yet a response using the task parameters.
pyext/ctmodel.i
1 1 /***************************************************************************
2   - * ctmodel - CTA model cube generation tool *
  2 + * ctmodel - Model cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2012-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,23 +20,21 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctmodel.i
23   - * @brief CTA model cube tool definition
  23 + * @brief Model cube generation tool definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26 %{
27 27 /* Put headers and other declarations here that are needed for compilation */
28 28 #include "ctmodel.hpp"
29   -#include "GTools.hpp"
30 29 %}
31 30  
32 31  
33 32 /***********************************************************************//**
34 33 * @class ctmodel
35 34 *
36   - * @brief CTA counts model tool interface defintion
  35 + * @brief Model cube generation tool
37 36 ***************************************************************************/
38   -class ctmodel : public GApplication {
39   -
  37 +class ctmodel : public ctool {
40 38 public:
41 39 // Constructors and destructors
42 40 ctmodel(void);
... ... @@ -56,7 +54,7 @@ public:
56 54  
57 55  
58 56 /***********************************************************************//**
59   - * @brief CTA counts model tool Python extension
  57 + * @brief Model cube generation tool Python extension
60 58 ***************************************************************************/
61 59 %extend ctmodel {
62 60 ctmodel copy() {
... ...
src/ctexpcube/ctexpcube.cpp
... ... @@ -394,8 +394,9 @@ void ctexpcube::get_parameters(void)
394 394 get_obs();
395 395 }
396 396  
397   - // Make sure that response is set
398   - set_response();
  397 + // For all observations that have no response, set the response
  398 + // from the task parameters
  399 + set_response(m_obs);
399 400  
400 401 // Read energy dispersion flag
401 402 m_apply_edisp = (*this)["edisp"].boolean();
... ... @@ -480,37 +481,6 @@ void ctexpcube::get_obs(void)
480 481  
481 482  
482 483 /***********************************************************************//**
483   - * @brief Set observation response
484   - *
485   - * Set response for all observations that so have no response.
486   - ***************************************************************************/
487   -void ctexpcube::set_response(void)
488   -{
489   - // Loop over all observations
490   - for (int i = 0; i < m_obs.size(); ++i) {
491   -
492   - // Is this observation a CTA observation?
493   - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
494   -
495   - // Yes ...
496   - if (obs != NULL) {
497   -
498   - // If the observation has no response, then set it from
499   - // the task parameters
500   - if (!obs->has_response()) {
501   - set_obs_response(obs);
502   - }
503   -
504   - } // endif: observation was a CTA observation
505   -
506   - } // endfor: looped over all observations
507   -
508   - // Return
509   - return;
510   -}
511   -
512   -
513   -/***********************************************************************//**
514 484 * @brief Set exposure cube definition from counts map
515 485 *
516 486 * @exception GException::invalid_value
... ...
src/ctexpcube/ctexpcube.hpp
... ... @@ -69,7 +69,6 @@ protected:
69 69 void free_members(void);
70 70 void get_parameters(void);
71 71 void get_obs(void);
72   - void set_response(void);
73 72 void set_from_cntmap(const std::string& filename);
74 73  
75 74 // User parameters
... ...
src/ctlike/ctlike.cpp
... ... @@ -415,26 +415,9 @@ void ctlike::get_parameters(void)
415 415 // Load observations from XML file
416 416 m_obs.load(filename);
417 417  
418   - // Check if all observations have response information. If
419   - // not, get the calibration database parameters and set
420   - // the response properly
421   - for (int i = 0; i < m_obs.size(); ++i) {
422   -
423   - // Get CTA observation
424   - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
425   -
426   - // Continue only if observation is a CTA observation
427   - if (obs != NULL) {
428   -
429   - // If response is not valid then set response from
430   - // task parameters
431   - if (!obs->has_response()) {
432   - set_obs_response(obs);
433   - }
434   -
435   - } // endif: observation was a CTA observation
436   -
437   - } // endfor: looped over observations
  418 + // For all observations that have no response, set the response
  419 + // from the task parameters
  420 + set_response(m_obs);
438 421  
439 422 } // endcatch: file was an XML file
440 423  
... ...
src/ctmodel/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 = ctmodel
5 8  
... ... @@ -14,7 +17,7 @@ libctmodel_la_SOURCES = $(sources)
14 17 ctmodel_SOURCES = main.cpp
15 18 ctmodel_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@
16 19 ctmodel_CPPFLAGS = @CPPFLAGS@
17   -ctmodel_LDADD = libctmodel.la
  20 +ctmodel_LDADD = libctmodel.la $(top_srcdir)/src/support/libsupport.la
18 21  
19 22 # Parameter files
20 23 pfilesdir = $(prefix)/syspfiles
... ...
src/ctmodel/ctmodel.cpp
1 1 /***************************************************************************
2   - * ctmodel - CTA model cube generation tool *
  2 + * ctmodel - Model cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2012-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctmodel.cpp
23   - * @brief CTA model cube tool implementation
  23 + * @brief Model cube generation tool implementation
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ... @@ -33,7 +33,6 @@
33 33 #include "GTools.hpp"
34 34  
35 35 /* __ Method name definitions ____________________________________________ */
36   -#define G_GET_EBOUNDS "ctmodel::get_ebounds()"
37 36  
38 37 /* __ Debug definitions __________________________________________________ */
39 38  
... ... @@ -49,14 +48,11 @@
49 48 /***********************************************************************//**
50 49 * @brief Void constructor
51 50 ***************************************************************************/
52   -ctmodel::ctmodel(void) : GApplication(CTMODEL_NAME, CTMODEL_VERSION)
  51 +ctmodel::ctmodel(void) : ctool(CTMODEL_NAME, CTMODEL_VERSION)
53 52 {
54 53 // Initialise members
55 54 init_members();
56 55  
57   - // Write header into logger
58   - log_header();
59   -
60 56 // Return
61 57 return;
62 58 }
... ... @@ -70,8 +66,7 @@ ctmodel::ctmodel(void) : GApplication(CTMODEL_NAME, CTMODEL_VERSION)
70 66 * This method creates an instance of the class by copying an existing
71 67 * observations container.
72 68 ***************************************************************************/
73   -ctmodel::ctmodel(const GObservations& obs) :
74   - GApplication(CTMODEL_NAME, CTMODEL_VERSION)
  69 +ctmodel::ctmodel(const GObservations& obs) : ctool(CTMODEL_NAME, CTMODEL_VERSION)
75 70 {
76 71 // Initialise members
77 72 init_members();
... ... @@ -79,9 +74,6 @@ ctmodel::ctmodel(const GObservations&amp; obs) :
79 74 // Set observations
80 75 m_obs = obs;
81 76  
82   - // Write header into logger
83   - log_header();
84   -
85 77 // Return
86 78 return;
87 79 }
... ... @@ -95,14 +87,11 @@ ctmodel::ctmodel(const GObservations&amp; obs) :
95 87 * @param[in] argv Array of command line arguments.
96 88 ***************************************************************************/
97 89 ctmodel::ctmodel(int argc, char *argv[]) :
98   - GApplication(CTMODEL_NAME, CTMODEL_VERSION, argc, argv)
  90 + ctool(CTMODEL_NAME, CTMODEL_VERSION, argc, argv)
99 91 {
100 92 // Initialise members
101 93 init_members();
102 94  
103   - // Write header into logger
104   - log_header();
105   -
106 95 // Return
107 96 return;
108 97 }
... ... @@ -113,7 +102,7 @@ ctmodel::ctmodel(int argc, char *argv[]) :
113 102 *
114 103 * @param[in] app Application.
115 104 ***************************************************************************/
116   -ctmodel::ctmodel(const ctmodel& app) : GApplication(app)
  105 +ctmodel::ctmodel(const ctmodel& app) : ctool(app)
117 106 {
118 107 // Initialise members
119 108 init_members();
... ... @@ -151,13 +140,13 @@ ctmodel::~ctmodel(void)
151 140 * @param[in] app ctmodel application.
152 141 * @return Returns ctmodel application.
153 142 ***************************************************************************/
154   -ctmodel& ctmodel::operator= (const ctmodel& app)
  143 +ctmodel& ctmodel::operator=(const ctmodel& app)
155 144 {
156 145 // Execute only if object is not identical
157 146 if (this != &app) {
158 147  
159 148 // Copy base class members
160   - this->GApplication::operator=(app);
  149 + this->ctool::operator=(app);
161 150  
162 151 // Free members
163 152 free_members();
... ... @@ -188,10 +177,12 @@ void ctmodel::clear(void)
188 177 {
189 178 // Free members
190 179 free_members();
  180 + this->ctool::free_members();
191 181 this->GApplication::free_members();
192 182  
193 183 // Initialise members
194 184 this->GApplication::init_members();
  185 + this->ctool::init_members();
195 186 init_members();
196 187  
197 188 // Return
... ... @@ -454,11 +445,6 @@ void ctmodel::copy_members(const ctmodel&amp; app)
454 445 ***************************************************************************/
455 446 void ctmodel::free_members(void)
456 447 {
457   - // Write separator into logger
458   - if (logTerse()) {
459   - log << std::endl;
460   - }
461   -
462 448 // Return
463 449 return;
464 450 }
... ... @@ -654,38 +640,9 @@ void ctmodel::setup_obs(void)
654 640 m_obs.models(GModels(m_srcmdl));
655 641 }
656 642  
657   - // Setup response for all observations
658   - for (int i = 0; i < m_obs.size(); ++i) {
659   -
660   - // Is this observation a CTA observation?
661   - GCTAObservation* obs = dynamic_cast<GCTAObservation*>(m_obs[i]);
662   -
663   - // Yes ...
664   - if (obs != NULL) {
665   -
666   - // Set response if we don't have one
667   - if (!obs->has_response()) {
668   -
669   - // Set calibration database. If specified parameter is a
670   - // directory then use this as the pathname to the calibration
671   - // database. Otherwise interpret this as the instrument name,
672   - // the mission being "cta"
673   - GCaldb caldb;
674   - if (gammalib::dir_exists(m_caldb)) {
675   - caldb.rootdir(m_caldb);
676   - }
677   - else {
678   - caldb.open("cta", m_caldb);
679   - }
680   -
681   - // Set reponse
682   - obs->response(m_irf, caldb);
683   -
684   - } // endif: observation already has a response
685   -
686   - } // endif: observation was a CTA observation
687   -
688   - } // endfor: looped over all observations
  643 + // For all observations that have no response, set the response
  644 + // from the task parameters
  645 + set_response(m_obs);
689 646  
690 647 // Return
691 648 return;
... ... @@ -716,7 +673,7 @@ void ctmodel::init_cube(void)
716 673 gti.append(GTime(0.0), GTime(0.1234));
717 674  
718 675 // Set energy boundaries
719   - get_ebounds();
  676 + m_ebounds = get_ebounds();
720 677  
721 678 // Setup skymap
722 679 GSkymap map = GSkymap(m_proj, m_coordsys,
... ... @@ -824,80 +781,3 @@ void ctmodel::fill_cube(const GCTAObservation* obs)
824 781 // Return
825 782 return;
826 783 }
827   -
828   -
829   -/***********************************************************************//**
830   - * @brief Get the energy boundaries
831   - *
832   - * @exception GException::invalid_value
833   - * No valid energy boundary extension found.
834   - *
835   - * Get the energy boundaries according to the user parameters. The method
836   - * supports loading of energy boundary information from the EBOUNDS or
837   - * ENERGYBINS extension, or setting energy boundaries using a linear
838   - * or logarithmical spacing.
839   - *
840   - * @todo Ultimately this method should go in a support library as it is
841   - * used by several ctools.
842   - ***************************************************************************/
843   -void ctmodel::get_ebounds(void)
844   -{
845   - // Initialse energy boundary information
846   - m_ebounds.clear();
847   -
848   - // Check whether energy binning information should be read from a FITS
849   - // file ...
850   - if (m_ebinalg == "FILE") {
851   -
852   - // Open energy boundary file using the EBOUNDS or ENERGYBINS
853   - // extension. Throw an exception if opening fails.
854   - GFits file(m_ebinfile);
855   - if (file.contains("EBOUNDS")) {
856   - file.close();
857   - m_ebounds.load(m_ebinfile,"EBOUNDS");
858   - }
859   - else if (file.contains("ENERGYBINS")) {
860   - file.close();
861   - m_ebounds.load(m_ebinfile,"ENERGYBINS");
862   - }
863   - else {
864   - file.close();
865   - std::string msg = "No extension with name \"EBOUNDS\" or"
866   - " \"ENERGYBINS\" found in FITS file"
867   - " \""+m_ebinfile+"\".\n"
868   - "An \"EBOUNDS\" or \"ENERGYBINS\" extension"
869   - " is required if the parameter \"ebinalg\""
870   - " is set to \"FILE\".";
871   - throw GException::invalid_value(G_GET_EBOUNDS, msg);
872   - }
873   -
874   - // Set enumbins parameter to number of ebounds
875   - m_enumbins = m_ebounds.size();
876   -
877   - } // endif: ebinalg was "FILE"
878   -
879   - // ... otherwise use a linear or a logarithmically-spaced energy binning
880   - else {
881   -
882   - // Initialise log mode for ebinning
883   - bool log = true;
884   -
885   - // check if algorithm is linear
886   - if (m_ebinalg == "LIN") {
887   - log = false;
888   - }
889   -
890   - // todo: should we also check if m_ebinalg is "LOG"
891   - // and throw an exception if neither LIN/LOG/FILE
892   - // is given?
893   -
894   - // Setup energy range covered by data
895   - GEnergy emin(m_emin, "TeV");
896   - GEnergy emax(m_emax, "TeV");
897   - m_ebounds = GEbounds(m_enumbins, emin, emax, log);
898   -
899   - } //endif: ebinalg was not "FILE"
900   -
901   - // Return
902   - return;
903   -}
... ...
src/ctmodel/ctmodel.hpp
1 1 /***************************************************************************
2   - * ctmodel - CTA model cube generation tool *
  2 + * ctmodel - Model cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4 4 * copyright (C) 2012-2014 by Juergen Knoedlseder *
5 5 * ----------------------------------------------------------------------- *
... ... @@ -20,7 +20,7 @@
20 20 ***************************************************************************/
21 21 /**
22 22 * @file ctmodel.hpp
23   - * @brief CTA model cube tool definition
  23 + * @brief Model cube generation tool definition
24 24 * @author Juergen Knoedlseder
25 25 */
26 26  
... ... @@ -30,6 +30,7 @@
30 30 /* __ Includes ___________________________________________________________ */
31 31 #include "GammaLib.hpp"
32 32 #include "GCTALib.hpp"
  33 +#include "ctool.hpp"
33 34  
34 35 /* __Definitions _________________________________________________________ */
35 36 #define CTMODEL_NAME "ctmodel"
... ... @@ -39,7 +40,7 @@
39 40 /***********************************************************************//**
40 41 * @class ctmodel
41 42 *
42   - * @brief CTA counts model tool interface defintion
  43 + * @brief Model cube generation tool
43 44 *
44 45 * This class creates counts model map(s). The definition of the counts model
45 46 * can be taken from a predefined observation container, from the counts maps
... ... @@ -50,7 +51,7 @@
50 51 * in form of FITS files (model maps) and an updated observation definition
51 52 * XML file.
52 53 ***************************************************************************/
53   -class ctmodel : public GApplication {
  54 +class ctmodel : public ctool {
54 55  
55 56 public:
56 57 // Constructors and destructors
... ... @@ -80,7 +81,6 @@ protected:
80 81 void setup_obs(void);
81 82 void init_cube(void);
82 83 void fill_cube(const GCTAObservation* obs);
83   - void get_ebounds(void);
84 84  
85 85 // User parameters
86 86 std::string m_infile; //!< Input counts cube
... ...
src/support/ctool.cpp
... ... @@ -303,6 +303,39 @@ GEbounds ctool::get_ebounds(void)
303 303  
304 304  
305 305 /***********************************************************************//**
  306 + * @brief Set response for all CTA observations in container
  307 + *
  308 + * @param[in,out] obs Observation container
  309 + *
  310 + * Set the response for a CTA observations in the container that so far have
  311 + * no response using the "database" and "irf" task parameters.
  312 + ***************************************************************************/
  313 +void ctool::set_response(GObservations& obs)
  314 +{
  315 + // Setup response for all observations
  316 + for (int i = 0; i < obs.size(); ++i) {
  317 +
  318 + // Is this observation a CTA observation?
  319 + GCTAObservation* cta = dynamic_cast<GCTAObservation*>(obs[i]);
  320 +
  321 + // Yes ...
  322 + if (cta != NULL) {
  323 +
  324 + // Set response if we don't have one
  325 + if (!cta->has_response()) {
  326 + set_obs_response(cta);
  327 + }
  328 +
  329 + } // endif: observation was a CTA observation
  330 +
  331 + } // endfor: looped over all observations
  332 +
  333 + // Return
  334 + return;
  335 +}
  336 +
  337 +
  338 +/***********************************************************************//**
306 339 * @brief Set response for CTA observation
307 340 *
308 341 * @param[in,out] obs CTA observation
... ...
src/support/ctool.hpp
... ... @@ -60,6 +60,7 @@ protected:
60 60 void copy_members(const ctool& app);
61 61 void free_members(void);
62 62 GEbounds get_ebounds(void);
  63 + void set_response(GObservations& obs);
63 64 void set_obs_response(GCTAObservation* obs);
64 65 };
65 66  
... ...