From b2608b4d9e795908693df5051fb203a824f1a60a Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Tue, 13 Jan 2015 22:57:54 +0100 Subject: [PATCH] Review code. --- src/ctbin/ctbin.cpp | 21 ++++++++++----------- src/ctbkgcube/ctbkgcube.cpp | 22 ++++++++++++---------- src/ctbkgcube/ctbkgcube.hpp | 7 +++---- src/ctbkgcube/ctbkgcube.par | 2 +- src/ctbutterfly/ctbutterfly.cpp | 24 +++++++++++------------- src/ctbutterfly/ctbutterfly.hpp | 4 ++-- src/ctbutterfly/ctbutterfly.par | 4 ++-- src/ctcubemask/ctcubemask.cpp | 42 ++++++++++++++++++++---------------------- src/ctcubemask/ctcubemask.hpp | 3 +-- src/ctcubemask/ctcubemask.par | 2 +- src/ctexpcube/ctexpcube.cpp | 26 ++++++++++++++------------ src/ctexpcube/ctexpcube.par | 2 +- src/ctlike/ctlike.cpp | 15 +++++++++------ src/ctlike/ctlike.hpp | 4 ++-- src/ctlike/ctlike.par | 14 +++++++------- src/ctmodel/ctmodel.par | 4 ++-- src/ctobssim/ctobssim.cpp | 20 +++++++++----------- src/ctobssim/ctobssim.hpp | 4 ++-- src/ctobssim/ctobssim.par | 8 ++++---- src/ctpsfcube/ctpsfcube.cpp | 24 +++++++++++++----------- src/ctpsfcube/ctpsfcube.par | 2 +- src/ctselect/ctselect.cpp | 18 ++++++++++-------- src/ctselect/ctselect.hpp | 4 ++-- src/ctselect/ctselect.par | 8 ++++---- src/ctskymap/ctskymap.cpp | 52 ++++++++++++++++++++++++++++------------------------ src/ctskymap/ctskymap.hpp | 4 ++-- src/cttsmap/cttsmap.cpp | 44 +++++++++++++++++++++++--------------------- src/cttsmap/cttsmap.hpp | 10 +++++----- src/cttsmap/cttsmap.par | 10 +++++----- src/support/ctool.cpp | 616 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/support/ctool.hpp | 39 +++++++++++++++++++-------------------- 31 files changed, 559 insertions(+), 500 deletions(-) diff --git a/src/ctbin/ctbin.cpp b/src/ctbin/ctbin.cpp index 8cbebfb..f676ec2 100644 --- a/src/ctbin/ctbin.cpp +++ b/src/ctbin/ctbin.cpp @@ -334,7 +334,7 @@ void ctbin::init_members(void) { // Initialise members m_outcube.clear(); - m_usepnt = false; + m_usepnt = false; // Initialise protected members m_obs.clear(); @@ -357,16 +357,16 @@ void ctbin::init_members(void) void ctbin::copy_members(const ctbin& app) { // Copy attributes - m_outcube = app.m_outcube; - m_usepnt = app.m_usepnt; + m_outcube = app.m_outcube; + m_usepnt = app.m_usepnt; // Copy protected members - m_obs = app.m_obs; - m_cube = app.m_cube; - m_ebounds = app.m_ebounds; - m_gti = app.m_gti; - m_ontime = app.m_ontime; - m_livetime = app.m_livetime; + m_obs = app.m_obs; + m_cube = app.m_cube; + m_ebounds = app.m_ebounds; + m_gti = app.m_gti; + m_ontime = app.m_ontime; + m_livetime = app.m_livetime; // Return return; @@ -400,8 +400,7 @@ void ctbin::get_parameters(void) // If there are no observations in container then load them via user parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events + // Throw exception if no infile is given if ((*this)["inobs"].filename() == "NONE" || (*this)["inobs"].filename() == "") { std::string msg = "A valid file needs to be specified for the " diff --git a/src/ctbkgcube/ctbkgcube.cpp b/src/ctbkgcube/ctbkgcube.cpp index 3c99886..f65c473 100644 --- a/src/ctbkgcube/ctbkgcube.cpp +++ b/src/ctbkgcube/ctbkgcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Chia-Chun Lu * + * copyright (C) 2014-2015 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -481,8 +481,8 @@ void ctbkgcube::init_members(void) void ctbkgcube::copy_members(const ctbkgcube& app) { // Copy members - m_outmodel = app.m_outmodel; - m_outcube = app.m_outcube; + m_outmodel = app.m_outmodel; + m_outcube = app.m_outcube; m_obs = app.m_obs; m_bkgcube = app.m_bkgcube; m_bkgmdl = app.m_bkgmdl; @@ -509,9 +509,8 @@ void ctbkgcube::free_members(void) /***********************************************************************//** * @brief Get application parameters * - * @exception GException::invalid_value - * Parameter "inobs" is required for ctbkgcube. * @exception GException::invalid_value + * Parameter "inobs" is required for ctbkgcube. * No background model definition XML file specified. * * Get all task parameters from parameter file or (if required) by querying @@ -524,10 +523,13 @@ void ctbkgcube::get_parameters(void) // Throw exception if no infile is given, since this tool needs an observation // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctbkgcube." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -592,7 +594,7 @@ void ctbkgcube::get_parameters(void) // Read output filenames (if needed) if (read_ahead()) { - m_outcube = (*this)["outcube"].filename(); + m_outcube = (*this)["outcube"].filename(); m_outmodel = (*this)["outmodel"].filename(); } diff --git a/src/ctbkgcube/ctbkgcube.hpp b/src/ctbkgcube/ctbkgcube.hpp index 22b6d5e..aa9d065 100644 --- a/src/ctbkgcube/ctbkgcube.hpp +++ b/src/ctbkgcube/ctbkgcube.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbkgcube - Background cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Chia-Chun Lu * + * copyright (C) 2014-2015 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -71,9 +71,8 @@ protected: void fill_cube(GCTAObservation* obs); // Protected members - std::string m_outcube; //!< Filename of output cube - std::string m_outmodel; //!< Filename of output xml model - + std::string m_outcube; //!< Filename of output cube + std::string m_outmodel; //!< Filename of output XML model GObservations m_obs; //!< Observation container GCTAEventCube m_bkgcube; //!< Background cube GModels m_bkgmdl; //!< CTA background models diff --git a/src/ctbkgcube/ctbkgcube.par b/src/ctbkgcube/ctbkgcube.par index 0089ba6..acfcee3 100644 --- a/src/ctbkgcube/ctbkgcube.par +++ b/src/ctbkgcube/ctbkgcube.par @@ -17,7 +17,7 @@ # # Observational parameters #=================== -inobs, f, a, "NONE",,, "Input event list, cube or observation definition file" +inobs, f, a, "NONE",,, "Input event list, cube or observation definition file" inmodel, f, a, "NONE",,, "Input (background) model XML file" incube, f, a, "NONE",,, "Counts cube for background cube definition" outcube, f, a, "bkgcube.fits",,, "Output background cube file" diff --git a/src/ctbutterfly/ctbutterfly.cpp b/src/ctbutterfly/ctbutterfly.cpp index d454189..501a544 100644 --- a/src/ctbutterfly/ctbutterfly.cpp +++ b/src/ctbutterfly/ctbutterfly.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbutterfly - butterfly calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Michael Mayer * + * copyright (C) 2014-2015 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -399,7 +399,6 @@ void ctbutterfly::save(void) void ctbutterfly::init_members(void) { // Initialise members - //m_inobs.clear(); m_srcname.clear(); m_outfile.clear(); m_ebounds.clear(); @@ -424,7 +423,6 @@ void ctbutterfly::init_members(void) void ctbutterfly::copy_members(const ctbutterfly& app) { // Copy attributes - // m_inobs = app.m_inobs; m_srcname = app.m_srcname; m_outfile = app.m_outfile; m_ebounds = app.m_ebounds; @@ -456,8 +454,6 @@ void ctbutterfly::free_members(void) * * @exception GException::invalid_value * Parameter "inobs" is required for ctbutterfly. - - * @exception GException::invalid_value * Test source not found or no RA/DEC parameters found for test * source. * @@ -472,12 +468,14 @@ void ctbutterfly::get_parameters(void) // If there are no observations in container then load them via user parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctbutterfly." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -515,8 +513,8 @@ void ctbutterfly::get_parameters(void) std::string matrixfilename = (*this)["matrix"].filename(); if (matrixfilename != "NONE") { std::string msg = "Loading of matrix from file not implemented yet. " - "Use filename = \"NONE\" to induce a recomputation of " - "the matrix internally."; + "Use filename = \"NONE\" to induce a recomputation of " + "the matrix internally."; throw GException::feature_not_implemented(G_GET_PARAMETERS, msg); // m_covariance.load(matrixfilename); } diff --git a/src/ctbutterfly/ctbutterfly.hpp b/src/ctbutterfly/ctbutterfly.hpp index 4c83796..263c6d2 100644 --- a/src/ctbutterfly/ctbutterfly.hpp +++ b/src/ctbutterfly/ctbutterfly.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctbutterfly - butterfly calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Michael Mayer * + * copyright (C) 2014-2015 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -84,7 +84,7 @@ protected: std::string m_outfile; //!< Output ascii file GEbounds m_ebounds; //!< Energy binning definition - // Protected members + // Protected members GObservations m_obs; //!< Observation container GMatrixSparse m_covariance; //!< Covariance matrix std::vector m_energies; //!< Energy values for storage diff --git a/src/ctbutterfly/ctbutterfly.par b/src/ctbutterfly/ctbutterfly.par index 0fea881..751a077 100644 --- a/src/ctbutterfly/ctbutterfly.par +++ b/src/ctbutterfly/ctbutterfly.par @@ -17,8 +17,8 @@ # # General parameters #=================== -inobs, f, a, "events.fits",,,"Input event list, cube or observation definition file" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" +inobs, f, a, "events.fits",,,"Input event list, cube or observation definition file" +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" srcname, s, a, "Crab",,,"Source of interest" caldb, s, a, "dummy",,, "Calibration database" irf, s, a, "cta_dummy_irf",,, "Instrument response function" diff --git a/src/ctcubemask/ctcubemask.cpp b/src/ctcubemask/ctcubemask.cpp index 35e6d65..3bf4732 100644 --- a/src/ctcubemask/ctcubemask.cpp +++ b/src/ctcubemask/ctcubemask.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctcubemask - Cube filter tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Chia-Chun Lu * + * copyright (C) 2014-2015 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -36,7 +36,7 @@ /* __ Method name definitions ____________________________________________ */ #define G_RUN "ctcubemask::run()" #define G_APPLY_MASK "ctcubemask::apply_mask(GCTAObservation*)" -#define G_GET_PARAMETERS "ctcubemask::get_parameters()" +#define G_GET_PARAMETERS "ctcubemask::get_parameters()" /* __ Debug definitions __________________________________________________ */ @@ -349,27 +349,29 @@ void ctcubemask::save(void) ***************************************************************************/ void ctcubemask::get_parameters(void) { - // If there are no observations in container then load them via user parameters - if (m_obs.size() == 0) { - - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctcubemask." - "Specify a vaild observation definition (XML or FITS) file to proceed" - "It is not possible to build a binned observation from scratch"; - throw GException::invalid_value(G_GET_PARAMETERS, msg); - } + // If there are no observations in container then load them via user + // parameters + if (m_obs.size() == 0) { + + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; + throw GException::invalid_value(G_GET_PARAMETERS, msg); + } - // Build observation container without response (not needed) - m_obs = get_observations(false); + // Build observation container without response (not needed) + m_obs = get_observations(false); - } // endif: there was no observation in the container + } // endif: there was no observation in the container // Get parameters m_regfile = (*this)["regfile"].filename(); - m_usepnt = (*this)["usepnt"].boolean(); + m_usepnt = (*this)["usepnt"].boolean(); if (!m_usepnt) { m_ra = (*this)["ra"].real(); m_dec = (*this)["dec"].real(); @@ -523,7 +525,6 @@ void ctcubemask::apply_mask(GCTAObservation* obs) void ctcubemask::init_members(void) { // Initialise parameters - //m_infile.clear(); m_regfile.clear(); m_outcube.clear(); m_prefix.clear(); @@ -537,7 +538,6 @@ void ctcubemask::init_members(void) // Initialise protected members m_obs.clear(); m_infiles.clear(); -// m_use_xml = false; // Return return; @@ -552,7 +552,6 @@ void ctcubemask::init_members(void) void ctcubemask::copy_members(const ctcubemask& app) { // Copy parameters - //m_infile = app.m_infile; m_regfile = app.m_regfile; m_outcube = app.m_outcube; m_prefix = app.m_prefix; @@ -566,7 +565,6 @@ void ctcubemask::copy_members(const ctcubemask& app) // Copy protected members m_obs = app.m_obs; m_infiles = app.m_infiles; -// m_use_xml = app.m_use_xml; // Return return; diff --git a/src/ctcubemask/ctcubemask.hpp b/src/ctcubemask/ctcubemask.hpp index 034fd57..f7a5756 100644 --- a/src/ctcubemask/ctcubemask.hpp +++ b/src/ctcubemask/ctcubemask.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctcubemask - Cube filter tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Chia-Chun Lu * + * copyright (C) 2014-2015 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -92,7 +92,6 @@ protected: // Protected members GObservations m_obs; //!< Observations container std::vector m_infiles; //!< Input event filenames - //bool m_use_xml; //!< Use XML file instead of FITS file }; diff --git a/src/ctcubemask/ctcubemask.par b/src/ctcubemask/ctcubemask.par index d68308e..d8021a3 100644 --- a/src/ctcubemask/ctcubemask.par +++ b/src/ctcubemask/ctcubemask.par @@ -17,7 +17,7 @@ # # File information #================= -inobs, f, a, "cntmap.fits",,,"Input counts cube or observation definition file" +inobs, f, a, "cntmap.fits",,,"Input counts cube or observation definition file" regfile, f, a, "NONE",,,"Exclusion region file in ds9 format" outcube, f, a, "filtered_cube.fits",,,"Output event cube or observation definition file" prefix, s, h, "filtered_",,,"Prefix for counts cube in observation definition file" diff --git a/src/ctexpcube/ctexpcube.cpp b/src/ctexpcube/ctexpcube.cpp index ea01fd3..521714a 100644 --- a/src/ctexpcube/ctexpcube.cpp +++ b/src/ctexpcube/ctexpcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctexpcube - Exposure cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Juergen Knoedlseder * + * copyright (C) 2014-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -312,7 +312,6 @@ void ctexpcube::init_members(void) // Initialise protected members m_obs.clear(); m_expcube.clear(); - //m_ebounds.clear(); // Return return; @@ -331,8 +330,8 @@ void ctexpcube::copy_members(const ctexpcube& app) m_apply_edisp = app.m_apply_edisp; // Copy protected members - m_obs = app.m_obs; - m_expcube = app.m_expcube; + m_obs = app.m_obs; + m_expcube = app.m_expcube; // Return return; @@ -361,15 +360,18 @@ void ctexpcube::free_members(void) ***************************************************************************/ void ctexpcube::get_parameters(void) { - // If there are no observations in container then load them via user parameters + // If there are no observations in container then load them via user + // parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctexpcube." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -411,7 +413,7 @@ void ctexpcube::get_parameters(void) // Define exposure cube m_expcube = GCTAExposure(cube); - } // endif: filename was not valid + } // endif: filename was not valid // ... otherwise setup the exposure cube from the counts map else { diff --git a/src/ctexpcube/ctexpcube.par b/src/ctexpcube/ctexpcube.par index 546ed6e..bf9da56 100644 --- a/src/ctexpcube/ctexpcube.par +++ b/src/ctexpcube/ctexpcube.par @@ -17,7 +17,7 @@ # # Observational parameters #=================== -inobs, f, a, "NONE",,, "Event list or observation definition file" +inobs, f, a, "NONE",,, "Event list or observation definition file" incube, f, a, "NONE",,, "Counts map for exposure cube definition" outcube, f, a, "expcube.fits",,, "Output exposure cube file" caldb, s, a, "dummy",,, "Calibration database" diff --git a/src/ctlike/ctlike.cpp b/src/ctlike/ctlike.cpp index 8ddef07..91617e9 100644 --- a/src/ctlike/ctlike.cpp +++ b/src/ctlike/ctlike.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctlike - Maximum likelihood fitting tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -363,11 +363,14 @@ void ctlike::get_parameters(void) // If there are no observations in container then load them via user parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - std::string msg = "Parameter \"inobs\" is required to be given in ctlike." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } diff --git a/src/ctlike/ctlike.hpp b/src/ctlike/ctlike.hpp index ad8b852..6e7ac22 100644 --- a/src/ctlike/ctlike.hpp +++ b/src/ctlike/ctlike.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctlike - Maximum likelihood fitting tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -74,7 +74,7 @@ protected: // User parameters bool m_refit; //!< Refitting - std::string m_outmodel; //!< Source model output XML file + std::string m_outmodel; //!< Source model output XML file bool m_apply_edisp; //!< Apply energy dispersion? // Members diff --git a/src/ctlike/ctlike.par b/src/ctlike/ctlike.par index 7ac742f..bb766d2 100644 --- a/src/ctlike/ctlike.par +++ b/src/ctlike/ctlike.par @@ -17,13 +17,13 @@ # # General parameters #=================== -inobs, f, a, "events.fits",,, "Event list, counts cube or observation definition file" -stat, s, h, "POISSON",,, "Optimization statistics" -edisp, b, h, no,,, "Apply energy dispersion?" -refit, b, h, no,,, "Do refitting?" -caldb, s, a, "dummy",,, "Calibration database" -irf, s, a, "cta_dummy_irf",,, "Instrument response function" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" +inobs, f, a, "events.fits",,, "Event list, counts cube or observation definition file" +stat, s, h, "POISSON",,, "Optimization statistics" +edisp, b, h, no,,, "Apply energy dispersion?" +refit, b, h, no,,, "Do refitting?" +caldb, s, a, "dummy",,, "Calibration database" +irf, s, a, "cta_dummy_irf",,, "Instrument response function" +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" outmodel, f, a, "crab_results.xml",,, "Source model output file" # # Standard parameters diff --git a/src/ctmodel/ctmodel.par b/src/ctmodel/ctmodel.par index 8e2f072..4593962 100644 --- a/src/ctmodel/ctmodel.par +++ b/src/ctmodel/ctmodel.par @@ -19,12 +19,12 @@ #=================== incube, f, a, "NONE",,, "Input counts map or observation definition file" outcube, f, a, "modmap.fits",,, "Output counts map or observation definition file" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" edisp, b, h, no,,, "Apply energy dispersion?" # # Observation parameters #======================= -inobs, f, a, "NONE",,, "Input event list, cube or observation definition file" +inobs, f, a, "NONE",,, "Input event list, cube or observation definition file" caldb, s, a, "$CTOOLS/share/caldb/data/cta/dummy",,, "Calibration database" irf, s, a, "cta_dummy_irf",,, "Instrument response function" ra, r, a, 83.63,0,360, "RA of pointing (degrees)" diff --git a/src/ctobssim/ctobssim.cpp b/src/ctobssim/ctobssim.cpp index e07e21b..ff22ffb 100644 --- a/src/ctobssim/ctobssim.cpp +++ b/src/ctobssim/ctobssim.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctobssim - Observation simulator tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -427,6 +427,7 @@ void ctobssim::run(void) return; } + /***********************************************************************//** * @brief Save the selected event list(s) * @@ -491,7 +492,7 @@ void ctobssim::init_members(void) // Initialise user parameters m_outevents.clear(); m_prefix.clear(); - m_seed = 1; + m_seed = 1; m_apply_edisp = false; // Initialise protected members @@ -519,7 +520,7 @@ void ctobssim::init_members(void) void ctobssim::copy_members(const ctobssim& app) { // Copy user parameters - m_outevents = app.m_outevents; + m_outevents = app.m_outevents; m_prefix = app.m_prefix; m_seed = app.m_seed; m_apply_edisp = app.m_apply_edisp; @@ -559,21 +560,18 @@ void ctobssim::free_members(void) void ctobssim::get_parameters(void) { // If there are no observations in container then load them via user parameters - if (m_obs.size() == 0) { + if (m_obs.size() == 0) { // Build observation container m_obs = get_observations(); - } // endif: there was no observation in the container + } // endif: there was no observation in the container - // Read model definition file if required - if (m_obs.models().size() == 0) { + // Read model definition file if required + if (m_obs.models().size() == 0) { std::string inmodel = (*this)["inmodel"].filename(); - - // Load models from file m_obs.models(inmodel); - - } // endif: there were no models + } // Get other parameters m_seed = (*this)["seed"].integer(); diff --git a/src/ctobssim/ctobssim.hpp b/src/ctobssim/ctobssim.hpp index 695f922..e58276e 100644 --- a/src/ctobssim/ctobssim.hpp +++ b/src/ctobssim/ctobssim.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctobssim - Observation simulator tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -85,7 +85,7 @@ protected: void save_xml(void); // User parameters - std::string m_outevents; //!< Output events file + std::string m_outevents; //!< Output events file std::string m_prefix; //!< Prefix for multiple event lists int m_seed; //!< Random number generator seed bool m_apply_edisp; //!< Apply energy dispersion? diff --git a/src/ctobssim/ctobssim.par b/src/ctobssim/ctobssim.par index 201e142..073e6a1 100644 --- a/src/ctobssim/ctobssim.par +++ b/src/ctobssim/ctobssim.par @@ -17,10 +17,10 @@ # # File information #================= -inobs, f, h, "NONE",,,"Input event list or observation definition file" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Model" -outevents,f, a, "events.fits",,, "Output event data file or observation definition file" -prefix, s, h, "sim_events_",,, "Prefix for event lists in observation definition file" +inobs, f, h, "NONE",,,"Input event list or observation definition file" +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Model" +outevents, f, a, "events.fits",,,"Output event data file or observation definition file" +prefix, s, h, "sim_events_",,,"Prefix for event lists in observation definition file" # # Observation parameters #======================= diff --git a/src/ctpsfcube/ctpsfcube.cpp b/src/ctpsfcube/ctpsfcube.cpp index c690460..3f31154 100644 --- a/src/ctpsfcube/ctpsfcube.cpp +++ b/src/ctpsfcube/ctpsfcube.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctpsfcube - PSF cube generation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Chia-Chun Lu * + * copyright (C) 2014-2015 by Chia-Chun Lu * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -35,7 +35,6 @@ /* __ Method name definitions ____________________________________________ */ #define G_GET_PARAMETERS "ctpsfcube::get_parameters()" -#define G_SET_FROM_CNTMAP "ctpsfcube::set_from_cntmap(std::string&)" /* __ Debug definitions __________________________________________________ */ @@ -355,12 +354,14 @@ void ctpsfcube::get_parameters(void) // If there are no observations in container then load them via user parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctpsfcube." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -373,8 +374,8 @@ void ctpsfcube::get_parameters(void) std::string incube = (*this)["incube"].filename(); // Get additional binning parameters - double dmax = (*this)["amax"].real(); - int ndbins = (*this)["anumbins"].integer(); + double dmax = (*this)["amax"].real(); + int ndbins = (*this)["anumbins"].integer(); // Check for filename validity if ((incube == "NONE") || (gammalib::strip_whitespace(incube) == "")) { @@ -388,7 +389,7 @@ void ctpsfcube::get_parameters(void) // Check if pointing should be used if (usepnt) { - // buld cube from user parameters and pointing information + // Build cube from user parameters and pointing information cube = get_cube(m_obs); } // endif: pointing used as map center @@ -402,6 +403,7 @@ void ctpsfcube::get_parameters(void) // Define psf cube m_psfcube = GCTAMeanPsf(cube, dmax, ndbins); + } // ... otherwise setup the exposure cube from the counts map diff --git a/src/ctpsfcube/ctpsfcube.par b/src/ctpsfcube/ctpsfcube.par index 0583757..0914fd5 100644 --- a/src/ctpsfcube/ctpsfcube.par +++ b/src/ctpsfcube/ctpsfcube.par @@ -17,7 +17,7 @@ # # Observational parameters #=================== -inobs, f, a, "NONE",,, "Event list or observation definition file" +inobs, f, a, "NONE",,, "Event list or observation definition file" incube, f, a, "NONE",,, "Counts map for exposure cube definition" outcube, f, a, "psfcube.fits",,, "Output exposure cube file" caldb, s, a, "dummy",,, "Calibration database" diff --git a/src/ctselect/ctselect.cpp b/src/ctselect/ctselect.cpp index b66cb32..dd4d016 100644 --- a/src/ctselect/ctselect.cpp +++ b/src/ctselect/ctselect.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctselect - Data selection tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -471,12 +471,14 @@ void ctselect::get_parameters(void) // If there are no observations in container then load them via user parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctselect." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -511,7 +513,7 @@ void ctselect::get_parameters(void) // dumped into the log file if (read_ahead()) { m_outobs = (*this)["outobs"].filename(); - m_prefix = (*this)["prefix"].string(); + m_prefix = (*this)["prefix"].string(); } // Set time interval with input times given in CTA reference diff --git a/src/ctselect/ctselect.hpp b/src/ctselect/ctselect.hpp index 9a27231..5932eab 100644 --- a/src/ctselect/ctselect.hpp +++ b/src/ctselect/ctselect.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctselect - Data selection tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -82,7 +82,7 @@ protected: const std::string& outfile) const; // User parameters - std::string m_outobs; //!< Output event list or XML file + std::string m_outobs; //!< Output event list or XML file std::string m_prefix; //!< Prefix for multiple event lists bool m_usepnt; //!< Use pointing instead of RA/DEC parameters double m_ra; //!< RA of ROI centre diff --git a/src/ctselect/ctselect.par b/src/ctselect/ctselect.par index e1642eb..adb8e22 100644 --- a/src/ctselect/ctselect.par +++ b/src/ctselect/ctselect.par @@ -17,11 +17,11 @@ # # File information #================= -inobs, f, a, "events.fits",,,"Input event list or observation definition file" -outobs,f, a, "selected_events.fits",,,"Output event list or observation definition file" +inobs, f, a, "events.fits",,,"Input event list or observation definition file" +outobs, f, a, "selected_events.fits",,,"Output event list or observation definition file" prefix, s, h, "selected_",,,"Prefix for event lists in observation definition file" -caldb, s, h, "dummy",,, "Calibration database" -irf, s, h, "cta_dummy_irf",,, "Instrument response function" +caldb, s, h, "dummy",,, "Calibration database" +irf, s, h, "cta_dummy_irf",,, "Instrument response function" # # Selection parameters #===================== diff --git a/src/ctskymap/ctskymap.cpp b/src/ctskymap/ctskymap.cpp index 5fac288..a07bda9 100644 --- a/src/ctskymap/ctskymap.cpp +++ b/src/ctskymap/ctskymap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctskymap - Sky mapping tool * * ----------------------------------------------------------------------- * - * copyright (C) 2011-2014 by Juergen Knoedlseder * + * copyright (C) 2011-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -35,7 +35,8 @@ /* __ Method name definitions ____________________________________________ */ #define G_INIT_MAP "ctskymap::init_map(GCTAObservation* obs)" #define G_BIN_EVENTS "ctskymap::bin_events(GCTAObservation*)" -#define G_GET_PARAMETERS "ctskymap::get_parameters()" +#define G_GET_PARAMETERS "ctskymap::get_parameters()" + /* __ Debug definitions __________________________________________________ */ /* __ Coding definitions _________________________________________________ */ @@ -329,22 +330,25 @@ void ctskymap::save(void) ***************************************************************************/ void ctskymap::get_parameters(void) { - // If there are no observations in container then load them via user parameters - if (m_obs.size() == 0) { - - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in ctskymap." - "Specify a vaild observation definition (XML or FITS) file to proceed"; - throw GException::invalid_value(G_GET_PARAMETERS, msg); - } + // If there are no observations in container then load them via user + // parameters + if (m_obs.size() == 0) { + + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; + throw GException::invalid_value(G_GET_PARAMETERS, msg); + } - // Build observation container without response (not needed) - m_obs = get_observations(false); + // Build observation container without response (not needed) + m_obs = get_observations(false); - } // endif: there was no observation in the container + } // endif: there was no observation in the container // Get parameters bool usepnt = (*this)["usepnt"].boolean(); @@ -365,8 +369,8 @@ void ctskymap::get_parameters(void) } // endelse: m_usepnt was false // Get remaining parameters - m_emin = (*this)["emin"].real(); - m_emax = (*this)["emax"].real(); + m_emin = (*this)["emin"].real(); + m_emax = (*this)["emax"].real(); // Read ahead parameters if (read_ahead()) { @@ -485,8 +489,8 @@ void ctskymap::init_members(void) // Initialise members m_obs.clear(); m_skymap.clear(); - m_emin = 0.0; - m_emax = 0.0; + m_emin = 0.0; + m_emax = 0.0; // Return return; @@ -501,10 +505,10 @@ void ctskymap::init_members(void) void ctskymap::copy_members(const ctskymap& app) { // Copy attributes - m_obs = app.m_obs; - m_skymap = app.m_skymap; - m_emin = app.m_emin; - m_emax = app.m_emax; + m_obs = app.m_obs; + m_skymap = app.m_skymap; + m_emin = app.m_emin; + m_emax = app.m_emax; // Return return; diff --git a/src/ctskymap/ctskymap.hpp b/src/ctskymap/ctskymap.hpp index b5ebb97..b52fcff 100644 --- a/src/ctskymap/ctskymap.hpp +++ b/src/ctskymap/ctskymap.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctskymap - Sky mapping tool * * ----------------------------------------------------------------------- * - * copyright (C) 2010-2014 by Juergen Knoedlseder * + * copyright (C) 2010-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -72,7 +72,7 @@ protected: void map_events(GCTAObservation* obs); // User parameters - std::string m_outmap; //!< Output counts map + std::string m_outmap; //!< Output counts map double m_emin; //!< Minimum energy (TeV) double m_emax; //!< Maximum energy (TeV) diff --git a/src/cttsmap/cttsmap.cpp b/src/cttsmap/cttsmap.cpp index a0416b8..8b55e24 100644 --- a/src/cttsmap/cttsmap.cpp +++ b/src/cttsmap/cttsmap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * cttsmap - TS map calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Michael Mayer * + * copyright (C) 2014-2015 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -436,18 +436,18 @@ void cttsmap::init_members(void) void cttsmap::copy_members(const cttsmap& app) { // Copy attributes - m_srcname = app.m_srcname; + m_srcname = app.m_srcname; m_outmap = app.m_outmap; // Copy protected members - m_binmin = app.m_binmin; - m_binmax = app.m_binmax; - m_logL0 = app.m_logL0; - m_obs = app.m_obs; - m_tsmap = app.m_tsmap; - m_mapnames = app.m_mapnames; - m_maps = app.m_maps; - m_statusmap = app.m_statusmap; + m_binmin = app.m_binmin; + m_binmax = app.m_binmax; + m_logL0 = app.m_logL0; + m_obs = app.m_obs; + m_tsmap = app.m_tsmap; + m_mapnames = app.m_mapnames; + m_maps = app.m_maps; + m_statusmap = app.m_statusmap; // Clone protected members m_testsource = (app.m_testsource != NULL) ? app.m_testsource->clone() : NULL; @@ -485,15 +485,18 @@ void cttsmap::free_members(void) ***************************************************************************/ void cttsmap::get_parameters(void) { - // If there are no observations in container then load them via user parameters + // If there are no observations in container then load them via user + // parameters if (m_obs.size() == 0) { - // Throw exception if no infile is given, since this tool needs an observation - // including events - if ((*this)["inobs"].filename()=="NONE" || (*this)["inobs"].filename() == "") { - - std::string msg = "Parameter \"inobs\" is required to be given in cttsmap." - "Specify a vaild observation definition (XML or FITS) file to proceed"; + // Throw exception if no infile is given + if ((*this)["inobs"].filename() == "NONE" || + (*this)["inobs"].filename() == "") { + std::string msg = "A valid file needs to be specified for the " + "\"inobs\" parameter, yet \""+ + (*this)["inobs"].filename()+"\" was given." + " Specify a vaild observation definition or " + "event list FITS file to proceed."; throw GException::invalid_value(G_GET_PARAMETERS, msg); } @@ -544,14 +547,13 @@ void cttsmap::get_parameters(void) (*m_testsource)["DEC"].fix(); } - - // Get sky map binning from user parameters - // and check if pointing should be used + // Get sky map binning from user parameters and check if pointing + // should be used GSkymap map; bool usepnt = (*this)["usepnt"].boolean(); if (usepnt) { - // build cube from user parameters and pointing information + // Build cube from user parameters and pointing information map = get_map(m_obs); } // endif: pointing used as map center diff --git a/src/cttsmap/cttsmap.hpp b/src/cttsmap/cttsmap.hpp index f17bfdc..369c565 100644 --- a/src/cttsmap/cttsmap.hpp +++ b/src/cttsmap/cttsmap.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * cttsmap - TS map calculation tool * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Michael Mayer * + * copyright (C) 2014-2015 by Michael Mayer * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -85,12 +85,12 @@ protected: // User parameters std::string m_srcname; //!< Name of source which is moved around - std::string m_outmap; //!< Output counts map or XML file + std::string m_outmap; //!< Output counts map or XML file // Parameters to control speed and job splitting - int m_binmin; //!< Map bin number from which computation should start - int m_binmax; //!< Map bin number where map computation should end - double m_logL0; //!< Likelihood value of null hypothesis + int m_binmin; //!< Map bin number from which computation should start + int m_binmax; //!< Map bin number where map computation should end + double m_logL0; //!< Likelihood value of null hypothesis // Protected members GObservations m_obs; //!< Observation container diff --git a/src/cttsmap/cttsmap.par b/src/cttsmap/cttsmap.par index d0db7b7..eb29ce5 100644 --- a/src/cttsmap/cttsmap.par +++ b/src/cttsmap/cttsmap.par @@ -17,11 +17,11 @@ # # General parameters #=================== -inobs, f, a, "events.fits",,,"Input event list, cube or observation definition file" -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" -srcname, s, a, "TestSource",,,"Test source" -caldb, s, a, "dummy",,, "Calibration database" -irf, s, a, "cta_dummy_irf",,, "Instrument response function" +inobs, f, a, "events.fits",,, "Input event list, cube or observation definition file" +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Source model" +srcname, s, a, "TestSource",,, "Test source" +caldb, s, a, "dummy",,, "Calibration database" +irf, s, a, "cta_dummy_irf",,, "Instrument response function" outmap, f, a, "tsmap.fits",,, "Output counts cube" # diff --git a/src/support/ctool.cpp b/src/support/ctool.cpp index 3c83843..5c20de9 100644 --- a/src/support/ctool.cpp +++ b/src/support/ctool.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Juergen Knoedlseder * + * copyright (C) 2014-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -48,8 +48,9 @@ /* __ Method name definitions ____________________________________________ */ #define G_GET_EBOUNDS "ctool::get_ebounds()" -#define G_SET_FROM_CNTMAP "ctool::set_from_cntmap(std::string&)" -#define G_GET_CUBE "ctool::get_cube(GObservations&)" +#define G_SET_FROM_CNTMAP "ctool::set_from_cntmap(std::string&)" +#define G_GET_MEAN_POINTING "ctool::get_mean_pointing(GObservations&)" +#define G_GET_CUBE "ctool::get_cube(GObservations&)" /* __ Debug definitions __________________________________________________ */ @@ -228,7 +229,7 @@ void ctool::init_members(void) { // Initialise members m_read_ahead = false; - m_use_xml = false; + m_use_xml = false; // Set CTA time reference. G_CTA_MJDREF is the CTA reference MJD, // which is defined in GCTALib.hpp. This is somehow a kluge. We need @@ -252,8 +253,8 @@ void ctool::copy_members(const ctool& app) { // Copy members m_read_ahead = app.m_read_ahead; - m_use_xml = app.m_use_xml; - m_cta_ref = app.m_cta_ref; + m_use_xml = app.m_use_xml; + m_cta_ref = app.m_cta_ref; // Return return; @@ -276,6 +277,172 @@ void ctool::free_members(void) /***********************************************************************//** + * @brief Build a CTA observation with an empty event list + * + * Creates an empty CTA observation from user parameters. An empty event list + * including RoI, GTI and energy boundary information is attached to the + * observation. The method also sets the pointing direction using the ra and + * dec parameter, the ROI based on ra, dec and rad, a single GTI based on + * tmin and tmax, and a single energy boundary based on emin and emax. The + * method furthermore sets the ontime, livetime and deadtime correction + * factor. + * + * The following parameters are read: + * ra - Right Ascension of pointing and RoI centre (deg) + * dec - Declination of pointing and RoI centre (deg) + * rad - Radius of RoI (deg) + * deadc - Deadtime correction factor + * tmin - Start time + * tmax - Stop time + * emin - Minimum energy (TeV) + * emax - Maximum energy (TeV) + ***************************************************************************/ +GCTAObservation ctool::setup_obs(void) +{ + // Get CTA observation parameters + double ra = (*this)["ra"].real(); + double dec = (*this)["dec"].real(); + double rad = (*this)["rad"].real(); + double deadc = (*this)["deadc"].real(); + double t_min = (*this)["tmin"].real(); + double t_max = (*this)["tmax"].real(); + double e_min = (*this)["emin"].real(); + double e_max = (*this)["emax"].real(); + + // Allocate CTA observation and empty event list + GCTAObservation obs; + GCTAEventList list; + + // Set pointing direction + GCTAPointing pnt; + GSkyDir skydir; + skydir.radec_deg(ra, dec); + pnt.dir(skydir); + + // Set ROI + GCTAInstDir instdir(skydir); + GCTARoi roi(instdir, rad); + + // Set GTI + GGti gti(m_cta_ref); + GTime tstart; + GTime tstop; + tstart.set(t_min, m_cta_ref); + tstop.set(t_max, m_cta_ref); + gti.append(tstart, tstop); + + // Set energy boundaries + GEbounds ebounds; + GEnergy emin; + GEnergy emax; + emin.TeV(e_min); + emax.TeV(e_max); + ebounds.append(emin, emax); + + // Set CTA event list attributes + list.roi(roi); + list.gti(gti); + list.ebounds(ebounds); + + // Attach event list to CTA observation + obs.events(list); + + // Set observation ontime, livetime and deadtime correction factor + obs.pointing(pnt); + obs.ontime(gti.ontime()); + obs.livetime(gti.ontime()*deadc); + obs.deadc(deadc); + + // Return CTA observation + return obs; + +} + + +/***********************************************************************//** + * @brief Build a skymap based on user parameters + * + * Creates an empty skymap from input user parameters. + * + * The following parameters are read: + * proj - Coordinate projection + * coordsys - Coordinate system + * binsz - Bin size (deg) + * nxpix - Number of pixels in Right Ascension or longitude + * nypix - Number of pixels in Declination or latitude + ***************************************************************************/ +GSkymap ctool::get_map() +{ + // Read task parameters + double xref = (*this)["xref"].real(); + double yref = (*this)["yref"].real(); + std::string proj = (*this)["proj"].string(); + std::string coordsys = (*this)["coordsys"].string(); + double binsz = (*this)["binsz"].real(); + int nxpix = (*this)["nxpix"].integer(); + int nypix = (*this)["nypix"].integer(); + + // Initialise sky map + GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, + nxpix, nypix, 1); + + // Return sky map + return map; +} + + +/***********************************************************************//** + * @brief Build a skymap based on user parameters + * + * @param[in] obs Observation container. + * + * Creates an empty skymap from input user parameters. The reference + * coordinate is extracted from the mean pointing of the CTA observations + * in the observation container (see get_mean_pointing()). + * + * The following parameters are read: + * proj - Coordinate projection + * coordsys - Coordinate system + * binsz - Bin size (deg) + * nxpix - Number of pixels in Right Ascension or longitude + * nypix - Number of pixels in Declination or latitude + ***************************************************************************/ +GSkymap ctool::get_map(const GObservations& obs) +{ + // Read task parameters + std::string proj = (*this)["proj"].string(); + std::string coordsys = (*this)["coordsys"].string(); + double binsz = (*this)["binsz"].real(); + int nxpix = (*this)["nxpix"].integer(); + int nypix = (*this)["nypix"].integer(); + + // Initialise reference coordinates + double xref = 0.0; + double yref = 0.0; + + // Get pointing from observations + GSkyDir pnt = get_mean_pointing(obs); + + // Use correct coordinate system + if (gammalib::toupper(coordsys) == "GAL") { + xref = pnt.l_deg(); + yref = pnt.b_deg(); + } + else { + xref = pnt.ra_deg(); + yref = pnt.dec_deg(); + } + + // Initialise sky map + GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, + nxpix, nypix, 1); + + // Return sky map + return map; +} + + +/***********************************************************************//** * @brief Get the energy boundaries * * @exception GException::invalid_value @@ -285,6 +452,12 @@ void ctool::free_members(void) * supports loading of energy boundary information from the EBOUNDS or * ENERGYBINS extension, or setting energy boundaries using a linear * or logarithmical spacing. + * + * The following parameters are read: + * ebinalg - Energy binning algorithm + * emin - Minimum energy (if ebinalg != FILE) + * emax - Maximum energy (if ebinalg != FILE) + * enumbins - Number of energy bins (if ebinalg != FILE) ***************************************************************************/ GEbounds ctool::get_ebounds(void) { @@ -352,52 +525,16 @@ GEbounds ctool::get_ebounds(void) } - - -/***********************************************************************//** - * @brief Get a GCTAEventCube from file - * - * @param[in] filename FITS file of count cube. - * @exception GException::invalid_value - * Counts map not of WCS type - * - * Gets an cta event cube from file. This function is used in many ctools - * to obtain a skymap definition from file - * - ***************************************************************************/ -GCTAEventCube ctool::set_from_cntmap(const std::string filename) -{ - // Allocate CTA observation - GCTAEventCube cube; - - // Load counts map in CTA observation - cube.load(filename); - - // Check for valid WCS coordinate system - const GWcs* wcs = dynamic_cast(cube.map().projection()); - if (wcs == NULL) { - - std::string msg = "Counts map project is not of WCS type."; - throw GException::invalid_value(G_SET_FROM_CNTMAP, msg); - - } // endif: WCS projection was not valid - - // Return cube - return cube; -} - - - /***********************************************************************//** * @brief Get observation container * - * @param[in] get_response flag whether response information should be loaded + * @param[in] get_response Indicates whether response information should + * be loaded (default: true) * * Get an observation container according to the user parameters. The method - * supports loading of a individual FITS file, an observation definition file in XML - * format. If the input filename is empty, parameters are read to build a CTA observation - * from scratch. - * + * supports loading of a individual FITS file or an observation definition + * file in XML format. If the input filename is empty, parameters are read + * to build a CTA observation from scratch. ***************************************************************************/ GObservations ctool::get_observations(const bool& get_response) { @@ -428,6 +565,7 @@ GObservations ctool::get_observations(const bool& get_response) } // endif: filename was "NONE" or "" + // ... otherwise we have a file name else { // Try first to open as FITS file @@ -454,6 +592,7 @@ GObservations ctool::get_observations(const bool& get_response) m_use_xml = false; } + // ... otherwise try to open as XML file catch (GException::fits_open_error &e) { @@ -472,7 +611,8 @@ GObservations ctool::get_observations(const bool& get_response) // Signal that XML file should be used for storage m_use_xml = true; - } // endcatch: file was an XML file + } // endcatch: file was an XML file + } // Return observation container @@ -480,118 +620,58 @@ GObservations ctool::get_observations(const bool& get_response) } + /***********************************************************************//** - * @brief Build a CTA observation with an empty event list + * @brief Derives mean pointing from CTA observations * - * Creates an empty CTA observation from user parameters. An empty event list - * including RoI, GTi and energy boundary information is attached to the observation. - * The method also sets the pointing direction using the ra and dec parameter, the ROI based on - * ra, dec and rad, a single GTI based on tmin and tmax, and a - * single energy boundary based on emin and emax. The method furthermore - * sets the ontime, livetime and deadtime correction factor. + * @param[in] obs Observation container. + * @return Pointing direction. + * + * Computes the mean pointing direction from all CTA observations in the + * observation container. * + * @todo This method does not work properly for wrap arounds in Right + * Ascension. It certainly will also lead to bad results near the + * celestial pole. ***************************************************************************/ -GCTAObservation ctool::setup_obs(void) -{ - //Get CTA observation parameters - double ra = (*this)["ra"].real(); - double dec = (*this)["dec"].real(); - double rad = (*this)["rad"].real(); - double deadc = (*this)["deadc"].real(); - double t_min = (*this)["tmin"].real(); - double t_max = (*this)["tmax"].real(); - double e_min = (*this)["emin"].real(); - double e_max = (*this)["emax"].real(); - - // Allocate CTA observation and empty event list - GCTAObservation obs; - GCTAEventList list; - - // Set pointing direction - GCTAPointing pnt; - GSkyDir skydir; - skydir.radec_deg(ra, dec); - pnt.dir(skydir); - - // Set ROI - GCTAInstDir instdir(skydir); - GCTARoi roi(instdir, rad); - - // Set GTI - GGti gti(m_cta_ref); - GTime tstart; - GTime tstop; - tstart.set(t_min, m_cta_ref); - tstop.set(t_max, m_cta_ref); - gti.append(tstart, tstop); - - // Set energy boundaries - GEbounds ebounds; - GEnergy emin; - GEnergy emax; - emin.TeV(e_min); - emax.TeV(e_max); - ebounds.append(emin, emax); - - // Set CTA event list attributes - list.roi(roi); - list.gti(gti); - list.ebounds(ebounds); - - // Attach event list to CTA observation - obs.events(list); - - // Set observation ontime, livetime and deadtime correction factor - obs.pointing(pnt); - obs.ontime(gti.ontime()); - obs.livetime(gti.ontime()*deadc); - obs.deadc(deadc); - - // Return CTA observation - return obs; - -} - -GSkyDir ctool::get_pointing(const GObservations& obs) +GSkyDir ctool::get_mean_pointing(const GObservations& obs) { // Initialise values - double xref = 0.0; - double yref = 0.0; - int n_pnt = 0; - bool found = false; + double xref = 0.0; + double yref = 0.0; + int n_pnt = 0; // Loop over all observations to compute mean pointings for (int i = 0; i < obs.size(); ++i) { - const GCTAObservation* cta_obs = dynamic_cast(obs[i]); - if (cta_obs != NULL) { - // get pointing + // If we have a CTA observation then extract the pointing direction + const GCTAObservation* cta_obs = dynamic_cast(obs[i]); + if (cta_obs != NULL) { + + // Get pointing const GCTAPointing& pnt = cta_obs->pointing(); // Add to coordinates - xref += pnt.dir().ra_deg(); - yref += pnt.dir().dec_deg(); + xref += pnt.dir().ra_deg(); + yref += pnt.dir().dec_deg(); n_pnt += 1; - // Signal that pointing has been found - found = true; - } // endif: cta observation was valid - } // endfor: loop over alle observations + } // endfor: loop over all observations // Signal if no pointing is found - if (!found) { + if (n_pnt < 1) { std::string msg = "No valid CTA observation has been found in " "observation list, hence no pointing information " "could be extracted. Use the \"usepnt=no\" " - "option and specify pointing explicitly"; - throw GException::invalid_value(G_GET_CUBE, msg); + "option and specify the pointing explicitly."; + throw GException::invalid_value(G_GET_MEAN_POINTING, msg); } // Calculate mean coordinates - double ra = xref / double (n_pnt); - double dec = yref / double (n_pnt); + double ra = xref / double(n_pnt); + double dec = yref / double(n_pnt); // Initialise sky dir GSkyDir dir = GSkyDir(); @@ -601,23 +681,30 @@ GSkyDir ctool::get_pointing(const GObservations& obs) return dir; } + /***********************************************************************//** - * @brief Build a GCTAEventCube based on user parameters + * @brief Build CTA event cube based on user parameters * - * Creates an empty CTA event cube from input user parameters. It appends a dummy - * GTi to the event cube. + * Creates an empty CTA event cube from input user parameters. It appends a + * dummy GTI to the event cube. * + * The following parameters are read: + * xref - Reference in Right Ascension or longitude (deg) + * yref - Reference in Declination or latitude (deg) + * proj - Coordinate projection + * coordsys - Coordinate system + * binsz - Bin size (deg) + * nxpix - Number of pixels in Right Ascension or longitude + * nypix - Number of pixels in Declination or latitude + * ebinalg - Energy binning algorithm + * emin - Minimum energy (if ebinalg != FILE) + * emax - Maximum energy (if ebinalg != FILE) + * enumbins - Number of energy bins (if ebinalg != FILE) ***************************************************************************/ GCTAEventCube ctool::get_cube(void) { - // Get cube parameters - double xref = (*this)["xref"].real(); - double yref = (*this)["yref"].real(); - std::string proj = (*this)["proj"].string(); - std::string coordsys = (*this)["coordsys"].string(); - double binsz = (*this)["binsz"].real(); - int nxpix = (*this)["nxpix"].integer(); - int nypix = (*this)["nypix"].integer(); + // Get skymap + GSkymap map = get_map(); // Set energy boundaries GEbounds ebounds = get_ebounds(); @@ -626,145 +713,153 @@ GCTAEventCube ctool::get_cube(void) GGti gti; gti.append(GTime(0.0), GTime(0.1234)); - // Initialise sky map - GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, nxpix, nypix, ebounds.size()); + // Extend skymap to the requested number of maps + map.nmaps(ebounds.size()); // Build event cube from given information - GCTAEventCube cube = GCTAEventCube(map,ebounds,gti); + GCTAEventCube cube = GCTAEventCube(map, ebounds, gti); // Return cube return cube; - } + /***********************************************************************//** - * @brief Build a GCTAEventCube based on user parameters + * @brief Build CTA event cube based on user parameters * - * @param[in] obs observation container + * @param[in] obs Observation container. * - * Creates an empty CTA event cube from input user parameters. It appends a dummy - * GTi to the event cube. The input parameter is used to extract the pointing information - * from the given observations. This function is used if a ctool has the input parameter - * usepnt=true. + * Creates an empty CTA event cube from input user parameters. The reference + * coordinate is extracted from the mean pointing of the CTA observations + * in the observation container (see get_mean_pointing()). This method will + * be used if a ctool has the input parameter usepnt=true. The method + * appends a dummy GTI to the event cube. * + * The following parameters are read: + * proj - Coordinate projection + * coordsys - Coordinate system + * binsz - Bin size (deg) + * nxpix - Number of pixels in Right Ascension or longitude + * nypix - Number of pixels in Declination or latitude + * ebinalg - Energy binning algorithm + * emin - Minimum energy (if ebinalg != FILE) + * emax - Maximum energy (if ebinalg != FILE) + * enumbins - Number of energy bins (if ebinalg != FILE) ***************************************************************************/ GCTAEventCube ctool::get_cube(const GObservations& obs) { - // Read ahead map information - std::string proj = (*this)["proj"].string(); - std::string coordsys = (*this)["coordsys"].string(); - - // Initialise reference coordinates - double xref = 0.0; - double yref = 0.0; - - // Get pointing from observations - GSkyDir pnt = get_pointing(obs); - - // Use correct coordinate system - if (gammalib::toupper(coordsys) == "GAL") { - xref = pnt.l_deg(); - yref = pnt.b_deg(); - } - else { - xref = pnt.ra_deg(); - yref = pnt.dec_deg(); - } - - // Read further binning parameters - double binsz = (*this)["binsz"].real(); - int nxpix = (*this)["nxpix"].integer(); - int nypix = (*this)["nypix"].integer(); + // Get skymap + GSkymap map = get_map(obs); // Set energy boundaries - GEbounds ebounds = get_ebounds(); + GEbounds ebounds = get_ebounds(); // Set dummy GTI that is needed for event cube creation GGti gti; gti.append(GTime(0.0), GTime(0.1234)); - // Build skymap from user parameters - GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, nxpix, nypix, ebounds.size()); + // Extend skymap to the requested number of maps + map.nmaps(ebounds.size()); // Initialise event cube from all parameters - GCTAEventCube cube = GCTAEventCube(map,ebounds,gti); + GCTAEventCube cube = GCTAEventCube(map, ebounds, gti); // Return event cube return cube; - } + /***********************************************************************//** - * @brief Build a skymap based on user parameters - * - * Creates an empty skymap from input user parameters. + * @brief Get current resident set size (physical memory use) in Bytes * + * @return Physical memory use in Bytes. ***************************************************************************/ -GSkymap ctool::get_map() +size_t ctool::get_current_rss(void) { - // Read map information - double xref = (*this)["xref"].real(); - double yref = (*this)["yref"].real(); - std::string proj = (*this)["proj"].string(); - std::string coordsys = (*this)["coordsys"].string(); - double binsz = (*this)["binsz"].real(); - int nxpix = (*this)["nxpix"].integer(); - int nypix = (*this)["nypix"].integer(); + // Initialize resident set size + size_t rss = 0; - // Initialise sky map - GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, nxpix, nypix, 1); + // Determine resident set size (architecture dependent) + // OSX + #if defined(__APPLE__) && defined(__MACH__) + #ifdef MACH_TASK_BASIC_INFO + struct mach_task_basic_info info; + mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; + if (task_info(mach_task_self( ), MACH_TASK_BASIC_INFO, + (task_info_t)&info, &infoCount) == KERN_SUCCESS) { + rss = (size_t)info.resident_size; + } + #else + struct task_basic_info info; + mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT; + if (task_info(mach_task_self(), TASK_BASIC_INFO, + (task_info_t)&info, &info_count) == KERN_SUCCESS) { + rss = (size_t)info.resident_size; + } + #endif + // Linux + #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) + FILE* fp = NULL; + if ((fp = fopen( "/proc/self/statm", "r" )) != NULL) { + if (fscanf( fp, "%*s%ld", &rss ) == 1) { + rss *= (size_t)sysconf(_SC_PAGESIZE); + } + fclose(fp); + } + // AIX, BSD, Solaris, and Unknown OS + #else + rss = 0; + #endif - // Return sky map - return map; + // Return resident set size + return rss; } + /***********************************************************************//** - * @brief Build a skymap based on user parameters + * @brief Get a CTA ebent cube from from file * - * Creates an empty skymap from input user parameters. + * @param[in] filename FITS file of count cube. + * + * @exception GException::invalid_value + * Counts map not of WCS type * + * Gets an event cube from a FITS file. This function is used in many ctools + * to obtain a skymap definition from an event cube. + * + * @todo Is it necessary to restrict this method to WCS coordinates? ***************************************************************************/ -GSkymap ctool::get_map(const GObservations& obs) +GCTAEventCube ctool::set_from_cntmap(const std::string filename) { - // Read ahead map information - std::string proj = (*this)["proj"].string(); - std::string coordsys = (*this)["coordsys"].string(); - - // Initialise reference coordinates - double xref = 0.0; - double yref = 0.0; - - // Get pointing from observations - GSkyDir pnt = get_pointing(obs); - - // Use correct coordinate system - if (gammalib::toupper(coordsys) == "GAL") { - xref = pnt.l_deg(); - yref = pnt.b_deg(); - } - else { - xref = pnt.ra_deg(); - yref = pnt.dec_deg(); - } - - double binsz = (*this)["binsz"].real(); - int nxpix = (*this)["nxpix"].integer(); - int nypix = (*this)["nypix"].integer(); + // Allocate CTA observation + GCTAEventCube cube; - // Initialise sky map - GSkymap map = GSkymap(proj, coordsys, xref, yref, -binsz, binsz, nxpix, nypix, 1); + // Load counts map in CTA observation + cube.load(filename); - // Return sky map - return map; + // Check for valid WCS coordinate system + const GWcs* wcs = dynamic_cast(cube.map().projection()); + if (wcs == NULL) { + std::string msg = "Counts map project is not of WCS type."; + throw GException::invalid_value(G_SET_FROM_CNTMAP, msg); + } + + // Return cube + return cube; } + /***********************************************************************//** * @brief Set response for all CTA observations in container * * @param[in,out] obs Observation container * * Set the response for a CTA observations in the container that so far have - * no response using the "database" and "irf" task parameters. + * no response using the "caldb" and "irf" task parameters. + * + * The following parameters are read: + * caldb - Calibration database + * irf - Instrument response function ***************************************************************************/ void ctool::set_response(GObservations& obs) { @@ -796,8 +891,12 @@ void ctool::set_response(GObservations& obs) * * @param[in,out] obs CTA observation * - * Set the response for a CTA observation using the "database" and "irf" + * Set the response for a CTA observation using the "caldb" and "irf" * task parameters. + * + * The following parameters are read: + * caldb - Calibration database + * irf - Instrument response function ***************************************************************************/ void ctool::set_obs_response(GCTAObservation* obs) { @@ -822,50 +921,3 @@ void ctool::set_obs_response(GCTAObservation* obs) // Return return; } - - -/***********************************************************************//** - * @brief Get current resident set size (physical memory use) in Bytes - * - * @return Physical memory use in Bytes. - ***************************************************************************/ -size_t ctool::get_current_rss(void) -{ - // Initialize resident set size - size_t rss = 0; - - // Determine resident set size (architecture dependent) - // OSX - #if defined(__APPLE__) && defined(__MACH__) - #ifdef MACH_TASK_BASIC_INFO - struct mach_task_basic_info info; - mach_msg_type_number_t infoCount = MACH_TASK_BASIC_INFO_COUNT; - if (task_info(mach_task_self( ), MACH_TASK_BASIC_INFO, - (task_info_t)&info, &infoCount) == KERN_SUCCESS) { - rss = (size_t)info.resident_size; - } - #else - struct task_basic_info info; - mach_msg_type_number_t info_count = TASK_BASIC_INFO_COUNT; - if (task_info(mach_task_self(), TASK_BASIC_INFO, - (task_info_t)&info, &info_count) == KERN_SUCCESS) { - rss = (size_t)info.resident_size; - } - #endif - // Linux - #elif defined(__linux__) || defined(__linux) || defined(linux) || defined(__gnu_linux__) - FILE* fp = NULL; - if ((fp = fopen( "/proc/self/statm", "r" )) != NULL) { - if (fscanf( fp, "%*s%ld", &rss ) == 1) { - rss *= (size_t)sysconf(_SC_PAGESIZE); - } - fclose(fp); - } - // AIX, BSD, Solaris, and Unknown OS - #else - rss = 0; - #endif - - // Return resident set size - return rss; -} diff --git a/src/support/ctool.hpp b/src/support/ctool.hpp index 9035b18..665e2be 100644 --- a/src/support/ctool.hpp +++ b/src/support/ctool.hpp @@ -1,7 +1,7 @@ /*************************************************************************** * ctool - ctool base class * * ----------------------------------------------------------------------- * - * copyright (C) 2014 by Juergen Knoedlseder * + * copyright (C) 2014-2015 by Juergen Knoedlseder * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -62,28 +62,27 @@ public: protected: // Protected methods - void init_members(void); - void copy_members(const ctool& app); - void free_members(void); - const bool& read_ahead(void) const; - GEbounds get_ebounds(void); - GObservations get_observations(const bool& get_response=true); + void init_members(void); + void copy_members(const ctool& app); + void free_members(void); + const bool& read_ahead(void) const; GCTAObservation setup_obs(void); - GSkymap get_map(void); - GCTAEventCube get_cube(void); - GSkymap get_map(const GObservations& obs); - GCTAEventCube get_cube(const GObservations& obs); - GCTAEventCube set_from_cntmap(const std::string filename); - GSkyDir get_pointing(const GObservations& obs); - - void set_response(GObservations& obs); - void set_obs_response(GCTAObservation* obs); - size_t get_current_rss(void); + GSkymap get_map(void); + GSkymap get_map(const GObservations& obs); + GEbounds get_ebounds(void); + GObservations get_observations(const bool& get_response = true); + GCTAEventCube get_cube(void); + GCTAEventCube get_cube(const GObservations& obs); + GSkyDir get_mean_pointing(const GObservations& obs); + size_t get_current_rss(void); + GCTAEventCube set_from_cntmap(const std::string filename); + void set_response(GObservations& obs); + void set_obs_response(GCTAObservation* obs); // Protected members - bool m_read_ahead; //!< Read ahead parameters - bool m_use_xml; //!< Use XML file instead of FITS file for observations - GTimeReference m_cta_ref; //!< CTA time reference + bool m_read_ahead; //!< Read ahead parameters + bool m_use_xml; //!< Use XML file instead of FITS file for observations + GTimeReference m_cta_ref; //!< CTA time reference }; -- libgit2 0.21.4