GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralComposite.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralComposite.hpp - Spectral composite 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 GModelSpectralComposite.hpp
23  * @brief Composite spectral model class interface definition
24  * @author Michael Mayer
25  */
26 
27 #ifndef GMODELSPECTRALCOMPOSITE_HPP
28 #define GMODELSPECTRALCOMPOSITE_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 GModelSpectralComposite
44  *
45  * @brief Composite spectral model class
46  *
47  * This class implements a composite spectrum. The model is defined by the sum
48  * of several individual spectral models. Each spectral model can be added via
49  * the XML interface or using the append() method.
50  *
51  ***************************************************************************/
53 
54 public:
55  // Constructors and destructors
57  explicit GModelSpectralComposite(const GXmlElement& xml);
59  virtual ~GModelSpectralComposite(void);
60 
61  // Operators
63 
64  // Implemented pure virtual methods
65  virtual void clear(void);
66  virtual GModelSpectralComposite* clone(void) const;
67  virtual std::string classname(void) const;
68  virtual std::string type(void) const;
69  virtual double eval(const GEnergy& srcEng,
70  const GTime& srcTime = GTime(),
71  const bool& gradients = false) const;
72  virtual double flux(const GEnergy& emin,
73  const GEnergy& emax) const;
74  virtual double eflux(const GEnergy& emin,
75  const GEnergy& emax) const;
76  virtual GEnergy mc(const GEnergy& emin,
77  const GEnergy& emax,
78  const GTime& time,
79  GRan& ran) const;
80  virtual void read(const GXmlElement& xml);
81  virtual void write(GXmlElement& xml) const;
82  virtual std::string print(const GChatter& chatter = NORMAL) const;
83 
84  // Other methods
85  void append(const GModelSpectral& spec,
86  const std::string& name="");
87  int components(void) const;
88  const GModelSpectral* component(const int& index) const;
89  const GModelSpectral* component(const std::string& name) const;
90 
91 protected:
92  // Protected methods
93  void init_members(void);
94  void copy_members(const GModelSpectralComposite& model);
95  void free_members(void);
96  void update_mc_cache(const GEnergy& emin, const GEnergy& emax) const;
97 
98  // Protected members
99  std::string m_type; //!< Model type
100  std::vector<GModelSpectral*> m_spectral; //!< Container of spectral models
101  std::vector<std::string> m_components; //!< Names of components
102 
103  // MC cache
104  mutable double m_mc_flux; //!< Flux cache
105  mutable std::vector<double> m_mc_probs; //!< Probailities of individual components
106  mutable GEnergy m_mc_emin; //!< Last minimum energy
107  mutable GEnergy m_mc_emax; //!< Last maximum energy
108  mutable std::vector<double> m_mc_values; //!< Parameter values
109 };
110 
111 
112 /***********************************************************************//**
113  * @brief Return class name
114  *
115  * @return String containing the class name ("GModelSpectralComposite").
116  ***************************************************************************/
117 inline
118 std::string GModelSpectralComposite::classname(void) const
119 {
120  return ("GModelSpectralComposite");
121 }
122 
123 
124 /***********************************************************************//**
125  * @brief Return model type
126  *
127  * @return Model type.
128  *
129  * Returns the type of the spectral composite model.
130  ***************************************************************************/
131 inline
132 std::string GModelSpectralComposite::type(void) const
133 {
134  return (m_type);
135 }
136 
137 
138 /***********************************************************************//**
139  * @brief Return number of spectral components
140  *
141  * @return Number of model components.
142  *
143  * Returns the number of spectral components.
144  ***************************************************************************/
145 inline
147 {
148  return ((int)m_spectral.size());
149 }
150 
151 #endif /* GMODELSPECTRALCOMPOSITE_HPP */
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
GModelSpectralComposite(void)
Void constructor.
std::vector< double > m_mc_probs
Probailities of individual components.
std::vector< GModelSpectral * > m_spectral
Container of spectral models.
Energy value class definition.
Abstract spectral model base class.
void init_members(void)
Initialise class members.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
XML element node class.
Definition: GXmlElement.hpp:47
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:54
std::string m_type
Model type.
int components(void) const
Return number of spectral components.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
Model parameter class interface definition.
virtual void read(const GXmlElement &xml)
Read model from XML element.
void append(const GModelSpectral &spec, const std::string &name="")
Append spectral component.
virtual void clear(void)
Clear composite spectral model.
std::vector< double > m_mc_values
Parameter values.
const GModelSpectral * component(const int &index) const
Returns spectral component element.
GChatter
Definition: GTypemaps.hpp:33
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
void free_members(void)
Delete class members.
Abstract spectral model base class interface definition.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void copy_members(const GModelSpectralComposite &model)
Copy class members.
Composite spectral model class.
virtual std::string classname(void) const
Return class name.
GEnergy m_mc_emax
Last maximum energy.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print composite spectral model information.
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
virtual GModelSpectralComposite & operator=(const GModelSpectralComposite &model)
Assignment operator.
std::vector< std::string > m_components
Names of components.
virtual GModelSpectralComposite * clone(void) const
Clone composite spectral model.
virtual ~GModelSpectralComposite(void)
Destructor.
GEnergy m_mc_emin
Last minimum energy.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48