GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralConst.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralConst.hpp - Spectral constant model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-2018 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 GModelSpectralConst.hpp
23  * @brief Constant spectral model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPECTRALCONST_HPP
28 #define GMODELSPECTRALCONST_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 GModelSpectralConst
44  *
45  * @brief Constant spectral model class
46  *
47  * This class implements a constant spectrum. The model is defined by
48  *
49  * \f[
50  * S_{\rm E}(E | t) = {\tt m\_norm}
51  * \f]
52  *
53  * where
54  * \f${\tt m\_norm}\f$ is the normalization constant in units of
55  * ph/cm2/s/MeV.
56  ***************************************************************************/
58 
59 public:
60  // Constructors and destructors
61  GModelSpectralConst(void);
62  GModelSpectralConst(const std::string& type, const std::string& value);
63  explicit GModelSpectralConst(const GXmlElement& xml);
64  explicit GModelSpectralConst(const double& value);
66  virtual ~GModelSpectralConst(void);
67 
68  // Operators
69  virtual GModelSpectralConst& operator=(const GModelSpectralConst& model);
70 
71  // Implemented pure virtual base class methods
72  virtual void clear(void);
73  virtual GModelSpectralConst* clone(void) const;
74  virtual std::string classname(void) const;
75  virtual std::string type(void) const;
76  virtual double eval(const GEnergy& srcEng,
77  const GTime& srcTime = GTime(),
78  const bool& gradients = false) const;
79  virtual double flux(const GEnergy& emin,
80  const GEnergy& emax) const;
81  virtual double eflux(const GEnergy& emin,
82  const GEnergy& emax) const;
83  virtual GEnergy mc(const GEnergy& emin,
84  const GEnergy& emax,
85  const GTime& time,
86  GRan& ran) const;
87  virtual void read(const GXmlElement& xml);
88  virtual void write(GXmlElement& xml) const;
89  virtual std::string print(const GChatter& chatter = NORMAL) const;
90 
91  // Other methods
92  void type(const std::string& type);
93  double value(void) const;
94  void value(const double& value);
95 
96 protected:
97  // Protected methods
98  void init_members(void);
99  void copy_members(const GModelSpectralConst& model);
100  void free_members(void);
101 
102  // Protected members
103  std::string m_type; //!< Model type
104  GModelPar m_norm; //!< Normalization factor
105 };
106 
107 
108 /***********************************************************************//**
109  * @brief Return class name
110  *
111  * @return String containing the class name ("GModelSpectralConst").
112  ***************************************************************************/
113 inline
114 std::string GModelSpectralConst::classname(void) const
115 {
116  return ("GModelSpectralConst");
117 }
118 
119 
120 /***********************************************************************//**
121  * @brief Return model type
122  *
123  * @return Model type.
124  *
125  * Returns the type of the constant spectral model.
126  ***************************************************************************/
127 inline
128 std::string GModelSpectralConst::type(void) const
129 {
130  return (m_type);
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Set model type
136  *
137  * @param[in] type Model type.
138  *
139  * Set the type of the constant spectral model.
140  ***************************************************************************/
141 inline
142 void GModelSpectralConst::type(const std::string& type)
143 {
144  m_type = type;
145  return;
146 }
147 
148 
149 /***********************************************************************//**
150  * @brief Return model value
151  *
152  * @return Model value (ph/cm2/s/MeV).
153  *
154  * Returns the model value.
155  ***************************************************************************/
156 inline
157 double GModelSpectralConst::value(void) const
158 {
159  return (m_norm.value());
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Set model value
165  *
166  * @param[in] value Model value (ph/cm2/s/MeV).
167  *
168  * Sets the model value.
169  ***************************************************************************/
170 inline
171 void GModelSpectralConst::value(const double& value)
172 {
173  m_norm.value(value);
174  return;
175 }
176 
177 #endif /* GMODELSPECTRALCONST_HPP */
virtual void read(const GXmlElement &xml)
Read model from XML element.
void init_members(void)
Initialise class members.
virtual GModelSpectralConst & operator=(const GModelSpectralConst &model)
Assignment operator.
Energy value class definition.
Abstract spectral model base class.
virtual GModelSpectralConst * clone(void) const
Clone constant spectral model.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate model value.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
std::string m_type
Model type.
XML element node class.
Definition: GXmlElement.hpp:48
double value(void) const
Return model value.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
void copy_members(const GModelSpectralConst &model)
Copy class members.
virtual std::string classname(void) const
Return class name.
Model parameter class interface definition.
Model parameter class.
Definition: GModelPar.hpp:87
GModelSpectralConst(void)
Void constructor.
virtual void clear(void)
Clear constant spectral model.
GChatter
Definition: GTypemaps.hpp:33
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
virtual std::string print(const GChatter &chatter=NORMAL) const
Print spectral model information.
virtual std::string type(void) const
Return model type.
Abstract spectral model base class interface definition.
double value(void) const
Return parameter value.
virtual ~GModelSpectralConst(void)
Destructor.
GModelPar m_norm
Normalization factor.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Constant spectral model class.
void free_members(void)
Delete class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48