GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralExponential Class Reference

Exponential spectral model class. More...

#include <GModelSpectralExponential.hpp>

Inheritance diagram for GModelSpectralExponential:
GModelSpectral GBase

Classes

class  eflux_kern
 
class  flux_kern
 

Public Member Functions

 GModelSpectralExponential (void)
 Void constructor. More...
 
 GModelSpectralExponential (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralExponential (const GModelSpectral *spec)
 Model constructor. More...
 
 GModelSpectralExponential (const GModelSpectralExponential &model)
 Copy constructor. More...
 
virtual ~GModelSpectralExponential (void)
 Destructor. More...
 
virtual GModelSpectralExponentialoperator= (const GModelSpectralExponential &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear Exponential spectral model. More...
 
virtual GModelSpectralExponentialclone (void) const
 Clone Exponential 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 Exponential spectral model information. More...
 
void exponent (const GModelSpectral *spec)
 Set exponent. More...
 
const GModelSpectralexponent (void) const
 Return exponent. 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 GModelSpectralExponential &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...
 
GModelSpectralm_exponent
 Exponent model component. 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...
 

Detailed Description

Exponential spectral model class.

This class implements a spectral model that is the exponential of a spectral model component. The spectral model component can be defined in an XML file, or using the exponent() method.

Definition at line 53 of file GModelSpectralExponential.hpp.

Constructor & Destructor Documentation

GModelSpectralExponential::GModelSpectralExponential ( void  )

Void constructor.

Definition at line 62 of file GModelSpectralExponential.cpp.

References init_members().

Referenced by clone().

GModelSpectralExponential::GModelSpectralExponential ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element containing spectral model information.

Constructs an exponential spectral model by extracting information from an XML element.

Definition at line 81 of file GModelSpectralExponential.cpp.

References init_members(), and read().

GModelSpectralExponential::GModelSpectralExponential ( const GModelSpectral spec)
explicit

Model constructor.

Parameters
[in]specSpectral model

Constructs exponential spectral model by setting the exponent model.

Definition at line 102 of file GModelSpectralExponential.cpp.

References exponent(), and init_members().

GModelSpectralExponential::GModelSpectralExponential ( const GModelSpectralExponential model)

Copy constructor.

Parameters
[in]modelExponential spectral model.

Definition at line 121 of file GModelSpectralExponential.cpp.

References copy_members(), and init_members().

GModelSpectralExponential::~GModelSpectralExponential ( void  )
virtual

Destructor.

Definition at line 138 of file GModelSpectralExponential.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GModelSpectral.

Definition at line 144 of file GModelSpectralExponential.hpp.

void GModelSpectralExponential::clear ( void  )
virtual

Clear Exponential spectral model.

Implements GModelSpectral.

Definition at line 193 of file GModelSpectralExponential.cpp.

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

GModelSpectralExponential * GModelSpectralExponential::clone ( void  ) const
virtual

Clone Exponential spectral model model.

Returns
Pointer to deep copy of Exponential spectral model.

Implements GModelSpectral.

Definition at line 213 of file GModelSpectralExponential.cpp.

References GModelSpectralExponential().

void GModelSpectralExponential::copy_members ( const GModelSpectralExponential model)
protected

Copy class members.

Parameters
[in]modelExponential spectral model.

Definition at line 603 of file GModelSpectralExponential.cpp.

References exponent(), m_exponent, m_mc_emax, m_mc_emin, m_mc_spectrum, m_mc_values, and m_type.

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

double GModelSpectralExponential::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 energy flux of Exponential spectral model

Implements GModelSpectral.

Definition at line 343 of file GModelSpectralExponential.cpp.

References GIntegral::eps(), m_exponent, GEnergy::MeV(), and GIntegral::romberg().

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

\[ \exp{M}(\rm srcEng, srcTime) \]

where \({M}\) is the exponent model component.

If the gradients flag is true the method will also compute the partial derivatives of each parameter with respect to the parameters using

\[ \frac{\delta S}{\delta P_{\rm i}}\exp{M} \]

where \({P_{\rm i}}\) is the i-th parameter.

Implements GModelSpectral.

Definition at line 245 of file GModelSpectralExponential.cpp.

References GModelSpectral::eval(), exp(), GOptimizerPar::gradient(), gammalib::is_infinite(), gammalib::is_notanumber(), m_exponent, and GModelSpectral::size().

Referenced by update_mc_cache().

void GModelSpectralExponential::exponent ( const GModelSpectral spec)

Set exponent.

Parameters
[in]specSpectral model to use as exponent.

Set a spectral model as exponent

Definition at line 501 of file GModelSpectralExponential.cpp.

References GModelSpectral::clone(), m_exponent, GModelSpectral::m_pars, and GModelSpectral::size().

const GModelSpectral * GModelSpectralExponential::exponent ( void  ) const

Return exponent.

Returns pointer to exponent spectral model

Definition at line 530 of file GModelSpectralExponential.cpp.

References m_exponent.

Referenced by copy_members(), GModelSpectralExponential(), and read().

double GModelSpectralExponential::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 photon flux of Exponential spectral model

Implements GModelSpectral.

Definition at line 305 of file GModelSpectralExponential.cpp.

References GIntegral::eps(), m_exponent, GEnergy::MeV(), and GIntegral::romberg().

void GModelSpectralExponential::free_members ( void  )
protected

Delete class members.

Definition at line 627 of file GModelSpectralExponential.cpp.

References m_exponent.

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

void GModelSpectralExponential::init_members ( void  )
protected
GEnergy GModelSpectralExponential::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.

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

Implements GModelSpectral.

Definition at line 384 of file GModelSpectralExponential.cpp.

References gammalib::check_energy_interval(), G_MC, m_exponent, m_mc_spectrum, GModelSpectralNodes::mc(), and update_mc_cache().

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

Assignment operator.

Parameters
[in]modelExponential spectral model.
Returns
Exponential spectral model.

Definition at line 160 of file GModelSpectralExponential.cpp.

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

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

Print Exponential spectral model information.

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

Implements GModelSpectral.

Definition at line 543 of file GModelSpectralExponential.cpp.

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

void GModelSpectralExponential::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.

Reads the spectral information from an XML element. The XML element shall have the following format

<spectrum type="Exponential">
  <spectrum type="Constant">
    <parameter name="Normalization" scale="1" value="1" min="0" max="2" free="1"/>
  </spectrum>
</spectrum>

Implements GModelSpectral.

Definition at line 424 of file GModelSpectralExponential.cpp.

References GModelSpectralRegistry::alloc(), GXmlNode::element(), GXmlNode::elements(), and exponent().

Referenced by GModelSpectralExponential().

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

Return model type.

Returns
Model type.

Returns the type of the spectral Multiplicative model.

Implements GModelSpectral.

Definition at line 158 of file GModelSpectralExponential.hpp.

References m_type.

Referenced by write().

void GModelSpectralExponential::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. 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 Exponential 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 653 of file GModelSpectralExponential.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().

void GModelSpectralExponential::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element.

Writes the spectral information into an XML element. The XML element will have the following format:

<spectrum type="Exponential">
  <spectrum type="Constant">
    <parameter name="Normalization" scale="1" value="1" min="0" max="2" free="1"/>
  </spectrum>
</spectrum>

If no exponential model component is defined the method writes the following XML structure

<spectrum type="Exponential">
</spectrum>

Implements GModelSpectral.

Definition at line 473 of file GModelSpectralExponential.cpp.

References GXmlNode::append(), GXmlNode::element(), G_WRITE, m_exponent, type(), GModelSpectral::write(), and gammalib::xml_check_type().

Member Data Documentation

GModelSpectral* GModelSpectralExponential::m_exponent
protected

Exponent model component.

Definition at line 128 of file GModelSpectralExponential.hpp.

Referenced by copy_members(), eflux(), eval(), exponent(), flux(), free_members(), init_members(), mc(), and write().

GEnergy GModelSpectralExponential::m_mc_emax
mutableprotected

Last maximum energy.

Definition at line 133 of file GModelSpectralExponential.hpp.

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

GEnergy GModelSpectralExponential::m_mc_emin
mutableprotected

Last minimum energy.

Definition at line 132 of file GModelSpectralExponential.hpp.

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

GModelSpectralNodes GModelSpectralExponential::m_mc_spectrum
mutableprotected

MC spectrum cache.

Definition at line 131 of file GModelSpectralExponential.hpp.

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

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

Parameter values.

Definition at line 134 of file GModelSpectralExponential.hpp.

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

std::string GModelSpectralExponential::m_type
protected

Model type.

Definition at line 127 of file GModelSpectralExponential.hpp.

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


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