GammaLib  1.7.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-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 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, const GEnergy& emin, const GEnergy& emax,
75  const bool& log = true);
76  virtual ~GEbounds(void);
77 
78  // Operators
79  GEbounds& operator=(const GEbounds& ebds);
80 
81  // Methods
82  void clear(void);
83  GEbounds* clone(void) const;
84  std::string classname(void) const;
85  int size(void) const;
86  bool is_empty(void) const;
87  void append(const GEnergy& emin, const GEnergy& emax);
88  void insert(const GEnergy& emin, const GEnergy& emax);
89  void merge(void);
90  void merge(const GEnergy& emin, const GEnergy& emax);
91  void remove(const int& index);
92  void reserve(const int& num);
93  void extend(const GEbounds& ebds);
94  void set(const GEnergies& energies);
95  void set_lin(const int& num, const GEnergy& emin, const GEnergy& emax);
96  void set_log(const int& num, const GEnergy& emin, const GEnergy& emax);
97  void load(const GFilename& filename);
98  void save(const GFilename& filename,
99  const bool& clobber = false,
100  const std::string& unit = "keV") const;
101  void read(const GFitsTable& table);
102  void write(GFits& file,
103  const std::string& extname = gammalib::extname_ebounds,
104  const std::string& unit = "keV") const;
105  void read(const GXmlElement& xml);
106  void write(GXmlElement& xml) const;
107  int index(const GEnergy& eng) const;
108  const GEnergy& emin(void) const;
109  const GEnergy& emax(void) const;
110  void emin(const int& index, const GEnergy& energy);
111  void emax(const int& index, const GEnergy& energy);
112  GEnergy emin(const int& index) const;
113  GEnergy emax(const int& index) const;
114  GEnergy emean(const int& index) const;
115  GEnergy elogmean(const int& index) const;
116  GEnergy ewidth(const int& index) const;
117  bool contains(const GEnergy& eng) const;
118  bool contains(const GEnergy& emin, const GEnergy& emax) const;
119  std::string print(const GChatter& chatter = NORMAL) const;
120 
121 
122 protected:
123  // Protected methods
124  void init_members(void);
125  void copy_members(const GEbounds& ebds);
126  void free_members(void);
127  void set_attributes(void);
128  void insert_eng(const int& index, const GEnergy& emin, const GEnergy& emax);
129 
130  // Protected data area
131  int m_num; //!< Number of energy boundaries
132  GEnergy m_emin; //!< Minimum energy of all intervals
133  GEnergy m_emax; //!< Maximum energy of all intervals
134  GEnergy* m_min; //!< Array of interval minimum energies
135  GEnergy* m_max; //!< Array of interval maximum energies
136 };
137 
138 
139 /***********************************************************************//**
140  * @brief Return class name
141  *
142  * @return String containing the class name ("GEbounds").
143  ***************************************************************************/
144 inline
145 std::string GEbounds::classname(void) const
146 {
147  return ("GEbounds");
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Return number of energy boundaries
153  *
154  * @return Number of energy boundaries.
155  ***************************************************************************/
156 inline
157 int GEbounds::size(void) const
158 {
159  return m_num;
160 }
161 
162 
163 /***********************************************************************//**
164  * @brief Signal if there are no energy boundaries
165  *
166  * @return True if there are no energy boundaries.
167  ***************************************************************************/
168 inline
169 bool GEbounds::is_empty(void) const
170 {
171  return (m_num == 0);
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Return minimum energy of all intervals
177  *
178  * @return Minimum energy of all intervals.
179  ***************************************************************************/
180 inline
181 const GEnergy& GEbounds::emin(void) const
182 {
183  return m_emin;
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Return maximum energy of all intervals
189  *
190  * @return Maximum energy of all intervals.
191  ***************************************************************************/
192 inline
193 const GEnergy& GEbounds::emax(void) const
194 {
195  return m_emax;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Energy boundaries inequality operator friend
201  *
202  * @param[in] a First energy boundaries.
203  * @param[in] b Second energy boundaries.
204  * @return True if both energy boundaries are different.
205  ***************************************************************************/
206 inline
207 bool operator!=(const GEbounds& a, const GEbounds& b)
208 {
209  return (!(a == b));
210 }
211 
212 #endif /* GEBOUNDS_HPP */
GEnergy * m_max
Array of interval maximum energies.
Definition: GEbounds.hpp:135
void set_lin(const int &num, const GEnergy &emin, const GEnergy &emax)
Set linearly spaced energy intervals.
Definition: GEbounds.cpp:583
void init_members(void)
Initialise class members.
Definition: GEbounds.cpp:1293
void copy_members(const GEbounds &ebds)
Copy class members.
Definition: GEbounds.cpp:1312
friend bool operator==(const GEbounds &a, const GEbounds &b)
Energy boundaries equality operator friend.
Definition: GEbounds.cpp:1474
Energy value class definition.
GEnergy m_emin
Minimum energy of all intervals.
Definition: GEbounds.hpp:132
friend bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:207
GEbounds(void)
Constructor.
Definition: GEbounds.cpp:74
int size(void) const
Return number of energy boundaries.
Definition: GEbounds.hpp:157
void append(const GEnergy &emin, const GEnergy &emax)
Append energy interval.
Definition: GEbounds.cpp:302
GEbounds * clone(void) const
Clone energy boundaries.
Definition: GEbounds.cpp:287
bool contains(const GEnergy &eng) const
Checks whether energy boundaries contain energy.
Definition: GEbounds.cpp:1192
void set_attributes(void)
Set class attributes.
Definition: GEbounds.cpp:1358
XML element node class.
Definition: GXmlElement.hpp:47
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
Definition: GEbounds.cpp:776
FITS file class.
Definition: GFits.hpp:63
GEnergy emean(const int &index) const
Returns mean energy for a given energy interval.
Definition: GEbounds.cpp:1110
GEnergy ewidth(const int &index) const
Returns energy interval width.
Definition: GEbounds.cpp:1167
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:831
Energy container class.
Definition: GEnergies.hpp:60
int index(const GEnergy &eng) const
Returns energy bin index for a given energy.
Definition: GEbounds.cpp:963
int m_num
Number of energy boundaries.
Definition: GEbounds.hpp:131
void extend(const GEbounds &ebds)
Append energy boundaries.
Definition: GEbounds.cpp:476
void insert_eng(const int &index, const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:1401
void insert(const GEnergy &emin, const GEnergy &emax)
Insert energy interval.
Definition: GEbounds.cpp:323
Energy boundaries container class.
Definition: GEbounds.hpp:60
void set(const GEnergies &energies)
Set energy boundaries from energy container.
Definition: GEbounds.cpp:542
Filename class.
Definition: GFilename.hpp:62
const GEnergy & emin(void) const
Return minimum energy of all intervals.
Definition: GEbounds.hpp:181
bool is_empty(void) const
Signal if there are no energy boundaries.
Definition: GEbounds.hpp:169
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1184
const std::string extname_ebounds
Definition: GEbounds.hpp:44
void set_log(const int &num, const GEnergy &emin, const GEnergy &emax)
Set logarithmically spaced energy intervals.
Definition: GEbounds.cpp:638
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
std::string print(const GChatter &chatter=NORMAL) const
Print energy boundaries.
Definition: GEbounds.cpp:1244
GChatter
Definition: GTypemaps.hpp:33
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
Definition: GEbounds.cpp:1140
void reserve(const int &num)
Reserve space for energy intervals.
Definition: GEbounds.cpp:462
void clear(void)
Clear energy boundaries.
Definition: GEbounds.cpp:269
GEnergy * m_min
Array of interval minimum energies.
Definition: GEbounds.hpp:134
void free_members(void)
Delete class members.
Definition: GEbounds.cpp:1337
std::string classname(void) const
Return class name.
Definition: GEbounds.hpp:145
GEnergy m_emax
Maximum energy of all intervals.
Definition: GEbounds.hpp:133
virtual ~GEbounds(void)
Destructor.
Definition: GEbounds.cpp:217
Definition of interface for container classes.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
Definition: GEbounds.hpp:193
void save(const GFilename &filename, const bool &clobber=false, const std::string &unit="keV") const
Save energy boundaries into FITS file.
Definition: GEbounds.cpp:748
bool operator!=(const GEbounds &a, const GEbounds &b)
Energy boundaries inequality operator friend.
Definition: GEbounds.hpp:207
GEbounds & operator=(const GEbounds &ebds)
Assignment operator.
Definition: GEbounds.cpp:239
Interface class for container classes.
Definition: GContainer.hpp:52
void merge(void)
Merge all overlapping or connecting successive energy intervals.
Definition: GEbounds.cpp:350
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:704