Commit 24af49bb5cb897d39aad9992a0fde9ed4b8d7f80
1 parent
06e26db0
ctbkgcube now derives from ctool class, removed get_ebounds() method as it is pr…
…ovided by the base class
Showing
6 changed files
with
25 additions
and
118 deletions
pyext/ctbin.i
pyext/ctbkgcube.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbkgcube - CTA background cube tool * | |
| 2 | + * ctbkgcube - Background cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Chia-Chun Lu * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,23 +20,21 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbkgcube.i |
| 23 | - * @brief CTA background cube tool definition | |
| 23 | + * @brief Background cube generation tool definition | |
| 24 | 24 | * @author Chia-Chun Lu |
| 25 | 25 | */ |
| 26 | 26 | |
| 27 | 27 | %{ |
| 28 | 28 | /* Put headers and other declarations here that are needed for compilation */ |
| 29 | 29 | #include "ctbkgcube.hpp" |
| 30 | -#include "GTools.hpp" | |
| 31 | 30 | %} |
| 32 | 31 | |
| 33 | 32 | /***********************************************************************//** |
| 34 | 33 | * @class ctbkgcube |
| 35 | 34 | * |
| 36 | - * @brief CTA background cube tool | |
| 35 | + * @brief Background cube generation tool | |
| 37 | 36 | ***************************************************************************/ |
| 38 | 37 | class ctbkgcube : public GApplication { |
| 39 | - | |
| 40 | 38 | public: |
| 41 | 39 | // Constructors and destructors |
| 42 | 40 | ctbkgcube(void); |
| ... | ... | @@ -54,7 +52,7 @@ public: |
| 54 | 52 | }; |
| 55 | 53 | |
| 56 | 54 | /***********************************************************************//** |
| 57 | - * @brief CTA background cube tool Python extension | |
| 55 | + * @brief Background cube generation tool Python extension | |
| 58 | 56 | ***************************************************************************/ |
| 59 | 57 | %extend ctbkgcube { |
| 60 | 58 | ctbkgcube copy() { | ... | ... |
src/ctbin/ctbin.cpp
| ... | ... | @@ -35,7 +35,6 @@ |
| 35 | 35 | /* __ Method name definitions ____________________________________________ */ |
| 36 | 36 | #define G_INIT_CUBE "ctbin::init_cube()" |
| 37 | 37 | #define G_FILL_CUBE "ctbin::fill_cube(GCTAObservation*)" |
| 38 | -#define G_GET_EBOUNDS "ctbin::get_ebounds()" | |
| 39 | 38 | |
| 40 | 39 | /* __ Debug definitions __________________________________________________ */ |
| 41 | 40 | ... | ... |
src/ctbkgcube/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 = ctbkgcube |
| 5 | 8 | |
| ... | ... | @@ -14,7 +17,7 @@ libctbkgcube_la_SOURCES = $(sources) |
| 14 | 17 | ctbkgcube_SOURCES = main.cpp |
| 15 | 18 | ctbkgcube_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ |
| 16 | 19 | ctbkgcube_CPPFLAGS = @CPPFLAGS@ |
| 17 | -ctbkgcube_LDADD = libctbkgcube.la | |
| 20 | +ctbkgcube_LDADD = libctbkgcube.la $(top_srcdir)/src/support/libsupport.la | |
| 18 | 21 | |
| 19 | 22 | # Parameter files |
| 20 | 23 | pfilesdir = $(prefix)/syspfiles | ... | ... |
src/ctbkgcube/ctbkgcube.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbkgcube - CTA background cube tool * | |
| 2 | + * ctbkgcube - Background cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Chia-Chun Lu * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbkgcube.cpp |
| 23 | - * @brief CTA background cube tool implementation | |
| 23 | + * @brief Background cube generation tool definition | |
| 24 | 24 | * @author Chia-Chun Lu |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -35,7 +35,6 @@ |
| 35 | 35 | /* __ Method name definitions ____________________________________________ */ |
| 36 | 36 | #define G_GET_PARAMETERS "ctbkgcube::get_parameters()" |
| 37 | 37 | #define G_GET_OBS "ctbkgcube::get_obs()" |
| 38 | -#define G_GET_EBOUNDS "ctbkgcube::get_ebounds()" | |
| 39 | 38 | #define G_SET_FROM_CNTMAP "ctbkgcube::set_from_cntmap(std::string&)" |
| 40 | 39 | #define G_FILL_CUBE "ctbkgcube::fill_cube(GCTAObservation*)" |
| 41 | 40 | |
| ... | ... | @@ -53,14 +52,11 @@ |
| 53 | 52 | /***********************************************************************//** |
| 54 | 53 | * @brief Void constructor |
| 55 | 54 | ***************************************************************************/ |
| 56 | -ctbkgcube::ctbkgcube(void) : GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) | |
| 55 | +ctbkgcube::ctbkgcube(void) : ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) | |
| 57 | 56 | { |
| 58 | 57 | // Initialise members |
| 59 | 58 | init_members(); |
| 60 | 59 | |
| 61 | - // Write header into logger | |
| 62 | - log_header(); | |
| 63 | - | |
| 64 | 60 | // Return |
| 65 | 61 | return; |
| 66 | 62 | } |
| ... | ... | @@ -75,7 +71,7 @@ ctbkgcube::ctbkgcube(void) : GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) |
| 75 | 71 | * observations container. |
| 76 | 72 | ***************************************************************************/ |
| 77 | 73 | ctbkgcube::ctbkgcube(const GObservations& obs) : |
| 78 | - GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) | |
| 74 | + ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION) | |
| 79 | 75 | { |
| 80 | 76 | // Initialise members |
| 81 | 77 | init_members(); |
| ... | ... | @@ -83,9 +79,6 @@ ctbkgcube::ctbkgcube(const GObservations& obs) : |
| 83 | 79 | // Set observations |
| 84 | 80 | m_obs = obs; |
| 85 | 81 | |
| 86 | - // Write header into logger | |
| 87 | - log_header(); | |
| 88 | - | |
| 89 | 82 | // Return |
| 90 | 83 | return; |
| 91 | 84 | } |
| ... | ... | @@ -99,14 +92,11 @@ ctbkgcube::ctbkgcube(const GObservations& obs) : |
| 99 | 92 | * @param[in] argv Array of command line arguments. |
| 100 | 93 | ***************************************************************************/ |
| 101 | 94 | ctbkgcube::ctbkgcube(int argc, char *argv[]) : |
| 102 | - GApplication(CTBKGCUBE_NAME, CTBKGCUBE_VERSION, argc, argv) | |
| 95 | + ctool(CTBKGCUBE_NAME, CTBKGCUBE_VERSION, argc, argv) | |
| 103 | 96 | { |
| 104 | 97 | // Initialise members |
| 105 | 98 | init_members(); |
| 106 | 99 | |
| 107 | - // Write header into logger | |
| 108 | - log_header(); | |
| 109 | - | |
| 110 | 100 | // Return |
| 111 | 101 | return; |
| 112 | 102 | } |
| ... | ... | @@ -117,7 +107,7 @@ ctbkgcube::ctbkgcube(int argc, char *argv[]) : |
| 117 | 107 | * |
| 118 | 108 | * @param[in] app ctbkgcube application. |
| 119 | 109 | ***************************************************************************/ |
| 120 | -ctbkgcube::ctbkgcube(const ctbkgcube& app) : GApplication(app) | |
| 110 | +ctbkgcube::ctbkgcube(const ctbkgcube& app) : ctool(app) | |
| 121 | 111 | { |
| 122 | 112 | // Initialise members |
| 123 | 113 | init_members(); |
| ... | ... | @@ -161,7 +151,7 @@ ctbkgcube& ctbkgcube::operator=(const ctbkgcube& app) |
| 161 | 151 | if (this != &app) { |
| 162 | 152 | |
| 163 | 153 | // Copy base class members |
| 164 | - this->GApplication::operator=(app); | |
| 154 | + this->ctool::operator=(app); | |
| 165 | 155 | |
| 166 | 156 | // Free members |
| 167 | 157 | free_members(); |
| ... | ... | @@ -192,10 +182,12 @@ void ctbkgcube::clear(void) |
| 192 | 182 | { |
| 193 | 183 | // Free members |
| 194 | 184 | free_members(); |
| 185 | + this->ctool::free_members(); | |
| 195 | 186 | this->GApplication::free_members(); |
| 196 | 187 | |
| 197 | 188 | // Initialise members |
| 198 | 189 | this->GApplication::init_members(); |
| 190 | + this->ctool::init_members(); | |
| 199 | 191 | init_members(); |
| 200 | 192 | |
| 201 | 193 | // Return |
| ... | ... | @@ -472,11 +464,6 @@ void ctbkgcube::copy_members(const ctbkgcube& app) |
| 472 | 464 | ***************************************************************************/ |
| 473 | 465 | void ctbkgcube::free_members(void) |
| 474 | 466 | { |
| 475 | - // Write separator into logger | |
| 476 | - if (logTerse()) { | |
| 477 | - log << std::endl; | |
| 478 | - } | |
| 479 | - | |
| 480 | 467 | // Return |
| 481 | 468 | return; |
| 482 | 469 | } |
| ... | ... | @@ -530,7 +517,7 @@ void ctbkgcube::get_parameters(void) |
| 530 | 517 | int nypix = (*this)["nypix"].integer(); |
| 531 | 518 | |
| 532 | 519 | // Get energy definition |
| 533 | - get_ebounds(); | |
| 520 | + m_ebounds = get_ebounds(); | |
| 534 | 521 | |
| 535 | 522 | // Define skymap for background cube |
| 536 | 523 | GSkymap map(proj, coordsys, xref, yref, |
| ... | ... | @@ -613,85 +600,6 @@ void ctbkgcube::get_obs(void) |
| 613 | 600 | |
| 614 | 601 | |
| 615 | 602 | /***********************************************************************//** |
| 616 | - * @brief Get energy boundaries from parameters | |
| 617 | - * | |
| 618 | - * @exception GException::invalid_value | |
| 619 | - * Energy bin definition file not defined or invalid extension | |
| 620 | - * name encountered. | |
| 621 | - * | |
| 622 | - * Get the energy boundaries from the user parameters. | |
| 623 | - ***************************************************************************/ | |
| 624 | -void ctbkgcube::get_ebounds(void) | |
| 625 | -{ | |
| 626 | - // Determine the energy binning alogrithm | |
| 627 | - std::string ebinalg = (*this)["ebinalg"].string(); | |
| 628 | - | |
| 629 | - // If we have the binning given by a file then try to get the boundaries | |
| 630 | - // from that file | |
| 631 | - if (ebinalg == "FILE") { | |
| 632 | - | |
| 633 | - // Get filename | |
| 634 | - std::string filename = (*this)["ebinfile"].filename(); | |
| 635 | - | |
| 636 | - // Check whether infile parameter is undefined | |
| 637 | - if (gammalib::toupper(filename) == "NONE") { | |
| 638 | - std::string msg = "No energy bin definition file specified. " | |
| 639 | - "Please set the \"ebinfile\" parameter to a " | |
| 640 | - "file containing the energy bin definition."; | |
| 641 | - throw GException::invalid_value(G_GET_EBOUNDS, msg); | |
| 642 | - } | |
| 643 | - | |
| 644 | - // Open fits file to check which extension is given | |
| 645 | - GFits file(filename); | |
| 646 | - | |
| 647 | - // Check first for EBOUNDS extension | |
| 648 | - if (file.contains("EBOUNDS")) { | |
| 649 | - file.close(); | |
| 650 | - m_ebounds.load(filename, "EBOUNDS"); | |
| 651 | - } | |
| 652 | - | |
| 653 | - // ... then check for ENERGYBINS extension | |
| 654 | - else if (file.contains("ENERGYBINS")) { | |
| 655 | - file.close(); | |
| 656 | - m_ebounds.load(filename, "ENERGYBINS"); | |
| 657 | - } | |
| 658 | - | |
| 659 | - // ... otherwise throw an exception | |
| 660 | - else { | |
| 661 | - file.close(); | |
| 662 | - std::string msg = "No extension with name \"EBOUNDS\" or" | |
| 663 | - " \"ENERGYBINS\" found in FITS file" | |
| 664 | - " \""+filename+"\".\n" | |
| 665 | - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | |
| 666 | - " is required if the parameter \"ebinalg\"" | |
| 667 | - " is set to \"FILE\"."; | |
| 668 | - throw GException::invalid_value(G_GET_EBOUNDS, msg); | |
| 669 | - } | |
| 670 | - } | |
| 671 | - | |
| 672 | - // ... otherwise read emin, emax and nebins | |
| 673 | - else { | |
| 674 | - | |
| 675 | - // Get the relevant parameters | |
| 676 | - double emin = (*this)["emin"].real(); | |
| 677 | - double emax = (*this)["emax"].real(); | |
| 678 | - int enumbins = (*this)["enumbins"].integer(); | |
| 679 | - bool log = ((*this)["ebinalg"].string() == "LIN") ? false : true; | |
| 680 | - | |
| 681 | - // Create energy boundaries | |
| 682 | - m_ebounds = GEbounds(enumbins, | |
| 683 | - GEnergy(emin, "TeV"), | |
| 684 | - GEnergy(emax, "TeV"), | |
| 685 | - log); | |
| 686 | - | |
| 687 | - } | |
| 688 | - | |
| 689 | - // Return | |
| 690 | - return; | |
| 691 | -} | |
| 692 | - | |
| 693 | - | |
| 694 | -/***********************************************************************//** | |
| 695 | 603 | * @brief Set background cube definition from counts map |
| 696 | 604 | * |
| 697 | 605 | * @exception GException::invalid_value | ... | ... |
src/ctbkgcube/ctbkgcube.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbkgcube - CTA background cube tool * | |
| 2 | + * ctbkgcube - Background cube generation tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2014 by Chia-Chun Lu * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbkgcube.hpp |
| 23 | - * @brief CTA background cube tool definition | |
| 23 | + * @brief Background cube generation tool definition | |
| 24 | 24 | * @author Chia-Chun Lu |
| 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 CTBKGCUBE_NAME "ctbkgcube" |
| ... | ... | @@ -39,9 +40,9 @@ |
| 39 | 40 | /***********************************************************************//** |
| 40 | 41 | * @class ctbkgcube |
| 41 | 42 | * |
| 42 | - * @brief CTA background cube tool | |
| 43 | + * @brief Background cube generation tool | |
| 43 | 44 | ***************************************************************************/ |
| 44 | -class ctbkgcube : public GApplication { | |
| 45 | +class ctbkgcube : public ctool { | |
| 45 | 46 | |
| 46 | 47 | public: |
| 47 | 48 | // Constructors and destructors |
| ... | ... | @@ -68,7 +69,6 @@ protected: |
| 68 | 69 | void free_members(void); |
| 69 | 70 | void get_parameters(void); |
| 70 | 71 | void get_obs(void); |
| 71 | - void get_ebounds(void); | |
| 72 | 72 | void set_from_cntmap(const std::string& filename); |
| 73 | 73 | void fill_cube(GCTAObservation* obs); |
| 74 | 74 | |
| ... | ... | @@ -83,9 +83,9 @@ protected: |
| 83 | 83 | |
| 84 | 84 | |
| 85 | 85 | /***********************************************************************//** |
| 86 | - * @brief Return CTA event cube containing background rate | |
| 86 | + * @brief Return event cube containing background rate | |
| 87 | 87 | * |
| 88 | - * @return CTA event cube. | |
| 88 | + * @return Background event cube. | |
| 89 | 89 | ***************************************************************************/ |
| 90 | 90 | inline |
| 91 | 91 | const GCTAEventCube& ctbkgcube::cube(void) const | ... | ... |