Commit 454357fbb8f49a1d81185293f45fdabd58a69bfb

Authored by Jürgen Knödlseder
1 parent 9fd8ce1a

Add cube setting method to ctmodel.

pyext/ctmodel.i
@@ -49,6 +49,7 @@ public: @@ -49,6 +49,7 @@ public:
49 void save(void); 49 void save(void);
50 const GObservations& obs(void) const; 50 const GObservations& obs(void) const;
51 const GCTAEventCube& cube(void) const; 51 const GCTAEventCube& cube(void) const;
  52 + void cube(const GCTAEventCube& cube);
52 }; 53 };
53 54
54 55
src/ctmodel/ctmodel.cpp
@@ -246,8 +246,10 @@ void ctmodel::run(void) @@ -246,8 +246,10 @@ void ctmodel::run(void)
246 log.header1("Generate model cube"); 246 log.header1("Generate model cube");
247 } 247 }
248 248
249 - // Initialise counts cube  
250 - init_cube(); 249 + // Initialise counts cube if cube has not yet been set
  250 + if (!has_cube()) {
  251 + init_cube();
  252 + }
251 253
252 // Loop over all observations in the container 254 // Loop over all observations in the container
253 for (int i = 0; i < m_obs.size(); ++i) { 255 for (int i = 0; i < m_obs.size(); ++i) {
@@ -320,6 +322,31 @@ void ctmodel::save(void) @@ -320,6 +322,31 @@ void ctmodel::save(void)
320 } 322 }
321 323
322 324
  325 +/***********************************************************************//**
  326 + * @brief Set model cube
  327 + *
  328 + * @param[in] cube Model cube.
  329 + *
  330 + * Set model cube and set all cube bins to zero.
  331 + ***************************************************************************/
  332 +void ctmodel::cube(const GCTAEventCube& cube)
  333 +{
  334 + // Set cube
  335 + m_cube = cube;
  336 +
  337 + // Set all cube bins to zero
  338 + for (int i = 0; i < m_cube.size(); ++i) {
  339 + m_cube[i]->counts(0.0);
  340 + }
  341 +
  342 + // Signal that cube has been set
  343 + m_has_cube = true;
  344 +
  345 + // Return
  346 + return;
  347 +}
  348 +
  349 +
323 /*========================================================================== 350 /*==========================================================================
324 = = 351 = =
325 = Private methods = 352 = Private methods =
@@ -362,6 +389,7 @@ void ctmodel::init_members(void) @@ -362,6 +389,7 @@ void ctmodel::init_members(void)
362 m_cube.clear(); 389 m_cube.clear();
363 m_ebounds.clear(); 390 m_ebounds.clear();
364 m_gti.clear(); 391 m_gti.clear();
  392 + m_has_cube = false;
365 393
366 // Return 394 // Return
367 return; 395 return;
@@ -406,6 +434,7 @@ void ctmodel::copy_members(const ctmodel&amp; app) @@ -406,6 +434,7 @@ void ctmodel::copy_members(const ctmodel&amp; app)
406 m_cube = app.m_cube; 434 m_cube = app.m_cube;
407 m_ebounds = app.m_ebounds; 435 m_ebounds = app.m_ebounds;
408 m_gti = app.m_gti; 436 m_gti = app.m_gti;
  437 + m_has_cube = app.m_has_cube;
409 438
410 // Return 439 // Return
411 return; 440 return;
@@ -431,7 +460,9 @@ void ctmodel::free_members(void) @@ -431,7 +460,9 @@ void ctmodel::free_members(void)
431 void ctmodel::get_parameters(void) 460 void ctmodel::get_parameters(void)
432 { 461 {
433 // Read input and optionally output cube filenames 462 // Read input and optionally output cube filenames
434 - m_infile = (*this)["infile"].filename(); 463 + if (!has_cube()) {
  464 + m_infile = (*this)["infile"].filename();
  465 + }
435 if (read_ahead()) { 466 if (read_ahead()) {
436 m_outfile = (*this)["outfile"].filename(); 467 m_outfile = (*this)["outfile"].filename();
437 } 468 }
@@ -482,7 +513,8 @@ void ctmodel::get_parameters(void) @@ -482,7 +513,8 @@ void ctmodel::get_parameters(void)
482 513
483 // If no cube file has been specified then read all parameters that 514 // If no cube file has been specified then read all parameters that
484 // are necessary to create the cube from scratch (see method init_cube) 515 // are necessary to create the cube from scratch (see method init_cube)
485 - if ((m_infile == "NONE") || (gammalib::strip_whitespace(m_infile) == "")) { 516 + if ((!has_cube()) &&
  517 + ((m_infile == "NONE") || (gammalib::strip_whitespace(m_infile) == ""))) {
486 m_ebinalg = (*this)["ebinalg"].string(); 518 m_ebinalg = (*this)["ebinalg"].string();
487 if (m_ebinalg == "FILE") { 519 if (m_ebinalg == "FILE") {
488 m_ebinfile = (*this)["ebinfile"].filename(); 520 m_ebinfile = (*this)["ebinfile"].filename();
@@ -670,6 +702,9 @@ void ctmodel::init_cube(void) @@ -670,6 +702,9 @@ void ctmodel::init_cube(void)
670 702
671 } 703 }
672 704
  705 + // Signal that cube has been set
  706 + m_has_cube = true;
  707 +
673 // Return 708 // Return
674 return; 709 return;
675 } 710 }
src/ctmodel/ctmodel.hpp
@@ -70,6 +70,7 @@ public: @@ -70,6 +70,7 @@ public:
70 void save(void); 70 void save(void);
71 const GObservations& obs(void) const; 71 const GObservations& obs(void) const;
72 const GCTAEventCube& cube(void) const; 72 const GCTAEventCube& cube(void) const;
  73 + void cube(const GCTAEventCube& cube);
73 74
74 protected: 75 protected:
75 // Protected methods 76 // Protected methods
@@ -80,6 +81,7 @@ protected: @@ -80,6 +81,7 @@ protected:
80 void setup_obs(void); 81 void setup_obs(void);
81 void init_cube(void); 82 void init_cube(void);
82 void fill_cube(const GCTAObservation* obs); 83 void fill_cube(const GCTAObservation* obs);
  84 + bool has_cube(void) const;
83 85
84 // User parameters 86 // User parameters
85 std::string m_infile; //!< Input counts cube 87 std::string m_infile; //!< Input counts cube
@@ -112,13 +114,14 @@ protected: @@ -112,13 +114,14 @@ protected:
112 GCTAEventCube m_cube; //!< Model cube 114 GCTAEventCube m_cube; //!< Model cube
113 GEbounds m_ebounds; //!< Energy boundaries 115 GEbounds m_ebounds; //!< Energy boundaries
114 GGti m_gti; //!< Model cube GTIs 116 GGti m_gti; //!< Model cube GTIs
  117 + bool m_has_cube; //!< Signal if cube has been set or loaded
115 }; 118 };
116 119
117 120
118 /***********************************************************************//** 121 /***********************************************************************//**
119 * @brief Return observation container 122 * @brief Return observation container
120 * 123 *
121 - * @return Reference to observation container 124 + * @return Reference to observation container.
122 ***************************************************************************/ 125 ***************************************************************************/
123 inline 126 inline
124 const GObservations& ctmodel::obs(void) const 127 const GObservations& ctmodel::obs(void) const
@@ -130,7 +133,7 @@ const GObservations&amp; ctmodel::obs(void) const @@ -130,7 +133,7 @@ const GObservations&amp; ctmodel::obs(void) const
130 /***********************************************************************//** 133 /***********************************************************************//**
131 * @brief Return model cube 134 * @brief Return model cube
132 * 135 *
133 - * @return Reference to model cube 136 + * @return Reference to model cube.
134 ***************************************************************************/ 137 ***************************************************************************/
135 inline 138 inline
136 const GCTAEventCube& ctmodel::cube(void) const 139 const GCTAEventCube& ctmodel::cube(void) const
@@ -138,4 +141,16 @@ const GCTAEventCube&amp; ctmodel::cube(void) const @@ -138,4 +141,16 @@ const GCTAEventCube&amp; ctmodel::cube(void) const
138 return m_cube; 141 return m_cube;
139 } 142 }
140 143
  144 +
  145 +/***********************************************************************//**
  146 + * @brief Signal if cube has been set or loaded
  147 + *
  148 + * @return True if cube has been set or loaded.
  149 + ***************************************************************************/
  150 +inline
  151 +bool ctmodel::has_cube(void) const
  152 +{
  153 + return m_has_cube;
  154 +}
  155 +
141 #endif /* CTMODEL_HPP */ 156 #endif /* CTMODEL_HPP */