GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralGauss.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralGauss.hpp - Spectral Gaussian model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2014-2016 by Christoph Deil & Ellis Owen *
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 GModelSpectralGauss.hpp
23 * @brief Gaussian spectral model class interface definition
24 * @author Christoph Deil & Ellis Owen
25 */
26
27#ifndef GMODELSPECTRALGAUSS_HPP
28#define GMODELSPECTRALGAUSS_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 _______________________________________________ */
38class GRan;
39class GTime;
40class GXmlElement;
41
42
43/***********************************************************************//**
44 * @class GModelSpectralGauss
45 *
46 * @brief Gaussian spectral model class
47 *
48 * This class implements a Gaussian spectrum. The model is defined by
49 *
50 * \f[
51 * S_{\rm E}(E | t) =
52 * \frac{\tt m\_norm}{\sqrt{2 \pi} m\_sigma^2} \exp
53 * \left(\frac{-(E - m\_mean)^2}{2 m_\sigma^2} \right)
54 * \f]
55 *
56 * where
57 * - \f${\tt m\_norm}\f$ is the normalization,
58 * - \f${\tt m\_mean}\f$ is the mean energy,
59 * - \f${\tt m\_sigma}\f$ is the energy width.
60 ***************************************************************************/
62
63public:
64 // Constructors and destructors
66 explicit GModelSpectralGauss(const GXmlElement& xml);
67 GModelSpectralGauss(const double& norm,
68 const GEnergy& mean,
69 const GEnergy& sigma);
71 virtual ~GModelSpectralGauss(void);
72
73 // Operators
75
76 // Implemented pure virtual base class methods
77 virtual void clear(void);
78 virtual GModelSpectralGauss* clone(void) const;
79 virtual std::string classname(void) const;
80 virtual std::string type(void) const;
81 virtual double eval(const GEnergy& srcEng,
82 const GTime& srcTime = GTime(),
83 const bool& gradients = false) const;
84 virtual double flux(const GEnergy& emin,
85 const GEnergy& emax) const;
86 virtual double eflux(const GEnergy& emin,
87 const GEnergy& emax) const;
88 virtual GEnergy mc(const GEnergy& emin,
89 const GEnergy& emax,
90 const GTime& time,
91 GRan& ran) const;
92 virtual void read(const GXmlElement& xml);
93 virtual void write(GXmlElement& xml) const;
94 virtual std::string print(const GChatter& chatter = NORMAL) const;
95
96 // Other methods
97 double norm(void) const;
98 void norm(const double& norm);
99 GEnergy mean(void) const;
100 void mean(const GEnergy& mean);
101 GEnergy sigma(void) const;
102 void sigma(const GEnergy& sigma);
103
104protected:
105 // Protected methods
106 void init_members(void);
107 void copy_members(const GModelSpectralGauss& model);
108 void free_members(void);
109 void update_eval_cache(const GEnergy& energy) const;
110
111 // Energy flux integration kernel
112 class eflux_kernel : public GFunction {
113 public:
114 eflux_kernel(const double& norm,
115 const double& mean,
116 const double& sigma) :
117 m_norm(norm),
118 m_mean(mean),
119 m_sigma(sigma) {}
120 double eval(const double& eng);
121 protected:
122 double m_norm; //!< Normalization
123 double m_mean; //!< Mean
124 double m_sigma; //!< Sigma
125 };
126
127 // Protected members
128 GModelPar m_norm; //!< Normalization factor
129 GModelPar m_mean; //!< Gaussian mean energy
130 GModelPar m_sigma; //!< Gaussian energy width
131};
132
133
134/***********************************************************************//**
135 * @brief Return class name
136 *
137 * @return String containing the class name ("GModelSpectralGauss").
138 ***************************************************************************/
139inline
140std::string GModelSpectralGauss::classname(void) const
141{
142 return ("GModelSpectralGauss");
143}
144
145
146/***********************************************************************//**
147 * @brief Return model type
148 *
149 * @return "ConstantValue".
150 *
151 * Returns the type of the Gaussian spectral model.
152 ***************************************************************************/
153inline
154std::string GModelSpectralGauss::type(void) const
155{
156 return "Gaussian";
157}
158
159
160/***********************************************************************//**
161 * @brief Return normalization
162 *
163 * @return Normalization (ph/cm2/s).
164 ***************************************************************************/
165inline
167{
168 return (m_norm.value());
169}
170
171
172/***********************************************************************//**
173 * @brief Set normalization
174 *
175 * @param[in] norm Normalization (ph/cm2/s).
176 ***************************************************************************/
177inline
179{
181 return;
182}
183
184/***********************************************************************//**
185 * @brief Return mean energy
186 *
187 * @return Mean energy.
188 ***************************************************************************/
189inline
191{
192 GEnergy energy;
193 energy.MeV(m_mean.value());
194 return energy;
195}
196
197
198/***********************************************************************//**
199 * @brief Set mean energy
200 *
201 * @param[in] mean Mean energy.
202 ***************************************************************************/
203inline
205{
206 m_mean.value(mean.MeV());
207 return;
208}
209
210/***********************************************************************//**
211 * @brief Return energy width
212 *
213 * @return Energy width
214 ***************************************************************************/
215inline
217{
218 GEnergy energy;
219 energy.MeV(m_sigma.value());
220 return energy;
221}
222
223
224/***********************************************************************//**
225 * @brief Set energy width
226 *
227 * @param[in] sigma Energy width.
228 ***************************************************************************/
229inline
231{
233 return;
234}
235
236#endif /* GMODELSPECTRALGAUSS_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
eflux_kernel(const double &norm, const double &mean, const double &sigma)
double eval(const double &eng)
Kernel for energy flux integration.
Gaussian spectral model class.
GModelPar m_sigma
Gaussian energy width.
virtual std::string classname(void) const
Return class name.
GEnergy mean(void) const
Return mean energy.
GModelPar m_norm
Normalization factor.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (ph/cm2/s)
virtual ~GModelSpectralGauss(void)
Destructor.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print spectral model information.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
void init_members(void)
Initialise class members.
virtual void clear(void)
Clear Gaussian spectral model.
GModelPar m_mean
Gaussian mean energy.
GModelSpectralGauss(void)
Void constructor.
void copy_members(const GModelSpectralGauss &model)
Copy class members.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate model value.
void free_members(void)
Delete class members.
virtual GModelSpectralGauss * clone(void) const
Clone Gaussian spectral model.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual std::string type(void) const
Return model type.
double norm(void) const
Return normalization.
virtual GModelSpectralGauss & operator=(const GModelSpectralGauss &model)
Assignment operator.
virtual void read(const GXmlElement &xml)
Read model from XML element.
void update_eval_cache(const GEnergy &energy) const
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (erg/cm2/s)
GEnergy sigma(void) const
Return energy width.
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.