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

Gaussian spectral model class. More...

#include <GModelSpectralGauss.hpp>

Inheritance diagram for GModelSpectralGauss:
GModelSpectral GBase

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 GModelSpectralGaussoperator= (const GModelSpectralGauss &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear Gaussian spectral model. More...
 
virtual GModelSpectralGaussclone (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 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 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...
 

Detailed Description

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

  • \({\tt m\_norm}\) is the normalization,
  • \({\tt m\_mean}\) is the mean energy,
  • \({\tt m\_sigma}\) is the energy width.

Definition at line 61 of file GModelSpectralGauss.hpp.

Constructor & Destructor Documentation

GModelSpectralGauss::GModelSpectralGauss ( void  )

Void constructor.

Definition at line 69 of file GModelSpectralGauss.cpp.

References init_members().

Referenced by clone().

GModelSpectralGauss::GModelSpectralGauss ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML 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.

Parameters
[in]normTotal flux under Gaussian (in ph/cm2/s).
[in]meanMean energy.
[in]sigmaEnergy 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.

Parameters
[in]modelSpectral Gaussian model.

Definition at line 135 of file GModelSpectralGauss.cpp.

References copy_members(), and init_members().

GModelSpectralGauss::~GModelSpectralGauss ( void  )
virtual

Destructor.

Definition at line 152 of file GModelSpectralGauss.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GModelSpectral.

Definition at line 140 of file GModelSpectralGauss.hpp.

void GModelSpectralGauss::clear ( void  )
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().

GModelSpectralGauss * GModelSpectralGauss::clone ( void  ) const
virtual

Clone Gaussian spectral model.

Returns
Pointer to deep copy of Gaussian spectral model.

Implements GModelSpectral.

Definition at line 227 of file GModelSpectralGauss.cpp.

References GModelSpectralGauss().

void GModelSpectralGauss::copy_members ( const GModelSpectralGauss model)
protected

Copy class members.

Parameters
[in]modelSpectral 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=().

double GModelSpectralGauss::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

\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE \]

where

  • [emin, emax] is an energy interval, and
  • \(S_{\rm E}(E | t)\) is the spectral model (ph/cm2/s/MeV). The integration is done analytically.

Implements GModelSpectral.

Definition at line 397 of file GModelSpectralGauss.cpp.

References m_mean, m_norm, m_sigma, GEnergy::MeV(), gammalib::MeV2erg, and GOptimizerPar::value().

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

Evaluate model value.

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

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

  • \({\tt m\_norm}\) is the normalization,
  • \({\tt m\_mean}\) is the mean energy, and
  • \({\tt m\_sigma}\) is the energy width.

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().

double GModelSpectralGauss::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

\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE \]

where

  • [emin, emax] is an energy interval, and
  • \(S_{\rm E}(E | t)\) is the spectral model (ph/cm2/s/MeV). The integration is done analytically.

Implements 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().

void GModelSpectralGauss::free_members ( void  )
protected

Delete class members.

Definition at line 661 of file GModelSpectralGauss.cpp.

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

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

Returns MC 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 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().

GEnergy GModelSpectralGauss::mean ( void  ) const
inline

Return mean energy.

Returns
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().

void GModelSpectralGauss::mean ( const GEnergy mean)
inline

Set mean energy.

Parameters
[in]meanMean energy.

Definition at line 204 of file GModelSpectralGauss.hpp.

References m_mean, GEnergy::MeV(), and GOptimizerPar::value().

double GModelSpectralGauss::norm ( void  ) const
inline

Return normalization.

Returns
Normalization (ph/cm2/s).

Definition at line 166 of file GModelSpectralGauss.hpp.

References m_norm, and GOptimizerPar::value().

Referenced by eval(), flux(), read(), and write().

void GModelSpectralGauss::norm ( const double &  norm)
inline

Set normalization.

Parameters
[in]normNormalization (ph/cm2/s).

Definition at line 178 of file GModelSpectralGauss.hpp.

References m_norm, and GOptimizerPar::value().

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

Assignment operator.

Parameters
[in]modelGauss spectral model.
Returns
Gauss spectral model.

Definition at line 174 of file GModelSpectralGauss.cpp.

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

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

Print spectral model information.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing spectral model information.

Implements GModelSpectral.

Definition at line 555 of file GModelSpectralGauss.cpp.

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

void GModelSpectralGauss::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML 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().

GEnergy GModelSpectralGauss::sigma ( void  ) const
inline

Return energy width.

Returns
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().

void GModelSpectralGauss::sigma ( const GEnergy sigma)
inline

Set energy width.

Parameters
[in]sigmaEnergy width.

Definition at line 230 of file GModelSpectralGauss.hpp.

References m_sigma, GEnergy::MeV(), and GOptimizerPar::value().

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

Return model type.

Returns
"ConstantValue".

Returns the type of the Gaussian spectral model.

Implements GModelSpectral.

Definition at line 154 of file GModelSpectralGauss.hpp.

Referenced by write().

void GModelSpectralGauss::update_eval_cache ( const GEnergy energy) const
protected
void GModelSpectralGauss::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML 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().

Member Data Documentation

GModelPar GModelSpectralGauss::m_mean
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().

GModelPar GModelSpectralGauss::m_norm
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().

GModelPar GModelSpectralGauss::m_sigma
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().


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