Commit fef082192fd1190fdc565ee7a754fbeffe81fed2
1 parent
4cf9b3ba
Read ahead output filename in case that tool is executed.
Showing
2 changed files
with
47 additions
and
23 deletions
src/cterror/cterror.cpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * cterror - Parameter error calculation tool * | 2 | * cterror - Parameter error calculation tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Florent Forest * | 4 | + * copyright (C) 2015-2016 by Florent Forest * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -51,6 +51,8 @@ | @@ -51,6 +51,8 @@ | ||
| 51 | 51 | ||
| 52 | /***********************************************************************//** | 52 | /***********************************************************************//** |
| 53 | * @brief Void constructor | 53 | * @brief Void constructor |
| 54 | + * | ||
| 55 | + * Constructs an empty cterror tool. | ||
| 54 | ***************************************************************************/ | 56 | ***************************************************************************/ |
| 55 | cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | 57 | cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) |
| 56 | { | 58 | { |
| @@ -67,8 +69,8 @@ cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | @@ -67,8 +69,8 @@ cterror::cterror(void) : ctool(CTERROR_NAME, CTERROR_VERSION) | ||
| 67 | * | 69 | * |
| 68 | * param[in] obs Observation container. | 70 | * param[in] obs Observation container. |
| 69 | * | 71 | * |
| 70 | - * This method creates an instance of the class by copying an existing | ||
| 71 | - * observations container. | 72 | + * Constructs an instance of the cterror tool that will operate on the |
| 73 | + * provided observation container. | ||
| 72 | ***************************************************************************/ | 74 | ***************************************************************************/ |
| 73 | cterror::cterror(const GObservations& obs) : | 75 | cterror::cterror(const GObservations& obs) : |
| 74 | ctool(CTERROR_NAME, CTERROR_VERSION) | 76 | ctool(CTERROR_NAME, CTERROR_VERSION) |
| @@ -90,6 +92,9 @@ cterror::cterror(const GObservations& obs) : | @@ -90,6 +92,9 @@ cterror::cterror(const GObservations& obs) : | ||
| 90 | * | 92 | * |
| 91 | * @param[in] argc Number of arguments in command line. | 93 | * @param[in] argc Number of arguments in command line. |
| 92 | * @param[in] argv Array of command line arguments. | 94 | * @param[in] argv Array of command line arguments. |
| 95 | + * | ||
| 96 | + * Constructs an instance of the cterror tool that will parse user | ||
| 97 | + * parameters that are provided as command line arguments. | ||
| 93 | ***************************************************************************/ | 98 | ***************************************************************************/ |
| 94 | cterror::cterror(int argc, char *argv[]) : | 99 | cterror::cterror(int argc, char *argv[]) : |
| 95 | ctool(CTERROR_NAME, CTERROR_VERSION, argc, argv) | 100 | ctool(CTERROR_NAME, CTERROR_VERSION, argc, argv) |
| @@ -106,6 +111,9 @@ cterror::cterror(int argc, char *argv[]) : | @@ -106,6 +111,9 @@ cterror::cterror(int argc, char *argv[]) : | ||
| 106 | * @brief Copy constructor | 111 | * @brief Copy constructor |
| 107 | * | 112 | * |
| 108 | * @param[in] app Application. | 113 | * @param[in] app Application. |
| 114 | + * | ||
| 115 | + * Constructs an instance of the cterror tool by copying information from | ||
| 116 | + * another ctulimit tool. | ||
| 109 | ***************************************************************************/ | 117 | ***************************************************************************/ |
| 110 | cterror::cterror(const cterror& app) : ctool(app) | 118 | cterror::cterror(const cterror& app) : ctool(app) |
| 111 | { | 119 | { |
| @@ -122,6 +130,8 @@ cterror::cterror(const cterror& app) : ctool(app) | @@ -122,6 +130,8 @@ cterror::cterror(const cterror& app) : ctool(app) | ||
| 122 | 130 | ||
| 123 | /***********************************************************************//** | 131 | /***********************************************************************//** |
| 124 | * @brief Destructor | 132 | * @brief Destructor |
| 133 | + * | ||
| 134 | + * Destructs the cterror tool. | ||
| 125 | ***************************************************************************/ | 135 | ***************************************************************************/ |
| 126 | cterror::~cterror(void) | 136 | cterror::~cterror(void) |
| 127 | { | 137 | { |
| @@ -144,6 +154,8 @@ cterror::~cterror(void) | @@ -144,6 +154,8 @@ cterror::~cterror(void) | ||
| 144 | * | 154 | * |
| 145 | * @param[in] app Application. | 155 | * @param[in] app Application. |
| 146 | * @return Application. | 156 | * @return Application. |
| 157 | + * | ||
| 158 | + * Assigns a cterror tool. | ||
| 147 | ***************************************************************************/ | 159 | ***************************************************************************/ |
| 148 | cterror& cterror::operator=(const cterror& app) | 160 | cterror& cterror::operator=(const cterror& app) |
| 149 | { | 161 | { |
| @@ -177,6 +189,8 @@ cterror& cterror::operator=(const cterror& app) | @@ -177,6 +189,8 @@ cterror& cterror::operator=(const cterror& app) | ||
| 177 | 189 | ||
| 178 | /***********************************************************************//** | 190 | /***********************************************************************//** |
| 179 | * @brief Clear instance | 191 | * @brief Clear instance |
| 192 | + * | ||
| 193 | + * Resets the cterror tool to a clean initial state. | ||
| 180 | ***************************************************************************/ | 194 | ***************************************************************************/ |
| 181 | void cterror::clear(void) | 195 | void cterror::clear(void) |
| 182 | { | 196 | { |
| @@ -196,7 +210,9 @@ void cterror::clear(void) | @@ -196,7 +210,9 @@ void cterror::clear(void) | ||
| 196 | 210 | ||
| 197 | 211 | ||
| 198 | /***********************************************************************//** | 212 | /***********************************************************************//** |
| 199 | - * @brief Computes | 213 | + * @brief Compute parameter errors using a likelihood profile method |
| 214 | + * | ||
| 215 | + * Computes the parameter errors using a likelihood profile method. | ||
| 200 | ***************************************************************************/ | 216 | ***************************************************************************/ |
| 201 | void cterror::run(void) | 217 | void cterror::run(void) |
| 202 | { | 218 | { |
| @@ -381,9 +397,9 @@ void cterror::run(void) | @@ -381,9 +397,9 @@ void cterror::run(void) | ||
| 381 | 397 | ||
| 382 | 398 | ||
| 383 | /***********************************************************************//** | 399 | /***********************************************************************//** |
| 384 | - * @brief Save source model | 400 | + * @brief Save model |
| 385 | * | 401 | * |
| 386 | - * This method saves the soutce model to an XML file. | 402 | + * Saves the model into an XML file. |
| 387 | ***************************************************************************/ | 403 | ***************************************************************************/ |
| 388 | void cterror::save(void) | 404 | void cterror::save(void) |
| 389 | { | 405 | { |
| @@ -394,11 +410,11 @@ void cterror::save(void) | @@ -394,11 +410,11 @@ void cterror::save(void) | ||
| 394 | } | 410 | } |
| 395 | 411 | ||
| 396 | // Get output filename | 412 | // Get output filename |
| 397 | - std::string outmodel = (*this)["outmodel"].filename(); | 413 | + m_outmodel = (*this)["outmodel"].filename(); |
| 398 | 414 | ||
| 399 | // Write results out as XML model | 415 | // Write results out as XML model |
| 400 | - if (gammalib::toupper(outmodel) != "NONE") { | ||
| 401 | - m_obs.models().save(outmodel); | 416 | + if (gammalib::toupper(m_outmodel.url()) != "NONE") { |
| 417 | + m_obs.models().save(m_outmodel); | ||
| 402 | } | 418 | } |
| 403 | 419 | ||
| 404 | // Return | 420 | // Return |
| @@ -419,6 +435,7 @@ void cterror::init_members(void) | @@ -419,6 +435,7 @@ void cterror::init_members(void) | ||
| 419 | { | 435 | { |
| 420 | // Initialise user parameters | 436 | // Initialise user parameters |
| 421 | m_srcname.clear(); | 437 | m_srcname.clear(); |
| 438 | + m_outmodel.clear(); | ||
| 422 | m_confidence = 0.68; | 439 | m_confidence = 0.68; |
| 423 | m_tol = 1.0e-3; | 440 | m_tol = 1.0e-3; |
| 424 | m_max_iter = 50; | 441 | m_max_iter = 50; |
| @@ -427,9 +444,9 @@ void cterror::init_members(void) | @@ -427,9 +444,9 @@ void cterror::init_members(void) | ||
| 427 | // Initialise protected members | 444 | // Initialise protected members |
| 428 | m_obs.clear(); | 445 | m_obs.clear(); |
| 429 | m_opt.clear(); | 446 | m_opt.clear(); |
| 430 | - m_dlogL = 0.0; | ||
| 431 | - m_best_logL = 0.0; | ||
| 432 | - m_model_par = NULL; | 447 | + m_dlogL = 0.0; |
| 448 | + m_best_logL = 0.0; | ||
| 449 | + m_model_par = NULL; | ||
| 433 | m_apply_edisp = false; | 450 | m_apply_edisp = false; |
| 434 | 451 | ||
| 435 | // Set optimizer parameters | 452 | // Set optimizer parameters |
| @@ -449,10 +466,11 @@ void cterror::init_members(void) | @@ -449,10 +466,11 @@ void cterror::init_members(void) | ||
| 449 | void cterror::copy_members(const cterror& app) | 466 | void cterror::copy_members(const cterror& app) |
| 450 | { | 467 | { |
| 451 | // Copy user parameters | 468 | // Copy user parameters |
| 452 | - m_srcname = app.m_srcname; | ||
| 453 | - m_confidence = app.m_confidence; | ||
| 454 | - m_tol = app.m_tol; | ||
| 455 | - m_max_iter = app.m_max_iter; | 469 | + m_srcname = app.m_srcname; |
| 470 | + m_outmodel = app.m_outmodel; | ||
| 471 | + m_confidence = app.m_confidence; | ||
| 472 | + m_tol = app.m_tol; | ||
| 473 | + m_max_iter = app.m_max_iter; | ||
| 456 | m_apply_edisp = app.m_apply_edisp; | 474 | m_apply_edisp = app.m_apply_edisp; |
| 457 | 475 | ||
| 458 | // Copy protected members | 476 | // Copy protected members |
| @@ -534,18 +552,24 @@ void cterror::get_parameters(void) | @@ -534,18 +552,24 @@ void cterror::get_parameters(void) | ||
| 534 | m_tol = (*this)["tol"].real(); | 552 | m_tol = (*this)["tol"].real(); |
| 535 | m_max_iter = (*this)["max_iter"].integer(); | 553 | m_max_iter = (*this)["max_iter"].integer(); |
| 536 | 554 | ||
| 555 | + // Read ahead parameters that are only needed when the tool gets | ||
| 556 | + // executed | ||
| 557 | + if (read_ahead()) { | ||
| 558 | + m_outmodel = (*this)["outmodel"].filename(); | ||
| 559 | + } | ||
| 560 | + | ||
| 537 | // Return | 561 | // Return |
| 538 | return; | 562 | return; |
| 539 | } | 563 | } |
| 540 | 564 | ||
| 541 | 565 | ||
| 542 | /***********************************************************************//** | 566 | /***********************************************************************//** |
| 543 | - * @brief Performs error computation by using a bisection method | 567 | + * @brief Calculate error using a bisection method |
| 544 | * | 568 | * |
| 545 | * @param[in] min Minimum parameter value | 569 | * @param[in] min Minimum parameter value |
| 546 | * @param[in] max Maximum parameter value | 570 | * @param[in] max Maximum parameter value |
| 547 | * | 571 | * |
| 548 | - * This method calculates the error using a bisection method. | 572 | + * Calculates the error using a bisection method. |
| 549 | ***************************************************************************/ | 573 | ***************************************************************************/ |
| 550 | double cterror::error_bisection(const double& min, const double& max) | 574 | double cterror::error_bisection(const double& min, const double& max) |
| 551 | { | 575 | { |
| @@ -667,8 +691,7 @@ double cterror::error_bisection(const double& min, const double& max) | @@ -667,8 +691,7 @@ double cterror::error_bisection(const double& min, const double& max) | ||
| 667 | * @param[in] value Parameter factor value | 691 | * @param[in] value Parameter factor value |
| 668 | * @return Log-likelihood value | 692 | * @return Log-likelihood value |
| 669 | * | 693 | * |
| 670 | - * This method evaluates the log-likelihood as a function of the parameter | ||
| 671 | - * of interest. | 694 | + * Evaluates the log-likelihood as a function of the parameter of interest. |
| 672 | ***************************************************************************/ | 695 | ***************************************************************************/ |
| 673 | double cterror::evaluate(const double& value) | 696 | double cterror::evaluate(const double& value) |
| 674 | { | 697 | { |
src/cterror/cterror.hpp
| 1 | /*************************************************************************** | 1 | /*************************************************************************** |
| 2 | * cterror - Parameter error calculation tool * | 2 | * cterror - Parameter error calculation tool * |
| 3 | * ----------------------------------------------------------------------- * | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2015 by Florent Forest * | 4 | + * copyright (C) 2015-2016 by Florent Forest * |
| 5 | * ----------------------------------------------------------------------- * | 5 | * ----------------------------------------------------------------------- * |
| 6 | * * | 6 | * * |
| 7 | * This program is free software: you can redistribute it and/or modify * | 7 | * This program is free software: you can redistribute it and/or modify * |
| @@ -28,20 +28,20 @@ | @@ -28,20 +28,20 @@ | ||
| 28 | #define CTERROR_HPP | 28 | #define CTERROR_HPP |
| 29 | 29 | ||
| 30 | /* __ Includes ___________________________________________________________ */ | 30 | /* __ Includes ___________________________________________________________ */ |
| 31 | +#include <string> | ||
| 31 | #include "GammaLib.hpp" | 32 | #include "GammaLib.hpp" |
| 32 | #include "GCTALib.hpp" | 33 | #include "GCTALib.hpp" |
| 33 | #include "ctool.hpp" | 34 | #include "ctool.hpp" |
| 34 | 35 | ||
| 35 | /* __Definitions _________________________________________________________ */ | 36 | /* __Definitions _________________________________________________________ */ |
| 36 | #define CTERROR_NAME "cterror" | 37 | #define CTERROR_NAME "cterror" |
| 37 | -#define CTERROR_VERSION "01-00-00" | 38 | +#define CTERROR_VERSION "1.1.0" |
| 38 | 39 | ||
| 39 | 40 | ||
| 40 | /***********************************************************************//** | 41 | /***********************************************************************//** |
| 41 | * @class cterror | 42 | * @class cterror |
| 42 | * | 43 | * |
| 43 | * @brief Parameter error calculation tool | 44 | * @brief Parameter error calculation tool |
| 44 | - * | ||
| 45 | ***************************************************************************/ | 45 | ***************************************************************************/ |
| 46 | class cterror : public ctool { | 46 | class cterror : public ctool { |
| 47 | 47 | ||
| @@ -74,6 +74,7 @@ protected: | @@ -74,6 +74,7 @@ protected: | ||
| 74 | 74 | ||
| 75 | // User parameters | 75 | // User parameters |
| 76 | std::string m_srcname; //!< Name of source | 76 | std::string m_srcname; //!< Name of source |
| 77 | + GFilename m_outmodel; //!< Output model XML file | ||
| 77 | double m_confidence; //!< Confidence level | 78 | double m_confidence; //!< Confidence level |
| 78 | double m_tol; //!< Tolerance for limit determination | 79 | double m_tol; //!< Tolerance for limit determination |
| 79 | int m_max_iter; //!< Maximum number of iterations | 80 | int m_max_iter; //!< Maximum number of iterations |