GammaLib
2.0.0
|
CTA 2D background class. More...
#include <GCTABackground2D.hpp>
Public Member Functions | |
GCTABackground2D (void) | |
Void constructor. More... | |
GCTABackground2D (const GFilename &filename) | |
File constructor. More... | |
GCTABackground2D (const GCTABackground2D &bgd) | |
Copy constructor. More... | |
virtual | ~GCTABackground2D (void) |
Destructor. More... | |
virtual double | operator() (const double &logE, const double &detx, const double &dety) const |
Return background rate in units of events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\). More... | |
GCTABackground2D & | operator= (const GCTABackground2D &bgd) |
Assignment operator. More... | |
void | clear (void) |
Clear background. More... | |
GCTABackground2D * | clone (void) const |
Clone background. More... | |
std::string | classname (void) const |
Return class name. More... | |
void | load (const GFilename &filename) |
Load background from FITS file. More... | |
GFilename | filename (void) const |
Return filename. More... | |
GCTAInstDir | mc (const GEnergy &energy, const GTime &time, GRan &ran) const |
Returns MC instrument direction. More... | |
const GModelSpectralNodes & | spectrum (void) const |
Get response cube spectrum. More... | |
double | rate_ebin (const GCTAInstDir &dir, const GEnergy &emin, const GEnergy &emax) const |
Returns background rate integrated over energy interval in units of events s \(^{-1}\) sr \(^{-1}\). More... | |
std::string | print (const GChatter &chatter=NORMAL) const |
Print background information. More... | |
bool | is_valid (void) const |
Return validity of background model. More... | |
const GCTAResponseTable & | table (void) const |
Return response table. More... | |
void | table (const GCTAResponseTable &table) |
Assign response table. More... | |
void | read (const GFitsTable &table) |
Read background from FITS table. More... | |
void | write (GFitsBinTable &table) const |
Write background into FITS table. More... | |
void | save (const GFilename &filename, const bool &clobber=false) const |
Save background into FITS file. More... | |
Public Member Functions inherited from GCTABackground | |
GCTABackground (void) | |
Void constructor. More... | |
GCTABackground (const GCTABackground &bgd) | |
Copy constructor. More... | |
virtual | ~GCTABackground (void) |
Destructor. More... | |
GCTABackground & | operator= (const GCTABackground &bgd) |
Assignment operator. More... | |
Public Member Functions inherited from GBase | |
virtual | ~GBase (void) |
Destructor. More... | |
Private Member Functions | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GCTABackground2D &bgd) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_members (void) |
Set members from background table. More... | |
int | index (const int &itheta, const int &iebin) const |
Return background rate bin index. More... | |
void | init_mc_cache (void) const |
Initialise Monte Carlo cache. More... | |
void | init_mc_max_rate (void) const |
Initialise array of maximum background rate. More... | |
double | solid_angle (const double &detx1, const double &dety1, const double &detx2, const double &dety2, const double &detx3, const double &dety3) const |
Compute solid angle of pixel wedge. More... | |
double | rate (const int &iebin, const double &theta) const |
Return background rate for a given energy bin and offset angle value (events/s/MeV/sr) More... | |
Private Attributes | |
GFilename | m_filename |
Name of background response file. More... | |
GCTAResponseTable | m_background |
Background response table. More... | |
GEnergies | m_energy |
Vector of energies. More... | |
int | m_inx_theta |
THETA axis index. More... | |
int | m_inx_energy |
Energy axis index. More... | |
int | m_inx_bgd |
Background index. More... | |
int | m_num_theta |
Number of THETA bins. More... | |
int | m_num_energy |
Number of energy bins. More... | |
int | m_num [2] |
Array of number of bins. More... | |
double | m_theta_min |
THETA minimum (radians) More... | |
double | m_theta_max |
THETA maximum (radians) More... | |
double | m_logE_min |
Log10(E/TeV) minimum. More... | |
double | m_logE_max |
Log10(E/TeV) maximum. More... | |
std::vector< double > | m_mc_max |
Maximum background rate. More... | |
GModelSpectralNodes | m_mc_spectrum |
Response cube spectrum. More... | |
Additional Inherited Members | |
Protected Member Functions inherited from GCTABackground | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GCTABackground &bgd) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
CTA 2D background class.
Definition at line 53 of file GCTABackground2D.hpp.
GCTABackground2D::GCTABackground2D | ( | void | ) |
Void constructor.
Constructs empty background.
Definition at line 69 of file GCTABackground2D.cpp.
References init_members().
Referenced by clone().
|
explicit |
File constructor.
[in] | filename | FITS file name. |
Constructs background from a FITS file.
Definition at line 86 of file GCTABackground2D.cpp.
References init_members(), and load().
GCTABackground2D::GCTABackground2D | ( | const GCTABackground2D & | bgd | ) |
Copy constructor.
[in] | bgd | Background. |
Constructs background by copying from another background.
Definition at line 107 of file GCTABackground2D.cpp.
References copy_members(), and init_members().
|
virtual |
Destructor.
Destructs background.
Definition at line 126 of file GCTABackground2D.cpp.
References free_members().
|
inlinevirtual |
Return class name.
Implements GCTABackground.
Definition at line 135 of file GCTABackground2D.hpp.
|
virtual |
Clear background.
Clears background.
Implements GCTABackground.
Definition at line 255 of file GCTABackground2D.cpp.
References GCTABackground::free_members(), free_members(), GCTABackground::init_members(), and init_members().
|
virtual |
Clone background.
Returns a pointer to a deep copy of the background.
Implements GCTABackground.
Definition at line 277 of file GCTABackground2D.cpp.
References GCTABackground2D().
|
private |
Copy class members.
[in] | bgd | Background. |
Definition at line 753 of file GCTABackground2D.cpp.
References m_background, m_energy, m_filename, m_inx_bgd, m_inx_energy, m_inx_theta, m_logE_max, m_logE_min, m_mc_max, m_mc_spectrum, m_num, m_num_energy, m_num_theta, m_theta_max, and m_theta_min.
Referenced by GCTABackground2D(), and operator=().
|
inlinevirtual |
Return filename.
Implements GCTABackground.
Definition at line 147 of file GCTABackground2D.hpp.
References m_filename.
Referenced by load().
|
private |
Delete class members.
Definition at line 783 of file GCTABackground2D.cpp.
Referenced by clear(), operator=(), and ~GCTABackground2D().
|
private |
Return background rate bin index.
[in] | itheta | THETA index. |
[in] | iebin | Energy index. |
Returns the background rate bin index independent of the ordering.
Definition at line 869 of file GCTABackground2D.cpp.
References m_inx_energy, m_inx_theta, and m_num.
Referenced by init_mc_max_rate(), and rate().
|
private |
Initialise Monte Carlo cache.
GException::invalid_value | Background response table was empty. |
Initialises the cache for Monte Carlo sampling.
Definition at line 893 of file GCTABackground2D.cpp.
References GModelSpectralNodes::append(), GCTAResponseTable::axis_hi(), GCTAResponseTable::axis_hi_unit(), GCTAResponseTable::axis_lo(), GCTAResponseTable::axis_lo_unit(), GModelSpectralNodes::clear(), GEnergies::extend(), G_INIT_MC_CACHE, init_mc_max_rate(), m_background, m_energy, m_inx_energy, m_mc_max, m_mc_spectrum, m_num_energy, m_num_theta, m_theta_max, GModelSpectralNodes::nodes(), GEnergies::remove(), GEnergies::size(), and solid_angle().
Referenced by mc(), and spectrum().
|
private |
Initialise array of maximum background rate.
Initialises the array m_mc_max that holds the maximum background rate for each energy of the background model.
Definition at line 1036 of file GCTABackground2D.cpp.
References index(), m_background, m_inx_bgd, m_mc_max, m_num_energy, m_num_theta, and rate().
Referenced by init_mc_cache().
|
private |
Initialise class members.
Definition at line 721 of file GCTABackground2D.cpp.
References GCTAResponseTable::clear(), GEnergies::clear(), GFilename::clear(), GModelSpectralNodes::clear(), m_background, m_energy, m_filename, m_inx_bgd, m_inx_energy, m_inx_theta, m_logE_max, m_logE_min, m_mc_max, m_mc_spectrum, m_num, m_num_energy, m_num_theta, m_theta_max, and m_theta_min.
Referenced by clear(), GCTABackground2D(), and operator=().
|
inline |
Return validity of background model.
Definition at line 177 of file GCTABackground2D.hpp.
References GCTAResponseTable::axes(), and m_background.
Referenced by operator()(), print(), and rate_ebin().
|
virtual |
Load background from FITS file.
[in] | filename | FITS file name. |
Loads the background from a FITS file.
If no extension name is given the method scans the HDUCLASS
keywords of all extensions and loads the background from the first extension for which HDUCLAS4=BKG_2D
.
Otherwise, the background will be loaded from the BKG
extension.
Implements GCTABackground.
Definition at line 368 of file GCTABackground2D.cpp.
References GFits::close(), GFilename::extname(), gammalib::extname_cta_background2d, filename(), gammalib::gadf_hduclas4(), m_filename, read(), table(), and GFits::table().
Referenced by GCTABackground2D().
|
virtual |
Returns MC instrument direction.
[in] | energy | Event energy. |
[in] | time | Event trigger time. |
[in,out] | ran | Random number generator. |
Returns a Monte Carlo simulated instrument direction for a given energy
and event trigger time
. The simulation is done using a rejection method that makes use of the background rate access operator. This assures that the simulation is consistent with the background rate interpolation that is done by the access operator.
Implements GCTABackground.
Definition at line 461 of file GCTABackground2D.cpp.
References GCTAResponseTable::axis_nodes(), GCTAInstDir::detx(), GCTAInstDir::dety(), GModelSpectralNodes::energy(), G_MC, init_mc_cache(), GNodeArray::inx_left(), GNodeArray::inx_right(), GEnergy::log10TeV(), m_background, m_inx_energy, m_mc_max, m_mc_spectrum, m_theta_max, GModelSpectralNodes::nodes(), operator()(), GEnergy::print(), gammalib::rad2deg, GNodeArray::set_value(), gammalib::str(), GRan::uniform(), and gammalib::warning().
|
virtual |
Return background rate in units of events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\).
[in] | logE | Log10 of the true photon energy (TeV). |
[in] | detx | Tangential X coordinate in nominal system (radians). |
[in] | dety | Tangential Y coordinate in nominal system (radians). |
Returns the background rate for a given energy and detector coordinates. The rate is given per ontime. The operator computes the offset angle
\[\theta = \sqrt{ {\rm DETX}^2 + {\rm DETY}^2 }\]
and interpolates linearly in \(\theta\) and logarithmically in energy.
The operator assures that the background rate never becomes negative. For invalid background models or detector coordinates outside the range covered by the response cube, the operator returns a rate of zero.
Implements GCTABackground.
Definition at line 194 of file GCTABackground2D.cpp.
References GCTAResponseTable::axis_nodes(), exp(), GNodeArray::inx_left(), GNodeArray::inx_right(), is_valid(), log(), m_background, m_inx_energy, m_theta_max, m_theta_min, rate(), GNodeArray::set_value(), sqrt(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
Referenced by mc().
GCTABackground2D & GCTABackground2D::operator= | ( | const GCTABackground2D & | bgd | ) |
Assignment operator.
[in] | bgd | Background. |
Assigns background.
Definition at line 150 of file GCTABackground2D.cpp.
References copy_members(), free_members(), init_members(), and GCTABackground::operator=().
Print background information.
[in] | chatter | Chattiness. |
Implements GCTABackground.
Definition at line 660 of file GCTABackground2D.cpp.
References GCTAResponseTable::axis_hi(), GCTAResponseTable::axis_lo(), is_valid(), m_background, m_filename, m_inx_energy, m_inx_theta, m_num_energy, m_num_theta, gammalib::parformat(), SILENT, and gammalib::str().
|
private |
Return background rate for a given energy bin and offset angle value (events/s/MeV/sr)
[in] | iebin | Energy index. |
[in] | theta | Offset angle in nominal system (radians). |
Definition at line 1149 of file GCTABackground2D.cpp.
References GCTAResponseTable::axis_nodes(), index(), GNodeArray::inx_left(), GNodeArray::inx_right(), m_background, m_inx_bgd, m_inx_theta, GNodeArray::set_value(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
Referenced by init_mc_max_rate(), operator()(), and rate_ebin().
|
virtual |
Returns background rate integrated over energy interval in units of events s \(^{-1}\) sr \(^{-1}\).
[in] | dir | Instrument direction. |
[in] | emin | Minimum energy of energy interval. |
[in] | emax | Maximum energy of energy interval. |
Returns the background count rate for a given instrument direction that is integrated over a specified energy interval. The rate is given per ontime.
If the energy interval is not positive, a zero background rate is returned.
Implements GCTABackground.
Definition at line 576 of file GCTABackground2D.cpp.
References GCTAInstDir::detx(), GCTAInstDir::dety(), is_valid(), GEnergy::log10TeV(), m_energy, m_theta_max, m_theta_min, GEnergy::MeV(), gammalib::plaw_integral(), rate(), GEnergies::size(), and sqrt().
void GCTABackground2D::read | ( | const GFitsTable & | table | ) |
Read background from FITS table.
[in] | table | FITS table. |
Reads the background form the FITS table
. The following column names are mandatory:
THETA_LO - THETA lower bin boundaries THETA_HI - THETA upper bin boundaries ENERG_LO - Energy lower bin boundaries ENERG_HI - Energy upper bin boundaries BKG - Background template
The data are stored in the m_background member. The THETA
axis will be set to radians, the energy axis will be set to log10. The data are expected to be given in unit of events per MeV, second and steradian, where the time is the real ontime.
This method ignores all column names that are not the mandatory column names in the FITS table
.
Definition at line 305 of file GCTABackground2D.cpp.
References GCTAResponseTable::clear(), GFitsTable::clone(), m_background, GFitsTable::ncols(), GCTAResponseTable::read(), GFitsTable::remove(), and set_members().
Referenced by load().
void GCTABackground2D::save | ( | const GFilename & | filename, |
const bool & | clobber = false |
||
) | const |
Save background into FITS file.
[in] | filename | Background table FITS file name. |
[in] | clobber | Overwrite existing file? |
Saves background 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. The method will create a (or replace an existing) background extension. The extension name can be specified as part of the filename
, or if no extension name is given, is assumed to be BKG
.
An existing file will only be modified if the clobber
flag is set to true.
Definition at line 413 of file GCTABackground2D.cpp.
References GFitsHDU::extname(), GFilename::extname(), gammalib::extname_cta_background2d, GFits::remove(), table(), GFilename::url(), and write().
|
private |
Set members from background table.
GException::invalid_value | Response table is not three-dimensional. |
Set class members based on the background table. The THETA axis will be set to radians, the energy axis will be set to log10.
Definition at line 799 of file GCTABackground2D.cpp.
References GEnergies::append(), GCTAResponseTable::axes(), GCTAResponseTable::axis(), GCTAResponseTable::axis_bins(), GCTAResponseTable::axis_hi(), GCTAResponseTable::axis_hi_unit(), GCTAResponseTable::axis_lo(), GCTAResponseTable::axis_lo_unit(), GCTAResponseTable::axis_log10(), GCTAResponseTable::axis_radians(), GEnergies::clear(), gammalib::deg2rad, G_SET_MEMBERS, m_background, m_energy, m_inx_bgd, m_inx_energy, m_inx_theta, m_logE_max, m_logE_min, m_num, m_num_energy, m_num_theta, m_theta_max, m_theta_min, sqrt(), gammalib::str(), and GCTAResponseTable::table().
|
private |
Compute solid angle of pixel wedge.
[in] | detx1 | DETX of first edge. |
[in] | dety1 | DETY of first edge. |
[in] | detx2 | DETX of second edge. |
[in] | dety2 | DETY of second edge. |
[in] | detx3 | DETX of third edge. |
[in] | dety3 | DETY of third edge. |
Estimate the solid angle subtended by 3 coordinates using Huilier's theorem.
Below, the definiton of the pixel cornes and sides are shown as used within the code.
a12 1---------2 | / | / | / | / a13| /a23 | / | / | / |/
Definition at line 1106 of file GCTABackground2D.cpp.
References atan(), gammalib::atan2(), GSkyDir::dist(), gammalib::pihalf, GSkyDir::radec(), sqrt(), and tan().
Referenced by init_mc_cache().
|
inlinevirtual |
Get response cube spectrum.
Returns the response cube spectrum.
Implements GCTABackground.
Definition at line 162 of file GCTABackground2D.hpp.
References init_mc_cache(), m_mc_spectrum, and GModelSpectralNodes::nodes().
|
inline |
Return response table.
Definition at line 189 of file GCTABackground2D.hpp.
References m_background.
|
inline |
Assign response table.
[in] | table | Response table. |
Definition at line 201 of file GCTABackground2D.hpp.
References m_background, set_members(), and table().
void GCTABackground2D::write | ( | GFitsBinTable & | table | ) | const |
Write background into FITS table.
[in] | table | FITS binary table. |
Writes background into a FITS binary table
.
Definition at line 345 of file GCTABackground2D.cpp.
References m_background, and GCTAResponseTable::write().
Referenced by save().
|
private |
Background response table.
Definition at line 110 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), is_valid(), mc(), operator()(), print(), rate(), read(), set_members(), table(), and write().
|
private |
Vector of energies.
Definition at line 111 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), rate_ebin(), and set_members().
|
private |
Name of background response file.
Definition at line 109 of file GCTABackground2D.hpp.
Referenced by copy_members(), filename(), init_members(), load(), and print().
|
private |
Background index.
Definition at line 114 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_max_rate(), init_members(), rate(), and set_members().
|
private |
Energy axis index.
Definition at line 113 of file GCTABackground2D.hpp.
Referenced by copy_members(), index(), init_mc_cache(), init_members(), mc(), operator()(), print(), and set_members().
|
private |
THETA axis index.
Definition at line 112 of file GCTABackground2D.hpp.
Referenced by copy_members(), index(), init_members(), print(), rate(), and set_members().
|
private |
Log10(E/TeV) maximum.
Definition at line 121 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_members(), and set_members().
|
private |
Log10(E/TeV) minimum.
Definition at line 120 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_members(), and set_members().
|
mutableprivate |
Maximum background rate.
Definition at line 124 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), and mc().
|
mutableprivate |
Response cube spectrum.
Definition at line 125 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), and spectrum().
|
private |
Array of number of bins.
Definition at line 117 of file GCTABackground2D.hpp.
Referenced by copy_members(), index(), init_members(), and set_members().
|
private |
Number of energy bins.
Definition at line 116 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), print(), and set_members().
|
private |
Number of THETA bins.
Definition at line 115 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), print(), and set_members().
|
private |
THETA maximum (radians)
Definition at line 119 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), operator()(), rate_ebin(), and set_members().
|
private |
THETA minimum (radians)
Definition at line 118 of file GCTABackground2D.hpp.
Referenced by copy_members(), init_members(), operator()(), rate_ebin(), and set_members().