GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTABackground3D Class Reference

CTA 3D background class. More...

#include <GCTABackground3D.hpp>

Inheritance diagram for GCTABackground3D:
GCTABackground GBase

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...
 
GCTABackground3Doperator= (const GCTABackground3D &bgd)
 Assignment operator. More...
 
void clear (void)
 Clear background. More...
 
GCTABackground3Dclone (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 GModelSpectralNodesspectrum (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 GCTAResponseTabletable (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...
 
GCTABackgroundoperator= (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...
 

Detailed Description

CTA 3D background class.

Definition at line 53 of file GCTABackground3D.hpp.

Constructor & Destructor Documentation

GCTABackground3D::GCTABackground3D ( void  )

Void constructor.

Constructs empty background.

Definition at line 69 of file GCTABackground3D.cpp.

References init_members().

Referenced by clone().

GCTABackground3D::GCTABackground3D ( const GFilename filename)
explicit

File constructor.

Parameters
[in]filenameFITS 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.

Parameters
[in]bgdBackground.

Constructs background by copying from another background.

Definition at line 107 of file GCTABackground3D.cpp.

References copy_members(), and init_members().

GCTABackground3D::~GCTABackground3D ( void  )
virtual

Destructor.

Destructs background.

Definition at line 126 of file GCTABackground3D.cpp.

References free_members().

Member Function Documentation

std::string GCTABackground3D::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GCTABackground3D").

Implements GCTABackground.

Definition at line 139 of file GCTABackground3D.hpp.

void GCTABackground3D::clear ( void  )
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().

GCTABackground3D * GCTABackground3D::clone ( void  ) const
virtual

Clone background.

Returns
Deep copy of background.

Returns a pointer to a deep copy of the background.

Implements GCTABackground.

Definition at line 268 of file GCTABackground3D.cpp.

References GCTABackground3D().

void GCTABackground3D::copy_members ( const GCTABackground3D bgd)
private
GFilename GCTABackground3D::filename ( void  ) const
inlinevirtual

Return filename.

Returns
Returns filename from which the background was loaded.

Implements GCTABackground.

Definition at line 151 of file GCTABackground3D.hpp.

References m_filename.

Referenced by load().

void GCTABackground3D::free_members ( void  )
private

Delete class members.

Definition at line 798 of file GCTABackground3D.cpp.

Referenced by clear(), operator=(), and ~GCTABackground3D().

int GCTABackground3D::index ( const int &  idetx,
const int &  idety,
const int &  iebin 
) const
private

Return background rate bin index.

Parameters
[in]idetxDETX index.
[in]idetyDETY index.
[in]iebinEnergy index.
Returns
Background rate bin 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().

void GCTABackground3D::init_mc_max_rate ( void  ) const
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().

bool GCTABackground3D::is_valid ( void  ) const
inline

Return validity of background model.

Returns
True if background model is valid.

Definition at line 181 of file GCTABackground3D.hpp.

References GCTAResponseTable::axes(), and m_background.

Referenced by operator()(), print(), and rate_ebin().

void GCTABackground3D::load ( const GFilename filename)
virtual

Load background from FITS file.

Parameters
[in]filenameFITS 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().

GCTAInstDir GCTABackground3D::mc ( const GEnergy energy,
const GTime time,
GRan ran 
) const
virtual

Returns MC instrument direction.

Parameters
[in]energyEvent energy.
[in]timeEvent trigger time.
[in,out]ranRandom number generator.
Returns
CTA instrument direction.

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().

double GCTABackground3D::operator() ( const double &  logE,
const double &  detx,
const double &  dety 
) const
virtual

Return background rate in units of events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\).

Parameters
[in]logELog10 of the true photon energy (TeV).
[in]detxTangential X coordinate in nominal system (radians).
[in]detyTangential Y coordinate in nominal system (radians).
Returns
Background rate (events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\)).

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.

Parameters
[in]bgdBackground.
Returns
Background.

Assigns background.

Definition at line 150 of file GCTABackground3D.cpp.

References copy_members(), free_members(), init_members(), and GCTABackground::operator=().

std::string GCTABackground3D::print ( const GChatter chatter = NORMAL) const
virtual

Print background information.

Parameters
[in]chatterChattiness.
Returns
String containing background information.

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().

double GCTABackground3D::rate ( const int &  iebin,
const double &  detx,
const double &  dety 
) const
private

Return background rate for a given energy bin and DETX-DETY value (events/s/MeV/sr)

Parameters
[in]iebinEnergy index.
[in]detxTangential X coordinate in nominal system (radians).
[in]detyTangential Y coordinate in nominal system (radians).
Returns
Background rate (events/s/MeV/sr)

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().

double GCTABackground3D::rate_ebin ( const GCTAInstDir dir,
const GEnergy emin,
const GEnergy emax 
) const
virtual

Returns background rate integrated over energy interval in units of events s \(^{-1}\) sr \(^{-1}\).

Parameters
[in]dirInstrument direction.
[in]eminMinimum energy of energy interval.
[in]emaxMaximum energy of energy interval.
Returns
Integrated background count rate (events s \(^{-1}\) sr \(^{-1}\)).

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.

Parameters
[in]tableFITS 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.

Parameters
[in]filenameBackground table FITS file name.
[in]clobberOverwrite 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().

double GCTABackground3D::solid_angle ( const double &  detx1,
const double &  dety1,
const double &  detx2,
const double &  dety2,
const double &  detx3,
const double &  dety3 
) const
private

Compute solid angle of pixel wedge.

Parameters
[in]detx1DETX of first edge.
[in]dety1DETY of first edge.
[in]detx2DETX of second edge.
[in]dety2DETY of second edge.
[in]detx3DETX of third edge.
[in]dety3DETY of third edge.
Returns
Solid angle (steradians).

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().

const GModelSpectralNodes & GCTABackground3D::spectrum ( void  ) const
inlinevirtual

Get response cube spectrum.

Returns
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().

const GCTAResponseTable & GCTABackground3D::table ( void  ) const
inline

Return response table.

Returns
Response table.

Definition at line 193 of file GCTABackground3D.hpp.

References m_background.

Referenced by load(), save(), and table().

void GCTABackground3D::table ( const GCTAResponseTable table)
inline

Assign response table.

Parameters
[in]tableResponse 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.

Parameters
[in]tableFITS binary table.

Writes background into a FITS binary table.

Todo:
Add necessary keywords.

Definition at line 341 of file GCTABackground3D.cpp.

References m_background, and GCTAResponseTable::write().

Referenced by save().

Member Data Documentation

GCTAResponseTable GCTABackground3D::m_background
private
double GCTABackground3D::m_detx_max
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().

double GCTABackground3D::m_detx_min
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().

double GCTABackground3D::m_dety_max
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().

double GCTABackground3D::m_dety_min
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().

GEnergies GCTABackground3D::m_energy
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().

GFilename GCTABackground3D::m_filename
private

Name of background response file.

Definition at line 109 of file GCTABackground3D.hpp.

Referenced by copy_members(), filename(), init_members(), load(), and print().

int GCTABackground3D::m_inx_bgd
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().

int GCTABackground3D::m_inx_detx
private

DETX index.

Definition at line 112 of file GCTABackground3D.hpp.

Referenced by copy_members(), index(), init_members(), print(), rate(), and set_members().

int GCTABackground3D::m_inx_dety
private

DETY index.

Definition at line 113 of file GCTABackground3D.hpp.

Referenced by copy_members(), index(), init_members(), print(), rate(), and set_members().

int GCTABackground3D::m_inx_energy
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().

double GCTABackground3D::m_logE_max
private

Log10(E/TeV) maximum.

Definition at line 125 of file GCTABackground3D.hpp.

Referenced by copy_members(), init_members(), and set_members().

double GCTABackground3D::m_logE_min
private

Log10(E/TeV) minimum.

Definition at line 124 of file GCTABackground3D.hpp.

Referenced by copy_members(), init_members(), and set_members().

std::vector<double> GCTABackground3D::m_mc_max
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().

GModelSpectralNodes GCTABackground3D::m_mc_spectrum
mutableprivate

Response cube spectrum.

Definition at line 129 of file GCTABackground3D.hpp.

Referenced by copy_members(), init_mc_cache(), init_members(), mc(), and spectrum().

int GCTABackground3D::m_num[3]
private

Array of number of bins.

Definition at line 119 of file GCTABackground3D.hpp.

Referenced by copy_members(), index(), init_members(), and set_members().

int GCTABackground3D::m_num_detx
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().

int GCTABackground3D::m_num_dety
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().

int GCTABackground3D::m_num_energy
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().


The documentation for this class was generated from the following files: