GammaLib 2.0.0
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 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 "GResponse.hpp"
32#include "GSkyMap.hpp"
33#include "GNodeArray.hpp"
34#include "GEbounds.hpp"
35#include "GFilename.hpp"
36
37/* __ Forward declaration ________________________________________________ */
38class GEvent;
39class GPhoton;
40class GEnergy;
41class GTime;
42class GSource;
43class GObservation;
44class GModelSky;
45class GEbounds;
46class GSPIObservation;
47class GSPIEventCube;
48class GSPIEventBin;
49
50/* __ Constants __________________________________________________________ */
51
52
53/***********************************************************************//**
54 * @class GSPIResponse
55 *
56 * @brief INTEGRAL/SPI instrument response function class
57 *
58 * The INTEGRAL/SPI instrument response function class defines the function
59 * that translates from physical quantities to measured quantities.
60 *
61 * @todo Complete the class description.
62 ***************************************************************************/
63class GSPIResponse : public GResponse {
64
65public:
66 // Constructors and destructors
67 GSPIResponse(void);
68 GSPIResponse(const GSPIResponse& rsp);
69 explicit GSPIResponse(const GFilename& rspname);
70 virtual ~GSPIResponse(void);
71
72 // Operators
73 virtual GSPIResponse& operator=(const GSPIResponse & rsp);
74
75 // Implement pure virtual base class methods
76 virtual void clear(void);
77 virtual GSPIResponse* clone(void) const;
78 virtual std::string classname(void) const;
79 virtual bool use_edisp(void) const;
80 virtual bool use_tdisp(void) const;
81 virtual double irf(const GEvent& event,
82 const GPhoton& photon,
83 const GObservation& obs) const;
84 virtual double nroi(const GModelSky& model,
85 const GEnergy& obsEng,
86 const GTime& obsTime,
87 const GObservation& obs) const;
88 virtual GEbounds ebounds(const GEnergy& obsEnergy) const;
89 virtual std::string print(const GChatter& chatter = NORMAL) const;
90
91 // Other Methods
92 void rspname(const GFilename& rspname);
93 const GFilename& rspname(void) const;
94 bool is_precomputed(void) const;
95 const double& energy_keV(void) const;
96 const double& dlogE(void) const;
97 const double& gamma(void) const;
98 void set(const GSPIObservation& obs,
99 const GEnergy& energy = GEnergy());
100 double irf_value(const GSkyDir& srcDir,
101 const GSPIEventBin& bin,
102 const int& ireg) const;
103 double zenith(const int& ipt, const GSkyDir& dir) const;
104 double azimuth(const int& ipt, const GSkyDir& dir) const;
105 void read(const GFits& fits);
106 void write(GFits& fits) const;
107 void load(const GFilename& filename);
108 void save(const GFilename& filename,
109 const bool& clobber = false) const;
110
111private:
112 // Private methods
113 void init_members(void);
114 void copy_members(const GSPIResponse& rsp);
115 void free_members(void);
116 void read_detids(const GFits& fits);
117 void read_energies(const GFits& fits);
118 void write_detids(GFits& fits) const;
119 void write_energies(GFits& fits) const;
120 void load_irfs(const int& region);
121 GSkyMap load_irf(const GFilename& rspname) const;
122 GSkyMap compute_irf(const double& emin, const double& emax) const;
123 void set_wcs(const GFitsImage* image);
124 void set_detids(const GSPIEventCube* cube);
125 void set_cache(const GSPIEventCube* cube);
126 int irf_detid(const int& detid) const;
127 double irf_weight(const double& beta,
128 const double& emin,
129 const double& emax) const;
130
131 // Private data members
132 GFilename m_rspname; //!< File name of response group
133 std::vector<int> m_detids; //!< Vector of detector IDs
134 GNodeArray m_energies; //!< Node array of IRF energies
135 GEbounds m_ebounds; //!< Energy bounaries of IRF
136 GSkyMap m_irfs; //!< IRFs stored as sky map
137 double m_energy_keV; //!< IRF line energy (optional)
138 double m_dlogE; //!< Logarithmic energy step for IRF band
139 double m_gamma; //!< Power-law spectral index for IRF band
140
141 // Private cache
142 std::vector<GSkyDir> m_spix; //!< SPI pointing direction
143 std::vector<double> m_posang; //!< Position angle of Y axis (CEL, radians)
144 mutable bool m_has_wcs; //!< Has WCS information
145 mutable double m_wcs_xmin; //!< Minimum X value (radians)
146 mutable double m_wcs_ymin; //!< Minimum Y value (radians)
147 mutable double m_wcs_xmax; //!< Maximum X value (radians)
148 mutable double m_wcs_ymax; //!< Maximum Y value (radians)
149 mutable double m_wcs_xbin; //!< X value bin size (radians)
150 mutable double m_wcs_ybin; //!< Y value bin size (radians)
151 mutable double m_wcs_xpix_max; //!< Maximum X pixel index
152 mutable double m_wcs_ypix_max; //!< Maximum Y pixel index
153 mutable double m_max_zenith; //!< Maximum zenith angle (radians)
154};
155
156
157/***********************************************************************//**
158 * @brief Return class name
159 *
160 * @return String containing the class name ("GSPIResponse").
161 ***************************************************************************/
162inline
163std::string GSPIResponse::classname(void) const
164{
165 return ("GSPIResponse");
166}
167
168
169/***********************************************************************//**
170 * @brief Signal if energy dispersion will be used
171 *
172 * @return False.
173 *
174 * @todo Implement method as needed.
175 ***************************************************************************/
176inline
178{
179 return false;
180}
181
182
183/***********************************************************************//**
184 * @brief Signal if time dispersion will be used
185 *
186 * @return False.
187 *
188 * @todo Implement method as needed.
189 ***************************************************************************/
190inline
192{
193 return false;
194}
195
196
197/***********************************************************************//**
198 * @brief Set response name
199 *
200 * @param[in] rspname Response group file name.
201 *
202 * Sets the response group file name.
203 ***************************************************************************/
204inline
206{
208 return;
209}
210
211
212/***********************************************************************//**
213 * @brief Get response group file name
214 *
215 * @return Response group file name.
216 *
217 * Returns the response group file name.
218 ***************************************************************************/
219inline
221{
222 return m_rspname;
223}
224
225
226/***********************************************************************//**
227 * @brief Signals if response is precomputed
228 *
229 * @return True if response is precomputed.
230 *
231 * Signals if the response was precomputed.
232 ***************************************************************************/
233inline
235{
236 return (!m_ebounds.is_empty());
237}
238
239
240/***********************************************************************//**
241 * @brief Return line IRF energy in keV
242 *
243 * @return Line IRF energy (keV).
244 *
245 * Returns the energy in keV for a line IRF. If the IRF is a continuum IRF
246 * the method returns 0.
247 ***************************************************************************/
248inline
249const double& GSPIResponse::energy_keV(void) const
250{
251 return (m_energy_keV);
252}
253
254
255/***********************************************************************//**
256 * @brief Return logarithmic step size for continuum IRFs
257 *
258 * @return Logarithmic step size for continuum IRFs.
259 *
260 * Returns the logarithmic step size for the computation of continuum IRFs.
261 ***************************************************************************/
262inline
263const double& GSPIResponse::dlogE(void) const
264{
265 return (m_dlogE);
266}
267
268
269/***********************************************************************//**
270 * @brief Return power-law index for continuum IRFs
271 *
272 * @return Power-law index for continuum IRFs.
273 *
274 * Returns the power-law index for the computation of continuum IRFs.
275 ***************************************************************************/
276inline
277const double& GSPIResponse::gamma(void) const
278{
279 return (m_gamma);
280}
281
282
283/***********************************************************************//**
284 * @brief Return zenith angle of sky direction for pointing in radians
285 *
286 * @param[in] ipt Pointing index.
287 * @param[in] dir Sky direction.
288 * @return Zenith angle (radians).
289 *
290 * Returns zenith angle of sky direction for pointing in radians.
291 ***************************************************************************/
292inline
293double GSPIResponse::zenith(const int& ipt, const GSkyDir& dir) const
294{
295 return (m_spix[ipt].dist(dir));
296}
297
298
299/***********************************************************************//**
300 * @brief Return azimuth angle of sky direction for pointing in radians
301 *
302 * @param[in] ipt Pointing index.
303 * @param[in] dir Sky direction.
304 * @return Azimuth angle (radians).
305 *
306 * Returns azimuth angle of sky direction for pointing in radians.
307 ***************************************************************************/
308inline
309double GSPIResponse::azimuth(const int& ipt, const GSkyDir& dir) const
310{
311 double azimuth = m_posang[ipt] - m_spix[ipt].posang(dir); // Celestial system
312 if (azimuth < 0.0) {
314 }
315 return (azimuth);
316}
317
318#endif /* GSPIRESPONSE_HPP */
Energy boundaries class interface definition.
Filename class interface definition.
Node array class interface definition.
Abstract response base class definition.
Sky map class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
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
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.
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.
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.
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)
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.
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
const double twopi
Definition GMath.hpp:36