GammaLib  1.7.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-2020 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 std::string type(void) const = 0;
95  virtual GClassCode code(void) const = 0;
96  virtual double eval(const GPhoton& photon,
97  const bool& gradients = false) const = 0;
98  virtual GSkyDir mc(const GEnergy& energy, const GTime& time,
99  GRan& ran) const = 0;
100  virtual double mc_norm(const GSkyDir& dir,
101  const double& radius) const = 0;
102  virtual bool contains(const GSkyDir& dir,
103  const double& margin = 0.0) const = 0;
104  virtual void read(const GXmlElement& xml) = 0;
105  virtual void write(GXmlElement& xml) const = 0;
106  virtual GSkyRegion* region(void) const = 0;
107  virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
108 
109  // Methods
110  GModelPar& at(const int& index);
111  const GModelPar& at(const int& index) const;
112  bool has_par(const std::string& name) const;
113  bool has_free_pars(void) const;
114  int size(void) const;
115  void autoscale(void);
116  double flux(const GSkyRegion* reg,
117  const GEnergy& srcEng = GEnergy(),
118  const GTime& srcTime = GTime()) const;
119 
120 protected:
121  // Protected methods
122  void init_members(void);
123  void copy_members(const GModelSpatial& model);
124  void free_members(void);
125 
126  // Kernel for circular sky region radial integration
128  public:
130  const GSkyRegionCircle* reg,
131  const GEnergy& srcEng,
132  const GTime& srcTime,
133  const double distance,
134  const double cosdist,
135  const double sindist,
136  const double modrad,
137  const double cosmodrad) :
138  m_model(model),
139  m_reg(reg),
140  m_srcEng(srcEng),
141  m_srcTime(srcTime),
142  m_dist(distance),
143  m_cosdist(cosdist),
144  m_sindist(sindist),
145  m_modrad(modrad),
146  m_cosmodrad(cosmodrad) { }
147  double eval(const double& rho);
148  public:
149  const GModelSpatial* m_model; //!< Spatial model
150  const GSkyRegionCircle* m_reg; //!< Interation region
151  GEnergy m_srcEng; //!< Photon energy
152  GTime m_srcTime; //!< Photon time
153  double m_dist; //!< Distance model-region (rad)
154  double m_cosdist; //!< Cos of distance model-region
155  double m_sindist; //!< Sin of distance model-region
156  double m_modrad; //!< Model radius (rad)
157  double m_cosmodrad; //!< Cos of model radius
158  };
159 
160  // Kernel for circular sky region azimuth angle integration
162  public:
164  const GSkyRegionCircle* reg,
165  const double& rho,
166  const GEnergy& srcEng,
167  const GTime& srcTime) :
168  m_model(model),
169  m_reg(reg),
170  m_rho(rho),
171  m_srcEng(srcEng),
172  m_srcTime(srcTime) { }
173  double eval(const double& omega);
174  public:
175  const GModelSpatial* m_model; //!< Spatial model
176  const GSkyRegionCircle* m_reg; //!< Interation region
177  double m_rho; //!< Offset from center of the region
178  GEnergy m_srcEng; //!< Photon energy
179  GTime m_srcTime; //!< Photon time
180  };
181 
182  // Proteced members
183  std::vector<GModelPar*> m_pars; //!< Parameter pointers
184 };
185 
186 
187 /***********************************************************************//**
188  * @brief Returns model parameter
189  *
190  * @param[in] index Parameter index [0,...,size()-1].
191  * @return Model parameter.
192  *
193  * Returns model parameter without @p index range checking.
194  ***************************************************************************/
195 inline
197 {
198  return *(m_pars[index]);
199 }
200 
201 
202 /***********************************************************************//**
203  * @brief Returns model parameter (const version)
204  *
205  * @param[in] index Parameter index [0,...,size()-1].
206  * @return Model parameter.
207  *
208  * Returns model parameter without @p index range checking.
209  ***************************************************************************/
210 inline
211 const GModelPar& GModelSpatial::operator[](const int& index) const
212 {
213  return *(m_pars[index]);
214 }
215 
216 
217 /***********************************************************************//**
218  * @brief Return number of parameters
219  *
220  * @return Number of parameters in spatial model component.
221  *
222  * Returns the number of parameters in the spatial model component.
223  ***************************************************************************/
224 inline
225 int GModelSpatial::size(void) const
226 {
227  return (int)m_pars.size();
228 }
229 
230 #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)
XML element node class.
Definition: GXmlElement.hpp:47
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:54
Interface for the circular sky region class.
virtual GClassCode code(void) const =0
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 flux(const GSkyRegion *reg, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns model flux integrated in circular sky region.
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
Interation region.
Photon class definition.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
virtual std::string type(void) const =0
void free_members(void)
Delete class members.
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
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.
void init_members(void)
Initialise class members.
const GSkyRegionCircle * m_reg
Interation region.
Integration class interface definition.
Sky direction class.
Definition: GSkyDir.hpp:62
virtual GSkyRegion * region(void) const =0
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