Commit 47e4904f8ca284ac9c97b679b00996d465ee3f1d

Authored by Jürgen Knödlseder
1 parent d664295a

Add C++ unit test for CTA On/Off fitting

inst/cta/test/data/onoff_arf.fits 0 → 100644
No preview for this file type
inst/cta/test/data/onoff_obs.xml 0 → 100644
  1 +<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2 +<observation_list title="observation list">
  3 + <observation name="Crab" id="00001" instrument="CTAOnOff">
  4 + <parameter name="Pha_on" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_pha_on.fits" />
  5 + <parameter name="Pha_off" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_pha_off.fits" />
  6 + <parameter name="Regions_on" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_region_on.reg" />
  7 + <parameter name="Regions_off" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_region_off.reg" />
  8 + <parameter name="Arf" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_arf.fits" />
  9 + <parameter name="Rmf" file="$(PACKAGE_SOURCE)/inst/cta/test/data/onoff_rmf.fits" />
  10 + </observation>
  11 +</observation_list>
... ...
inst/cta/test/data/onoff_pha_off.fits 0 → 100644
No preview for this file type
inst/cta/test/data/onoff_pha_on.fits 0 → 100644
No preview for this file type
inst/cta/test/data/onoff_region_off.reg 0 → 100644
  1 +# Region file format: DS9 version 4.1
  2 +global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
  3 +fk5
  4 +circle(83.6331, 23.5145, 0.5)
... ...
inst/cta/test/data/onoff_region_on.reg 0 → 100644
  1 +# Region file format: DS9 version 4.1
  2 +global color=green dashlist=8 3 width=1 font="helvetica 10 normal roman" select=1 highlite=1 dash=0 fixed=0 edit=1 move=1 delete=1 include=1 source=1
  3 +fk5
  4 +circle(83.6331, 22.0145, 0.2)
... ...
inst/cta/test/data/onoff_rmf.fits 0 → 100644
No preview for this file type
inst/cta/test/test_CTA.cpp
... ... @@ -77,6 +77,10 @@ const std::string cta_stacked_psfcube = datadir+&quot;/stacked_psfcube.fits&quot;;
77 77 const std::string cta_stacked_edispcube = datadir+"/stacked_edispcube.fits";
78 78 const std::string cta_stacked_bkgcube = datadir+"/stacked_bkgcube.fits";
79 79  
  80 +/* __ Test files for On/Off analysis _____________________________________ */
  81 +const std::string cta_onoff_xml = datadir+"/onoff_obs.xml";
  82 +const std::string cta_onoff_model = datadir+"/onoff_model.xml";
  83 +
