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

Multi-wavelength spectrum class interface. More...

#include <GMWLSpectrum.hpp>

Inheritance diagram for GMWLSpectrum:
GEventCube GEvents GBase

Public Member Functions

 GMWLSpectrum (void)
 Void constructor. More...
 
 GMWLSpectrum (const GFilename &filename)
 File constructor. More...
 
 GMWLSpectrum (const GMWLSpectrum &spec)
 Copy constructor. More...
 
virtual ~GMWLSpectrum (void)
 Destructor. More...
 
virtual GMWLSpectrumoperator= (const GMWLSpectrum &spec)
 Assignment operator. More...
 
virtual GMWLDatumoperator[] (const int &index)
 Spectral point access operator. More...
 
virtual const GMWLDatumoperator[] (const int &index) const
 Spectral point access operator (const version) More...
 
virtual void clear (void)
 Clear spectrum. More...
 
virtual GMWLSpectrumclone (void) const
 Clone spectrum. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual int size (void) const
 Return number of spectral bins. More...
 
virtual int dim (void) const
 Return dimension of spectrum. More...
 
virtual int naxis (const int &axis) const
 Return number of spectral bins per dimension. More...
 
virtual void load (const GFilename &filename)
 Load spectrum. More...
 
virtual void save (const GFilename &filename, const bool &clobber=false) const
 Save spectrum. More...
 
virtual void read (const GFits &file)
 Read spectrum from FITS file. More...
 
virtual void write (GFits &file) const
 Write spectrum into FITS file. More...
 
virtual int number (void) const
 Return number of points in spectrum. More...
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print spectrum. More...
 
void read (const GFits &file, const std::string &extname)
 Read spectrum from FITS file. More...
 
void read (const GFits &file, const int &extno)
 Read spectrum from FITS file. More...
 
const std::string & telescope (void) const
 Return telescope name. More...
 
const std::string & instrument (void) const
 Return instrument name. More...
 
- Public Member Functions inherited from GEventCube
 GEventCube (void)
 Void constructor. More...
 
 GEventCube (const GEventCube &cube)
 Copy constructor. More...
 
virtual ~GEventCube (void)
 Destructor. More...
 
virtual GEventCubeoperator= (const GEventCube &cube)
 Assignment operator. More...
 
- Public Member Functions inherited from GEvents
 GEvents (void)
 Void constructor. More...
 
 GEvents (const GEvents &events)
 Copy constructor. More...
 
virtual ~GEvents (void)
 Destructor. More...
 
virtual GEventsoperator= (const GEvents &events)
 Assignment operator. More...
 
void ebounds (const GEbounds &ebounds)
 Set energy boundaries. More...
 
void gti (const GGti &gti)
 Set Good Time Intervals. More...
 
const GEboundsebounds (void) const
 Return energy boundaries. More...
 
const GGtigti (void) const
 Return Good Time Intervals. More...
 
const GTimetstart (void) const
 Return start time. More...
 
const GTimetstop (void) const
 Return stop time. More...
 
const GEnergyemin (void) const
 Return minimum energy. More...
 
const GEnergyemax (void) const
 Return maximum energy. 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 GMWLSpectrum &spec)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void set_ebounds (void)
 Set energy boundaries. More...
 
void read_fits (const GFitsTable &table)
 Read spectrum from FITS file. More...
 
GEnergy conv_energy (const double &energy, const std::string &unit)
 Convert value into energy. More...
 
double conv_flux (const GEnergy &energy, const double &flux, const std::string &unit)
 Convert value into flux. More...
 
- Protected Member Functions inherited from GEventCube
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GEventCube &cube)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
virtual void set_energies (void)
 Set energies (dummy method) More...
 
virtual void set_times (void)
 Set times (dummy method) More...
 
- Protected Member Functions inherited from GEvents
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GEvents &events)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Protected Attributes

std::string m_telescope
 Telescope name. More...
 
std::string m_instrument
 Instrument name. More...
 
std::vector< GMWLDatumm_data
 Spectral data. More...
 
- Protected Attributes inherited from GEvents
GEbounds m_ebounds
 Energy boundaries covered by events. More...
 
GGti m_gti
 Good time intervals covered by events. More...
 

Detailed Description

Multi-wavelength spectrum class interface.

This class defines a multi-wavelength spectrum and is a container for spectral points of type GMWLDatum. It derives from the abstract GEventCube base class.

Definition at line 50 of file GMWLSpectrum.hpp.

Constructor & Destructor Documentation

GMWLSpectrum::GMWLSpectrum ( void  )

Void constructor.

Creates instance of an undefined spectrum.

Definition at line 66 of file GMWLSpectrum.cpp.

References init_members().

Referenced by clone().

GMWLSpectrum::GMWLSpectrum ( const GFilename filename)
explicit

File constructor.

Parameters
[in]filenameFile name.

Creates instance from file.

Definition at line 83 of file GMWLSpectrum.cpp.

References init_members(), and load().

GMWLSpectrum::GMWLSpectrum ( const GMWLSpectrum spec)

Copy constructor.

Parameters
[in]specSpectrum.

