43#define G_OPERATOR_PLUS "GPha::operator+=(GPha&)"
44#define G_OPERATOR_MINUS "GPha::operator-=(GPha&)"
45#define G_OPERATOR "GPha::operator[](std::string&)"
46#define G_AT1 "GPha::at(int&)"
47#define G_AT2 "GPha::at(int&, int&)"
48#define G_APPEND "GPha::append(std::string&, std::vector<double>&)"
49#define G_AREASCAL_SET "GPha::areascal(int&, double&)"
50#define G_AREASCAL_GET "GPha::areascal(int&)"
51#define G_BACKSCAL_SET "GPha::backscal(int&, double&)"
52#define G_BACKSCAL_GET "GPha::backscal(int&)"
53#define G_READ "GPha::read(GFitsTable*)"
235 std::string msg =
"Incompatible energy binning of Pulse Height "
236 "Analyzer spectrum.";
241 for (
int i = 0; i < this->
size(); ++i) {
248 double f1 = (a1 > 0.0) ? n1/a1 : 0.0;
249 double f2 = (a2 > 0.0) ? n2/a2 : 0.0;
301 std::string msg =
"Incompatible energy binning of Pulse Height "
302 "Analyzer spectrum.";
307 for (
int i = 0; i < this->
size(); ++i) {
314 double f1 = (a1 > 0.0) ? n1/a1 : 0.0;
315 double f2 = (a2 > 0.0) ? n2/a2 : 0.0;
346 for (
int i = 0; i < this->
size(); ++i) {
372 for (
int i = 0; i < this->
size(); ++i) {
401 std::string msg =
"Could not find additional column with name \""+
426 std::string msg =
"Could not find additional column with name \""+
468 return new GPha(*
this);
485 if (index < 0 || index >=
size()) {
507 if (index < 0 || index >=
size()) {
530 if (index < 0 || index >=
size()) {
533 if (col < 0 || col >=
columns()) {
553const double&
GPha::at(
const int& index,
const int& col)
const
556 if (index < 0 || index >=
size()) {
559 if (col < 0 || col >=
columns()) {
574void GPha::append(
const std::string& name,
const std::vector<double>& column)
578 if (column.size() !=
size()) {
579 std::string msg =
"Size of column "+
gammalib::str(column.size())+
580 " is incompatible with size of spectrum "+
610 if (index < 0 || index >=
size()) {
637 if (index < 0 || index >=
size()) {
661 if (index < 0 || index >=
size()) {
688 if (index < 0 || index >=
size()) {
709 for (
int i = 0; i <
m_counts.size(); ++i) {
731 for (
int i = 0; i <
size; ++i) {
754 for (
int i = 0; i <
size; ++i) {
928 int length = col_data->
nrows();
933 std::string msg =
"Mismatch between the "+
gammalib::str(length)+
934 " channels in the PHA file and the "+
936 "boundaries. Please correct either the energy "
937 "boundaris or the PHA file.";
946 for (
int i = 0; i < length; ++i) {
953 for (
int icol = 0; icol < table.
ncols(); ++icol) {
956 std::string colname(table[icol]->name());
957 if ((colname ==
"CHANNEL") ||
958 (colname ==
"COUNTS") ||
959 (colname ==
"STAT_ERR") ||
960 (colname ==
"SYS_ERR") ||
961 (colname ==
"QUALITY") ||
962 (colname ==
"GROUPING") ||
963 (colname ==
"AREASCAL") ||
964 (colname ==
"BACKSCAL")) {
972 std::vector<double> coldata;
973 for (
int i = 0; i < length; ++i) {
974 coldata.push_back(column->
real(i));
1046 int length =
size();
1065 for (
int i = 0; i < length; ++i) {
1068 col_stat(i) = float(std::sqrt(std::abs(
m_counts[i])));
1088 for (
int icol = 0; icol <
columns(); ++icol) {
1094 for (
int i = 0; i < length; ++i) {
1110 hdu.
card(
"TELESCOP",
"unknown",
"Telescope");
1111 hdu.
card(
"INSTRUME",
"unknown",
"Instrument");
1112 hdu.
card(
"FILTER",
"none",
"Filter");
1113 hdu.
card(
"EXPOSURE",
m_exposure,
"[s] Deadtime corrected exposure time");
1114 hdu.
card(
"BACKFILE",
backfile,
"Associated background filename");
1115 hdu.
card(
"CORRFILE",
corrfile,
"Associated correction filename");
1116 hdu.
card(
"CORRSCAL", 1.0,
"Correction scaling factor");
1117 hdu.
card(
"RESPFILE",
respfile,
"Associated RMF filename");
1118 hdu.
card(
"ANCRFILE",
ancrfile,
"Associated ARF filename");
1119 hdu.
card(
"HDUCLASS",
"OGIP",
"Format conforms to OGIP standard");
1120 hdu.
card(
"HDUCLAS1",
"SPECTRUM",
"PHA dataset");
1121 hdu.
card(
"HDUVERS",
"1.2.1",
"Version of the file format");
1122 hdu.
card(
"POISSERR",
true,
"Poisson errors to be assumed");
1123 hdu.
card(
"CHANTYPE",
"PI",
"Channel type");
1124 hdu.
card(
"DETCHANS",
size(),
"Total number of possible channels");
1128 hdu.
card(
"OVERFLOW",
m_overflow,
"Number of overflowing events");
1129 hdu.
card(
"OUTFLOW",
m_outflow,
"Number of outflowing events");
1135 (
m_header[i].keyname() ==
"TELESCOP") ||
1136 (
m_header[i].keyname() ==
"INSTRUME") ||
1137 (
m_header[i].keyname() ==
"FILTER")) {
1172 result.append(
"=== GPha ===");
1182 result.append(
" - ");
1186 result.append(
"not specified");
1193 result.append(
" - ");
1197 result.append(
"not specified");
1336 for (
int i = 0; i <
columns(); ++i) {
Energy value class definition.
Exception handler interface definition.
FITS binary table class definition.
FITS table float column class interface definition.
FITS table short integer column class interface definition.
FITS table abstract base class interface definition.
FITS file class interface definition.
N-dimensional array class interface definition.
XSPEC Pulse Height Analyzer class definition.
Energy boundaries container class.
int index(const GEnergy &eng) const
Returns energy bin index for a given energy.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
int size(void) const
Return number of energy boundaries.
void clear(void)
Clear energy boundaries.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
void write(GFits &file, const std::string &extname=gammalib::extname_ebounds, const std::string &unit="keV") const
Write energy boundaries into FITS object.
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.
void clear(void)
Clear instance.
std::string url(void) const
Return Uniform Resource Locator (URL)
void clear(void)
Clear file name.
const GFitsHeader & header(void) const
Return extension header.
bool has_card(const int &cardno) const
Check existence of header card.
const std::string & extname(void) const
Return extension name.
double real(const std::string &keyname) const
Return card value as double precision.
std::string string(const std::string &keyname) const
Return card value as string.
GFitsHeaderCard & card(const int &cardno)
Return header card.
Abstract interface for FITS table column.
virtual double real(const int &row, const int &inx=0) const =0
void nrows(const int &nrows)
Set number of rows in column.
FITS table short integer column.
Abstract interface for FITS table.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
const int & ncols(void) const
Return number of columns in table.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
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.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
N-dimensional array class.
Pulse Height Analyzer class.
virtual ~GPha(void)
Destructor.
void copy_members(const GPha &pha)
Copy class members.
const std::string & ancrfile(void) const
Return Ancilliary Response File name.
std::string print(const GChatter &chatter=NORMAL) const
Print Pulse Height Analyzer spectrum.
GPha(void)
Void constructor.
void save(const GFilename &filename, const bool &clobber=false) const
Save Pulse Height Analyzer spectrum.
void fill(const GEnergy &energy, const double &value=1.0)
Fill spectrum with a value.
void alloc(const int &size)
Allocate spectrum.
double & operator[](const int &index)
Return content of spectral bin.
std::vector< double > m_backscal
Background scaling.
void init_members(void)
Initialise class members.
GEnergy m_emax_obs
Minimum energy of observation.
GNdarray counts_spectrum(void) const
Get number of counts in spectrum as GNdarray.
std::string m_ancrfile
ARF file.
double m_outflow
Number of outflowing events.
GFitsHeader m_header
FITS header cards.
GPha & operator*=(const double &scale)
Scale spectrum values.
void free_members(void)
Delete class members.
double & at(const int &index)
Return content of spectral bin.
void read(const GFits &fits)
Read Pulse Height Analyzer spectrum.
const double & exposure(void) const
Return exposure time.
void backscal(const int &index, const double &backscal)
Set background scaling factor.
GFilename m_filename
Filename of origin.
double m_exposure
Deadtime corr. exp. time (sec)
void write(GFits &fits) const
Write Pulse Height Analyzer spectrum.
const std::string & respfile(void) const
Return Redistribution Matrix File name.
GEbounds m_ebounds
Energy boundaries.
GEnergy m_emin_obs
Minimum energy of observation.
const GFilename & filename(void) const
Return file name.
std::vector< double > m_counts
Counts data.
double m_overflow
Number of overflowing events.
double counts(void) const
Number of counts in spectrum.
int column_index(const std::string &colname) const
Returns index of additional vector column.
double m_underflow
Number of underflowing events.
GPha & operator-=(const GPha &pha)
Subtract spectrum.
int size(void) const
Return number of bins in spectrum.
std::string m_respfile
RMF file.
GPha & operator/=(const double &scale)
Divide spectrum values.
const std::string & backfile(void) const
Return background file name.
GNdarray backscal_spectrum(void) const
Get background scaling factors as GNdarray.
std::string m_corrfile
Correction file.
const std::string & corrfile(void) const
Return correction file name.
GPha * clone(void) const
Clone object.
void areascal(const int &index, const double &areascal)
Set area scaling factor.
int columns(void) const
Return number of additional columns.
std::vector< double > m_areascal
Area scaling.
std::vector< std::vector< double > > m_coldata
Additional column data.
void clear(void)
Clear object.
GPha & operator+=(const GPha &pha)
Add spectrum.
const GEbounds & ebounds(void) const
Return energy boundaries.
void load(const GFilename &filename)
Load Pulse Height Analyzer spectrum.
GPha & operator=(const GPha &pha)
Assignment operator.
std::vector< std::string > m_colnames
Additional column names.
void append(const std::string &name, const std::vector< double > &column)
Append additional column to spectrum.
std::string m_backfile
Background file.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
const std::string extname_ebounds
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
const std::string extname_pha
std::string tolower(const std::string &s)
Convert string to lower case.