GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GEnergies Class Reference

Energy container class. More...

#include <GEnergies.hpp>

Inheritance diagram for GEnergies:
GContainer GBase

Public Member Functions

 GEnergies (void)
 Void constructor. More...
 
 GEnergies (const GFilename &filename)
 FITS file constructor. More...
 
 GEnergies (const GEbounds &ebounds)
 Energy boundaries constructor. More...
 
 GEnergies (const GEnergies &energies)
 Copy constructor. More...
 
 GEnergies (const int &num, const GEnergy &emin, const GEnergy &emax, const std::string &method="LOG", const double &gamma=1.0)
 Interval constructor. More...
 
virtual ~GEnergies (void)
 Destructor. More...
 
GEnergiesoperator= (const GEnergies &energies)
 Assignment operator. More...
 
GEnergyoperator[] (const int &index)
 Return reference to energy. More...
 
const GEnergyoperator[] (const int &index) const
 Return reference to energy (const version) More...
 
void clear (void)
 Clear energy container. More...
 
GEnergiesclone (void) const
 Clone energy container. More...
 
std::string classname (void) const
 Return class name. More...
 
GEnergyat (const int &index)
 Return reference to energy. More...
 
const GEnergyat (const int &index) const
 Return reference to energy (const version) More...
 
int size (void) const
 Return number of energies in container. More...
 
bool is_empty (void) const
 Signals if there are no energies in container. More...
 
GEnergyappend (const GEnergy &energy)
 Append energy to container. More...
 
GEnergyinsert (const int &index, const GEnergy &energy)
 Insert energy into container. More...
 
void remove (const int &index)
 Remove energy from container. More...
 
void reserve (const int &num)
 Reserves space for energies in container. More...
 
void extend (const GEnergies &energies)
 Append energy container. More...
 
void set (const GEbounds &ebounds)
 Set energies from energy boundaries. More...
 
void set (const int &num, const GEnergy &emin, const GEnergy &emax, const std::string &method="LOG", const double &gamma=1.0)
 Set energies. More...
 
void load (const GFilename &filename)
 Load energies from FITS file. More...
 
void save (const GFilename &filename, const bool &clobber=false) const
 Save energies into FITS file. More...
 
void read (const GFitsTable &table)
 Read energies from FITS table. More...
 
void write (GFits &file, const std::string &extname=gammalib::extname_energies) const
 Write energies into FITS object. More...
 
std::string print (const GChatter &chatter=NORMAL) const
 Print energy container information. More...
 
- Public Member Functions inherited from GContainer
virtual ~GContainer (void)
 Destructor. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GEnergies &energies)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void set_lin (const int &num, const GEnergy &emin, const GEnergy &emax)
 Set linearly spaced energies. More...
 
void set_log (const int &num, const GEnergy &emin, const GEnergy &emax)
 Set logarithmically spaced energies. More...
 
void set_pow (const int &num, const GEnergy &emin, const GEnergy &emax, const double &gamma)
 Set power-law spaced energy intervals. More...
 

Protected Attributes

std::vector< GEnergym_energies
 List of energies. More...
 

Detailed Description

Energy container class.

This class is a container for energies. Energies are implemented by the GEnergy class which stores energies in a unit independent way.

An energy container can be constructed from a FITS file or by defining a number of energies within a given interval, spaced either linearly or logarithmically.

Definition at line 60 of file GEnergies.hpp.

Constructor & Destructor Documentation

GEnergies::GEnergies ( void  )

Void constructor.

Constructs empty energy container.

Definition at line 70 of file GEnergies.cpp.

References init_members().

Referenced by clone().

GEnergies::GEnergies ( const GFilename filename)
explicit

FITS file constructor.

Parameters
[in]filenameFITS file name.

Constructs energy container from a FITS file.

Definition at line 87 of file GEnergies.cpp.

References init_members(), and load().

GEnergies::GEnergies ( const GEbounds ebounds)
explicit

Energy boundaries constructor.

Parameters
[in]eboundsEnergy boundaries.

Constructs energy container from energy boundaries.

Definition at line 107 of file GEnergies.cpp.

References init_members(), and set().

GEnergies::GEnergies ( const GEnergies energies)

Copy constructor.

Parameters
[in]energiesEnergy container.

Construct energy container by copying from another energy container.

Definition at line 127 of file GEnergies.cpp.

