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