GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralFunc.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralFunc.hpp - Spectral function model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2016 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 GModelSpectralFunc.hpp
23  * @brief Spectral function model class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPECTRALFUNC_HPP
28 #define GMODELSPECTRALFUNC_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <vector>
32 #include <string>
33 #include "GModelSpectral.hpp"
34 #include "GModelPar.hpp"
35 #include "GEnergy.hpp"
36 #include "GNodeArray.hpp"
37 #include "GFilename.hpp"
38 
39 /* __ Forward declarations _______________________________________________ */
40 class GRan;
41 class GTime;
42 class GXmlElement;
43 
44 
45 /***********************************************************************//**
46  * @class GModelSpectralFunc
47  *
48  * @brief Spectral function model class
49  *
50  * This class implements an arbitrary function as the spectral model
51  * component. The model is defined by
52  *
53  * \f[
54  * S_{\rm E}(E | t) = {\tt m\_norm}
55  * \f]
56  *
57  * where
58  * - \f${\tt m\_norm}\f$ is the normalization of the function.
59  ***************************************************************************/
61 
62 public:
63  // Constructors and destructors
64  GModelSpectralFunc(void);
66  const double& norm);
67  explicit GModelSpectralFunc(const GXmlElement& xml);
69  virtual ~GModelSpectralFunc(void);
70 
71  // Operators
72  virtual GModelSpectralFunc& operator=(const GModelSpectralFunc& model);
73 
74  // Implemented pure virtual base class methods
75  virtual void clear(void);
76  virtual GModelSpectralFunc* clone(void) const;
77  virtual std::string classname(void) const;
78  virtual std::string type(void) const;
79  virtual double eval(const GEnergy& srcEng,
80  const GTime& srcTime = GTime(),
81  const bool& gradients = false) const;
82  virtual double flux(const GEnergy& emin,
83  const GEnergy& emax) const;
84  virtual double eflux(const GEnergy& emin,
85  const GEnergy& emax) const;
86  virtual GEnergy mc(const GEnergy& emin,
87  const GEnergy& emax,
88  const GTime& time,
89  GRan& ran) const;
90  virtual void read(const GXmlElement& xml);
91  virtual void write(GXmlElement& xml) const;
92  virtual std::string print(const GChatter& chatter = NORMAL) const;
93 
94  // Other methods
95  const GFilename& filename(void) const;
96  void filename(const GFilename& filename);
97  double norm(void) const;
98  void norm(const double& norm);
99 
100 protected:
101  // Protected methods
102  void init_members(void);
103  void copy_members(const GModelSpectralFunc& model);
104  void free_members(void);
105  void load_nodes(const GFilename& filename);
106  void set_cache(void) const;
107  void mc_update(const GEnergy& emin, const GEnergy& emax) const;
108 
109  // Protected members
110  GModelPar m_norm; //!< Normalization factor
111  mutable GNodeArray m_lin_nodes; //!< Energy nodes of function
112  mutable GNodeArray m_log_nodes; //!< lof10(Energy) nodes of function
113  std::vector<double> m_lin_values; //!< Function values at nodes
114  std::vector<double> m_log_values; //!< log10(Function) values at nodes
115  GFilename m_filename; //!< Name of file function
116 
117  // Cached members used for pre-computations
118  mutable std::vector<double> m_prefactor; //!< Power-law normalisations
119  mutable std::vector<double> m_gamma; //!< Power-law indices
120  mutable std::vector<double> m_epivot; //!< Power-law pivot energies
121  mutable std::vector<double> m_flux; //!< Photon fluxes
122  mutable std::vector<double> m_eflux; //!< Energy fluxes
123 
124  // Cached members for MC
125  mutable GEnergy m_mc_emin; //!< Minimum energy
126  mutable GEnergy m_mc_emax; //!< Maximum energy
127  mutable std::vector<double> m_mc_cum; //!< Cumulative distribution
128  mutable std::vector<double> m_mc_min; //!< Lower boundary for MC
129  mutable std::vector<double> m_mc_max; //!< Upper boundary for MC
130  mutable std::vector<double> m_mc_exp; //!< Exponent for MC
131 };
132 
133 
134 /***********************************************************************//**
135  * @brief Return class name
136  *
137  * @return String containing the class name ("GModelSpectralFunc").
138  ***************************************************************************/
139 inline
140 std::string GModelSpectralFunc::classname(void) const
141 {
142  return ("GModelSpectralFunc");
143 }
144 
145 
146 /***********************************************************************//**
147  * @brief Return model type
148  *
149  * @return "FileFunction".
150  *
151  * Returns the type of the spectral function model.
152  ***************************************************************************/
153 inline
154 std::string GModelSpectralFunc::type(void) const
155 {
156  return "FileFunction";
157 }
158 
159 
160 /***********************************************************************//**
161  * @brief Return normalization factor
162  *
163  * @return Normalization factor.
164  *
165  * Returns the normalization factor.
166  ***************************************************************************/
167 inline
168 double GModelSpectralFunc::norm(void) const
169 {
170  return (m_norm.value());
171 }
172 
173 
174 /***********************************************************************//**
175  * @brief Set normalization factor
176  *
177  * @param[in] norm Normalization factor.
178  *
179  * Sets the normalization factor.
180  ***************************************************************************/
181 inline
182 void GModelSpectralFunc::norm(const double& norm)
183 {
184  m_norm.value(norm);
185  return;
186 }
187 
188 
189 /***********************************************************************//**
190  * @brief Return file name
191  *
192  * @return Name of node file.
193  *
194  * Returns the name of the file function node file.
195  ***************************************************************************/
196 inline
198 {
199  return (m_filename);
200 }
201 
202 
203 /***********************************************************************//**
204  * @brief Loads nodes from node file and set filename
205  *
206  * @param[in] filename Node file name.
207  *
208  * Loads the nodes from a file function node file and sets the filename.
209  ***************************************************************************/
210 inline
212 {
213  load_nodes(filename);
214  return;
215 }
216 
217 #endif /* GMODELSPECTRALFUNC_HPP */
std::vector< double > m_gamma
Power-law indices.
void mc_update(const GEnergy &emin, const GEnergy &emax) const
Set MC pre-computation cache.
GEnergy m_mc_emax
Maximum energy.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
std::vector< double > m_lin_values
Function values at nodes.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:821
Node array class.
Definition: GNodeArray.hpp:60
Energy value class definition.
Abstract spectral model base class.
std::vector< double > m_mc_max
Upper boundary for MC.
std::vector< double > m_mc_exp
Exponent for MC.
XML element node class.
Definition: GXmlElement.hpp:47
virtual void read(const GXmlElement &xml)
Read model from XML element.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:54
void load_nodes(const GFilename &filename)
Load nodes from file.
void free_members(void)
Delete class members.
const GFilename & filename(void) const
Return file name.
std::vector< double > m_log_values
log10(Function) values at nodes
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual std::string classname(void) const
Return class name.
Model parameter class interface definition.
GFilename m_filename
Name of file function.
Model parameter class.
Definition: GModelPar.hpp:87
virtual ~GModelSpectralFunc(void)
Destructor.
std::vector< double > m_eflux
Energy fluxes.
Node array class interface definition.
std::vector< double > m_mc_min
Lower boundary for MC.
GEnergy m_mc_emin
Minimum energy.
virtual void clear(void)
Clear file function.
Filename class.
Definition: GFilename.hpp:62
void set_cache(void) const
Set pre-computation cache.
GNodeArray m_log_nodes
lof10(Energy) nodes of function
GModelPar m_norm
Normalization factor.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
GChatter
Definition: GTypemaps.hpp:33
void copy_members(const GModelSpectralFunc &model)
Copy class members.
virtual std::string type(void) const
Return model type.
std::vector< double > m_epivot
Power-law pivot energies.
Abstract spectral model base class interface definition.
Spectral function model class.
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_mc_cum
Cumulative distribution.
virtual GModelSpectralFunc * clone(void) const
Clone file function.
double value(void) const
Return parameter value.
std::vector< double > m_prefactor
Power-law normalisations.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print file function information.
void init_members(void)
Initialise class members.
GModelSpectralFunc(void)
Void constructor.
GNodeArray m_lin_nodes
Energy nodes of function.
virtual GModelSpectralFunc & operator=(const GModelSpectralFunc &model)
Assignment operator.
double norm(void) const
Return normalization factor.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
Filename class interface definition.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
std::vector< double > m_flux
Photon fluxes.