GammaLib
2.0.0
|
Gaussian spectral model class. More...
#include <GModelSpectralGauss.hpp>
Classes | |
class | eflux_kernel |
Public Member Functions | |
GModelSpectralGauss (void) | |
Void constructor. More... | |
GModelSpectralGauss (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpectralGauss (const double &norm, const GEnergy &mean, const GEnergy &sigma) | |
Constructor. More... | |
GModelSpectralGauss (const GModelSpectralGauss &model) | |
Copy constructor. More... | |
virtual | ~GModelSpectralGauss (void) |
Destructor. More... | |
virtual GModelSpectralGauss & | operator= (const GModelSpectralGauss &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear Gaussian spectral model. More... | |
virtual GModelSpectralGauss * | clone (void) const |
Clone Gaussian 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 model value. 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 MC 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 spectral model information. More... | |
double | norm (void) const |
Return normalization. More... | |
void | norm (const double &norm) |
Set normalization. More... | |
GEnergy | mean (void) const |
Return mean energy. More... | |
void | mean (const GEnergy &mean) |
Set mean energy. More... | |
GEnergy | sigma (void) const |
Return energy width. More... | |
void | sigma (const GEnergy &sigma) |
Set energy width. 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 GModelSpectralGauss &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | update_eval_cache (const GEnergy &energy) const |
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 | |
GModelPar | m_norm |
Normalization factor. More... | |
GModelPar | m_mean |
Gaussian mean energy. More... | |
GModelPar | m_sigma |
Gaussian energy width. More... | |
Protected Attributes inherited from GModelSpectral | |
std::vector< GModelPar * > | m_pars |
Parameter pointers. More... | |
Gaussian spectral model class.
This class implements a Gaussian spectrum. The model is defined by
\[ S_{\rm E}(E | t) = \frac{\tt m\_norm}{\sqrt{2 \pi} m\_sigma^2} \exp \left(\frac{-(E - m\_mean)^2}{2 m_\sigma^2} \right) \]
where
Definition at line 61 of file GModelSpectralGauss.hpp.
GModelSpectralGauss::GModelSpectralGauss | ( | void | ) |
Void constructor.
Definition at line 69 of file GModelSpectralGauss.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs constant 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 88 of file GModelSpectralGauss.cpp.
References init_members(), and read().
GModelSpectralGauss::GModelSpectralGauss | ( | const double & | norm, |
const GEnergy & | mean, | ||
const GEnergy & | sigma | ||
) |
Constructor.
[in] | norm | Total flux under Gaussian (in ph/cm2/s). |
[in] | mean | Mean energy. |
[in] | sigma | Energy width. |
Definition at line 109 of file GModelSpectralGauss.cpp.
References GModelSpectral::autoscale(), init_members(), m_mean, m_norm, m_sigma, GEnergy::MeV(), and GOptimizerPar::value().
GModelSpectralGauss::GModelSpectralGauss | ( | const GModelSpectralGauss & | model | ) |
Copy constructor.
[in] | model | Spectral Gaussian model. |
Definition at line 135 of file GModelSpectralGauss.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 140 of file GModelSpectralGauss.hpp.
|
virtual |
Clear Gaussian spectral model.
Implements GModelSpectral.
Definition at line 207 of file GModelSpectralGauss.cpp.
References free_members(), GModelSpectral::free_members(), init_members(), and GModelSpectral::init_members().
|
virtual |
Clone Gaussian spectral model.
Implements GModelSpectral.
Definition at line 227 of file GModelSpectralGauss.cpp.
References GModelSpectralGauss().
|
protected |
Copy class members.
[in] | model | Spectral constant model. |
Definition at line 640 of file GModelSpectralGauss.cpp.
References m_mean, m_norm, GModelSpectral::m_pars, and m_sigma.
Referenced by GModelSpectralGauss(), and operator=().
Returns model energy flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes
\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE \]
where
emin
, emax
] is an energy interval, andImplements GModelSpectral.
Definition at line 397 of file GModelSpectralGauss.cpp.
References m_mean, m_norm, m_sigma, GEnergy::MeV(), gammalib::MeV2erg, and GOptimizerPar::value().
|
virtual |
Evaluate model value.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
Evaluates
\[ S_{\rm E}(E | t) = \frac{m\_norm}{\sqrt{2\pi}m\_sigma} \exp(\frac{-(E-m\_mean)^2}{2 m\_sigma^2}) \]
where
If the gradients
flag is true the method will also compute the partial derivatives of the model with respect to the parameters using
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_norm}} = \frac{S_{\rm E}(E | t)}{{\tt m\_norm}} \]
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_mean}} = S_{\rm E}(E | t) \frac{E-m\_mean}{m\_sigma^2} \]
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_sigma}} = \frac{S_{\rm E}(E | t)}{{\tt m\_sigma}} \left( \frac{(E-m\_mean)^2}{m\_sigma^2} - 1 \right) \]
Implements GModelSpectral.
Definition at line 273 of file GModelSpectralGauss.cpp.
References exp(), GOptimizerPar::factor_gradient(), gammalib::inv_sqrt2pi, GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), m_mean, m_norm, m_sigma, mean(), GEnergy::MeV(), norm(), GOptimizerPar::scale(), sigma(), and GOptimizerPar::value().
Returns model photon flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes
\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE \]
where
emin
, emax
] is an energy interval, andImplements GModelSpectral.
Definition at line 351 of file GModelSpectralGauss.cpp.
References gammalib::gauss_integral(), m_mean, m_norm, m_sigma, mean(), GEnergy::MeV(), norm(), sigma(), and GOptimizerPar::value().
|
protected |
Delete class members.
Definition at line 661 of file GModelSpectralGauss.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralGauss().
|
protected |
Initialise class members.
Definition at line 589 of file GModelSpectralGauss.cpp.
References GOptimizerPar::clear(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_mean, m_norm, GModelSpectral::m_pars, m_sigma, GOptimizerPar::min(), GOptimizerPar::name(), GOptimizerPar::scale(), GOptimizerPar::unit(), and GOptimizerPar::value().
Referenced by clear(), GModelSpectralGauss(), and operator=().
|
virtual |
Returns MC 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. |
GException::erange_invalid | Energy range is invalid (emin < emax required). |
Returns Monte Carlo energy by randomly drawing from a constant between the minimum and maximum photon energy.
Method Used: Box-Muller transform, outlined here: http://en.wikipedia.org/wiki/Box%E2%80%93Muller_transform
Code from: http://www.design.caltech.edu/erik/Misc/Gaussian.html
Implements GModelSpectral.
Definition at line 448 of file GModelSpectralGauss.cpp.
References gammalib::check_energy_interval(), G_MC, m_mean, m_sigma, GEnergy::MeV(), GRan::normal(), and GOptimizerPar::value().
|
inline |
Return mean energy.
Definition at line 190 of file GModelSpectralGauss.hpp.
References m_mean, GEnergy::MeV(), and GOptimizerPar::value().
Referenced by GResponse::ebounds_model(), eval(), flux(), read(), and write().
|
inline |
Set mean energy.
[in] | mean | Mean energy. |
Definition at line 204 of file GModelSpectralGauss.hpp.
References m_mean, GEnergy::MeV(), and GOptimizerPar::value().
|
inline |
Return normalization.
Definition at line 166 of file GModelSpectralGauss.hpp.
References m_norm, and GOptimizerPar::value().
|
inline |
Set normalization.
[in] | norm | Normalization (ph/cm2/s). |
Definition at line 178 of file GModelSpectralGauss.hpp.
References m_norm, and GOptimizerPar::value().
|
virtual |
Assignment operator.
[in] | model | Gauss spectral model. |
Definition at line 174 of file GModelSpectralGauss.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print spectral model information.
[in] | chatter | Chattiness (defaults to NORMAL). |
Implements GModelSpectral.
Definition at line 555 of file GModelSpectralGauss.cpp.
References GModelSpectral::m_pars, gammalib::parformat(), SILENT, GModelSpectral::size(), and gammalib::str().
|
virtual |
Read model from XML element.
[in] | xml | XML element containing Gaussian model information. |
Read the spectral Gaussian information from an XML element. The format of the XML elements is:
<spectrum type="Gaussian"> <parameter name="Normalization" scale=".." value=".." min=".." max=".." free=".."/> <parameter name="Mean" scale=".." value=".." min=".." max=".." free=".."/> <parameter name="Sigma" scale=".." value=".." min=".." max=".." free=".."/> </spectrum>
Implements GModelSpectral.
Definition at line 495 of file GModelSpectralGauss.cpp.
References G_READ, m_mean, m_norm, m_sigma, mean(), GOptimizerPar::name(), norm(), GModelPar::read(), sigma(), gammalib::xml_check_parnum(), and gammalib::xml_get_par().
Referenced by GModelSpectralGauss().
|
inline |
Return energy width.
Definition at line 216 of file GModelSpectralGauss.hpp.
References m_sigma, GEnergy::MeV(), and GOptimizerPar::value().
Referenced by GResponse::ebounds_model(), eval(), flux(), read(), and write().
|
inline |
Set energy width.
[in] | sigma | Energy width. |
Definition at line 230 of file GModelSpectralGauss.hpp.
References m_sigma, GEnergy::MeV(), and GOptimizerPar::value().
|
inlinevirtual |
Return model type.
Returns the type of the Gaussian spectral model.
Implements GModelSpectral.
Definition at line 154 of file GModelSpectralGauss.hpp.
Referenced by write().
|
protected |
|
virtual |
Write model into XML element.
[in] | xml | XML element into which model information is written. |
Writes the spectral information into an XML element. The format of the XML element is
<spectrum type="Gaussian"> <parameter name="Normalization" scale=".." value=".." min=".." max=".." free=".."/> <parameter name="Mean" scale=".." value=".." min=".." max=".." free=".."/> <parameter name="Sigma" scale=".." value=".." min=".." max=".." free=".."/> </spectrum>
Implements GModelSpectral.
Definition at line 529 of file GModelSpectralGauss.cpp.
References G_WRITE, m_mean, m_norm, m_sigma, mean(), GOptimizerPar::name(), norm(), sigma(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().
|
protected |
Gaussian mean energy.
Definition at line 129 of file GModelSpectralGauss.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralGauss(), init_members(), mc(), mean(), read(), and write().
|
protected |
Normalization factor.
Definition at line 128 of file GModelSpectralGauss.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralGauss(), init_members(), norm(), read(), and write().
|
protected |
Gaussian energy width.
Definition at line 130 of file GModelSpectralGauss.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralGauss(), init_members(), mc(), read(), sigma(), and write().