Commit 239868b40bab1c8608bc56baa61a74d2e75689ac

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

Unnormalize background cube values in ctbkgcube (#2685)

ChangeLog
... ... @@ -3,6 +3,7 @@
3 3 * Version 1.6.0 released
4 4 ========================
5 5  
  6 + Unnormalize background cube values in ctbkgcube (#2685)
6 7 Account for varying energy thresholds in ctbin weight computation (#2685)
7 8 Add ctbkgcube::cntcube() method (#2685)
8 9 Avoid ctselect error in case that RoI radius is unchanged (#2682)
... ...
... ... @@ -61,8 +61,11 @@ ctbkgcube - CTA background cube generation
61 61 ------------------------------------------
62 62 Add ctbkgcube::cntcube() method so that a counts cube be specified as
63 63 instance before running the tool. This avoids storing the counts cube on
64   -disk if the couts cube definition should be used to generate a background
65   -cube (#2685).
  64 +disk if the counts cube definition should be used to generate a background
  65 +cube. In addition, the background cube values are now devided by the
  66 +weight values of the counts cube since later, during model evaluation,
  67 +the model is multiplied by the weight values. This makes sure that the
  68 +normalisation is correct (#2685).
66 69  
67 70  
68 71 ctbutterfly - Generate butterfly diagrams
... ...
doc/source/admin/release_history/1.6.rst
... ... @@ -36,7 +36,8 @@ Improvements
36 36  
37 37 * [`2685 <https://cta-redmine.irap.omp.eu/issues/2685>`_] -
38 38 Add ``ctbkgcube::cntcube()`` method
39   - Accout for varying energy thresholds in :ref:`ctbin` weight computation
  39 + Account for varying energy thresholds in :ref:`ctbin` weight computation
  40 + Unnormalize background cube values in :ref:`ctbkgcube`
40 41 * Add ``use_irf_bkg`` parameter to :ref:`cslightcrv`
41 42 * [`2671 <https://cta-redmine.irap.omp.eu/issues/2671>`_] -
42 43 Do not skip bins with zero counts in :ref:`csspec`
... ...
src/ctbkgcube/ctbkgcube.cpp
... ... @@ -296,6 +296,18 @@ void ctbkgcube::run(void)
296 296 // Fill background cube from observations
297 297 m_background.fill(m_obs, logger);
298 298  
  299 + // Un-normalize background cube. We do this since the counts cube weight is
  300 + // later multiplied when computing the model value for binned analysis.
  301 + GSkyMap* bkg = const_cast<GSkyMap*>(&m_background.cube());
  302 + for (int pixel = 0; pixel < m_cube.npix(); ++pixel) {
  303 + for (int iebin = 0; iebin < m_cube.ebins(); ++iebin) {
  304 + double weight = m_cube.weights()(pixel, iebin);
  305 + if (weight > 0.0) {
  306 + (*bkg)(pixel, iebin) /= weight;
  307 + }
  308 + }
  309 + }
  310 +
299 311 // Create a background model for the output background cube and append
300 312 // that model to the input model in place of the original
301 313 // background models
... ... @@ -432,6 +444,7 @@ void ctbkgcube::init_members(void)
432 444  
433 445 // Initialise protected members
434 446 m_background.clear();
  447 + m_cube.clear();
435 448 m_bkgmdl.clear();
436 449 m_outmdl.clear();
437 450  
... ... @@ -456,6 +469,7 @@ void ctbkgcube::copy_members(const ctbkgcube&amp; app)
456 469  
457 470 // Copy protected members
458 471 m_background = app.m_background;
  472 + m_cube = app.m_cube;
459 473 m_bkgmdl = app.m_bkgmdl;
460 474 m_outmdl = app.m_outmdl;
461 475  
... ... @@ -486,15 +500,21 @@ void ctbkgcube::get_parameters(void)
486 500 // event lists, but do not accept counts cubes.
487 501 setup_observations(m_obs, true, true, false);
488 502  
489   - // If the "incube" file name is valid then setup the background cube from
490   - // the counts cube. Otherwise create a counts cube from the user
  503 + // If there is a valid event cube than use it for construction.
  504 + // Otherwise check if "incube" file name is valid then use the specified
  505 + // counts cube. Otherwise create a counts cube from the user
491 506 // parameters
492   - GCTAEventCube cube = (*this)["incube"].is_valid()
493   - ? GCTAEventCube((*this)["incube"].filename())
494   - : create_cube(m_obs);
  507 + if (m_cube.size() == 0) {
  508 + if ((*this)["incube"].is_valid()) {
  509 + m_cube = GCTAEventCube((*this)["incube"].filename());
  510 + }
  511 + else {
  512 + m_cube = create_cube(m_obs);
  513 + }
  514 + }
495 515  
496 516 // Define background cube
497   - m_background = GCTACubeBackground(cube);
  517 + m_background = GCTACubeBackground(m_cube);
498 518  
499 519 // Setup models from "inmodel" parameter
500 520 setup_models(m_obs);
... ...