GammaLib  2.0.0
 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-2021 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 double eval(const GPhoton& photon,
74  const bool& gradients = false) const;
75  virtual GSkyDir mc(const GEnergy& energy,
76  const GTime& time,
77  GRan& ran) const;
78  virtual double mc_norm(const GSkyDir& dir,
79  const double& radius) const;
80  virtual bool contains(const GSkyDir& dir,
81  const double& margin = 0.0) const;
82  virtual void read(const GXmlElement& xml);
83  virtual void write(GXmlElement& xml) const;
84  virtual std::string print(const GChatter& chatter = NORMAL) const;
85 
86  // Overloaded base class methods
87  virtual double flux(const GSkyRegion& region,
88  const GEnergy& srcEng = GEnergy(),
89  const GTime& srcTime = GTime()) const;
90 
91  // Other methods
92  double value(void) const;
93  void value(const double& value);
94  const GFilename& filename(void) const;
95  void load(const GFilename& filename);
96  const GSkyMap& map(void) const;
97  void map(const GSkyMap& map);
98  bool normalize(void) const;
99  void mc_cone(const GSkyRegionCircle& cone) const;
100  const GSkyRegionCircle& mc_cone(void) const;
101 
102 protected:
103  // Protected methods
104  void init_members(void);
105  void copy_members(const GModelSpatialDiffuseMap& model);
106  void free_members(void);
107  void prepare_map(void);
108  virtual void set_region(void) const;
109 
110  // Protected members
111  GModelPar m_value; //!< Value
112  GSkyMap m_map; //!< Skymap
113  GFilename m_filename; //!< Name of skymap
114  bool m_normalize; //!< Normalize map (default: true)
115  bool m_has_normalize; //!< XML has normalize attribute
116 
117  // MC simulation cache
118  mutable GSkyRegionCircle m_mc_cone; //!< MC cone
119  mutable double m_mc_one_minus_cosrad; //!< 1-cosine of radius
120  mutable double m_mc_norm; //!< Map normalization
121  mutable double m_mc_max; //!< Map maximum for MC
122 };
123 
124 
125 /***********************************************************************//**
126  * @brief Return class name
127  *
128  * @return String containing the class name ("GModelSpatialDiffuseMap").
129  ***************************************************************************/
130 inline
131 std::string GModelSpatialDiffuseMap::classname(void) const
132 {
133  return ("GModelSpatialDiffuseMap");
134 }
135 
136 
137 /***********************************************************************//**
138  * @brief Get model value
139  *
140  * @return Model value.
141  *
142  * Returns the value of the spatial map model.
143  ***************************************************************************/
144 inline
146 {
147  return (m_value.value());
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Set model value
153  *
154  * @param[in] value Model value.
155  *
156  * Set the value of the spatial map model.
157  ***************************************************************************/
158 inline
159 void GModelSpatialDiffuseMap::value(const double& value)
160 {
161  m_value.value(value);
162  return;
163 }
164 
165 
166 /***********************************************************************//**
167  * @brief Get file name
168  *
169  * @return File name.
170  *
171  * Returns the file name of the spatial map model.
172  ***************************************************************************/
173 inline
175 {
176  return (m_filename);
177 }
178 
179 
180 /***********************************************************************//**
181  * @brief Get map
182  *
183  * @return Sky map.
184  *
185  * Returns the sky map.
186  ***************************************************************************/
187 inline
189 {
190  return (m_map);
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Set map cube
196  *
197  * @param[in] map Sky map.
198  *
199  * Set the sky map.
200  ***************************************************************************/
201 inline
203 {
204  m_map = map;
205  prepare_map();
206  return;
207 }
208 
209 
210 /***********************************************************************//**
211  * @brief Return normalization flag
212  *
213  * @return True if the map has been normalized, false otherwise.
214  *
215  * Signals whether a map has been normalized or not.
216  ***************************************************************************/
217 inline
219 {
220  return (m_normalize);
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Get Monte Carlo simulation cone
226  *
227  * @return Monte Carlo simulation sky region circle.
228  *
229  * Returns the sky region circle used for Monte Carlo simulations.
230  ***************************************************************************/
231 inline
233 {
234  return (m_mc_cone);
235 }
236 
237 #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.
virtual 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.
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:48
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
double m_mc_max
Map maximum for MC.
Interface for the circular sky region class.
Sky map class definition.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GModelSpatialDiffuseMap(void)
Void constructor.
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.
const GFilename & filename(void) const
Get file name.
GChatter
Definition: GTypemaps.hpp:33
std::string type(void) const
Return model type.
const GSkyRegionCircle & mc_cone(void) const
Get Monte Carlo simulation cone.
Abstract diffuse spatial model base class interface definition.
virtual ~GModelSpatialDiffuseMap(void)
Destructor.
void free_members(void)
Delete class members.
const GSkyRegion * region(void) const
Return boundary sky region.
bool m_has_normalize
XML has normalize attribute.
double value(void) const
Return parameter value.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns diffuse map flux integrated in sky region.
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.
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.
GSkyRegionCircle m_mc_cone
MC cone.