GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEbounds.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GEbounds.hpp - Energy boundaries class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-2020 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 GEbounds.hpp
23  * @brief Energy boundaries class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GEBOUNDS_HPP
28 #define GEBOUNDS_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GContainer.hpp"
33 #include "GEnergy.hpp"
34 
35 /* __ Forward declarations _______________________________________________ */
36 class GXmlElement;
37 class GFits;
38 class GFitsTable;
39 class GFilename;
40 class GEnergies;
41 
42 /* __ Constants __________________________________________________________ */
43 namespace gammalib {
44  const std::string extname_ebounds = "EBOUNDS";
45 }
46 
47 
48 /***********************************************************************//**
49  * @class GEbounds
50  *
51  * @brief Energy boundaries container class
52  *
53  * This class holds a list of energy intervals that are defined by a minimum
54  * and maximum energy. Energies are implement using the GEnergy class which
55  * holds unit independent energy information.
56  *
57  * The class has no method for sorting of the energy boundaries; it is
58  * expected that the energy boundaries are correctly set by the client.
59  ***************************************************************************/
60 class GEbounds : public GContainer {
61 
62  // Operator friends
63  friend bool operator==(const GEbounds& a, const GEbounds& b);
64  friend bool operator!=(const GEbounds& a, const GEbounds& b);
65 
66 public:
67  // Constructors and destructors
68  GEbounds(void);
69  explicit GEbounds(const GFilename& filename);
70  explicit GEbounds(const GXmlElement& xml);
71  explicit GEbounds(const GEnergies& energies);
72  GEbounds(const GEbounds& ebds);
73  GEbounds(const GEnergy& emin, const GEnergy& emax);
74  GEbounds(const int& num,
75  const GEnergy& emin,
76  const GEnergy& emax,
77  const std::string& method = "LOG",
78  const double& gamma = 1.0);
79  virtual ~GEbounds(void);
80 
81  // Operators
82  GEbounds& operator=(const GEbounds& ebds);
83 
84  // Methods
85  void clear(void);
86  GEbounds* clone(void) const;
87  std::string classname(void) const;
88  int size(void) const;
89  bool is_empty(void) const;
90  void append(const GEnergy& emin, const GEnergy& emax);
91  void insert(const GEnergy& emin, const GEnergy& emax);
92  void merge(void);
93  void merge(const GEnergy& emin, const GEnergy& emax);
94  void remove(const int& index);
95  void reserve(const int& num);
96  void extend(const GEbounds& ebds);
97  void set(const GEnergies& energies);
98  void set(const int& num,
99  const GEnergy& emin,
100  const GEnergy& emax,
101  const std::string& method = "LOG",
102  const double& gamma = 1.0);
103  void load(const GFilename& filename);
104  void save(const GFilename& filename,
105  const bool& clobber = false,
106  const std::string& unit = "keV") const;
107  void read(const GFitsTable& table);
108  void write(GFits& file,
109  const std::string& extname = gammalib::extname_ebounds,
110  const std::string& unit = "keV") const;
111  void read(const GXmlElement& xml);
112  void write(GXmlElement& xml) const;
113  int index(const GEnergy& eng) const;
114  const GEnergy& emin(void) const;
115  const GEnergy& emax(void) const;
116  void emin(const int& index, const GEnergy& energy);
117  void emax(const int& index, const GEnergy& energy);
118  GEnergy emin(const int& index) const;
119  GEnergy emax(const int& index) const;
120  GEnergy emean(const int& index) const;
121  GEnergy elogmean(const int& index) const;
122  GEnergy ewidth(const int& index) const;
123  bool contains(const GEnergy& eng) const;
124  bool contains(const GEnergy& emin, const GEnergy& emax) const;
125  std::string print(const GChatter& chatter = NORMAL) const;
126 
127 protected:
128  // Protected methods
129  void init_members(void);
130  void copy_members(const GEbounds& ebds);
131  void free_members(void);
132  void set_attributes(void);
133  void insert_eng(const int& index, const GEnergy& emin, const GEnergy& emax);
134 
135  // Protected data area
136  int m_num; //!< Number of energy boundaries
137  GEnergy m_emin; //!< Minimum energy of all intervals
138  GEnergy m_emax; //!< Maximum energy of all intervals
139  GEnergy* m_min; //!< Array of interval minimum energies
140  GEnergy* m_max; //!< Array of interval maximum energies
141 };
142 
143 
144 /***********************************************************************//**
145  * @brief Return class name
146  *
147  * @return String containing the class name ("GEbounds").
148  ***************************************************************************/
149 inline
150 std::string GEbounds::classname(void) const
151 {
152  return ("GEbounds");
153 }
154 
155 
156 /***********************************************************************//**
157  * @brief Return number of energy boundaries
158  *
159  * @return Number of energy boundaries.
160  ***************************************************************************/
161 inline
162 int GEbounds::size(void) const
163 {
164  return m_num;
165 }
166 
167 
168 /***********************************************************************//**
169  * @brief Signal if there are no energy boundaries
170  *
171  * @return True if there are no energy boundaries.
172  ***************************************************************************/
173 inline
174 bool GEbounds::is_empty(void) const
175 {
176  return (m_num == 0);
177 }
178 
179 
180 /***********************************************************************//**
181  * @brief Return minimum energy of all intervals
182  *
183  * @return Minimum energy of all intervals.
184  ***************************************************************************/
185 inline
186 const GEnergy& GEbounds::emin(void) const
187 {
188  return m_emin;
189 }
190 
191 
192 /***********************************************************************//**
193  * @brief Return maximum energy of all intervals
194  *
195  * @return Maximum energy of all intervals.
196  ***************************************************************************/
197 inline
198 const GEnergy& GEbounds::emax(void) const
199 {
200  return m_emax;
201 }
202 
203 
204 /***********************************************************************//**
205  * @brief Energy boundaries inequality operator friend
206  *
207  * @param[in] a First energy boundaries.
208  * @param[in] b Second energy boundaries.
209  * @return True if both energy boundaries are different.
210  ***************************************************************************/
211 inline
212 bool operator!=(const GEbounds& a, const GEbounds& b)
213 {
214  return (!(a == b));
215 }
216 
217 #endif /* GEBOUNDS_HPP */
GEnergy * m_max
Array of interval maximum energies.
Definition: GEbounds.hpp:140
void init_members(void)
Initialise class members.
Definition: GEbounds.cpp:1200
void copy_members(const GEbounds &ebds)
Copy class members.
Definition: GEbounds.cpp:1219
friend bool operator==(const GEbounds &a, const GEbounds &b)
Energy boundaries equality operator friend.
Definition: GEbounds.cpp:1381
Energy value class definition.
GEnergy m_emin
Minimum energy of all intervals.
Definition: GEbounds.hpp:137
friend bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:212
GEbounds(void)
Constructor.
Definition: GEbounds.cpp:72
int size(void) const
Return number of energy boundaries.
Definition: GEbounds.hpp:162
void append(const GEnergy &emin, const GEnergy &emax)
Append energy interval.
Definition: GEbounds.cpp:300
GEbounds * clone(void) const
Clone energy boundaries.
Definition: GEbounds.cpp:285
bool contains(const GEnergy &eng) const
Checks whether energy boundaries contain energy.
Definition: GEbounds.cpp:1099
void set_attributes(void)
Set class attributes.
Definition: GEbounds.cpp:1265
XML element node class.
Definition: GXmlElement.hpp:47
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
Definition: GEbounds.cpp:683
FITS file class.
Definition: GFits.hpp:63
GEnergy emean(const int &index) const
Returns mean energy for a given energy interval.
Definition: GEbounds.cpp:1017
GEnergy ewidth(const int &index) const
Returns energy interval width.
Definition: GEbounds.cpp:1074
void write(GFits &file, const std::string &extname=gammalib::extname_ebounds, const std::string &unit="keV") const
Write energy boundaries into FITS object.
Definition: GEbounds.cpp:738
Energy container class.
Definition: GEnergies.hpp:60
int index(const GEnergy &eng) const
Returns energy bin index for a given energy.
Definition: GEbounds.cpp:870
int m_num
Number of energy boundaries.
Definition: GEbounds.hpp:136
void extend(const GEbounds &ebds)
Append energy boundaries.
Definition: GEbounds.cpp:474
void insert_eng(const int &index, const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:1308
void insert(const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:321
Energy boundaries container class.
Definition: GEbounds.hpp:60
void set(const GEnergies &energies)
Set energy boundaries from energy container.
Definition: GEbounds.cpp:540
Filename class.
Definition: GFilename.hpp:62
const GEnergy & emin(void) const
Return minimum energy of all intervals.
Definition: GEbounds.hpp:186
bool is_empty(void) const
Signal if there are no energy boundaries.
Definition: GEbounds.hpp:174
const std::string extname_ebounds
Definition: GEbounds.hpp:44
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
std::string print(const GChatter &chatter=NORMAL) const
Print energy boundaries.
Definition: GEbounds.cpp:1151
GChatter
Definition: GTypemaps.hpp:33
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
Definition: GEbounds.cpp:1047
void reserve(const int &num)
Reserve space for energy intervals.
Definition: GEbounds.cpp:460
void clear(void)
Clear energy boundaries.
Definition: GEbounds.cpp:267
GEnergy * m_min
Array of interval minimum energies.
Definition: GEbounds.hpp:139
void free_members(void)
Delete class members.
Definition: GEbounds.cpp:1244
std::string classname(void) const
Return class name.
Definition: GEbounds.hpp:150
GEnergy m_emax
Maximum energy of all intervals.
Definition: GEbounds.hpp:138
virtual ~GEbounds(void)
Destructor.
Definition: GEbounds.cpp:215
Definition of interface for container classes.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
Definition: GEbounds.hpp:198
void save(const GFilename &filename, const bool &clobber=false, const std::string &unit="keV") const
Save energy boundaries into FITS file.
Definition: GEbounds.cpp:655
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:212
GEbounds & operator=(const GEbounds &ebds)
Assignment operator.
Definition: GEbounds.cpp:237
Interface class for container classes.
Definition: GContainer.hpp:52
void merge(void)
Merge all overlapping or connecting successive energy intervals.
Definition: GEbounds.cpp:348
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void load(const GFilename &filename)
Load energy boundaries from FITS file.
Definition: GEbounds.cpp:611