GammaLib 2.0.0
|
Spectral table model class. More...
#include <GModelSpectralTable.hpp>
Public Member Functions | |
GModelSpectralTable (void) | |
Void constructor. | |
GModelSpectralTable (const GFilename &filename, const double &norm) | |
File constructor. | |
GModelSpectralTable (const GEbounds &ebounds, const GModelSpectralTablePars &pars, const GNdarray &spectra) | |
Table model constructor. | |
GModelSpectralTable (const GXmlElement &xml) | |
XML constructor. | |
GModelSpectralTable (const GModelSpectralTable &model) | |
Copy constructor. | |
virtual | ~GModelSpectralTable (void) |
Destructor. | |
virtual GModelSpectralTable & | operator= (const GModelSpectralTable &model) |
Assignment operator. | |
virtual void | clear (void) |
Clear table model. | |
virtual GModelSpectralTable * | clone (void) const |
Clone table model. | |
virtual std::string | classname (void) const |
Return class name. | |
virtual std::string | type (void) const |
Return model type. | |
virtual double | eval (const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const |
Evaluate spectral table model. | |
virtual double | flux (const GEnergy &emin, const GEnergy &emax) const |
Returns model photon flux between [emin, emax] (units: ph/cm2/s) | |
virtual double | eflux (const GEnergy &emin, const GEnergy &emax) const |
Returns model energy flux between [emin, emax] (units: erg/cm2/s) | |
virtual GEnergy | mc (const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const |
Returns MC energy between [emin, emax]. | |
virtual void | read (const GXmlElement &xml) |
Read model from XML element. | |
virtual void | write (GXmlElement &xml) const |
Write model into XML element. | |
virtual std::string | print (const GChatter &chatter=NORMAL) const |
Print table model information. | |
GModelSpectralTablePar & | table_par (const int &index) |
Return reference to table parameter. | |
const GModelSpectralTablePar & | table_par (const int &index) const |
Return const reference to table parameter. | |
GModelSpectralTablePar & | table_par (const std::string &name) |
Return reference to table parameter. | |
const GModelSpectralTablePar & | table_par (const std::string &name) const |
Return const reference to table parameter. | |
double | norm (void) const |
Return normalization factor. | |
void | norm (const double &norm) |
Set normalization factor. | |
const GEbounds & | ebounds (void) const |
Return reference to energy boundaries. | |
void | load (const GFilename &filename) |
Load table from file. | |
void | save (const GFilename &filename, const bool &clobber=false) const |
Save table into file. | |
const GFilename & | filename (void) const |
Return file name. | |
Public Member Functions inherited from GModelSpectral | |
GModelSpectral (void) | |
Void constructor. | |
GModelSpectral (const GModelSpectral &model) | |
Copy constructor. | |
virtual | ~GModelSpectral (void) |
Destructor. | |
virtual GModelSpectral & | operator= (const GModelSpectral &model) |
Assignment operator. | |
virtual GModelPar & | operator[] (const int &index) |
Returns model parameter. | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns model parameter (const version) | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns reference to model parameter. | |
virtual const GModelPar & | operator[] (const std::string &name) const |
Returns reference to model parameter (const version) | |
GModelPar & | at (const int &index) |
Returns model parameter. | |
const GModelPar & | at (const int &index) const |
Returns model parameter (const version) | |
bool | has_par (const std::string &name) const |
Checks if parameter name exists. | |
int | size (void) const |
Return number of parameters. | |
void | autoscale (void) |
Autoscale parameters. | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. | |
Protected Member Functions | |
void | init_members (void) |
Initialise class members. | |
void | copy_members (const GModelSpectralTable &model) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
void | set_par_pointers (void) |
Set parameter pointers. | |
void | set_energy_nodes (void) |
Set energy nodes from energy boundaries. | |
GFitsBinTable | create_par_table (void) const |
Create PARAMETERS FITS table. | |
GFitsBinTable | create_eng_table (void) const |
Create ENERGIES FITS table. | |
GFitsBinTable | create_spec_table (void) const |
Create SPECTRA FITS table. | |
void | load_par (const GFits &fits) |
Load data from PARAMETERS extension. | |
void | load_eng (const GFits &fits) |
Load data from ENERGIES extension. | |
void | load_spec (const GFits &fits) |
Load data from SPECTRA extension. | |
int | par_index (const std::string &name) const |
Return index for parameter name. | |
void | update (void) const |
Update cache for spectral table model computation. | |
void | update_flux (void) const |
Update flux cache. | |
void | update_mc (const GEnergy &emin, const GEnergy &emax) const |
Update MC cache. | |
Protected Member Functions inherited from GModelSpectral | |
void | init_members (void) |
Initialise class members. | |
void | copy_members (const GModelSpectral &model) |
Copy class members. | |
void | free_members (void) |
Delete class members. | |
Protected Attributes | |
GModelPar | m_norm |
Normalization factor. | |
GModelSpectralTablePars | m_table_pars |
Table model parameters. | |
GNdarray | m_spectra |
Spectra. | |
GEbounds | m_ebounds |
Energy boundaries. | |
GFilename | m_filename |
Filename of table. | |
int | m_npars |
Number of parameters. | |
int | m_nebins |
Number of energy bins. | |
std::vector< double > | m_last_values |
Last parameter values. | |
GNodeArray | m_lin_nodes |
Energy nodes of function. | |
GNodeArray | m_log_nodes |
log10(Energy) nodes of function | |
GNdarray | m_lin_values |
Function values and grad's. | |
GNdarray | m_log_values |
log10(Function) values and grad's | |
std::vector< double > | m_prefactor |
Power-law normalisations. | |
std::vector< double > | m_gamma |
Power-law indices. | |
std::vector< double > | m_epivot |
Power-law pivot energies. | |
std::vector< double > | m_flux |
Photon fluxes. | |
std::vector< double > | m_eflux |
Energy fluxes. | |
GEnergy | m_mc_emin |
Minimum energy. | |
GEnergy | m_mc_emax |
Maximum energy. | |
std::vector< double > | m_mc_cum |
Cumulative distribution. | |
std::vector< double > | m_mc_min |
Lower boundary for MC. | |
std::vector< double > | m_mc_max |
Upper boundary for MC. | |
std::vector< double > | m_mc_exp |
Exponent for MC. | |
Protected Attributes inherited from GModelSpectral | |
std::vector< GModelPar * > | m_pars |
Parameter pointers. | |
Spectral table model class.
Definition at line 55 of file GModelSpectralTable.hpp.
GModelSpectralTable::GModelSpectralTable | ( | void | ) |
Void constructor.
Definition at line 85 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 104 of file GModelSpectralTable.cpp.
References filename(), init_members(), load(), m_norm, 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 136 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(), GEbounds::size(), GModelSpectralTablePars::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 204 of file GModelSpectralTable.cpp.
References init_members(), and read().
GModelSpectralTable::GModelSpectralTable | ( | const GModelSpectralTable & | model | ) |
Copy constructor.
[in] | model | Table model. |
Definition at line 223 of file GModelSpectralTable.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GModelSpectral.
Definition at line 157 of file GModelSpectralTable.hpp.
|
virtual |
Clear table model.
Implements GModelSpectral.
Definition at line 295 of file GModelSpectralTable.cpp.
References GModelSpectral::free_members(), free_members(), GModelSpectral::init_members(), and init_members().
Referenced by load().
|
virtual |
Clone table model.
Implements GModelSpectral.
Definition at line 313 of file GModelSpectralTable.cpp.
References GModelSpectralTable().
|
protected |
Copy class members.
[in] | model | Table model. |
Definition at line 1101 of file GModelSpectralTable.cpp.
References m_ebounds, m_eflux, m_epivot, m_filename, m_flux, m_gamma, m_last_values, m_lin_nodes, m_lin_values, 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 1355 of file GModelSpectralTable.cpp.
References GFitsTable::append(), GFitsHDU::card(), GEbounds::emax(), GEbounds::emin(), GFitsHDU::extname(), GEnergy::keV(), m_ebounds, GEbounds::size(), and GFitsTableCol::unit().
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 1216 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(), GModelSpectral::size(), GModelSpectralTablePars::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 1400 of file GModelSpectralTable.cpp.
References GFitsTable::append(), GFitsHDU::card(), GNdarray::dim(), GFitsHDU::extname(), m_ebounds, m_spectra, m_table_pars, GNdarray::shape(), GEbounds::size(), GModelSpectralTablePars::size(), and GFitsTableCol::unit().
Referenced by save().
|
inline |
Return reference to energy boundaries.
Returns a reference to energy boundaries.
Definition at line 214 of file GModelSpectralTable.hpp.
References m_ebounds.
Referenced by GModelSpectralTable(), and update().
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
[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 556 of file GModelSpectralTable.cpp.
References eflux(), 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 eflux(), and update_flux().
|
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 374 of file GModelSpectralTable.cpp.
References GOptimizerPar::factor_gradient(), GNodeArray::inx_left(), GNodeArray::inx_right(), GOptimizerPar::is_free(), gammalib::is_infinite(), gammalib::is_notanumber(), GEnergy::log10MeV(), m_lin_values, m_log_nodes, m_norm, m_table_pars, norm(), GOptimizerPar::scale(), GNodeArray::set_value(), GModelSpectralTablePars::size(), update(), GOptimizerPar::value(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
|
inline |
Return file name.
Returns the name of the table file.
Definition at line 228 of file GModelSpectralTable.hpp.
References m_filename.
Referenced by GModelSpectralTable(), load(), and save().
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
[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 463 of file GModelSpectralTable.cpp.
References flux(), 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 flux(), update_flux(), and update_mc().
|
protected |
Delete class members.
Definition at line 1148 of file GModelSpectralTable.cpp.
Referenced by clear(), operator=(), and ~GModelSpectralTable().
|
protected |
Initialise class members.
Definition at line 1046 of file GModelSpectralTable.cpp.
References GEbounds::clear(), GEnergy::clear(), GFilename::clear(), GModelSpectralTablePars::clear(), GNdarray::clear(), GNodeArray::clear(), GOptimizerPar::clear(), GOptimizerPar::free(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_ebounds, m_eflux, m_epivot, m_filename, m_flux, m_gamma, m_last_values, m_lin_nodes, m_lin_values, 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(), GModelSpectralTable(), GModelSpectralTable(), GModelSpectralTable(), 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 789 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 1583 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 1487 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 1627 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 647 of file GModelSpectralTable.cpp.
References gammalib::check_energy_interval(), G_MC, m_mc_cum, m_mc_exp, m_mc_max, m_mc_min, GEnergy::MeV(), GRan::uniform(), update(), update_flux(), and update_mc().
|
inline |
Set normalization factor.
[in] | norm | Normalization factor. |
Sets the normalization factor.
Definition at line 199 of file GModelSpectralTable.hpp.
References m_norm, norm(), and GOptimizerPar::value().
|
inline |
Return normalization factor.
Returns the normalization factor.
Definition at line 185 of file GModelSpectralTable.hpp.
References m_norm, and GOptimizerPar::value().
Referenced by eflux(), eval(), flux(), GModelSpectralTable(), norm(), read(), update_mc(), and write().
|
virtual |
Assignment operator.
[in] | model | Table model. |
Definition at line 262 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 1707 of file GModelSpectralTable.cpp.
References G_PAR_INDEX, m_table_pars, and GModelSpectral::size().
Referenced by table_par(), and table_par().
Print table model information.
[in] | chatter | Chattiness. |
Implements GModelSpectral.
Definition at line 956 of file GModelSpectralTable.cpp.
References GNdarray::dim(), GEbounds::emax(), GEbounds::emin(), m_ebounds, m_filename, GModelSpectral::m_pars, m_spectra, m_table_pars, max(), min(), gammalib::parformat(), GEnergy::print(), print(), GNdarray::shape(), SILENT, GEbounds::size(), GModelSpectral::size(), GModelSpectralTablePars::size(), gammalib::str(), and GFilename::url().
Referenced by print().
|
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 711 of file GModelSpectralTable.cpp.
References GXmlElement::attribute(), G_READ, 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 840 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 |
Set energy nodes from energy boundaries.
Definition at line 1179 of file GModelSpectralTable.cpp.
References GNodeArray::append(), GEbounds::elogmean(), m_ebounds, m_lin_nodes, m_lin_values, 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 1158 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 886 of file GModelSpectralTable.cpp.
References G_TABLE_PAR, m_table_pars, and GModelSpectral::size().
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 905 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 924 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 940 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 171 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 1794 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(), GEbounds::size(), GModelSpectralTablePars::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 2009 of file GModelSpectralTable.cpp.
References eflux(), flux(), 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(), and GNodeArray::size().
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 2071 of file GModelSpectralTable.cpp.
References flux(), GNodeArray::inx_left(), 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(), 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 755 of file GModelSpectralTable.cpp.
References GXmlElement::attribute(), G_WRITE, 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 126 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_eng_table(), create_spec_table(), ebounds(), GModelSpectralTable(), init_members(), load_eng(), print(), and set_energy_nodes().
|
mutableprotected |
Energy fluxes.
Definition at line 141 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), init_members(), and update_flux().
|
mutableprotected |
Power-law pivot energies.
Definition at line 139 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
mutableprotected |
Filename of table.
Definition at line 127 of file GModelSpectralTable.hpp.
Referenced by copy_members(), filename(), init_members(), load(), print(), save(), and write().
|
mutableprotected |
Photon fluxes.
Definition at line 140 of file GModelSpectralTable.hpp.
Referenced by copy_members(), flux(), init_members(), update_flux(), and update_mc().
|
mutableprotected |
Power-law indices.
Definition at line 138 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
mutableprotected |
Last parameter values.
Definition at line 132 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Energy nodes of function.
Definition at line 133 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), set_energy_nodes(), update_flux(), and update_mc().
|
mutableprotected |
Function values and grad's.
Definition at line 135 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), init_members(), set_energy_nodes(), update(), and update_flux().
|
mutableprotected |
log10(Energy) nodes of function
Definition at line 134 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), init_members(), and set_energy_nodes().
|
mutableprotected |
log10(Function) values and grad's
Definition at line 136 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), set_energy_nodes(), and update().
|
mutableprotected |
Cumulative distribution.
Definition at line 144 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Maximum energy.
Definition at line 143 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update_mc().
|
mutableprotected |
Minimum energy.
Definition at line 142 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update_mc().
|
mutableprotected |
Exponent for MC.
Definition at line 147 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Upper boundary for MC.
Definition at line 146 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Lower boundary for MC.
Definition at line 145 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), mc(), and update_mc().
|
mutableprotected |
Number of energy bins.
Definition at line 131 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update().
|
protected |
Normalization factor.
Definition at line 123 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eval(), GModelSpectralTable(), init_members(), norm(), norm(), read(), set_par_pointers(), and write().
|
mutableprotected |
Number of parameters.
Definition at line 130 of file GModelSpectralTable.hpp.
Referenced by copy_members(), init_members(), and update().
|
mutableprotected |
Power-law normalisations.
Definition at line 137 of file GModelSpectralTable.hpp.
Referenced by copy_members(), eflux(), flux(), init_members(), update_flux(), and update_mc().
|
protected |
Spectra.
Definition at line 125 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_spec_table(), GModelSpectralTable(), init_members(), load_spec(), print(), and update().
|
protected |
Table model parameters.
Definition at line 124 of file GModelSpectralTable.hpp.
Referenced by copy_members(), create_par_table(), create_spec_table(), eval(), GModelSpectralTable(), init_members(), load_par(), load_spec(), par_index(), print(), read(), set_par_pointers(), table_par(), table_par(), table_par(), table_par(), update(), and write().