GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTABackgroundPerfTable.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTABackgroundPerfTable.hpp - CTA performance table background class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2020 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 GCTABackgroundPerfTable.hpp
23  * @brief CTA performance table background class definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTABACKGROUNDPERFTABLE_HPP
28 #define GCTABACKGROUNDPERFTABLE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GFilename.hpp"
33 #include "GFunction.hpp"
34 #include "GEnergies.hpp"
35 #include "GNodeArray.hpp"
36 #include "GModelSpectralNodes.hpp"
37 #include "GCTABackground.hpp"
38 
39 /* __ Forward declarations _______________________________________________ */
40 
41 
42 /***********************************************************************//**
43  * @class GCTABackgroundPerfTable
44  *
45  * @brief CTA performance table background class
46  ***************************************************************************/
48 
49 public:
50  // Constructors and destructors
54  virtual ~GCTABackgroundPerfTable(void);
55 
56  // Implemented pure virtual operators
57  virtual double operator()(const double& logE,
58  const double& detx,
59  const double& dety) const;
60 
61  // Operators
63 
64  // Implemented pure virtual methods
65  void clear(void);
66  GCTABackgroundPerfTable* clone(void) const;
67  std::string classname(void) const;
68  void load(const GFilename& filename);
69  GFilename filename(void) const;
70  GCTAInstDir mc(const GEnergy& energy,
71  const GTime& time,
72  GRan& ran) const;
73  const GModelSpectralNodes& spectrum(void) const;
74  double rate_ebin(const GCTAInstDir& dir,
75  const GEnergy& emin,
76  const GEnergy& emax) const;
77  std::string print(const GChatter& chatter = NORMAL) const;
78 
79  // Methods
80  int size(void) const;
81  void sigma(const double& sigma);
82  const double& sigma(void) const;
83 
84 private:
85  // Methods
86  void init_members(void);
87  void copy_members(const GCTABackgroundPerfTable& bgd);
88  void free_members(void);
89  double solidangle(void) const;
90  void init_mc_cache(void) const;
91  double rate(const double& logE) const;
92 
93  // Radial integration class (used by solidangle() method). Note that
94  // the sigma parameter is given in rad^2
95  class integrand : public GFunction {
96  public:
97  integrand(const double& sigma) : m_sigma(sigma) { }
98  double eval(const double& x) {
99  double arg = x * x / m_sigma;
100  double arg2 = arg * arg;
101  double f = std::exp(-0.5 * arg2);
102  return (f*std::sin(x));
103  }
104  private:
105  double m_sigma;
106  };
107 
108  // Members
109  GFilename m_filename; //!< Name of background response file
110  GEnergies m_energy; //!< Vector of energies
111  GNodeArray m_log10_energy; //!< log10(E) nodes for background interpolation
112  std::vector<double> m_background; //!< Background rate
113  std::vector<double> m_log_background; //!< log(background rate)
114  double m_sigma; //!< Sigma for offset angle computation (0=none)
115 
116  // Monte Carlo cache
117  mutable GModelSpectralNodes m_mc_spectrum; //!< Background spectrum
118 };
119 
120 
121 /***********************************************************************//**
122  * @brief Return class name
123  *
124  * @return String containing the class name ("GCTABackgroundPerfTable").
125  ***************************************************************************/
126 inline
127 std::string GCTABackgroundPerfTable::classname(void) const
128 {
129  return ("GCTABackgroundPerfTable");
130 }
131 
132 
133 /***********************************************************************//**
134  * @brief Return filename
135  *
136  * @return Returns filename from which the background was loaded.
137  ***************************************************************************/
138 inline
140 {
141  // Return filename
142  return m_filename;
143 }
144 
145 
146 /***********************************************************************//**
147  * @brief Return number of node energies in response
148  *
149  * @return Number of node energies.
150  ***************************************************************************/
151 inline
153 {
154  return (m_energy.size());
155 }
156 
157 
158 /***********************************************************************//**
159  * @brief Set sigma for offset angle dependence
160  *
161  * @param[in] sigma Sigma for offset angle dependence.
162  *
163  * Sets the sigma parameter for the offset angle dependence of the effective
164  * area. If @p sigma is 0, no offset angle dependency will be assumed. By
165  * default, @p sigma = 3.
166  ***************************************************************************/
167 inline
168 void GCTABackgroundPerfTable::sigma(const double& sigma)
169 {
170  m_sigma = sigma;
171  return;
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Return sigma for offset angle dependence
177  *
178  * @return Sigma for offset angle dependence.
179  ***************************************************************************/
180 inline
181 const double& GCTABackgroundPerfTable::sigma(void) const
182 {
183  return (m_sigma);
184 }
185 
186 
187 /***********************************************************************//**
188  * @brief Get response cube spectrum
189  *
190  * @return Response cube spectrum.
191  *
192  * Returns the response cube spectrum.
193  ***************************************************************************/
194 inline
196 {
197  if (m_mc_spectrum.nodes() == 0) {
198  init_mc_cache();
199  }
200  return (m_mc_spectrum);
201 }
202 
203 #endif /* GCTABACKGROUNDPERFTABLE_HPP */
GCTABackgroundPerfTable(void)
Void constructor.
CTA background model base class definition.
GCTABackgroundPerfTable & operator=(const GCTABackgroundPerfTable &bgd)
Assignment operator.
std::vector< double > m_log_background
log(background rate)
std::string classname(void) const
Return class name.
void init_members(void)
Initialise class members.
double solidangle(void) const
Returns integral over radial model (in steradians)
Node array class.
Definition: GNodeArray.hpp:60
virtual ~GCTABackgroundPerfTable(void)
Destructor.
void free_members(void)
Delete class members.
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
void load(const GFilename &filename)
Load background from performance table.
Time class.
Definition: GTime.hpp:55
GFilename filename(void) const
Return filename.
void copy_members(const GCTABackgroundPerfTable &bgd)
Copy class members.
GCTABackgroundPerfTable * clone(void) const
Clone background.
Energy container class.
Definition: GEnergies.hpp:60
Spectral nodes model class.
GNodeArray m_log10_energy
log10(E) nodes for background interpolation
Node array class interface definition.
GEnergies m_energy
Vector of energies.
const double & sigma(void) const
Return sigma for offset angle dependence.
double rate(const double &logE) const
Return background rate for a given energy (events/s/MeV/sr)
Single parameter function abstract base class definition.
Filename class.
Definition: GFilename.hpp:62
Energy container class definition.
int size(void) const
Return number of energies in container.
Definition: GEnergies.hpp:170
void init_mc_cache(void) const
Initialise Monte Carlo cache.
GChatter
Definition: GTypemaps.hpp:33
int size(void) const
Return number of node energies in response.
virtual double operator()(const double &logE, const double &detx, const double &dety) const
Return background rate in units of events MeV s sr .
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
GModelSpectralNodes m_mc_spectrum
Background spectrum.
GCTAInstDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC instrument direction.
int nodes(void) const
Return number of nodes.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
GVector sin(const GVector &vector)
Computes sine of vector elements.
Definition: GVector.cpp:1316
void clear(void)
Clear background.
Abstract base class for the CTA background model.
const GModelSpectralNodes & spectrum(void) const
Get response cube spectrum.
CTA performance table background class.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
Definition: GVector.cpp:1232
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 .
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
std::vector< double > m_background
Background rate.
double m_sigma
Sigma for offset angle computation (0=none)
GFilename m_filename
Name of background response file.
Filename class interface definition.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48