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()) {
553 const double&
GPha::at(
const int& index,
const int& col)
const
556 if (index < 0 || index >=
size()) {
559 if (col < 0 || col >=
columns()) {
574 void 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) {
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) {
const int & ncols(void) const
Return number of columns in table.
const double & exposure(void) const
Return exposure time.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
const std::string & ancrfile(void) const
Return Ancilliary Response File name.
bool contains(const int &extno) const
Check if HDU exists in FITS file.
bool has_card(const int &cardno) const
Check existence of header card.
GPha * clone(void) const
Clone object.
void append(const std::string &name, const std::vector< double > &column)
Append additional column to spectrum.
virtual ~GPha(void)
Destructor.
Energy value class definition.
double m_overflow
Number of overflowing events.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
int size(void) const
Return number of energy boundaries.
double m_exposure
Deadtime corr. exp. time (sec)
const GEbounds & ebounds(void) const
Return energy boundaries.
double m_underflow
Number of underflowing events.
double counts(void) const
Number of counts in spectrum.
void nrows(const int &nrows)
Set number of rows in column.
GNdarray counts_spectrum(void) const
Get number of counts in spectrum as GNdarray.
GFilename m_filename
Filename of origin.
GFitsTableCol * append(const GFitsTableCol &column)
Append column to the table.
void backscal(const int &index, const double &backscal)
Set background scaling factor.
double MeV(void) const
Return energy in MeV.
std::vector< double > m_areascal
Area scaling.
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
FITS table float column class interface definition.
GPha & operator*=(const double &scale)
Scale spectrum values.
const GFitsHeader & header(void) const
Return extension header.
FITS file class interface definition.
void fill(const GEnergy &energy, const double &value=1.0)
Fill spectrum with a value.
void init_members(void)
Initialise class members.
void write(GFits &file, const std::string &extname=gammalib::extname_ebounds, const std::string &unit="keV") const
Write energy boundaries into FITS object.
void load(const GFilename &filename)
Load Pulse Height Analyzer spectrum.
int index(const GEnergy &eng) const
Returns energy bin index for a given energy.
void saveto(const GFilename &filename, const bool &clobber=false)
Saves to specified FITS file.
double m_outflow
Number of outflowing events.
double real(const std::string &keyname) const
Return card value as double precision.
GEbounds m_ebounds
Energy boundaries.
XSPEC Pulse Height Analyzer class definition.
int column_index(const std::string &colname) const
Returns index of additional vector column.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
std::vector< std::vector< double > > m_coldata
Additional column data.
Energy boundaries container class.
void remove(const int &extno)
Remove HDU from FITS file.
const std::string & corrfile(void) const
Return correction file name.
std::string m_respfile
RMF file.
const std::string & respfile(void) const
Return Redistribution Matrix File name.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
N-dimensional array class interface definition.
std::string m_corrfile
Correction file.
GPha & operator=(const GPha &pha)
Assignment operator.
const GEnergy & emin(void) const
Return minimum energy of all intervals.
Abstract interface for FITS table column.
double & operator[](const int &index)
Return content of spectral bin.
void free_members(void)
Delete class members.
const std::string extname_ebounds
Abstract interface for FITS table.
N-dimensional array class.
const std::string & extname(void) const
Return extension name.
const std::string extname_pha
void clear(void)
Clear energy boundaries.
void clear(void)
Clear object.
GPha & operator/=(const double &scale)
Divide spectrum values.
const std::string & backfile(void) const
Return background file name.
GPha & operator+=(const GPha &pha)
Add spectrum.
void write(GFits &fits) const
Write Pulse Height Analyzer spectrum.
void save(const GFilename &filename, const bool &clobber=false) const
Save Pulse Height Analyzer spectrum.
std::vector< double > m_counts
Counts data.
std::string m_backfile
Background file.
GEnergy m_emin_obs
Minimum energy of observation.
std::string url(void) const
Return Uniform Resource Locator (URL)
void clear(void)
Clear file name.
void copy_members(const GPha &pha)
Copy class members.
virtual double real(const int &row, const int &inx=0) const =0
std::string print(const GChatter &chatter=NORMAL) const
Print Pulse Height Analyzer spectrum.
int size(void) const
Return number of bins in spectrum.
void read(const GFits &fits)
Read Pulse Height Analyzer spectrum.
GPha(void)
Void constructor.
std::string string(const std::string &keyname) const
Return card value as string.
Exception handler interface definition.
GFitsHDU * append(const GFitsHDU &hdu)
Append HDU to FITS file.
GFitsHeader m_header
FITS header cards.
FITS binary table class definition.
std::string tolower(const std::string &s)
Convert string to lower case.
FITS table short integer column class interface definition.
double & at(const int &index)
Return content of spectral bin.
void areascal(const int &index, const double &areascal)
Set area scaling factor.
void alloc(const int &size)
Allocate spectrum.
FITS table short integer column.
const GEnergy & emax(void) const
Return maximum energy of all intervals.
std::string m_ancrfile
ARF file.
std::vector< std::string > m_colnames
Additional column names.
std::vector< double > m_backscal
Background scaling.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
int columns(void) const
Return number of additional columns.
Pulse Height Analyzer class.
GFitsHeaderCard & card(const int &cardno)
Return header card.
GNdarray backscal_spectrum(void) const
Get background scaling factors as GNdarray.
GPha & operator-=(const GPha &pha)
Subtract spectrum.
void clear(void)
Clear instance.
GEnergy m_emax_obs
Minimum energy of observation.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
FITS table abstract base class interface definition.