GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatial.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatial.hpp - Spatial model abstract base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-2023 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 GModelSpatial.hpp
23  * @brief Abstract spatial model base class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIAL_HPP
28 #define GMODELSPATIAL_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GBase.hpp"
34 #include "GModelPar.hpp"
35 #include "GPhoton.hpp"
36 #include "GSkyDir.hpp"
37 #include "GSkyRegionCircle.hpp"
38 #include "GEnergy.hpp"
39 #include "GTime.hpp"
40 #include "GXmlElement.hpp"
41 #include "GRan.hpp"
42 #include "GFunction.hpp"
43 #include "GIntegral.hpp"
44 
45 /* __ Forward declarations _______________________________________________ */
46 class GSkyRegion;
47 
48 
49 /***********************************************************************//**
50  * @class GModelSpatial
51  *
52  * @brief Abstract spatial model base class
53  *
54  * This class implements the spatial component of the factorized gamma-ray
55  * source model. The spatial component is given by
56  *
57  * \f[
58  * S_{\rm p}(\vec{p} | E, t)
59  * \f]
60  *
61  * where
62  * - \f$\vec{p}\f$ is the true photon arrival direction,
63  * - \f$E\f$ is the true photon energy, and
64  * - \f$t\f$ is the true photon arrival time.
65  *
66  * The spatial component describes the energy and time dependent morphology
67  * of the source. It satisfies
68  * \f[
69  * \int_{\Omega} S_{\rm p}(\vec{p} | E, t) d\Omega = 1
70  * \f]
71  * for all \f$E\f$ and \f$t\f$, hence the spatial component does not
72  * impact the spatially integrated spectral and temporal properties of the
73  * source.
74  ***************************************************************************/
75 class GModelSpatial : public GBase {
76 
77 public:
78  // Constructors and destructors
79  GModelSpatial(void);
80  GModelSpatial(const GModelSpatial& model);
81  virtual ~GModelSpatial(void);
82 
83  // Operators
84  virtual GModelSpatial& operator=(const GModelSpatial& model);
85  virtual GModelPar& operator[](const int& index);
86  virtual const GModelPar& operator[](const int& index) const;
87  virtual GModelPar& operator[](const std::string& name);
88  virtual const GModelPar& operator[](const std::string& name) const;
89 
90  // Pure virtual methods
91  virtual void clear(void) = 0;
92  virtual GModelSpatial* clone(void) const = 0;
93  virtual std::string classname(void) const = 0;
94  virtual GClassCode code(void) const = 0;
95  virtual double eval(const GPhoton& photon,
96  const bool& gradients = false) const = 0;
97  virtual GSkyDir mc(const GEnergy& energy, const GTime& time,
98  GRan& ran) const = 0;
99  virtual double mc_norm(const GSkyDir& dir,
100  const double& radius) const = 0;
101  virtual bool contains(const GSkyDir& dir,
102  const double& margin = 0.0) const = 0;
103  virtual void read(const GXmlElement& xml) = 0;
104  virtual void write(GXmlElement& xml) const = 0;
105  virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
106 
107  // Virtual methods
108  virtual double flux(const GSkyRegion& region,
109  const GEnergy& srcEng = GEnergy(),
110  const GTime& srcTime = GTime()) const;
111 
112  // Methods
113  std::string type(void) const;
114  void type(const std::string& type);
115  GModelPar& at(const int& index);
116  const GModelPar& at(const int& index) const;
117  bool has_par(const std::string& name) const;
118  bool has_free_pars(void) const;
119  int size(void) const;
120  void autoscale(void);
121  const GSkyRegion* region(void) const;
122 
123 protected:
124  // Protected methods
125  void init_members(void);
126  void copy_members(const GModelSpatial& model);
127  void free_members(void);
128  virtual void set_region(void) const = 0;
129 
130  // Kernel for spatial model radial integration
132  public:
134  const GSkyRegion& region,
135  const GSkyDir& centre,
136  const GEnergy& srcEng,
137  const GTime& srcTime) :
138  m_model(model),
139  m_region(region),
140  m_centre(centre),
141  m_srcEng(srcEng),
142  m_srcTime(srcTime) { }
143  double eval(const double& rho);
144  public:
145  const GModelSpatial* m_model; //!< Spatial model
146  const GSkyRegion& m_region; //!< Sky region
147  const GSkyDir& m_centre; //!< Model centre
148  GEnergy m_srcEng; //!< Photon energy
149  GTime m_srcTime; //!< Photon time
150  };
151 
152  // Kernel for spatial model azimuth angle integration
154  public:
156  const GSkyRegion& region,
157  const GSkyDir& centre,
158  const double& rho,
159  const GEnergy& srcEng,
160  const GTime& srcTime) :
161  m_model(model),
162  m_region(region),
163  m_centre(centre),
164  m_rho(rho),
165  m_srcEng(srcEng),
166  m_srcTime(srcTime) { }
167  double eval(const double& omega);
168  public:
169  const GModelSpatial* m_model; //!< Spatial model
170  const GSkyRegion& m_region; //!< Sky region
171  const GSkyDir& m_centre; //!< Model centre
172  double m_rho; //!< Offset from center of the region
173  GEnergy m_srcEng; //!< Photon energy
174  GTime m_srcTime; //!< Photon time
175  };
176 
177  // Proteced members
178  std::string m_type; //!< Spatial model type
179  GSkyRegionCircle m_region; //!< Bounding circle
180  std::vector<GModelPar*> m_pars; //!< Parameter pointers
181 };
182 
183 
184 /***********************************************************************//**
185  * @brief Return model type
186  *
187  * @return Model type.
188  *
189  * Returns the type of the spatial model.
190  ***************************************************************************/
191 inline
192 std::string GModelSpatial::type(void) const
193 {
194  return (m_type);
195 }
196 
197 
198 /***********************************************************************//**
199  * @brief Set model type
200  *
201  * @param[in] type Model type.
202  *
203  * Set the type of the spatial model.
204  ***************************************************************************/
205 inline
206 void GModelSpatial::type(const std::string& type)
207 {
208  m_type = type;
209  return;
210 }
211 
212 
213 /***********************************************************************//**
214  * @brief Returns model parameter
215  *
216  * @param[in] index Parameter index [0,...,size()-1].
217  * @return Model parameter.
218  *
219  * Returns model parameter without @p index range checking.
220  ***************************************************************************/
221 inline
223 {
224  return *(m_pars[index]);
225 }
226 
227 
228 /***********************************************************************//**
229  * @brief Returns model parameter (const version)
230  *
231  * @param[in] index Parameter index [0,...,size()-1].
232  * @return Model parameter.
233  *
234  * Returns model parameter without @p index range checking.
235  ***************************************************************************/
236 inline
237 const GModelPar& GModelSpatial::operator[](const int& index) const
238 {
239  return *(m_pars[index]);
240 }
241 
242 
243 /***********************************************************************//**
244  * @brief Return number of parameters
245  *
246  * @return Number of parameters in spatial model component.
247  *
248  * Returns the number of parameters in the spatial model component.
249  ***************************************************************************/
250 inline
251 int GModelSpatial::size(void) const
252 {
253  return (int)m_pars.size();
254 }
255 
256 
257 /***********************************************************************//**
258  * @brief Return boundary sky region
259  *
260  * @return Boundary sky region.
261  *
262  * Returns a sky region that fully encloses the spatial model component.
263  ***************************************************************************/
264 inline
266 {
267  const_cast<GModelSpatial*>(this)->set_region();
268  return (&m_region);
269 }
270 
271 #endif /* GMODELSPATIAL_HPP */
const GSkyDir & m_centre
Model centre.
virtual void read(const GXmlElement &xml)=0
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
Energy value class definition.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const =0
Random number generator class definition.
XML element node class interface definition.
circle_int_kern_omega(const GModelSpatial *model, const GSkyRegion &region, const GSkyDir &centre, const double &rho, const GEnergy &srcEng, const GTime &srcTime)
int size(void) const
Return number of parameters.
GModelSpatial(void)
Void constructor.
bool has_free_pars(void) const
Checks if the spatial model has free parameters.
Sky direction class interface definition.
virtual ~GModelSpatial(void)
Destructor.
Definition of interface for all GammaLib classes.
double eval(const double &omega)
Kernel for spatial model azimuth angle integration.
XML element node class.
Definition: GXmlElement.hpp:48
const GSkyRegion & m_region
Sky region.
virtual GModelSpatial & operator=(const GModelSpatial &model)
Assignment operator.
Random number generator class.
Definition: GRan.hpp:44
virtual GModelPar & operator[](const int &index)
Returns model parameter.
Time class.
Definition: GTime.hpp:55
Interface for the circular sky region class.
virtual GClassCode code(void) const =0
std::string centre(const std::string &s, const int &n, const char &c= ' ')
Centre string to achieve a length of n characters.
Definition: GTools.cpp:1118
GSkyRegionCircle m_region
Bounding circle.
void copy_members(const GModelSpatial &model)
Copy class members.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
Model parameter class.
Definition: GModelPar.hpp:87
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
double eval(const double &rho)
Kernel for spatial model radial integration.
Single parameter function abstract base class definition.
const GModelSpatial * m_model
Spatial model.
circle_int_kern_rho(const GModelSpatial *model, const GSkyRegion &region, const GSkyDir &centre, const GEnergy &srcEng, const GTime &srcTime)
std::vector< GModelPar * > m_pars
Parameter pointers.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
const GModelSpatial * m_model
Spatial model.
GChatter
Definition: GTypemaps.hpp:33
double m_rho
Offset from center of the region.
const GSkyDir & m_centre
Model centre.
std::string type(void) const
Return model type.
Photon class definition.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
const GSkyRegion * region(void) const
Return boundary sky region.
void free_members(void)
Delete class members.
std::string m_type
Spatial model type.
GModelPar & at(const int &index)
Returns model parameter.
GClassCode
Definition: GTypemaps.hpp:42
bool has_par(const std::string &name) const
Checks if parameter name exists.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
const GSkyRegion & m_region
Sky region.
virtual std::string classname(void) const =0
Return class name.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const =0
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns model flux within sky region.
Abstract spatial model base class.
virtual void write(GXmlElement &xml) const =0
virtual void clear(void)=0
Clear object.
virtual void set_region(void) const =0
void init_members(void)
Initialise class members.
Integration class interface definition.
Sky direction class.
Definition: GSkyDir.hpp:62
virtual GModelSpatial * clone(void) const =0
Clones object.
Time class interface definition.
Circular sky region class interface definition.
void autoscale(void)
Autoscale parameters.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48