GammaLib 2.0.0
Loading...
Searching...
No Matches
GModelSpectralBins.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpectralBins.hpp - Spectral bins model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2021 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 GModelSpectralBins.hpp
23 * @brief Spectral bins model class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMODELSPECTRALBINS_HPP
28#define GMODELSPECTRALBINS_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <vector>
32#include <string>
33#include "GModelSpectral.hpp"
34#include "GModelPar.hpp"
35#include "GEnergy.hpp"
36
37/* __ Forward declarations _______________________________________________ */
38class GRan;
39class GTime;
40class GEbounds;
41class GXmlElement;
42
43
44/***********************************************************************//**
45 * @class GModelSpectralBins
46 *
47 * @brief Spectral bins model class
48 *
49 * This class implements spectral bins that have a constant intensity within
50 * their boundaries. A spectral bin is defined by a lower and upper energy
51 * limit, with the lower limit included and the upper limit excluded from an
52 * energy bin.
53 ***************************************************************************/
55
56public:
57 // Constructors and destructors
60 const GEbounds& ebounds,
61 const double& index = -2.0);
62 explicit GModelSpectralBins(const GXmlElement& xml);
64 virtual ~GModelSpectralBins(void);
65
66 // Operators
67 virtual GModelSpectralBins& operator=(const GModelSpectralBins& model);
68
69 // Implemented pure virtual base class methods
70 virtual void clear(void);
71 virtual GModelSpectralBins* clone(void) const;
72 virtual std::string classname(void) const;
73 virtual std::string type(void) const;
74 virtual double eval(const GEnergy& srcEng,
75 const GTime& srcTime = GTime(),
76 const bool& gradients = false) const;
77 virtual double flux(const GEnergy& emin,
78 const GEnergy& emax) const;
79 virtual double eflux(const GEnergy& emin,
80 const GEnergy& emax) const;
81 virtual GEnergy mc(const GEnergy& emin,
82 const GEnergy& emax,
83 const GTime& time,
84 GRan& ran) const;
85 virtual void read(const GXmlElement& xml);
86 virtual void write(GXmlElement& xml) const;
87 virtual std::string print(const GChatter& chatter = NORMAL) const;
88
89 // Other methods
90 int bins(void) const;
91 void append(const GEnergy& emin,
92 const GEnergy& emax,
93 const double& intensity);
94 void insert(const int& index,
95 const GEnergy& emin,
96 const GEnergy& emax,
97 const double& intensity);
98 void remove(const int& index);
99 void reserve(const int& num);
100 void extend(const GModelSpectralBins& bins);
101 double index(void) const;
102 void index(const double& index);
103 GEnergy emin(const int& index) const;
104 GEnergy emax(const int& index) const;
105 void emin(const int& index, const GEnergy& emin);
106 void emax(const int& index, const GEnergy& emax);
107 double intensity(const int& index) const;
108 void intensity(const int& index, const double& intensity);
109 double error(const int& index) const;
110
111protected:
112 // Protected methods
113 void init_members(void);
114 void copy_members(const GModelSpectralBins& model);
115 void free_members(void);
116 int bin_index(const GEnergy& energy) const;
117 void update_pars(void);
118 void set_cache(void) const;
119 void mc_update(const GEnergy& emin, const GEnergy& emax) const;
120
121 // Protected members
122 GModelPar m_index; //!< Spectral index of all bins
123 std::vector<GModelPar> m_emin; //!< Lower energy limits
124 std::vector<GModelPar> m_emax; //!< Upper energy limits
125 std::vector<GModelPar> m_values; //!< Bin values
126
127 // Evaluation cache
128 mutable std::vector<double> m_epivot; //!< Power-law pivot energies in MeV
129
130 // MC cache
131 mutable GEnergy m_mc_emin; //!< Minimum energy
132 mutable GEnergy m_mc_emax; //!< Maximum energy
133 mutable std::vector<double> m_mc_cum; //!< Cumulative distribution
134 mutable std::vector<double> m_mc_min; //!< Lower boundary for MC
135 mutable std::vector<double> m_mc_max; //!< Upper boundary for MC
136 mutable std::vector<double> m_mc_exp; //!< Exponent for MC
137};
138
139
140/***********************************************************************//**
141 * @brief Return class name
142 *
143 * @return String containing the class name ("GModelSpectralBins").
144 ***************************************************************************/
145inline
146std::string GModelSpectralBins::classname(void) const
147{
148 return ("GModelSpectralBins");
149}
150
151
152/***********************************************************************//**
153 * @brief Return model type
154 *
155 * @return "BinFunction".
156 *
157 * Returns the type of the spectral bin function model.
158 ***************************************************************************/
159inline
160std::string GModelSpectralBins::type(void) const
161{
162 return "BinFunction";
163}
164
165
166/***********************************************************************//**
167 * @brief Return number of bins
168 *
169 * @return Number of bins.
170 *
171 * Returns the number of bins in the bin function model.
172 ***************************************************************************/
173inline
175{
176 return (int)m_values.size();
177}
178
179#endif /* GMODELSPECTRALBINS_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
Energy boundaries container class.
Definition GEbounds.hpp:60
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Model parameter class.
Definition GModelPar.hpp:87
Spectral bins model class.
std::vector< GModelPar > m_emax
Upper energy limits.
GEnergy emax(const int &index) const
Return upper energy limit of bin.
void reserve(const int &num)
Reserve space for bins.
int bin_index(const GEnergy &energy) const
Return bin index for energy.
virtual GModelSpectralBins & operator=(const GModelSpectralBins &model)
Assignment operator.
virtual GModelSpectralBins * clone(void) const
Clone spectral bins model.
GModelPar m_index
Spectral index of all bins.
void free_members(void)
Delete class members.
void mc_update(const GEnergy &emin, const GEnergy &emax) const
Set MC pre-computation cache.
std::vector< double > m_mc_cum
Cumulative distribution.
void copy_members(const GModelSpectralBins &model)
Copy class members.
void insert(const int &index, const GEnergy &emin, const GEnergy &emax, const double &intensity)
Insert bin.
std::vector< double > m_mc_exp
Exponent for MC.
GEnergy emin(const int &index) const
Return lower energy limit of bin.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
void update_pars(void)
Update parameter mapping.
std::vector< double > m_mc_min
Lower boundary for MC.
GEnergy m_mc_emax
Maximum energy.
std::vector< double > m_mc_max
Upper boundary for MC.
void append(const GEnergy &emin, const GEnergy &emax, const double &intensity)
Append bin.
virtual ~GModelSpectralBins(void)
Destructor.
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 init_members(void)
Initialise class members.
void set_cache(void) const
Set cache.
double index(void) const
Return spectral power law index.
std::vector< GModelPar > m_values
Bin values.
GEnergy m_mc_emin
Minimum energy.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual std::string classname(void) const
Return class name.
int bins(void) const
Return number of bins.
std::vector< GModelPar > m_emin
Lower energy limits.
double error(const int &index) const
Return intensity error of bin.
double intensity(const int &index) const
Return bin intensity.
void extend(const GModelSpectralBins &bins)
Append bins from bin function.
virtual void clear(void)
Clear spectral bins model.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
void remove(const int &index)
Remove bin.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print bin function information.
virtual std::string type(void) const
Return model type.
std::vector< double > m_epivot
Power-law pivot energies in MeV.
GModelSpectralBins(void)
Void constructor.
Abstract spectral model base class.
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
XML element node class.