GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialPointSource.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialPointSource.hpp - Spatial point source model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-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 GModelSpatialPointSource.hpp
23  * @brief Point source spatial model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIALPOINTSOURCE_HPP
28 #define GMODELSPATIALPOINTSOURCE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GModelSpatial.hpp"
33 #include "GModelPar.hpp"
34 #include "GSkyDir.hpp"
35 
36 /* __ Forward declarations _______________________________________________ */
37 class GEnergy;
38 class GTime;
39 class GPhoton;
40 class GRan;
41 class GSkyRegion;
42 class GXmlElement;
43 
44 
45 /***********************************************************************//**
46  * @class GModelSpatialPointSource
47  *
48  * @brief Point source spatial model
49  *
50  * This class implements a point source as the spatial component of the
51  * factorised source model. The point source has two parameters: the
52  * longitude and latitude of the point source location. The parameters may
53  * either be specified in celestial or Galactic coordinates. For celestial
54  * coordinates the parameter names are "RA" and "DEC", for Galactic
55  * coordinates the parameter names are "GLON" and "GLAT".
56  ***************************************************************************/
58 
59 public:
60  // Constructors and destructors
62  GModelSpatialPointSource(const bool& dummy, const std::string& type);
64  const std::string& coordsys = "CEL");
65  GModelSpatialPointSource(const double& lon,
66  const double& lat,
67  const std::string& coordsys = "CEL");
68  explicit GModelSpatialPointSource(const GXmlElement& xml);
70  virtual ~GModelSpatialPointSource(void);
71 
72  // Operators
74 
75  // Implemented pure virtual methods
76  virtual void clear(void);
77  virtual GModelSpatialPointSource* clone(void) const;
78  virtual std::string classname(void) const;
79  virtual GClassCode code(void) const;
80  virtual double eval(const GPhoton& photon,
81  const bool& gradients = false) const;
82  virtual GSkyDir mc(const GEnergy& energy,
83  const GTime& time,
84  GRan& ran) const;
85  virtual double mc_norm(const GSkyDir& dir,
86  const double& radius) const;
87  virtual bool contains(const GSkyDir& dir,
88  const double& margin = 0.0) const;
89  virtual void read(const GXmlElement& xml);
90  virtual void write(GXmlElement& xml) const;
91  virtual std::string print(const GChatter& chatter = NORMAL) const;
92 
93  // Overloaded base class methods
94  virtual double flux(const GSkyRegion& region,
95  const GEnergy& srcEng = GEnergy(),
96  const GTime& srcTime = GTime()) const;
97 
98  // Other methods
99  std::string coordsys(void) const;
100  const GSkyDir& dir(void) const;
101  void dir(const GSkyDir& dir);
102 
103 protected:
104  // Protected methods
105  void init_members(void);
106  void copy_members(const GModelSpatialPointSource& model);
107  void free_members(void);
108  bool is_celestial(void) const;
109  virtual void set_region(void) const;
110 
111  // Protected members
112  GModelPar m_lon; //!< Right Ascension or Galactic longitude (deg)
113  GModelPar m_lat; //!< Declination or Galactic latitude (deg)
114 
115  // Cached members for sky direction handling
116  mutable GSkyDir m_dir; //!< Sky direction representing parameters
117  mutable double m_last_lon; //!< Last longitude
118  mutable double m_last_lat; //!< Last latitude
119 };
120 
121 
122 /***********************************************************************//**
123  * @brief Return class name
124  *
125  * @return String containing the class name ("GModelSpatialPointSource").
126  ***************************************************************************/
127 inline
128 std::string GModelSpatialPointSource::classname(void) const
129 {
130  return ("GModelSpatialPointSource");
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Return class code
136  *
137  * @return GModelSpatialPointSource.
138  *
139  * Returns the code GModelSpatialPointSource of the class.
140  ***************************************************************************/
141 inline
143 {
145 }
146 
147 
148 /***********************************************************************//**
149  * @brief Return normalization of point source for Monte Carlo simulations
150  *
151  * @param[in] dir Centre of simulation cone.
152  * @param[in] radius Radius of simulation cone (degrees).
153  * @return Normalization.
154  *
155  * Returns the normalization for a point source within a circular region.
156  * The normalization is 1 if the point source falls within the circle
157  * defined by @p dir and @p radius, 0 otherwise.
158  ***************************************************************************/
159 inline
161  const double& radius) const
162 {
163  double norm = (dir.dist_deg(this->dir()) <= radius) ? 1.0 : 0.0;
164  return (norm);
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Return coordinate system
170  *
171  * @return Coordinate system of point source model.
172  *
173  * Returns "CEL" for a celestial coordinate system and "GAL" for a Galactic
174  * coordinate system.
175  ***************************************************************************/
176 inline
177 std::string GModelSpatialPointSource::coordsys(void) const
178 {
179  return (is_celestial() ? "CEL" : "GAL");
180 }
181 
182 
183 /***********************************************************************//**
184  * @brief Check if model holds celestial coordinates
185  *
186  * @return True if model holds celestial coordinates, false otherwise.
187  ***************************************************************************/
188 inline
190 {
191  return (m_lon.name() == "RA");
192 }
193 
194 #endif /* GMODELSPATIALPOINTSOURCE_HPP */
void free_members(void)
Delete class members.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Definition: GSkyDir.hpp:286
std::string coordsys(void) const
Return coordinate system.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
const std::string & name(void) const
Return parameter name.
const GSkyDir & dir(void) const
Return position of point source.
Sky direction class interface definition.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of point source for Monte Carlo simulations.
XML element node class.
Definition: GXmlElement.hpp:48
virtual GModelSpatialPointSource * clone(void) const
Clone point source model.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
Abstract spatial model base class interface definition.
Random number generator class.
Definition: GRan.hpp:44
GModelPar m_lon
Right Ascension or Galactic longitude (deg)
Time class.
Definition: GTime.hpp:55
virtual void clear(void)
Clear point source model.
void copy_members(const GModelSpatialPointSource &model)
Copy class members.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
virtual GClassCode code(void) const
Return class code.
Model parameter class.
Definition: GModelPar.hpp:87
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
virtual std::string print(const GChatter &chatter=NORMAL) const
Print point source information.
virtual ~GModelSpatialPointSource(void)
Destructor.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns model flux integrated in sky region.
virtual void read(const GXmlElement &xml)
Read model from XML element.
bool is_celestial(void) const
Check if model holds celestial coordinates.
GChatter
Definition: GTypemaps.hpp:33
std::string type(void) const
Return model type.
Point source spatial model.
const GSkyRegion * region(void) const
Return boundary sky region.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks where model contains specified sky direction.
GClassCode
Definition: GTypemaps.hpp:42
GSkyDir m_dir
Sky direction representing parameters.
GModelSpatialPointSource(void)
Void constructor.
void init_members(void)
Initialise class members.
Abstract spatial model base class.
virtual void set_region(void) const
Set boundary sky region.
virtual GModelSpatialPointSource & operator=(const GModelSpatialPointSource &model)
Assignment operator.
virtual std::string classname(void) const
Return class name.
Sky direction class.
Definition: GSkyDir.hpp:62
GModelPar m_lat
Declination or Galactic latitude (deg)
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48