GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GPulsarEphemeris.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GPulsarEphemeris.cpp - Pulsar ephemeris class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2022 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 GPulsarEphemeris.cpp
23 * @brief Pulsar ephemeris class implementation
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GPulsarEphemeris.hpp"
32#include "GTools.hpp"
33
34/* __ Method name definitions ____________________________________________ */
35
36/* __ Macros _____________________________________________________________ */
37
38/* __ Coding definitions _________________________________________________ */
39
40/* __ Debug definitions __________________________________________________ */
41
42
43
44/*==========================================================================
45 = =
46 = Constructors/destructors =
47 = =
48 ==========================================================================*/
49
50/***********************************************************************//**
51 * @brief Void constructor
52 ***************************************************************************/
54{
55 // Initialise class members
57
58 // Return
59 return;
60}
61
62
63/***********************************************************************//**
64 * @brief Copy constructor
65 *
66 * @param[in] ephemeris Pulsar ephemeris.
67 ***************************************************************************/
69{
70 // Initialise class members
72
73 // Copy members
74 copy_members(ephemeris);
75
76 // Return
77 return;
78}
79
80
81/***********************************************************************//**
82 * @brief Destructor
83 ***************************************************************************/
85{
86 // Free members
88
89 // Return
90 return;
91}
92
93
94/*==========================================================================
95 = =
96 = Operators =
97 = =
98 ==========================================================================*/
99
100/***********************************************************************//**
101 * @brief Assignment operator
102 *
103 * @param[in] ephemeris Pulsar ephemeris.
104 * @return Pulsar ephemeris.
105 ***************************************************************************/
107{
108 // Execute only if object is not identical
109 if (this != &ephemeris) {
110
111 // Free members
112 free_members();
113
114 // Initialise private members
115 init_members();
116
117 // Copy members
118 copy_members(ephemeris);
119
120 } // endif: object was not identical
121
122 // Return this object
123 return *this;
124}
125
126
127/*==========================================================================
128 = =
129 = Public methods =
130 = =
131 ==========================================================================*/
132
133/***********************************************************************//**
134 * @brief Clear Pulsar ephemeris
135 ***************************************************************************/
137{
138 // Free members
139 free_members();
140
141 // Initialise private members
142 init_members();
143
144 // Return
145 return;
146}
147
148
149/***********************************************************************//**
150 * @brief Clone Pulsar ephemeris
151 *
152 * @return Pointer to deep copy of Pulsar ephemeris.
153 ***************************************************************************/
155{
156 return new GPulsarEphemeris(*this);
157}
158
159
160/***********************************************************************//**
161 * @brief Returns pulsar phase
162 *
163 * @param[in] time Time.
164 * @param[in] timesys Time system of time to be used for evaluation.
165 * @return Pulsar phase.
166 *
167 * Computes
168 *
169 * \f[
170 * \Phi(t) = \Phi_0 + f(t-t_0) + \frac{1}{2}\dot{f} (t-t_0)^2 +
171 * \frac{1}{6}\ddot{f} (t-t_0)^3
172 * \f]
173 *
174 * where
175 * \f$t\f$ is the specified @p time in seconds,
176 * \f$t_0\f$ is a reference time in seconds,
177 * \f$\Phi_0\f$ is the phase at the reference time,
178 * \f$f\f$ is the variation frequency at the reference time,
179 * \f$\dot{f}\f$ is the first derivative of the variation frequency at the
180 * reference time, and
181 * \f$\dot{f}\f$ is the second derivative of the variation frequency at the
182 * reference time.
183 *
184 * The phase \f$\Phi(t)\f$ is in the interval [0,1].
185 ***************************************************************************/
187 const std::string& timesys) const
188{
189 // Set constants
190 const double c1 = 0.5;
191 const double c2 = 1.0 / 6.0;
192
193 // Compute time since reference time in seconds
194 double dt = time.secs(timesys) - m_t0.secs(m_timesys);
195
196 // Computes phase
197 double phase = m_phase + dt * (m_f0 + dt * (c1 * m_f1 + c2 * m_f2 * dt));
198
199 // Put phase into interval [0,1]
200 phase -= floor(phase);
201
202 // Return phase
203 return phase;
204}
205
206
207/***********************************************************************//**
208 * @brief Print Pulsar ephemeris
209 *
210 * @param[in] chatter Chattiness.
211 * @return String containing Pulsar ephemeris information.
212 ***************************************************************************/
213std::string GPulsarEphemeris::print(const GChatter& chatter) const
214{
215 // Initialise result string
216 std::string result;
217
218 // Continue only if chatter is not silent
219 if (chatter != SILENT) {
220
221 // Append header
222 result.append("=== GPulsarEphemeris ===");
223
224 // Append pulsar name and direction
225 result.append("\n"+gammalib::parformat("Pulsar name"));
226 result.append(m_name);
227 result.append("\n"+gammalib::parformat("Pulsar Right Ascension"));
228 result.append(gammalib::str(m_dir.ra_deg()));
229 result.append(" deg");
230 result.append("\n"+gammalib::parformat("Pulsar Declination"));
231 result.append(gammalib::str(m_dir.dec_deg()));
232 result.append(" deg");
233
234 // Get phase information
235 double f0 = this->f0();
236
237 // Append phase information
238 result.append("\n"+gammalib::parformat("Time system of ephemeris"));
239 result.append(m_timesys);
240 result.append("\n"+gammalib::parformat("Reference epoch"));
241 result.append("MJD ");
242 result.append(gammalib::str(t0().mjd(m_timesys)));
243 result.append("\n"+gammalib::parformat("Phase"));
244 result.append(gammalib::str(phase()));
245 result.append("\n"+gammalib::parformat("Frequency"));
246 result.append(gammalib::str(f0));
247 result.append(" Hz");
248 result.append("\n"+gammalib::parformat("Frequency derivative"));
249 result.append(gammalib::str(f1()));
250 result.append(" Hz/s");
251 result.append("\n"+gammalib::parformat("2nd frequency derivative"));
252 result.append(gammalib::str(f2()));
253 result.append(" Hz/s^2");
254 result.append("\n"+gammalib::parformat("Period"));
255 if (f0 != 0.0) {
256 double p0 = 1.0 / f0;
257 if (p0 < 1.0) {
258 result.append(gammalib::str(p0*1000.0));
259 result.append(" ms");
260 }
261 else {
262 result.append(gammalib::str(p0));
263 result.append(" s");
264 }
265 }
266 else {
267 result.append("infinity");
268 }
269
270 // Append validity information
271 result.append("\n"+gammalib::parformat("Validity MJD range"));
272 result.append(gammalib::str(tstart().mjd(m_timesys)));
273 result.append(" - ");
274 result.append(gammalib::str(tstop().mjd(m_timesys)));
275 result.append("\n"+gammalib::parformat("Validity UTC range"));
276 result.append(tstart().utc());
277 result.append(" - ");
278 result.append(tstop().utc());
279
280 } // endif: chatter was not silent
281
282 // Return result
283 return result;
284}
285
286
287/*==========================================================================
288 = =
289 = Private methods =
290 = =
291 ==========================================================================*/
292
293/***********************************************************************//**
294 * @brief Initialise class members
295 ***************************************************************************/
297{
298 // Initialise members
299 m_name.clear();
300 m_tstart.clear();
301 m_tstop.clear();
302 m_dir.clear();
303 m_t0.clear();
304 m_timesys = "TT";
305 m_phase = 0.0;
306 m_f0 = 0.0;
307 m_f1 = 0.0;
308 m_f2 = 0.0;
309
310 // Return
311 return;
312}
313
314
315/***********************************************************************//**
316 * @brief Copy class members
317 *
318 * @param[in] ephemeris Pulsar ephemeris.
319 ***************************************************************************/
321{
322 // Copy members
323 m_name = ephemeris.m_name;
324 m_tstart = ephemeris.m_tstart;
325 m_tstop = ephemeris.m_tstop;
326 m_dir = ephemeris.m_dir;
327 m_timesys = ephemeris.m_timesys;
328 m_t0 = ephemeris.m_t0;
329 m_phase = ephemeris.m_phase;
330 m_f0 = ephemeris.m_f0;
331 m_f1 = ephemeris.m_f1;
332 m_f2 = ephemeris.m_f2;
333
334 // Return
335 return;
336}
337
338
339/***********************************************************************//**
340 * @brief Delete class members
341 ***************************************************************************/
343{
344 // Return
345 return;
346}
Pulsar ephemeris class definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
Pulsar ephemeris class.
double m_phase
Pulse phase.
const GTime & tstop(void) const
Returns validity stop time.
GPulsarEphemeris(void)
Void constructor.
GPulsarEphemeris & operator=(const GPulsarEphemeris &ephemeris)
Assignment operator.
void copy_members(const GPulsarEphemeris &ephemeris)
Copy class members.
virtual ~GPulsarEphemeris(void)
Destructor.
void init_members(void)
Initialise class members.
double m_f2
Pulsar second frequency derivative (s^-3)
virtual GPulsarEphemeris * clone(void) const
Clone Pulsar ephemeris.
void free_members(void)
Delete class members.
GSkyDir m_dir
Pulsar sky direction.
GTime m_tstart
Validity start time.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print Pulsar ephemeris.
const std::string & timesys(void) const
Returns pulsar ephemeris time system.
double f0(void) const
Returns pulsar frequency (Hz)
GTime t0(void) const
Returns reference epoch of pulsar ephemeris.
double f1(void) const
Returns pulsar frequency derivative (s^-2)
std::string m_name
Pulsar name.
virtual void clear(void)
Clear Pulsar ephemeris.
double m_f1
Pulsar frequency derivative (s^-2)
GTime m_t0
Reference epoch of pulsar ephemeris.
double f2(void) const
Returns pulsar second frequency derivative (s^-3)
GTime m_tstop
Validity stop time.
double m_f0
Pulsar frequency (Hz)
double phase(void) const
Returns pulse phase.
std::string m_timesys
Time system of pulsar ephemeris.
const GTime & tstart(void) const
Returns validity start time.
double dec_deg(void) const
Returns Declination in degrees.
Definition GSkyDir.hpp:258
double ra_deg(void) const
Returns Right Ascension in degrees.
Definition GSkyDir.hpp:231
void clear(void)
Clear sky direction.
Definition GSkyDir.cpp:185
Time class.
Definition GTime.hpp:55
void clear(void)
Clear time.
Definition GTime.cpp:252
const double & secs(void) const
Return time in seconds in native reference (TT)
Definition GTime.hpp:156
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1162
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508