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