GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModel Class Referenceabstract

Abstract model class. More...

#include <GModel.hpp>

Inheritance diagram for GModel:
GBase GModelData GModelSky GCOMModelDRBFitting GCTAModelAeffBackground GCTAModelBackground GCTAModelCubeBackground GCTAModelIrfBackground GCTAModelRadialAcceptance

Public Member Functions

 GModel (void)
 Void constructor. More...
 
 GModel (const GXmlElement &xml)
 XML constructor. More...
 
 GModel (const GModel &model)
 Copy constructor. More...
 
virtual ~GModel (void)
 Destructor. More...
 
virtual GModeloperator= (const GModel &model)
 Assignment operator. More...
 
virtual GModelParoperator[] (const int &index)
 Returns reference to model parameter by index. More...
 
virtual const GModelParoperator[] (const int &index) const
 Returns reference to model parameter by index (const version) More...
 
virtual GModelParoperator[] (const std::string &name)
 Returns reference to model parameter by name. More...
 
virtual const GModelParoperator[] (const std::string &name) const
 Returns reference to model parameter by name const version) More...
 
virtual void clear (void)=0
 Clear object. More...
 
virtual GModelclone (void) const =0
 Clones object. More...
 
virtual std::string classname (void) const =0
 Return class name. More...
 
virtual std::string type (void) const =0
 
virtual bool is_constant (void) const =0
 
virtual double eval (const GEvent &event, const GObservation &obs, const bool &gradients=false) const =0
 
virtual double npred (const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const =0
 
virtual void read (const GXmlElement &xml)=0
 
virtual void write (GXmlElement &xml) const =0
 
virtual std::string print (const GChatter &chatter=NORMAL) const =0
 Print content of object. More...
 
int size (void) const
 Return number of parameters in model. More...
 
int scales (void) const
 Return number of scale parameters in model. More...
 
GModelParat (const int &index)
 Returns reference to model parameter by index. More...
 
const GModelParat (const int &index) const
 Returns reference to model parameter by index (const version) More...
 
bool has_par (const std::string &name) const
 Checks if parameter name exists. More...
 
bool has_scales (void) const
 Signals that model has scales. More...
 
const std::string & name (void) const
 Return parameter name. More...
 
void name (const std::string &name)
 Set parameter name. More...
 
const double & ts (void) const
 Return Test Statistic value. More...
 
void ts (const double &ts)
 Set Test Statistic value. More...
 
const bool & tscalc (void) const
 Return Test Statistic computation flag. More...
 
void tscalc (const bool &tscalc)
 Set Test Statistic computation flag. More...
 
const bool & has_ts (void) const
 Signals that model has Test Statistics value. More...
 
std::string instruments (void) const
 Returns instruments to which model applies. More...
 
void instruments (const std::string &instruments)
 Set instruments to which model applies. More...
 
GModelParscale (const int &index)
 Returns reference to scale parameter by index. More...
 
const GModelParscale (const int &index) const
 Returns reference to scale parameter by index (const version) More...
 
GModelPar scale (const std::string &instrument) const
 Returns model scale factor for a given instrument. More...
 
void scale (const GModelPar &par)
 Set model scale factor for a given instrument. More...
 
std::string ids (void) const
 Returns observation identifiers to which model applies. More...
 
void ids (const std::string &ids)
 Set observation identifiers to which model applies. More...
 
bool is_valid (const std::string &instruments, const std::string &ids) const
 Verifies if model is valid for a given instrument and identifier. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModel &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void read_attributes (const GXmlElement &xml)
 Read model attributes. More...
 
void write_attributes (GXmlElement &xml) const
 Write model attributes. More...
 
std::string print_attributes (void) const
 Print model attributes. More...
 
void read_scales (const GXmlElement &xml)
 Read instrument scales from XML element. More...
 
void write_scales (GXmlElement &xml) const
 Write instrument scales into XML element. More...
 

Protected Attributes

std::string m_name
 Model name. More...
 
std::vector< std::string > m_instruments
 Instruments to which model applies. More...
 
std::vector< GModelParm_scales
 Model instrument scale factors. More...
 
std::vector< std::string > m_ids
 Identifiers to which model applies. More...
 
std::vector< GModelPar * > m_pars
 Pointers to all model parameters. More...
 
bool m_has_ts
 Signals if TS is available. More...
 
bool m_has_tscalc
 Signals if tscalc attribute is available. More...
 
bool m_tscalc
 Signals if TS should be computed. More...
 
double m_ts
 Test Statistic of the model. More...
 

Detailed Description

Abstract model class.

This class implements a parametric model. The eval() method evaluates the model for a given event and observation. If the gradients parameter is set to true, the eval() method also computes analytical parameter gradients if they exist.

A model has the following attributes:

  • name
  • type
  • instruments
  • ids
  • scales

The model name is a text string that names the model. The name() methods allow setting and retrieving the model name. The model handling does not actual depend on the value of this text string.

The model type is a text string that specifies the kind of the model. Examples are PointSource, ExtendedSource or DiffuseSource for sky models. The type() method allows retrieving the model type. The model handling does not actual depend on the value of this text string.

The model instruments is a list of text strings that specifies the instruments to which the model applies. The is_valid() method will check a given instrument name against that list to verify if the model applies to an instrument. The instruments() method returns a comma separated list of all instruments. Another instance of this method allows setting the instrument list from a comma separated list. If the instruments list is empty, the model applies to all instruments.

The model ids is a list of text strings that specifies the observation identifiers to which the model applies. This allows specifying of models for a specific list of observations. The is_valid() method will check a given observation identifier against that list to verify if the model applies. The ids() method returns a comma separated list of all observation identifiers. Another instance of this method allows setting the observation identifiers from a comma separated list. If the ids list is empty, the model applies to all observation identifiers.

The model scales is a list of model parameters that specify an instrument dependent scaling factor. This allows to prescale a model for a given instrument. The scale() methods allow to set and to retrieve the scale factor for a specific instrument.

As the class holds simply a collection of model parameters, it should neither deal with allocation and deallocation, nor with cloning of model parameters. This will be done by the classes that actually implement the model parameters.

Definition at line 97 of file GModel.hpp.

Constructor & Destructor Documentation

GModel::GModel ( void  )

Void constructor.

Definition at line 57 of file GModel.cpp.

References init_members().

GModel::GModel ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Construct model from XML element. The method extracts all model attributes from the XML file (see the read_attributes() method for more information about the supported attributes).

Definition at line 76 of file GModel.cpp.

References init_members(), and read_attributes().

GModel::GModel ( const GModel model)

Copy constructor.

Parameters
[in]modelModel.

Definition at line 94 of file GModel.cpp.

References copy_members(), and init_members().

GModel::~GModel ( void  )
virtual

Destructor.

Definition at line 110 of file GModel.cpp.

References free_members().

Member Function Documentation

GModelPar & GModel::at ( const int &  index)

Returns reference to model parameter by index.

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Reference to model parameter.
Exceptions
GException::out_of_rangeParameter index is out of range.

Returns a reference to the model parameter of the specified index. Throws an exception if index is not valid.

Definition at line 235 of file GModel.cpp.

References G_AT, m_pars, and size().

const GModelPar & GModel::at ( const int &  index) const

Returns reference to model parameter by index (const version)

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Const reference to model parameter.
Exceptions
GException::out_of_rangeParameter index is out of range.

Returns a const reference to the model parameter of the specified index. Throws an exception if index is not valid.

Definition at line 259 of file GModel.cpp.

References G_AT, m_pars, and size().

virtual std::string GModel::classname ( void  ) const
pure virtual

Return class name.

Returns
String containing the class name.

Returns the class name for non-abstract classes in a human readable way.

Implements GBase.

Implemented in GModelSky, GCTAModelBackground, GCTAModelRadialAcceptance, GCTAModelCubeBackground, GModelData, GCOMModelDRBFitting, GCTAModelAeffBackground, and GCTAModelIrfBackground.

virtual void GModel::clear ( void  )
pure virtual

Clear object.

Sets the object to a clean initial state. After calling the method the object will be in the same state as it were if an empty instance of the object would have been created.

Implements GBase.

Implemented in GModelSky, GCTAModelBackground, GCTAModelRadialAcceptance, GCTAModelCubeBackground, GModelData, GCOMModelDRBFitting, GCTAModelAeffBackground, and GCTAModelIrfBackground.

virtual GModel* GModel::clone ( void  ) const
pure virtual

Clones object.

Returns
Pointer to deep copy of object.

Creates a deep copy of the object and returns a pointer to the object.

Implements GBase.

Implemented in GModelSky, GCTAModelBackground, GCTAModelRadialAcceptance, GCTAModelCubeBackground, GModelData, GCOMModelDRBFitting, GCTAModelAeffBackground, and GCTAModelIrfBackground.

Referenced by GModels::append(), GModels::insert(), and GModels::set().

void GModel::copy_members ( const GModel model)
protected

Copy class members.

Parameters
[in]modelModel.

Definition at line 635 of file GModel.cpp.

References m_has_ts, m_has_tscalc, m_ids, m_instruments, m_name, m_pars, m_scales, m_ts, and m_tscalc.

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

virtual double GModel::eval ( const GEvent event,
const GObservation obs,
const bool &  gradients = false 
) const
pure virtual
void GModel::free_members ( void  )
protected
bool GModel::has_par ( const std::string &  name) const

Checks if parameter name exists.

Parameters
[in]nameParameter name.
Returns
True if parameter with specified name exists.

Searches all parameter names for a match with the specified name. If the specified name has been found, true is returned.

Definition at line 280 of file GModel.cpp.

References m_pars, name(), and size().

bool GModel::has_scales ( void  ) const
inline

Signals that model has scales.

Returns
True if model has scale factors.

Definition at line 338 of file GModel.hpp.

References m_scales.

Referenced by GResponse::eval_prob(), GCTAOnOffObservation::N_gamma(), and GCTAResponseIrf::nroi().

const bool & GModel::has_ts ( void  ) const
inline

Signals that model has Test Statistics value.

Returns
True if model has TS value.

Definition at line 350 of file GModel.hpp.

References m_has_ts.

std::string GModel::ids ( void  ) const

Returns observation identifiers to which model applies.

Returns a comma separated list of observation identifiers to which model applies. If no observation identifier exists then an empty string is returned.

Definition at line 492 of file GModel.cpp.

References m_ids.

Referenced by read_attributes(), and write_attributes().

void GModel::ids ( const std::string &  ids)

Set observation identifiers to which model applies.

Parameters
[in]idsString of observation identifiers.

Sets the observation identifiers to which the model applies from a comma separated list of strings. The observation identifiers are case sensitive, but any leading and trailing whitespace will be stripped.

If the observation identifier string is empty, the model is considered to apply to all observation identifiers.

Definition at line 522 of file GModel.cpp.

References m_ids, gammalib::split(), and gammalib::strip_whitespace().

void GModel::init_members ( void  )
protected
std::string GModel::instruments ( void  ) const

Returns instruments to which model applies.

Returns a comma separated list of instruments to which model applies. If no instrument exists then an empty string is returned.

Definition at line 304 of file GModel.cpp.

References m_instruments.

Referenced by read_attributes(), GCOMModelDRBFitting::write(), and write_attributes().

void GModel::instruments ( const std::string &  instruments)

Set instruments to which model applies.

Parameters
[in]instrumentsString of instruments.

Sets the instruments to which the model applies from a comma separated list of strings. The instrument names are case sensitive.

If the instrument string is empty, the model is considered to apply to all instruments.

Definition at line 333 of file GModel.cpp.

References m_instruments, gammalib::split(), and gammalib::strip_whitespace().

virtual bool GModel::is_constant ( void  ) const
pure virtual
bool GModel::is_valid ( const std::string &  instrument,
const std::string &  id 
) const

Verifies if model is valid for a given instrument and identifier.

Parameters
[in]instrumentInstrument name.
[in]idObservation identifier.
Returns
Validity flag

Checks if specified instrument name and observation identifier is in list of applicable instruments and identifiers. The check is case sensitive.

If the list of applicable instruments is empty, the model applies to all possible instruments. If the list of applicable observation identifiers is empty, the model applies to all identifiers.

If an empty string is provided as instrument parameter, the check for instrument validity will be skipped. Similarily, if an empty string is provided as id parameter, the identifier check will be skipped. This allows for example to check for models of a given identifier whatever the instrument, or for models for a given instrument, whatever the identifier.

Definition at line 560 of file GModel.cpp.

References m_ids, and m_instruments.

Referenced by GObservation::model(), GCTAOnOffObservation::N_bgd(), GCTAOnOffObservation::N_gamma(), GObservation::npred(), and GObservations::npred().

void GModel::name ( const std::string &  name)
inline

Set parameter name.

Parameters
[in]nameParameter name.

Set the parameter name.

Definition at line 259 of file GModel.hpp.

References m_name, and name().

virtual double GModel::npred ( const GEnergy obsEng,
const GTime obsTime,
const GObservation obs 
) const
pure virtual
GModel & GModel::operator= ( const GModel model)
virtual

Assignment operator.

Parameters
[in]modelModel.
Returns
Model.

Definition at line 132 of file GModel.cpp.

References copy_members(), free_members(), and init_members().

Referenced by GModelData::operator=(), and GModelSky::operator=().

GModelPar & GModel::operator[] ( const int &  index)
inlinevirtual

Returns reference to model parameter by index.

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Reference to model parameter.

Returns a reference to the model parameter of the specified index.

Definition at line 186 of file GModel.hpp.

References m_pars.

const GModelPar & GModel::operator[] ( const int &  index) const
inlinevirtual

Returns reference to model parameter by index (const version)

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Const reference to model parameter.

Returns a const reference to the model parameter of the specified

Definition at line 202 of file GModel.hpp.

References m_pars.

GModelPar & GModel::operator[] ( const std::string &  name)
virtual

Returns reference to model parameter by name.

Parameters
[in]nameParameter name.
Returns
Reference to model parameter.
Exceptions
GException::par_not_foundParameter with specified name not found in container.

Returns a reference to the model parameter of the specified name. Throws an exception if no parameter with name is found.

Definition at line 165 of file GModel.cpp.

References G_ACCESS, m_pars, name(), and size().

const GModelPar & GModel::operator[] ( const std::string &  name) const
virtual

Returns reference to model parameter by name const version)

