diff --git a/ChangeLog b/ChangeLog index af6a7c0..561de1e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,13 +1,15 @@ -2018-01-09 +2018-01-12 * Version 1.5.0 released ========================= - Set reference time to CTA reference time in GCTAEventcube, GCTAEventList and GCTACubeExposure (#2295) + Set reference time to CTA reference time in GCTAEventcube, GCTAEventList and + GCTACubeExposure (#2295) Add GPha::counts_spectrum() and GPha::backscal_spectrum() methods (#2290) Add GNdarray sign(), operator*= and operator/= (#2290) Add GSkyMap::counts() and GSkyMap::flux() methods and clip() friend operator (#2290) Add GSkyMap::array() method to Python interface (#2285) + Add Off sky regions to GCTAObservation (#2284) CTA observations handle "statistic" attribute in XML file (#2238) Use CSTAT and CHI2 instead of POISSON and GAUSSIAN for statistic (#2237) Changed GObservation::statistics() to statistic() (#2238) diff --git a/NEWS b/NEWS index a61482d..8536613 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in GammaLib 1.5.0 -9 January 2018 +12 January 2018 1. Introduction @@ -83,6 +83,8 @@ The following methods have been added: - operator*(GRmf&, double&) - operator*(double&, double&) - operator/(GRmf&, double&) +- GCTAObservation::off_regions(GSkyRegions&) +- GCTAObservation::off_regions() - GCTAOnOffObservation(GObservations&) - GCTAOnOffObservation(GPha&, GPha&, GArf&, GRmf&) - GCOMInstDir(GSkyDir&, double&) @@ -246,6 +248,11 @@ also position fitting is now possible for Fermi-LAT (#604, #2183). Set the Good Time Interval time reference to the CTA time reference in GCTAEventList, GCTAEventCube and GCTACubeExposure (#2295). +Add Off sky regions attribute to the GCTAObservation class. The Off sky regions +can be set and accessed using the GCTAObservation::off_regions() method. The +Off regions filename is also read from and written into the observation +definition XML file (#2284). + GCTAObservation and GCTAOnOffObservation handle statistic attribute in XML file (#2238). diff --git a/doc/source/admin/release_history/1.5.rst b/doc/source/admin/release_history/1.5.rst index 2a7caf3..2760b61 100644 --- a/doc/source/admin/release_history/1.5.rst +++ b/doc/source/admin/release_history/1.5.rst @@ -39,6 +39,8 @@ Improvements and ``GPha::counts_spectrum()`` and ``GPha::backscal_spectrum()`` methods * [`2285 `_] - Add ``GSkyMap::array()`` method to Python interface +* [`2284 `_] - + Add Off sky regions to ``GCTAObservation`` * [`2238 `_] - ``GCTAObservation`` and ``GCTAOnOffObservation`` handle ``statistic`` attribute in XML file * [`2231 `_] - diff --git a/inst/cta/include/GCTAObservation.hpp b/inst/cta/include/GCTAObservation.hpp index f274bfc..8bfcb80 100644 --- a/inst/cta/include/GCTAObservation.hpp +++ b/inst/cta/include/GCTAObservation.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAObservation.hpp - CTA Observation class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -31,6 +31,7 @@ #include #include "GFilename.hpp" #include "GObservation.hpp" +#include "GSkyRegions.hpp" #include "GCTAResponse.hpp" #include "GCTAPointing.hpp" #include "GCTAEventList.hpp" @@ -126,6 +127,8 @@ public: const GCTACubeBackground& bkgcube); void pointing(const GCTAPointing& pointing); const GCTAPointing& pointing(void) const; + void off_regions(const GSkyRegions& off_regions); + const GSkyRegions& off_regions(void) const; GCTARoi roi(void) const; GGti gti(void) const; GEbounds ebounds(void) const; @@ -162,6 +165,7 @@ protected: GFilename m_eventfile; //!< Event filename GCTAResponse* m_response; //!< Pointer to instrument response functions GCTAPointing m_pointing; //!< Pointing direction + GSkyRegions m_off_regions; //!< Off regions int m_obs_id; //!< Observation ID double m_ontime; //!< Ontime (seconds) double m_livetime; //!< Livetime (seconds) @@ -297,6 +301,31 @@ void GCTAObservation::pointing(const GCTAPointing& pointing) /***********************************************************************//** + * @brief Return sky off regions + * + * @return Sky off regions + ***************************************************************************/ +inline +const GSkyRegions& GCTAObservation::off_regions(void) const +{ + return m_off_regions; +} + + +/***********************************************************************//** + * @brief Set sky off regions + * + * @param[in] off_regions Sky off regions. + ***************************************************************************/ +inline +void GCTAObservation::off_regions(const GSkyRegions& off_regions) +{ + m_off_regions = off_regions; + return; +} + + +/***********************************************************************//** * @brief Set CTA observation object name * * @param[in] object Object name. diff --git a/inst/cta/pyext/GCTAObservation.i b/inst/cta/pyext/GCTAObservation.i index c74d4ad..2183416 100644 --- a/inst/cta/pyext/GCTAObservation.i +++ b/inst/cta/pyext/GCTAObservation.i @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAObservation.i - CTA Observation class interface * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2016 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -94,6 +94,8 @@ public: const GCTACubeBackground& bkgcube); void pointing(const GCTAPointing& pointing); const GCTAPointing& pointing(void) const; + void off_regions(const GSkyRegions& off_regions); + const GSkyRegions& off_regions(void) const; GCTARoi roi(void) const; GGti gti(void) const; GEbounds ebounds(void) const; diff --git a/inst/cta/src/GCTAObservation.cpp b/inst/cta/src/GCTAObservation.cpp index 7322c10..87c8245 100644 --- a/inst/cta/src/GCTAObservation.cpp +++ b/inst/cta/src/GCTAObservation.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GCTAObservation.cpp - CTA Observation class * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -728,6 +728,18 @@ void GCTAObservation::read(const GXmlElement& xml) } + // Read Off regions + else if (par->attribute("name") == "OffRegions") { + + // Read off regions file name + std::string filename = gammalib::xml_file_expand(xml, + par->attribute("file")); + + // Load off regions + m_off_regions = GSkyRegions(filename); + + } + } // endfor: looped over observation parameters // Analyse parameters @@ -1016,6 +1028,13 @@ void GCTAObservation::write(GXmlElement& xml) const m_response->write(xml); } + // Write Off regions filename + if (!m_off_regions.filename().is_empty()) { + GXmlElement* par = gammalib::xml_need_par(G_WRITE, xml, "OffRegions"); + par->attribute("file", gammalib::xml_file_reduce(xml, + m_off_regions.filename().url())); + } + // Return return; } @@ -1509,6 +1528,7 @@ void GCTAObservation::init_members(void) m_bgdfile.clear(); m_response = NULL; m_pointing.clear(); + m_off_regions.clear(); m_obs_id = 0; m_ontime = 0.0; m_livetime = 0.0; @@ -1537,6 +1557,7 @@ void GCTAObservation::copy_members(const GCTAObservation& obs) m_eventfile = obs.m_eventfile; m_bgdfile = obs.m_bgdfile; m_pointing = obs.m_pointing; + m_off_regions = obs.m_off_regions; m_obs_id = obs.m_obs_id; m_ontime = obs.m_ontime; m_livetime = obs.m_livetime; diff --git a/inst/cta/test/test_CTA.cpp b/inst/cta/test/test_CTA.cpp index 42d67e2..ceb1247 100644 --- a/inst/cta/test/test_CTA.cpp +++ b/inst/cta/test/test_CTA.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * test_CTA.cpp - Test CTA classes * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2017 by Juergen Knoedlseder * + * copyright (C) 2010-2018 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -82,6 +82,7 @@ const std::string cta_stacked_bkgcube = datadir+"/stacked_bkgcube.fits"; /* __ Test files for On/Off analysis _____________________________________ */ const std::string cta_onoff_obs = datadir+"/onoff_obs.xml"; const std::string cta_onoff_model = datadir+"/onoff_model.xml"; +const std::string cta_onoff_onreg = datadir+"/onoff_region_on.reg"; /***********************************************************************//** @@ -2000,18 +2001,40 @@ void TestGCTAObservation::test_stacked_obs(void) /***********************************************************************//** * @brief Test On/Off observation handling - * - * @todo Unit test to be implemented ***************************************************************************/ void TestGCTAObservation::test_onoff_obs(void) { // Load On/Off observation into container GObservations obs(cta_onoff_obs); - //std::cout << *(obs[0]) << std::endl; // Save observation container into XML file obs.save("test_cta_onoff_obs.xml"); + // Load CTA observations + obs.load(cta_unbin_xml); + + // Setup sky regions + GSkyRegions regions(cta_onoff_onreg); + + // Set and check regions + for (int i = 0; i < obs.size(); ++i) { + static_cast(obs[i])->off_regions(regions); + test_value(static_cast(obs[i])->off_regions().size(), + 1, "Check number of sky regions"); + } + + // Save observation container into XML file + obs.save("test_cta_onoff_obs_regions.xml"); + + // Re-load observation container and check regions + obs.load("test_cta_onoff_obs_regions.xml"); + + // Check regions + for (int i = 0; i < obs.size(); ++i) { + test_value(static_cast(obs[i])->off_regions().size(), + 1, "Check number of sky regions"); + } + // Return return; }