80 84  
81 85 /***********************************************************************//**
82 86 * @brief Set CTA response test methods
... ... @@ -187,6 +191,8 @@ void TestGCTAObservation::set(void)
187 191 "Test binned observation");
188 192 append(static_cast<pfunction>(&TestGCTAObservation::test_stacked_obs),
189 193 "Test stacked observation");
  194 + append(static_cast<pfunction>(&TestGCTAObservation::test_onoff_obs),
  195 + "Test On/Off observation");
190 196  
191 197 // Return
192 198 return;
... ... @@ -220,6 +226,8 @@ void TestGCTAOptimize::set(void)
220 226 "Test binned optimizer");
221 227 append(static_cast<pfunction>(&TestGCTAOptimize::test_stacked_optimizer),
222 228 "Test stacked optimizer");
  229 + append(static_cast<pfunction>(&TestGCTAOptimize::test_onoff_optimizer),
  230 + "Test On/Off optimizer");
223 231  
224 232 // Return
225 233 return;
... ... @@ -1802,6 +1810,25 @@ void TestGCTAObservation::test_stacked_obs(void)
1802 1810  
1803 1811  
1804 1812 /***********************************************************************//**
  1813 + * @brief Test On/Off observation handling
  1814 + *
  1815 + * @todo Unit test to be implemented
  1816 + ***************************************************************************/
  1817 +void TestGCTAObservation::test_onoff_obs(void)
  1818 +{
  1819 + // Load On/Off observation into container
  1820 + GObservations obs(cta_onoff_xml);
  1821 + //std::cout << *(obs[0]) << std::endl;
  1822 +
  1823 + // Save observation container into XML file
  1824 + obs.save("test_cta_onoff_obs.xml");
  1825 +
  1826 + // Return
  1827 + return;
  1828 +}
  1829 +
  1830 +
  1831 +/***********************************************************************//**
1805 1832 * @brief Test unbinned optimizer
1806 1833 ***************************************************************************/
1807 1834 void TestGCTAOptimize::test_unbinned_optimizer(void)
... ... @@ -1965,6 +1992,58 @@ void TestGCTAOptimize::test_stacked_optimizer(void)
1965 1992 }
1966 1993  
1967 1994  
  1995 +/***********************************************************************//**
  1996 + * @brief Test On/Off optimizer
  1997 + ***************************************************************************/
  1998 +void TestGCTAOptimize::test_onoff_optimizer(void)
  1999 +{
  2000 + // Set reference result
  2001 + double fit_results[] = {83.6331, 0,
  2002 + 22.0145, 0,
  2003 + 5.95777e-16, 2.02034e-17,
  2004 + -2.50932, 0.0304839,
  2005 + 300000, 0,
  2006 + 1, 0,
  2007 + 1.09509, 0.140468,
  2008 + 0.54909, 0.0872644,
  2009 + 1.0e6, 0,
  2010 + 1, 0};
  2011 +
  2012 + // Load On/Off CTA observation
  2013 + GObservations obs(cta_onoff_xml);
  2014 +
  2015 + // Load models from XML file
  2016 + obs.models(cta_onoff_model);
  2017 +
  2018 + // Perform LM optimization
  2019 + GOptimizerLM opt;
  2020 + opt.max_iter(100);
  2021 + obs.optimize(opt);
  2022 + obs.errors(opt);
  2023 + //std::cout << opt << std::endl;
  2024 + //std::cout << obs << std::endl;
  2025 + //std::cout << obs.models() << std::endl;
  2026 +
  2027 + // Verify fit results
  2028 + for (int i = 0, j = 0; i < obs.models().size(); ++i) {
  2029 + const GModel* model = obs.models()[i];
  2030 + for (int k = 0; k < model->size(); ++k) {
  2031 + GModelPar par = (*model)[k];
  2032 + std::string msg = "Verify optimization result for " + par.print();
  2033 + test_value(par.value(), fit_results[j],
  2034 + std::abs(1.0e-4*fit_results[j]), msg);
  2035 + j++;
  2036 + test_value(par.error(), fit_results[j],
  2037 + std::abs(1.0e-4*fit_results[j]), msg);
  2038 + j++;
  2039 + }
  2040 + }
  2041 +
  2042 + // Return
  2043 + return;
  2044 +}
  2045 +
  2046 +
1968 2047 /***************************************************************************
1969 2048 * @brief Main entry point for test executable
1970 2049 ***************************************************************************/
... ...
inst/cta/test/test_CTA.hpp
... ... @@ -119,6 +119,7 @@ public:
119 119 void test_unbinned_obs(void);
120 120 void test_binned_obs(void);
121 121 void test_stacked_obs(void);
  122 + void test_onoff_obs(void);
122 123 };
123 124  
124 125  
... ... @@ -142,8 +143,10 @@ public:
142 143 void test_unbinned_optimizer(void);
143 144 void test_binned_optimizer(void);
144 145 void test_stacked_optimizer(void);
  146 + void test_onoff_optimizer(void);
145 147 };
146 148  
  149 +
147 150 /***********************************************************************//**
148 151 * @class TestGCTAPointing
149 152 *
... ...