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

Power law spectral model class. More...

#include <GModelSpectralPlaw.hpp>

Inheritance diagram for GModelSpectralPlaw:
GModelSpectral GBase

Public Member Functions

 GModelSpectralPlaw (void)
 Void constructor. More...
 
 GModelSpectralPlaw (const std::string &type, const std::string &prefactor, const std::string &index, const std::string &pivot)
 Model type and parameter name constructor. More...
 
 GModelSpectralPlaw (const double &prefactor, const double &index, const GEnergy &pivot)
 Parameter constructor. More...
 
 GModelSpectralPlaw (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralPlaw (const GModelSpectralPlaw &model)
 Copy constructor. More...
 
virtual ~GModelSpectralPlaw (void)
 Destructor. More...
 
virtual GModelSpectralPlawoperator= (const GModelSpectralPlaw &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear spectral power law model. More...
 
virtual GModelSpectralPlawclone (void) const
 Clone spectral power law 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 powerlaw information. More...
 
void type (const std::string &type)
 Set model type. More...
 
double prefactor (void) const
 Return pre factor. More...
 
double index (void) const
 Return power law index. More...
 
GEnergy pivot (void) const
 Return pivot energy. More...
 
void prefactor (const double &prefactor)
 Set pre factor. More...
 
void index (const double &index)
 Set power law index. More...
 
void pivot (const GEnergy &pivot)
 Set pivot energy. 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 GModelSpectralPlaw &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void update_eval_cache (const GEnergy &energy) const
 Update eval precomputation cache. 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...
 
GModelPar m_norm
 Normalization factor. More...
 
GModelPar m_index
 Spectral index. More...
 
GModelPar m_pivot
 Pivot energy. More...
 
GEnergy m_last_energy
 Last energy value. More...
 
double m_last_norm
 Last norm parameter. More...
 
double m_last_index
 Last index parameter. More...
 
double m_last_pivot
 Last pivot parameter. More...
 
double m_last_e_norm
 Last E/Epivot value. More...
 
double m_last_log_e_norm
 Last ln(E/Epivot) value. More...
 
double m_last_power
 Last power value. More...
 
double m_mc_emin
 Minimum energy. More...
 
double m_mc_emax
 Maximum energy. More...
 
double m_mc_exponent
 Exponent (index+1) More...
 
double m_mc_pow_emin
 Power of minimum energy. More...
 
double m_mc_pow_ewidth
 Power of energy width. More...
 
- Protected Attributes inherited from GModelSpectral
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Power law spectral model class.

This class implements a power law spectrum. The model is defined by

\[ S_{\rm E}(E | t) = {\tt m\_norm} \left( \frac{E}{\tt m\_pivot} \right)^{\tt m\_index} \]

where

  • \({\tt m\_norm}\) is the normalization or prefactor,
  • \({\tt m\_index}\) is the spectral index, and
  • \({\tt m\_pivot}\) is the pivot energy.

Definition at line 59 of file GModelSpectralPlaw.hpp.

Constructor & Destructor Documentation

GModelSpectralPlaw::GModelSpectralPlaw ( void  )

Void constructor.

Definition at line 76 of file GModelSpectralPlaw.cpp.

References init_members().

Referenced by clone().

GModelSpectralPlaw::GModelSpectralPlaw ( const std::string &  type,
const std::string &  prefactor,
const std::string &  index,
const std::string &  pivot 
)

Model type and parameter name constructor.

Parameters
[in]typeModel type.
[in]prefactorName of prefactor parameter.
[in]indexName of index parameter.
[in]pivotName of pivot parameter.

Definition at line 94 of file GModelSpectralPlaw.cpp.

References init_members(), m_index, m_norm, m_pivot, m_type, GOptimizerPar::name(), and type().

GModelSpectralPlaw::GModelSpectralPlaw ( const double &  prefactor,
const double &  index,
const GEnergy pivot 
)

Parameter constructor.

Parameters
[in]prefactorPower law pre factor (ph/cm2/s/MeV).
[in]indexPower law index.
[in]pivotPivot energy.

Constructs a spectral power law using the model parameters

  • power law prefactor (ph/cm2/s/MeV)
  • spectral index
  • pivot energy.

Definition at line 128 of file GModelSpectralPlaw.cpp.

References GModelSpectral::autoscale(), init_members(), m_index, m_norm, m_pivot, GEnergy::MeV(), and GOptimizerPar::value().

GModelSpectralPlaw::GModelSpectralPlaw ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element containing position information.

Constructs a power law 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 158 of file GModelSpectralPlaw.cpp.

References init_members(), and read().

GModelSpectralPlaw::GModelSpectralPlaw ( const GModelSpectralPlaw model)

Copy constructor.

Parameters
[in]modelSpectral power law model.

Definition at line 176 of file GModelSpectralPlaw.cpp.

References copy_members(), and init_members().

GModelSpectralPlaw::~GModelSpectralPlaw ( void  )
virtual

Destructor.

Definition at line 193 of file GModelSpectralPlaw.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GModelSpectral.

Definition at line 143 of file GModelSpectralPlaw.hpp.

void GModelSpectralPlaw::clear ( void  )
virtual

Clear spectral power law model.

Implements GModelSpectral.

Definition at line 248 of file GModelSpectralPlaw.cpp.

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

GModelSpectralPlaw * GModelSpectralPlaw::clone ( void  ) const
virtual

Clone spectral power law model.

Returns
Pointer to deep copy of spectral power law model.

Implements GModelSpectral.

Definition at line 268 of file GModelSpectralPlaw.cpp.

References GModelSpectralPlaw().

void GModelSpectralPlaw::copy_members ( const GModelSpectralPlaw model)
protected
double GModelSpectralPlaw::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 422 of file GModelSpectralPlaw.cpp.

References m_index, m_norm, m_pivot, GEnergy::MeV(), gammalib::MeV2erg, gammalib::plaw_energy_flux(), and GOptimizerPar::value().

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

\[ S_{\rm E}(E | t) = {\tt m\_norm} \left( \frac{E}{\tt m\_pivot} \right)^{\tt m\_index} \]

where

  • \({\tt m\_norm}\) is the normalization or prefactor,
  • \({\tt m\_index}\) is the spectral index, and
  • \({\tt m\_pivot}\) is the pivot energy.

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\_index}} = S_{\rm E}(E | t) \, \ln(E/{\tt m_pivot}) \]

\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_pivot}} = -S_{\rm E}(E | t) \, \left( \frac{{\tt m\_index}}{{\tt m\_pivot}} \right) \]

Todo:
The method expects that energy!=0. Otherwise Inf or NaN may result.

Implements GModelSpectral.

Definition at line 316 of file GModelSpectralPlaw.cpp.

References GOptimizerPar::factor_gradient(), GOptimizerPar::factor_value(), G_EVAL, GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), m_index, m_last_index, m_last_log_e_norm, m_last_power, m_norm, GModelSpectral::m_pars, m_pivot, GEnergy::print(), GTime::print(), GOptimizerPar::scale(), gammalib::str(), update_eval_cache(), GOptimizerPar::value(), and gammalib::warning().

double GModelSpectralPlaw::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 381 of file GModelSpectralPlaw.cpp.

References m_index, m_norm, m_pivot, GEnergy::MeV(), gammalib::plaw_photon_flux(), and GOptimizerPar::value().

void GModelSpectralPlaw::free_members ( void  )
protected

Delete class members.

Definition at line 701 of file GModelSpectralPlaw.cpp.

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

double GModelSpectralPlaw::index ( void  ) const
inline

Return power law index.

Returns
Power law index.

Returns the power law index.

Definition at line 215 of file GModelSpectralPlaw.hpp.

References m_index, and GOptimizerPar::value().

Referenced by mc(), read(), GCOMIaq::set(), update_eval_cache(), update_mc_cache(), and write().

void GModelSpectralPlaw::index ( const double &  index)
inline

Set power law index.

Parameters
[in]indexPower law index.

Sets the power law index.

Definition at line 229 of file GModelSpectralPlaw.hpp.

References m_index, and GOptimizerPar::value().

GEnergy GModelSpectralPlaw::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 power law.

Implements GModelSpectral.

Definition at line 459 of file GModelSpectralPlaw.cpp.

References gammalib::check_energy_interval(), exp(), G_MC, index(), log(), m_mc_exponent, m_mc_pow_emin, m_mc_pow_ewidth, GEnergy::MeV(), GRan::uniform(), and update_mc_cache().

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

Assignment operator.

Parameters
[in]modelSpectral power law model.
Returns
Spectral power law model.

Definition at line 215 of file GModelSpectralPlaw.cpp.

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

GEnergy GModelSpectralPlaw::pivot ( void  ) const
inline

Return pivot energy.

Returns
Pivot energy.

Returns the pivot energy.

Definition at line 244 of file GModelSpectralPlaw.hpp.

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

Referenced by read(), update_eval_cache(), and write().

void GModelSpectralPlaw::pivot ( const GEnergy pivot)
inline

Set pivot energy.

Parameters
[in]pivotPivot energy.

Sets the pivot energy.

Definition at line 260 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::prefactor ( void  ) const
inline

Return pre factor.

Returns
Pre factor (ph/cm2/s/MeV).

Returns the pre factor.

Definition at line 186 of file GModelSpectralPlaw.hpp.

References m_norm, and GOptimizerPar::value().

void GModelSpectralPlaw::prefactor ( const double &  prefactor)
inline

Set pre factor.

