From 77abb6420657b29170e34431d8cb8e715e053243 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Thu, 8 Jun 2017 01:06:28 +0200 Subject: [PATCH] ctbkgcube throws exception if no background model is found (#1652) --- ChangeLog | 15 ++++++++------- NEWS | 6 ++++-- doc/source/users/release_history/1.3.rst | 3 ++- src/ctbkgcube/ctbkgcube.cpp | 32 ++++++++++++++++++++++++++------ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/ChangeLog b/ChangeLog index 686f335..0c03851 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,25 +1,26 @@ -2017-05-31 +2017-06-07 * Version 1.3.0 released ======================== Correct covariance matrix computation in ctbutterfly (#2121) Add missing *.i SWIG file into release tarball (#2114) - ctobssim adds Monte Carlo identifiers to simulated events (#1483) Add "phase" parameter to ctselect (#1996) - Add ctphase tool (#1982) Add ctprob tool (#1991) - ctlike stores covariance matrix in either CSV or FITS format (#1863) - Use correct ROOT histograms in csroot2caldb Implement regression scheme in cssens and remove num_avg parameter (#1989) - Implement Gaussian error propagation in ctbutterfly (#1862) Copy cscripts into bin directory instead of creating a symbolic links (#1987) If code originates from Git, always compile the Python bindings (#1985) Raise exception instead of exiting with return code in Python tests (#1983) - Support of map cubes lying outside RoI in ctobssim + Add ctphase tool (#1982) Support energy boundary FITS file in ctmapcube (#1978) Add csebins script (#1976) Consider RoI in ctskymap and use numerical integration for IRF (#1975) + ctlike stores covariance matrix in either CSV or FITS format (#1863) + Use correct ROOT histograms in csroot2caldb + Implement Gaussian error propagation in ctbutterfly (#1862) + Support of map cubes lying outside RoI in ctobssim + ctbkgcube throws exception if no background model is found (#1652) + ctobssim adds Monte Carlo identifiers to simulated events (#1483) Set local language to english (#1370) Enhance logfile output of csroot2caldb script Set default deadc value to 0.98 (CTA has <2% deadtime) diff --git a/NEWS b/NEWS index 5812d57..eb223a9 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,6 @@ New Features and Important Changes in ctools 1.3.0.dev1 -31 May 2017 +7 June 2017 Introduction @@ -112,7 +112,9 @@ None ctbkgcube - CTA background cube generation ------------------------------------------ -None +The tool now throws an exception if no valid background model was found in +the model container. This prevents from creating an empty background cube +(#1652). ctmapcube - CTA map cube generation diff --git a/doc/source/users/release_history/1.3.rst b/doc/source/users/release_history/1.3.rst index a8b4001..154d317 100644 --- a/doc/source/users/release_history/1.3.rst +++ b/doc/source/users/release_history/1.3.rst @@ -29,10 +29,11 @@ Bug fixes * Support of map cubes lying outside RoI in ctobssim * [`1975 `_] - Consider RoI in :ref:`ctskymap` and use numerical integration for IRF +* [`1652 `_] - + :ref:`ctbkgcube` throws exception if no background model is found * [`1370 `_] - Set local language to english - Improvements ------------ diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index ab48178..bc85fdf 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014-2016 by Chia-Chun Lu * + * copyright (C) 2014-2017 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -33,6 +33,7 @@ #include "GTools.hpp" /* __ Method name definitions ____________________________________________ */ +#define G_RUN "ctbkgcube::run()" /* __ Debug definitions __________________________________________________ */ @@ -236,6 +237,9 @@ void ctbkgcube::run(void) m_bkgmdl = m_obs.models(); m_outmdl.clear(); + // Initialise instruments string + std::string instruments; + // Remove all models that are not CTA background models from the // container and put all removed components in the output // container @@ -249,7 +253,15 @@ void ctbkgcube::run(void) // have a CTA background model and we want to keep the model if ((dynamic_cast(m_bkgmdl[i]) != NULL) && (m_bkgmdl[i]->classname().substr(0,4) == "GCTA")) { + + // Signal that model should be kept remove = false; + + // Collect instrument identifiers + if (instruments.length() > 0) { + instruments += ","; + } + instruments += m_bkgmdl[i]->instruments(); } // Log model removal or keeping @@ -267,6 +279,16 @@ void ctbkgcube::run(void) } // endfor: looped over all background models + // If there are no models in the background model container then throw + // an exception since we need at least one model to generate a background + // cube + if (m_bkgmdl.size() == 0) { + std::string msg = "No background model found in model container. " + "At least one background model is required in the " + "model container to generate a background cube."; + throw GException::invalid_value(G_RUN, msg); + } + // Write header log_header1(TERSE, "Generate background cube"); @@ -291,10 +313,8 @@ void ctbkgcube::run(void) // Set model name model.name("BackgroundModel"); - // Set model instrument - // TODO: Account for possibility to have observations from different - // IACTs in the same container - model.instruments("CTA,HESS,MAGIC,VERITAS"); + // Set model instruments + model.instruments(instruments); // Append model to output container m_outmdl.append(model); @@ -469,7 +489,7 @@ void ctbkgcube::get_parameters(void) // parameters GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube) : create_cube(m_obs); - + // Define background cube m_background = GCTACubeBackground(cube); -- libgit2 0.21.4