GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralPlaw.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralPlaw.cpp - Spectral power law model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2009-2021 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 GModelSpectralPlaw.cpp
23  * @brief Power law spectral model class implementation
24  * @author Juergen Knoedlseder
25  */
26 
27 /* __ Includes ___________________________________________________________ */
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
31 #include <cmath>
32 #include "GException.hpp"
33 #include "GTools.hpp"
34 #include "GRan.hpp"
35 #include "GModelSpectralPlaw.hpp"
37 
38 /* __ Constants __________________________________________________________ */
39 
40 /* __ Globals ____________________________________________________________ */
42  "Prefactor",
43  "Index",
44  "PivotEnergy");
45 const GModelSpectralRegistry g_spectral_plaw_registry1(&g_spectral_plaw_seed1);
46 #if defined(G_LEGACY_XML_FORMAT)
47 const GModelSpectralPlaw g_spectral_plaw_seed2("PowerLaw",
48  "Prefactor",
49  "Index",
50  "Scale");
51 const GModelSpectralRegistry g_spectral_plaw_registry2(&g_spectral_plaw_seed2);
52 #endif
53 
54 /* __ Method name definitions ____________________________________________ */
55 #define G_EVAL "GModelSpectralPlaw::eval(GEnergy&, GTime&, bool&)"
56 #define G_MC "GModelSpectralPlaw::mc(GEnergy&, GEnergy&, GTime&, GRan&)"
57 #define G_READ "GModelSpectralPlaw::read(GXmlElement&)"
58 #define G_WRITE "GModelSpectralPlaw::write(GXmlElement&)"
59 
60 /* __ Macros _____________________________________________________________ */
61 
62 /* __ Coding definitions _________________________________________________ */
63 
64 /* __ Debug definitions __________________________________________________ */
65 
66 
67 /*==========================================================================
68  = =
69  = Constructors/destructors =
70  = =
71  ==========================================================================*/
72 
73 /***********************************************************************//**
74  * @brief Void constructor
75  ***************************************************************************/
77 {
78  // Initialise private members for clean destruction
79  init_members();
80 
81  // Return
82  return;
83 }
84 
85 
86 /***********************************************************************//**
87  * @brief Model type and parameter name constructor
88  *
89  * @param[in] type Model type.
90  * @param[in] prefactor Name of prefactor parameter.
91  * @param[in] index Name of index parameter.
92  * @param[in] pivot Name of pivot parameter.
93  ***************************************************************************/
95  const std::string& prefactor,
96  const std::string& index,
97  const std::string& pivot) :
99 {
100  // Initialise members
101  init_members();
102 
103  // Set model type
104  m_type = type;
105 
106  // Set parameter names
107  m_norm.name(prefactor);
108  m_index.name(index);
109  m_pivot.name(pivot);
110 
111  // Return
112  return;
113 }
114 
115 
116 /***********************************************************************//**
117  * @brief Parameter constructor
118  *
119  * @param[in] prefactor Power law pre factor (ph/cm2/s/MeV).
120  * @param[in] index Power law index.
121  * @param[in] pivot Pivot energy.
122  *
123  * Constructs a spectral power law using the model parameters
124  * - power law @p prefactor (ph/cm2/s/MeV)
125  * - spectral @p index
126  * - @p pivot energy.
127  ***************************************************************************/
129  const double& index,
130  const GEnergy& pivot) :
132 {
133  // Initialise members
134  init_members();
135 
136  // Set parameters
137  m_norm.value(prefactor);
138  m_index.value(index);
139  m_pivot.value(pivot.MeV()); // Internally stored in MeV
140 
141  // Perform autoscaling of parameter
142  autoscale();
143 
144  // Return
145  return;
146 }
147 
148 
149 /***********************************************************************//**
150  * @brief XML constructor
151  *
152  * @param[in] xml XML element containing position information.
153  *
154  * Constructs a power law spectral model by extracting information from an
155  * XML element. See the read() method for more information about the expected
156  * structure of the XML element.
157  ***************************************************************************/
159 {
160  // Initialise members
161  init_members();
162 
163  // Read information from XML element
164  read(xml);
165 
166  // Return
167  return;
168 }
169 
170 
171 /***********************************************************************//**
172  * @brief Copy constructor
173  *
174  * @param[in] model Spectral power law model.
175  ***************************************************************************/
177  : GModelSpectral(model)
178 {
179  // Initialise members
180  init_members();
181 
182  // Copy members
183  copy_members(model);
184 
185  // Return
186  return;
187 }
188 
189 
190 /***********************************************************************//**
191  * @brief Destructor
192  ***************************************************************************/
194 {
195  // Free members
196  free_members();
197 
198  // Return
199  return;
200 }
201 
202 
203 /*==========================================================================
204  = =
205  = Operators =
206  = =
207  ==========================================================================*/
208 
209 /***********************************************************************//**
210  * @brief Assignment operator
211  *
212  * @param[in] model Spectral power law model.
213  * @return Spectral power law model.
214  ***************************************************************************/
216 {
217  // Execute only if object is not identical
218  if (this != &model) {
219 
220  // Copy base class members
221  this->GModelSpectral::operator=(model);
222 
223  // Free members
224  free_members();
225 
226  // Initialise members
227  init_members();
228 
229  // Copy members
230  copy_members(model);
231 
232  } // endif: object was not identical
233 
234  // Return
235  return *this;
236 }
237 
238 
239 /*==========================================================================
240  = =
241  = Public methods =
242  = =
243  ==========================================================================*/
244 
245 /***********************************************************************//**
246  * @brief Clear spectral power law model
247  ***************************************************************************/
249 {
250  // Free class members (base and derived classes, derived class first)
251  free_members();
253 
254  // Initialise members
256  init_members();
257 
258  // Return
259  return;
260 }
261 
262 
263 /***********************************************************************//**
264  * @brief Clone spectral power law model
265  *
266  * @return Pointer to deep copy of spectral power law model.
267  ***************************************************************************/
269 {
270  // Clone spectral power law model
271  return new GModelSpectralPlaw(*this);
272 }
273 
274 
275 /***********************************************************************//**
276  * @brief Evaluate function
277  *
278  * @param[in] srcEng True photon energy.
279  * @param[in] srcTime True photon arrival time.
280  * @param[in] gradients Compute gradients?
281  * @return Model value (ph/cm2/s/MeV).
282  *
283  * Evaluates
284  *
285  * \f[
286  * S_{\rm E}(E | t) = {\tt m\_norm}
287  * \left( \frac{E}{\tt m\_pivot} \right)^{\tt m\_index}
288  * \f]
289  *
290  * where
291  * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
292  * - \f${\tt m\_index}\f$ is the spectral index, and
293  * - \f${\tt m\_pivot}\f$ is the pivot energy.
294  *
295  * If the @p gradients flag is true the method will also compute the
296  * partial derivatives of the model with respect to the parameters using
297  *
298  * \f[
299  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_norm}} =
300  * \frac{S_{\rm E}(E | t)}{{\tt m\_norm}}
301  * \f]
302  *
303  * \f[
304  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} =
305  * S_{\rm E}(E | t) \, \ln(E/{\tt m_pivot})
306  * \f]
307  *
308  * \f[
309  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_pivot}} =
310  * -S_{\rm E}(E | t) \,
311  * \left( \frac{{\tt m\_index}}{{\tt m\_pivot}} \right)
312  * \f]
313  *
314  * @todo The method expects that energy!=0. Otherwise Inf or NaN may result.
315  ***************************************************************************/
316 double GModelSpectralPlaw::eval(const GEnergy& srcEng,
317  const GTime& srcTime,
318  const bool& gradients) const
319 {
320  // Update the evaluation cache
321  update_eval_cache(srcEng);
322 
323  // Compute function value
324  double value = m_norm.value() * m_last_power;
325 
326  // Optionally compute gradients
327  if (gradients) {
328 
329  // Compute partial derivatives of the parameter values
330  double g_norm = (m_norm.is_free())
331  ? m_norm.scale() * m_last_power : 0.0;
332  double g_index = (m_index.is_free())
333  ? value * m_index.scale() * m_last_log_e_norm : 0.0;
334  double g_pivot = (m_pivot.is_free() && m_pivot.factor_value() != 0.0)
335  ? -value * m_last_index / m_pivot.factor_value() : 0.0;
336 
337  // Set gradients
338  m_norm.factor_gradient(g_norm);
339  m_index.factor_gradient(g_index);
340  m_pivot.factor_gradient(g_pivot);
341 
342  } // endif: gradient computation was requested
343 
344  // Compile option: Check for NaN/Inf
345  #if defined(G_NAN_CHECK)
346  if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
347  std::string msg = "Model value not a number:";
348  for (int i = 0; i < m_pars.size(); ++i) {
349  msg += " " + m_pars[i]->name() + "=";
350  msg += gammalib::str(m_pars[i]->value());
351  }
352  msg += " srcEng=" + srcEng.print();
353  msg += " srcTime=" + srcTime.print();
355  }
356  #endif
357 
358  // Return
359  return value;
360 }
361 
362 
363 /***********************************************************************//**
364  * @brief Returns model photon flux between [emin, emax] (units: ph/cm2/s)
365  *
366  * @param[in] emin Minimum photon energy.
367  * @param[in] emax Maximum photon energy.
368  * @return Photon flux (ph/cm2/s).
369  *
370  * Computes
371  *
372  * \f[
373  * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE
374  * \f]
375  *
376  * where
377  * - [@p emin, @p emax] is an energy interval, and
378  * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
379  * The integration is done analytically.
380  ***************************************************************************/
382  const GEnergy& emax) const
383 {
384  // Initialise flux
385  double flux = 0.0;
386 
387  // Compute only if integration range is valid
388  if (emin < emax) {
389 
390  // Compute photon flux
391  flux = m_norm.value() *
393  emax.MeV(),
394  m_pivot.value(),
395  m_index.value());
396 
397  } // endif: integration range was valid
398 
399  // Return flux
400  return flux;
401 }
402 
403 
404 /***********************************************************************//**
405  * @brief Returns model energy flux between [emin, emax] (units: erg/cm2/s)
406  *
407  * @param[in] emin Minimum photon energy.
408  * @param[in] emax Maximum photon energy.
409  * @return Energy flux (erg/cm2/s).
410  *
411  * Computes
412  *
413  * \f[
414  * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE
415  * \f]
416  *
417  * where
418  * - [@p emin, @p emax] is an energy interval, and
419  * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
420  * The integration is done analytically.
421  ***************************************************************************/
423  const GEnergy& emax) const
424 {
425  // Initialise flux
426  double eflux = 0.0;
427 
428  // Compute only if integration range is valid
429  if (emin < emax) {
430 
431  // Compute photon flux
432  eflux = m_norm.value() *
434  emax.MeV(),
435  m_pivot.value(),
436  m_index.value());
437 
438  // Convert from MeV/cm2/s to erg/cm2/s
439  eflux *= gammalib::MeV2erg;
440 
441  } // endif: integration range was valid
442 
443  // Return flux
444  return eflux;
445 }
446 
447 
448 /***********************************************************************//**
449  * @brief Returns Monte Carlo energy between [emin, emax]
450  *
451  * @param[in] emin Minimum photon energy.
452  * @param[in] emax Maximum photon energy.
453  * @param[in] time True photon arrival time.
454  * @param[in,out] ran Random number generator.
455  * @return Energy.
456  *
457  * Returns Monte Carlo energy by randomly drawing from a power law.
458  ***************************************************************************/
460  const GEnergy& emax,
461  const GTime& time,
462  GRan& ran) const
463 {
464  // Check energy interval
466 
467  // Update cache
468  update_mc_cache(emin, emax);
469 
470  // Get uniform random number
471  double u = ran.uniform();
472 
473  // Initialise energy
474  double eng;
475 
476  // Case A: Index is not -1
477  if (index() != -1.0) {
478  if (u > 0.0) {
480  m_mc_exponent);
481  }
482  else {
483  eng = 0.0;
484  }
485  }
486 
487  // Case B: Index is -1
488  else {
490  }
491 
492  // Set energy
493  GEnergy energy;
494  energy.MeV(eng);
495 
496  // Return energy
497  return energy;
498 }
499 
500 
501 /***********************************************************************//**
502  * @brief Read model from XML element
503  *
504  * @param[in] xml XML element.
505  *
506  * Reads the spectral information from an XML element.
507  ***************************************************************************/
509 {
510  // Verify number of model parameters
512 
513  // Get parameter pointers
517 
518  // Read parameters
519  m_norm.read(*norm);
520  m_index.read(*index);
521  m_pivot.read(*pivot);
522 
523  // Return
524  return;
525 }
526 
527 
528 /***********************************************************************//**
529  * @brief Write model into XML element
530  *
531  * @param[in] xml XML element.
532  *
533  * Writes the spectral information into an XML element.
534  ***************************************************************************/
536 {
537  // Verify model type
539 
540  // Get XML parameters
544 
545  // Write parameters
546  m_norm.write(*norm);
547  m_index.write(*index);
548  m_pivot.write(*pivot);
549 
550  // Return
551  return;
552 }
553 
554 
555 /***********************************************************************//**
556  * @brief Print powerlaw information
557  *
558  * @param[in] chatter Chattiness (defaults to NORMAL).
559  * @return String containing model information.
560  ***************************************************************************/
561 std::string GModelSpectralPlaw::print(const GChatter& chatter) const
562 {
563  // Initialise result string
564  std::string result;
565 
566  // Continue only if chatter is not silent
567  if (chatter != SILENT) {
568 
569  // Append header
570  result.append("=== GModelSpectralPlaw ===");
571 
572  // Append information
573  result.append("\n"+gammalib::parformat("Number of parameters"));
574  result.append(gammalib::str(size()));
575  for (int i = 0; i < size(); ++i) {
576  result.append("\n"+m_pars[i]->print(chatter));
577  }
578 
579  } // endif: chatter was not silent
580 
581  // Return result
582  return result;
583 }
584 
585 
586 /*==========================================================================
587  = =
588  = Private methods =
589  = =
590  ==========================================================================*/
591 
592 /***********************************************************************//**
593  * @brief Initialise class members
594  ***************************************************************************/
596 {
597  // Initialise model type
598  m_type = "PowerLaw";
599 
600  // Initialise powerlaw normalisation
601  m_norm.clear();
602  m_norm.name("Prefactor");
603  m_norm.unit("ph/cm2/s/MeV");
604  m_norm.scale(1.0);
605  m_norm.value(1.0); // default: 1.0
606  m_norm.min(0.0); // min: 0.0
607  m_norm.free();
608  m_norm.gradient(0.0);
609  m_norm.has_grad(true);
610 
611  // Initialise powerlaw index
612  m_index.clear();
613  m_index.name("Index");
614  m_index.scale(1.0);
615  m_index.value(-2.0); // default: -2.0
616  m_index.range(-10.0,+10.0); // range: [-10,+10]
617  m_index.free();
618  m_index.gradient(0.0);
619  m_index.has_grad(true);
620 
621  // Initialise pivot energy
622  m_pivot.clear();
623  m_pivot.name("PivotEnergy");
624  m_pivot.unit("MeV");
625  m_pivot.scale(1.0);
626  m_pivot.value(100.0); // default: 100
627  m_pivot.fix();
628  m_pivot.gradient(0.0);
629  m_pivot.has_grad(true);
630 
631  // Set parameter pointer(s)
632  m_pars.clear();
633  m_pars.push_back(&m_norm);
634  m_pars.push_back(&m_index);
635  m_pars.push_back(&m_pivot);
636 
637  // Initialise eval cache
639  m_last_norm = 1.0e30;
640  m_last_index = 1.0e30;
641  m_last_pivot = 1.0e30;
642  m_last_e_norm = 0.0;
643  m_last_log_e_norm = 0.0;
644  m_last_power = 0.0;
645 
646  // Initialise MC cache
647  m_mc_emin = 0.0;
648  m_mc_emax = 0.0;
649  m_mc_exponent = 0.0;
650  m_mc_pow_emin = 0.0;
651  m_mc_pow_ewidth = 0.0;
652 
653  // Return
654  return;
655 }
656 
657 
658 /***********************************************************************//**
659  * @brief Copy class members
660  *
661  * @param[in] model GModelSpectralPlaw members which should be copied.
662  ***************************************************************************/
664 {
665  // Copy members
666  m_type = model.m_type;
667  m_norm = model.m_norm;
668  m_index = model.m_index;
669  m_pivot = model.m_pivot;
670 
671  // Set parameter pointer(s)
672  m_pars.clear();
673  m_pars.push_back(&m_norm);
674  m_pars.push_back(&m_index);
675  m_pars.push_back(&m_pivot);
676 
677  // Copy eval cache
679  m_last_norm = model.m_last_norm;
680  m_last_index = model.m_last_index;
681  m_last_pivot = model.m_last_pivot;
684  m_last_power = model.m_last_power;
685 
686  // Copy MC cache
687  m_mc_emin = model.m_mc_emin;
688  m_mc_emax = model.m_mc_emax;
692 
693  // Return
694  return;
695 }
696 
697 
698 /***********************************************************************//**
699  * @brief Delete class members
700  ***************************************************************************/
702 {
703  // Return
704  return;
705 }
706 
707 
708 /***********************************************************************//**
709  * @brief Update eval precomputation cache
710  *
711  * @param[in] energy Energy.
712  *
713  * Updates the precomputation cache for eval() method.
714  ***************************************************************************/
716 {
717  // Get parameter values (takes 2 multiplications which are difficult
718  // to avoid)
719  double index = m_index.value();
720  double pivot = m_pivot.value();
721 
722  // If the energy or one of the parameters index or pivot energy has
723  // changed then recompute the cache
724  if ((m_last_energy != energy) ||
725  (m_last_index != index) ||
726  (m_last_pivot != pivot)) {
727 
728  // Store actual energy and parameter values
729  m_last_energy = energy;
732 
733  // Compute and store value
734  double eng = energy.MeV();
735  m_last_e_norm = eng / m_last_pivot;
738 
739  } // endif: recomputation was required
740 
741  // Return
742  return;
743 }
744 
745 
746 /***********************************************************************//**
747  * @brief Update Monte Carlo pre computation cache
748  *
749  * @param[in] emin Minimum photon energy.
750  * @param[in] emax Maximum photon energy.
751  *
752  * Updates the precomputation cache for Monte Carlo simulations.
753  ***************************************************************************/
755  const GEnergy& emax) const
756 
757 {
758  // Case A: Index is not -1
759  if (index() != -1.0) {
760 
761  // Change in energy boundaries?
762  if (emin.MeV() != m_mc_emin || emax.MeV() != m_mc_emax) {
763  m_mc_emin = emin.MeV();
764  m_mc_emax = emax.MeV();
765  m_mc_exponent = index() + 1.0;
768  }
769 
770  }
771 
772  // Case B: Index is -1
773  else {
774 
775  // Change in energy boundaries?
776  if (emin.MeV() != m_mc_emin || emax.MeV() != m_mc_emax) {
777  m_mc_emin = emin.MeV();
778  m_mc_emax = emax.MeV();
779  m_mc_exponent = 0.0;
782  }
783 
784  }
785 
786  // Return
787  return;
788 }
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
virtual GModelSpectralPlaw & operator=(const GModelSpectralPlaw &model)
Assignment operator.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
const double & factor_gradient(void) const
Return parameter factor gradient.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:864
virtual ~GModelSpectralPlaw(void)
Destructor.
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
void warning(const std::string &origin, const std::string &message)
Emits warning.
Definition: GTools.cpp:1386
Abstract spectral model base class.
double gradient(void) const
Return parameter gradient.
std::string m_type
Model type.
int size(void) const
Return number of parameters.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
Definition: GModelPar.cpp:351
double m_last_log_e_norm
Last ln(E/Epivot) value.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
std::vector< GModelPar * > m_pars
Parameter pointers.
XML element node class.
Definition: GXmlElement.hpp:48
Spectral model registry class definition.
double m_last_index
Last index parameter.
Random number generator class.
Definition: GRan.hpp:44
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
double min(void) const
Return parameter minimum boundary.
double plaw_energy_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute energy flux between two energies for a power law.
Definition: GTools.cpp:1248
bool is_free(void) const
Signal if parameter is free.
Power law spectral model class.
#define G_EVAL
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:201
double m_last_power
Last power value.
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:184
double m_mc_exponent
Exponent (index+1)
virtual void clear(void)
Clear spectral power law model.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
virtual void read(const GXmlElement &xml)
Read model from XML element.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
Definition: GEnergy.cpp:748
void free(void)
Free a parameter.
GEnergy pivot(void) const
Return pivot energy.
void fix(void)
Fix a parameter.
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:1637
double m_last_e_norm
Last E/Epivot value.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1274
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition: GRan.cpp:242
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
Definition: GException.cpp:364
void clear(void)
Clear parameter.
#define G_MC
Power law spectral model class interface definition.
#define G_WRITE
double m_mc_emin
Minimum energy.
GModelSpectralPlaw(void)
Void constructor.
GChatter
Definition: GTypemaps.hpp:33
const GModelSpectralPlaw g_spectral_plaw_seed1("PowerLaw","Prefactor","Index","PivotEnergy")
std::string print(const GChatter &chatter=NORMAL) const
Print time.
Definition: GTime.cpp:1188
virtual GModelSpectralPlaw * clone(void) const
Clone spectral power law model.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
Definition: GTools.cpp:1777
Interface definition for the spectral model registry class.
void init_members(void)
Initialise class members.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
void autoscale(void)
Autoscale parameters.
GEnergy m_last_energy
Last energy value.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
double m_mc_pow_emin
Power of minimum energy.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
const double MeV2erg
Definition: GTools.hpp:45
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print powerlaw information.
double m_last_pivot
Last pivot parameter.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Definition: GModelPar.cpp:229
double value(void) const
Return parameter value.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
Definition: GVector.cpp:1422
const std::string & unit(void) const
Return parameter unit.
GModelPar m_pivot
Pivot energy.
Exception handler interface definition.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
double m_mc_pow_ewidth
Power of energy width.
double index(void) const
Return power law index.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
Definition: GVector.cpp:1232
double m_mc_emax
Maximum energy.
virtual std::string type(void) const
Return model type.
GModelPar m_norm
Normalization factor.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
GModelPar m_index
Spectral index.
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:1689
virtual void write(GXmlElement &xml) const
Write model into XML element.
void free_members(void)
Delete class members.
double m_last_norm
Last norm parameter.
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
const double & factor_value(void) const
Return parameter factor value.
#define G_READ
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
double plaw_photon_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute photon flux between two energies for a power law.
Definition: GTools.cpp:1200
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489
void copy_members(const GModelSpectralPlaw &model)
Copy class members.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition: GTools.cpp:1819