GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAInstDir.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAInstDir.hpp - CTA instrument direction class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-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 GCTAInstDir.hpp
23  * @brief CTA instrument direction class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTAINSTDIR_HPP
28 #define GCTAINSTDIR_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <sys/types.h>
33 #if defined(__sun) && (defined(__svr4__) || defined(__SVR4)) // SOLARIS
34  typedef uint64_t u_int64_t;
35 #endif // SOLARIS
36 #include "GInstDir.hpp"
37 #include "GSkyDir.hpp"
38 #include "GMath.hpp"
39 #include "GException.hpp"
40 
41 /* __ Method name definitions ____________________________________________ */
42 #define G_DETX "GCTAInstDir::detx()"
43 #define G_DETY "GCTAInstDir::dety()"
44 #define G_THETA "GCTAInstDir::theta()"
45 #define G_PHI "GCTAInstDir::theta()"
46 #define G_DIR "GCTAInstDir::dir()"
47 
48 
49 /***********************************************************************//**
50  * @class GCTAInstDir
51  *
52  * @brief CTA instrument direction class.
53  *
54  * The CTA instrument direction defines the measured (or reconstructed)
55  * direction of an event. The instrument direction comprises a sky direction
56  * and detector coordinates. Not all the information is necessary provided,
57  * and the has_dir(), has_detx() and has_dety() methods inform which
58  * information is contained in a class instance. Note also that the dir(),
59  * detx() and dety() methods will throw an exception in case that no
60  * information exists. This assures that only valid information can be
61  * accessed.
62  ***************************************************************************/
63 class GCTAInstDir : public GInstDir {
64 
65 public:
66  // Constructors and destructors
67  GCTAInstDir(void);
68  explicit GCTAInstDir(const GSkyDir& dir);
69  GCTAInstDir(const double& detx, const double& dety);
70  GCTAInstDir(const GSkyDir& dir, const double& detx, const double& dety);
71  GCTAInstDir(const GCTAInstDir& dir);
72  virtual ~GCTAInstDir(void);
73 
74  // Operators
75  GCTAInstDir& operator=(const GCTAInstDir& dir);
76 
77  // Implemented pure virtual base class methods
78  virtual void clear(void);
79  virtual GCTAInstDir* clone(void) const;
80  virtual std::string classname(void) const;
81  virtual u_int64_t hash(void) const;
82  virtual std::string print(const GChatter& chatter = NORMAL) const;
83 
84  // Other methods
85  void dir(const GSkyDir& dir);
86  const GSkyDir& dir(void) const;
87  void detx(const double &x);
88  void dety(const double &y);
89  const double& detx(void) const;
90  const double& dety(void) const;
91  double theta(void) const;
92  double phi(void) const;
93  const bool& has_dir(void) const;
94  const bool& has_detx(void) const;
95  const bool& has_dety(void) const;
96 
97 protected:
98  // Protected methods
99  void init_members(void);
100  void copy_members(const GCTAInstDir& dir);
101  void free_members(void);
102 
103  // Data members
104  GSkyDir m_dir; //!< Observed incident direction of event
105  double m_detx; //!< Instrument coordinate X (radians)
106  double m_dety; //!< Instrument coordinate Y (radians)
107  bool m_has_dir; //!< Has valid incident direction
108  bool m_has_detx; //!< Has valid instrument coordinate X
109  bool m_has_dety; //!< Has valid instrument coordinate Y
110 };
111 
112 
113 /***********************************************************************//**
114  * @brief Return class name
115  *
116  * @return String containing the class name ("GCTAInstDir").
117  ***************************************************************************/
118 inline
119 std::string GCTAInstDir::classname(void) const
120 {
121  return ("GCTAInstDir");
122 }
123 
124 
125 /***********************************************************************//**
126  * @brief Set sky direction
127  *
128  * @param[in] dir Sky direction.
129  *
130  * Set the sky direction.
131  ***************************************************************************/
132 inline
133 void GCTAInstDir::dir(const GSkyDir& dir)
134 {
135  m_dir = dir;
136  m_has_dir = true;
137  return;
138 }
139 
140 
141 /***********************************************************************//**
142  * @brief Return reference to sky direction (const version)
143  *
144  * @return Reference to sky direction.
145  *
146  * @exception GException::runtime_error
147  * Instrument coordinate has no valid sky direction
148  *
149  * Returns reference to the sky direction.
150  ***************************************************************************/
151 inline
152 const GSkyDir& GCTAInstDir::dir(void) const
153 {
154  if (!m_has_dir) {
155  std::string msg = "Instrument coordinate has no valid sky direction.";
156  throw GException::runtime_error(G_DIR, msg);
157  }
158  return (m_dir);
159 }
160 
161 
162 /***********************************************************************//**
163  * @brief Set DETX coordinate (in radians)
164  *
165  * @param[in] x DETX coordinate (in radians).
166  *
167  * Set DETX coordinate.
168  ***************************************************************************/
169 inline
170 void GCTAInstDir::detx(const double &x)
171 {
172  m_detx = x;
173  m_has_detx = true;
174  return;
175 }
176 
177 
178 /***********************************************************************//**
179  * @brief Set DETY coordinate (in radians)
180  *
181  * @param[in] y DETY coordinate (in radians).
182  *
183  * Set DETY coordinate.
184  ***************************************************************************/
185 inline
186 void GCTAInstDir::dety(const double &y)
187 {
188  m_dety = y;
189  m_has_dety = true;
190  return;
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Return reference to DETX coordinate (in radians)
196  *
197  * @return Reference to DETX coordinate (in radians).
198  *
199  * @exception GException::runtime_error
200  * Instrument coordinate has no valid DETX coordinate
201  *
202  * Returns reference DETX coordinate (in radians).
203  ***************************************************************************/
204 inline
205 const double& GCTAInstDir::detx(void) const
206 {
207  if (!m_has_detx) {
208  std::string msg = "Instrument coordinate has no valid DETX coordinate.";
209  throw GException::runtime_error(G_DETX, msg);
210  }
211  return (m_detx);
212 }
213 
214 
215 /***********************************************************************//**
216  * @brief Return reference to DETY coordinate (in radians)
217  *
218  * @return Reference to DETY coordinate (in radians).
219  *
220  * @exception GException::runtime_error
221  * Instrument coordinate has no valid DETY coordinate
222  *
223  * Returns reference DETY coordinate (in radians).
224  ***************************************************************************/
225 inline
226 const double& GCTAInstDir::dety(void) const
227 {
228  if (!m_has_dety) {
229  std::string msg = "Instrument coordinate has no valid DETY coordinate.";
230  throw GException::runtime_error(G_DETY, msg);
231  }
232  return (m_dety);
233 }
234 
235 
236 /***********************************************************************//**
237  * @brief Return offset angle (in radians)
238  *
239  * @return Offset angle (in radians).
240  *
241  * @exception GException::runtime_error
242  * Instrument coordinate has no valid DETX or DETY coordinate
243  *
244  * Returns the offset angle from the camera centre (in radians). The offset
245  * angle \f$\theta\f$ is computed using
246  *
247  * \f[\theta = \sqrt{{\rm DETX}^2 + {\rm DETY}^2}\f]
248  *
249  * where \f${\rm DETX}\f$ and \f${\rm DETY}\f$ are the detector coordinates.
250  ***************************************************************************/
251 inline
252 double GCTAInstDir::theta(void) const
253 {
254  if (!m_has_detx || !m_has_dety) {
255  std::string msg = "Instrument coordinate has no valid DETX or DETY coordinate.";
257  }
258  return (std::sqrt(m_detx*m_detx + m_dety*m_dety));
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Return azimuth angle (in radians)
264  *
265  * @return Azimuth angle (in radians).
266  *
267  * @exception GException::runtime_error
268  * Instrument coordinate has no valid DETX or DETY coordinate
269  *
270  * Returns the azimuth angle from the camera centre (in radians). The
271  * azimuth angle \f$\phi\f$ is computed using
272  *
273  * \f[\phi = \arctan \left( \frac{{\rm DETY}}{{\rm DETX}} \right)\f]
274  *
275  * where \f${\rm DETX}\f$ and \f${\rm DETY}\f$ are the detector coordinates.
276  * The \c atan2(DETY,DETX) function is used for the computation.
277  ***************************************************************************/
278 inline
279 double GCTAInstDir::phi(void) const
280 {
281  if (!m_has_detx || !m_has_dety) {
282  std::string msg = "Instrument coordinate has no valid DETX or DETY coordinate.";
283  throw GException::runtime_error(G_PHI, msg);
284  }
285  return (gammalib::atan2(m_dety, m_detx));
286 }
287 
288 
289 /***********************************************************************//**
290  * @brief Signal if instrument direction has valid sky direction
291  *
292  * @return True of instrument direction has valid sky direction.
293  ***************************************************************************/
294 inline
295 const bool& GCTAInstDir::has_dir(void) const
296 {
297  return (m_has_dir);
298 }
299 
300 
301 /***********************************************************************//**
302  * @brief Signal if instrument direction has valid DETX coordinate
303  *
304  * @return True of instrument direction has valid DETX coordinate.
305  ***************************************************************************/
306 inline
307 const bool& GCTAInstDir::has_detx(void) const
308 {
309  return (m_has_detx);
310 }
311 
312 
313 /***********************************************************************//**
314  * @brief Signal if instrument direction has valid DETY coordinate
315  *
316  * @return True of instrument direction has valid DETY coordinate.
317  ***************************************************************************/
318 inline
319 const bool& GCTAInstDir::has_dety(void) const
320 {
321  return (m_has_dety);
322 }
323 
324 #endif /* GCTAINSTDIR_HPP */
bool m_has_detx
Has valid instrument coordinate X.
Abstract instrument direction base class definition.
virtual ~GCTAInstDir(void)
Destructor.
const double & dety(void) const
Return reference to DETY coordinate (in radians)
Sky direction class interface definition.
#define G_DETX
Definition: GCTAInstDir.hpp:42
bool m_has_dir
Has valid incident direction.
const double & detx(void) const
Return reference to DETX coordinate (in radians)
#define G_DIR
Definition: GCTAInstDir.hpp:46
const bool & has_dir(void) const
Signal if instrument direction has valid sky direction.
GCTAInstDir & operator=(const GCTAInstDir &dir)
Assignment operator.
const GSkyDir & dir(void) const
Return reference to sky direction (const version)
Abstract instrument direction base class.
Definition: GInstDir.hpp:51
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
Definition: GVector.cpp:1358
double m_dety
Instrument coordinate Y (radians)
#define G_PHI
Definition: GCTAInstDir.hpp:45
double theta(void) const
Return offset angle (in radians)
void init_members(void)
Initialise class members.
double m_detx
Instrument coordinate X (radians)
bool m_has_dety
Has valid instrument coordinate Y.
#define G_THETA
Definition: GCTAInstDir.hpp:44
GChatter
Definition: GTypemaps.hpp:33
GCTAInstDir(void)
Void constructor.
Definition: GCTAInstDir.cpp:56
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
#define G_DETY
Definition: GCTAInstDir.hpp:43
virtual GCTAInstDir * clone(void) const
CTA instrument direction.
virtual void clear(void)
Clear CTA instrument direction.
GSkyDir m_dir
Observed incident direction of event.
const bool & has_dety(void) const
Signal if instrument direction has valid DETY coordinate.
Exception handler interface definition.
double atan2(const double &y, const double &x)
Compute arc tangens in radians.
Definition: GMath.cpp:102
void copy_members(const GCTAInstDir &dir)
Copy class members.
virtual std::string classname(void) const
Return class name.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
const bool & has_detx(void) const
Signal if instrument direction has valid DETX coordinate.
double phi(void) const
Return azimuth angle (in radians)
Sky direction class.
Definition: GSkyDir.hpp:62
void free_members(void)
Delete class members.
virtual u_int64_t hash(void) const
Return instrument direction hash value.
Mathematical function definitions.