GammaLib 2.0.0
Loading...
Searching...
No Matches
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 _______________________________________________ */
40class GFits;
41class GFitsTable;
42
43/* __ Constants __________________________________________________________ */
44namespace gammalib {
45 const std::string extname_arf = "SPECRESP";
46}
47
48
49/***********************************************************************//**
50 * @class GArf
51 *
52 * @brief Auxiliary Response File class
53 ***************************************************************************/
54class 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
63public:
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
112protected:
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 ***************************************************************************/
136inline
137std::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 ***************************************************************************/
150inline
151double& 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 ***************************************************************************/
164inline
165const 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 ***************************************************************************/
179inline
180double& 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 ***************************************************************************/
194inline
195const 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 ***************************************************************************/
208inline
209int 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 ***************************************************************************/
222inline
223int 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 ***************************************************************************/
236inline
237const 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 ***************************************************************************/
253inline
254const 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 ***************************************************************************/
265inline
266const 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 ***************************************************************************/
277inline
278void GArf::header(const GFitsHeader& header)
279{
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 ***************************************************************************/
292inline
293GArf 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 ***************************************************************************/
308inline
309GArf 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 ***************************************************************************/
324inline
325GArf 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 ***************************************************************************/
340inline
341GArf 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 ***************************************************************************/
356inline
357GArf 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 &a, const GArf &b)
Auxiliary Response File addition operator friend.
Definition GArf.hpp:293
GArf operator*(const GArf &arf, const double &scale)
Auxiliary Response File scaling operator friend.
Definition GArf.hpp:325
GArf operator-(const GArf &a, const GArf &b)
Auxiliary Response File subtraction operator friend.
Definition GArf.hpp:309
GArf operator/(const GArf &arf, const double &scale)
Auxiliary Response File vision operator friend.
Definition GArf.hpp:357
Definition of interface for all GammaLib classes.
Energy boundaries class interface definition.
Filename class interface definition.
FITS header cards container class definition.
Node array class interface definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Auxiliary Response File class.
Definition GArf.hpp:54
int column_index(const std::string &colname) const
Returns index of additional vector column.
Definition GArf.cpp:958
friend GArf operator+(const GArf &a, const GArf &b)
Auxiliary Response File addition operator friend.
Definition GArf.hpp:293
const GFitsHeader & header(void) const
Return FITS header.
Definition GArf.hpp:266
GFitsHeader m_header
FITS header cards.
Definition GArf.hpp:127
GArf & operator=(const GArf &arf)
Assignment operator.
Definition GArf.cpp:161
void read(const GFits &fits)
Read Auxiliary Response File.
Definition GArf.cpp:617
void save(const GFilename &filename, const bool &clobber=false) const
Save Auxiliary Response File.
Definition GArf.cpp:589
int size(void) const
Return number of spectral bins.
Definition GArf.hpp:209
GArf(void)
Void constructor.
Definition GArf.cpp:66
GArf & operator*=(const double &scale)
Scale Auxiliary Response File values.
Definition GArf.cpp:257
double & operator[](const int &index)
Return content of spectral bin.
Definition GArf.hpp:151
double & at(const int &index)
Return content of spectral bin.
Definition GArf.cpp:428
GArf & operator/=(const double &scale)
Divide Auxiliary Response File values.
Definition GArf.cpp:277
const GEbounds & ebounds(void) const
Return energy boundaries.
Definition GArf.hpp:237
void set_logetrue(void)
Set true energy node array.
Definition GArf.cpp:919
void append(const std::string &name, const std::vector< double > &column)
Append additional column to spectrum.
Definition GArf.cpp:522
virtual ~GArf(void)
Destructor.
Definition GArf.cpp:139
GEbounds m_ebounds
Energy boundaries.
Definition GArf.hpp:122
GNodeArray m_logetrue
Log10 energies in TeV.
Definition GArf.hpp:123
std::string classname(void) const
Return class name.
Definition GArf.hpp:137
std::string print(const GChatter &chatter=NORMAL) const
Print Auxiliary Response File.
Definition GArf.cpp:834
GArf * clone(void) const
Clone object.
Definition GArf.cpp:411
void init_members(void)
Initialise class members.
Definition GArf.cpp:869
std::vector< double > m_specresp
Spectral response.
Definition GArf.hpp:124
GArf & operator-=(const GArf &arf)
Subtract Auxiliary Response File.
Definition GArf.cpp:230
friend GArf operator*(const GArf &arf, const double &scale)
Auxiliary Response File scaling operator friend.
Definition GArf.hpp:325
void copy_members(const GArf &pha)
Copy class members.
Definition GArf.cpp:890
void write(GFits &fits) const
Write Auxiliary Response File.
Definition GArf.cpp:740
std::vector< std::vector< double > > m_coldata
Additional column data.
Definition GArf.hpp:126
int columns(void) const
Return number of additional columns.
Definition GArf.hpp:223
void clear(void)
Clear object.
Definition GArf.cpp:395
const GFilename & filename(void) const
Return file name.
Definition GArf.hpp:254
friend GArf operator-(const GArf &a, const GArf &b)
Auxiliary Response File subtraction operator friend.
Definition GArf.hpp:309
void free_members(void)
Delete class members.
Definition GArf.cpp:909
friend GArf operator/(const GArf &arf, const double &scale)
Auxiliary Response File vision operator friend.
Definition GArf.hpp:357
std::vector< std::string > m_colnames
Additional column names.
Definition GArf.hpp:125
double & operator()(const int &index, const int &col)
Return content of additional columns.
Definition GArf.hpp:180
GFilename m_filename
Filename of origin.
Definition GArf.hpp:121
GArf & operator+=(const GArf &arf)
Add Auxiliary Response File.
Definition GArf.cpp:196
void load(const GFilename &filename)
Load Auxiliary Response File.
Definition GArf.cpp:552
Interface class for all GammaLib classes.
Definition GBase.hpp:52
Energy boundaries container class.
Definition GEbounds.hpp:60
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Filename class.
Definition GFilename.hpp:62
Interface for FITS header class.
Abstract interface for FITS table.
FITS file class.
Definition GFits.hpp:63
Node array class.
const std::string extname_arf
Definition GArf.hpp:45