Parameters
[in]nameParameter name.
Returns
Reference to model parameter.
Exceptions
GException::par_not_foundParameter with specified name not found in container.

Returns a const reference to the model parameter of the specified name. Throws an exception if no parameter with name is found.

Definition at line 197 of file GModel.cpp.

References G_ACCESS, m_pars, name(), and size().

virtual std::string GModel::print ( const GChatter chatter = NORMAL) const
pure virtual

Print content of object.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing the content of the object.

Formats the content in a standard way and puts this content in a C++ string that is returned.

Implements GBase.

Implemented in GModelSky, GCTAModelBackground, GCTAModelRadialAcceptance, GCTAModelCubeBackground, GModelData, GCOMModelDRBFitting, GCTAModelAeffBackground, and GCTAModelIrfBackground.

std::string GModel::print_attributes ( void  ) const
protected
void GModel::read_scales ( const GXmlElement xml)
protected

Read instrument scales from XML element.

Parameters
[in]xmlXML source element.

Reads the instrument scale factors from a tag with the following format

 <scaling>
    <instrument name="LAT" scale="1.0" min="0.1" max="10.0" value="1.0" free="0"/>
    <instrument name="CTA" scale="1.0" min="0.1" max="10.0" value="0.5" free="0"/>
 </scaling>

