Commit c7a508a50fb0ccd40bb19837f1f285edd0cbbeed

Authored by Michael Mayer
1 parent 4dc6a2e5

Added functionality to read energy boundaries from IRF Fits file as well from ob…

…servation definition XML files
inst/cta/include/GCTAObservation.hpp
... ... @@ -120,6 +120,8 @@ public:
120 120 void eventfile(const std::string& filename);
121 121 const std::string& eventfile(void) const;
122 122 void dispose_events(void);
  123 + double lo_user_thres(void) const;
  124 + double hi_user_thres(void) const;
123 125  
124 126 protected:
125 127 // Protected methods
... ... @@ -143,6 +145,10 @@ protected:
143 145 double m_ra_obj; //!< Right Ascension of object (degrees)
144 146 double m_dec_obj; //!< Declination of object (degrees)
145 147  
  148 + // User defined energy thresholds
  149 + double m_lo_user_thres; //!< user defined lower energy threshold
  150 + double m_hi_user_thres; //!< user defined upper energy boundary
  151 +
146 152 // Special protected member for GCTAModelCubeBackground friend
147 153 std::string m_bgdfile; //!< Background filename
148 154 };
... ... @@ -387,4 +393,30 @@ const std::string&amp; GCTAObservation::eventfile(void) const
387 393 return m_eventfile;
388 394 }
389 395  
  396 +
  397 +/***********************************************************************//**
  398 + * @brief Return low energy threshold from IRF
  399 + *
  400 + * @return return low energy threshold
  401 + ***************************************************************************/
  402 +inline
  403 +double GCTAObservation::lo_user_thres(void) const
  404 +{
  405 + return m_lo_user_thres;
  406 +}
  407 +
  408 +/***********************************************************************//**
  409 + * @brief Return high energy threshold from IRF
  410 + *
  411 + * @return return low energy threshold
  412 + ***************************************************************************/
  413 +inline
  414 +double GCTAObservation::hi_user_thres(void) const
  415 +{
  416 + return m_hi_user_thres;
  417 +}
  418 +
  419 +
  420 +
  421 +
390 422 #endif /* GCTAOBSERVATION_HPP */
... ...
inst/cta/include/GCTAResponse.hpp
... ... @@ -93,6 +93,7 @@ protected:
93 93 const GObservation& obs) const;
94 94 const GCTAInstDir& retrieve_dir(const std::string& origin,
95 95 const GEvent& event) const;
  96 +
96 97 };
97 98  
98 99 #endif /* GCTARESPONSE_HPP */
... ...
inst/cta/include/GCTAResponseIrf.hpp
... ... @@ -128,6 +128,9 @@ public:
128 128 const GCTABackground* background(void) const;
129 129 void background(GCTABackground* background);
130 130  
  131 + double lo_save_thres(void) const;
  132 + double hi_save_thres(void) const;
  133 +
131 134 // Low-level response methods
132 135 double aeff(const double& theta,
133 136 const double& phi,
... ... @@ -178,6 +181,10 @@ private:
178 181 GCTABackground* m_background; //!< Energy dispersion
179 182 mutable bool m_apply_edisp; //!< Apply energy dispersion
180 183  
  184 + // Energy thresholds
  185 + double m_lo_save_thres;//!< save energy threshold
  186 + double m_hi_save_thres;//!< save maximum energy
  187 +
181 188 // XML response filename
182 189 std::string m_xml_caldb; //!< Calibration database string in XML file
183 190 std::string m_xml_rspname; //!< Response name in XML file
... ... @@ -398,4 +405,28 @@ void GCTAResponseIrf::background(GCTABackground* background)
398 405 return;
399 406 }
400 407  
  408 +/***********************************************************************//**
  409 + * @brief Return low energy threshold from IRF
  410 + *
  411 + * @return return low energy threshold
  412 + ***************************************************************************/
  413 +inline
  414 +double GCTAResponseIrf::lo_save_thres(void) const
  415 +{
  416 + return m_lo_save_thres;
  417 +}
  418 +
  419 +/***********************************************************************//**
  420 + * @brief Return high energy threshold from IRF
  421 + *
  422 + * @return return low energy threshold
  423 + ***************************************************************************/
  424 +inline
  425 +double GCTAResponseIrf::hi_save_thres(void) const
  426 +{
  427 + return m_hi_save_thres;
  428 +}
  429 +
  430 +
  431 +
401 432 #endif /* GCTARESPONSEIRF_HPP */
... ...
inst/cta/src/GCTAObservation.cpp
... ... @@ -652,6 +652,17 @@ void GCTAObservation::read(const GXmlElement&amp; xml)
652 652  
653 653 // Extract instrument name
654 654 m_instrument = xml.attribute("instrument");
  655 +// m_name = xml.attribute("name");
  656 +// m_id = xml.attribute("id");
  657 +
  658 + // Read in user defined energy boundaries of this observation
  659 + if (xml.attribute("emin") != "") {
  660 + m_lo_user_thres = gammalib::todouble(xml.attribute("emin"));
  661 + }
  662 +
  663 + if (xml.attribute("emax") != "") {
  664 + m_hi_user_thres = gammalib::todouble(xml.attribute("emax"));
  665 + }
655 666  
656 667 // Determine number of parameter nodes in XML element
657 668 int npars = xml.elements("parameter");
... ... @@ -813,6 +824,13 @@ void GCTAObservation::write(GXmlElement&amp; xml) const
813 824 throw GException::invalid_value(G_WRITE, msg);
814 825 }
815 826  
  827 + if (m_lo_user_thres > 0.0) {
  828 + xml.attribute("emin",gammalib::str(m_lo_user_thres));
  829 + }
  830 + if (m_hi_user_thres > 0.0) {
  831 + xml.attribute("emax",gammalib::str(m_hi_user_thres));
  832 + }
  833 +
