ctools  2.0.0
 All Classes Namespaces Files Functions Variables Macros Pages
ctlike Class Reference

Maximum likelihood fitting tool. More...

#include <ctlike.hpp>

Inheritance diagram for ctlike:
ctlikelihood ctobservation ctool GApplication

Public Member Functions

 ctlike (void)
 Void constructor. More...
 
 ctlike (const GObservations &obs)
 Observations constructor. More...
 
 ctlike (int argc, char *argv[])
 Command line constructor. More...
 
 ctlike (const ctlike &app)
 Copy constructor. More...
 
virtual ~ctlike (void)
 Destructor. More...
 
ctlikeoperator= (const ctlike &app)
 Assignment operator. More...
 
void clear (void)
 Clear ctlike tool. More...
 
void process (void)
 Process maximum likelihood analysis. More...
 
void save (void)
 Save results. More...
 
const int & iter (void) const
 Return number of maximum likelihood iterations. More...
 
const double & logL (void) const
 Return maximum likelihood value. More...
 
const double & nobs (void) const
 Return number of observed events. More...
 
const double & npred (void) const
 Return number of predicted events. More...
 
- Public Member Functions inherited from ctlikelihood
 ctlikelihood (const std::string &name, const std::string &version)
 Name constructor. More...
 
 ctlikelihood (const std::string &name, const std::string &version, const GApplicationPars &pars)
 Application parameters constructor. More...
 
 ctlikelihood (const std::string &name, const std::string &version, int argc, char *argv[])
 Command line constructor. More...
 
 ctlikelihood (const std::string &name, const std::string &version, const GObservations &obs)
 Observations constructor. More...
 
 ctlikelihood (const ctlikelihood &app)
 Copy constructor. More...
 
virtual ~ctlikelihood (void)
 Destructor. More...
 
ctlikelihoodoperator= (const ctlikelihood &app)
 Assignment operator. More...
 
void opt (const GOptimizer *opt)
 Set optimizer. More...
 
const GOptimizer * opt (void) const
 Return optimizer. More...
 
- Public Member Functions inherited from ctobservation
 ctobservation (const std::string &name, const std::string &version)
 Name constructor. More...
 
 ctobservation (const std::string &name, const std::string &version, const GApplicationPars &pars)
 Application parameters constructor. More...
 
 ctobservation (const std::string &name, const std::string &version, int argc, char *argv[])
 Command line constructor. More...
 
 ctobservation (const std::string &name, const std::string &version, const GObservations &obs)
 Observations constructor. More...
 
 ctobservation (const ctobservation &app)
 Copy constructor. More...
 
virtual ~ctobservation (void)
 Destructor. More...
 
ctobservationoperator= (const ctobservation &app)
 Assignment operator. More...
 
void obs (const GObservations &obs)
 Set observation container. More...
 
const GObservations & obs (void) const
 Return observation container. More...
 
- Public Member Functions inherited from ctool
 ctool (const std::string &name, const std::string &version)
 Name constructor. More...
 
 ctool (const std::string &name, const std::string &version, const GApplicationPars &pars)
 Application parameter constructor. More...
 
 ctool (const std::string &name, const std::string &version, int argc, char *argv[])
 Command line constructor. More...
 
 ctool (const ctool &app)
 Copy constructor. More...
 
virtual ~ctool (void)
 Destructor. More...
 
ctooloperator= (const ctool &app)
 Assignment operator. More...
 
virtual void run (void)
 Run ctool. More...
 
virtual void execute (void)
 Execute ctool. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const ctlike &app)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void get_parameters (void)
 Get application parameters. More...
 
void optimize_lm (void)
 Optimise model parameters. More...
 
double reoptimize_lm (void)
 Re-optimise model parameters for TS computation. More...
 
GXml xml_result (void) const
 Generate XML result. More...
 
bool refit (const GOptimizer *opt)
 Refit needed? More...
 
- Protected Member Functions inherited from ctlikelihood
double evaluate (GModelPar &par, const double &value)
 Evaluates the log-likelihood function. More...
 
void init_members (void)
 Initialise class members. More...
 
void copy_members (const ctlikelihood &app)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
- Protected Member Functions inherited from ctobservation
GCTAObservation * first_unbinned_observation (void)
 Return first unbinned CTA observation. More...
 
GCTAObservation * next_unbinned_observation (void)
 Return next unbinned CTA observation. More...
 
const GCTAObservation * first_unbinned_observation (void) const
 Return first unbinned CTA observation (const version) More...
 
const GCTAObservation * next_unbinned_observation (void) const
 Return next unbinned CTA observation (const version) More...
 
void read_ogip_keywords (GFitsHDU *hdu) const
 Read OGIP keywords from FITS HDU. More...
 