Creates instance by copying an existing spectrum.

Definition at line 103 of file GMWLSpectrum.cpp.

References copy_members(), and init_members().

GMWLSpectrum::~GMWLSpectrum ( void  )
virtual

Destructor.

Destroy instance.

Definition at line 121 of file GMWLSpectrum.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GEventCube.

Definition at line 109 of file GMWLSpectrum.hpp.

void GMWLSpectrum::clear ( void  )
virtual
GMWLSpectrum * GMWLSpectrum::clone ( void  ) const
virtual

Clone spectrum.

Returns
Pointer to deep copy of spectrum.

Implements GEventCube.

Definition at line 242 of file GMWLSpectrum.cpp.

References GMWLSpectrum().

GEnergy GMWLSpectrum::conv_energy ( const double &  energy,
const std::string &  unit 
)
protected

Convert value into energy.

Parameters
[in]energyEnergy value.
[in]unitUnit of value.

Converts an energy value into a GEnergy object based on the specified units. The following units are supported (case insensitive): erg, keV, MeV, GeV, and TeV.

Definition at line 671 of file GMWLSpectrum.cpp.

Referenced by read_fits().

double GMWLSpectrum::conv_flux ( const GEnergy energy,
const double &  flux,
const std::string &  unit 
)
protected

Convert value into flux.

Parameters
[in]energyEnergy at which flux is given.
[in]fluxFlux value.
[in]unitUnit of value.
Exceptions
GException::invalid_argumentInvalid unit encountered.

Converts a flux value into units of ph/cm2/s/MeV based on the specified units. The following units are supported (case insensitive): ph/cm2/s/MeV, ph/s/cm2/MeV, erg/cm2/s and erg/s/cm2.

Definition at line 695 of file GMWLSpectrum.cpp.

References gammalib::erg2MeV, G_CONV_FLUX, GEnergy::MeV(), gammalib::strip_whitespace(), and gammalib::toupper().

Referenced by read_fits().

void GMWLSpectrum::copy_members ( const GMWLSpectrum spec)
protected

Copy class members.

Parameters
[in]specInstance to be copied.

Definition at line 516 of file GMWLSpectrum.cpp.

References m_data, m_instrument, and m_telescope.

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

int GMWLSpectrum::dim ( void  ) const
inlinevirtual

Return dimension of spectrum.

Returns
Dimension of spectrum (always 1).

Implements GEventCube.

Definition at line 133 of file GMWLSpectrum.hpp.

void GMWLSpectrum::free_members ( void  )
protected

Delete class members.

Definition at line 531 of file GMWLSpectrum.cpp.

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

void GMWLSpectrum::init_members ( void  )
protected

Initialise class members.

Definition at line 499 of file GMWLSpectrum.cpp.

References m_data, m_instrument, and m_telescope.

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

const std::string & GMWLSpectrum::instrument ( void  ) const
inline

Return instrument name.

Returns
Instrument name.

Definition at line 170 of file GMWLSpectrum.hpp.

References m_instrument.

Referenced by GMWLObservation::load().

void GMWLSpectrum::load ( const GFilename filename)
virtual

Load spectrum.

Parameters
[in]filenameFile name.

This method loads a spectrum from a variety of file types. The method analyses the format of the file that is presented and choses then the appropriate method to load the specific format. The following file formats are supported: FITS, TBW ...

Todo:
So far only FITS file support is implemented.

Implements GEventCube.

Definition at line 260 of file GMWLSpectrum.cpp.

References clear(), GFits::close(), GFilename::extname(), GFilename::extno(), GFilename::has_extname(), GFilename::has_extno(), and read().

Referenced by GMWLSpectrum(), and GMWLObservation::load().

int GMWLSpectrum::naxis ( const int &  axis) const
inlinevirtual

Return number of spectral bins per dimension.

Parameters
[in]axisAxis (ignored).
Returns
Number of bins in spectrum.

Implements GEventCube.

Definition at line 146 of file GMWLSpectrum.hpp.

References m_data.

int GMWLSpectrum::number ( void  ) const
virtual

Return number of points in spectrum.

Implements GEventCube.

Definition at line 413 of file GMWLSpectrum.cpp.

References size().

GMWLSpectrum & GMWLSpectrum::operator= ( const GMWLSpectrum spec)
virtual

Assignment operator.

Parameters
[in]specSpectrum.
Returns
Spectrum.

Definition at line 143 of file GMWLSpectrum.cpp.

References copy_members(), free_members(), init_members(), and GEventCube::operator=().

GMWLDatum * GMWLSpectrum::operator[] ( const int &  index)
virtual

Spectral point access operator.

Parameters
[in]indexSpectral point index [0,...,size()-1].
Exceptions
GException::out_of_rangeSpectral point index outside valid range.

Implements GEventCube.

Definition at line 175 of file GMWLSpectrum.cpp.

References G_OPERATOR, m_data, and size().

const GMWLDatum * GMWLSpectrum::operator[] ( const int &  index) const
virtual

Spectral point access operator (const version)

Parameters
[in]indexSpectral point index [0,...,size()-1].
Exceptions
GException::out_of_rangeSpectral point index outside valid range.

