GammaLib  2.0.0
 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-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 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 double eval(const GPhoton& photon,
82  const bool& gradients = false) const;
83  virtual GSkyDir mc(const GEnergy& energy,
84  const GTime& time,
85  GRan& ran) const;
86  virtual double mc_norm(const GSkyDir& dir,
87  const double& radius) const;
88  virtual bool contains(const GSkyDir& dir,
89  const double& margin = 0.0) const;
90  virtual void read(const GXmlElement& xml);
91  virtual void write(GXmlElement& xml) const;
92  virtual std::string print(const GChatter& chatter = NORMAL) const;
93 
94  // Overloaded base class methods
95  virtual double flux(const GSkyRegion& region,
96  const GEnergy& srcEng = GEnergy(),
97  const GTime& srcTime = GTime()) const;
98 
99  // Other methods
100  double value(void) const;
101  void value(const double& value);
102  const GFilename& filename(void) const;
103  void filename(const GFilename& filename);
104  const GSkyMap& cube(void) const;
105  void cube(const GSkyMap& cube);
106  GEnergies energies(void);
107  void energies(const GEnergies& energies);
108  const GModelSpectralNodes& spectrum(void) const;
109  void mc_cone(const GSkyRegionCircle& cone) const;
110  const GSkyRegionCircle& mc_cone(void) const;
111  void load(const GFilename& filename);
112  void save(const GFilename& filename,
113  const bool& clobber = false) const;
114  void read(const GFits& fits);
115  void write(GFits& fits) const;
116 
117 protected:
118  // Protected methods
119  void init_members(void);
120  void copy_members(const GModelSpatialDiffuseCube& model);
121  void free_members(void);
122  void fetch_cube(void) const;
123  void load_cube(const GFilename& filename);
124  void set_energy_boundaries(void);
125  void update_mc_cache(void);
126  double cube_intensity(const GPhoton& photon) const;
127  virtual void set_region(void) const;
128 
129  // Protected members
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 
137  // Monte Carlo cache
138  mutable GSkyRegionCircle m_mc_cone; //!< MC cone
139  mutable double m_mc_one_minus_cosrad; //!< 1-cosine of radius
140  mutable std::vector<double> m_mc_max; //!< Maximum values for MC
141  mutable GModelSpectralNodes m_mc_spectrum; //!< Map cube spectrum
142 };
143 
144 
145 /***********************************************************************//**
146  * @brief Return class name
147  *
148  * @return String containing the class name ("GModelSpatialDiffuseCube").
149  ***************************************************************************/
150 inline
151 std::string GModelSpatialDiffuseCube::classname(void) const
152 {
153  return ("GModelSpatialDiffuseCube");
154 }
155 
156 
157 /***********************************************************************//**
158  * @brief Get model value
159  *
160  * @return Model value.
161  *
162  * Returns the value of the spatial map cube model.
163  ***************************************************************************/
164 inline
166 {
167  return (m_value.value());
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Set model value
173  *
174  * @param[in] value Model value.
175  *
176  * Set the value of the spatial map cube model.
177  ***************************************************************************/
178 inline
179 void GModelSpatialDiffuseCube::value(const double& value)
180 {
181  m_value.value(value);
182  return;
183 }
184 
185 
186 /***********************************************************************//**
187  * @brief Get file name
188  *
189  * @return File name.
190  *
191  * Returns the file name of the spatial map cube model.
192  ***************************************************************************/
193 inline
195 {
196  return (m_filename);
197 }
198 
199 
200 /***********************************************************************//**
201  * @brief Set file name
202  *
203  * @param[in] filename File name.
204  *
205  * Set the file name of the spatial map cube model.
206  ***************************************************************************/
207 inline
209 {
211  return;
212 }
213 
214 
215 /***********************************************************************//**
216  * @brief Get map cube
217  *
218  * @return Map cube.
219  *
220  * Returns the map cube.
221  ***************************************************************************/
222 inline
224 {
225  fetch_cube();
226  return (m_cube);
227 }
228 
229 
230 /***********************************************************************//**
231  * @brief Get map cube spectrum
232  *
233  * @return Map cube spectrum.
234  *
235  * Returns the map cube spectrum.
236  ***************************************************************************/
237 inline
239 {
240  fetch_cube();
241  return (m_mc_spectrum);
242 }
243 
244 
245 /***********************************************************************//**
246  * @brief Return normalization of diffuse cube for Monte Carlo simulations
247  *
248  * @param[in] dir Centre of simulation cone.
249  * @param[in] radius Radius of simulation cone (degrees).
250  * @return Normalization.
251  *
252  * Returns the normalization of a diffuse cube. The normalization is given
253  * by the model value. The @p dir and @p radius parameters are not used.
254  ***************************************************************************/
255 inline
257  const double& radius) const
258 {
259  return (value());
260 }
261 
262 
263 /***********************************************************************//**
264  * @brief Get Monte Carlo simulation cone
265  *
266  * @return Monte Carlo simulation sky region circle.
267  *
268  * Returns the sky region circle used for Monte Carlo simulations.
269  ***************************************************************************/
270 inline
272 {
273  return (m_mc_cone);
274 }
275 
276 #endif /* GMODELSPATIALDIFFUSECUBE_HPP */
Sky map class.
Definition: GSkyMap.hpp:89
bool m_loaded
Signals if map cube has been loaded.
virtual 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
const GFilename & filename(void) const
Get file name.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns diffuse cube flux integrated in sky region.
Sky direction class interface definition.
void init_members(void)
Initialise class members.
GFilename m_filename
Name of map cube.
XML element node class.
Definition: GXmlElement.hpp:48
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.
GSkyRegionCircle m_mc_cone
MC cone.
Time class.
Definition: GTime.hpp:55
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
Sky map class definition.
GNodeArray m_logE
Log10(energy) values of the maps.
Energy container class.
Definition: GEnergies.hpp:60
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.
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
void save(const GFilename &filename, const bool &clobber=false) const
Save cube into FITS file.
Energy boundaries container class.
Definition: GEbounds.hpp:60
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
const GSkyRegionCircle & mc_cone(void) const
Get Monte Carlo simulation cone.
GChatter
Definition: GTypemaps.hpp:33
std::string type(void) const
Return model type.
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.
const GSkyRegion * region(void) const
Return boundary sky region.
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.
Energy boundaries class interface definition.
Abstract diffuse spatial model base class.
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