References copy_members(), and init_members().

GEnergies::GEnergies ( const int &  num,
const GEnergy emin,
const GEnergy emax,
const std::string &  method = "LOG",
const double &  gamma = 1.0 
)

Interval constructor.

Parameters
[in]numNumber of energies.
[in]eminMinimum energy.
[in]emaxMaximum energy.
[in]methodEnergy spacing method (one of "LIN", "LOG" or "POW").
[in]gammaPower law index for POW method.

Constructs energy container by defining num energies between emin and emax. The method parameter controls the energy spacing of the energies. See the set() method for more information.

Definition at line 153 of file GEnergies.cpp.

References init_members(), and set().

GEnergies::~GEnergies ( void  )
virtual

Destructor.

Definition at line 173 of file GEnergies.cpp.

References free_members().

Member Function Documentation

GEnergy & GEnergies::append ( const GEnergy energy)

Append energy to container.

Parameters
[in]energyEnergy.
Returns
Reference to appended energy.

Appends energy to the container by making a deep copy of the energy.

Definition at line 305 of file GEnergies.cpp.

References m_energies, and size().

Referenced by GModelSpatialDiffuseCube::energies(), GCTAResponseCube::irf_radial(), GCTABackgroundPerfTable::load(), GCTABackgroundPerfTable::print(), read(), set_lin(), set_log(), GCTABackground3D::set_members(), GCTABackground2D::set_members(), set_pow(), and GModelSpatialDiffuseCube::write().

GEnergy & GEnergies::at ( const int &  index)

Return reference to energy.

Parameters
[in]indexEnergy index [0,...,size()[.
Exceptions
GException::out_of_rangeEnergy index is out of range.

Returns a reference to the energy with the specified index.

Definition at line 263 of file GEnergies.cpp.

References G_AT, m_energies, and size().

const GEnergy & GEnergies::at ( const int &  index) const

Return reference to energy (const version)

Parameters
[in]indexEnergy index [0,...,size()[.
Exceptions
GException::out_of_rangeEnergy index is out of range.

Returns a reference to the energy with the specified index.

Definition at line 285 of file GEnergies.cpp.

References G_AT, m_energies, and size().

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

Return class name.

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

Implements GBase.

Definition at line 128 of file GEnergies.hpp.

GEnergies * GEnergies::clone ( void  ) const
virtual

Clone energy container.

Returns
Pointer to deep copy of energy container

Makes a deep copy of the energy container instance.

Implements GBase.

Definition at line 247 of file GEnergies.cpp.

References GEnergies().

void GEnergies::copy_members ( const GEnergies energies)
protected

Copy class members.

Parameters
[in]energiesEnergy container.

Definition at line 753 of file GEnergies.cpp.

References m_energies.

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

void GEnergies::extend ( const GEnergies energies)

Append energy container.

Parameters
[in]energiesEnergy container.

Append energy container to the container.

Definition at line 388 of file GEnergies.cpp.

References is_empty(), m_energies, reserve(), and size().

Referenced by GCTABackground2D::init_mc_cache(), and GCTABackground3D::init_mc_cache().

void GEnergies::free_members ( void  )
protected

Delete class members.

Definition at line 766 of file GEnergies.cpp.

Referenced by clear(), operator=(), read(), and ~GEnergies().

void GEnergies::init_members ( void  )
protected

Initialise class members.

Definition at line 738 of file GEnergies.cpp.

References m_energies.

Referenced by clear(), GEnergies(), operator=(), and read().

GEnergy & GEnergies::insert ( const int &  index,
const GEnergy energy 
)

Insert energy into container.

Parameters
[in]indexEnergy index (0,...,size()[.
[in]energyEnergy.
Exceptions
GException::out_of_rangeEnergy index is out of range.

Inserts an energy into the container before the energy with the specified index.

Definition at line 327 of file GEnergies.cpp.

References G_INSERT, is_empty(), m_energies, and size().

bool GEnergies::is_empty ( void  ) const
inlinevirtual

Signals if there are no energies in container.

Returns
True if container is empty, false otherwise.

Signals if the energy container does not contain any energy.

Implements GContainer.

Definition at line 184 of file GEnergies.hpp.

References m_energies.

Referenced by GCTACubeEdisp::ebounds(), extend(), and insert().

void GEnergies::load ( const GFilename filename)

Load energies from FITS file.

Parameters
[in]filenameFITS file name.

Loads the energies from FITS file.

If no extension name is provided, the energies are loaded from the ENERGIES extension.

Definition at line 548 of file GEnergies.cpp.

References GFits::close(), GFilename::extname(), gammalib::extname_energies, read(), and GFits::table().

Referenced by GEnergies().

GEnergies & GEnergies::operator= ( const GEnergies energies)

Assignment operator.

Parameters
[in]energiesEnergy container.
Returns
Energy container.

Definition at line 195 of file GEnergies.cpp.

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

GEnergy & GEnergies::operator[] ( const int &  index)
inline

Return reference to energy.

Parameters
[in]indexEnergy index [0,...,size()-1].

Returns a reference to the energy with the specified index.

Definition at line 142 of file GEnergies.hpp.

References m_energies.

const GEnergy & GEnergies::operator[] ( const int &  index) const
inline

Return reference to energy (const version)

Parameters
[in]indexEnergy index [0,...,size()-1].

Returns a reference to the energy with the specified index.

Definition at line 156 of file GEnergies.hpp.

References m_energies.

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

Print energy container information.

Parameters
[in]chatterChattiness.
Returns
String containing energy container information.

Implements GBase.

Definition at line 698 of file GEnergies.cpp.

References EXPLICIT, m_energies, gammalib::parformat(), SILENT, size(), and gammalib::str().

Referenced by GCTACubeExposure::print(), GCTACubePsf::print(), and GCTACubeEdisp::print().

void GEnergies::read ( const GFitsTable table)

Read energies from FITS table.

Parameters
[in]tableFITS table.

Reads the energies from a FITS table.

Definition at line 615 of file GEnergies.cpp.

References append(), free_members(), GFitsHDU::has_card(), init_members(), GFitsHDU::integer(), GFitsTableCol::real(), and GFitsHDU::string().

Referenced by load(), GCTACubeExposure::read(), GCTACubePsf::read(), GCTACubeEdisp::read(), and GModelSpatialDiffuseCube::read().

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

Remove energy from container.

Parameters
[in]indexEnergy index (0,...,size()[.
Exceptions
GException::out_of_rangeEnergy index is out of range.

Remove energy of specified index from container.

Implements GContainer.

Definition at line 363 of file GEnergies.cpp.

References G_REMOVE, m_energies, and size().

Referenced by GCTABackground2D::init_mc_cache(), and GCTABackground3D::init_mc_cache().

void GEnergies::reserve ( const int &  num)
inlinevirtual

Reserves space for energies in container.

Parameters
[in]numNumber of energies.

Reserves space for num energies in the container.

Implements GContainer.

Definition at line 198 of file GEnergies.hpp.

References m_energies.

Referenced by GModelSpatialDiffuseCube::energies(), and extend().

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

Save energies into FITS file.

Parameters
[in]filenameFITS filename.
[in]clobberOverwrite an existing energies extension?

Saves energies 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. Energies 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 energies to the FITS file. The extension name can be specified as part of the filename. For example the filename

 myfile.fits[ENERGY VALUES]

will save the energies in the ENERGY VALUES 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 ENERGIES as the default extension name for energies.

Definition at line 591 of file GEnergies.cpp.

References GFilename::extname(), gammalib::extname_energies, GFilename::url(), and write().

void GEnergies::set ( const GEbounds ebounds)

Set energies from energy boundaries.

Parameters
[in]eboundsEnergy boundaries.

Sets the energies from energy boundaries. Each unique minimum and maximum energy boundary will be appended as energy to the container.

Definition at line 421 of file GEnergies.cpp.

References clear(), GEbounds::emax(), GEbounds::emin(), m_energies, and GEbounds::size().

Referenced by GCTACubeEdisp::GCTACubeEdisp(), GCTACubeExposure::GCTACubeExposure(), GCTACubePsf::GCTACubePsf(), and GEnergies().

void GEnergies::set ( const int &  num,
const GEnergy emin,
const GEnergy emax,
const std::string &  method = "LOG",
const double &  gamma = 1.0 
)

Set energies.

Parameters
[in]numNumber of energies.
[in]eminMinimum energy.
[in]emaxMaximum energy.
[in]methodEnergy spacing method (one of "LIN", "LOG" or "POW").
[in]gammaPower law index for POW method.
Exceptions
GException::invalid_argumentInvalid number of energies, energy interval or energy spacing method specified.

Sets energies by defining num successive energies between emin and emax. The method parameter controls the energy spacing. See the set_lin(), set_log() and set_pow() methods for more information.

Definition at line 476 of file GEnergies.cpp.

References G_SET, GEnergy::print(), set_lin(), set_log(), set_pow(), gammalib::str(), and gammalib::toupper().

void GEnergies::set_lin ( const int &  num,
const GEnergy emin,
const GEnergy emax 
)
protected

Set linearly spaced energies.

Parameters
[in]numNumber of energies (>0).
[in]eminMinimum energy.
[in]emaxMaximum energy.

Creates \(N\) linearly spaced energy boundaries running from \(E_{\rm min}\) to \(E_{\rm max}\) defined by

\[ E_i = E_{\rm min} + \frac{E_{\rm max} - E_{\rm min}}{N-1} \times i \]

The method does not check the validity of the num, emin and emax arguments.

Definition at line 791 of file GEnergies.cpp.

References append(), and clear().

Referenced by set().

void GEnergies::set_log ( const int &  num,
const GEnergy emin,
const GEnergy emax 
)
protected

Set logarithmically spaced energies.

Parameters
[in]numNumber of energies (>0).
[in]eminMinimum energy.
[in]emaxMaximum energy.
Exceptions
GException::invalid_argumentMinimum or maximum energy are not positive.

Creates \(N\) logarithmically spaced energy boundaries running from \(E_{\rm min}\) to \(E_{\rm max}\) defined by

\[ E_i = 10^{\log_{10} E_{\rm min} + \frac{\log_{10} E_{\rm max} - \log_{10} E_{\rm min}}{N-1} \times i} \]

The method does not check the validity of the num, emin and emax arguments except for the positivity of emin and emax.

Definition at line 845 of file GEnergies.cpp.

References append(), clear(), G_SET_LOG, log10(), GEnergy::MeV(), pow(), and GEnergy::print().

Referenced by set().

void GEnergies::set_pow ( const int &  num,
const GEnergy emin,
const GEnergy emax,
const double &  gamma 
)
protected

Set power-law spaced energy intervals.

Parameters
[in]numNumber of energy intervals (>0).
[in]eminMinimum energy of first interval.
[in]emaxMaximum energy of last interval.
[in]gammaPower law index.
Exceptions
GException::invalid_argumentMinimum or maximum energy are not positive.

Creates \(N\) power-law spaced energy boundaries running from \(E_{\rm min}\) to \(E_{\rm max}\) defined by

\[ E_i = \left \{ \begin{array}{l l} \exp \left( \frac{\log E_{\rm max} - \log E_{\rm min}}{N-1} + \log E_{i-1} \right) & \mbox{if $a = 0$} \\ \\ \exp \left( \frac{\log \left(\frac{E_{\rm max}^a - E_{\rm min}^a}{N-1} \right) + E_{i-1}^{a}}{a} \right) & \mbox{else} \end{array} \right . \]

where \(i>0\), \(a=1-\gamma\) and \(E_0=E_{\rm min}\).

The method does not check the validity of the num, emin and emax arguments except for the positivity of emin and emax.

Definition at line 926 of file GEnergies.cpp.

References append(), clear(), exp(), G_SET_POW, log(), GEnergy::MeV(), pow(), and GEnergy::print().

Referenced by set().

void GEnergies::write ( GFits fits,
const std::string &  extname = gammalib::extname_energies 
) const

Write energies into FITS object.

Parameters
[in]fitsFITS file.
[in]extnameEnergy extension name.

Writes energies into FITS object.

Definition at line 659 of file GEnergies.cpp.

References GFitsTable::append(), GFits::append(), GFits::contains(), GFitsHDU::extname(), m_energies, GFits::remove(), and GFitsTableCol::unit().

Referenced by save(), GCTACubeExposure::write(), GCTACubePsf::write(), GCTACubeEdisp::write(), and GModelSpatialDiffuseCube::write().

Member Data Documentation

std::vector<GEnergy> GEnergies::m_energies
protected

List of energies.

Definition at line 118 of file GEnergies.hpp.

Referenced by append(), at(), copy_members(), extend(), init_members(), insert(), is_empty(), operator[](), print(), remove(), reserve(), set(), size(), and write().


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