GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GPhoton.hpp
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.hpp
23  * @brief Photon class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GPHOTON_HPP
28 #define GPHOTON_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GBase.hpp"
33 #include "GSkyDir.hpp"
34 #include "GEnergy.hpp"
35 #include "GTime.hpp"
36 
37 
38 /***********************************************************************//**
39  * @class GPhoton
40  *
41  * @brief Class that handles photons.
42  *
43  * The GPhoton class stores the physical attributes of a photon such as the
44  * photon arrival direction, its energy and its arrival time. This class is
45  * mainly used for Monte Carlo simulations.
46  ***************************************************************************/
47 class GPhoton : public GBase {
48 
49  // Operator friends
50  friend bool operator==(const GPhoton &a, const GPhoton &b);
51  friend bool operator!=(const GPhoton &a, const GPhoton &b);
52 
53 public:
54  // Constructors and destructors
55  GPhoton(void);
56  GPhoton(const GSkyDir& dir, const GEnergy& energy, const GTime& time,
57  const int& mc_id = -1);
58  GPhoton(const GPhoton& photon);
59  virtual ~GPhoton(void);
60 
61  // Operators
62  GPhoton& operator=(const GPhoton& photon);
63 
64  // Methods
65  void clear(void);
66  GPhoton* clone(void) const;
67  std::string classname(void) const;
68  const GSkyDir& dir(void) const;
69  const GEnergy& energy(void) const;
70  const GTime& time(void) const;
71  const int& mc_id(void) const;
72  void dir(const GSkyDir& dir);
73  void energy(const GEnergy& energy);
74  void time(const GTime& time);
75  void mc_id(const int& mc_id);
76  std::string print(const GChatter& chatter = NORMAL) const;
77 
78 protected:
79  // Protected methods
80  void init_members(void);
81  void copy_members(const GPhoton& photon);
82  void free_members(void);
83 
84  // Protected data members
85  GSkyDir m_dir; //!< Photon arrival direction
86  GEnergy m_energy; //!< Photon energy
87  GTime m_time; //!< Photon arrival time
88  int m_mc_id; //!< Monte Carlo simulation origin
89 };
90 
91 
92 /***********************************************************************//**
93  * @brief Return class name
94  *
95  * @return String containing the class name ("GPhoton").
96  ***************************************************************************/
97 inline
98 std::string GPhoton::classname(void) const
99 {
100  return ("GPhoton");
101 }
102 
103 
104 /***********************************************************************//**
105  * @brief Return photon sky direction
106  *
107  * @return Sky direction of photon.
108  ***************************************************************************/
109 inline
110 const GSkyDir& GPhoton::dir(void) const
111 {
112  return m_dir;
113 }
114 
115 
116 /***********************************************************************//**
117  * @brief Return photon energy
118  *
119  * @return Energy of photon.
120  ***************************************************************************/
121 inline
122 const GEnergy& GPhoton::energy(void) const
123 {
124  return m_energy;
125 }
126 
127 
128 /***********************************************************************//**
129  * @brief Return photon time
130  *
131  * @return Time of photon.
132  ***************************************************************************/
133 inline
134 const GTime& GPhoton::time(void) const
135 {
136  return m_time;
137 }
138 
139 
140 /***********************************************************************//**
141  * @brief Return photon Monte-Carlo identifier
142  *
143  * @return Photon Monte-Carlo identifier.
144  ***************************************************************************/
145 inline
146 const int& GPhoton::mc_id(void) const
147 {
148  return m_mc_id;
149 }
150 
151 
152 /***********************************************************************//**
153  * @brief Set photon sky direction
154  *
155  * @param[in] dir Sky direction of photon.
156  ***************************************************************************/
157 inline
158 void GPhoton::dir(const GSkyDir& dir)
159 {
160  m_dir = dir;
161  return;
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Set photon energy
167  *
168  * @param[in] energy Photon energy.
169  ***************************************************************************/
170 inline
171 void GPhoton::energy(const GEnergy& energy)
172 {
173  m_energy = energy;
174  return;
175 }
176 
177 
178 /***********************************************************************//**
179  * @brief Set photon time
180  *
181  * @param[in] time Photon time.
182  ***************************************************************************/
183 inline
184 void GPhoton::time(const GTime& time)
185 {
186  m_time = time;
187  return;
188 }
189 
190 
191 /***********************************************************************//**
192  * @brief Set photon Monte-Carlo identifier
193  *
194  * @param[in] mc_id Photon Monte-Carlo identifier.
195  ***************************************************************************/
196 inline
197 void GPhoton::mc_id(const int& mc_id)
198 {
199  m_mc_id = mc_id;
200  return;
201 }
202 
203 
204 /***********************************************************************//**
205  * @brief Equality friend operator
206  *
207  * @param[in] a First photon.
208  * @param[in] b Second photon.
209  * @return True is first photon is identical to second photon
210  ***************************************************************************/
211 inline
212 bool operator==(const GPhoton &a, const GPhoton &b)
213 {
214  return (a.m_energy == b.m_energy && a.m_time == b.m_time &&
215  a.m_dir.dist(b.m_dir) == 0.0);
216 }
217 
218 
219 /***********************************************************************//**
220  * @brief Non-equality friend operator
221  *
222  * @param[in] a First photon.
223  * @param[in] b Second photon.
224  * @return True is first photon is not identical to second photon
225  ***************************************************************************/
226 inline
227 bool operator!=(const GPhoton &a, const GPhoton &b)
228 {
229  return (a.m_energy != b.m_energy || a.m_time != b.m_time ||
230  a.m_dir.dist(b.m_dir) > 0.0);
231 }
232 
233 #endif /* GPHOTON_HPP */
void copy_members(const GPhoton &photon)
Copy class members.
Definition: GPhoton.cpp:246
GTime m_time
Photon arrival time.
Definition: GPhoton.hpp:87
Energy value class definition.
std::string print(const GChatter &chatter=NORMAL) const
Print photon.
Definition: GPhoton.cpp:193
GEnergy m_energy
Photon energy.
Definition: GPhoton.hpp:86
Sky direction class interface definition.
void free_members(void)
Delete class members.
Definition: GPhoton.cpp:262
Definition of interface for all GammaLib classes.
friend bool operator!=(const GPhoton &a, const GPhoton &b)
Non-equality friend operator.
Definition: GPhoton.hpp:227
Time class.
Definition: GTime.hpp:55
const int & mc_id(void) const
Return photon Monte-Carlo identifier.
Definition: GPhoton.hpp:146
Class that handles photons.
Definition: GPhoton.hpp:47
void clear(void)
Clear photon.
Definition: GPhoton.cpp:162
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
virtual ~GPhoton(void)
Destructor.
Definition: GPhoton.cpp:110
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
GPhoton * clone(void) const
Clone photon.
Definition: GPhoton.cpp:180
friend bool operator==(const GPhoton &a, const GPhoton &b)
Equality friend operator.
Definition: GPhoton.hpp:212
int m_mc_id
Monte Carlo simulation origin.
Definition: GPhoton.hpp:88
std::string classname(void) const
Return class name.
Definition: GPhoton.hpp:98
GSkyDir m_dir
Photon arrival direction.
Definition: GPhoton.hpp:85
const GEnergy & energy(void) const
Return photon energy.
Definition: GPhoton.hpp:122
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
Definition: GSkyDir.hpp:271
bool operator==(const GEnergy &a, const GEnergy &b)
Energy equality operator friend.
Definition: GEnergy.hpp:297
Sky direction class.
Definition: GSkyDir.hpp:62
const GSkyDir & dir(void) const
Return photon sky direction.
Definition: GPhoton.hpp:110
Time class interface definition.
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:213
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
GPhoton & operator=(const GPhoton &photon)
Assignment operator.
Definition: GPhoton.cpp:132