From 72966fc3a6750c4cdccfbd8e7b6b84ce49681c94 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Sat, 19 Jul 2014 02:00:58 +0200 Subject: [PATCH] Adapt to refactored CTA response. --- ChangeLog | 1 + configure.ac | 2 +- ctools.pc.in | 4 ++-- doc/Doxyfile | 2 +- doc/source/conf.py | 4 ++-- src/ctbin/ctbin.cpp | 2 +- src/ctexpcube/ctexpcube.cpp | 10 +++++----- src/ctlike/ctlike.cpp | 12 ++++++------ src/ctmodel/ctmodel.cpp | 12 ++++++------ src/ctobssim/ctobssim.cpp | 31 ++++++++++++++++++------------- src/ctselect/ctselect.cpp | 4 ++-- src/ctskymap/ctskymap.cpp | 4 ++-- test/test_python.py | 17 ++++------------- 13 files changed, 51 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index c2de956..73dd803 100644 --- a/ChangeLog +++ b/ChangeLog @@ -3,6 +3,7 @@ * Version 0.8.0 released ======================== + Adapt to GammaLib 0.9.0 interface ctbin now always merges event lists into a single counts cube Add ctexpcube tool Support energy dispersion in ctobssim, ctlike and ctmodel diff --git a/configure.ac b/configure.ac index 97b2a6e..2f33138 100644 --- a/configure.ac +++ b/configure.ac @@ -29,7 +29,7 @@ ############################################################################# # Initialisation # ############################################################################# -AC_INIT([ctools], [0.7.1], [jurgen.knodlseder@irap.omp.eu], [ctools]) +AC_INIT([ctools], [0.8.0], [jurgen.knodlseder@irap.omp.eu], [ctools]) AC_CONFIG_SRCDIR([src/ctselect/ctselect.cpp]) AC_CONFIG_MACRO_DIR([m4]) #AM_INIT_AUTOMAKE([gnu no-dependencies]) diff --git a/ctools.pc.in b/ctools.pc.in index f6dad68..252ad61 100644 --- a/ctools.pc.in +++ b/ctools.pc.in @@ -6,9 +6,9 @@ includedir=${prefix}/include Name: ctools Description: CTA science analysis tools URL: http://cta.irap.omp.eu/ctools -Version: 0.7.1 +Version: 0.8.0 Requires: -Requires.private: gammalib >= 0.8.1 +Requires.private: gammalib >= 0.9.0 Conflicts: Cflags: -I${includedir}/ctools @OPENMP_CXXFLAGS@ Libs: -L${libdir} -lctools diff --git a/doc/Doxyfile b/doc/Doxyfile index 57bfbd8..2f111aa 100644 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -32,7 +32,7 @@ PROJECT_NAME = ctools # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 0.7.1 +PROJECT_NUMBER = 0.8.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/doc/source/conf.py b/doc/source/conf.py index c63ed9a..a77e2ae 100644 --- a/doc/source/conf.py +++ b/doc/source/conf.py @@ -73,10 +73,10 @@ copyright = u'2014, ctools developers' # built documents. # # The short X.Y version. -version = '0.7' +version = '0.8' # The full version, including alpha/beta/rc tags. -release = '0.7.2' +release = '0.8.0' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index df25149..e7eeeda 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -430,7 +430,7 @@ void ctbin::get_parameters(void) try { // Load event list in CTA observation - obs.load_unbinned(m_evfile); + obs.load(m_evfile); // Append CTA observation to container m_obs.append(obs); diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index 0881abb..39ff33e 100644 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -252,8 +252,8 @@ void ctexpcube::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - save_edisp[i] = obs->response().apply_edisp(); - obs->response().apply_edisp(m_apply_edisp); + save_edisp[i] = obs->response()->apply_edisp(); + obs->response()->apply_edisp(m_apply_edisp); } } @@ -282,7 +282,7 @@ void ctexpcube::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - obs->response().apply_edisp(save_edisp[i]); + obs->response()->apply_edisp(save_edisp[i]); } } @@ -431,8 +431,8 @@ void ctexpcube::set_response(void) // Yes ... if (obs != NULL) { - // Set response if it isn't set already - if (obs->response().aeff() == NULL) { + // Set response if we don't have one + if (!obs->hasresponse()) { // Load response information std::string database = (*this)["caldb"].string(); diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp index d5999cc..a302e06 100644 --- a/src/ctlike/ctlike.cpp +++ b/src/ctlike/ctlike.cpp @@ -248,8 +248,8 @@ void ctlike::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - save_edisp[i] = obs->response().apply_edisp(); - obs->response().apply_edisp(m_apply_edisp); + save_edisp[i] = obs->response()->apply_edisp(); + obs->response()->apply_edisp(m_apply_edisp); } } @@ -332,7 +332,7 @@ void ctlike::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - obs->response().apply_edisp(save_edisp[i]); + obs->response()->apply_edisp(save_edisp[i]); } } @@ -448,9 +448,9 @@ void ctlike::get_parameters(void) // Continue only if observation is a CTA observation if (obs != NULL) { - // If there is no effective area information then - // set response from task parameters - if (obs->response().aeff() == NULL) { + // If response is not valid then set response from + // task parameters + if (!obs->hasresponse()) { // Get calibration parameters if (!asked_for_response) { diff --git a/src/ctmodel/ctmodel.cpp b/src/ctmodel/ctmodel.cpp index 1c2618a..aa5e31d 100644 --- a/src/ctmodel/ctmodel.cpp +++ b/src/ctmodel/ctmodel.cpp @@ -253,8 +253,8 @@ void ctmodel::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - save_edisp[i] = obs->response().apply_edisp(); - obs->response().apply_edisp(m_apply_edisp); + save_edisp[i] = obs->response()->apply_edisp(); + obs->response()->apply_edisp(m_apply_edisp); } } @@ -341,7 +341,7 @@ void ctmodel::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - obs->response().apply_edisp(save_edisp[i]); + obs->response()->apply_edisp(save_edisp[i]); } } @@ -554,7 +554,7 @@ void ctmodel::setup_obs(void) GCTAObservation obs; // Load counts map in CTA observation - obs.load_binned(m_infile); + obs.load(m_infile); // Append CTA observation to container m_obs.append(obs); @@ -602,8 +602,8 @@ void ctmodel::setup_obs(void) throw GException::no_cube(G_SETUP_OBS); } - // Set response if it isn't set already - if (obs->response().aeff() == NULL) { + // Set response if we don't have one + if (!obs->hasresponse()) { // Set calibration database. If specified parameter is a // directory then use this as the pathname to the calibration diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index ae1c7fb..762cbd4 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -33,8 +33,8 @@ #include "GTools.hpp" /* __ Method name definitions ____________________________________________ */ -#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*,"\ - " GPhotons&)" +#define G_SIMULATE_SOURCE "ctobssim::simulate_source(GCTAObservation*, "\ + "GModels&, GRan&, GLog*)" /* __ Constants __________________________________________________________ */ const double g_roi_margin = 0.5; //!< Simulation radius margin (degrees) @@ -263,8 +263,8 @@ void ctobssim::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - save_edisp[i] = obs->response().apply_edisp(); - obs->response().apply_edisp(m_apply_edisp); + save_edisp[i] = obs->response()->apply_edisp(); + obs->response()->apply_edisp(m_apply_edisp); } } @@ -380,7 +380,7 @@ void ctobssim::run(void) for (int i = 0; i < m_obs.size(); ++i) { GCTAObservation* obs = dynamic_cast(m_obs[i]); if (obs != NULL) { - obs->response().apply_edisp(save_edisp[i]); + obs->response()->apply_edisp(save_edisp[i]); } } @@ -664,7 +664,12 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, } // Get CTA response - const GCTAResponse& rsp = obs->response(); + const GCTAResponseIrf* rsp = dynamic_cast(obs->response()); + if (rsp == NULL) { + std::string msg = "Response is not an IRF response.\n" + + obs->response()->print(); + throw GException::invalid_value(G_SIMULATE_SOURCE, msg); + } // Make sure that the observation holds a CTA event list. If this // is not the case then allocate and attach a CTA event list now. @@ -723,9 +728,9 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, // has energy dispersion then add margin GEnergy e_true_min = emin; GEnergy e_true_max = emax; - if (rsp.use_edisp()) { - e_true_min = rsp.ebounds_src(e_true_min).emin(); - e_true_max = rsp.ebounds_src(e_true_max).emax(); + if (rsp->use_edisp()) { + e_true_min = rsp->ebounds_src(e_true_min).emin(); + e_true_max = rsp->ebounds_src(e_true_max).emax(); } // Dump energy range @@ -822,10 +827,10 @@ void ctobssim::simulate_source(GCTAObservation* obs, const GModels& models, // Simulate event. Note that this method // includes the deadtime correction. - GCTAEventAtom* event = rsp.mc(m_area, - photons[i], - *obs, - ran); + GCTAEventAtom* event = rsp->mc(m_area, + photons[i], + *obs, + ran); if (event != NULL) { // Use event only if it falls within ROI diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index 341fd81..598921f 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -641,8 +641,8 @@ void ctselect::select_events(GCTAObservation* obs, const std::string& filename) } else { - // Readload observation from FITS file - obs->load(file); + // Re-read observation from FITS object + obs->read(file); } diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index 478a82f..5353093 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctskymap - CTA sky mapping tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2013 by Juergen Knoedlseder * + * copyright (C) 2011-2014 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -366,7 +366,7 @@ void ctskymap::get_parameters(void) // Load unbinned CTA observation GCTAObservation obs; - obs.load_unbinned(m_evfile); + obs.load(m_evfile); // Append CTA observation to container m_obs.append(obs); diff --git a/test/test_python.py b/test/test_python.py index d916df6..a84d25c 100755 --- a/test/test_python.py +++ b/test/test_python.py @@ -3,7 +3,7 @@ # This script illustrates how to build an unbinned analysis pipeline using # the ctools. # -# Copyright (C) 2011 Jurgen Knodlseder +# Copyright (C) 2011-2014 Juergen Knoedlseder # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -43,7 +43,7 @@ def pipeline_v1(): events_name = "events.fits" selected_events_name = "selected_events.fits" result_name = "results.xml" - caldb = "irf" + caldb = "dummy" irf = "cta_dummy_irf" ra = 83.63 dec = 22.01 @@ -122,17 +122,8 @@ def pipeline_v2(model_name="data/crab.xml", \ FITS files on disk. All data is only hold in memory. """ # Set script parameters - #model_name = "data/crab.xml" - caldb = "irf" - irf = "cta_dummy_irf" - #ra = 83.63 - #dec = 22.01 - #rad_sim = 10.0 - #tstart = 0.0 - #tstop = 1800.0 - #emin = 0.1 - #emax = 100.0 - #rad_select = 3.0 + caldb = "dummy" + irf = "cta_dummy_irf" # Simulate events sim = ctobssim() -- libgit2 0.21.4