ctools 2.1.0.dev
Loading...
Searching...
No Matches
ctlike.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * ctlike - Maximum likelihood fitting tool *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2010-2022 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file ctlike.cpp
23 * @brief Maximum likelihood fitting tool implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <cstdio>
32#include "ctlike.hpp"
33#include "GTools.hpp"
34
35/* __ OpenMP section _____________________________________________________ */
36#ifdef _OPENMP
37#include <omp.h>
38#endif
39
40/* __ Method name definitions ____________________________________________ */
41
42/* __ Debug definitions __________________________________________________ */
43
44/* __ Coding definitions _________________________________________________ */
45
46
47/*==========================================================================
48 = =
49 = Constructors/destructors =
50 = =
51 ==========================================================================*/
52
53/***********************************************************************//**
54 * @brief Void constructor
55 ***************************************************************************/
57{
58 // Initialise members
60
61 // Return
62 return;
63}
64
65
66/***********************************************************************//**
67 * @brief Observations constructor
68 *
69 * param[in] obs Observation container.
70 *
71 * Constructs ctlike tool from an observations container.
72 ***************************************************************************/
73ctlike::ctlike(const GObservations& obs) :
74 ctlikelihood(CTLIKE_NAME, VERSION, obs)
75{
76 // Initialise members
78
79 // Return
80 return;
81}
82
83
84/***********************************************************************//**
85 * @brief Command line constructor
86 *
87 * @param[in] argc Number of arguments in command line.
88 * @param[in] argv Array of command line arguments.
89 *
90 * Constructs an instance of the ctlike tool that will parse user parameters
91 * that are provided as command line arguments.
92 ***************************************************************************/
93ctlike::ctlike(int argc, char *argv[]) :
94 ctlikelihood(CTLIKE_NAME, VERSION, argc, argv)
95{
96 // Initialise members
98
99 // Return
100 return;
101}
102
103
104/***********************************************************************//**
105 * @brief Copy constructor
106 *
107 * @param[in] app Application.
108 ***************************************************************************/
110{
111 // Initialise members
112 init_members();
113
114 // Copy members
115 copy_members(app);
116
117 // Return
118 return;
119}
120
121
122/***********************************************************************//**
123 * @brief Destructor
124 ***************************************************************************/
126{
127 // Free members
128 free_members();
129
130 // Return
131 return;
132}
133
134
135/*==========================================================================
136 = =
137 = Operators =
138 = =
139 ==========================================================================*/
140
141/***********************************************************************//**
142 * @brief Assignment operator
143 *
144 * @param[in] app Application.
145 * @return Application.
146 ***************************************************************************/
148{
149 // Execute only if object is not identical
150 if (this != &app) {
151
152 // Copy base class members
153 this->ctlikelihood::operator=(app);
154
155 // Free members
156 free_members();
157
158 // Initialise members
159 init_members();
160
161 // Copy members
162 copy_members(app);
163
164 } // endif: object was not identical
165
166 // Return this object
167 return *this;
168}
169
170
171/*==========================================================================
172 = =
173 = Public methods =
174 = =
175 ==========================================================================*/
176
177/***********************************************************************//**
178 * @brief Clear ctlike tool
179 *
180 * Clears ctlike tool.
181 ***************************************************************************/
183{
184 // Free members
185 free_members();
188 this->ctool::free_members();
189
190 // Clear base class (needed to conserve tool name and version)
191 this->GApplication::clear();
192
193 // Initialise members
194 this->ctool::init_members();
197 init_members();
198
199 // Write header into logger
200 log_header();
201
202 // Return
203 return;
204}
205
206
207/***********************************************************************//**
208 * @brief Process maximum likelihood analysis
209 *
210 * The following analysis steps are performed:
211 * 1. Read the parameters (and write them into logger)
212 * 2. Load observation
213 * 3. Setup models for optimizing
214 * 4. Optimize model (and write result into logger)
215 ***************************************************************************/
217{
218 // Get parameters
220
221 // Set energy dispersion flags of all CTA observations and save old
222 // values in save_edisp vector
223 std::vector<bool> save_edisp = set_edisp(m_obs, m_apply_edisp);
224
225 // Write input observation container into logger
226 log_observations(NORMAL, m_obs, "Input observation");
227
228 // Compute number of observed events in all observations
229 m_nobs = 0.0;
230 for (int i = 0; i < m_obs.size(); ++i) {
231 double data = m_obs[i]->nobserved();
232 if (data >= 0.0) {
233 m_nobs += data;
234 }
235 }
236
237 // Optimize model parameters using LM optimizer
238 optimize_lm();
239
240 // Store copy of curvature matrix
241 GMatrixSparse curvature =
242 *(const_cast<GObservations::likelihood&>(m_obs.function()).curvature());
243
244 // Store Npred
245 m_npred = m_obs.npred();
246
247 // Store models for which TS should be computed
248 std::vector<std::string> ts_srcs;
249 GModels models_orig = m_obs.models();
250 for (int i = 0; i < models_orig.size(); ++i) {
251 GModel* model = models_orig[i];
252 if (model->tscalc()) {
253 ts_srcs.push_back(model->name());
254 }
255 }
256
257 // Compute TS values if requested
258 if (!ts_srcs.empty()) {
259
260 // Write general fit results in logger (will be repeated at the
261 // end)
262 log_header1(EXPLICIT, "Maximum likelihood optimisation results");
263 log_string(EXPLICIT, m_opt.print(m_chatter));
264 log_value(EXPLICIT, "Maximum log likelihood", gammalib::str(m_logL,3));
265 log_value(EXPLICIT, "Observed events (Nobs)", gammalib::str(m_nobs,3));
266 log_value(EXPLICIT, "Predicted events (Npred)", gammalib::str(m_npred,3)+
267 " (Nobs - Npred = "+gammalib::str(m_nobs-m_npred)+")");
268 log_string(VERBOSE, m_obs.models().print(m_chatter));
269
270 // Store original maximum likelihood and models
271 double logL_src = m_logL;
272 GModels models = m_obs.models();
273
274 // Fix spatial parameters if requested
275 if (m_fix_spat_for_ts) {
276
277 // Loop over all models
278 for (int i = 0; i < models.size(); ++i) {
279
280 // Continue only if model is skymodel
281 GModelSky* sky= dynamic_cast<GModelSky*>(models[i]);
282 if (sky != NULL) {
283
284 // Fix spatial parameters
285 GModelSpatial* spatial = sky->spatial();
286 for (int j = 0; j < spatial->size(); j++) {
287 (*spatial)[j].fix();
288 } // endfor: looped over spatial parameters
289
290 } // endif: there was a sky model
291
292 } // endfor: looped over models
293
294 } // endif: spatial parameter should be fixed
295
296 // Loop over stored models, remove source and refit
297 for (int i = 0; i < ts_srcs.size(); ++i) {
298
299 // Create copy of models
300 GModels models_copy = models;
301
302 // Remove source of interest
303 models_copy.remove(ts_srcs[i]);
304
305 // Set models for fitting
306 m_obs.models(models_copy);
307
308 // Re-optimise log-likelihood for the source removed
309 double logL_nosrc = reoptimize_lm();
310
311 // Compute source TS value
312 double ts = 2.0 * (logL_src-logL_nosrc);
313
314 // Store TS value in original model
315 models_orig[ts_srcs[i]]->ts(ts);
316
317 } // endfor: looped over sources
318
319 // Restore best fit values
320 m_obs.models(models_orig);
321
322 } // endif: requested TS computation
323
324 // Write results into logger
325 log_header1(NORMAL, "Maximum likelihood optimisation results");
326 log_string(NORMAL, m_opt.print(m_chatter));
327 log_value(NORMAL, "Total number of iterations", m_iter);
328 log_value(NORMAL, "Maximum log likelihood", gammalib::str(m_logL,3));
329 log_value(NORMAL, "Observed events (Nobs)", gammalib::str(m_nobs,3));
330 log_value(NORMAL, "Predicted events (Npred)", gammalib::str(m_npred,3)+
331 " (Nobs - Npred = "+gammalib::str(m_nobs-m_npred)+")");
332 log_string(NORMAL, m_obs.models().print(m_chatter));
333
334 // Restore energy dispersion flags of all CTA observations
335 restore_edisp(m_obs, save_edisp);
336
337 // Restore curvature matrix
338 *(const_cast<GObservations::likelihood&>(m_obs.function()).curvature()) =
339 curvature;
340
341 // Return
342 return;
343}
344
345
346/***********************************************************************//**
347 * @brief Save results
348 *
349 * This method saves the fit results and the covariance matrix. The fit
350 * results are written into a XML file while the covariance matrix is written
351 * into either a FITS or a CSV file, depending on the file type extension
352 * (an extension of `.fits` or `.fit` produce a FITS file, any other
353 * extension produces a CSV file).
354 *
355 * If the filenames are `NONE` no information is saved.
356 ***************************************************************************/
357void ctlike::save(void)
358{
359 // Write header
360 log_header1(TERSE, "Save results");
361
362 // Save model only if filename is valid
363 if ((*this)["outmodel"].is_valid()) {
364
365 // Generate XML instance
366 GXml xml = xml_result();
367
368 // Get output filename
369 m_outmodel = (*this)["outmodel"].filename();
370
371 // Log filename
372 log_value(NORMAL, "Model definition file", m_outmodel.url());
373
374 // Write results out as XML model
375 xml.save(m_outmodel);
376
377 } // endif: filename was valid
378
379 // ... otherwise signal that file was not saved
380 else {
381 log_value(NORMAL, "Model definition file", "NONE");
382 }
383
384 // Save covariance matrix only if filename is valid
385 if ((*this)["outcovmat"].is_valid()) {
386
387 // Get output filenames
388 m_outcovmat = (*this)["outcovmat"].filename();
389
390 // Log filename
391 log_value(NORMAL, "Covariance matrix file", m_outcovmat.url());
392
393 // Save covariance matrix
394 m_obs.function().save(m_outcovmat);
395
396 }
397
398 // ... otherwise signal that no covariance matrix was not saved
399 else {
400 log_value(NORMAL, "Covariance matrix file", "NONE");
401 }
402
403 // Return
404 return;
405}
406
407
408/*==========================================================================
409 = =
410 = Private methods =
411 = =
412 ==========================================================================*/
413
414/***********************************************************************//**
415 * @brief Initialise class members
416 ***************************************************************************/
418{
419 // Initialise members
420 m_outmodel.clear();
421 m_outcovmat.clear();
422 m_max_iter = 50;
423 m_refit = false;
424 m_refit_if_failed = true;
425 m_apply_edisp = false;
426 m_fix_spat_for_ts = false;
427 m_chatter = static_cast<GChatter>(2);
428 m_iter = 0;
429 m_logL = 0.0;
430 m_nobs = 0.0;
431 m_npred = 0.0;
432
433 // Set logger properties
434 log.date(true);
435
436 // Return
437 return;
438}
439
440
441/***********************************************************************//**
442 * @brief Copy class members
443 *
444 * @param[in] app Application.
445 ***************************************************************************/
447{
448 // Copy attributes
449 m_outmodel = app.m_outmodel;
450 m_outcovmat = app.m_outcovmat;
451 m_max_iter = app.m_max_iter;
452 m_refit = app.m_refit;
453 m_refit_if_failed = app.m_refit_if_failed;
454 m_apply_edisp = app.m_apply_edisp;
455 m_fix_spat_for_ts = app.m_fix_spat_for_ts;
456 m_chatter = app.m_chatter;
457 m_iter = app.m_iter;
458 m_logL = app.m_logL;
459 m_nobs = app.m_nobs;
460 m_npred = app.m_npred;
461
462 // Return
463 return;
464}
465
466
467/***********************************************************************//**
468 * @brief Delete class members
469 ***************************************************************************/
471{
472 // Return
473 return;
474}
475
476
477/***********************************************************************//**
478 * @brief Get application parameters
479 *
480 * Get all required task parameters from the parameter file.
481 ***************************************************************************/
483{
484 // Setup observations from "inobs" parameter
486
487 // Set observation statistic
488 set_obs_statistic(gammalib::toupper((*this)["statistic"].string()));
489
490 // If there is are no models associated with the observations then
491 // load now the model definition
492 if (m_obs.models().size() == 0) {
493
494 // Get models XML filename
495 std::string filename = (*this)["inmodel"].filename();
496
497 // Setup models for optimizing.
498 m_obs.models(GModels(filename));
499
500 } // endif: no models were associated with observations
501
502 // Set optimizer characteristics from user parameters
503 m_max_iter = (*this)["max_iter"].integer();
504 m_opt.max_iter(m_max_iter);
505 m_opt.eps((*this)["like_accuracy"].real());
506 m_opt.accept_dec((*this)["accept_dec"].real());
507
508 // Get other parameters
509 m_refit = (*this)["refit"].boolean();
510 m_refit_if_failed = (*this)["refit_if_failed"].boolean();
511 m_apply_edisp = (*this)["edisp"].boolean();
512 m_fix_spat_for_ts = (*this)["fix_spat_for_ts"].boolean();
513 m_chatter = static_cast<GChatter>((*this)["chatter"].integer());
514
515 // If needed later, query output filenames now
516 if (read_ahead()) {
517 (*this)["outmodel"].query();
518 (*this)["outcovmat"].query();
519 }
520
521 // Set optimizer logger
522 if (logNormal()) {
523 static_cast<GOptimizerLM*>(&m_opt)->logger(&log);
524 }
525 else {
526 static_cast<GOptimizerLM*>(&m_opt)->logger(NULL);
527 }
528
529 // Set number of OpenMP threads
530 #ifdef _OPENMP
531 int nthreads = (*this)["nthreads"].integer();
532 if (nthreads > 0) {
533 omp_set_num_threads(nthreads);
534 }
535 #endif
536
537 // Write parameters into logger
538 log_parameters(TERSE);
539
540 // Return
541 return;
542}
543
544
545/***********************************************************************//**
546 * @brief Optimise model parameters
547 *
548 * Optimise model parameters using a maximum likelihood fit.
549 ***************************************************************************/
551{
552 // Write header
553 log_header1(TERSE, "Maximum likelihood optimisation");
554 log.indent(1);
555
556 // Initialise number of iterations
557 m_iter = 0;
558
559 // Compute number of fitted parameters
560 int nfit = 0;
561 for (int i = 0; i < m_obs.models().size(); ++i) {
562 const GModel* model = m_obs.models()[i];
563 for (int k = 0; k < model->size(); ++k) {
564 if ((*model)[k].is_free()) {
565 nfit++;
566 }
567 }
568 }
569
570 // Notify if all parameters are fixed
571 if (nfit == 0) {
572 log_string(TERSE, "WARNING: All model parameters are fixed!");
573 log_string(TERSE, " ctlike will proceed without fitting parameters.");
574 log_string(TERSE, " All curvature matrix elements will be zero.");
575 }
576
577 // Perform LM optimization
578 m_obs.optimize(m_opt);
579
580 // Add number of iterations
581 m_iter += m_opt.iter();
582
583 // Optionally refit
584 if (refit(&m_opt)) {
585
586 // Dump new header
587 log.indent(0);
588 log_header1(TERSE, "Maximum likelihood re-optimisation");
589 log.indent(1);
590
591 // Optimise again
592 m_obs.optimize(m_opt);
593
594 // Add number of iterations
595 m_iter += m_opt.iter();
596
597 }
598
599 // Optionally show curvature matrix
600 log_header1(EXPLICIT, "Curvature matrix");
601 log.indent(1);
602 log_string(EXPLICIT, (const_cast<GObservations::likelihood&>
603 (m_obs.function()).curvature())->print());
604
605 // Compute errors
606 m_obs.errors(m_opt);
607
608 // Store maximum log likelihood value
609 m_logL = -(m_opt.value());
610
611 // Remove indent
612 log.indent(0);
613
614 // Return
615 return;
616}
617
618
619/***********************************************************************//**
620 * @brief Re-optimise model parameters for TS computation
621 *
622 * Re-optimise the model parameters using a maximum likelihood fit for
623 * computation of the Test Statistic value for a given source.
624 ***************************************************************************/
626{
627 // Write Header for optimization and indent for optimizer logging
628 log_header1(TERSE, "Maximum likelihood re-optimisation");
629 log.indent(1);
630
631 // Initialise number of iterations
632 int iter = 0;
633
634 // Create a clone of the optimizer for the re-optimisation
635 GOptimizer* opt = m_opt.clone();
636
637 // Perform LM optimization
638 m_obs.optimize(*opt);
639
640 // Add number of iterations
641 iter += opt->iter();
642
643 // Optionally refit
644 if (refit(opt)) {
645
646 // Refit
647 m_obs.optimize(*opt);
648
649 // Add number of iterations
650 iter += opt->iter();
651
652 }
653
654 // Store maximum log likelihood value
655 double logL = -(opt->value());
656
657 // Write optimization results
658 log.indent(0);
659 log_header1(EXPLICIT, "Maximum likelihood re-optimisation results");
660 log_string(EXPLICIT, opt->print(m_chatter));
661 log_value(EXPLICIT, "Total number of iterations", iter);
662 log_value(EXPLICIT, "Maximum log likelihood", gammalib::str(logL,3));
663 log_value(EXPLICIT, "Observed events (Nobs)", gammalib::str(m_nobs,3));
664 log_value(EXPLICIT, "Predicted events (Npred)", gammalib::str(m_obs.npred(),3)+
665 " (Nobs - Npred = "+gammalib::str(m_nobs-m_obs.npred())+")");
666 log_string(VERBOSE, m_obs.models().print(m_chatter));
667
668 // Return
669 return (logL);
670}
671
672
673/***********************************************************************//**
674 * @brief Generate XML result
675 *
676 * @return XML result
677 *
678 * Generates the XML result composed of the ctlike results and the model
679 * fitting results.
680 ***************************************************************************/
681GXml ctlike::xml_result(void) const
682{
683 // Initialise XML result
684 GXml xml;
685
686 // Set fit status
687 std::string status;
688 switch (m_opt.status()) {
689 case G_LM_CONVERGED:
690 status.append("converged");
691 break;
692 case G_LM_STALLED:
693 status.append("stalled");
694 break;
695 case G_LM_SINGULAR:
696 status.append("singular curvature matrix encountered");
697 break;
698 case G_LM_NOT_POSTIVE_DEFINITE:
699 status.append("curvature matrix not positive definite");
700 break;
701 case G_LM_BAD_ERRORS:
702 status.append("errors are inaccurate");
703 break;
704 default:
705 status.append("unknown");
706 break;
707 }
708
709 // Set flag strings
710 std::string refit = (m_refit) ? "yes" : "no";
711 std::string edisp = (m_apply_edisp) ? "yes" : "no";
712 std::string fix_spat_for_ts = (m_fix_spat_for_ts) ? "yes" : "no";
713
714 // Write ctlike results into XML instance
715 if (xml.elements("ctlike_results") == 0) {
716 xml.append(GXmlElement("ctlike_results title=\"ctlike fit results\""));
717 }
718 GXmlElement* result = xml.element("ctlike_results", 0);
719 result->append(GXmlElement("status", status));
720 result->append(GXmlElement("log-likelihood", m_logL));
721 result->append(GXmlElement("precision", m_opt.eps()));
722 result->append(GXmlElement("iterations", m_iter));
723 result->append(GXmlElement("lambda", m_opt.lambda()));
724 result->append(GXmlElement("total_parameters", m_opt.npars()));
725 result->append(GXmlElement("fitted_parameters", m_opt.nfree()));
726 result->append(GXmlElement("observed-events", m_nobs));
727 result->append(GXmlElement("predicted-events", m_npred));
728 result->append(GXmlElement("refit", refit));
729 result->append(GXmlElement("edisp", edisp));
730 result->append(GXmlElement("fix-spatial-for-ts", fix_spat_for_ts));
731 result->append(GXmlElement("elapsed-time", this->telapse()));
732 result->append(GXmlElement("cpu-seconds", this->celapse()));
733
734 // Write model results into XML instance
735 m_obs.models().write(xml);
736
737 // Return XML result
738 return xml;
739}
740
741
742/***********************************************************************//**
743 * @brief Refit needed?
744 *
745 * @param[in] opt Pointer to optimiser.
746 * @return True if refit is needed, false otherwise.
747 *
748 * This method returns true if either the "refit" parameter is set to yes
749 * or the "refit_if_failed" parameter is set to yes and the fit has failed.
750 * The fit is considered as failed if it either has stalled or the number
751 * of fit iterations is exhausted.
752 ***************************************************************************/
753bool ctlike::refit(const GOptimizer* opt)
754{
755 // Initialise refit flag
756 bool refit = m_refit;
757
758 // If flag is false and "refit_if_failed" is true then examine optimiser
759 // result to determine whether the fit has failed
760 if (!refit && m_refit_if_failed) {
761
762 // Has the fit stalled?
763 if (opt->status() == G_LM_STALLED) {
764 refit = true;
765 log_value(NORMAL, "Refit requested", "Fit has stalled");
766 }
767
768 // ... otherwise were the number of fit iterations exhausted?
769 else if (opt->iter() >= m_max_iter) {
770 refit = true;
771 log_value(NORMAL, "Refit requested",
772 "Number of fit iterations exhausted");
773 }
774
775 // ... otherwise check if there is a significant difference between
776 // the number of observed and predicted events
777 else {
778 double npred = m_obs.npred();
779 double difference = m_nobs - npred;
780 if (m_nobs > 0.0) {
781 double fraction = difference / m_nobs;
782 if (std::abs(fraction) > 1.0e-5) {
783 refit = true;
784 log_value(NORMAL, "Refit requested",
785 "Difference "+
786 gammalib::str(difference,3)+
787 " between number of observed events "+
788 gammalib::str(m_nobs,3)+
789 " and predicted events "+
790 gammalib::str(npred,3)+
791 " is larger than +/- 1.0e-5 times the number of"+
792 " observed events ("+
793 gammalib::str(fraction)+").");
794 }
795 }
796 if (!refit && std::abs(difference) > 5.0) {
797 refit = true;
798 log_value(NORMAL, "Refit requested",
799 "Difference "+
800 gammalib::str(difference,3)+
801 " between number of observed events "+
802 gammalib::str(m_nobs,3)+
803 " and predicted events "+
804 gammalib::str(npred,3)+
805 " is larger than +/- 5.");
806 }
807 } // endelse: check number of events
808
809 }
810
811 // Return refit flag
812 return refit;
813}
Maximum likelihood fitting tool.
Definition ctlike.hpp:42
void process(void)
Process maximum likelihood analysis.
Definition ctlike.cpp:216
GXml xml_result(void) const
Generate XML result.
Definition ctlike.cpp:681
int m_max_iter
Maximum number of iterations.
Definition ctlike.hpp:78
ctlike(void)
Void constructor.
Definition ctlike.cpp:56
void save(void)
Save results.
Definition ctlike.cpp:357
ctlike & operator=(const ctlike &app)
Assignment operator.
Definition ctlike.cpp:147
void copy_members(const ctlike &app)
Copy class members.
Definition ctlike.cpp:446
bool refit(const GOptimizer *opt)
Refit needed?
Definition ctlike.cpp:753
const double & npred(void) const
Return number of predicted events.
Definition ctlike.hpp:135
GFilename m_outmodel
Source model output XML file name.
Definition ctlike.hpp:76
void free_members(void)
Delete class members.
Definition ctlike.cpp:470
bool m_refit_if_failed
Refitting in case of failure?
Definition ctlike.hpp:80
void optimize_lm(void)
Optimise model parameters.
Definition ctlike.cpp:550
const int & iter(void) const
Return number of maximum likelihood iterations.
Definition ctlike.hpp:99
bool m_fix_spat_for_ts
Fix spatial parameters for TS computation?
Definition ctlike.hpp:82
bool m_refit
Refitting?
Definition ctlike.hpp:79
double m_npred
Number of predicted events.
Definition ctlike.hpp:89
void get_parameters(void)
Get application parameters.
Definition ctlike.cpp:482
double reoptimize_lm(void)
Re-optimise model parameters for TS computation.
Definition ctlike.cpp:625
GFilename m_outcovmat
Covariance matrix output file name.
Definition ctlike.hpp:77
double m_logL
Maximum log likelihood.
Definition ctlike.hpp:87
double m_nobs
Number of observed events.
Definition ctlike.hpp:88
void clear(void)
Clear ctlike tool.
Definition ctlike.cpp:182
int m_iter
Number of iterations.
Definition ctlike.hpp:86
bool m_apply_edisp
Apply energy dispersion?
Definition ctlike.hpp:81
const double & logL(void) const
Return maximum likelihood value.
Definition ctlike.hpp:111
GChatter m_chatter
Chattiness.
Definition ctlike.hpp:83
virtual ~ctlike(void)
Destructor.
Definition ctlike.cpp:125
void init_members(void)
Initialise class members.
Definition ctlike.cpp:417
Base class for likelihood tools.
GOptimizerLM m_opt
Optimizer.
const GOptimizer * opt(void) const
Return optimizer.
ctlikelihood & operator=(const ctlikelihood &app)
Assignment operator.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
GObservations m_obs
Observation container.
void init_members(void)
Initialise class members.
void set_obs_statistic(const std::string &statistic)
Set fit statistic for CTA observations.
void restore_edisp(GObservations &obs, const std::vector< bool > &edisp) const
Restore energy dispersion flags of CTA observations.
Definition ctool.cpp:1689
void free_members(void)
Delete class members.
Definition ctool.cpp:357
void log_observations(const GChatter &chatter, const GObservations &obs, const std::string &what="Observation")
Log observation container.
Definition ctool.cpp:1251
std::vector< bool > set_edisp(GObservations &obs, const bool &edisp) const
Set energy dispersion to CTA observations.
Definition ctool.cpp:1649
const bool & read_ahead(void) const
Signal whether parameters should be read ahead.
Definition ctool.hpp:177
void log_parameters(const GChatter &chatter)
Log application parameters.
Definition ctool.cpp:1208
void init_members(void)
Initialise class members.
Definition ctool.cpp:321
void setup_observations(GObservations &obs, const bool &response=true, const bool &list=true, const bool &cube=true)
Setup observation container.
Definition ctool.cpp:431
Maximum likelihood fitting tool definition.
#define CTLIKE_NAME
Definition ctlike.hpp:34