GModelSky.hpp
11.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
/***************************************************************************
* GModelSky.hpp - Sky model class *
* ----------------------------------------------------------------------- *
* copyright (C) 2011-2015 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GModelSky.hpp
* @brief Sky model class interface definition
* @author Juergen Knoedlseder
*/
#ifndef GMODELSKY_HPP
#define GMODELSKY_HPP
/* __ Includes ___________________________________________________________ */
#include <string>
#include "GModel.hpp"
#include "GModelPar.hpp"
#include "GModelSpatial.hpp"
#include "GModelSpectral.hpp"
#include "GModelTemporal.hpp"
#include "GSkyDir.hpp"
#include "GEnergy.hpp"
#include "GTime.hpp"
#include "GPhoton.hpp"
#include "GPhotons.hpp"
#include "GRan.hpp"
#include "GVector.hpp"
#include "GEvent.hpp"
#include "GObservation.hpp"
#include "GXmlElement.hpp"
/* __ Forward declarations _______________________________________________ */
class GEvent;
class GObservation;
/***********************************************************************//**
* @class GModelSky
*
* @brief Sky model class
*
* This class implements a sky model that is factorized into a spatial,
* a spectral and a temporal component. The factorization is given by
*
* \f[
* S(\vec{p}, E, t) = S_{\rm p}(\vec{p} | E, t) \,
* S_{\rm E}(E | t) \,
* S_{\rm t}(t)
* \f]
*
* where
* - \f$S_{\rm p}(\vec{p} | E, t)\f$ is the spatial component,
* - \f$S_{\rm E}(E | t)\f$ is the spectral component, and
* - \f$S_{\rm t}(t)\f$ is the temporal component.
*
* The spatial component describes the energy and time dependent morphology
* of the source. It satisfies
* \f[
* \int_{\Omega} S_{\rm p}(\vec{p} | E, t) d\Omega = 1
* \f]
* for all \f$E\f$ and \f$t\f$, hence the spatial component does not
* impact the spatially integrated spectral and temporal properties of the
* source.
*
* The spectral component describes the spatially integrated time dependent
* spectral distribution of the source. It satisfies
* \f[
* \int_{E} S_{\rm E}(E | t) dE = \Phi
* \f]
* for all \f$t\f$, where \f$\Phi\f$ is the spatially and spectrally
* integrated total source flux. The spectral component does not impact
* the temporal properties of the integrated flux \f$\Phi\f$.
*
* The temporal component describes the temporal variation of the total
* integrated flux \f$\Phi\f$ of the source.
*
* The class has two methods for model evaluation that evaluate the model
* for a specific event, given an observation. The eval() method returns
* the model value, the eval_gradients() returns the model value and sets
* the analytical gradients for all model parameters.
* Note that the eval() and eval_gradients() methods call protected
* methods that handle time dispersion, energy dispersion and the point
* spread function (spatial dispersion). Dispersion is handled by
* integrating over the relevant intervals of the source properties.
* Integration of the model is done by three nested integrals.
* The outmost integral integrates over time (method integrate_time()),
* the next integral integrates over energy (method integrate_energy()),
* and the innermost integral integrates over the point spread function
* (method integrate_dir()).
*
* The npred() method returns the integral over the model for a given
* observed energy and time.
*
* The read() and write() methods allow reading of model information from
* and writing to an XML element. The type() method returns the model type
* that has been found in an XML element.
*
* The model factorization is implemented by the abstract model component
* classes GModelSpatial, GModelSpectral and GModelTemporal. The GModelSky
* class holds pointers to derived instances of these classes, which can
* be accessed using the spatial(), spectral() and temporal() methods. Note
* that these pointers can be NULL (for example if no model has been yet
* defined), so the validity of the pointers needs to be checked before
* using them.
***************************************************************************/
class GModelSky : public GModel {
public:
// Constructors and destructors
GModelSky(void);
explicit GModelSky(const std::string& type);
explicit GModelSky(const GXmlElement& xml);
GModelSky(const GXmlElement& spatial,
const GXmlElement& spectral);
GModelSky(const GXmlElement& spatial,
const GXmlElement& spectral,
const GXmlElement& temporal);
GModelSky(const GModelSpatial& spatial,
const GModelSpectral& spectral);
GModelSky(const GModelSpatial& spatial,
const GModelSpectral& spectral,
const GModelTemporal& temporal);
GModelSky(const GModelSky& model);
virtual ~GModelSky(void);
// Operators
virtual GModelSky& operator=(const GModelSky& model);
// Implemented pure virtual base class methods
virtual void clear(void);
virtual GModelSky* clone(void) const;
virtual std::string classname(void) const;
virtual std::string type(void) const;
virtual bool is_constant(void) const;
virtual double eval(const GEvent& event,
const GObservation& obs) const;
virtual double eval_gradients(const GEvent& event,
const GObservation& obs) const;
virtual double npred(const GEnergy& obsEng,
const GTime& obsTime,
const GObservation& obs) const;
virtual void read(const GXmlElement& xml);
virtual void write(GXmlElement& xml) const;
virtual std::string print(const GChatter& chatter = NORMAL) const;
// Other methods
GModelSpatial* spatial(void) const;
GModelSpectral* spectral(void) const;
GModelTemporal* temporal(void) const;
double value(const GPhoton& photon);
GVector gradients(const GPhoton& photon);
GPhotons mc(const double& area,
const GSkyDir& dir, const double& radius,
const GEnergy& emin, const GEnergy& emax,
const GTime& tmin, const GTime& tmax,
GRan& ran) const;
protected:
// Protected methods
void init_members(void);
void copy_members(const GModelSky& model);
void free_members(void);
void set_pointers(void);
void set_type(void);
GModelSpatial* xml_spatial(const GXmlElement& spatial) const;
GModelSpectral* xml_spectral(const GXmlElement& spectral) const;
GModelTemporal* xml_temporal(const GXmlElement& temporal) const;
bool valid_model(void) const;
// Protected data members
std::string m_type; //!< Model type
GModelSpatial* m_spatial; //!< Spatial model
GModelSpectral* m_spectral; //!< Spectral model
GModelTemporal* m_temporal; //!< Temporal model
};
/***********************************************************************//**
* @brief Return class name
*
* @return String containing the class name ("GModelSky").
***************************************************************************/
inline
std::string GModelSky::classname(void) const
{
return ("GModelSky");
}
/***********************************************************************//**
* @brief Return sky model type
*
* @return Sky model type.
*
* Returns the type of the sky model. The type is an arbitrary string that
* is used in the XML declaration of the model to describe the model type.
***************************************************************************/
inline
std::string GModelSky::type(void) const
{
return (m_type);
}
/***********************************************************************//**
* @brief Signals if sky model is temporally constant
*
* @return True if sky model is temporally constant, false otherwise.
*
* Signals if the sky model is temporally constant. A temporally constant
* model is a model that has a temporal component of type "Constant".
***************************************************************************/
inline
bool GModelSky::is_constant(void) const
{
return (m_temporal != NULL && m_temporal->type() == "Constant");
}
/***********************************************************************//**
* @brief Return spatial model component
*
* @return Pointer to spatial model component.
*
* Returns a pointer to the spatial model component of the model. The pointer
* is of type GModelSpatial. Note that a NULL pointer may be returned if the
* sky model has no spatial model component.
***************************************************************************/
inline
GModelSpatial* GModelSky::spatial(void) const
{
return (m_spatial);
}
/***********************************************************************//**
* @brief Return spectral model component
*
* @return Pointer to spectral model component.
*
* Returns a pointer to the spectral model component of the model. The
* pointer is of type GModelSpectral. Note that a NULL pointer may be
* returned if the sky model has no spectral model component.
***************************************************************************/
inline
GModelSpectral* GModelSky::spectral(void) const
{
return (m_spectral);
}
/***********************************************************************//**
* @brief Return temporal model component
*
* @return Pointer to temporal model component.
*
* Returns a pointer to the temporal model component of the model. The
* pointer is of type GModelTemporal. Note that a NULL pointer may be
* returned if the sky model has no temporal model component.
***************************************************************************/
inline
GModelTemporal* GModelSky::temporal(void) const
{
return (m_temporal);
}
#endif /* GMODELSKY_HPP */