From 73586a8dbe70fdf69171ce1d8efc00a5a11a8159 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sun, 22 Feb 2015 16:23:57 +0100 Subject: [PATCH] Add set_obs_bounds() method that queries observation boundaries (emin,emax,rad) in case that those are not provided in the event list. --- pyext/ctool.i | 1 + src/support/ctool.cpp | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/support/ctool.hpp | 1 + 3 files changed, 69 insertions(+), 0 deletions(-) diff --git a/pyext/ctool.i b/pyext/ctool.i index 53f557a..04ddb49 100644 --- a/pyext/ctool.i +++ b/pyext/ctool.i @@ -103,6 +103,7 @@ public: // Protected support methods void set_response(GObservations& obs); void set_obs_response(GCTAObservation* obs); + void set_obs_bounds(GObservations& obs); GSkyDir get_mean_pointing(const GObservations& obs); size_t get_current_rss(void); }; diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index b702e2c..f73bcd7 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -356,6 +356,9 @@ GObservations ctool::get_observations(const bool& get_response) } // endif: response was required + // Set observation boundary parameters (emin, emax, rad) + set_obs_bounds(obs); + // Signal that XML file should be used for storage m_use_xml = true; @@ -805,6 +808,70 @@ void ctool::set_obs_response(GCTAObservation* obs) /***********************************************************************//** + * @brief Set observation boundaries + * + * @param[in,out] obs Observation container + * + ***************************************************************************/ +void ctool::set_obs_bounds(GObservations& obs) +{ + // Setup response for all observations + for (int i = 0; i < obs.size(); ++i) { + + // Is this observation a CTA observation? + GCTAObservation* cta = dynamic_cast(obs[i]); + + // Yes ... + if (cta != NULL) { + + // Get pointer on event list + GCTAEventList* list = const_cast(dynamic_cast(cta->events())); + + // Continue only if it's valid + if (list != NULL) { + + // If there are no energy boundaries then read the user + // parameters and add them + if (list->ebounds().is_empty()) { + + // If there are "emin" and "emax" parameters then use them + if (has_par("emin") && has_par("emax")) { + double emin = (*this)["emin"].real(); + double emax = (*this)["emax"].real(); + GEbounds ebounds(GEnergy(emin, "TeV"), GEnergy(emax, "TeV")); + list->ebounds(ebounds); + } + + } + + // If there is no ROI then read the user parameters and add + // them + if (list->roi().radius() == 0) { + + // If there is a "rad" parameter then use it + if (has_par("rad")) { + double rad = (*this)["rad"].real(); + GCTARoi roi(GCTAInstDir(cta->pointing().dir()), rad); + list->roi(roi); + } + + } + + } // endif: list was valid + + } // endif: observation was CTA + + } // endfor: looped over observations + + + // Return + return; +} + + + + +/***********************************************************************//** * @brief Derives mean pointing from CTA observations * * @param[in] obs Observation container. diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 4df1d71..572da83 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -85,6 +85,7 @@ protected: // Protected support methods void set_response(GObservations& obs); void set_obs_response(GCTAObservation* obs); + void set_obs_bounds(GObservations& obs); GSkyDir get_mean_pointing(const GObservations& obs); size_t get_current_rss(void); -- libgit2 0.21.4