Commit 6f4762d72678a3a7615a0b06e9cd788ed26ccda5

Authored by Jürgen Knödlseder
1 parent c7a508a5

Integrate code.

ChangeLog
1   -2014-10-31 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
  1 +2014-11-07 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
2 2  
3 3 * Version 0.9.0 released
4 4 ========================
... ... @@ -34,6 +34,7 @@
34 34 Introduce class codes to avoid dynamic type casting
35 35 Remove error computation from optimization
36 36 Add GOptimize::errors() method for error computation
  37 + Add support for user and save CTA energy thresholds
37 38 Several bug corrections
38 39  
39 40  
... ...
... ... @@ -2,7 +2,7 @@ New Features and Important Changes in GammaLib 00-09-00
2 2  
3 3 Author(s) : Juergen Knoedlseder
4 4  
5   -31 October 2014
  5 +7 November 2014
6 6  
7 7  
8 8 1. Introduction
... ... @@ -307,6 +307,11 @@ Events are now only loaded when needed into GCTAObservation. This reduces memory
307 307 the usage. The method dispose_events() has been added to explicitely allow the
308 308 disposal of the events.
309 309  
  310 +Support for user provided energy thresholds and save energy thresholds has been
  311 +implemented. Save energy thresholds will be extracted from the LO_THRES and
  312 +HI_THRES keywords if they are present in the effective area response FITS
  313 +file. The user may supply energy thresholds in the XML file.
  314 +
310 315  
311 316 21. COMPTEL interface
312 317 ---------------------
... ...
inst/cta/include/GCTAObservation.hpp
... ... @@ -120,8 +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 + const double& lo_user_thres(void) const;
  124 + const double& hi_user_thres(void) const;
125 125  
126 126 protected:
127 127 // Protected methods
... ... @@ -133,21 +133,19 @@ protected:
133 133 void set_event_type(void);
134 134  
135 135 // Protected members
136   - std::string m_instrument; //!< Instrument name
137   - std::string m_eventfile; //!< Event filename
138   - std::string m_eventtype; //!< Event type (for XML file)
139   - GCTAResponse* m_response; //!< Pointer to instrument response functions
140   - GCTAPointing m_pointing; //!< Pointing direction
141   - int m_obs_id; //!< Observation ID
142   - double m_ontime; //!< Ontime (seconds)
143   - double m_livetime; //!< Livetime (seconds)
144   - double m_deadc; //!< Deadtime correction (livetime/ontime)
145   - double m_ra_obj; //!< Right Ascension of object (degrees)
146   - double m_dec_obj; //!< Declination of object (degrees)
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
  136 + std::string m_instrument; //!< Instrument name
  137 + std::string m_eventfile; //!< Event filename
  138 + std::string m_eventtype; //!< Event type (for XML file)
  139 + GCTAResponse* m_response; //!< Pointer to instrument response functions
  140 + GCTAPointing m_pointing; //!< Pointing direction
  141 + int m_obs_id; //!< Observation ID
  142 + double m_ontime; //!< Ontime (seconds)
  143 + double m_livetime; //!< Livetime (seconds)
  144 + double m_deadc; //!< Deadtime correction (livetime/ontime)
  145 + double m_ra_obj; //!< Right Ascension of object (degrees)
  146 + double m_dec_obj; //!< Declination of object (degrees)
  147 + double m_lo_user_thres; //!< User defined lower energy threshold
  148 + double m_hi_user_thres; //!< User defined upper energy boundary
151 149  
152 150 // Special protected member for GCTAModelCubeBackground friend
153 151 std::string m_bgdfile; //!< Background filename
... ... @@ -395,23 +393,23 @@ const std::string&amp; GCTAObservation::eventfile(void) const
395 393  
396 394  
397 395 /***********************************************************************//**
398   - * @brief Return low energy threshold from IRF
  396 + * @brief Return user low energy threshold
399 397 *
400   - * @return return low energy threshold
  398 + * @return User low energy threshold.
401 399 ***************************************************************************/
402 400 inline
403   -double GCTAObservation::lo_user_thres(void) const
  401 +const double& GCTAObservation::lo_user_thres(void) const
404 402 {
405 403 return m_lo_user_thres;
406 404 }
407 405  
408 406 /***********************************************************************//**
409   - * @brief Return high energy threshold from IRF
  407 + * @brief Return user high energy threshold
410 408 *
411   - * @return return low energy threshold
  409 + * @return User high energy threshold.
412 410 ***************************************************************************/
413 411 inline
414   -double GCTAObservation::hi_user_thres(void) const
  412 +const double& GCTAObservation::hi_user_thres(void) const
