GammaLib 2.0.0
Loading...
Searching...
No Matches
GCTABackground2D.hpp
Go to the documentation of this file.
1/***************************************************************************
2 * GCTABackground2D.hpp - CTA 2D background class *
3 * ----------------------------------------------------------------------- *
4 * copyright (C) 2021 by Juergen Knoedlseder *
5 * ----------------------------------------------------------------------- *
6 * *
7 * This program is free software: you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation, either version 3 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
19 * *
20 ***************************************************************************/
21/**
22 * @file GCTABackground2D.hpp
23 * @brief CTA 2D background class definition
24 * @author Juergen Knoedlseder
25 */
26
27#ifndef GCTABACKGROUND2D_HPP
28#define GCTABACKGROUND2D_HPP
29
30/* __ Includes ___________________________________________________________ */
31#include <string>
32#include "GEnergies.hpp"
33#include "GFilename.hpp"
35#include "GCTABackground.hpp"
36#include "GCTAResponseTable.hpp"
37
38/* __ Forward declarations _______________________________________________ */
39class GFits;
40class GFitsBinTable;
41
42/* __ Constants __________________________________________________________ */
43namespace gammalib {
44 const std::string extname_cta_background2d = "BKG";
45}
46
47
48/***********************************************************************//**
49 * @class GCTABackground2D
50 *
51 * @brief CTA 2D background class
52 ***************************************************************************/
54
55public:
56 // Constructors and destructors
57 GCTABackground2D(void);
58 explicit GCTABackground2D(const GFilename& filename);
60 virtual ~GCTABackground2D(void);
61
62 // Implemented pure virtual operators
63 virtual double operator()(const double& logE,
64 const double& detx,
65 const double& dety) const;
66
67 // Operators
69
70 // Implemented pure virtual methods
71 void clear(void);
72 GCTABackground2D* clone(void) const;
73 std::string classname(void) const;
74 void load(const GFilename& filename);
75 GFilename filename(void) const;
76 GCTAInstDir mc(const GEnergy& energy,
77 const GTime& time,
78 GRan& ran) const;
79 const GModelSpectralNodes& spectrum(void) const;
80 double rate_ebin(const GCTAInstDir& dir,
81 const GEnergy& emin,
82 const GEnergy& emax) const;
83 std::string print(const GChatter& chatter = NORMAL) const;
84
85 // Methods
86 bool is_valid(void) const;
87 const GCTAResponseTable& table(void) const;
88 void table(const GCTAResponseTable& table);
89 void read(const GFitsTable& table);
90 void write(GFitsBinTable& table) const;
91 void save(const GFilename& filename,
92 const bool& clobber = false) const;
93
94private:
95 // Methods
96 void init_members(void);
97 void copy_members(const GCTABackground2D& bgd);
98 void free_members(void);
99 void set_members(void);
100 int index(const int& itheta, const int& iebin) const;
101 void init_mc_cache(void) const;
102 void init_mc_max_rate(void) const;
103 double solid_angle(const double& detx1, const double& dety1,
104 const double& detx2, const double& dety2,
105 const double& detx3, const double& dety3) const;
106 double rate(const int& iebin, const double& theta) const;
107
108 // Members
109 GFilename m_filename; //!< Name of background response file
110 GCTAResponseTable m_background; //!< Background response table
111 GEnergies m_energy; //!< Vector of energies
112 int m_inx_theta; //!< THETA axis index
113 int m_inx_energy; //!< Energy axis index
114 int m_inx_bgd; //!< Background index
115 int m_num_theta; //!< Number of THETA bins
116 int m_num_energy; //!< Number of energy bins
117 int m_num[2]; //!< Array of number of bins
118 double m_theta_min; //!< THETA minimum (radians)
119 double m_theta_max; //!< THETA maximum (radians)
120 double m_logE_min; //!< Log10(E/TeV) minimum
121 double m_logE_max; //!< Log10(E/TeV) maximum
122
123 // Monte Carlo cache
124 mutable std::vector<double> m_mc_max; //!< Maximum background rate
125 mutable GModelSpectralNodes m_mc_spectrum; //!< Response cube spectrum
126};
127
128
129/***********************************************************************//**
130 * @brief Return class name
131 *
132 * @return String containing the class name ("GCTABackground2D").
133 ***************************************************************************/
134inline
135std::string GCTABackground2D::classname(void) const
136{
137 return ("GCTABackground2D");
138}
139
140
141/***********************************************************************//**
142 * @brief Return filename
143 *
144 * @return Returns filename from which the background was loaded.
145 ***************************************************************************/
146inline
148{
149 // Return filename
150 return m_filename;
151}
152
153
154/***********************************************************************//**
155 * @brief Get response cube spectrum
156 *
157 * @return Response cube spectrum.
158 *
159 * Returns the response cube spectrum.
160 ***************************************************************************/
161inline
163{
164 if (m_mc_spectrum.nodes() == 0) {
166 }
167 return (m_mc_spectrum);
168}
169
170
171/***********************************************************************//**
172 * @brief Return validity of background model
173 *
174 * @return True if background model is valid.
175 ***************************************************************************/
176inline
178{
179 return (m_background.axes() == 2);
180}
181
182
183/***********************************************************************//**
184 * @brief Return response table
185 *
186 * @return Response table.
187 ***************************************************************************/
188inline
190{
191 return m_background;
192}
193
194
195/***********************************************************************//**
196 * @brief Assign response table
197 *
198 * @param[in] table Response table.
199 ***************************************************************************/
200inline
202{
204 set_members();
205}
206
207#endif /* GCTABACKGROUND2D_HPP */
CTA background model base class definition.
CTA response table class definition.
Energy container class definition.
Filename class interface definition.
Spectral nodes model class definition.
GChatter
Definition GTypemaps.hpp:33
@ NORMAL
Definition GTypemaps.hpp:36
CTA 2D background class.
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)
void save(const GFilename &filename, const bool &clobber=false) const
Save background into FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
const GCTAResponseTable & table(void) const
Return response table.
int index(const int &itheta, const int &iebin) const
Return background rate bin index.
virtual ~GCTABackground2D(void)
Destructor.
GFilename filename(void) const
Return filename.
int m_inx_theta
THETA axis index.
bool is_valid(void) const
Return validity of background model.
GCTABackground2D(void)
Void constructor.
std::string classname(void) const
Return class name.
GFilename m_filename
Name of background response file.
void init_mc_max_rate(void) const
Initialise array of maximum background rate.
void init_members(void)
Initialise class members.
void clear(void)
Clear background.
GCTAResponseTable m_background
Background response table.
void read(const GFitsTable &table)
Read background from FITS table.
const GModelSpectralNodes & spectrum(void) const
Get response cube spectrum.
double m_theta_min
THETA minimum (radians)
void free_members(void)
Delete class members.
void write(GFitsBinTable &table) const
Write background into FITS table.
void copy_members(const GCTABackground2D &bgd)
Copy class members.
GEnergies m_energy
Vector of energies.
int m_num_energy
Number of energy bins.
double m_logE_min
Log10(E/TeV) minimum.
void init_mc_cache(void) const
Initialise Monte Carlo cache.
double m_theta_max
THETA maximum (radians)
GCTABackground2D & operator=(const GCTABackground2D &bgd)
Assignment operator.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
int m_num[2]
Array of number of bins.
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.
GCTABackground2D * clone(void) const
Clone background.
int m_inx_bgd
Background index.
void set_members(void)
Set members from background table.
int m_num_theta
Number of THETA bins.
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 sr .
int m_inx_energy
Energy axis index.
double m_logE_max
Log10(E/TeV) maximum.
std::vector< double > m_mc_max
Maximum background rate.
GModelSpectralNodes m_mc_spectrum
Response cube spectrum.
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
void load(const GFilename &filename)
Load background from FITS file.
Abstract base class for the CTA background model.
CTA instrument direction class.
CTA response table class.
const int & axes(void) const
Return number of axes of the tables.
Energy container class.
Definition GEnergies.hpp:60
Class that handles energies in a unit independent way.
Definition GEnergy.hpp:48
Filename class.
Definition GFilename.hpp:62
FITS binary table class.
Abstract interface for FITS table.
FITS file class.
Definition GFits.hpp:63
Spectral nodes model class.
int nodes(void) const
Return number of nodes.
Random number generator class.
Definition GRan.hpp:44
Time class.
Definition GTime.hpp:55
const std::string extname_cta_background2d