Parameters
[in]prefactorPre factor (ph/cm2/s/MeV).

Sets the pre factor.

Definition at line 200 of file GModelSpectralPlaw.hpp.

References m_norm, and GOptimizerPar::value().

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

Print powerlaw information.

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

Implements GModelSpectral.

Definition at line 561 of file GModelSpectralPlaw.cpp.

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

void GModelSpectralPlaw::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.

Reads the spectral information from an XML element.

Implements GModelSpectral.

Definition at line 508 of file GModelSpectralPlaw.cpp.

References G_READ, index(), m_index, m_norm, m_pivot, GOptimizerPar::name(), norm(), pivot(), GModelPar::read(), gammalib::xml_check_parnum(), and gammalib::xml_get_par().

Referenced by GModelSpectralPlaw().

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

Return model type.

Returns
Model type.

Returns the type of the spectral power law model.

Implements GModelSpectral.

Definition at line 157 of file GModelSpectralPlaw.hpp.

References m_type.

Referenced by GModelSpectralPlaw(), type(), and write().

void GModelSpectralPlaw::type ( const std::string &  type)
inline

Set model type.

Parameters
[in]typeModel type.

Set the type of the spectral power law model.

Definition at line 171 of file GModelSpectralPlaw.hpp.

References m_type, and type().

void GModelSpectralPlaw::update_eval_cache ( const GEnergy energy) const
protected

Update eval precomputation cache.

Parameters
[in]energyEnergy.

Updates the precomputation cache for eval() method.

Definition at line 715 of file GModelSpectralPlaw.cpp.

References index(), log(), m_index, m_last_e_norm, m_last_energy, m_last_index, m_last_log_e_norm, m_last_pivot, m_last_power, m_pivot, GEnergy::MeV(), pivot(), pow(), and GOptimizerPar::value().

Referenced by eval().

void GModelSpectralPlaw::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.

Definition at line 754 of file GModelSpectralPlaw.cpp.

References index(), log(), m_mc_emax, m_mc_emin, m_mc_exponent, m_mc_pow_emin, m_mc_pow_ewidth, GEnergy::MeV(), and pow().

Referenced by mc().

void GModelSpectralPlaw::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element.

Writes the spectral information into an XML element.

Implements GModelSpectral.

Definition at line 535 of file GModelSpectralPlaw.cpp.

References G_WRITE, index(), m_index, m_norm, m_pivot, GOptimizerPar::name(), norm(), pivot(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().

Member Data Documentation

GModelPar GModelSpectralPlaw::m_index
protected
double GModelSpectralPlaw::m_last_e_norm
mutableprotected

Last E/Epivot value.

Definition at line 126 of file GModelSpectralPlaw.hpp.

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

GEnergy GModelSpectralPlaw::m_last_energy
mutableprotected

Last energy value.

Definition at line 122 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_last_index
mutableprotected

Last index parameter.

Definition at line 124 of file GModelSpectralPlaw.hpp.

Referenced by copy_members(), eval(), init_members(), and update_eval_cache().

double GModelSpectralPlaw::m_last_log_e_norm
mutableprotected

Last ln(E/Epivot) value.

Definition at line 127 of file GModelSpectralPlaw.hpp.

Referenced by copy_members(), eval(), init_members(), and update_eval_cache().

double GModelSpectralPlaw::m_last_norm
mutableprotected

Last norm parameter.

Definition at line 123 of file GModelSpectralPlaw.hpp.

Referenced by copy_members(), and init_members().

double GModelSpectralPlaw::m_last_pivot
mutableprotected

Last pivot parameter.

Definition at line 125 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_last_power
mutableprotected

Last power value.

Definition at line 128 of file GModelSpectralPlaw.hpp.

Referenced by copy_members(), eval(), init_members(), and update_eval_cache().

double GModelSpectralPlaw::m_mc_emax
mutableprotected

Maximum energy.

Definition at line 130 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_mc_emin
mutableprotected

Minimum energy.

Definition at line 129 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_mc_exponent
mutableprotected

Exponent (index+1)

Definition at line 131 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_mc_pow_emin
mutableprotected

Power of minimum energy.

Definition at line 132 of file GModelSpectralPlaw.hpp.

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

double GModelSpectralPlaw::m_mc_pow_ewidth
mutableprotected

Power of energy width.

Definition at line 133 of file GModelSpectralPlaw.hpp.

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

GModelPar GModelSpectralPlaw::m_norm
protected

Normalization factor.

Definition at line 117 of file GModelSpectralPlaw.hpp.

Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralPlaw(), init_members(), prefactor(), read(), and write().

GModelPar GModelSpectralPlaw::m_pivot
protected
std::string GModelSpectralPlaw::m_type
protected

Model type.

Definition at line 116 of file GModelSpectralPlaw.hpp.

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


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