GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
spi_helpers_response_vector.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * SPI helper classes for vector response *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2024 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 spi_helpers_response_vector.cpp
23 * @brief Implementation of SPI helper classes for vector response
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <cmath>
32#include "GVector.hpp"
33#include "GMatrix.hpp"
34#include "GIntegrals.hpp"
37#include "GSPIResponse.hpp"
39
40/* __ Method name definitions ____________________________________________ */
41
42/* __ Macros _____________________________________________________________ */
43
44/* __ Coding definitions _________________________________________________ */
45
46/* __ Debug definitions __________________________________________________ */
47
48/* __ Constants __________________________________________________________ */
49
50
51/*==========================================================================
52 = =
53 = Helper methods =
54 = =
55 ==========================================================================*/
56
57/***********************************************************************//**
58 * @brief Kernel for radial integration of radial models
59 *
60 * @param[in] rho Rho angle (radians).
61 * @return Azimuthally integrated radial model.
62 ***************************************************************************/
64{
65 // Set static model energy and time
66 static const GEnergy energy;
67 static const GTime time;
68
69 // Initialise kernel vector values to zero
70 m_irfs = 0.0;
71
72 // Continue only if rho is positive
73 if (rho > 0.0) {
74
75 // Compute radial model value
76 double model = m_radial->eval(rho, energy, time);
77
78 // Continue only if model is positive
79 if (model > 0.0) {
80
81 // Precompute cosine and sine terms for azimuthal integration
82 double sin_rho = std::sin(rho);
83 double cos_rho = std::cos(rho);
84
85 // Setup azimuthal integration kernel
87 m_rsp,
88 m_ipt,
90 m_rot,
91 sin_rho,
92 cos_rho,
93 m_irfs);
94
95 // Setup integrator
96 GIntegrals integral(&integrands);
97 integral.fixed_iter(m_iter);
98
99 // Integrate over Omega angle
100 m_irfs = integral.romberg(0.0, gammalib::twopi, m_iter) * model * sin_rho;
101
102 } // endif: radial model was positive
103
104 } // endif: phigeo was positive
105
106 // Return kernel values
107 return m_irfs;
108}
109
110
111/***********************************************************************//**
112 * @brief Kernel for azimuthal integration of radial models
113 *
114 * @param[in] omega Omega angle (radians).
115 * @return Kernel value for radial model.
116 ***************************************************************************/
118{
119 // Initialise kernel vector values to zero
120 m_irfs = 0.0;
121
122 // Set up native coordinate vector
123 double sin_omega = std::sin(omega);
124 double cos_omega = std::cos(omega);
125 GVector native(-cos_omega*m_sin_rho, sin_omega*m_sin_rho, m_cos_rho);
126
127 // Rotate vector into celestial coordinates
128 GVector vector = m_rot * native;
129
130 // Convert vector into sky direction
131 GSkyDir dir(vector);
132
133 // Convert sky direction to zenith angle (radians)
134 double zenith = m_rsp->zenith(m_ipt, dir);
135
136 // Continue only if zenith angle is smaller than the maximum zenith angle.
137 if (zenith < m_rsp->m_max_zenith) {
138
139 // Convert sky direction to azimuth angle (radians)
140 double azimuth = m_rsp->azimuth(m_ipt, dir);
141
142 // Compute pixel
143 double xpix = (zenith * std::cos(azimuth) - m_rsp->m_wcs_xmin) / m_rsp->m_wcs_xbin;
144 double ypix = (zenith * std::sin(azimuth) - m_rsp->m_wcs_ymin) / m_rsp->m_wcs_ybin;
145
146 // Continue only if pixel is within IRF
147 if (xpix > 0.0 && xpix < m_rsp->m_wcs_xpix_max &&
148 ypix > 0.0 && ypix < m_rsp->m_wcs_ypix_max) {
149
150 // Compute IRF values for this pointing (photo peak only)
151 m_rsp->irf_vector(m_cube, xpix, ypix, 0, m_livetimes, &m_irfs);
152
153 } // endif: pixel was within IRF
154
155 } // endif: zenith angle was within validity range
156
157 // Return kernel values
158 return m_irfs;
159}
160
161
162/***********************************************************************//**
163 * @brief Kernel for radial integration of elliptical models
164 *
165 * @param[in] rho Rho angle (radians).
166 * @return Azimuthally integrated elliptical model.
167 ***************************************************************************/
169{
170 // Initialise kernel vector values to zero
171 m_irfs = 0.0;
172
173 // Continue only if rho is positive
174 if (rho > 0.0) {
175
176 // Precompute cosine and sine terms for azimuthal integration
177 double sin_rho = std::sin(rho);
178 double cos_rho = std::cos(rho);
179
180 // Setup azimuthal integration kernel
182 m_rsp,
184 m_ipt,
186 m_rot,
187 rho,
188 sin_rho,
189 cos_rho,
190 m_irfs);
191
192 // Setup integrator
193 GIntegrals integral(&integrands);
194 integral.fixed_iter(m_iter);
195
196 // Integrate over Omega angle
197 m_irfs = integral.romberg(0.0, gammalib::twopi, m_iter) * sin_rho;
198
199 } // endif: phigeo was positive
200
201 // Return kernel values
202 return m_irfs;
203}
204
205
206/***********************************************************************//**
207 * @brief Kernel for azimuthal integration of elliptical models
208 *
209 * @param[in] omega Omega angle (radians).
210 * @return Kernel value for elliptical model.
211 ***************************************************************************/
213{
214 // Set static model energy and time
215 static const GEnergy energy;
216 static const GTime time;
217
218 // Initialise kernel vector values to zero
219 m_irfs = 0.0;
220
221 // Set up native coordinate vector
222 double sin_omega = std::sin(omega);
223 double cos_omega = std::cos(omega);
224 GVector native(-cos_omega*m_sin_rho, sin_omega*m_sin_rho, m_cos_rho);
225
226 // Rotate vector into celestial coordinates
227 GVector vector = m_rot * native;
228
229 // Convert vector into sky direction
230 GSkyDir dir(vector);
231
232 // Convert sky direction to zenith angle (radians)
233 double zenith = m_rsp->zenith(m_ipt, dir);
234
235 // Continue only if zenith angle is smaller than the maximum zenith angle.
236 if (zenith < m_rsp->m_max_zenith) {
237
238 // Convert sky direction to azimuth angle (radians)
239 double azimuth = m_rsp->azimuth(m_ipt, dir);
240
241 // Compute pixel
242 double xpix = (zenith * std::cos(azimuth) - m_rsp->m_wcs_xmin) / m_rsp->m_wcs_xbin;
243 double ypix = (zenith * std::sin(azimuth) - m_rsp->m_wcs_ymin) / m_rsp->m_wcs_ybin;
244
245 // Continue only if pixel is within IRF
246 if (xpix > 0.0 && xpix < m_rsp->m_wcs_xpix_max &&
247 ypix > 0.0 && ypix < m_rsp->m_wcs_ypix_max) {
248
249 // Compute radial model value
250 double model = m_elliptical->eval(m_rho, omega, energy, time);
251
252 // Continue only if model is positive
253 if (model > 0.0) {
254
255 // Compute IRF values for this pointing (photo peak only)
256 m_rsp->irf_vector(m_cube, xpix, ypix, 0, m_livetimes, &m_irfs);
257
258 // Multiply with model value
259 m_irfs *= model;
260
261 } // endif: model was positive
262
263 } // endif: pixel was within IRF
264
265 } // endif: zenith angle was within validity range
266
267 // Return kernel values
268 return m_irfs;
269}
Integration class for set of functions interface definition.
Generic matrix class definition.
Abstract elliptical spatial model base class interface definition.
Abstract radial spatial model base class interface definition.
INTEGRAL/SPI instrument response function class definition.
Vector class interface definition.
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Integration class for set of functions.
GVector romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void fixed_iter(const int &iter)
Set fixed number of iterations.
virtual double eval(const double &theta, const double &posangle, const GEnergy &energy, const GTime &time, const bool &gradients=false) const =0
virtual double eval(const double &theta, const GEnergy &energy, const GTime &time, const bool &gradients=false) const =0
double m_wcs_xbin
X value bin size (radians)
double m_wcs_ymin
Minimum Y value (radians)
double m_wcs_ybin
Y value bin size (radians)
double azimuth(const int &ipt, const GSkyDir &dir) const
Return azimuth angle of sky direction for pointing in radians.
double zenith(const int &ipt, const GSkyDir &dir) const
Return zenith angle of sky direction for pointing in radians.
void irf_vector(const GSPIEventCube *cube, const double &xpix, const double &ypix, const int &ireg, const double *livetimes, GVector *irf) const
Fill vector of INTEGRAL/SPI instrument response for IRF pixel.
double m_wcs_xmin
Minimum X value (radians)
Sky direction class.
Definition GSkyDir.hpp:62
Time class.
Definition GTime.hpp:55
Vector class.
Definition GVector.hpp:46
Kernel for azimuth angle integration of elliptical models.
const double & m_cos_rho
Cosine of Rho.
const GModelSpatialElliptical * m_elliptical
Elliptical spatial model.
const GSPIResponse * m_rsp
Pointer to response.
const GMatrix & m_rot
Rotation matrix.
const GSPIEventCube * m_cube
Pointer to event cube.
GVector & m_irfs
IRF vector to update.
const double * m_livetimes
Livetime array.
GVector eval(const double &omega)
Kernel for azimuthal integration of elliptical models.
GVector & m_irfs
IRF vector to update.
const double * m_livetimes
Livetime array.
const GSPIEventCube * m_cube
Pointer to event cube.
GVector eval(const double &omega)
Kernel for radial integration of elliptical models.
const int & m_iter
Number of azimuthal iterations.
const GMatrix & m_rot
Rotation matrix.
const GModelSpatialElliptical * m_elliptical
Elliptical spatial model.
const GSPIResponse * m_rsp
Pointer to response.
Kernel for azimuth angle integration of radial models.
const double & m_sin_rho
Sine of Rho.
GVector & m_irfs
IRF vector to update.
const double * m_livetimes
Livetime array.
const int & m_ipt
Pointing index.
const GMatrix & m_rot
Rotation matrix.
const GSPIResponse * m_rsp
Pointer to response.
const GSPIEventCube * m_cube
Pointer to event cube.
GVector eval(const double &omega)
Kernel for azimuthal integration of radial models.
const double & m_cos_rho
Cosine of Rho.
const int & m_ipt
Pointing index.
const int & m_iter
Number of azimuthal iterations.
const GSPIEventCube * m_cube
Pointer to event cube.
const double * m_livetimes
Livetime array.
GVector & m_irfs
IRF vector to update.
const GModelSpatialRadial * m_radial
Radial spatial model.
const GSPIResponse * m_rsp
Pointer to response.
GVector eval(const double &omega)
Kernel for radial integration of radial models.
const GMatrix & m_rot
Rotation matrix.
const double twopi
Definition GMath.hpp:36
Defintion of SPI helper classes for vector response.