GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCOMRoi.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCOMRoi.cpp - COMPTEL region of interest class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2017-2021 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 GCOMRoi.cpp
23  * @brief COMPTEL 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 "GTools.hpp"
32 #include "GEvent.hpp"
33 #include "GCOMRoi.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 Copy constructor
66  *
67  * @param[in] roi COMPTEL region of interest.
68  ***************************************************************************/
69 GCOMRoi::GCOMRoi(const GCOMRoi& roi) : GRoi(roi)
70 {
71  // Initialise class members
72  init_members();
73 
74  // Copy members
75  copy_members(roi);
76 
77  // Return
78  return;
79 }
80 
81 
82 /***********************************************************************//**
83  * @brief Region of interest constructor
84  *
85  * @param[in] centre Instrument direction centre.
86  * @param[in] radius Instrument direction radius.
87  * @param[in] phibar_min Phibar minimum (deg).
88  * @param[in] phibar_max Phibar maximum (deg).
89  ***************************************************************************/
90 GCOMRoi::GCOMRoi(const GCOMInstDir& centre, const double& radius,
91  const double& phibar_min, const double& phibar_max) : GRoi()
92 
93 {
94  // Initialise class members
95  init_members();
96 
97  // Set members
98  this->centre(centre);
99  this->radius(radius);
100  this->phibar_min(phibar_min);
101  this->phibar_max(phibar_max);
102 
103  // Return
104  return;
105 }
106 
107 
108 /***********************************************************************//**
109  * @brief Destructor
110  ***************************************************************************/
112 {
113  // Free members
114  free_members();
115 
116  // Return
117  return;
118 }
119 
120 
121 /*==========================================================================
122  = =
123  = Operators =
124  = =
125  ==========================================================================*/
126 
127 /***********************************************************************//**
128  * @brief Assignment operator
129  *
130  * @param[in] roi COMPTEL region of interest.
131  * @return COMPTEL region of interest.
132  ***************************************************************************/
134 {
135  // Execute only if object is not identical
136  if (this != &roi) {
137 
138  // Copy base class members
139  this->GRoi::operator=(roi);
140 
141  // Free members
142  free_members();
143 
144  // Initialise private members
145  init_members();
146 
147  // Copy members
148  copy_members(roi);
149 
150  } // endif: object was not identical
151 
152  // Return this object
153  return *this;
154 }
155 
156 
157 /*==========================================================================
158  = =
159  = Public methods =
160  = =
161  ==========================================================================*/
162 
163 /***********************************************************************//**
164  * @brief Clear region of interest
165  ***************************************************************************/
166 void GCOMRoi::clear(void)
167 {
168  // Free members
169  free_members();
170  this->GRoi::free_members();
171 
172  // Initialise private members
173  this->GRoi::init_members();
174  init_members();
175 
176  // Return
177  return;
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Clone region of interest
183  *
184  * @return Pointer to deep copy of COMPTEL region of interest.
185  ***************************************************************************/
187 {
188  return new GCOMRoi(*this);
189 }
190 
191 
192 /***********************************************************************//**
193  * @brief Check if region of interest contains an event
194  *
195  * @return True if region of interest contains event, false otherwise.
196  ***************************************************************************/
197 bool GCOMRoi::contains(const GEvent& event) const
198 {
199  // Initialise flag to non-containment
200  bool contains = false;
201 
202  // Get pointer to COMPTEL instrument direction
203  const GCOMInstDir* dir = dynamic_cast<const GCOMInstDir*>(&event.dir());
204 
205  // If instrument direction is a COMPTEL instrument direction then check
206  // on containment
207  if (dir != NULL) {
208  if ((m_centre.dir().dist_deg(dir->dir()) <= m_radius) &&
209  (m_phibar_min <= dir->phibar()) &&
210  (m_phibar_max >= dir->phibar())) {
211  contains = true;
212  }
213  }
214 
215  // Return containment flag
216  return contains;
217 }
218 
219 
220 /***********************************************************************//**
221  * @brief Print region of interest information
222  *
223  * @param[in] chatter Chattiness.
224  * @return String containing region of interest information.
225  *
226  * @todo Implement method.
227  ***************************************************************************/
228 std::string GCOMRoi::print(const GChatter& chatter) const
229 {
230  // Initialise result string
231  std::string result;
232 
233  // Continue only if chatter is not silent
234  if (chatter != SILENT) {
235 
236  // Append header
237  result.append("=== GCOMRoi ===");
238 
239  // Append information
240  result.append("\n"+gammalib::parformat("RoI centre"));
241  result.append(m_centre.print());
242  result.append("\n"+gammalib::parformat("RoI radius"));
243  result.append(gammalib::str(m_radius)+" deg");
244  result.append("\n"+gammalib::parformat("Phibar range"));
245  result.append(gammalib::str(m_phibar_min)+" - ");
246  result.append(gammalib::str(m_phibar_max)+" deg");
247 
248  } // endif: chatter was not silent
249 
250  // Return result
251  return result;
252 }
253 
254 
255 /*==========================================================================
256  = =
257  = Private methods =
258  = =
259  ==========================================================================*/
260 
261 /***********************************************************************//**
262  * @brief Initialise class members
263  ***************************************************************************/
265 {
266  // Initialise members
267  m_centre.clear();
268  m_radius = 0.0;
269  m_phibar_min = 0.0;
270  m_phibar_max = 0.0;
271 
272  // Return
273  return;
274 }
275 
276 
277 /***********************************************************************//**
278  * @brief Copy class members
279  *
280  * @param[in] roi COMPTEL region of interest.
281  ***************************************************************************/
283 {
284  // Copy attributes
285  m_centre = roi.m_centre;
286  m_radius = roi.m_radius;
289 
290  // Return
291  return;
292 }
293 
294 
295 /***********************************************************************//**
296  * @brief Delete class members
297  ***************************************************************************/
299 {
300  // Return
301  return;
302 }
void phibar(const double &phibar)
Set event Compton scatter angle.
virtual GRoi & operator=(const GRoi &roi)
Assignment operator.
Definition: GRoi.cpp:104
const GCOMInstDir & centre(void) const
Return centre of region of interest.
Definition: GCOMRoi.hpp:108
double m_radius
Radius of region of interest.
Definition: GCOMRoi.hpp:82
void free_members(void)
Delete class members.
Definition: GCOMRoi.cpp:298
Abstract interface for the event classes.
Definition: GEvent.hpp:71
Gammalib tools definition.
virtual GCOMRoi * clone(void) const
Clone region of interest.
Definition: GCOMRoi.cpp:186
COMPTEL region of interest class definition.
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 std::string print(const GChatter &chatter=NORMAL) const
Print region of interest information.
Definition: GCOMRoi.cpp:228
GCOMInstDir m_centre
Centre of RoI in instrument coordinates.
Definition: GCOMRoi.hpp:81
virtual bool contains(const GEvent &event) const
Check if region of interest contains an event.
Definition: GCOMRoi.cpp:197
GCOMRoi(void)
Void constructor.
Definition: GCOMRoi.cpp:54
virtual ~GCOMRoi(void)
Destructor.
Definition: GCOMRoi.cpp:111
void dir(const GSkyDir &dir)
Set event scatter direction.
void init_members(void)
Initialise class members.
Definition: GRoi.cpp:141
virtual std::string print(const GChatter &chatter=NORMAL) const
Print instrument direction information.
Abstract event base class definition.
virtual void clear(void)
Clear region of interest.
Definition: GCOMRoi.cpp:166
double m_phibar_min
Minimum Phibar of region of interest.
Definition: GCOMRoi.hpp:83
GChatter
Definition: GTypemaps.hpp:33
void copy_members(const GCOMRoi &roi)
Copy class members.
Definition: GCOMRoi.cpp:282
COMPTEL region of interest class.
Definition: GCOMRoi.hpp:44
void free_members(void)
Delete class members.
Definition: GRoi.cpp:163
double m_phibar_max
Minimum Phibar of region of interest.
Definition: GCOMRoi.hpp:84
virtual void clear(void)
Clear instance.
const double & phibar_max(void) const
Return maximum Phibar of region of interest.
Definition: GCOMRoi.hpp:195
const double & phibar_min(void) const
Return minimum Phibar of region of interest.
Definition: GCOMRoi.hpp:166
void init_members(void)
Initialise class members.
Definition: GCOMRoi.cpp:264
Interface for the region of interest classes.
Definition: GRoi.hpp:48
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
const double & radius(void) const
Return radius of region of interest.
Definition: GCOMRoi.hpp:137
GCOMRoi & operator=(const GCOMRoi &roi)
Assignment operator.
Definition: GCOMRoi.cpp:133
Interface for the COMPTEL instrument direction class.
Definition: GCOMInstDir.hpp:45
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489