GammaLib  2.0.0
 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-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 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 circular sky region radial integration
132  public:
134  const GSkyRegionCircle* reg,
135  const GEnergy& srcEng,
136  const GTime& srcTime,
137  const double distance,
138  const double cosdist,
139  const double sindist,
140  const double modrad,
141  const double cosmodrad) :
142  m_model(model),
143  m_reg(reg),
144  m_srcEng(srcEng),
145  m_srcTime(srcTime),
146  m_dist(distance),
147  m_cosdist(cosdist),
148  m_sindist(sindist),
149  m_modrad(modrad),
150  m_cosmodrad(cosmodrad) { }
151  double eval(const double& rho);
152  public:
153  const GModelSpatial* m_model; //!< Spatial model
154  const GSkyRegionCircle* m_reg; //!< Integration region
155  GEnergy m_srcEng; //!< Photon energy
156  GTime m_srcTime; //!< Photon time
157  double m_dist; //!< Distance model-region (rad)
158  double m_cosdist; //!< Cos of distance model-region
159  double m_sindist; //!< Sin of distance model-region
160  double m_modrad; //!< Model radius (rad)
161  double m_cosmodrad; //!< Cos of model radius
162  };
163 
164  // Kernel for circular sky region azimuth angle integration
166  public:
168  const GSkyRegionCircle* reg,
169  const double& rho,
170  const GEnergy& srcEng,
171  const GTime& srcTime) :
172  m_model(model),
173  m_reg(reg),
174  m_rho(rho),
175  m_srcEng(srcEng),
176  m_srcTime(srcTime) { }
177  double eval(const double& omega);
178  public:
179  const GModelSpatial* m_model; //!< Spatial model
180  const GSkyRegionCircle* m_reg; //!< Integration region
181  double m_rho; //!< Offset from center of the region
182  GEnergy m_srcEng; //!< Photon energy
183  GTime m_srcTime; //!< Photon time
184  };
185 
186  // Proteced members
187  std::string m_type; //!< Spatial model type
188  GSkyRegionCircle m_region; //!< Bounding circle
189  std::vector<GModelPar*> m_pars; //!< Parameter pointers
190 };
191 
192 
193 /***********************************************************************//**
194  * @brief Return model type
195  *
196  * @return Model type.
197  *
198  * Returns the type of the spatial model.
199  ***************************************************************************/
200 inline
201 std::string GModelSpatial::type(void) const
202 {
203  return (m_type);
204 }
205 
206 
207 /***********************************************************************//**
208  * @brief Set model type
209  *
210  * @param[in] type Model type.
211  *
212  * Set the type of the spatial model.
213  ***************************************************************************/
214 inline
215 void GModelSpatial::type(const std::string& type)
216 {
217  m_type = type;
218  return;
219 }
220 
221 
222 /***********************************************************************//**
223  * @brief Returns model parameter
224  *
225  * @param[in] index Parameter index [0,...,size()-1].
226  * @return Model parameter.
227  *
228  * Returns model parameter without @p index range checking.
229  ***************************************************************************/
230 inline
232 {
233  return *(m_pars[index]);
234 }
235 
236 
237 /***********************************************************************//**
238  * @brief Returns model parameter (const version)
239  *
240  * @param[in] index Parameter index [0,...,size()-1].
241  * @return Model parameter.
242  *
243  * Returns model parameter without @p index range checking.
244  ***************************************************************************/
245 inline
246 const GModelPar& GModelSpatial::operator[](const int& index) const
247 {
248  return *(m_pars[index]);
249 }
250 
251 
252 /***********************************************************************//**
253  * @brief Return number of parameters
254  *
255  * @return Number of parameters in spatial model component.
256  *
257  * Returns the number of parameters in the spatial model component.
258  ***************************************************************************/
259 inline
260 int GModelSpatial::size(void) const
261 {
262  return (int)m_pars.size();
263 }
264 
265 
266 /***********************************************************************//**
267  * @brief Return boundary sky region
268  *
269  * @return Boundary sky region.
270  *
271  * Returns a sky region that fully encloses the spatial model component.
272  ***************************************************************************/
273 inline
275 {
276  const_cast<GModelSpatial*>(this)->set_region();
277  return (&m_region);
278 }
279 
280 #endif /* GMODELSPATIAL_HPP */
double m_modrad
Model radius (rad)
virtual void read(const GXmlElement &xml)=0
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
double m_dist
Distance model-region (rad)
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.
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 circular sky region azimuth angle integration.
XML element node class.
Definition: GXmlElement.hpp:48
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
GSkyRegionCircle m_region
Bounding circle.
void copy_members(const GModelSpatial &model)
Copy class members.
double m_sindist
Sin of distance model-region.
Model parameter class interface definition.
circle_int_kern_rho(const GModelSpatial *model, const GSkyRegionCircle *reg, const GEnergy &srcEng, const GTime &srcTime, const double distance, const double cosdist, const double sindist, const double modrad, const double cosmodrad)
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 circular sky region radial integration.
Single parameter function abstract base class definition.
const GModelSpatial * m_model
Spatial model.
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.
double m_cosmodrad
Cos of model radius.
GChatter
Definition: GTypemaps.hpp:33
double m_rho
Offset from center of the region.
const GSkyRegionCircle * m_reg
Integration region.
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
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 integrated in circular sky region.
circle_int_kern_omega(const GModelSpatial *model, const GSkyRegionCircle *reg, const double &rho, const GEnergy &srcEng, const GTime &srcTime)
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.
const GSkyRegionCircle * m_reg
Integration region.
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.
double m_cosdist
Cos of distance model-region.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48