GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralSuperExpPlaw.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralSuperExpPlaw.hpp - Super exp. cut off power law model *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2014-2021 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 GModelSpectralSuperExpPlaw.hpp
23 * @brief Super exponential cut off power law spectral class interface definition
24 * @author Michael Mayer
25 */
26
27#ifndef GMODELSPECTRALSUPEREXPPLAW_HPP
28#define GMODELSPECTRALSUPEREXPPLAW_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GModelSpectral.hpp"
33#include "GFunction.hpp"
34#include "GEnergy.hpp"
35#include "GModelPar.hpp"
36
37/* __ Forward declarations _______________________________________________ */
38class GRan;
39class GTime;
40class GXmlElement;
41
42
43/***********************************************************************//**
44 * @class GModelSpectralSuperExpPlaw
45 *
46 * @brief Super exponential cut off power law spectral class
47 *
48 * This class implements a power law spectrum with super exponential cut off.
49 * The model is defined by
50 *
51 * \f[
52 * S_{\rm E}(E | t) = {\tt m\_norm}
53 * \left( \frac{E}{\tt m\_pivot} \right)^{\tt m\_index1}
54 * \exp \left( - \left( \frac{E}{\tt m\_ecut} \right)^{\tt m\_index2}
55 * \right)
56 * \f]
57 *
58 * where
59 * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
60 * - \f${\tt m\_pivot}\f$ is the pivot energy,
61 * - \f${\tt m\_index1}\f$ is the spectral index
62 * - \f${\tt m\_ecut}\f$ is the cut off energy, and
63 * - \f${\tt m\_index2}\f$ is the index of the cut off.
64 ***************************************************************************/
66
67public:
68 // Constructors and destructors
70 GModelSpectralSuperExpPlaw(const std::string& type,
71 const std::string& prefactor,
72 const std::string& index1,
73 const std::string& pivot,
74 const std::string& cutoff,
75 const std::string& index2);
77 const double& index1,
78 const GEnergy& pivot,
79 const GEnergy& cutoff,
80 const double& index2);
81 explicit GModelSpectralSuperExpPlaw(const GXmlElement& xml);
83 virtual ~GModelSpectralSuperExpPlaw(void);
84
85 // Operators
87
88 // Implemented pure virtual methods
89 virtual void clear(void);
90 virtual GModelSpectralSuperExpPlaw* clone(void) const;
91 virtual std::string classname(void) const;
92 virtual std::string type(void) const;
93 virtual double eval(const GEnergy& srcEng,
94 const GTime& srcTime = GTime(),
95 const bool& gradients = false) const;
96 virtual double flux(const GEnergy& emin,
97 const GEnergy& emax) const;
98 virtual double eflux(const GEnergy& emin,
99 const GEnergy& emax) const;
100 virtual GEnergy mc(const GEnergy& emin,
101 const GEnergy& emax,
102 const GTime& time,
103 GRan& ran) const;
104 virtual void read(const GXmlElement& xml);
105 virtual void write(GXmlElement& xml) const;
106 virtual std::string print(const GChatter& chatter = NORMAL) const;
107
108 // Other methods
109 void type(const std::string& type);
110 double prefactor(void) const;
111 void prefactor(const double& prefactor);
112 double index1(void) const;
113 void index1(const double& index1);
114 double index2(void) const;
115 void index2(const double& index2);
116 GEnergy cutoff(void) const;
117 void cutoff(const GEnergy& cutoff);
118 GEnergy pivot(void) const;
119 void pivot(const GEnergy& pivot);
120
121protected:
122 // Protected methods
123 void init_members(void);
124 void copy_members(const GModelSpectralSuperExpPlaw& model);
125 void free_members(void);
126 void update_eval_cache(const GEnergy& energy) const;
127 void update_mc_cache(const GEnergy& emin, const GEnergy& emax) const;
128
129 // Photon flux integration kernel
130 class flux_kernel : public GFunction {
131 public:
132 flux_kernel(const double& norm,
133 const double& index1,
134 const double& pivot,
135 const double& ecut,
136 const double& index2) :
137 m_norm(norm),
139 m_inv_pivot(1.0/pivot),
140 m_inv_ecut(1.0/ecut),
141 m_index2(index2) {}
142 double eval(const double& eng);
143 protected:
144 double m_norm; //!< Normalization
145 double m_index1; //!< Index1
146 double m_inv_pivot; //!< 1 / Pivot energy
147 double m_inv_ecut; //!< 1 / Cut off energy
148 double m_index2; //!< Index2
149 };
150
151 // Energy flux integration kernel
152 class eflux_kernel : public GFunction {
153 public:
154 eflux_kernel(const double& norm,
155 const double& index1,
156 const double& pivot,
157 const double& ecut,
158 const double& index2) :
159 m_norm(norm),
161 m_inv_pivot(1.0/pivot),
162 m_inv_ecut(1.0/ecut),
163 m_index2(index2) {}
164 double eval(const double& eng);
165 protected:
166 double m_norm; //!< Normalization
167 double m_index1; //!< Index1
168 double m_inv_pivot; //!< 1 / Pivot energy
169 double m_inv_ecut; //!< 1 / Cut off energy
170 double m_index2; //!< Index2
171 };
172
173 // Protected members
174 std::string m_type; //!< Model type
175 GModelPar m_norm; //!< Normalization factor
176 GModelPar m_index1; //!< Spectral index
177 GModelPar m_index2; //!< Index of cutoff
178 GModelPar m_ecut; //!< Exponential cut off energy
179 GModelPar m_pivot; //!< Pivot energy
180
181 // Cached members used for pre-computations
182 mutable GEnergy m_last_energy; //!< Last energy value
183 mutable double m_last_index1; //!< Last index1 parameter
184 mutable double m_last_ecut; //!< Last energy cut-off parameter
185 mutable double m_last_pivot; //!< Last pivot parameter
186 mutable double m_last_index2; //!< Last index2 parameter
187 mutable double m_last_e_norm; //!< Last E/Epivot value
188 mutable double m_last_e_cut; //!< Last E/Ecut value
189 mutable double m_last_exponent; //!< last pow(E/Ecut,index2) value
190 mutable double m_last_power; //!< Last power value
191 mutable double m_mc_emin; //!< Minimum energy
192 mutable double m_mc_emax; //!< Maximum energy
193 mutable double m_mc_exponent; //!< Exponent (index+1)
194 mutable double m_mc_pow_emin; //!< Power of minimum energy
195 mutable double m_mc_pow_ewidth; //!< Power of energy width
196};
197
198
199/***********************************************************************//**
200 * @brief Return class name
201 *
202 * @return String containing the class name ("GModelSpectralSuperExpPlaw").
203 ***************************************************************************/
204inline
206{
207 return ("GModelSpectralSuperExpPlaw");
208}
209
210
211/***********************************************************************//**
212 * @brief Return model type
213 *
214 * @return "SuperExpCutoff".
215 *
216 * Returns the type of the super exponentially cut off power law model.
217 ***************************************************************************/
218inline
219std::string GModelSpectralSuperExpPlaw::type(void) const
220{
221 return (m_type);
222}
223
224
225/***********************************************************************//**
226 * @brief Set model type
227 *
228 * @param[in] type Model type.
229 *
230 * Set the type of the super exponentially cut off power law model.
231 ***************************************************************************/
232inline
233void GModelSpectralSuperExpPlaw::type(const std::string& type)
234{
235 m_type = type;
236 return;
237}
238
239
240/***********************************************************************//**
241 * @brief Return pre factor
242 *
243 * @return Pre factor (ph/cm2/s/MeV).
244 *
245 * Returns the pre factor.
246 ***************************************************************************/
247inline
249{
250 return (m_norm.value());
251}
252
253
254/***********************************************************************//**
255 * @brief Set pre factor
256 *
257 * @param[in] prefactor Pre factor (ph/cm2/s/MeV).
258 *
259 * Sets the pre factor.
260 ***************************************************************************/
261inline
262void GModelSpectralSuperExpPlaw::prefactor(const double& prefactor)
263{
265 return;
266}
267
268
269/***********************************************************************//**
270 * @brief Return power law index
271 *
272 * @return Power law index.
273 *
274 * Returns the power law index.
275 ***************************************************************************/
276inline
278{
279 return (m_index1.value());
280}
281
282
283/***********************************************************************//**
284 * @brief Set power law index
285 *
286 * @param[in] index1 Power law index.
287 *
288 * Sets the power law index.
289 ***************************************************************************/
290inline
291void GModelSpectralSuperExpPlaw::index1(const double& index1)
292{
294 return;
295}
296
297/***********************************************************************//**
298 * @brief Return cut off index
299 *
300 * @return cut off index.
301 *
302 * Returns the cut off index.
303 ***************************************************************************/
304inline
306{
307 return (m_index2.value());
308}
309
310
311/***********************************************************************//**
312 * @brief Set cut off index
313 *
314 * @param[in] index2 Cut off index.
315 *
316 * Sets the cut off index.
317 ***************************************************************************/
318inline
319void GModelSpectralSuperExpPlaw::index2(const double& index2)
320{
322 return;
323}
324
325
326/***********************************************************************//**
327 * @brief Return pivot energy
328 *
329 * @return Pivot energy.
330 *
331 * Returns the pivot energy.
332 ***************************************************************************/
333inline
335{
336 GEnergy energy;
337 energy.MeV(m_pivot.value());
338 return energy;
339}
340
341
342/***********************************************************************//**
343 * @brief Set pivot energy
344 *
345 * @param[in] pivot Pivot energy.
346 *
347 * Sets the pivot energy.
348 ***************************************************************************/
349inline
351{
353 return;
354}
355
356
357/***********************************************************************//**
358 * @brief Return exponential cut-off energy
359 *
360 * @return Exponential cut-off energy.
361 *
362 * Returns the exponential cut-off energy.
363 ***************************************************************************/
364inline
366{
367 GEnergy energy;
368 energy.MeV(m_ecut.value());
369 return energy;
370}
371
372
373/***********************************************************************//**
374 * @brief Set exponential cut-off energy
375 *
376 * @param[in] cutoff Exponential cut-off energy.
377 *
378 * Sets the exponential cut-off energy.
379 ***************************************************************************/
380inline
382{
384 return;
385}
386
387#endif /* GMODELSPECTRALSUPEREXPPLAW_HPP */
Energy value class definition.
Single parameter function abstract base class definition.
Model parameter class interface definition.
Abstract spectral model base 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
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
Single parameter function abstract base class.
Definition GFunction.hpp:44
Model parameter class.
Definition GModelPar.hpp:87
double eval(const double &eng)
Kernel for energy flux integration.
eflux_kernel(const double &norm, const double &index1, const double &pivot, const double &ecut, const double &index2)
flux_kernel(const double &norm, const double &index1, const double &pivot, const double &ecut, const double &index2)
double eval(const double &eng)
Kernel for photon flux integration.
Super exponential cut off power law spectral class.
virtual GModelSpectralSuperExpPlaw * clone(void) const
Clone super exponentially cut off power law model.
double prefactor(void) const
Return pre factor.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
double m_last_ecut
Last energy cut-off parameter.
virtual GModelSpectralSuperExpPlaw & operator=(const GModelSpectralSuperExpPlaw &model)
Assignment operator.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void init_members(void)
Initialise class members.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual ~GModelSpectralSuperExpPlaw(void)
Destructor.
GEnergy cutoff(void) const
Return exponential cut-off energy.
GModelSpectralSuperExpPlaw(void)
Void constructor.
double m_mc_pow_ewidth
Power of energy width.
double m_mc_pow_emin
Power of minimum energy.
void copy_members(const GModelSpectralSuperExpPlaw &model)
Copy class members.
virtual void clear(void)
Clear exponentially cut off power law model.
GEnergy m_last_energy
Last energy value.
virtual std::string classname(void) const
Return class name.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
void free_members(void)
Delete class members.
double m_last_pivot
Last pivot parameter.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
double index1(void) const
Return power law index.
double m_last_exponent
last pow(E/Ecut,index2) value
double m_last_index1
Last index1 parameter.
double index2(void) const
Return cut off index.
GEnergy pivot(void) const
Return pivot energy.
GModelPar m_ecut
Exponential cut off energy.
double m_last_e_norm
Last E/Epivot value.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
GModelPar m_norm
Normalization factor.
virtual std::string type(void) const
Return model type.
double m_last_index2
Last index2 parameter.
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.