GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAResponseCube.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAResponseCube.hpp - CTA cube analysis response function class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2022 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 GCTAResponseCube.hpp
23  * @brief CTA cube-style response function class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTARESPONSECUBE_HPP
28 #define GCTARESPONSECUBE_HPP
29 
30 /* __ Coding definitions _________________________________________________ */
31 #define G_CUBE_FAST
32 
33 /* __ Includes ___________________________________________________________ */
34 #include <string>
35 #include <vector>
36 #include "GNdarray.hpp"
37 #include "GCTAResponse.hpp"
38 #include "GCTACubeExposure.hpp"
39 #include "GCTACubePsf.hpp"
40 #include "GCTACubeEdisp.hpp"
41 #include "GCTACubeBackground.hpp"
42 #include "GCTACubeSource.hpp"
43 
44 /* __ Type definitions ___________________________________________________ */
45 
46 /* __ Forward declarations _______________________________________________ */
47 #if defined(G_CUBE_FAST)
48 class GEnergies;
49 #endif
50 class GPhoton;
51 class GEvent;
52 class GObservation;
53 class GCTAObservation;
54 class GCTAInstDir;
57 
58 
59 /***********************************************************************//**
60  * @class GCTAResponseCube
61  *
62  * @brief CTA cube-style response function class
63  ***************************************************************************/
65 
66 public:
67  // Expose GCTAResponse::irf method
68  using GCTAResponse::irf;
69 
70  // Constructors and destructors
71  GCTAResponseCube(void);
73  explicit GCTAResponseCube(const GXmlElement& xml);
75  const GCTACubePsf& psf,
77  GCTAResponseCube(const GCTACubeExposure& exposure,
78  const GCTACubePsf& psf,
79  const GCTACubeEdisp& edisp,
80  const GCTACubeBackground& background);
81  virtual ~GCTAResponseCube(void);
82 
83  // Operators
84  virtual GCTAResponseCube& operator=(const GCTAResponseCube & rsp);
85 
86  // Implement pure virtual base class methods
87  virtual void clear(void);
88  virtual GCTAResponseCube* clone(void) const;
89  virtual std::string classname(void) const;
90  virtual bool is_valid(void) const;
91  virtual bool use_edisp(void) const;
92  virtual bool use_tdisp(void) const;
93  virtual bool apply_edisp(void) const;
94  virtual void apply_edisp(const bool& apply_edisp) const;
95  virtual double irf(const GEvent& event,
96  const GPhoton& photon,
97  const GObservation& obs) const;
98  virtual double nroi(const GModelSky& model,
99  const GEnergy& obsEng,
100  const GTime& obsTime,
101  const GObservation& obs) const;
102  virtual GEbounds ebounds(const GEnergy& obsEng) const;
103  virtual void read(const GXmlElement& xml);
104  virtual void write(GXmlElement& xml) const;
105  virtual std::string print(const GChatter& chatter = NORMAL) const;
106 
107  // Overloaded virtual base class methods
108  virtual double irf_spatial(const GEvent& event,
109  const GSource& source,
110  const GObservation& obs) const;
111 
112  // Other Methods
113  const GCTACubeExposure& exposure(void) const;
114  void exposure(const GCTACubeExposure& exposure);
115  const GCTACubePsf& psf(void) const;
116  void psf(const GCTACubePsf& psf);
117  const GCTACubeEdisp& edisp(void) const;
118  void edisp(const GCTACubeEdisp& edisp);
119  const GCTACubeBackground& background(void) const;
120  void background(const GCTACubeBackground& background);
121 
122 private:
123  // Private methods
124  void init_members(void);
125  void copy_members(const GCTAResponseCube& rsp);
126  void free_members(void);
127  double psf_radial(const GModelSpatialRadial* model,
128  const double& rho_obs,
129  const GSkyDir& obsDir,
130  const GEnergy& srcEng,
131  const GTime& srcTime) const;
132  double psf_elliptical(const GModelSpatialElliptical* model,
133  const double& rho_obs,
134  const double& posangle_obs,
135  const GSkyDir& obsDir,
136  const GEnergy& srcEng,
137  const GTime& srcTime) const;
138  double psf_diffuse(const GModelSpatial* model,
139  const GSkyDir& obsDir,
140  const GEnergy& srcEng,
141  const GTime& srcTime) const;
142  double irf_ptsrc(const GEvent& event,
143  const GSource& source,
144  const GObservation& obs) const;
145  double irf_radial(const GEvent& event,
146  const GSource& source,
147  const GObservation& obs) const;
148  double irf_elliptical(const GEvent& event,
149  const GSource& source,
150  const GObservation& obs) const;
151  double irf_diffuse(const GEvent& event,
152  const GSource& source,
153  const GObservation& obs) const;
154 
155  // New methods
156  GVector irf_radial(const GModelSky& model,
157  const GObservation& obs,
158  GMatrix* gradients = NULL) const;
160  const double& zeta,
161  const GSkyDir& obsDir,
162  const GEnergies& srcEngs,
163  const GTime& srcTime,
164  const bool& grad) const;
165 
166  // Private data members
167  GCTACubeExposure m_exposure; //!< Exposure cube
168  GCTACubePsf m_psf; //!< Mean point spread function
169  GCTACubeBackground m_background; //!< Background cube
170  GCTACubeEdisp m_edisp; //!< Energy dispersion cube
171  mutable bool m_apply_edisp; //!< Apply energy dispersion
172  mutable bool m_has_edisp; //!< Flag to indicate if energy
173 
174  // Kludge: cube response cache
175  mutable std::vector<std::string> m_cache_names; //!< Model names
176  mutable std::vector<GNdarray> m_cache_values; //!< Cached values
177 };
178 
179 
180 /***********************************************************************//**
181  * @brief Return class name
182  *
183  * @return String containing the class name ("GCTAResponseCube").
184  ***************************************************************************/
185 inline
186 std::string GCTAResponseCube::classname(void) const
187 {
188  return ("GCTAResponseCube");
189 }
190 
191 
192 /***********************************************************************//**
193  * @brief Signal if response is valid
194  *
195  * @return True if response is valid
196  *
197  * @todo: To be implemented (check if GCTACubeExposure and GCTACubePsf is loaded)
198  ***************************************************************************/
199 inline
201 {
202  return (true);
203 }
204 
205 
206 /***********************************************************************//**
207  * @brief Signal if response uses energy dispersion
208  *
209  * @return True if response uses energy dispersion
210  *
211  * Signals if the response uses energy dispersion. This implies that the
212  * apply_edisp flag has been set to true and that energy dispersion response
213  * information is available.
214  ***************************************************************************/
215 inline
217 {
218  return (m_apply_edisp && m_has_edisp);
219 }
220 
221 
222 /***********************************************************************//**
223  * @brief Signal if time dispersion will be used
224  *
225  * @return False.
226  ***************************************************************************/
227 inline
229 {
230  return false;
231 }
232 
233 
234 /***********************************************************************//**
235  * @brief Signal if energy dispersion should be applied
236  *
237  * @return True if energy dispersion should be applied
238  ***************************************************************************/
239 inline
241 {
242  return m_apply_edisp;
243 }
244 
245 /***********************************************************************//**
246  * @brief Signal if energy dispersion should be applied
247  *
248  * @param[in] apply_edisp Set true if energy dispersion should be applied
249  ***************************************************************************/
250 inline
251 void GCTAResponseCube::apply_edisp(const bool& apply_edisp) const
252 {
254  return;
255 }
256 
257 
258 /***********************************************************************//**
259  * @brief Return exposure cube
260  *
261  * @return Reference to exposure cube.
262  ***************************************************************************/
263 inline
265 {
266  return (m_exposure);
267 }
268 
269 
270 /***********************************************************************//**
271  * @brief Set exposure cube
272  *
273  * @param[in] exposure Exposure cube.
274  ***************************************************************************/
275 inline
277 {
279  return;
280 }
281 
282 
283 /***********************************************************************//**
284  * @brief Return cube analysis point spread function
285  *
286  * @return Reference to cube analysis point spread function.
287  ***************************************************************************/
288 inline
290 {
291  return (m_psf);
292 }
293 
294 
295 /***********************************************************************//**
296  * @brief Set cube analysis point spread function cube
297  *
298  * @param[in] psf Cube analysis point spread function.
299  ***************************************************************************/
300 inline
302 {
303  m_psf = psf;
304  return;
305 }
306 
307 
308 /***********************************************************************//**
309  * @brief Set cube analysis energy dispersion cube
310  *
311  * @param[in] edisp Cube analysis energy dispersion cube.
312  ***************************************************************************/
313 inline
315 {
316  m_edisp = edisp;
317  m_has_edisp = true;
318  return;
319 }
320 
321 
322 /***********************************************************************//**
323  * @brief Return cube analysis energy dispersion cube
324  *
325  * @return Reference to cube analysis energy dispersion cube.
326  ***************************************************************************/
327 inline
329 {
330  return (m_edisp);
331 }
332 
333 
334 /***********************************************************************//**
335  * @brief Set cube analysis background cube
336  *
337  * @param[in] background Cube analysis background cube.
338  ***************************************************************************/
339 inline
341 {
343  return;
344 }
345 
346 
347 /***********************************************************************//**
348  * @brief Return cube analysis background cube
349  *
350  * @return Reference to cube analysis background cube.
351  ***************************************************************************/
352 inline
354 {
355  return (m_background);
356 }
357 
358 
359 #endif /* GCTARESPONSECUBE_HPP */
void copy_members(const GCTAResponseCube &rsp)
Copy class members.
CTA exposure cube class.
double irf_radial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to radial source.
GCTACubePsf m_psf
Mean point spread function.
virtual bool use_edisp(void) const
Signal if response uses energy dispersion.
Abstract elliptical spatial model base class.
GCTACubeExposure m_exposure
Exposure cube.
CTA cube analysis point spread function class definition.
const GCTACubeBackground & background(void) const
Return cube analysis background cube.
CTA cube background class.
CTA cube-style response function class.
Abstract interface for the event classes.
Definition: GEvent.hpp:71
XML element node class.
Definition: GXmlElement.hpp:48
std::vector< std::string > m_cache_names
Model names.
double psf_radial(const GModelSpatialRadial *model, const double &rho_obs, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate Psf over radial model.
virtual GCTAResponseCube & operator=(const GCTAResponseCube &rsp)
Assignment operator.
Time class.
Definition: GTime.hpp:55
virtual double irf_spatial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response integrated over the spatial model.
double irf_diffuse(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to diffuse source.
virtual void write(GXmlElement &xml) const
Write response information into XML element.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print response information.
Energy container class.
Definition: GEnergies.hpp:60
CTA cube background class definition.
void init_members(void)
Initialise class members.
Class that handles photons.
Definition: GPhoton.hpp:47
std::vector< GNdarray > m_cache_values
Cached values.
const GCTACubeExposure & exposure(void) const
Return exposure cube.
virtual std::string classname(void) const
Return class name.
Energy boundaries container class.
Definition: GEbounds.hpp:60
virtual ~GCTAResponseCube(void)
Destructor.
const GCTACubePsf & psf(void) const
Return cube analysis point spread function.
N-dimensional array class interface definition.
Abstract CTA cube analysis source base class definition.
GCTACubeBackground m_background
Background cube.
bool m_has_edisp
Flag to indicate if energy.
double psf_elliptical(const GModelSpatialElliptical *model, const double &rho_obs, const double &posangle_obs, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate Psf over elliptical model.
void free_members(void)
Delete class members.
const GCTACubeEdisp & edisp(void) const
Return cube analysis energy dispersion cube.
virtual GCTAResponseCube * clone(void) const
Clone instance.
virtual GEbounds ebounds(const GEnergy &obsEng) const
Return true energy boundaries for a specific observed energy.
CTA energy dispersion for stacked analysis.
GChatter
Definition: GTypemaps.hpp:33
virtual void clear(void)
Clear instance.
Abstract observation base class.
double psf_diffuse(const GModelSpatial *model, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate PSF over diffuse model.
CTA response abstract base class definition.
double irf_ptsrc(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to point source.
CTA instrument response function class.
CTA point spread function for cube analysis.
Definition: GCTACubePsf.hpp:62
Sky model class.
Definition: GModelSky.hpp:122
virtual bool use_tdisp(void) const
Signal if time dispersion will be used.
virtual bool is_valid(void) const
Signal if response is valid.
bool m_apply_edisp
Apply energy dispersion.
GCTACubeEdisp m_edisp
Energy dispersion cube.
virtual void read(const GXmlElement &xml)
Read response information from XML element.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return instrument response.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
Abstract spatial model base class.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const =0
Abstract radial spatial model base class.
GCTAResponseCube(void)
Void constructor.
Generic matrix class definition.
Definition: GMatrix.hpp:79
Vector class.
Definition: GVector.hpp:46
double irf_elliptical(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to elliptical source.
CTA cube analysis exposure class definition.
CTA observation class.
virtual bool apply_edisp(void) const
Signal if energy dispersion should be applied.
Class that handles gamma-ray sources.
Definition: GSource.hpp:53
Sky direction class.
Definition: GSkyDir.hpp:62
virtual double nroi(const GModelSky &model, const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return integral of event probability for a given sky model over ROI.
CTA cube analysis energy disperson class definition.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48