GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCOMModelDRBPhibarNodes Class Reference

COMPTEL DRB Phibar nodes model fitting class. More...

#include <GCOMModelDRBPhibarNodes.hpp>

Inheritance diagram for GCOMModelDRBPhibarNodes:
GModelData GModel GBase

Public Member Functions

 GCOMModelDRBPhibarNodes (void)
 Void constructor. More...
 
 GCOMModelDRBPhibarNodes (const GXmlElement &xml)
 XML constructor. More...
 
 GCOMModelDRBPhibarNodes (const GCOMModelDRBPhibarNodes &model)
 Copy constructor. More...
 
virtual ~GCOMModelDRBPhibarNodes (void)
 Destructor. More...
 
virtual GCOMModelDRBPhibarNodesoperator= (const GCOMModelDRBPhibarNodes &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear instance. More...
 
virtual GCOMModelDRBPhibarNodesclone (void) const
 Clone instance. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual std::string type (void) const
 Return model type. More...
 
virtual bool is_constant (void) const
 Signals if model is temporally constant. More...
 
virtual double eval (const GEvent &event, const GObservation &obs, const bool &gradients=false) const
 Evaluate function. More...
 
virtual double npred (const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
 Return spatially integrated data model. More...
 
virtual GCOMEventCubemc (const GObservation &obs, GRan &ran) const
 Return simulated list of events. More...
 
virtual void read (const GXmlElement &xml)
 Read model from XML element. More...
 
virtual void write (GXmlElement &xml) const
 Write model into XML element. More...
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print model information. More...
 
- Public Member Functions inherited from GModelData
 GModelData (void)
 Void constructor. More...
 
 GModelData (const GXmlElement &xml)
 XML constructor. More...
 
 GModelData (const GModelData &model)
 Copy constructor. More...
 
virtual ~GModelData (void)
 Destructor. More...
 
virtual GModelDataoperator= (const GModelData &model)
 Assignment operator. More...
 
virtual GVector eval (const GObservation &obs, GMatrixSparse *gradients=NULL) const
 Return model values and gradients. More...
 
- Public Member Functions inherited from GModel
 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...
 
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...
 
const GModelAssociationsassociations (void) const
 Return model associations. More...
 
void associations (const GModelAssociations &associations)
 Set model associations. More...
 
const bool & has_eval_indices (void) const
 Signals that parameter indices updated by eval() method were set. More...
 
const std::vector< int > & eval_indices (void) const
 Return vector of parameter indices updated by eval() method. 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 GCOMModelDRBPhibarNodes &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void set_pointers (void)
 Set pointers. More...
 
void set_cache (void) const
 Set evaluation cache. More...
 
void update_cache (void) const
 Update evaluation cache. More...
 
- Protected Member Functions inherited from GModelData
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelData &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
- Protected Member Functions inherited from GModel
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::vector< GModelParm_phibars
 Node Phibar values. More...
 
std::vector< GModelParm_values
 Node values. More...
 
bool m_scale
 Model is a scale factor. More...
 
bool m_fixed
 All Phibar values are fixed. More...
 
std::vector< double > m_old_phibars
 Old Phibar values. More...
 
GNodeArray m_nodes
 Phibar node values. More...
 
- Protected Attributes inherited from GModel
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...
 
GModelAssociations m_associations
 Model associations. 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...
 
bool m_has_eval_inx
 
std::vector< int > m_eval_inx
 

Detailed Description

COMPTEL DRB Phibar nodes model fitting class.

This class implements a COMPTEL background model that is based on fitting of a DRB model. The model parameters are a set of normalization parameters defined for a given Phibar value, and linear interpolations are performed between these values.

Definition at line 51 of file GCOMModelDRBPhibarNodes.hpp.

Constructor & Destructor Documentation

GCOMModelDRBPhibarNodes::GCOMModelDRBPhibarNodes ( void  )

Void constructor.

Constructs an empty COMPTEL DRB fitting model.

Definition at line 71 of file GCOMModelDRBPhibarNodes.cpp.

References init_members().

Referenced by clone().

GCOMModelDRBPhibarNodes::GCOMModelDRBPhibarNodes ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Constructs a COMPTEL DRB fitting model from the information that is found in an XML element. Please refer to the method GCOMModelDRBPhibarNodes::read to learn more about the information that is expected in the XML element.

Definition at line 90 of file GCOMModelDRBPhibarNodes.cpp.

References init_members(), and read().

GCOMModelDRBPhibarNodes::GCOMModelDRBPhibarNodes ( const GCOMModelDRBPhibarNodes model)

Copy constructor.

Parameters
[in]modelCOMPTEL DRB fitting model.

Constructs a COMPTEL DRB fitting model by copying information from an existing model. Note that the copy is a deep copy, so the original object can be destroyed after the copy without any loss of information.

Definition at line 113 of file GCOMModelDRBPhibarNodes.cpp.

References copy_members(), and init_members().

GCOMModelDRBPhibarNodes::~GCOMModelDRBPhibarNodes ( void  )
virtual

Destructor.

Destroys a COMPTEL DRB fitting model.

Definition at line 132 of file GCOMModelDRBPhibarNodes.cpp.

References free_members().

Member Function Documentation

std::string GCOMModelDRBPhibarNodes::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GCOMModelDRBPhibarNodes").

Implements GModelData.

Definition at line 106 of file GCOMModelDRBPhibarNodes.hpp.

void GCOMModelDRBPhibarNodes::clear ( void  )
virtual

Clear instance.

Resets the object to a clean initial state. All information that resided in the object will be lost.

Implements GModelData.

Definition at line 195 of file GCOMModelDRBPhibarNodes.cpp.

References free_members(), GModelData::free_members(), GModel::free_members(), init_members(), GModelData::init_members(), and GModel::init_members().

GCOMModelDRBPhibarNodes * GCOMModelDRBPhibarNodes::clone ( void  ) const
virtual

Clone instance.

Returns
Pointer to deep copy of COMPTEL DRB fitting model.

Clone a COMPTEL DRB fitting model. Cloning performs a deep copy of the information, so the original object can be destroyed after cloning without any loss of information.

Implements GModelData.

Definition at line 221 of file GCOMModelDRBPhibarNodes.cpp.

References GCOMModelDRBPhibarNodes().

void GCOMModelDRBPhibarNodes::copy_members ( const GCOMModelDRBPhibarNodes model)
protected

Copy class members.

Parameters
[in]modelModel.

Definition at line 705 of file GCOMModelDRBPhibarNodes.cpp.

References m_fixed, m_nodes, m_old_phibars, m_phibars, m_scale, m_values, and set_pointers().

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

double GCOMModelDRBPhibarNodes::eval ( const GEvent event,
const GObservation obs,
const bool &  gradients = false 
) const
virtual

Evaluate function.

Parameters
[in]eventObserved event.
[in]obsObservation.
[in]gradientsCompute gradients?
Returns
Background model value.
Exceptions
GException::invalid_argumentObservation is not a COMPTEL observation. Event is not a COMPTEL event bin.

Evaluates the COMPTEL DRB fitting model.

Implements GModelData.

Definition at line 241 of file GCOMModelDRBPhibarNodes.cpp.

References GCOMEventBin::dir(), GCOMObservation::drb(), G_EVAL, GCOMEventBin::index(), GNodeArray::inx_left(), GNodeArray::inx_right(), gammalib::is_infinite(), gammalib::is_notanumber(), m_nodes, m_scale, m_values, GCOMDri::map(), GModel::name(), GCOMInstDir::phibar(), GSkyMap::pixels(), GModel::scale(), GNodeArray::set_value(), GCOMEventBin::size(), GModel::size(), update_cache(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().

void GCOMModelDRBPhibarNodes::free_members ( void  )
protected

Delete class members.

Definition at line 728 of file GCOMModelDRBPhibarNodes.cpp.

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

void GCOMModelDRBPhibarNodes::init_members ( void  )
protected

Initialise class members.

Definition at line 683 of file GCOMModelDRBPhibarNodes.cpp.

References GNodeArray::clear(), m_fixed, m_nodes, m_old_phibars, m_phibars, m_scale, and m_values.

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

bool GCOMModelDRBPhibarNodes::is_constant ( void  ) const
inlinevirtual

Signals if model is temporally constant.

Returns
True if model is temporally constant, false otherwise.

Signals if the model is temporally constant. By definition, a DRB fitting model is always temporally constant.

Implements GModelData.

Definition at line 136 of file GCOMModelDRBPhibarNodes.hpp.

GCOMEventCube * GCOMModelDRBPhibarNodes::mc ( const GObservation obs,
GRan ran 
) const
virtual

Return simulated list of events.

Parameters
[in]obsObservation.
[in]ranRandom number generator.
Returns
COMPTEL event cube.
Exceptions
GException::feature_not_implementedMethod is not implemented.

Draws a sample of events from the COMPTEL DRB fitting model using a Monte Carlo simulation.

Todo:
Implement method.

Implements GModelData.

Definition at line 420 of file GCOMModelDRBPhibarNodes.cpp.

References G_MC.

double GCOMModelDRBPhibarNodes::npred ( const GEnergy obsEng,
const GTime obsTime,
const GObservation obs 
) const
virtual

Return spatially integrated data model.

Parameters
[in]obsEngMeasured event energy.
[in]obsTimeMeasured event time.
[in]obsObservation.
Returns
Spatially integrated data model.
Exceptions
GException::feature_not_implementedMethod is not implemented.

Spatially integrates the data model for a given measured event energy and event time.

Todo:
Implement method.

Implements GModelData.

Definition at line 389 of file GCOMModelDRBPhibarNodes.cpp.

References G_NRED.

GCOMModelDRBPhibarNodes & GCOMModelDRBPhibarNodes::operator= ( const GCOMModelDRBPhibarNodes model)
virtual

Assignment operator.

Parameters
[in]modelCOMPTEL DRB fitting model.
Returns
COMPTEL DRB fitting model

Assigns the information from a COMPTEL DRB fitting model to the actual object. Note that a deep copy of the information is performed, so the original object can be destroyed after the assignment without any loss of information.

Definition at line 159 of file GCOMModelDRBPhibarNodes.cpp.

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

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

Print model information.

Parameters
[in]chatterChattiness.
Returns
String containing model information.

Implements GModelData.

Definition at line 644 of file GCOMModelDRBPhibarNodes.cpp.

References GModel::m_pars, m_phibars, gammalib::parformat(), GModel::print_attributes(), SILENT, GModel::size(), and gammalib::str().

void GCOMModelDRBPhibarNodes::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.
Exceptions
GException::invalid_valueModel definition requires at least one node.

Read the COMPTEL DRB fitting model from an XML element.

The model is composed of nodes that define the normalization value as function of Phibar value. The following XML file syntax is expected:

<source name="Background" type="DRBPhibarNodes" instrument="COM">
  <node>
    <parameter name="Phibar"        .../>
    <parameter name="Normalization" .../>
  </node>
  ...
  <node>
    <parameter name="Phibar"        .../>
    <parameter name="Normalization" .../>
  </node>
</source>

Implements GModelData.

Definition at line 460 of file GCOMModelDRBPhibarNodes.cpp.

References GXmlNode::element(), GXmlNode::elements(), G_READ, GOptimizerPar::has_grad(), m_phibars, m_values, GOptimizerPar::name(), GModelPar::read(), GModel::read_attributes(), set_cache(), set_pointers(), gammalib::str(), GOptimizerPar::unit(), and gammalib::xml_get_par().

Referenced by GCOMModelDRBPhibarNodes().

void GCOMModelDRBPhibarNodes::set_cache ( void  ) const
protected

Set evaluation cache.

Set the evaluation cache for fast computations. The evaluation cache consists of the Phibar values stored in a node array. The evaluation cache is only filled if at least 2 nodes are available. If only a single node is available, the model is considered as a simple scaling factor.

Definition at line 777 of file GCOMModelDRBPhibarNodes.cpp.

References GNodeArray::append(), GNodeArray::clear(), m_fixed, m_nodes, m_old_phibars, m_phibars, and m_scale.

Referenced by read().

void GCOMModelDRBPhibarNodes::set_pointers ( void  )
protected

Set pointers.

Set pointers to all model parameters. The pointers are stored in a vector that is member of the GModel base class.

Definition at line 741 of file GCOMModelDRBPhibarNodes.cpp.

References GModel::m_pars, m_phibars, and m_values.

Referenced by copy_members(), and read().

std::string GCOMModelDRBPhibarNodes::type ( void  ) const
inlinevirtual

Return model type.

Returns
Model type.

Returns the type of the model. The type for a DRB fitting model is "DRBPhibarNodes".

Implements GModelData.

Definition at line 121 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by write().

void GCOMModelDRBPhibarNodes::update_cache ( void  ) const
protected

Update evaluation cache.

Updates the evaluation cache by computing the changed.

Definition at line 817 of file GCOMModelDRBPhibarNodes.cpp.

References m_nodes, m_old_phibars, and m_phibars.

Referenced by eval().

void GCOMModelDRBPhibarNodes::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element.
Exceptions
GException::model_invalid_spectralExisting XML element is not of required type
GException::model_invalid_parnumInvalid number of model parameters or nodes found in XML element.
GException::model_invalid_parnamesInvalid model parameter names found in XML element.

Write the COMPTEL DRB fitting model into an XML element.

The model is composed of nodes that define the normalization value as function of Phibar value. The following XML file syntax is expected:

<source name="Background" type="DRBPhibarNodes" instrument="COM">
  <node>
    <parameter name="Phibar"        .../>
    <parameter name="Normalization" .../>
  </node>
  ...
  <node>
    <parameter name="Phibar"        .../>
    <parameter name="Normalization" .../>
  </node>
</source>

Implements GModelData.

Definition at line 557 of file GCOMModelDRBPhibarNodes.cpp.

References GXmlNode::append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), G_WRITE, GModel::instruments(), m_phibars, m_values, GModel::name(), GOptimizerPar::name(), gammalib::str(), type(), GModelPar::write(), GModel::write_attributes(), and gammalib::xml_need_par().

Member Data Documentation

bool GCOMModelDRBPhibarNodes::m_fixed
mutableprotected

All Phibar values are fixed.

Definition at line 94 of file GCOMModelDRBPhibarNodes.hpp.

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

GNodeArray GCOMModelDRBPhibarNodes::m_nodes
mutableprotected

Phibar node values.

Definition at line 96 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by copy_members(), eval(), init_members(), set_cache(), and update_cache().

std::vector<double> GCOMModelDRBPhibarNodes::m_old_phibars
mutableprotected

Old Phibar values.

Definition at line 95 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by copy_members(), init_members(), set_cache(), and update_cache().

std::vector<GModelPar> GCOMModelDRBPhibarNodes::m_phibars
protected

Node Phibar values.

Definition at line 89 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by copy_members(), init_members(), print(), read(), set_cache(), set_pointers(), update_cache(), and write().

bool GCOMModelDRBPhibarNodes::m_scale
mutableprotected

Model is a scale factor.

Definition at line 93 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by copy_members(), eval(), init_members(), and set_cache().

std::vector<GModelPar> GCOMModelDRBPhibarNodes::m_values
protected

Node values.

Definition at line 90 of file GCOMModelDRBPhibarNodes.hpp.

Referenced by copy_members(), eval(), init_members(), read(), set_pointers(), and write().


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