GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 _______________________________________________ */
38 class GRan;
39 class GTime;
40 class 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 
63 public:
64  // Constructors and destructors
65  GModelSpectralGauss(void);
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
74  virtual GModelSpectralGauss& operator=(const GModelSpectralGauss& model);
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 
104 protected:
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  ***************************************************************************/
139 inline
140 std::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  ***************************************************************************/
153 inline
154 std::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  ***************************************************************************/
165 inline
166 double GModelSpectralGauss::norm(void) const
167 {
168  return (m_norm.value());
169 }
170 
171 
172 /***********************************************************************//**
173  * @brief Set normalization
174  *
175  * @param[in] norm Normalization (ph/cm2/s).
176  ***************************************************************************/
177 inline
178 void GModelSpectralGauss::norm(const double& norm)
179 {
180  m_norm.value(norm);
181  return;
182 }
183 
184 /***********************************************************************//**
185  * @brief Return mean energy
186  *
187  * @return Mean energy.
188  ***************************************************************************/
189 inline
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  ***************************************************************************/
203 inline
205 {
206  m_mean.value(mean.MeV());
207  return;
208 }
209 
210 /***********************************************************************//**
211  * @brief Return energy width
212  *
213  * @return Energy width
214  ***************************************************************************/
215 inline
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  ***************************************************************************/
229 inline
231 {
232  m_sigma.value(sigma.MeV());
233  return;
234 }
235 
236 #endif /* GMODELSPECTRALGAUSS_HPP */
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:821
virtual GModelSpectralGauss & operator=(const GModelSpectralGauss &model)
Assignment operator.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print spectral model information.
Energy value class definition.
Abstract spectral model base class.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual void clear(void)
Clear Gaussian spectral model.
XML element node class.
Definition: GXmlElement.hpp:47
Random number generator class.
Definition: GRan.hpp:44
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
Time class.
Definition: GTime.hpp:54
double eval(const double &eng)
Kernel for energy flux integration.
GModelPar m_norm
Normalization factor.
Gaussian spectral model class.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
Model parameter class interface definition.
virtual GModelSpectralGauss * clone(void) const
Clone Gaussian spectral model.
Model parameter class.
Definition: GModelPar.hpp:87
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate model value.
void copy_members(const GModelSpectralGauss &model)
Copy class members.
virtual std::string classname(void) const
Return class name.
Single parameter function abstract base class definition.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void init_members(void)
Initialise class members.
GEnergy mean(void) const
Return mean energy.
GModelPar m_sigma
Gaussian energy width.
GChatter
Definition: GTypemaps.hpp:33
void free_members(void)
Delete class members.
virtual ~GModelSpectralGauss(void)
Destructor.
double norm(void) const
Return normalization.
eflux_kernel(const double &norm, const double &mean, const double &sigma)
Abstract spectral model base class interface definition.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
virtual std::string type(void) const
Return model type.
double value(void) const
Return parameter value.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
GModelSpectralGauss(void)
Void constructor.
void update_eval_cache(const GEnergy &energy) const
GModelPar m_mean
Gaussian mean energy.
GEnergy sigma(void) const
Return energy width.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48