GammaLib
2.1.0.dev
|
Spectral table model class. More...
#include <GModelSpectralTable.hpp>
Public Member Functions | |
GModelSpectralTable (void) | |
Void constructor. More... | |
GModelSpectralTable (const GFilename &filename, const double &norm) | |
File constructor. More... | |
GModelSpectralTable (const GEbounds &ebounds, const GModelSpectralTablePars &pars, const GNdarray &spectra) | |
Table model constructor. More... | |
GModelSpectralTable (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpectralTable (const GModelSpectralTable &model) | |
Copy constructor. More... | |
virtual | ~GModelSpectralTable (void) |
Destructor. More... | |
virtual GModelSpectralTable & | operator= (const GModelSpectralTable &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear table model. More... | |
virtual GModelSpectralTable * | clone (void) const |
Clone table 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 spectral table model. 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 table model information. More... | |
int | nspectra (void) const |
Return number of spectra in table model. More... | |
GModelSpectralTablePar & | table_par (const int &index) |
Return reference to table parameter. More... | |
const GModelSpectralTablePar & | table_par (const int &index) const |
Return const reference to table parameter. More... | |
GModelSpectralTablePar & | table_par (const std::string &name) |
Return reference to table parameter. More... | |
const GModelSpectralTablePar & | table_par (const std::string &name) const |
Return const reference to table parameter. More... | |
double | norm (void) const |
Return normalization factor. More... | |
void | norm (const double &norm) |
Set normalization factor. More... | |
const GEbounds & | ebounds (void) const |
Return reference to energy boundaries. More... | |
void | load (const GFilename &filename) |
Load table from file. More... | |
void | save (const GFilename &filename, const bool &clobber=false) const |
Save table into file. More... | |
const GFilename & | filename (void) const |
Return file name. More... | |
void | energy_scale (const std::string &name) |
Set energy scale. 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 GModelSpectralTable &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_par_pointers (void) |
Set parameter pointers. More... | |
void | set_energy_nodes (void) |
Set energy nodes from energy boundaries. More... | |
void | scale_energy (void) |
Scale energy. More... | |
bool | has_energy_scale (void) const |
Signal that energy scale was set. More... | |
GFitsBinTable | create_par_table (void) const |
Create PARAMETERS FITS table. More... | |
GFitsBinTable | create_eng_table (void) const |
Create ENERGIES FITS table. More... | |
GFitsBinTable | create_spec_table (void) const |
Create SPECTRA FITS table. More... | |
void | load_par (const GFits &fits) |
Load data from PARAMETERS extension. More... | |
void | load_eng (const GFits &fits) |
Load data from ENERGIES extension. More... | |
void | load_spec (const GFits &fits) |
Load data from SPECTRA extension. More... | |
int | par_index (const std::string &name) const |
Return index for parameter name. More... | |
void | update (void) const |
Update cache for spectral table model computation. More... | |
void | update_flux (void) const |
Update flux cache. More... | |
void | update_mc (const GEnergy &emin, const GEnergy &emax) const |
Update MC 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 | |
GModelPar | m_norm |
Normalization factor. More... | |
GModelSpectralTablePars | m_table_pars |
Table model parameters. More... | |
GNdarray | m_spectra |
Spectra. More... | |
GEbounds | m_ebounds |
Energy boundaries. More... | |
GFilename | m_filename |
Filename of table. More... | |
std::string | m_escale_par |
Energy scaling parameter. More... | |
double | m_escale |
Energy scale. More... | |
double | m_log10escale |
log10 of energy scale More... | |
int | m_npars |
Number of parameters. More... | |
int | m_nebins |
Number of energy bins. More... | |
std::vector< double > | m_last_values |
Last parameter values. More... | |
GNodeArray | m_lin_nodes |
Energy nodes of function. More... | |
GNodeArray | m_log_nodes |
log10(Energy) nodes of function More... | |
GNdarray | m_lin_values |
Function values and grad's. More... | |
GNdarray | m_log_values |
log10(Function) values and grad's More... | |
std::vector< double > | m_prefactor |
Power-law normalisations. More... | |
std::vector< double > | m_gamma |
Power-law indices. More... | |
std::vector< double > | m_epivot |
Power-law pivot energies. More... | |
std::vector< double > | m_flux |
Photon fluxes. More... | |
std::vector< double > | m_eflux |
Energy fluxes. More... | |
GEnergy | m_mc_emin |
Minimum energy. More... | |
GEnergy | m_mc_emax |
Maximum energy. More... | |
std::vector< double > | m_mc_cum |
Cumulative distribution. More... | |
std::vector< double > | m_mc_min |
Lower boundary for MC. More... | |
std::vector< double > | m_mc_max |
Upper boundary for MC. More... | |
std::vector< double > | m_mc_exp |
Exponent for MC. More... | |
Protected Attributes inherited from GModelSpectral | |
std::vector< GModelPar * > | m_pars |
Parameter pointers. More... | |
Spectral table model class.
Definition at line 55 of file GModelSpectralTable.hpp.
GModelSpectralTable::GModelSpectralTable | ( | void | ) |
Void constructor.
Definition at line 88 of file GModelSpectralTable.cpp.
References init_members().
Referenced by clone().
GModelSpectralTable::GModelSpectralTable | ( | const GFilename & | filename, |
const double & | norm | ||
) |
File constructor.
[in] | filename | File name of table model. |
[in] | norm | Normalization factor. |
Constructs a spectral table model from a FITS file. See the load() method for more information about the expected structure of the FITS file.
Definition at line 107 of file GModelSpectralTable.cpp.
References init_members(), load(), m_norm, GOptimizerPar::range(), GOptimizerPar::remove_range(), GOptimizerPar::scale(), and GOptimizerPar::value().
GModelSpectralTable::GModelSpectralTable | ( | const GEbounds & | ebounds, |
const GModelSpectralTablePars & | pars, | ||
const GNdarray & | spectra | ||
) |
Table model constructor.
[in] | ebounds | Energy boundaries. |
[in] | pars | Table model parameters. |
[in] | spectra | Spectra. |
Constructs a spectral table model from energy boundaries, table model parameters, and spectra.
Definition at line 139 of file GModelSpectralTable.cpp.
References GNdarray::dim(), ebounds(), G_CONST, init_members(), m_ebounds, m_spectra, m_table_pars, set_energy_nodes(), set_par_pointers(), GNdarray::shape(), GModelSpectralTablePars::size(), GEbounds::size(), and gammalib::str().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs a spectral table 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 207 of file GModelSpectralTable.cpp.
References init_members(), and read().
GModelSpectralTable::GModelSpectralTable | ( | const GModelSpectralTable & | model | ) |
Copy constructor.
[in] | model | Table model. |
Definition at line 226 of file GModelSpectralTable.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 164 of file GModelSpectralTable.hpp.
|
virtual |
Clear table model.
Implements GModelSpectral.
Definition at line 298 of file GModelSpectralTable.cpp.
References free_members(), GModelSpectral::free_members(), init_members(), and GModelSpectral::init_members().
Referenced by load().
|
virtual |
Clone table model.
Implements GModelSpectral.
Definition at line 316 of file GModelSpectralTable.cpp.
References GModelSpectralTable().
|
protected |
Copy class members.
[in] | model | Table model. |
Definition at line 1222 of file GModelSpectralTable.cpp.
References m_ebounds, m_eflux, m_epivot, m_escale, m_escale_par, m_filename, m_flux, m_gamma, m_last_values, m_lin_nodes, m_lin_values, m_log10escale, m_log_nodes, m_log_values, m_mc_cum, m_mc_emax, m_mc_emin, m_mc_exp, m_mc_max, m_mc_min, m_nebins, m_norm, m_npars, m_prefactor, m_spectra, m_table_pars, set_energy_nodes(), and set_par_pointers().
Referenced by GModelSpectralTable(), and operator=().
|
protected |
Create ENERGIES FITS table.
The method creates a binary FITS table that is compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node7.html
Definition at line 1636 of file GModelSpectralTable.cpp.
References GFitsTable::append(), GFitsHDU::card(), GEbounds::emax(), GEbounds::emin(), GFitsHDU::extname(), GEnergy::keV(), m_ebounds, and GEbounds::size().
Referenced by save().
|
protected |
Create PARAMETERS FITS table.
The method creates a binary FITS table that is compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node6.html
Definition at line 1497 of file GModelSpectralTable.cpp.
References GFitsTable::append(), GFitsHDU::card(), GFitsHDU::extname(), GOptimizerPar::has_max(), GOptimizerPar::has_min(), GOptimizerPar::is_fixed(), m_table_pars, GOptimizerPar::max(), GOptimizerPar::min(), GOptimizerPar::name(), GModelSpectralTablePars::size(), GModelSpectral::size(), and GOptimizerPar::value().
Referenced by save().
|
protected |
Create SPECTRA FITS table.
The method creates a binary FITS table that is compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node8.html
Definition at line 1681 of file GModelSpectralTable.cpp.
References GFitsTable::append(), GFitsHDU::card(), GNdarray::dim(), GFitsHDU::extname(), m_ebounds, m_spectra, m_table_pars, GNdarray::shape(), GModelSpectralTablePars::size(), GEbounds::size(), and GFitsTableCol::unit().
Referenced by save().
|
inline |
Return reference to energy boundaries.
Returns a reference to energy boundaries.
Definition at line 221 of file GModelSpectralTable.hpp.
References m_ebounds.
Referenced by GModelSpectralTable(), and update().
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 584 of file GModelSpectralTable.cpp.
References GNodeArray::inx_left(), m_eflux, m_epivot, m_gamma, m_lin_nodes, m_prefactor, GEnergy::MeV(), gammalib::MeV2erg, norm(), gammalib::plaw_energy_flux(), GNodeArray::set_value(), update(), and update_flux().
Referenced by update_flux().
void GModelSpectralTable::energy_scale | ( | const std::string & | name | ) |
Set energy scale.
[in] | name | Table parameter name for energy scaling. |
GException::invalid_argument | Table model parameter name not found.s |
Sets a given table parameter name
as energy scale for table model interpolation.
Definition at line 1029 of file GModelSpectralTable.cpp.
References G_READ, m_escale_par, m_log10escale, m_table_pars, GOptimizerPar::name(), scale_energy(), and GModelSpectralTablePars::size().
Referenced by read().
|
virtual |
Evaluate spectral table model.
[in] | srcEng | True photon energy. |
[in] | srcTime | True photon arrival time. |
[in] | gradients | Compute gradients? |
Evaluates
\[ S_{\rm E}(E | t) = {\tt m\_norm} \times \left( w_l F_l(p) + w_r F_r(p) \right) \]
where
The weights are computed using
\[ w_r = \frac{\log_{10} E - \log_{10} E_l}{\log_{10} E_r - \log_{10} E_l} \]
and \(w_l = 1 - w_r\).
If gradient
is true, the method also computes the parameter gradients using
\[ \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_norm}} = \frac{S_{\rm E}(E | t)}{{\tt m\_norm}} \]
and
\[ \frac{\delta S_{\rm E}(E | t)}{\delta p} = {\tt m\_norm} \times \left( w_l \frac{\delta F_l(p)}{\delta p} + w_r \frac{\delta F_r(p)}{\delta p} \right) \]
for all other parameters.
For the computation of \(F_l(p)\), \(F_r(p)\), \(\frac{\delta F_l(p)}{\delta p}\), and \(\frac{\delta F_r(p)}{\delta p}\) see the update() method.
Implements GModelSpectral.
Definition at line 377 of file GModelSpectralTable.cpp.
References GOptimizerPar::factor_gradient(), GOptimizerPar::factor_value(), GNodeArray::inx_left(), GNodeArray::inx_right(), GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), gammalib::ln10, log10(), GEnergy::log10MeV(), m_escale_par, m_lin_values, m_log10escale, m_log_nodes, m_norm, m_table_pars, GOptimizerPar::name(), norm(), GOptimizerPar::scale(), GNodeArray::set_value(), GModelSpectralTablePars::size(), table_par(), update(), GOptimizerPar::value(), GNodeArray::wgt_grad_left(), GNodeArray::wgt_grad_right(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
|
inline |
Return file name.
Returns the name of the table file.
Definition at line 235 of file GModelSpectralTable.hpp.
References m_filename.
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 491 of file GModelSpectralTable.cpp.
References GNodeArray::inx_left(), m_epivot, m_flux, m_gamma, m_lin_nodes, m_prefactor, GEnergy::MeV(), norm(), gammalib::plaw_photon_flux(), GNodeArray::set_value(), update(), and update_flux().
Referenced by update_flux(), and update_mc().
|
protected |
Delete class members.
Definition at line 1272 of file GModelSpectralTable.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralTable().
|
protected |
Signal that energy scale was set.
Definition at line 1479 of file GModelSpectralTable.cpp.
References m_escale.
Referenced by set_energy_nodes().
|
protected |
Initialise class members.
Definition at line 1164 of file GModelSpectralTable.cpp.
References GModelSpectralTablePars::clear(), GNodeArray::clear(), GEnergy::clear(), GFilename::clear(), GEbounds::clear(), GNdarray::clear(), GOptimizerPar::clear(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_ebounds, m_eflux, m_epivot, m_escale, m_escale_par, m_filename, m_flux, m_gamma, m_last_values, m_lin_nodes, m_lin_values, m_log10escale, m_log_nodes, m_log_values, m_mc_cum, m_mc_emax, m_mc_emin, m_mc_exp, m_mc_max, m_mc_min, m_nebins, m_norm, m_npars, m_prefactor, m_spectra, m_table_pars, GOptimizerPar::name(), GOptimizerPar::range(), GOptimizerPar::scale(), set_par_pointers(), and GOptimizerPar::value().
Referenced by clear(), GModelSpectralTable(), and operator=().
void GModelSpectralTable::load | ( | const GFilename & | filename | ) |
Load table from file.
[in] | filename | File name. |
Loads table model from FITS file. The format of the FITS file complies with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/ogip_92_009.html
Definition at line 827 of file GModelSpectralTable.cpp.
References clear(), GFits::close(), filename(), GFilename::is_empty(), load_eng(), load_par(), load_spec(), m_filename, set_energy_nodes(), and set_par_pointers().
Referenced by GModelSpectralTable(), and read().
|
protected |
Load data from ENERGIES extension.
[in] | fits | FITS file. |
The method loads data from the ENERGIES binary table. The format of the table needs to be compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node7.html
If energy units are provided in the ENERGIES extension the method decodes the units and interprets the energy values correspondingly.
Definition at line 1867 of file GModelSpectralTable.cpp.
References GEbounds::append(), GFitsHDU::integer(), m_ebounds, and GFits::table().
Referenced by load().
|
protected |
Load data from PARAMETERS extension.
[in] | fits | FITS file. |
GException::invalid_value | Non-positive parameter value encountered for logarithmic parameters. |
The method loads data from the PARAMETERS binary table. The format of the table needs to be compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node6.html
Definition at line 1771 of file GModelSpectralTable.cpp.
References GModelSpectralTablePars::append(), GOptimizerPar::factor_range(), GOptimizerPar::fix(), GOptimizerPar::free(), GOptimizerPar::has_grad(), GFitsHDU::integer(), m_table_pars, max(), GModelSpectralTablePar::method(), min(), GFitsHDU::real(), GOptimizerPar::scale(), and GFits::table().
Referenced by load().
|
protected |
Load data from SPECTRA extension.
[in] | fits | FITS file. |
The method loads data from the SPECTRA binary table. The format of the table needs to be compliant with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/node8.html
Definition at line 1911 of file GModelSpectralTable.cpp.
References GFitsHDU::integer(), GNodeArray::inx_left(), GNodeArray::inx_right(), m_spectra, m_table_pars, GFitsHDU::real(), GNodeArray::set_value(), GFits::table(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
Referenced by load().
|
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 broken power law defined by the file function.
Implements GModelSpectral.
Definition at line 675 of file GModelSpectralTable.cpp.
References gammalib::check_energy_interval(), exp(), G_MC, log(), m_mc_cum, m_mc_exp, m_mc_max, m_mc_min, GEnergy::MeV(), GRan::uniform(), update(), update_flux(), and update_mc().
|
inline |
Return normalization factor.
Returns the normalization factor.
Definition at line 192 of file GModelSpectralTable.hpp.
References m_norm, and GOptimizerPar::value().
Referenced by eflux(), eval(), flux(), read(), update_mc(), and write().
|
inline |
Set normalization factor.
[in] | norm | Normalization factor. |
Sets the normalization factor.
Definition at line 206 of file GModelSpectralTable.hpp.
References m_norm, and GOptimizerPar::value().
int GModelSpectralTable::nspectra | ( | void | ) | const |
Return number of spectra in table model.
If the table model is empty the method returns zero.
Definition at line 925 of file GModelSpectralTable.cpp.
References m_table_pars, and GModelSpectralTablePars::size().
Referenced by print(), and scale_energy().
|
virtual |
Assignment operator.
[in] | model | Table model. |
Definition at line 265 of file GModelSpectralTable.cpp.
References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().
|
protected |
Return index for parameter name.
[in] | name | Parameter name. |
GException::invalid_argument | Parameter name not found in spectral table. |
Definition at line 1991 of file GModelSpectralTable.cpp.
References G_PAR_INDEX, m_table_pars, and GModelSpectral::size().
Referenced by scale_energy(), and table_par().
Print table model information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 1074 of file GModelSpectralTable.cpp.
References GModelSpectralTablePars::append(), GNdarray::dim(), GEbounds::emax(), GEbounds::emin(), m_ebounds, m_filename, GModelSpectral::m_pars, m_spectra, m_table_pars, max(), min(), nspectra(), gammalib::parformat(), GEnergy::print(), GNdarray::shape(), SILENT, GModelSpectralTablePars::size(), GEbounds::size(), GModelSpectral::size(), gammalib::str(), and GFilename::url().
|
virtual |
Read model from XML element.
[in] | xml | XML element containing power law model information. |
Reads the spectral information from an XML element. The format of the XML elements is
<spectrum type="TableModel" file=".."> <parameter name="Normalization" scale=".." value=".." min=".." max=".." free=".."/> </spectrum>
Optionally, values for the model table parameters can also be provided.
Implements GModelSpectral.
Definition at line 739 of file GModelSpectralTable.cpp.
References GXmlElement::attribute(), energy_scale(), G_READ, GXmlElement::has_attribute(), load(), m_norm, m_table_pars, GOptimizerPar::name(), norm(), GModelPar::read(), GModelSpectralTablePars::size(), gammalib::xml_file_expand(), gammalib::xml_get_par(), and gammalib::xml_has_par().
Referenced by GModelSpectralTable().
void GModelSpectralTable::save | ( | const GFilename & | filename, |
const bool & | clobber = false |
||
) | const |
Save table into file.
[in] | filename | File name. |
[in] | clobber | Overwrite existing file? |
Save the table model into a FITS file. The FITS file will contain three binary table extensions:
* PARAMETERS - Table model parameters * ENERGIES - Table model energies * SPECTRA - Table model spectra
The format of the FITS file complies with https://heasarc.gsfc.nasa.gov/docs/heasarc/ofwg/docs/general/ogip_92_009/ogip_92_009.html
Definition at line 878 of file GModelSpectralTable.cpp.
References GFits::append(), GFitsHDU::card(), create_eng_table(), create_par_table(), create_spec_table(), filename(), m_filename, GFits::saveto(), and GFilename::url().
|
protected |
Scale energy.
Scales the energy axis so that all spectra are relative to the energy scaling parameter. This scaling is useful for better interpolation of spectra that have a feature that depends of an energy parameter.
Definition at line 1359 of file GModelSpectralTable.cpp.
References GNdarray::index(), GNodeArray::inx_left(), GNodeArray::inx_right(), log10(), m_ebounds, m_escale, m_escale_par, m_last_values, m_lin_nodes, m_log10escale, m_log_nodes, m_spectra, m_table_pars, nspectra(), par_index(), GNodeArray::set_value(), GModelSpectralTablePars::size(), GNodeArray::size(), GEbounds::size(), table_par(), GModelSpectralTablePar::values(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
Referenced by energy_scale().
|
protected |
Set energy nodes from energy boundaries.
Definition at line 1308 of file GModelSpectralTable.cpp.
References GNodeArray::append(), GEbounds::elogmean(), has_energy_scale(), log10(), m_ebounds, m_escale, m_lin_nodes, m_lin_values, m_log10escale, m_log_nodes, m_log_values, GEnergy::MeV(), and GEbounds::size().
Referenced by copy_members(), GModelSpectralTable(), and load().
|
protected |
Set parameter pointers.
Definition at line 1282 of file GModelSpectralTable.cpp.
References m_norm, GModelSpectral::m_pars, m_table_pars, and GModelSpectralTablePars::size().
Referenced by copy_members(), GModelSpectralTable(), init_members(), and load().
GModelSpectralTablePar & GModelSpectralTable::table_par | ( | const int & | index | ) |
Return reference to table parameter.
[in] | index | Table parameter index [0,...,size()[. |
Definition at line 954 of file GModelSpectralTable.cpp.
References G_TABLE_PAR, m_table_pars, and GModelSpectral::size().
Referenced by eval(), and scale_energy().
const GModelSpectralTablePar & GModelSpectralTable::table_par | ( | const int & | index | ) | const |
Return const reference to table parameter.
[in] | index | Table parameter index [0,...,size()[. |
Definition at line 973 of file GModelSpectralTable.cpp.
References G_TABLE_PAR, m_table_pars, and GModelSpectral::size().
GModelSpectralTablePar & GModelSpectralTable::table_par | ( | const std::string & | name | ) |
Return reference to table parameter.
[in] | name | Table parameter name. |
Definition at line 992 of file GModelSpectralTable.cpp.
References m_table_pars, and par_index().
const GModelSpectralTablePar & GModelSpectralTable::table_par | ( | const std::string & | name | ) | const |
Return const reference to table parameter.
[in] | name | Table parameter name. |
Definition at line 1008 of file GModelSpectralTable.cpp.
References m_table_pars, and par_index().
|
inlinevirtual |
Return model type.
Returns the type of the spectral model.
Implements GModelSpectral.
Definition at line 178 of file GModelSpectralTable.hpp.
Referenced by write().
|
protected |
Update cache for spectral table model computation.
Update interval vectors for function values and gradients. An update is performed in case that some of the parameter values have changed. The method sets the following cache members:
m_npars (number of model parameters) m_nebins (number of energy bins in spectra) m_last_values (last model parameter values) m_lin_values (function values)
The array \({\tt m\_lin\_values}\) holds the vector \(F(E|p)\) as function of energy \(E\), computed for the current set of parameters \(p\). The computation is done using the N-dimensional linear interpolation
\[ F(E|p) = \sum_{k=1}^M \left( \prod_{i=1}^N w_x(p) \right) F_p(E) \]
where
For each parameter \(i\), the weighting factors \(w_i^l(p)\) and \(w_i^r(p)\) are computed using
\[ w_i^r(p) = \frac{p - p_l}{p_r - p_l} \]
and \(w_i^l(p) = 1 - w_i^r(p)\), where \(p_l\) is the largest parameter value that satisfies \(p<p_l\) and \(p_r\) is the smallest parameter value that satisfies \(p>p_r\).
The method also computes the gradients
\[ \frac{\delta F(E|p)}{\delta p} = \sum_{k=1}^M \left( \frac{\delta w_{x_p}(p)}{\delta p} \prod_{i=1 \land i \neq i_p}^N w_x(p) \right) F_p(E) \]
where \(x_p = 2 k + i_p/2^k \mod 2\).
Definition at line 2078 of file GModelSpectralTable.cpp.
References ebounds(), GNodeArray::inx_left(), GNodeArray::inx_right(), m_last_values, m_lin_values, m_log_values, m_nebins, m_npars, m_spectra, m_table_pars, GNodeArray::set_value(), GModelSpectralTablePars::size(), GEbounds::size(), GOptimizerPar::value(), GNodeArray::wgt_grad_left(), GNodeArray::wgt_grad_right(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
|
protected |
Update flux cache.
Definition at line 2293 of file GModelSpectralTable.cpp.
References eflux(), flux(), log(), m_eflux, m_epivot, m_flux, m_gamma, m_lin_nodes, m_lin_values, m_prefactor, gammalib::MeV2erg, gammalib::plaw_energy_flux(), gammalib::plaw_photon_flux(), pow(), GNodeArray::size(), and sqrt().
Update MC cache.
[in] | emin | Minimum energy. |
[in] | emax | Maximum energy. |
This method sets up an array of indices and the cumulative distribution function needed for MC simulations.
Definition at line 2356 of file GModelSpectralTable.cpp.
References abs(), flux(), GNodeArray::inx_left(), log(), m_epivot, m_flux, m_gamma, m_lin_nodes, m_mc_cum, m_mc_emax, m_mc_emin, m_mc_exp, m_mc_max, m_mc_min, m_prefactor, GEnergy::MeV(), norm(), gammalib::plaw_photon_flux(), pow(), and GNodeArray::set_value().
Referenced by mc().
|
virtual |
Write model into XML element.
[in] | xml | XML element into which model information is written. |
Writes the spectral information into an XML element. The format of the XML element is
<spectrum type="FileFunction" file=".."> <parameter name="Normalization" scale=".." value=".." min=".." max=".." free=".."/> </spectrum>
In addition, the method writes the model table parameters into the XML file.
Note that the function nodes will not be written since they will not be altered by any method.
Implements GModelSpectral.
Definition at line 788 of file GModelSpectralTable.cpp.
References GXmlElement::attribute(), G_WRITE, m_escale_par, m_filename, m_norm, m_table_pars, GOptimizerPar::name(), norm(), GModelSpectralTablePars::size(), type(), GModelPar::write(), gammalib::xml_check_type(), gammalib::xml_file_reduce(), and gammalib::xml_need_par().
|
protected |
Energy boundaries.
Definition at line 130 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_eng_table(), create_spec_table(), ebounds(), GModelSpectralTable(), init_members(), load_eng(), print(), scale_energy(), and set_energy_nodes().
|
mutableprotected |
Energy fluxes.
Definition at line 148 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), init_members(), and update_flux().
|
mutableprotected |
Power-law pivot energies.
Definition at line 146 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
protected |
Energy scale.
Definition at line 133 of file GModelSpectralTable.hpp.
Referenced by copy_members(), has_energy_scale(), init_members(), scale_energy(), and set_energy_nodes().
|
protected |
Energy scaling parameter.
Definition at line 132 of file GModelSpectralTable.hpp.
Referenced by copy_members(), energy_scale(), eval(), init_members(), scale_energy(), and write().
|
mutableprotected |
Filename of table.
Definition at line 131 of file GModelSpectralTable.hpp.
Referenced by copy_members(), filename(), init_members(), load(), print(), save(), and write().
|
mutableprotected |
Photon fluxes.
Definition at line 147 of file GModelSpectralTable.hpp.
Referenced by copy_members(), flux(), init_members(), update_flux(), and update_mc().
|
mutableprotected |
Power-law indices.
Definition at line 145 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
mutableprotected |
Last parameter values.
Definition at line 139 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), scale_energy(), and update().
|
mutableprotected |
Energy nodes of function.
Definition at line 140 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), scale_energy(), set_energy_nodes(), update_flux(), and update_mc().
|
mutableprotected |
Function values and grad's.
Definition at line 142 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), init_members(), set_energy_nodes(), update(), and update_flux().
|
protected |
log10 of energy scale
Definition at line 134 of file GModelSpectralTable.hpp.
Referenced by copy_members(), energy_scale(), eval(), init_members(), scale_energy(), and set_energy_nodes().
|
mutableprotected |
log10(Energy) nodes of function
Definition at line 141 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), init_members(), scale_energy(), and set_energy_nodes().
|
mutableprotected |
log10(Function) values and grad's
Definition at line 143 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), set_energy_nodes(), and update().
|
mutableprotected |
Cumulative distribution.
Definition at line 151 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Maximum energy.
Definition at line 150 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update_mc().
|
mutableprotected |
Minimum energy.
Definition at line 149 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update_mc().
|
mutableprotected |
Exponent for MC.
Definition at line 154 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Upper boundary for MC.
Definition at line 153 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Lower boundary for MC.
Definition at line 152 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Number of energy bins.
Definition at line 138 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update().
|
protected |
Normalization factor.
Definition at line 127 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), GModelSpectralTable(), init_members(), norm(), read(), set_par_pointers(), and write().
|
mutableprotected |
Number of parameters.
Definition at line 137 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law normalisations.
Definition at line 144 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
protected |
Spectra.
Definition at line 129 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_spec_table(), GModelSpectralTable(), init_members(), load_spec(), print(), scale_energy(), and update().
|
protected |
Table model parameters.
Definition at line 128 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_par_table(), create_spec_table(), energy_scale(), eval(), GModelSpectralTable(), init_members(), load_par(), load_spec(), nspectra(), par_index(), print(), read(), scale_energy(), set_par_pointers(), table_par(), update(), and write().