GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAEdispRmf.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAEdispRmf.hpp - CTA RMF energy dispersion class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2014-2018 by Christoph Deil & Ellis Owen *
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 GCTAEdispRmf.hpp
23  * @brief CTA RMF energy dispersion class definition
24  * @author Christoph Deil & Ellis Owen
25  */
26 
27 #ifndef GCTAEDISPRMF_HPP
28 #define GCTAEDISPRMF_HPP
29 
30 /* __ Includes (members required) ________________________________________ */
31 #include <string>
32 #include "GFilename.hpp"
33 #include "GRmf.hpp"
34 #include "GMatrixSparse.hpp"
35 #include "GNodeArray.hpp"
36 #include "GCTAEdisp.hpp"
37 
38 /* __ Forward declarations _______________________________________________ */
39 class GFunction;
40 class GRan;
41 class GEnergy;
42 class GEbounds;
43 
44 
45 /***********************************************************************//**
46  * @class GCTAEdispRmf
47  *
48  * @brief CTA Redistribution Matrix File (RMF) energy dispersion class
49  *
50  * The energy dispersion is defined as
51  *
52  * \f[
53  * E_{\rm disp}(E_{\rm reco} | E_{\rm true})
54  * \f]
55  *
56  * in units of MeV\f$^{-1}\f$ where
57  * \f$E_{\rm reco}\f$ is the reconstructed energy, and
58  * \f$E_{\rm true}\f$ is the true energy.
59  ***************************************************************************/
60 class GCTAEdispRmf : public GCTAEdisp {
61 
62 public:
63  // Constructors and destructors
64  GCTAEdispRmf(void);
65  explicit GCTAEdispRmf(const GFilename& filename);
66  GCTAEdispRmf(const GCTAEdispRmf& edisp);
67  virtual ~GCTAEdispRmf(void);
68 
69  // Operators
70  GCTAEdispRmf& operator=(const GCTAEdispRmf& edisp);
71  double operator()(const GEnergy& ereco,
72  const GEnergy& etrue,
73  const double& theta = 0.0,
74  const double& phi = 0.0,
75  const double& zenith = 0.0,
76  const double& azimuth = 0.0) const;
77 
78  // Implemented pure virtual methods
79  void clear(void);
80  GCTAEdispRmf* clone(void) const;
81  std::string classname(void) const;
82  void load(const GFilename& filename);
83  GFilename filename(void) const;
84  GEnergy mc(GRan& ran,
85  const GEnergy& etrue,
86  const double& theta = 0.0,
87  const double& phi = 0.0,
88  const double& zenith = 0.0,
89  const double& azimuth = 0.0) const;
90  GEbounds ereco_bounds(const GEnergy& etrue,
91  const double& theta = 0.0,
92  const double& phi = 0.0,
93  const double& zenith = 0.0,
94  const double& azimuth = 0.0) const;
95  GEbounds etrue_bounds(const GEnergy& ereco,
96  const double& theta = 0.0,
97  const double& phi = 0.0,
98  const double& zenith = 0.0,
99  const double& azimuth = 0.0) const;
100  double prob_erecobin(const GEnergy& ereco_min,
101  const GEnergy& ereco_max,
102  const GEnergy& etrue,
103  const double& theta) const;
104  std::string print(const GChatter& chatter = NORMAL) const;
105 
106  // Other methods
107  const GRmf& rmf(void) const;
108 
109 private:
110  // Methods
111  void init_members(void);
112  void copy_members(const GCTAEdispRmf& psf);
113  void free_members(void);
114  void set_matrix(void);
115  void set_max_edisp(void);
116  void set_cache(void) const;
117  void update(const GEnergy& ereco, const GEnergy& etrue) const;
118  void compute_ereco_bounds(void) const;
119  void compute_etrue_bounds(void) const;
120 
121  // Members
122  GFilename m_filename; //!< Name of response file
123  GRmf m_rmf; //!< Redistribution matrix file
124  GMatrixSparse m_matrix; //!< Normalised redistribution matrix
125  double m_max_edisp; //!< Maximum energy dispersion value for MC
126 
127  // Interpolation cache
128  mutable GNodeArray m_etrue; //!< Array of log10(Etrue)
129  mutable GNodeArray m_ereco; //!< Array of log10(Ereco)
130  mutable GEnergy m_last_etrue; //!< Last true energy
131  mutable GEnergy m_last_ereco; //!< Last reconstructed energy
132  mutable int m_itrue1; //!< Index of left Etrue
133  mutable int m_itrue2; //!< Index of right Etrue
134  mutable int m_ireco1; //!< Index of left Ereco
135  mutable int m_ireco2; //!< Index of right Ereco
136  mutable double m_wgt1; //!< Weight of lower left node
137  mutable double m_wgt2; //!< Weight of upper left node
138  mutable double m_wgt3; //!< Weight of lower right node
139  mutable double m_wgt4; //!< Weight of upper right node
140 
141  // Computation cache
146  mutable int m_index_ereco;
147  mutable int m_index_etrue;
148  mutable std::vector<GEbounds> m_ereco_bounds;
149  mutable std::vector<GEbounds> m_etrue_bounds;
150 };
151 
152 
153 /***********************************************************************//**
154  * @brief Return class name
155  *
156  * @return String containing the class name ("GCTAEdispRmf").
157  ***************************************************************************/
158 inline
159 std::string GCTAEdispRmf::classname(void) const
160 {
161  return ("GCTAEdispRmf");
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Return filename
167  *
168  * @return Returns filename from which the Redistribution Matrix was loaded.
169  ***************************************************************************/
170 inline
172 {
173  return (m_filename);
174 }
175 
176 
177 /***********************************************************************//**
178  * @brief Return Redistribution Matrix File
179  *
180  * @return Reference to Redistribution Matrix File.
181  ***************************************************************************/
182 inline
183 const GRmf& GCTAEdispRmf::rmf(void) const
184 {
185  return (m_rmf);
186 }
187 
188 #endif /* GCTAEDISPRMF_HPP */
virtual ~GCTAEdispRmf(void)
Destructor.
GEbounds etrue_bounds(const GEnergy &ereco, const double &theta=0.0, const double &phi=0.0, const double &zenith=0.0, const double &azimuth=0.0) const
Return true energy interval that contains the energy dispersion.
std::string classname(void) const
Return class name.
Node array class.
Definition: GNodeArray.hpp:60
Sparse matrix class interface definition.
void clear(void)
Clear instance.
void set_max_edisp(void)
Set maximum energy dispersion value.
int m_itrue2
Index of right Etrue.
const GRmf & rmf(void) const
Return Redistribution Matrix File.
Abstract base class for the CTA energy dispersion.
Definition: GCTAEdisp.hpp:49
Redistribution Matrix File class.
Definition: GRmf.hpp:55
CTA Redistribution Matrix File (RMF) energy dispersion class.
Random number generator class.
Definition: GRan.hpp:44
void init_members(void)
Initialise class members.
double m_wgt3
Weight of lower right node.
GCTAEdispRmf(void)
Void constructor.
void copy_members(const GCTAEdispRmf &psf)
Copy class members.
void free_members(void)
Delete class members.
GEnergy mc(GRan &ran, const GEnergy &etrue, const double &theta=0.0, const double &phi=0.0, const double &zenith=0.0, const double &azimuth=0.0) const
Simulate energy dispersion.
void compute_ereco_bounds(void) const
Compute m_ereco_bounds vector.
GMatrixSparse m_matrix
Normalised redistribution matrix.
int m_itrue1
Index of left Etrue.
GEnergy m_last_ereco
Last reconstructed energy.
Node array class interface definition.
XSPEC Redistribution Matrix File class definition.
Energy boundaries container class.
Definition: GEbounds.hpp:60
GFilename m_filename
Name of response file.
Filename class.
Definition: GFilename.hpp:62
std::vector< GEbounds > m_etrue_bounds
GNodeArray m_etrue
Array of log10(Etrue)
GCTAEdispRmf & operator=(const GCTAEdispRmf &edisp)
Assignment operator.
GEbounds ereco_bounds(const GEnergy &etrue, const double &theta=0.0, const double &phi=0.0, const double &zenith=0.0, const double &azimuth=0.0) const
Return observed energy interval that contains the energy dispersion.
GChatter
Definition: GTypemaps.hpp:33
Abstract CTA energy dispersion base class definition.
bool m_ereco_bounds_computed
void load(const GFilename &filename)
Load energy dispersion from RMF file.
GFilename filename(void) const
Return filename.
GCTAEdispRmf * clone(void) const
Clone instance.
int m_ireco2
Index of right Ereco.
double operator()(const GEnergy &ereco, const GEnergy &etrue, const double &theta=0.0, const double &phi=0.0, const double &zenith=0.0, const double &azimuth=0.0) const
Return energy dispersion in units of MeV .
bool m_etrue_bounds_computed
void set_cache(void) const
Set interpolation cache.
void update(const GEnergy &ereco, const GEnergy &etrue) const
Update cache.
GEnergy m_last_etrue
Last true energy.
double m_wgt1
Weight of lower left node.
Single parameter function abstract base class.
Definition: GFunction.hpp:44
Sparse matrix class definition.
double m_wgt2
Weight of upper left node.
void compute_etrue_bounds(void) const
Compute m_etrue_bounds vector.
GEnergy m_last_etrue_bounds
GNodeArray m_ereco
Array of log10(Ereco)
GEnergy m_last_ereco_bounds
int m_ireco1
Index of left Ereco.
double m_wgt4
Weight of upper right node.
void set_matrix(void)
Set redistribution matrix.
GRmf m_rmf
Redistribution matrix file.
double m_max_edisp
Maximum energy dispersion value for MC.
std::vector< GEbounds > m_ereco_bounds
std::string print(const GChatter &chatter=NORMAL) const
Print RMF information.
Filename class interface definition.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
double prob_erecobin(const GEnergy &ereco_min, const GEnergy &ereco_max, const GEnergy &etrue, const double &theta) const
Return energy dispersion probability for reconstructed energy interval.