GammaLib
2.1.0.dev
|
Photon flux normalized power law spectral model class. More...
#include <GModelSpectralPlawPhotonFlux.hpp>
Public Member Functions | |
GModelSpectralPlawPhotonFlux (void) | |
Void constructor. More... | |
GModelSpectralPlawPhotonFlux (const std::string &type, const std::string &flux, const std::string &index, const std::string &emin, const std::string &emax) | |
Model type and parameter name constructor. More... | |
GModelSpectralPlawPhotonFlux (const double &flux, const double &index, const GEnergy &emin, const GEnergy &emax) | |
Constructor. More... | |
GModelSpectralPlawPhotonFlux (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpectralPlawPhotonFlux (const GModelSpectralPlawPhotonFlux &model) | |
Copy constructor. More... | |
virtual | ~GModelSpectralPlawPhotonFlux (void) |
Destructor. More... | |
virtual GModelSpectralPlawPhotonFlux & | operator= (const GModelSpectralPlawPhotonFlux &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear power law model. More... | |
virtual GModelSpectralPlawPhotonFlux * | 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 | flux (void) const |
Return photon flux. More... | |
void | flux (const double &flux) |
Set photon 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 GModelSpectralPlawPhotonFlux &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_flux |
Photon flux (ph/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... | |
Photon 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\_flux} \frac{{\tt m\_index}+1} {{\tt e\_max}^{{\tt m\_index}+1} - {\tt e\_min}^{{\tt m\_index}+1}} E^{\tt m\_index} \]
for \({\tt m\_index} \ne -1\) and
\[ S_{\rm E}(E | t) = \frac{{\tt m\_flux}} {\log {\tt e\_max} - \log {\tt e\_min}} E^{\tt m\_index} \]
for \({\tt m\_index} = -1\), where
Definition at line 73 of file GModelSpectralPlawPhotonFlux.hpp.
GModelSpectralPlawPhotonFlux::GModelSpectralPlawPhotonFlux | ( | void | ) |
Void constructor.
Constructs empty power law photon flux model.
Definition at line 83 of file GModelSpectralPlawPhotonFlux.cpp.
References init_members().
Referenced by clone().
GModelSpectralPlawPhotonFlux::GModelSpectralPlawPhotonFlux | ( | const std::string & | type, |
const std::string & | flux, | ||
const std::string & | index, | ||
const std::string & | emin, | ||
const std::string & | emax | ||
) |
Model type and parameter name constructor.
[in] | type | Model type. |
[in] | flux | Name of photon flux parameter. |
[in] | index | Name of index parameter. |
[in] | emin | Name of emin parameter. |
[in] | emax | Name of emax parameter. |
Definition at line 103 of file GModelSpectralPlawPhotonFlux.cpp.
References init_members(), m_emax, m_emin, m_flux, m_index, m_type, GOptimizerPar::name(), and type().
GModelSpectralPlawPhotonFlux::GModelSpectralPlawPhotonFlux | ( | const double & | flux, |
const double & | index, | ||
const GEnergy & | emin, | ||
const GEnergy & | emax | ||
) |
Constructor.
[in] | flux | Photon flux (ph/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 141 of file GModelSpectralPlawPhotonFlux.cpp.
References init_members(), m_emax, m_emin, m_flux, m_index, GEnergy::MeV(), and GOptimizerPar::value().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs flux normalized power law spectral model by extracting information from an XML element.
Definition at line 169 of file GModelSpectralPlawPhotonFlux.cpp.
References init_members(), and read().
GModelSpectralPlawPhotonFlux::GModelSpectralPlawPhotonFlux | ( | const GModelSpectralPlawPhotonFlux & | model | ) |
Copy constructor.
[in] | model | Spectral power law model. |
Definition at line 188 of file GModelSpectralPlawPhotonFlux.cpp.
References copy_members(), and init_members().
|
virtual |
Destructor.
Definition at line 205 of file GModelSpectralPlawPhotonFlux.cpp.
References free_members().
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 160 of file GModelSpectralPlawPhotonFlux.hpp.
|
virtual |
Clear power law model.
Implements GModelSpectral.
Definition at line 260 of file GModelSpectralPlawPhotonFlux.cpp.
References GModelSpectral::free_members(), free_members(), GModelSpectral::init_members(), and init_members().
|
virtual |
Clone power law model.
Implements GModelSpectral.
Definition at line 280 of file GModelSpectralPlawPhotonFlux.cpp.
References GModelSpectralPlawPhotonFlux().
|
protected |
Copy class members.
[in] | model | Spectral power law model. |
Definition at line 740 of file GModelSpectralPlawPhotonFlux.cpp.
References m_emax, m_emin, m_flux, 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 GModelSpectralPlawPhotonFlux(), 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 469 of file GModelSpectralPlawPhotonFlux.cpp.
References emax(), emin(), index(), log(), m_flux, m_index, GEnergy::MeV(), gammalib::MeV2erg, norm(), pow(), and GOptimizerPar::value().
|
inline |
Return maximum energy.
Returns the maximum energy.
Definition at line 294 of file GModelSpectralPlawPhotonFlux.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 310 of file GModelSpectralPlawPhotonFlux.hpp.
References m_emax, GEnergy::MeV(), and GOptimizerPar::value().
|
inline |
Return minimum energy.
Returns the minimum energy.
Definition at line 263 of file GModelSpectralPlawPhotonFlux.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 279 of file GModelSpectralPlawPhotonFlux.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\_flux} \frac{{\tt m\_index}+1} {{\tt e\_max}^{{\tt m\_index}+1} - {\tt e\_min}^{{\tt m\_index}+1}} E^{\tt m\_index} \]
for \({\tt m\_index} \ne -1\) and
\[ S_{\rm E}(E | t) = \frac{{\tt m\_flux}} {\log {\tt e\_max} - \log {\tt e\_min}} E^{\tt m\_index} \]
for \({\tt m\_index} = -1\), 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\_flux}} = \frac{S_{\rm E}(E | t)}{{\tt m\_flux}} \]
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} = S_{\rm E}(E | t) \, \left( \frac{1}{{\tt m\_index}+1} - \frac{\log({\tt e\_max}) {\tt e\_max}^{{\tt m\_index}+1} - \log({\tt e\_min}) {\tt e\_min}^{{\tt m\_index}+1}} {{\tt e\_max}^{{\tt m\_index}+1} - {\tt e\_min}^{{\tt m\_index}+1}} + \ln(E) \right) \]
for \({\tt m\_index} \ne -1\) and
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} = S_{\rm E}(E | t) \, \ln(E) \]
for \({\tt m\_index} = -1\).
Implements GModelSpectral.
Definition at line 349 of file GModelSpectralPlawPhotonFlux.cpp.
References GOptimizerPar::factor_gradient(), GOptimizerPar::factor_value(), flux(), GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), gammalib::ln10, GEnergy::log10MeV(), m_flux, 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 413 of file GModelSpectralPlawPhotonFlux.cpp.
References emax(), emin(), flux(), index(), log(), m_flux, m_index, GEnergy::MeV(), pow(), and GOptimizerPar::value().
|
inline |
Return photon flux.
Returns the photon flux.
Definition at line 203 of file GModelSpectralPlawPhotonFlux.hpp.
References m_flux, and GOptimizerPar::value().
|
inline |
Set photon flux.
[in] | flux | Photon flux (ph/cm2/s). |
Sets the photon flux.
Definition at line 217 of file GModelSpectralPlawPhotonFlux.hpp.
References m_flux, and GOptimizerPar::value().
|
protected |
Delete class members.
Definition at line 776 of file GModelSpectralPlawPhotonFlux.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralPlawPhotonFlux().
|
inline |
Return power law index.
Returns the power law index.
Definition at line 234 of file GModelSpectralPlawPhotonFlux.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 248 of file GModelSpectralPlawPhotonFlux.hpp.
References m_index, and GOptimizerPar::value().
|
protected |
Initialise class members.
Definition at line 663 of file GModelSpectralPlawPhotonFlux.cpp.
References GOptimizerPar::clear(), GOptimizerPar::fix(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_emax, m_emin, m_flux, 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(), GModelSpectralPlawPhotonFlux(), 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 528 of file GModelSpectralPlawPhotonFlux.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 227 of file GModelSpectralPlawPhotonFlux.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
Print power law information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 629 of file GModelSpectralPlawPhotonFlux.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 572 of file GModelSpectralPlawPhotonFlux.cpp.
References emax(), emin(), flux(), G_READ, index(), m_emax, m_emin, m_flux, m_index, GOptimizerPar::name(), GModelPar::read(), gammalib::xml_check_parnum(), and gammalib::xml_get_par().
Referenced by GModelSpectralPlawPhotonFlux().
|
inlinevirtual |
Return model type.
Returns the type of the spectral power law model.
Implements GModelSpectral.
Definition at line 174 of file GModelSpectralPlawPhotonFlux.hpp.
References m_type.
Referenced by GModelSpectralPlawPhotonFlux(), 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 GModelSpectralPlawPhotonFlux.hpp.
|
protected |
Update precomputed values.
[in] | srcEng | Source energy |
Definition at line 788 of file GModelSpectralPlawPhotonFlux.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 601 of file GModelSpectralPlawPhotonFlux.cpp.
References emax(), emin(), flux(), G_WRITE, index(), m_emax, m_emin, m_flux, m_index, GOptimizerPar::name(), type(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().
|
protected |
Upper energy limit (MeV)
Definition at line 137 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), emax(), GModelSpectralPlawPhotonFlux(), init_members(), read(), and write().
|
protected |
Lower energy limit (MeV)
Definition at line 136 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), emin(), GModelSpectralPlawPhotonFlux(), init_members(), read(), and write().
|
protected |
Photon flux (ph/cm2/s)
Definition at line 134 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralPlawPhotonFlux(), init_members(), read(), and write().
|
mutableprotected |
Power-law normalization gradient.
Definition at line 145 of file GModelSpectralPlawPhotonFlux.hpp.
|
protected |
Spectral index.
Definition at line 135 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), eflux(), eval(), flux(), GModelSpectralPlawPhotonFlux(), index(), init_members(), read(), and write().
|
mutableprotected |
Last upper energy limit.
Definition at line 149 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last lower energy limit.
Definition at line 148 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last source energy.
Definition at line 150 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Last spectral index (MeV)
Definition at line 147 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Log(emax)
Definition at line 141 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Log(emin)
Definition at line 140 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law normalization (for pivot energy 1 MeV)
Definition at line 144 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), eval(), init_members(), and update().
|
mutableprotected |
emax^(index+1)
Definition at line 143 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
emin^(index+1)
Definition at line 142 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law factor.
Definition at line 146 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), eval(), init_members(), and update().
|
protected |
Model type.
Definition at line 133 of file GModelSpectralPlawPhotonFlux.hpp.
Referenced by copy_members(), GModelSpectralPlawPhotonFlux(), init_members(), and type().