GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralTable Class Reference

Spectral table model class. More...

#include <GModelSpectralTable.hpp>

Inheritance diagram for GModelSpectralTable:
GModelSpectral GBase

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 GModelSpectralTableoperator= (const GModelSpectralTable &model)
 Assignment operator.
 
virtual void clear (void)
 Clear table model.
 
virtual GModelSpectralTableclone (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.
 
GModelSpectralTablePartable_par (const int &index)
 Return reference to table parameter.
 
const GModelSpectralTablePartable_par (const int &index) const
 Return const reference to table parameter.
 
GModelSpectralTablePartable_par (const std::string &name)
 Return reference to table parameter.
 
const GModelSpectralTablePartable_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 GEboundsebounds (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 GFilenamefilename (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 GModelSpectraloperator= (const GModelSpectral &model)
 Assignment operator.
 
virtual GModelParoperator[] (const int &index)
 Returns model parameter.
 
virtual const GModelParoperator[] (const int &index) const
 Returns model parameter (const version)
 
virtual GModelParoperator[] (const std::string &name)
 Returns reference to model parameter.
 
virtual const GModelParoperator[] (const std::string &name) const
 Returns reference to model parameter (const version)
 
GModelParat (const int &index)
 Returns model parameter.
 
const GModelParat (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.
 

Detailed Description

Spectral table model class.

Definition at line 55 of file GModelSpectralTable.hpp.

Constructor & Destructor Documentation

◆ GModelSpectralTable() [1/5]

GModelSpectralTable::GModelSpectralTable ( void )

Void constructor.

Definition at line 85 of file GModelSpectralTable.cpp.

References init_members().

Referenced by clone().

◆ GModelSpectralTable() [2/5]

GModelSpectralTable::GModelSpectralTable ( const GFilename & filename,
const double & norm )

File constructor.

Parameters
[in]filenameFile name of table model.
[in]normNormalization 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() [3/5]

GModelSpectralTable::GModelSpectralTable ( const GEbounds & ebounds,
const GModelSpectralTablePars & pars,
const GNdarray & spectra )

Table model constructor.

Parameters
[in]eboundsEnergy boundaries.
[in]parsTable model parameters.
[in]spectraSpectra.

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().

◆ GModelSpectralTable() [4/5]

GModelSpectralTable::GModelSpectralTable ( const GXmlElement & xml)
explicit

XML constructor.

Parameters
[in]xmlXML 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() [5/5]

GModelSpectralTable::GModelSpectralTable ( const GModelSpectralTable & model)

Copy constructor.

Parameters
[in]modelTable model.

Definition at line 223 of file GModelSpectralTable.cpp.

References copy_members(), and init_members().

◆ ~GModelSpectralTable()

GModelSpectralTable::~GModelSpectralTable ( void )
virtual

Destructor.

Definition at line 240 of file GModelSpectralTable.cpp.

References free_members().

Member Function Documentation

◆ classname()

std::string GModelSpectralTable::classname ( void ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GModelSpectralTable").

Implements GModelSpectral.

Definition at line 157 of file GModelSpectralTable.hpp.

◆ clear()

void GModelSpectralTable::clear ( void )
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().

◆ clone()

GModelSpectralTable * GModelSpectralTable::clone ( void ) const
virtual

Clone table model.

Implements GModelSpectral.

Definition at line 313 of file GModelSpectralTable.cpp.

References GModelSpectralTable().

◆ copy_members()

void GModelSpectralTable::copy_members ( const GModelSpectralTable & model)
protected

◆ create_eng_table()

GFitsBinTable GModelSpectralTable::create_eng_table ( void ) const
protected

Create ENERGIES FITS table.

Returns
Binary FITS table containing table model energies

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().

◆ create_par_table()

GFitsBinTable GModelSpectralTable::create_par_table ( void ) const
protected

◆ create_spec_table()

GFitsBinTable GModelSpectralTable::create_spec_table ( void ) const
protected

Create SPECTRA FITS table.

Returns
Binary FITS table containing table model spectra

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().

◆ ebounds()

const GEbounds & GModelSpectralTable::ebounds ( void ) const
inline

Return reference to energy boundaries.

Returns
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().

◆ eflux()

double GModelSpectralTable::eflux ( const GEnergy & emin,
const GEnergy & emax ) const
virtual

Returns model energy flux between [emin, emax] (units: erg/cm2/s)

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
Returns
Energy flux (erg/cm2/s).

Computes

\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE \]

where

  • [emin, emax] is an energy interval, and
  • \(S_{\rm E}(E | t)\) is the spectral model (ph/cm2/s/MeV).

Implements 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().

◆ eval()

double GModelSpectralTable::eval ( const GEnergy & srcEng,
const GTime & srcTime = GTime(),
const bool & gradients = false ) const
virtual

Evaluate spectral table model.

Parameters
[in]srcEngTrue photon energy.
[in]srcTimeTrue photon arrival time.
[in]gradientsCompute gradients?
Returns
Model value (ph/cm2/s/MeV).

Evaluates

\[ S_{\rm E}(E | t) = {\tt m\_norm} \times \left( w_l F_l(p) + w_r F_r(p) \right) \]

where

  • \({\tt m\_norm}\) is the normalization factor of the spectral table model,
  • \(w_l\) is the weight of the spectral vector \(F_l(p)\) with the largest energy \(E_l\) that satisfies \(E<E_l\), and
  • \(w_r\) is the weight of the spectral vector \(F_r(p)\) with the smallest energy \(E_r\) that satisfies \(E>E_r\).

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().

◆ filename()

const GFilename & GModelSpectralTable::filename ( void ) const
inline

Return file name.

Returns
Name of table file.

Returns the name of the table file.

Definition at line 228 of file GModelSpectralTable.hpp.

References m_filename.

Referenced by GModelSpectralTable(), load(), and save().

◆ flux()

double GModelSpectralTable::flux ( const GEnergy & emin,
const GEnergy & emax ) const
virtual

Returns model photon flux between [emin, emax] (units: ph/cm2/s)

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
Returns
Photon flux (ph/cm2/s).

Computes

\[ \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE \]

where

  • [emin, emax] is an energy interval, and
  • \(S_{\rm E}(E | t)\) is the spectral model (ph/cm2/s/MeV).

Implements 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().

◆ free_members()

void GModelSpectralTable::free_members ( void )
protected

Delete class members.

Definition at line 1148 of file GModelSpectralTable.cpp.

Referenced by clear(), operator=(), and ~GModelSpectralTable().

◆ init_members()

◆ load()

void GModelSpectralTable::load ( const GFilename & filename)

Load table from file.

Parameters
[in]filenameFile 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().

◆ load_eng()

void GModelSpectralTable::load_eng ( const GFits & fits)
protected

Load data from ENERGIES extension.

Parameters
[in]fitsFITS 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().

◆ load_par()

void GModelSpectralTable::load_par ( const GFits & fits)
protected

Load data from PARAMETERS extension.

Parameters
[in]fitsFITS file.
Exceptions
GException::invalid_valueNon-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().

◆ load_spec()

void GModelSpectralTable::load_spec ( const GFits & fits)
protected

Load data from SPECTRA extension.

Parameters
[in]fitsFITS 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().

◆ mc()

GEnergy GModelSpectralTable::mc ( const GEnergy & emin,
const GEnergy & emax,
const GTime & time,
GRan & ran ) const
virtual

Returns MC energy between [emin, emax].

Parameters
[in]eminMinimum photon energy.
[in]emaxMaximum photon energy.
[in]timeTrue photon arrival time.
[in,out]ranRandom number generator.
Returns
Energy.

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().

◆ norm() [1/2]

void GModelSpectralTable::norm ( const double & norm)
inline

Set normalization factor.

Parameters
[in]normNormalization factor.

Sets the normalization factor.

Definition at line 199 of file GModelSpectralTable.hpp.

References m_norm, norm(), and GOptimizerPar::value().

◆ norm() [2/2]

double GModelSpectralTable::norm ( void ) const
inline

Return normalization factor.

Returns
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().

◆ operator=()

GModelSpectralTable & GModelSpectralTable::operator= ( const GModelSpectralTable & model)
virtual

Assignment operator.

Parameters
[in]modelTable model.
Returns
Table model.

Definition at line 262 of file GModelSpectralTable.cpp.

References copy_members(), free_members(), init_members(), and GModelSpectral::operator=().

◆ par_index()

int GModelSpectralTable::par_index ( const std::string & name) const
protected

Return index for parameter name.

Parameters
[in]nameParameter name.
Returns
Parameter index.
Exceptions
GException::invalid_argumentParameter 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()

std::string GModelSpectralTable::print ( const GChatter & chatter = NORMAL) const
virtual

Print table model information.

Parameters
[in]chatterChattiness.
Returns
String containing table model information.

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().

◆ read()

void GModelSpectralTable::read ( const GXmlElement & xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML 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().

◆ save()

void GModelSpectralTable::save ( const GFilename & filename,
const bool & clobber = false ) const

Save table into file.

Parameters
[in]filenameFile name.
[in]clobberOverwrite 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().

◆ set_energy_nodes()

void GModelSpectralTable::set_energy_nodes ( void )
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().

◆ set_par_pointers()

void GModelSpectralTable::set_par_pointers ( void )
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().

◆ table_par() [1/4]

GModelSpectralTablePar & GModelSpectralTable::table_par ( const int & index)

Return reference to table parameter.

Parameters
[in]indexTable parameter index [0,...,size()[.
Returns
Reference to table parameter.

Definition at line 886 of file GModelSpectralTable.cpp.

References G_TABLE_PAR, m_table_pars, and GModelSpectral::size().

◆ table_par() [2/4]

const GModelSpectralTablePar & GModelSpectralTable::table_par ( const int & index) const

Return const reference to table parameter.

Parameters
[in]indexTable parameter index [0,...,size()[.
Returns
Const reference to table parameter.

Definition at line 905 of file GModelSpectralTable.cpp.

References G_TABLE_PAR, m_table_pars, and GModelSpectral::size().

◆ table_par() [3/4]

GModelSpectralTablePar & GModelSpectralTable::table_par ( const std::string & name)

Return reference to table parameter.

Parameters
[in]nameTable parameter name.
Returns
Reference to table parameter.

Definition at line 924 of file GModelSpectralTable.cpp.

References m_table_pars, and par_index().

◆ table_par() [4/4]

const GModelSpectralTablePar & GModelSpectralTable::table_par ( const std::string & name) const

Return const reference to table parameter.

Parameters
[in]nameTable parameter name.
Returns
Const reference to table parameter.

Definition at line 940 of file GModelSpectralTable.cpp.

References m_table_pars, and par_index().

◆ type()

std::string GModelSpectralTable::type ( void ) const
inlinevirtual

Return model type.

Returns
"TableModel".

Returns the type of the spectral model.

Implements GModelSpectral.

Definition at line 171 of file GModelSpectralTable.hpp.

Referenced by write().

◆ update()

void GModelSpectralTable::update ( void ) const
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

  • \(M=2^N\) is the number of parameter combinations,
  • \(N\) is the number of table model parameters,
  • \(w_x(p) = \{w_0^l, w_0^r, w_1^l, w_1^r, ...\}\) is an array of subsequently arranged left and right weighting factors for the linear interpolation of parameters, where \(w_0^l\) and \(w_0^r\) are the left and right weighting factors for the first parameter, \(w_1^l\) and \(w_1^r\) are the left and right weighting factors for the second parameter, and so on,
  • \(x=2 k + i/2^k \mod 2\) is the index in the array of weighting factors for parameter combination \(k\) and parameter \(i\), and
  • \(F_p(E)\) are the table model spectra, computed for a grid of possible parameter values.

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().

Referenced by eflux(), eval(), flux(), and mc().

◆ update_flux()

void GModelSpectralTable::update_flux ( void ) const
protected

◆ update_mc()

void GModelSpectralTable::update_mc ( const GEnergy & emin,
const GEnergy & emax ) const
protected

Update MC cache.

Parameters
[in]eminMinimum energy.
[in]emaxMaximum 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().

◆ write()

void GModelSpectralTable::write ( GXmlElement & xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML 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().

Member Data Documentation

◆ m_ebounds

GEbounds GModelSpectralTable::m_ebounds
protected

◆ m_eflux

std::vector<double> GModelSpectralTable::m_eflux
mutableprotected

Energy fluxes.

Definition at line 141 of file GModelSpectralTable.hpp.

Referenced by copy_members(), eflux(), init_members(), and update_flux().

◆ m_epivot

std::vector<double> GModelSpectralTable::m_epivot
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().

◆ m_filename

GFilename GModelSpectralTable::m_filename
mutableprotected

Filename of table.

Definition at line 127 of file GModelSpectralTable.hpp.

Referenced by copy_members(), filename(), init_members(), load(), print(), save(), and write().

◆ m_flux

std::vector<double> GModelSpectralTable::m_flux
mutableprotected

Photon fluxes.

Definition at line 140 of file GModelSpectralTable.hpp.

Referenced by copy_members(), flux(), init_members(), update_flux(), and update_mc().

◆ m_gamma

std::vector<double> GModelSpectralTable::m_gamma
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().

◆ m_last_values

std::vector<double> GModelSpectralTable::m_last_values
mutableprotected

Last parameter values.

Definition at line 132 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), and update().

◆ m_lin_nodes

GNodeArray GModelSpectralTable::m_lin_nodes
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().

◆ m_lin_values

GNdarray GModelSpectralTable::m_lin_values
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().

◆ m_log_nodes

GNodeArray GModelSpectralTable::m_log_nodes
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().

◆ m_log_values

GNdarray GModelSpectralTable::m_log_values
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().

◆ m_mc_cum

std::vector<double> GModelSpectralTable::m_mc_cum
mutableprotected

Cumulative distribution.

Definition at line 144 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), mc(), and update_mc().

◆ m_mc_emax

GEnergy GModelSpectralTable::m_mc_emax
mutableprotected

Maximum energy.

Definition at line 143 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), and update_mc().

◆ m_mc_emin

GEnergy GModelSpectralTable::m_mc_emin
mutableprotected

Minimum energy.

Definition at line 142 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), and update_mc().

◆ m_mc_exp

std::vector<double> GModelSpectralTable::m_mc_exp
mutableprotected

Exponent for MC.

Definition at line 147 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), mc(), and update_mc().

◆ m_mc_max

std::vector<double> GModelSpectralTable::m_mc_max
mutableprotected

Upper boundary for MC.

Definition at line 146 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), mc(), and update_mc().

◆ m_mc_min

std::vector<double> GModelSpectralTable::m_mc_min
mutableprotected

Lower boundary for MC.

Definition at line 145 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), mc(), and update_mc().

◆ m_nebins

int GModelSpectralTable::m_nebins
mutableprotected

Number of energy bins.

Definition at line 131 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), and update().

◆ m_norm

GModelPar GModelSpectralTable::m_norm
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().

◆ m_npars

int GModelSpectralTable::m_npars
mutableprotected

Number of parameters.

Definition at line 130 of file GModelSpectralTable.hpp.

Referenced by copy_members(), init_members(), and update().

◆ m_prefactor

std::vector<double> GModelSpectralTable::m_prefactor
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().

◆ m_spectra

GNdarray GModelSpectralTable::m_spectra
protected

◆ m_table_pars


The documentation for this class was generated from the following files: