GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralExponential.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralExponential.hpp - Exponential spectral model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2018 by Luigi Tibaldo *
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 GModelSpectralExponential.hpp
23 * @brief Exponential spectral model class interface definition
24 * @author Luigi Tibaldo
25 */
26
27#ifndef GMODELSPECTRALEXPONENTIAL_HPP
28#define GMODELSPECTRALEXPONENTIAL_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GModelSpectral.hpp"
34#include "GEnergy.hpp"
36#include "GFunction.hpp"
37
38/* __ Forward declarations _______________________________________________ */
39class GRan;
40class GTime;
41class GXmlElement;
42
43
44/***********************************************************************//**
45 * @class GModelSpectralExponential
46 *
47 * @brief Exponential spectral model class
48 *
49 * This class implements a spectral model that is the exponential of a
50 * spectral model component. The spectral model component can be defined in
51 * an XML file, or using the exponent() method.
52 ***************************************************************************/
54
55public:
56 // Constructors and destructors
58 explicit GModelSpectralExponential(const GXmlElement& xml);
59 explicit GModelSpectralExponential(const GModelSpectral* spec);
61 virtual ~GModelSpectralExponential(void);
62
63 // Operators
65
66 // Implemented pure virtual methods
67 virtual void clear(void);
68 virtual GModelSpectralExponential* clone(void) const;
69 virtual std::string classname(void) const;
70 virtual std::string type(void) const;
71 virtual double eval(const GEnergy& srcEng,
72 const GTime& srcTime = GTime(),
73 const bool& gradients = false) const;
74 virtual double flux(const GEnergy& emin,
75 const GEnergy& emax) const;
76 virtual double eflux(const GEnergy& emin,
77 const GEnergy& emax) const;
78 virtual GEnergy mc(const GEnergy& emin,
79 const GEnergy& emax,
80 const GTime& time,
81 GRan& ran) const;
82 virtual void read(const GXmlElement& xml);
83 virtual void write(GXmlElement& xml) const;
84 virtual std::string print(const GChatter& chatter = NORMAL) const;
85
86 // Other methods
87 void exponent(const GModelSpectral* spec);
88 const GModelSpectral* exponent(void) const;
89
90protected:
91 // Protected methods
92 void init_members(void);
93 void copy_members(const GModelSpectralExponential& model);
94 void free_members(void);
95 void update_mc_cache(const GEnergy& emin, const GEnergy& emax) const;
96
97 // Class to determine the integral photon flux
98 class flux_kern : public GFunction {
99 public:
100 // Constructor
101 flux_kern(const GModelSpectral* spec) : m_exp(spec) {}
102
103 // Method
104 double eval(const double& x) {
105 GEnergy energy(x, "MeV");
106 double value = m_exp->eval(energy);
107 value = exp(value);
108 return value;
109 }
110 protected:
112 };
113
114 // Class to determine the integral energy flux, derived from flux_kern
115 class eflux_kern : public flux_kern {
116 public:
117 // Constructor
118 eflux_kern(const GModelSpectral* spec) : flux_kern(spec) {}
119
120 // Method
121 double eval(const double& x) {
122 return x * flux_kern::eval(x);
123 }
124 };
125
126 // Protected members
127 std::string m_type; //!< Model type
128 GModelSpectral* m_exponent; //!< Exponent model component
129
130 // MC cache
131 mutable GModelSpectralNodes m_mc_spectrum; //!< MC spectrum cache
132 mutable GEnergy m_mc_emin; //!< Last minimum energy
133 mutable GEnergy m_mc_emax; //!< Last maximum energy
134 mutable std::vector<double> m_mc_values; //!< Parameter values
135};
136
137
138/***********************************************************************//**
139 * @brief Return class name
140 *
141 * @return String containing the class name ("GModelSpectralExponential").
142 ***************************************************************************/
143inline
145{
146 return ("GModelSpectralExponential");
147}
148
149
150/***********************************************************************//**
151 * @brief Return model type
152 *
153 * @return Model type.
154 *
155 * Returns the type of the spectral Multiplicative model.
156 ***************************************************************************/
157inline
158std::string GModelSpectralExponential::type(void) const
159{
160 return (m_type);
161}
162
163#endif /* GMODELSPECTRALEXPONENTIAL_HPP */
Energy value class definition.
Single parameter function abstract base class definition.
Spectral nodes model class definition.
Abstract spectral model base class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
GVector exp(const GVector &vector)
Computes exponential of vector elements.
Definition GVector.cpp:1232
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Single parameter function abstract base class.
Definition GFunction.hpp:44
Exponential spectral model class.
void copy_members(const GModelSpectralExponential &model)
Copy class members.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
std::vector< double > m_mc_values
Parameter values.
const GModelSpectral * exponent(void) const
Return exponent.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
GModelSpectralNodes m_mc_spectrum
MC spectrum cache.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
virtual std::string classname(void) const
Return class name.
GEnergy m_mc_emax
Last maximum energy.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print Exponential spectral model information.
GModelSpectralExponential(void)
Void constructor.
GEnergy m_mc_emin
Last minimum energy.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
virtual ~GModelSpectralExponential(void)
Destructor.
GModelSpectral * m_exponent
Exponent model component.
virtual std::string type(void) const
Return model type.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
virtual GModelSpectralExponential * clone(void) const
Clone Exponential spectral model model.
virtual GModelSpectralExponential & operator=(const GModelSpectralExponential &model)
Assignment operator.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual void clear(void)
Clear Exponential spectral model.
Spectral nodes model class.
Abstract spectral model base class.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
XML element node class.