GammaLib
2.1.0.dev
|
Multiplicative spectral model class. More...
#include <GModelSpectralMultiplicative.hpp>
Classes | |
class | eflux_kern |
class | flux_kern |
Public Member Functions | |
GModelSpectralMultiplicative (void) | |
Void constructor. More... | |
GModelSpectralMultiplicative (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpectralMultiplicative (const GModelSpectralMultiplicative &model) | |
Copy constructor. More... | |
virtual | ~GModelSpectralMultiplicative (void) |
Destructor. More... | |
virtual GModelSpectralMultiplicative & | operator= (const GModelSpectralMultiplicative &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear multiplicative spectral model. More... | |
virtual GModelSpectralMultiplicative * | clone (void) const |
Clone multiplicative spectral model 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 multiplicative 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 |
Return spectral model component by index. More... | |
const GModelSpectral * | component (const std::string &name) const |
Return spectral model component by name. 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 GModelSpectralMultiplicative &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... | |
GModelSpectralNodes | m_mc_spectrum |
MC spectrum cache. 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... | |
Multiplicative spectral model class.
This class implements a spectral model that is a multiplication spectral model components. The spectral model components can be defined in an XML file, or added using the append() method.
Definition at line 53 of file GModelSpectralMultiplicative.hpp.
GModelSpectralMultiplicative::GModelSpectralMultiplicative | ( | void | ) |
Void constructor.
Definition at line 73 of file GModelSpectralMultiplicative.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML constructor.
[in] | xml | XML element containing spectral model information. |
Constructs a multiplicative spectral model by extracting information from an XML element. See the read() method for more information about the expected structure of the XML element.
Definition at line 93 of file GModelSpectralMultiplicative.cpp.
References init_members(), and read().
GModelSpectralMultiplicative::GModelSpectralMultiplicative | ( | const GModelSpectralMultiplicative & | model | ) |
Copy constructor.
[in] | model | Multiplicative spectral model. |
Definition at line 112 of file GModelSpectralMultiplicative.cpp.
References copy_members(), and init_members().
|
virtual |
Destructor.
Definition at line 129 of file GModelSpectralMultiplicative.cpp.
References free_members().
void GModelSpectralMultiplicative::append | ( | const GModelSpectral & | spec, |
const std::string & | name = "" |
||
) |
Append spectral component.
[in] | spec | Spectral model component. |
[in] | name | Name of spectral component (can be empty). |
GException::invalid_value | Invalid component name specified |
Appends a spectral component to the Multiplicative model
Definition at line 540 of file GModelSpectralMultiplicative.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 150 of file GModelSpectralMultiplicative.hpp.
|
virtual |
Clear multiplicative spectral model.
Implements GModelSpectral.
Definition at line 184 of file GModelSpectralMultiplicative.cpp.
References free_members(), GModelSpectral::free_members(), init_members(), and GModelSpectral::init_members().
|
virtual |
Clone multiplicative spectral model model.
Implements GModelSpectral.
Definition at line 204 of file GModelSpectralMultiplicative.cpp.
References GModelSpectralMultiplicative().
const GModelSpectral * GModelSpectralMultiplicative::component | ( | const int & | index | ) | const |
Return spectral model component by index.
[in] | index | Index of spectral component. |
Returns a component of the multiplicative spectral model by index
.
Definition at line 597 of file GModelSpectralMultiplicative.cpp.
References G_COMPONENT_INDEX, and m_spectral.
const GModelSpectral * GModelSpectralMultiplicative::component | ( | const std::string & | name | ) | const |
Return spectral model component by name.
[in] | name | Name of spectral component. |
GException::invalid_argument | Model component not found. |
Returns a component of the multiplicative spectral model by name
.
Definition at line 621 of file GModelSpectralMultiplicative.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 178 of file GModelSpectralMultiplicative.hpp.
References m_spectral.
Referenced by copy_members(), and print().
|
protected |
Copy class members.
[in] | model | Multiplicative spectral model. |
Definition at line 713 of file GModelSpectralMultiplicative.cpp.
References components(), m_components, m_mc_emax, m_mc_emin, m_mc_spectrum, m_mc_values, GModelSpectral::m_pars, m_spectral, m_type, and GModelSpectral::size().
Referenced by GModelSpectralMultiplicative(), and operator=().
|
virtual |
Returns model energy flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes the energy flux of multiplicative spectral model
Implements GModelSpectral.
Definition at line 355 of file GModelSpectralMultiplicative.cpp.
References GIntegral::eps(), m_spectral, GEnergy::MeV(), and GIntegral::romberg().
|
virtual |
Evaluate function.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
Evaluates
\[ \prod_{i=0}^{N} {M_{\rm i}}(\rm srcEng, srcTime) \]
where \({M_{\rm i}}\) is the i-th model component.
If the gradients
flag is true the method will also compute the partial derivatives of each parameter of eachmodel component with respect to the parameters using
\[ \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k} \]
where \({P_{\rm ij}}\) is the j-th parameter of the i-th multiplicative component, while \({M_{\rm k}}\) is the k-th model component and n the number of model components.
Implements GModelSpectral.
Definition at line 241 of file GModelSpectralMultiplicative.cpp.
References GOptimizerPar::gradient(), gammalib::is_infinite(), gammalib::is_notanumber(), and m_spectral.
Referenced by update_mc_cache().
|
virtual |
Returns model photon flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes the photon flux of multiplicative spectral model
Implements GModelSpectral.
Definition at line 318 of file GModelSpectralMultiplicative.cpp.
References GIntegral::eps(), m_spectral, GEnergy::MeV(), and GIntegral::romberg().
|
protected |
Delete class members.
Definition at line 757 of file GModelSpectralMultiplicative.cpp.
References m_spectral.
Referenced by clear(), operator=(), and ~GModelSpectralMultiplicative().
|
protected |
Initialise class members.
Definition at line 688 of file GModelSpectralMultiplicative.cpp.
References GEnergy::clear(), GModelSpectralNodes::clear(), m_components, m_mc_emax, m_mc_emin, m_mc_spectrum, m_mc_values, m_spectral, and m_type.
Referenced by clear(), GModelSpectralMultiplicative(), 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 multiplicative spectral model.
Implements GModelSpectral.
Definition at line 395 of file GModelSpectralMultiplicative.cpp.
References gammalib::check_energy_interval(), G_MC, m_mc_spectrum, m_spectral, GModelSpectralNodes::mc(), and update_mc_cache().
|
virtual |
Assignment operator.
[in] | model | Multiplicative spectral model. |
Definition at line 151 of file GModelSpectralMultiplicative.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print multiplicative spectral model information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 650 of file GModelSpectralMultiplicative.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 428 of file GModelSpectralMultiplicative.cpp.
References GModelSpectralRegistry::alloc(), append(), GXmlElement::attribute(), GXmlNode::element(), and GXmlNode::elements().
Referenced by GModelSpectralMultiplicative().
|
inlinevirtual |
Return model type.
Returns the type of the spectral Multiplicative model.
Implements GModelSpectral.
Definition at line 164 of file GModelSpectralMultiplicative.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. In case that the energy boundaries have changed or at least one of the model parameters has changed the method computes a spectral node function which has 100 nodes per decade containing the multiplicative spectral model values and stores that into a Monte Carlo cache. This cache is then used by the mc() method for simulations.
Definition at line 788 of file GModelSpectralMultiplicative.cpp.
References GModelSpectralNodes::append(), GModelSpectralNodes::clear(), eval(), GEnergy::log10MeV(), m_mc_emax, m_mc_emin, m_mc_spectrum, m_mc_values, GModelSpectral::m_pars, GEnergies::size(), and GModelSpectral::size().
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 468 of file GModelSpectralMultiplicative.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 134 of file GModelSpectralMultiplicative.hpp.
Referenced by append(), component(), copy_members(), init_members(), and write().
|
mutableprotected |
Last maximum energy.
Definition at line 139 of file GModelSpectralMultiplicative.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
mutableprotected |
Last minimum energy.
Definition at line 138 of file GModelSpectralMultiplicative.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
mutableprotected |
MC spectrum cache.
Definition at line 137 of file GModelSpectralMultiplicative.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc_cache().
|
mutableprotected |
Parameter values.
Definition at line 140 of file GModelSpectralMultiplicative.hpp.
Referenced by copy_members(), init_members(), and update_mc_cache().
|
protected |
Container of spectral models.
Definition at line 133 of file GModelSpectralMultiplicative.hpp.
Referenced by append(), component(), components(), copy_members(), eflux(), eval(), flux(), free_members(), init_members(), mc(), and write().
|
protected |
Model type.
Definition at line 132 of file GModelSpectralMultiplicative.hpp.
Referenced by copy_members(), init_members(), and type().