GammaLib  1.7.0.dev
 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-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 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 "GEnergies.hpp"
34 #include "GNodeArray.hpp"
35 #include "GModelSpectralNodes.hpp"
36 #include "GCTABackground.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 
40 
41 /***********************************************************************//**
42  * @class GCTABackgroundPerfTable
43  *
44  * @brief CTA performance table background class
45  ***************************************************************************/
47 
48 public:
49  // Constructors and destructors
53  virtual ~GCTABackgroundPerfTable(void);
54 
55  // Implemented pure virtual operators
56  virtual double operator()(const double& logE,
57  const double& detx,
58  const double& dety) const;
59 
60  // Operators
62 
63  // Implemented pure virtual methods
64  void clear(void);
65  GCTABackgroundPerfTable* clone(void) const;
66  std::string classname(void) const;
67  void load(const GFilename& filename);
68  GFilename filename(void) const;
69  GCTAInstDir mc(const GEnergy& energy,
70  const GTime& time,
71  GRan& ran) const;
72  const GModelSpectralNodes& spectrum(void) const;
73  double rate_ebin(const GCTAInstDir& dir,
74  const GEnergy& emin,
75  const GEnergy& emax) const;
76  std::string print(const GChatter& chatter = NORMAL) const;
77 
78  // Methods
79  int size(void) const;
80  void sigma(const double& sigma);
81  const double& sigma(void) const;
82 
83 private:
84  // Methods
85  void init_members(void);
86  void copy_members(const GCTABackgroundPerfTable& bgd);
87  void free_members(void);
88  double solidangle(void) const;
89  void init_mc_cache(void) const;
90  double rate(const double& logE) const;
91 
92  // Radial integration class (used by solidangle() method). Note that
93  // the sigma parameter is given in rad^2
94  class integrand : public GFunction {
95  public:
96  integrand(const double& sigma) : m_sigma(sigma) { }
97  double eval(const double& x) {
98  double arg = x * x / m_sigma;
99  double arg2 = arg * arg;
100  double f = std::exp(-0.5 * arg2);
101  return (f*std::sin(x));
102  }
103  private:
104  double m_sigma;
105  };
106 
107  // Members
108  GFilename m_filename; //!< Name of background response file
109  GEnergies m_energy; //!< Vector of energies
110  GNodeArray m_log10_energy; //!< log10(E) nodes for background interpolation
111  std::vector<double> m_background; //!< Background rate
112  std::vector<double> m_log_background; //!< log(background rate)
113  double m_sigma; //!< Sigma for offset angle computation (0=none)
114 
115  // Monte Carlo cache
116  mutable GModelSpectralNodes m_mc_spectrum; //!< Background spectrum
117 };
118 
119 
120 /***********************************************************************//**
121  * @brief Return class name
122  *
123  * @return String containing the class name ("GCTABackgroundPerfTable").
124  ***************************************************************************/
125 inline
126 std::string GCTABackgroundPerfTable::classname(void) const
127 {
128  return ("GCTABackgroundPerfTable");
129 }
130 
131 
132 /***********************************************************************//**
133  * @brief Return filename
134  *
135  * @return Returns filename from which the background was loaded.
136  ***************************************************************************/
137 inline
139 {
140  // Return filename
141  return m_filename;
142 }
143 
144 
145 /***********************************************************************//**
146  * @brief Return number of node energies in response
147  *
148  * @return Number of node energies.
149  ***************************************************************************/
150 inline
152 {
153  return (m_energy.size());
154 }
155 
156 
157 /***********************************************************************//**
158  * @brief Set sigma for offset angle dependence
159  *
160  * @param[in] sigma Sigma for offset angle dependence.
161  *
162  * Sets the sigma parameter for the offset angle dependence of the effective
163  * area. If @p sigma is 0, no offset angle dependency will be assumed. By
164  * default, @p sigma = 3.
165  ***************************************************************************/
166 inline
167 void GCTABackgroundPerfTable::sigma(const double& sigma)
168 {
169  m_sigma = sigma;
170  return;
171 }
172 
173 
174 /***********************************************************************//**
175  * @brief Return sigma for offset angle dependence
176  *
177  * @return Sigma for offset angle dependence.
178  ***************************************************************************/
179 inline
180 const double& GCTABackgroundPerfTable::sigma(void) const
181 {
182  return (m_sigma);
183 }
184 
185 
186 /***********************************************************************//**
187  * @brief Get response cube spectrum
188  *
189  * @return Response cube spectrum.
190  *
191  * Returns the response cube spectrum.
192  ***************************************************************************/
193 inline
195 {
196  if (m_mc_spectrum.nodes() == 0) {
197  init_mc_cache();
198  }
199  return (m_mc_spectrum);
200 }
201 
202 #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:54
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)
Filename class.
Definition: GFilename.hpp:62
Energy container class definition.
int size(void) const
Return number of energies in container.
Definition: GEnergies.hpp:162
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:1226
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:1142
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:59
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