GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralPlawEnergyFlux.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralPlawEnergyFlux.hpp - Spectral power law model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2016-2018 by Michael Mayer *
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 GModelSpectralPlawEnergyFlux.hpp
23 * @brief Energy flux normalized power law spectral model class interface definition
24 * @author Michael Mayer
25 */
26
27#ifndef GMODELSPECTRALPLAWENERGYFLUX_HPP
28#define GMODELSPECTRALPLAWENERGYFLUX_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 GModelSpectralPlawEnergyFlux
44 *
45 * @brief Energy 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\_eflux}
51 * \frac{{\tt m\_index}+1}
52 * {{\tt e\_max}^{{\tt m\_index}+2} -
53 * {\tt e\_min}^{{\tt m\_index}+2}}
54 * E^{\tt m\_index}
55 * \f]
56 *
57 * for \f${\tt m\_index} \ne -2\f$ and
58 *
59 * \f[
60 * S_{\rm E}(E | t) =
61 * \frac{{\tt m\_eflux}}
62 * {\log {\tt e\_max} - \log {\tt e\_min}}
63 * E^{\tt m\_index}
64 * \f]
65 *
66 * for \f${\tt m\_index} = -2\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\_eflux}\f$ is the energy 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 GModelSpectralPlawEnergyFlux(const std::string& type,
79 const std::string& eflux,
80 const std::string& index,
81 const std::string& emin,
82 const std::string& emax);
83 explicit GModelSpectralPlawEnergyFlux(const double& eflux,
84 const double& index,
85 const GEnergy& emin,
86 const GEnergy& emax);
87 explicit GModelSpectralPlawEnergyFlux(const GXmlElement& xml);
90
91 // Operators
93
94 // Implemented pure virtual base class methods
95 virtual void clear(void);
96 virtual GModelSpectralPlawEnergyFlux* 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 eflux(void) const;
117 void eflux(const double& eflux);
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_eflux; //!< Energy flux (erg/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 ("GModelSpectralPlawEnergyFlux").
158 ***************************************************************************/
159inline
161{
162 return ("GModelSpectralPlawEnergyFlux");
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 GModelSpectralPlawEnergyFlux::type(const std::string& type)
189{
190 m_type = type;
191 return;
192}
193
194
195/***********************************************************************//**
196 * @brief Return energy flux
197 *
198 * @return Energy flux (erg/cm2/s).
199 *
200 * Returns the energy flux.
201 ***************************************************************************/
202inline
204{
205 return (m_eflux.value());
206}
207
208
209/***********************************************************************//**
210 * @brief Set energy flux
211 *
212 * @param[in] eflux Energy flux (erg/cm2/s).
213 *
214 * Sets the energy flux.
215 ***************************************************************************/
216inline
217void GModelSpectralPlawEnergyFlux::eflux(const double& eflux)
218{
220 return;
221}
222
223
224/***********************************************************************//**
225 * @brief Return power law index
226 *
227 * @return Power law index.
228 *
229 * Returns the power law index.
230 ***************************************************************************/
231inline
233{
234 return (m_index.value());
235}
236
237
238/***********************************************************************//**
239 * @brief Set power law index
240 *
241 * @param[in] index Power law index.
242 *
243 * Sets the power law index.
244 ***************************************************************************/
245inline
246void GModelSpectralPlawEnergyFlux::index(const double& index)
247{
249 return;
250}
251
252
253/***********************************************************************//**
254 * @brief Return minimum energy
255 *
256 * @return Minimum energy.
257 *
258 * Returns the minimum energy.
259 ***************************************************************************/
260inline
262{
263 GEnergy energy;
264 energy.MeV(m_emin.value());
265 return energy;
266}
267
268
269/***********************************************************************//**
270 * @brief Set minimum energy
271 *
272 * @param[in] emin Minimum energy.
273 *
274 * Sets the minimum energy.
275 ***************************************************************************/
276inline
278{
279 m_emin.value(emin.MeV());
280 return;
281}
282
283
284/***********************************************************************//**
285 * @brief Return maximum energy
286 *
287 * @return Maximum energy.
288 *
289 * Returns the maximum energy.
290 ***************************************************************************/
291inline
293{
294 GEnergy energy;
295 energy.MeV(m_emax.value());
296 return energy;
297}
298
299
300/***********************************************************************//**
301 * @brief Set maximum energy
302 *
303 * @param[in] emax Maximum energy.
304 *
305 * Sets the maximum energy.
306 ***************************************************************************/
307inline
309{
310 m_emax.value(emax.MeV());
311 return;
312}
313
314#endif /* GMODELSPECTRALPLAWENERGYFLUX_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
Energy flux normalized power law spectral model class.
GModelSpectralPlawEnergyFlux(void)
Void constructor.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
virtual GModelSpectralPlawEnergyFlux * clone(void) const
Clone power law model.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual std::string type(void) const
Return model type.
virtual ~GModelSpectralPlawEnergyFlux(void)
Destructor.
void free_members(void)
Delete class members.
double eflux(void) const
Return energy flux.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
void update(const GEnergy &srcEng) const
Update precomputed values.
void copy_members(const GModelSpectralPlawEnergyFlux &model)
Copy class members.
GModelPar m_eflux
Energy flux (erg/cm2/s)
GEnergy emax(void) const
Return maximum energy.
GEnergy emin(void) const
Return minimum energy.
GModelPar m_emin
Lower energy limit (MeV)
double m_last_index
Last spectral index (MeV)
GEnergy m_last_emax
Last upper energy limit.
double index(void) const
Return power law index.
void init_members(void)
Initialise class members.
virtual std::string classname(void) const
Return class name.
GEnergy m_last_emin
Last lower energy limit.
virtual void clear(void)
Clear power law model.
GModelPar m_emax
Upper energy limit (MeV)
double m_norm
Power-law normalization (for pivot energy 1 MeV)
double m_g_norm
Power-law normalization gradient.
virtual GModelSpectralPlawEnergyFlux & operator=(const GModelSpectralPlawEnergyFlux &model)
Assignment operator.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/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.