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

Composite spectral model class. More...

#include <GModelSpectralComposite.hpp>

Inheritance diagram for GModelSpectralComposite:
GModelSpectral GBase

Public Member Functions

 GModelSpectralComposite (void)
 Void constructor. More...
 
 GModelSpectralComposite (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralComposite (const GModelSpectralComposite &model)
 Copy constructor. More...
 
virtual ~GModelSpectralComposite (void)
 Destructor. More...
 
virtual GModelSpectralCompositeoperator= (const GModelSpectralComposite &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear composite spectral model. More...
 
virtual GModelSpectralCompositeclone (void) const
 Clone composite spectral model. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual std::string type (void) const
 Return model type. More...
 
virtual double eval (const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
 Evaluate function. More...
 
virtual double flux (const GEnergy &emin, const GEnergy &emax) const
 Returns model photon flux between emin, emax More...
 
virtual double eflux (const GEnergy &emin, const GEnergy &emax) const
 Returns model energy flux between emin, emax More...
 
virtual GEnergy mc (const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
 Returns Monte Carlo energy between [emin, emax]. 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 composite spectral model information. More...
 
void append (const GModelSpectral &spec, const std::string &name="")
 Append spectral component. More...
 
int components (void) const
 Return number of spectral components. More...
 
const GModelSpectralcomponent (const int &index) const
 Returns spectral component element. More...
 
const GModelSpectralcomponent (const std::string &name) const
 Returns pointer to specific spectral component. More...
 
- Public Member Functions inherited from GModelSpectral
 GModelSpectral (void)
 Void constructor. More...
 
 GModelSpectral (const GModelSpectral &model)
 Copy constructor. More...
 
virtual ~GModelSpectral (void)
 Destructor. More...
 
virtual GModelSpectraloperator= (const GModelSpectral &model)
 Assignment operator. More...
 
virtual GModelParoperator[] (const int &index)
 Returns model parameter. More...
 
virtual const GModelParoperator[] (const int &index) const
 Returns model parameter (const version) More...
 
virtual GModelParoperator[] (const std::string &name)
 Returns reference to model parameter. More...
 
virtual const GModelParoperator[] (const std::string &name) const
 Returns reference to model parameter (const version) More...
 
GModelParat (const int &index)
 Returns model parameter. More...
 
const GModelParat (const int &index) const
 Returns model parameter (const version) More...
 
bool has_par (const std::string &name) const
 Checks if parameter name exists. More...
 
int size (void) const
 Return number of parameters. More...
 
void autoscale (void)
 Autoscale parameters. 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 GModelSpectralComposite &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void update_mc_cache (const GEnergy &emin, const GEnergy &emax) const
 Update Monte Carlo pre computation cache. More...
 
- Protected Member Functions inherited from GModelSpectral
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelSpectral &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

std::string m_type
 Model type. More...
 
std::vector< GModelSpectral * > m_spectral
 Container of spectral models. More...
 
std::vector< std::string > m_components
 Names of components. More...
 
double m_mc_flux
 Flux cache. More...
 
std::vector< double > m_mc_probs
 Probailities of individual components. More...
 
GEnergy m_mc_emin
 Last minimum energy. More...
 
GEnergy m_mc_emax
 Last maximum energy. More...
 
std::vector< double > m_mc_values
 Parameter values. More...
 
- Protected Attributes inherited from GModelSpectral
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Composite spectral model class.

This class implements a composite spectrum. The model is defined by the sum of several individual spectral models. Each spectral model can be added via the XML interface or using the append() method.

Definition at line 52 of file GModelSpectralComposite.hpp.

Constructor & Destructor Documentation

GModelSpectralComposite::GModelSpectralComposite ( void  )

Void constructor.

Definition at line 68 of file GModelSpectralComposite.cpp.

References init_members().

Referenced by clone().

GModelSpectralComposite::GModelSpectralComposite ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element containing model information.

Constructs a composite spectral model by extracting information from an XML element.

Definition at line 86 of file GModelSpectralComposite.cpp.

References init_members(), and read().

GModelSpectralComposite::GModelSpectralComposite ( const GModelSpectralComposite model)

Copy constructor.

Parameters
[in]modelComposite spectral model.

Definition at line 105 of file GModelSpectralComposite.cpp.

References copy_members(), and init_members().

GModelSpectralComposite::~GModelSpectralComposite ( void  )
virtual

Destructor.

Definition at line 122 of file GModelSpectralComposite.cpp.

References free_members().

Member Function Documentation

void GModelSpectralComposite::append ( const GModelSpectral spec,
const std::string &  name = "" 
)

Append spectral component.

Parameters
[in]specSpectral model component.
[in]nameName of spectral component.

Appends a spectral component to the composite model

Definition at line 506 of file GModelSpectralComposite.cpp.

References GModelSpectral::clone(), gammalib::contains(), G_APPEND, m_components, GModelSpectral::m_pars, m_spectral, GOptimizerPar::name(), and gammalib::str().

Referenced by read().

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

Return class name.

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

Implements GModelSpectral.

Definition at line 118 of file GModelSpectralComposite.hpp.

void GModelSpectralComposite::clear ( void  )
virtual

Clear composite spectral model.

Implements GModelSpectral.

Definition at line 177 of file GModelSpectralComposite.cpp.

References free_members(), GModelSpectral::free_members(), init_members(), and GModelSpectral::init_members().

GModelSpectralComposite * GModelSpectralComposite::clone ( void  ) const
virtual

Clone composite spectral model.

Returns
Pointer to deep copy of composite spectral model.

Implements GModelSpectral.

Definition at line 197 of file GModelSpectralComposite.cpp.

References GModelSpectralComposite().

const GModelSpectral * GModelSpectralComposite::component ( const int &  index) const

Returns spectral component element.

Parameters
[in]indexIndex of spectral component.
Returns
Spectral model.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns a spectral component to the composite model

Definition at line 564 of file GModelSpectralComposite.cpp.

References G_COMPONENT_INDEX, and m_spectral.

const GModelSpectral * GModelSpectralComposite::component ( const std::string &  name) const

Returns pointer to specific spectral component.

Parameters
[in]nameName of spectral component.
Returns
Spectral model.
Exceptions
GException::invalid_argumentSpectral model not found.

Returns a spectral component of the composite model

Definition at line 588 of file GModelSpectralComposite.cpp.

References G_COMPONENT_NAME, m_components, and m_spectral.

int GModelSpectralComposite::components ( void  ) const
inline

Return number of spectral components.

Returns
Number of model components.

Returns the number of spectral components.

Definition at line 146 of file GModelSpectralComposite.hpp.

References m_spectral.

Referenced by copy_members(), and print().

void GModelSpectralComposite::copy_members ( const GModelSpectralComposite model)
protected

Copy class members.

Parameters
[in]modelGModelSpectralComposite members which should be copied.

Definition at line 682 of file GModelSpectralComposite.cpp.

References components(), m_components, m_mc_emax, m_mc_emin, m_mc_flux, m_mc_probs, m_mc_values, GModelSpectral::m_pars, m_spectral, m_type, and GModelSpectral::size().

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

double GModelSpectralComposite::eflux ( const GEnergy emin,
const GEnergy emax 
) const
virtual

Returns model energy flux between emin, emax

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
Returns
Energy flux (erg/cm2/s).

Computes the sum of the energy fluxes in all components.

Implements GModelSpectral.

Definition at line 298 of file GModelSpectralComposite.cpp.

References m_spectral.

double GModelSpectralComposite::eval ( const GEnergy srcEng,
const GTime srcTime = GTime(),
const bool &  gradients = false 
) const
virtual

Evaluate function.

Parameters
[in]srcEngTrue photon energy.
[in]srcTimeTrue photon arrival time.
[in]gradientsCompute gradients?
Returns
Model value (ph/cm2/s/MeV).

Evaluates

\[ \sum_{i=0}^{N} {M_{\rm i}}(\rm srcEng, srcTime) \]

where \({M_{\rm i}}\) is the model evaluation of the i-th model

If the gradients flag is true the method will also compute the partial derivatives of each model component with respect to the parameters.

Implements GModelSpectral.

Definition at line 224 of file GModelSpectralComposite.cpp.

References gammalib::is_infinite(), gammalib::is_notanumber(), and m_spectral.

double GModelSpectralComposite::flux ( const GEnergy emin,
const GEnergy emax 
) const
virtual

Returns model photon flux between emin, emax

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
Returns
Photon flux (ph/cm2/s).

Computes the sum of the photon fluxes in all components.

Implements GModelSpectral.

Definition at line 265 of file GModelSpectralComposite.cpp.

References m_spectral.

Referenced by update_mc_cache().

void GModelSpectralComposite::free_members ( void  )
protected

Delete class members.

Definition at line 729 of file GModelSpectralComposite.cpp.

References m_spectral.

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

void GModelSpectralComposite::init_members ( void  )
protected

Initialise class members.

Definition at line 656 of file GModelSpectralComposite.cpp.

References GEnergy::clear(), m_components, m_mc_emax, m_mc_emin, m_mc_flux, m_mc_probs, m_mc_values, m_spectral, and m_type.

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

GEnergy GModelSpectralComposite::mc ( const GEnergy emin,
const GEnergy emax,
const GTime time,
GRan ran 
) const
virtual

Returns Monte Carlo energy between [emin, emax].

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
[in]timeTrue photon arrival time.
[in,out]ranRandom number generator.
Returns
Energy.
Exceptions
GException::erange_invalidEnergy range is invalid (emin < emax required).

Returns Monte Carlo energy by randomly drawing from a composite spectral model.

Implements GModelSpectral.

Definition at line 337 of file GModelSpectralComposite.cpp.

References G_MC, m_mc_probs, m_spectral, GEnergy::MeV(), GRan::uniform(), and update_mc_cache().

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

Assignment operator.

Parameters
[in]modelComposite spectral model.
Returns
Composite spectral model.

Definition at line 144 of file GModelSpectralComposite.cpp.

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

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

Print composite spectral model information.

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

Implements GModelSpectral.

Definition at line 618 of file GModelSpectralComposite.cpp.

References components(), GModelSpectral::m_pars, gammalib::parformat(), SILENT, GModelSpectral::size(), and gammalib::str().

void GModelSpectralComposite::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.

Reads the spectral information from an XML element.

Implements GModelSpectral.

Definition at line 387 of file GModelSpectralComposite.cpp.

References GModelSpectralRegistry::alloc(), append(), GXmlElement::attribute(), GXmlNode::element(), and GXmlNode::elements().

Referenced by GModelSpectralComposite().

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

Return model type.

Returns
Model type.

Returns the type of the spectral composite model.

Implements GModelSpectral.

Definition at line 132 of file GModelSpectralComposite.hpp.

References m_type.

Referenced by write().

void GModelSpectralComposite::update_mc_cache ( const GEnergy emin,
const GEnergy emax 
) const
protected

Update Monte Carlo pre computation cache.

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.

Updates the precomputation cache for Monte Carlo simulations.

Definition at line 756 of file GModelSpectralComposite.cpp.

References flux(), m_mc_emax, m_mc_emin, m_mc_flux, m_mc_probs, m_mc_values, GModelSpectral::m_pars, m_spectral, GModelSpectral::size(), and sum().

Referenced by mc().

void GModelSpectralComposite::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element.
Exceptions
GException::model_invalid_spectralExisting XML element is not of the expected type.

Writes the spectral information into an XML element.

Implements GModelSpectral.

Definition at line 430 of file GModelSpectralComposite.cpp.

References GXmlNode::append(), GXmlElement::attribute(), gammalib::contains(), GXmlNode::element(), GXmlNode::elements(), G_WRITE, m_components, m_spectral, GOptimizerPar::name(), GModelSpectral::size(), gammalib::split(), gammalib::str(), type(), and GModelSpectral::write().

Member Data Documentation

std::vector<std::string> GModelSpectralComposite::m_components
protected

Names of components.

Definition at line 101 of file GModelSpectralComposite.hpp.

Referenced by append(), component(), copy_members(), init_members(), and write().

GEnergy GModelSpectralComposite::m_mc_emax
mutableprotected

Last maximum energy.

Definition at line 107 of file GModelSpectralComposite.hpp.

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

GEnergy GModelSpectralComposite::m_mc_emin
mutableprotected

Last minimum energy.

Definition at line 106 of file GModelSpectralComposite.hpp.

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

double GModelSpectralComposite::m_mc_flux
mutableprotected

Flux cache.

Definition at line 104 of file GModelSpectralComposite.hpp.

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

std::vector<double> GModelSpectralComposite::m_mc_probs
mutableprotected

Probailities of individual components.

Definition at line 105 of file GModelSpectralComposite.hpp.

Referenced by copy_members(), init_members(), mc(), and update_mc_cache().

std::vector<double> GModelSpectralComposite::m_mc_values
mutableprotected

Parameter values.

Definition at line 108 of file GModelSpectralComposite.hpp.

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

std::vector<GModelSpectral*> GModelSpectralComposite::m_spectral
protected

Container of spectral models.

Definition at line 100 of file GModelSpectralComposite.hpp.

Referenced by append(), component(), components(), copy_members(), eflux(), eval(), flux(), free_members(), init_members(), mc(), update_mc_cache(), and write().

std::string GModelSpectralComposite::m_type
protected

Model type.

Definition at line 99 of file GModelSpectralComposite.hpp.

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


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