Commit 77abb6420657b29170e34431d8cb8e715e053243

Authored by Jürgen Knödlseder
1 parent 8bcf9b79

ctbkgcube throws exception if no background model is found (#1652)

ChangeLog
1   -2017-05-31
  1 +2017-06-07
2 2  
3 3 * Version 1.3.0 released
4 4 ========================
5 5  
6 6 Correct covariance matrix computation in ctbutterfly (#2121)
7 7 Add missing *.i SWIG file into release tarball (#2114)
8   - ctobssim adds Monte Carlo identifiers to simulated events (#1483)
9 8 Add "phase" parameter to ctselect (#1996)
10   - Add ctphase tool (#1982)
11 9 Add ctprob tool (#1991)
12   - ctlike stores covariance matrix in either CSV or FITS format (#1863)
13   - Use correct ROOT histograms in csroot2caldb
14 10 Implement regression scheme in cssens and remove num_avg parameter (#1989)
15   - Implement Gaussian error propagation in ctbutterfly (#1862)
16 11 Copy cscripts into bin directory instead of creating a symbolic links (#1987)
17 12 If code originates from Git, always compile the Python bindings (#1985)
18 13 Raise exception instead of exiting with return code in Python tests (#1983)
19   - Support of map cubes lying outside RoI in ctobssim
  14 + Add ctphase tool (#1982)
20 15 Support energy boundary FITS file in ctmapcube (#1978)
21 16 Add csebins script (#1976)
22 17 Consider RoI in ctskymap and use numerical integration for IRF (#1975)
  18 + ctlike stores covariance matrix in either CSV or FITS format (#1863)
  19 + Use correct ROOT histograms in csroot2caldb
  20 + Implement Gaussian error propagation in ctbutterfly (#1862)
  21 + Support of map cubes lying outside RoI in ctobssim
  22 + ctbkgcube throws exception if no background model is found (#1652)
  23 + ctobssim adds Monte Carlo identifiers to simulated events (#1483)
23 24 Set local language to english (#1370)
24 25 Enhance logfile output of csroot2caldb script
25 26 Set default deadc value to 0.98 (CTA has <2% deadtime)
... ...
1 1 New Features and Important Changes in ctools 1.3.0.dev1
2 2  
3   -31 May 2017
  3 +7 June 2017
4 4  
5 5  
6 6 Introduction
... ... @@ -112,7 +112,9 @@ None
112 112  
113 113 ctbkgcube - CTA background cube generation
114 114 ------------------------------------------
115   -None
  115 +The tool now throws an exception if no valid background model was found in
  116 +the model container. This prevents from creating an empty background cube
  117 +(#1652).
116 118  
117 119  
118 120 ctmapcube - CTA map cube generation
... ...
doc/source/users/release_history/1.3.rst
... ... @@ -29,10 +29,11 @@ Bug fixes
29 29 * Support of map cubes lying outside RoI in ctobssim
30 30 * [`1975 <https://cta-redmine.irap.omp.eu/issues/1975>`_] -
31 31 Consider RoI in :ref:`ctskymap` and use numerical integration for IRF
  32 +* [`1652 <https://cta-redmine.irap.omp.eu/issues/1652>`_] -
  33 + :ref:`ctbkgcube` throws exception if no background model is found
32 34 * [`1370 <https://cta-redmine.irap.omp.eu/issues/1370>`_] -
33 35 Set local language to english
34 36  
35   -
36 37 Improvements
37 38 ------------
38 39  
... ...
src/ctbkgcube/ctbkgcube.cpp
1 1 /***************************************************************************
2 2 * ctbkgcube - Background cube generation tool *
3 3 * ----------------------------------------------------------------------- *
4   - * copyright (C) 2014-2016 by Chia-Chun Lu *
  4 + * copyright (C) 2014-2017 by Chia-Chun Lu *
5 5 * ----------------------------------------------------------------------- *
6 6 * *
7 7 * This program is free software: you can redistribute it and/or modify *
... ... @@ -33,6 +33,7 @@
33 33 #include "GTools.hpp"
34 34  
35 35 /* __ Method name definitions ____________________________________________ */
  36 +#define G_RUN "ctbkgcube::run()"
36 37  
37 38 /* __ Debug definitions __________________________________________________ */
38 39  
... ... @@ -236,6 +237,9 @@ void ctbkgcube::run(void)
236 237 m_bkgmdl = m_obs.models();
237 238 m_outmdl.clear();
238 239  
  240 + // Initialise instruments string
  241 + std::string instruments;
  242 +
239 243 // Remove all models that are not CTA background models from the
240 244 // container and put all removed components in the output
241 245 // container
... ... @@ -249,7 +253,15 @@ void ctbkgcube::run(void)
249 253 // have a CTA background model and we want to keep the model
250 254 if ((dynamic_cast<GModelData*>(m_bkgmdl[i]) != NULL) &&
251 255 (m_bkgmdl[i]->classname().substr(0,4) == "GCTA")) {
  256 +
  257 + // Signal that model should be kept
252 258 remove = false;
  259 +
  260 + // Collect instrument identifiers
  261 + if (instruments.length() > 0) {
  262 + instruments += ",";
  263 + }
  264 + instruments += m_bkgmdl[i]->instruments();
253 265 }
254 266  
255 267 // Log model removal or keeping
... ... @@ -267,6 +279,16 @@ void ctbkgcube::run(void)
267 279  
268 280 } // endfor: looped over all background models
269 281  
  282 + // If there are no models in the background model container then throw
  283 + // an exception since we need at least one model to generate a background
  284 + // cube
  285 + if (m_bkgmdl.size() == 0) {
  286 + std::string msg = "No background model found in model container. "
  287 + "At least one background model is required in the "
  288 + "model container to generate a background cube.";
  289 + throw GException::invalid_value(G_RUN, msg);
  290 + }
  291 +
270 292 // Write header
271 293 log_header1(TERSE, "Generate background cube");
272 294  
... ... @@ -291,10 +313,8 @@ void ctbkgcube::run(void)
291 313 // Set model name
292 314 model.name("BackgroundModel");
293 315  
294   - // Set model instrument
295   - // TODO: Account for possibility to have observations from different
296   - // IACTs in the same container
297   - model.instruments("CTA,HESS,MAGIC,VERITAS");
  316 + // Set model instruments
  317 + model.instruments(instruments);
298 318  
299 319 // Append model to output container
300 320 m_outmdl.append(model);
... ... @@ -469,7 +489,7 @@ void ctbkgcube::get_parameters(void)
469 489 // parameters
470 490 GCTAEventCube cube = is_valid_filename(incube) ? GCTAEventCube(incube)
471 491 : create_cube(m_obs);
472   -
  492 +
473 493 // Define background cube
474 494 m_background = GCTACubeBackground(cube);
475 495  
... ...