GammaLib 2.0.0
Loading...
Searching...
No Matches
GCOMTools.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCOMTools.cpp - COMPTEL tools *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2021-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 GCOMTools.hpp
23 * @brief Implementation of COMPTEL tools
24 * @author Juergen Knoedlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include "GTime.hpp"
32#include "GTools.hpp"
33#include "GCOMTools.hpp"
34
35/* __ Coding definitions _________________________________________________ */
36
37/* __ Debug definitions __________________________________________________ */
38
39
40/***********************************************************************//**
41 * @brief Convert TJD and COMPTEL tics in GTime object
42 *
43 * @param[in] tjd Truncated Julian Days (days).
44 * @param[in] tics COMPTEL tics (1/8 ms).
45 * @return Time.
46 *
47 * Converts TJD and COMPTEL tics into a GTime object. COMPTEL times are
48 * given in UTC, i.e. 8393:0 converts into 1991-05-17T00:00:00 UT
49 * (see COM-RP-UNH-DRG-037).
50 *
51 * The method applies the CGRO clock correction. The CGRO clock was too
52 * fast by 2.042144 seconds before 8798:28800000 (1992-06-25T01:00:00).
53 * After that date the clock was corrected.
54 ***************************************************************************/
55GTime gammalib::com_time(const int& tjd, const int& tics)
56{
57 // Compute tics to days conversion factor
58 const double tics2days = 0.000125 * gammalib::sec2day;
59 const double clockcor_days = 2.042144 * gammalib::sec2day;
60
61 // Compute MJD
62 double mjd = double(tjd) + 40000.0 + double(tics) * tics2days;
63
64 // Apply CGRO clock correction as the clock was too fast by 2.042144 sec
65 // before 8798:28800000 (1992-06-25T01:00:00).
66 if ((tjd < 8798) || ((tjd == 8798) && (tics < 28800000))) {
67 mjd -= clockcor_days;
68 }
69
70 // Set time in MJD in the UTC time system
71 GTime time;
72 time.mjd(mjd, "UTC");
73
74 // Return time
75 return time;
76}
77
78
79/***********************************************************************//**
80 * @brief Convert GTime in COMPTEL TJD
81 *
82 * @param[in] time Time.
83 * @return Truncated Julian Days (days).
84 *
85 * Converts GTime object in TJD.
86 *
87 * The method applies the CGRO clock correction. The CGRO clock was too
88 * fast by 2.042144 seconds before 8798:28800000 (1992-06-25T01:00:00).
89 * After that date the clock was corrected.
90 ***************************************************************************/
91int gammalib::com_tjd(const GTime& time)
92{
93 // Set MJD in UTC of clock correction
94 const double mjd_of_clockcor = 48798.04166666666424134746;
95 const double clockcor_days = 2.042144 * gammalib::sec2day;
96 const double half_tics2days = 0.5 * 0.000125 * gammalib::sec2day;
97
98 // Compute MJD, applying the CGRO clock correction before 8798:28800000
99 // (1992-06-25T01:00:00)
100 double mjd = time.mjd("UTC");
101 if (mjd < mjd_of_clockcor) {
102 mjd += clockcor_days;
103 }
104
105 // Compute TJD, rounding to the nearest tics
106 int tjd = int(mjd + half_tics2days) - 40000;
107
108 // Return TJD
109 return tjd;
110}
111
112
113/***********************************************************************//**
114 * @brief Convert GTime in COMPTEL tics
115 *
116 * @param[in] time Time.
117 * @return COMPTEL tics (1/8 ms).
118 *
119 * Converts GTime object in COMPTEL tics (1/8 ms).
120 *
121 * The method applies the CGRO clock correction. The CGRO clock was too
122 * fast by 2.042144 seconds before 8798:28800000 (1992-06-25T01:00:00).
123 * After that date the clock was corrected.
124 ***************************************************************************/
125int gammalib::com_tics(const GTime& time)
126{
127 // Set MJD in UTC of clock correction
128 const double mjd_of_clockcor = 48798.04166666666424134746;
129 const double clockcor_days = 2.042144 * gammalib::sec2day;
130 const int tics_in_day = 691200000;
131
132 // Compute MJD, applying the CGRO clock correction before 8798:28800000
133 // (1992-06-25T01:00:00)
134 double mjd = time.mjd("UTC");
135 if (mjd < mjd_of_clockcor) {
136 mjd += clockcor_days;
137 }
138
139 // Compute number of tics, rounding to nearest int
140 int tics = int((mjd - double(int(mjd))) * tics_in_day + 0.5);
141
142 // If number of tics exceeds number of tics in one day then decrement
143 // number of tics
144 while (tics >= tics_in_day) {
145 tics -= tics_in_day;
146 }
147
148 // Return tics
149 return tics;
150}
Definition of COMPTEL tools.
Time class interface definition.
Gammalib tools definition.
Time class.
Definition GTime.hpp:55
double mjd(void) const
Return time in Modified Julian Days (TT)
Definition GTime.cpp:320
const double sec2day
Definition GTools.hpp:50
int com_tics(const GTime &time)
Convert GTime in COMPTEL tics.
int com_tjd(const GTime &time)
Convert GTime in COMPTEL TJD.
Definition GCOMTools.cpp:91
GTime com_time(const int &tjd, const int &tics)
Convert TJD and COMPTEL tics in GTime object.
Definition GCOMTools.cpp:55