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 49 void save(void);
50 50 const GObservations& obs(void) const;
51 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 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 254 // Loop over all observations in the container
253 255 for (int i = 0; i < m_obs.size(); ++i) {
... ... @@ -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 352 = Private methods =
... ... @@ -362,6 +389,7 @@ void ctmodel::init_members(void)
362 389 m_cube.clear();
363 390 m_ebounds.clear();
364 391 m_gti.clear();
  392 + m_has_cube = false;
365 393  
366 394 // Return
367 395 return;
... ... @@ -406,6 +434,7 @@ void ctmodel::copy_members(const ctmodel&amp; app)
406 434 m_cube = app.m_cube;
407 435 m_ebounds = app.m_ebounds;
408 436 m_gti = app.m_gti;
  437 + m_has_cube = app.m_has_cube;
409 438  
410 439 // Return
411 440 return;
... ... @@ -431,7 +460,9 @@ void ctmodel::free_members(void)
431 460 void ctmodel::get_parameters(void)
432 461 {
433 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 466 if (read_ahead()) {
436 467 m_outfile = (*this)["outfile"].filename();
437 468 }
... ... @@ -482,7 +513,8 @@ void ctmodel::get_parameters(void)
482 513  
483 514 // If no cube file has been specified then read all parameters that
484 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 518 m_ebinalg = (*this)["ebinalg"].string();
487 519 if (m_ebinalg == "FILE") {
488 520 m_ebinfile = (*this)["ebinfile"].filename();
... ... @@ -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 708 // Return
674 709 return;
675 710 }
... ...
src/ctmodel/ctmodel.hpp
... ... @@ -70,6 +70,7 @@ public:
70 70 void save(void);
71 71 const GObservations& obs(void) const;
72 72 const GCTAEventCube& cube(void) const;
  73 + void cube(const GCTAEventCube& cube);
73 74  
74 75 protected:
75 76 // Protected methods
... ... @@ -80,6 +81,7 @@ protected:
80 81 void setup_obs(void);
81 82 void init_cube(void);
82 83 void fill_cube(const GCTAObservation* obs);
  84 + bool has_cube(void) const;
83 85  
84 86 // User parameters
85 87 std::string m_infile; //!< Input counts cube
... ... @@ -112,13 +114,14 @@ protected:
112 114 GCTAEventCube m_cube; //!< Model cube
113 115 GEbounds m_ebounds; //!< Energy boundaries
114 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 122 * @brief Return observation container
120 123 *
121   - * @return Reference to observation container
  124 + * @return Reference to observation container.
122 125 ***************************************************************************/
123 126 inline
124 127 const GObservations& ctmodel::obs(void) const
... ... @@ -130,7 +133,7 @@ const GObservations&amp; ctmodel::obs(void) const
130 133 /***********************************************************************//**
131 134 * @brief Return model cube
132 135 *
133   - * @return Reference to model cube
  136 + * @return Reference to model cube.
134 137 ***************************************************************************/
135 138 inline
136 139 const GCTAEventCube& ctmodel::cube(void) const
... ... @@ -138,4 +141,16 @@ const GCTAEventCube&amp; ctmodel::cube(void) const
138 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 156 #endif /* CTMODEL_HPP */
... ...