GammaLib
2.0.0
|
Composite spectral model class. More...
#include <GModelSpectralComposite.hpp>
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 GModelSpectralComposite & | operator= (const GModelSpectralComposite &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear composite spectral model. More... | |
virtual GModelSpectralComposite * | clone (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 GModelSpectral * | component (const int &index) const |
Returns spectral component element. More... | |
const GModelSpectral * | component (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 GModelSpectral & | operator= (const GModelSpectral &model) |
Assignment operator. More... | |
virtual GModelPar & | operator[] (const int &index) |
Returns model parameter. More... | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns model parameter (const version) More... | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns reference to model parameter. More... | |
virtual const GModelPar & | operator[] (const std::string &name) const |
Returns reference to model parameter (const version) More... | |
GModelPar & | at (const int &index) |
Returns model parameter. More... | |
const GModelPar & | at (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... | |
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.
GModelSpectralComposite::GModelSpectralComposite | ( | void | ) |
Void constructor.
Definition at line 69 of file GModelSpectralComposite.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML constructor.
[in] | xml | XML element containing model information. |
Constructs a composite spectral model by extracting information from an XML element.
Definition at line 87 of file GModelSpectralComposite.cpp.
References init_members(), and read().
GModelSpectralComposite::GModelSpectralComposite | ( | const GModelSpectralComposite & | model | ) |
Copy constructor.
[in] | model | Composite spectral model. |
Definition at line 106 of file GModelSpectralComposite.cpp.
References copy_members(), and init_members().
|
virtual |
void GModelSpectralComposite::append | ( | const GModelSpectral & | spec, |
const std::string & | name = "" |
||
) |
Append spectral component.
[in] | spec | Spectral model component. |
[in] | name | Name of spectral component. |
Appends a spectral component to the composite model
Definition at line 490 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().
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 118 of file GModelSpectralComposite.hpp.
|
virtual |
Clear composite spectral model.
Implements GModelSpectral.
Definition at line 178 of file GModelSpectralComposite.cpp.
References free_members(), GModelSpectral::free_members(), init_members(), and GModelSpectral::init_members().
|
virtual |
Clone composite spectral model.
Implements GModelSpectral.
Definition at line 198 of file GModelSpectralComposite.cpp.
References GModelSpectralComposite().
const GModelSpectral * GModelSpectralComposite::component | ( | const int & | index | ) | const |
Returns spectral component element.
[in] | index | Index of spectral component. |
GException::out_of_range | Index is out of range. |
Returns a spectral component to the composite model
Definition at line 548 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.
[in] | name | Name of spectral component. |
GException::invalid_argument | Spectral model not found. |
Returns a spectral component of the composite model
Definition at line 572 of file GModelSpectralComposite.cpp.
References G_COMPONENT_NAME, m_components, and m_spectral.
|
inline |
Return number of spectral components.
Returns the number of spectral components.
Definition at line 146 of file GModelSpectralComposite.hpp.
References m_spectral.
Referenced by copy_members(), and print().
|
protected |
Copy class members.
[in] | model | GModelSpectralComposite members which should be copied. |
Definition at line 666 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=().
Returns model energy flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes the sum of the energy fluxes in all components.
Implements GModelSpectral.
Definition at line 299 of file GModelSpectralComposite.cpp.
References m_spectral.
|
virtual |
Evaluate function.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
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 225 of file GModelSpectralComposite.cpp.
References gammalib::is_infinite(), gammalib::is_notanumber(), and m_spectral.
Returns model photon flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes the sum of the photon fluxes in all components.
Implements GModelSpectral.
Definition at line 266 of file GModelSpectralComposite.cpp.
References m_spectral.
Referenced by update_mc_cache().
|
protected |
Delete class members.
Definition at line 713 of file GModelSpectralComposite.cpp.
References m_spectral.
Referenced by clear(), operator=(), and ~GModelSpectralComposite().
|
protected |
Initialise class members.
Definition at line 640 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=().
|
virtual |
Returns Monte Carlo energy between [emin, emax].
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
[in] | time | True photon arrival time. |
[in,out] | ran | Random number generator. |
Returns Monte Carlo energy by randomly drawing from a composite spectral model.
Implements GModelSpectral.
Definition at line 335 of file GModelSpectralComposite.cpp.
References gammalib::check_energy_interval(), G_MC, m_mc_probs, m_spectral, GRan::uniform(), and update_mc_cache().
|
virtual |
Assignment operator.
[in] | model | Composite spectral model. |
Definition at line 145 of file GModelSpectralComposite.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print composite spectral model information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 602 of file GModelSpectralComposite.cpp.
References components(), GModelSpectral::m_pars, gammalib::parformat(), SILENT, GModelSpectral::size(), and gammalib::str().
|
virtual |
Read model from XML element.
[in] | xml | XML element. |
Reads the spectral information from an XML element.
Implements GModelSpectral.
Definition at line 382 of file GModelSpectralComposite.cpp.
References GModelSpectralRegistry::alloc(), append(), GXmlElement::attribute(), GXmlNode::element(), and GXmlNode::elements().
Referenced by GModelSpectralComposite().
|
inlinevirtual |
Return 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().
|
protected |
Update Monte Carlo pre computation cache.
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Updates the precomputation cache for Monte Carlo simulations.
Definition at line 740 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, GEnergy::print(), GModelSpectral::size(), and sum().
Referenced by mc().
|
virtual |
Write model into XML element.
[in] | xml | XML element. |
Writes the spectral information into an XML element.
Implements GModelSpectral.
Definition at line 422 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(), GModelSpectral::write(), and gammalib::xml_check_type().
|
protected |
Names of components.
Definition at line 101 of file GModelSpectralComposite.hpp.
Referenced by append(), component(), copy_members(), init_members(), and write().
|
mutableprotected |
Last maximum energy.
Definition at line 107 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
mutableprotected |
Last minimum energy.
Definition at line 106 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
mutableprotected |
Flux cache.
Definition at line 104 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
mutableprotected |
Probailities of individual components.
Definition at line 105 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc_cache().
|
mutableprotected |
Parameter values.
Definition at line 108 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
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().
|
protected |
Model type.
Definition at line 99 of file GModelSpectralComposite.hpp.
Referenced by copy_members(), init_members(), and type().