GammaLib 2.0.0
Loading...
Searching...
No Matches
GCOMInstDir.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCOMInstDir.cpp - COMPTEL instrument direction class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2012-2017 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 GCOMInstDir.cpp
23 * @brief COMPTEL instrument direction class implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <cstring> // memcpy
32#include "GCOMInstDir.hpp"
33#include "GTools.hpp"
34
35/* __ Method name definitions ____________________________________________ */
36
37/* __ Macros _____________________________________________________________ */
38
39/* __ Coding definitions _________________________________________________ */
40
41/* __ Debug definitions __________________________________________________ */
42
43/* __ Prototypes _________________________________________________________ */
44
45/*==========================================================================
46 = =
47 = Constructors/destructors =
48 = =
49 ==========================================================================*/
50
51/***********************************************************************//**
52 * @brief Void constructor
53 ***************************************************************************/
55{
56 // Initialise class members
58
59 // Return
60 return;
61}
62
63
64/***********************************************************************//**
65 * @brief Copy constructor
66 *
67 * @param[in] dir Instrument direction.
68 ***************************************************************************/
70{
71 // Initialise class members
73
74 // Copy members
76
77 // Return
78 return;
79}
80
81
82/***********************************************************************//**
83 * @brief Instrument direction constructor
84 *
85 * @param[in] dir Sky direction.
86 * @param[in] phibar Phibar (deg).
87 *
88 * Constructs a COMPTEL instrument direction from a sky direction and a
89 * phibar value.
90 ***************************************************************************/
91GCOMInstDir::GCOMInstDir(const GSkyDir& dir, const double& phibar) : GInstDir()
92{
93 // Initialise class members
95
96 // Set class members
97 this->dir(dir);
98 this->phibar(phibar);
99
100 // Return
101 return;
102}
103
104
105/***********************************************************************//**
106 * @brief Destructor
107 ***************************************************************************/
109{
110 // Free members
111 free_members();
112
113 // Return
114 return;
115}
116
117
118/*==========================================================================
119 = =
120 = Operators =
121 = =
122 ==========================================================================*/
123
124/***********************************************************************//**
125 * @brief Assignment operator
126 *
127 * @param[in] dir Instrument direction.
128 * @return Instrument direction.
129 ***************************************************************************/
131{
132 // Execute only if object is not identical
133 if (this != &dir) {
134
135 // Copy base class members
136 this->GInstDir::operator=(dir);
137
138 // Free members
139 free_members();
140
141 // Initialise private members
142 init_members();
143
144 // Copy members
146
147 } // endif: object was not identical
148
149 // Return this object
150 return *this;
151}
152
153
154/*==========================================================================
155 = =
156 = Public methods =
157 = =
158 ==========================================================================*/
159
160/***********************************************************************//**
161 * @brief Clear instance
162 ***************************************************************************/
164{
165 // Free members
166 free_members();
168
169 // Initialise private members
171 init_members();
172
173 // Return
174 return;
175}
176
177
178/***********************************************************************//**
179 * @brief Clone instance
180 *
181 * @return Pointer to deep copy of instrument direction.
182 ***************************************************************************/
184{
185 return new GCOMInstDir(*this);
186}
187
188
189/***********************************************************************//**
190 * @brief Return instrument direction hash value
191 *
192 * @return Hash value.
193 *
194 * Returns a hash value that can be used in the response cache.
195 ***************************************************************************/
196u_int64_t GCOMInstDir::hash(void) const
197{
198 // Allocate static array to store the information as floats
199 static float buffer[2];
200
201 // Scale Phibar for addition to Right Ascension and Declination in
202 // radians
203 float scaled_phibar = 10.0 * float(m_phibar);
204
205 // Store the two sky coordinates as floats
206 buffer[0] = float(m_dir.ra() + scaled_phibar);
207 buffer[1] = float(m_dir.dec() + scaled_phibar);
208
209 // Map the floats to an unsigned 64 Bit integer
210 u_int64_t hash; std::memcpy(&hash, &buffer, sizeof hash);
211
212 // Return hash value
213 return hash;
214}
215
216
217/***********************************************************************//**
218 * @brief Print instrument direction information
219 *
220 * @param[in] chatter Chattiness.
221 * @return String containing instrument direction information.
222 ***************************************************************************/
223std::string GCOMInstDir::print(const GChatter& chatter) const
224{
225 // Initialise result string
226 std::string result;
227
228 // Continue only if chatter is not silent
229 if (chatter != SILENT) {
230
231 // Append header
232 result.append("=== GCOMInstDir ===");
233
234 // Append information
235 result.append("\n"+gammalib::parformat("Sky direction (Chi,Psi)"));
236 result.append(m_dir.print(chatter));
237 result.append("\n"+gammalib::parformat("Scatter angle (Phibar)"));
238 result.append(gammalib::str(m_phibar)+" deg");
239
240 } // endif: chatter was not silent
241
242 // Return result
243 return result;
244}
245
246
247/*==========================================================================
248 = =
249 = Private methods =
250 = =
251 ==========================================================================*/
252
253/***********************************************************************//**
254 * @brief Initialise class members
255 ***************************************************************************/
257{
258 // Initialise members
259 m_dir.clear();
260 m_phibar = 0.0;
261
262 // Return
263 return;
264}
265
266
267/***********************************************************************//**
268 * @brief Copy class members
269 *
270 * @param[in] dir Instrument direction.
271 ***************************************************************************/
273{
274 // Copy members
275 m_dir = dir.m_dir;
276 m_phibar = dir.m_phibar;
277
278 // Return
279 return;
280}
281
282
283/***********************************************************************//**
284 * @brief Delete class members
285 ***************************************************************************/
287{
288 // Return
289 return;
290}
COMPTEL instrument direction class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
Interface for the COMPTEL instrument direction class.
const GSkyDir & dir(void) const
Return event scatter direction.
virtual ~GCOMInstDir(void)
Destructor.
GSkyDir m_dir
Observed scatter direction of event.
const double & phibar(void) const
Return event Compton scatter angle.
void copy_members(const GCOMInstDir &dir)
Copy class members.
virtual u_int64_t hash(void) const
Return instrument direction hash value.
virtual void clear(void)
Clear instance.
virtual GCOMInstDir * clone(void) const
Clone instance.
GCOMInstDir & operator=(const GCOMInstDir &dir)
Assignment operator.
double m_phibar
Observed scatter angle of event.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
GCOMInstDir(void)
Void constructor.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
Abstract instrument direction base class.
Definition GInstDir.hpp:51
virtual GInstDir & operator=(const GInstDir &dir)
Assignment operator.
Definition GInstDir.cpp:105
void init_members(void)
Initialise class members.
Definition GInstDir.cpp:141
void free_members(void)
Delete class members.
Definition GInstDir.cpp:163
Sky direction class.
Definition GSkyDir.hpp:62
const double & dec(void) const
Return Declination in radians.
Definition GSkyDir.hpp:241
void clear(void)
Clear sky direction.
Definition GSkyDir.cpp:164
std::string print(const GChatter &chatter=NORMAL) const
Print sky direction information.
Definition GSkyDir.cpp:1227
const double & ra(void) const
Return Right Ascension in radians.
Definition GSkyDir.hpp:214
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1143
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:489