GammaLib  2.1.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-2022 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 remove(const GEnergy& emin, const GEnergy& emax);
96  void reserve(const int& num);
97  void extend(const GEbounds& ebds);
98  void set(const GEnergies& energies);
99  void set(const int& num,
100  const GEnergy& emin,
101  const GEnergy& emax,
102  const std::string& method = "LOG",
103  const double& gamma = 1.0);
104  void load(const GFilename& filename);
105  void save(const GFilename& filename,
106  const bool& clobber = false,
107  const std::string& unit = "keV") const;
108  void read(const GFitsTable& table);
109  void write(GFits& file,
110  const std::string& extname = gammalib::extname_ebounds,
111  const std::string& unit = "keV") const;
112  void read(const GXmlElement& xml);
113  void write(GXmlElement& xml) const;
114  int index(const GEnergy& eng) const;
115  const GEnergy& emin(void) const;
116  const GEnergy& emax(void) const;
117  void emin(const int& index, const GEnergy& energy);
118  void emax(const int& index, const GEnergy& energy);
119  GEnergy emin(const int& index) const;
120  GEnergy emax(const int& index) const;
121  GEnergy emean(const int& index) const;
122  GEnergy elogmean(const int& index) const;
123  GEnergy ewidth(const int& index) const;
124  bool contains(const GEnergy& eng) const;
125  bool contains(const GEnergy& emin, const GEnergy& emax) const;
126  std::string print(const GChatter& chatter = NORMAL) const;
127 
128 protected:
129  // Protected methods
130  void init_members(void);
131  void copy_members(const GEbounds& ebds);
132  void free_members(void);
133  void set_attributes(void);
134  void insert_eng(const int& index, const GEnergy& emin, const GEnergy& emax);
135 
136  // Protected data area
137  int m_num; //!< Number of energy boundaries
138  GEnergy m_emin; //!< Minimum energy of all intervals
139  GEnergy m_emax; //!< Maximum energy of all intervals
140  GEnergy* m_min; //!< Array of interval minimum energies
141  GEnergy* m_max; //!< Array of interval maximum energies
142 };
143 
144 
145 /***********************************************************************//**
146  * @brief Return class name
147  *
148  * @return String containing the class name ("GEbounds").
149  ***************************************************************************/
150 inline
151 std::string GEbounds::classname(void) const
152 {
153  return ("GEbounds");
154 }
155 
156 
157 /***********************************************************************//**
158  * @brief Return number of energy boundaries
159  *
160  * @return Number of energy boundaries.
161  ***************************************************************************/
162 inline
163 int GEbounds::size(void) const
164 {
165  return m_num;
166 }
167 
168 
169 /***********************************************************************//**
170  * @brief Signal if there are no energy boundaries
171  *
172  * @return True if there are no energy boundaries.
173  ***************************************************************************/
174 inline
175 bool GEbounds::is_empty(void) const
176 {
177  return (m_num == 0);
178 }
179 
180 
181 /***********************************************************************//**
182  * @brief Return minimum energy of all intervals
183  *
184  * @return Minimum energy of all intervals.
185  ***************************************************************************/
186 inline
187 const GEnergy& GEbounds::emin(void) const
188 {
189  return m_emin;
190 }
191 
192 
193 /***********************************************************************//**
194  * @brief Return maximum energy of all intervals
195  *
196  * @return Maximum energy of all intervals.
197  ***************************************************************************/
198 inline
199 const GEnergy& GEbounds::emax(void) const
200 {
201  return m_emax;
202 }
203 
204 
205 /***********************************************************************//**
206  * @brief Energy boundaries inequality operator friend
207  *
208  * @param[in] a First energy boundaries.
209  * @param[in] b Second energy boundaries.
210  * @return True if both energy boundaries are different.
211  ***************************************************************************/
212 inline
213 bool operator!=(const GEbounds& a, const GEbounds& b)
214 {
215  return (!(a == b));
216 }
217 
218 #endif /* GEBOUNDS_HPP */
GEnergy * m_max
Array of interval maximum energies.
Definition: GEbounds.hpp:141
void init_members(void)
Initialise class members.
Definition: GEbounds.cpp:1281
void copy_members(const GEbounds &ebds)
Copy class members.
Definition: GEbounds.cpp:1300
friend bool operator==(const GEbounds &a, const GEbounds &b)
Energy boundaries equality operator friend.
Definition: GEbounds.cpp:1462
Energy value class definition.
GEnergy m_emin
Minimum energy of all intervals.
Definition: GEbounds.hpp:138
friend bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:213
GEbounds(void)
Constructor.
Definition: GEbounds.cpp:73
int size(void) const
Return number of energy boundaries.
Definition: GEbounds.hpp:163
void append(const GEnergy &emin, const GEnergy &emax)
Append energy interval.
Definition: GEbounds.cpp:301
GEbounds * clone(void) const
Clone energy boundaries.
Definition: GEbounds.cpp:286
bool contains(const GEnergy &eng) const
Checks whether energy boundaries contain energy.
Definition: GEbounds.cpp:1180
void set_attributes(void)
Set class attributes.
Definition: GEbounds.cpp:1346
XML element node class.
Definition: GXmlElement.hpp:48
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
Definition: GEbounds.cpp:761
FITS file class.
Definition: GFits.hpp:63
GEnergy emean(const int &index) const
Returns mean energy for a given energy interval.
Definition: GEbounds.cpp:1095
GEnergy ewidth(const int &index) const
Returns energy interval width.
Definition: GEbounds.cpp:1154
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:816
Energy container class.
Definition: GEnergies.hpp:60
int index(const GEnergy &eng) const
Returns energy bin index for a given energy.
Definition: GEbounds.cpp:948
int m_num
Number of energy boundaries.
Definition: GEbounds.hpp:137
void extend(const GEbounds &ebds)
Append energy boundaries.
Definition: GEbounds.cpp:552
void insert_eng(const int &index, const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:1389
void insert(const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:322
Energy boundaries container class.
Definition: GEbounds.hpp:60
void set(const GEnergies &energies)
Set energy boundaries from energy container.
Definition: GEbounds.cpp:618
Filename class.
Definition: GFilename.hpp:62
const GEnergy & emin(void) const
Return minimum energy of all intervals.
Definition: GEbounds.hpp:187
bool is_empty(void) const
Signal if there are no energy boundaries.
Definition: GEbounds.hpp:175
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:1232
GChatter
Definition: GTypemaps.hpp:33
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
Definition: GEbounds.cpp:1126
void reserve(const int &num)
Reserve space for energy intervals.
Definition: GEbounds.cpp:538
void clear(void)
Clear energy boundaries.
Definition: GEbounds.cpp:268
GEnergy * m_min
Array of interval minimum energies.
Definition: GEbounds.hpp:140
void free_members(void)
Delete class members.
Definition: GEbounds.cpp:1325
std::string classname(void) const
Return class name.
Definition: GEbounds.hpp:151
GEnergy m_emax
Maximum energy of all intervals.
Definition: GEbounds.hpp:139
virtual ~GEbounds(void)
Destructor.
Definition: GEbounds.cpp:216
Definition of interface for container classes.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
Definition: GEbounds.hpp:199
void save(const GFilename &filename, const bool &clobber=false, const std::string &unit="keV") const
Save energy boundaries into FITS file.
Definition: GEbounds.cpp:733
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:213
GEbounds & operator=(const GEbounds &ebds)
Assignment operator.
Definition: GEbounds.cpp:238
Interface class for container classes.
Definition: GContainer.hpp:52
void merge(void)
Merge all overlapping or connecting successive energy intervals.
Definition: GEbounds.cpp:349
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:689