415 413 {
416 414 return m_hi_user_thres;
417 415 }
... ...
inst/cta/include/GCTAResponseIrf.hpp
... ... @@ -127,9 +127,8 @@ public:
127 127 void edisp(GCTAEdisp* edisp);
128 128 const GCTABackground* background(void) const;
129 129 void background(GCTABackground* background);
130   -
131   - double lo_save_thres(void) const;
132   - double hi_save_thres(void) const;
  130 + const double& lo_save_thres(void) const;
  131 + const double& hi_save_thres(void) const;
133 132  
134 133 // Low-level response methods
135 134 double aeff(const double& theta,
... ... @@ -180,10 +179,8 @@ private:
180 179 GCTAEdisp* m_edisp; //!< Energy dispersion
181 180 GCTABackground* m_background; //!< Energy dispersion
182 181 mutable bool m_apply_edisp; //!< Apply energy dispersion
183   -
184   - // Energy thresholds
185   - double m_lo_save_thres;//!< save energy threshold
186   - double m_hi_save_thres;//!< save maximum energy
  182 + double m_lo_save_thres; //!< Save low energy threshold
  183 + double m_hi_save_thres; //!< Save high energy threshold
187 184  
188 185 // XML response filename
189 186 std::string m_xml_caldb; //!< Calibration database string in XML file
... ... @@ -408,10 +405,10 @@ void GCTAResponseIrf::background(GCTABackground* background)
408 405 /***********************************************************************//**
409 406 * @brief Return low energy threshold from IRF
410 407 *
411   - * @return return low energy threshold
  408 + * @return Low energy threshold from IRF.
412 409 ***************************************************************************/
413 410 inline
414   -double GCTAResponseIrf::lo_save_thres(void) const
  411 +const double& GCTAResponseIrf::lo_save_thres(void) const
415 412 {
416 413 return m_lo_save_thres;
417 414 }
... ... @@ -419,14 +416,12 @@ double GCTAResponseIrf::lo_save_thres(void) const
419 416 /***********************************************************************//**
420 417 * @brief Return high energy threshold from IRF
421 418 *
422   - * @return return low energy threshold
  419 + * @return High energy threshold from IRF.
423 420 ***************************************************************************/
424 421 inline
425   -double GCTAResponseIrf::hi_save_thres(void) const
  422 +const double& GCTAResponseIrf::hi_save_thres(void) const
426 423 {
427 424 return m_hi_save_thres;
428 425 }
429 426  
430   -
431   -
432 427 #endif /* GCTARESPONSEIRF_HPP */
... ...
inst/cta/pyext/GCTAObservation.i
... ... @@ -93,6 +93,8 @@ public:
93 93 void eventfile(const std::string& filename);
94 94 const std::string& eventfile(void) const;
95 95 void dispose_events(void);
  96 + const double& lo_user_thres(void) const;
  97 + const double& hi_user_thres(void) const;
96 98 };
97 99  
98 100  
... ...
inst/cta/src/GCTAObservation.cpp
... ... @@ -638,7 +638,10 @@ GEbounds GCTAObservation::ebounds(void) const
638 638 * ...
639 639 * </observation>
640 640 *
641   - * for a binned observation.
  641 + * for a binned observation. Optional user energy thresholds can be
  642 + * specified by adding the emin and emax attributes:
  643 + *
  644 + * <observation name="..." id="..." instrument="..." emin="..." emax="...">
642 645 *
643 646 * The method does no load the events into memory but stores the file name
644 647 * of the event file. The events are only loaded when required. This reduces
... ... @@ -652,14 +655,11 @@ void GCTAObservation::read(const GXmlElement&amp; xml)
652 655  
653 656 // Extract instrument name
654 657 m_instrument = xml.attribute("instrument");
655   -// m_name = xml.attribute("name");
656   -// m_id = xml.attribute("id");
657 658  
658 659 // Read in user defined energy boundaries of this observation
659 660 if (xml.attribute("emin") != "") {
660 661 m_lo_user_thres = gammalib::todouble(xml.attribute("emin"));
661 662 }
662   -
663 663 if (xml.attribute("emax") != "") {
664 664 m_hi_user_thres = gammalib::todouble(xml.attribute("emax"));
665 665 }
... ... @@ -804,7 +804,12 @@ void GCTAObservation::read(const GXmlElement&amp; xml)
804 804 * ...
805 805 * </observation>
806 806 *
807   - * for a binned observation.
  807 + * for a binned observation. If user energy threshold are defined (i.e.
  808 + * threshold values are >0) the additional emin and emax attributes will
  809 + * be written to the file:
  810 + *
  811 + * <observation name="..." id="..." instrument="..." emin="..." emax="...">
  812 + *
808 813 ***************************************************************************/
809 814 void GCTAObservation::write(GXmlElement& xml) const
810 815 {
... ... @@ -824,11 +829,12 @@ void GCTAObservation::write(GXmlElement&amp; xml) const
824 829 throw GException::invalid_value(G_WRITE, msg);
825 830 }
826 831  
  832 + // Add user energy threshold attributes (if set)
