GammaLib 2.0.0
Loading...
Searching...
No Matches
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 _______________________________________________ */
37class GRan;
38class GTime;
39class 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
54public:
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
91protected:
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 ***************************************************************************/
117inline
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 ***************************************************************************/
131inline
132std::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 ***************************************************************************/
145inline
147{
148 return ((int)m_spectral.size());
149}
150
151#endif /* GMODELSPECTRALCOMPOSITE_HPP */
Energy value class definition.
Model parameter class interface definition.
Abstract spectral model base class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Composite spectral model class.
void free_members(void)
Delete class members.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
virtual GModelSpectralComposite * clone(void) const
Clone composite spectral model.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
virtual ~GModelSpectralComposite(void)
Destructor.
void init_members(void)
Initialise class members.
std::vector< double > m_mc_probs
Probailities of individual components.
const GModelSpectral * component(const int &index) const
Returns spectral component element.
std::vector< double > m_mc_values
Parameter values.
GModelSpectralComposite(void)
Void constructor.
virtual GModelSpectralComposite & operator=(const GModelSpectralComposite &model)
Assignment operator.
GEnergy m_mc_emin
Last minimum energy.
void copy_members(const GModelSpectralComposite &model)
Copy class members.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
virtual void clear(void)
Clear composite spectral model.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
virtual std::string classname(void) const
Return class name.
virtual std::string type(void) const
Return model type.
std::vector< std::string > m_components
Names of components.
GEnergy m_mc_emax
Last maximum energy.
void append(const GModelSpectral &spec, const std::string &name="")
Append spectral component.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print composite spectral model information.
std::vector< GModelSpectral * > m_spectral
Container of spectral models.
int components(void) const
Return number of spectral components.
Abstract spectral model base class.
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
XML element node class.