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