GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralPlawPhotonFlux.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralPlawPhotonFlux.hpp - Spectral power law model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2011-2018 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 GModelSpectralPlawPhotonFlux.hpp
23 * @brief Flux normalized power law spectral model class interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMODELSPECTRALPLAWPHOTONFLUX_HPP
28#define GMODELSPECTRALPLAWPHOTONFLUX_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GModelSpectral.hpp"
33#include "GModelPar.hpp"
34#include "GEnergy.hpp"
35
36/* __ Forward declarations _______________________________________________ */
37class GRan;
38class GTime;
39class GXmlElement;
40
41
42/***********************************************************************//**
43 * @class GModelSpectralPlawPhotonFlux
44 *
45 * @brief Photon flux normalized power law spectral model class
46 *
47 * This class implements a power law spectrum. The model is defined by
48 *
49 * \f[
50 * S_{\rm E}(E | t) = {\tt m\_flux}
51 * \frac{{\tt m\_index}+1}
52 * {{\tt e\_max}^{{\tt m\_index}+1} -
53 * {\tt e\_min}^{{\tt m\_index}+1}}
54 * E^{\tt m\_index}
55 * \f]
56 *
57 * for \f${\tt m\_index} \ne -1\f$ and
58 *
59 * \f[
60 * S_{\rm E}(E | t) =
61 * \frac{{\tt m\_flux}}
62 * {\log {\tt e\_max} - \log {\tt e\_min}}
63 * E^{\tt m\_index}
64 * \f]
65 *
66 * for \f${\tt m\_index} = -1\f$, where
67 * - \f${\tt e\_min}\f$ is the minimum energy of an interval,
68 * - \f${\tt e\_max}\f$ is the maximum energy of an interval,
69 * - \f${\tt m\_flux}\f$ is the photon flux between
70 * \f${\tt e\_min}\f$ and \f${\tt e\_max}\f$, and
71 * - \f${\tt m\_index}\f$ is the spectral index.
72 ***************************************************************************/
74
75public:
76 // Constructors and destructors
78 GModelSpectralPlawPhotonFlux(const std::string& type,
79 const std::string& flux,
80 const std::string& index,
81 const std::string& emin,
82 const std::string& emax);
84 const double& index,
85 const GEnergy& emin,
86 const GEnergy& emax);
87 explicit GModelSpectralPlawPhotonFlux(const GXmlElement& xml);
90
91 // Operators
93
94 // Implemented pure virtual base class methods
95 virtual void clear(void);
96 virtual GModelSpectralPlawPhotonFlux* clone(void) const;
97 virtual std::string classname(void) const;
98 virtual std::string type(void) const;
99 virtual double eval(const GEnergy& srcEng,
100 const GTime& srcTime = GTime(),
101 const bool& gradients = false) const;
102 virtual double flux(const GEnergy& emin,
103 const GEnergy& emax) const;
104 virtual double eflux(const GEnergy& emin,
105 const GEnergy& emax) const;
106 virtual GEnergy mc(const GEnergy& emin,
107 const GEnergy& emax,
108 const GTime& time,
109 GRan& ran) const;
110 virtual void read(const GXmlElement& xml);
111 virtual void write(GXmlElement& xml) const;
112 virtual std::string print(const GChatter& chatter = NORMAL) const;
113
114 // Other methods
115 void type(const std::string& type);
116 double flux(void) const;
117 void flux(const double& flux);
118 double index(void) const;
119 void index(const double& index);
120 GEnergy emin(void) const;
121 void emin(const GEnergy& emin);
122 GEnergy emax(void) const;
123 void emax(const GEnergy& emax);
124
125protected:
126 // Protected methods
127 void init_members(void);
129 void free_members(void);
130 void update(const GEnergy& srcEng) const;
131
132 // Protected members
133 std::string m_type; //!< Model type
134 GModelPar m_flux; //!< Photon flux (ph/cm2/s)
135 GModelPar m_index; //!< Spectral index
136 GModelPar m_emin; //!< Lower energy limit (MeV)
137 GModelPar m_emax; //!< Upper energy limit (MeV)
138
139 // Cached members used for pre-computations
140 mutable double m_log_emin; //!< Log(emin)
141 mutable double m_log_emax; //!< Log(emax)
142 mutable double m_pow_emin; //!< emin^(index+1)
143 mutable double m_pow_emax; //!< emax^(index+1)
144 mutable double m_norm; //!< Power-law normalization (for pivot energy 1 MeV)
145 mutable double m_g_norm; //!< Power-law normalization gradient
146 mutable double m_power; //!< Power-law factor
147 mutable double m_last_index; //!< Last spectral index (MeV)
148 mutable GEnergy m_last_emin; //!< Last lower energy limit
149 mutable GEnergy m_last_emax; //!< Last upper energy limit
150 mutable GEnergy m_last_energy; //!< Last source energy
151};
152
153
154/***********************************************************************//**
155 * @brief Return class name
156 *
157 * @return String containing the class name ("GModelSpectralPlawPhotonFlux").
158 ***************************************************************************/
159inline
161{
162 return ("GModelSpectralPlawPhotonFlux");
163}
164
165
166/***********************************************************************//**
167 * @brief Return model type
168 *
169 * @return Model type.
170 *
171 * Returns the type of the spectral power law model.
172 ***************************************************************************/
173inline
175{
176 return (m_type);
177}
178
179
180/***********************************************************************//**
181 * @brief Set model type
182 *
183 * @param[in] type Model type.
184 *
185 * Set the type of the spectral power law model.
186 ***************************************************************************/
187inline
188void GModelSpectralPlawPhotonFlux::type(const std::string& type)
189{
190 m_type = type;
191 return;
192}
193
194
195/***********************************************************************//**
196 * @brief Return photon flux
197 *
198 * @return Photon flux (ph/cm2/s).
199 *
200 * Returns the photon flux.
201 ***************************************************************************/
202inline
204{
205 return (m_flux.value());
206}
207
208
209/***********************************************************************//**
210 * @brief Set photon flux
211 *
212 * @param[in] flux Photon flux (ph/cm2/s).
213 *
214 * Sets the photon flux.
215 ***************************************************************************/
216inline
218{
220 return;
221}
222
223
224
225
226/***********************************************************************//**
227 * @brief Return power law index
228 *
229 * @return Power law index.
230 *
231 * Returns the power law index.
232 ***************************************************************************/
233inline
235{
236 return (m_index.value());
237}
238
239
240/***********************************************************************//**
241 * @brief Set power law index
242 *
243 * @param[in] index Power law index.
244 *
245 * Sets the power law index.
246 ***************************************************************************/
247inline
248void GModelSpectralPlawPhotonFlux::index(const double& index)
249{
251 return;
252}
253
254
255/***********************************************************************//**
256 * @brief Return minimum energy
257 *
258 * @return Minimum energy.
259 *
260 * Returns the minimum energy.
261 ***************************************************************************/
262inline
264{
265 GEnergy energy;
266 energy.MeV(m_emin.value());
267 return energy;
268}
269
270
271/***********************************************************************//**
272 * @brief Set minimum energy
273 *
274 * @param[in] emin Minimum energy.
275 *
276 * Sets the minimum energy.
277 ***************************************************************************/
278inline
280{
281 m_emin.value(emin.MeV());
282 return;
283}
284
285
286/***********************************************************************//**
287 * @brief Return maximum energy
288 *
289 * @return Maximum energy.
290 *
291 * Returns the maximum energy.
292 ***************************************************************************/
293inline
295{
296 GEnergy energy;
297 energy.MeV(m_emax.value());
298 return energy;
299}
300
301
302/***********************************************************************//**
303 * @brief Set maximum energy
304 *
305 * @param[in] emax Maximum energy.
306 *
307 * Sets the maximum energy.
308 ***************************************************************************/
309inline
311{
312 m_emax.value(emax.MeV());
313 return;
314}
315
316#endif /* GMODELSPECTRALPLAWPHOTONFLUX_HPP */
Energy value class definition.
Model parameter class interface definition.
Abstract spectral model base class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
double MeV(void) const
Return energy in MeV.
Definition GEnergy.cpp:321
Model parameter class.
Definition GModelPar.hpp:87
Photon flux normalized power law spectral model class.
virtual std::string type(void) const
Return model type.
void update(const GEnergy &srcEng) const
Update precomputed values.
virtual GModelSpectralPlawPhotonFlux * clone(void) const
Clone power law model.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
double m_last_index
Last spectral index (MeV)
GModelPar m_emax
Upper energy limit (MeV)
GModelSpectralPlawPhotonFlux(void)
Void constructor.
virtual void read(const GXmlElement &xml)
Read model from XML element.
GEnergy emin(void) const
Return minimum energy.
void init_members(void)
Initialise class members.
GEnergy m_last_emin
Last lower energy limit.
GEnergy emax(void) const
Return maximum energy.
virtual std::string classname(void) const
Return class name.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelSpectralPlawPhotonFlux & operator=(const GModelSpectralPlawPhotonFlux &model)
Assignment operator.
void free_members(void)
Delete class members.
void copy_members(const GModelSpectralPlawPhotonFlux &model)
Copy class members.
GModelPar m_flux
Photon flux (ph/cm2/s)
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
double flux(void) const
Return photon flux.
double m_norm
Power-law normalization (for pivot energy 1 MeV)
double index(void) const
Return power law index.
double m_g_norm
Power-law normalization gradient.
virtual void clear(void)
Clear power law model.
virtual ~GModelSpectralPlawPhotonFlux(void)
Destructor.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
GModelPar m_emin
Lower energy limit (MeV)
GEnergy m_last_emax
Last upper energy limit.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
Abstract spectral model base 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.