void write_ogip_keywords (GFitsHDU *hdu) const
 Write OGIP keywords in FITS HDU. More...
 
void set_obs_statistic (const std::string &statistic)
 Set fit statistic for CTA observations. More...
 
void set_obs_bounds ()
 Set observation boundaries for CTA observations. More...
 
void save_events_fits (void)
 Save event list in FITS format. More...
 
void save_events_xml (void)
 Save event list(s) in XML format. More...
 
void init_members (void)
 Initialise class members. More...
 
void copy_members (const ctobservation &app)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
- Protected Member Functions inherited from ctool
void init_members (void)
 Initialise class members. More...
 
void copy_members (const ctool &app)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void sync_pfiles (void)
 Synchronise parameter files. More...
 
const bool & read_ahead (void) const
 Signal whether parameters should be read ahead. More...
 
void setup_observations (GObservations &obs, const bool &response=true, const bool &list=true, const bool &cube=true)
 Setup observation container. More...
 
void setup_models (GObservations &obs, const std::string &name="")
 Setup model container. More...
 
GEbounds create_ebounds (void)
 Create energy boundaries from user parameters. More...
 
GEnergies create_energies (void)
 Create energies from user parameters. More...
 
GSkyMap create_map (const GObservations &obs)
 Create a skymap from user parameters. More...
 
GCTAEventCube create_cube (const GObservations &obs)
 Create a CTA event cube from user parameters. More...
 
GCTAObservation create_cta_obs (void)
 Create a CTA observation from User parameters. More...
 
void require_inobs (const std::string &method)
 Throws exception if inobs parameter is not valid. More...
 
void require_inobs_nolist (const std::string &method)
 
void require_inobs_nocube (const std::string &method)
 Throws exception if inobs parameter is a counts cube. More...
 
GCTARoi get_roi (const GCTAPointing &pnt=GCTAPointing())
 Return RoI from User parameters. More...
 
GEbounds get_ebounds (void)
 Return energy boundaries from User parameters. More...
 
GGti get_gti (const GTimeReference &ref)
 Return Good Time Intervals from User parameter. More...
 
GCTAPointing get_pointing (void)
 Return CTA pointing from User parameters. More...
 
GSkyDir get_skydir (void)
 Return sky direction from User parameters. More...
 
std::string set_outfile_name (const std::string &filename)
 Set output file name. More...
 
bool is_stacked (void)
 Query user parameters for stacked analysis. More...
 
bool is_onoff (void)
 Query user parameters for On/Off analysis. More...
 
void log_parameters (const GChatter &chatter)
 Log application parameters. More...
 
void log_observations (const GChatter &chatter, const GObservations &obs, const std::string &what="Observation")
 Log observation container. More...
 
void log_models (const GChatter &chatter, const GModels &models, const std::string &what="Model")
 Log model container. More...
 
void set_response (GObservations &obs)
 Set response for all CTA observations in container. More...
 
std::vector< bool > set_edisp (GObservations &obs, const bool &edisp) const
 Set energy dispersion to CTA observations. More...
 
void restore_edisp (GObservations &obs, const std::vector< bool > &edisp) const
 Restore energy dispersion flags of CTA observations. More...
 
void set_obs_response (GCTAObservation *obs)
 Set response for CTA observation. More...
 
GObservations get_observations (const bool &get_response=true)
 Get observation container. More...
 
GSkyDir get_mean_pointing (const GObservations &obs)
 Derives mean pointing from CTA observations. More...
 
size_t get_current_rss (void)
 Get current resident set size (physical memory use) in Bytes. More...
 
std::string get_obs_header (const GObservation *obs) const
 Return observation header string. More...
 
GEnergies insert_energy_boundaries (const GEnergies &energies, const GCTAObservation &obs)
 Insert observation energy boundaries into list of energies. More...
 
std::vector< bool > cube_layer_usage (const GEbounds &cube_ebounds, const GEbounds &list_ebounds) const
 Determine the counts cube layer usage. More...
 
std::string get_gtiname (const std::string &filename, const std::string &evtname) const
 Get Good Time Intervals extension name. More...
 
void save_event_list (const GCTAObservation *obs, const std::string &infile, const std::string &evtname, const std::string &gtiname, const std::string &outfile) const
 Save event list into FITS file. More...
 
std::string warn_too_few_energies (const GEnergies &energies) const
 Set warning string if there are too few energies. More...
 
std::string warn_xml_suffix (const GFilename &filename) const
 Set warning string if file has no .xml suffix. More...
 
void provide_help (void) const
 Dump help text in the console. More...
 

Protected Attributes

GFilename m_outmodel
 Source model output XML file name. More...
 
