GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GCOSRoi.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCOSRoi.cpp - COSI region of interest class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2026 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 GCOSRoi.cpp
23 * @brief COSI 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 "GEvent.hpp"
32#include "GCOSRoi.hpp"
33#include "GCOSInstDir.hpp"
34
35/* __ Method name definitions ____________________________________________ */
36
37/* __ Macros _____________________________________________________________ */
38
39/* __ Coding definitions _________________________________________________ */
40#define G_RADIUS "GCOSRoi::radius(double&)"
41
42/* __ Debug definitions __________________________________________________ */
43
44
45
46/*==========================================================================
47 = =
48 = Constructors/destructors =
49 = =
50 ==========================================================================*/
51
52/***********************************************************************//**
53 * @brief Void constructor
54 ***************************************************************************/
56{
57 // Initialise class members
59
60 // Return
61 return;
62}
63
64
65/***********************************************************************//**
66 * @brief Radius constructor
67 *
68 * @param[in] radius Region of interest radius
69 ***************************************************************************/
70GCOSRoi::GCOSRoi(const double& radius) : GRoi()
71{
72 // Initialise class members
74
75 // Set radius
76 this->radius(radius);
77
78 // Return
79 return;
80}
81
82
83/***********************************************************************//**
84 * @brief Copy constructor
85 *
86 * @param[in] roi COSI region of interest.
87 ***************************************************************************/
88GCOSRoi::GCOSRoi(const GCOSRoi& roi) : GRoi(roi)
89{
90 // Initialise class members
92
93 // Copy members
94 copy_members(roi);
95
96 // Return
97 return;
98}
99
100
101/***********************************************************************//**
102 * @brief Destructor
103 ***************************************************************************/
105{
106 // Free members
107 free_members();
108
109 // Return
110 return;
111}
112
113
114/*==========================================================================
115 = =
116 = Operators =
117 = =
118 ==========================================================================*/
119
120/***********************************************************************//**
121 * @brief Assignment operator
122 *
123 * @param[in] roi COSI region of interest.
124 * @return COSI region of interest.
125 ***************************************************************************/
127{
128 // Execute only if object is not identical
129 if (this != &roi) {
130
131 // Copy base class members
132 this->GRoi::operator=(roi);
133
134 // Free members
135 free_members();
136
137 // Initialise private members
138 init_members();
139
140 // Copy members
141 copy_members(roi);
142
143 } // endif: object was not identical
144
145 // Return this object
146 return *this;
147}
148
149
150/*==========================================================================
151 = =
152 = Public methods =
153 = =
154 ==========================================================================*/
155
156/***********************************************************************//**
157 * @brief Clear region of interest
158 ***************************************************************************/
160{
161 // Free members
162 free_members();
163 this->GRoi::free_members();
164
165 // Initialise private members
166 this->GRoi::init_members();
167 init_members();
168
169 // Return
170 return;
171}
172
173
174/***********************************************************************//**
175 * @brief Clone region of interest
176 *
177 * @return Pointer to deep copy of COSI region of interest.
178 ***************************************************************************/
180{
181 return new GCOSRoi(*this);
182}
183
184
185/***********************************************************************//**
186 * @brief Check if region of interest contains an event
187 *
188 * @return True if region of interest contains event, false otherwise.
189 *
190 * This method checks whether an event is contained in the region of interest.
191 * As COSI regions of interest are always 180 deg an event is always
192 * contained in the region in case that a region of interest is defined (i.e.
193 * it has a radius of 180 deg).
194 *
195 * If the instrument direction of the event is not of type GCOSInstDir then
196 * the method returns false.
197 ***************************************************************************/
198bool GCOSRoi::contains(const GEvent& event) const
199{
200 // Initialise flag to non-containment
201 bool contains = false;
202
203 // Get pointer to COSI instrument direction
204 const GCOSInstDir* dir = dynamic_cast<const GCOSInstDir*>(&event.dir());
205
206 // If instrument direction is a COSI instrument direction then check on
207 // containment
208 if (dir != NULL) {
209
210 // If region of interest radius is 180 deg then instrument direction
211 // is certainty contained into the region
212 if (m_radius == 180.0) {
213 contains = true;
214 }
215
216 } // endif: pointer was a COSI instrument direction
217
218 // Return containment flag
219 return contains;
220}
221
222
223/***********************************************************************//**
224 * @brief Set radius of region of interest
225 *
226 * @param[in] radius Region of interest radius (degrees).
227 *
228 * @exception GException::invalid_argument
229 * ROI radius is not 0 or 180 degrees.
230 *
231 * Set the radius of the region of interest.
232 ***************************************************************************/
233void GCOSRoi::radius(const double& radius)
234{
235 // Throw an exception if argument is not valid
236 if ((radius != 0.0) && (radius != 180.0)) {
237 std::string msg = "Invalid RoI radius "+gammalib::str(radius)+
238 " specified. The radius must be either 0 or 180"
239 " degrees.";
241 }
242
243 // Set radius value
245
246 // Return
247 return;
248}
249
250
251/***********************************************************************//**
252 * @brief Print region of interest information
253 *
254 * @param[in] chatter Chattiness.
255 * @return String containing region of interest information.
256 ***************************************************************************/
257std::string GCOSRoi::print(const GChatter& chatter) const
258{
259 // Initialise result string
260 std::string result;
261
262 // Continue only if chatter is not silent
263 if (chatter != SILENT) {
264
265 // Append header
266 result.append("=== GCOSRoi ===");
267
268 // Append information
269 result.append("\n"+gammalib::parformat("RoI radius"));
270 result.append(gammalib::str(m_radius)+" deg");
271
272 } // endif: chatter was not silent
273
274 // Return result
275 return result;
276}
277
278
279/*==========================================================================
280 = =
281 = Private methods =
282 = =
283 ==========================================================================*/
284
285/***********************************************************************//**
286 * @brief Initialise class members
287 ***************************************************************************/
289{
290 // Initialise members
291 m_radius = 0.0;
292
293 // Return
294 return;
295}
296
297
298/***********************************************************************//**
299 * @brief Copy class members
300 *
301 * @param[in] roi COSI region of interest.
302 ***************************************************************************/
304{
305 // Copy members
306 m_radius = roi.m_radius;
307
308 // Return
309 return;
310}
311
312
313/***********************************************************************//**
314 * @brief Delete class members
315 ***************************************************************************/
317{
318 // Return
319 return;
320}
COSI instrument direction class definition.
COSI region of interest class definition.
Abstract event base class definition.
#define G_RADIUS
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
COSI instrument direction class.
COSI region of interest class.
Definition GCOSRoi.hpp:50
double m_radius
Region of interest radius.
Definition GCOSRoi.hpp:80
virtual bool contains(const GEvent &event) const
Check if region of interest contains an event.
Definition GCOSRoi.cpp:198
const double & radius(void) const
Returns region of interest radius.
Definition GCOSRoi.hpp:104
GCOSRoi & operator=(const GCOSRoi &roi)
Assignment operator.
Definition GCOSRoi.cpp:126
virtual ~GCOSRoi(void)
Destructor.
Definition GCOSRoi.cpp:104
void copy_members(const GCOSRoi &roi)
Copy class members.
Definition GCOSRoi.cpp:303
virtual GCOSRoi * clone(void) const
Clone region of interest.
Definition GCOSRoi.cpp:179
virtual std::string print(const GChatter &chatter=NORMAL) const
Print region of interest information.
Definition GCOSRoi.cpp:257
virtual void clear(void)
Clear region of interest.
Definition GCOSRoi.cpp:159
GCOSRoi(void)
Void constructor.
Definition GCOSRoi.cpp:55
void free_members(void)
Delete class members.
Definition GCOSRoi.cpp:316
void init_members(void)
Initialise class members.
Definition GCOSRoi.cpp:288
Abstract interface for the event classes.
Definition GEvent.hpp:71
Interface for the region of interest classes.
Definition GRoi.hpp:48
virtual GRoi & operator=(const GRoi &roi)
Assignment operator.
Definition GRoi.cpp:104
void free_members(void)
Delete class members.
Definition GRoi.cpp:163
void init_members(void)
Initialise class members.
Definition GRoi.cpp:141
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition GTools.cpp:1136
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:508