GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GBounds.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GBounds.hpp - Boundaries class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2026 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 GBounds.hpp
23 * @brief Boundaries class interface definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GBOUNDS_HPP
28#define GBOUNDS_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include <vector>
33#include "GContainer.hpp"
34#include "GEnergy.hpp"
35
36/* __ Forward declarations _______________________________________________ */
37class GFits;
38class GFitsTable;
39class GFilename;
40
41/* __ Constants __________________________________________________________ */
42namespace gammalib {
43 const std::string extname_bounds = "BOUNDS";
44}
45
46
47/***********************************************************************//**
48 * @class GBounds
49 *
50 * @brief Boundaries container class
51 *
52 * This class holds a list of intervals which are each defined by a minimum
53 * and a maximum value. Intervals may be continuous or not and overlapping or
54 * not. The order of the intervals is not managed by the class, they will
55 * be stored as provided. An interval is defined by a minimum and maximum
56 * value. By definition, the minimum value is included in the interval, the
57 * maximum value is excluded.
58 ***************************************************************************/
59class GBounds : public GContainer {
60
61 // Operator friends
62 friend bool operator==(const GBounds& a, const GBounds& b);
63 friend bool operator!=(const GBounds& a, const GBounds& b);
64
65public:
66 // Constructors and destructors
67 GBounds(void);
68 explicit GBounds(const GFilename& filename);
69 explicit GBounds(const std::vector<double>& array, const std::string& unit = "");
70 GBounds(const GBounds& bounds);
71 GBounds(const double& min, const double& max, const std::string& unit = "");
72 GBounds(const int& num,
73 const double& min,
74 const double& max,
75 const std::string& method,
76 const std::string& unit = "",
77 const double& gamma = 1.0);
78 virtual ~GBounds(void);
79
80 // Operators
81 GBounds& operator=(const GBounds& bounds);
82
83 // Methods
84 void clear(void);
85 GBounds* clone(void) const;
86 std::string classname(void) const;
87 int size(void) const;
88 bool is_empty(void) const;
89 const std::string& unit(void) const;
90 void unit(const std::string& unit);
91 void append(const double& min, const double& max);
92 void insert(const double& min, const double& max);
93 void remove(const int& index);
94 void reserve(const int& num);
95 void extend(const GBounds& bounds);
96 void set(const std::vector<double>& array);
97 void set(const int& num,
98 const double& min,
99 const double& max,
100 const std::string& method,
101 const double& gamma = 1.0);
102 void load(const GFilename& filename);
103 void save(const GFilename& filename,
104 const bool& clobber = false) const;
105 void read(const GFitsTable& table);
106 void write(GFits& file,
107 const std::string& extname = gammalib::extname_bounds) const;
108 int index(const double& value) const;
109 double min(void) const;
110 double max(void) const;
111 void min(const int& index, const double& value);
112 void max(const int& index, const double& value);
113 double min(const int& index) const;
114 double max(const int& index) const;
115 double mean(const int& index) const;
116 double logmean(const int& index) const;
117 double width(const int& index) const;
118 bool contains(const double& value) const;
119 bool contains(const double& min, const double& max) const;
120 std::string print(const GChatter& chatter = NORMAL) const;
121
122protected:
123 // Protected methods
124 void init_members(void);
125 void copy_members(const GBounds& bounds);
126 void free_members(void);
127 void insert_interval(const int& index, const double& min, const double& max);
128
129 // Protected data area
130 std::string m_unit; //!< Unit of values
131 std::vector<double> m_min; //!< Array of interval minimum values
132 std::vector<double> m_max; //!< Array of interval maximum values
133};
134
135
136/***********************************************************************//**
137 * @brief Return class name
138 *
139 * @return String containing the class name ("GBounds").
140 ***************************************************************************/
141inline
142std::string GBounds::classname(void) const
143{
144 return ("GBounds");
145}
146
147
148/***********************************************************************//**
149 * @brief Return number of boundaries
150 *
151 * @return Number of boundaries.
152 ***************************************************************************/
153inline
154int GBounds::size(void) const
155{
156 return (m_min.size());
157}
158
159
160/***********************************************************************//**
161 * @brief Signal if there are no boundaries
162 *
163 * @return True if there are no boundaries.
164 ***************************************************************************/
165inline
166bool GBounds::is_empty(void) const
167{
168 return (m_min.empty());
169}
170
171
172/***********************************************************************//**
173 * @brief Return boundary units.
174 *
175 * @return Boundary units.
176 ***************************************************************************/
177inline
178const std::string& GBounds::unit(void) const
179{
180 return (m_unit);
181}
182
183
184/***********************************************************************//**
185 * @brief Set boundary units.
186 *
187 * @return unit Boundary units.
188 ***************************************************************************/
189inline
190void GBounds::unit(const std::string& unit)
191{
192 m_unit = unit;
193 return;
194}
195
196
197/***********************************************************************//**
198 * @brief Boundaries inequality operator friend
199 *
200 * @param[in] a First boundaries.
201 * @param[in] b Second boundaries.
202 * @return True if both boundaries are different.
203 ***************************************************************************/
204inline
205bool operator!=(const GBounds& a, const GBounds& b)
206{
207 return (!(a == b));
208}
209
210#endif /* GBOUNDS_HPP */
bool operator!=(const GBounds &a, const GBounds &b)
Boundaries inequality operator friend.
Definition GBounds.hpp:205
Definition of interface for container classes.
Energy value class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
Boundaries container class.
Definition GBounds.hpp:59
void insert(const double &min, const double &max)
Insert interval.
Definition GBounds.cpp:314
void extend(const GBounds &bounds)
Append boundaries.
Definition GBounds.cpp:381
void read(const GFitsTable &table)
Read boundaries from FITS table.
Definition GBounds.cpp:662
void remove(const int &index)
Remove interval.
Definition GBounds.cpp:339
void clear(void)
Clear boundaries.
Definition GBounds.cpp:262
friend bool operator!=(const GBounds &a, const GBounds &b)
Boundaries inequality operator friend.
Definition GBounds.hpp:205
GBounds(void)
Void constructor.
Definition GBounds.cpp:71
bool is_empty(void) const
Signal if there are no boundaries.
Definition GBounds.hpp:166
GBounds * clone(void) const
Clone boundaries.
Definition GBounds.cpp:280
void init_members(void)
Initialise class members.
Definition GBounds.cpp:1128
const std::string & unit(void) const
Return boundary units.
Definition GBounds.hpp:178
void free_members(void)
Delete class members.
Definition GBounds.cpp:1160
void append(const double &min, const double &max)
Append interval.
Definition GBounds.cpp:294
friend bool operator==(const GBounds &a, const GBounds &b)
Boundaries equality operator friend.
Definition GBounds.cpp:1221
void reserve(const int &num)
Reserve space for intervals.
Definition GBounds.cpp:363
void copy_members(const GBounds &bounds)
Copy class members.
Definition GBounds.cpp:1145
std::string m_unit
Unit of values.
Definition GBounds.hpp:130
std::vector< double > m_max
Array of interval maximum values.
Definition GBounds.hpp:132
void save(const GFilename &filename, const bool &clobber=false) const
Save boundaries into FITS file.
Definition GBounds.cpp:637
double max(void) const
Return maximum value of all intervals.
Definition GBounds.cpp:806
GBounds & operator=(const GBounds &bounds)
Assignment operator.
Definition GBounds.cpp:232
std::string print(const GChatter &chatter=NORMAL) const
Print boundaries.
Definition GBounds.cpp:1075
double mean(const int &index) const
Returns mean value for a given interval.
Definition GBounds.cpp:943
double min(void) const
Return minimum value of all intervals.
Definition GBounds.cpp:781
virtual ~GBounds(void)
Destructor.
Definition GBounds.cpp:210
void insert_interval(const int &index, const double &min, const double &max)
Insert interval.
Definition GBounds.cpp:1186
void write(GFits &file, const std::string &extname=gammalib::extname_bounds) const
Write boundaries into FITS object.
Definition GBounds.cpp:703
std::vector< double > m_min
Array of interval minimum values.
Definition GBounds.hpp:131
int size(void) const
Return number of boundaries.
Definition GBounds.hpp:154
void set(const std::vector< double > &array)
Set boundaries from array.
Definition GBounds.cpp:428
bool contains(const double &value) const
Checks whether boundaries contain value.
Definition GBounds.cpp:1023
std::string classname(void) const
Return class name.
Definition GBounds.hpp:142
double logmean(const int &index) const
Returns logarithmic mean value for a given interval.
Definition GBounds.cpp:972
void load(const GFilename &filename)
Load boundaries from FITS file.
Definition GBounds.cpp:595
double width(const int &index) const
Returns interval width.
Definition GBounds.cpp:999
int index(const double &value) const
Returns bin index for a value.
Definition GBounds.cpp:758
Interface class for container classes.
Filename class.
Definition GFilename.hpp:62
Abstract interface for FITS table.
FITS file class.
Definition GFits.hpp:63
const std::string extname_bounds
Definition GBounds.hpp:43