GammaLib  2.1.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-2021 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 GClassCode code(void) const;
65  virtual double eval(const GPhoton& photon,
66  const bool& gradients = false) const;
67  virtual GSkyDir mc(const GEnergy& energy,
68  const GTime& time,
69  GRan& ran) const;
70  virtual double mc_norm(const GSkyDir& dir,
71  const double& radius) const;
72  virtual bool contains(const GSkyDir& dir,
73  const double& margin = 0.0) const;
74  virtual void read(const GXmlElement& xml);
75  virtual void write(GXmlElement& xml) const;
76  virtual std::string print(const GChatter& chatter = NORMAL) const;
77 
78  // Overloaded base class methods
79  virtual double flux(const GSkyRegion& region,
80  const GEnergy& srcEng = GEnergy(),
81  const GTime& srcTime = GTime()) const;
82 
83  // Other methods
84  int components(void) const;
85  void append(const GModelSpatial& component,
86  const std::string& name = "",
87  const GModelPar& par = GModelPar("", 1.0));
88  const GModelSpatial* component(const int& index) const;
89  const GModelSpatial* component(const std::string& name) const;
90  double scale(const int& index) const;
91  double sum_of_scales(void) const;
92 
93 
94 protected:
95  // Protected methods
96  void init_members(void);
97  void copy_members(const GModelSpatialComposite& model);
98  void free_members(void);
99  virtual void set_region(void) const;
100 
101  // Protected members
102  std::vector<GModelSpatial*> m_components; //!< Components
103  std::vector<std::string> m_names; //!< Component names
104  std::vector<GModelPar*> m_scales; //!< Component scales
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 class code
122  *
123  * @return GModelSpatialComposite.
124  *
125  * Returns the code GModelSpatialComposite of the class.
126  ***************************************************************************/
127 inline
129 {
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Return normalization of composite source for Monte Carlo
136  * simulations
137  *
138  * @param[in] dir Centre of simulation cone.
139  * @param[in] radius Radius of simulation cone (degrees).
140  * @return Normalization.
141  *
142  * Returns unity.
143  ***************************************************************************/
144 inline
146  const double& radius) const
147 {
148  return 1.0;
149 }
150 
151 
152 /***********************************************************************//**
153  * @brief Return number of model components
154  *
155  * @return Number of model components.
156  ***************************************************************************/
157 inline
159 {
160  return ((int)m_components.size());
161 }
162 
163 #endif /* GMODELSPATIALCOMPOSITE_HPP */
virtual std::string classname(void) const
Return class name.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns flux integrated in sky region.
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:48
Abstract spatial model base class interface definition.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
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.
std::string type(void) const
Return model type.
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.
int components(void) const
Return number of model components.
const GSkyRegion * region(void) const
Return boundary sky region.
void free_members(void)
Delete class members.
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 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
virtual 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.