GammaLib 2.0.0
Loading...
Searching...
No Matches
GLATEventBin.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * GLATEventBin.cpp - Fermi/LAT event bin class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2009-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 GLATEventBin.cpp
23 * @brief Fermi/LAT event bin class implementation
24 * @author Juergen Knodlseder
25 */
26
27/* __ Includes ___________________________________________________________ */
28#ifdef HAVE_CONFIG_H
29#include <config.h>
30#endif
31#include <string>
32#include <cmath>
33#include "GException.hpp"
34#include "GTools.hpp"
35#include "GLATEventBin.hpp"
36
37/* __ Method name definitions ____________________________________________ */
38#define G_DIR "GLATEventBin::dir()"
39#define G_ENERGY "GLATEventBin::energy()"
40#define G_TIME "GLATEventBin::time()"
41#define G_COUNTS_GET "GLATEventBin::counts()"
42#define G_COUNTS_SET "GLATEventBin::counts(double&)"
43#define G_SOLIDANGLE "GLATEventBin::solidangle()"
44#define G_EWIDTH "GLATEventBin::ewidth()"
45#define G_ONTIME "GLATEventBin::ontime()"
46
47/* __ Macros _____________________________________________________________ */
48
49/* __ Coding definitions _________________________________________________ */
50
51/* __ Debug definitions __________________________________________________ */
52
53
54/*==========================================================================
55 = =
56 = Constructors/destructors =
57 = =
58 ==========================================================================*/
59
60/***********************************************************************//**
61 * @brief Void constructor
62 ***************************************************************************/
64{
65 // Initialise class members for clean destruction
67
68 // Return
69 return;
70}
71
72
73/***********************************************************************//**
74 * @brief Copy constructor
75 *
76 * @param[in] bin Event bin.
77 ***************************************************************************/
79{
80 // Initialise class members for clean destruction
82
83 // Copy members
84 copy_members(bin);
85
86 // Return
87 return;
88}
89
90
91/***********************************************************************//**
92 * @brief Destructor
93 ***************************************************************************/
95{
96 // Free members
98
99 // Return
100 return;
101}
102
103
104/*==========================================================================
105 = =
106 = Operators =
107 = =
108 ==========================================================================*/
109
110/***********************************************************************//**
111 * @brief Assignment operator
112 *
113 * @param[in] bin LAT event bin.
114 * @return Lat event bin.
115 ***************************************************************************/
117{
118 // Execute only if object is not identical
119 if (this != &bin) {
120
121 // Copy base class members
122 this->GEventBin::operator=(bin);
123
124 // Free members
125 free_members();
126
127 // Initialise private members for clean destruction
128 init_members();
129
130 // Copy members
131 copy_members(bin);
132
133 } // endif: object was not identical
134
135 // Return this object
136 return *this;
137}
138
139
140/*==========================================================================
141 = =
142 = Public methods =
143 = =
144 ==========================================================================*/
145
146/***********************************************************************//**
147 * @brief Clear event bin
148 ***************************************************************************/
150{
151 // Free class members (base and derived classes, derived class first)
152 free_members();
154 this->GEvent::free_members();
155
156 // Initialise members
157 this->GEvent::init_members();
159 init_members();
160
161 // Return
162 return;
163}
164
165
166/***********************************************************************//**
167 * @brief Clone event bin
168 *
169 * @return Pointer to deep copy of Fermi/LAT event bin.
170 ***************************************************************************/
172{
173 return new GLATEventBin(*this);
174}
175
176
177/***********************************************************************//**
178 * @brief Return size of event bin
179 *
180 * @return Size of event bin in units of sr MeV s.
181 *
182 * The size of the event bin (units sr MeV s) is given by
183 * \f[size = \Omega \times \Delta E \times \Delta T\f]
184 * where
185 * \f$\Omega\f$ is the size of the spatial bin in sr,
186 * \f$\Delta E\f$ is the size of the energy bin in MeV, and
187 * \f$\Delta T\f$ is the ontime of the observation in seconds.
188 ***************************************************************************/
189double GLATEventBin::size(void) const
190{
191 // Compute bin size
192 double size = solidangle() * ewidth().MeV() * ontime();
193
194 // Return bin size
195 return size;
196}
197
198
199/***********************************************************************//**
200 * @brief Return instrument direction of event bin
201 *
202 * @return Instrument direction of event bin.
203 *
204 * @exception GException::invalid_value
205 * Invalid instrument direction pointer encountered.
206 *
207 * Returns reference to the instrument direction of the event bin.
208 ***************************************************************************/
210{
211 // Throw an exception if instrument direction pointer is not valid
212 if (m_dir == NULL) {
213 std::string msg = "Invalid instrument direction pointer encountered. "
214 "Please set up the event bin correctly.";
216 }
217
218 // Return instrument direction
219 return *m_dir;
220}
221
222
223/***********************************************************************//**
224 * @brief Return energy of event bin
225 *
226 * @return Energy of event bin.
227 *
228 * @exception GException::invalid_value
229 * Invalid energy pointer encountered.
230 *
231 * Returns reference to the energy of the event bin.
232 ***************************************************************************/
234{
235 // Throw an exception if energy pointer is not valid
236 if (m_energy == NULL) {
237 std::string msg = "Invalid energy pointer encountered. Please set up "
238 "the event bin correctly.";
240 }
241
242 // Return energy
243 return *m_energy;
244}
245
246
247/***********************************************************************//**
248 * @brief Return time of event bin
249 *
250 * @return Time of event bin.
251 *
252 * @exception GException::invalid_value
253 * Invalid time pointer encountered.
254 *
255 * Returns reference to the time of the event bin.
256 ***************************************************************************/
257const GTime& GLATEventBin::time(void) const
258{
259 // Throw an exception if time pointer is not valid
260 if (m_time == NULL) {
261 std::string msg = "Invalid time pointer encountered. Please set up "
262 "the event bin correctly.";
264 }
265
266 // Return time
267 return *m_time;
268}
269
270
271/***********************************************************************//**
272 * @brief Return number of counts in event bin
273 *
274 * @return Number of counts in event bin.
275 *
276 * @exception GLATException::no_member
277 * Invalid counts pointer.
278 *
279 * Returns reference to the number of counts in the event bin.
280 ***************************************************************************/
281double GLATEventBin::counts(void) const
282{
283 // Throw an exception if counts pointer is not valid
284 if (m_counts == NULL) {
285 std::string msg = "Invalid counts pointer encountered. Please set up "
286 "the event bin correctly.";
288 }
289
290 // Return counts
291 return *m_counts;
292}
293
294
295/***********************************************************************//**
296 * @brief Set number of counts in event bin
297 *
298 * @param[in] counts Number of counts.
299 *
300 * @exception GException::invalid_value
301 * Invalid counts pointer encountered.
302 *
303 * Set the number of counts in the event bin.
304 ***************************************************************************/
305void GLATEventBin::counts(const double& counts)
306{
307 // Throw an exception if counts pointer is not valid
308 if (m_counts == NULL) {
309 std::string msg = "Invalid counts pointer encountered. Please set up "
310 "the event bin correctly.";
312 }
313
314 // Set number of counts in event bin
315 *m_counts = counts;
316
317 // Return
318 return;
319}
320
321
322/***********************************************************************//**
323 * @brief Return error in number of counts
324 *
325 * @return Error in number of counts in event bin.
326 *
327 * Returns \f$\sqrt(counts+delta)\f$ as the uncertainty in the number of
328 * counts in the bin. Adding delta avoids uncertainties of 0 which will
329 * lead in the optimisation step to the exlusion of the corresponding bin.
330 * In the actual implementation delta=1e-50.
331 *
332 * @todo The choice of delta has been made somewhat arbitrary, mainly
333 * because the optimizer routines filter error^2 below 1e-100.
334 ***************************************************************************/
335double GLATEventBin::error(void) const
336{
337 // Compute uncertainty
338 double error = sqrt(counts()+1.0e-50);
339
340 // Return error
341 return error;
342}
343
344
345/***********************************************************************//**
346 * @brief Return solid angle of event bin
347 *
348 * @return Solid angle of event bin.
349 *
350 * @exception GException::invalid_value
351 * Invalid solid angle pointer encountered.
352 *
353 * Returns reference to the solid angle of the event bin.
354 ***************************************************************************/
355const double& GLATEventBin::solidangle(void) const
356{
357 // Throw an exception if solid angle pointer is not valid
358 if (m_solidangle == NULL) {
359 std::string msg = "Invalid solid angle pointer encountered. Please "
360 "set up the event bin correctly.";
362 }
363
364 // Return solid angle
365 return *m_solidangle;
366}
367
368
369/***********************************************************************//**
370 * @brief Return energy width of event bin
371 *
372 * @return Energy width of event bin.
373 *
374 * @exception GException::invalid_value
375 * Invalid energy width pointer encountered.
376 *
377 * Returns reference to the energy width of the event bin.
378 ***************************************************************************/
380{
381 // Throw an exception if energy width pointer is not valid
382 if (m_ewidth == NULL) {
383 std::string msg = "Invalid energy width pointer encountered. Please "
384 "set up the event bin correctly.";
386 }
387
388 // Return energy width
389 return *m_ewidth;
390}
391
392
393/***********************************************************************//**
394 * @brief Return ontime of event bin
395 *
396 * @return Ontime of event bin.
397 *
398 * @exception GException::invalid_value
399 * Invalid ontime pointer encountered.
400 *
401 * Returns reference to the ontime of the event bin.
402 ***************************************************************************/
403const double& GLATEventBin::ontime(void) const
404{
405 // Throw an exception if ontime pointer is not valid
406 if (m_ontime == NULL) {
407 std::string msg = "Invalid ontime pointer encountered. Please set up "
408 "the event bin correctly.";
410 }
411
412 // Return ontime
413 return *m_ontime;
414}
415
416
417/***********************************************************************//**
418 * @brief Print event information
419 *
420 * @param[in] chatter Chattiness.
421 * @return String containing number of counts in event bin.
422 ***************************************************************************/
423std::string GLATEventBin::print(const GChatter& chatter) const
424{
425 // Initialise result string
426 std::string result;
427
428 // Continue only if chatter is not silent
429 if (chatter != SILENT) {
430
431 // Append number of counts
432 result.append(gammalib::str(counts()));
433
434 } // endif: chatter was not silent
435
436 // Return result
437 return result;
438}
439
440
441/*==========================================================================
442 = =
443 = Private methods =
444 = =
445 ==========================================================================*/
446
447/***********************************************************************//**
448 * @brief Initialise class members
449 ***************************************************************************/
451{
452 // Initialise members
453 m_cube = NULL;
454 m_index = -1;
455 m_ipix = -1;
456 m_ieng = -1;
457 m_energy = NULL;
458 m_dir = NULL;
459 m_time = NULL;
460 m_counts = NULL;
461 m_solidangle = NULL;
462 m_ewidth = NULL;
463 m_ontime = NULL;
464
465 // Return
466 return;
467}
468
469
470/***********************************************************************//**
471 * @brief Copy class members
472 *
473 * @param[in] bin Event bin.
474 ***************************************************************************/
476{
477 // Copy members
478 m_cube = bin.m_cube;
479 m_index = bin.m_index;
480 m_ipix = bin.m_ipix;
481 m_ieng = bin.m_ieng;
482 m_energy = bin.m_energy;
483 m_dir = bin.m_dir;
484 m_time = bin.m_time;
485 m_counts = bin.m_counts;
487 m_ewidth = bin.m_ewidth;
488 m_ontime = bin.m_ontime;
489
490 // Return
491 return;
492}
493
494
495/***********************************************************************//**
496 * @brief Delete class members
497 ***************************************************************************/
499{
500 // Return
501 return;
502}
#define G_COUNTS_GET
#define G_COUNTS_SET
#define G_ONTIME
#define G_TIME
#define G_ENERGY
#define G_SOLIDANGLE
#define G_DIR
#define G_EWIDTH
Definition GEbounds.cpp:54
Exception handler interface definition.
Fermi/LAT event bin class interface definition.
Gammalib tools definition.
GChatter
Definition GTypemaps.hpp:33
@ SILENT
Definition GTypemaps.hpp:34
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
Definition GVector.cpp:1358
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
double MeV(void) const
Return energy in MeV.
Definition GEnergy.cpp:321
Abstract interface for the event bin class.
Definition GEventBin.hpp:64
void free_members(void)
Delete class members.
virtual GEventBin & operator=(const GEventBin &bin)
Assignment operator.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
Definition GEvent.cpp:163
void init_members(void)
Initialise class members.
Definition GEvent.cpp:141
Fermi/LAT event bin class.
virtual double counts(void) const
Return number of counts in event bin.
virtual const GEnergy & energy(void) const
Return energy of event bin.
const double & solidangle(void) const
Return solid angle of event bin.
virtual double size(void) const
Return size of event bin.
virtual const GLATInstDir & dir(void) const
Return instrument direction of event bin.
const GEnergy & ewidth(void) const
Return energy width of event bin.
GLATEventBin(void)
Void constructor.
void copy_members(const GLATEventBin &bin)
Copy class members.
virtual GLATEventBin * clone(void) const
Clone event bin.
GEnergy * m_ewidth
Pointer to energy width of bin.
virtual GLATEventBin & operator=(const GLATEventBin &bin)
Assignment operator.
void free_members(void)
Delete class members.
int m_index
Actual skymap index.
void init_members(void)
Initialise class members.
GLATEventCube * m_cube
Event cube back pointer.
double * m_solidangle
Pointer to solid angle of pixel (sr)
int m_ipix
Actual spatial index.
double * m_ontime
Pointer to ontime of bin (seconds)
virtual ~GLATEventBin(void)
Destructor.
virtual const GTime & time(void) const
Return time of event bin.
int m_ieng
Actual energy index.
double * m_counts
Pointer to number of counts.
virtual void clear(void)
Clear event bin.
const double & ontime(void) const
Return ontime of event bin.
GEnergy * m_energy
Pointer to bin energy.
virtual double error(void) const
Return error in number of counts.
GLATInstDir * m_dir
Pointer to bin direction.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print event information.
GTime * m_time
Pointer to bin time.
Fermi/LAT instrument direction class.
Time class.
Definition GTime.hpp:55
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition GTools.cpp:489