GammaLib  2.0.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GCTAModelSpatialLookup.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GCTAModelSpatialLookup.hpp - Spatial lookup table model *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2019 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 GCTAModelSpatialLookup.hpp
23  * @brief Spatial lookup table model interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GCTAMODELSPATIALLOOKUP_HPP
28 #define GCTAMODELSPATIALLOOKUP_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <string>
32 #include "GCTAModelSpatial.hpp"
33 #include "GCTAResponseTable.hpp"
34 
35 /* __ Forward declarations _______________________________________________ */
36 class GFilename;
37 class GXmlElement;
38 class GCTAInstDir;
39 class GEnergy;
40 class GTime;
41 class GEbounds;
42 class GFitsTable;
43 class GFitsBinTable;
44 class GObservations;
45 class GCTAObservation;
46 
47 /* __ Constants __________________________________________________________ */
48 namespace gammalib {
49  const std::string extname_cta_spatial_lookup = "RADIAL BACKGROUND LOOKUP";
50 }
51 
52 
53 /***********************************************************************//**
54  * @class GCTAModelSpatialLookup
55  *
56  * @brief Spatial lookup table model class
57  ***************************************************************************/
59 
60 public:
61  // Constructors and destructors
63  explicit GCTAModelSpatialLookup(const GFilename& filename);
65  explicit GCTAModelSpatialLookup(const GXmlElement& xml);
66  GCTAModelSpatialLookup(const double& maxrad,
67  const double& radbin,
68  const GEbounds& ebds);
70  virtual ~GCTAModelSpatialLookup(void);
71 
72  // Operators
74 
75  // Implemented pure virtual methods
76  virtual void clear(void);
77  virtual GCTAModelSpatialLookup* clone(void) const;
78  virtual std::string classname(void) const;
79  virtual std::string type(void) const;
80  virtual double eval(const GCTAInstDir& dir,
81  const GEnergy& energy,
82  const GTime& time,
83  const bool& gradients = false) const;
84  virtual double mc_max_value(const GCTAObservation& obs) const;
85  virtual void read(const GXmlElement& xml);
86  virtual void write(GXmlElement& xml) const;
87  virtual std::string print(const GChatter& chatter = NORMAL) const;
88 
89  // Other methods
90  void fill(const GCTAObservation& obs);
91  void fill(const GObservations& obs);
92  const GCTAResponseTable& table(void) const;
93  void table(const GCTAResponseTable& table);
94  void read(const GFitsTable& table);
95  void write(GFitsBinTable& table) const;
96  void load(const GFilename& filename);
97  void save(const GFilename& filename,
98  const bool& clobber = false) const;
99  double norm(void) const;
100  void norm(const double& norm);
101 
102 protected:
103  // Protected methods
104  void init_members(void);
105  void copy_members(const GCTAModelSpatialLookup& model);
106  void free_members(void);
107  void prepare_table(void);
108  void normalise_table(void);
109  int table_index(const int& ienergy, const int& itheta) const;
110  void fill_buffer(const GCTAObservation& obs, std::vector<double>& buffer);
111  void set_from_buffer(const std::vector<double>& buffer);
112 
113  // Protected members
114  GFilename m_filename; //!< Name of lookup table
115  GCTAResponseTable m_lookup; //!< Lookup table
116  GModelPar m_norm; //!< Normalization factor
117  int m_inx_energy; //!< Energy index
118  int m_inx_theta; //!< Theta index
119 };
120 
121 
122 /***********************************************************************//**
123  * @brief Return class name
124  *
125  * @return String containing the class name ("GCTAModelSpatialLookup").
126  ***************************************************************************/
127 inline
128 std::string GCTAModelSpatialLookup::classname(void) const
129 {
130  return ("GCTAModelSpatialLookup");
131 }
132 
133 
134 /***********************************************************************//**
135  * @brief Return model type
136  *
137  * @return Model type "LookupTable".
138  ***************************************************************************/
139 inline
140 std::string GCTAModelSpatialLookup::type(void) const
141 {
142  return ("LookupTable");
143 }
144 
145 
146 /***********************************************************************//**
147  * @brief Return maximum function value for Monte Carlo simulations
148  *
149  * @param[in] obs CTA Observation.
150  * @return Maximum function value for Monte Carlo simulations.
151  *
152  * This method always returns 1.
153  ***************************************************************************/
154 inline
156 {
157  return 1.0;
158 }
159 
160 
161 /***********************************************************************//**
162  * @brief Return lookup table
163  *
164  * @return Lookup table.
165  *
166  * Returns the lookup table.
167  ***************************************************************************/
168 inline
170 {
171  return m_lookup;
172 }
173 
174 
175 /***********************************************************************//**
176  * @brief Get lookup table model normalisation
177  *
178  * @return Lookup table model normalisation.
179  *
180  * Returns the normalisation of the lookup table model.
181  ***************************************************************************/
182 inline
184 {
185  return (m_norm.value());
186 }
187 
188 
189 /***********************************************************************//**
190  * @brief Set lookup table model normalisation
191  *
192  * @param[in] norm Lookup table model normalisation.
193  *
194  * Set the normalisation of the lookup table model.
195  ***************************************************************************/
196 inline
198 {
199  m_norm.value(norm);
200  return;
201 }
202 
203 #endif /* GCTAMODELSPATIALLOOKUP_HPP */
Abstract spatial model class.
double norm(void) const
Get lookup table model normalisation.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print lookup table information.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
virtual std::string type(void) const
Return model type.
void prepare_table(void)
Prepare lookup table indices.
XML element node class.
Definition: GXmlElement.hpp:48
void fill_buffer(const GCTAObservation &obs, std::vector< double > &buffer)
Fill buffer from events in CTA observation.
Time class.
Definition: GTime.hpp:55
const GCTAResponseTable & table(void) const
Return lookup table.
Model parameter class.
Definition: GModelPar.hpp:87
virtual void read(const GXmlElement &xml)
Read model from XML element.
CTA response table class definition.
void set_from_buffer(const std::vector< double > &buffer)
Set lookup table from buffer.
void init_members(void)
Initialise class members.
Energy boundaries container class.
Definition: GEbounds.hpp:60
GCTAModelSpatialLookup(void)
Void constructor.
void save(const GFilename &filename, const bool &clobber=false) const
Save lookup table into FITS file.
void load(const GFilename &filename)
Load lookup table.
Filename class.
Definition: GFilename.hpp:62
GModelPar m_norm
Normalization factor.
GFilename m_filename
Name of lookup table.
virtual GCTAModelSpatialLookup & operator=(const GCTAModelSpatialLookup &model)
Assignment operator.
int table_index(const int &ienergy, const int &itheta) const
Return index of lookup table element.
virtual void clear(void)
Clear instance.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
const std::string extname_cta_spatial_lookup
void normalise_table(void)
Normalise lookup table.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Observation container class.
virtual GCTAModelSpatialLookup * clone(void) const
Clone instance.
Spatial lookup table model class.
Abstract spatial model class interface definition.
virtual double mc_max_value(const GCTAObservation &obs) const
Return maximum function value for Monte Carlo simulations.
double value(void) const
Return parameter value.
FITS binary table class.
void fill(const GCTAObservation &obs)
Fill lookup table with events from one CTA observation.
GCTAResponseTable m_lookup
Lookup table.
CTA response table class.
CTA instrument direction class.
Definition: GCTAInstDir.hpp:63
CTA observation class.
virtual double eval(const GCTAInstDir &dir, const GEnergy &energy, const GTime &time, const bool &gradients=false) const
Evaluate function.
void free_members(void)
Delete class members.
virtual ~GCTAModelSpatialLookup(void)
Destructor.
void copy_members(const GCTAModelSpatialLookup &model)
Copy class members.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
virtual std::string classname(void) const
Return class name.