GammaLib 2.0.0
Loading...
Searching...
No Matches
GResponse.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GResponse.hpp - Abstract response base class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2008-2021 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 GResponse.hpp
23 * @brief Abstract response base class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GRESPONSE_HPP
28#define GRESPONSE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GBase.hpp"
33#include "GFunction.hpp"
34#include "GTime.hpp"
35#include "GResponseCache.hpp"
37#include "GFunctions.hpp"
38
39/* __ Forward declarations _______________________________________________ */
40class GVector;
41class GMatrix;
42class GMatrixSparse;
43class GEvent;
44class GPhoton;
45class GSource;
46class GSkyDir;
47class GEnergy;
48class GEbounds;
49class GObservation;
50class GModelPar;
51class GModelSky;
54
55
56/***********************************************************************//**
57 * @class GResponse
58 *
59 * @brief Abstract instrument response base class
60 *
61 * The response function provides conversion between physical parameters
62 * (such as source position, flux, ...) and the measured instrumental
63 * parameters (such as measured energy, photon interaction, ...).
64 *
65 * For a given observation, the irf method returns the instrument response
66 * for a given event and photon. An alternative method exists that returns
67 * the response for a specific source.
68 *
69 * The nroi method returns the spatial integral of the instrument response
70 * function times the sky model over the region of interest. This method is
71 * only required for unbinned analysis.
72 *
73 * The ebounds method returns the true energy boundaries for a specified
74 * measured event energy. This method is used for computing the energy
75 * dispersion.
76 ***************************************************************************/
77class GResponse : public GBase {
78
79public:
80 // Constructors and destructors
81 GResponse(void);
82 GResponse(const GResponse& rsp);
83 virtual ~GResponse(void);
84
85 // Operators
86 virtual GResponse& operator=(const GResponse& rsp);
87
88 // Pure virtual methods
89 virtual void clear(void) = 0;
90 virtual GResponse* clone(void) const = 0;
91 virtual std::string classname(void) const = 0;
92 virtual bool use_edisp(void) const = 0;
93 virtual bool use_tdisp(void) const = 0;
94 virtual double irf(const GEvent& event,
95 const GPhoton& photon,
96 const GObservation& obs) const = 0;
97 virtual double nroi(const GModelSky& model,
98 const GEnergy& obsEng,
99 const GTime& obsTime,
100 const GObservation& obs) const = 0;
101 virtual GEbounds ebounds(const GEnergy& obsEng) const = 0;
102 virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
103
104 // Virtual methods
105 virtual double convolve(const GModelSky& model,
106 const GEvent& event,
107 const GObservation& obs,
108 const bool& grad = true) const;
109 virtual GVector convolve(const GModelSky& model,
110 const GObservation& obs,
111 GMatrixSparse* gradients = NULL) const;
112 virtual double irf_spatial(const GEvent& event,
113 const GSource& source,
114 const GObservation& obs) const;
115 virtual GVector irf_spatial(const GModelSky& model,
116 const GObservation& obs,
117 GMatrix* gradients = NULL) const;
118 virtual void remove_response_cache(const std::string& name);
119
120protected:
121 // Protected methods
122 void init_members(void);
123 void copy_members(const GResponse& rsp);
124 void free_members(void);
125 double eval_prob(const GModelSky& model,
126 const GEvent& event,
127 const GEnergy& srcEng,
128 const GTime& srcTime,
129 const GObservation& obs,
130 const bool& grad) const;
131 GVector eval_probs(const GModelSky& model,
132 const GObservation& obs,
133 GMatrixSparse* gradients = NULL) const;
134 int size_edisp_vector(const GModelSky& model,
135 const GObservation& obs,
136 const bool& grad) const;
137 GEbounds ebounds_model(const GModelSky& model) const;
138
139 // Virtual protected methods
140 virtual double irf_ptsrc(const GEvent& event,
141 const GSource& source,
142 const GObservation& obs) const;
143 virtual double irf_radial(const GEvent& event,
144 const GSource& source,
145 const GObservation& obs) const;
146 virtual double irf_elliptical(const GEvent& event,
147 const GSource& source,
148 const GObservation& obs) const;
149 virtual double irf_diffuse(const GEvent& event,
150 const GSource& source,
151 const GObservation& obs) const;
152 virtual double irf_composite(const GEvent& event,
153 const GSource& source,
154 const GObservation& obs) const;
155 virtual GVector irf_ptsrc(const GModelSky& model,
156 const GObservation& obs,
157 GMatrix* gradients = NULL) const;
158 virtual GVector irf_radial(const GModelSky& model,
159 const GObservation& obs,
160 GMatrix* gradients = NULL) const;
161 virtual GVector irf_elliptical(const GModelSky& model,
162 const GObservation& obs,
163 GMatrix* gradients = NULL) const;
164 virtual GVector irf_diffuse(const GModelSky& model,
165 const GObservation& obs,
166 GMatrix* gradients = NULL) const;
167 virtual GVector irf_composite(const GModelSky& model,
168 const GObservation& obs,
169 GMatrix* gradients = NULL) const;
170
171 // Protected classes
172 class edisp_kerns : public GFunctions {
173 public:
174 edisp_kerns(const GResponse* parent,
175 const GObservation* obs,
176 const GModelSky* model,
177 const GEvent* event,
178 const GTime& srcTime,
179 const bool& grad);
180 int size(void) const { return m_size; }
181 GVector eval(const double& etrue);
182 protected:
183 const GResponse* m_parent; //!< Response
184 const GObservation* m_obs; //!< Observation
185 const GModelSky* m_model; //!< Sky model
186 const GEvent* m_event; //!< Event
187 int m_size; //!< Array of values and gradients
188 std::vector<GModelPar*> m_pars; //!< Parameter pointers
189 GTime m_srcTime; //!< True arrival time
190 bool m_grad; //!< Gradient flag
191 };
193 public:
195 const GEvent* event,
196 const GObservation* obs,
197 const GModelSpatialRadial* model,
198 const GMatrix* rot,
199 const GEnergy* srcEng,
200 const GTime* srcTime,
201 int iter_phi) :
202 m_rsp(rsp),
203 m_event(event),
204 m_obs(obs),
205 m_model(model),
206 m_rot(rot),
207 m_srcEng(srcEng),
208 m_srcTime(srcTime),
209 m_iter_phi(iter_phi) { }
210 double eval(const double& phi);
211 protected:
212 const GResponse* m_rsp; //!< Response
213 const GEvent* m_event; //!< Event
214 const GObservation* m_obs; //!< Observation
215 const GModelSpatialRadial* m_model; //!< Radial model
216 const GMatrix* m_rot; //!< Rotation matrix
217 const GEnergy* m_srcEng; //!< True photon energy
218 const GTime* m_srcTime; //!< Arrival time
219 int m_iter_phi; //!< Iterations in phi
220 };
222 public:
224 const GEvent* event,
225 const GObservation* obs,
226 const GMatrix* rot,
227 const double& theta,
228 const GEnergy* srcEng,
229 const GTime* srcTime) :
230 m_rsp(rsp),
231 m_event(event),
232 m_obs(obs),
233 m_rot(rot),
234 m_sin_theta(std::sin(theta)),
235 m_cos_theta(std::cos(theta)),
236 m_srcEng(srcEng),
237 m_srcTime(srcTime) { }
238 double eval(const double& phi);
239 protected:
240 const GResponse* m_rsp; //!< Response
241 const GEvent* m_event; //!< Event
242 const GObservation* m_obs; //!< Observation
243 const GMatrix* m_rot; //!< Rotation matrix
244 double m_sin_theta; //!< sin(theta)
245 double m_cos_theta; //!< cos(theta)
246 const GEnergy* m_srcEng; //!< True photon energy
247 const GTime* m_srcTime; //!< Arrival time
248 };
250 public:
252 const GEvent* event,
253 const GObservation* obs,
254 const GModelSpatialElliptical* model,
255 const GMatrix* rot,
256 const GEnergy* srcEng,
257 const GTime* srcTime,
258 int iter_phi) :
259 m_rsp(rsp),
260 m_event(event),
261 m_obs(obs),
262 m_model(model),
263 m_rot(rot),
264 m_srcEng(srcEng),
265 m_srcTime(srcTime),
266 m_iter_phi(iter_phi) { }
267 double eval(const double& phi);
268 protected:
269 const GResponse* m_rsp; //!< Response
270 const GEvent* m_event; //!< Event
271 const GObservation* m_obs; //!< Observation
272 const GModelSpatialElliptical* m_model; //!< Elliptical model
273 const GMatrix* m_rot; //!< Rotation matrix
274 const GEnergy* m_srcEng; //!< True photon energy
275 const GTime* m_srcTime; //!< Arrival time
276 int m_iter_phi; //!< Iterations in phi
277 };
279 public:
281 const GEvent* event,
282 const GObservation* obs,
283 const GModelSpatialElliptical* model,
284 const GMatrix* rot,
285 const double& theta,
286 const GEnergy* srcEng,
287 const GTime* srcTime) :
288 m_rsp(rsp),
289 m_event(event),
290 m_obs(obs),
291 m_model(model),
292 m_rot(rot),
293 m_theta(theta),
294 m_sin_theta(std::sin(theta)),
295 m_cos_theta(std::cos(theta)),
296 m_srcEng(srcEng),
297 m_srcTime(srcTime) { }
298 double eval(const double& phi);
299 protected:
300 const GResponse* m_rsp; //!< Response
301 const GEvent* m_event; //!< Event
302 const GObservation* m_obs; //!< Observation
303 const GModelSpatialElliptical* m_model; //!< Elliptical model
304 const GMatrix* m_rot; //!< Rotation matrix
305 double m_theta; //!< Theta
306 double m_sin_theta; //!< sin(theta)
307 double m_cos_theta; //!< cos(theta)
308 const GEnergy* m_srcEng; //!< True photon energy
309 const GTime* m_srcTime; //!< Arrival time
310 };
311
312 // Protected members
313 bool m_use_irf_cache; //!< Control usage of irf cache
314 bool m_use_nroi_cache; //!< Control usage of nroi cache
315 int m_irf_radial_iter_theta; //!< Radial model integration theta iterations
316 int m_irf_radial_iter_phi; //!< Radial model integration phi iterations
317 int m_irf_elliptical_iter_theta; //!< Elliptical model integration theta iterations
318 int m_irf_elliptical_iter_phi; //!< Elliptical model integration phi iterations
319 double m_irf_diffuse_resolution; //!< Angular resolution for diffuse model
320
321 // Cache for irf(GEvent&, GSource&, GObservation&) and
322 // nroi(GModelSky&, GEnergy&, GTime&, GEnergy&, GTime&, GObservation&)
323 // computations
327};
328
329#endif /* GRESPONSE_HPP */
Definition of interface for all GammaLib classes.
Single parameter function abstract base class definition.
Single parameter functions abstract base class definition.
Response cache class definition.
Response vector cache class definition.
Time class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
GVector cos(const GVector &vector)
Computes cosine of vector elements.
Definition GVector.cpp:1190
GVector sin(const GVector &vector)
Computes sine of vector elements.
Definition GVector.cpp:1316
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Energy boundaries container class.
Definition GEbounds.hpp:60
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Abstract interface for the event classes.
Definition GEvent.hpp:71
Single parameter function abstract base class.
Definition GFunction.hpp:44
Single parameter functions abstract base class.
Sparse matrix class interface definition.
Generic matrix class definition.
Definition GMatrix.hpp:79
Model parameter class.
Definition GModelPar.hpp:87
Sky model class.
Abstract elliptical spatial model base class.
Abstract radial spatial model base class.
Abstract observation base class.
Class that handles photons.
Definition GPhoton.hpp:47
Response cache class.
Response vector cache class.
const GEvent * m_event
Event.
const GResponse * m_parent
Response.
std::vector< GModelPar * > m_pars
Parameter pointers.
int size(void) const
GVector eval(const double &etrue)
Evaluate energy dispersion integration kernel.
bool m_grad
Gradient flag.
int m_size
Array of values and gradients.
const GModelSky * m_model
Sky model.
edisp_kerns(const GResponse *parent, const GObservation *obs, const GModelSky *model, const GEvent *event, const GTime &srcTime, const bool &grad)
Constructor for energy dispersion integration kernels class.
GTime m_srcTime
True arrival time.
const GObservation * m_obs
Observation.
const GModelSpatialElliptical * m_model
Elliptical model.
const GResponse * m_rsp
Response.
const GTime * m_srcTime
Arrival time.
const GObservation * m_obs
Observation.
double eval(const double &phi)
Azimuth angle integration kernel for elliptical model.
const GEnergy * m_srcEng
True photon energy.
const GMatrix * m_rot
Rotation matrix.
irf_elliptical_kern_phi(const GResponse *rsp, const GEvent *event, const GObservation *obs, const GModelSpatialElliptical *model, const GMatrix *rot, const double &theta, const GEnergy *srcEng, const GTime *srcTime)
const GEnergy * m_srcEng
True photon energy.
const GTime * m_srcTime
Arrival time.
const GMatrix * m_rot
Rotation matrix.
const GModelSpatialElliptical * m_model
Elliptical model.
irf_elliptical_kern_theta(const GResponse *rsp, const GEvent *event, const GObservation *obs, const GModelSpatialElliptical *model, const GMatrix *rot, const GEnergy *srcEng, const GTime *srcTime, int iter_phi)
const GObservation * m_obs
Observation.
double eval(const double &phi)
Zenith angle integration kernel for elliptical model.
const GResponse * m_rsp
Response.
const GTime * m_srcTime
Arrival time.
const GObservation * m_obs
Observation.
const GEnergy * m_srcEng
True photon energy.
const GResponse * m_rsp
Response.
irf_radial_kern_phi(const GResponse *rsp, const GEvent *event, const GObservation *obs, const GMatrix *rot, const double &theta, const GEnergy *srcEng, const GTime *srcTime)
const GEvent * m_event
Event.
const GMatrix * m_rot
Rotation matrix.
double eval(const double &phi)
Azimuth angle integration kernel for radial model.
const GEnergy * m_srcEng
True photon energy.
double eval(const double &phi)
Zenith angle integration kernel for radial model.
const GMatrix * m_rot
Rotation matrix.
const GObservation * m_obs
Observation.
const GResponse * m_rsp
Response.
const GModelSpatialRadial * m_model
Radial model.
irf_radial_kern_theta(const GResponse *rsp, const GEvent *event, const GObservation *obs, const GModelSpatialRadial *model, const GMatrix *rot, const GEnergy *srcEng, const GTime *srcTime, int iter_phi)
int m_iter_phi
Iterations in phi.
const GEvent * m_event
Event.
const GTime * m_srcTime
Arrival time.
Abstract instrument response base class.
Definition GResponse.hpp:77
GResponseCache m_irf_cache
GVector eval_probs(const GModelSky &model, const GObservation &obs, GMatrixSparse *gradients=NULL) const
Convolve sky model with the instrument response.
virtual double irf_spatial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response integrated over the spatial model.
int m_irf_elliptical_iter_theta
Elliptical model integration theta iterations.
virtual void remove_response_cache(const std::string &name)
Remove response cache for model.
int m_irf_radial_iter_phi
Radial model integration phi iterations.
void copy_members(const GResponse &rsp)
Copy class members.
virtual ~GResponse(void)
Destructor.
virtual double irf_ptsrc(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to point source.
GResponseCache m_nroi_cache
double eval_prob(const GModelSky &model, const GEvent &event, const GEnergy &srcEng, const GTime &srcTime, const GObservation &obs, const bool &grad) const
Convolve sky model with the instrument response.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const =0
virtual double nroi(const GModelSky &model, const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const =0
GResponse(void)
Void constructor.
Definition GResponse.cpp:86
virtual double convolve(const GModelSky &model, const GEvent &event, const GObservation &obs, const bool &grad=true) const
Convolve sky model with the instrument response.
virtual std::string classname(void) const =0
Return class name.
virtual void clear(void)=0
Clear object.
virtual GResponse * clone(void) const =0
Clones object.
virtual double irf_radial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to radial source.
GEbounds ebounds_model(const GModelSky &model) const
Return true energy intervals for sky model.
int size_edisp_vector(const GModelSky &model, const GObservation &obs, const bool &grad) const
Return size of vector for energy dispersion computation.
int m_irf_elliptical_iter_phi
Elliptical model integration phi iterations.
bool m_use_nroi_cache
Control usage of nroi cache.
virtual GEbounds ebounds(const GEnergy &obsEng) const =0
virtual bool use_tdisp(void) const =0
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
virtual double irf_elliptical(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to elliptical source.
virtual double irf_diffuse(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to diffuse source.
virtual bool use_edisp(void) const =0
GResponseVectorCache m_irf_vector_cache
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
bool m_use_irf_cache
Control usage of irf cache.
virtual double irf_composite(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to composite source.
virtual GResponse & operator=(const GResponse &rsp)
Assignment operator.
double m_irf_diffuse_resolution
Angular resolution for diffuse model.
int m_irf_radial_iter_theta
Radial model integration theta iterations.
Sky direction class.
Definition GSkyDir.hpp:62
Class that handles gamma-ray sources.
Definition GSource.hpp:53
Time class.
Definition GTime.hpp:55
Vector class.
Definition GVector.hpp:46