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