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

CTA 2D background class. More...

#include <GCTABackground2D.hpp>

Inheritance diagram for GCTABackground2D:
GCTABackground GBase

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...
 
GCTABackground2Doperator= (const GCTABackground2D &bgd)
 Assignment operator. More...
 
void clear (void)
 Clear background. More...
 
GCTABackground2Dclone (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 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...
 

Detailed Description

CTA 2D background class.

Definition at line 53 of file GCTABackground2D.hpp.

Constructor & Destructor Documentation

GCTABackground2D::GCTABackground2D ( void  )

Void constructor.

Constructs empty background.

Definition at line 69 of file GCTABackground2D.cpp.

References init_members().

Referenced by clone().

GCTABackground2D::GCTABackground2D ( const GFilename filename)
explicit

File constructor.

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

Parameters
[in]bgdBackground.

Constructs background by copying from another background.

Definition at line 107 of file GCTABackground2D.cpp.

References copy_members(), and init_members().

GCTABackground2D::~GCTABackground2D ( void  )
virtual

Destructor.

Destructs background.

Definition at line 126 of file GCTABackground2D.cpp.

References free_members().

Member Function Documentation

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

Return class name.

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

Implements GCTABackground.

Definition at line 135 of file GCTABackground2D.hpp.

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

GCTABackground2D * GCTABackground2D::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 277 of file GCTABackground2D.cpp.

References GCTABackground2D().

void GCTABackground2D::copy_members ( const GCTABackground2D bgd)
private

Copy class members.

Parameters
[in]bgdBackground.

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

GFilename GCTABackground2D::filename ( void  ) const
inlinevirtual

Return filename.

Returns
Returns filename from which the background was loaded.

Implements GCTABackground.

Definition at line 147 of file GCTABackground2D.hpp.

References m_filename.

Referenced by load().

void GCTABackground2D::free_members ( void  )
private

Delete class members.

Definition at line 783 of file GCTABackground2D.cpp.

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

int GCTABackground2D::index ( const int &  itheta,
const int &  iebin 
) const
private

Return background rate bin index.

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

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

bool GCTABackground2D::is_valid ( void  ) const
inline

Return validity of background model.

Returns
True if background model is valid.

Definition at line 177 of file GCTABackground2D.hpp.

References GCTAResponseTable::axes(), and m_background.

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

void GCTABackground2D::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_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().

GCTAInstDir GCTABackground2D::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 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().

double GCTABackground2D::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 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.

Parameters
[in]bgdBackground.
Returns
Background.

Assigns background.

Definition at line 150 of file GCTABackground2D.cpp.

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

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

Print background information.

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

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

double GCTABackground2D::rate ( const int &  iebin,
const double &  theta 
) const
private

Return background rate for a given energy bin and offset angle value (events/s/MeV/sr)

Parameters
[in]iebinEnergy index.
[in]thetaOffset angle in nominal system (radians).
Returns
Background rate (events/s/MeV/sr)

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

double GCTABackground2D::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 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.

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

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

void GCTABackground2D::set_members ( void  )
private
double GCTABackground2D::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 1106 of file GCTABackground2D.cpp.

References atan(), gammalib::atan2(), GSkyDir::dist(), gammalib::pihalf, GSkyDir::radec(), sqrt(), and tan().

Referenced by init_mc_cache().

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

Get response cube spectrum.

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

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

Return response table.

Returns
Response table.

Definition at line 189 of file GCTABackground2D.hpp.

References m_background.

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

void GCTABackground2D::table ( const GCTAResponseTable table)
inline

Assign response table.

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

Parameters
[in]tableFITS binary table.

Writes background into a FITS binary table.

Todo:
Add necessary keywords.

Definition at line 345 of file GCTABackground2D.cpp.

References m_background, and GCTAResponseTable::write().

Referenced by save().

Member Data Documentation

GCTAResponseTable GCTABackground2D::m_background
private
GEnergies GCTABackground2D::m_energy
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().

GFilename GCTABackground2D::m_filename
private

Name of background response file.

Definition at line 109 of file GCTABackground2D.hpp.

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

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

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

int GCTABackground2D::m_inx_theta
private

THETA axis index.

Definition at line 112 of file GCTABackground2D.hpp.

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

double GCTABackground2D::m_logE_max
private

Log10(E/TeV) maximum.

Definition at line 121 of file GCTABackground2D.hpp.

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

double GCTABackground2D::m_logE_min
private

Log10(E/TeV) minimum.

Definition at line 120 of file GCTABackground2D.hpp.

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

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

GModelSpectralNodes GCTABackground2D::m_mc_spectrum
mutableprivate

Response cube spectrum.

Definition at line 125 of file GCTABackground2D.hpp.

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

int GCTABackground2D::m_num[2]
private

Array of number of bins.

Definition at line 117 of file GCTABackground2D.hpp.

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

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

int GCTABackground2D::m_num_theta
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().

double GCTABackground2D::m_theta_max
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().

double GCTABackground2D::m_theta_min
private

THETA minimum (radians)

Definition at line 118 of file GCTABackground2D.hpp.

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


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