GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelTemporalPhaseCurve.hpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelTemporalPhaseCurve.hpp - Temporal phase 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 GModelTemporalPhaseCurve.hpp
23  * @brief Temporal phase curve model class interface definition
24  * @author Juergen Knoedlseder
25  */
26 
27 #ifndef GMODELTEMPORALPHASECURVE_HPP
28 #define GMODELTEMPORALPHASECURVE_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 "GTime.hpp"
38 
39 /* __ Forward declarations _______________________________________________ */
40 class GRan;
41 class GXmlElement;
42 
43 
44 /***********************************************************************//**
45  * @class GModelTemporalPhaseCurve
46  *
47  * @brief Temporal phase curve model class
48  *
49  * This class implements a temporal variation based on the phase
50  * \f$\Phi(t)\f$ that is computed using
51  *
52  * \f[
53  * \Phi(t) = \Phi_0 + f(t-t_0) + \frac{1}{2}\dot{f} (t-t_0)^2 +
54  * \frac{1}{6}\ddot{f} (t-t_0)^3
55  * \f]
56  *
57  * where
58  * \f$t_0\f$ is a reference time,
59  * \f$\Phi_0\f$ is the phase at the reference time,
60  * \f$f\f$ is the variation frequency at the reference time,
61  * \f$\dot{f}\f$ is the first derivative of the variation frequency at the
62  * reference time, and
63  * \f$\ddot{f}\f$ is the second derivative of the variation frequency at the
64  * reference time.
65  *
66  * The temporal variation is then computed using
67  *
68  * \f[
69  * S_{\rm t}(t) = r(\Phi(t)) \times {\tt m\_norm}
70  * \f]
71  *
72  * where \f$r(\Phi(t))\f$ is the rate defined by linear interpolation between
73  * the nodes in a FITS file, and \f${\tt m\_norm}\f$ is a normalisation
74  * constant.
75  ***************************************************************************/
77 
78 public:
79  // Constructors and destructors
81  explicit GModelTemporalPhaseCurve(const GXmlElement& xml);
83  const GTime& mjd,
84  const double& phase,
85  const double& f0,
86  const double& f1,
87  const double& f2,
88  const double& norm = 1.0,
89  const bool& normalize = true);
91  virtual ~GModelTemporalPhaseCurve(void);
92 
93  // Operators
95 
96  // Implemented virtual base class methods
97  virtual void clear(void);
98  virtual GModelTemporalPhaseCurve* clone(void) const;
99  virtual std::string classname(void) const;
100  virtual std::string type(void) const;
101  virtual double eval(const GTime& srcTime,
102  const bool& gradients = false) const;
103  virtual GTimes mc(const double& rate, const GTime& tmin,
104  const GTime& tmax, GRan& ran) const;
105  virtual void read(const GXmlElement& xml);
106  virtual void write(GXmlElement& xml) const;
107  virtual std::string print(const GChatter& chatter = NORMAL) const;
108 
109  // Other methods
110  const GFilename& filename(void) const;
111  void filename(const GFilename& filename);
112  double norm(void) const;
113  void norm(const double& norm);
114  GTime mjd(void) const;
115  void mjd(const GTime& time);
116  double phase(void) const;
117  double phase(const GTime& time) const;
118  void phase(const double& phase);
119  double value(const double& phase) const;
120  double f0(void) const;
121  void f0(const double& f0);
122  double f1(void) const;
123  void f1(const double& f1);
124  double f2(void) const;
125  void f2(const double& f2);
126  bool normalize(void) const;
127 
128 protected:
129  // Protected methods
130  void init_members(void);
131  void copy_members(const GModelTemporalPhaseCurve& model);
132  void free_members(void);
133  void load_nodes(const GFilename& filename);
134  void normalize_nodes(void);
135 
136  // Protected parameter members
137  GModelPar m_norm; //!< Normalization factor
138  GModelPar m_mjd; //!< Reference MJD
139  GModelPar m_phase; //!< Phase at reference MJD
140  GModelPar m_f0; //!< Frequency at reference MJD
141  GModelPar m_f1; //!< First freq. derivative at reference MJD
142  GModelPar m_f2; //!< Second freq. derivative at reference MJD
143  bool m_normalize; //!< Normalize phase curve (default: true)
144  bool m_has_normalize; //!< XML has normalize attribute
145 
146  // Protected members
147  mutable GNodeArray m_nodes; //!< Phase values of nodes
148  std::vector<double> m_values; //!< Function values at nodes
149  double m_scale; //!< Scale factor due to normalization
150  GFilename m_filename; //!< Name of phase file function
151 };
152 
153 
154 /***********************************************************************//**
155  * @brief Return class name
156  *
157  * @return String containing the class name ("GModelTemporalPhaseCurve").
158  ***************************************************************************/
159 inline
160 std::string GModelTemporalPhaseCurve::classname(void) const
161 {
162  return ("GModelTemporalPhaseCurve");
163 }
164 
165 
166 /***********************************************************************//**
167  * @brief Return model type
168  *
169  * @return "PhaseCurve".
170  *
171  * Returns the type of the temporal model.
172  ***************************************************************************/
173 inline
174 std::string GModelTemporalPhaseCurve::type(void) const
175 {
176  return ("PhaseCurve");
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 
209 /***********************************************************************//**
210  * @brief Return normalization factor
211  *
212  * @return Normalization factor.
213  *
214  * Returns the normalization factor.
215  ***************************************************************************/
216 inline
218 {
219  return (m_norm.value());
220 }
221 
222 
223 /***********************************************************************//**
224  * @brief Set normalization factor
225  *
226  * @param[in] norm Normalization factor.
227  *
228  * Sets the normalization factor.
229  ***************************************************************************/
230 inline
232 {
233  m_norm.value(norm);
234  return;
235 }
236 
237 
238 /***********************************************************************//**
239  * @brief Return reference Modified Julian Day
240  *
241  * @return Reference Modified Julian Day.
242  *
243  * Returns the reference Modified Julian Day.
244  ***************************************************************************/
245 inline
247 {
248  GTime time;
249  time.mjd(m_mjd.value());
250  return (time);
251 }
252 
253 
254 /***********************************************************************//**
255  * @brief Set reference Modified Julian Day
256  *
257  * @param[in] mjd Reference Modified Julian Day.
258  *
259  * Sets the reference Modified Julian Day.
260  ***************************************************************************/
261 inline
263 {
264  m_mjd.value(mjd.mjd());
265  return;
266 }
267 
268 
269 /***********************************************************************//**
270  * @brief Return phase at reference Modified Julian Day
271  *
272  * @return Phase at reference Modified Julian Day.
273  *
274  * Returns the phase at reference Modified Julian Day.
275  ***************************************************************************/
276 inline
278 {
279  return (m_phase.value());
280 }
281 
282 
283 /***********************************************************************//**
284  * @brief Set phase at reference Modified Julian Day
285  *
286  * @param[in] phase Phase at reference Modified Julian Day.
287  *
288  * Sets the phase at reference Modified Julian Day.
289  ***************************************************************************/
290 inline
291 void GModelTemporalPhaseCurve::phase(const double& phase)
292 {
293  m_phase.value(phase);
294  return;
295 }
296 
297 
298 /***********************************************************************//**
299  * @brief Return frequency at reference Modified Julian Day
300  *
301  * @return Frequency at reference Modified Julian Day.
302  *
303  * Returns the frequency at reference Modified Julian Day.
304  ***************************************************************************/
305 inline
307 {
308  return (m_f0.value());
309 }
310 
311 
312 /***********************************************************************//**
313  * @brief Set frequency at reference Modified Julian Day
314  *
315  * @param[in] f0 Frequency at reference Modified Julian Day.
316  *
317  * Sets the frequency at reference Modified Julian Day.
318  ***************************************************************************/
319 inline
320 void GModelTemporalPhaseCurve::f0(const double& f0)
321 {
322  m_f0.value(f0);
323  return;
324 }
325 
326 
327 /***********************************************************************//**
328  * @brief Return first frequency derivative at reference Modified Julian Day
329  *
330  * @return First frequency derivative at reference Modified Julian Day.
331  *
332  * Returns the first frequency derivative at reference Modified Julian Day.
333  ***************************************************************************/
334 inline
336 {
337  return (m_f1.value());
338 }
339 
340 
341 /***********************************************************************//**
342  * @brief Set first frequency derivative at reference Modified Julian Day
343  *
344  * @param[in] f1 First frequency derivative at reference Modified Julian Day.
345  *
346  * Sets the first frequency derivative at reference Modified Julian Day.
347  ***************************************************************************/
348 inline
349 void GModelTemporalPhaseCurve::f1(const double& f1)
350 {
351  m_f1.value(f1);
352  return;
353 }
354 
355 
356 /***********************************************************************//**
357  * @brief Return second frequency derivative at reference Modified Julian Day
358  *
359  * @return Second frequency derivative at reference Modified Julian Day.
360  *
361  * Returns the second frequency derivative at reference Modified Julian Day.
362  ***************************************************************************/
363 inline
365 {
366  return (m_f2.value());
367 }
368 
369 
370 /***********************************************************************//**
371  * @brief Set second frequency derivative at reference Modified Julian Day
372  *
373  * @param[in] f2 Second frequency derivative at reference Modified Julian Day.
374  *
375  * Sets the second frequency derivative at reference Modified Julian Day.
376  ***************************************************************************/
377 inline
378 void GModelTemporalPhaseCurve::f2(const double& f2)
379 {
380  m_f2.value(f2);
381  return;
382 }
383 
384 
385 /***********************************************************************//**
386  * @brief Return normalization flag
387  *
388  * @return True if the phase curve has been normalized, false otherwise.
389  *
390  * Signals whether a phase curve has been normalized or not.
391  ***************************************************************************/
392 inline
394 {
395  return (m_normalize);
396 }
397 
398 #endif /* GMODELTEMPORALPHASECURVE_HPP */
bool m_has_normalize
XML has normalize attribute.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
Node array class.
Definition: GNodeArray.hpp:60
bool normalize(void) const
Return normalization flag.
GNodeArray m_nodes
Phase values of nodes.
Abstract temporal model base class.
GTime mjd(void) const
Return reference Modified Julian Day.
void init_members(void)
Initialise class members.
GModelPar m_f0
Frequency at reference MJD.
bool m_normalize
Normalize phase curve (default: true)
XML element node class.
Definition: GXmlElement.hpp:48
double m_scale
Scale factor due to normalization.
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:55
std::vector< double > m_values
Function values at nodes.
double f2(void) const
Return second frequency derivative at reference Modified Julian Day.
virtual GModelTemporalPhaseCurve & operator=(const GModelTemporalPhaseCurve &model)
Assignment operator.
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const
Return vector of random event times.
Time container class.
Definition: GTimes.hpp:45
Model parameter class interface definition.
virtual std::string type(void) const
Return model type.
Model parameter class.
Definition: GModelPar.hpp:87
Node array class interface definition.
Abstract temporal model base class interface definition.
Filename class.
Definition: GFilename.hpp:62
void load_nodes(const GFilename &filename)
Load nodes from file.
double f0(void) const
Return frequency at reference Modified Julian Day.
void copy_members(const GModelTemporalPhaseCurve &model)
Copy class members.
GChatter
Definition: GTypemaps.hpp:33
void free_members(void)
Delete class members.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual ~GModelTemporalPhaseCurve(void)
Destructor.
GModelPar m_f1
First freq. derivative at reference MJD.
GModelPar m_norm
Normalization factor.
double phase(void) const
Return phase at reference Modified Julian Day.
double value(const double &phase) const
Evaluate phase curve value for a given phase.
const GFilename & filename(void) const
Return file name.
double norm(void) const
Return normalization factor.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print phase curve information.
GModelPar m_f2
Second freq. derivative at reference MJD.
GModelTemporalPhaseCurve(void)
Void constructor.
double value(void) const
Return parameter value.
double f1(void) const
Return first frequency derivative at reference Modified Julian Day.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const
Evaluate function.
double mjd(void) const
Return time in Modified Julian Days (TT)
Definition: GTime.cpp:320
virtual GModelTemporalPhaseCurve * clone(void) const
Clone phase curve.
GModelPar m_phase
Phase at reference MJD.
GModelPar m_mjd
Reference MJD.
void normalize_nodes(void)
Normalise nodes.
GFilename m_filename
Name of phase file function.
Temporal phase curve model class.
Time class interface definition.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Filename class interface definition.
virtual std::string classname(void) const
Return class name.
virtual void clear(void)
Clear phase curve.