Commit 8fbde373edf7e69550520716ddd60b23fc0c0410
1 parent
7f5d46f9
Enhance set_obs_response() method so that the expcube and psfcube parameters wil…
…l be queried in case that the observation contains a counts cube and if these parameters to indeed exist in the parameter file.
Showing
1 changed file
with
68 additions
and
21 deletions
src/support/ctool.cpp
| @@ -319,7 +319,7 @@ GObservations ctool::get_observations(const bool& get_response) | @@ -319,7 +319,7 @@ GObservations ctool::get_observations(const bool& get_response) | ||
| 319 | // Try first to open as FITS file | 319 | // Try first to open as FITS file |
| 320 | try { | 320 | try { |
| 321 | 321 | ||
| 322 | - // Allocate empyt CTA observation | 322 | + // Allocate empty CTA observation |
| 323 | GCTAObservation cta_obs; | 323 | GCTAObservation cta_obs; |
| 324 | 324 | ||
| 325 | // Load data | 325 | // Load data |
| @@ -707,32 +707,79 @@ void ctool::set_response(GObservations& obs) | @@ -707,32 +707,79 @@ void ctool::set_response(GObservations& obs) | ||
| 707 | * | 707 | * |
| 708 | * @param[in,out] obs CTA observation | 708 | * @param[in,out] obs CTA observation |
| 709 | * | 709 | * |
| 710 | - * Set the response for a CTA observation using the "caldb" and "irf" | ||
| 711 | - * task parameters. | 710 | + * Set the response for a CTA observation. If the CTA observation contains |
| 711 | + * a counts cube the method first attempts to set the response information | ||
| 712 | + * using the @a expcube and @a psfcube user parameters. If this is not | ||
| 713 | + * successful (for example because the parameters do not exist or their | ||
| 714 | + * value is NONE or blank), the method will set the response information | ||
| 715 | + * from the @a caldb and @a irf user parameters. | ||
| 712 | * | 716 | * |
| 713 | * The following parameters are read: | 717 | * The following parameters are read: |
| 714 | - * caldb - Calibration database | ||
| 715 | - * irf - Instrument response function | 718 | + * expcube - Exposure cube file (optional) |
| 719 | + * psfcube - PSF cube file (optional) | ||
| 720 | + * caldb - Calibration database (optional) | ||
| 721 | + * irf - Instrument response function (optional) | ||
| 716 | ***************************************************************************/ | 722 | ***************************************************************************/ |
| 717 | void ctool::set_obs_response(GCTAObservation* obs) | 723 | void ctool::set_obs_response(GCTAObservation* obs) |
| 718 | { | 724 | { |
| 719 | - // Load response information | ||
| 720 | - std::string database = (*this)["caldb"].string(); | ||
| 721 | - std::string irf = (*this)["irf"].string(); | ||
| 722 | - | ||
| 723 | - // Set calibration database. If "database" is a valid directory then use | ||
| 724 | - // this as the pathname to the calibration database. Otherwise, interpret | ||
| 725 | - // "database" as the instrument name, the mission being "cta" | ||
| 726 | - GCaldb caldb; | ||
| 727 | - if (gammalib::dir_exists(database)) { | ||
| 728 | - caldb.rootdir(database); | ||
| 729 | - } | ||
| 730 | - else { | ||
| 731 | - caldb.open("cta", database); | ||
| 732 | - } | 725 | + // Initialise response flag |
| 726 | + bool has_response = false; | ||
| 727 | + | ||
| 728 | + // If the observation contains a counts cube, then first check whether | ||
| 729 | + // the expcube and psfcube parameters exist and are not NONE | ||
| 730 | + if (dynamic_cast<const GCTAEventCube*>(obs->events()) != NULL) { | ||
| 731 | + if (has_par("expcube") && has_par("psfcube")) { | ||
| 732 | + | ||
| 733 | + // Get filenames | ||
| 734 | + std::string expcube = (*this)["expcube"].filename(); | ||
| 735 | + std::string psfcube = (*this)["psfcube"].filename(); | ||
| 736 | + | ||
| 737 | + // Extract response information if available | ||
| 738 | + if ((expcube != "NONE") && (psfcube != "NONE") && | ||
| 739 | + (gammalib::strip_whitespace(expcube) != "") && | ||
| 740 | + (gammalib::strip_whitespace(psfcube) != "")) { | ||
| 741 | + | ||
| 742 | + // Get exposure and PSF cubes | ||
| 743 | + GCTACubeExposure exposure(expcube); | ||
| 744 | + GCTACubePsf psf(psfcube); | ||
| 745 | + | ||
| 746 | + // Set reponse | ||
| 747 | + obs->response(exposure, psf); | ||
| 748 | + | ||
| 749 | + // Signal response availability | ||
| 750 | + has_response = true; | ||
| 751 | + | ||
| 752 | + } // endif: filenames were available | ||
| 753 | + | ||
| 754 | + } // endif: expcube and psfcube parameters exist | ||
| 755 | + } // endif: observation contains a counts cube | ||
| 756 | + | ||
| 757 | + // If we have not yet response information then get it now | ||
| 758 | + // from the caldb and irf parameters | ||
| 759 | + if (!has_response) { | ||
| 760 | + | ||
| 761 | + // Load response information | ||
| 762 | + std::string database = (*this)["caldb"].string(); | ||
| 763 | + std::string irf = (*this)["irf"].string(); | ||
| 764 | + | ||
| 765 | + // Set calibration database. If "database" is a valid directory then use | ||
| 766 | + // this as the pathname to the calibration database. Otherwise, interpret | ||
| 767 | + // "database" as the instrument name, the mission being "cta" | ||
| 768 | + GCaldb caldb; | ||
| 769 | + if (gammalib::dir_exists(database)) { | ||
| 770 | + caldb.rootdir(database); | ||
| 771 | + } | ||
| 772 | + else { | ||
| 773 | + caldb.open("cta", database); | ||
| 774 | + } | ||
| 775 | + | ||
| 776 | + // Set reponse | ||
| 777 | + obs->response(irf, caldb); | ||
| 778 | + | ||
| 779 | + // Signal response availability | ||
| 780 | + has_response = true; | ||
| 733 | 781 | ||
| 734 | - // Set reponse | ||
| 735 | - obs->response(irf, caldb); | 782 | + } // endif: no response information was available |
| 736 | 783 | ||
| 737 | // Return | 784 | // Return |
| 738 | return; | 785 | return; |