The instrument name is case sensitive, but any leading and trailing white space will be removed.

If no scaling tag is found, all instrument scale factors will be cleared.

Definition at line 816 of file GModel.cpp.

References GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GOptimizerPar::has_grad(), m_pars, m_scales, GOptimizerPar::name(), GModelPar::read(), scale(), scales(), and gammalib::strip_whitespace().

Referenced by read_attributes().

GModelPar & GModel::scale ( const int &  index)

Returns reference to scale parameter by index.

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Reference to scale parameter.
Exceptions
GException::out_of_rangeScale parameter index is out of range.

Returns a reference to the scale parameter of the specified index. Throws an exception if index is not valid.

Definition at line 363 of file GModel.cpp.

References G_SCALE, m_scales, and scales().

Referenced by GCOMModelDRBFitting::eval(), GResponse::eval_prob(), GCTAOnOffObservation::N_gamma(), GCTAResponseIrf::nroi(), GModelSky::print(), read_scales(), scale(), and write_scales().

const GModelPar & GModel::scale ( const int &  index) const

Returns reference to scale parameter by index (const version)

Parameters
[in]indexParameter index [0,...,size()-1].
Returns
Reference to scale parameter.
Exceptions
GException::out_of_rangeScale parameter index is out of range.

Returns a reference to the scale parameter of the specified index. Throws an exception if index is not valid.

Definition at line 387 of file GModel.cpp.

References G_SCALE, m_scales, and scales().

GModelPar GModel::scale ( const std::string &  instrument) const

Returns model scale factor for a given instrument.

Parameters
[in]instrumentInstrument.

Returns the model scale factor for a given instrument. The search is case sensitive.

If the instrument is not found, the method returns a scale factor of unity.

Definition at line 410 of file GModel.cpp.

References GOptimizerPar::fix(), m_scales, name(), GOptimizerPar::name(), scale(), and GOptimizerPar::value().

void GModel::scale ( const GModelPar par)

Set model scale factor for a given instrument.

