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

Constant spectral model class. More...

#include <GModelSpectralConst.hpp>

Inheritance diagram for GModelSpectralConst:
GModelSpectral GBase

Public Member Functions

 GModelSpectralConst (void)
 Void constructor. More...
 
 GModelSpectralConst (const std::string &type, const std::string &value)
 Model type and parameter name constructor. More...
 
 GModelSpectralConst (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpectralConst (const double &value)
 Value constructor. More...
 
 GModelSpectralConst (const GModelSpectralConst &model)
 Copy constructor. More...
 
virtual ~GModelSpectralConst (void)
 Destructor. More...
 
virtual GModelSpectralConstoperator= (const GModelSpectralConst &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear constant spectral model. More...
 
virtual GModelSpectralConstclone (void) const
 Clone constant 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...
 
void type (const std::string &type)
 Set model type. More...
 
double value (void) const
 Return model value. More...
 
void value (const double &value)
 Set model value. 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 GModelSpectralConst &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. 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...
 
- Protected Attributes inherited from GModelSpectral
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Constant spectral model class.

This class implements a constant spectrum. The model is defined by

\[ S_{\rm E}(E | t) = {\tt m\_norm} \]

where \({\tt m\_norm}\) is the normalization constant in units of ph/cm2/s/MeV.

Definition at line 57 of file GModelSpectralConst.hpp.

Constructor & Destructor Documentation

GModelSpectralConst::GModelSpectralConst ( void  )

Void constructor.

Definition at line 70 of file GModelSpectralConst.cpp.

References init_members().

Referenced by clone().

GModelSpectralConst::GModelSpectralConst ( const std::string &  type,
const std::string &  value 
)

Model type and parameter name constructor.

Parameters
[in]typeModel type.
[in]valueName of value parameter.

Definition at line 86 of file GModelSpectralConst.cpp.

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

GModelSpectralConst::GModelSpectralConst ( 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 113 of file GModelSpectralConst.cpp.

References init_members(), and read().

GModelSpectralConst::GModelSpectralConst ( const double &  value)
explicit

Value constructor.

Parameters
[in]valueModel value (ph/cm2/s/MeV).

Constructs constant spectral model by setting the model value.

Definition at line 134 of file GModelSpectralConst.cpp.

References init_members(), m_norm, and GOptimizerPar::value().

GModelSpectralConst::GModelSpectralConst ( const GModelSpectralConst model)

Copy constructor.

Parameters
[in]modelSpectral constant model.

Definition at line 153 of file GModelSpectralConst.cpp.

References copy_members(), and init_members().

GModelSpectralConst::~GModelSpectralConst ( void  )
virtual

Destructor.

Definition at line 170 of file GModelSpectralConst.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GModelSpectral.

Definition at line 114 of file GModelSpectralConst.hpp.

void GModelSpectralConst::clear ( void  )
virtual

Clear constant spectral model.

Implements GModelSpectral.

Definition at line 225 of file GModelSpectralConst.cpp.

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

GModelSpectralConst * GModelSpectralConst::clone ( void  ) const
virtual

Clone constant spectral model.

Returns
Pointer to deep copy of constant spectral model.

Implements GModelSpectral.

Definition at line 245 of file GModelSpectralConst.cpp.

References GModelSpectralConst().

void GModelSpectralConst::copy_members ( const GModelSpectralConst model)
protected

Copy class members.

Parameters
[in]modelSpectral constant model.

Definition at line 527 of file GModelSpectralConst.cpp.

References m_norm, GModelSpectral::m_pars, and m_type.

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

double GModelSpectralConst::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 355 of file GModelSpectralConst.cpp.

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

double GModelSpectralConst::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) = {\tt m\_norm} \]

where \({\tt m\_norm}\) is the normalization constant in units of ph/cm2/s/MeV.

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}} = 1 \]

Implements GModelSpectral.

Definition at line 277 of file GModelSpectralConst.cpp.

References GOptimizerPar::factor_gradient(), GOptimizerPar::is_free(), m_norm, GOptimizerPar::scale(), value(), and GOptimizerPar::value().

double GModelSpectralConst::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 318 of file GModelSpectralConst.cpp.

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

void GModelSpectralConst::free_members ( void  )
protected

Delete class members.

Definition at line 545 of file GModelSpectralConst.cpp.

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

GEnergy GModelSpectralConst::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.

Returns Monte Carlo energy by randomly drawing from a constant between the minimum and maximum photon energy.

Implements GModelSpectral.

Definition at line 390 of file GModelSpectralConst.cpp.

References gammalib::check_energy_interval(), G_MC, GEnergy::MeV(), and GRan::uniform().

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

Assignment operator.

Parameters
[in]modelConstant spectral model.
Returns
Constant spectral model.

Definition at line 192 of file GModelSpectralConst.cpp.

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

std::string GModelSpectralConst::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 464 of file GModelSpectralConst.cpp.

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

void GModelSpectralConst::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 419 of file GModelSpectralConst.cpp.

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

Referenced by GModelSpectralConst().

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

Return model type.

Returns
Model type.

Returns the type of the constant spectral model.

Implements GModelSpectral.

Definition at line 128 of file GModelSpectralConst.hpp.

References m_type.

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

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

Set model type.

Parameters
[in]typeModel type.

Set the type of the constant spectral model.

Definition at line 142 of file GModelSpectralConst.hpp.

References m_type, and type().

double GModelSpectralConst::value ( void  ) const
inline

Return model value.

Returns
Model value (ph/cm2/s/MeV).

Returns the model value.

Definition at line 157 of file GModelSpectralConst.hpp.

References m_norm, and GOptimizerPar::value().

Referenced by eval().

void GModelSpectralConst::value ( const double &  value)
inline

Set model value.

Parameters
[in]valueModel value (ph/cm2/s/MeV).

Sets the model value.

Definition at line 171 of file GModelSpectralConst.hpp.

References m_norm, and GOptimizerPar::value().

void GModelSpectralConst::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 442 of file GModelSpectralConst.cpp.

References G_WRITE, m_norm, GOptimizerPar::name(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().

Member Data Documentation

GModelPar GModelSpectralConst::m_norm
protected

Normalization factor.

Definition at line 104 of file GModelSpectralConst.hpp.

Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralConst(), init_members(), read(), value(), and write().

std::string GModelSpectralConst::m_type
protected

Model type.

Definition at line 103 of file GModelSpectralConst.hpp.

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


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