GammaLib
2.0.0
|
Constant spectral model class. More...
#include <GModelSpectralConst.hpp>
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 GModelSpectralConst & | operator= (const GModelSpectralConst &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear constant spectral model. More... | |
virtual GModelSpectralConst * | clone (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 GModelSpectral & | operator= (const GModelSpectral &model) |
Assignment operator. More... | |
virtual GModelPar & | operator[] (const int &index) |
Returns model parameter. More... | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns model parameter (const version) More... | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns reference to model parameter. More... | |
virtual const GModelPar & | operator[] (const std::string &name) const |
Returns reference to model parameter (const version) More... | |
GModelPar & | at (const int &index) |
Returns model parameter. More... | |
const GModelPar & | at (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... | |
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.
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.
[in] | type | Model type. |
[in] | value | Name of value parameter. |
Definition at line 86 of file GModelSpectralConst.cpp.
References init_members(), m_norm, m_type, GOptimizerPar::name(), and type().
|
explicit |
XML constructor.
[in] | xml | XML 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().
|
explicit |
Value constructor.
[in] | value | Model 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.
[in] | model | Spectral constant model. |
Definition at line 153 of file GModelSpectralConst.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 114 of file GModelSpectralConst.hpp.
|
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().
|
virtual |
Clone constant spectral model.
Implements GModelSpectral.
Definition at line 245 of file GModelSpectralConst.cpp.
References GModelSpectralConst().
|
protected |
Copy class members.
[in] | model | Spectral constant model. |
Definition at line 527 of file GModelSpectralConst.cpp.
References m_norm, GModelSpectral::m_pars, and m_type.
Referenced by GModelSpectralConst(), and operator=().
Returns model energy flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes
\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE \]
where
emin
, emax
] is an energy interval, andImplements GModelSpectral.
Definition at line 355 of file GModelSpectralConst.cpp.
References m_norm, GEnergy::MeV(), gammalib::MeV2erg, and GOptimizerPar::value().
|
virtual |
Evaluate model value.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
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().
Returns model photon flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
Computes
\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE \]
where
emin
, emax
] is an energy interval, andImplements GModelSpectral.
Definition at line 318 of file GModelSpectralConst.cpp.
References m_norm, GEnergy::MeV(), and GOptimizerPar::value().
|
protected |
Delete class members.
Definition at line 545 of file GModelSpectralConst.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralConst().
|
protected |
Initialise class members.
Definition at line 498 of file GModelSpectralConst.cpp.
References GOptimizerPar::clear(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_norm, GModelSpectral::m_pars, m_type, GOptimizerPar::name(), GOptimizerPar::range(), GOptimizerPar::scale(), and GOptimizerPar::value().
Referenced by clear(), GModelSpectralConst(), and operator=().
|
virtual |
Returns MC energy between [emin, emax].
[in] | emin | Minimum photon energy. |
[in] | emax | Maximum photon energy. |
[in] | time | True photon arrival time. |
[in,out] | ran | Random number generator. |
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().
|
virtual |
Assignment operator.
[in] | model | Constant spectral model. |
Definition at line 192 of file GModelSpectralConst.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print spectral model information.
[in] | chatter | Chattiness (defaults to NORMAL). |
Implements GModelSpectral.
Definition at line 464 of file GModelSpectralConst.cpp.
References GModelSpectral::m_pars, gammalib::parformat(), SILENT, GModelSpectral::size(), and gammalib::str().
|
virtual |
Read model from XML element.
[in] | xml | XML 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().
|
inlinevirtual |
Return 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().
|
inline |
Set model type.
[in] | type | Model type. |
Set the type of the constant spectral model.
Definition at line 142 of file GModelSpectralConst.hpp.
|
inline |
Return model value.
Returns the model value.
Definition at line 157 of file GModelSpectralConst.hpp.
References m_norm, and GOptimizerPar::value().
Referenced by eval().
|
inline |
Set model value.
[in] | value | Model value (ph/cm2/s/MeV). |
Sets the model value.
Definition at line 171 of file GModelSpectralConst.hpp.
References m_norm, and GOptimizerPar::value().
|
virtual |
Write model into XML element.
[in] | xml | XML 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().
|
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().
|
protected |
Model type.
Definition at line 103 of file GModelSpectralConst.hpp.
Referenced by copy_members(), GModelSpectralConst(), init_members(), and type().