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