GammaLib  1.7.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 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 "GEvent.hpp"
32 #include "GCOMRoi.hpp"
33 
34 /* __ Method name definitions ____________________________________________ */
35 
36 /* __ Macros _____________________________________________________________ */
37 
38 /* __ Coding definitions _________________________________________________ */
39 
40 /* __ Debug definitions __________________________________________________ */
41 
42 
43 
44 /*==========================================================================
45  = =
46  = Constructors/destructors =
47  = =
48  ==========================================================================*/
49 
50 /***********************************************************************//**
51  * @brief Void constructor
52  ***************************************************************************/
54 {
55  // Initialise class members
56  init_members();
57 
58  // Return
59  return;
60 }
61 
62 
63 /***********************************************************************//**
64  * @brief Copy constructor
65  *
66  * @param[in] roi COMPTEL region of interest.
67  ***************************************************************************/
68 GCOMRoi::GCOMRoi(const GCOMRoi& roi) : GRoi(roi)
69 {
70  // Initialise class members
71  init_members();
72 
73  // Copy members
74  copy_members(roi);
75 
76  // Return
77  return;
78 }
79 
80 
81 /***********************************************************************//**
82  * @brief Region of interest constructor
83  *
84  * @param[in] centre Instrument direction centre.
85  * @param[in] radius Instrument direction radius.
86  * @param[in] phibar_min Phibar minimum (deg).
87  * @param[in] phibar_max Phibar maximum (deg).
88  ***************************************************************************/
89 GCOMRoi::GCOMRoi(const GCOMInstDir& centre, const double& radius,
90  const double& phibar_min, const double& phibar_max) : GRoi()
91 
92 {
93  // Initialise class members
94  init_members();
95 
96  // Set members
97  this->centre(centre);
98  this->radius(radius);
99  this->phibar_min(phibar_min);
100  this->phibar_max(phibar_max);
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] roi COMPTEL region of interest.
130  * @return COMPTEL region of interest.
131  ***************************************************************************/
133 {
134  // Execute only if object is not identical
135  if (this != &roi) {
136 
137  // Copy base class members
138  this->GRoi::operator=(roi);
139 
140  // Free members
141  free_members();
142 
143  // Initialise private members
144  init_members();
145 
146  // Copy members
147  copy_members(roi);
148 
149  } // endif: object was not identical
150 
151  // Return this object
152  return *this;
153 }
154 
155 
156 /*==========================================================================
157  = =
158  = Public methods =
159  = =
160  ==========================================================================*/
161 
162 /***********************************************************************//**
163  * @brief Clear region of interest
164  ***************************************************************************/
165 void GCOMRoi::clear(void)
166 {
167  // Free members
168  free_members();
169  this->GRoi::free_members();
170 
171  // Initialise private members
172  this->GRoi::init_members();
173  init_members();
174 
175  // Return
176  return;
177 }
178 
179 
180 /***********************************************************************//**
181  * @brief Clone region of interest
182  *
183  * @return Pointer to deep copy of COMPTEL region of interest.
184  ***************************************************************************/
186 {
187  return new GCOMRoi(*this);
188 }
189 
190 
191 /***********************************************************************//**
192  * @brief Check if region of interest contains an event
193  *
194  * @return True if region of interest contains event, false otherwise.
195  ***************************************************************************/
196 bool GCOMRoi::contains(const GEvent& event) const
197 {
198  // Initialise flag to non-containment
199  bool contains = false;
200 
201  // Get pointer to COMPTEL instrument direction
202  const GCOMInstDir* dir = dynamic_cast<const GCOMInstDir*>(&event.dir());
203 
204  // If instrument direction is a COMPTEL instrument direction then check
205  // on containment
206  if (dir != NULL) {
207  if ((m_centre.dir().dist_deg(dir->dir()) <= m_radius) &&
208  (m_phibar_min <= dir->phibar()) &&
209  (m_phibar_max >= dir->phibar())) {
210  contains = true;
211  }
212  }
213 
214  // Return containment flag
215  return contains;
216 }
217 
218 
219 /***********************************************************************//**
220  * @brief Print region of interest information
221  *
222  * @param[in] chatter Chattiness.
223  * @return String containing region of interest information.
224  *
225  * @todo Implement method.
226  ***************************************************************************/
227 std::string GCOMRoi::print(const GChatter& chatter) const
228 {
229  // Initialise result string
230  std::string result;
231 
232  // Continue only if chatter is not silent
233  if (chatter != SILENT) {
234 
235  // Append header
236  result.append("=== GCOMRoi ===");
237 
238  // Append information
239  result.append("\n"+gammalib::parformat("RoI centre"));
240  result.append(m_centre.print());
241  result.append("\n"+gammalib::parformat("RoI radius"));
242  result.append(gammalib::str(m_radius)+" deg");
243  result.append("\n"+gammalib::parformat("Phibar range"));
244  result.append(gammalib::str(m_phibar_min)+" - ");
245  result.append(gammalib::str(m_phibar_max)+" deg");
246 
247  } // endif: chatter was not silent
248 
249  // Return result
250  return result;
251 }
252 
253 
254 /*==========================================================================
255  = =
256  = Private methods =
257  = =
258  ==========================================================================*/
259 
260 /***********************************************************************//**
261  * @brief Initialise class members
262  ***************************************************************************/
264 {
265  // Initialise members
266  m_centre.clear();
267  m_radius = 0.0;
268  m_phibar_min = 0.0;
269  m_phibar_max = 0.0;
270 
271  // Return
272  return;
273 }
274 
275 
276 /***********************************************************************//**
277  * @brief Copy class members
278  *
279  * @param[in] roi COMPTEL region of interest.
280  ***************************************************************************/
282 {
283  // Copy attributes
284  m_centre = roi.m_centre;
285  m_radius = roi.m_radius;
288 
289  // Return
290  return;
291 }
292 
293 
294 /***********************************************************************//**
295  * @brief Delete class members
296  ***************************************************************************/
298 {
299  // Return
300  return;
301 }
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:297
Abstract interface for the event classes.
Definition: GEvent.hpp:71
virtual GCOMRoi * clone(void) const
Clone region of interest.
Definition: GCOMRoi.cpp:185
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:997
virtual std::string print(const GChatter &chatter=NORMAL) const
Print region of interest information.
Definition: GCOMRoi.cpp:227
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:196
GCOMRoi(void)
Void constructor.
Definition: GCOMRoi.cpp:53
virtual ~GCOMRoi(void)
Destructor.
Definition: GCOMRoi.cpp:110
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:165
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:281
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:263
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:1022
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:132
Interface for the COMPTEL instrument direction class.
Definition: GCOMInstDir.hpp:41
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:413