Commit fc6ccd390a71c3680df38e5f8402293c5fce3957
1 parent
24af49bb
ctexpcube now derives from ctool. Added set_obs_response() to the ctool base cla…
…ss for CTA observation response setting.
Showing
6 changed files
with
63 additions
and
119 deletions
pyext/ctexpcube.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctexpcube - CTA exposure cube tool * | |
| 2 | + * ctexpcube - Exposure cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,23 +20,21 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctexpcube.i |
| 23 | - * @brief CTA exposure cube tool definition | |
| 23 | + * @brief Exposure cube generation tool definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| 27 | 27 | /* Put headers and other declarations here that are needed for compilation */ |
| 28 | 28 | #include "ctexpcube.hpp" |
| 29 | -#include "GTools.hpp" | |
| 30 | 29 | %} |
| 31 | 30 | |
| 32 | 31 | |
| 33 | 32 | /***********************************************************************//** |
| 34 | 33 | * @class ctexpcube |
| 35 | 34 | * |
| 36 | - * @brief CTA exposure cube tool | |
| 35 | + * @brief Exposure cube generation tool | |
| 37 | 36 | ***************************************************************************/ |
| 38 | -class ctexpcube : public GApplication { | |
| 39 | - | |
| 37 | +class ctexpcube : public ctool { | |
| 40 | 38 | public: |
| 41 | 39 | // Constructors and destructors |
| 42 | 40 | ctexpcube(void); |
| ... | ... | @@ -55,7 +53,7 @@ public: |
| 55 | 53 | |
| 56 | 54 | |
| 57 | 55 | /***********************************************************************//** |
| 58 | - * @brief CTA exposure cube tool Python extension | |
| 56 | + * @brief Exposure cube generation tool Python extension | |
| 59 | 57 | ***************************************************************************/ |
| 60 | 58 | %extend ctexpcube { |
| 61 | 59 | ctexpcube copy() { | ... | ... |
src/ctexpcube/Makefile.am
| 1 | 1 | ## Process this file with automake to produce Makefile.in |
| 2 | 2 | |
| 3 | +# Set include directories | |
| 4 | +INCLUDES = -I$(top_srcdir)/src/support | |
| 5 | + | |
| 3 | 6 | # Program name |
| 4 | 7 | bin_PROGRAMS = ctexpcube |
| 5 | 8 | |
| ... | ... | @@ -14,7 +17,7 @@ libctexpcube_la_SOURCES = $(sources) |
| 14 | 17 | ctexpcube_SOURCES = main.cpp |
| 15 | 18 | ctexpcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ |
| 16 | 19 | ctexpcube_CPPFLAGS = @CPPFLAGS@ |
| 17 | -ctexpcube_LDADD = libctexpcube.la | |
| 20 | +ctexpcube_LDADD = libctexpcube.la $(top_srcdir)/src/support/libsupport.la | |
| 18 | 21 | |
| 19 | 22 | # Parameter files |
| 20 | 23 | pfilesdir = $(prefix)/syspfiles | ... | ... |
src/ctexpcube/ctexpcube.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctexpcube - CTA exposure cube tool * | |
| 2 | + * ctexpcube - Exposure cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctexpcube.cpp |
| 23 | - * @brief CTA exposure cube tool implementation | |
| 23 | + * @brief Exposure cube generation tool implementation | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -34,7 +34,6 @@ |
| 34 | 34 | #include "GWcs.hpp" |
| 35 | 35 | |
| 36 | 36 | /* __ Method name definitions ____________________________________________ */ |
| 37 | -#define G_GET_EBOUNDS "ctexpcube::get_ebounds()" | |
| 38 | 37 | #define G_GET_PARAMETERS "ctexpcube::get_parameters()" |
| 39 | 38 | #define G_SET_FROM_CNTMAP "ctexpcube::set_from_cntmap(std::string&)" |
| 40 | 39 | |
| ... | ... | @@ -52,7 +51,7 @@ |
| 52 | 51 | /***********************************************************************//** |
| 53 | 52 | * @brief Void constructor |
| 54 | 53 | ***************************************************************************/ |
| 55 | -ctexpcube::ctexpcube(void) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | |
| 54 | +ctexpcube::ctexpcube(void) : ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | |
| 56 | 55 | { |
| 57 | 56 | // Initialise members |
| 58 | 57 | init_members(); |
| ... | ... | @@ -74,7 +73,7 @@ ctexpcube::ctexpcube(void) : GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) |
| 74 | 73 | * observations container. |
| 75 | 74 | ***************************************************************************/ |
| 76 | 75 | ctexpcube::ctexpcube(const GObservations& obs) : |
| 77 | - GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | |
| 76 | + ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION) | |
| 78 | 77 | { |
| 79 | 78 | // Initialise members |
| 80 | 79 | init_members(); |
| ... | ... | @@ -98,7 +97,7 @@ ctexpcube::ctexpcube(const GObservations& obs) : |
| 98 | 97 | * @param[in] argv Array of command line arguments. |
| 99 | 98 | ***************************************************************************/ |
| 100 | 99 | ctexpcube::ctexpcube(int argc, char *argv[]) : |
| 101 | - GApplication(CTEXPCUBE_NAME, CTEXPCUBE_VERSION, argc, argv) | |
| 100 | + ctool(CTEXPCUBE_NAME, CTEXPCUBE_VERSION, argc, argv) | |
| 102 | 101 | { |
| 103 | 102 | // Initialise members |
| 104 | 103 | init_members(); |
| ... | ... | @@ -116,7 +115,7 @@ ctexpcube::ctexpcube(int argc, char *argv[]) : |
| 116 | 115 | * |
| 117 | 116 | * @param[in] app ctexpcube application. |
| 118 | 117 | ***************************************************************************/ |
| 119 | -ctexpcube::ctexpcube(const ctexpcube& app) : GApplication(app) | |
| 118 | +ctexpcube::ctexpcube(const ctexpcube& app) : ctool(app) | |
| 120 | 119 | { |
| 121 | 120 | // Initialise members |
| 122 | 121 | init_members(); |
| ... | ... | @@ -160,7 +159,7 @@ ctexpcube& ctexpcube::operator=(const ctexpcube& app) |
| 160 | 159 | if (this != &app) { |
| 161 | 160 | |
| 162 | 161 | // Copy base class members |
| 163 | - this->GApplication::operator=(app); | |
| 162 | + this->ctool::operator=(app); | |
| 164 | 163 | |
| 165 | 164 | // Free members |
| 166 | 165 | free_members(); |
| ... | ... | @@ -191,10 +190,12 @@ void ctexpcube::clear(void) |
| 191 | 190 | { |
| 192 | 191 | // Free members |
| 193 | 192 | free_members(); |
| 193 | + this->ctool::free_members(); | |
| 194 | 194 | this->GApplication::free_members(); |
| 195 | 195 | |
| 196 | 196 | // Initialise members |
| 197 | 197 | this->GApplication::init_members(); |
| 198 | + this->ctool::init_members(); | |
| 198 | 199 | init_members(); |
| 199 | 200 | |
| 200 | 201 | // Return |
| ... | ... | @@ -372,11 +373,6 @@ void ctexpcube::copy_members(const ctexpcube& app) |
| 372 | 373 | ***************************************************************************/ |
| 373 | 374 | void ctexpcube::free_members(void) |
| 374 | 375 | { |
| 375 | - // Write separator into logger | |
| 376 | - if (logTerse()) { | |
| 377 | - log << std::endl; | |
| 378 | - } | |
| 379 | - | |
| 380 | 376 | // Return |
| 381 | 377 | return; |
| 382 | 378 | } |
| ... | ... | @@ -419,7 +415,7 @@ void ctexpcube::get_parameters(void) |
| 419 | 415 | int nypix = (*this)["nypix"].integer(); |
| 420 | 416 | |
| 421 | 417 | // Get energy definition |
| 422 | - get_ebounds(); | |
| 418 | + m_ebounds = get_ebounds(); | |
| 423 | 419 | |
| 424 | 420 | // Define exposure cube |
| 425 | 421 | m_expcube = GCTAExposure(wcs, coordsys, xref, yref, |
| ... | ... | @@ -499,29 +495,11 @@ void ctexpcube::set_response(void) |
| 499 | 495 | // Yes ... |
| 500 | 496 | if (obs != NULL) { |
| 501 | 497 | |
| 502 | - // Set response if we don't have one | |
| 498 | + // If the observation has no response, then set it from | |
| 499 | + // the task parameters | |
| 503 | 500 | if (!obs->has_response()) { |
| 504 | - | |
| 505 | - // Load response information | |
| 506 | - std::string database = (*this)["caldb"].string(); | |
| 507 | - std::string irf = (*this)["irf"].string(); | |
| 508 | - | |
| 509 | - // Set calibration database. If specified parameter is a | |
| 510 | - // directory then use this as the pathname to the calibration | |
| 511 | - // database. Otherwise interpret this as the instrument name, | |
| 512 | - // the mission being "cta" | |
| 513 | - GCaldb caldb; | |
| 514 | - if (gammalib::dir_exists(database)) { | |
| 515 | - caldb.rootdir(database); | |
| 516 | - } | |
| 517 | - else { | |
| 518 | - caldb.open("cta", database); | |
| 519 | - } | |
| 520 | - | |
| 521 | - // Set reponse | |
| 522 | - obs->response(irf, caldb); | |
| 523 | - | |
| 524 | - } // endif: observation already has a response | |
| 501 | + set_obs_response(obs); | |
| 502 | + } | |
| 525 | 503 | |
| 526 | 504 | } // endif: observation was a CTA observation |
| 527 | 505 | |
| ... | ... | @@ -533,76 +511,6 @@ void ctexpcube::set_response(void) |
| 533 | 511 | |
| 534 | 512 | |
| 535 | 513 | /***********************************************************************//** |
| 536 | - * @brief Get energy boundaries from parameters | |
| 537 | - * | |
| 538 | - * @exception GException::invalid_value | |
| 539 | - * Invalid extension name encountered. | |
| 540 | - * | |
| 541 | - * Get the energy boundaries from the user parameters. | |
| 542 | - ***************************************************************************/ | |
| 543 | -void ctexpcube::get_ebounds(void) | |
| 544 | -{ | |
| 545 | - // Determine the energy binning alogrithm | |
| 546 | - std::string ebinalg = (*this)["ebinalg"].string(); | |
| 547 | - | |
| 548 | - // If we have the binning given by a file then try to get the boundaries | |
| 549 | - // from that file | |
| 550 | - if (ebinalg == "FILE") { | |
| 551 | - | |
| 552 | - // Get filename | |
| 553 | - std::string filename = (*this)["ebinfile"].filename(); | |
| 554 | - | |
| 555 | - // Open fits file to check which extension is given | |
| 556 | - GFits file(filename); | |
| 557 | - | |
| 558 | - // Check first for EBOUNDS extension | |
| 559 | - if (file.contains("EBOUNDS")) { | |
| 560 | - file.close(); | |
| 561 | - m_ebounds.load(filename, "EBOUNDS"); | |
| 562 | - } | |
| 563 | - | |
| 564 | - // ... then check for ENERGYBINS extension | |
| 565 | - else if (file.contains("ENERGYBINS")) { | |
| 566 | - file.close(); | |
| 567 | - m_ebounds.load(filename, "ENERGYBINS"); | |
| 568 | - } | |
| 569 | - | |
| 570 | - // ... otherwise throw an exception | |
| 571 | - else { | |
| 572 | - file.close(); | |
| 573 | - std::string msg = "No extension with name \"EBOUNDS\" or" | |
| 574 | - " \"ENERGYBINS\" found in FITS file" | |
| 575 | - " \""+filename+"\".\n" | |
| 576 | - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | |
| 577 | - " is required if the parameter \"ebinalg\"" | |
| 578 | - " is set to \"FILE\"."; | |
| 579 | - throw GException::invalid_value(G_GET_EBOUNDS, msg); | |
| 580 | - } | |
| 581 | - } | |
| 582 | - | |
| 583 | - // ... otherwise read emin, emax and nebins | |
| 584 | - else { | |
| 585 | - | |
| 586 | - // Get the relevant parameters | |
| 587 | - double emin = (*this)["emin"].real(); | |
| 588 | - double emax = (*this)["emax"].real(); | |
| 589 | - int enumbins = (*this)["enumbins"].integer(); | |
| 590 | - bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true; | |
| 591 | - | |
| 592 | - // Create energy boundaries | |
| 593 | - m_ebounds = GEbounds(enumbins, | |
| 594 | - GEnergy(emin, "TeV"), | |
| 595 | - GEnergy(emax, "TeV"), | |
| 596 | - log); | |
| 597 | - | |
| 598 | - } | |
| 599 | - | |
| 600 | - // Return | |
| 601 | - return; | |
| 602 | -} | |
| 603 | - | |
| 604 | - | |
| 605 | -/***********************************************************************//** | |
| 606 | 514 | * @brief Set exposure cube definition from counts map |
| 607 | 515 | * |
| 608 | 516 | * @exception GException::invalid_value | ... | ... |
src/ctexpcube/ctexpcube.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctexpcube - CTA exposure cube tool * | |
| 2 | + * ctexpcube - Exposure cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctexpcube.hpp |
| 23 | - * @brief CTA exposure cube tool definition | |
| 23 | + * @brief Exposure cube generation tool definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -30,6 +30,7 @@ |
| 30 | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | 31 | #include "GammaLib.hpp" |
| 32 | 32 | #include "GCTALib.hpp" |
| 33 | +#include "ctool.hpp" | |
| 33 | 34 | |
| 34 | 35 | /* __Definitions _________________________________________________________ */ |
| 35 | 36 | #define CTEXPCUBE_NAME "ctexpcube" |
| ... | ... | @@ -39,9 +40,9 @@ |
| 39 | 40 | /***********************************************************************//** |
| 40 | 41 | * @class ctexpcube |
| 41 | 42 | * |
| 42 | - * @brief CTA exposure cube tool | |
| 43 | + * @brief Exposure cube generation tool | |
| 43 | 44 | ***************************************************************************/ |
| 44 | -class ctexpcube : public GApplication { | |
| 45 | +class ctexpcube : public ctool { | |
| 45 | 46 | |
| 46 | 47 | public: |
| 47 | 48 | // Constructors and destructors |
| ... | ... | @@ -69,7 +70,6 @@ protected: |
| 69 | 70 | void get_parameters(void); |
| 70 | 71 | void get_obs(void); |
| 71 | 72 | void set_response(void); |
| 72 | - void get_ebounds(void); | |
| 73 | 73 | void set_from_cntmap(const std::string& filename); |
| 74 | 74 | |
| 75 | 75 | // User parameters | ... | ... |
src/support/ctool.cpp
| ... | ... | @@ -29,6 +29,7 @@ |
| 29 | 29 | #include <config.h> |
| 30 | 30 | #endif |
| 31 | 31 | #include "ctool.hpp" |
| 32 | +#include "GTools.hpp" | |
| 32 | 33 | |
| 33 | 34 | /* __ Method name definitions ____________________________________________ */ |
| 34 | 35 | #define G_GET_EBOUNDS "ctool::get_ebounds()" |
| ... | ... | @@ -299,3 +300,36 @@ GEbounds ctool::get_ebounds(void) |
| 299 | 300 | // Return energy boundaries |
| 300 | 301 | return ebounds; |
| 301 | 302 | } |
| 303 | + | |
| 304 | + | |
| 305 | +/***********************************************************************//** | |
| 306 | + * @brief Set response for CTA observation | |
| 307 | + * | |
| 308 | + * @param[in,out] obs CTA observation | |
| 309 | + * | |
| 310 | + * Set the response for a CTA observation using the "database" and "irf" | |
| 311 | + * task parameters. | |
| 312 | + ***************************************************************************/ | |
| 313 | +void ctool::set_obs_response(GCTAObservation* obs) | |
| 314 | +{ | |
| 315 | + // Load response information | |
| 316 | + std::string database = (*this)["caldb"].string(); | |
| 317 | + std::string irf = (*this)["irf"].string(); | |
| 318 | + | |
| 319 | + // Set calibration database. If "database" is a valid directory then use | |
| 320 | + // this as the pathname to the calibration database. Otherwise, interpret | |
| 321 | + // "database" as the instrument name, the mission being "cta" | |
| 322 | + GCaldb caldb; | |
| 323 | + if (gammalib::dir_exists(database)) { | |
| 324 | + caldb.rootdir(database); | |
| 325 | + } | |
| 326 | + else { | |
| 327 | + caldb.open("cta", database); | |
| 328 | + } | |
| 329 | + | |
| 330 | + // Set reponse | |
| 331 | + obs->response(irf, caldb); | |
| 332 | + | |
| 333 | + // Return | |
| 334 | + return; | |
| 335 | +} | ... | ... |