GResponse.hpp
14.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
/***************************************************************************
* GResponse.hpp - Abstract response base class *
* ----------------------------------------------------------------------- *
* copyright (C) 2008-2020 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GResponse.hpp
* @brief Abstract response base class definition
* @author Juergen Knoedlseder
*/
#ifndef GRESPONSE_HPP
#define GRESPONSE_HPP
/* __ Includes ___________________________________________________________ */
#include <string>
#include "GBase.hpp"
#include "GFunction.hpp"
#include "GTime.hpp"
#include "GResponseCache.hpp"
/* __ Forward declarations _______________________________________________ */
class GMatrix;
class GEvent;
class GPhoton;
class GSource;
class GSkyDir;
class GEnergy;
class GEbounds;
class GObservation;
class GModelSky;
class GModelSpatialRadial;
class GModelSpatialElliptical;
/***********************************************************************//**
* @class GResponse
*
* @brief Abstract instrument response base class
*
* The response function provides conversion between physical parameters
* (such as source position, flux, ...) and the measured instrumental
* parameters (such as measured energy, photon interaction, ...).
*
* For a given observation, the irf method returns the instrument response
* for a given event and photon. An alternative method exists that returns
* the response for a specific source.
*
* The nroi method returns the spatial integral of the instrument response
* function times the sky model over the region of interest. This method is
* only required for unbinned analysis.
*
* The ebounds method returns the true energy boundaries for a specified
* measured event energy. This method is used for computing the energy
* dispersion.
***************************************************************************/
class GResponse : public GBase {
public:
// Constructors and destructors
GResponse(void);
GResponse(const GResponse& rsp);
virtual ~GResponse(void);
// Operators
virtual GResponse& operator=(const GResponse& rsp);
// Pure virtual methods
virtual void clear(void) = 0;
virtual GResponse* clone(void) const = 0;
virtual std::string classname(void) const = 0;
virtual bool use_edisp(void) const = 0;
virtual bool use_tdisp(void) const = 0;
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;
virtual GEbounds ebounds(const GEnergy& obsEng) const = 0;
virtual std::string print(const GChatter& chatter = NORMAL) const = 0;
// Virtual methods
virtual double convolve(const GModelSky& model,
const GEvent& event,
const GObservation& obs,
const bool& grad = true) const;
virtual double irf_spatial(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual void remove_response_cache(const std::string& name);
protected:
// Protected methods
void init_members(void);
void copy_members(const GResponse& rsp);
void free_members(void);
double eval_prob(const GModelSky& model,
const GEvent& event,
const GEnergy& srcEng,
const GTime& srcTime,
const GObservation& obs,
const bool& grad) const;
// Virtual protected methods
virtual bool use_source(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual double irf_ptsrc(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual double irf_radial(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual double irf_elliptical(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual double irf_diffuse(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
virtual double irf_composite(const GEvent& event,
const GSource& source,
const GObservation& obs) const;
// Protected classes
class edisp_kern : public GFunction {
public:
edisp_kern(const GResponse* parent,
const GObservation* obs,
const GModelSky* model,
const GEvent* event,
const GTime& srcTime,
const bool& grad) :
m_parent(parent),
m_obs(obs),
m_model(model),
m_event(event),
m_srcTime(srcTime),
m_grad(grad) { }
double eval(const double& etrue);
protected:
const GResponse* m_parent; //!< Response
const GObservation* m_obs; //!< Observation
const GModelSky* m_model; //!< Sky model
const GEvent* m_event; //!< Event
GTime m_srcTime; //!< True arrival time
bool m_grad; //!< Gradient flag
};
class irf_radial_kern_theta : public GFunction {
public:
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) :
m_rsp(rsp),
m_event(event),
m_obs(obs),
m_model(model),
m_rot(rot),
m_srcEng(srcEng),
m_srcTime(srcTime),
m_iter_phi(iter_phi) { }
double eval(const double& phi);
protected:
const GResponse* m_rsp; //!< Response
const GEvent* m_event; //!< Event
const GObservation* m_obs; //!< Observation
const GModelSpatialRadial* m_model; //!< Radial model
const GMatrix* m_rot; //!< Rotation matrix
const GEnergy* m_srcEng; //!< True photon energy
const GTime* m_srcTime; //!< Arrival time
int m_iter_phi; //!< Iterations in phi
};
class irf_radial_kern_phi : public GFunction {
public:
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) :
m_rsp(rsp),
m_event(event),
m_obs(obs),
m_rot(rot),
m_sin_theta(std::sin(theta)),
m_cos_theta(std::cos(theta)),
m_srcEng(srcEng),
m_srcTime(srcTime) { }
double eval(const double& phi);
protected:
const GResponse* m_rsp; //!< Response
const GEvent* m_event; //!< Event
const GObservation* m_obs; //!< Observation
const GMatrix* m_rot; //!< Rotation matrix
double m_sin_theta; //!< sin(theta)
double m_cos_theta; //!< cos(theta)
const GEnergy* m_srcEng; //!< True photon energy
const GTime* m_srcTime; //!< Arrival time
};
class irf_elliptical_kern_theta : public GFunction {
public:
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) :
m_rsp(rsp),
m_event(event),
m_obs(obs),
m_model(model),
m_rot(rot),
m_srcEng(srcEng),
m_srcTime(srcTime),
m_iter_phi(iter_phi) { }
double eval(const double& phi);
protected:
const GResponse* m_rsp; //!< Response
const GEvent* m_event; //!< Event
const GObservation* m_obs; //!< Observation
const GModelSpatialElliptical* m_model; //!< Elliptical model
const GMatrix* m_rot; //!< Rotation matrix
const GEnergy* m_srcEng; //!< True photon energy
const GTime* m_srcTime; //!< Arrival time
int m_iter_phi; //!< Iterations in phi
};
class irf_elliptical_kern_phi : public GFunction {
public:
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) :
m_rsp(rsp),
m_event(event),
m_obs(obs),
m_model(model),
m_rot(rot),
m_theta(theta),
m_sin_theta(std::sin(theta)),
m_cos_theta(std::cos(theta)),
m_srcEng(srcEng),
m_srcTime(srcTime) { }
double eval(const double& phi);
protected:
const GResponse* m_rsp; //!< Response
const GEvent* m_event; //!< Event
const GObservation* m_obs; //!< Observation
const GModelSpatialElliptical* m_model; //!< Elliptical model
const GMatrix* m_rot; //!< Rotation matrix
double m_theta; //!< Theta
double m_sin_theta; //!< sin(theta)
double m_cos_theta; //!< cos(theta)
const GEnergy* m_srcEng; //!< True photon energy
const GTime* m_srcTime; //!< Arrival time
};
// Protected members
bool m_use_irf_cache; //!< Control usage of irf cache
bool m_use_nroi_cache; //!< Control usage of nroi cache
int m_irf_radial_iter_theta; //!< Radial model integration theta iterations
int m_irf_radial_iter_phi; //!< Radial model integration phi iterations
int m_irf_elliptical_iter_theta; //!< Elliptical model integration theta iterations
int m_irf_elliptical_iter_phi; //!< Elliptical model integration phi iterations
double m_irf_diffuse_resolution; //!< Angular resolution for diffuse model
// Cache for irf(GEvent&, GSource&, GObservation&) and
// nroi(GModelSky&, GEnergy&, GTime&, GEnergy&, GTime&, GObservation&)
// computations
mutable GResponseCache m_irf_cache;
mutable GResponseCache m_nroi_cache;
};
#endif /* GRESPONSE_HPP */