GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 ________________________________________________ */
38 class GEvent;
39 class GPhoton;
40 class GEnergy;
41 class GTime;
42 class GSource;
43 class GObservation;
44 class GModelSky;
45 class GEbounds;
46 class GSPIObservation;
47 class GSPIEventCube;
48 class 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  ***************************************************************************/
63 class GSPIResponse : public GResponse {
64 
65 public:
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 
111 private:
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  ***************************************************************************/
162 inline
163 std::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  ***************************************************************************/
176 inline
177 bool GSPIResponse::use_edisp(void) const
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  ***************************************************************************/
190 inline
191 bool GSPIResponse::use_tdisp(void) const
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  ***************************************************************************/
204 inline
205 void GSPIResponse::rspname(const GFilename& rspname)
206 {
207  m_rspname = rspname;
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  ***************************************************************************/
219 inline
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  ***************************************************************************/
233 inline
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  ***************************************************************************/
248 inline
249 const 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  ***************************************************************************/
262 inline
263 const 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  ***************************************************************************/
276 inline
277 const 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  ***************************************************************************/
292 inline
293 double 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  ***************************************************************************/
308 inline
309 double 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) {
313  azimuth += gammalib::twopi;
314  }
315  return (azimuth);
316 }
317 
318 #endif /* GSPIRESPONSE_HPP */
Sky map class.
Definition: GSkyMap.hpp:89
double m_wcs_xmin
Minimum X value (radians)
double m_wcs_ymax
Maximum Y value (radians)
Abstract FITS image base class.
Definition: GFitsImage.hpp:43
double azimuth(const int &ipt, const GSkyDir &dir) const
Return azimuth angle of sky direction for pointing in radians.
virtual void clear(void)
Clear instance.
GSkyMap m_irfs
IRFs stored as sky map.
Node array class.
Definition: GNodeArray.hpp:60
void set_cache(const GSPIEventCube *cube)
Set computation cache.
double m_max_zenith
Maximum zenith angle (radians)
std::vector< GSkyDir > m_spix
SPI pointing direction.
virtual bool use_edisp(void) const
Signal if energy dispersion will be used.
double m_energy_keV
IRF line energy (optional)
Abstract interface for the event classes.
Definition: GEvent.hpp:71
virtual GEbounds ebounds(const GEnergy &obsEnergy) const
Return true energy boundaries for a specific observed energy.
virtual ~GSPIResponse(void)
Destructor.
const double & gamma(void) const
Return power-law index for continuum IRFs.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print INTEGRAL/SPI response information.
Time class.
Definition: GTime.hpp:55
void write_detids(GFits &fits) const
Write detector identifiers into FITS object.
FITS file class.
Definition: GFits.hpp:63
virtual std::string classname(void) const
Return class name.
double m_wcs_ybin
Y value bin size (radians)
Sky map class definition.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return value of INTEGRAL/SPI instrument response for a photon.
int irf_detid(const int &detid) const
Convert detector identifier into IRF detector identifier.
double m_dlogE
Logarithmic energy step for IRF band.
void write_energies(GFits &fits) const
Write energies into FITS object.
Class that handles photons.
Definition: GPhoton.hpp:47
void set_wcs(const GFitsImage *image)
Set IRF image limits.
INTEGRAL/SPI event bin container class.
virtual GSPIResponse * clone(void) const
Clone instance.
double zenith(const int &ipt, const GSkyDir &dir) const
Return zenith angle of sky direction for pointing in radians.
Node array class interface definition.
void read_detids(const GFits &fits)
Read detector identifiers from FITS object.
void copy_members(const GSPIResponse &rsp)
Copy class members.
Energy boundaries container class.
Definition: GEbounds.hpp:60
double m_wcs_xpix_max
Maximum X pixel index.
const GFilename & rspname(void) const
Get response group file name.
void set_detids(const GSPIEventCube *cube)
Set vector of detector identifiers used by the observation.
double m_wcs_xmax
Maximum X value (radians)
Filename class.
Definition: GFilename.hpp:62
void read_energies(const GFits &fits)
Read energies from FITS object.
double m_wcs_xbin
X value bin size (radians)
bool is_empty(void) const
Signal if there are no energy boundaries.
Definition: GEbounds.hpp:175
virtual GSPIResponse & operator=(const GSPIResponse &rsp)
Assignment operator.
std::vector< int > m_detids
Vector of detector IDs.
GSkyMap compute_irf(const double &emin, const double &emax) const
Compute as sky map.
double irf_weight(const double &beta, const double &emin, const double &emax) const
Compute weight of logarithmic energy bin.
void save(const GFilename &filename, const bool &clobber=false) const
Save SPI response into file.
void load_irfs(const int &region)
Load Instrument Response Functions.
GNodeArray m_energies
Node array of IRF energies.
double m_wcs_ymin
Minimum Y value (radians)
GChatter
Definition: GTypemaps.hpp:33
GSkyMap load_irf(const GFilename &rspname) const
Load IRF as sky map.
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. ...
Abstract observation base class.
double m_wcs_ypix_max
Maximum Y pixel index.
Abstract response base class definition.
std::vector< double > m_posang
Position angle of Y axis (CEL, radians)
INTEGRAL/SPI observation class.
bool is_precomputed(void) const
Signals if response is precomputed.
Sky model class.
Definition: GModelSky.hpp:122
GSPIResponse(void)
Void constructor.
const double & dlogE(void) const
Return logarithmic step size for continuum IRFs.
Energy boundaries class interface definition.
INTEGRAL/SPI event bin class.
void read(const GFits &fits)
Read SPI response from FITS object.
GFilename m_rspname
File name of response group.
GEbounds m_ebounds
Energy bounaries of IRF.
INTEGRAL/SPI instrument response function class.
double m_gamma
Power-law spectral index for IRF band.
bool m_has_wcs
Has WCS information.
virtual bool use_tdisp(void) const
Signal if time dispersion will be used.
const double twopi
Definition: GMath.hpp:36
void init_members(void)
Initialise class members.
void load(const GFilename &filename)
Load SPI response from file.
Abstract instrument response base class.
Definition: GResponse.hpp:77
Class that handles gamma-ray sources.
Definition: GSource.hpp:53
void write(GFits &fits) const
Write SPI response into FITS object.
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.
Sky direction class.
Definition: GSkyDir.hpp:62
void free_members(void)
Delete class members.
Filename class interface definition.
const double & energy_keV(void) const
Return line IRF energy in keV.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void set(const GSPIObservation &obs, const GEnergy &energy=GEnergy())
Set response for a specific observation.