GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralPlawEnergyFlux.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralPlawEnergyFlux.hpp - Spectral power law model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2018 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 GModelSpectralPlawEnergyFlux.hpp
23  * @brief Energy flux normalized power law spectral model class interface definition
24  * @author Michael Mayer
25  */
26 
27 #ifndef GMODELSPECTRALPLAWENERGYFLUX_HPP
28 #define GMODELSPECTRALPLAWENERGYFLUX_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GModelSpectral.hpp"
33 #include "GModelPar.hpp"
34 #include "GEnergy.hpp"
35 
36 /* __ Forward declarations _______________________________________________ */
37 class GRan;
38 class GTime;
39 class GXmlElement;
40 
41 
42 /***********************************************************************//**
43  * @class GModelSpectralPlawEnergyFlux
44  *
45  * @brief Energy flux normalized power law spectral model class
46  *
47  * This class implements a power law spectrum. The model is defined by
48  *
49  * \f[
50  * S_{\rm E}(E | t) = {\tt m\_eflux}
51  * \frac{{\tt m\_index}+1}
52  * {{\tt e\_max}^{{\tt m\_index}+2} -
53  * {\tt e\_min}^{{\tt m\_index}+2}}
54  * E^{\tt m\_index}
55  * \f]
56  *
57  * for \f${\tt m\_index} \ne -2\f$ and
58  *
59  * \f[
60  * S_{\rm E}(E | t) =
61  * \frac{{\tt m\_eflux}}
62  * {\log {\tt e\_max} - \log {\tt e\_min}}
63  * E^{\tt m\_index}
64  * \f]
65  *
66  * for \f${\tt m\_index} = -2\f$, where
67  * - \f${\tt e\_min}\f$ is the minimum energy of an interval,
68  * - \f${\tt e\_max}\f$ is the maximum energy of an interval,
69  * - \f${\tt m\_eflux}\f$ is the energy flux between
70  * \f${\tt e\_min}\f$ and \f${\tt e\_max}\f$, and
71  * - \f${\tt m\_index}\f$ is the spectral index.
72  ***************************************************************************/
74 
75 public:
76  // Constructors and destructors
78  GModelSpectralPlawEnergyFlux(const std::string& type,
79  const std::string& eflux,
80  const std::string& index,
81  const std::string& emin,
82  const std::string& emax);
83  explicit GModelSpectralPlawEnergyFlux(const double& eflux,
84  const double& index,
85  const GEnergy& emin,
86  const GEnergy& emax);
87  explicit GModelSpectralPlawEnergyFlux(const GXmlElement& xml);
89  virtual ~GModelSpectralPlawEnergyFlux(void);
90 
91  // Operators
93 
94  // Implemented pure virtual base class methods
95  virtual void clear(void);
96  virtual GModelSpectralPlawEnergyFlux* clone(void) const;
97  virtual std::string classname(void) const;
98  virtual std::string type(void) const;
99  virtual double eval(const GEnergy& srcEng,
100  const GTime& srcTime = GTime(),
101  const bool& gradients = false) const;
102  virtual double flux(const GEnergy& emin,
103  const GEnergy& emax) const;
104  virtual double eflux(const GEnergy& emin,
105  const GEnergy& emax) const;
106  virtual GEnergy mc(const GEnergy& emin,
107  const GEnergy& emax,
108  const GTime& time,
109  GRan& ran) const;
110  virtual void read(const GXmlElement& xml);
111  virtual void write(GXmlElement& xml) const;
112  virtual std::string print(const GChatter& chatter = NORMAL) const;
113 
114  // Other methods
115  void type(const std::string& type);
116  double eflux(void) const;
117  void eflux(const double& eflux);
118  double index(void) const;
119  void index(const double& index);
120  GEnergy emin(void) const;
121  void emin(const GEnergy& emin);
122  GEnergy emax(void) const;
123  void emax(const GEnergy& emax);
124 
125 protected:
126  // Protected methods
127  void init_members(void);
128  void copy_members(const GModelSpectralPlawEnergyFlux& model);
129  void free_members(void);
130  void update(const GEnergy& srcEng) const;
131 
132  // Protected members
133  std::string m_type; //!< Model type
134  GModelPar m_eflux; //!< Energy flux (erg/cm2/s)
135  GModelPar m_index; //!< Spectral index
136  GModelPar m_emin; //!< Lower energy limit (MeV)
137  GModelPar m_emax; //!< Upper energy limit (MeV)
138 
139  // Cached members used for pre-computations
140  mutable double m_log_emin; //!< Log(emin)
141  mutable double m_log_emax; //!< Log(emax)
142  mutable double m_pow_emin; //!< emin^(index+1)
143  mutable double m_pow_emax; //!< emax^(index+1)
144  mutable double m_norm; //!< Power-law normalization (for pivot energy 1 MeV)
145  mutable double m_g_norm; //!< Power-law normalization gradient
146  mutable double m_power; //!< Power-law factor
147  mutable double m_last_index; //!< Last spectral index (MeV)
148  mutable GEnergy m_last_emin; //!< Last lower energy limit
149  mutable GEnergy m_last_emax; //!< Last upper energy limit
150  mutable GEnergy m_last_energy; //!< Last source energy
151 };
152 
153 
154 /***********************************************************************//**
155  * @brief Return class name
156  *
157  * @return String containing the class name ("GModelSpectralPlawEnergyFlux").
158  ***************************************************************************/
159 inline
161 {
162  return ("GModelSpectralPlawEnergyFlux");
163 }
164 
165 
166 /***********************************************************************//**
167  * @brief Return model type
168  *
169  * @return Model type.
170  *
171  * Returns the type of the spectral power law model.
172  ***************************************************************************/
173 inline
174 std::string GModelSpectralPlawEnergyFlux::type(void) const
175 {
176  return (m_type);
177 }
178 
179 
180 /***********************************************************************//**
181  * @brief Set model type
182  *
183  * @param[in] type Model type.
184  *
185  * Set the type of the spectral power law model.
186  ***************************************************************************/
187 inline
188 void GModelSpectralPlawEnergyFlux::type(const std::string& type)
189 {
190  m_type = type;
191  return;
192 }
193 
194 
195 /***********************************************************************//**
196  * @brief Return energy flux
197  *
198  * @return Energy flux (erg/cm2/s).
199  *
200  * Returns the energy flux.
201  ***************************************************************************/
202 inline
204 {
205  return (m_eflux.value());
206 }
207 
208 
209 /***********************************************************************//**
210  * @brief Set energy flux
211  *
212  * @param[in] eflux Energy flux (erg/cm2/s).
213  *
214  * Sets the energy flux.
215  ***************************************************************************/
216 inline
217 void GModelSpectralPlawEnergyFlux::eflux(const double& eflux)
218 {
219  m_eflux.value(eflux);
220  return;
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Return power law index
226  *
227  * @return Power law index.
228  *
229  * Returns the power law index.
230  ***************************************************************************/
231 inline
233 {
234  return (m_index.value());
235 }
236 
237 
238 /***********************************************************************//**
239  * @brief Set power law index
240  *
241  * @param[in] index Power law index.
242  *
243  * Sets the power law index.
244  ***************************************************************************/
245 inline
246 void GModelSpectralPlawEnergyFlux::index(const double& index)
247 {
248  m_index.value(index);
249  return;
250 }
251 
252 
253 /***********************************************************************//**
254  * @brief Return minimum energy
255  *
256  * @return Minimum energy.
257  *
258  * Returns the minimum energy.
259  ***************************************************************************/
260 inline
262 {
263  GEnergy energy;
264  energy.MeV(m_emin.value());
265  return energy;
266 }
267 
268 
269 /***********************************************************************//**
270  * @brief Set minimum energy
271  *
272  * @param[in] emin Minimum energy.
273  *
274  * Sets the minimum energy.
275  ***************************************************************************/
276 inline
278 {
279  m_emin.value(emin.MeV());
280  return;
281 }
282 
283 
284 /***********************************************************************//**
285  * @brief Return maximum energy
286  *
287  * @return Maximum energy.
288  *
289  * Returns the maximum energy.
290  ***************************************************************************/
291 inline
293 {
294  GEnergy energy;
295  energy.MeV(m_emax.value());
296  return energy;
297 }
298 
299 
300 /***********************************************************************//**
301  * @brief Set maximum energy
302  *
303  * @param[in] emax Maximum energy.
304  *
305  * Sets the maximum energy.
306  ***************************************************************************/
307 inline
309 {
310  m_emax.value(emax.MeV());
311  return;
312 }
313 
314 #endif /* GMODELSPECTRALPLAWENERGYFLUX_HPP */
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_last_index
Last spectral index (MeV)
Energy value class definition.
Abstract spectral model base class.
XML element node class.
Definition: GXmlElement.hpp:48
GEnergy emin(void) const
Return minimum energy.
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:55
void init_members(void)
Initialise class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual ~GModelSpectralPlawEnergyFlux(void)
Destructor.
virtual GModelSpectralPlawEnergyFlux & operator=(const GModelSpectralPlawEnergyFlux &model)
Assignment operator.
virtual GModelSpectralPlawEnergyFlux * clone(void) const
Clone power law model.
GModelPar m_emin
Lower energy limit (MeV)
void update(const GEnergy &srcEng) const
Update precomputed values.
Model parameter class interface definition.
Model parameter class.
Definition: GModelPar.hpp:87
GModelPar m_eflux
Energy flux (erg/cm2/s)
GEnergy m_last_emax
Last upper energy limit.
GEnergy m_last_emin
Last lower energy limit.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual std::string type(void) const
Return model type.
double m_g_norm
Power-law normalization gradient.
GModelPar m_emax
Upper energy limit (MeV)
GModelSpectralPlawEnergyFlux(void)
Void constructor.
GChatter
Definition: GTypemaps.hpp:33
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
GEnergy m_last_energy
Last source energy.
Abstract spectral model base class interface definition.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
void copy_members(const GModelSpectralPlawEnergyFlux &model)
Copy class members.
double m_norm
Power-law normalization (for pivot energy 1 MeV)
double value(void) const
Return parameter value.
double index(void) const
Return power law index.
void free_members(void)
Delete class members.
double eflux(void) const
Return energy flux.
Energy flux normalized power law spectral model class.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
GEnergy emax(void) const
Return maximum energy.
virtual void clear(void)
Clear power law model.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string classname(void) const
Return class name.