GammaLib  1.7.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 bool &log=true)
 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_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 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...
 

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 67 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 84 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 104 of file GEnergies.cpp.

References init_members(), and set().

GEnergies::GEnergies ( const GEnergies energies)

Copy constructor.

Parameters
energiesEnergy container.

Construct energy container by copying from another energy container.

Definition at line 124 of file GEnergies.cpp.

References copy_members(), and init_members().

GEnergies::GEnergies ( const int &  num,
const GEnergy emin,
const GEnergy emax,
const bool &  log = true 
)

Interval constructor.

Parameters
[in]numNumber of energies.
[in]eminMinimum energy.
[in]emaxMaximum energy.
[in]logUse logarithmic spacing? (defaults to true).

Constructs energy container by defining num energies between emin and emax. The log parameter controls whether the energy spacing is logarihmic (default) or linear.

Definition at line 149 of file GEnergies.cpp.

References init_members(), set_lin(), and set_log().

GEnergies::~GEnergies ( void  )
virtual

Destructor.

Definition at line 171 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 303 of file GEnergies.cpp.

References m_energies, and size().

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

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

Return reference to energy.

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

Returns a reference to the energy with the specified index.

Definition at line 261 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()-1].
Exceptions
GException::out_of_rangeEnergy index is out of range.

Returns a reference to the energy with the specified index.

Definition at line 283 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 120 of file GEnergies.hpp.

void GEnergies::clear ( void  )
virtual
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 245 of file GEnergies.cpp.

References GEnergies().

void GEnergies::copy_members ( const GEnergies energies)
protected

Copy class members.

Parameters
[in]energiesEnergy container.

Definition at line 819 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 383 of file GEnergies.cpp.

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

Referenced by GCTABackground3D::init_mc_cache().

void GEnergies::free_members ( void  )
protected

Delete class members.

Definition at line 832 of file GEnergies.cpp.

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

void GEnergies::init_members ( void  )
protected

Initialise class members.

Definition at line 804 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()-1).
[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 325 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 176 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 615 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 193 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 134 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 148 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 764 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 681 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()-1).
Exceptions
GException::out_of_rangeEnergy index is out of range.

Remove energy of specified index from container.

Implements GContainer.

Definition at line 359 of file GEnergies.cpp.

References G_REMOVE, m_energies, and size().

Referenced by 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 190 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 657 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 416 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_lin ( const int &  num,
const GEnergy emin,
const GEnergy emax 
)

Set linearly spaced energies.

Parameters
[in]numNumber of energies.
[in]eminMinimum energy.
[in]emaxMaximum energy.
Exceptions
GException::invalid_argumentInvalid number of energies or minimum and maximum energy requested.

Creates num linearly spaced energies running from emin to emax.

Definition at line 467 of file GEnergies.cpp.

References append(), clear(), G_SET_LIN, GEnergy::print(), and gammalib::str().

Referenced by GEnergies().

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

Set logarithmically spaced energies.

Parameters
[in]numNumber of energies.
[in]eminMinimum energy.
[in]emaxMaximum energy.
Exceptions
GException::invalid_argumentInvalid number of energies or minimum and maximum energy requested.

Creates num logarithmically spaced energies running from emin to emax.

Definition at line 542 of file GEnergies.cpp.

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

Referenced by GEnergies().

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 725 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 110 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: