GammaLib 2.0.0
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-2020 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 GModelSpectralTablePar& table_par(const int& index);
93 const GModelSpectralTablePar& table_par(const int& index) const;
94 GModelSpectralTablePar& table_par(const std::string& name);
95 const GModelSpectralTablePar& table_par(const std::string& name) const;
96 double norm(void) const;
97 void norm(const double& norm);
98 const GEbounds& ebounds(void) const;
99 void load(const GFilename& filename);
100 void save(const GFilename& filename,
101 const bool& clobber = false) const;
102 const GFilename& filename(void) const;
103
104protected:
105 // Protected methods
106 void init_members(void);
107 void copy_members(const GModelSpectralTable& model);
108 void free_members(void);
109 void set_par_pointers(void);
110 void set_energy_nodes(void);
114 void load_par(const GFits& fits);
115 void load_eng(const GFits& fits);
116 void load_spec(const GFits& fits);
117 int par_index(const std::string& name) const;
118 void update(void) const;
119 void update_flux(void) const;
120 void update_mc(const GEnergy& emin, const GEnergy& emax) const;
121
122 // Protected members
123 GModelPar m_norm; //!< Normalization factor
124 GModelSpectralTablePars m_table_pars; //!< Table model parameters
125 GNdarray m_spectra; //!< Spectra
126 GEbounds m_ebounds; //!< Energy boundaries
127 mutable GFilename m_filename; //!< Filename of table
128
129 // Cached members used for pre-computations
130 mutable int m_npars; //!< Number of parameters
131 mutable int m_nebins; //!< Number of energy bins
132 mutable std::vector<double> m_last_values; //!< Last parameter values
133 mutable GNodeArray m_lin_nodes; //!< Energy nodes of function
134 mutable GNodeArray m_log_nodes; //!< log10(Energy) nodes of function
135 mutable GNdarray m_lin_values; //!< Function values and grad's
136 mutable GNdarray m_log_values; //!< log10(Function) values and grad's
137 mutable std::vector<double> m_prefactor; //!< Power-law normalisations
138 mutable std::vector<double> m_gamma; //!< Power-law indices
139 mutable std::vector<double> m_epivot; //!< Power-law pivot energies
140 mutable std::vector<double> m_flux; //!< Photon fluxes
141 mutable std::vector<double> m_eflux; //!< Energy fluxes
142 mutable GEnergy m_mc_emin; //!< Minimum energy
143 mutable GEnergy m_mc_emax; //!< Maximum energy
144 mutable std::vector<double> m_mc_cum; //!< Cumulative distribution
145 mutable std::vector<double> m_mc_min; //!< Lower boundary for MC
146 mutable std::vector<double> m_mc_max; //!< Upper boundary for MC
147 mutable std::vector<double> m_mc_exp; //!< Exponent for MC
148};
149
150
151/***********************************************************************//**
152 * @brief Return class name
153 *
154 * @return String containing the class name ("GModelSpectralTable").
155 ***************************************************************************/
156inline
157std::string GModelSpectralTable::classname(void) const
158{
159 return ("GModelSpectralTable");
160}
161
162
163/***********************************************************************//**
164 * @brief Return model type
165 *
166 * @return "TableModel".
167 *
168 * Returns the type of the spectral model.
169 ***************************************************************************/
170inline
171std::string GModelSpectralTable::type(void) const
172{
173 return ("TableModel");
174}
175
176
177/***********************************************************************//**
178 * @brief Return normalization factor
179 *
180 * @return Normalization factor.
181 *
182 * Returns the normalization factor.
183 ***************************************************************************/
184inline
186{
187 return (m_norm.value());
188}
189
190
191/***********************************************************************//**
192 * @brief Set normalization factor
193 *
194 * @param[in] norm Normalization factor.
195 *
196 * Sets the normalization factor.
197 ***************************************************************************/
198inline
200{
202 return;
203}
204
205
206/***********************************************************************//**
207 * @brief Return reference to energy boundaries
208 *
209 * @return Reference to energy boundaries.
210 *
211 * Returns a reference to energy boundaries.
212 ***************************************************************************/
213inline
215{
216 return (m_ebounds);
217}
218
219
220/***********************************************************************//**
221 * @brief Return file name
222 *
223 * @return Name of table file.
224 *
225 * Returns the name of the table file.
226 ***************************************************************************/
227inline
229{
230 return (m_filename);
231}
232
233#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:864
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.
GModelSpectralTable(void)
Void constructor.
virtual void write(GXmlElement &xml) const
Write model into XML element.
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.
GFilename m_filename
Filename of table.
void set_par_pointers(void)
Set parameter pointers.
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.
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.
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.