GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialDiffuseMap.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialDiffuseMap.hpp - Spatial map model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-2016 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 GModelSpatialDiffuseMap.hpp
23  * @brief Spatial map model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIALDIFFUSEMAP_HPP
28 #define GMODELSPATIALDIFFUSEMAP_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GModelSpatialDiffuse.hpp"
34 #include "GModelPar.hpp"
35 #include "GSkyDir.hpp"
36 #include "GSkyMap.hpp"
37 #include "GSkyRegionCircle.hpp"
38 #include "GXmlElement.hpp"
39 #include "GFilename.hpp"
40 
41 
42 /***********************************************************************//**
43  * @class GModelSpatialDiffuseMap
44  *
45  * @brief Spatial map model
46  *
47  * This class implements the spatial component of the factorised source
48  * model for a skymap.
49  ***************************************************************************/
51 
52 public:
53  // Constructors and destructors
55  GModelSpatialDiffuseMap(const bool& dummy, const std::string& type);
56  explicit GModelSpatialDiffuseMap(const GXmlElement& xml);
58  const double& value = 1.0,
59  const bool& normalize = true);
61  const double& value = 1.0,
62  const bool& normalize = true);
64  virtual ~GModelSpatialDiffuseMap(void);
65 
66  // Operators
68 
69  // Implemented pure virtual methods
70  virtual void clear(void);
71  virtual GModelSpatialDiffuseMap* clone(void) const;
72  virtual std::string classname(void) const;
73  virtual std::string type(void) const;
74  virtual double eval(const GPhoton& photon,
75  const bool& gradients = false) const;
76  virtual GSkyDir mc(const GEnergy& energy,
77  const GTime& time,
78  GRan& ran) const;
79  virtual double mc_norm(const GSkyDir& dir,
80  const double& radius) const;
81  virtual bool contains(const GSkyDir& dir,
82  const double& margin = 0.0) const;
83  virtual GSkyRegion* region(void) const;
84  virtual void read(const GXmlElement& xml);
85  virtual void write(GXmlElement& xml) const;
86  virtual std::string print(const GChatter& chatter = NORMAL) const;
87 
88  // Other methods
89  double value(void) const;
90  void value(const double& value);
91  const GFilename& filename(void) const;
92  void load(const GFilename& filename);
93  const GSkyMap& map(void) const;
94  void map(const GSkyMap& map);
95  bool normalize(void) const;
96  void set_mc_cone(const GSkyDir& centre,
97  const double& radius) const;
98 
99 protected:
100  // Protected methods
101  void init_members(void);
102  void copy_members(const GModelSpatialDiffuseMap& model);
103  void free_members(void);
104  void prepare_map(void);
105  void set_region(void) const;
106 
107  // Protected members
108  std::string m_type; //!< Model type
109  GModelPar m_value; //!< Value
110  GSkyMap m_map; //!< Skymap
111  GFilename m_filename; //!< Name of skymap
112  GSkyDir m_centre; //!< Centre of bounding circle
113  double m_radius; //!< Radius of bounding circle
114  bool m_normalize; //!< Normalize map (default: true)
115  bool m_has_normalize; //!< XML has normalize attribute
116  mutable GSkyRegionCircle m_region; //!< Bounding circle
117 
118  // MC simulation cache
119  mutable GSkyDir m_mc_centre; //!< Centre of MC cone
120  mutable double m_mc_radius; //!< Radius of MC cone
121  mutable double m_mc_one_minus_cosrad; //!< 1-cosine of radius
122  mutable double m_mc_norm; //!< Map normalization
123  mutable double m_mc_max; //!< Map maximum for MC
124 };
125 
126 
127 /***********************************************************************//**
128  * @brief Return class name
129  *
130  * @return String containing the class name ("GModelSpatialDiffuseMap").
131  ***************************************************************************/
132 inline
133 std::string GModelSpatialDiffuseMap::classname(void) const
134 {
135  return ("GModelSpatialDiffuseMap");
136 }
137 
138 
139 /***********************************************************************//**
140  * @brief Return spatial model type
141  *
142  * @return Model type.
143  *
144  * Returns the type of the spatial map model.
145  ***************************************************************************/
146 inline
147 std::string GModelSpatialDiffuseMap::type(void) const
148 {
149  return (m_type);
150 }
151 
152 
153 /***********************************************************************//**
154  * @brief Get model value
155  *
156  * @return Model value.
157  *
158  * Returns the value of the spatial map model.
159  ***************************************************************************/
160 inline
162 {
163  return (m_value.value());
164 }
165 
166 
167 /***********************************************************************//**
168  * @brief Set model value
169  *
170  * @param[in] value Model value.
171  *
172  * Set the value of the spatial map model.
173  ***************************************************************************/
174 inline
175 void GModelSpatialDiffuseMap::value(const double& value)
176 {
177  m_value.value(value);
178  return;
179 }
180 
181 
182 /***********************************************************************//**
183  * @brief Get file name
184  *
185  * @return File name.
186  *
187  * Returns the file name of the spatial map model.
188  ***************************************************************************/
189 inline
191 {
192  return (m_filename);
193 }
194 
195 
196 /***********************************************************************//**
197  * @brief Get map
198  *
199  * @return Sky map.
200  *
201  * Returns the sky map.
202  ***************************************************************************/
203 inline
205 {
206  return (m_map);
207 }
208 
209 
210 /***********************************************************************//**
211  * @brief Set map cube
212  *
213  * @param[in] map Sky map.
214  *
215  * Set the sky map.
216  ***************************************************************************/
217 inline
219 {
220  m_map = map;
221  prepare_map();
222  return;
223 }
224 
225 
226 /***********************************************************************//**
227  * @brief Return normalization flag
228  *
229  * @return True if the map has been normalized, false otherwise.
230  *
231  * Signals whether a map has been normalized or not.
232  ***************************************************************************/
233 inline
235 {
236  return (m_normalize);
237 }
238 
239 
240 /***********************************************************************//**
241  * @brief Return boundary sky region
242  *
243  * @return Boundary sky region.
244  *
245  * Returns a sky region that fully encloses the point source.
246  ***************************************************************************/
247 inline
249 {
250  set_region();
251  return (&m_region);
252 }
253 
254 #endif /* GMODELSPATIALDIFFUSEMAP_HPP */
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Return intensity of sky map.
bool m_normalize
Normalize map (default: true)
Sky map class.
Definition: GSkyMap.hpp:89
bool normalize(void) const
Return normalization flag.
double m_mc_one_minus_cosrad
1-cosine of radius
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of diffuse map for Monte Carlo simulations.
std::string m_type
Model type.
void set_region(void) const
Set boundary sky region.
void load(const GFilename &filename)
Load skymap into the model class.
double value(void) const
Get model value.
XML element node class interface definition.
Sky direction class interface definition.
GSkyRegionCircle m_region
Bounding circle.
const GSkyMap & map(void) const
Get map.
virtual GModelSpatialDiffuseMap * clone(void) const
Clone spatial map model.
void prepare_map(void)
Prepare sky map after loading.
virtual void clear(void)
Clear spatial map model.
XML element node class.
Definition: GXmlElement.hpp:47
Random number generator class.
Definition: GRan.hpp:44
double m_mc_radius
Radius of MC cone.
Time class.
Definition: GTime.hpp:54
double m_mc_max
Map maximum for MC.
Interface for the circular sky region class.
Sky map class definition.
std::string centre(const std::string &s, const int &n, const char &c= ' ')
Centre string to achieve a length of n characters.
Definition: GTools.cpp:997
virtual void write(GXmlElement &xml) const
Write model into XML element.
GModelSpatialDiffuseMap(void)
Void constructor.
void set_mc_cone(const GSkyDir &centre, const double &radius) const
Set Monte Carlo simulation cone.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
double m_mc_norm
Map normalization.
void init_members(void)
Initialise class members.
Model parameter class.
Definition: GModelPar.hpp:87
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
Filename class.
Definition: GFilename.hpp:62
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
virtual GSkyRegion * region(void) const
Return boundary sky region.
virtual std::string type(void) const
Return spatial model type.
const GFilename & filename(void) const
Get file name.
GChatter
Definition: GTypemaps.hpp:33
double m_radius
Radius of bounding circle.
Abstract diffuse spatial model base class interface definition.
virtual ~GModelSpatialDiffuseMap(void)
Destructor.
GSkyDir m_centre
Centre of bounding circle.
void free_members(void)
Delete class members.
bool m_has_normalize
XML has normalize attribute.
double value(void) const
Return parameter value.
virtual std::string classname(void) const
Return class name.
Abstract diffuse spatial model base class.
void copy_members(const GModelSpatialDiffuseMap &model)
Copy class members.
GFilename m_filename
Name of skymap.
Sky direction class.
Definition: GSkyDir.hpp:62
virtual GModelSpatialDiffuseMap & operator=(const GModelSpatialDiffuseMap &model)
Assignment operator.
Circular sky region class interface definition.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print map information.
Filename class interface definition.
GSkyDir m_mc_centre
Centre of MC cone.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Signals whether model contains sky direction.