GammaLib 2.0.0
Loading...
Searching...
No Matches
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"
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_background3d = "BACKGROUND";
45}
46
47
48/***********************************************************************//**
49 * @class GCTABackground3D
50 *
51 * @brief CTA 3D background class
52 ***************************************************************************/
54
55public:
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
94private:
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 ***************************************************************************/
138inline
139std::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 ***************************************************************************/
150inline
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 ***************************************************************************/
165inline
167{
168 if (m_mc_spectrum.nodes() == 0) {
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 ***************************************************************************/
180inline
182{
183 return (m_background.axes() == 3);
184}
185
186
187/***********************************************************************//**
188 * @brief Return response table
189 *
190 * @return Response table.
191 ***************************************************************************/
192inline
194{
195 return m_background;
196}
197
198
199/***********************************************************************//**
200 * @brief Assign response table
201 *
202 * @param[in] table Response table.
203 ***************************************************************************/
204inline
206{
208 set_members();
209}
210
211#endif /* GCTABACKGROUND3D_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 3D background class.
void init_members(void)
Initialise class members.
double m_dety_min
DETY minimum (radians)
double m_dety_max
DETY maximum (radians)
void init_mc_cache(void) const
Initialise Monte Carlo cache.
GCTABackground3D * clone(void) const
Clone background.
void free_members(void)
Delete class members.
void read(const GFitsTable &table)
Read background from FITS table.
void save(const GFilename &filename, const bool &clobber=false) const
Save background into FITS file.
const GModelSpectralNodes & spectrum(void) const
Get response cube spectrum.
GFilename m_filename
Name of background response file.
GFilename filename(void) const
Return filename.
const GCTAResponseTable & table(void) const
Return response table.
int m_num_detx
Number of DETX bins.
virtual ~GCTABackground3D(void)
Destructor.
int m_num_energy
Number of energy bins.
int m_num[3]
Array of number of bins.
GCTAResponseTable m_background
Background response table.
GCTABackground3D & operator=(const GCTABackground3D &bgd)
Assignment operator.
void load(const GFilename &filename)
Load background from FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
double m_logE_min
Log10(E/TeV) minimum.
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_detx
DETX index.
GEnergies m_energy
Vector of energies.
void write(GFitsBinTable &table) const
Write background into FITS table.
void copy_members(const GCTABackground3D &bgd)
Copy class members.
int m_inx_dety
DETY index.
int m_num_dety
Number of DETY bins.
GModelSpectralNodes m_mc_spectrum
Response cube spectrum.
int index(const int &idetx, const int &idety, const int &iebin) const
Return background rate bin index.
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)
GCTABackground3D(void)
Void constructor.
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 .
double m_logE_max
Log10(E/TeV) maximum.
int m_inx_energy
Energy index.
bool is_valid(void) const
Return validity of background model.
void init_mc_max_rate(void) const
Initialise array of maximum background rate.
std::string classname(void) const
Return class name.
void set_members(void)
Set members from background table.
std::vector< double > m_mc_max
Maximum background rate.
double m_detx_min
DETX minimum (radians)
double m_detx_max
DETX maximum (radians)
void clear(void)
Clear background.
int m_inx_bgd
Background index.
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
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_background3d