GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSky.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSky.hpp - Sky model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2011-2025 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 GModelSky.hpp
23 * @brief Sky model class interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GMODELSKY_HPP
28#define GMODELSKY_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GFunction.hpp"
33#include "GModel.hpp"
34#include "GModelPar.hpp"
35#include "GModelSpatial.hpp"
36#include "GModelSpectral.hpp"
37#include "GModelTemporal.hpp"
38#include "GSkyDir.hpp"
39#include "GEnergy.hpp"
40#include "GTime.hpp"
41#include "GPhoton.hpp"
42#include "GPhotons.hpp"
43#include "GRan.hpp"
44#include "GEvent.hpp"
45#include "GObservation.hpp"
46#include "GXmlElement.hpp"
47
48/* __ Forward declarations _______________________________________________ */
49class GEvent;
50class GObservation;
51class GVector;
52class GMatrixSparse;
53
54
55/***********************************************************************//**
56 * @class GModelSky
57 *
58 * @brief Sky model class
59 *
60 * This class implements a sky model that is factorized into a spatial,
61 * a spectral and a temporal component. The factorization is given by
62 *
63 * \f[
64 * S(\vec{p}, E, t) = S_{\rm p}(\vec{p} | E, t) \,
65 * S_{\rm E}(E | t) \,
66 * S_{\rm t}(t)
67 * \f]
68 *
69 * where
70 * - \f$S_{\rm p}(\vec{p} | E, t)\f$ is the spatial component,
71 * - \f$S_{\rm E}(E | t)\f$ is the spectral component, and
72 * - \f$S_{\rm t}(t)\f$ is the temporal component.
73 *
74 * The spatial component describes the energy and time dependent morphology
75 * of the source. It satisfies
76 * \f[
77 * \int_{\Omega} S_{\rm p}(\vec{p} | E, t) d\Omega = 1
78 * \f]
79 * for all \f$E\f$ and \f$t\f$, hence the spatial component does not
80 * impact the spatially integrated spectral and temporal properties of the
81 * source.
82 *
83 * The spectral component describes the spatially integrated time dependent
84 * spectral distribution of the source. It satisfies
85 * \f[
86 * \int_{E} S_{\rm E}(E | t) dE = \Phi
87 * \f]
88 * for all \f$t\f$, where \f$\Phi\f$ is the spatially and spectrally
89 * integrated total source flux. The spectral component does not impact
90 * the temporal properties of the integrated flux \f$\Phi\f$.
91 *
92 * The temporal component describes the temporal variation of the total
93 * integrated flux \f$\Phi\f$ of the source.
94 *
95 * The class has two methods for model evaluation that evaluate the model
96 * for a specific event, given an observation. The eval() method returns
97 * the model value. Note that the eval() method calls protected methods that
98 * handle time dispersion, energy dispersion and the point
99 * spread function (spatial dispersion). Dispersion is handled by
100 * integrating over the relevant intervals of the source properties.
101 * Integration of the model is done by three nested integrals.
102 * The outmost integral integrates over time (method integrate_time()),
103 * the next integral integrates over energy (method integrate_energy()),
104 * and the innermost integral integrates over the point spread function
105 * (method integrate_dir()).
106 *
107 * The npred() method returns the integral over the model for a given
108 * observed energy and time.
109 *
110 * The read() and write() methods allow reading of model information from
111 * and writing to an XML element. The type() method returns the model type
112 * that has been found in an XML element.
113 *
114 * The model factorization is implemented by the abstract model component
115 * classes GModelSpatial, GModelSpectral and GModelTemporal. The GModelSky
116 * class holds pointers to derived instances of these classes, which can
117 * be accessed using the spatial(), spectral() and temporal() methods. Note
118 * that these pointers can be NULL (for example if no model has been yet
119 * defined), so the validity of the pointers needs to be checked before
120 * using them.
121 ***************************************************************************/
122class GModelSky : public GModel {
123
124public:
125 // Constructors and destructors
126 GModelSky(void);
127 explicit GModelSky(const std::string& type);
128 explicit GModelSky(const GXmlElement& xml);
130 const GXmlElement& spectral);
132 const GXmlElement& spectral,
133 const GXmlElement& temporal);
135 const GModelSpectral& spectral);
138 const GModelTemporal& temporal);
139 GModelSky(const GModelSky& model);
140 virtual ~GModelSky(void);
141
142 // Operators
143 virtual GModelSky& operator=(const GModelSky& model);
144
145 // Implemented pure virtual base class methods
146 virtual void clear(void);
147 virtual GModelSky* clone(void) const;
148 virtual std::string classname(void) const;
149 virtual std::string type(void) const;
150 virtual bool is_constant(void) const;
151 virtual double eval(const GEvent& event,
152 const GObservation& obs,
153 const bool& gradients = false) const;
154 virtual GVector eval(const GObservation& obs,
155 GMatrixSparse* gradients = NULL,
156 const int& offset = 0) const;
157 virtual double npred(const GEnergy& obsEng,
158 const GTime& obsTime,
159 const GObservation& obs) const;
160 virtual void read(const GXmlElement& xml);
161 virtual void write(GXmlElement& xml) const;
162 virtual std::string print(const GChatter& chatter = NORMAL) const;
163
164 // Other methods
165 GModelSpatial* spatial(void) const;
166 GModelSpectral* spectral(void) const;
167 GModelTemporal* temporal(void) const;
168 void spatial(const GModelSpatial* spatial);
169 void spectral(const GModelSpectral* spectral);
170 void temporal(const GModelTemporal* temporal);
171 double value(const GPhoton& photon);
172 GVector gradients(const GPhoton& photon);
173 GPhotons mc(const double& area,
174 const GSkyDir& dir, const double& radius,
175 const GEnergy& emin, const GEnergy& emax,
176 const GTime& tmin, const GTime& tmax,
177 GRan& ran) const;
178 double flux(const GEnergy& emin,
179 const GEnergy& emax) const;
180 double flux(const GSkyRegion& region,
181 const GEnergy& emin,
182 const GEnergy& emax) const;
183 double eflux(const GEnergy& emin,
184 const GEnergy& emax) const;
185 double eflux(const GSkyRegion& region,
186 const GEnergy& emin,
187 const GEnergy& emax) const;
188 double flux_error(const GEnergy& emin,
189 const GEnergy& emax) const;
190 double flux_error(const GSkyRegion& region,
191 const GEnergy& emin,
192 const GEnergy& emax) const;
193 double eflux_error(const GEnergy& emin,
194 const GEnergy& emax) const;
195 double eflux_error(const GSkyRegion& region,
196 const GEnergy& emin,
197 const GEnergy& emax) const;
198
199protected:
200 // Protected methods
201 void init_members(void);
202 void copy_members(const GModelSky& model);
203 void free_members(void);
204 void set_pointers(void);
205 void set_type(void);
206 void signal_analytical_gradients(const GObservation& obs) const;
210 bool valid_model(void) const;
211
212 // Flux integration kernels
213 class flux_kern : public GFunction {
214 public:
215 flux_kern(const GModelSky* parent,
216 const GSkyRegion* region) :
217 m_parent(parent),
218 m_region(region) { }
219 double eval(const double& x);
220 protected:
221 const GModelSky* m_parent; //!< Sky model
222 const GSkyRegion* m_region; //!< Sky region
223 };
224 class eflux_kern : public GFunction {
225 public:
226 eflux_kern(const GModelSky* parent,
227 const GSkyRegion* region) :
228 m_parent(parent),
229 m_region(region) { }
230 double eval(const double& x);
231 protected:
232 const GModelSky* m_parent; //!< Sky model
233 const GSkyRegion* m_region; //!< Sky region
234 };
235
236 // Protected data members
237 std::string m_type; //!< Model type
238 GModelSpatial* m_spatial; //!< Spatial model
239 GModelSpectral* m_spectral; //!< Spectral model
240 GModelTemporal* m_temporal; //!< Temporal model
241};
242
243
244/***********************************************************************//**
245 * @brief Return class name
246 *
247 * @return String containing the class name ("GModelSky").
248 ***************************************************************************/
249inline
250std::string GModelSky::classname(void) const
251{
252 return ("GModelSky");
253}
254
255
256/***********************************************************************//**
257 * @brief Return sky model type
258 *
259 * @return Sky model type.
260 *
261 * Returns the type of the sky model. The type is an arbitrary string that
262 * is used in the XML declaration of the model to describe the model type.
263 ***************************************************************************/
264inline
265std::string GModelSky::type(void) const
266{
267 return (m_type);
268}
269
270
271/***********************************************************************//**
272 * @brief Signals if sky model is temporally constant
273 *
274 * @return True if sky model is temporally constant, false otherwise.
275 *
276 * Signals if the sky model is temporally constant. A temporally constant
277 * model is a model that has a temporal component of type "Constant".
278 ***************************************************************************/
279inline
281{
282 return (m_temporal != NULL && m_temporal->type() == "Constant");
283}
284
285
286/***********************************************************************//**
287 * @brief Return spatial model component
288 *
289 * @return Pointer to spatial model component.
290 *
291 * Returns a pointer to the spatial model component of the model. The pointer
292 * is of type GModelSpatial. Note that a NULL pointer may be returned if the
293 * sky model has no spatial model component.
294 ***************************************************************************/
295inline
297{
298 return (m_spatial);
299}
300
301
302/***********************************************************************//**
303 * @brief Return spectral model component
304 *
305 * @return Pointer to spectral model component.
306 *
307 * Returns a pointer to the spectral model component of the model. The
308 * pointer is of type GModelSpectral. Note that a NULL pointer may be
309 * returned if the sky model has no spectral model component.
310 ***************************************************************************/
311inline
313{
314 return (m_spectral);
315}
316
317
318/***********************************************************************//**
319 * @brief Return temporal model component
320 *
321 * @return Pointer to temporal model component.
322 *
323 * Returns a pointer to the temporal model component of the model. The
324 * pointer is of type GModelTemporal. Note that a NULL pointer may be
325 * returned if the sky model has no temporal model component.
326 ***************************************************************************/
327inline
329{
330 return (m_temporal);
331}
332
333#endif /* GMODELSKY_HPP */
Energy value class definition.
Abstract event base class definition.
Single parameter function abstract base class definition.
Model parameter class interface definition.
Abstract spatial model base class interface definition.
Abstract spectral model base class interface definition.
Abstract temporal model base class interface definition.
Abstract model base class interface definition.
Abstract observation base class interface definition.
Photon class definition.
Photon container class definition.
Random number generator class definition.
Sky direction class interface definition.
Time class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
XML element node class interface definition.
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Abstract interface for the event classes.
Definition GEvent.hpp:71
Single parameter function abstract base class.
Definition GFunction.hpp:44
Sparse matrix class interface definition.
eflux_kern(const GModelSky *parent, const GSkyRegion *region)
double eval(const double &x)
Integration kernel for eflux_kern() class.
const GModelSky * m_parent
Sky model.
const GSkyRegion * m_region
Sky region.
const GModelSky * m_parent
Sky model.
double eval(const double &x)
Integration kernel for flux_kern() class.
const GSkyRegion * m_region
Sky region.
flux_kern(const GModelSky *parent, const GSkyRegion *region)
Sky model class.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
virtual GModelSky & operator=(const GModelSky &model)
Assignment operator.
double eflux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux error.
void init_members(void)
Initialise class members.
GModelTemporal * m_temporal
Temporal model.
double value(const GPhoton &photon)
Return value of sky model for a given photon.
void set_pointers(void)
Set parameter pointers.
GModelSpatial * xml_spatial(const GXmlElement &spatial) const
Return pointer to spatial model from XML element.
bool valid_model(void) const
Verifies if model has all components.
GModelSpectral * m_spectral
Spectral model.
virtual bool is_constant(void) const
Signals if sky model is temporally constant.
GModelSpatial * m_spatial
Spatial model.
double flux(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux.
virtual void read(const GXmlElement &xml)
Read sky model from XML element.
std::string m_type
Model type.
virtual GModelSky * clone(void) const
Clone sky model.
void set_type(void)
Set model type based on spatial model component.
double flux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux error.
GModelSpectral * spectral(void) const
Return spectral model component.
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
Return simulated list of photons.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated sky model.
GVector gradients(const GPhoton &photon)
Return parameter gradients of sky model for a given photon.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
GModelSky(void)
Void constructor.
Definition GModelSky.cpp:91
void signal_analytical_gradients(const GObservation &obs) const
Signal all parameters that have analytical gradients for a given observation.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Evaluate sky model for a given event of an observation.
virtual void clear(void)
Clear sky model.
void free_members(void)
Delete class members.
virtual std::string classname(void) const
Return class name.
double eflux(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux.
GModelTemporal * temporal(void) const
Return temporal model component.
void copy_members(const GModelSky &model)
Copy class members.
GModelSpatial * spatial(void) const
Return spatial model component.
virtual std::string type(void) const
Return sky model type.
virtual ~GModelSky(void)
Destructor.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
Abstract spatial model base class.
Abstract spectral model base class.
Abstract temporal model base class.
virtual std::string type(void) const =0
Abstract model class.
Definition GModel.hpp:100
Abstract observation base class.
Class that handles photons.
Definition GPhoton.hpp:47
Photon container class.
Definition GPhotons.hpp:45
Random number generator class.
Definition GRan.hpp:44
Sky direction class.
Definition GSkyDir.hpp:62
Abstract interface for the sky region class.
Time class.
Definition GTime.hpp:55
Vector class.
Definition GVector.hpp:46
XML element node class.