GammaLib  1.7.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GRmf.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GRmf.hpp - XSPEC Redistribution Matrix File class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2013-2018 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 GRmf.hpp
23  * @brief XSPEC Redistribution Matrix File class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GRMF_HPP
28 #define GRMF_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 #include "GFilename.hpp"
34 #include "GEbounds.hpp"
35 #include "GMatrixSparse.hpp"
36 #include "GFitsHeader.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GFits;
40 class GFitsTable;
41 
42 /* __ Constants __________________________________________________________ */
43 namespace gammalib {
44  const std::string extname_rmf = "MATRIX";
45 }
46 
47 
48 /***********************************************************************//**
49  * @class GRmf
50  *
51  * @brief Redistribution Matrix File class
52  *
53  * Matrix rows are true energy, columns are channels
54  ***************************************************************************/
55 class GRmf : public GBase {
56 
57  // Operator friends
58  friend GRmf operator+(const GRmf& a, const GRmf& b);
59  friend GRmf operator-(const GRmf& a, const GRmf& b);
60  friend GRmf operator*(const GRmf& rmf, const double& scale);
61  friend GRmf operator*(const double& scale, const GRmf& rmf);
62  friend GRmf operator/(const GRmf& rmf, const double& scale);
63 
64 public:
65  // Constructors and destructors
66  GRmf(void);
67  explicit GRmf(const GFilename& filename);
68  GRmf(const GEbounds& etrue, const GEbounds& emeasured);
69  GRmf(const GRmf& rmf);
70  virtual ~GRmf(void);
71 
72  // Operators
73  GRmf& operator=(const GRmf& rmf);
74  GRmf& operator+=(const GRmf& rmf);
75  GRmf& operator-=(const GRmf& rmf);
76  GRmf& operator*=(const double& scale);
77  GRmf& operator/=(const double& scale);
78  double& operator()(const int& itrue, const int& imeasured);
79  const double& operator()(const int& itrue, const int& imeasured) const;
80 
81  // Methods
82  void clear(void);
83  GRmf* clone(void) const;
84  std::string classname(void) const;
85  int size(void) const;
86  int ntrue(void) const;
87  int nmeasured(void) const;
88  int itruemax(void) const;
89  int imeasmax(void) const;
90  double& at(const int& itrue, const int& imeasured);
91  const double& at(const int& itrue, const int& imeasured) const;
92  const GEbounds& etrue(void) const;
93  const GEbounds& emeasured(void) const;
94  GEbounds etrue(const GEnergy& emeasured) const;
95  GEbounds emeasured(const GEnergy& etrue) const;
96  const GMatrixSparse& matrix(void) const;
97  void load(const GFilename& filename);
98  void save(const GFilename& filename,
99  const bool& clobber = false,
100  const std::string& unit = "keV") const;
101  void read(const GFits& fits);
102  void read(const GFitsTable& table);
103  void write(GFits& fits,
104  const std::string& unit = "keV") const;
105  const GFilename& filename(void) const;
106  const GFitsHeader& header(void) const;
107  void header(const GFitsHeader& header);
108  std::string print(const GChatter& chatter = NORMAL) const;
109 
110 protected:
111  // Protected methods
112  void init_members(void);
113  void copy_members(const GRmf& rmf);
114  void free_members(void);
115 
116  // Protected members
117  mutable GFilename m_filename; //!< Filename of origin
118  GEbounds m_ebds_true; //!< True energy boundaries
119  GEbounds m_ebds_measured; //!< Measured energy boundaries
120  GMatrixSparse m_matrix; //!< Sparse redistribution matrix
121  int m_imeasmax; //!< Index of measured maximum
122  int m_itruemax; //!< Index of true maximum
123  GFitsHeader m_header; //!< FITS header cards
124 };
125 
126 
127 /***********************************************************************//**
128  * @brief Return class name
129  *
130  * @return String containing the class name ("GRmf").
131  ***************************************************************************/
132 inline
133 std::string GRmf::classname(void) const
134 {
135  return ("GRmf");
136 }
137 
138 
139 /***********************************************************************//**
140  * @brief Return content of redistribution matrix bin
141  *
142  * @param[in] itrue True energy index [0,...,ntrue()-1].
143  * @param[in] imeasured Measured energy index [0,...,nmeasured()-1].
144  *
145  * Returns reference to content of redistribution matrix bin bin with true
146  * energy index @p itrue and measured energy index @p imeasured.
147  ***************************************************************************/
148 inline
149 double& GRmf::operator()(const int& itrue, const int& imeasured)
150 {
151  return (m_matrix(itrue, imeasured));
152 }
153 
154 
155 /***********************************************************************//**
156  * @brief Return content of redistribution matrix bin (const version)
157  *
158  * @param[in] itrue True energy index [0,...,ntrue()-1].
159  * @param[in] imeasured Measured energy index [0,...,nmeasured()-1].
160  *
161  * Returns reference to content of redistribution matrix bin bin with true
162  * energy index @p itrue and measured energy index @p imeasured.
163  ***************************************************************************/
164 inline
165 const double& GRmf::operator()(const int& itrue, const int& imeasured) const
166 {
167  return (m_matrix(itrue, imeasured));
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Return number of redistribution matrix bins
173  *
174  * @return Number of redistribution matrix bins.
175  *
176  * Returns the number of redistribution matrix bins.
177  ***************************************************************************/
178 inline
179 int GRmf::size(void) const
180 {
181  return (m_matrix.rows()*m_matrix.columns());
182 }
183 
184 
185 /***********************************************************************//**
186  * @brief Return number of true energy bins in redistribution matrix
187  *
188  * @return Number true energy bins in redistribution matrix.
189  *
190  * Returns the number of true energy bins in redistribution matrix.
191  ***************************************************************************/
192 inline
193 int GRmf::ntrue(void) const
194 {
195  return (m_matrix.rows());
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Return number of measured energy bins in redistribution matrix
201  *
202  * @return Number measured energy bins in redistribution matrix.
203  *
204  * Returns the number of measured energy bins in redistribution matrix.
205  ***************************************************************************/
206 inline
207 int GRmf::nmeasured(void) const
208 {
209  return (m_matrix.columns());
210 }
211 
212 
213 
214 
215 /***********************************************************************//**
216  * @brief Return true energy index of maximum value of the redistribution matrix
217  *
218  * @return True energy index of maximum value of the redistribution matrix.
219  *
220  * Returns the true energy index of maximum value of the redistribution matrix.
221  ***************************************************************************/
222 inline
223 int GRmf::itruemax(void) const
224 {
225  return m_itruemax;
226 }
227 
228 
229 /***********************************************************************//**
230  * @brief Return measured energy index of maximum value of the redistribution matrix
231  *
232  * @return Measured energy index of maximum value of the redistribution matrix.
233  *
234  * Returns the measured energy index of maximum value of the redistribution matrix.
235  ***************************************************************************/
236 inline
237 int GRmf::imeasmax(void) const
238 {
239  return m_imeasmax;
240 }
241 
242 
243 /***********************************************************************//**
244  * @brief Return true energy boundaries
245  *
246  * @return True energy boundaries for redistribution matrix.
247  *
248  * Returns the true energy boundaries for redistribution matrix.
249  ***************************************************************************/
250 inline
251 const GEbounds& GRmf::etrue(void) const
252 {
253  return m_ebds_true;
254 }
255 
256 
257 /***********************************************************************//**
258  * @brief Return measured energy boundaries
259  *
260  * @return Measured energy boundaries for redistribution matrix.
261  *
262  * Returns the measured energy boundaries for redistribution matrix.
263  ***************************************************************************/
264 inline
265 const GEbounds& GRmf::emeasured(void) const
266 {
267  return m_ebds_measured;
268 }
269 
270 
271 /***********************************************************************//**
272  * @brief Return redistribution matrix
273  *
274  * @return Redistribution matrix.
275  ***************************************************************************/
276 inline
277 const GMatrixSparse& GRmf::matrix(void) const
278 {
279  return m_matrix;
280 }
281 
282 
283 /***********************************************************************//**
284  * @brief Return file name
285  *
286  * @return File name from which the RMF information has been read or into
287  * which RMF information has been saved.
288  *
289  * Returns the file name from which the RMF information has been read or into
290  * which RMF information has been saved. The returned string will be empty if
291  * no load() or save() method has been called before.
292  ***************************************************************************/
293 inline
294 const GFilename& GRmf::filename(void) const
295 {
296  return (m_filename);
297 }
298 
299 
300 /***********************************************************************//**
301  * @brief Return FITS header
302  *
303  * @return FITS header or RMF file.
304  ***************************************************************************/
305 inline
306 const GFitsHeader& GRmf::header(void) const
307 {
308  return (m_header);
309 }
310 
311 
312 /***********************************************************************//**
313  * @brief Set FITS header
314  *
315  * @param[in] header FITS header.
316  ***************************************************************************/
317 inline
318 void GRmf::header(const GFitsHeader& header)
319 {
320  m_header = header;
321  return;
322 }
323 
324 
325 /***********************************************************************//**
326  * @brief Redistribution Matrix File addition operator friend
327  *
328  * @param[in] a First Redistribution Matrix File.
329  * @param[in] b Second Redistribution Matrix File.
330  * @return Sum of Redistribution Matrix Files.
331  ***************************************************************************/
332 inline
333 GRmf operator+(const GRmf& a, const GRmf& b)
334 {
335  GRmf result = a;
336  result += b;
337  return result;
338 }
339 
340 
341 /***********************************************************************//**
342  * @brief Redistribution Matrix File subtraction operator friend
343  *
344  * @param[in] a First Redistribution Matrix File.
345  * @param[in] b Second Redistribution Matrix File.
346  * @return Difference of Redistribution Matrix Files.
347  ***************************************************************************/
348 inline
349 GRmf operator-(const GRmf& a, const GRmf& b)
350 {
351  GRmf result = a;
352  result -= b;
353  return result;
354 }
355 
356 
357 /***********************************************************************//**
358  * @brief Redistribution Matrix File scaling operator friend
359  *
360  * @param[in] rmf Redistribution Matrix File.
361  * @param[in] scale Scale factor.
362  * @return Scaled Redistribution Matrix File.
363  ***************************************************************************/
364 inline
365 GRmf operator*(const GRmf& rmf, const double& scale)
366 {
367  GRmf result = rmf;
368  result *= scale;
369  return result;
370 }
371 
372 
373 /***********************************************************************//**
374  * @brief Redistribution Matrix File scaling operator friend
375  *
376  * @param[in] scale Scale factor.
377  * @param[in] rmf Redistribution Matrix File.
378  * @return Scaled Redistribution Matrix File.
379  ***************************************************************************/
380 inline
381 GRmf operator*(const double& scale, const GRmf& rmf)
382 {
383  GRmf result = rmf;
384  result *= scale;
385  return result;
386 }
387 
388 
389 /***********************************************************************//**
390  * @brief Redistribution Matrix File vision operator friend
391  *
392  * @param[in] rmf Redistribution Matrix File.
393  * @param[in] scale Division factor.
394  * @return Divided Redistribution Matrix File.
395  ***************************************************************************/
396 inline
397 GRmf operator/(const GRmf& rmf, const double& scale)
398 {
399  GRmf result = rmf;
400  result /= scale;
401  return result;
402 }
403 
404 #endif /* GRMF_HPP */
int size(void) const
Return number of redistribution matrix bins.
Definition: GRmf.hpp:179
int imeasmax(void) const
Return measured energy index of maximum value of the redistribution matrix.
Definition: GRmf.hpp:237
std::string print(const GChatter &chatter=NORMAL) const
Print Redistribution Matrix File.
Definition: GRmf.cpp:862
int m_imeasmax
Index of measured maximum.
Definition: GRmf.hpp:121
GArf operator/(const GArf &arf, const double &scale)
Auxiliary Response File vision operator friend.
Definition: GArf.hpp:357
GRmf(void)
Void constructor.
Definition: GRmf.cpp:62
void free_members(void)
Delete class members.
Definition: GRmf.cpp:943
Sparse matrix class interface definition.
Definition of interface for all GammaLib classes.
Redistribution Matrix File class.
Definition: GRmf.hpp:55
int nmeasured(void) const
Return number of measured energy bins in redistribution matrix.
Definition: GRmf.hpp:207
double & at(const int &itrue, const int &imeasured)
Return content of redistribution matrix bin.
Definition: GRmf.cpp:350
GFilename m_filename
Filename of origin.
Definition: GRmf.hpp:117
FITS file class.
Definition: GFits.hpp:63
GRmf & operator=(const GRmf &rmf)
Assignment operator.
Definition: GRmf.cpp:156
void copy_members(const GRmf &rmf)
Copy class members.
Definition: GRmf.cpp:924
GArf operator+(const GArf &a, const GArf &b)
Auxiliary Response File addition operator friend.
Definition: GArf.hpp:293
friend GRmf operator*(const GRmf &rmf, const double &scale)
Redistribution Matrix File scaling operator friend.
Definition: GRmf.hpp:365
void init_members(void)
Initialise class members.
Definition: GRmf.cpp:903
GRmf & operator+=(const GRmf &rmf)
Add Redistribution Matrix File.
Definition: GRmf.cpp:192
const GEbounds & emeasured(void) const
Return measured energy boundaries.
Definition: GRmf.hpp:265
const GFilename & filename(void) const
Return file name.
Definition: GRmf.hpp:294
Interface for FITS header class.
Definition: GFitsHeader.hpp:49
int m_itruemax
Index of true maximum.
Definition: GRmf.hpp:122
GRmf & operator-=(const GRmf &rmf)
Subtract Redistribution Matrix File.
Definition: GRmf.cpp:233
Energy boundaries container class.
Definition: GEbounds.hpp:60
GRmf * clone(void) const
Clone object.
Definition: GRmf.cpp:331
Filename class.
Definition: GFilename.hpp:62
const int & rows(void) const
Return number of matrix rows.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
GMatrixSparse m_matrix
Sparse redistribution matrix.
Definition: GRmf.hpp:120
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GEbounds m_ebds_measured
Measured energy boundaries.
Definition: GRmf.hpp:119
int ntrue(void) const
Return number of true energy bins in redistribution matrix.
Definition: GRmf.hpp:193
GChatter
Definition: GTypemaps.hpp:33
GArf operator*(const GArf &arf, const double &scale)
Auxiliary Response File scaling operator friend.
Definition: GArf.hpp:325
void clear(void)
Clear object.
Definition: GRmf.cpp:315
friend GRmf operator+(const GRmf &a, const GRmf &b)
Redistribution Matrix File addition operator friend.
Definition: GRmf.hpp:333
void save(const GFilename &filename, const bool &clobber=false, const std::string &unit="keV") const
Save Redistribution Matrix File.
Definition: GRmf.cpp:547
GFitsHeader m_header
FITS header cards.
Definition: GRmf.hpp:123
FITS header cards container class definition.
const GFitsHeader & header(void) const
Return FITS header.
Definition: GRmf.hpp:306
int itruemax(void) const
Return true energy index of maximum value of the redistribution matrix.
Definition: GRmf.hpp:223
GRmf & operator/=(const double &scale)
Divide Redistribution Matrix File values.
Definition: GRmf.cpp:290
double & operator()(const int &itrue, const int &imeasured)
Return content of redistribution matrix bin.
Definition: GRmf.hpp:149
GRmf & operator*=(const double &scale)
Scale Redistribution Matrix File values.
Definition: GRmf.cpp:268
friend GRmf operator/(const GRmf &rmf, const double &scale)
Redistribution Matrix File vision operator friend.
Definition: GRmf.hpp:397
Sparse matrix class definition.
Energy boundaries class interface definition.
void read(const GFits &fits)
Read Redistribution Matrix File.
Definition: GRmf.cpp:578
std::string classname(void) const
Return class name.
Definition: GRmf.hpp:133
const GEbounds & etrue(void) const
Return true energy boundaries.
Definition: GRmf.hpp:251
GEbounds m_ebds_true
True energy boundaries.
Definition: GRmf.hpp:118
GArf operator-(const GArf &a, const GArf &b)
Auxiliary Response File subtraction operator friend.
Definition: GArf.hpp:309
virtual ~GRmf(void)
Destructor.
Definition: GRmf.cpp:134
const int & columns(void) const
Return number of matrix columns.
friend GRmf operator-(const GRmf &a, const GRmf &b)
Redistribution Matrix File subtraction operator friend.
Definition: GRmf.hpp:349
void write(GFits &fits, const std::string &unit="keV") const
Write Redistribution Matrix File.
Definition: GRmf.cpp:706
Filename class interface definition.
void load(const GFilename &filename)
Load Redistribution Matrix File.
Definition: GRmf.cpp:506
const GMatrixSparse & matrix(void) const
Return redistribution matrix.
Definition: GRmf.hpp:277
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
const std::string extname_rmf
Definition: GRmf.hpp:44