GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialDiffuseCube.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialDiffuseCube.hpp - Spatial map cube model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2018 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 GModelSpatialDiffuseCube.hpp
23  * @brief Spatial map cube model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELSPATIALDIFFUSECUBE_HPP
28 #define GMODELSPATIALDIFFUSECUBE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GModelSpatialDiffuse.hpp"
33 #include "GModelSpectral.hpp"
34 #include "GModelSpectralNodes.hpp"
35 #include "GModelPar.hpp"
36 #include "GSkyDir.hpp"
37 #include "GSkyMap.hpp"
38 #include "GSkyRegionCircle.hpp"
39 #include "GNodeArray.hpp"
40 #include "GEbounds.hpp"
41 #include "GFilename.hpp"
42 
43 /* __ Forward declarations _______________________________________________ */
44 class GFits;
45 class GEnergies;
46 class GXmlElement;
47 
48 
49 /***********************************************************************//**
50  * @class GModelSpatialDiffuseCube
51  *
52  * @brief Spatial map cube model
53  *
54  * This class implements the spatial component of the factorised source
55  * model for a map cube. A map cube is a set of sky maps for different
56  * energies. It is assumed that the pixels of the sky map are given in the
57  * units ph/cm2/s/sr/MeV.
58  ***************************************************************************/
60 
61 public:
62  // Constructors and destructors
64  GModelSpatialDiffuseCube(const bool& dummy, const std::string& type);
65  explicit GModelSpatialDiffuseCube(const GXmlElement& xml);
67  const double& value = 1.0);
69  const GEnergies& energies,
70  const double& value = 1.0);
72  virtual ~GModelSpatialDiffuseCube(void);
73 
74  // Operators
76 
77  // Implemented pure virtual methods
78  virtual void clear(void);
79  virtual GModelSpatialDiffuseCube* clone(void) const;
80  virtual std::string classname(void) const;
81  virtual std::string type(void) const;
82  virtual double eval(const GPhoton& photon,
83  const bool& gradients = false) const;
84  virtual GSkyDir mc(const GEnergy& energy,
85  const GTime& time,
86  GRan& ran) const;
87  virtual double mc_norm(const GSkyDir& dir,
88  const double& radius) const;
89  virtual bool contains(const GSkyDir& dir,
90  const double& margin = 0.0) const;
91  virtual GSkyRegion* region(void) const;
92  virtual void read(const GXmlElement& xml);
93  virtual void write(GXmlElement& xml) const;
94  virtual std::string print(const GChatter& chatter = NORMAL) const;
95 
96  // Other methods
97  int maps(void) const;
98  int pixels(void) const;
99  double value(void) const;
100  void value(const double& value);
101  const GFilename& filename(void) const;
102  void filename(const GFilename& filename);
103  const GSkyMap& cube(void) const;
104  void cube(const GSkyMap& cube);
105  GEnergies energies(void);
106  void energies(const GEnergies& energies);
107  const GModelSpectralNodes& spectrum(void) const;
108  void set_mc_cone(const GSkyDir& centre,
109  const double& radius) const;
110  void load(const GFilename& filename);
111  void save(const GFilename& filename,
112  const bool& clobber = false) const;
113  void read(const GFits& fits);
114  void write(GFits& fits) const;
115 
116 protected:
117  // Protected methods
118  void init_members(void);
119  void copy_members(const GModelSpatialDiffuseCube& model);
120  void free_members(void);
121  void fetch_cube(void) const;
122  void load_cube(const GFilename& filename);
123  void set_energy_boundaries(void);
124  void update_mc_cache(void);
125  double cube_intensity(const GPhoton& photon) const;
126  void set_region(void) const;
127 
128  // Protected members
129  std::string m_type; //!< Model type
130  GModelPar m_value; //!< Value
131  GFilename m_filename; //!< Name of map cube
132  bool m_loaded; //!< Signals if map cube has been loaded
133  GSkyMap m_cube; //!< Map cube
134  GNodeArray m_logE; //!< Log10(energy) values of the maps
135  GEbounds m_ebounds; //!< Energy bounds of the maps
136  mutable GSkyRegionCircle m_region; //!< Bounding circle
137 
138  // Monte Carlo cache
139  mutable GSkyDir m_mc_centre; //!< Centre of MC cone
140  mutable double m_mc_radius; //!< Radius of MC cone (degrees)
141  mutable double m_mc_one_minus_cosrad; //!< 1-cosine of radius
142  mutable std::vector<double> m_mc_max; //!< Maximum values for MC
143  mutable GModelSpectralNodes m_mc_spectrum; //!< Map cube spectrum
144 };
145 
146 
147 /***********************************************************************//**
148  * @brief Return class name
149  *
150  * @return String containing the class name ("GModelSpatialDiffuseCube").
151  ***************************************************************************/
152 inline
153 std::string GModelSpatialDiffuseCube::classname(void) const
154 {
155  return ("GModelSpatialDiffuseCube");
156 }
157 
158 
159 /***********************************************************************//**
160  * @brief Return spatial model type
161  *
162  * @return Model type.
163  *
164  * Returns the type of the spatial map cube model.
165  ***************************************************************************/
166 inline
167 std::string GModelSpatialDiffuseCube::type(void) const
168 {
169  return (m_type);
170 }
171 
172 
173 /***********************************************************************//**
174  * @brief Return number of maps in cube
175  *
176  * @return Number of maps in cube.
177  *
178  * Returns the number of maps in the cube.
179  ***************************************************************************/
180 inline
182 {
183  return (m_cube.nmaps());
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Return number of pixels in cube
189  *
190  * @return Number of pixels in cube.
191  *
192  * Returns the number of pixels in the cube.
193  ***************************************************************************/
194 inline
196 {
197  return (m_cube.npix());
198 }
199 
200 
201 /***********************************************************************//**
202  * @brief Get model value
203  *
204  * @return Model value.
205  *
206  * Returns the value of the spatial map cube model.
207  ***************************************************************************/
208 inline
210 {
211  return (m_value.value());
212 }
213 
214 
215 /***********************************************************************//**
216  * @brief Set model value
217  *
218  * @param[in] value Model value.
219  *
220  * Set the value of the spatial map cube model.
221  ***************************************************************************/
222 inline
223 void GModelSpatialDiffuseCube::value(const double& value)
224 {
225  m_value.value(value);
226  return;
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Get file name
232  *
233  * @return File name.
234  *
235  * Returns the file name of the spatial map cube model.
236  ***************************************************************************/
237 inline
239 {
240  return (m_filename);
241 }
242 
243 
244 /***********************************************************************//**
245  * @brief Set file name
246  *
247  * @param[in] filename File name.
248  *
249  * Set the file name of the spatial map cube model.
250  ***************************************************************************/
251 inline
253 {
255  return;
256 }
257 
258 
259 /***********************************************************************//**
260  * @brief Get map cube
261  *
262  * @return Map cube.
263  *
264  * Returns the map cube.
265  ***************************************************************************/
266 inline
268 {
269  return (m_cube);
270 }
271 
272 
273 /***********************************************************************//**
274  * @brief Get map cube spectrum
275  *
276  * @return Map cube spectrum.
277  *
278  * Returns the map cube spectrum.
279  ***************************************************************************/
280 inline
282 {
283  return (m_mc_spectrum);
284 }
285 
286 
287 /***********************************************************************//**
288  * @brief Return normalization of diffuse cube for Monte Carlo simulations
289  *
290  * @param[in] dir Centre of simulation cone.
291  * @param[in] radius Radius of simulation cone (degrees).
292  * @return Normalization.
293  *
294  * Returns the normalization of a diffuse cube. The normalization is given
295  * by the model value. The @p dir and @p radius parameters are not used.
296  ***************************************************************************/
297 inline
299  const double& radius) const
300 {
301  return (value());
302 }
303 
304 
305 /***********************************************************************//**
306  * @brief Return boundary sky region
307  *
308  * @return Boundary sky region.
309  *
310  * Returns a sky region that fully encloses the point source.
311  ***************************************************************************/
312 inline
314 {
315  set_region();
316  return (&m_region);
317 }
318 
319 #endif /* GMODELSPATIALDIFFUSECUBE_HPP */
Sky map class.
Definition: GSkyMap.hpp:89
bool m_loaded
Signals if map cube has been loaded.
void set_region(void) const
Set boundary sky region.
void free_members(void)
Delete class members.
void fetch_cube(void) const
Fetch cube.
Node array class.
Definition: GNodeArray.hpp:60
void set_mc_cone(const GSkyDir &centre, const double &radius) const
Set Monte Carlo simulation cone.
const GFilename & filename(void) const
Get file name.
Sky direction class interface definition.
void init_members(void)
Initialise class members.
GFilename m_filename
Name of map cube.
int maps(void) const
Return number of maps in cube.
XML element node class.
Definition: GXmlElement.hpp:47
virtual std::string print(const GChatter &chatter=NORMAL) const
Print map cube information.
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
Time class.
Definition: GTime.hpp:54
int pixels(void) const
Return number of pixels in cube.
virtual ~GModelSpatialDiffuseCube(void)
Destructor.
FITS file class.
Definition: GFits.hpp:63
virtual void read(const GXmlElement &xml)
Read model from XML element.
Interface for the circular sky region class.
double m_mc_one_minus_cosrad
1-cosine of radius
virtual std::string type(void) const
Return spatial model type.
Sky map class definition.
GNodeArray m_logE
Log10(energy) values of the maps.
Energy container class.
Definition: GEnergies.hpp:60
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
Spectral nodes model class.
virtual GModelSpatialDiffuseCube & operator=(const GModelSpatialDiffuseCube &model)
Assignment operator.
void load(const GFilename &filename)
Load cube into the model class.
void copy_members(const GModelSpatialDiffuseCube &model)
Copy class members.
Model parameter class interface definition.
Class that handles photons.
Definition: GPhoton.hpp:47
std::vector< double > m_mc_max
Maximum values for MC.
double value(void) const
Get model value.
Model parameter class.
Definition: GModelPar.hpp:87
Node array class interface definition.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GSkyDir m_mc_centre
Centre of MC cone.
const GModelSpectralNodes & spectrum(void) const
Get map cube spectrum.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of diffuse cube for Monte Carlo simulations.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
GSkyRegionCircle m_region
Bounding circle.
void save(const GFilename &filename, const bool &clobber=false) const
Save cube into FITS file.
Energy boundaries container class.
Definition: GEbounds.hpp:60
double m_mc_radius
Radius of MC cone (degrees)
const int & nmaps(void) const
Returns number of maps.
Definition: GSkyMap.hpp:378
void load_cube(const GFilename &filename)
Load map cube.
double cube_intensity(const GPhoton &photon) const
Compute cube intensity by log-log interpolation.
void update_mc_cache(void)
Update Monte Carlo cache.
Filename class.
Definition: GFilename.hpp:62
GChatter
Definition: GTypemaps.hpp:33
Abstract spectral model base class interface definition.
Abstract diffuse spatial model base class interface definition.
GModelSpatialDiffuseCube(void)
Void constructor.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Signals whether model contains sky direction.
void set_energy_boundaries(void)
Set energy boundaries.
GEnergies energies(void)
Returns map cube energies.
double value(void) const
Return parameter value.
GModelSpectralNodes m_mc_spectrum
Map cube spectrum.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
virtual GSkyRegion * region(void) const
Return boundary sky region.
Energy boundaries class interface definition.
Abstract diffuse spatial model base class.
const int & npix(void) const
Returns number of pixels.
Definition: GSkyMap.hpp:334
Sky direction class.
Definition: GSkyDir.hpp:62
const GSkyMap & cube(void) const
Get map cube.
Circular sky region class interface definition.
virtual void clear(void)
Clear map cube model.
GEbounds m_ebounds
Energy bounds of the maps.
virtual std::string classname(void) const
Return class name.
Filename class interface definition.
virtual GModelSpatialDiffuseCube * clone(void) const
Clone map cube model.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48