GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralExpPlaw.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralExpPlaw.hpp - Exponential cut off power law model *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-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 GModelSpectralExpPlaw.hpp
23  * @brief Exponential cut off power law spectral class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPECTRALEXPPLAW_HPP
28 #define GMODELSPECTRALEXPPLAW_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 GModelSpectralExpPlaw
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( \frac{-E}{\tt m\_ecut} \right)
55  * \f]
56  *
57  * where
58  * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
59  * - \f${\tt m\_index}\f$ is the spectral index,
60  * - \f${\tt m\_ecut}\f$ is the cut off energy, and
61  * - \f${\tt m\_pivot}\f$ is the pivot energy.
62  ***************************************************************************/
64 
65 public:
66  // Constructors and destructors
68  GModelSpectralExpPlaw(const std::string& type,
69  const std::string& prefactor,
70  const std::string& index,
71  const std::string& pivot,
72  const std::string& cutoff);
73  GModelSpectralExpPlaw(const double& prefactor,
74  const double& index,
75  const GEnergy& pivot,
76  const GEnergy& cutoff);
77  explicit GModelSpectralExpPlaw(const GXmlElement& xml);
79  virtual ~GModelSpectralExpPlaw(void);
80 
81  // Operators
83 
84  // Implemented pure virtual methods
85  virtual void clear(void);
86  virtual GModelSpectralExpPlaw* clone(void) const;
87  virtual std::string classname(void) const;
88  virtual std::string type(void) const;
89  virtual double eval(const GEnergy& srcEng,
90  const GTime& srcTime = GTime(),
91  const bool& gradients = false) const;
92  virtual double flux(const GEnergy& emin,
93  const GEnergy& emax) const;
94  virtual double eflux(const GEnergy& emin,
95  const GEnergy& emax) const;
96  virtual GEnergy mc(const GEnergy& emin,
97  const GEnergy& emax,
98  const GTime& time,
99  GRan& ran) const;
100  virtual void read(const GXmlElement& xml);
101  virtual void write(GXmlElement& xml) const;
102  virtual std::string print(const GChatter& chatter = NORMAL) const;
103 
104  // Other methods
105  void type(const std::string& type);
106  double prefactor(void) const;
107  void prefactor(const double& prefactor);
108  double index(void) const;
109  void index(const double& index);
110  GEnergy cutoff(void) const;
111  void cutoff(const GEnergy& cutoff);
112  GEnergy pivot(void) const;
113  void pivot(const GEnergy& pivot);
114 
115 protected:
116  // Protected methods
117  void init_members(void);
118  void copy_members(const GModelSpectralExpPlaw& model);
119  void free_members(void);
120  void update_eval_cache(const GEnergy& energy) const;
121  void update_mc_cache(const GEnergy& emin, const GEnergy& emax) const;
122 
123  // Photon flux integration kernel
124  class flux_kernel : public GFunction {
125  public:
126  flux_kernel(const double& norm,
127  const double& index,
128  const double& pivot,
129  const double& ecut) :
130  m_norm(norm),
131  m_index(index),
132  m_inv_pivot(1.0/pivot),
133  m_inv_ecut(1.0/ecut) {}
134  double eval(const double& eng);
135  protected:
136  double m_norm; //!< Normalization
137  double m_index; //!< Index
138  double m_inv_pivot; //!< 1 / Pivot energy
139  double m_inv_ecut; //!< 1 / Cut off energy
140  };
141 
142  // Energy flux integration kernel
143  class eflux_kernel : public GFunction {
144  public:
145  eflux_kernel(const double& norm,
146  const double& index,
147  const double& pivot,
148  const double& ecut) :
149  m_norm(norm),
150  m_index(index),
151  m_inv_pivot(1.0/pivot),
152  m_inv_ecut(1.0/ecut) {}
153  double eval(const double& eng);
154  protected:
155  double m_norm; //!< Normalization
156  double m_index; //!< Index
157  double m_inv_pivot; //!< 1 / Pivot energy
158  double m_inv_ecut; //!< 1 / Cut off energy
159  };
160 
161  // Protected members
162  std::string m_type; //!< Model type
163  GModelPar m_norm; //!< Normalization factor
164  GModelPar m_index; //!< Spectral index
165  GModelPar m_ecut; //!< Exponential cut off energy
166  GModelPar m_pivot; //!< Pivot energy
167 
168  // Cached members used for pre-computations
169  mutable GEnergy m_last_energy; //!< Last energy value
170  mutable double m_last_index; //!< Last index parameter
171  mutable double m_last_ecut; //!< Last energy cut-off parameter
172  mutable double m_last_pivot; //!< Last pivot parameter
173  mutable double m_last_e_norm; //!< Last E/Epivot value
174  mutable double m_last_e_cut; //!< Last E/Ecut value
175  mutable double m_last_power; //!< Last power value
176  mutable double m_mc_emin; //!< Minimum energy
177  mutable double m_mc_emax; //!< Maximum energy
178  mutable double m_mc_exponent; //!< Exponent (index+1)
179  mutable double m_mc_pow_emin; //!< Power of minimum energy
180  mutable double m_mc_pow_ewidth; //!< Power of energy width
181 };
182 
183 
184 /***********************************************************************//**
185  * @brief Return class name
186  *
187  * @return String containing the class name ("GModelSpectralExpPlaw").
188  ***************************************************************************/
189 inline
190 std::string GModelSpectralExpPlaw::classname(void) const
191 {
192  return ("GModelSpectralExpPlaw");
193 }
194 
195 
196 /***********************************************************************//**
197  * @brief Return model type
198  *
199  * @return Model type.
200  *
201  * Returns the type of the exponentially cut off power law model.
202  ***************************************************************************/
203 inline
204 std::string GModelSpectralExpPlaw::type(void) const
205 {
206  return (m_type);
207 }
208 
209 
210 /***********************************************************************//**
211  * @brief Set model type
212  *
213  * @param[in] type Model type.
214  *
215  * Set the type of the exponentially cut off power law model.
216  ***************************************************************************/
217 inline
218 void GModelSpectralExpPlaw::type(const std::string& type)
219 {
220  m_type = type;
221  return;
222 }
223 
224 
225 /***********************************************************************//**
226  * @brief Return pre factor
227  *
228  * @return Pre factor (ph/cm2/s/MeV).
229  *
230  * Returns the pre factor.
231  ***************************************************************************/
232 inline
234 {
235  return (m_norm.value());
236 }
237 
238 
239 /***********************************************************************//**
240  * @brief Set pre factor
241  *
242  * @param[in] prefactor Pre factor (ph/cm2/s/MeV).
243  *
244  * Sets the pre factor.
245  ***************************************************************************/
246 inline
247 void GModelSpectralExpPlaw::prefactor(const double& prefactor)
248 {
249  m_norm.value(prefactor);
250  return;
251 }
252 
253 
254 /***********************************************************************//**
255  * @brief Return power law index
256  *
257  * @return Power law index.
258  *
259  * Returns the power law index.
260  ***************************************************************************/
261 inline
263 {
264  return (m_index.value());
265 }
266 
267 
268 /***********************************************************************//**
269  * @brief Set power law index
270  *
271  * @param[in] index Power law index.
272  *
273  * Sets the power law index.
274  ***************************************************************************/
275 inline
276 void GModelSpectralExpPlaw::index(const double& index)
277 {
278  m_index.value(index);
279  return;
280 }
281 
282 
283 /***********************************************************************//**
284  * @brief Return pivot energy
285  *
286  * @return Pivot energy.
287  *
288  * Returns the pivot energy.
289  ***************************************************************************/
290 inline
292 {
293  GEnergy energy;
294  energy.MeV(m_pivot.value());
295  return energy;
296 }
297 
298 
299 /***********************************************************************//**
300  * @brief Set pivot energy
301  *
302  * @param[in] pivot Pivot energy.
303  *
304  * Sets the pivot energy.
305  ***************************************************************************/
306 inline
308 {
309  m_pivot.value(pivot.MeV());
310  return;
311 }
312 
313 
314 /***********************************************************************//**
315  * @brief Return exponential cut-off energy
316  *
317  * @return Exponential cut-off energy.
318  *
319  * Returns the exponential cut-off energy.
320  ***************************************************************************/
321 inline
323 {
324  GEnergy energy;
325  energy.MeV(m_ecut.value());
326  return energy;
327 }
328 
329 
330 /***********************************************************************//**
331  * @brief Set exponential cut-off energy
332  *
333  * @param[in] cutoff Exponential cut-off energy.
334  *
335  * Sets the exponential cut-off energy.
336  ***************************************************************************/
337 inline
339 {
340  m_ecut.value(cutoff.MeV());
341  return;
342 }
343 
344 #endif /* GMODELSPECTRALEXPPLAW_HPP */
eflux_kernel(const double &norm, const double &index, const double &pivot, const double &ecut)
double m_last_e_norm
Last E/Epivot value.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
double m_mc_emax
Maximum energy.
Energy value class definition.
Abstract spectral model base class.
double m_last_index
Last index parameter.
virtual std::string type(void) const
Return model type.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void copy_members(const GModelSpectralExpPlaw &model)
Copy class members.
double m_mc_exponent
Exponent (index+1)
GEnergy pivot(void) const
Return pivot energy.
XML element node class.
Definition: GXmlElement.hpp:48
double eval(const double &eng)
Kernel for photon flux integration.
Random number generator class.
Definition: GRan.hpp:44
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
Time class.
Definition: GTime.hpp:55
void free_members(void)
Delete class members.
GModelPar m_ecut
Exponential cut off energy.
double prefactor(void) const
Return pre factor.
Model parameter class interface definition.
Model parameter class.
Definition: GModelPar.hpp:87
virtual ~GModelSpectralExpPlaw(void)
Destructor.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
GModelPar m_norm
Normalization factor.
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].
Single parameter function abstract base class definition.
virtual void clear(void)
Clear exponentially cut off power law model.
GEnergy cutoff(void) const
Return exponential cut-off energy.
double m_last_ecut
Last energy cut-off parameter.
double m_mc_emin
Minimum energy.
GModelSpectralExpPlaw(void)
Void constructor.
double index(void) const
Return power law index.
GChatter
Definition: GTypemaps.hpp:33
GEnergy m_last_energy
Last energy value.
std::string m_type
Model type.
double m_last_pivot
Last pivot parameter.
Abstract spectral model base class interface definition.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
double m_last_power
Last power value.
double m_mc_pow_emin
Power of minimum energy.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
double value(void) const
Return parameter value.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
Exponential cut off power law spectral class.
double eval(const double &eng)
Kernel for energy flux integration.
GModelPar m_pivot
Pivot energy.
virtual GModelSpectralExpPlaw & operator=(const GModelSpectralExpPlaw &model)
Assignment operator.
flux_kernel(const double &norm, const double &index, const double &pivot, const double &ecut)
void init_members(void)
Initialise class members.
virtual GModelSpectralExpPlaw * clone(void) const
Clone exponentially cut off power law model.
GModelPar m_index
Spectral index.
double m_last_e_cut
Last E/Ecut value.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string classname(void) const
Return class name.
double m_mc_pow_ewidth
Power of energy width.