GFilename m_outcovmat
 Covariance matrix output file name. More...
 
int m_max_iter
 Maximum number of iterations. More...
 
bool m_refit
 Refitting? More...
 
bool m_refit_if_failed
 Refitting in case of failure? More...
 
bool m_apply_edisp
 Apply energy dispersion? More...
 
bool m_fix_spat_for_ts
 Fix spatial parameters for TS computation? More...
 
GChatter m_chatter
 Chattiness. More...
 
int m_iter
 Number of iterations. More...
 
double m_logL
 Maximum log likelihood. More...
 
double m_nobs
 Number of observed events. More...
 
double m_npred
 Number of predicted events. More...
 
- Protected Attributes inherited from ctlikelihood
GOptimizerLM m_opt
 Optimizer. More...
 
- Protected Attributes inherited from ctobservation
GObservations m_obs
 Observation container. More...
 
- Protected Attributes inherited from ctool
bool m_read_ahead
 Read ahead output parameters. More...
 
bool m_use_xml
 Use XML file instead of FITS file for observations. More...
 

Detailed Description

Maximum likelihood fitting tool.

Definition at line 42 of file ctlike.hpp.

Constructor & Destructor Documentation

ctlike::ctlike ( void  )

Void constructor.

Definition at line 56 of file ctlike.cpp.

References init_members().

ctlike::ctlike ( const GObservations &  obs)
explicit

Observations constructor.

param[in] obs Observation container.

Constructs ctlike tool from an observations container.

Definition at line 73 of file ctlike.cpp.

References init_members().

ctlike::ctlike ( int  argc,
char *  argv[] 
)

Command line constructor.

Parameters
[in]argcNumber of arguments in command line.
[in]argvArray of command line arguments.

Constructs an instance of the ctlike tool that will parse user parameters that are provided as command line arguments.

Definition at line 93 of file ctlike.cpp.

References init_members().

ctlike::ctlike ( const ctlike app)

Copy constructor.

Parameters
[in]appApplication.

Definition at line 109 of file ctlike.cpp.

References copy_members(), and init_members().

ctlike::~ctlike ( void  )
virtual

Destructor.

Definition at line 125 of file ctlike.cpp.

References free_members().

Member Function Documentation

void ctlike::clear ( void  )
virtual
void ctlike::copy_members ( const ctlike app)
protected

Copy class members.

Parameters
[in]appApplication.

Definition at line 446 of file ctlike.cpp.

References m_apply_edisp, m_chatter, m_fix_spat_for_ts, m_iter, m_logL, m_max_iter, m_nobs, m_npred, m_outcovmat, m_outmodel, m_refit, and m_refit_if_failed.

Referenced by ctlike(), and operator=().

void ctlike::free_members ( void  )
protected

Delete class members.

Definition at line 470 of file ctlike.cpp.

Referenced by clear(), operator=(), and ~ctlike().

void ctlike::get_parameters ( void  )
protected
void ctlike::init_members ( void  )
protected

Initialise class members.

Definition at line 417 of file ctlike.cpp.

References m_apply_edisp, m_chatter, m_fix_spat_for_ts, m_iter, m_logL, m_max_iter, m_nobs, m_npred, m_outcovmat, m_outmodel, m_refit, and m_refit_if_failed.

Referenced by clear(), ctlike(), and operator=().

const int & ctlike::iter ( void  ) const
inline

Return number of maximum likelihood iterations.

Returns
Number of maximum likelihood iterations.

Definition at line 99 of file ctlike.hpp.

References m_iter.

Referenced by reoptimize_lm().

const double & ctlike::logL ( void  ) const
inline

Return maximum likelihood value.

Returns
Maximum likelihood value.

Definition at line 111 of file ctlike.hpp.

References m_logL.

Referenced by reoptimize_lm().

const double & ctlike::nobs ( void  ) const
inline

Return number of observed events.

Returns
Number of observed events.

Definition at line 123 of file ctlike.hpp.

References m_nobs.

const double & ctlike::npred ( void  ) const
inline

Return number of predicted events.

Returns
Number of predicted events.

Definition at line 135 of file ctlike.hpp.

References m_npred.

Referenced by refit().

ctlike & ctlike::operator= ( const ctlike app)

Assignment operator.

Parameters
[in]appApplication.
Returns
Application.

Definition at line 147 of file ctlike.cpp.

References copy_members(), free_members(), init_members(), and ctlikelihood::operator=().

void ctlike::optimize_lm ( void  )
protected

Optimise model parameters.

Optimise model parameters using a maximum likelihood fit.

Definition at line 550 of file ctlike.cpp.

References m_iter, m_logL, ctobservation::m_obs, ctlikelihood::m_opt, and refit().

Referenced by process().

void ctlike::process ( void  )
virtual

Process maximum likelihood analysis.

The following analysis steps are performed:

  1. Read the parameters (and write them into logger)
  2. Load observation
  3. Setup models for optimizing
  4. Optimize model (and write result into logger)

Implements ctlikelihood.

Definition at line 216 of file ctlike.cpp.

References get_parameters(), ctool::log_observations(), m_apply_edisp, m_chatter, m_fix_spat_for_ts, m_iter, m_logL, m_nobs, m_npred, ctobservation::m_obs, ctlikelihood::m_opt, optimize_lm(), reoptimize_lm(), ctool::restore_edisp(), and ctool::set_edisp().

bool ctlike::refit ( const GOptimizer *  opt)
protected

Refit needed?

Parameters
[in]optPointer to optimiser.
Returns
True if refit is needed, false otherwise.

This method returns true if either the "refit" parameter is set to yes or the "refit_if_failed" parameter is set to yes and the fit has failed. The fit is considered as failed if it either has stalled or the number of fit iterations is exhausted.

Definition at line 753 of file ctlike.cpp.

References m_max_iter, m_nobs, ctobservation::m_obs, m_refit, m_refit_if_failed, and npred().

Referenced by optimize_lm(), reoptimize_lm(), and xml_result().

double ctlike::reoptimize_lm ( void  )
protected

Re-optimise model parameters for TS computation.

Re-optimise the model parameters using a maximum likelihood fit for computation of the Test Statistic value for a given source.

Definition at line 625 of file ctlike.cpp.

References iter(), logL(), m_chatter, m_nobs, ctobservation::m_obs, ctlikelihood::m_opt, ctlikelihood::opt(), and refit().

Referenced by process().

void ctlike::save ( void  )
virtual

Save results.

This method saves the fit results and the covariance matrix. The fit results are written into a XML file while the covariance matrix is written into either a FITS or a CSV file, depending on the file type extension (an extension of .fits or .fit produce a FITS file, any other extension produces a CSV file).

If the filenames are NONE no information is saved.

Implements ctlikelihood.

Definition at line 357 of file ctlike.cpp.

References ctobservation::m_obs, m_outcovmat, m_outmodel, and xml_result().

GXml ctlike::xml_result ( void  ) const
protected

Generate XML result.

Returns
XML result

Generates the XML result composed of the ctlike results and the model fitting results.

Definition at line 681 of file ctlike.cpp.

References m_apply_edisp, m_fix_spat_for_ts, m_iter, m_logL, m_nobs, m_npred, ctobservation::m_obs, ctlikelihood::m_opt, m_refit, and refit().

Referenced by save().

Member Data Documentation

bool ctlike::m_apply_edisp
protected

Apply energy dispersion?

Definition at line 81 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), process(), and xml_result().

GChatter ctlike::m_chatter
protected

Chattiness.

Definition at line 83 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), process(), and reoptimize_lm().

bool ctlike::m_fix_spat_for_ts
protected

Fix spatial parameters for TS computation?

Definition at line 82 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), process(), and xml_result().

int ctlike::m_iter
protected

Number of iterations.

Definition at line 86 of file ctlike.hpp.

Referenced by copy_members(), init_members(), iter(), optimize_lm(), process(), and xml_result().

double ctlike::m_logL
protected

Maximum log likelihood.

Definition at line 87 of file ctlike.hpp.

Referenced by copy_members(), init_members(), logL(), optimize_lm(), process(), and xml_result().

int ctlike::m_max_iter
protected

Maximum number of iterations.

Definition at line 78 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), and refit().

double ctlike::m_nobs
protected

Number of observed events.

Definition at line 88 of file ctlike.hpp.

Referenced by copy_members(), init_members(), nobs(), process(), refit(), reoptimize_lm(), and xml_result().

double ctlike::m_npred
protected

Number of predicted events.

Definition at line 89 of file ctlike.hpp.

Referenced by copy_members(), init_members(), npred(), process(), and xml_result().

GFilename ctlike::m_outcovmat
protected

Covariance matrix output file name.

Definition at line 77 of file ctlike.hpp.

Referenced by copy_members(), init_members(), and save().

GFilename ctlike::m_outmodel
protected

Source model output XML file name.

Definition at line 76 of file ctlike.hpp.

Referenced by copy_members(), init_members(), and save().

bool ctlike::m_refit
protected

Refitting?

Definition at line 79 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), refit(), and xml_result().

bool ctlike::m_refit_if_failed
protected

Refitting in case of failure?

Definition at line 80 of file ctlike.hpp.

Referenced by copy_members(), get_parameters(), init_members(), and refit().


The documentation for this class was generated from the following files: