Commit 051d2fc65ffc0bedd5fa40d26db440d52e7354f6

Authored by Jürgen Knödlseder
1 parent 209428cf

Add models() method to ctobssim (#3441)

ChangeLog
1 -2020-11-03 1 +2020-11-07
2 2
3 * Version 2.0.0 released 3 * Version 2.0.0 released
4 ======================== 4 ========================
5 5
  6 + Add models() method to ctobssim (#3441)
6 Add ctlike results to XML file (#3431) 7 Add ctlike results to XML file (#3431)
7 Fix implementation of fix_spat_for_ts parameter in ctlike (#3426) 8 Fix implementation of fix_spat_for_ts parameter in ctlike (#3426)
8 9
1 New Features and Important Changes in ctools 2.0.0 1 New Features and Important Changes in ctools 2.0.0
2 2
3 -3 November 2020 3 +7 November 2020
4 4
5 5
6 Introduction 6 Introduction
@@ -97,7 +97,8 @@ None @@ -97,7 +97,8 @@ None
97 97
98 ctobssim - CTA observation simulation 98 ctobssim - CTA observation simulation
99 ------------------------------------- 99 -------------------------------------
100 -None 100 +Added models() method allowing for a setting of the model container without
  101 +using the "inmodels" parameter (#3441).
101 102
102 103
103 ctphase - Event phase computation 104 ctphase - Event phase computation
README.md
1 ctools information 1 ctools information
2 ================== 2 ==================
3 -* Version: 2.0.0.dev (3 November 2020) 3 +* Version: 2.0.0.dev (7 November 2020)
4 * GammaLib dependency: 2.0.0.dev 4 * GammaLib dependency: 2.0.0.dev
5 5
6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/) 6 [![Build Status](https://cta-jenkins.irap.omp.eu/buildStatus/icon?job=ctools-integrate-os)](https://cta-jenkins.irap.omp.eu/job/ctools-integrate-os/)
doc/source/admin/release_history/2.0.rst
1 .. _2.0: 1 .. _2.0:
2 2
3 -ctools 2.0 release (3 November 2020) 3 +ctools 2.0 release (7 November 2020)
4 ==================================== 4 ====================================
5 5
6 Overview 6 Overview
@@ -24,6 +24,8 @@ Bug fixes @@ -24,6 +24,8 @@ Bug fixes
24 Improvements 24 Improvements
25 ------------ 25 ------------
26 26
  27 +* [`3441 <https://cta-redmine.irap.omp.eu/issues/3441>`_] -
  28 + Add ``models()`` method to :ref:`ctobssim`
27 * [`3431 <https://cta-redmine.irap.omp.eu/issues/3431>`_] - 29 * [`3431 <https://cta-redmine.irap.omp.eu/issues/3431>`_] -
28 Add :ref:`ctlike` results to XML file 30 Add :ref:`ctlike` results to XML file
29 31
pyext/ctobssim.i
1 /*************************************************************************** 1 /***************************************************************************
2 * ctobssim - Observation simulator tool * 2 * ctobssim - Observation simulator tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2011-2016 by Juergen Knoedlseder * 4 + * copyright (C) 2011-2020 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -50,6 +50,7 @@ public: @@ -50,6 +50,7 @@ public:
50 void publish(const std::string& name = ""); 50 void publish(const std::string& name = "");
51 const double& max_rate(void) const; 51 const double& max_rate(void) const;
52 void max_rate(const double& max_rate); 52 void max_rate(const double& max_rate);
  53 + void models(const GModels& models);
53 }; 54 };
54 55
55 56
src/ctobssim/ctobssim.cpp
@@ -551,6 +551,7 @@ void ctobssim::init_members(void) @@ -551,6 +551,7 @@ void ctobssim::init_members(void)
551 m_max_rate = 1.0e6; 551 m_max_rate = 1.0e6;
552 552
553 // Initialise protected members 553 // Initialise protected members
  554 + m_models.clear();
554 m_rans.clear(); 555 m_rans.clear();
555 m_save_and_dispose = false; 556 m_save_and_dispose = false;
556 557
@@ -582,9 +583,10 @@ void ctobssim::copy_members(const ctobssim&amp; app) @@ -582,9 +583,10 @@ void ctobssim::copy_members(const ctobssim&amp; app)
582 m_max_rate = app.m_max_rate; 583 m_max_rate = app.m_max_rate;
583 584
584 // Copy protected members 585 // Copy protected members
  586 + m_models = app.m_models;
  587 + m_save_and_dispose = app.m_save_and_dispose;
585 m_max_photons = app.m_max_photons; 588 m_max_photons = app.m_max_photons;
586 m_rans = app.m_rans; 589 m_rans = app.m_rans;
587 - m_save_and_dispose = app.m_save_and_dispose;  
588 m_event_id = app.m_event_id; 590 m_event_id = app.m_event_id;
589 591
590 // Return 592 // Return
@@ -634,6 +636,13 @@ void ctobssim::get_parameters(void) @@ -634,6 +636,13 @@ void ctobssim::get_parameters(void)
634 setup_observations(m_obs); 636 setup_observations(m_obs);
635 } 637 }
636 638
  639 + // If models have been specified using the models() method then use
  640 + // these models instead of any models that may already exist in the
  641 + // observations.
  642 + if (m_models.size() > 0) {
  643 + m_obs.models(m_models);
  644 + }
  645 +
637 // Set observation boundaries 646 // Set observation boundaries
638 set_obs_bounds(); 647 set_obs_bounds();
639 648
src/ctobssim/ctobssim.hpp
1 /*************************************************************************** 1 /***************************************************************************
2 * ctobssim - Observation simulator tool * 2 * ctobssim - Observation simulator tool *
3 * ----------------------------------------------------------------------- * 3 * ----------------------------------------------------------------------- *
4 - * copyright (C) 2011-2019 by Juergen Knoedlseder * 4 + * copyright (C) 2011-2020 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- * 5 * ----------------------------------------------------------------------- *
6 * * 6 * *
7 * This program is free software: you can redistribute it and/or modify * 7 * This program is free software: you can redistribute it and/or modify *
@@ -67,6 +67,7 @@ public: @@ -67,6 +67,7 @@ public:
67 void publish(const std::string& name = ""); 67 void publish(const std::string& name = "");
68 const double& max_rate(void) const; 68 const double& max_rate(void) const;
69 void max_rate(const double& max_rate); 69 void max_rate(const double& max_rate);
  70 + void models(const GModels& models);
70 71
71 protected: 72 protected:
72 // Protected methods 73 // Protected methods
@@ -144,13 +145,14 @@ protected: @@ -144,13 +145,14 @@ protected:
144 int m_seed; //!< Random number generator seed 145 int m_seed; //!< Random number generator seed
145 int m_eslices; //!< Number of energy slices 146 int m_eslices; //!< Number of energy slices
146 bool m_apply_edisp; //!< Apply energy dispersion? 147 bool m_apply_edisp; //!< Apply energy dispersion?
  148 + double m_max_rate; //!< Maximum photon rate
147 149
148 // Protected members 150 // Protected members
149 - mutable bool m_save_and_dispose; //!< Save and dispose immediately  
150 - int m_max_photons; //!< Maximum number of photons/slice  
151 - double m_max_rate; //!< Maximum photon rate  
152 - std::vector<GRan> m_rans; //!< Random number generators  
153 - int m_event_id; //!< Event identifier 151 + GModels m_models; //!< Optionally provided models
  152 + mutable bool m_save_and_dispose; //!< Save and dispose immediately
  153 + int m_max_photons; //!< Maximum number of photons/slice
  154 + std::vector<GRan> m_rans; //!< Random number generators
  155 + int m_event_id; //!< Event identifier
154 }; 156 };
155 157
156 158
@@ -178,4 +180,22 @@ void ctobssim::max_rate(const double&amp; max_rate) @@ -178,4 +180,22 @@ void ctobssim::max_rate(const double&amp; max_rate)
178 return; 180 return;
179 } 181 }
180 182
  183 +
  184 +/***********************************************************************//**
  185 + * @brief Set models for simulation
  186 + *
  187 + * @param[in] models Model container.
  188 + *
  189 + * Sets the model container that should be used for simulations. If a
  190 + * model container exists already in the input observations the model
  191 + * container will be overwritten. The models will not be queried, and
  192 + * any model specified using the "inmodel" parameter will be ignored.
  193 + ***************************************************************************/
  194 +inline
  195 +void ctobssim::models(const GModels& models)
  196 +{
  197 + m_models = models;
  198 + return;
  199 +}
  200 +
181 #endif /* CTOBSSIM_HPP */ 201 #endif /* CTOBSSIM_HPP */
test/test_ctobssim.py
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 # ========================================================================== 2 # ==========================================================================
3 # This scripts performs unit tests for the ctobssim tool 3 # This scripts performs unit tests for the ctobssim tool
4 # 4 #
5 -# Copyright (C) 2014-2018 Juergen Knoedlseder 5 +# Copyright (C) 2014-2020 Juergen Knoedlseder
6 # 6 #
7 # This program is free software: you can redistribute it and/or modify 7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by 8 # it under the terms of the GNU General Public License as published by
@@ -219,6 +219,29 @@ class Test(test): @@ -219,6 +219,29 @@ class Test(test):
219 self._test_list(obs[0].events(), 3630) 219 self._test_list(obs[0].events(), 3630)
220 self._test_list(obs[1].events(), 3594) 220 self._test_list(obs[1].events(), 3594)
221 221
  222 + # Set ctobssim parameters
  223 + sim = ctools.ctobssim()
  224 + sim['caldb'] = self._caldb
  225 + sim['irf'] = self._irf
  226 + sim['ra'] = 83.63
  227 + sim['dec'] = 22.01
  228 + sim['rad'] = 2.0
  229 + sim['tmin'] = '2020-01-01T00:00:00'
  230 + sim['tmax'] = '2020-01-01T00:05:00'
  231 + sim['emin'] = 1.0
  232 + sim['emax'] = 100.0
  233 + sim['logfile'] = 'ctobssim_py4.log'
  234 + sim['chatter'] = 2
  235 +
  236 + # Run tool
  237 + sim.models(gammalib.GModels(self._model))
  238 + sim.logFileOpen()
  239 + sim.run()
  240 +
  241 + # Check content of observation
  242 + self._test_observation(sim)
  243 + self._test_list(sim.obs()[0].events(), 261)
  244 +
222 # Return 245 # Return
223 return 246 return
224 247