43#define G_AT "GEnergies::at(int&)"
44#define G_INSERT "GEnergies::insert(int&, GEnergy&)"
45#define G_REMOVE "GEnergies::remove(int&)"
46#define G_SET "GEnergies::set(int&, GEnergy&, GEnergy&, std::string&, "\
48#define G_SET_LIN "GEnergies::set_lin(int&, GEnergy&, GEnergy&)"
49#define G_SET_LOG "GEnergies::set_log(int&, GEnergy&, GEnergy&)"
50#define G_SET_POW "GEnergies::set_pow(int&, GEnergy&, GEnergy&, double&)"
156 const std::string& method,
163 set(num, emin, emax, method, gamma);
198 if (
this != &energies) {
266 if (index < 0 || index >=
size()) {
288 if (index < 0 || index >=
size()) {
330 #if defined(G_RANGE_CHECK)
338 if (index < 0 || index >=
size()) {
366 #if defined(G_RANGE_CHECK)
367 if (index < 0 || index >=
size()) {
396 int num = energies.
size();
402 for (
int i = 0; i < num; ++i) {
427 int num = ebounds.
size();
430 for (
int i = 0; i < num; ++i) {
433 for (
int j = 0; j < 2; ++j) {
439 bool not_found =
true;
479 const std::string& method,
484 std::string msg =
"Negative number of energies "+
gammalib::str(num)+
485 " specified. Please specify a non-negative number "
492 std::string msg =
"Minimum energy "+emin.
print()+
" is larger than "
493 "maximum energy "+emax.
print()+
". Please specify "
494 "a minimum energy that does not exceed the "
504 std::string msg =
"Single energy is requested but the minimum "
505 "energy "+emin.
print()+
" differs from the "
506 "maximum energy "+emax.
print()+
". Please "
507 "specify identical energies.";
517 if (umethod ==
"LIN") {
520 else if (umethod ==
"LOG") {
523 else if (umethod ==
"POW") {
524 set_pow(num, emin, emax, gamma);
527 std::string msg =
"Invalid energy spacing method \""+umethod+
"\" "
528 "specified. Please provide one of \"LIN\", \"LOG\""
551 GFits fits(filename);
624 int num = table.
integer(
"NAXIS2");
631 std::string unit =
"MeV";
633 unit = table.
string(
"TUNIT1");
640 for (
int i = 0; i < num; ++i) {
668 for (
int i = 0; i < num; ++i) {
669 col_energy(i) = (*this)[i].MeV();
671 col_energy.
unit(
"MeV");
707 result.append(
"=== GEnergies ===");
715 for (
int i = 0; i <
size(); ++i) {
807 GEnergy ebin = (emax - emin)/
double(num-1);
811 for (
int i = 0; i < num; ++i) {
853 if (emin.
MeV() <= 0.0) {
854 std::string msg =
"Non-positive minimum energy "+emin.
print()+
855 " specified. Please provide a positive minimum "
859 if (emax.
MeV() <= 0.0) {
860 std::string msg =
"Non-positive maximum energy "+emax.
print()+
861 " specified. Please provide a positive minimum "
875 double elogmin = std::log10(emin.
MeV());
876 double elogmax = std::log10(emax.
MeV());
877 double elogbin = (elogmax - elogmin)/
double(num-1);
881 for (
int i = 0; i < num; ++i) {
882 energy.
MeV(std::pow(10.0,
double(i)*elogbin + elogmin));
935 if (emin.
MeV() <= 0.0) {
936 std::string msg =
"Non-positive minimum energy "+emin.
print()+
937 " specified. Please provide a positive minimum "
941 if (emax.
MeV() <= 0.0) {
942 std::string msg =
"Non-positive maximum energy "+emax.
print()+
943 " specified. Please provide a positive minimum "
960 double a = 1.0 - gamma;
961 double c = (a == 0.0) ? 1.0 / (std::log(emax.
MeV()) - std::log(emin.
MeV()))
962 : a / (std::pow(emax.
MeV(),a) - std::pow(emin.
MeV(),a));
963 double b = double(c*(num-1.0));
966 double e = emin.
MeV();
969 for (
int i = 0; i < num-1; ++i) {
972 double log_e_next = (a == 0.0)
973 ? 1.0/b + std::log(e)
974 : std::log(a/b + std::pow(e,a)) / a;
975 double e_next = std::exp(log_e_next);
Energy boundaries class interface definition.
Energy container class definition.
Exception handler interface definition.
Filename class interface definition.
FITS binary table class definition.
FITS table column abstract base class definition.
FITS table double column class interface definition.
FITS table abstract base class interface definition.
FITS file class interface definition.
Energy boundaries container class.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
int size(void) const
Return number of energy boundaries.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
std::string print(const GChatter &chatter=NORMAL) const
Print energy container information.
void init_members(void)
Initialise class members.
void read(const GFitsTable &table)
Read energies from FITS table.
void load(const GFilename &filename)
Load energies from FITS file.
GEnergies & operator=(const GEnergies &energies)
Assignment operator.
GEnergies(void)
Void constructor.
void clear(void)
Clear energy container.
int size(void) const
Return number of energies in container.
void set_pow(const int &num, const GEnergy &emin, const GEnergy &emax, const double &gamma)
Set power-law spaced energy intervals.
void copy_members(const GEnergies &energies)
Copy class members.
GEnergy & at(const int &index)
Return reference to energy.
void set(const GEbounds &ebounds)
Set energies from energy boundaries.
void reserve(const int &num)
Reserves space for energies in container.
void extend(const GEnergies &energies)
Append energy container.
GEnergies * clone(void) const
Clone energy container.
GEnergy & append(const GEnergy &energy)
Append energy to container.
void save(const GFilename &filename, const bool &clobber=false) const
Save energies into FITS file.
virtual ~GEnergies(void)
Destructor.
void write(GFits &file, const std::string &extname=gammalib::extname_energies) const
Write energies into FITS object.
void set_lin(const int &num, const GEnergy &emin, const GEnergy &emax)
Set linearly spaced energies.
void remove(const int &index)
Remove energy from container.
bool is_empty(void) const
Signals if there are no energies in container.
void set_log(const int &num, const GEnergy &emin, const GEnergy &emax)
Set logarithmically spaced energies.
GEnergy & insert(const int &index, const GEnergy &energy)
Insert energy into container.
void free_members(void)
Delete class members.
std::vector< GEnergy > m_energies
List of energies.
Class that handles energies in a unit independent way.
double MeV(void) const
Return energy in MeV.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
std::string url(void) const
Return Uniform Resource Locator (URL)
std::string extname(const std::string &defaultname="") const
Return extension name.
bool has_card(const int &cardno) const
Check existence of header card.
const std::string & extname(void) const
Return extension name.
std::string string(const std::string &keyname) const
Return card value as string.
int integer(const std::string &keyname) const
Return card value as integer.
Abstract interface for FITS table column.
virtual double real(const int &row, const int &inx=0) const =0
void unit(const std::string &unit)
Set column unit.
FITS table double column.
Abstract interface for FITS table.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
bool contains(const int &extno) const
Check if HDU exists in FITS file.
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
void close(void)
Close FITS file.
void remove(const int &extno)
Remove HDU from FITS file.
void save(const bool &clobber=false)
Saves FITS file.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
std::string toupper(const std::string &s)
Convert string to upper case.
const std::string extname_energies