GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GMWLDatum.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GMWLDatum.cpp - Multi-wavelength spectral point class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2010-2018 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 GMWLDatum.cpp
23  * @brief Multi-wavelength spectral point class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <iostream>
32 #include "GLog.hpp"
33 #include "GTools.hpp"
34 #include "GMWLDatum.hpp"
35 
36 /* __ Method name definitions ____________________________________________ */
37 
38 /* __ Macros _____________________________________________________________ */
39 
40 /* __ Coding definitions _________________________________________________ */
41 
42 /* __ Debug definitions __________________________________________________ */
43 
44 
45 /*==========================================================================
46  = =
47  = Constructors/destructors =
48  = =
49  ==========================================================================*/
50 
51 /***********************************************************************//**
52  * @brief Void constructor
53  *
54  * Creates instance of an undefined spectral point.
55  ***************************************************************************/
57 {
58  // Initialise class members
59  init_members();
60 
61  // Return
62  return;
63 }
64 
65 
66 /***********************************************************************//**
67  * @brief Value constructor
68  *
69  * @param[in] energy Energy.
70  * @param[in] energy_err Uncertainty in energy.
71  * @param[in] flux Flux.
72  * @param[in] flux_err Uncertainty in flux.
73  *
74  * Constructs spectral point.
75  ***************************************************************************/
77  const GEnergy& energy_err,
78  const double& flux,
79  const double& flux_err) : GEventBin()
80 {
81  // Initialise class members
82  init_members();
83 
84  // Set members
85  m_eng = energy;
87  m_flux = flux;
89 
90  // Return
91  return;
92 }
93 
94 
95 /***********************************************************************//**
96  * @brief Copy constructor
97  *
98  * @param[in] datum Spectral point.
99  *
100  * Creates instance by copying an existing spectral point.
101  ***************************************************************************/
103 {
104  // Initialise class members
105  init_members();
106 
107  // Copy members
108  copy_members(datum);
109 
110  // Return
111  return;
112 }
113 
114 
115 /***********************************************************************//**
116  * @brief Destructor
117  *
118  * Destroy instance.
119  ***************************************************************************/
121 {
122  // Free members
123  free_members();
124 
125  // Return
126  return;
127 }
128 
129 
130 /*==========================================================================
131  = =
132  = Operators =
133  = =
134  ==========================================================================*/
135 
136 /***********************************************************************//**
137  * @brief Assignment operator
138  *
139  * @param[in] datum Spectral point.
140  * @return Spectral point.
141  *
142  * Copies spectral point into the instance.
143  ***************************************************************************/
145 {
146  // Execute only if object is not identical
147  if (this != &datum) {
148 
149  // Copy base class members
150  this->GEventBin::operator=(datum);
151 
152  // Free members
153  free_members();
154 
155  // Initialise private members for clean destruction
156  init_members();
157 
158  // Copy members
159  copy_members(datum);
160 
161  } // endif: object was not identical
162 
163  // Return this object
164  return *this;
165 }
166 
167 
168 /*==========================================================================
169  = =
170  = Public methods =
171  = =
172  ==========================================================================*/
173 
174 /***********************************************************************//**
175  * @brief Clear instance
176  *
177  * This method properly resets the instance to an initial state.
178  ***************************************************************************/
180 {
181  // Free class members (base and derived classes, derived class first)
182  free_members();
183  this->GEventBin::free_members();
184  this->GEvent::free_members();
185 
186  // Initialise members
187  this->GEvent::init_members();
188  this->GEventBin::init_members();
189  init_members();
190 
191  // Return
192  return;
193 }
194 
195 
196 /***********************************************************************//**
197  * @brief Clone instance
198  ***************************************************************************/
200 {
201  return new GMWLDatum(*this);
202 }
203 
204 
205 /***********************************************************************//**
206  * @brief Returns flux error
207  *
208  * Returns flux error value in units of ph/cm2/s/MeV.
209  *
210  * If the flux error is 0 it is assumed that no flux error information is
211  * available, and in that case the flux error is assumed to 10% of the flux
212  * value. This is mainly needed for the optimizer methods to work.
213  ***************************************************************************/
214 double GMWLDatum::error(void) const
215 {
216  // Set flux error
217  double error = (m_flux_err == 0.0) ? 0.1*m_flux : m_flux_err;
218 
219  // Return error
220  return error;
221 }
222 
223 
224 /***********************************************************************//**
225  * @brief Print spectral point information
226  *
227  * @param[in] chatter Chattiness.
228  * @return String containing spectral point information.
229  ***************************************************************************/
230 std::string GMWLDatum::print(const GChatter& chatter) const
231 {
232  // Initialise result string
233  std::string result;
234 
235  // Continue only if chatter is not silent
236  if (chatter != SILENT) {
237 
238  // Append spectral point
239  result.append(m_eng.print());
240  if (m_eng_err.MeV() > 0.0) {
241  result.append(" +/- "+m_eng_err.print());
242  }
243  result.append(": "+gammalib::str(m_flux));
244  if (m_flux_err > 0.0) {
245  result.append(" +/- "+gammalib::str(m_flux_err));
246  }
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_dir.clear();
268  m_time.clear();
269  m_eng.clear();
270  m_eng_err.clear();
271  m_flux = 0.0;
272  m_flux_err = 0.0;
273 
274  // Return
275  return;
276 }
277 
278 
279 /***********************************************************************//**
280  * @brief Copy class members
281  *
282  * @param[in] datum Instance to be copied.
283  ***************************************************************************/
285 {
286  // Copy members
287  m_dir = datum.m_dir;
288  m_time = datum.m_time;
289  m_eng = datum.m_eng;
290  m_eng_err = datum.m_eng_err;
291  m_flux = datum.m_flux;
292  m_flux_err = datum.m_flux_err;
293 
294  // Return
295  return;
296 }
297 
298 
299 /***********************************************************************//**
300  * @brief Delete class members
301  *
302  * This class does not allocate any memory but simply holds pointers. Hence
303  * nothing has to be deallocated.
304  ***************************************************************************/
306 {
307  // Return
308  return;
309 }
const double & flux_err(void) const
Return flux error of spectral bin.
Definition: GMWLDatum.hpp:216
double m_flux
Flux of spectral point (ph/cm2/s/MeV)
Definition: GMWLDatum.hpp:94
virtual GMWLDatum & operator=(const GMWLDatum &datum)
Assignment operator.
Definition: GMWLDatum.cpp:144
double m_flux_err
Uncertainty in flux (ph/cm2/s/MeV)
Definition: GMWLDatum.hpp:95
virtual std::string print(const GChatter &chatter=NORMAL) const
Print spectral point information.
Definition: GMWLDatum.cpp:230
Abstract interface for the event bin class.
Definition: GEventBin.hpp:64
virtual GMWLDatum * clone(void) const
Clone instance.
Definition: GMWLDatum.cpp:199
void clear(void)
Clear time.
Definition: GTime.cpp:252
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
const double & flux(void) const
Return flux of spectral bin.
Definition: GMWLDatum.hpp:191
Gammalib tools definition.
virtual void clear(void)
Clear instance.
Definition: GMWLDatum.cpp:179
GEnergy m_eng_err
Uncertainty in energy.
Definition: GMWLDatum.hpp:93
virtual const GEnergy & energy(void) const
Return energy of spectral bin.
Definition: GMWLDatum.hpp:142
GEnergy m_eng
Energy of spectral point.
Definition: GMWLDatum.hpp:92
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
Definition: GEnergy.cpp:748
GChatter
Definition: GTypemaps.hpp:33
void init_members(void)
Initialise class members.
Definition: GEvent.cpp:141
virtual ~GMWLDatum(void)
Destructor.
Definition: GMWLDatum.cpp:120
void free_members(void)
Delete class members.
Definition: GEventBin.cpp:182
Multi-wavelength spectral point class.
Definition: GMWLDatum.hpp:45
Information logger class definition.
Multi-wavelength spectral point class interface definition.
void free_members(void)
Delete class members.
Definition: GEvent.cpp:163
void init_members(void)
Initialise class members.
Definition: GMWLDatum.cpp:264
void copy_members(const GMWLDatum &datum)
Copy class members.
Definition: GMWLDatum.cpp:284
GMWLInstDir m_dir
Instrument direction of spectral point (not used)
Definition: GMWLDatum.hpp:90
virtual GEventBin & operator=(const GEventBin &bin)
Assignment operator.
Definition: GEventBin.cpp:105
GMWLDatum(void)
Void constructor.
Definition: GMWLDatum.cpp:56
void free_members(void)
Delete class members.
Definition: GMWLDatum.cpp:305
const GEnergy & energy_err(void) const
Return energy error of spectral bin.
Definition: GMWLDatum.hpp:254
GTime m_time
Time of spectral point (not used)
Definition: GMWLDatum.hpp:91
virtual void clear(void)
Clear instance.
void init_members(void)
Initialise class members.
Definition: GEventBin.cpp:160
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual double error(void) const
Returns flux error.
Definition: GMWLDatum.cpp:214
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489