Implements GEventCube.

Definition at line 197 of file GMWLSpectrum.cpp.

References G_OPERATOR, m_data, and size().

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

Print spectrum.

Parameters
[in]chatterChattiness (defaults to NORMAL).
Returns
String containing spectrum

Implements GEventCube.

Definition at line 426 of file GMWLSpectrum.cpp.

References GEvents::emax(), GEvents::emin(), EXPLICIT, m_data, GEvents::m_ebounds, GEvents::m_gti, m_instrument, m_telescope, gammalib::parformat(), SILENT, size(), GGti::size(), GEbounds::size(), gammalib::str(), GEvents::tstart(), and GEvents::tstop().

void GMWLSpectrum::read ( const GFits file)
virtual

Read spectrum from FITS file.

Parameters
[in]fileFITS file.

Read spectrum from first extension in FITS file.

Implements GEventCube.

Definition at line 310 of file GMWLSpectrum.cpp.

References clear().

Referenced by load().

void GMWLSpectrum::read ( const GFits fits,
const std::string &  extname 
)

Read spectrum from FITS file.

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

Definition at line 329 of file GMWLSpectrum.cpp.

References clear(), read_fits(), and GFits::table().

void GMWLSpectrum::read ( const GFits fits,
const int &  extno 
)

Read spectrum from FITS file.

Parameters
[in]fitsFITS file.
[in]extnoExtension number of spectrum.
Exceptions
GException::invalid_argumentNo table found in FITS file.

Read the spectrum from a FITS table found in the specified extension. In no extension number if specified (or if extno=0) then the spectrum is loaded from the first table extension that is found in the file.

Definition at line 358 of file GMWLSpectrum.cpp.

References GFits::at(), clear(), GFitsHDU::exttype(), GFits::filename(), G_READ, GFitsHDU::HT_ASCII_TABLE, GFitsHDU::HT_BIN_TABLE, read_fits(), GFits::size(), GFits::table(), and GFilename::url().

void GMWLSpectrum::read_fits ( const GFitsTable table)
protected

Read spectrum from FITS file.

Parameters
[in]tableFITS table.
Exceptions
GException::invalid_argumentTable does not contain at least two columns.

Read spectrum from FITS table. The table is expected to be in one of the three following formats: 2 columns: energy, flux 3 columns: energy, flux, e_flux 4 columns or more: energy, e_energy, flux, e_flux, ...

Todo:
Investigate whether we can exploit UCDs for identifying the correct columns or for determining the units.

Definition at line 584 of file GMWLSpectrum.cpp.

References conv_energy(), conv_flux(), GFitsHDU::extname(), G_READ_FITS, GFitsHDU::has_card(), m_data, GMWLDatum::m_eng, GMWLDatum::m_eng_err, GMWLDatum::m_flux, GMWLDatum::m_flux_err, m_instrument, m_telescope, GFitsTable::ncols(), GFitsTable::nrows(), GFitsTableCol::real(), set_ebounds(), gammalib::str(), GFitsHDU::string(), and GFitsTableCol::unit().

Referenced by read().

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

Save spectrum.

Parameters
[in]filenameFile name.
[in]clobberOverwrite existing file (default: false).
Todo:
To be implemented.

Implements GEventCube.

Definition at line 295 of file GMWLSpectrum.cpp.

void GMWLSpectrum::set_ebounds ( void  )
protected

Set energy boundaries.

Definition at line 541 of file GMWLSpectrum.cpp.

References GEbounds::append(), GEbounds::clear(), GEvents::emax(), GEvents::emin(), m_data, GEvents::m_ebounds, and size().

Referenced by read_fits().

int GMWLSpectrum::size ( void  ) const
inlinevirtual

Return number of spectral bins.

Returns
Number of bins in spectrum.

Implements GEventCube.

Definition at line 121 of file GMWLSpectrum.hpp.

References m_data.

Referenced by number(), operator[](), print(), and set_ebounds().

const std::string & GMWLSpectrum::telescope ( void  ) const
inline

Return telescope name.

Returns
Telescope name.

Definition at line 158 of file GMWLSpectrum.hpp.

References m_telescope.

void GMWLSpectrum::write ( GFits file) const
virtual

Write spectrum into FITS file.

Parameters
[in]fileFITS file.
Todo:
To be implemented.

Implements GEventCube.

Definition at line 403 of file GMWLSpectrum.cpp.

Member Data Documentation

std::vector<GMWLDatum> GMWLSpectrum::m_data
protected

Spectral data.

Definition at line 99 of file GMWLSpectrum.hpp.

Referenced by copy_members(), init_members(), naxis(), operator[](), print(), read_fits(), set_ebounds(), and size().

std::string GMWLSpectrum::m_instrument
protected

Instrument name.

Definition at line 98 of file GMWLSpectrum.hpp.

Referenced by copy_members(), init_members(), instrument(), print(), and read_fits().

std::string GMWLSpectrum::m_telescope
protected

Telescope name.

Definition at line 97 of file GMWLSpectrum.hpp.

Referenced by copy_members(), init_members(), print(), read_fits(), and telescope().


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