Parameters
[in]parModel parameter for scaling.

Sets the model parameter for a given instrument. The instrument name is case sensitive, but any leading to trailing white space will be stripped.

If the instrument is not yet defined it will be appended to the list of instruments.

Definition at line 443 of file GModel.cpp.

References m_pars, m_scales, name(), GOptimizerPar::name(), and gammalib::strip_whitespace().

int GModel::scales ( void  ) const
inline

Return number of scale parameters in model.

Returns
Number of scale parameters in model.

Returns the number of scale parameters in the model.

Definition at line 231 of file GModel.hpp.

References m_scales.

Referenced by GResponse::eval_prob(), GModelSky::print(), read_scales(), and scale().

const double & GModel::ts ( void  ) const
inline

Return Test Statistic value.

Returns
Test Statistic value.

Returns the Test Statistic value. The Test Statistic value is twice the difference between the log-likelihood of the null hypothesis and the alternative hypothesis.

Definition at line 275 of file GModel.hpp.

References m_ts.

Referenced by print_attributes(), read_attributes(), ts(), and write_attributes().

void GModel::ts ( const double &  ts)
inline

Set Test Statistic value.

Parameters
[in]tsTest Statistic value.

Set the Test Statistic value. The Test Statistic value is twice the difference between the log-likelihood of the null hypothesis and the alternative hypothesis.

< Signals that TS is now available

Definition at line 291 of file GModel.hpp.

References m_has_ts, m_ts, and ts().

const bool & GModel::tscalc ( void  ) const
inline

Return Test Statistic computation flag.

Returns
Test Statistic computation flag; true is Test Statistic should be computed.

Returns the flag that signals whether Test Statistic values should be computed.

Definition at line 309 of file GModel.hpp.

References m_tscalc.

Referenced by read_attributes(), tscalc(), and write_attributes().

void GModel::tscalc ( const bool &  tscalc)
inline

Set Test Statistic computation flag.

Parameters
[in]tscalcTest Statistic computation flag.

Set the flag that signals whether Test Statistic values should be computed.

< Signals that tscalc is now available

Definition at line 324 of file GModel.hpp.

References m_has_tscalc, m_tscalc, and tscalc().

void GModel::write_scales ( GXmlElement xml) const
protected

Write instrument scales into XML element.

Parameters
[in]xmlXML source element.
Exceptions
GException::model_invalid_parnumInvalid number of instrument tags found in XML element.

If there are instrument scale factors then add a tag with the following format to the XML element:

 <scaling>
    <instrument name="LAT" scale="1" min="0.1" max="10" value="1.0" free="0"/>
    <instrument name="CTA" scale="1" min="0.1" max="10" value="0.5" free="0"/>
 </scaling>

Definition at line 864 of file GModel.cpp.

References GXmlNode::append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_WRITE_SCALES, m_scales, name(), scale(), and gammalib::str().

Referenced by write_attributes().

Member Data Documentation

bool GModel::m_has_ts
protected

Signals if TS is available.

Definition at line 170 of file GModel.hpp.

Referenced by copy_members(), has_ts(), init_members(), print_attributes(), ts(), and write_attributes().

bool GModel::m_has_tscalc
protected

Signals if tscalc attribute is available.

Definition at line 171 of file GModel.hpp.

Referenced by copy_members(), init_members(), tscalc(), and write_attributes().

std::vector<std::string> GModel::m_ids
protected

Identifiers to which model applies.

Definition at line 168 of file GModel.hpp.

Referenced by copy_members(), ids(), init_members(), is_valid(), and print_attributes().

std::vector<std::string> GModel::m_instruments
protected

Instruments to which model applies.

Definition at line 166 of file GModel.hpp.

Referenced by copy_members(), init_members(), instruments(), is_valid(), and print_attributes().

std::string GModel::m_name
protected

Model name.

Definition at line 165 of file GModel.hpp.

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

std::vector<GModelPar> GModel::m_scales
protected

Model instrument scale factors.

Definition at line 167 of file GModel.hpp.

Referenced by copy_members(), has_scales(), init_members(), read_scales(), scale(), scales(), GModelSky::set_pointers(), and write_scales().

double GModel::m_ts
protected

Test Statistic of the model.

Definition at line 173 of file GModel.hpp.

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

bool GModel::m_tscalc
protected

Signals if TS should be computed.

Definition at line 172 of file GModel.hpp.

Referenced by copy_members(), init_members(), print_attributes(), and tscalc().


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