Commit 06e26db0cd274900f89faf3ed0563d1ed3b8f16a
1 parent
dd94aa23
Use ctool base class in ctbin tool.
The ctool base class is now used in the ctbin tool. The get_ebounds() method has been moved to the ctool base class so that it can be used also in other tools. This reduces code duplication.
Showing
8 changed files
with
196 additions
and
173 deletions
pyext/ctbin.i
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbin - CTA data binning tool * | |
| 2 | + * ctbin - Event binning tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbin.i |
| 23 | - * @brief CTA data binning tool Python interface definition | |
| 23 | + * @brief Event binning tool definition | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | %{ |
| ... | ... | @@ -33,9 +33,9 @@ |
| 33 | 33 | /***********************************************************************//** |
| 34 | 34 | * @class ctbin |
| 35 | 35 | * |
| 36 | - * @brief CTA data binning tool Python interface | |
| 36 | + * @brief Event binning tool | |
| 37 | 37 | ***************************************************************************/ |
| 38 | -class ctbin : public GApplication { | |
| 38 | +class ctbin : public ctool { | |
| 39 | 39 | public: |
| 40 | 40 | // Constructors and destructors |
| 41 | 41 | ctbin(void); |
| ... | ... | @@ -55,7 +55,7 @@ public: |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | /***********************************************************************//** |
| 58 | - * @brief CTA data binning tool Python extension | |
| 58 | + * @brief Event binning tool Python extension | |
| 59 | 59 | ***************************************************************************/ |
| 60 | 60 | %extend ctbin { |
| 61 | 61 | ctbin copy() { | ... | ... |
pyext/ctool.i
| ... | ... | @@ -38,6 +38,9 @@ class ctool : public GApplication { |
| 38 | 38 | public: |
| 39 | 39 | // Constructors and destructors |
| 40 | 40 | ctool(void); |
| 41 | + ctool(const std::string& name, const std::string& version); | |
| 42 | + ctool(const std::string& name, const std::string& version, | |
| 43 | + int argc, char* argv[]); | |
| 41 | 44 | ctool(const ctool& app); |
| 42 | 45 | virtual ~ctool(void); |
| 43 | 46 | ... | ... |
src/Makefile.am
| ... | ... | @@ -5,7 +5,8 @@ MACOSX_DEPLOYMENT_TARGET=@CONFIGURE_MACOSX_DEPLOYMENT_TARGET@ |
| 5 | 5 | @EXPORT_MACOSX_DEPLOYMENT_TARGET@export MACOSX_DEPLOYMENT_TARGET |
| 6 | 6 | |
| 7 | 7 | # Set sub directories |
| 8 | -SUBDIRS = ctbin \ | |
| 8 | +SUBDIRS = support \ | |
| 9 | + ctbin \ | |
| 9 | 10 | ctlike \ |
| 10 | 11 | ctmodel \ |
| 11 | 12 | ctobssim \ |
| ... | ... | @@ -15,8 +16,7 @@ SUBDIRS = ctbin \ |
| 15 | 16 | ctpsfcube \ |
| 16 | 17 | ctbkgcube \ |
| 17 | 18 | ctcubemask \ |
| 18 | - cttsmap \ | |
| 19 | - support | |
| 19 | + cttsmap | |
| 20 | 20 | |
| 21 | 21 | # Scripts to be distributed |
| 22 | 22 | scripts = ctools-setup \ |
| ... | ... | @@ -28,7 +28,8 @@ scripts = ctools-setup \ |
| 28 | 28 | # not have to build this library if no python bindings are used. |
| 29 | 29 | lib_LTLIBRARIES = libctools.la |
| 30 | 30 | libctools_la_SOURCES = |
| 31 | -libctools_la_LIBADD = ctbin/libctbin.la \ | |
| 31 | +libctools_la_LIBADD = support/libsupport.la \ | |
| 32 | + ctbin/libctbin.la \ | |
| 32 | 33 | ctlike/libctlike.la \ |
| 33 | 34 | ctmodel/libctmodel.la \ |
| 34 | 35 | ctobssim/libctobssim.la \ |
| ... | ... | @@ -38,8 +39,8 @@ libctools_la_LIBADD = ctbin/libctbin.la \ |
| 38 | 39 | ctpsfcube/libctpsfcube.la \ |
| 39 | 40 | ctbkgcube/libctbkgcube.la \ |
| 40 | 41 | ctcubemask/libctcubemask.la \ |
| 41 | - cttsmap/libcttsmap.la \ | |
| 42 | - support/libsupport.la | |
| 42 | + cttsmap/libcttsmap.la | |
| 43 | + | |
| 43 | 44 | |
| 44 | 45 | # Distribute scripts |
| 45 | 46 | EXTRA_DIST = $(scripts) | ... | ... |
src/ctbin/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 = ctbin |
| 5 | 8 | |
| ... | ... | @@ -14,7 +17,7 @@ libctbin_la_SOURCES = $(sources) |
| 14 | 17 | ctbin_SOURCES = main.cpp |
| 15 | 18 | ctbin_LDFLAGS = $(LIB_LINK_OPTION) @LDFLAGS@ |
| 16 | 19 | ctbin_CPPFLAGS = @CPPFLAGS@ |
| 17 | -ctbin_LDADD = libctbin.la | |
| 20 | +ctbin_LDADD = libctbin.la $(top_srcdir)/src/support/libsupport.la | |
| 18 | 21 | |
| 19 | 22 | # Parameter files |
| 20 | 23 | pfilesdir = $(prefix)/syspfiles | ... | ... |
src/ctbin/ctbin.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbin - CTA data binning tool * | |
| 2 | + * ctbin - Event binning tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbin.cpp |
| 23 | - * @brief CTA data binning tool implementation | |
| 23 | + * @brief Event binning tool implementation | |
| 24 | 24 | * @author Juergen Knoedlseder |
| 25 | 25 | */ |
| 26 | 26 | |
| ... | ... | @@ -51,14 +51,11 @@ |
| 51 | 51 | /***********************************************************************//** |
| 52 | 52 | * @brief Void constructor |
| 53 | 53 | ***************************************************************************/ |
| 54 | -ctbin::ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) | |
| 54 | +ctbin::ctbin(void) : ctool(CTBIN_NAME, CTBIN_VERSION) | |
| 55 | 55 | { |
| 56 | 56 | // Initialise members |
| 57 | 57 | init_members(); |
| 58 | 58 | |
| 59 | - // Write header into logger | |
| 60 | - log_header(); | |
| 61 | - | |
| 62 | 59 | // Return |
| 63 | 60 | return; |
| 64 | 61 | } |
| ... | ... | @@ -72,8 +69,7 @@ ctbin::ctbin(void) : GApplication(CTBIN_NAME, CTBIN_VERSION) |
| 72 | 69 | * This method creates an instance of the class by copying an existing |
| 73 | 70 | * observations container. |
| 74 | 71 | ***************************************************************************/ |
| 75 | -ctbin::ctbin(const GObservations& obs) : | |
| 76 | - GApplication(CTBIN_NAME, CTBIN_VERSION) | |
| 72 | +ctbin::ctbin(const GObservations& obs) : ctool(CTBIN_NAME, CTBIN_VERSION) | |
| 77 | 73 | { |
| 78 | 74 | // Initialise members |
| 79 | 75 | init_members(); |
| ... | ... | @@ -81,9 +77,6 @@ ctbin::ctbin(const GObservations& obs) : |
| 81 | 77 | // Set observations |
| 82 | 78 | m_obs = obs; |
| 83 | 79 | |
| 84 | - // Write header into logger | |
| 85 | - log_header(); | |
| 86 | - | |
| 87 | 80 | // Return |
| 88 | 81 | return; |
| 89 | 82 | } |
| ... | ... | @@ -97,14 +90,11 @@ ctbin::ctbin(const GObservations& obs) : |
| 97 | 90 | * @param[in] argv Array of command line arguments. |
| 98 | 91 | ***************************************************************************/ |
| 99 | 92 | ctbin::ctbin(int argc, char *argv[]) : |
| 100 | - GApplication(CTBIN_NAME, CTBIN_VERSION, argc, argv) | |
| 93 | + ctool(CTBIN_NAME, CTBIN_VERSION, argc, argv) | |
| 101 | 94 | { |
| 102 | 95 | // Initialise members |
| 103 | 96 | init_members(); |
| 104 | 97 | |
| 105 | - // Write header into logger | |
| 106 | - log_header(); | |
| 107 | - | |
| 108 | 98 | // Return |
| 109 | 99 | return; |
| 110 | 100 | } |
| ... | ... | @@ -115,7 +105,7 @@ ctbin::ctbin(int argc, char *argv[]) : |
| 115 | 105 | * |
| 116 | 106 | * @param[in] app Application. |
| 117 | 107 | ***************************************************************************/ |
| 118 | -ctbin::ctbin(const ctbin& app) : GApplication(app) | |
| 108 | +ctbin::ctbin(const ctbin& app) : ctool(app) | |
| 119 | 109 | { |
| 120 | 110 | // Initialise members |
| 121 | 111 | init_members(); |
| ... | ... | @@ -158,7 +148,7 @@ ctbin& ctbin::operator=(const ctbin& app) |
| 158 | 148 | if (this != &app) { |
| 159 | 149 | |
| 160 | 150 | // Copy base class members |
| 161 | - this->GApplication::operator=(app); | |
| 151 | + this->ctool::operator=(app); | |
| 162 | 152 | |
| 163 | 153 | // Free members |
| 164 | 154 | free_members(); |
| ... | ... | @@ -189,10 +179,12 @@ void ctbin::clear(void) |
| 189 | 179 | { |
| 190 | 180 | // Free members |
| 191 | 181 | free_members(); |
| 182 | + this->ctool::free_members(); | |
| 192 | 183 | this->GApplication::free_members(); |
| 193 | 184 | |
| 194 | 185 | // Initialise members |
| 195 | 186 | this->GApplication::init_members(); |
| 187 | + this->ctool::init_members(); | |
| 196 | 188 | init_members(); |
| 197 | 189 | |
| 198 | 190 | // Return |
| ... | ... | @@ -371,12 +363,7 @@ void ctbin::init_members(void) |
| 371 | 363 | m_outfile.clear(); |
| 372 | 364 | m_proj.clear(); |
| 373 | 365 | m_coordsys.clear(); |
| 374 | - m_ebinalg.clear(); | |
| 375 | - m_ebinfile.clear(); | |
| 376 | 366 | m_usepnt = false; |
| 377 | - m_emin = 0.0; | |
| 378 | - m_emax = 0.0; | |
| 379 | - m_enumbins = 0; | |
| 380 | 367 | m_xref = 0.0; |
| 381 | 368 | m_yref = 0.0; |
| 382 | 369 | m_binsz = 0.0; |
| ... | ... | @@ -412,12 +399,7 @@ void ctbin::copy_members(const ctbin& app) |
| 412 | 399 | m_outfile = app.m_outfile; |
| 413 | 400 | m_proj = app.m_proj; |
| 414 | 401 | m_coordsys = app.m_coordsys; |
| 415 | - m_ebinalg = app.m_ebinalg; | |
| 416 | - m_ebinfile = app.m_ebinfile; | |
| 417 | 402 | m_usepnt = app.m_usepnt; |
| 418 | - m_emin = app.m_emin; | |
| 419 | - m_emax = app.m_emax; | |
| 420 | - m_enumbins = app.m_enumbins; | |
| 421 | 403 | m_xref = app.m_xref; |
| 422 | 404 | m_yref = app.m_yref; |
| 423 | 405 | m_binsz = app.m_binsz; |
| ... | ... | @@ -443,11 +425,6 @@ void ctbin::copy_members(const ctbin& app) |
| 443 | 425 | ***************************************************************************/ |
| 444 | 426 | void ctbin::free_members(void) |
| 445 | 427 | { |
| 446 | - // Write separator into logger | |
| 447 | - if (logTerse()) { | |
| 448 | - log << std::endl; | |
| 449 | - } | |
| 450 | - | |
| 451 | 428 | // Return |
| 452 | 429 | return; |
| 453 | 430 | } |
| ... | ... | @@ -464,6 +441,9 @@ void ctbin::free_members(void) |
| 464 | 441 | ***************************************************************************/ |
| 465 | 442 | void ctbin::get_parameters(void) |
| 466 | 443 | { |
| 444 | + // Initialize energy boundaries | |
| 445 | + m_ebounds.clear(); | |
| 446 | + | |
| 467 | 447 | // If there are no observations in container then add a single CTA |
| 468 | 448 | // observation using the parameters from the parameter file |
| 469 | 449 | if (m_obs.size() == 0) { |
| ... | ... | @@ -506,19 +486,9 @@ void ctbin::get_parameters(void) |
| 506 | 486 | m_binsz = (*this)["binsz"].real(); |
| 507 | 487 | m_nxpix = (*this)["nxpix"].integer(); |
| 508 | 488 | m_nypix = (*this)["nypix"].integer(); |
| 509 | - m_ebinalg = (*this)["ebinalg"].string(); | |
| 510 | - | |
| 511 | - // If we have the binning given by a file then read filename | |
| 512 | - if (m_ebinalg == "FILE") { | |
| 513 | - m_ebinfile = (*this)["ebinfile"].filename(); | |
| 514 | - } | |
| 515 | 489 | |
| 516 | - // ... otherwise read emin, emax and nebins | |
| 517 | - else{ | |
| 518 | - m_emin = (*this)["emin"].real(); | |
| 519 | - m_emax = (*this)["emax"].real(); | |
| 520 | - m_enumbins = (*this)["enumbins"].integer(); | |
| 521 | - } | |
| 490 | + // Set energy boundaries | |
| 491 | + m_ebounds = get_ebounds(); | |
| 522 | 492 | |
| 523 | 493 | // Optionally read ahead parameters so that they get correctly |
| 524 | 494 | // dumped into the log file |
| ... | ... | @@ -546,7 +516,6 @@ void ctbin::init_cube(void) |
| 546 | 516 | m_ontime = 0.0; |
| 547 | 517 | m_livetime = 0.0; |
| 548 | 518 | m_cube.clear(); |
| 549 | - m_ebounds.clear(); | |
| 550 | 519 | m_gti.clear(); |
| 551 | 520 | |
| 552 | 521 | // Set event cube centre, either from the user parameters or from the |
| ... | ... | @@ -587,13 +556,10 @@ void ctbin::init_cube(void) |
| 587 | 556 | |
| 588 | 557 | } // endif: used pointing |
| 589 | 558 | |
| 590 | - // Set energy boundaries | |
| 591 | - get_ebounds(); | |
| 592 | - | |
| 593 | 559 | // Create skymap |
| 594 | 560 | m_cube = GSkymap(m_proj, m_coordsys, |
| 595 | 561 | xref, yref, -m_binsz, m_binsz, |
| 596 | - m_nxpix, m_nypix, m_enumbins); | |
| 562 | + m_nxpix, m_nypix, m_ebounds.size()); | |
| 597 | 563 | |
| 598 | 564 | // Return |
| 599 | 565 | return; |
| ... | ... | @@ -779,80 +745,3 @@ void ctbin::obs_cube(void) |
| 779 | 745 | // Return |
| 780 | 746 | return; |
| 781 | 747 | } |
| 782 | - | |
| 783 | - | |
| 784 | -/***********************************************************************//** | |
| 785 | - * @brief Get the energy boundaries | |
| 786 | - * | |
| 787 | - * @exception GException::invalid_value | |
| 788 | - * No valid energy boundary extension found. | |
| 789 | - * | |
| 790 | - * Get the energy boundaries according to the user parameters. The method | |
| 791 | - * supports loading of energy boundary information from the EBOUNDS or | |
| 792 | - * ENERGYBINS extension, or setting energy boundaries using a linear | |
| 793 | - * or logarithmical spacing. | |
| 794 | - * | |
| 795 | - * @todo Ultimately this method should go in a support library as it is | |
| 796 | - * used by several ctools. | |
| 797 | - ***************************************************************************/ | |
| 798 | -void ctbin::get_ebounds(void) | |
| 799 | -{ | |
| 800 | - // Initialse energy boundary information | |
| 801 | - m_ebounds.clear(); | |
| 802 | - | |
| 803 | - // Check whether energy binning information should be read from a FITS | |
| 804 | - // file ... | |
| 805 | - if (m_ebinalg == "FILE") { | |
| 806 | - | |
| 807 | - // Open energy boundary file using the EBOUNDS or ENERGYBINS | |
| 808 | - // extension. Throw an exception if opening fails. | |
| 809 | - GFits file(m_ebinfile); | |
| 810 | - if (file.contains("EBOUNDS")) { | |
| 811 | - file.close(); | |
| 812 | - m_ebounds.load(m_ebinfile,"EBOUNDS"); | |
| 813 | - } | |
| 814 | - else if (file.contains("ENERGYBINS")) { | |
| 815 | - file.close(); | |
| 816 | - m_ebounds.load(m_ebinfile,"ENERGYBINS"); | |
| 817 | - } | |
| 818 | - else { | |
| 819 | - file.close(); | |
| 820 | - std::string msg = "No extension with name \"EBOUNDS\" or" | |
| 821 | - " \"ENERGYBINS\" found in FITS file" | |
| 822 | - " \""+m_ebinfile+"\".\n" | |
| 823 | - "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | |
| 824 | - " is required if the parameter \"ebinalg\"" | |
| 825 | - " is set to \"FILE\"."; | |
| 826 | - throw GException::invalid_value(G_GET_EBOUNDS, msg); | |
| 827 | - } | |
| 828 | - | |
| 829 | - // Set enumbins parameter to number of ebounds | |
| 830 | - m_enumbins = m_ebounds.size(); | |
| 831 | - | |
| 832 | - } // endif: ebinalg was "FILE" | |
| 833 | - | |
| 834 | - // ... otherwise use a linear or a logarithmically-spaced energy binning | |
| 835 | - else { | |
| 836 | - | |
| 837 | - // Initialise log mode for ebinning | |
| 838 | - bool log = true; | |
| 839 | - | |
| 840 | - // check if algorithm is linear | |
| 841 | - if (m_ebinalg == "LIN") { | |
| 842 | - log = false; | |
| 843 | - } | |
| 844 | - | |
| 845 | - // todo: should we also check if m_ebinalg is "LOG" | |
| 846 | - // and throw an exception if neither LIN/LOG/FILE | |
| 847 | - // is given? | |
| 848 | - | |
| 849 | - // Setup energy range covered by data | |
| 850 | - GEnergy emin(m_emin, "TeV"); | |
| 851 | - GEnergy emax(m_emax, "TeV"); | |
| 852 | - m_ebounds = GEbounds(m_enumbins, emin, emax, log); | |
| 853 | - | |
| 854 | - } //endif: ebinalg was not "FILE" | |
| 855 | - | |
| 856 | - // Return | |
| 857 | - return; | |
| 858 | -} | ... | ... |
src/ctbin/ctbin.hpp
| 1 | 1 | /*************************************************************************** |
| 2 | - * ctbin - CTA data binning tool * | |
| 2 | + * ctbin - Event binning tool * | |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | 4 | * copyright (C) 2010-2014 by Juergen Knoedlseder * |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| ... | ... | @@ -20,7 +20,7 @@ |
| 20 | 20 | ***************************************************************************/ |
| 21 | 21 | /** |
| 22 | 22 | * @file ctbin.hpp |
| 23 | - * @brief CTA data binning tool definition | |
| 23 | + * @brief Event binning 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 CTBIN_NAME "ctbin" |
| ... | ... | @@ -39,10 +40,10 @@ |
| 39 | 40 | /***********************************************************************//** |
| 40 | 41 | * @class ctbin |
| 41 | 42 | * |
| 42 | - * @brief CTA data binning tool interface defintion | |
| 43 | + * @brief Event binning tool | |
| 43 | 44 | * |
| 44 | - * This class bins CTA event list(s) into a single counts cube. The class | |
| 45 | - * can operate on predefined observation containers, on individual event list | |
| 45 | + * This class bins event list(s) into a single counts cube. The class can | |
| 46 | + * operate on predefined observation containers, on individual event list | |
| 46 | 47 | * FITS files, and on observation definition XML files. |
| 47 | 48 | * |
| 48 | 49 | * If multiple event lists are specified in the observation container or the |
| ... | ... | @@ -60,7 +61,7 @@ |
| 60 | 61 | * PSF cubes should be used for response computation. This is however not |
| 61 | 62 | * yet fully implemented. |
| 62 | 63 | ***************************************************************************/ |
| 63 | -class ctbin : public GApplication { | |
| 64 | +class ctbin : public ctool { | |
| 64 | 65 | public: |
| 65 | 66 | // Constructors and destructors |
| 66 | 67 | ctbin(void); |
| ... | ... | @@ -89,33 +90,27 @@ protected: |
| 89 | 90 | void init_cube(void); |
| 90 | 91 | void fill_cube(GCTAObservation* obs); |
| 91 | 92 | void obs_cube(void); |
| 92 | - void get_ebounds(void); | |
| 93 | 93 | |
| 94 | 94 | // User parameters |
| 95 | - std::string m_evfile; //!< Input event list or XML file | |
| 96 | - std::string m_outfile; //!< Output counts map or XML file | |
| 97 | - bool m_usepnt; //!< Use pointing instead of xref/yref parameters | |
| 98 | - double m_emin; //!< Lower energy | |
| 99 | - double m_emax; //!< Upper energy | |
| 100 | - int m_enumbins; //!< Number of energy bins | |
| 101 | - std::string m_proj; //!< WCS projection | |
| 102 | - std::string m_coordsys; //!< Coordinate system | |
| 103 | - std::string m_ebinalg; //!< Algorithm for energy binning | |
| 104 | - std::string m_ebinfile; //!< FITS-file containing energy binning | |
| 105 | - double m_xref; //!< Longitude reference coordinate | |
| 106 | - double m_yref; //!< Latitude reference coordinate | |
| 107 | - double m_binsz; //!< Pixel size | |
| 108 | - int m_nxpix; //!< Number of pixels in longitude | |
| 109 | - int m_nypix; //!< Number of pixels in latitude | |
| 95 | + std::string m_evfile; //!< Input event list or XML file | |
| 96 | + std::string m_outfile; //!< Output counts map or XML file | |
| 97 | + bool m_usepnt; //!< Use pointing instead of xref/yref parameters | |
| 98 | + std::string m_proj; //!< WCS projection | |
| 99 | + std::string m_coordsys; //!< Coordinate system | |
| 100 | + double m_xref; //!< Longitude reference coordinate | |
| 101 | + double m_yref; //!< Latitude reference coordinate | |
| 102 | + double m_binsz; //!< Pixel size | |
| 103 | + int m_nxpix; //!< Number of pixels in longitude | |
| 104 | + int m_nypix; //!< Number of pixels in latitude | |
| 110 | 105 | |
| 111 | 106 | // Protected members |
| 112 | - GObservations m_obs; //!< Observation container | |
| 113 | - bool m_read_ahead; //!< Read ahead parameters | |
| 114 | - GSkymap m_cube; //!< Event cube | |
| 115 | - GEbounds m_ebounds; //!< Energy boundaries | |
| 116 | - GGti m_gti; //!< Good time intervals | |
| 117 | - double m_ontime; //!< Total ontime | |
| 118 | - double m_livetime; //!< Total livetime | |
| 107 | + GObservations m_obs; //!< Observation container | |
| 108 | + bool m_read_ahead; //!< Read ahead parameters | |
| 109 | + GSkymap m_cube; //!< Event cube | |
| 110 | + GEbounds m_ebounds; //!< Energy boundaries | |
| 111 | + GGti m_gti; //!< Good time intervals | |
| 112 | + double m_ontime; //!< Total ontime | |
| 113 | + double m_livetime; //!< Total livetime | |
| 119 | 114 | }; |
| 120 | 115 | |
| 121 | 116 | /***********************************************************************//** |
| ... | ... | @@ -135,7 +130,7 @@ const GObservations& ctbin::obs(void) const |
| 135 | 130 | * |
| 136 | 131 | * @return Event cube |
| 137 | 132 | * |
| 138 | - * Returns a CTA event cube built from the ctbin member information. | |
| 133 | + * Returns a event cube built from the ctbin member information. | |
| 139 | 134 | ***************************************************************************/ |
| 140 | 135 | inline |
| 141 | 136 | GCTAEventCube ctbin::cube(void) const | ... | ... |
src/support/ctool.cpp
| ... | ... | @@ -28,10 +28,10 @@ |
| 28 | 28 | #ifdef HAVE_CONFIG_H |
| 29 | 29 | #include <config.h> |
| 30 | 30 | #endif |
| 31 | -//#include <cstdio> | |
| 32 | 31 | #include "ctool.hpp" |
| 33 | 32 | |
| 34 | 33 | /* __ Method name definitions ____________________________________________ */ |
| 34 | +#define G_GET_EBOUNDS "ctool::get_ebounds()" | |
| 35 | 35 | |
| 36 | 36 | /* __ Debug definitions __________________________________________________ */ |
| 37 | 37 | |
| ... | ... | @@ -52,6 +52,52 @@ ctool::ctool(void) : GApplication() |
| 52 | 52 | // Initialise members |
| 53 | 53 | init_members(); |
| 54 | 54 | |
| 55 | + // Write header into logger | |
| 56 | + log_header(); | |
| 57 | + | |
| 58 | + // Return | |
| 59 | + return; | |
| 60 | +} | |
| 61 | + | |
| 62 | + | |
| 63 | +/***********************************************************************//** | |
| 64 | + * @brief Name constructor | |
| 65 | + * | |
| 66 | + * @param[in] name Application name. | |
| 67 | + * @param[in] version Application version. | |
| 68 | + ***************************************************************************/ | |
| 69 | +ctool::ctool(const std::string& name, const std::string& version) : | |
| 70 | + GApplication(name, version) | |
| 71 | +{ | |
| 72 | + // Initialise members | |
| 73 | + init_members(); | |
| 74 | + | |
| 75 | + // Write header into logger | |
| 76 | + log_header(); | |
| 77 | + | |
| 78 | + // Return | |
| 79 | + return; | |
| 80 | +} | |
| 81 | + | |
| 82 | + | |
| 83 | +/***********************************************************************//** | |
| 84 | + * @brief Command line constructor | |
| 85 | + * | |
| 86 | + * @param[in] name Application name. | |
| 87 | + * @param[in] version Application version. | |
| 88 | + * @param[in] argc Number of arguments in command line. | |
| 89 | + * @param[in] argv Array of command line arguments. | |
| 90 | + ***************************************************************************/ | |
| 91 | +ctool::ctool(const std::string& name, const std::string& version, | |
| 92 | + int argc, char *argv[]) : | |
| 93 | + GApplication(name, version, argc, argv) | |
| 94 | +{ | |
| 95 | + // Initialise members | |
| 96 | + init_members(); | |
| 97 | + | |
| 98 | + // Write header into logger | |
| 99 | + log_header(); | |
| 100 | + | |
| 55 | 101 | // Return |
| 56 | 102 | return; |
| 57 | 103 | } |
| ... | ... | @@ -168,6 +214,88 @@ void ctool::copy_members(const ctool& app) |
| 168 | 214 | ***************************************************************************/ |
| 169 | 215 | void ctool::free_members(void) |
| 170 | 216 | { |
| 217 | + // Write separator into logger | |
| 218 | + if (logTerse()) { | |
| 219 | + log << std::endl; | |
| 220 | + } | |
| 221 | + | |
| 171 | 222 | // Return |
| 172 | 223 | return; |
| 173 | 224 | } |
| 225 | + | |
| 226 | + | |
| 227 | +/***********************************************************************//** | |
| 228 | + * @brief Get the energy boundaries | |
| 229 | + * | |
| 230 | + * @exception GException::invalid_value | |
| 231 | + * No valid energy boundary extension found. | |
| 232 | + * | |
| 233 | + * Get the energy boundaries according to the user parameters. The method | |
| 234 | + * supports loading of energy boundary information from the EBOUNDS or | |
| 235 | + * ENERGYBINS extension, or setting energy boundaries using a linear | |
| 236 | + * or logarithmical spacing. | |
| 237 | + ***************************************************************************/ | |
| 238 | +GEbounds ctool::get_ebounds(void) | |
| 239 | +{ | |
| 240 | + // Allocate energy boundaries | |
| 241 | + GEbounds ebounds; | |
| 242 | + | |
| 243 | + // Get energy binning algorithm | |
| 244 | + std::string ebinalg = (*this)["ebinalg"].string(); | |
| 245 | + | |
| 246 | + // If energy binning algorithm is of type "FILE" (case sensitive), then | |
| 247 | + // read energy boundaries from FITS file ... | |
| 248 | + if (ebinalg == "FILE") { | |
| 249 | + | |
| 250 | + // Get filename | |
| 251 | + std::string ebinfile = (*this)["ebinfile"].filename(); | |
| 252 | + | |
| 253 | + // Open energy boundary file using the EBOUNDS or ENERGYBINS | |
| 254 | + // extension. Throw an exception if opening fails. | |
| 255 | + GFits file(ebinfile); | |
| 256 | + if (file.contains("EBOUNDS")) { | |
| 257 | + file.close(); | |
| 258 | + ebounds.load(ebinfile,"EBOUNDS"); | |
| 259 | + } | |
| 260 | + else if (file.contains("ENERGYBINS")) { | |
| 261 | + file.close(); | |
| 262 | + ebounds.load(ebinfile,"ENERGYBINS"); | |
| 263 | + } | |
| 264 | + else { | |
| 265 | + file.close(); | |
| 266 | + std::string msg = "No extension with name \"EBOUNDS\" or" | |
| 267 | + " \"ENERGYBINS\" found in FITS file" | |
| 268 | + " \""+ebinfile+"\".\n" | |
| 269 | + "An \"EBOUNDS\" or \"ENERGYBINS\" extension" | |
| 270 | + " is required if the parameter \"ebinalg\"" | |
| 271 | + " is set to \"FILE\"."; | |
| 272 | + throw GException::invalid_value(G_GET_EBOUNDS, msg); | |
| 273 | + } | |
| 274 | + | |
| 275 | + } // endif: ebinalg was "FILE" | |
| 276 | + | |
| 277 | + // ... otherwise use a linear or a logarithmically-spaced energy binning | |
| 278 | + else { | |
| 279 | + | |
| 280 | + // Get task parameters | |
| 281 | + double emin = (*this)["emin"].real(); | |
| 282 | + double emax = (*this)["emax"].real(); | |
| 283 | + int enumbins = (*this)["enumbins"].integer(); | |
| 284 | + | |
| 285 | + // Initialise log mode for ebinning | |
| 286 | + bool log = true; | |
| 287 | + | |
| 288 | + // Check if algorithm is linear | |
| 289 | + if (ebinalg == "LIN") { | |
| 290 | + log = false; | |
| 291 | + } | |
| 292 | + | |
| 293 | + // Setup energy bins | |
| 294 | + ebounds = GEbounds(enumbins, GEnergy(emin, "TeV"), | |
| 295 | + GEnergy(emax, "TeV"), log); | |
| 296 | + | |
| 297 | + } // endelse: ebinalg was not "FILE" | |
| 298 | + | |
| 299 | + // Return energy boundaries | |
| 300 | + return ebounds; | |
| 301 | +} | ... | ... |
src/support/ctool.hpp
| ... | ... | @@ -43,19 +43,23 @@ class ctool : public GApplication { |
| 43 | 43 | public: |
| 44 | 44 | // Constructors and destructors |
| 45 | 45 | ctool(void); |
| 46 | + ctool(const std::string& name, const std::string& version); | |
| 47 | + ctool(const std::string& name, const std::string& version, | |
| 48 | + int argc, char* argv[]); | |
| 46 | 49 | ctool(const ctool& app); |
| 47 | 50 | virtual ~ctool(void); |
| 48 | 51 | |
| 49 | 52 | // Operators |
| 50 | 53 | ctool& operator=(const ctool& app); |
| 51 | 54 | |
| 52 | - // Methods | |
| 55 | + // Public methods | |
| 53 | 56 | |
| 54 | 57 | protected: |
| 55 | 58 | // Protected methods |
| 56 | - void init_members(void); | |
| 57 | - void copy_members(const ctool& app); | |
| 58 | - void free_members(void); | |
| 59 | + void init_members(void); | |
| 60 | + void copy_members(const ctool& app); | |
| 61 | + void free_members(void); | |
| 62 | + GEbounds get_ebounds(void); | |
| 59 | 63 | }; |
| 60 | 64 | |
| 61 | 65 | #endif /* CTOOL_HPP */ | ... | ... |