GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialRadial.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialRadial.hpp - Abstract radial spatial model base class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-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 GModelSpatialRadial.hpp
23  * @brief Abstract radial spatial model base class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIALRADIAL_HPP
28 #define GMODELSPATIALRADIAL_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 GModelSpatialRadial
48  *
49  * @brief Abstract radial spatial model base class
50  *
51  * This class defines the interface for a radial model as spatial component
52  * of the factorized source model. Typical examples of radial components are
53  * axisymmetric Disk, Gaussian or Shell sources.
54  ***************************************************************************/
56 
57 public:
58  // Constructors and destructors
59  GModelSpatialRadial(void);
61  explicit GModelSpatialRadial(const GXmlElement& xml);
62  virtual ~GModelSpatialRadial(void);
63 
64  // Operators
65  virtual GModelSpatialRadial& operator=(const GModelSpatialRadial& model);
66 
67  // Pure virtual methods
68  virtual void clear(void) = 0;
69  virtual GModelSpatialRadial* clone(void) const = 0;
70  virtual std::string classname(void) const = 0;
71  virtual double eval(const double& theta,
72  const GEnergy& energy,
73  const GTime& time,
74  const bool& gradients = false) const = 0;
75  virtual GSkyDir mc(const GEnergy& energy,
76  const GTime& time,
77  GRan& ran) const = 0;
78  virtual bool contains(const GSkyDir& dir,
79  const double& margin = 0.0) const = 0;
80  virtual double theta_max(void) const = 0;
81  virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
82 
83  // Implemented pure virtual base class methods
84  virtual GClassCode code(void) const;
85  virtual bool is_energy_dependent(void) const;
86  virtual bool is_time_dependent(void) const;
87  virtual double eval(const GPhoton& photon,
88  const bool& gradients = false) const;
89  virtual double mc_norm(const GSkyDir& dir, const double& radius) const;
90  virtual void read(const GXmlElement& xml);
91  virtual void write(GXmlElement& xml) const;
92 
93  // Other methods
94  std::string coordsys(void) const;
95  const GSkyDir& dir(void) const;
96  void dir(const GSkyDir& dir);
97 
98 protected:
99  // Protected methods
100  void init_members(void);
101  void copy_members(const GModelSpatialRadial& model);
102  void free_members(void);
103  bool is_celestial(void) const;
104  virtual void set_region(void) const = 0;
105 
106  // Protected members
107  GModelPar m_lon; //!< Right Ascension or Galactic longitude (deg)
108  GModelPar m_lat; //!< Declination or Galactic latitude (deg)
109 
110  // Cached members for sky direction handling
111  mutable GSkyDir m_dir; //!< Sky direction representing parameters
112  mutable double m_last_lon; //!< Last longitude
113  mutable double m_last_lat; //!< Last latitude
114 };
115 
116 
117 /***********************************************************************//**
118  * @brief Return class code
119  *
120  * @return GModelSpatialRadial.
121  *
122  * Returns the code GModelSpatialRadial of the class.
123  ***************************************************************************/
124 inline
126 {
127  return GMODEL_SPATIAL_RADIAL;
128 }
129 
130 
131 /***********************************************************************//**
132  * @brief Signals whether radial model is energy dependent
133  *
134  * @return True if radial model is energy dependent, false otherwise.
135  *
136  * Signals whether the radial model is energy dependent. This method always
137  * returns false.
138  ***************************************************************************/
139 inline
141 {
142  return (false);
143 }
144 
145 
146 /***********************************************************************//**
147  * @brief Signals whether radial model is time dependent
148  *
149  * @return True if radial model is time dependent, false otherwise.
150  *
151  * Signals whether the radial model is time dependent. This method always
152  * returns false.
153  ***************************************************************************/
154 inline
156 {
157  return (false);
158 }
159 
160 
161 /***********************************************************************//**
162  * @brief Return normalization of radial source for Monte Carlo simulations
163  *
164  * @param[in] dir Centre of simulation cone.
165  * @param[in] radius Radius of simulation cone (degrees).
166  * @return Normalization.
167  *
168  * Returns the normalization for a radial source within a circular region.
169  * The normalization is 1 if the radial source falls within the circle
170  * defined by @p dir and @p radius, 0 otherwise.
171  ***************************************************************************/
172 inline
174  const double& radius) const
175 {
176  double norm = (dir.dist_deg(this->dir()) <= radius+theta_max()) ? 1.0 : 0.0;
177  return (norm);
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Return coordinate system
183  *
184  * @return Coordinate system of point source model.
185  *
186  * Returns "CEL" for a celestial coordinate system and "GAL" for a Galactic
187  * coordinate system.
188  ***************************************************************************/
189 inline
190 std::string GModelSpatialRadial::coordsys(void) const
191 {
192  return (is_celestial() ? "CEL" : "GAL");
193 }
194 
195 
196 /***********************************************************************//**
197  * @brief Check if model holds celestial coordinates
198  *
199  * @return True if model holds celestial coordinates, false otherwise.
200  ***************************************************************************/
201 inline
203 {
204  return (m_lon.name() == "RA");
205 }
206 
207 #endif /* GMODELSPATIALRADIAL_HPP */
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Definition: GSkyDir.hpp:286
virtual void set_region(void) const =0
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
double m_last_lon
Last longitude.
const std::string & name(void) const
Return parameter name.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of radial source for Monte Carlo simulations.
Sky direction class interface definition.
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
virtual GClassCode code(void) const
Return class code.
void copy_members(const GModelSpatialRadial &model)
Copy class members.
XML element node class.
Definition: GXmlElement.hpp:48
std::string coordsys(void) const
Return coordinate system.
Abstract spatial model base class interface definition.
Random number generator class.
Definition: GRan.hpp:44
GModelSpatialRadial(void)
Void constructor.
Time class.
Definition: GTime.hpp:55
virtual bool is_time_dependent(void) const
Signals whether radial model is time dependent.
virtual GModelSpatialRadial * clone(void) const =0
Clones object.
virtual void clear(void)=0
Clear object.
void init_members(void)
Initialise class members.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
Model parameter class.
Definition: GModelPar.hpp:87
virtual ~GModelSpatialRadial(void)
Destructor.
virtual double eval(const double &theta, const GEnergy &energy, const GTime &time, const bool &gradients=false) const =0
GSkyDir m_dir
Sky direction representing parameters.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
const GSkyDir & dir(void) const
Return position of radial spatial model.
void free_members(void)
Delete class members.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
double m_last_lat
Last latitude.
GChatter
Definition: GTypemaps.hpp:33
virtual bool is_energy_dependent(void) const
Signals whether radial model is energy dependent.
bool is_celestial(void) const
Check if model holds celestial coordinates.
virtual std::string classname(void) const =0
Return class name.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelSpatialRadial & operator=(const GModelSpatialRadial &model)
Assignment operator.
GModelPar m_lat
Declination or Galactic latitude (deg)
GClassCode
Definition: GTypemaps.hpp:42
GModelPar m_lon
Right Ascension or Galactic longitude (deg)
virtual double theta_max(void) const =0
Abstract spatial model base class.
Abstract radial spatial model base class.
Sky direction class.
Definition: GSkyDir.hpp:62
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48