GammaLib
2.0.0
|
Energy container class. More...
#include <GEnergies.hpp>
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... | |
GEnergies & | operator= (const GEnergies &energies) |
Assignment operator. More... | |
GEnergy & | operator[] (const int &index) |
Return reference to energy. More... | |
const GEnergy & | operator[] (const int &index) const |
Return reference to energy (const version) More... | |
void | clear (void) |
Clear energy container. More... | |
GEnergies * | clone (void) const |
Clone energy container. More... | |
std::string | classname (void) const |
Return class name. More... | |
GEnergy & | at (const int &index) |
Return reference to energy. More... | |
const GEnergy & | at (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... | |
GEnergy & | append (const GEnergy &energy) |
Append energy to container. More... | |
GEnergy & | insert (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< GEnergy > | m_energies |
List of energies. More... | |
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.
GEnergies::GEnergies | ( | void | ) |
Void constructor.
Constructs empty energy container.
Definition at line 70 of file GEnergies.cpp.
References init_members().
Referenced by clone().
|
explicit |
FITS file constructor.
[in] | filename | FITS file name. |
Constructs energy container from a FITS file.
Definition at line 87 of file GEnergies.cpp.
References init_members(), and load().
|
explicit |
Energy boundaries constructor.
[in] | ebounds | Energy 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.
[in] | energies | Energy 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.
[in] | num | Number of energies. |
[in] | emin | Minimum energy. |
[in] | emax | Maximum energy. |
[in] | method | Energy spacing method (one of "LIN", "LOG" or "POW"). |
[in] | gamma | Power 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().
|
virtual |
Append energy to container.
[in] | energy | 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.
[in] | index | Energy index [0,...,size()[. |
GException::out_of_range | Energy 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)
[in] | index | Energy index [0,...,size()[. |
GException::out_of_range | Energy 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().
|
inlinevirtual |
Return class name.
Implements GBase.
Definition at line 128 of file GEnergies.hpp.
|
virtual |
Clear energy container.
Removes all energies from the container.
Implements GBase.
Definition at line 227 of file GEnergies.cpp.
References free_members(), and init_members().
Referenced by GCTABackgroundPerfTable::init_members(), GCTABackground2D::init_members(), GCTABackground3D::init_members(), GCTACubeExposure::init_members(), GCTACubePsf::init_members(), GCTACubeEdisp::init_members(), GCTABackgroundPerfTable::load(), set(), set_lin(), set_log(), GCTABackground2D::set_members(), GCTABackground3D::set_members(), and set_pow().
|
virtual |
Clone energy container.
Makes a deep copy of the energy container instance.
Implements GBase.
Definition at line 247 of file GEnergies.cpp.
References GEnergies().
|
protected |
Copy class members.
[in] | energies | Energy 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.
[in] | energies | Energy 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().
|
protected |
Delete class members.
Definition at line 766 of file GEnergies.cpp.
Referenced by clear(), operator=(), read(), and ~GEnergies().
|
protected |
Initialise class members.
Definition at line 738 of file GEnergies.cpp.
References m_energies.
Referenced by clear(), GEnergies(), operator=(), and read().
Insert energy into container.
[in] | index | Energy index (0,...,size()[. |
[in] | energy | Energy. |
GException::out_of_range | Energy 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().
|
inlinevirtual |
Signals if there are no energies in container.
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.
[in] | filename | FITS 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().
Assignment operator.
[in] | energies | Energy container. |
Definition at line 195 of file GEnergies.cpp.
References copy_members(), free_members(), and init_members().
|
inline |
Return reference to energy.
[in] | index | Energy 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.
|
inline |
Return reference to energy (const version)
[in] | index | Energy 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.
Print energy container information.
[in] | chatter | Chattiness. |
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.
[in] | table | FITS 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().
|
virtual |
Remove energy from container.
[in] | index | Energy index (0,...,size()[. |
GException::out_of_range | Energy 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().
|
inlinevirtual |
Reserves space for energies in container.
[in] | num | Number 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.
[in] | filename | FITS filename. |
[in] | clobber | Overwrite 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.
[in] | ebounds | Energy 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.
[in] | num | Number of energies. |
[in] | emin | Minimum energy. |
[in] | emax | Maximum energy. |
[in] | method | Energy spacing method (one of "LIN", "LOG" or "POW"). |
[in] | gamma | Power law index for POW method. |
GException::invalid_argument | Invalid 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().
Set linearly spaced energies.
[in] | num | Number of energies (>0). |
[in] | emin | Minimum energy. |
[in] | emax | Maximum 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().
Set logarithmically spaced energies.
[in] | num | Number of energies (>0). |
[in] | emin | Minimum energy. |
[in] | emax | Maximum energy. |
GException::invalid_argument | Minimum 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().
|
protected |
Set power-law spaced energy intervals.
[in] | num | Number of energy intervals (>0). |
[in] | emin | Minimum energy of first interval. |
[in] | emax | Maximum energy of last interval. |
[in] | gamma | Power law index. |
GException::invalid_argument | Minimum 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().
|
inlinevirtual |
Return number of energies in container.
Returns the number of energies in the energy container.
Implements GContainer.
Definition at line 170 of file GEnergies.hpp.
References m_energies.
Referenced by append(), at(), GCTACubeEdisp::compute_ebounds(), GCTACubeEdisp::ebounds(), GModelSpatialDiffuseCube::energies(), cta_psf_radial_kerns_delta::eval(), extend(), GCTACubeEdisp::fill(), GCTACubePsf::fill(), GCTACubeExposure::fill_cube(), GCTACubePsf::fill_cube(), GCTACubeEdisp::fill_cube(), GCTACubeEdisp::GCTACubeEdisp(), GCTACubeExposure::GCTACubeExposure(), GCTACubePsf::GCTACubePsf(), GModelSpectralFunc::GModelSpectralFunc(), GModelSpectralNodes::GModelSpectralNodes(), GCTABackground2D::init_mc_cache(), GCTABackground3D::init_mc_cache(), insert(), GModelSpatialDiffuseCube::load_cube(), GCTACubeExposure::print(), print(), GCTACubePsf::print(), GCTACubeEdisp::print(), GCTAResponseCube::psf_radial(), GCTABackground3D::rate_ebin(), GCTABackground2D::rate_ebin(), GModelSpatialDiffuseCube::read(), remove(), GEbounds::set(), GCTACubeExposure::set_eng_axis(), GCTACubePsf::set_eng_axis(), GCTACubeEdisp::set_eng_axis(), GCTACubePsf::set_to_smooth(), cta_psf_radial_kerns_delta::size(), GCTABackgroundPerfTable::size(), GModelSpectralExponential::update_mc_cache(), and GModelSpectralMultiplicative::update_mc_cache().
void GEnergies::write | ( | GFits & | fits, |
const std::string & | extname = gammalib::extname_energies |
||
) | const |
Write energies into FITS object.
[in] | fits | FITS file. |
[in] | extname | Energy 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().
|
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().