GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
36 #include "GResponseVectorCache.hpp"
37 #include "GFunctions.hpp"
38 
39 /* __ Forward declarations _______________________________________________ */
40 class GVector;
41 class GMatrix;
42 class GMatrixSparse;
43 class GEvent;
44 class GPhoton;
45 class GSource;
46 class GSkyDir;
47 class GEnergy;
48 class GEbounds;
49 class GObservation;
50 class GModelPar;
51 class 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  ***************************************************************************/
77 class GResponse : public GBase {
78 
79 public:
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 
120 protected:
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 */
double m_irf_diffuse_resolution
Angular resolution for diffuse model.
Definition: GResponse.hpp:319
double eval(const double &phi)
Azimuth angle integration kernel for radial model.
Definition: GResponse.cpp:2114
bool m_use_irf_cache
Control usage of irf cache.
Definition: GResponse.hpp:313
double m_sin_theta
sin(theta)
Definition: GResponse.hpp:244
bool m_grad
Gradient flag.
Definition: GResponse.hpp:190
const GObservation * m_obs
Observation.
Definition: GResponse.hpp:184
const GMatrix * m_rot
Rotation matrix.
Definition: GResponse.hpp:304
Response vector cache class.
Abstract elliptical spatial model base class.
Sparse matrix class interface definition.
GResponse(void)
Void constructor.
Definition: GResponse.cpp:86
const GObservation * m_obs
Observation.
Definition: GResponse.hpp:271
int m_iter_phi
Iterations in phi.
Definition: GResponse.hpp:276
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const =0
const GObservation * m_obs
Observation.
Definition: GResponse.hpp:214
GVector cos(const GVector &vector)
Computes cosine of vector elements.
Definition: GVector.cpp:1190
virtual void remove_response_cache(const std::string &name)
Remove response cache for model.
Definition: GResponse.cpp:766
Abstract interface for the event classes.
Definition: GEvent.hpp:71
Definition of interface for all GammaLib classes.
const GMatrix * m_rot
Rotation matrix.
Definition: GResponse.hpp:273
virtual double irf_composite(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to composite source.
Definition: GResponse.cpp:1255
virtual void clear(void)=0
Clear object.
std::vector< GModelPar * > m_pars
Parameter pointers.
Definition: GResponse.hpp:188
double eval(const double &phi)
Azimuth angle integration kernel for elliptical model.
Definition: GResponse.cpp:2193
int m_irf_elliptical_iter_theta
Elliptical model integration theta iterations.
Definition: GResponse.hpp:317
double eval(const double &phi)
Zenith angle integration kernel for radial model.
Definition: GResponse.cpp:2060
const GObservation * m_obs
Observation.
Definition: GResponse.hpp:242
Time class.
Definition: GTime.hpp:55
void init_members(void)
Initialise class members.
Definition: GResponse.cpp:787
const GEvent * m_event
Event.
Definition: GResponse.hpp:186
const GEnergy * m_srcEng
True photon energy.
Definition: GResponse.hpp:217
virtual double irf_spatial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response integrated over the spatial model.
Definition: GResponse.cpp:596
GResponseVectorCache m_irf_vector_cache
Definition: GResponse.hpp:326
const GEvent * m_event
Event.
Definition: GResponse.hpp:213
GEbounds ebounds_model(const GModelSky &model) const
Return true energy intervals for sky model.
Definition: GResponse.cpp:1965
Response cache class definition.
Class that handles photons.
Definition: GPhoton.hpp:47
virtual double irf_elliptical(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to elliptical source.
Definition: GResponse.cpp:1015
const GEvent * m_event
Event.
Definition: GResponse.hpp:241
virtual double irf_diffuse(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to diffuse source.
Definition: GResponse.cpp:1118
Model parameter class.
Definition: GModelPar.hpp:87
int m_irf_elliptical_iter_phi
Elliptical model integration phi iterations.
Definition: GResponse.hpp:318
int size(void) const
Definition: GResponse.hpp:180
Single parameter functions abstract base class definition.
double eval(const double &phi)
Zenith angle integration kernel for elliptical model.
Definition: GResponse.cpp:2147
Energy boundaries container class.
Definition: GEbounds.hpp:60
Single parameter function abstract base class definition.
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)
Definition: GResponse.hpp:251
const GMatrix * m_rot
Rotation matrix.
Definition: GResponse.hpp:243
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
const GEnergy * m_srcEng
True photon energy.
Definition: GResponse.hpp:246
Response vector cache class definition.
const GResponse * m_parent
Response.
Definition: GResponse.hpp:183
bool m_use_nroi_cache
Control usage of nroi cache.
Definition: GResponse.hpp:314
virtual ~GResponse(void)
Destructor.
Definition: GResponse.cpp:117
virtual GEbounds ebounds(const GEnergy &obsEng) const =0
GChatter
Definition: GTypemaps.hpp:33
GResponseCache m_nroi_cache
Definition: GResponse.hpp:325
const GEvent * m_event
Event.
Definition: GResponse.hpp:301
const GEnergy * m_srcEng
True photon energy.
Definition: GResponse.hpp:274
double m_cos_theta
cos(theta)
Definition: GResponse.hpp:245
Abstract observation base class.
const GEnergy * m_srcEng
True photon energy.
Definition: GResponse.hpp:308
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)
Definition: GResponse.hpp:280
const GModelSpatialElliptical * m_model
Elliptical model.
Definition: GResponse.hpp:303
const GTime * m_srcTime
Arrival time.
Definition: GResponse.hpp:218
const GModelSpatialRadial * m_model
Radial model.
Definition: GResponse.hpp:215
void free_members(void)
Delete class members.
Definition: GResponse.cpp:835
virtual bool use_edisp(void) const =0
int m_irf_radial_iter_phi
Radial model integration phi iterations.
Definition: GResponse.hpp:316
virtual GResponse & operator=(const GResponse &rsp)
Assignment operator.
Definition: GResponse.cpp:139
virtual double irf_radial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to radial source.
Definition: GResponse.cpp:908
virtual double nroi(const GModelSky &model, const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const =0
int iter_phi(const double &rho, const double &resolution, const int &iter_min, const int &iter_max)
Determine number of azimuthal Romberg iterations.
int m_iter_phi
Iterations in phi.
Definition: GResponse.hpp:219
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.
Definition: GResponse.cpp:1891
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.
Definition: GResponse.cpp:1536
Sky model class.
Definition: GModelSky.hpp:122
const GObservation * m_obs
Observation.
Definition: GResponse.hpp:302
Single parameter function abstract base class.
Definition: GFunction.hpp:44
void copy_members(const GResponse &rsp)
Copy class members.
Definition: GResponse.cpp:813
virtual std::string print(const GChatter &chatter=NORMAL) const =0
Print content of object.
const GResponse * m_rsp
Response.
Definition: GResponse.hpp:300
virtual std::string classname(void) const =0
Return class name.
GVector sin(const GVector &vector)
Computes sine of vector elements.
Definition: GVector.cpp:1316
const GResponse * m_rsp
Response.
Definition: GResponse.hpp:269
int m_irf_radial_iter_theta
Radial model integration theta iterations.
Definition: GResponse.hpp:315
int size_edisp_vector(const GModelSky &model, const GObservation &obs, const bool &grad) const
Return size of vector for energy dispersion computation.
Definition: GResponse.cpp:1836
int m_size
Array of values and gradients.
Definition: GResponse.hpp:187
const GModelSky * m_model
Sky model.
Definition: GResponse.hpp:185
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)
Definition: GResponse.hpp:194
virtual double irf_ptsrc(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to point source.
Definition: GResponse.cpp:852
GResponseCache m_irf_cache
Definition: GResponse.hpp:324
const GResponse * m_rsp
Response.
Definition: GResponse.hpp:212
Abstract radial spatial model base class.
Generic matrix class definition.
Definition: GMatrix.hpp:79
Vector class.
Definition: GVector.hpp:46
GVector eval(const double &etrue)
Evaluate energy dispersion integration kernel.
Definition: GResponse.cpp:2012
Abstract instrument response base class.
Definition: GResponse.hpp:77
Response cache class.
Class that handles gamma-ray sources.
Definition: GSource.hpp:53
virtual bool use_tdisp(void) const =0
virtual double convolve(const GModelSky &model, const GEvent &event, const GObservation &obs, const bool &grad=true) const
Convolve sky model with the instrument response.
Definition: GResponse.cpp:186
const GTime * m_srcTime
Arrival time.
Definition: GResponse.hpp:247
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)
Definition: GResponse.hpp:223
Sky direction class.
Definition: GSkyDir.hpp:62
const GTime * m_srcTime
Arrival time.
Definition: GResponse.hpp:275
const GMatrix * m_rot
Rotation matrix.
Definition: GResponse.hpp:216
Time class interface definition.
GTime m_srcTime
True arrival time.
Definition: GResponse.hpp:189
const GResponse * m_rsp
Response.
Definition: GResponse.hpp:240
const GModelSpatialElliptical * m_model
Elliptical model.
Definition: GResponse.hpp:272
Single parameter functions abstract base class.
Definition: GFunctions.hpp:50
const GTime * m_srcTime
Arrival time.
Definition: GResponse.hpp:309
GVector eval_probs(const GModelSky &model, const GObservation &obs, GMatrixSparse *gradients=NULL) const
Convolve sky model with the instrument response.
Definition: GResponse.cpp:1674
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual GResponse * clone(void) const =0
Clones object.