GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSpatialComposite.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GModelSpatialComposite.hpp - Spatial composite model class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2016-2024 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
49public:
50 // Constructors and destructors
51 GModelSpatialComposite(const bool& normalize = true);
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 std::string name(const int& index) const;
91 const GModelPar* scale(const int& index) const;
92 double sum_of_scales(void) const;
93 const bool& normalize(void) const;
94
95protected:
96 // Protected methods
97 void init_members(void);
98 void copy_members(const GModelSpatialComposite& model);
99 void free_members(void);
100 virtual void set_region(void) const;
101
102 // Protected members
103 bool m_normalize; //!< Normalize component
104 bool m_has_normalize; //!< XML has normalize attribute
105 std::vector<GModelSpatial*> m_components; //!< Components
106 std::vector<std::string> m_names; //!< Component names
107 std::vector<GModelPar*> m_scales; //!< Component scales
108};
109
110
111/***********************************************************************//**
112 * @brief Return class name
113 *
114 * @return String containing the class name ("GModelSpatialComposite").
115 ***************************************************************************/
116inline
118{
119 return ("GModelSpatialComposite");
120}
121
122
123/***********************************************************************//**
124 * @brief Return class code
125 *
126 * @return GModelSpatialComposite.
127 *
128 * Returns the code GModelSpatialComposite of the class.
129 ***************************************************************************/
130inline
135
136
137/***********************************************************************//**
138 * @brief Return normalization of composite source for Monte Carlo
139 * simulations
140 *
141 * @param[in] dir Centre of simulation cone.
142 * @param[in] radius Radius of simulation cone (degrees).
143 * @return Normalization.
144 *
145 * Returns unity.
146 ***************************************************************************/
147inline
149 const double& radius) const
150{
151 return 1.0;
152}
153
154
155/***********************************************************************//**
156 * @brief Return number of model components
157 *
158 * @return Number of model components.
159 ***************************************************************************/
160inline
162{
163 return ((int)m_components.size());
164}
165
166
167/***********************************************************************//**
168 * @brief Return normalisation flag
169 *
170 * @return True if composite model is normalised.
171 ***************************************************************************/
172inline
174{
175 return (m_normalize);
176}
177
178#endif /* GMODELSPATIALCOMPOSITE_HPP */
Model parameter class interface definition.
Abstract spatial model base class interface definition.
Sky direction class interface definition.
Circular sky region class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
GClassCode
Definition GTypemaps.hpp:42
@ GMODEL_SPATIAL_COMPOSITE
Definition GTypemaps.hpp:47
XML element node class interface definition.
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Model parameter class.
Definition GModelPar.hpp:87
Spatial composite model.
void free_members(void)
Delete class members.
std::vector< std::string > m_names
Component names.
virtual void clear(void)
Clear spatial composite model.
std::vector< GModelSpatial * > m_components
Components.
bool m_normalize
Normalize component.
virtual double flux(const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns flux integrated in sky region.
GModelSpatialComposite(const bool &normalize=true)
Void constructor.
void copy_members(const GModelSpatialComposite &model)
Copy class members.
const GModelSpatial * component(const int &index) const
Returns pointer to spatial component element.
void append(const GModelSpatial &component, const std::string &name="", const GModelPar &par=GModelPar("", 1.0))
Append spatial component.
virtual GModelSpatialComposite * clone(void) const
Clone spatial composite model.
const GModelPar * scale(const int &index) const
Returns scale parameter of spatial component.
virtual std::string classname(void) const
Return class name.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
virtual void read(const GXmlElement &xml)
Read model from XML element.
int components(void) const
Return number of model components.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const
Evaluate function.
virtual void set_region(void) const
Set boundary sky region.
std::vector< GModelPar * > m_scales
Component scales.
virtual GClassCode code(void) const
Return class code.
void init_members(void)
Initialise class members.
double sum_of_scales(void) const
Returns sum of all model scales.
virtual ~GModelSpatialComposite(void)
Destructor.
const bool & normalize(void) const
Return normalisation flag.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks where model contains specified sky direction.
std::string name(const int &index) const
Returns names of spatial component.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print composite spatial model information.
bool m_has_normalize
XML has normalize attribute.
virtual GModelSpatialComposite & operator=(const GModelSpatialComposite &model)
Assignment operator.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const
Return normalization of composite source for Monte Carlo simulations.
Abstract spatial model base class.
std::string type(void) const
Return model type.
const GSkyRegion * region(void) const
Return boundary sky region.
Class that handles photons.
Definition GPhoton.hpp:47
Random number generator class.
Definition GRan.hpp:44
Sky direction class.
Definition GSkyDir.hpp:62
Abstract interface for the sky region class.
Time class.
Definition GTime.hpp:55
XML element node class.