GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GLATRoi.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GLATRoi.cpp - Fermi/LAT region of interest class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2013 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 GLATRoi.cpp
23  * @brief Fermi/LAT region of interest class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GLATRoi.hpp"
32 #include "GEvent.hpp"
33 #include "GTools.hpp"
34 
35 /* __ Method name definitions ____________________________________________ */
36 
37 /* __ Macros _____________________________________________________________ */
38 
39 /* __ Coding definitions _________________________________________________ */
40 
41 /* __ Debug definitions __________________________________________________ */
42 
43 
44 
45 /*==========================================================================
46  = =
47  = Constructors/destructors =
48  = =
49  ==========================================================================*/
50 
51 /***********************************************************************//**
52  * @brief Void constructor
53  ***************************************************************************/
55 {
56  // Initialise class members
57  init_members();
58 
59  // Return
60  return;
61 }
62 
63 
64 /***********************************************************************//**
65  * @brief Region of interest constructor
66  *
67  * @param[in] centre Region of interest centre.
68  * @param[in] radius Radius of region of interest (degrees).
69  ***************************************************************************/
70 GLATRoi::GLATRoi(const GLATInstDir& centre, const double& radius) : GRoi()
71 {
72  // Initialise class members
73  init_members();
74 
75  // Set members
76  this->centre(centre);
77  this->radius(radius);
78 
79  // Return
80  return;
81 }
82 
83 
84 /***********************************************************************//**
85  * @brief Copy constructor
86  *
87  * @param[in] roi Region of interest.
88  ***************************************************************************/
89 GLATRoi::GLATRoi(const GLATRoi& roi) : GRoi(roi)
90 {
91  // Initialise class members
92  init_members();
93 
94  // Copy members
95  copy_members(roi);
96 
97  // Return
98  return;
99 }
100 
101 
102 /***********************************************************************//**
103  * @brief Destructor
104  ***************************************************************************/
106 {
107  // Free members
108  free_members();
109 
110  // Return
111  return;
112 }
113 
114 
115 /*==========================================================================
116  = =
117  = Operators =
118  = =
119  ==========================================================================*/
120 
121 /***********************************************************************//**
122  * @brief Assignment operator
123  *
124  * @param[in] roi Region of interest.
125  * @return Region of interest.
126  ***************************************************************************/
128 {
129  // Execute only if object is not identical
130  if (this != &roi) {
131 
132  // Copy base class members
133  this->GRoi::operator=(roi);
134 
135  // Free members
136  free_members();
137 
138  // Initialise private members
139  init_members();
140 
141  // Copy members
142  copy_members(roi);
143 
144  } // endif: object was not identical
145 
146  // Return this object
147  return *this;
148 }
149 
150 
151 /*==========================================================================
152  = =
153  = Public methods =
154  = =
155  ==========================================================================*/
156 
157 /***********************************************************************//**
158  * @brief Clear region of interest
159  ***************************************************************************/
160 void GLATRoi::clear(void)
161 {
162  // Free members
163  free_members();
164  this->GRoi::free_members();
165 
166  // Initialise private members
167  this->GRoi::init_members();
168  init_members();
169 
170  // Return
171  return;
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Clone region of interest
177  *
178  * @return Pointer to deep copy of region of interest
179  ***************************************************************************/
181 {
182  return new GLATRoi(*this);
183 }
184 
185 
186 /***********************************************************************//**
187  * @brief Check if region of interest contains an event
188  *
189  * @return True if region of interest contains event, false otherwise
190  ***************************************************************************/
191 bool GLATRoi::contains(const GEvent& event) const
192 {
193  // Initialise flag to non-containment
194  bool contains = false;
195 
196  // Get pointer to Fermi/LAT instrument direction
197  const GLATInstDir* dir = dynamic_cast<const GLATInstDir*>(&event.dir());
198 
199  // If instrument direction is a Fermi/LAT instrument direction then check
200  // on containment
201  if (dir != NULL) {
202  if (m_centre.dir().dist_deg(dir->dir()) <= m_radius) {
203  contains = true;
204  }
205  }
206 
207  // Return containment flag
208  return contains;
209 }
210 
211 
212 /***********************************************************************//**
213  * @brief Print region of interest information
214  *
215  * @param[in] chatter Chattiness.
216  * @return String containing region of interest information.
217  ***************************************************************************/
218 std::string GLATRoi::print(const GChatter& chatter) const
219 {
220  // Initialise result string
221  std::string result;
222 
223  // Continue only if chatter is not silent
224  if (chatter != SILENT) {
225 
226  // Append header
227  result.append("=== GLATRoi ===");
228 
229  // Append information
230  result.append("\n"+gammalib::parformat("RoI centre"));
231  result.append(m_centre.print());
232  result.append("\n"+gammalib::parformat("RoI radius"));
233  result.append(gammalib::str(m_radius)+" deg");
234 
235  } // endif: chatter was not silent
236 
237  // Return result
238  return result;
239 }
240 
241 
242 /*==========================================================================
243  = =
244  = Private methods =
245  = =
246  ==========================================================================*/
247 
248 /***********************************************************************//**
249  * @brief Initialise class members
250  ***************************************************************************/
252 {
253  // Initialise members
254  m_centre.clear();
255  m_radius = 0.0;
256 
257  // Return
258  return;
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Copy class members
264  *
265  * @param[in] roi Region of interest from which members should be copied.
266  ***************************************************************************/
268 {
269  // Copy attributes
270  m_centre = roi.m_centre;
271  m_radius = roi.m_radius;
272 
273  // Return
274  return;
275 }
276 
277 
278 /***********************************************************************//**
279  * @brief Delete class members
280  ***************************************************************************/
282 {
283  // Return
284  return;
285 }
virtual GRoi & operator=(const GRoi &roi)
Assignment operator.
Definition: GRoi.cpp:104
void dir(const GSkyDir &dir)
Set sky direction.
void free_members(void)
Delete class members.
Definition: GLATRoi.cpp:281
Fermi/LAT instrument direction class.
Definition: GLATInstDir.hpp:48
virtual GLATRoi * clone(void) const
Clone region of interest.
Definition: GLATRoi.cpp:180
double m_radius
Radius of ROI in degrees.
Definition: GLATRoi.hpp:78
Abstract interface for the event classes.
Definition: GEvent.hpp:71
const double & radius(void) const
Returns radius of region of interest in degrees.
Definition: GLATRoi.hpp:116
Gammalib tools definition.
Fermi/LAT region of interest class definition.
GLATRoi & operator=(const GLATRoi &roi)
Assignment operator.
Definition: GLATRoi.cpp:127
std::string centre(const std::string &s, const int &n, const char &c= ' ')
Centre string to achieve a length of n characters.
Definition: GTools.cpp:1118
virtual bool contains(const GEvent &event) const
Check if region of interest contains an event.
Definition: GLATRoi.cpp:191
virtual void clear(void)
Clear Fermi/LAT instrument direction.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print region of interest information.
Definition: GLATRoi.cpp:218
void init_members(void)
Initialise class members.
Definition: GRoi.cpp:141
Abstract event base class definition.
void init_members(void)
Initialise class members.
Definition: GLATRoi.cpp:251
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
GChatter
Definition: GTypemaps.hpp:33
virtual void clear(void)
Clear region of interest.
Definition: GLATRoi.cpp:160
void free_members(void)
Delete class members.
Definition: GRoi.cpp:163
GLATRoi(void)
Void constructor.
Definition: GLATRoi.cpp:54
virtual ~GLATRoi(void)
Destructor.
Definition: GLATRoi.cpp:105
void copy_members(const GLATRoi &roi)
Copy class members.
Definition: GLATRoi.cpp:267
GLATInstDir m_centre
Centre of ROI in instrument coordinates.
Definition: GLATRoi.hpp:77
Interface for the region of interest classes.
Definition: GRoi.hpp:48
const GLATInstDir & centre(void) const
Returns region of interest centre.
Definition: GLATRoi.hpp:102
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
Fermi/LAT region of interest class.
Definition: GLATRoi.hpp:45
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489