816 834 // If XML element has 0 nodes then add the required parameter nodes
817 835 if (xml.elements() == 0) {
818 836 std::string text = "parameter name=\""+m_eventtype+"\"";
... ... @@ -1033,6 +1051,7 @@ void GCTAObservation::load(const std::string&amp; cntcube,
1033 1051 ***************************************************************************/
1034 1052 void GCTAObservation::save(const std::string& filename, const bool& clobber) const
1035 1053 {
  1054 +
1036 1055 // Create FITS file
1037 1056 GFits fits;
1038 1057  
... ... @@ -1227,6 +1246,8 @@ void GCTAObservation::init_members(void)
1227 1246 m_deadc = 0.0;
1228 1247 m_ra_obj = 0.0;
1229 1248 m_dec_obj = 0.0;
  1249 + m_lo_user_thres = 0.0;
  1250 + m_hi_user_thres = 0.0;
1230 1251  
1231 1252 // Return
1232 1253 return;
... ... @@ -1252,6 +1273,8 @@ void GCTAObservation::copy_members(const GCTAObservation&amp; obs)
1252 1273 m_deadc = obs.m_deadc;
1253 1274 m_ra_obj = obs.m_ra_obj;
1254 1275 m_dec_obj = obs.m_dec_obj;
  1276 + m_lo_user_thres = obs.m_lo_user_thres;
  1277 + m_hi_user_thres = obs.m_hi_user_thres;
1255 1278  
1256 1279 // Clone members
1257 1280 m_response = (obs.m_response != NULL) ? obs.m_response->clone() : NULL;
... ...
inst/cta/src/GCTAResponseIrf.cpp
... ... @@ -948,6 +948,17 @@ void GCTAResponseIrf::load_aeff(const std::string&amp; filename)
948 948 // If file contains an "EFFECTIVE AREA" extension then load it
949 949 // as CTA response table
950 950 if (file.contains("EFFECTIVE AREA")) {
  951 +
  952 + const GFitsHDU* hdu = file.at("EFFECTIVE AREA");
  953 +
  954 + // Read save energy threshold if available
  955 + if (hdu->has_card("LO_THRES")) {
  956 + m_lo_save_thres = hdu->real("LO_THRES");
  957 + }
  958 + if (hdu->has_card("HI_THRES")) {
  959 + m_hi_save_thres = hdu->real("HI_THRES");
  960 + }
  961 +
951 962 file.close();
952 963 m_aeff = new GCTAAeff2D(filename);
953 964 }
... ... @@ -955,6 +966,17 @@ void GCTAResponseIrf::load_aeff(const std::string&amp; filename)
955 966 // ... else if file contains a "SPECRESP" extension then load it
956 967 // as ARF
957 968 else if (file.contains("SPECRESP")) {
  969 +
  970 + const GFitsHDU* hdu = file.at("SPECRESP");
  971 +
  972 + // Read save energy threshold if available
  973 + if (hdu->has_card("LO_THRES")) {
  974 + m_lo_save_thres = file["SPECRESP"]->real("LO_THRES");
  975 + }
  976 + if (hdu->has_card("LO_THRES")) {
  977 + m_hi_save_thres = file["SPECRESP"]->real("HI_THRES");
  978 + }
  979 +
958 980 file.close();
959 981 m_aeff = new GCTAAeffArf(filename);
960 982 }
... ... @@ -2911,6 +2933,10 @@ void GCTAResponseIrf::init_members(void)
2911 2933 m_background = NULL;
2912 2934 m_apply_edisp = false; //!< Switched off by default
2913 2935  
  2936 + // Energy thresholds
  2937 + m_lo_save_thres = 0.0;
  2938 + m_hi_save_thres = 0.0;
  2939 +
2914 2940 // XML response filenames
2915 2941 m_xml_caldb.clear();
2916 2942 m_xml_rspname.clear();
... ... @@ -2942,6 +2968,10 @@ void GCTAResponseIrf::copy_members(const GCTAResponseIrf&amp; rsp)
2942 2968 m_rspname = rsp.m_rspname;
2943 2969 m_apply_edisp = rsp.m_apply_edisp;
2944 2970  
  2971 + // Copy energy thresholds
  2972 + m_lo_save_thres = rsp.m_lo_save_thres;
  2973 + m_hi_save_thres = rsp.m_hi_save_thres;
  2974 +
2945 2975 // Copy response filenames
2946 2976 m_xml_caldb = rsp.m_xml_caldb;
2947 2977 m_xml_rspname = rsp.m_xml_rspname;
... ...
src/obs/GObservations.cpp
... ... @@ -646,7 +646,7 @@ void GObservations::write(GXml&amp; xml) const
646 646  
647 647 // Write all observations into library
648 648 for (int i = 0; i < size(); ++i) {
649   -
  649 +
650 650 // Initialise pointer on observation
651 651 GXmlElement* obs = NULL;
652 652  
... ... @@ -670,7 +670,7 @@ void GObservations::write(GXml&amp; xml) const
670 670 obs->attribute("id", m_obs[i]->id());
671 671 obs->attribute("instrument", m_obs[i]->instrument());
672 672 }
673   -
  673 +
674 674 // Write now observation
675 675 m_obs[i]->write(*obs);
676 676  
... ...