GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelTemporalLightCurve.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelTemporalLightCurve.hpp - Temporal light curve model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2017 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 GModelTemporalLightCurve.hpp
23  * @brief Light curve model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELTEMPORALLIGHTCURVE_HPP
28 #define GMODELTEMPORALLIGHTCURVE_HPP
29 
30 /* __ Includes ___________________________________________________________ */
31 #include <vector>
32 #include <string>
33 #include "GModelPar.hpp"
34 #include "GModelTemporal.hpp"
35 #include "GNodeArray.hpp"
36 #include "GFilename.hpp"
37 #include "GTimeReference.hpp"
38 #include "GTime.hpp"
39 
40 /* __ Forward declarations _______________________________________________ */
41 class GRan;
42 class GXmlElement;
43 
44 
45 /***********************************************************************//**
46  * @class GModelTemporalLightCurve
47  *
48  * @brief Light curve model class
49  *
50  * This class implements a light curve defined by nodes given specified in
51  * a FITS file. The model is defined by
52  *
53  * \f[
54  * S_{\rm t}(t) = r(t) \times {\tt m\_norm}
55  * \f]
56  *
57  * where
58  * \f$r(t)\f$ is the rate defined by linear interpolation between the nodes
59  * in a FITS file, and
60  * \f${\tt m\_norm}\f$ is a normalisation constant.
61  ***************************************************************************/
63 
64 public:
65  // Constructors and destructors
67  explicit GModelTemporalLightCurve(const GXmlElement& xml);
69  const double& norm = 1.0);
71  virtual ~GModelTemporalLightCurve(void);
72 
73  // Operators
75 
76  // Implemented virtual base class methods
77  virtual void clear(void);
78  virtual GModelTemporalLightCurve* clone(void) const;
79  virtual std::string classname(void) const;
80  virtual std::string type(void) const;
81  virtual double eval(const GTime& srcTime,
82  const bool& gradients = false) const;
83  virtual GTimes mc(const double& rate, const GTime& tmin,
84  const GTime& tmax, GRan& ran) 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  const GFilename& filename(void) const;
91  void filename(const GFilename& filename);
92  double norm(void) const;
93  void norm(const double& norm);
94 
95 protected:
96  // Protected methods
97  void init_members(void);
98  void copy_members(const GModelTemporalLightCurve& model);
99  void free_members(void);
100  void load_nodes(const GFilename& filename);
101  void mc_update(const GTime& tmin, const GTime& tmax) const;
102 
103  // Protected members
104  GModelPar m_norm; //!< Normalization factor
105  mutable GNodeArray m_nodes; //!< Time nodes of function
106  std::vector<double> m_values; //!< Function values at nodes
107  GFilename m_filename; //!< Name of file function
108  GTimeReference m_timeref; //!< Time reference
109  GTime m_tmin; //!< Minimum time of model
110  GTime m_tmax; //!< Maximum time of model
111 
112  // Cached members for MC
113  mutable GTime m_mc_tmin; //!< Minimum time
114  mutable GTime m_mc_tmax; //!< Maximum time
115  mutable double m_mc_norm; //!< Light curve normalisation
116  mutable double m_mc_eff_duration; //!< Effective duration
117  mutable std::vector<double> m_mc_cum; //!< Cumulative distribution
118  mutable std::vector<double> m_mc_slope; //!< Slope of interval
119  mutable std::vector<double> m_mc_offset; //!< Offset of interval
120  mutable std::vector<double> m_mc_time; //!< Start time of interval
121  mutable std::vector<double> m_mc_dt; //!< Length of interval
122 };
123 
124 
125 /***********************************************************************//**
126  * @brief Return class name
127  *
128  * @return String containing the class name ("GModelTemporalLightCurve").
129  ***************************************************************************/
130 inline
131 std::string GModelTemporalLightCurve::classname(void) const
132 {
133  return ("GModelTemporalLightCurve");
134 }
135 
136 
137 /***********************************************************************//**
138  * @brief Return model type
139  *
140  * @return "LightCurve".
141  *
142  * Returns the type of the temporal model.
143  ***************************************************************************/
144 inline
145 std::string GModelTemporalLightCurve::type(void) const
146 {
147  return "LightCurve";
148 }
149 
150 
151 /***********************************************************************//**
152  * @brief Return normalization factor
153  *
154  * @return Normalization factor.
155  *
156  * Returns the normalization factor.
157  ***************************************************************************/
158 inline
160 {
161  return (m_norm.value());
162 }
163 
164 
165 /***********************************************************************//**
166  * @brief Set normalization factor
167  *
168  * @param[in] norm Normalization factor.
169  *
170  * Sets the normalization factor.
171  ***************************************************************************/
172 inline
174 {
175  m_norm.value(norm);
176  return;
177 }
178 
179 
180 /***********************************************************************//**
181  * @brief Return file name
182  *
183  * @return Name of node file.
184  *
185  * Returns the name of the file function node file.
186  ***************************************************************************/
187 inline
189 {
190  return (m_filename);
191 }
192 
193 
194 /***********************************************************************//**
195  * @brief Loads nodes from node file and set filename
196  *
197  * @param[in] filename Node file name.
198  *
199  * Loads the nodes from a file function node file and sets the filename.
200  ***************************************************************************/
201 inline
203 {
204  load_nodes(filename);
205  return;
206 }
207 
208 #endif /* GMODELTEMPORALLIGHTCURVE_HPP */
std::vector< double > m_mc_time
Start time of interval.
std::vector< double > m_mc_cum
Cumulative distribution.
void copy_members(const GModelTemporalLightCurve &model)
Copy class members.
GTime m_tmax
Maximum time of model.
std::vector< double > m_mc_slope
Slope of interval.
GTimeReference m_timeref
Time reference.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
Node array class.
Definition: GNodeArray.hpp:60
std::vector< double > m_mc_offset
Offset of interval.
void mc_update(const GTime &tmin, const GTime &tmax) const
Set MC pre-computation cache.
GModelTemporalLightCurve(void)
Void constructor.
Abstract temporal model base class.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print light curve information.
const GFilename & filename(void) const
Return file name.
virtual ~GModelTemporalLightCurve(void)
Destructor.
virtual std::string classname(void) const
Return class name.
XML element node class.
Definition: GXmlElement.hpp:48
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
double m_mc_norm
Light curve normalisation.
GFilename m_filename
Name of file function.
void free_members(void)
Delete class members.
Time container class.
Definition: GTimes.hpp:45
Model parameter class interface definition.
std::vector< double > m_values
Function values at nodes.
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const
Returns vector of random event times.
GModelPar m_norm
Normalization factor.
Model parameter class.
Definition: GModelPar.hpp:87
Node array class interface definition.
Abstract temporal model base class interface definition.
virtual void read(const GXmlElement &xml)
Read model from XML element.
Filename class.
Definition: GFilename.hpp:62
Time reference class interface definition.
virtual void clear(void)
Clear light curve model.
GChatter
Definition: GTypemaps.hpp:33
virtual double eval(const GTime &srcTime, const bool &gradients=false) const
Evaluate function.
GTime m_tmin
Minimum time of model.
void load_nodes(const GFilename &filename)
Load nodes from file.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelTemporalLightCurve * clone(void) const
Clone light curve model.
Light curve model class.
virtual GModelTemporalLightCurve & operator=(const GModelTemporalLightCurve &model)
Assignment operator.
GNodeArray m_nodes
Time nodes of function.
double value(void) const
Return parameter value.
Implements a time reference.
virtual std::string type(void) const
Return model type.
double norm(void) const
Return normalization factor.
Time class interface definition.
std::vector< double > m_mc_dt
Length of interval.
void init_members(void)
Initialise class members.
Filename class interface definition.
double m_mc_eff_duration
Effective duration.