GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTABackground3D.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTABackground3D.hpp - CTA 3D background class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2018 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 GCTABackground3D.hpp
23  * @brief CTA 3D background class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTABACKGROUND3D_HPP
28 #define GCTABACKGROUND3D_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_background3d = "BACKGROUND";
45 }
46 
47 
48 /***********************************************************************//**
49  * @class GCTABackground3D
50  *
51  * @brief CTA 3D background class
52  ***************************************************************************/
54 
55 public:
56  // Constructors and destructors
57  GCTABackground3D(void);
58  explicit GCTABackground3D(const GFilename& filename);
60  virtual ~GCTABackground3D(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  GCTABackground3D* 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 GCTABackground3D& bgd);
98  void free_members(void);
99  void set_members(void);
100  int index(const int& idetx, const int& idety, 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& detx, const double& dety) 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_detx; //!< DETX index
113  int m_inx_dety; //!< DETY index
114  int m_inx_energy; //!< Energy index
115  int m_inx_bgd; //!< Background index
116  int m_num_detx; //!< Number of DETX bins
117  int m_num_dety; //!< Number of DETY bins
118  int m_num_energy; //!< Number of energy bins
119  int m_num[3]; //!< Array of number of bins
120  double m_detx_min; //!< DETX minimum (radians)
121  double m_detx_max; //!< DETX maximum (radians)
122  double m_dety_min; //!< DETY minimum (radians)
123  double m_dety_max; //!< DETY maximum (radians)
124  double m_logE_min; //!< Log10(E/TeV) minimum
125  double m_logE_max; //!< Log10(E/TeV) maximum
126 
127  // Monte Carlo cache
128  mutable std::vector<double> m_mc_max; //!< Maximum background rate
129  mutable GModelSpectralNodes m_mc_spectrum; //!< Response cube spectrum
130 };
131 
132 
133 /***********************************************************************//**
134  * @brief Return class name
135  *
136  * @return String containing the class name ("GCTABackground3D").
137  ***************************************************************************/
138 inline
139 std::string GCTABackground3D::classname(void) const
140 {
141  return ("GCTABackground3D");
142 }
143 
144 
145 /***********************************************************************//**
146  * @brief Return filename
147  *
148  * @return Returns filename from which the background was loaded.
149  ***************************************************************************/
150 inline
152 {
153  // Return filename
154  return m_filename;
155 }
156 
157 
158 /***********************************************************************//**
159  * @brief Get response cube spectrum
160  *
161  * @return Response cube spectrum.
162  *
163  * Returns the response cube spectrum.
164  ***************************************************************************/
165 inline
167 {
168  if (m_mc_spectrum.nodes() == 0) {
169  init_mc_cache();
170  }
171  return (m_mc_spectrum);
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Return validity of background model
177  *
178  * @return True if background model is valid.
179  ***************************************************************************/
180 inline
182 {
183  return (m_background.axes() == 3);
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Return response table
189  *
190  * @return Response table.
191  ***************************************************************************/
192 inline
194 {
195  return m_background;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Assign response table
201  *
202  * @param[in] table Response table.
203  ***************************************************************************/
204 inline
206 {
208  set_members();
209 }
210 
211 #endif /* GCTABACKGROUND3D_HPP */
CTA background model base class definition.
double m_dety_max
DETY maximum (radians)
GCTABackground3D & operator=(const GCTABackground3D &bgd)
Assignment operator.
GFilename m_filename
Name of background response file.
void init_mc_max_rate(void) const
Initialise array of maximum background rate.
double m_dety_min
DETY minimum (radians)
int m_num_dety
Number of DETY bins.
int m_num[3]
Array of number of bins.
const GModelSpectralNodes & spectrum(void) const
Get response cube spectrum.
const GCTAResponseTable & table(void) const
Return response table.
std::vector< double > m_mc_max
Maximum background rate.
void write(GFitsBinTable &table) const
Write background into FITS table.
const std::string extname_cta_background3d
GEnergies m_energy
Vector of energies.
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
Time class.
Definition: GTime.hpp:55
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.
FITS file class.
Definition: GFits.hpp:63
CTA 3D background class.
int m_inx_detx
DETX index.
Energy container class.
Definition: GEnergies.hpp:60
void clear(void)
Clear background.
Spectral nodes model class.
void copy_members(const GCTABackground3D &bgd)
Copy class members.
double m_detx_max
DETX maximum (radians)
CTA response table class definition.
int m_num_energy
Number of energy bins.
void init_members(void)
Initialise class members.
void save(const GFilename &filename, const bool &clobber=false) const
Save background into FITS file.
void free_members(void)
Delete class members.
int m_num_detx
Number of DETX bins.
void set_members(void)
Set members from background table.
Filename class.
Definition: GFilename.hpp:62
Energy container class definition.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
int index(const int &idetx, const int &idety, const int &iebin) const
Return background rate bin index.
double m_logE_min
Log10(E/TeV) minimum.
void init_mc_cache(void) const
Initialise Monte Carlo cache.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
bool is_valid(void) const
Return validity of background model.
GChatter
Definition: GTypemaps.hpp:33
GCTAResponseTable m_background
Background response table.
void load(const GFilename &filename)
Load background from FITS file.
int m_inx_dety
DETY index.
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
double m_logE_max
Log10(E/TeV) maximum.
GModelSpectralNodes m_mc_spectrum
Response cube spectrum.
int nodes(void) const
Return number of nodes.
int m_inx_energy
Energy index.
FITS binary table class.
GCTABackground3D(void)
Void constructor.
Abstract base class for the CTA background model.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
CTA response table class.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
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) ...
const int & axes(void) const
Return number of axes of the tables.
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 .
GFilename filename(void) const
Return filename.
Filename class interface definition.
virtual ~GCTABackground3D(void)
Destructor.
int m_inx_bgd
Background index.
void read(const GFitsTable &table)
Read background from FITS table.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
std::string classname(void) const
Return class name.
GCTABackground3D * clone(void) const
Clone background.
double m_detx_min
DETX minimum (radians)