GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralExpInvPlaw.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralExpInvPlaw.hpp - Exponential cut off power law model *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2018 by Alexander Ziegler *
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 GModelSpectralExpInvPlaw.hpp
23  * @brief Exponential cut off power law spectral class interface definition
24  * @author Alexander Ziegler
25  */
26 
27 #ifndef GMODELSPECTRALEXPINVPLAW_HPP
28 #define GMODELSPECTRALEXPINVPLAW_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GModelSpectral.hpp"
33 #include "GFunction.hpp"
34 #include "GModelPar.hpp"
35 #include "GEnergy.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GRan;
39 class GTime;
40 class GXmlElement;
41 
42 
43 /***********************************************************************//**
44  * @class GModelSpectralExpInvPlaw
45  *
46  * @brief Exponential cut off power law spectral class
47  *
48  * This class implements a power law spectrum with exponential cut off. The
49  * 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\_index}
54  * \exp \left( -{\tt m\_lambda}*E \right)
55  * \f]
56  *
57  * where
58  * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
59  * - \f${\tt m\_pivot}\f$ is the pivot energy,
60  * - \f${\tt m\_index}\f$ is the spectral index, and
61  * - \f${\tt m\_lambda}\f$ is the cut-off parameter (1/cut-off energy).
62  ***************************************************************************/
64 
65 public:
66  // Constructors and destructors
68  GModelSpectralExpInvPlaw(const std::string& type,
69  const std::string& prefactor,
70  const std::string& index,
71  const std::string& pivot,
72  const std::string& lambda);
73  GModelSpectralExpInvPlaw(const double& prefactor,
74  const double& index,
75  const GEnergy& pivot,
76  const double& lambda);
77  GModelSpectralExpInvPlaw(const double& prefactor,
78  const double& index,
79  const GEnergy& pivot,
80  const GEnergy& cutoff);
81  explicit GModelSpectralExpInvPlaw(const GXmlElement& xml);
83  virtual ~GModelSpectralExpInvPlaw(void);
84 
85  // Operators
87 
88  // Implemented pure virtual methods
89  virtual void clear(void);
90  virtual GModelSpectralExpInvPlaw* 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 index(void) const;
113  void index(const double& index);
114  double inverse_cutoff(void) const;
115  void inverse_cutoff(const double& lambda);
116  GEnergy cutoff(void) const;
117  void cutoff(const GEnergy& cutoff);
118  GEnergy pivot(void) const;
119  void pivot(const GEnergy& pivot);
120 
121 protected:
122  // Protected methods
123  void init_members(void);
124  void copy_members(const GModelSpectralExpInvPlaw& 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& index,
134  const double& pivot,
135  const double& lambda) :
136  m_norm(norm),
137  m_index(index),
138  m_inv_pivot(1.0/pivot),
139  m_lambda(lambda) {}
140  double eval(const double& eng);
141  protected:
142  double m_norm; //!< Normalization
143  double m_index; //!< Index
144  double m_inv_pivot; //!< 1 / Pivot energy
145  double m_lambda; //!< Cut-off parameter
146  };
147 
148  // Energy flux integration kernel
149  class eflux_kernel : public GFunction {
150  public:
151  eflux_kernel(const double& norm,
152  const double& index,
153  const double& pivot,
154  const double& lambda) :
155  m_norm(norm),
156  m_index(index),
157  m_inv_pivot(1.0/pivot),
158  m_lambda(lambda) {}
159  double eval(const double& eng);
160  protected:
161  double m_norm; //!< Normalization
162  double m_index; //!< Index
163  double m_inv_pivot; //!< 1 / Pivot energy
164  double m_lambda; //!< Cut-off parameter
165  };
166 
167  // Protected members
168  std::string m_type; //!< Model type
169  GModelPar m_norm; //!< Normalization factor
170  GModelPar m_index; //!< Spectral index
171  GModelPar m_lambda; //!< Cut-off parameter
172  GModelPar m_pivot; //!< Pivot energy
173 
174  // Cached members used for pre-computations
175  mutable GEnergy m_last_energy; //!< Last energy value
176  mutable double m_last_index; //!< Last index parameter
177  mutable double m_last_lambda; //!< Last cut-off parameter
178  mutable double m_last_pivot; //!< Last pivot parameter
179  mutable double m_last_e_norm; //!< Last E/Epivot value
180  mutable double m_last_e_lambda; //!< Last E*lambda value
181  mutable double m_last_power; //!< Last power value
182  mutable double m_mc_emin; //!< Minimum energy
183  mutable double m_mc_emax; //!< Maximum energy
184  mutable double m_mc_exponent; //!< Exponent (index+1)
185  mutable double m_mc_pow_emin; //!< Power of minimum energy
186  mutable double m_mc_pow_ewidth; //!< Power of energy width
187 };
188 
189 
190 /***********************************************************************//**
191  * @brief Return class name
192  *
193  * @return String containing the class name ("GModelSpectralExpInvPlaw").
194  ***************************************************************************/
195 inline
196 std::string GModelSpectralExpInvPlaw::classname(void) const
197 {
198  return ("GModelSpectralExpInvPlaw");
199 }
200 
201 
202 /***********************************************************************//**
203  * @brief Return model type
204  *
205  * @return Model type.
206  *
207  * Returns the type of the exponentially cut off power law model.
208  ***************************************************************************/
209 inline
210 std::string GModelSpectralExpInvPlaw::type(void) const
211 {
212  return (m_type);
213 }
214 
215 
216 /***********************************************************************//**
217  * @brief Set model type
218  *
219  * @param[in] type Model type.
220  *
221  * Set the type of the exponentially cut off power law model.
222  ***************************************************************************/
223 inline
224 void GModelSpectralExpInvPlaw::type(const std::string& type)
225 {
226  m_type = type;
227  return;
228 }
229 
230 
231 /***********************************************************************//**
232  * @brief Return pre factor
233  *
234  * @return Pre factor (ph/cm2/s/MeV).
235  *
236  * Returns the pre factor.
237  ***************************************************************************/
238 inline
240 {
241  return (m_norm.value());
242 }
243 
244 
245 /***********************************************************************//**
246  * @brief Set pre factor
247  *
248  * @param[in] prefactor Pre factor (ph/cm2/s/MeV).
249  *
250  * Sets the pre factor.
251  ***************************************************************************/
252 inline
253 void GModelSpectralExpInvPlaw::prefactor(const double& prefactor)
254 {
255  m_norm.value(prefactor);
256  return;
257 }
258 
259 
260 /***********************************************************************//**
261  * @brief Return power law index
262  *
263  * @return Power law index.
264  *
265  * Returns the power law index.
266  ***************************************************************************/
267 inline
269 {
270  return (m_index.value());
271 }
272 
273 
274 /***********************************************************************//**
275  * @brief Set power law index
276  *
277  * @param[in] index Power law index.
278  *
279  * Sets the power law index.
280  ***************************************************************************/
281 inline
282 void GModelSpectralExpInvPlaw::index(const double& index)
283 {
284  m_index.value(index);
285  return;
286 }
287 
288 
289 /***********************************************************************//**
290  * @brief Return pivot energy
291  *
292  * @return Pivot energy.
293  *
294  * Returns the pivot energy.
295  ***************************************************************************/
296 inline
298 {
299  GEnergy energy;
300  energy.MeV(m_pivot.value());
301  return energy;
302 }
303 
304 
305 /***********************************************************************//**
306  * @brief Set pivot energy
307  *
308  * @param[in] pivot Pivot energy.
309  *
310  * Sets the pivot energy.
311  ***************************************************************************/
312 inline
314 {
315  m_pivot.value(pivot.MeV());
316  return;
317 }
318 
319 
320 /***********************************************************************//**
321  * @brief Return exponential cut-off parameter
322  *
323  * @return Exponential cut-off parameter.
324  *
325  * Returns the exponential cut-off parameter.
326  ***************************************************************************/
327 inline
329 {
330  return (m_lambda.value());
331 }
332 
333 
334 /***********************************************************************//**
335  * @brief Set exponential cut-off parameter
336  *
337  * @param[in] lambda Exponential cut-off parameter.
338  *
339  * Sets the exponential cut-off parameter.
340  ***************************************************************************/
341 inline
343 {
344  m_lambda.value(lambda);
345  return;
346 }
347 
348 
349 /***********************************************************************//**
350  * @brief Return cut-off energy
351  *
352  * @return Exponential cut-off energy.
353  *
354  * Returns the exponential cut-off energy as derived from the cut-off
355  * parameter.
356  ***************************************************************************/
357 inline
359 {
360  GEnergy cutoff;
361  cutoff.MeV(1.0/m_lambda.value());
362  return cutoff;
363 }
364 
365 
366 /***********************************************************************//**
367  * @brief Set exponential cut-off energy
368  *
369  * @param[in] cutoff Exponential cut-off energy.
370  *
371  * Sets the exponential cut-off parameter from the cut-off energy.
372  ***************************************************************************/
373 inline
375 {
376  m_lambda.value(1.0/cutoff.MeV());
377  return;
378 }
379 
380 #endif /* GMODELSPECTRALEXPINVPLAW_HPP */
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:821
double inverse_cutoff(void) const
Return exponential cut-off parameter.
Energy value class definition.
Abstract spectral model base class.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelSpectralExpInvPlaw * clone(void) const
Clone exponentially cut off power law model.
virtual std::string classname(void) const
Return class name.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
double m_last_power
Last power value.
virtual void read(const GXmlElement &xml)
Read model from XML element.
XML element node class.
Definition: GXmlElement.hpp:47
double m_mc_pow_emin
Power of minimum energy.
Random number generator class.
Definition: GRan.hpp:44
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
GEnergy m_last_energy
Last energy value.
Time class.
Definition: GTime.hpp:54
double m_last_e_norm
Last E/Epivot value.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
GModelPar m_index
Spectral index.
Exponential cut off power law spectral class.
double m_mc_pow_ewidth
Power of energy width.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
Model parameter class interface definition.
GEnergy cutoff(void) const
Return cut-off energy.
Model parameter class.
Definition: GModelPar.hpp:87
void init_members(void)
Initialise class members.
double m_mc_exponent
Exponent (index+1)
GModelPar m_lambda
Cut-off parameter.
Single parameter function abstract base class definition.
double m_last_pivot
Last pivot parameter.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
virtual void clear(void)
Clear exponentially cut off power law model.
GChatter
Definition: GTypemaps.hpp:33
virtual std::string type(void) const
Return model type.
double index(void) const
Return power law index.
Abstract spectral model base class interface definition.
GModelSpectralExpInvPlaw(void)
Void constructor.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
GModelPar m_norm
Normalization factor.
double value(void) const
Return parameter value.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
double m_last_lambda
Last cut-off parameter.
virtual ~GModelSpectralExpInvPlaw(void)
Destructor.
virtual GModelSpectralExpInvPlaw & operator=(const GModelSpectralExpInvPlaw &model)
Assignment operator.
eflux_kernel(const double &norm, const double &index, const double &pivot, const double &lambda)
double m_last_index
Last index parameter.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
void free_members(void)
Delete class members.
double eval(const double &eng)
Kernel for energy flux integration.
double m_last_e_lambda
Last E*lambda value.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
GEnergy pivot(void) const
Return pivot energy.
double eval(const double &eng)
Kernel for photon flux integration.
void copy_members(const GModelSpectralExpInvPlaw &model)
Copy class members.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
double prefactor(void) const
Return pre factor.
flux_kernel(const double &norm, const double &index, const double &pivot, const double &lambda)