diff --git a/pyext/ctmodel.i b/pyext/ctmodel.i index dd43f3d..27632f3 100644 --- a/pyext/ctmodel.i +++ b/pyext/ctmodel.i @@ -49,6 +49,7 @@ public: void save(void); const GObservations& obs(void) const; const GCTAEventCube& cube(void) const; + void cube(const GCTAEventCube& cube); }; diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index 43e5019..0bf482b 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -246,8 +246,10 @@ void ctmodel::run(void) log.header1("Generate model cube"); } - // Initialise counts cube - init_cube(); + // Initialise counts cube if cube has not yet been set + if (!has_cube()) { + init_cube(); + } // Loop over all observations in the container for (int i = 0; i < m_obs.size(); ++i) { @@ -320,6 +322,31 @@ void ctmodel::save(void) } +/***********************************************************************//** + * @brief Set model cube + * + * @param[in] cube Model cube. + * + * Set model cube and set all cube bins to zero. + ***************************************************************************/ +void ctmodel::cube(const GCTAEventCube& cube) +{ + // Set cube + m_cube = cube; + + // Set all cube bins to zero + for (int i = 0; i < m_cube.size(); ++i) { + m_cube[i]->counts(0.0); + } + + // Signal that cube has been set + m_has_cube = true; + + // Return + return; +} + + /*========================================================================== = = = Private methods = @@ -362,6 +389,7 @@ void ctmodel::init_members(void) m_cube.clear(); m_ebounds.clear(); m_gti.clear(); + m_has_cube = false; // Return return; @@ -406,6 +434,7 @@ void ctmodel::copy_members(const ctmodel& app) m_cube = app.m_cube; m_ebounds = app.m_ebounds; m_gti = app.m_gti; + m_has_cube = app.m_has_cube; // Return return; @@ -431,7 +460,9 @@ void ctmodel::free_members(void) void ctmodel::get_parameters(void) { // Read input and optionally output cube filenames - m_infile = (*this)["infile"].filename(); + if (!has_cube()) { + m_infile = (*this)["infile"].filename(); + } if (read_ahead()) { m_outfile = (*this)["outfile"].filename(); } @@ -482,7 +513,8 @@ void ctmodel::get_parameters(void) // If no cube file has been specified then read all parameters that // are necessary to create the cube from scratch (see method init_cube) - if ((m_infile == "NONE") || (gammalib::strip_whitespace(m_infile) == "")) { + if ((!has_cube()) && + ((m_infile == "NONE") || (gammalib::strip_whitespace(m_infile) == ""))) { m_ebinalg = (*this)["ebinalg"].string(); if (m_ebinalg == "FILE") { m_ebinfile = (*this)["ebinfile"].filename(); @@ -670,6 +702,9 @@ void ctmodel::init_cube(void) } + // Signal that cube has been set + m_has_cube = true; + // Return return; } diff --git a/src/ctmodel/ctmodel.hpp b/src/ctmodel/ctmodel.hpp index 52f71c7..7c43083 100644 --- a/src/ctmodel/ctmodel.hpp +++ b/src/ctmodel/ctmodel.hpp @@ -70,6 +70,7 @@ public: void save(void); const GObservations& obs(void) const; const GCTAEventCube& cube(void) const; + void cube(const GCTAEventCube& cube); protected: // Protected methods @@ -80,6 +81,7 @@ protected: void setup_obs(void); void init_cube(void); void fill_cube(const GCTAObservation* obs); + bool has_cube(void) const; // User parameters std::string m_infile; //!< Input counts cube @@ -112,13 +114,14 @@ protected: GCTAEventCube m_cube; //!< Model cube GEbounds m_ebounds; //!< Energy boundaries GGti m_gti; //!< Model cube GTIs + bool m_has_cube; //!< Signal if cube has been set or loaded }; /***********************************************************************//** * @brief Return observation container * - * @return Reference to observation container + * @return Reference to observation container. ***************************************************************************/ inline const GObservations& ctmodel::obs(void) const @@ -130,7 +133,7 @@ const GObservations& ctmodel::obs(void) const /***********************************************************************//** * @brief Return model cube * - * @return Reference to model cube + * @return Reference to model cube. ***************************************************************************/ inline const GCTAEventCube& ctmodel::cube(void) const @@ -138,4 +141,16 @@ const GCTAEventCube& ctmodel::cube(void) const return m_cube; } + +/***********************************************************************//** + * @brief Signal if cube has been set or loaded + * + * @return True if cube has been set or loaded. + ***************************************************************************/ +inline +bool ctmodel::has_cube(void) const +{ + return m_has_cube; +} + #endif /* CTMODEL_HPP */