GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectral.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectral.hpp - Abstract spectral model base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2009-2016 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 GModelSpectral.hpp
23 * @brief Abstract spectral model base class interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMODELSPECTRAL_HPP
28#define GMODELSPECTRAL_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GBase.hpp"
34#include "GTime.hpp"
35
36/* __ Forward declaration ________________________________________________ */
37class GEnergy;
38class GRan;
39class GModelPar;
40class GXmlElement;
41
42
43/***********************************************************************//**
44 * @class GModelSpectral
45 *
46 * @brief Abstract spectral model base class
47 *
48 * This class implements the spectral component of the factorized source
49 * model
50 *
51 * \f[
52 * S_{\rm E}(E | t)
53 * \f]
54 *
55 * where
56 * \f$E\f$ is the true photon energy, and
57 * \f$t\f$ is the true photon arrival time.
58 *
59 * The spectral component describes the spatially integrated time dependent
60 * spectral distribution of the source. It satisfies
61 * \f[
62 * \int_{E} S_{\rm E}(E | t) dE = \Phi
63 * \f]
64 * for all \f$t\f$, where \f$\Phi\f$ is the spatially and spectrally
65 * integrated total source flux. The spectral component does not impact
66 * the temporal properties of the integrated flux \f$\Phi\f$.
67 ***************************************************************************/
68class GModelSpectral : public GBase {
69
70public:
71 // Constructors and destructors
72 GModelSpectral(void);
73 GModelSpectral(const GModelSpectral& model);
74 virtual ~GModelSpectral(void);
75
76 // Operators
77 virtual GModelSpectral& operator=(const GModelSpectral& model);
78 virtual GModelPar& operator[](const int& index);
79 virtual const GModelPar& operator[](const int& index) const;
80 virtual GModelPar& operator[](const std::string& name);
81 virtual const GModelPar& operator[](const std::string& name) const;
82
83 // Pure virtual methods
84 virtual void clear(void) = 0;
85 virtual GModelSpectral* clone(void) const = 0;
86 virtual std::string classname(void) const = 0;
87 virtual std::string type(void) const = 0;
88 virtual double eval(const GEnergy& srcEng,
89 const GTime& srcTime = GTime(),
90 const bool& gradients = false) const = 0;
91 virtual double flux(const GEnergy& emin,
92 const GEnergy& emax) const = 0;
93 virtual double eflux(const GEnergy& emin,
94 const GEnergy& emax) const = 0;
95 virtual GEnergy mc(const GEnergy& emin, const GEnergy& emax,
96 const GTime& time, GRan& ran) const = 0;
97 virtual void read(const GXmlElement& xml) = 0;
98 virtual void write(GXmlElement& xml) const = 0;
99 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
100
101 // Methods
102 GModelPar& at(const int& index);
103 const GModelPar& at(const int& index) const;
104 bool has_par(const std::string& name) const;
105 int size(void) const;
106 void autoscale(void);
107
108protected:
109 // Protected methods
110 void init_members(void);
111 void copy_members(const GModelSpectral& model);
112 void free_members(void);
113
114 // Proteced members
115 std::vector<GModelPar*> m_pars; //!< Parameter pointers
116};
117
118
119/***********************************************************************//**
120 * @brief Returns model parameter
121 *
122 * @param[in] index Parameter index [0,...,size()-1].
123 * @return Model parameter.
124 *
125 * Returns model parameter without @p index range checking.
126 ***************************************************************************/
127inline
129{
130 return *(m_pars[index]);
131}
132
133
134/***********************************************************************//**
135 * @brief Returns model parameter (const version)
136 *
137 * @param[in] index Parameter index [0,...,size()-1].
138 * @return Model parameter.
139 *
140 * Returns model parameter without @p index range checking.
141 ***************************************************************************/
142inline
143const GModelPar& GModelSpectral::operator[](const int& index) const
144{
145 return *(m_pars[index]);
146}
147
148
149/***********************************************************************//**
150 * @brief Return number of parameters
151 *
152 * @return Number of parameters in spectral model component.
153 *
154 * Returns the number of parameters in the spectral model component.
155 ***************************************************************************/
156inline
157int GModelSpectral::size(void) const
158{
159 return (int)m_pars.size();
160}
161
162#endif /* GMODELSPECTRAL_HPP */
Definition of interface for all GammaLib classes.
Time class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Model parameter class.
Definition GModelPar.hpp:87
Abstract spectral model base class.
bool has_par(const std::string &name) const
Checks if parameter name exists.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
void free_members(void)
Delete class members.
virtual void read(const GXmlElement &xml)=0
GModelPar & at(const int &index)
Returns model parameter.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
void copy_members(const GModelSpectral &model)
Copy class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const =0
virtual ~GModelSpectral(void)
Destructor.
virtual GModelPar & operator[](const int &index)
Returns model parameter.
std::vector< GModelPar * > m_pars
Parameter pointers.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const =0
void autoscale(void)
Autoscale parameters.
virtual void clear(void)=0
Clear object.
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual void write(GXmlElement &xml) const =0
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const =0
virtual std::string classname(void) const =0
Return class name.
virtual std::string type(void) const =0
int size(void) const
Return number of parameters.
GModelSpectral(void)
Void constructor.
void init_members(void)
Initialise class members.
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
XML element node class.