Commit 1ae952bd36fc6a00890fa42dea5033ee7fd5f9e1

Authored by Jürgen Knödlseder
1 parent ac17570c

Re-enable ctmodel model computation for stacked analysis.

ChangeLog
@@ -3,6 +3,8 @@ @@ -3,6 +3,8 @@
3 * Bug fix version 1.0.1 released 3 * Bug fix version 1.0.1 released
4 ================================ 4 ================================
5 5
  6 + Re-enable ctmodel computation for stacked analysis (#1609)
  7 +
6 8
7 2015-12-18 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu> 9 2015-12-18 Juergen Knoedlseder <jurgen.knodlseder@irap.omp.eu>
8 10
@@ -59,7 +59,8 @@ None @@ -59,7 +59,8 @@ None
59 59
60 11. ctmodel - CTA counts cube modelling 60 11. ctmodel - CTA counts cube modelling
61 --------------------------------------- 61 ---------------------------------------
62 -None 62 +The get_obs() method, that has been accidently removed, has been put back
  63 +which allows computation of a model cube for a stacked analysis.
63 64
64 65
65 12. ctexpcube - CTA exposure cube generation 66 12. ctexpcube - CTA exposure cube generation
src/ctmodel/ctmodel.cpp
@@ -411,7 +411,7 @@ void ctmodel::init_members(void) @@ -411,7 +411,7 @@ void ctmodel::init_members(void)
411 m_gti.clear(); 411 m_gti.clear();
412 m_has_cube = false; 412 m_has_cube = false;
413 m_append_cube = false; 413 m_append_cube = false;
414 - m_binned = false; 414 + m_binned = false;
415 415
416 // Return 416 // Return
417 return; 417 return;
@@ -435,7 +435,7 @@ void ctmodel::copy_members(const ctmodel&amp; app) @@ -435,7 +435,7 @@ void ctmodel::copy_members(const ctmodel&amp; app)
435 m_gti = app.m_gti; 435 m_gti = app.m_gti;
436 m_has_cube = app.m_has_cube; 436 m_has_cube = app.m_has_cube;
437 m_append_cube = app.m_append_cube; 437 m_append_cube = app.m_append_cube;
438 - m_binned = app.m_binned; 438 + m_binned = app.m_binned;
439 439
440 // Return 440 // Return
441 return; 441 return;
@@ -466,7 +466,7 @@ void ctmodel::get_parameters(void) @@ -466,7 +466,7 @@ void ctmodel::get_parameters(void)
466 // If there are no observations in container then load them via user 466 // If there are no observations in container then load them via user
467 // parameters 467 // parameters
468 if (m_obs.size() == 0) { 468 if (m_obs.size() == 0) {
469 - m_obs = get_observations(); 469 + get_obs();
470 } 470 }
471 471
472 // Check if we got excactly one binned CTA observation 472 // Check if we got excactly one binned CTA observation
@@ -574,6 +574,134 @@ void ctmodel::get_parameters(void) @@ -574,6 +574,134 @@ void ctmodel::get_parameters(void)
574 574
575 575
576 /***********************************************************************//** 576 /***********************************************************************//**
  577 + * @brief Get observation container
  578 + *
  579 + * Get an observation container according to the user parameters. The method
  580 + * supports loading of a individual FITS file or an observation definition
  581 + * file in XML format.
  582 + *
  583 + * If the input filename is empty, the method checks for the existence of the
  584 + * "expcube", "psfcube" and "bkgcube" parameters. If file names have been
  585 + * specified, the method loads the files and creates a dummy events cube that
  586 + * is appended to the observation container.
  587 + *
  588 + * If no file names are specified for the "expcube", "psfcube" or "bkgcube"
  589 + * parameters, the method reads the necessary parameters to build a CTA
  590 + * observation from scratch.
  591 + ***************************************************************************/
  592 +void ctmodel::get_obs(void)
  593 +{
  594 + // Get the filename from the input parameters
  595 + std::string filename = (*this)["inobs"].filename();
  596 +
  597 + // If no observation definition file has been specified then read all
  598 + // parameters that are necessary to create an observation from scratch
  599 + if ((filename == "NONE") || (gammalib::strip_whitespace(filename) == "")) {
  600 +
  601 + // Get response cube filenames
  602 + std::string expcube = (*this)["expcube"].filename();
  603 + std::string psfcube = (*this)["psfcube"].filename();
  604 + std::string bkgcube = (*this)["bkgcube"].filename();
  605 +
  606 + // If the filenames are valid then build an observation from cube
  607 + // response information
  608 + if ((expcube != "NONE") && (psfcube != "NONE") && (bkgcube != "NONE") &&
  609 + (gammalib::strip_whitespace(expcube) != "") &&
  610 + (gammalib::strip_whitespace(psfcube) != "") &&
  611 + (gammalib::strip_whitespace(bkgcube) != "")) {
  612 +
  613 + // Get exposure, PSF and background cubes
  614 + GCTACubeExposure exposure(expcube);
  615 + GCTACubePsf psf(psfcube);
  616 + GCTACubeBackground background(bkgcube);
  617 +
  618 + // Create energy boundaries
  619 + GEbounds ebounds = create_ebounds();
  620 +
  621 + // Create dummy sky map cube
  622 + GSkyMap map("CAR","GAL",0.0,0.0,1.0,1.0,1,1,ebounds.size());
  623 + m_append_cube = true;
  624 +
  625 + // Create event cube
  626 + GCTAEventCube cube(map, ebounds, exposure.gti());
  627 +
  628 + // Create CTA observation
  629 + GCTAObservation cta;
  630 + cta.events(cube);
  631 + cta.response(exposure, psf, background);
  632 +
  633 + // Append observation to container
  634 + m_obs.append(cta);
  635 +
  636 + } // endif: cube response information was available
  637 +
  638 + // ... otherwise build an observation from IRF response information
  639 + else {
  640 +
  641 + // Create CTA observation
  642 + GCTAObservation cta = create_cta_obs();
  643 +
  644 + // Set response
  645 + set_obs_response(&cta);
  646 +
  647 + // Append observation to container
  648 + m_obs.append(cta);
  649 +
  650 + }
  651 +
  652 + } // endif: filename was "NONE" or ""
  653 +
  654 + // ... otherwise we have a file name
  655 + else {
  656 +
  657 + // If file is a FITS file then create an empty CTA observation
  658 + // and load file into observation
  659 + if (gammalib::is_fits(filename)) {
  660 +
  661 + // Allocate empty CTA observation
  662 + GCTAObservation cta;
  663 +
  664 + // Load data
  665 + cta.load(filename);
  666 +
  667 + // Set response
  668 + set_obs_response(&cta);
  669 +
  670 + // Append observation to container
  671 + m_obs.append(cta);
  672 +
  673 + // Signal that no XML file should be used for storage
  674 + m_use_xml = false;
  675 +
  676 + }
  677 +
  678 + // ... otherwise load file into observation container
  679 + else {
  680 +
  681 + // Load observations from XML file
  682 + m_obs.load(filename);
  683 +
  684 + // For all observations that have no response, set the response
  685 + // from the task parameters
  686 + set_response(m_obs);
  687 +
  688 + // Set observation boundary parameters (emin, emax, rad)
  689 + set_obs_bounds(m_obs);
  690 +
  691 + // Signal that XML file should be used for storage
  692 + m_use_xml = true;
  693 +
  694 + } // endelse: file was an XML file
  695 +
  696 + }
  697 +
  698 + // Return
  699 + return;
  700 +
  701 +}
  702 +
  703 +
  704 +/***********************************************************************//**
577 * @brief Fill model into model cube 705 * @brief Fill model into model cube
578 * 706 *
579 * @param[in] obs CTA observation. 707 * @param[in] obs CTA observation.
src/ctmodel/ctmodel.hpp
@@ -34,7 +34,7 @@ @@ -34,7 +34,7 @@
34 34
35 /* __Definitions _________________________________________________________ */ 35 /* __Definitions _________________________________________________________ */
36 #define CTMODEL_NAME "ctmodel" 36 #define CTMODEL_NAME "ctmodel"
37 -#define CTMODEL_VERSION "1.0.0" 37 +#define CTMODEL_VERSION "1.0.1"
38 38
39 39
40 /***********************************************************************//** 40 /***********************************************************************//**
@@ -79,6 +79,7 @@ protected: @@ -79,6 +79,7 @@ protected:
79 void copy_members(const ctmodel& app); 79 void copy_members(const ctmodel& app);
80 void free_members(void); 80 void free_members(void);
81 void get_parameters(void); 81 void get_parameters(void);
  82 + void get_obs(void);
82 void fill_cube(const GCTAObservation* obs); 83 void fill_cube(const GCTAObservation* obs);
83 bool has_cube(void) const; 84 bool has_cube(void) const;
84 85
src/ctmodel/ctmodel.par
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 # ------------------------------------------------------------------------- # 5 # ------------------------------------------------------------------------- #
6 # # 6 # #
7 # File: ctmodel.par # 7 # File: ctmodel.par #
8 -# Version: 1.0.0 # 8 +# Version: 1.0.1 #
9 # # 9 # #
10 # Author: Juergen Knoedlseder # 10 # Author: Juergen Knoedlseder #
11 # Jurgen.Knodlseder@irap.omp.eu # 11 # Jurgen.Knodlseder@irap.omp.eu #