|
GammaLib 2.2.0.dev
|
Boundaries container class. More...
#include <GBounds.hpp>
Public Member Functions | |
| GBounds (void) | |
| Void constructor. | |
| GBounds (const GFilename &filename) | |
| FITS file constructor. | |
| GBounds (const std::vector< double > &array, const std::string &unit="") | |
| Array constructor. | |
| GBounds (const GBounds &bounds) | |
| Copy constructor. | |
| GBounds (const double &min, const double &max, const std::string &unit="") | |
| Interval constructor. | |
| GBounds (const int &num, const double &min, const double &max, const std::string &method, const std::string &unit="", const double &gamma=1.0) | |
| Boundary constructor. | |
| virtual | ~GBounds (void) |
| Destructor. | |
| GBounds & | operator= (const GBounds &bounds) |
| Assignment operator. | |
| void | clear (void) |
| Clear boundaries. | |
| GBounds * | clone (void) const |
| Clone boundaries. | |
| std::string | classname (void) const |
| Return class name. | |
| int | size (void) const |
| Return number of boundaries. | |
| bool | is_empty (void) const |
| Signal if there are no boundaries. | |
| const std::string & | unit (void) const |
| Return boundary units. | |
| void | unit (const std::string &unit) |
| Set boundary units. | |
| void | append (const double &min, const double &max) |
| Append interval. | |
| void | insert (const double &min, const double &max) |
| Insert interval. | |
| void | remove (const int &index) |
| Remove interval. | |
| void | reserve (const int &num) |
| Reserve space for intervals. | |
| void | extend (const GBounds &bounds) |
| Append boundaries. | |
| void | set (const std::vector< double > &array) |
| Set boundaries from array. | |
| void | set (const int &num, const double &min, const double &max, const std::string &method, const double &gamma=1.0) |
| Set intervals. | |
| void | load (const GFilename &filename) |
| Load boundaries from FITS file. | |
| void | save (const GFilename &filename, const bool &clobber=false) const |
| Save boundaries into FITS file. | |
| void | read (const GFitsTable &table) |
| Read boundaries from FITS table. | |
| void | write (GFits &file, const std::string &extname=gammalib::extname_bounds) const |
| Write boundaries into FITS object. | |
| int | index (const double &value) const |
| Returns bin index for a value. | |
| double | min (void) const |
| Return minimum value of all intervals. | |
| double | max (void) const |
| Return maximum value of all intervals. | |
| void | min (const int &index, const double &value) |
| Set minimum value for a given interval. | |
| void | max (const int &index, const double &value) |
| Set maximum value for a given interval. | |
| double | min (const int &index) const |
| Returns minimum value for a given interval. | |
| double | max (const int &index) const |
| Returns maximum value for a given interval. | |
| double | mean (const int &index) const |
| Returns mean value for a given interval. | |
| double | logmean (const int &index) const |
| Returns logarithmic mean value for a given interval. | |
| double | width (const int &index) const |
| Returns interval width. | |
| bool | contains (const double &value) const |
| Checks whether boundaries contain value. | |
| bool | contains (const double &min, const double &max) const |
| Checks whether boundaries contain an interval. | |
| std::string | print (const GChatter &chatter=NORMAL) const |
| Print boundaries. | |
Public Member Functions inherited from GContainer | |
| virtual | ~GContainer (void) |
| Destructor. | |
Public Member Functions inherited from GBase | |
| virtual | ~GBase (void) |
| Destructor. | |
Protected Member Functions | |
| void | init_members (void) |
| Initialise class members. | |
| void | copy_members (const GBounds &bounds) |
| Copy class members. | |
| void | free_members (void) |
| Delete class members. | |
| void | insert_interval (const int &index, const double &min, const double &max) |
| Insert interval. | |
Protected Attributes | |
| std::string | m_unit |
| Unit of values. | |
| std::vector< double > | m_min |
| Array of interval minimum values. | |
| std::vector< double > | m_max |
| Array of interval maximum values. | |
Friends | |
| bool | operator== (const GBounds &a, const GBounds &b) |
| Boundaries equality operator friend. | |
| bool | operator!= (const GBounds &a, const GBounds &b) |
| Boundaries inequality operator friend. | |
Boundaries container class.
This class holds a list of intervals which are each defined by a minimum and a maximum value. Intervals may be continuous or not and overlapping or not. The order of the intervals is not managed by the class, they will be stored as provided. An interval is defined by a minimum and maximum value. By definition, the minimum value is included in the interval, the maximum value is excluded.
Definition at line 59 of file GBounds.hpp.
| GBounds::GBounds | ( | void | ) |
Void constructor.
Constructs empty boundaries.
Definition at line 71 of file GBounds.cpp.
References init_members().
Referenced by clone().
|
explicit |
FITS file constructor.
| [in] | filename | FITS file name. |
Constructs boundaries from a FITS file.
Definition at line 88 of file GBounds.cpp.
References init_members(), and load().
|
explicit |
Array constructor.
| [in] | array | Array. |
| [in] | unit | Boundary units. |
Constructs boundaries from an array of values. Optionally boundary units may be specified for the array values.
Definition at line 110 of file GBounds.cpp.
References init_members(), set(), and unit().
| GBounds::GBounds | ( | const GBounds & | bounds | ) |
Copy constructor.
| [in] | bounds | Boundaries. |
Definition at line 131 of file GBounds.cpp.
References copy_members(), and init_members().
| GBounds::GBounds | ( | const double & | min, |
| const double & | max, | ||
| const std::string & | unit = "" ) |
Interval constructor.
| [in] | min | Minimum of the interval. |
| [in] | max | Maximum of the interval. |
| [in] | unit | Boundary units. |
Constructs boundaries for one [min, max[ interval. Optionally boundary units may be specified for the interval values.
Definition at line 154 of file GBounds.cpp.
References append(), init_members(), max(), min(), and unit().
| GBounds::GBounds | ( | const int & | num, |
| const double & | min, | ||
| const double & | max, | ||
| const std::string & | method, | ||
| const std::string & | unit = "", | ||
| const double & | gamma = 1.0 ) |
Boundary constructor.
| [in] | num | Number of intervals. |
| [in] | min | Minimum value of first interval. |
| [in] | max | Maximum value of last interval. |
| [in] | method | Spacing method (one of "LIN", "LOG" or "POW"). |
| [in] | unit | Boundary units. |
| [in] | gamma | Power law index for POW method. |
Constructs boundaries by defining num successive intervals between min and max. The method parameter controls the spacing of the boundaries. Optionally boundary units may be specified for the interval values. For the POW method, the parameter gamma controls the slope of the power law. See the set() method for more information.
Definition at line 186 of file GBounds.cpp.
References init_members(), max(), min(), set(), and unit().
|
virtual |
| void GBounds::append | ( | const double & | min, |
| const double & | max ) |
Append interval.
| [in] | min | Minimum value of interval. |
| [in] | max | Maximum value of interval. |
Appends an interval to the end of the boundaries container.
Definition at line 294 of file GBounds.cpp.
References insert_interval(), max(), min(), and size().
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 142 of file GBounds.hpp.
|
virtual |
Clear boundaries.
Implements GBase.
Definition at line 262 of file GBounds.cpp.
References free_members(), and init_members().
Referenced by GCOSEventCube::init_members(), read(), set(), and set().
|
virtual |
Clone boundaries.
Implements GBase.
Definition at line 280 of file GBounds.cpp.
References GBounds().
| bool GBounds::contains | ( | const double & | min, |
| const double & | max ) const |
Checks whether boundaries contain an interval.
| [in] | min | Minimum value of interval to be checked. |
| [in] | max | Maximum value of interval to be checked. |
Checks if the interval [min, max] exists within the boundary contained.
Definition at line 1051 of file GBounds.cpp.
| bool GBounds::contains | ( | const double & | value | ) | const |
Checks whether boundaries contain value.
| [in] | value | Value to be checked. |
Checks if the value falls in at least one of the intervals. The method exits when the first matching interval has been found.
Definition at line 1023 of file GBounds.cpp.
|
protected |
Copy class members.
| [in] | ebds | Energy boundaries. |
Definition at line 1145 of file GBounds.cpp.
References m_max, m_min, and m_unit.
Referenced by GBounds(), and operator=().
| void GBounds::extend | ( | const GBounds & | bounds | ) |
Append boundaries.
| [in] | ebds | Energy boundaries. |
Append boundaries to the container.
Definition at line 381 of file GBounds.cpp.
References is_empty(), m_max, m_min, reserve(), and size().
|
protected |
Delete class members.
Definition at line 1160 of file GBounds.cpp.
Referenced by clear(), operator=(), and ~GBounds().
| int GBounds::index | ( | const double & | value | ) | const |
Returns bin index for a value.
| [in] | value | Value. |
Returns the boundary bin index for a given value. By convention, the limits for a bin are defined as
min <= value < max
i.e. a value equaling to max falls above the boundary.
If the value falls outside all boundaries, -1 is returned.
Definition at line 758 of file GBounds.cpp.
References index(), m_max, m_min, and size().
Referenced by GCOSEventCube::fill(), index(), insert_interval(), logmean(), max(), max(), mean(), min(), min(), remove(), and width().
|
protected |
| void GBounds::insert | ( | const double & | min, |
| const double & | max ) |
Insert interval.
| [in] | min | Minimum value of interval. |
| [in] | max | Maximum value of interval. |
Inserts an interval into the boundaries after the first boundary that has a minimum value smaller than min. The method implicitely assumes that the intervals are ordered by increasing minimum value.
Definition at line 314 of file GBounds.cpp.
References insert_interval(), m_min, max(), min(), and size().
|
protected |
Insert interval.
| [in] | index | Index after with interval is inserted. |
| [in] | min | Minimum value of interval. |
| [in] | max | Maximum value of interval. |
| GException::invalid_argument | Minimum value larger than maximum value |
Inserts an interval after the specified index in the boundaries. The method does not reorder the intervals, instead the client needs to determine the approriate index.
Invalid parameters do not produce any exception, but are handled transparently. If the interval is invalid (i.e. min > max) an exception is thrown. If the index is out of the valid range, the index will be adjusted to either the first or the last element.
Definition at line 1186 of file GBounds.cpp.
References G_INSERT_VALUE, index(), m_max, m_min, max(), min(), and gammalib::str().
|
inlinevirtual |
Signal if there are no boundaries.
Implements GContainer.
Definition at line 166 of file GBounds.hpp.
References m_min.
Referenced by extend().
| void GBounds::load | ( | const GFilename & | filename | ) |
Load boundaries from FITS file.
| [in] | filename | FITS file name. |
Loads boundaries from a FITS file.
If no extension name is provided, the boundaries are loaded from the BOUNDS extension.
Definition at line 595 of file GBounds.cpp.
References GFits::close(), GFilename::extname(), gammalib::extname_bounds, read(), and GFits::table().
Referenced by GBounds().
| double GBounds::logmean | ( | const int & | index | ) | const |
Returns logarithmic mean value for a given interval.
| [in] | index | Interval index (0,...,size()-1). |
| GException::out_of_range | Specified index is out of range. |
Computes the logarithmic mean value for the interval index.
Definition at line 972 of file GBounds.cpp.
References G_LOGMEAN, index(), logmean(), m_max, m_min, and size().
Referenced by logmean().
| double GBounds::max | ( | const int & | index | ) | const |
Returns maximum value for a given interval.
| [in] | index | Interval index (0,...,size()-1). |
| GException::out_of_range | Specified index is out of range. |
Definition at line 917 of file GBounds.cpp.
| void GBounds::max | ( | const int & | index, |
| const double & | value ) |
Set maximum value for a given interval.
| [in] | index | Interval index (0,...,size()-1). |
| [in] | value | Maximum value of interval. |
| GException::out_of_range | Specified index is out of range. |
Sets the maximum value for the interval index.
Definition at line 866 of file GBounds.cpp.
| double GBounds::max | ( | void | ) | const |
Return maximum value of all intervals.
Definition at line 806 of file GBounds.cpp.
References m_max, max(), and size().
Referenced by append(), contains(), GBounds(), GBounds(), insert(), insert_interval(), max(), print(), GCOSEventCube::print(), set(), and GCOSEventCube::set_scatter_angles().
| double GBounds::mean | ( | const int & | index | ) | const |
Returns mean value for a given interval.
| [in] | index | Interval index (0,...,size()-1). |
| GException::out_of_range | Specified index is out of range. |
Computes the mean value for the interval index.
Definition at line 943 of file GBounds.cpp.
References G_MEAN, index(), m_max, m_min, mean(), and size().
Referenced by mean(), and GCOSEventCube::set_scatter_angles().
| double GBounds::min | ( | const int & | index | ) | const |
Returns minimum value for a given interval.
| [in] | index | Interval index (0,...,size()-1). |
| GException::out_of_range | Specified index is out of range. |
Definition at line 893 of file GBounds.cpp.
| void GBounds::min | ( | const int & | index, |
| const double & | value ) |
Set minimum value for a given interval.
| [in] | index | Energy interval index (0,...,size()-1). |
| [in] | value | Minimum value of interval. |
| GException::out_of_range | Specified index is out of range. |
Sets the minimum value for the interval index.
Definition at line 837 of file GBounds.cpp.
| double GBounds::min | ( | void | ) | const |
Return minimum value of all intervals.
Definition at line 781 of file GBounds.cpp.
References m_min, min(), and size().
Referenced by append(), contains(), GBounds(), GBounds(), insert(), insert_interval(), min(), print(), GCOSEventCube::print(), set(), and GCOSEventCube::set_scatter_angles().
Assignment operator.
| [in] | bounds | Boundaries to be assigned. |
Definition at line 232 of file GBounds.cpp.
References copy_members(), free_members(), and init_members().
Print boundaries.
| [in] | chatter | Chattiness. |
Implements GBase.
Definition at line 1075 of file GBounds.cpp.
References EXPLICIT, max(), min(), gammalib::parformat(), SILENT, size(), gammalib::str(), and unit().
| void GBounds::read | ( | const GFitsTable & | table | ) |
Read boundaries from FITS table.
| [in] | table | FITS table. |
Reads the boundaries from a FITS table.
Definition at line 662 of file GBounds.cpp.
References append(), clear(), m_unit, GFitsTable::nrows(), GFitsTableCol::real(), reserve(), and GFitsTableCol::unit().
Referenced by load(), and GCOSEventCube::read().
|
virtual |
Remove interval.
| [in] | index | Interval index [0,...,size()[. |
Removes interval at index from the boundaries container. All intervals after the specified index are moved forward by one position.
Implements GContainer.
Definition at line 339 of file GBounds.cpp.
References G_REMOVE_INX, index(), m_max, m_min, and size().
|
virtual |
Reserve space for intervals.
| [in] | num | Number of elements. |
Implements GContainer.
Definition at line 363 of file GBounds.cpp.
| void GBounds::save | ( | const GFilename & | filename, |
| const bool & | clobber = false ) const |
Save boundaries into FITS file.
| [in] | filename | FITS file name. |
| [in] | clobber | Overwrite an existing boundaries extension? |
Saves boundaries into a FITS file. If a file with the given filename does not yet exist it will be created, otherwise the method opens the existing file. Boundaries can only be appended to an existing file if the clobber flag is set to "true" (otherwise an exception is thrown).
The method will append a binary FITS table containing the boundaries to the FITS file. The extension name can be specified as part of the filename. For example the filename
myfile.fits[BOUNDARIES]
will save the boundaries in the BOUNDARIES extension of the "myfile.fits" file. If the extension exists already in the file it will be replaced, otherwise a new extension will be created. If no extension name is provided, the method will use BOUNDS as the default extension name for boundaries.
Definition at line 637 of file GBounds.cpp.
References GFilename::extname(), gammalib::extname_bounds, GFits::save(), GFilename::url(), and write().
| void GBounds::set | ( | const int & | num, |
| const double & | min, | ||
| const double & | max, | ||
| const std::string & | method, | ||
| const double & | gamma = 1.0 ) |
Set intervals.
| [in] | num | Number of intervals. |
| [in] | min | Minimum value of first interval. |
| [in] | max | Maximum value of last interval. |
| [in] | method | Energy spacing method (one of "LIN", "LOG" or "POW"). |
| [in] | gamma | Power law index for POW method. |
| GException::invalid_argument | num is negative. min value is not smaller than max value. Non-positive min value specified for LOG or POW method. Invalid spacing method specified. |
Sets boundaries by defining num successive intervals between min and max. The method parameter controls the spacing of the boundaries. Note that the max value needs to be larger than the min value. For the "LOG" and "POW" methods the min value needs to be positive.
Note that the method conserves the units of the boundaries.
Definition at line 484 of file GBounds.cpp.
References append(), clear(), G_SET, m_unit, max(), min(), reserve(), gammalib::str(), gammalib::toupper(), and unit().
| void GBounds::set | ( | const std::vector< double > & | array | ) |
Set boundaries from array.
| [in] | array | Array. |
Sets boundaries from an array. Each two subsequent values in the array will form a boundary. This means that n values will lead to n-1 boundaries with the following mapping:
[array[0], array[1]] [array[1], array[2]] ... [array[n-2], array[n-1]]
If there is only one value in the array the following empty boundary will be appended:
[array[0], array[0]]
Note that the method conserves the units of the boundaries.
Definition at line 428 of file GBounds.cpp.
|
inlinevirtual |
Return number of boundaries.
Implements GContainer.
Definition at line 154 of file GBounds.hpp.
References m_min.
Referenced by append(), contains(), contains(), extend(), GCOSEventCube::fill(), index(), insert(), logmean(), max(), max(), max(), mean(), min(), min(), min(), print(), GCOSEventCube::print(), GCOSEventCube::read(), remove(), GCOSEventCube::set(), GCOSEventCube::set_scatter_angles(), width(), and write().
|
inline |
|
inline |
Return boundary units.
Definition at line 178 of file GBounds.hpp.
References m_unit.
Referenced by GBounds(), GBounds(), GBounds(), print(), GCOSEventCube::print(), set(), set(), GCOSEventCube::set(), and unit().
| double GBounds::width | ( | const int & | index | ) | const |
Returns interval width.
| [in] | index | Interval index (0,...,size()-1). |
| GException::out_of_range | Specified index is out of range. |
Definition at line 999 of file GBounds.cpp.
| void GBounds::write | ( | GFits & | fits, |
| const std::string & | extname = gammalib::extname_bounds ) const |
Write boundaries into FITS object.
| [in] | fits | FITS file. |
| [in] | extname | Boundary extension name. |
Writes the boundaries into a FITS object.
Definition at line 703 of file GBounds.cpp.
References GFits::append(), GFitsTable::append(), GFits::contains(), GFitsHDU::extname(), m_max, m_min, m_unit, GFits::remove(), size(), and GFitsTableCol::unit().
Referenced by save(), and GCOSEventCube::write().
Boundaries inequality operator friend.
| [in] | a | First boundaries. |
| [in] | b | Second boundaries. |
Definition at line 205 of file GBounds.hpp.
Boundaries equality operator friend.
| [in] | a | First boundaries. |
| [in] | b | Second boundaries. |
Definition at line 1221 of file GBounds.cpp.
|
protected |
Array of interval maximum values.
Definition at line 132 of file GBounds.hpp.
Referenced by contains(), contains(), copy_members(), extend(), index(), init_members(), insert_interval(), logmean(), max(), max(), max(), mean(), remove(), reserve(), width(), and write().
|
protected |
Array of interval minimum values.
Definition at line 131 of file GBounds.hpp.
Referenced by contains(), contains(), copy_members(), extend(), index(), init_members(), insert(), insert_interval(), is_empty(), logmean(), mean(), min(), min(), min(), remove(), reserve(), size(), width(), and write().
|
protected |
Unit of values.
Definition at line 130 of file GBounds.hpp.
Referenced by copy_members(), init_members(), read(), set(), set(), unit(), unit(), and write().