GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GCOSInstDir.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCOSInstDir.cpp - COSI instrument direction class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2026 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 GCOSInstDir.cpp
23 * @brief COSI 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> // std::memcpy
32#include "GTools.hpp"
33#include "GCOSInstDir.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 *
54 * Creates an empty COSI instrument direction.
55 ***************************************************************************/
57{
58 // Initialise class members
60
61 // Return
62 return;
63}
64
65
66/***********************************************************************//**
67 * @brief Copy constructor
68 *
69 * @param[in] dir COSI instrument direction.
70 ***************************************************************************/
72{
73 // Initialise class members
75
76 // Copy members
78
79 // Return
80 return;
81}
82
83
84/***********************************************************************//**
85 * @brief Instrument direction constructor
86 *
87 * @param[in] dir Sky direction in celestial system.
88 * @param[in] dir_local Sky direction in spacecraft system.
89 * @param[in] phi Compton scatter angle (deg).
90 *
91 * Constructs a COSI instrument direction from a sky direction in the
92 * celestial and spacecraft systems and a phi value.
93 ***************************************************************************/
95 const GSkyDir& dir_local,
96 const double& phi) : GInstDir()
97{
98 // Initialise class members
100
101 // Set class members
102 this->dir(dir);
103 this->dir_local(dir_local);
104 this->phi(phi);
105
106 // Return
107 return;
108}
109
110
111/***********************************************************************//**
112 * @brief Destructor
113 ***************************************************************************/
115{
116 // Free members
117 free_members();
118
119 // Return
120 return;
121}
122
123
124/*==========================================================================
125 = =
126 = Operators =
127 = =
128 ==========================================================================*/
129
130/***********************************************************************//**
131 * @brief Assignment operator
132 *
133 * @param[in] dir COSI instrument direction.
134 * @return COSI instrument direction.
135 ***************************************************************************/
137{
138 // Execute only if object is not identical
139 if (this != &dir) {
140
141 // Copy base class members
142 this->GInstDir::operator=(dir);
143
144 // Free members
145 free_members();
146
147 // Initialise private members
148 init_members();
149
150 // Copy members
152
153 } // endif: object was not identical
154
155 // Return this object
156 return *this;
157}
158
159
160/*==========================================================================
161 = =
162 = Public methods =
163 = =
164 ==========================================================================*/
165
166/***********************************************************************//**
167 * @brief Clear COSI instrument direction
168 *
169 * Clears COSI instrument direction by resetting all class members to
170 * an initial state. Any information that was present before will be lost.
171 ***************************************************************************/
173{
174 // Free members
175 free_members();
177
178 // Initialise private members
180 init_members();
181
182 // Return
183 return;
184}
185
186
187/***********************************************************************//**
188 * @brief Clone COSI instrument direction
189 *
190 * @return Pointer to deep copy of COSI instrument direction.
191 ***************************************************************************/
193{
194 return new GCOSInstDir(*this);
195}
196
197
198/***********************************************************************//**
199 * @brief Return COSI instrument direction hash value
200 *
201 * @return Hash value.
202 *
203 * Returns a hash value that can be used in the response cache.
204 ***************************************************************************/
205u_int64_t GCOSInstDir::hash(void) const
206{
207 // Allocate static array to store the information as floats
208 static float buffer[2];
209
210 // Store the two sky coordinates as floats
211 buffer[0] = float(m_dir.ra());
212 buffer[1] = float(m_dir.dec());
213
214 // Map the floats to an unsigned 64 Bit integer
215 u_int64_t hash;
216 std::memcpy(&hash, &buffer, sizeof hash);
217
218 // Return hash value
219 return hash;
220}
221
222
223/***********************************************************************//**
224 * @brief Print COSI instrument direction information
225 *
226 * @param[in] chatter Chattiness.
227 * @return String containing COSI instrument direction information.
228 ***************************************************************************/
229std::string GCOSInstDir::print(const GChatter& chatter) const
230{
231 // Initialise result string
232 std::string result;
233
234 // Continue only if chatter is not silent
235 if (chatter != SILENT) {
236
237 // Append header
238 result.append("=== GCOSInstDir ===");
239
240 // Append information
241 result.append("\n"+gammalib::parformat("Sky direction (Chi,Psi)"));
242 result.append(m_dir.print(chatter));
243 result.append("\n"+gammalib::parformat("Spacecraft direction (Chi,Psi)"));
244 result.append(m_dir_local.print(chatter));
245 result.append("\n"+gammalib::parformat("Scatter angle (Phi)"));
246 result.append(gammalib::str(m_phi)+" deg");
247
248 } // endif: chatter was not silent
249
250 // Return result
251 return result;
252}
253
254
255/*==========================================================================
256 = =
257 = Private methods =
258 = =
259 ==========================================================================*/
260
261/***********************************************************************//**
262 * @brief Initialise class members
263 ***************************************************************************/
265{
266 // Initialise members
267 m_dir.clear();
269 m_phi = 0.0;
270
271 // Return
272 return;
273}
274
275
276/***********************************************************************//**
277 * @brief Copy class members
278 *
279 * @param[in] dir COSI instrument direction.
280 ***************************************************************************/
282{
283 // Copy members
284 m_dir = dir.m_dir;
285 m_dir_local = dir.m_dir_local;
286 m_phi = dir.m_phi;
287
288 // Return
289 return;
290}
291
292
293/***********************************************************************//**
294 * @brief Delete class members
295 ***************************************************************************/
297{
298 // Return
299 return;
300}
COSI instrument direction class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
COSI instrument direction class.
virtual u_int64_t hash(void) const
Return COSI instrument direction hash value.
double m_phi
Observed scatter angle of event (deg)
GSkyDir m_dir_local
Observed scatter direction of event in local coordinates.
virtual ~GCOSInstDir(void)
Destructor.
void copy_members(const GCOSInstDir &dir)
Copy class members.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print COSI instrument direction information.
const GSkyDir & dir_local(void) const
Return event scatter direction in spacecraft coordinates.
GCOSInstDir & operator=(const GCOSInstDir &dir)
Assignment operator.
virtual void clear(void)
Clear COSI instrument direction.
void init_members(void)
Initialise class members.
const GSkyDir & dir(void) const
Return event scatter direction in celestial coordinates.
GCOSInstDir(void)
Void constructor.
const double & phi(void) const
Return event Compton scatter angle.
void free_members(void)
Delete class members.
virtual GCOSInstDir * clone(void) const
Clone COSI instrument direction.
GSkyDir m_dir
Observed scatter direction of event in celestial coordinates.
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:243
void clear(void)
Clear sky direction.
Definition GSkyDir.cpp:186
std::string print(const GChatter &chatter=NORMAL) const
Print sky direction information.
Definition GSkyDir.cpp:1376
const double & ra(void) const
Return Right Ascension in radians.
Definition GSkyDir.hpp:216
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1136
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508