GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GSPIResponse.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GSPIResponse.hpp - INTEGRAL/SPI response class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2020-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 GSPIResponse.hpp
23 * @brief INTEGRAL/SPI instrument response function class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GSPIRESPONSE_HPP
28#define GSPIRESPONSE_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <vector>
32#include "GNodeArray.hpp"
33#include "GFilename.hpp"
34#include "GVector.hpp"
35#include "GMatrix.hpp"
36#include "GEbounds.hpp"
37#include "GSkyDir.hpp"
38#include "GSkyMap.hpp"
39#include "GResponse.hpp"
40
41/* __ Forward declaration ________________________________________________ */
42class GEvent;
43class GPhoton;
44class GEnergy;
45class GTime;
46class GSource;
47class GObservation;
48class GModelSky;
50class GEbounds;
51class GSPIObservation;
52class GSPIEventCube;
53class GSPIEventBin;
54
55/* __ Type definitions ___________________________________________________ */
56typedef struct {
57 int nevents; // Number of events
58 int nirf; // Dimension of IRF
59 int nx; // Number of IRF pixels in x direction
60 int ny; // Number of IRF pixels in y direction
61 int nxy; // Number of IRF pixels
62 int ndet; // Number of detectors
63 int nreg; // Number of IRF regions
64 int ireg; // IRF region (0 = photopeak)
65 std::vector<int> detids; // Vector of detector IDs
66 std::vector<bool> zero; // Vector of IRF pixel usage
67 GVector zeniths; // Zenith angles for all IRF pixels
68 GVector sin_zeniths; // Sine of zenith angles for all IRF pixels
69 GVector cos_zeniths; // Cosine of zenith angles for all IRF pixels
70 GVector azimuths; // Azimuth angles for all IRF pixels
71 GVector solidangle; // Solid angles for all IRF pixels
72 GMatrix rot; // Current rotation matrix
73 GSkyDir dir; // Current sky direction of IRF pixel
75
76/* __ Constants __________________________________________________________ */
77
78
79/***********************************************************************//**
80 * @class GSPIResponse
81 *
82 * @brief INTEGRAL/SPI instrument response function class
83 *
84 * The INTEGRAL/SPI instrument response function class defines the function
85 * that translates from physical quantities to measured quantities.
86 *
87 * @todo Complete the class description.
88 ***************************************************************************/
89class GSPIResponse : public GResponse {
90
91 // Friends
96
97public:
98 // Constructors and destructors
99 GSPIResponse(void);
100 GSPIResponse(const GSPIResponse& rsp);
101 explicit GSPIResponse(const GFilename& rspname);
102 virtual ~GSPIResponse(void);
103
104 // Operators
105 virtual GSPIResponse& operator=(const GSPIResponse & rsp);
106
107 // Implement pure virtual base class methods
108 virtual void clear(void);
109 virtual GSPIResponse* clone(void) const;
110 virtual std::string classname(void) const;
111 virtual bool use_edisp(void) const;
112 virtual bool use_tdisp(void) const;
113 virtual double irf(const GEvent& event,
114 const GPhoton& photon,
115 const GObservation& obs) const;
116 virtual double nroi(const GModelSky& model,
117 const GEnergy& obsEng,
118 const GTime& obsTime,
119 const GObservation& obs) const;
120 virtual GEbounds ebounds(const GEnergy& obsEnergy) const;
121 virtual std::string print(const GChatter& chatter = NORMAL) const;
122
123 // Other Methods
124 void rspname(const GFilename& rspname);
125 const GFilename& rspname(void) const;
126 bool is_precomputed(void) const;
127 const double& energy_keV(void) const;
128 const double& dlogE(void) const;
129 const double& gamma(void) const;
130 void set(const GSPIObservation& obs,
131 const GEnergy& energy = GEnergy());
132 double irf_value(const GSkyDir& srcDir,
133 const GSPIEventBin& bin,
134 const int& ireg) const;
135 double zenith(const int& ipt, const GSkyDir& dir) const;
136 double azimuth(const int& ipt, const GSkyDir& dir) const;
137 void read(const GFits& fits);
138 void write(GFits& fits) const;
139 void load(const GFilename& filename);
140 void save(const GFilename& filename,
141 const bool& clobber = false) const;
142
143private:
144 // Private methods
145 void init_members(void);
146 void copy_members(const GSPIResponse& rsp);
147 void free_members(void);
148 void read_detids(const GFits& fits);
149 void read_energies(const GFits& fits);
150 void write_detids(GFits& fits) const;
151 void write_energies(GFits& fits) const;
152 void load_irfs(const int& region);
153 GSkyMap load_irf(const GFilename& rspname) const;
154 GSkyMap compute_irf(const double& emin, const double& emax) const;
155 void set_wcs(const GFitsImage* image);
156 void set_detids(const GSPIEventCube* cube);
157 void set_cache(const GSPIEventCube* cube);
158 void irf_vector(const GSPIEventCube* cube,
159 const double& xpix,
160 const double& ypix,
161 const int& ireg,
162 const double* livetimes,
163 GVector* irf) const;
164 int irf_detid(const int& detid) const;
165 double irf_weight(const double& beta,
166 const double& emin,
167 const double& emax) const;
168 void irf_diffuse_map(const GModelSpatialDiffuseMap* diffuse,
169 const GObservation& obs,
170 GVector* irfs,
171 GMatrix* gradients = NULL) const;
172 void irf_init(const GObservation& obs, GSPIResponseIrf* irf) const;
173 void irf_rot_matrix(const int& ipt,
174 GSPIResponseIrf* irf) const;
175 void irf_skydir(const int& ipt,
176 const int& inx,
177 GSPIResponseIrf* irf) const;
178 int irf_map(const int& idet,
179 const int& ieng,
180 const GSPIResponseIrf* irf) const;
181
182 // Overloaded virtual base class methods
183 virtual GVector irf_ptsrc(const GModelSky& model,
184 const GObservation& obs,
185 GMatrix* gradients = NULL) const;
186 virtual GVector irf_radial(const GModelSky& model,
187 const GObservation& obs,
188 GMatrix* gradients = NULL) const;
189 virtual GVector irf_elliptical(const GModelSky& model,
190 const GObservation& obs,
191 GMatrix* gradients = NULL) const;
192 virtual GVector irf_diffuse(const GModelSky& model,
193 const GObservation& obs,
194 GMatrix* gradients = NULL) const;
195
196 // Private data members
197 GFilename m_rspname; //!< File name of response group
198 std::vector<int> m_detids; //!< Vector of detector IDs
199 GNodeArray m_energies; //!< Node array of IRF energies
200 GEbounds m_ebounds; //!< Energy bounaries of IRF
201 GSkyMap m_irfs; //!< IRFs stored as sky map
202 double m_energy_keV; //!< IRF line energy (optional)
203 double m_dlogE; //!< Logarithmic energy step for IRF band
204 double m_gamma; //!< Power-law spectral index for IRF band
205
206 // Private cache
207 std::vector<GSkyDir> m_spix; //!< SPI pointing direction
208 std::vector<double> m_posang; //!< Position angle of Y axis (CEL, radians)
209 mutable bool m_has_wcs; //!< Has WCS information
210 mutable double m_wcs_xmin; //!< Minimum X value (radians)
211 mutable double m_wcs_ymin; //!< Minimum Y value (radians)
212 mutable double m_wcs_xmax; //!< Maximum X value (radians)
213 mutable double m_wcs_ymax; //!< Maximum Y value (radians)
214 mutable double m_wcs_xbin; //!< X value bin size (radians)
215 mutable double m_wcs_ybin; //!< Y value bin size (radians)
216 mutable double m_wcs_xpix_max; //!< Maximum X pixel index
217 mutable double m_wcs_ypix_max; //!< Maximum Y pixel index
218 mutable double m_max_zenith; //!< Maximum zenith angle (radians)
219};
220
221
222/***********************************************************************//**
223 * @brief Return class name
224 *
225 * @return String containing the class name ("GSPIResponse").
226 ***************************************************************************/
227inline
228std::string GSPIResponse::classname(void) const
229{
230 return ("GSPIResponse");
231}
232
233
234/***********************************************************************//**
235 * @brief Signal if energy dispersion will be used
236 *
237 * @return False.
238 *
239 * @todo Implement method as needed.
240 ***************************************************************************/
241inline
243{
244 return false;
245}
246
247
248/***********************************************************************//**
249 * @brief Signal if time dispersion will be used
250 *
251 * @return False.
252 *
253 * @todo Implement method as needed.
254 ***************************************************************************/
255inline
257{
258 return false;
259}
260
261
262/***********************************************************************//**
263 * @brief Set response name
264 *
265 * @param[in] rspname Response group file name.
266 *
267 * Sets the response group file name.
268 ***************************************************************************/
269inline
271{
273 return;
274}
275
276
277/***********************************************************************//**
278 * @brief Get response group file name
279 *
280 * @return Response group file name.
281 *
282 * Returns the response group file name.
283 ***************************************************************************/
284inline
286{
287 return m_rspname;
288}
289
290
291/***********************************************************************//**
292 * @brief Signals if response is precomputed
293 *
294 * @return True if response is precomputed.
295 *
296 * Signals if the response was precomputed.
297 ***************************************************************************/
298inline
300{
301 return (!m_ebounds.is_empty());
302}
303
304
305/***********************************************************************//**
306 * @brief Return line IRF energy in keV
307 *
308 * @return Line IRF energy (keV).
309 *
310 * Returns the energy in keV for a line IRF. If the IRF is a continuum IRF
311 * the method returns 0.
312 ***************************************************************************/
313inline
314const double& GSPIResponse::energy_keV(void) const
315{
316 return (m_energy_keV);
317}
318
319
320/***********************************************************************//**
321 * @brief Return logarithmic step size for continuum IRFs
322 *
323 * @return Logarithmic step size for continuum IRFs.
324 *
325 * Returns the logarithmic step size for the computation of continuum IRFs.
326 ***************************************************************************/
327inline
328const double& GSPIResponse::dlogE(void) const
329{
330 return (m_dlogE);
331}
332
333
334/***********************************************************************//**
335 * @brief Return power-law index for continuum IRFs
336 *
337 * @return Power-law index for continuum IRFs.
338 *
339 * Returns the power-law index for the computation of continuum IRFs.
340 ***************************************************************************/
341inline
342const double& GSPIResponse::gamma(void) const
343{
344 return (m_gamma);
345}
346
347
348/***********************************************************************//**
349 * @brief Return zenith angle of sky direction for pointing in radians
350 *
351 * @param[in] ipt Pointing index.
352 * @param[in] dir Sky direction.
353 * @return Zenith angle (radians).
354 *
355 * Returns zenith angle of sky direction for pointing in radians.
356 ***************************************************************************/
357inline
358double GSPIResponse::zenith(const int& ipt, const GSkyDir& dir) const
359{
360 return (m_spix[ipt].dist(dir));
361}
362
363
364/***********************************************************************//**
365 * @brief Return azimuth angle of sky direction for pointing in radians
366 *
367 * @param[in] ipt Pointing index.
368 * @param[in] dir Sky direction.
369 * @return Azimuth angle (radians).
370 *
371 * Returns azimuth angle of sky direction for pointing in radians.
372 ***************************************************************************/
373inline
374double GSPIResponse::azimuth(const int& ipt, const GSkyDir& dir) const
375{
376 double azimuth = m_posang[ipt] - m_spix[ipt].posang(dir); // Celestial system
377 if (azimuth < 0.0) {
379 }
380 return (azimuth);
381}
382
383
384/***********************************************************************//**
385 * @brief Return map index for detector and energy index
386 *
387 * @param[in] idet Detector index.
388 * @param[in] ieng Energy index.
389 * @param[in] irf Stucture for projection computation of response.
390 * @return Map index.
391 *
392 * Returns the map index for a specific detector index @p idet and energy
393 * index @p ieng.
394 *
395 * The client needs to make sure that the indices are comprised within the
396 * valid ranges and that the GSPIResponse::irf_init() method was called
397 * prior to invoking this method.
398 ***************************************************************************/
399inline
400int GSPIResponse::irf_map(const int& idet,
401 const int& ieng,
402 const GSPIResponseIrf* irf) const
403{
404 // Get IRF map index
405 int map = irf->detids[idet] + (irf->ireg + ieng * irf->nreg) * irf->ndet;
406
407 // Return map index
408 return map;
409}
410
411#endif /* GSPIRESPONSE_HPP */
Energy boundaries class interface definition.
Filename class interface definition.
Generic matrix class definition.
Node array class interface definition.
Abstract response base class definition.
Sky direction class interface definition.
Sky map class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Vector class interface definition.
Energy boundaries container class.
Definition GEbounds.hpp:60
bool is_empty(void) const
Signal if there are no energy boundaries.
Definition GEbounds.hpp:175
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Abstract interface for the event classes.
Definition GEvent.hpp:71
Filename class.
Definition GFilename.hpp:62
Abstract FITS image base class.
FITS file class.
Definition GFits.hpp:63
Generic matrix class definition.
Definition GMatrix.hpp:79
Sky model class.
Node array class.
Abstract observation base class.
Class that handles photons.
Definition GPhoton.hpp:47
Abstract instrument response base class.
Definition GResponse.hpp:77
INTEGRAL/SPI event bin class.
INTEGRAL/SPI event bin container class.
INTEGRAL/SPI observation class.
INTEGRAL/SPI instrument response function class.
void irf_init(const GObservation &obs, GSPIResponseIrf *irf) const
Initialise structure for projection computation of response.
double m_wcs_xpix_max
Maximum X pixel index.
void set_detids(const GSPIEventCube *cube)
Set vector of detector identifiers used by the observation.
virtual std::string classname(void) const
Return class name.
virtual GSPIResponse & operator=(const GSPIResponse &rsp)
Assignment operator.
const double & gamma(void) const
Return power-law index for continuum IRFs.
const double & dlogE(void) const
Return logarithmic step size for continuum IRFs.
void write(GFits &fits) const
Write SPI response into FITS object.
int irf_map(const int &idet, const int &ieng, const GSPIResponseIrf *irf) const
Return map index for detector and energy index.
void irf_skydir(const int &ipt, const int &inx, GSPIResponseIrf *irf) const
Set sky direction for pointing and IRF pixel index.
virtual GVector irf_radial(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to radial source sky model.
virtual GVector irf_ptsrc(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to point source sky model.
virtual GVector irf_elliptical(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to elliptical source sky model.
double m_wcs_xbin
X value bin size (radians)
void save(const GFilename &filename, const bool &clobber=false) const
Save SPI response into file.
GSkyMap m_irfs
IRFs stored as sky map.
GNodeArray m_energies
Node array of IRF energies.
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.
double irf_weight(const double &beta, const double &emin, const double &emax) const
Compute weight of logarithmic energy bin.
double m_wcs_ymin
Minimum Y value (radians)
virtual std::string print(const GChatter &chatter=NORMAL) const
Print INTEGRAL/SPI response information.
double m_wcs_ybin
Y value bin size (radians)
void set_wcs(const GFitsImage *image)
Set IRF image limits.
double irf_value(const GSkyDir &srcDir, const GSPIEventBin &bin, const int &ireg) const
Return value of INTEGRAL/SPI instrument response for sky direction and event bin.
void read(const GFits &fits)
Read SPI response from FITS object.
GSkyMap compute_irf(const double &emin, const double &emax) const
Compute as sky map.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return value of INTEGRAL/SPI instrument response for a photon.
GSkyMap load_irf(const GFilename &rspname) const
Load IRF as sky map.
std::vector< GSkyDir > m_spix
SPI pointing direction.
double m_dlogE
Logarithmic energy step for IRF band.
virtual bool use_edisp(void) const
Signal if energy dispersion will be used.
void write_detids(GFits &fits) const
Write detector identifiers into FITS object.
void init_members(void)
Initialise class members.
virtual ~GSPIResponse(void)
Destructor.
double azimuth(const int &ipt, const GSkyDir &dir) const
Return azimuth angle of sky direction for pointing in radians.
void copy_members(const GSPIResponse &rsp)
Copy class members.
std::vector< int > m_detids
Vector of detector IDs.
virtual GVector irf_diffuse(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to diffuse source sky model.
void free_members(void)
Delete class members.
GFilename m_rspname
File name of response group.
void write_energies(GFits &fits) const
Write energies into FITS object.
void load(const GFilename &filename)
Load SPI response from file.
double m_wcs_ypix_max
Maximum Y pixel index.
double m_gamma
Power-law spectral index for IRF band.
void read_detids(const GFits &fits)
Read detector identifiers from FITS object.
void set_cache(const GSPIEventCube *cube)
Set computation cache.
int irf_detid(const int &detid) const
Convert detector identifier into IRF detector identifier.
double zenith(const int &ipt, const GSkyDir &dir) const
Return zenith angle of sky direction for pointing in radians.
double m_wcs_xmax
Maximum X value (radians)
bool is_precomputed(void) const
Signals if response is precomputed.
double m_wcs_ymax
Maximum Y value (radians)
void irf_rot_matrix(const int &ipt, GSPIResponseIrf *irf) const
Set rotation matrix for pointing.
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.
virtual GSPIResponse * clone(void) const
Clone instance.
double m_wcs_xmin
Minimum X value (radians)
double m_energy_keV
IRF line energy (optional)
GEbounds m_ebounds
Energy bounaries of IRF.
double m_max_zenith
Maximum zenith angle (radians)
void read_energies(const GFits &fits)
Read energies from FITS object.
GSPIResponse(void)
Void constructor.
virtual void clear(void)
Clear instance.
const GFilename & rspname(void) const
Get response group file name.
const double & energy_keV(void) const
Return line IRF energy in keV.
bool m_has_wcs
Has WCS information.
virtual GEbounds ebounds(const GEnergy &obsEnergy) const
Return true energy boundaries for a specific observed energy.
void set(const GSPIObservation &obs, const GEnergy &energy=GEnergy())
Set response for a specific observation.
virtual bool use_tdisp(void) const
Signal if time dispersion will be used.
std::vector< double > m_posang
Position angle of Y axis (CEL, radians)
void load_irfs(const int &region)
Load Instrument Response Functions.
void irf_diffuse_map(const GModelSpatialDiffuseMap *diffuse, const GObservation &obs, GVector *irfs, GMatrix *gradients=NULL) const
Return instrument response to diffuse map sky model.
Sky direction class.
Definition GSkyDir.hpp:62
Sky map class.
Definition GSkyMap.hpp:89
Class that handles gamma-ray sources.
Definition GSource.hpp:53
Time class.
Definition GTime.hpp:55
Vector class.
Definition GVector.hpp:46
Kernel for azimuth angle integration of elliptical models.
Kernel for rho angle integration of elliptical models.
Kernel for azimuth angle integration of radial models.
Kernel for rho angle integration of radial models.
const double twopi
Definition GMath.hpp:36
std::vector< int > detids
std::vector< bool > zero