GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
35 #include "GModelSpectralNodes.hpp"
36 #include "GFunction.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GRan;
40 class GTime;
41 class 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 
55 public:
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 
90 protected:
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  ***************************************************************************/
143 inline
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  ***************************************************************************/
157 inline
158 std::string GModelSpectralExponential::type(void) const
159 {
160  return (m_type);
161 }
162 
163 #endif /* GMODELSPECTRALEXPONENTIAL_HPP */
virtual void write(GXmlElement &xml) const
Write model into XML element.
void free_members(void)
Delete class members.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
Energy value class definition.
Abstract spectral model base class.
GModelSpectral * m_exponent
Exponent model component.
void init_members(void)
Initialise class members.
virtual std::string type(void) const
Return model type.
GEnergy m_mc_emin
Last minimum energy.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual GModelSpectralExponential * clone(void) const
Clone Exponential spectral model model.
XML element node class.
Definition: GXmlElement.hpp:47
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
Time class.
Definition: GTime.hpp:54
virtual void clear(void)
Clear Exponential spectral model.
Spectral nodes model class.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
Single parameter function abstract base class definition.
virtual GModelSpectralExponential & operator=(const GModelSpectralExponential &model)
Assignment operator.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
GModelSpectralNodes m_mc_spectrum
MC spectrum cache.
const GModelSpectral * exponent(void) const
Return exponent.
GChatter
Definition: GTypemaps.hpp:33
Exponential spectral model class.
Abstract spectral model base class interface definition.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
virtual std::string classname(void) const
Return class name.
virtual ~GModelSpectralExponential(void)
Destructor.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
Definition: GVector.cpp:1142
GEnergy m_mc_emax
Last maximum energy.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
GModelSpectralExponential(void)
Void constructor.
void copy_members(const GModelSpectralExponential &model)
Copy class members.
std::vector< double > m_mc_values
Parameter values.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string print(const GChatter &chatter=NORMAL) const
Print Exponential spectral model information.