GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
34 #include "GModelSpectralNodes.hpp"
35 #include "GCTABackground.hpp"
36 #include "GCTAResponseTable.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GFits;
40 class GFitsBinTable;
41 
42 /* __ Constants __________________________________________________________ */
43 namespace 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 
55 public:
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 
94 private:
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  ***************************************************************************/
134 inline
135 std::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  ***************************************************************************/
146 inline
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  ***************************************************************************/
161 inline
163 {
164  if (m_mc_spectrum.nodes() == 0) {
165  init_mc_cache();
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  ***************************************************************************/
176 inline
178 {
179  return (m_background.axes() == 2);
180 }
181 
182 
183 /***********************************************************************//**
184  * @brief Return response table
185  *
186  * @return Response table.
187  ***************************************************************************/
188 inline
190 {
191  return m_background;
192 }
193 
194 
195 /***********************************************************************//**
196  * @brief Assign response table
197  *
198  * @param[in] table Response table.
199  ***************************************************************************/
200 inline
202 {
204  set_members();
205 }
206 
207 #endif /* GCTABACKGROUND2D_HPP */
CTA background model base class definition.
virtual ~GCTABackground2D(void)
Destructor.
int index(const int &itheta, const int &iebin) const
Return background rate bin index.
std::vector< double > m_mc_max
Maximum background rate.
double m_theta_min
THETA minimum (radians)
bool is_valid(void) const
Return validity of background model.
GCTABackground2D * clone(void) const
Clone background.
double m_logE_min
Log10(E/TeV) minimum.
int m_inx_energy
Energy axis index.
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 .
void copy_members(const GCTABackground2D &bgd)
Copy class members.
double m_logE_max
Log10(E/TeV) maximum.
int m_num_energy
Number of energy bins.
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
const std::string extname_cta_background2d
Time class.
Definition: GTime.hpp:55
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
FITS file class.
Definition: GFits.hpp:63
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) ...
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
GEnergies m_energy
Vector of energies.
Energy container class.
Definition: GEnergies.hpp:60
GCTABackground2D & operator=(const GCTABackground2D &bgd)
Assignment operator.
Spectral nodes model class.
int m_inx_theta
THETA axis index.
void clear(void)
Clear background.
std::string classname(void) const
Return class name.
int m_num[2]
Array of number of bins.
double m_theta_max
THETA maximum (radians)
void init_mc_cache(void) const
Initialise Monte Carlo cache.
GFilename filename(void) const
Return filename.
CTA response table class definition.
void init_mc_max_rate(void) const
Initialise array of maximum background rate.
int m_num_theta
Number of THETA bins.
void write(GFitsBinTable &table) const
Write background into FITS table.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
Filename class.
Definition: GFilename.hpp:62
Energy container class definition.
void free_members(void)
Delete class members.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
const GCTAResponseTable & table(void) const
Return response table.
GChatter
Definition: GTypemaps.hpp:33
GModelSpectralNodes m_mc_spectrum
Response cube spectrum.
GCTAResponseTable m_background
Background response table.
void set_members(void)
Set members from background table.
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.
int m_inx_bgd
Background index.
CTA 2D background class.
GCTABackground2D(void)
Void constructor.
int nodes(void) const
Return number of nodes.
FITS binary table class.
Abstract base class for the CTA background model.
GFilename m_filename
Name of background response file.
CTA response table class.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
void init_members(void)
Initialise class members.
const int & axes(void) const
Return number of axes of the tables.
void load(const GFilename &filename)
Load background from FITS file.
const GModelSpectralNodes & spectrum(void) const
Get response cube spectrum.
void save(const GFilename &filename, const bool &clobber=false) const
Save background into FITS file.
Filename class interface definition.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
void read(const GFitsTable &table)
Read background from FITS table.