GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialElliptical.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialElliptical.hpp - Abstract elliptical spatial model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2022 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 GModelSpatialElliptical.hpp
23  * @brief Abstract elliptical spatial model base class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIALELLIPTICAL_HPP
28 #define GMODELSPATIALELLIPTICAL_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GModelSpatial.hpp"
34 #include "GModelPar.hpp"
35 #include "GSkyDir.hpp"
36 
37 /* __ Forward declarations _______________________________________________ */
38 class GEnergy;
39 class GTime;
40 class GPhoton;
41 class GRan;
42 class GSkyRegion;
43 class GXmlElement;
44 
45 
46 /***********************************************************************//**
47  * @class GModelSpatialElliptical
48  *
49  * @brief Abstract elliptical spatial model base class
50  *
51  * This class defines the interface for an elliptical model as spatial
52  * component of the factorized source model. Typical examples of elliptical
53  * components are elliptical Disk, Gaussian or Shell shaped sources.
54  ***************************************************************************/
56 
57 public:
58  // Constructors and destructors
61  explicit GModelSpatialElliptical(const GXmlElement& xml);
62  virtual ~GModelSpatialElliptical(void);
63 
64  // Operators
66 
67  // Pure virtual methods
68  virtual void clear(void) = 0;
69  virtual GModelSpatialElliptical* clone(void) const = 0;
70  virtual std::string classname(void) const = 0;
71  virtual double eval(const double& theta,
72  const double& posangle,
73  const GEnergy& energy,
74  const GTime& time,
75  const bool& gradients = false) const = 0;
76  virtual GSkyDir mc(const GEnergy& energy,
77  const GTime& time,
78  GRan& ran) const = 0;
79  virtual bool contains(const GSkyDir& dir,
80  const double& margin = 0.0) const = 0;
81  virtual double theta_max(void) const = 0;
82  virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
83 
84  // Implemented virtual base class methods
85  virtual GClassCode code(void) const;
86  virtual double eval(const GPhoton& photon,
87  const bool& gradients = false) const;
88  virtual double mc_norm(const GSkyDir& dir, const double& radius) const;
89  virtual void read(const GXmlElement& xml);
90  virtual void write(GXmlElement& xml) const;
91 
92  // Other methods
93  std::string coordsys(void) const;
94  const GSkyDir& dir(void) const;
95  void dir(const GSkyDir& dir);
96  double posangle(void) const;
97  void posangle(const double& posangle);
98  double semiminor(void) const;
99  double semimajor(void) const;
100  void semiminor(const double& semiminor);
101  void semimajor(const double& semimajor);
102 
103 protected:
104  // Protected methods
105  void init_members(void);
106  void copy_members(const GModelSpatialElliptical& model);
107  void free_members(void);
108  bool is_celestial(void) const;
109  virtual void set_region(void) const = 0;
110 
111  // Protected members
112  GModelPar m_lon; //!< Right Ascension or Galactic longitude (deg)
113  GModelPar m_lat; //!< Declination or Galactic latitude (deg)
114  GModelPar m_posangle; //!< Position angle from North, counterclockwise (deg)
115  GModelPar m_semiminor; //!< Semi-minor axis of ellipse (deg)
116  GModelPar m_semimajor; //!< Semi-major axis of ellipse (deg)
117 
118  // Cached members for sky direction handling
119  mutable GSkyDir m_dir; //!< Sky direction representing parameters
120  mutable double m_last_lon; //!< Last longitude
121  mutable double m_last_lat; //!< Last latitude
122 };
123 
124 
125 /***********************************************************************//**
126  * @brief Return class code
127  *
128  * @return GModelSpatialElliptical.
129  *
130  * Returns the code GModelSpatialElliptical of the class.
131  ***************************************************************************/
132 inline
134 {
136 }
137 
138 
139 /***********************************************************************//**
140  * @brief Return Position Angle of model
141  *
142  * @return Position Angle of model (degrees).
143  *
144  * Returns the Position Angle of model in degrees, measured counterclockwise
145  * from celestial North.
146  ***************************************************************************/
147 inline
149 {
150  return (m_posangle.value());
151 }
152 
153 
154 /***********************************************************************//**
155  * @brief Set Position Angle of model
156  *
157  * @param[in] posangle Position Angle of model (degrees).
158  *
159  * Sets the Position Angle of model in degrees, measured counterclockwise
160  * from celestial North.
161  ***************************************************************************/
162 inline
163 void GModelSpatialElliptical::posangle(const double& posangle)
164 {
165  m_posangle.value(posangle);
166  return;
167 }
168 
169 
170 /***********************************************************************//**
171  * @brief Return semi-minor axis of ellipse
172  *
173  * @return Semi-minor axis of ellipse (degrees).
174  *
175  * Returns the semi-minor axis of the ellipse in degrees.
176  ***************************************************************************/
177 inline
179 {
180  return (m_semiminor.value());
181 }
182 
183 
184 /***********************************************************************//**
185  * @brief Set semi-minor axis of ellipse
186  *
187  * @param[in] semiminor Semi-minor axis of ellipse (degrees)
188  *
189  * Sets the semi-minor axis of the ellipse in degrees.
190  ***************************************************************************/
191 inline
192 void GModelSpatialElliptical::semiminor(const double& semiminor)
193 {
194  m_semiminor.value(semiminor);
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Return semi-major axis of ellipse
201  *
202  * @return Semi-major axis of ellipse (degrees).
203  *
204  * Returns the semi-major axis of the ellipse in degrees.
205  ***************************************************************************/
206 inline
208 {
209  return (m_semimajor.value());
210 }
211 
212 
213 /***********************************************************************//**
214  * @brief Set semi-major axis of ellipse
215  *
216  * @param[in] semimajor Semi-major axis of ellipse (degrees)
217  *
218  * Sets the semi-major axis of the ellipse in degrees.
219  ***************************************************************************/
220 inline
221 void GModelSpatialElliptical::semimajor(const double& semimajor)
222 {
223  m_semimajor.value(semimajor);
224  return;
225 }
226 
227 
228 /***********************************************************************//**
229  * @brief Return normalization of elliptical source for Monte Carlo
230  * simulations
231  *
232  * @param[in] dir Centre of simulation cone.
233  * @param[in] radius Radius of simulation cone (degrees).
234  * @return Normalization.
235  *
236  * Returns the normalization for an elliptical source within a circular
237  * region. The normalization is 1 if the elliptical source falls within
238  * the circle define by @p dir and @p radius, 0 otherwise.
239  ***************************************************************************/
240 inline
242  const double& radius) const
243 {
244  double norm = (dir.dist_deg(this->dir()) <= radius+theta_max()) ? 1.0 : 0.0;
245  return (norm);
246 }
247 
248 
249 /***********************************************************************//**
250  * @brief Return coordinate system
251  *
252  * @return Coordinate system of point source model.
253  *
254  * Returns "CEL" for a celestial coordinate system and "GAL" for a Galactic
255  * coordinate system.
256  ***************************************************************************/
257 inline
258 std::string GModelSpatialElliptical::coordsys(void) const
259 {
260  return (is_celestial() ? "CEL" : "GAL");
261 }
262 
263 
264 /***********************************************************************//**
265  * @brief Check if model holds celestial coordinates
266  *
267  * @return True if model holds celestial coordinates, false otherwise.
268  ***************************************************************************/
269 inline
271 {
272  return (m_lon.name() == "RA");
273 }
274 
275 #endif /* GMODELSPATIALELLIPTICAL_HPP */
GModelPar m_semimajor
Semi-major axis of ellipse (deg)
virtual void write(GXmlElement &xml) const
Write model into XML element.
void free_members(void)
Delete class members.
virtual std::string classname(void) const =0
Return class name.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Definition: GSkyDir.hpp:286
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
Abstract elliptical spatial model base class.
const std::string & name(void) const
Return parameter name.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
GModelPar m_lon
Right Ascension or Galactic longitude (deg)
double m_last_lat
Last latitude.
double m_last_lon
Last longitude.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of elliptical source for Monte Carlo simulations.
Sky direction class interface definition.
virtual GModelSpatialElliptical & operator=(const GModelSpatialElliptical &model)
Assignment operator.
XML element node class.
Definition: GXmlElement.hpp:48
virtual void set_region(void) const =0
const GSkyDir & dir(void) const
Return position of elliptical spatial model.
Abstract spatial model base class interface definition.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
GModelPar m_posangle
Position angle from North, counterclockwise (deg)
void init_members(void)
Initialise class members.
virtual double theta_max(void) const =0
virtual GClassCode code(void) const
Return class code.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
Model parameter class.
Definition: GModelPar.hpp:87
GModelSpatialElliptical(void)
Void constructor.
double semiminor(void) const
Return semi-minor axis of ellipse.
virtual ~GModelSpatialElliptical(void)
Destructor.
bool is_celestial(void) const
Check if model holds celestial coordinates.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
void copy_members(const GModelSpatialElliptical &model)
Copy class members.
GChatter
Definition: GTypemaps.hpp:33
std::string coordsys(void) const
Return coordinate system.
virtual void read(const GXmlElement &xml)
Read model from XML element.
GModelPar m_semiminor
Semi-minor axis of ellipse (deg)
virtual void clear(void)=0
Clear object.
double posangle(void) const
Return Position Angle of model.
GClassCode
Definition: GTypemaps.hpp:42
double value(void) const
Return parameter value.
GModelPar m_lat
Declination or Galactic latitude (deg)
GSkyDir m_dir
Sky direction representing parameters.
Abstract spatial model base class.
virtual GModelSpatialElliptical * clone(void) const =0
Clones object.
virtual double eval(const double &theta, const double &posangle, const GEnergy &energy, const GTime &time, const bool &gradients=false) const =0
Sky direction class.
Definition: GSkyDir.hpp:62
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
double semimajor(void) const
Return semi-major axis of ellipse.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48