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