GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSpectralTable.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralTable.hpp - Spectral table model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2019-2022 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GModelSpectralTable.hpp
23 * @brief Spectral table model class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMODELSPECTRALTABLE_HPP
28#define GMODELSPECTRALTABLE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <vector>
32#include <string>
33#include "GModelSpectral.hpp"
34#include "GEbounds.hpp"
35#include "GModelPar.hpp"
36#include "GNdarray.hpp"
37#include "GNodeArray.hpp"
38#include "GFilename.hpp"
40
41/* __ Forward declarations _______________________________________________ */
42class GRan;
43class GEnergy;
44class GTime;
45class GFits;
46class GXmlElement;
47class GFitsBinTable;
48
49
50/***********************************************************************//**
51 * @class GModelSpectralTable
52 *
53 * @brief Spectral table model class
54 ***************************************************************************/
56
57public:
58 // Constructors and destructors
60 GModelSpectralTable(const GFilename& filename, const double& norm);
62 const GModelSpectralTablePars& pars,
63 const GNdarray& spectra);
64 explicit GModelSpectralTable(const GXmlElement& xml);
66 virtual ~GModelSpectralTable(void);
67
68 // Operators
70
71 // Implemented pure virtual base class methods
72 virtual void clear(void);
73 virtual GModelSpectralTable* clone(void) const;
74 virtual std::string classname(void) const;
75 virtual std::string type(void) const;
76 virtual double eval(const GEnergy& srcEng,
77 const GTime& srcTime = GTime(),
78 const bool& gradients = false) const;
79 virtual double flux(const GEnergy& emin,
80 const GEnergy& emax) const;
81 virtual double eflux(const GEnergy& emin,
82 const GEnergy& emax) const;
83 virtual GEnergy mc(const GEnergy& emin,
84 const GEnergy& emax,
85 const GTime& time,
86 GRan& ran) const;
87 virtual void read(const GXmlElement& xml);
88 virtual void write(GXmlElement& xml) const;
89 virtual std::string print(const GChatter& chatter = NORMAL) const;
90
91 // Other methods
92 int nspectra(void) const;
93 GModelSpectralTablePar& table_par(const int& index);
94 const GModelSpectralTablePar& table_par(const int& index) const;
95 GModelSpectralTablePar& table_par(const std::string& name);
96 const GModelSpectralTablePar& table_par(const std::string& name) const;
97 double norm(void) const;
98 void norm(const double& norm);
99 const GEbounds& ebounds(void) const;
100 void load(const GFilename& filename);
101 void save(const GFilename& filename,
102 const bool& clobber = false) const;
103 const GFilename& filename(void) const;
104 void energy_scale(const std::string& name);
105
106protected:
107 // Protected methods
108 void init_members(void);
109 void copy_members(const GModelSpectralTable& model);
110 void free_members(void);
111 void set_par_pointers(void);
112 void set_energy_nodes(void);
113 void scale_energy(void);
114 bool has_energy_scale(void) const;
118 void load_par(const GFits& fits);
119 void load_eng(const GFits& fits);
120 void load_spec(const GFits& fits);
121 int par_index(const std::string& name) const;
122 void update(void) const;
123 void update_flux(void) const;
124 void update_mc(const GEnergy& emin, const GEnergy& emax) const;
125
126 // Protected members
127 GModelPar m_norm; //!< Normalization factor
128 GModelSpectralTablePars m_table_pars; //!< Table model parameters
129 GNdarray m_spectra; //!< Spectra
130 GEbounds m_ebounds; //!< Energy boundaries
131 mutable GFilename m_filename; //!< Filename of table
132 std::string m_escale_par; //!< Energy scaling parameter
133 double m_escale; //!< Energy scale
134 double m_log10escale; //!< log10 of energy scale
135
136 // Cached members used for pre-computations
137 mutable int m_npars; //!< Number of parameters
138 mutable int m_nebins; //!< Number of energy bins
139 mutable std::vector<double> m_last_values; //!< Last parameter values
140 mutable GNodeArray m_lin_nodes; //!< Energy nodes of function
141 mutable GNodeArray m_log_nodes; //!< log10(Energy) nodes of function
142 mutable GNdarray m_lin_values; //!< Function values and grad's
143 mutable GNdarray m_log_values; //!< log10(Function) values and grad's
144 mutable std::vector<double> m_prefactor; //!< Power-law normalisations
145 mutable std::vector<double> m_gamma; //!< Power-law indices
146 mutable std::vector<double> m_epivot; //!< Power-law pivot energies
147 mutable std::vector<double> m_flux; //!< Photon fluxes
148 mutable std::vector<double> m_eflux; //!< Energy fluxes
149 mutable GEnergy m_mc_emin; //!< Minimum energy
150 mutable GEnergy m_mc_emax; //!< Maximum energy
151 mutable std::vector<double> m_mc_cum; //!< Cumulative distribution
152 mutable std::vector<double> m_mc_min; //!< Lower boundary for MC
153 mutable std::vector<double> m_mc_max; //!< Upper boundary for MC
154 mutable std::vector<double> m_mc_exp; //!< Exponent for MC
155};
156
157
158/***********************************************************************//**
159 * @brief Return class name
160 *
161 * @return String containing the class name ("GModelSpectralTable").
162 ***************************************************************************/
163inline
164std::string GModelSpectralTable::classname(void) const
165{
166 return ("GModelSpectralTable");
167}
168
169
170/***********************************************************************//**
171 * @brief Return model type
172 *
173 * @return "TableModel".
174 *
175 * Returns the type of the spectral model.
176 ***************************************************************************/
177inline
178std::string GModelSpectralTable::type(void) const
179{
180 return ("TableModel");
181}
182
183
184/***********************************************************************//**
185 * @brief Return normalization factor
186 *
187 * @return Normalization factor.
188 *
189 * Returns the normalization factor.
190 ***************************************************************************/
191inline
193{
194 return (m_norm.value());
195}
196
197
198/***********************************************************************//**
199 * @brief Set normalization factor
200 *
201 * @param[in] norm Normalization factor.
202 *
203 * Sets the normalization factor.
204 ***************************************************************************/
205inline
207{
209 return;
210}
211
212
213/***********************************************************************//**
214 * @brief Return reference to energy boundaries
215 *
216 * @return Reference to energy boundaries.
217 *
218 * Returns a reference to energy boundaries.
219 ***************************************************************************/
220inline
222{
223 return (m_ebounds);
224}
225
226
227/***********************************************************************//**
228 * @brief Return file name
229 *
230 * @return Name of table file.
231 *
232 * Returns the name of the table file.
233 ***************************************************************************/
234inline
236{
237 return (m_filename);
238}
239
240#endif /* GMODELSPECTRALTABLE_HPP */
Energy boundaries class interface definition.
Filename class interface definition.
Model parameter class interface definition.
Spectral table model parameter container class definition.
Abstract spectral model base class interface definition.
N-dimensional array class interface definition.
Node array class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
double norm(const GVector &vector)
Computes vector norm.
Definition GVector.cpp:932
Energy boundaries container class.
Definition GEbounds.hpp:60
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Filename class.
Definition GFilename.hpp:62
FITS binary table class.
FITS file class.
Definition GFits.hpp:63
Model parameter class.
Definition GModelPar.hpp:87
Spectral table model parameter class.
Spectral table model parameter container class.
Spectral table model class.
void scale_energy(void)
Scale energy.
GModelSpectralTable(void)
Void constructor.
virtual void write(GXmlElement &xml) const
Write model into XML element.
std::string m_escale_par
Energy scaling parameter.
std::vector< double > m_mc_cum
Cumulative distribution.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate spectral table model.
virtual void read(const GXmlElement &xml)
Read model from XML element.
std::vector< double > m_mc_min
Lower boundary for MC.
void save(const GFilename &filename, const bool &clobber=false) const
Save table into file.
GModelPar m_norm
Normalization factor.
void load_par(const GFits &fits)
Load data from PARAMETERS extension.
void load_spec(const GFits &fits)
Load data from SPECTRA extension.
GModelSpectralTablePar & table_par(const int &index)
Return reference to table parameter.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print table model information.
GEnergy m_mc_emax
Maximum energy.
GEbounds m_ebounds
Energy boundaries.
GNodeArray m_log_nodes
log10(Energy) nodes of function
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
std::vector< double > m_epivot
Power-law pivot energies.
virtual std::string type(void) const
Return model type.
void init_members(void)
Initialise class members.
double m_escale
Energy scale.
GFilename m_filename
Filename of table.
void set_par_pointers(void)
Set parameter pointers.
int nspectra(void) const
Return number of spectra in table model.
int par_index(const std::string &name) const
Return index for parameter name.
void set_energy_nodes(void)
Set energy nodes from energy boundaries.
void free_members(void)
Delete class members.
std::vector< double > m_mc_exp
Exponent for MC.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
int m_nebins
Number of energy bins.
bool has_energy_scale(void) const
Signal that energy scale was set.
void energy_scale(const std::string &name)
Set energy scale.
GNdarray m_log_values
log10(Function) values and grad's
GEnergy m_mc_emin
Minimum energy.
virtual ~GModelSpectralTable(void)
Destructor.
double norm(void) const
Return normalization factor.
GNodeArray m_lin_nodes
Energy nodes of function.
std::vector< double > m_flux
Photon fluxes.
void update_mc(const GEnergy &emin, const GEnergy &emax) const
Update MC cache.
void update(void) const
Update cache for spectral table model computation.
GNdarray m_lin_values
Function values and grad's.
GFitsBinTable create_eng_table(void) const
Create ENERGIES FITS table.
const GEbounds & ebounds(void) const
Return reference to energy boundaries.
virtual void clear(void)
Clear table model.
virtual std::string classname(void) const
Return class name.
virtual GModelSpectralTable * clone(void) const
Clone table model.
void load(const GFilename &filename)
Load table from file.
double m_log10escale
log10 of energy scale
std::vector< double > m_mc_max
Upper boundary for MC.
std::vector< double > m_last_values
Last parameter values.
void copy_members(const GModelSpectralTable &model)
Copy class members.
GFitsBinTable create_par_table(void) const
Create PARAMETERS FITS table.
void update_flux(void) const
Update flux cache.
std::vector< double > m_prefactor
Power-law normalisations.
int m_npars
Number of parameters.
void load_eng(const GFits &fits)
Load data from ENERGIES extension.
virtual GModelSpectralTable & operator=(const GModelSpectralTable &model)
Assignment operator.
std::vector< double > m_gamma
Power-law indices.
GModelSpectralTablePars m_table_pars
Table model parameters.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
const GFilename & filename(void) const
Return file name.
GFitsBinTable create_spec_table(void) const
Create SPECTRA FITS table.
std::vector< double > m_eflux
Energy fluxes.
Abstract spectral model base class.
N-dimensional array class.
Definition GNdarray.hpp:44
Node array class.
double value(void) const
Return parameter value.
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
XML element node class.