GammaLib 2.2.0.dev
Loading...
Searching...
No Matches
GBounds Class Reference

Boundaries container class. More...

#include <GBounds.hpp>

Inheritance diagram for GBounds:
GContainer GBase

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.
 
GBoundsoperator= (const GBounds &bounds)
 Assignment operator.
 
void clear (void)
 Clear boundaries.
 
GBoundsclone (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.
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ GBounds() [1/6]

GBounds::GBounds ( void )

Void constructor.

Constructs empty boundaries.

Definition at line 71 of file GBounds.cpp.

References init_members().

Referenced by clone().

◆ GBounds() [2/6]

GBounds::GBounds ( const GFilename & filename)
explicit

FITS file constructor.

Parameters
[in]filenameFITS file name.

Constructs boundaries from a FITS file.

Definition at line 88 of file GBounds.cpp.

References init_members(), and load().

◆ GBounds() [3/6]

GBounds::GBounds ( const std::vector< double > & array,
const std::string & unit = "" )
explicit

Array constructor.

Parameters
[in]arrayArray.
[in]unitBoundary 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() [4/6]

GBounds::GBounds ( const GBounds & bounds)

Copy constructor.

Parameters
[in]boundsBoundaries.

Definition at line 131 of file GBounds.cpp.

References copy_members(), and init_members().

◆ GBounds() [5/6]

GBounds::GBounds ( const double & min,
const double & max,
const std::string & unit = "" )

Interval constructor.

Parameters
[in]minMinimum of the interval.
[in]maxMaximum of the interval.
[in]unitBoundary 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() [6/6]

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.

Parameters
[in]numNumber of intervals.
[in]minMinimum value of first interval.
[in]maxMaximum value of last interval.
[in]methodSpacing method (one of "LIN", "LOG" or "POW").
[in]unitBoundary units.
[in]gammaPower 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().

◆ ~GBounds()

GBounds::~GBounds ( void )
virtual

Destructor.

Definition at line 210 of file GBounds.cpp.

References free_members().

Member Function Documentation

◆ append()

void GBounds::append ( const double & min,
const double & max )

Append interval.

Parameters
[in]minMinimum value of interval.
[in]maxMaximum 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().

Referenced by GBounds(), read(), set(), and set().

◆ classname()

std::string GBounds::classname ( void ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GBounds").

Implements GBase.

Definition at line 142 of file GBounds.hpp.

◆ clear()

void GBounds::clear ( void )
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().

◆ clone()

GBounds * GBounds::clone ( void ) const
virtual

Clone boundaries.

Returns
Pointer to deep copy of boundaries.

Implements GBase.

Definition at line 280 of file GBounds.cpp.

References GBounds().

◆ contains() [1/2]

bool GBounds::contains ( const double & min,
const double & max ) const

Checks whether boundaries contain an interval.

Parameters
[in]minMinimum value of interval to be checked.
[in]maxMaximum value of interval to be checked.
Returns
True if interval [min, max] exists within boundariesi.

Checks if the interval [min, max] exists within the boundary contained.

Definition at line 1051 of file GBounds.cpp.

References m_max, m_min, max(), min(), and size().

◆ contains() [2/2]

bool GBounds::contains ( const double & value) const

Checks whether boundaries contain value.

Parameters
[in]valueValue to be checked.
Returns
True if value falls in at least one interval, false otherwise.

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.

References m_max, m_min, and size().

◆ copy_members()

void GBounds::copy_members ( const GBounds & bounds)
protected

Copy class members.

Parameters
[in]ebdsEnergy boundaries.

Definition at line 1145 of file GBounds.cpp.

References m_max, m_min, and m_unit.

Referenced by GBounds(), and operator=().

◆ extend()

void GBounds::extend ( const GBounds & bounds)

Append boundaries.

Parameters
[in]ebdsEnergy boundaries.

Append boundaries to the container.

Definition at line 381 of file GBounds.cpp.

References is_empty(), m_max, m_min, reserve(), and size().

◆ free_members()

void GBounds::free_members ( void )
protected

Delete class members.

Definition at line 1160 of file GBounds.cpp.

Referenced by clear(), operator=(), and ~GBounds().

◆ index()

int GBounds::index ( const double & value) const

Returns bin index for a value.

Parameters
[in]valueValue.
Returns
Bin index.

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().

◆ init_members()

void GBounds::init_members ( void )
protected

Initialise class members.

Definition at line 1128 of file GBounds.cpp.

References m_max, m_min, and m_unit.

Referenced by clear(), GBounds(), GBounds(), GBounds(), GBounds(), GBounds(), GBounds(), and operator=().

◆ insert()

void GBounds::insert ( const double & min,
const double & max )

Insert interval.

Parameters
[in]minMinimum value of interval.
[in]maxMaximum 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().

◆ insert_interval()

void GBounds::insert_interval ( const int & index,
const double & min,
const double & max )
protected

Insert interval.

Parameters
[in]indexIndex after with interval is inserted.
[in]minMinimum value of interval.
[in]maxMaximum value of interval.
Exceptions
GException::invalid_argumentMinimum 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().

Referenced by append(), and insert().

◆ is_empty()

bool GBounds::is_empty ( void ) const
inlinevirtual

Signal if there are no boundaries.

Returns
True if there are no boundaries.

Implements GContainer.

Definition at line 166 of file GBounds.hpp.

References m_min.

Referenced by extend().

◆ load()

void GBounds::load ( const GFilename & filename)

Load boundaries from FITS file.

Parameters
[in]filenameFITS 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().

◆ logmean()

double GBounds::logmean ( const int & index) const

Returns logarithmic mean value for a given interval.

Parameters
[in]indexInterval index (0,...,size()-1).
Returns
Logarithmic mean value of interval.
Exceptions
GException::out_of_rangeSpecified 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().

◆ max() [1/3]

double GBounds::max ( const int & index) const

Returns maximum value for a given interval.

Parameters
[in]indexInterval index (0,...,size()-1).
Returns
Maximum value of interval.
Exceptions
GException::out_of_rangeSpecified index is out of range.

Definition at line 917 of file GBounds.cpp.

References G_MAX_GET, index(), m_max, and size().

◆ max() [2/3]

void GBounds::max ( const int & index,
const double & value )

Set maximum value for a given interval.

Parameters
[in]indexInterval index (0,...,size()-1).
[in]valueMaximum value of interval.
Exceptions
GException::out_of_rangeSpecified index is out of range.

Sets the maximum value for the interval index.

Definition at line 866 of file GBounds.cpp.

References G_MAX_SET, index(), m_max, and size().

◆ max() [3/3]

double GBounds::max ( void ) const

Return maximum value of all intervals.

Returns
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().

◆ mean()

double GBounds::mean ( const int & index) const

Returns mean value for a given interval.

Parameters
[in]indexInterval index (0,...,size()-1).
Returns
Mean value of interval.
Exceptions
GException::out_of_rangeSpecified 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().

◆ min() [1/3]

double GBounds::min ( const int & index) const

Returns minimum value for a given interval.

Parameters
[in]indexInterval index (0,...,size()-1).
Returns
Minimum value of interval.
Exceptions
GException::out_of_rangeSpecified index is out of range.

Definition at line 893 of file GBounds.cpp.

References G_MIN_GET, index(), m_min, and size().

◆ min() [2/3]

void GBounds::min ( const int & index,
const double & value )

Set minimum value for a given interval.

Parameters
[in]indexEnergy interval index (0,...,size()-1).
[in]valueMinimum value of interval.
Exceptions
GException::out_of_rangeSpecified index is out of range.

Sets the minimum value for the interval index.

Definition at line 837 of file GBounds.cpp.

References G_MIN_SET, index(), m_min, and size().

◆ min() [3/3]

double GBounds::min ( void ) const

Return minimum value of all intervals.

Returns
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().

◆ operator=()

GBounds & GBounds::operator= ( const GBounds & bounds)

Assignment operator.

Parameters
[in]boundsBoundaries to be assigned.
Returns
Boundaries.

Definition at line 232 of file GBounds.cpp.

References copy_members(), free_members(), and init_members().

◆ print()

std::string GBounds::print ( const GChatter & chatter = NORMAL) const
virtual

Print boundaries.

Parameters
[in]chatterChattiness.
Returns
String containing boundary information.

Implements GBase.

Definition at line 1075 of file GBounds.cpp.

References EXPLICIT, max(), min(), gammalib::parformat(), SILENT, size(), gammalib::str(), and unit().

◆ read()

void GBounds::read ( const GFitsTable & table)

Read boundaries from FITS table.

Parameters
[in]tableFITS 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().

◆ remove()

void GBounds::remove ( const int & index)
virtual

Remove interval.

Parameters
[in]indexInterval 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().

◆ reserve()

void GBounds::reserve ( const int & num)
virtual

Reserve space for intervals.

Parameters
[in]numNumber of elements.

Implements GContainer.

Definition at line 363 of file GBounds.cpp.

References m_max, and m_min.

Referenced by extend(), read(), and set().

◆ save()

void GBounds::save ( const GFilename & filename,
const bool & clobber = false ) const

Save boundaries into FITS file.

Parameters
[in]filenameFITS file name.
[in]clobberOverwrite 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().

◆ set() [1/2]

void GBounds::set ( const int & num,
const double & min,
const double & max,
const std::string & method,
const double & gamma = 1.0 )

Set intervals.

Parameters
[in]numNumber of intervals.
[in]minMinimum value of first interval.
[in]maxMaximum value of last interval.
[in]methodEnergy spacing method (one of "LIN", "LOG" or "POW").
[in]gammaPower law index for POW method.
Exceptions
GException::invalid_argumentnum 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().

◆ set() [2/2]

void GBounds::set ( const std::vector< double > & array)

Set boundaries from array.

Parameters
[in]arrayArray.

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.

References append(), clear(), m_unit, and unit().

Referenced by GBounds(), and GBounds().

◆ size()

int GBounds::size ( void ) const
inlinevirtual

◆ unit() [1/2]

void GBounds::unit ( const std::string & unit)
inline

Set boundary units.

Returns
unit Boundary units.

Definition at line 190 of file GBounds.hpp.

References m_unit, and unit().

◆ unit() [2/2]

const std::string & GBounds::unit ( void ) const
inline

Return boundary units.

Returns
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().

◆ width()

double GBounds::width ( const int & index) const

Returns interval width.

Parameters
[in]indexInterval index (0,...,size()-1).
Returns
Interval width.
Exceptions
GException::out_of_rangeSpecified index is out of range.

Definition at line 999 of file GBounds.cpp.

References G_WIDTH, index(), m_max, m_min, and size().

◆ write()

void GBounds::write ( GFits & fits,
const std::string & extname = gammalib::extname_bounds ) const

Write boundaries into FITS object.

Parameters
[in]fitsFITS file.
[in]extnameBoundary 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().

Friends And Related Symbol Documentation

◆ operator!=

bool operator!= ( const GBounds & a,
const GBounds & b )
friend

Boundaries inequality operator friend.

Parameters
[in]aFirst boundaries.
[in]bSecond boundaries.
Returns
True if both boundaries are different.

Definition at line 205 of file GBounds.hpp.

◆ operator==

bool operator== ( const GBounds & a,
const GBounds & b )
friend

Boundaries equality operator friend.

Parameters
[in]aFirst boundaries.
[in]bSecond boundaries.
Returns
True if both boundaries are identical.

Definition at line 1221 of file GBounds.cpp.

Member Data Documentation

◆ m_max

std::vector<double> GBounds::m_max
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().

◆ m_min

std::vector<double> GBounds::m_min
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().

◆ m_unit

std::string GBounds::m_unit
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().


The documentation for this class was generated from the following files: