GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GPhoton.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GPhoton.hpp - Photon class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2011-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 GPhoton.cpp
23  * @brief Photon class implementation
24  * @author Juergen Knodlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GPhoton.hpp"
32 #include "GTools.hpp"
33 
34 /* __ Constants __________________________________________________________ */
35 
36 /* __ Method name definitions ____________________________________________ */
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 
45 /*==========================================================================
46  = =
47  = Constructors/destructors =
48  = =
49  ==========================================================================*/
50 
51 /***********************************************************************//**
52  * @brief Void constructor
53  ***************************************************************************/
55 {
56  // Initialise private members
57  init_members();
58 
59  // Return
60  return;
61 }
62 
63 
64 /***********************************************************************//**
65  * @brief Photon constructor
66  *
67  * @param[in] dir Sky direction.
68  * @param[in] energy Energy.
69  * @param[in] time Time.
70  * @param[in] mc_id Monte-Carlo identifier.
71  ***************************************************************************/
72 GPhoton::GPhoton(const GSkyDir& dir, const GEnergy& energy,
73  const GTime& time, const int& mc_id)
74 {
75  // Initialise private members
76  init_members();
77 
78  // Set members
79  m_dir = dir;
80  m_energy = energy;
81  m_time = time;
82  m_mc_id = mc_id;
83 
84  // Return
85  return;
86 }
87 
88 
89 /***********************************************************************//**
90  * @brief Copy constructor
91  *
92  * @param[in] photon Photon.
93  ***************************************************************************/
94 GPhoton::GPhoton(const GPhoton& photon)
95 {
96  // Initialise private members
97  init_members();
98 
99  // Copy members
100  copy_members(photon);
101 
102  // Return
103  return;
104 }
105 
106 
107 /***********************************************************************//**
108  * @brief Destructor
109  ***************************************************************************/
111 {
112  // Free members
113  free_members();
114 
115  // Return
116  return;
117 }
118 
119 
120 /*==========================================================================
121  = =
122  = Operators =
123  = =
124  ==========================================================================*/
125 
126 /***********************************************************************//**
127  * @brief Assignment operator
128  *
129  * @param[in] photon Photon.
130  * @return Photon.
131  ***************************************************************************/
133 {
134  // Execute only if object is not identical
135  if (this != &photon) {
136 
137  // Free members
138  free_members();
139 
140  // Initialise private members for clean destruction
141  init_members();
142 
143  // Copy members
144  copy_members(photon);
145 
146  } // endif: object was not identical
147 
148  // Return
149  return *this;
150 }
151 
152 
153 /*==========================================================================
154  = =
155  = Public methods =
156  = =
157  ==========================================================================*/
158 
159 /***********************************************************************//**
160  * @brief Clear photon
161  ***************************************************************************/
162 void GPhoton::clear(void)
163 {
164  // Free members
165  free_members();
166 
167  // Initialise private members
168  init_members();
169 
170  // Return
171  return;
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Clone photon
177  *
178  * @return Pointer to deep copy of photon.
179  ***************************************************************************/
181 {
182  // Clone this photon
183  return new GPhoton(*this);
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Print photon
189  *
190  * @param[in] chatter Chattiness.
191  * @return String containing photon information.
192  ***************************************************************************/
193 std::string GPhoton::print(const GChatter& chatter) const
194 {
195  // Initialise result string
196  std::string result;
197 
198  // Continue only if chatter is not silent
199  if (chatter != SILENT) {
200 
201  // Build photon string
202  result.append("GPhoton(");
203  result.append("RA="+gammalib::str(m_dir.ra_deg()));
204  result.append(", Dec="+gammalib::str(m_dir.dec_deg()));
205  result.append(", E="+m_energy.print());
206  result.append(", MET="+m_time.print());
207  if (m_mc_id >= 0) {
208  result.append(", MC_ID="+gammalib::str(m_mc_id));
209  }
210  result.append(")");
211 
212  } // endif: chatter was not silent
213 
214  // Return
215  return result;
216 }
217 
218 
219 /*==========================================================================
220  = =
221  = Private methods =
222  = =
223  ==========================================================================*/
224 
225 /***********************************************************************//**
226  * @brief Initialise class members
227  ***************************************************************************/
229 {
230  // Initialise members
231  m_dir.clear();
232  m_energy.clear();
233  m_time.clear();
234  m_mc_id = -1;
235 
236  // Return
237  return;
238 }
239 
240 
241 /***********************************************************************//**
242  * @brief Copy class members
243  *
244  * @param[in] photon Photon.
245  ***************************************************************************/
246 void GPhoton::copy_members(const GPhoton& photon)
247 {
248  // Copy members
249  m_dir = photon.m_dir;
250  m_energy = photon.m_energy;
251  m_time = photon.m_time;
252  m_mc_id = photon.m_mc_id;
253 
254  // Return
255  return;
256 }
257 
258 
259 /***********************************************************************//**
260  * @brief Delete class members
261  ***************************************************************************/
263 {
264  // Return
265  return;
266 }
void copy_members(const GPhoton &photon)
Copy class members.
Definition: GPhoton.cpp:246
GTime m_time
Photon arrival time.
Definition: GPhoton.hpp:87
double dec_deg(void) const
Returns Declination in degrees.
Definition: GSkyDir.hpp:256
std::string print(const GChatter &chatter=NORMAL) const
Print photon.
Definition: GPhoton.cpp:193
GEnergy m_energy
Photon energy.
Definition: GPhoton.hpp:86
void free_members(void)
Delete class members.
Definition: GPhoton.cpp:262
void clear(void)
Clear time.
Definition: GTime.cpp:252
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
const int & mc_id(void) const
Return photon Monte-Carlo identifier.
Definition: GPhoton.hpp:146
Class that handles photons.
Definition: GPhoton.hpp:47
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
Definition: GEnergy.cpp:748
void clear(void)
Clear photon.
Definition: GPhoton.cpp:162
virtual ~GPhoton(void)
Destructor.
Definition: GPhoton.cpp:110
double ra_deg(void) const
Returns Right Ascension in degrees.
Definition: GSkyDir.hpp:229
GPhoton(void)
Void constructor.
Definition: GPhoton.cpp:54
const GTime & time(void) const
Return photon time.
Definition: GPhoton.hpp:134
GChatter
Definition: GTypemaps.hpp:33
void init_members(void)
Initialise class members.
Definition: GPhoton.cpp:228
std::string print(const GChatter &chatter=NORMAL) const
Print time.
Definition: GTime.cpp:1188
GPhoton * clone(void) const
Clone photon.
Definition: GPhoton.cpp:180
Photon class definition.
int m_mc_id
Monte Carlo simulation origin.
Definition: GPhoton.hpp:88
void clear(void)
Clear sky direction.
Definition: GSkyDir.cpp:164
GSkyDir m_dir
Photon arrival direction.
Definition: GPhoton.hpp:85
const GEnergy & energy(void) const
Return photon energy.
Definition: GPhoton.hpp:122
Sky direction class.
Definition: GSkyDir.hpp:62
const GSkyDir & dir(void) const
Return photon sky direction.
Definition: GPhoton.hpp:110
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489
GPhoton & operator=(const GPhoton &photon)
Assignment operator.
Definition: GPhoton.cpp:132