GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAResponseTable.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAResponseTable.hpp - CTA response table class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2012-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 GCTAResponseTable.hpp
23  * @brief CTA response table class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTARESPONSETABLE_HPP
28 #define GCTARESPONSETABLE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GBase.hpp"
34 #include "GNodeArray.hpp"
35 #include "GFitsTable.hpp"
36 
37 
38 /***********************************************************************//**
39  * @class GCTAResponseTable
40  *
41  * @brief CTA response table class
42  *
43  * A CTA response table holds n-dimensional data cubes that describe a
44  * component of the instrumental response function.
45  *
46  * Each dimension of the n-dimensional cube is describe by two axes vectors,
47  * providing the lower and upper bin boundaries of each axis.
48  *
49  * Each n-dimensional data cube is called a table. Table elements can be
50  * accessed by element index, or through linear, bilinear or trilinear
51  * interpolation operators.
52  ***************************************************************************/
53 class GCTAResponseTable : public GBase {
54 
55 public:
56  // Constructors and destructors
57  GCTAResponseTable(void);
59  explicit GCTAResponseTable(const GFitsTable& hdu);
60  virtual ~GCTAResponseTable(void);
61 
62  // Operators
64  std::vector<double> operator()(const double& arg) const;
65  std::vector<double> operator()(const double& arg1, const double& arg2) const;
66  std::vector<double> operator()(const double& arg1, const double& arg2,
67  const double& arg3) const;
68  const double& operator()(const int& element) const;
69  double& operator()(const int& element);
70  const double& operator()(const int& table, const int& element) const;
71  double& operator()(const int& table, const int& element);
72  double operator()(const int& table, const double& arg) const;
73  double operator()(const int& table, const double& arg1,
74  const double& arg2) const;
75  double operator()(const int& index, const double& arg1,
76  const double& arg2, const double& arg3) const;
77 
78  // Methods
79  void clear(void);
80  GCTAResponseTable* clone(void) const;
81  std::string classname(void) const;
82  bool has_table(const std::string& name) const;
83  bool has_axis(const std::string& name) const;
84  const int& axes(void) const;
85  const int& tables(void) const;
86  const int& elements(void) const;
87  int axis(const std::string& name) const;
88  int table(const std::string& name) const;
89  const std::string& unit(const int& table) const;
90  void scale(const int& table, const double& scale);
91  int axis_bins(const int& axis) const;
92  const double& axis_lo(const int& axis, const int& bin) const;
93  const double& axis_hi(const int& axis, const int& bin) const;
94  const GNodeArray& axis_nodes(const int& axis) const;
95  const std::string& axis_lo_name(const int& axis) const;
96  const std::string& axis_hi_name(const int& axis) const;
97  const std::string& axis_lo_unit(const int& axis) const;
98  const std::string& axis_hi_unit(const int& axis) const;
99  void axis_linear(const int& axis);
100  void axis_log10(const int& axis);
101  void axis_radians(const int& axis);
102  const std::string& telescope(void) const;
103  void telescope(const std::string& telescope);
104  void append_axis(const std::vector<double>& axis_lo,
105  const std::vector<double>& axis_hi,
106  const std::string& name,
107  const std::string& unit);
108  void append_table(const std::string& name,
109  const std::string& unit);
110  void read(const GFitsTable& table);
111  void write(GFitsTable& table) const;
112  std::string print(const GChatter& chatter = NORMAL) const;
113 
114 private:
115  // Methods
116  void init_members(void);
117  void copy_members(const GCTAResponseTable& table);
118  void free_members(void);
119  void read_colnames(const GFitsTable& hdu);
120  void read_axes(const GFitsTable& hdu);
121  void read_tables(const GFitsTable& hdu);
122  void update(const double& arg) const;
123  void update(const double& arg1, const double& arg2) const;
124  void update(const double& arg1, const double& arg2,
125  const double& arg3) const;
126 
127  // Table information
128  int m_naxes; //!< Number of axes
129  int m_ntables; //!< Number of tables
130  int m_nelements; //!< Number of elements per table
131  std::vector<std::string> m_colname_lo; //!< Column names for lower boundaries
132  std::vector<std::string> m_colname_hi; //!< Column names for upper boundaries
133  std::vector<std::string> m_colname_table; //!< Column names for table
134  std::vector<std::vector<double> > m_axis_lo; //!< Axes lower boundaries
135  std::vector<std::vector<double> > m_axis_hi; //!< Axes upper boundaries
136  std::vector<std::string> m_units_lo; //!< Lower boundaries units
137  std::vector<std::string> m_units_hi; //!< Upper boundaries units
138  std::vector<std::string> m_units_table; //!< Parameter units
139  std::vector<GNodeArray> m_axis_nodes; //!< Axes node arrays
140  std::vector<std::vector<double> > m_tables; //!< Tables
141  std::string m_telescope; //!< Telescope keyword
142 
143  // Response table computation cache for 1D access
144  mutable int m_inx_left; //!< Index of left node
145  mutable int m_inx_right; //!< Index of right node
146  mutable double m_wgt_left; //!< Weight of left node
147  mutable double m_wgt_right; //!< Weight of right node
148 
149  // Response table computation cache for 2D access
150  mutable int m_inx1; //!< Index of upper left node
151  mutable int m_inx2; //!< Index of lower left node
152  mutable int m_inx3; //!< Index of upper right node
153  mutable int m_inx4; //!< Index of lower right node
154  mutable double m_wgt1; //!< Weight of upper left node
155  mutable double m_wgt2; //!< Weight of lower left node
156  mutable double m_wgt3; //!< Weight of upper right node
157  mutable double m_wgt4; //!< Weight of lower right node
158 
159  // Response table computation cache for 3D access
160  mutable int m_inx5; //!< Index of upper left node
161  mutable int m_inx6; //!< Index of lower left node
162  mutable int m_inx7; //!< Index of upper right node
163  mutable int m_inx8; //!< Index of lower right node
164  mutable double m_wgt5; //!< Weight of upper left node
165  mutable double m_wgt6; //!< Weight of lower left node
166  mutable double m_wgt7; //!< Weight of upper right node
167  mutable double m_wgt8; //!< Weight of lower right node
168 };
169 
170 
171 /***********************************************************************//**
172  * @brief Return class name
173  *
174  * @return String containing the class name ("GCTAResponseTable").
175  ***************************************************************************/
176 inline
177 std::string GCTAResponseTable::classname(void) const
178 {
179  return ("GCTAResponseTable");
180 }
181 
182 
183 /***********************************************************************//**
184  * @brief Return number of axes of the tables
185  *
186  * @return Number of axes of tables.
187  *
188  * Returns the number of axes of tables.
189  ***************************************************************************/
190 inline
191 const int& GCTAResponseTable::axes(void) const
192 {
193  // Return number of axes
194  return (m_naxes);
195 }
196 
197 
198 /***********************************************************************//**
199  * @brief Return number of tables
200  *
201  * @return Number of tables.
202  *
203  * Returns the number of tables.
204  ***************************************************************************/
205 inline
206 const int& GCTAResponseTable::tables(void) const
207 {
208  return (m_ntables);
209 }
210 
211 
212 /***********************************************************************//**
213  * @brief Return number of elements per table
214  *
215  * @return Number of elements per table.
216  *
217  * Returns the number of elements per table.
218  ***************************************************************************/
219 inline
220 const int& GCTAResponseTable::elements(void) const
221 {
222  return (m_nelements);
223 }
224 
225 
226 /***********************************************************************//**
227  * @brief Return telescope string
228  *
229  * @return Telescope name.
230  *
231  * Returns string containing the telescope name.
232  ***************************************************************************/
233 inline
234 const std::string& GCTAResponseTable::telescope(void) const
235 {
236  return (m_telescope);
237 }
238 
239 
240 /***********************************************************************//**
241  * @brief Set telescope string
242  *
243  * @param[in] telescope Telescope name.
244  *
245  * Sets telescope name.
246  ***************************************************************************/
247 inline
248 void GCTAResponseTable::telescope(const std::string& telescope)
249 {
251  return;
252 }
253 
254 #endif /* GCTARESPONSETABLE_HPP */
int m_inx_left
Index of left node.
const GNodeArray & axis_nodes(const int &axis) const
Return axis nodes.
int m_inx5
Index of upper left node.
void append_table(const std::string &name, const std::string &unit)
Append table to response table.
Node array class.
Definition: GNodeArray.hpp:60
GCTAResponseTable(void)
Void constructor.
int m_ntables
Number of tables.
std::vector< std::string > m_units_hi
Upper boundaries units.
GCTAResponseTable & operator=(const GCTAResponseTable &table)
Assignment operator.
void update(const double &arg) const
Update 1D cache.
double m_wgt6
Weight of lower left node.
void axis_linear(const int &axis)
Set nodes for a linear axis.
double m_wgt2
Weight of lower left node.
Definition of interface for all GammaLib classes.
std::vector< double > operator()(const double &arg) const
Linear interpolation operator for 1D tables.
void init_members(void)
Initialise response table members.
int m_inx2
Index of lower left node.
const int & tables(void) const
Return number of tables.
int m_inx3
Index of upper right node.
void scale(const int &table, const double &scale)
Scale table.
void read_colnames(const GFitsTable &hdu)
Read column names from FITS HDU.
void read_axes(const GFitsTable &hdu)
Read axes definitions from FITS HDU.
std::vector< std::vector< double > > m_axis_hi
Axes upper boundaries.
void axis_radians(const int &axis)
Set nodes for a radians axis.
virtual ~GCTAResponseTable(void)
Destructor.
void read(const GFitsTable &table)
Read response table from FITS table HDU.
int m_inx4
Index of lower right node.
const double & axis_lo(const int &axis, const int &bin) const
Return lower bin boundary for bin in axis.
std::vector< std::vector< double > > m_tables
Tables.
void write(GFitsTable &table) const
Write response table into FITS table HDU.
int axis(const std::string &name) const
Determine index of an axis.
const std::string & unit(const int &table) const
Return table unit.
double m_wgt4
Weight of lower right node.
Node array class interface definition.
bool has_table(const std::string &name) const
Check whether a table exists.
void clear(void)
Clear response table.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
std::vector< std::string > m_colname_table
Column names for table.
std::string classname(void) const
Return class name.
double m_wgt3
Weight of upper right node.
int m_inx7
Index of upper right node.
const int & elements(void) const
Return number of elements per table.
GCTAResponseTable * clone(void) const
Clone response table.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
double m_wgt_left
Weight of left node.
GChatter
Definition: GTypemaps.hpp:33
std::string print(const GChatter &chatter=NORMAL) const
Print response table information.
void free_members(void)
Delete response table members.
void axis_log10(const int &axis)
Set nodes for a logarithmic (base 10) axis.
int table(const std::string &name) const
Determine index of table.
double m_wgt1
Weight of upper left node.
void copy_members(const GCTAResponseTable &table)
Copy response table members.
double m_wgt8
Weight of lower right node.
std::vector< std::string > m_units_table
Parameter units.
double m_wgt7
Weight of upper right node.
const std::string & telescope(void) const
Return telescope string.
int axis_bins(const int &axis) const
Return number bins in an axis.
std::vector< std::vector< double > > m_axis_lo
Axes lower boundaries.
void append_axis(const std::vector< double > &axis_lo, const std::vector< double > &axis_hi, const std::string &name, const std::string &unit)
Append an axis to the response table.
const std::string & axis_lo_name(const int &axis) const
Return lower bin boundary FITS table column name for axis.
int m_inx_right
Index of right node.
std::vector< std::string > m_colname_hi
Column names for upper boundaries.
int m_inx6
Index of lower left node.
std::vector< std::string > m_colname_lo
Column names for lower boundaries.
bool has_axis(const std::string &name) const
Check whether an axis exists.
const double & axis_hi(const int &axis, const int &bin) const
Return upper bin boundary for bin in axis.
const std::string & axis_hi_name(const int &axis) const
Return upper bin boundary FITS table column name for axis.
int m_naxes
Number of axes.
std::vector< GNodeArray > m_axis_nodes
Axes node arrays.
void read_tables(const GFitsTable &hdu)
Read tables.
CTA response table class.
int m_inx1
Index of upper left node.
const std::string & axis_lo_unit(const int &axis) const
Return lower bin boundary unit for axis.
const std::string & axis_hi_unit(const int &axis) const
Return upper bin boundary unit for axis.
double m_wgt5
Weight of upper left node.
int m_inx8
Index of lower right node.
const int & axes(void) const
Return number of axes of the tables.
int m_nelements
Number of elements per table.
std::vector< std::string > m_units_lo
Lower boundaries units.
double m_wgt_right
Weight of right node.
FITS table abstract base class interface definition.
std::string m_telescope
Telescope keyword.