GammaLib  2.0.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelTemporalLightCurve.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelTemporalLightCurve.cpp - Temporal light curve model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2017-2020 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.cpp
23  * @brief Light curve model class interface implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include "GTools.hpp"
32 #include "GException.hpp"
35 #include "GFits.hpp"
36 
37 /* __ Constants __________________________________________________________ */
38 
39 /* __ Globals ____________________________________________________________ */
41 const GModelTemporalRegistry g_temporal_lightcurve_registry(&g_temporal_lightcurve_seed);
42 
43 /* __ Method name definitions ____________________________________________ */
44 #define G_READ "GModelTemporalLightCurve::read(GXmlElement&)"
45 #define G_WRITE "GModelTemporalLightCurve::write(GXmlElement&)"
46 #define G_LOAD_NODES "GModelTemporalLightCurve::load_nodes(GFilename&)"
47 
48 /* __ Macros _____________________________________________________________ */
49 
50 /* __ Coding definitions _________________________________________________ */
51 
52 /* __ Debug definitions __________________________________________________ */
53 
54 
55 /*==========================================================================
56  = =
57  = Constructors/destructors =
58  = =
59  ==========================================================================*/
60 
61 /***********************************************************************//**
62  * @brief Void constructor
63  ***************************************************************************/
65 {
66  // Initialise members
67  init_members();
68 
69  // Return
70  return;
71 }
72 
73 
74 /***********************************************************************//**
75  * @brief File constructor
76  *
77  * @param[in] filename File name of nodes.
78  * @param[in] norm Normalization factor.
79  *
80  * Constructs light curve model from a list of nodes that is found in the
81  * specified FITS file. See the load_nodes() method for more information
82  * about the expected structure of the file.
83  ***************************************************************************/
85  const double& norm) :
87 {
88  // Initialise members
89  init_members();
90 
91  // Load nodes
92  load_nodes(filename);
93 
94  // Set normalization
95  m_norm.value(norm);
96 
97  // Return
98  return;
99 }
100 
101 
102 /***********************************************************************//**
103  * @brief XML constructor
104  *
105  * @param[in] xml XML element.
106  *
107  * Constructs light curve model by extracting information from an XML
108  * element. See the read() method for more information about the expected
109  * structure of the XML element.
110  ***************************************************************************/
113 {
114  // Initialise members
115  init_members();
116 
117  // Read information from XML element
118  read(xml);
119 
120  // Return
121  return;
122 }
123 
124 
125 /***********************************************************************//**
126  * @brief Copy constructor
127  *
128  * @param[in] model Light curve model.
129  ***************************************************************************/
131  GModelTemporal(model)
132 {
133  // Initialise members
134  init_members();
135 
136  // Copy members
137  copy_members(model);
138 
139  // Return
140  return;
141 }
142 
143 
144 /***********************************************************************//**
145  * @brief Destructor
146  ***************************************************************************/
148 {
149  // Free members
150  free_members();
151 
152  // Return
153  return;
154 }
155 
156 
157 /*==========================================================================
158  = =
159  = Operators =
160  = =
161  ==========================================================================*/
162 
163 /***********************************************************************//**
164  * @brief Assignment operator
165  *
166  * @param[in] model Light curve model.
167  * @return Light curve model.
168  ***************************************************************************/
170 {
171  // Execute only if object is not identical
172  if (this != &model) {
173 
174  // Copy base class members
175  this->GModelTemporal::operator=(model);
176 
177  // Free members
178  free_members();
179 
180  // Initialise members
181  init_members();
182 
183  // Copy members
184  copy_members(model);
185 
186  } // endif: object was not identical
187 
188  // Return
189  return *this;
190 }
191 
192 
193 /*==========================================================================
194  = =
195  = Public methods =
196  = =
197  ==========================================================================*/
198 
199 /***********************************************************************//**
200  * @brief Clear light curve model
201  ***************************************************************************/
203 {
204  // Free class members (base and derived classes, derived class first)
205  free_members();
207 
208  // Initialise members
210  init_members();
211 
212  // Return
213  return;
214 }
215 
216 
217 /***********************************************************************//**
218  * @brief Clone light curve model
219  *
220  * @return Pointer to deep copy of light curve model.
221  ***************************************************************************/
223 {
224  // Clone constant temporal model
225  return new GModelTemporalLightCurve(*this);
226 }
227 
228 
229 /***********************************************************************//**
230  * @brief Evaluate function
231  *
232  * @param[in] srcTime True photon arrival time (not used).
233  * @param[in] gradients Compute gradients?
234  * @return Value of light curve model.
235  *
236  * Computes
237  *
238  * \f[
239  * S_{\rm t}(t) = r(t) \times {\tt m\_norm}
240  * \f]
241  *
242  * where
243  * \f$r(t)\f$ is the light curve, computed by linear interpolation between
244  * the nodes in a FITS file, and \f${\tt m\_norm}\f$ is the normalization
245  * constant.
246  *
247  * If the @p gradients flag is true the method will also evaluate the partial
248  * derivatives of the model with respect to the normalization parameter using
249  *
250  * \f[
251  * \frac{\delta S_{\rm t}(t)}{\delta {\tt m\_norm}} = r(t)
252  * \f]
253  ***************************************************************************/
254 double GModelTemporalLightCurve::eval(const GTime& srcTime,
255  const bool& gradients) const
256 {
257  // Initialise value
258  double value = 0.0;
259 
260  // Optionally initialise gradient
261  if (gradients) {
262  m_norm.factor_gradient(0.0);
263  }
264 
265  // Set value if the time is within the validity range
266  if (srcTime >= m_tmin && srcTime <= m_tmax) {
267 
268  // Interpolate file function
269  double func = m_nodes.interpolate(srcTime.convert(m_timeref), m_values);
270 
271  // Compute function value
272  value = m_norm.value() * func;
273 
274  // Optionally compute gradients
275  if (gradients) {
276 
277  // Compute partial derivatives of the parameter values
278  double g_norm = (m_norm.is_free()) ? m_norm.scale() * func : 0.0;
279 
280  // Set gradients
281  m_norm.factor_gradient(g_norm);
282 
283  } // endif: gradient computation was requested
284 
285  } // endif: time was within the validity range
286 
287  // Return
288  return value;
289 }
290 
291 
292 /***********************************************************************//**
293  * @brief Returns vector of random event times
294  *
295  * @param[in] rate Mean event rate (events per second).
296  * @param[in] tmin Minimum event time.
297  * @param[in] tmax Maximum event time.
298  * @param[in,out] ran Random number generator.
299  *
300  * This method returns a vector of random event times between @p tmin and
301  * @p tmax assuming a light curve specified in a FITS file.
302  ***************************************************************************/
303 GTimes GModelTemporalLightCurve::mc(const double& rate, const GTime& tmin,
304  const GTime& tmax, GRan& ran) const
305 {
306  // Allocates empty vector of times
307  GTimes times;
308 
309  // Update Monte Carlo cache
310  mc_update(tmin, tmax);
311 
312  // Continue only if effective duration is positive and cache is not empty
313  if (m_mc_eff_duration > 0.0 && m_mc_cum.size() > 0) {
314 
315  // Compute mean number of times by multiplying the rate with the
316  // effective duration. Note that the light curve normalization factor
317  // is already included in the effective rate, hence we should not
318  // multiply it here again (see #2181).
319  double lambda = rate * m_mc_eff_duration;
320 
321  // Compute number of times to be sampled
322  int ntimes = int(ran.poisson(lambda)+0.5);
323 
324  // Loop over number of times
325  for (int i = 0; i < ntimes; ++i) {
326 
327  // Determine in which bin we reside
328  int inx = 0;
329  if (m_mc_cum.size() > 1) {
330  double u = ran.uniform();
331  for (inx = m_mc_cum.size()-1; inx > 0; --inx) {
332  if (m_mc_cum[inx-1] <= u) {
333  break;
334  }
335  }
336  }
337 
338  // Get random time
339  double seconds;
340  if (m_mc_slope[inx] == 0.0) {
341  seconds = m_mc_dt[inx] * ran.uniform() + m_mc_time[inx];
342  }
343  else {
344  seconds = (std::sqrt(m_mc_offset[inx]*m_mc_offset[inx] +
345  2.0 * m_mc_slope[inx] * ran.uniform()) -
346  m_mc_offset[inx]) / m_mc_slope[inx] + m_mc_time[inx];
347  }
348 
349  // Append random time
350  GTime time(seconds, m_timeref);
351  times.append(time);
352 
353  } // endfor: looped over times
354 
355  } // endif: cache was valid
356 
357  // Return vector of times
358  return times;
359 }
360 
361 
362 /***********************************************************************//**
363  * @brief Read model from XML element
364  *
365  * @param[in] xml XML element.
366  *
367  * Reads the temporal information from an XML element. The XML element should
368  * have the format
369  *
370  * <temporalModel type="LightCurve" file="..">
371  * <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="1"/>
372  * </temporalModel>
373  ***************************************************************************/
375 {
376  // Get parameter pointers
378 
379  // Read parameters
380  m_norm.read(*norm);
381 
382  // Load nodes from file
384 
385  // Return
386  return;
387 }
388 
389 
390 /***********************************************************************//**
391  * @brief Write model into XML element
392  *
393  * @param[in] xml XML element.
394  *
395  * @exception GExpection::invalid_value
396  * Invalid XML format encountered.
397  *
398  * Writes the temporal information into an XML element in the format
399  *
400  * <temporalModel type="LightCurve" file="..">
401  * <parameter name="Normalization" scale="1" value="1" min="0.1" max="10" free="1"/>
402  * </temporalModel>
403  ***************************************************************************/
405 {
406  // Set model type
407  if (xml.attribute("type") == "") {
408  xml.attribute("type", type());
409  }
410 
411  // Verify model type
412  if (xml.attribute("type") != type()) {
413  std::string msg = "Temporal model of type "+xml.attribute("type")+
414  " encountered while \""+type()+"\" was expected.";
416  }
417 
418  // Get XML parameters
420 
421  // Write parameters
422  m_norm.write(*norm);
423 
424  // Set file attribute
426 
427  // Return
428  return;
429 }
430 
431 
432 /***********************************************************************//**
433  * @brief Print light curve information
434  *
435  * @param[in] chatter Chattiness.
436  * @return String containing light curve information.
437  ***************************************************************************/
438 std::string GModelTemporalLightCurve::print(const GChatter& chatter) const
439 {
440  // Initialise result string
441  std::string result;
442 
443  // Continue only if chatter is not silent
444  if (chatter != SILENT) {
445 
446  // Append header
447  result.append("=== GModelTemporalLightCurve ===");
448 
449  // Append information
450  result.append("\n"+gammalib::parformat("Light curve file"));
451  result.append(m_filename.url());
452  result.append("\n"+gammalib::parformat("Number of parameters"));
453  result.append(gammalib::str(size()));
454  for (int i = 0; i < size(); ++i) {
455  result.append("\n"+m_pars[i]->print(chatter));
456  }
457 
458  // Append reference MJD and time range
459  result.append("\n"+gammalib::parformat("Reference MDJ"));
460  result.append(gammalib::str(m_timeref.mjdref()));
461  result.append("\n"+gammalib::parformat("Time range"));
462  result.append(gammalib::str(m_tmin.convert(m_timeref)));
463  result.append(" - ");
464  result.append(gammalib::str(m_tmax.convert(m_timeref)));
465  result.append(" "+m_timeref.timeunit());
466  result.append(" ("+m_timeref.timesys()+")");
467 
468  // Append node information
469  result.append("\n"+gammalib::parformat("Number of nodes"));
470  result.append(gammalib::str(m_nodes.size()));
471  for (int i = 0; i < m_nodes.size(); ++i) {
472  result.append("\n");
473  result.append(gammalib::parformat(" Time "+gammalib::str(m_nodes[i])+" s"));
474  result.append(gammalib::str(m_values[i]));
475  }
476 
477  } // endif: chatter was not silent
478 
479  // Return result
480  return result;
481 }
482 
483 
484 /*==========================================================================
485  = =
486  = Private methods =
487  = =
488  ==========================================================================*/
489 
490 /***********************************************************************//**
491  * @brief Initialise class members
492  ***************************************************************************/
494 {
495  // Initialise normalisation parameter
496  m_norm.clear();
497  m_norm.name("Normalization");
498  m_norm.unit("(relative value)");
499  m_norm.scale(1.0);
500  m_norm.value(1.0);
501  m_norm.range(0.0,1000.0);
502  m_norm.fix();
503  m_norm.gradient(0.0);
504  m_norm.has_grad(true);
505 
506  // Set parameter pointer(s)
507  m_pars.clear();
508  m_pars.push_back(&m_norm);
509 
510  // Initialise members
511  m_nodes.clear();
512  m_values.clear();
513  m_filename.clear();
514  m_timeref.clear();
515  m_tmin.clear();
516  m_tmax.clear();
517 
518  // Initialise cache
519  m_mc_tmin.clear();
520  m_mc_tmax.clear();
521  m_mc_norm = 0.0;
522  m_mc_eff_duration = 0.0;
523  m_mc_cum.clear();
524  m_mc_slope.clear();
525  m_mc_offset.clear();
526  m_mc_time.clear();
527  m_mc_dt.clear();
528 
529  // Return
530  return;
531 }
532 
533 
534 /***********************************************************************//**
535  * @brief Copy class members
536  *
537  * @param[in] model Light curve model.
538  ***************************************************************************/
540 {
541  // Copy members
542  m_norm = model.m_norm;
543  m_nodes = model.m_nodes;
544  m_values = model.m_values;
545  m_filename = model.m_filename;
546  m_timeref = model.m_timeref;
547  m_tmin = model.m_tmin;
548  m_tmax = model.m_tmax;
549 
550  // Copy cache
551  m_mc_tmin = model.m_mc_tmin;
552  m_mc_tmax = model.m_mc_tmax;
553  m_mc_norm = model.m_mc_norm;
555  m_mc_cum = model.m_mc_cum;
556  m_mc_slope = model.m_mc_slope;
557  m_mc_offset = model.m_mc_offset;
558  m_mc_time = model.m_mc_time;
559  m_mc_dt = model.m_mc_dt;
560 
561  // Set parameter pointer(s)
562  m_pars.clear();
563  m_pars.push_back(&m_norm);
564 
565  // Return
566  return;
567 }
568 
569 
570 /***********************************************************************//**
571  * @brief Delete class members
572  ***************************************************************************/
574 {
575  // Return
576  return;
577 }
578 
579 
580 /***********************************************************************//**
581  * @brief Load nodes from file
582  *
583  * @param[in] filename File name.
584  *
585  * @exception GException::invalid_value
586  * File function FITS file is invalid
587  *
588  * Load the light curve nodes from a FITS file. The light curve nodes are
589  * expected in the first extension of the FITS file, containing two mandatory
590  * columns with names "TIME" and "NORM".
591  ***************************************************************************/
593 {
594  // Set maximum light curve normalization value, including a small margin
595  const double max_norm = 1.0 + 1.0e-8;
596 
597  // Clear nodes and values
598  m_nodes.clear();
599  m_values.clear();
600 
601  // Set filename
603 
604  // Continue only if filename is not empty
605  if (!filename.is_empty()) {
606 
607  // Load FITS file
608  GFits fits = GFits(filename);
609 
610  // Extract binary table (so far always load extension 1 as table)
611  GFitsTable* table = fits.table(1);
612 
613  // Read time reference from binary table
614  m_timeref.read(*table);
615 
616  // Extract columns
617  GFitsTableCol* time_col = (*table)["TIME"];
618  GFitsTableCol* norm_col = (*table)["NORM"];
619 
620  // Check that there are at least two nodes in table
621  if (time_col->nrows() < 2) {
622  std::string msg = "\"TIME\" column contains "+
623  gammalib::str(time_col->nrows())+" rows but at "
624  "least two rows are required. Please specify a valid "
625  "temporal file function.";
627  }
628 
629  // Check that both columns are consistent
630  if (time_col->nrows() != norm_col->nrows()) {
631  std::string msg = "\"TIME\" and \"NORM\" columns have inconsistent "
632  "number of rows ("+
633  gammalib::str(time_col->nrows())+", "+
634  gammalib::str(norm_col->nrows())+"). Please "
635  "specify a valid temporal file function.";
637  }
638 
639  // Set number of nodes
640  int nodes = time_col->nrows();
641 
642  // Check that time values are in ascending order and that no node is
643  // larger than 1
644  double last_time = -1.0;
645  for (int i = 0; i < nodes; ++i) {
646 
647  // Check if time has increased
648  if (last_time >= 0.0 && time_col->real(i) <= last_time) {
649  std::string msg = "Time "+gammalib::str(time_col->real(i))+
650  " in row "+gammalib::str(i+1)+" of \"TIME\" "
651  "column is equal to or smaller than preceeding "
652  "value. Please provide a light curve file with "
653  "monotonically increasing times.";
655  }
656 
657  // Check if value is smaller than maximum allowed normalisation
658  if (norm_col->real(i) > max_norm) {
659  std::string msg = "Value "+gammalib::str(norm_col->real(i))+" at "
660  "time "+gammalib::str(time_col->real(i))+" is "
661  "larger than 1. Please provide a light curve file "
662  "with normalizations not exceeding 1.";
664  }
665 
666  } // endfor: looped over nodes
667 
668  // Extract nodes
669  for (int i = 0; i < nodes; ++i) {
670  m_nodes.append(time_col->real(i));
671  m_values.push_back(norm_col->real(i));
672  }
673 
674  // Make sure that no node exceeds 1
675  for (int i = 0; i < m_values.size(); ++i) {
676  if (m_values[i] > 1.0) {
677  m_values[i] = 1.0;
678  }
679  }
680 
681  // Set minimum and maximum times (assumes that times are ordered)
682  m_tmin.set(time_col->real(0), m_timeref);
683  m_tmax.set(time_col->real(time_col->nrows()-1), m_timeref);
684 
685  // Close FITS file
686  fits.close();
687 
688  } // endif: filename was not empty
689 
690  // Return
691  return;
692 }
693 
694 
695 /***********************************************************************//**
696  * @brief Set MC pre-computation cache
697  *
698  * @param[in] tmin Minimum time of time interval.
699  * @param[in] tmax Maximum time of time interval.
700  *
701  * This method sets up an array of indices and the cumulative distribution
702  * function needed for MC simulations.
703  ***************************************************************************/
705  const GTime& tmax) const
706 {
707  // Get light curve normalisation value to see whether it has changed
708  double norm = m_norm.value();
709 
710  // Update the cache only if the time interval or normalisation has changed
711  if (tmin != m_mc_tmin || tmax != m_mc_tmax || norm != m_mc_norm) {
712 
713  // Store new time interval and normalisation value
714  m_mc_tmin = tmin;
715  m_mc_tmax = tmax;
716  m_mc_norm = norm;
717 
718  // Initialise cache
719  m_mc_eff_duration = 0.0;
720  m_mc_cum.clear();
721  m_mc_slope.clear();
722  m_mc_offset.clear();
723  m_mc_time.clear();
724  m_mc_dt.clear();
725 
726  // Continue only if time interval overlaps with temporal file function
727  // and if time interval is valid
728  if (tmax > m_tmin && tmin < m_tmax && tmax > tmin) {
729 
730  // Loop over all intervals between the nodes
731  for (int i = 0; i < m_nodes.size()-1; ++i) {
732 
733  // Get start and stop time of interval
734  GTime tstart(m_nodes[i], m_timeref);
735  GTime tstop(m_nodes[i+1], m_timeref);
736 
737  // Make sure that we only consider the interval that overlaps
738  // with the requested time interval
739  if (tmin > tstart) {
740  tstart = tmin;
741  }
742  if (tmax < tstop) {
743  tstop = tmax;
744  }
745 
746  // If time interval is empty then skip this node
747  if (tstart >= tstop) {
748  continue;
749  }
750 
751  // Evaluate rate at start and stop time
752  double rstart = eval(tstart);
753  double rstop = eval(tstop);
754 
755  // Compute mean normalization for this interval
756  double norm = 0.5 * (rstart + rstop);
757 
758  // Compute integral for this interval
759  double dt = tstop - tstart;
760  double cum = norm * dt;
761 
762  // Compute slope, offset and start time of interval
763  double slope = (rstop - rstart) / dt;
764  double offset = rstart;
765  double renorm = (0.5 * slope * dt + offset) * dt;
766  slope /= renorm;
767  offset /= renorm;
768 
769  // Update effective duration
770  m_mc_eff_duration += cum;
771 
772  // Put mean normalization and integral on stack
773  m_mc_cum.push_back(cum);
774  m_mc_slope.push_back(slope);
775  m_mc_offset.push_back(offset);
776  m_mc_time.push_back(tstart.convert(m_timeref));
777  m_mc_dt.push_back(dt);
778 
779  } // endfor: next interval
780 
781  // Build cumulative distribution
782  for (int i = 1; i < m_mc_cum.size(); ++i) {
783  m_mc_cum[i] += m_mc_cum[i-1];
784  }
785  double norm = m_mc_cum[m_mc_cum.size()-1];
786  for (int i = 0; i < m_mc_cum.size(); ++i) {
787  m_mc_cum[i] /= norm;
788  }
789 
790  } // endif: time interval overlaps
791 
792  } // endif: Update was required
793 
794  // Return
795  return;
796 }
void clear(void)
Clear time reference.
int size(void) const
Return number of nodes in node array.
Definition: GNodeArray.hpp:192
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.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
Definition: GFits.cpp:472
GTime m_tmax
Maximum time of model.
std::vector< double > m_mc_slope
Slope of interval.
const double & factor_gradient(void) const
Return parameter factor gradient.
GTimeReference m_timeref
Time reference.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:828
const std::string & timeunit(void) const
Return time unit.
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.
std::vector< GModelPar * > m_pars
Parameter pointers.
const std::string & name(void) const
Return parameter name.
double gradient(void) const
Return parameter gradient.
Abstract temporal model base class.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print light curve information.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
Definition: GModelPar.cpp:351
const GFilename & filename(void) const
Return file name.
void read(const GFitsHDU &hdu)
Read time reference from FITS header.
virtual ~GModelTemporalLightCurve(void)
Destructor.
bool is_empty(void) const
Signal if filename is empty.
Definition: GFilename.hpp:160
XML element node class.
Definition: GXmlElement.hpp:47
void nrows(const int &nrows)
Set number of rows in column.
void clear(void)
Clear node array.
Definition: GNodeArray.cpp:235
void clear(void)
Clear time.
Definition: GTime.cpp:251
Random number generator class.
Definition: GRan.hpp:44
Time class.
Definition: GTime.hpp:54
Gammalib tools definition.
FITS file class.
Definition: GFits.hpp:63
FITS file class interface definition.
double m_mc_norm
Light curve normalisation.
GFilename m_filename
Name of file function.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
Definition: GTools.cpp:1733
void free_members(void)
Delete class members.
bool is_free(void) const
Signal if parameter is free.
Time container class.
Definition: GTimes.hpp:45
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.
const double & scale(void) const
Return parameter scale.
GModelPar m_norm
Normalization factor.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
Definition: GVector.cpp:1275
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
virtual void read(const GXmlElement &xml)
Read model from XML element.
const double & mjdref(void) const
Return MJD reference (units: days)
const GXmlAttribute * attribute(const int &index) const
Return attribute.
#define G_WRITE
Filename class.
Definition: GFilename.hpp:62
Abstract interface for FITS table column.
void fix(void)
Fix a parameter.
virtual void clear(void)
Clear light curve model.
int size(void) const
Return number of parameters.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1527
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition: GRan.cpp:242
void clear(void)
Clear parameter.
double interpolate(const double &value, const std::vector< double > &vector) const
Interpolate value.
Definition: GNodeArray.cpp:536
const std::string & timesys(void) const
Return time system.
Abstract interface for FITS table.
Definition: GFitsTable.hpp:44
GChatter
Definition: GTypemaps.hpp:33
virtual double eval(const GTime &srcTime, const bool &gradients=false) const
Evaluate function.
const GModelTemporalLightCurve g_temporal_lightcurve_seed
GTime m_tmin
Minimum time of model.
void load_nodes(const GFilename &filename)
Load nodes from file.
Interface definition for the temporal model registry class.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelTemporalLightCurve * clone(void) const
Clone light curve model.
std::string url(void) const
Return Uniform Resource Locator (URL)
Definition: GFilename.hpp:189
void clear(void)
Clear file name.
Definition: GFilename.cpp:188
Temporal model registry class definition.
virtual double real(const int &row, const int &inx=0) const =0
Light curve model class.
virtual GModelTemporalLightCurve & operator=(const GModelTemporalLightCurve &model)
Assignment operator.
double poisson(const double &lambda)
Returns Poisson deviates.
Definition: GRan.cpp:316
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
GNodeArray m_nodes
Time nodes of function.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Definition: GModelPar.cpp:229
double value(void) const
Return parameter value.
virtual GModelTemporal & operator=(const GModelTemporal &model)
Assignment operator.
#define G_READ
const std::string & unit(void) const
Return parameter unit.
Exception handler interface definition.
virtual std::string type(void) const
Return model type.
void init_members(void)
Initialise class members.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1033
void append(const double &node)
Append one node to array.
Definition: GNodeArray.cpp:351
double norm(void) const
Return normalization factor.
void close(void)
Close FITS file.
Definition: GFits.cpp:1314
std::vector< double > m_mc_dt
Length of interval.
void set(const double &time, const GTimeReference &ref)
Set time given in specified reference.
Definition: GTime.cpp:999
#define G_LOAD_NODES
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Definition: GTools.cpp:1579
void append(const GTime &time)
Append time to container.
Definition: GTimes.cpp:214
double convert(const GTimeReference &ref) const
Return time in specified reference.
Definition: GTime.cpp:692
void init_members(void)
Initialise class members.
double m_mc_eff_duration
Effective duration.
Light curve model class interface definition.
void free_members(void)
Delete class members.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
Definition: GTools.cpp:1703
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:415