diff --git a/AUTHORS b/AUTHORS index b1c349e..72430a1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,4 +1,4 @@ Juergen Knoedlseder (jurgen.knodlseder@irap.omp.eu) Jean-Baptiste Cayrou (cayrou@etud.insa-toulouse.fr) Christoph Deil (Christoph.Deil@mpi-hd.mpg.de) - +Michael Mayer (michael.mayer@desy.de) diff --git a/ChangeLog b/ChangeLog index 07cf961..5d72abb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,4 @@ -2013-11-19 Juergen Knoedlseder +2013-11-20 Juergen Knoedlseder * Version 0.7.0 released ======================== @@ -6,6 +6,7 @@ Adapt to GammaLib-00-08-00 interface ctobssim now only simulates events within ROI and supports all kinds of data space models + ctbin now implements LIN and FILE binning algorithms 2012-12-21 Juergen Knoedlseder diff --git a/NEWS b/NEWS index 0f1e26a..599027b 100644 --- a/NEWS +++ b/NEWS @@ -2,7 +2,7 @@ New Features and Important Changes in ctools 00-07-00 Author(s) : Juergen Knoedlseder -19 November 2013 +20 November 2013 1. Introduction @@ -45,7 +45,12 @@ None 6. ctbin - CTA event binning ---------------------------- -None +The ebinalg parameter is now used to specify the type of binning. +Linear (LIN) binning and binning retrieved from a FITS file (FILE) +is now supported. For the latter, an extension named EBOUNDS or +ENERGYBINS is expected. + +The ebinalg and ebinfile parameters are now automatic. 7. ctlike - CTA maximum likelihood fitting diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index cc26ad9..b66891f 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -432,9 +432,19 @@ void ctbin::get_parameters(void) m_xref = (*this)["xref"].real(); m_yref = (*this)["yref"].real(); } - m_emin = (*this)["emin"].real(); - m_emax = (*this)["emax"].real(); - m_enumbins = (*this)["enumbins"].integer(); + m_ebinalg = (*this)["ebinalg"].string(); + + // If we have the binning given by a file then read filename + if (m_ebinalg == "FILE") { + m_ebinfile = (*this)["ebinfile"].filename(); + } + + // ... otherwise read emin, emax and nebins + else{ + m_emin = (*this)["emin"].real(); + m_emax = (*this)["emax"].real(); + m_enumbins = (*this)["enumbins"].integer(); + } m_proj = (*this)["proj"].string(); m_coordsys = (*this)["coordsys"].string(); m_binsz = (*this)["binsz"].real(); @@ -483,10 +493,74 @@ void ctbin::bin_events(GCTAObservation* obs) throw GException::no_list(G_BIN_EVENTS); } - // Setup energy range covered by data - GEnergy emin(m_emin, "TeV"); - GEnergy emax(m_emax, "TeV"); - GEbounds ebds(m_enumbins, emin, emax); + // Initialise empty Ebounds object + GEbounds ebds; + + // First check wether we have FITS-file defining + // the binning + if (m_ebinalg == "FILE") { + + // Open fits file to check which extension is given + GFits file(m_ebinfile); + + if (file.hashdu("EBOUNDS")) { + + // Close file and load ebounds + file.close(); + ebds.load(m_ebinfile,"EBOUNDS"); + + } // endif: EBOUNDS extension was given + + else if (file.hashdu("ENERGYBINS")) { + + // Close file and load ebounds + file.close(); + ebds.load(m_ebinfile,"ENERGYBINS"); + + } // endelse: ENERGYBINS extension was given + + else { + + // Close file + file.close(); + + // Signal that no energy boundaries have been found + std::string msg = "No extension with name \"EBOUNDS\" or" + " \"ENERGYBINS\" found in FITS file" + " \""+m_ebinfile+"\".\n" + "An \"EBOUNDS\" or \"ENERGYBINS\" extension" + " is required if the parameter \"ebinalg\"" + " is set to \"FILE\"."; + throw GException::invalid_value(G_BIN_EVENTS, msg); + + } // endelse: no suited extension found + + // Set enumbins parameter to number of ebounds + m_enumbins = ebds.size(); + + } // endif: ebinalg was "FILE" + + else { + + // Initialise log mode for ebinning + bool log = true; + + // check if algorithm is linear + if (m_ebinalg == "LIN") { + log = false; + } + + // todo: should we also check if m_ebinalg is "LOG" + // and throw an exception if neither LIN/LOG/FILE + // is given? + + // Setup energy range covered by data + GEnergy emin(m_emin, "TeV"); + GEnergy emax(m_emax, "TeV"); + GEbounds ebounds(m_enumbins, emin, emax,log); + ebds = ebounds; + + } //endif: ebinalg was not "FILE" // Get Good Time intervals GGti gti = obs->events()->gti(); @@ -605,6 +679,8 @@ void ctbin::init_members(void) m_prefix.clear(); m_proj.clear(); m_coordsys.clear(); + m_ebinalg.clear(); + m_ebinfile.clear(); m_usepnt = false; m_emin = 0.0; m_emax = 0.0; @@ -642,6 +718,8 @@ void ctbin::copy_members(const ctbin& app) m_prefix = app.m_prefix; m_proj = app.m_proj; m_coordsys = app.m_coordsys; + m_ebinalg = app.m_ebinalg; + m_ebinfile = app.m_ebinfile; m_usepnt = app.m_usepnt; m_emin = app.m_emin; m_emax = app.m_emax; diff --git a/src/ctbin/ctbin.hpp b/src/ctbin/ctbin.hpp index 0aa70d3..79eb3f7 100644 --- a/src/ctbin/ctbin.hpp +++ b/src/ctbin/ctbin.hpp @@ -33,7 +33,7 @@ /* __Definitions _________________________________________________________ */ #define CTBIN_NAME "ctbin" -#define CTBIN_VERSION "00-04-00" +#define CTBIN_VERSION "00-05-00" /***********************************************************************//** @@ -89,6 +89,8 @@ protected: int m_enumbins; //!< Number of energy bins std::string m_proj; //!< WCS projection std::string m_coordsys; //!< Coordinate system + std::string m_ebinalg; //!< Algorithm for energy binning + std::string m_ebinfile; //!< FITS-file containing energy binning double m_xref; //!< Longitude reference coordinate double m_yref; //!< Latitude reference coordinate double m_binsz; //!< Pixel size diff --git a/src/ctbin/ctbin.par b/src/ctbin/ctbin.par index 54790b1..af2e156 100644 --- a/src/ctbin/ctbin.par +++ b/src/ctbin/ctbin.par @@ -5,7 +5,7 @@ # ------------------------------------------------------------------------- # # # # File: ctbin.par # -# Version: 00-04-00 # +# Version: 00-05-00 # # # # Author: Jurgen Knodlseder # # Jurgen.Knodlseder@irap.omp.eu # @@ -23,11 +23,11 @@ prefix, s, h, "cntmap_",,,"Prefix for counts maps in observation definition fil # # Energy binning parameters #========================== -ebinalg, s, h, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins" +ebinalg, s, a, "LOG", FILE|LIN|LOG,,"Algorithm for defining energy bins" emin, r, a, 0.1,,,"Start value for first energy bin in TeV" emax, r, a, 100.0,,,"Stop value for last energy bin in TeV" enumbins, i, a, 20,,,"Number of energy bins" -ebinfile, f, h, "NONE",,,"Name of the file containing the energy bin definition" +ebinfile, f, a, "NONE",,,"Name of the file containing the energy bin definition" # # Spatial binning parameters #=========================== diff --git a/test/test_ctools.sh b/test/test_ctools.sh index d2805cc..7b5076b 100755 --- a/test/test_ctools.sh +++ b/test/test_ctools.sh @@ -143,6 +143,7 @@ $ctbin evfile="events.fits" \ emin=0.1 \ emax=100.0 \ enumbins=20 \ + ebinalg="LOG" \ nxpix=200 \ nypix=200 \ binsz=0.02 \ @@ -165,6 +166,7 @@ $ctbin evfile="events2.fits" \ emin=0.3 \ emax=8.0 \ enumbins=10 \ + ebinalg="LOG" \ nxpix=50 \ nypix=50 \ binsz=0.02 \