GammaLib
2.0.0
|
Energy flux normalized power law spectral model class. More...
#include <GModelSpectralPlawEnergyFlux.hpp>
Public Member Functions | |
GModelSpectralPlawEnergyFlux (void) | |
Void constructor. More... | |
GModelSpectralPlawEnergyFlux (const std::string &type, const std::string &eflux, const std::string &index, const std::string &emin, const std::string &emax) | |
Model type and parameter name constructor. More... | |
GModelSpectralPlawEnergyFlux (const double &eflux, const double &index, const GEnergy &emin, const GEnergy &emax) | |
Constructor. More... | |
GModelSpectralPlawEnergyFlux (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpectralPlawEnergyFlux (const GModelSpectralPlawEnergyFlux &model) | |
Copy constructor. More... | |
virtual | ~GModelSpectralPlawEnergyFlux (void) |
Destructor. More... | |
virtual GModelSpectralPlawEnergyFlux & | operator= (const GModelSpectralPlawEnergyFlux &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear power law model. More... | |
virtual GModelSpectralPlawEnergyFlux * | clone (void) const |
Clone 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 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 power law information. More... | |
void | type (const std::string &type) |
Set model type. More... | |
double | eflux (void) const |
Return energy flux. More... | |
void | eflux (const double &eflux) |
Set energy flux. More... | |
double | index (void) const |
Return power law index. More... | |
void | index (const double &index) |
Set power law index. More... | |
GEnergy | emin (void) const |
Return minimum energy. More... | |
void | emin (const GEnergy &emin) |
Set minimum energy. More... | |
GEnergy | emax (void) const |
Return maximum energy. More... | |
void | emax (const GEnergy &emax) |
Set maximum 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 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 GModelSpectralPlawEnergyFlux &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | update (const GEnergy &srcEng) const |
Update precomputed values. 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_eflux |
Energy flux (erg/cm2/s) More... | |
GModelPar | m_index |
Spectral index. More... | |
GModelPar | m_emin |
Lower energy limit (MeV) More... | |
GModelPar | m_emax |
Upper energy limit (MeV) More... | |
double | m_log_emin |
Log(emin) More... | |
double | m_log_emax |
Log(emax) More... | |
double | m_pow_emin |
emin^(index+1) More... | |
double | m_pow_emax |
emax^(index+1) More... | |
double | m_norm |
Power-law normalization (for pivot energy 1 MeV) More... | |
double | m_g_norm |
Power-law normalization gradient. More... | |
double | m_power |
Power-law factor. More... | |
double | m_last_index |
Last spectral index (MeV) More... | |
GEnergy | m_last_emin |
Last lower energy limit. More... | |
GEnergy | m_last_emax |
Last upper energy limit. More... | |
GEnergy | m_last_energy |
Last source energy. More... | |
Protected Attributes inherited from GModelSpectral | |
std::vector< GModelPar * > | m_pars |
Parameter pointers. More... | |
Energy flux normalized power law spectral model class.
This class implements a power law spectrum. The model is defined by
\[ S_{\rm E}(E | t) = {\tt m\_eflux} \frac{{\tt m\_index}+1} {{\tt e\_max}^{{\tt m\_index}+2} - {\tt e\_min}^{{\tt m\_index}+2}} E^{\tt m\_index} \]
for \({\tt m\_index} \ne -2\) and
\[ S_{\rm E}(E | t) = \frac{{\tt m\_eflux}} {\log {\tt e\_max} - \log {\tt e\_min}} E^{\tt m\_index} \]
for \({\tt m\_index} = -2\), where
Definition at line 73 of file GModelSpectralPlawEnergyFlux.hpp.
GModelSpectralPlawEnergyFlux::GModelSpectralPlawEnergyFlux | ( | void | ) |
Void constructor.
Definition at line 73 of file GModelSpectralPlawEnergyFlux.cpp.
References init_members().
Referenced by clone().
GModelSpectralPlawEnergyFlux::GModelSpectralPlawEnergyFlux | ( | const std::string & | type, |
const std::string & | eflux, | ||
const std::string & | index, | ||
const std::string & | emin, | ||
const std::string & | emax | ||
) |
Model type and parameter name constructor.
[in] | type | Model type. |
[in] | eflux | Name of energy flux parameter. |
[in] | index | Name of index parameter. |
[in] | emin | Name of emin parameter. |
[in] | emax | Name of emax parameter. |
Definition at line 93 of file GModelSpectralPlawEnergyFlux.cpp.
References init_members(), m_eflux, m_emax, m_emin, m_index, m_type, GOptimizerPar::name(), and type().
|
explicit |
Constructor.
[in] | eflux | Energy flux (erg/cm2/s). |
[in] | index | Power law index. |
[in] | emin | Minimum energy. |
[in] | emax | Maximum energy. |
Construct a spectral power law from the
Definition at line 131 of file GModelSpectralPlawEnergyFlux.cpp.
References init_members(), m_eflux, m_emax, m_emin, m_index, GEnergy::MeV(), and GOptimizerPar::value().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs energy flux normalized power law spectral model by extracting information from an XML element.
Definition at line 159 of file GModelSpectralPlawEnergyFlux.cpp.
References init_members(), and read().
GModelSpectralPlawEnergyFlux::GModelSpectralPlawEnergyFlux | ( | const GModelSpectralPlawEnergyFlux & | model | ) |
Copy constructor.
[in] | model | Spectral power law model. |
Definition at line 178 of file GModelSpectralPlawEnergyFlux.cpp.
References copy_members(), and init_members().
|
virtual |
Destructor.
Definition at line 195 of file GModelSpectralPlawEnergyFlux.cpp.
References free_members().
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 160 of file GModelSpectralPlawEnergyFlux.hpp.
|
virtual |
Clear power law model.
Implements GModelSpectral.
Definition at line 250 of file GModelSpectralPlawEnergyFlux.cpp.
References GModelSpectral::free_members(), free_members(), GModelSpectral::init_members(), and init_members().
|
virtual |
Clone power law model.
Implements GModelSpectral.
Definition at line 270 of file GModelSpectralPlawEnergyFlux.cpp.
References GModelSpectralPlawEnergyFlux().
|
protected |
Copy class members.
[in] | model | Spectral power law model. |
Definition at line 730 of file GModelSpectralPlawEnergyFlux.cpp.
References m_eflux, m_emax, m_emin, m_index, m_last_emax, m_last_emin, m_last_energy, m_last_index, m_log_emax, m_log_emin, m_norm, GModelSpectral::m_pars, m_pow_emax, m_pow_emin, m_power, and m_type.
Referenced by GModelSpectralPlawEnergyFlux(), and operator=().
|
virtual |
Returns model energy flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Minimum 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 470 of file GModelSpectralPlawEnergyFlux.cpp.
References eflux(), emax(), emin(), index(), log(), m_eflux, m_index, GEnergy::MeV(), pow(), and GOptimizerPar::value().
|
inline |
Return energy flux.
Returns the energy flux.
Definition at line 203 of file GModelSpectralPlawEnergyFlux.hpp.
References m_eflux, and GOptimizerPar::value().
|
inline |
Set energy flux.
[in] | eflux | Energy flux (erg/cm2/s). |
Sets the energy flux.
Definition at line 217 of file GModelSpectralPlawEnergyFlux.hpp.
References m_eflux, and GOptimizerPar::value().
|
inline |
Return maximum energy.
Returns the maximum energy.
Definition at line 292 of file GModelSpectralPlawEnergyFlux.hpp.
References m_emax, GEnergy::MeV(), and GOptimizerPar::value().
Referenced by eflux(), flux(), read(), update(), and write().
|
inline |
Set maximum energy.
[in] | emax | Maximum energy. |
Sets the maximum energy.
Definition at line 308 of file GModelSpectralPlawEnergyFlux.hpp.
References m_emax, GEnergy::MeV(), and GOptimizerPar::value().
|
inline |
Return minimum energy.
Returns the minimum energy.
Definition at line 261 of file GModelSpectralPlawEnergyFlux.hpp.
References m_emin, GEnergy::MeV(), and GOptimizerPar::value().
Referenced by eflux(), flux(), read(), update(), and write().
|
inline |
Set minimum energy.
[in] | emin | Minimum energy. |
Sets the minimum energy.
Definition at line 277 of file GModelSpectralPlawEnergyFlux.hpp.
References m_emin, GEnergy::MeV(), and GOptimizerPar::value().
|
virtual |
Evaluate function.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
Computes
\[ S_{\rm E}(E | t) = {\tt m\_eflux} \frac{{\tt m\_index}+2} {{\tt e\_max}^{{\tt m\_index}+2} - {\tt e\_min}^{{\tt m\_index}+2}} E^{\tt m\_index} \]
for \({\tt m\_index} \ne -2\) and
\[ S_{\rm E}(E | t) = \frac{{\tt m\_eflux}} {\log {\tt e\_max} - \log {\tt e\_min}} E^{\tt m\_index} \]
for \({\tt m\_index} = -2\), where
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\_eflux}} = \frac{S_{\rm E}(E | t)}{{\tt m\_eflux}} \]
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} = S_{\rm E}(E | t) \, \left( \frac{1}{{\tt m\_index}+2} - \frac{\log({\tt e\_max}) {\tt e\_max}^{{\tt m\_index}+2} - \log({\tt e\_min}) {\tt e\_min}^{{\tt m\_index}+2}} {{\tt e\_max}^{{\tt m\_index}+2} - {\tt e\_min}^{{\tt m\_index}+2}} + \ln(E) \right) \]
for \({\tt m\_index} \ne -2\) and
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} = S_{\rm E}(E | t) \, \ln(E) \]
for \({\tt m\_index} = -2\).
No partial derivatives are supported for the energy boundaries.
Implements GModelSpectral.
Definition at line 341 of file GModelSpectralPlawEnergyFlux.cpp.
References eflux(), gammalib::erg2MeV, GOptimizerPar::factor_gradient(), GOptimizerPar::factor_value(), GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), gammalib::ln10, GEnergy::log10MeV(), m_eflux, m_g_norm, m_index, m_norm, m_power, GOptimizerPar::scale(), update(), and GOptimizerPar::value().
|
virtual |
Returns model photon flux between emin, emax
[in] | emin | Minimum photon energy. |
[in] | emax | Minimum 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 406 of file GModelSpectralPlawEnergyFlux.cpp.
References emax(), emin(), gammalib::erg2MeV, index(), log(), m_eflux, m_index, GEnergy::MeV(), norm(), pow(), and GOptimizerPar::value().
|
protected |
Delete class members.
Definition at line 766 of file GModelSpectralPlawEnergyFlux.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralPlawEnergyFlux().
|
inline |
Return power law index.
Returns the power law index.
Definition at line 232 of file GModelSpectralPlawEnergyFlux.hpp.
References m_index, and GOptimizerPar::value().
Referenced by eflux(), flux(), mc(), read(), GCOMIaq::set(), update(), and write().
|
inline |
Set power law index.
[in] | index | Power law index. |
Sets the power law index.
Definition at line 246 of file GModelSpectralPlawEnergyFlux.hpp.
References m_index, and GOptimizerPar::value().
|
protected |
Initialise class members.
Definition at line 653 of file GModelSpectralPlawEnergyFlux.cpp.
References GOptimizerPar::clear(), GOptimizerPar::fix(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_eflux, m_emax, m_emin, m_index, m_last_emax, m_last_emin, m_last_energy, m_last_index, m_log_emax, m_log_emin, m_norm, GModelSpectral::m_pars, m_pow_emax, m_pow_emin, m_power, m_type, GEnergy::MeV(), GOptimizerPar::name(), GOptimizerPar::range(), GOptimizerPar::scale(), GOptimizerPar::unit(), and GOptimizerPar::value().
Referenced by clear(), GModelSpectralPlawEnergyFlux(), 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 power law.
Implements GModelSpectral.
Definition at line 518 of file GModelSpectralPlawEnergyFlux.cpp.
References gammalib::check_energy_interval(), exp(), G_MC, index(), log(), GEnergy::MeV(), pow(), and GRan::uniform().
|
virtual |
Assignment operator.
[in] | model | Spectral power law model. |
Definition at line 217 of file GModelSpectralPlawEnergyFlux.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print power law information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 619 of file GModelSpectralPlawEnergyFlux.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 562 of file GModelSpectralPlawEnergyFlux.cpp.
References eflux(), emax(), emin(), G_READ, index(), m_eflux, m_emax, m_emin, m_index, GOptimizerPar::name(), GModelPar::read(), gammalib::xml_check_parnum(), and gammalib::xml_get_par().
Referenced by GModelSpectralPlawEnergyFlux().
|
inlinevirtual |
Return model type.
Returns the type of the spectral power law model.
Implements GModelSpectral.
Definition at line 174 of file GModelSpectralPlawEnergyFlux.hpp.
References m_type.
Referenced by GModelSpectralPlawEnergyFlux(), type(), and write().
|
inline |
Set model type.
[in] | type | Model type. |
Set the type of the spectral power law model.
Definition at line 188 of file GModelSpectralPlawEnergyFlux.hpp.
|
protected |
Update precomputed values.
[in] | srcEng | Source energy |
Definition at line 778 of file GModelSpectralPlawEnergyFlux.cpp.
References emax(), emin(), index(), log(), m_g_norm, m_last_emax, m_last_emin, m_last_energy, m_last_index, m_log_emax, m_log_emin, m_norm, m_pow_emax, m_pow_emin, m_power, GEnergy::MeV(), and pow().
Referenced by eval().
|
virtual |
Write model into XML element.
[in] | xml | XML element. |
Writes the spectral information into an XML element.
Implements GModelSpectral.
Definition at line 591 of file GModelSpectralPlawEnergyFlux.cpp.
References eflux(), emax(), emin(), G_WRITE, index(), m_eflux, m_emax, m_emin, m_index, GOptimizerPar::name(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().
|
protected |
Energy flux (erg/cm2/s)
Definition at line 134 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralPlawEnergyFlux(), init_members(), read(), and write().
|
protected |
Upper energy limit (MeV)
Definition at line 137 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), emax(), GModelSpectralPlawEnergyFlux(), init_members(), read(), and write().
|
protected |
Lower energy limit (MeV)
Definition at line 136 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), emin(), GModelSpectralPlawEnergyFlux(), init_members(), read(), and write().
|
mutableprotected |
Power-law normalization gradient.
Definition at line 145 of file GModelSpectralPlawEnergyFlux.hpp.
|
protected |
Spectral index.
Definition at line 135 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralPlawEnergyFlux(), index(), init_members(), read(), and write().
|
mutableprotected |
Last upper energy limit.
Definition at line 149 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last lower energy limit.
Definition at line 148 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last source energy.
Definition at line 150 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last spectral index (MeV)
Definition at line 147 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Log(emax)
Definition at line 141 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Log(emin)
Definition at line 140 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law normalization (for pivot energy 1 MeV)
Definition at line 144 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), eval(), init_members(), and update().
|
mutableprotected |
emax^(index+1)
Definition at line 143 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
emin^(index+1)
Definition at line 142 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law factor.
Definition at line 146 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), eval(), init_members(), and update().
|
protected |
Model type.
Definition at line 133 of file GModelSpectralPlawEnergyFlux.hpp.
Referenced by copy_members(), GModelSpectralPlawEnergyFlux(), init_members(), and type().