Commit 73586a8dbe70fdf69171ce1d8efc00a5a11a8159

Authored by Jürgen Knödlseder
1 parent 8308d2fb

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
@@ -103,6 +103,7 @@ public: @@ -103,6 +103,7 @@ public:
103 // Protected support methods 103 // Protected support methods
104 void set_response(GObservations& obs); 104 void set_response(GObservations& obs);
105 void set_obs_response(GCTAObservation* obs); 105 void set_obs_response(GCTAObservation* obs);
  106 + void set_obs_bounds(GObservations& obs);
106 GSkyDir get_mean_pointing(const GObservations& obs); 107 GSkyDir get_mean_pointing(const GObservations& obs);
107 size_t get_current_rss(void); 108 size_t get_current_rss(void);
108 }; 109 };
src/support/ctool.cpp
@@ -356,6 +356,9 @@ GObservations ctool::get_observations(const bool& get_response) @@ -356,6 +356,9 @@ GObservations ctool::get_observations(const bool& get_response)
356 356
357 } // endif: response was required 357 } // endif: response was required
358 358
  359 + // Set observation boundary parameters (emin, emax, rad)
  360 + set_obs_bounds(obs);
  361 +
359 // Signal that XML file should be used for storage 362 // Signal that XML file should be used for storage
360 m_use_xml = true; 363 m_use_xml = true;
361 364
@@ -805,6 +808,70 @@ void ctool::set_obs_response(GCTAObservation* obs) @@ -805,6 +808,70 @@ void ctool::set_obs_response(GCTAObservation* obs)
805 808
806 809
807 /***********************************************************************//** 810 /***********************************************************************//**
  811 + * @brief Set observation boundaries
  812 + *
  813 + * @param[in,out] obs Observation container
  814 + *
  815 + ***************************************************************************/
  816 +void ctool::set_obs_bounds(GObservations& obs)
  817 +{
  818 + // Setup response for all observations
  819 + for (int i = 0; i < obs.size(); ++i) {
  820 +
  821 + // Is this observation a CTA observation?
  822 + GCTAObservation* cta = dynamic_cast<GCTAObservation*>(obs[i]);
  823 +
  824 + // Yes ...
  825 + if (cta != NULL) {
  826 +
  827 + // Get pointer on event list
  828 + GCTAEventList* list = const_cast<GCTAEventList*>(dynamic_cast<const GCTAEventList*>(cta->events()));
  829 +
  830 + // Continue only if it's valid
  831 + if (list != NULL) {
  832 +
  833 + // If there are no energy boundaries then read the user
  834 + // parameters and add them
  835 + if (list->ebounds().is_empty()) {
  836 +
  837 + // If there are "emin" and "emax" parameters then use them
  838 + if (has_par("emin") && has_par("emax")) {
  839 + double emin = (*this)["emin"].real();
  840 + double emax = (*this)["emax"].real();
  841 + GEbounds ebounds(GEnergy(emin, "TeV"), GEnergy(emax, "TeV"));
  842 + list->ebounds(ebounds);
  843 + }
  844 +
  845 + }
  846 +
  847 + // If there is no ROI then read the user parameters and add
  848 + // them
  849 + if (list->roi().radius() == 0) {
  850 +
  851 + // If there is a "rad" parameter then use it
  852 + if (has_par("rad")) {
  853 + double rad = (*this)["rad"].real();
  854 + GCTARoi roi(GCTAInstDir(cta->pointing().dir()), rad);
  855 + list->roi(roi);
  856 + }
  857 +
  858 + }
  859 +
  860 + } // endif: list was valid
  861 +
  862 + } // endif: observation was CTA
  863 +
  864 + } // endfor: looped over observations
  865 +
  866 +
  867 + // Return
  868 + return;
  869 +}
  870 +
  871 +
  872 +
  873 +
  874 +/***********************************************************************//**
808 * @brief Derives mean pointing from CTA observations 875 * @brief Derives mean pointing from CTA observations
809 * 876 *
810 * @param[in] obs Observation container. 877 * @param[in] obs Observation container.
src/support/ctool.hpp
@@ -85,6 +85,7 @@ protected: @@ -85,6 +85,7 @@ protected:
85 // Protected support methods 85 // Protected support methods
86 void set_response(GObservations& obs); 86 void set_response(GObservations& obs);
87 void set_obs_response(GCTAObservation* obs); 87 void set_obs_response(GCTAObservation* obs);
  88 + void set_obs_bounds(GObservations& obs);
88 GSkyDir get_mean_pointing(const GObservations& obs); 89 GSkyDir get_mean_pointing(const GObservations& obs);
89 size_t get_current_rss(void); 90 size_t get_current_rss(void);
90 91