827 833 if (m_lo_user_thres > 0.0) {
828   - xml.attribute("emin",gammalib::str(m_lo_user_thres));
  834 + xml.attribute("emin", gammalib::str(m_lo_user_thres));
829 835 }
830 836 if (m_hi_user_thres > 0.0) {
831   - xml.attribute("emax",gammalib::str(m_hi_user_thres));
  837 + xml.attribute("emax", gammalib::str(m_hi_user_thres));
832 838 }
833 839  
834 840 // If XML element has 0 nodes then add the required parameter nodes
... ... @@ -1192,6 +1198,28 @@ std::string GCTAObservation::print(const GChatter&amp; chatter) const
1192 1198 result.append("\n"+gammalib::parformat("Deadtime correction"));
1193 1199 result.append(gammalib::str(m_deadc));
1194 1200  
  1201 + // Append user energy threshold information
  1202 + result.append("\n"+gammalib::parformat("User energy range"));
  1203 + if (m_lo_user_thres > 0.0 && m_hi_user_thres) {
  1204 + result.append(gammalib::str(m_lo_user_thres));
  1205 + result.append(" - ");
  1206 + result.append(gammalib::str(m_hi_user_thres));
  1207 + result.append(" TeV");
  1208 + }
  1209 + else if (m_lo_user_thres > 0.0) {
  1210 + result.append("> ");
  1211 + result.append(gammalib::str(m_lo_user_thres));
  1212 + result.append(" TeV");
  1213 + }
  1214 + else if (m_hi_user_thres > 0.0) {
  1215 + result.append("< ");
  1216 + result.append(gammalib::str(m_hi_user_thres));
  1217 + result.append(" TeV");
  1218 + }
  1219 + else {
  1220 + result.append("undefined");
  1221 + }
  1222 +
1195 1223 // Append detailed information
1196 1224 GChatter reduced_chatter = gammalib::reduce(chatter);
1197 1225 if (reduced_chatter > SILENT) {
... ... @@ -1240,12 +1268,12 @@ void GCTAObservation::init_members(void)
1240 1268 m_bgdfile.clear();
1241 1269 m_response = NULL;
1242 1270 m_pointing.clear();
1243   - m_obs_id = 0;
1244   - m_ontime = 0.0;
1245   - m_livetime = 0.0;
1246   - m_deadc = 0.0;
1247   - m_ra_obj = 0.0;
1248   - m_dec_obj = 0.0;
  1271 + m_obs_id = 0;
  1272 + m_ontime = 0.0;
  1273 + m_livetime = 0.0;
  1274 + m_deadc = 0.0;
  1275 + m_ra_obj = 0.0;
  1276 + m_dec_obj = 0.0;
1249 1277 m_lo_user_thres = 0.0;
1250 1278 m_hi_user_thres = 0.0;
1251 1279  
... ... @@ -1262,17 +1290,17 @@ void GCTAObservation::init_members(void)
1262 1290 void GCTAObservation::copy_members(const GCTAObservation& obs)
1263 1291 {
1264 1292 // Copy members
1265   - m_instrument = obs.m_instrument;
1266   - m_eventfile = obs.m_eventfile;
1267   - m_eventtype = obs.m_eventtype;
1268   - m_bgdfile = obs.m_bgdfile;
1269   - m_pointing = obs.m_pointing;
1270   - m_obs_id = obs.m_obs_id;
1271   - m_ontime = obs.m_ontime;
1272   - m_livetime = obs.m_livetime;
1273   - m_deadc = obs.m_deadc;
1274   - m_ra_obj = obs.m_ra_obj;
1275   - m_dec_obj = obs.m_dec_obj;
  1293 + m_instrument = obs.m_instrument;
  1294 + m_eventfile = obs.m_eventfile;
  1295 + m_eventtype = obs.m_eventtype;
  1296 + m_bgdfile = obs.m_bgdfile;
  1297 + m_pointing = obs.m_pointing;
  1298 + m_obs_id = obs.m_obs_id;
  1299 + m_ontime = obs.m_ontime;
  1300 + m_livetime = obs.m_livetime;
  1301 + m_deadc = obs.m_deadc;
  1302 + m_ra_obj = obs.m_ra_obj;
  1303 + m_dec_obj = obs.m_dec_obj;
1276 1304 m_lo_user_thres = obs.m_lo_user_thres;
1277 1305 m_hi_user_thres = obs.m_hi_user_thres;
1278 1306  
... ...
inst/cta/src/GCTAResponseIrf.cpp
... ... @@ -949,9 +949,10 @@ void GCTAResponseIrf::load_aeff(const std::string&amp; filename)
949 949 // as CTA response table
950 950 if (file.contains("EFFECTIVE AREA")) {
951 951  
  952 + // Get HDU
952 953 const GFitsHDU* hdu = file.at("EFFECTIVE AREA");
953 954  
954   - // Read save energy threshold if available
  955 + // Read save energy thresholds if available
955 956 if (hdu->has_card("LO_THRES")) {
956 957 m_lo_save_thres = hdu->real("LO_THRES");
957 958 }
... ... @@ -959,26 +960,35 @@ void GCTAResponseIrf::load_aeff(const std::string&amp; filename)
959 960 m_hi_save_thres = hdu->real("HI_THRES");
960 961 }
961 962  
  963 + // Close file
962 964 file.close();
  965 +
  966 + // Allocate Aeff from file
963 967 m_aeff = new GCTAAeff2D(filename);
  968 +
964 969 }
965 970  
966 971 // ... else if file contains a "SPECRESP" extension then load it
967 972 // as ARF
968 973 else if (file.contains("SPECRESP")) {
969 974  
  975 + // Get HDU
970 976 const GFitsHDU* hdu = file.at("SPECRESP");
971 977  
972   - // Read save energy threshold if available
  978 + // Read save energy thresholds if available
973 979 if (hdu->has_card("LO_THRES")) {
974   - m_lo_save_thres = file["SPECRESP"]->real("LO_THRES");
  980 + m_lo_save_thres = hdu->real("LO_THRES");
975 981 }
976 982 if (hdu->has_card("LO_THRES")) {
977   - m_hi_save_thres = file["SPECRESP"]->real("HI_THRES");
  983 + m_hi_save_thres = hdu->real("HI_THRES");
978 984 }
979 985  
  986 + // Close file
980 987 file.close();
  988 +
  989 + // Allocate Aeff from file
981 990 m_aeff = new GCTAAeffArf(filename);
  991 +
982 992 }
983 993  
984 994 }
... ... @@ -1243,6 +1253,28 @@ std::string GCTAResponseIrf::print(const GChatter&amp; chatter) const
1243 1253 }
1244 1254 }
1245 1255  
  1256 + // Append save energy threshold information
  1257 + result.append("\n"+gammalib::parformat("Save energy range"));
  1258 + if (m_lo_save_thres > 0.0 && m_hi_save_thres) {
  1259 + result.append(gammalib::str(m_lo_save_thres));
  1260 + result.append(" - ");
  1261 + result.append(gammalib::str(m_hi_save_thres));
  1262 + result.append(" TeV");
  1263 + }
  1264 + else if (m_lo_save_thres > 0.0) {
  1265 + result.append("> ");
  1266 + result.append(gammalib::str(m_lo_save_thres));
  1267 + result.append(" TeV");
  1268 + }
  1269 + else if (m_hi_save_thres > 0.0) {
  1270 + result.append("< ");
  1271 + result.append(gammalib::str(m_hi_save_thres));
  1272 + result.append(" TeV");
  1273 + }
  1274 + else {
  1275 + result.append("undefined");
  1276 + }
  1277 +
1246 1278 // Append calibration database
1247 1279 result.append("\n"+m_caldb.print(chatter));
1248 1280  
... ... @@ -2927,13 +2959,11 @@ void GCTAResponseIrf::init_members(void)
2927 2959 // Initialise members
2928 2960 m_caldb.clear();
2929 2961 m_rspname.clear();
2930   - m_aeff = NULL;
2931   - m_psf = NULL;
2932   - m_edisp = NULL;
2933   - m_background = NULL;
2934   - m_apply_edisp = false; //!< Switched off by default
2935   -
2936   - // Energy thresholds
  2962 + m_aeff = NULL;
  2963 + m_psf = NULL;
  2964 + m_edisp = NULL;
  2965 + m_background = NULL;
  2966 + m_apply_edisp = false; //!< Switched off by default
2937 2967 m_lo_save_thres = 0.0;
2938 2968 m_hi_save_thres = 0.0;
2939 2969  
... ... @@ -2964,11 +2994,9 @@ void GCTAResponseIrf::init_members(void)
2964 2994 void GCTAResponseIrf::copy_members(const GCTAResponseIrf& rsp)
2965 2995 {
2966 2996 // Copy members
2967   - m_caldb = rsp.m_caldb;
2968   - m_rspname = rsp.m_rspname;
2969   - m_apply_edisp = rsp.m_apply_edisp;
2970   -
2971   - // Copy energy thresholds
  2997 + m_caldb = rsp.m_caldb;
  2998 + m_rspname = rsp.m_rspname;
  2999 + m_apply_edisp = rsp.m_apply_edisp;
2972 3000 m_lo_save_thres = rsp.m_lo_save_thres;
2973 3001 m_hi_save_thres = rsp.m_hi_save_thres;
2974 3002  
... ...