diff --git a/ChangeLog b/ChangeLog index 2d0de2b..d5d9222 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,9 @@ -2020-11-03 +2020-11-07 * Version 2.0.0 released ======================== + Add models() method to ctobssim (#3441) Add ctlike results to XML file (#3431) Fix implementation of fix_spat_for_ts parameter in ctlike (#3426) diff --git a/NEWS b/NEWS index e7fc6b6..edf6ed2 100755 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 2.0.0 -3 November 2020 +7 November 2020 Introduction @@ -97,7 +97,8 @@ None ctobssim - CTA observation simulation ------------------------------------- -None +Added models() method allowing for a setting of the model container without +using the "inmodels" parameter (#3441). ctphase - Event phase computation diff --git a/README.md b/README.md index d6a0bfd..bad16ad 100755 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ctools information ================== -* Version: 2.0.0.dev (3 November 2020) +* Version: 2.0.0.dev (7 November 2020) * GammaLib dependency: 2.0.0.dev [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/) diff --git a/doc/source/admin/release_history/2.0.rst b/doc/source/admin/release_history/2.0.rst index 03e92bb..dc69fc5 100644 --- a/doc/source/admin/release_history/2.0.rst +++ b/doc/source/admin/release_history/2.0.rst @@ -1,6 +1,6 @@ .. _2.0: -ctools 2.0 release (3 November 2020) +ctools 2.0 release (7 November 2020) ==================================== Overview @@ -24,6 +24,8 @@ Bug fixes Improvements ------------ +* [`3441 `_] - + Add ``models()`` method to :ref:`ctobssim` * [`3431 `_] - Add :ref:`ctlike` results to XML file diff --git a/pyext/ctobssim.i b/pyext/ctobssim.i index f9d6d8e..3e27cf9 100755 --- a/pyext/ctobssim.i +++ b/pyext/ctobssim.i @@ -1,7 +1,7 @@ /*************************************************************************** * ctobssim - Observation simulator tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2016 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -50,6 +50,7 @@ public: void publish(const std::string& name = ""); const double& max_rate(void) const; void max_rate(const double& max_rate); + void models(const GModels& models); }; diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index 85968fc..6172cba 100755 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -551,6 +551,7 @@ void ctobssim::init_members(void) m_max_rate = 1.0e6; // Initialise protected members + m_models.clear(); m_rans.clear(); m_save_and_dispose = false; @@ -582,9 +583,10 @@ void ctobssim::copy_members(const ctobssim& app) m_max_rate = app.m_max_rate; // Copy protected members + m_models = app.m_models; + m_save_and_dispose = app.m_save_and_dispose; m_max_photons = app.m_max_photons; m_rans = app.m_rans; - m_save_and_dispose = app.m_save_and_dispose; m_event_id = app.m_event_id; // Return @@ -634,6 +636,13 @@ void ctobssim::get_parameters(void) setup_observations(m_obs); } + // If models have been specified using the models() method then use + // these models instead of any models that may already exist in the + // observations. + if (m_models.size() > 0) { + m_obs.models(m_models); + } + // Set observation boundaries set_obs_bounds(); diff --git a/src/ctobssim/ctobssim.hpp b/src/ctobssim/ctobssim.hpp index 6b8359f..3964909 100755 --- a/src/ctobssim/ctobssim.hpp +++ b/src/ctobssim/ctobssim.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctobssim - Observation simulator tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2019 by Juergen Knoedlseder * + * copyright (C) 2011-2020 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -67,6 +67,7 @@ public: void publish(const std::string& name = ""); const double& max_rate(void) const; void max_rate(const double& max_rate); + void models(const GModels& models); protected: // Protected methods @@ -144,13 +145,14 @@ protected: int m_seed; //!< Random number generator seed int m_eslices; //!< Number of energy slices bool m_apply_edisp; //!< Apply energy dispersion? + double m_max_rate; //!< Maximum photon rate // Protected members - mutable bool m_save_and_dispose; //!< Save and dispose immediately - int m_max_photons; //!< Maximum number of photons/slice - double m_max_rate; //!< Maximum photon rate - std::vector m_rans; //!< Random number generators - int m_event_id; //!< Event identifier + GModels m_models; //!< Optionally provided models + mutable bool m_save_and_dispose; //!< Save and dispose immediately + int m_max_photons; //!< Maximum number of photons/slice + std::vector m_rans; //!< Random number generators + int m_event_id; //!< Event identifier }; @@ -178,4 +180,22 @@ void ctobssim::max_rate(const double& max_rate) return; } + +/***********************************************************************//** + * @brief Set models for simulation + * + * @param[in] models Model container. + * + * Sets the model container that should be used for simulations. If a + * model container exists already in the input observations the model + * container will be overwritten. The models will not be queried, and + * any model specified using the "inmodel" parameter will be ignored. + ***************************************************************************/ +inline +void ctobssim::models(const GModels& models) +{ + m_models = models; + return; +} + #endif /* CTOBSSIM_HPP */ diff --git a/test/test_ctobssim.py b/test/test_ctobssim.py index 2ce1e29..c0f2ceb 100755 --- a/test/test_ctobssim.py +++ b/test/test_ctobssim.py @@ -2,7 +2,7 @@ # ========================================================================== # This scripts performs unit tests for the ctobssim tool # -# Copyright (C) 2014-2018 Juergen Knoedlseder +# Copyright (C) 2014-2020 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -219,6 +219,29 @@ class Test(test): self._test_list(obs[0].events(), 3630) self._test_list(obs[1].events(), 3594) + # Set ctobssim parameters + sim = ctools.ctobssim() + sim['caldb'] = self._caldb + sim['irf'] = self._irf + sim['ra'] = 83.63 + sim['dec'] = 22.01 + sim['rad'] = 2.0 + sim['tmin'] = '2020-01-01T00:00:00' + sim['tmax'] = '2020-01-01T00:05:00' + sim['emin'] = 1.0 + sim['emax'] = 100.0 + sim['logfile'] = 'ctobssim_py4.log' + sim['chatter'] = 2 + + # Run tool + sim.models(gammalib.GModels(self._model)) + sim.logFileOpen() + sim.run() + + # Check content of observation + self._test_observation(sim) + self._test_list(sim.obs()[0].events(), 261) + # Return return