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

Multiplicative spectral model class. More...

#include <GModelSpectralMultiplicative.hpp>

Inheritance diagram for GModelSpectralMultiplicative:
GModelSpectral GBase

Classes

class  eflux_kern
 
class  flux_kern
 

Public Member Functions

 GModelSpectralMultiplicative (void)
 Void constructor. More...
 
 GModelSpectralMultiplicative (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralMultiplicative (const GModelSpectralMultiplicative &model)
 Copy constructor. More...
 
virtual ~GModelSpectralMultiplicative (void)
 Destructor. More...
 
virtual
GModelSpectralMultiplicative
operator= (const GModelSpectralMultiplicative &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear multiplicative spectral model. More...
 
virtual
GModelSpectralMultiplicative
clone (void) const
 Clone multiplicative 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 multiplicative spectral model information. More...
 
void append (const GModelSpectral &spec, const std::string &name="")
 Append spectral component. More...
 
int components (void) const
 Return number of spectral components. More...
 
const GModelSpectralcomponent (const int &index) const
 Return spectral model component by index. More...
 
const GModelSpectralcomponent (const std::string &name) const
 Return spectral model component by name. 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 GModelSpectralMultiplicative &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...
 
std::vector< GModelSpectral * > m_spectral
 Container of spectral models. More...
 
std::vector< std::string > m_components
 Names of components. 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

Multiplicative spectral model class.

This class implements a spectral model that is a multiplication spectral model components. The spectral model components can be defined in an XML file, or added using the append() method.

Definition at line 53 of file GModelSpectralMultiplicative.hpp.

Constructor & Destructor Documentation

GModelSpectralMultiplicative::GModelSpectralMultiplicative ( void  )

Void constructor.

Definition at line 73 of file GModelSpectralMultiplicative.cpp.

References init_members().

Referenced by clone().

GModelSpectralMultiplicative::GModelSpectralMultiplicative ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element containing spectral model information.

Constructs a multiplicative 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 93 of file GModelSpectralMultiplicative.cpp.

References init_members(), and read().

GModelSpectralMultiplicative::GModelSpectralMultiplicative ( const GModelSpectralMultiplicative model)

Copy constructor.

Parameters
[in]modelMultiplicative spectral model.

Definition at line 112 of file GModelSpectralMultiplicative.cpp.

References copy_members(), and init_members().

GModelSpectralMultiplicative::~GModelSpectralMultiplicative ( void  )
virtual

Destructor.

Definition at line 129 of file GModelSpectralMultiplicative.cpp.

References free_members().

Member Function Documentation

void GModelSpectralMultiplicative::append ( const GModelSpectral spec,
const std::string &  name = "" 
)

Append spectral component.

Parameters
[in]specSpectral model component.
[in]nameName of spectral component (can be empty).
Exceptions
GException::invalid_valueInvalid component name specified

Appends a spectral component to the Multiplicative model

Definition at line 540 of file GModelSpectralMultiplicative.cpp.

References GModelSpectral::clone(), gammalib::contains(), G_APPEND, m_components, GModelSpectral::m_pars, m_spectral, GOptimizerPar::name(), and gammalib::str().

Referenced by read().

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

Return class name.

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

Implements GModelSpectral.

Definition at line 150 of file GModelSpectralMultiplicative.hpp.

void GModelSpectralMultiplicative::clear ( void  )
virtual

Clear multiplicative spectral model.

Implements GModelSpectral.

Definition at line 184 of file GModelSpectralMultiplicative.cpp.

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

GModelSpectralMultiplicative * GModelSpectralMultiplicative::clone ( void  ) const
virtual

Clone multiplicative spectral model model.

Returns
Pointer to deep copy of multiplicative spectral model.

Implements GModelSpectral.

Definition at line 204 of file GModelSpectralMultiplicative.cpp.

References GModelSpectralMultiplicative().

const GModelSpectral * GModelSpectralMultiplicative::component ( const int &  index) const

Return spectral model component by index.

Parameters
[in]indexIndex of spectral component.
Returns
Pointer to spectral model.

Returns a component of the multiplicative spectral model by index.

Definition at line 597 of file GModelSpectralMultiplicative.cpp.

References G_COMPONENT_INDEX, and m_spectral.

const GModelSpectral * GModelSpectralMultiplicative::component ( const std::string &  name) const

Return spectral model component by name.

Parameters
[in]nameName of spectral component.
Returns
Pointer to spectral model.
Exceptions
GException::invalid_argumentModel component not found.

Returns a component of the multiplicative spectral model by name.

Definition at line 621 of file GModelSpectralMultiplicative.cpp.

References G_COMPONENT_NAME, m_components, and m_spectral.

int GModelSpectralMultiplicative::components ( void  ) const
inline

Return number of spectral components.

Returns
Number of model components.

Returns the number of spectral components.

Definition at line 178 of file GModelSpectralMultiplicative.hpp.

References m_spectral.

Referenced by copy_members(), and print().

void GModelSpectralMultiplicative::copy_members ( const GModelSpectralMultiplicative model)
protected

Copy class members.

Parameters
[in]modelMultiplicative spectral model.

Definition at line 713 of file GModelSpectralMultiplicative.cpp.

References components(), m_components, m_mc_emax, m_mc_emin, m_mc_spectrum, m_mc_values, GModelSpectral::m_pars, m_spectral, m_type, and GModelSpectral::size().

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

double GModelSpectralMultiplicative::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 multiplicative spectral model

Implements GModelSpectral.

Definition at line 355 of file GModelSpectralMultiplicative.cpp.

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

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

\[ \prod_{i=0}^{N} {M_{\rm i}}(\rm srcEng, srcTime) \]

where \({M_{\rm i}}\) is the i-th model component.

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

\[ \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k} \]

where \({P_{\rm ij}}\) is the j-th parameter of the i-th multiplicative component, while \({M_{\rm k}}\) is the k-th model component and n the number of model components.

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

Implements GModelSpectral.

Definition at line 241 of file GModelSpectralMultiplicative.cpp.

References GOptimizerPar::gradient(), gammalib::is_infinite(), gammalib::is_notanumber(), and m_spectral.

Referenced by update_mc_cache().

double GModelSpectralMultiplicative::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 multiplicative spectral model

Implements GModelSpectral.

Definition at line 318 of file GModelSpectralMultiplicative.cpp.

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

void GModelSpectralMultiplicative::free_members ( void  )
protected

Delete class members.

Definition at line 757 of file GModelSpectralMultiplicative.cpp.

References m_spectral.

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

void GModelSpectralMultiplicative::init_members ( void  )
protected
GEnergy GModelSpectralMultiplicative::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 multiplicative spectral model.

Implements GModelSpectral.

Definition at line 395 of file GModelSpectralMultiplicative.cpp.

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

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

Assignment operator.

Parameters
[in]modelMultiplicative spectral model.
Returns
Multiplicative spectral model.

Definition at line 151 of file GModelSpectralMultiplicative.cpp.

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

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

Print multiplicative spectral model information.

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

Implements GModelSpectral.

Definition at line 650 of file GModelSpectralMultiplicative.cpp.

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

void GModelSpectralMultiplicative::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 428 of file GModelSpectralMultiplicative.cpp.

References GModelSpectralRegistry::alloc(), append(), GXmlElement::attribute(), GXmlNode::element(), and GXmlNode::elements().

Referenced by GModelSpectralMultiplicative().

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

Return model type.

Returns
Model type.

Returns the type of the spectral Multiplicative model.

Implements GModelSpectral.

Definition at line 164 of file GModelSpectralMultiplicative.hpp.

References m_type.

Referenced by write().

void GModelSpectralMultiplicative::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 multiplicative 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 788 of file GModelSpectralMultiplicative.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 GModelSpectralMultiplicative::write ( GXmlElement xml) const
virtual

Member Data Documentation

std::vector<std::string> GModelSpectralMultiplicative::m_components
protected

Names of components.

Definition at line 134 of file GModelSpectralMultiplicative.hpp.

Referenced by append(), component(), copy_members(), init_members(), and write().

GEnergy GModelSpectralMultiplicative::m_mc_emax
mutableprotected

Last maximum energy.

Definition at line 139 of file GModelSpectralMultiplicative.hpp.

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

GEnergy GModelSpectralMultiplicative::m_mc_emin
mutableprotected

Last minimum energy.

Definition at line 138 of file GModelSpectralMultiplicative.hpp.

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

GModelSpectralNodes GModelSpectralMultiplicative::m_mc_spectrum
mutableprotected

MC spectrum cache.

Definition at line 137 of file GModelSpectralMultiplicative.hpp.

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

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

Parameter values.

Definition at line 140 of file GModelSpectralMultiplicative.hpp.

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

std::vector<GModelSpectral*> GModelSpectralMultiplicative::m_spectral
protected

Container of spectral models.

Definition at line 133 of file GModelSpectralMultiplicative.hpp.

Referenced by append(), component(), components(), copy_members(), eflux(), eval(), flux(), free_members(), init_members(), mc(), and write().

std::string GModelSpectralMultiplicative::m_type
protected

Model type.

Definition at line 132 of file GModelSpectralMultiplicative.hpp.

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


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