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

Spectral nodes model class. More...

#include <GModelSpectralNodes.hpp>

Inheritance diagram for GModelSpectralNodes:
GModelSpectral GBase

Public Member Functions

 GModelSpectralNodes (void)
 Void constructor. More...
 
 GModelSpectralNodes (const GModelSpectral &model, const GEnergies &energies)
 Spectral model constructor. More...
 
 GModelSpectralNodes (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralNodes (const GModelSpectralNodes &model)
 Copy constructor. More...
 
virtual ~GModelSpectralNodes (void)
 Destructor. More...
 
virtual GModelSpectralNodesoperator= (const GModelSpectralNodes &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear spectral nodes model. More...
 
virtual GModelSpectralNodesclone (void) const
 Clone spectral nodes 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 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 node function information. More...
 
int nodes (void) const
 Return number of nodes. More...
 
void append (const GEnergy &energy, const double &intensity)
 Append node. More...
 
void insert (const int &index, const GEnergy &energy, const double &intensity)
 Insert node. More...
 
void remove (const int &index)
 Remove node. More...
 
void reserve (const int &num)
 Reserve space for nodes. More...
 
void extend (const GModelSpectralNodes &nodes)
 Append nodes from node function. More...
 
GEnergy energy (const int &index) const
 Return node energy. More...
 
void energy (const int &index, const GEnergy &energy)
 Set node energy. More...
 
double intensity (const int &index) const
 Return node intensity. More...
 
void intensity (const int &index, const double &intensity)
 Set node intensity. More...
 
double error (const int &index) const
 Return intensity error of node. 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 GModelSpectralNodes &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void update_pars (void)
 Update parameter mapping. More...
 
void set_cache (void) const
 Set pre-computation cache. More...
 
void set_eval_cache (void) const
 Set evaluation cache. More...
 
void set_flux_cache (void) const
 Set flux computation cache. More...
 
void update_eval_cache (void) const
 Update evaluation cache. More...
 
void update_flux_cache (void) const
 Update flux computation cache. More...
 
void mc_update (const GEnergy &emin, const GEnergy &emax) const
 Set MC 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::vector< GModelParm_energies
 Node energies. More...
 
std::vector< GModelParm_values
 Node values. More...
 
std::vector< double > m_old_energies
 Old energies. More...
 
std::vector< double > m_old_values
 Old values. More...
 
GNodeArray m_log_energies
 log10(energy) of nodes More...
 
std::vector< double > m_log_values
 log10(value) of nodes More...
 
GNodeArray m_lin_energies
 Energy of nodes. More...
 
std::vector< double > m_lin_values
 Values of nodes. More...
 
std::vector< double > m_prefactor
 Power-law normalisations. More...
 
std::vector< double > m_gamma
 Power-law indices. More...
 
std::vector< double > m_epivot
 Power-law pivot energies. More...
 
std::vector< double > m_flux
 Photon fluxes. More...
 
std::vector< double > m_eflux
 Energy fluxes. More...
 
GEnergy m_mc_emin
 Minimum energy. More...
 
GEnergy m_mc_emax
 Maximum energy. More...
 
std::vector< double > m_mc_cum
 Cumulative distribution. More...
 
std::vector< double > m_mc_min
 Lower boundary for MC. More...
 
std::vector< double > m_mc_max
 Upper boundary for MC. More...
 
std::vector< double > m_mc_exp
 Exponent for MC. More...
 
- Protected Attributes inherited from GModelSpectral
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Spectral nodes model class.

This class implements a piecewise power law between spectral nodes

\[ ({\tt m\_energies[i]}, {\tt m\_values[i]}) \]

where

  • \({\tt m\_energies[i]}\) is the energy, and
  • \({\tt m\_values[i]}\) is the intensity (in photons/cm2/s/MeV) of node \(i\).

For a given energy \(E\), the piecewise power law is computing by finding the bracketing energies \({\tt m\_energies[i]} <= E <= {\tt m\_energies[i+1]}\) and computing

\[ S_{\rm E}(E | t) = 10^{(\log {\tt m\_values[i]}) w_{i} + (\log {\tt m\_values[i+1]}) w_{i+1}} \]

where

  • \({\tt m\_values[i]}\) is the intensity of node \(i\),
  • \({\tt m\_values[i+1]}\) is the intensity of node \(i+1\),
  • \(w_{i}\) is the weighting of node \(i\), and
  • \(w_{i+1}\) is the weighting of node \(i+1\).

The weightings \(w_{i}\) and \(w_{i+1}\) are computed by linear interpolation (in the log-log plane) between the nodes \((\log {\tt m\_energies[i]}, \log{\tt m\_values[i]})\) and \((\log {\tt m\_energies[i+1]}, \log{\tt m\_values[i+1]})\) to the requested energy \(\log E\).

Definition at line 84 of file GModelSpectralNodes.hpp.

Constructor & Destructor Documentation

GModelSpectralNodes::GModelSpectralNodes ( void  )

Void constructor.

Constructs an empty spectral node model.

Definition at line 78 of file GModelSpectralNodes.cpp.

References init_members().

Referenced by clone().

GModelSpectralNodes::GModelSpectralNodes ( const GModelSpectral model,
const GEnergies energies 
)

Spectral model constructor.

Parameters
[in]modelSpectral model.
[in]energiesNode energies.

Constructs a spectral node model from any spectral model.

Definition at line 96 of file GModelSpectralNodes.cpp.

References append(), GModelSpectral::eval(), init_members(), reserve(), and GEnergies::size().

GModelSpectralNodes::GModelSpectralNodes ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Construct spectral nodes 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 125 of file GModelSpectralNodes.cpp.

References init_members(), and read().

GModelSpectralNodes::GModelSpectralNodes ( const GModelSpectralNodes model)

Copy constructor.

Parameters
[in]modelSpectral nodes model.

Definition at line 144 of file GModelSpectralNodes.cpp.

References copy_members(), and init_members().

GModelSpectralNodes::~GModelSpectralNodes ( void  )
virtual

Destructor.

Definition at line 161 of file GModelSpectralNodes.cpp.

References free_members().

Member Function Documentation

void GModelSpectralNodes::append ( const GEnergy energy,
const double &  intensity 
)

Append node.

Parameters
[in]energyNode energy.
[in]intensityNode intensity.
Exceptions
GException::invalid_argumentNon-positive energy or intensity specified.

Appends one node to the node function. By default the energy of the node is fixed while the intensity of the node is free.

Definition at line 801 of file GModelSpectralNodes.cpp.

References GOptimizerPar::fix(), GOptimizerPar::free(), G_APPEND, GOptimizerPar::has_grad(), m_energies, m_values, GEnergy::MeV(), GOptimizerPar::name(), GEnergy::print(), set_cache(), gammalib::str(), GOptimizerPar::unit(), update_pars(), and GOptimizerPar::value().

Referenced by GModelSpectralNodes(), GCTABackgroundPerfTable::init_mc_cache(), GCTABackground3D::init_mc_cache(), GCTABackground2D::init_mc_cache(), GModelSpatialDiffuseCube::mc_cone(), GModelSpectralExponential::update_mc_cache(), and GModelSpectralMultiplicative::update_mc_cache().

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

Return class name.

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

Implements GModelSpectral.

Definition at line 179 of file GModelSpectralNodes.hpp.

GModelSpectralNodes * GModelSpectralNodes::clone ( void  ) const
virtual

Clone spectral nodes model.

Implements GModelSpectral.

Definition at line 234 of file GModelSpectralNodes.cpp.

References GModelSpectralNodes().

void GModelSpectralNodes::copy_members ( const GModelSpectralNodes model)
protected

Copy class members.

Parameters
[in]modelSpectral function model.

Definition at line 1288 of file GModelSpectralNodes.cpp.

References m_eflux, m_energies, m_epivot, m_flux, m_gamma, m_lin_energies, m_lin_values, m_log_energies, m_log_values, m_mc_cum, m_mc_emax, m_mc_emin, m_mc_exp, m_mc_max, m_mc_min, m_old_energies, m_old_values, m_prefactor, m_values, and update_pars().

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

double GModelSpectralNodes::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).

Implements GModelSpectral.

Definition at line 446 of file GModelSpectralNodes.cpp.

References GNodeArray::inx_left(), m_eflux, m_epivot, m_gamma, m_lin_energies, m_prefactor, GEnergy::MeV(), gammalib::MeV2erg, gammalib::plaw_energy_flux(), GNodeArray::set_value(), and update_flux_cache().

Referenced by GModelSky::eflux(), and set_flux_cache().

GEnergy GModelSpectralNodes::energy ( const int &  index) const

Return node energy.

Parameters
[in]indexNode index [0,...,nodes()[.
Returns
Energy of node index.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns the energy of node index.

Definition at line 1037 of file GModelSpectralNodes.cpp.

References G_ENERGY_GET, m_energies, GEnergy::MeV(), and nodes().

Referenced by GModelSky::eflux(), GModelSky::flux(), GCTABackground3D::mc(), GCTABackground2D::mc(), mc(), GModelSky::mc(), GModelSpatialDiffuseCube::mc_cone(), read(), update_eval_cache(), and write().

void GModelSpectralNodes::energy ( const int &  index,
const GEnergy energy 
)

Set node energy.

Parameters
[in]indexNode index [0,...,nodes()[.
[in]energyNode energy.
Exceptions
GException::out_of_rangeIndex is out of range.
GException::invalid_argumentNon-positive energy specified.

Sets the energy of node index.

Definition at line 1069 of file GModelSpectralNodes.cpp.

References G_ENERGY_SET, m_energies, GEnergy::MeV(), nodes(), GEnergy::print(), and set_cache().

double GModelSpectralNodes::error ( const int &  index) const

Return intensity error of node.

Parameters
[in]indexNode index [0,...,nodes()[.
Returns
Intensity error of node index.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns the intensity error of node index.

Definition at line 1134 of file GModelSpectralNodes.cpp.

References G_ERROR_GET, m_values, and nodes().

double GModelSpectralNodes::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).

Computes

\[ S_{\rm E}(E | t) = 10^{(\log {\tt m\_values[i]}) w_{i} + (\log {\tt m\_values[i+1]}) w_{i+1}} \]

where

  • \({\tt m\_values[i]}\) is the intensity of node \(i\),
  • \({\tt m\_values[i+1]}\) is the intensity of node \(i+1\),
  • \(w_{i}\) is the weighting of node \(i\),
  • \(w_{i+1}\) is the weighting of node \(i+1\), and
  • \({\tt m\_energies[i]} <= E <= {\tt m\_energies[i+1]}\).

The weightings \(w_{i}\) and \(w_{i+1}\) are computed by linear interpolation (in the log-log plane) between the nodes \((\log {\tt m\_energies[i]}, \log{\tt m\_values[i]})\) and \((\log {\tt m\_energies[i+1]}, \log{\tt m\_values[i+1]})\) to the requested energy \(\log E\).

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\_values[i]}} = \frac{S_{\rm E}(E | t) \, w_i}{{\tt m\_values[i]}} \]

Implements GModelSpectral.

Definition at line 279 of file GModelSpectralNodes.cpp.

References GNodeArray::inx_left(), GNodeArray::inx_right(), gammalib::is_infinite(), gammalib::is_notanumber(), GEnergy::log10MeV(), m_log_energies, m_log_values, m_values, pow(), GNodeArray::set_value(), update_eval_cache(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().

void GModelSpectralNodes::extend ( const GModelSpectralNodes nodes)

Append nodes from node function.

Parameters
[in]nodesNode function.

Appends all nodes from a node function to current object.

Definition at line 994 of file GModelSpectralNodes.cpp.

References m_energies, m_values, nodes(), reserve(), set_cache(), and update_pars().

double GModelSpectralNodes::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).

Implements GModelSpectral.

Definition at line 359 of file GModelSpectralNodes.cpp.

References GNodeArray::inx_left(), m_epivot, m_flux, m_gamma, m_lin_energies, m_prefactor, GEnergy::MeV(), gammalib::plaw_photon_flux(), GNodeArray::set_value(), and update_flux_cache().

Referenced by GModelSky::flux(), mc_update(), and set_flux_cache().

void GModelSpectralNodes::free_members ( void  )
protected

Delete class members.

Definition at line 1328 of file GModelSpectralNodes.cpp.

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

void GModelSpectralNodes::init_members ( void  )
protected
void GModelSpectralNodes::insert ( const int &  index,
const GEnergy energy,
const double &  intensity 
)

Insert node.

Parameters
[in]indexNode index [0,...,nodes()[.
[in]energyNode energy.
[in]intensityNode intensity.
Exceptions
GException::out_of_rangeNode index is out of range.
GException::invalid_argumentNon-positive energy or intensity specified.

Inserts a node into the node function before the node with the specified index. By default the energy of the node is fixed while the intensity of the node is free.

Definition at line 867 of file GModelSpectralNodes.cpp.

References GOptimizerPar::fix(), GOptimizerPar::free(), G_INSERT, GOptimizerPar::has_grad(), m_energies, m_values, GEnergy::MeV(), GOptimizerPar::name(), nodes(), GEnergy::print(), set_cache(), gammalib::str(), GOptimizerPar::unit(), update_pars(), and GOptimizerPar::value().

double GModelSpectralNodes::intensity ( const int &  index) const

Return node intensity.

Parameters
[in]indexNode index [0,...,nodes()[.
Returns
Intensity of node index.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns the intensity of node index.

Definition at line 1108 of file GModelSpectralNodes.cpp.

References G_INTENSITY_GET, m_values, and nodes().

Referenced by GModelSky::eflux(), GModelSky::flux(), GModelSky::mc(), GModelSpatialDiffuseCube::mc_cone(), GModelSpatialDiffuseCube::print(), read(), and write().

void GModelSpectralNodes::intensity ( const int &  index,
const double &  intensity 
)

Set node intensity.

Parameters
[in]indexNode index [0,...,nodes()[.
[in]intensityNode Intensity.
Exceptions
GException::out_of_rangeIndex is out of range.
GException::invalid_argumentNon-positive intensity specified.

Set the intensity of node index.

Definition at line 1162 of file GModelSpectralNodes.cpp.

References G_INSERT, G_INTENSITY_SET, m_values, nodes(), set_cache(), and gammalib::str().

GEnergy GModelSpectralNodes::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::invalid_return_valueNo valid Monte Carlo cache

Returns Monte Carlo energy by randomly drawing from node function.

Implements GModelSpectral.

Definition at line 534 of file GModelSpectralNodes.cpp.

References gammalib::check_energy_interval(), energy(), exp(), G_MC, log(), m_mc_cum, m_mc_exp, m_mc_max, m_mc_min, mc_update(), GEnergy::MeV(), GEnergy::print(), and GRan::uniform().

Referenced by GModelSpectralMultiplicative::mc(), and GModelSpectralExponential::mc().

void GModelSpectralNodes::mc_update ( const GEnergy emin,
const GEnergy emax 
) const
protected

Set MC pre-computation cache.

Parameters
[in]eminMinimum energy.
[in]emaxMaximum energy.

This method sets up an array of indices and the cumulative distribution function needed for MC simulations.

Definition at line 1564 of file GModelSpectralNodes.cpp.

References abs(), flux(), GNodeArray::inx_left(), log(), m_epivot, m_flux, m_gamma, m_lin_energies, m_mc_cum, m_mc_emax, m_mc_emin, m_mc_exp, m_mc_max, m_mc_min, m_prefactor, GEnergy::MeV(), norm(), gammalib::plaw_photon_flux(), pow(), and GNodeArray::set_value().

Referenced by mc().

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

Assignment operator.

Parameters
[in]modelSpectral nodes model.
Returns
Spectral nodes model.

Definition at line 183 of file GModelSpectralNodes.cpp.

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

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

Print node function information.

Parameters
[in]chatterChattiness.
Returns
String containing node function information.

Implements GModelSpectral.

Definition at line 1198 of file GModelSpectralNodes.cpp.

References m_eflux, m_energies, m_epivot, m_flux, m_gamma, GModelSpectral::m_pars, m_prefactor, gammalib::parformat(), SILENT, GModelSpectral::size(), gammalib::str(), and VERBOSE.

void GModelSpectralNodes::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.
Exceptions
GException::invalid_valueNot enough nodes in node function.
GException::invalid_valueEnergy or intensity are not positive.

Reads the spectral information from an XML element. The format of the XML elements is

<spectrum type="NodeFunction">
  <node>
    <parameter name="Energy"    ../>
    <parameter name="Intensity" ../>
  </node>
  ...
  <node>
    <parameter name="Energy"    ../>
    <parameter name="Intensity" ../>
  </node>
</spectrum>
Todo:

Check that nodes are ordered

Check that energy boundaries are not overlapping

Check whether we require at least one or two nodes

Implements GModelSpectral.

Definition at line 620 of file GModelSpectralNodes.cpp.

References GXmlNode::element(), GXmlNode::elements(), energy(), G_READ, GOptimizerPar::has_grad(), intensity(), m_energies, m_values, GOptimizerPar::name(), nodes(), GModelPar::read(), set_cache(), gammalib::str(), GOptimizerPar::unit(), update_pars(), GOptimizerPar::value(), and gammalib::xml_get_par().

Referenced by GModelSpectralNodes().

void GModelSpectralNodes::remove ( const int &  index)

Remove node.

Parameters
[in]indexNode index [0,...,nodes()[.
Exceptions
GException::out_of_rangeNode index is out of range.

Removes node of specified index from the node function.

Definition at line 944 of file GModelSpectralNodes.cpp.

References G_REMOVE, m_energies, m_values, nodes(), set_cache(), and update_pars().

void GModelSpectralNodes::reserve ( const int &  num)

Reserve space for nodes.

Parameters
[in]numNumber of reseved nodes.

Reserves space for num nodes.

Definition at line 976 of file GModelSpectralNodes.cpp.

References m_energies, and m_values.

Referenced by extend(), GModelSpectralNodes(), and GModelSpatialDiffuseCube::mc_cone().

void GModelSpectralNodes::set_cache ( void  ) const
protected

Set pre-computation cache.

Definition at line 1382 of file GModelSpectralNodes.cpp.

References set_eval_cache(), and set_flux_cache().

Referenced by append(), energy(), extend(), insert(), intensity(), read(), and remove().

void GModelSpectralNodes::set_eval_cache ( void  ) const
protected

Set evaluation cache.

The evaluation cache contains pre-computed results that are needed for fast function evaluation.

Todo:
Check that all energies and intensities are > 0

Definition at line 1403 of file GModelSpectralNodes.cpp.

References GNodeArray::append(), GNodeArray::clear(), log10(), m_energies, m_log_energies, m_log_values, m_old_energies, m_old_values, and m_values.

Referenced by set_cache().

void GModelSpectralNodes::set_flux_cache ( void  ) const
protected

Set flux computation cache.

Pre-computes some values that are needed for flux computation.

Todo:
Handle special case emin=emax and fmin=fmax

Definition at line 1438 of file GModelSpectralNodes.cpp.

References GNodeArray::append(), GNodeArray::clear(), eflux(), flux(), log(), m_eflux, m_energies, m_epivot, m_flux, m_gamma, m_lin_energies, m_lin_values, m_prefactor, m_values, gammalib::MeV2erg, gammalib::plaw_energy_flux(), gammalib::plaw_photon_flux(), pow(), and sqrt().

Referenced by set_cache(), and update_flux_cache().

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

Return model type.

Returns
"NodeFunction".

Returns the type of the spectral node function model.

Implements GModelSpectral.

Definition at line 193 of file GModelSpectralNodes.hpp.

Referenced by write().

void GModelSpectralNodes::update_eval_cache ( void  ) const
protected

Update evaluation cache.

Updates the evaluation cache by computing only results for values that changed.

Todo:
Check that all energies and intensities are > 0

Definition at line 1507 of file GModelSpectralNodes.cpp.

References energy(), log10(), m_energies, m_log_energies, m_log_values, m_old_energies, m_old_values, and m_values.

Referenced by eval().

void GModelSpectralNodes::update_flux_cache ( void  ) const
protected

Update flux computation cache.

Updates the flux computation cache if either the energy boundaries or the intensity values have changed.

Definition at line 1538 of file GModelSpectralNodes.cpp.

References m_energies, m_lin_energies, m_lin_values, m_values, and set_flux_cache().

Referenced by eflux(), and flux().

void GModelSpectralNodes::update_pars ( void  )
protected

Update parameter mapping.

Sets the parameter pointers in the m_pars array, enabling iterating over all model parameters. This method needs to be called after changing the number of nodes in the spectral model. The method needs not to be called after value update.

Definition at line 1343 of file GModelSpectralNodes.cpp.

References m_energies, GModelSpectral::m_pars, m_values, nodes(), and gammalib::str().

Referenced by append(), copy_members(), extend(), init_members(), insert(), read(), and remove().

void GModelSpectralNodes::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element into which model information is written.
Exceptions
GException::invalid_valueInvalid number of nodes found in XML element.

Writes the spectral information into an XML element. The format of the XML element is

<spectrum type="NodeFunction">
  <node>
    <parameter name="Energy"    ../>
    <parameter name="Intensity" ../>
  </node>
  ...
  <node>
    <parameter name="Energy"    ../>
    <parameter name="Intensity" ../>
  </node>
</spectrum>

Implements GModelSpectral.

Definition at line 726 of file GModelSpectralNodes.cpp.

References GXmlNode::append(), GXmlNode::element(), GXmlNode::elements(), energy(), G_WRITE, intensity(), m_energies, m_values, GOptimizerPar::name(), nodes(), gammalib::str(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().

Member Data Documentation

std::vector<double> GModelSpectralNodes::m_eflux
mutableprotected

Energy fluxes.

Definition at line 161 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), eflux(), init_members(), print(), and set_flux_cache().

std::vector<GModelPar> GModelSpectralNodes::m_energies
protected
std::vector<double> GModelSpectralNodes::m_epivot
mutableprotected

Power-law pivot energies.

Definition at line 159 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), eflux(), flux(), init_members(), mc_update(), print(), and set_flux_cache().

std::vector<double> GModelSpectralNodes::m_flux
mutableprotected

Photon fluxes.

Definition at line 160 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), flux(), init_members(), mc_update(), print(), and set_flux_cache().

std::vector<double> GModelSpectralNodes::m_gamma
mutableprotected

Power-law indices.

Definition at line 158 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), eflux(), flux(), init_members(), mc_update(), print(), and set_flux_cache().

GNodeArray GModelSpectralNodes::m_lin_energies
mutableprotected

Energy of nodes.

Definition at line 155 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), eflux(), flux(), init_members(), mc_update(), set_flux_cache(), and update_flux_cache().

std::vector<double> GModelSpectralNodes::m_lin_values
mutableprotected

Values of nodes.

Definition at line 156 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), init_members(), set_flux_cache(), and update_flux_cache().

GNodeArray GModelSpectralNodes::m_log_energies
mutableprotected

log10(energy) of nodes

Definition at line 151 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_log_values
mutableprotected

log10(value) of nodes

Definition at line 152 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_mc_cum
mutableprotected

Cumulative distribution.

Definition at line 166 of file GModelSpectralNodes.hpp.

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

GEnergy GModelSpectralNodes::m_mc_emax
mutableprotected

Maximum energy.

Definition at line 165 of file GModelSpectralNodes.hpp.

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

GEnergy GModelSpectralNodes::m_mc_emin
mutableprotected

Minimum energy.

Definition at line 164 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_mc_exp
mutableprotected

Exponent for MC.

Definition at line 169 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_mc_max
mutableprotected

Upper boundary for MC.

Definition at line 168 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_mc_min
mutableprotected

Lower boundary for MC.

Definition at line 167 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_old_energies
mutableprotected

Old energies.

Definition at line 149 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_old_values
mutableprotected

Old values.

Definition at line 150 of file GModelSpectralNodes.hpp.

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

std::vector<double> GModelSpectralNodes::m_prefactor
mutableprotected

Power-law normalisations.

Definition at line 157 of file GModelSpectralNodes.hpp.

Referenced by copy_members(), eflux(), flux(), init_members(), mc_update(), print(), and set_flux_cache().

std::vector<GModelPar> GModelSpectralNodes::m_values
protected

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