GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAModelBackground.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAModelBackground.hpp - Background model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 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 GCTAModelBackground.hpp
23  * @brief Background model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTAMODELBACKGROUND_HPP
28 #define GCTAMODELBACKGROUND_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <cmath>
33 #include "GModelData.hpp"
34 #include "GModelSpectral.hpp"
35 #include "GModelTemporal.hpp"
36 #include "GFunction.hpp"
37 #include "GCTAModelSpatial.hpp"
38 #include "GCTAEventList.hpp"
39 
40 /* __ Forward declarations _______________________________________________ */
41 class GEvent;
42 class GObservation;
43 class GModelPar;
44 class GXmlElement;
45 
46 
47 /***********************************************************************//**
48  * @class GCTAModelBackground
49  *
50  * @brief Background model class
51  *
52  * This class implements a background model for CTA.
53  ***************************************************************************/
55 
56 public:
57  // Constructors and destructors
58  GCTAModelBackground(void);
59  explicit GCTAModelBackground(const GXmlElement& xml);
61  const GModelSpectral& spectral);
63  const GModelSpectral& spectral,
64  const GModelTemporal& temporal);
66  virtual ~GCTAModelBackground(void);
67 
68  // Operators
69  virtual GCTAModelBackground& operator=(const GCTAModelBackground& model);
70 
71  // Implemented pure virtual methods
72  virtual void clear(void);
73  virtual GCTAModelBackground* clone(void) const;
74  virtual std::string classname(void) const;
75  virtual std::string type(void) const;
76  virtual bool is_constant(void) const;
77  virtual double eval(const GEvent& event,
78  const GObservation& obs,
79  const bool& gradients = false) const;
80  virtual double npred(const GEnergy& energy,
81  const GTime& time,
82  const GObservation& obs) const;
83  virtual GCTAEventList* mc(const GObservation& obs, GRan& ran) const;
84  virtual void read(const GXmlElement& xml);
85  virtual void write(GXmlElement& xml) const;
86  virtual std::string print(const GChatter& chatter = NORMAL) const;
87 
88  // Other methods
89  GCTAModelSpatial* spatial(void) const;
90  GModelSpectral* spectral(void) const;
91  GModelTemporal* temporal(void) const;
92  void spatial(const GCTAModelSpatial* spatial);
93  void spectral(const GModelSpectral* spectral);
94  void temporal(const GModelTemporal* temporal);
95 
96 protected:
97  // Protected methods
98  void init_members(void);
99  void copy_members(const GCTAModelBackground& model);
100  void free_members(void);
101  void set_pointers(void);
102  GCTAModelSpatial* xml_spatial(const GXmlElement& spatial) const;
103  GModelSpectral* xml_spectral(const GXmlElement& spectral) const;
104  GModelTemporal* xml_temporal(const GXmlElement& temporal) const;
105  bool valid_model(void) const;
106 
107  // Proteced data members
108  GCTAModelSpatial* m_spatial; //!< Spatial model
109  GModelSpectral* m_spectral; //!< Spectral model
110  GModelTemporal* m_temporal; //!< Temporal model
111 };
112 
113 
114 /***********************************************************************//**
115  * @brief Return class name
116  *
117  * @return String containing the class name ("GCTAModelBackground").
118  ***************************************************************************/
119 inline
120 std::string GCTAModelBackground::classname(void) const
121 {
122  return ("GCTAModelBackground");
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Return model type
128  *
129  * @return Model type.
130  *
131  * Returns "CTABackground" as the type of the model.
132  ***************************************************************************/
133 inline
134 std::string GCTAModelBackground::type(void) const
135 {
136  return ("CTABackground");
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Signals if model is temporally constant
142  *
143  * @return True if model is temporally constant, false otherwise.
144  *
145  * Signals if the model is temporally constant. A temporally constant model
146  * is a model that has a temporal component of type "Constant".
147  ***************************************************************************/
148 inline
150 {
151  return (m_temporal != NULL && m_temporal->type() == "Constant");
152 }
153 
154 
155 /***********************************************************************//**
156  * @brief Return spatial model component
157  *
158  * @return Pointer to spatial model component.
159  *
160  * Returns a pointer to the spatial model component of the model. The pointer
161  * is of type GCTAModelSpatial. Note that a NULL pointer may be returned if
162  * the model has no spatial model component.
163  ***************************************************************************/
164 inline
166 {
167  return (m_spatial);
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Return spectral model component
173  *
174  * @return Pointer to spectral model component.
175  *
176  * Returns a pointer to the spectral model component of the model. The
177  * pointer is of type GModelSpectral. Note that a NULL pointer may be
178  * returned if the model has no spectral model component.
179  ***************************************************************************/
180 inline
182 {
183  return (m_spectral);
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Return temporal model component
189  *
190  * @return Pointer to temporal model component.
191  *
192  * Returns a pointer to the temporal model component of the model. The
193  * pointer is of type GModelTemporal. Note that a NULL pointer may be
194  * returned if the model has no temporal model component.
195  ***************************************************************************/
196 inline
198 {
199  return (m_temporal);
200 }
201 
202 #endif /* GCTAMODELBACKGROUND_HPP */
GCTAModelBackground(void)
Void constructor.
Abstract spatial model class.
CTA event list class interface definition.
virtual bool is_constant(void) const
Signals if model is temporally constant.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
Abstract spectral model base class.
virtual std::string classname(void) const
Return class name.
virtual void read(const GXmlElement &xml)
Read model from XML element.
Abstract temporal model base class.
GModelTemporal * m_temporal
Temporal model.
virtual double npred(const GEnergy &energy, const GTime &time, const GObservation &obs) const
Return spatially integrated background rate in units of events MeV s .
bool valid_model(void) const
Verifies if model has all components.
Abstract interface for the event classes.
Definition: GEvent.hpp:71
CTA event list class.
XML element node class.
Definition: GXmlElement.hpp:47
GModelSpectral * spectral(void) const
Return spectral model component.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:54
GModelSpectral * m_spectral
Spectral model.
void copy_members(const GCTAModelBackground &model)
Copy class members.
Model parameter class.
Definition: GModelPar.hpp:87
void free_members(void)
Delete class members.
Abstract temporal model base class interface definition.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
Single parameter function abstract base class definition.
GCTAModelSpatial * spatial(void) const
Return spatial model component.
Abstract data model base class interface definition.
void set_pointers(void)
Set pointers.
Abstract data model class.
Definition: GModelData.hpp:53
virtual GCTAModelBackground & operator=(const GCTAModelBackground &model)
Assignment operator.
GChatter
Definition: GTypemaps.hpp:33
GCTAModelSpatial * xml_spatial(const GXmlElement &spatial) const
Return pointer to spatial model from XML element.
Abstract observation base class.
void init_members(void)
Initialise class members.
Abstract spectral model base class interface definition.
Background model class.
virtual std::string type(void) const =0
virtual GCTAModelBackground * clone(void) const
Clone instance.
virtual void write(GXmlElement &xml) const
Write model into XML element.
GCTAModelSpatial * m_spatial
Spatial model.
GModelTemporal * temporal(void) const
Return temporal model component.
Abstract spatial model class interface definition.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return background rate in units of events MeV s sr .
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
virtual ~GCTAModelBackground(void)
Destructor.
virtual void clear(void)
Clear instance.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string type(void) const
Return model type.