GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialComposite.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpatialComposite.hpp - Spatial composite model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2018 by Domenico Tiziani *
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 GModelSpatialComposite.hpp
23  * @brief Spatial composite model class interface definition
24  * @author Domenico Tiziani
25  */
26 
27 #ifndef GMODELSPATIALCOMPOSITE_HPP
28 #define GMODELSPATIALCOMPOSITE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GModelSpatial.hpp"
33 #include "GModelPar.hpp"
34 #include "GSkyDir.hpp"
35 #include "GSkyRegionCircle.hpp"
36 #include "GXmlElement.hpp"
37 
38 
39 /***********************************************************************//**
40  * @class GModelSpatialComposite
41  *
42  * @brief Spatial composite model
43  *
44  * This class implements the spatial model for a composition of spatial
45  * models.
46  ***************************************************************************/
48 
49 public:
50  // Constructors and destructors
52  GModelSpatialComposite(const bool& dummy, const std::string& type);
53  explicit GModelSpatialComposite(const GXmlElement& xml);
55  virtual ~GModelSpatialComposite(void);
56 
57  // Operators
59 
60  // Implemented pure virtual methods
61  virtual void clear(void);
62  virtual GModelSpatialComposite* clone(void) const;
63  virtual std::string classname(void) const;
64  virtual std::string type(void) const;
65  virtual GClassCode code(void) const;
66  virtual double eval(const GPhoton& photon,
67  const bool& gradients = false) const;
68  virtual GSkyDir mc(const GEnergy& energy,
69  const GTime& time,
70  GRan& ran) const;
71  virtual double mc_norm(const GSkyDir& dir,
72  const double& radius) const;
73  virtual bool contains(const GSkyDir& dir,
74  const double& margin = 0.0) const;
75  virtual GSkyRegion* region(void) const;
76  virtual void read(const GXmlElement& xml);
77  virtual void write(GXmlElement& xml) const;
78  virtual std::string print(const GChatter& chatter = NORMAL) const;
79 
80  // Other methods
81  void type(const std::string& type);
82  int components(void) const;
83  void append(const GModelSpatial& component,
84  const std::string& name = "",
85  const GModelPar& par = GModelPar("", 1.0));
86  const GModelSpatial* component(const int& index) const;
87  const GModelSpatial* component(const std::string& name) const;
88  double scale(const int& index) const;
89  double sum_of_scales(void) const;
90 
91 
92 protected:
93  // Protected methods
94  void init_members(void);
95  void copy_members(const GModelSpatialComposite& model);
96  void free_members(void);
97  void set_region(void) const;
98 
99  // Protected members
100  std::string m_type; //!< Model type
101  std::vector<GModelSpatial*> m_components; //!< Components
102  std::vector<std::string> m_names; //!< Component names
103  std::vector<GModelPar*> m_scales; //!< Component scales
104  mutable GSkyRegionCircle m_region; //!< Bounding circle
105 };
106 
107 
108 /***********************************************************************//**
109  * @brief Return class name
110  *
111  * @return String containing the class name ("GModelSpatialComposite").
112  ***************************************************************************/
113 inline
114 std::string GModelSpatialComposite::classname(void) const
115 {
116  return ("GModelSpatialComposite");
117 }
118 
119 
120 /***********************************************************************//**
121  * @brief Return model type
122  *
123  * @return Model type.
124  *
125  * Returns the type of the spatial model.
126  ***************************************************************************/
127 inline
128 std::string GModelSpatialComposite::type(void) const
129 {
130  return (m_type);
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Set model type
136  *
137  * @param[in] type Model type.
138  *
139  * Set the type of the spatial model.
140  ***************************************************************************/
141 inline
142 void GModelSpatialComposite::type(const std::string& type)
143 {
144  m_type = type;
145  return;
146 }
147 
148 
149 /***********************************************************************//**
150  * @brief Return class code
151  *
152  * @return GModelSpatialComposite.
153  *
154  * Returns the code GModelSpatialComposite of the class.
155  ***************************************************************************/
156 inline
158 {
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Return normalization of composite source for Monte Carlo
165  * simulations
166  *
167  * @param[in] dir Centre of simulation cone.
168  * @param[in] radius Radius of simulation cone (degrees).
169  * @return Normalization.
170  *
171  * Returns unity.
172  ***************************************************************************/
173 inline
175  const double& radius) const
176 {
177  return 1.0;
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Return number of model components
183  *
184  * @return Number of model components.
185  ***************************************************************************/
186 inline
188 {
189  return ((int)m_components.size());
190 }
191 
192 
193 /***********************************************************************//**
194  * @brief Return boundary sky region
195  *
196  * @return Boundary sky region.
197  *
198  * Returns a sky region that fully encloses the point source.
199  ***************************************************************************/
200 inline
202 {
203  set_region();
204  return (&m_region);
205 }
206 
207 #endif /* GMODELSPATIALCOMPOSITE_HPP */
virtual std::string classname(void) const
Return class name.
virtual void read(const GXmlElement &xml)
Read model from XML element.
XML element node class interface definition.
const GModelSpatial * component(const int &index) const
Returns pointer to spatial component element.
Sky direction class interface definition.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual void clear(void)
Clear spatial composite model.
GModelSpatialComposite(void)
Void constructor.
XML element node class.
Definition: GXmlElement.hpp:47
Abstract spatial model base class interface definition.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:54
Interface for the circular sky region class.
virtual GClassCode code(void) const
Return class code.
Model parameter class interface definition.
double sum_of_scales(void) const
Returns sum of all model scales.
Class that handles photons.
Definition: GPhoton.hpp:47
Model parameter class.
Definition: GModelPar.hpp:87
virtual GModelSpatialComposite * clone(void) const
Clone spatial composite model.
std::vector< std::string > m_names
Component names.
Abstract interface for the sky region class.
Definition: GSkyRegion.hpp:57
std::vector< GModelSpatial * > m_components
Components.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
GChatter
Definition: GTypemaps.hpp:33
void copy_members(const GModelSpatialComposite &model)
Copy class members.
Spatial composite model.
GSkyRegionCircle m_region
Bounding circle.
virtual GModelSpatialComposite & operator=(const GModelSpatialComposite &model)
Assignment operator.
void append(const GModelSpatial &component, const std::string &name="", const GModelPar &par=GModelPar("", 1.0))
Append spatial component.
std::vector< GModelPar * > m_scales
Component scales.
virtual GSkyRegion * region(void) const
Return boundary sky region.
int components(void) const
Return number of model components.
void free_members(void)
Delete class members.
std::string m_type
Model type.
GClassCode
Definition: GTypemaps.hpp:42
virtual std::string print(const GChatter &chatter=NORMAL) const
Print composite spatial model information.
Abstract spatial model base class.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks where model contains specified sky direction.
virtual std::string type(void) const
Return model type.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of composite source for Monte Carlo simulations.
Sky direction class.
Definition: GSkyDir.hpp:62
void set_region(void) const
Set boundary sky region.
Circular sky region class interface definition.
double scale(const int &index) const
Returns scale of spatial component.
virtual ~GModelSpatialComposite(void)
Destructor.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void init_members(void)
Initialise class members.