GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTACubeEdisp.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTACubeEdisp.hpp - CTA cube analysis energy dispersion class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2018 by Michael Mayer *
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 GCTACubeEdisp.hpp
23  * @brief CTA cube analysis energy disperson class definition
24  * @author Michael Mayer
25  */
26 
27 #ifndef GCTACUBEEDISP_HPP
28 #define GCTACUBEEDISP_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include <vector>
33 #include "GBase.hpp"
34 #include "GSkyMap.hpp"
35 #include "GEbounds.hpp"
36 #include "GEnergies.hpp"
37 #include "GNodeArray.hpp"
38 
39 /* __ Forward declarations _______________________________________________ */
40 class GFits;
41 class GFilename;
42 class GObservations;
43 class GCTAEventCube;
44 class GCTAObservation;
45 
46 /* __ Constants __________________________________________________________ */
47 namespace gammalib {
48  const std::string extname_cta_migras = "MIGRAS";
49 }
50 
51 
52 /***********************************************************************//**
53  * @class GCTACubeEdisp
54  *
55  * @brief CTA energy dispersion for stacked analysis
56  *
57  * This class implements a mean CTA energy dispersion which provides the
58  * average energy dispersion probability density function for stacked
59  * analysis as function of sky position, energy migration, and true log10
60  * energy.
61  ***************************************************************************/
62 class GCTACubeEdisp : public GBase {
63 
64 public:
65  // Constructors and destructors
66  GCTACubeEdisp(void);
68  explicit GCTACubeEdisp(const GFilename& filename);
69  GCTACubeEdisp(const GCTAEventCube& cube,
70  const double& mmax,
71  const int& nmbins);
72  GCTACubeEdisp(const std::string& wcs,
73  const std::string& coords,
74  const double& x,
75  const double& y,
76  const double& dx,
77  const double& dy,
78  const int& nx,
79  const int& ny,
80  const GEnergies& energies,
81  const double& mmax,
82  const int& nmbins);
83  virtual ~GCTACubeEdisp(void);
84 
85  // Operators
87  double operator()(const GEnergy& ereco,
88  const GEnergy& etrue,
89  const GSkyDir& dir) const;
90 
91  // Methods
92  void clear(void);
93  GCTACubeEdisp* clone(void) const;
94  std::string classname(void) const;
95  void set(const GCTAObservation& obs);
96  void fill(const GObservations& obs, GLog* log = NULL);
97  const GSkyMap& cube(void) const;
98  const GEnergies& energies(void) const;
99  const GNodeArray& migras(void) const;
100  double migra_max(void) const;
101  int offset(const int& imigra, const int& iebin) const;
102  GEbounds ebounds(const GEnergy& obsEng) const;
103  void read(const GFits& fits);
104  void write(GFits& file) const;
105  void load(const GFilename& filename);
106  void save(const GFilename& filename,
107  const bool& clobber = false) const;
108  const GFilename& filename(void) const;
109  std::string print(const GChatter& chatter = NORMAL) const;
110 
111 protected:
112  // Methods
113  void init_members(void);
114  void copy_members(const GCTACubeEdisp& cube);
115  void free_members(void);
116  void clear_cube(void);
117  void fill_cube(const GCTAObservation& obs, GSkyMap* exposure = NULL,
118  GLog* log = NULL);
119  void update(const GEnergy& ereco, const GEnergy& etrue) const;
120  void set_eng_axis(void);
121  void set_migras(const double& mmax, const int& nmbins);
122  void compute_ebounds(void) const;
123 
124  // Members
125  mutable GFilename m_filename; //!< Filename
126  GSkyMap m_cube; //!< Energy dispersion cube
127  GEnergies m_energies; //!< True energy values of cube
128  GNodeArray m_elogmeans; //!< Mean log10TeV energy for the Edisp cube
129  GNodeArray m_migras; //!< Migra bins for the Edisp cube
130 
131 private:
132  // Response table computation cache for 2D access
133  mutable int m_inx1; //!< Index of upper left node
134  mutable int m_inx2; //!< Index of lower left node
135  mutable int m_inx3; //!< Index of upper right node
136  mutable int m_inx4; //!< Index of lower right node
137  mutable double m_wgt1; //!< Weight of upper left node
138  mutable double m_wgt2; //!< Weight of lower left node
139  mutable double m_wgt3; //!< Weight of upper right node
140  mutable double m_wgt4; //!< Weight of lower right node
141  mutable std::vector<GEbounds> m_ebounds; //!< Energy boundaries
142 };
143 
144 
145 /***********************************************************************//**
146  * @brief Return class name
147  *
148  * @return String containing the class name ("GCTACubeEdisp").
149  ***************************************************************************/
150 inline
151 std::string GCTACubeEdisp::classname(void) const
152 {
153  return ("GCTACubeEdisp");
154 }
155 
156 
157 /***********************************************************************//**
158  * @brief Return energy dispersion cube sky map
159  *
160  * @return Energy dispersion cube sky map.
161  *
162  * Returns the energy dispersion cube sky map.
163  ***************************************************************************/
164 inline
165 const GSkyMap& GCTACubeEdisp::cube(void) const
166 {
167  return (m_cube);
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Return energies for energy dispersion cub
173  *
174  * @return Energies for energy dispersion cube
175  *
176  * Returns the true energies of the energy dispersion cube.
177  ***************************************************************************/
178 inline
180 {
181  return (m_energies);
182 }
183 
184 
185 /***********************************************************************//**
186  * @brief Return migra fractions of true and measured photon energy
187  *
188  * @return Offset migra between fractions of true and measured photon energy
189  ***************************************************************************/
190 inline
192 {
193  return (m_migras);
194 }
195 
196 
197 /***********************************************************************//**
198  * @brief Return maximum migra value
199  *
200  * @return Maximum migra value.
201  ***************************************************************************/
202 inline
203 double GCTACubeEdisp::migra_max(void) const
204 {
205  // Get maximum delta value
206  double migra_max = (m_migras.size() > 0) ? m_migras[m_migras.size()-1] : 0.0;
207 
208  // Return
209  return (migra_max);
210 }
211 
212 
213 /***********************************************************************//**
214  * @brief Return edisp cube filename
215  *
216  * @return Energy dispersion cube filename.
217  *
218  * Returns the filename from which the energy dispersion cube was loaded or into which
219  * the cube has been saved.
220  ***************************************************************************/
221 inline
223 {
224  return (m_filename);
225 }
226 
227 
228 /***********************************************************************//**
229  * @brief Return map offset
230  *
231  * @param[in] imigra Migration bin index.
232  * @param[in] iebin Energy bin index.
233  * @return Map offset.
234  *
235  * Returns the offset of the energy dispersion in the sky map for a given
236  * migration bin index and a given energy bin index.
237  ***************************************************************************/
238 inline
239 int GCTACubeEdisp::offset(const int& imigra, const int& iebin) const
240 {
241  return (imigra + iebin*m_migras.size());
242 }
243 
244 #endif /* GCTACUBEEDISP_HPP */
const GFilename & filename(void) const
Return edisp cube filename.
int offset(const int &imigra, const int &iebin) const
Return map offset.
int size(void) const
Return number of nodes in node array.
Definition: GNodeArray.hpp:192
std::string print(const GChatter &chatter=NORMAL) const
Print energy dispersion cube information.
Sky map class.
Definition: GSkyMap.hpp:89
Node array class.
Definition: GNodeArray.hpp:60
const GSkyMap & cube(void) const
Return energy dispersion cube sky map.
std::vector< GEbounds > m_ebounds
Energy boundaries.
GFilename m_filename
Filename.
void copy_members(const GCTACubeEdisp &cube)
Copy class members.
int m_inx3
Index of upper right node.
void free_members(void)
Delete class members.
Definition of interface for all GammaLib classes.
virtual ~GCTACubeEdisp(void)
Destructor.
int m_inx1
Index of upper left node.
void write(GFits &file) const
Write energy dispersion cube into FITS file.
void fill(const GObservations &obs, GLog *log=NULL)
Fill energy dispersion cube from observation container.
void init_members(void)
Initialise class members.
const GEnergies & energies(void) const
Return energies for energy dispersion cub.
void load(const GFilename &filename)
Load energy dispersion cube from FITS file.
FITS file class.
Definition: GFits.hpp:63
GSkyMap m_cube
Energy dispersion cube.
GNodeArray m_migras
Migra bins for the Edisp cube.
void read(const GFits &fits)
Read energy dispersion cube from FITS file.
int m_inx4
Index of lower right node.
Sky map class definition.
Energy container class.
Definition: GEnergies.hpp:60
const std::string extname_cta_migras
double migra_max(void) const
Return maximum migra value.
GCTACubeEdisp(void)
Void constructor.
Information logger interface definition.
Definition: GLog.hpp:62
Node array class interface definition.
CTA event bin container class.
double m_wgt4
Weight of lower right node.
Energy boundaries container class.
Definition: GEbounds.hpp:60
GEbounds ebounds(const GEnergy &obsEng) const
Return boundaries in true energy.
void clear_cube(void)
Clear all pixels in the energy dispersion cube.
Filename class.
Definition: GFilename.hpp:62
Energy container class definition.
Interface class for all GammaLib classes.
Definition: GBase.hpp:52
void set(const GCTAObservation &obs)
Set energy dispersion cube for one CTA observation.
double m_wgt3
Weight of upper right node.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1274
GEnergies m_energies
True energy values of cube.
CTA energy dispersion for stacked analysis.
GChatter
Definition: GTypemaps.hpp:33
void set_migras(const double &mmax, const int &nmbins)
Set nodes for interpolation in migration.
GCTACubeEdisp & operator=(const GCTACubeEdisp &cube)
Assignment operator.
double m_wgt1
Weight of upper left node.
void compute_ebounds(void) const
Compute true energy boundary vector.
Observation container class.
double operator()(const GEnergy &ereco, const GEnergy &etrue, const GSkyDir &dir) const
Return energy dispersion in units of MeV .
void update(const GEnergy &ereco, const GEnergy &etrue) const
Update energy dispersion cube indices and weights cache.
GCTACubeEdisp * clone(void) const
Clone energy dispersion cube.
GNodeArray m_elogmeans
Mean log10TeV energy for the Edisp cube.
void set_eng_axis(void)
Set nodes for interpolation in true energy.
Energy boundaries class interface definition.
double m_wgt2
Weight of lower left node.
const GNodeArray & migras(void) const
Return migra fractions of true and measured photon energy.
int m_inx2
Index of lower left node.
std::string classname(void) const
Return class name.
CTA observation class.
void clear(void)
Clear energy dispersion cube.
void fill_cube(const GCTAObservation &obs, GSkyMap *exposure=NULL, GLog *log=NULL)
Fill energy dispersion cube from observation container.
Sky direction class.
Definition: GSkyDir.hpp:62
void save(const GFilename &filename, const bool &clobber=false) const
Save energy dispersion cube into FITS file.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48