GammaLib
2.0.0
|
CTA 3D background class. More...
#include <GCTABackground3D.hpp>
Public Member Functions | |
GCTABackground3D (void) | |
Void constructor. More... | |
GCTABackground3D (const GFilename &filename) | |
File constructor. More... | |
GCTABackground3D (const GCTABackground3D &bgd) | |
Copy constructor. More... | |
virtual | ~GCTABackground3D (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... | |
GCTABackground3D & | operator= (const GCTABackground3D &bgd) |
Assignment operator. More... | |
void | clear (void) |
Clear background. More... | |
GCTABackground3D * | 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 GCTABackground3D &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 &idetx, const int &idety, 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 &detx, const double &dety) const |
Return background rate for a given energy bin and DETX-DETY 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_detx |
DETX index. More... | |
int | m_inx_dety |
DETY index. More... | |
int | m_inx_energy |
Energy index. More... | |
int | m_inx_bgd |
Background index. More... | |
int | m_num_detx |
Number of DETX bins. More... | |
int | m_num_dety |
Number of DETY bins. More... | |
int | m_num_energy |
Number of energy bins. More... | |
int | m_num [3] |
Array of number of bins. More... | |
double | m_detx_min |
DETX minimum (radians) More... | |
double | m_detx_max |
DETX maximum (radians) More... | |
double | m_dety_min |
DETY minimum (radians) More... | |
double | m_dety_max |
DETY 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 3D background class.
Definition at line 53 of file GCTABackground3D.hpp.
GCTABackground3D::GCTABackground3D | ( | void | ) |
Void constructor.
Constructs empty background.
Definition at line 69 of file GCTABackground3D.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 GCTABackground3D.cpp.
References init_members(), and load().
GCTABackground3D::GCTABackground3D | ( | const GCTABackground3D & | bgd | ) |
Copy constructor.
[in] | bgd | Background. |
Constructs background by copying from another background.
Definition at line 107 of file GCTABackground3D.cpp.
References copy_members(), and init_members().
|
virtual |
Destructor.
Destructs background.
Definition at line 126 of file GCTABackground3D.cpp.
References free_members().
|
inlinevirtual |
Return class name.
Implements GCTABackground.
Definition at line 139 of file GCTABackground3D.hpp.
|
virtual |
Clear background.
Clears background.
Implements GCTABackground.
Definition at line 246 of file GCTABackground3D.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 268 of file GCTABackground3D.cpp.
References GCTABackground3D().
|
private |
Copy class members.
[in] | bgd | Background. |
Definition at line 763 of file GCTABackground3D.cpp.
References m_background, m_detx_max, m_detx_min, m_dety_max, m_dety_min, m_energy, m_filename, m_inx_bgd, m_inx_detx, m_inx_dety, m_inx_energy, m_logE_max, m_logE_min, m_mc_max, m_mc_spectrum, m_num, m_num_detx, m_num_dety, and m_num_energy.
Referenced by GCTABackground3D(), and operator=().
|
inlinevirtual |
Return filename.
Implements GCTABackground.
Definition at line 151 of file GCTABackground3D.hpp.
References m_filename.
Referenced by load().
|
private |
Delete class members.
Definition at line 798 of file GCTABackground3D.cpp.
Referenced by clear(), operator=(), and ~GCTABackground3D().
|
private |
Return background rate bin index.
[in] | idetx | DETX index. |
[in] | idety | DETY index. |
[in] | iebin | Energy index. |
Returns the background rate bin index independent of the ordering.
Definition at line 900 of file GCTABackground3D.cpp.
References m_inx_detx, m_inx_dety, m_inx_energy, 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 926 of file GCTABackground3D.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_detx_max, m_detx_min, m_dety_max, m_dety_min, m_energy, m_inx_energy, m_mc_max, m_mc_spectrum, m_num_detx, m_num_dety, m_num_energy, 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 in each DETX-DETY plane of the background model.
Definition at line 1069 of file GCTABackground3D.cpp.
References index(), m_background, m_inx_bgd, m_mc_max, m_num_detx, m_num_dety, m_num_energy, and rate().
Referenced by init_mc_cache().
|
private |
Initialise class members.
Definition at line 726 of file GCTABackground3D.cpp.
References GCTAResponseTable::clear(), GEnergies::clear(), GFilename::clear(), GModelSpectralNodes::clear(), m_background, m_detx_max, m_detx_min, m_dety_max, m_dety_min, m_energy, m_filename, m_inx_bgd, m_inx_detx, m_inx_dety, m_inx_energy, m_logE_max, m_logE_min, m_mc_max, m_mc_spectrum, m_num, m_num_detx, m_num_dety, and m_num_energy.
Referenced by clear(), GCTABackground3D(), and operator=().
|
inline |
Return validity of background model.
Definition at line 181 of file GCTABackground3D.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_3D
.
Otherwise, the background will be loaded from the BACKGROUND
extension.
Implements GCTABackground.
Definition at line 365 of file GCTABackground3D.cpp.
References GFits::close(), GFilename::extname(), gammalib::extname_cta_background3d, filename(), gammalib::gadf_hduclas4(), m_filename, read(), table(), and GFits::table().
Referenced by GCTABackground3D().
|
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 458 of file GCTABackground3D.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_detx_max, m_detx_min, m_dety_max, m_dety_min, m_inx_energy, m_mc_max, m_mc_spectrum, 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 interpolates linearly in DETX
and DETY
, 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 191 of file GCTABackground3D.cpp.
References GCTAResponseTable::axis_nodes(), exp(), GNodeArray::inx_left(), GNodeArray::inx_right(), is_valid(), log(), m_background, m_detx_max, m_detx_min, m_dety_max, m_dety_min, m_inx_energy, rate(), GNodeArray::set_value(), GNodeArray::wgt_left(), and GNodeArray::wgt_right().
Referenced by mc().
GCTABackground3D & GCTABackground3D::operator= | ( | const GCTABackground3D & | bgd | ) |
Assignment operator.
[in] | bgd | Background. |
Assigns background.
Definition at line 150 of file GCTABackground3D.cpp.
References copy_members(), free_members(), init_members(), and GCTABackground::operator=().
Print background information.
[in] | chatter | Chattiness. |
Implements GCTABackground.
Definition at line 655 of file GCTABackground3D.cpp.
References GCTAResponseTable::axis_hi(), GCTAResponseTable::axis_lo(), is_valid(), m_background, m_filename, m_inx_detx, m_inx_dety, m_inx_energy, m_num_detx, m_num_dety, m_num_energy, gammalib::parformat(), SILENT, and gammalib::str().
|
private |
Return background rate for a given energy bin and DETX-DETY value (events/s/MeV/sr)
[in] | iebin | Energy index. |
[in] | detx | Tangential X coordinate in nominal system (radians). |
[in] | dety | Tangential Y coordinate in nominal system (radians). |
Definition at line 1185 of file GCTABackground3D.cpp.
References GCTAResponseTable::axis_nodes(), index(), GNodeArray::inx_left(), GNodeArray::inx_right(), m_background, m_inx_bgd, m_inx_detx, m_inx_dety, 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 574 of file GCTABackground3D.cpp.
References GCTAInstDir::detx(), GCTAInstDir::dety(), is_valid(), GEnergy::log10TeV(), m_detx_max, m_detx_min, m_dety_max, m_dety_min, m_energy, GEnergy::MeV(), gammalib::plaw_integral(), rate(), and GEnergies::size().
void GCTABackground3D::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:
DETX_LO - DETX lower bin boundaries DETX_HI - DETX upper bin boundaries DETY_LO - DETY lower bin boundaries DETY_HI - DETY upper bin boundaries ENERG_LO - Energy lower bin boundaries ENERG_HI - Energy upper bin boundaries BKG - Background template (or BGD as legacy column name)
The data are stored in the m_background member. The DETX
and DETY
axes 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 298 of file GCTABackground3D.cpp.
References GCTAResponseTable::clear(), GFitsTable::clone(), m_background, GFitsTable::ncols(), GCTAResponseTable::read(), GFitsTable::remove(), and set_members().
Referenced by load().
void GCTABackground3D::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? (default: false) |
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 BACKGROUND
.
An existing file will only be modified if the clobber
flag is set to true.
Definition at line 410 of file GCTABackground3D.cpp.
References GFitsHDU::extname(), GFilename::extname(), gammalib::extname_cta_background3d, 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 DETX and DETY axes will be set to radians, the energy axis will be set to log10.
Definition at line 814 of file GCTABackground3D.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, GCTAResponseTable::has_table(), m_background, m_detx_max, m_detx_min, m_dety_max, m_dety_min, m_energy, m_inx_bgd, m_inx_detx, m_inx_dety, m_inx_energy, m_logE_max, m_logE_min, m_num, m_num_detx, m_num_dety, m_num_energy, 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 1141 of file GCTABackground3D.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 166 of file GCTABackground3D.hpp.
References init_mc_cache(), m_mc_spectrum, and GModelSpectralNodes::nodes().
|
inline |
Return response table.
Definition at line 193 of file GCTABackground3D.hpp.
References m_background.
|
inline |
Assign response table.
[in] | table | Response table. |
Definition at line 205 of file GCTABackground3D.hpp.
References m_background, set_members(), and table().
void GCTABackground3D::write | ( | GFitsBinTable & | table | ) | const |
Write background into FITS table.
[in] | table | FITS binary table. |
Writes background into a FITS binary table
.
Definition at line 341 of file GCTABackground3D.cpp.
References m_background, and GCTAResponseTable::write().
Referenced by save().
|
private |
Background response table.
Definition at line 110 of file GCTABackground3D.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 |
DETX maximum (radians)
Definition at line 121 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), operator()(), rate_ebin(), and set_members().
|
private |
DETX minimum (radians)
Definition at line 120 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), operator()(), rate_ebin(), and set_members().
|
private |
DETY maximum (radians)
Definition at line 123 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), operator()(), rate_ebin(), and set_members().
|
private |
DETY minimum (radians)
Definition at line 122 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), operator()(), rate_ebin(), and set_members().
|
private |
Vector of energies.
Definition at line 111 of file GCTABackground3D.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 GCTABackground3D.hpp.
Referenced by copy_members(), filename(), init_members(), load(), and print().
|
private |
Background index.
Definition at line 115 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_max_rate(), init_members(), rate(), and set_members().
|
private |
DETX index.
Definition at line 112 of file GCTABackground3D.hpp.
Referenced by copy_members(), index(), init_members(), print(), rate(), and set_members().
|
private |
DETY index.
Definition at line 113 of file GCTABackground3D.hpp.
Referenced by copy_members(), index(), init_members(), print(), rate(), and set_members().
|
private |
Energy index.
Definition at line 114 of file GCTABackground3D.hpp.
Referenced by copy_members(), index(), init_mc_cache(), init_members(), mc(), operator()(), print(), and set_members().
|
private |
Log10(E/TeV) maximum.
Definition at line 125 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_members(), and set_members().
|
private |
Log10(E/TeV) minimum.
Definition at line 124 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_members(), and set_members().
|
mutableprivate |
Maximum background rate.
Definition at line 128 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), and mc().
|
mutableprivate |
Response cube spectrum.
Definition at line 129 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_members(), mc(), and spectrum().
|
private |
Array of number of bins.
Definition at line 119 of file GCTABackground3D.hpp.
Referenced by copy_members(), index(), init_members(), and set_members().
|
private |
Number of DETX bins.
Definition at line 116 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), print(), and set_members().
|
private |
Number of DETY bins.
Definition at line 117 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), print(), and set_members().
|
private |
Number of energy bins.
Definition at line 118 of file GCTABackground3D.hpp.
Referenced by copy_members(), init_mc_cache(), init_mc_max_rate(), init_members(), print(), and set_members().