Commit 3ff175f6529448cf24f2d6711f78e15b6a9c3c23
Merge branch '1863_CovMat' into integration
# Conflicts: # ChangeLog # NEWS
Showing
7 changed files
with
68 additions
and
22 deletions
AUTHORS
ChangeLog
| 1 | -2016-10-07 | |
| 1 | +2016-10-17 | |
| 2 | 2 | |
| 3 | 3 | * Version 1.2.0 released |
| 4 | 4 | ======================== |
| 5 | 5 | |
| 6 | + Add outcovmat parameter to ctlike (#1863) | |
| 6 | 7 | Add publish parameter and methods to ctobssim, ctselect, cslightcrv and csspec (#1871) |
| 7 | 8 | Add csviscube script (#1853) |
| 8 | 9 | Add zenith and azimuth angle information to IRF caldb (#1853) | ... | ... |
NEWS
| 1 | 1 | New Features and Important Changes in ctools 1.2.0 |
| 2 | 2 | |
| 3 | -7 October 2016 | |
| 3 | +17 October 2016 | |
| 4 | 4 | |
| 5 | 5 | |
| 6 | 6 | Introduction |
| ... | ... | @@ -99,6 +99,10 @@ of the tool (#1835). |
| 99 | 99 | |
| 100 | 100 | The class now derives from ctlikelihood (#1828). |
| 101 | 101 | |
| 102 | +The hidden parameter "outcovmat" has been added that by default is set to "NONE". | |
| 103 | +If instead a FITS filename is given, ctlike will write the coraviance matrix of | |
| 104 | +the fit into a FITS file (#1863). | |
| 105 | + | |
| 102 | 106 | |
| 103 | 107 | cttsmap - Generation of Test Statistic map |
| 104 | 108 | ------------------------------------------ | ... | ... |
doc/source/users/reference_manual/ctlike.rst
| ... | ... | @@ -48,9 +48,13 @@ the spatial model parameters can be kept fixed during that computation |
| 48 | 48 | ctlike generates an output model XML file that contains the values of the |
| 49 | 49 | best fitting model parameters. For all free parameters, an ``error`` attribute |
| 50 | 50 | is added that provides the statistical uncertainty in the parameter estimate. |
| 51 | -If computation of the Test Statistics has been requested for a model component, | |
| 52 | -a ``ts`` attribute providing the Test Statistics value is added. The output | |
| 53 | -model can be used as an input model for other ctools. | |
| 51 | +In addition, the entire output of the covariance matrix to a separate FITS file | |
| 52 | +can be queried (parameter ``outcovmat``). The parameter order given in the file | |
| 53 | +corresponds to the arrangement of the covariance matrix entries. If computation | |
| 54 | +of the Test Statistics has been requested for a model component, a ``ts`` | |
| 55 | +attribute providing the Test Statistics value is added. The output model can be | |
| 56 | +used as an input model for other ctools. | |
| 57 | + | |
| 54 | 58 | |
| 55 | 59 | |
| 56 | 60 | General parameters |
| ... | ... | @@ -84,6 +88,9 @@ General parameters |
| 84 | 88 | Output model XML file with values and uncertainties updated by |
| 85 | 89 | the maximum likelihood fit. |
| 86 | 90 | |
| 91 | +``(outcovmat = NONE) [string]`` | |
| 92 | + Output FITS file to store covariance matrix. | |
| 93 | + | |
| 87 | 94 | ``(stat = POISSON) [string]`` |
| 88 | 95 | Fitting statistics (POISSON or GAUSSIAN; only affects binned analysis). |
| 89 | 96 | |
| ... | ... | @@ -92,8 +99,7 @@ General parameters |
| 92 | 99 | |
| 93 | 100 | ``(fix_spat_for_ts = no) [boolean]`` |
| 94 | 101 | Fix spatial parameters for TS computation. |
| 95 | - | |
| 96 | - | |
| 102 | + | |
| 97 | 103 | |
| 98 | 104 | Standard parameters |
| 99 | 105 | ------------------- | ... | ... |
src/ctlike/ctlike.cpp
| ... | ... | @@ -228,6 +228,13 @@ void ctlike::run(void) |
| 228 | 228 | // Optimize model parameters using LM optimizer |
| 229 | 229 | optimize_lm(); |
| 230 | 230 | |
| 231 | + // Get pointer to curvature matrix | |
| 232 | + GMatrixSparse* curvature_ptr = | |
| 233 | + const_cast<GObservations::likelihood&>(m_obs.function()).curvature(); | |
| 234 | + | |
| 235 | + // Store copy of curvature matrix | |
| 236 | + GMatrixSparse curvature = *curvature_ptr; | |
| 237 | + | |
| 231 | 238 | // Store Npred |
| 232 | 239 | double npred = m_obs.npred(); |
| 233 | 240 | |
| ... | ... | @@ -305,6 +312,9 @@ void ctlike::run(void) |
| 305 | 312 | // Restore energy dispersion flags of all CTA observations |
| 306 | 313 | restore_edisp(m_obs, save_edisp); |
| 307 | 314 | |
| 315 | + // Restore curvature matrix | |
| 316 | + *curvature_ptr = curvature; | |
| 317 | + | |
| 308 | 318 | // Return |
| 309 | 319 | return; |
| 310 | 320 | } |
| ... | ... | @@ -313,15 +323,17 @@ void ctlike::run(void) |
| 313 | 323 | /***********************************************************************//** |
| 314 | 324 | * @brief Save results |
| 315 | 325 | * |
| 316 | - * This method saves the fit results in a XML file. | |
| 326 | + * This method saves the fit results into a XML file and a FITS file. If | |
| 327 | + * the filename parameters are "NONE", the files are not saved. | |
| 317 | 328 | ***************************************************************************/ |
| 318 | 329 | void ctlike::save(void) |
| 319 | 330 | { |
| 320 | 331 | // Write header |
| 321 | 332 | log_header1(TERSE, "Save results"); |
| 322 | 333 | |
| 323 | - // Get output filename | |
| 324 | - m_outmodel = (*this)["outmodel"].filename(); | |
| 334 | + // Get output filenames | |
| 335 | + m_outmodel = (*this)["outmodel"].filename(); | |
| 336 | + m_outcovmat = (*this)["outcovmat"].filename(); | |
| 325 | 337 | |
| 326 | 338 | // Save only if filename is valid |
| 327 | 339 | if (is_valid_filename(m_outmodel)) { |
| ... | ... | @@ -339,6 +351,22 @@ void ctlike::save(void) |
| 339 | 351 | log_value(NORMAL, "Model definition file", "NONE"); |
| 340 | 352 | } |
| 341 | 353 | |
| 354 | + // Save covariance matrix if filename is valid | |
| 355 | + if (is_valid_filename(m_outcovmat)) { | |
| 356 | + | |
| 357 | + // Log filename | |
| 358 | + log_value(NORMAL, "Covariance matrix file", m_outcovmat.url()); | |
| 359 | + | |
| 360 | + // Save covarianve matrix | |
| 361 | + m_obs.function().save(m_outcovmat); | |
| 362 | + | |
| 363 | + } | |
| 364 | + | |
| 365 | + // ... otherwise signal that no covariance matrix was not saved | |
| 366 | + else { | |
| 367 | + log_value(NORMAL, "Covariance matrix file", "NONE"); | |
| 368 | + } | |
| 369 | + | |
| 342 | 370 | // Return |
| 343 | 371 | return; |
| 344 | 372 | } |
| ... | ... | @@ -397,7 +425,8 @@ void ctlike::get_parameters(void) |
| 397 | 425 | // Optionally read ahead parameters so that they get correctly |
| 398 | 426 | // dumped into the log file |
| 399 | 427 | if (read_ahead()) { |
| 400 | - m_outmodel = (*this)["outmodel"].filename(); | |
| 428 | + m_outmodel = (*this)["outmodel"].filename(); | |
| 429 | + m_outcovmat = (*this)["outcovmat"].filename(); | |
| 401 | 430 | } |
| 402 | 431 | |
| 403 | 432 | // Set optimizer logger |
| ... | ... | @@ -530,6 +559,7 @@ void ctlike::init_members(void) |
| 530 | 559 | { |
| 531 | 560 | // Initialise members |
| 532 | 561 | m_outmodel.clear(); |
| 562 | + m_outcovmat.clear(); | |
| 533 | 563 | m_refit = false; |
| 534 | 564 | m_max_iter = 100; // Set maximum number of iterations |
| 535 | 565 | m_max_stall = 10; // Set maximum number of stalls |
| ... | ... | @@ -560,6 +590,7 @@ void ctlike::copy_members(const ctlike& app) |
| 560 | 590 | // Copy attributes |
| 561 | 591 | m_refit = app.m_refit; |
| 562 | 592 | m_outmodel = app.m_outmodel; |
| 593 | + m_outcovmat = app.m_outcovmat; | |
| 563 | 594 | m_max_iter = app.m_max_iter; |
| 564 | 595 | m_max_stall = app.m_max_stall; |
| 565 | 596 | m_logL = app.m_logL; | ... | ... |
src/ctlike/ctlike.hpp
| ... | ... | @@ -70,6 +70,7 @@ protected: |
| 70 | 70 | // User parameters |
| 71 | 71 | bool m_refit; //!< Refitting |
| 72 | 72 | GFilename m_outmodel; //!< Source model output XML file name |
| 73 | + GFilename m_outcovmat; //!< Covariance matrix output FITS file name | |
| 73 | 74 | bool m_apply_edisp; //!< Apply energy dispersion? |
| 74 | 75 | bool m_fix_spat_for_ts; //!< Fix spatial parameters for TS computation? |
| 75 | 76 | GChatter m_chatter; //!< Chattiness | ... | ... |
src/ctlike/ctlike.par
| ... | ... | @@ -5,7 +5,7 @@ |
| 5 | 5 | # ------------------------------------------------------------------------- # |
| 6 | 6 | # # |
| 7 | 7 | # File: ctlike.par # |
| 8 | -# Version: 1.1.0 # | |
| 8 | +# Version: 1.2.0 # | |
| 9 | 9 | # # |
| 10 | 10 | # Author: Jurgen Knodlseder # |
| 11 | 11 | # Jurgen.Knodlseder@irap.omp.eu # |
| ... | ... | @@ -17,16 +17,17 @@ |
| 17 | 17 | # |
| 18 | 18 | # General parameters |
| 19 | 19 | #=================== |
| 20 | -inobs, f, a, "events.fits",,, "Input event list, counts cube or observation definition XML file" | |
| 21 | -inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file" | |
| 22 | -expcube, f, a, "NONE",,, "Input exposure cube file (only needed for stacked analysis)" | |
| 23 | -psfcube, f, a, "NONE",,, "Input PSF cube file (only needed for stacked analysis)" | |
| 24 | -edispcube, f, a, "NONE",,, "Input energy dispersion cube file (only needed for stacked analysis)" | |
| 25 | -bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked analysis)" | |
| 26 | -caldb, s, a, "prod2",,, "Calibration database" | |
| 27 | -irf, s, a, "South_0.5h",,, "Instrument response function" | |
| 28 | -edisp, b, h, no,,, "Apply energy dispersion?" | |
| 29 | -outmodel, f, a, "crab_results.xml",,, "Output model XML file" | |
| 20 | +inobs, f, a, "events.fits",,, "Input event list, counts cube or observation definition XML file" | |
| 21 | +inmodel, f, a, "$CTOOLS/share/models/crab.xml",,, "Input model XML file" | |
| 22 | +expcube, f, a, "NONE",,, "Input exposure cube file (only needed for stacked analysis)" | |
| 23 | +psfcube, f, a, "NONE",,, "Input PSF cube file (only needed for stacked analysis)" | |
| 24 | +edispcube, f, a, "NONE",,, "Input energy dispersion cube file (only needed for stacked analysis)" | |
| 25 | +bkgcube, f, a, "NONE",,, "Input background cube file (only needed for stacked analysis)" | |
| 26 | +caldb, s, a, "prod2",,, "Calibration database" | |
| 27 | +irf, s, a, "South_0.5h",,, "Instrument response function" | |
| 28 | +edisp, b, h, no,,, "Apply energy dispersion?" | |
| 29 | +outmodel, f, a, "crab_results.xml",,, "Output model XML file" | |
| 30 | +outcovmat, f, h, "NONE",,, "Output covariance matrix FITS file" | |
| 30 | 31 | |
| 31 | 32 | # |
| 32 | 33 | # Maximisation parameters | ... | ... |