GammaLib  1.7.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-2016 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_MC "GModelSpectralPlaw::mc(GEnergy&, GEnergy&, GTime&, GRan&)"
56 #define G_READ "GModelSpectralPlaw::read(GXmlElement&)"
57 #define G_WRITE "GModelSpectralPlaw::write(GXmlElement&)"
58 
59 /* __ Macros _____________________________________________________________ */
60 
61 /* __ Coding definitions _________________________________________________ */
62 
63 /* __ Debug definitions __________________________________________________ */
64 
65 
66 /*==========================================================================
67  = =
68  = Constructors/destructors =
69  = =
70  ==========================================================================*/
71 
72 /***********************************************************************//**
73  * @brief Void constructor
74  ***************************************************************************/
76 {
77  // Initialise private members for clean destruction
78  init_members();
79 
80  // Return
81  return;
82 }
83 
84 
85 /***********************************************************************//**
86  * @brief Model type and parameter name constructor
87  *
88  * @param[in] type Model type.
89  * @param[in] prefactor Name of prefactor parameter.
90  * @param[in] index Name of index parameter.
91  * @param[in] pivot Name of pivot parameter.
92  ***************************************************************************/
94  const std::string& prefactor,
95  const std::string& index,
96  const std::string& pivot) :
98 {
99  // Initialise members
100  init_members();
101 
102  // Set model type
103  m_type = type;
104 
105  // Set parameter names
106  m_norm.name(prefactor);
107  m_index.name(index);
108  m_pivot.name(pivot);
109 
110  // Return
111  return;
112 }
113 
114 
115 /***********************************************************************//**
116  * @brief Parameter constructor
117  *
118  * @param[in] prefactor Power law pre factor (ph/cm2/s/MeV).
119  * @param[in] index Power law index.
120  * @param[in] pivot Pivot energy.
121  *
122  * Constructs a spectral power law using the model parameters
123  * - power law @p prefactor (ph/cm2/s/MeV)
124  * - spectral @p index
125  * - @p pivot energy.
126  ***************************************************************************/
128  const double& index,
129  const GEnergy& pivot) :
131 {
132  // Initialise members
133  init_members();
134 
135  // Set parameters
136  m_norm.value(prefactor);
137  m_index.value(index);
138  m_pivot.value(pivot.MeV()); // Internally stored in MeV
139 
140  // Perform autoscaling of parameter
141  autoscale();
142 
143  // Return
144  return;
145 }
146 
147 
148 /***********************************************************************//**
149  * @brief XML constructor
150  *
151  * @param[in] xml XML element containing position information.
152  *
153  * Constructs a power law spectral model by extracting information from an
154  * XML element. See the read() method for more information about the expected
155  * structure of the XML element.
156  ***************************************************************************/
158 {
159  // Initialise members
160  init_members();
161 
162  // Read information from XML element
163  read(xml);
164 
165  // Return
166  return;
167 }
168 
169 
170 /***********************************************************************//**
171  * @brief Copy constructor
172  *
173  * @param[in] model Spectral power law model.
174  ***************************************************************************/
176  : GModelSpectral(model)
177 {
178  // Initialise members
179  init_members();
180 
181  // Copy members
182  copy_members(model);
183 
184  // Return
185  return;
186 }
187 
188 
189 /***********************************************************************//**
190  * @brief Destructor
191  ***************************************************************************/
193 {
194  // Free members
195  free_members();
196 
197  // Return
198  return;
199 }
200 
201 
202 /*==========================================================================
203  = =
204  = Operators =
205  = =
206  ==========================================================================*/
207 
208 /***********************************************************************//**
209  * @brief Assignment operator
210  *
211  * @param[in] model Spectral power law model.
212  * @return Spectral power law model.
213  ***************************************************************************/
215 {
216  // Execute only if object is not identical
217  if (this != &model) {
218 
219  // Copy base class members
220  this->GModelSpectral::operator=(model);
221 
222  // Free members
223  free_members();
224 
225  // Initialise members
226  init_members();
227 
228  // Copy members
229  copy_members(model);
230 
231  } // endif: object was not identical
232 
233  // Return
234  return *this;
235 }
236 
237 
238 /*==========================================================================
239  = =
240  = Public methods =
241  = =
242  ==========================================================================*/
243 
244 /***********************************************************************//**
245  * @brief Clear spectral power law model
246  ***************************************************************************/
248 {
249  // Free class members (base and derived classes, derived class first)
250  free_members();
252 
253  // Initialise members
255  init_members();
256 
257  // Return
258  return;
259 }
260 
261 
262 /***********************************************************************//**
263  * @brief Clone spectral power law model
264  *
265  * @return Pointer to deep copy of spectral power law model.
266  ***************************************************************************/
268 {
269  // Clone spectral power law model
270  return new GModelSpectralPlaw(*this);
271 }
272 
273 
274 /***********************************************************************//**
275  * @brief Evaluate function
276  *
277  * @param[in] srcEng True photon energy.
278  * @param[in] srcTime True photon arrival time.
279  * @param[in] gradients Compute gradients?
280  * @return Model value (ph/cm2/s/MeV).
281  *
282  * Evaluates
283  *
284  * \f[
285  * S_{\rm E}(E | t) = {\tt m\_norm}
286  * \left( \frac{E}{\tt m\_pivot} \right)^{\tt m\_index}
287  * \f]
288  *
289  * where
290  * - \f${\tt m\_norm}\f$ is the normalization or prefactor,
291  * - \f${\tt m\_index}\f$ is the spectral index, and
292  * - \f${\tt m\_pivot}\f$ is the pivot energy.
293  *
294  * If the @p gradients flag is true the method will also compute the
295  * partial derivatives of the model with respect to the parameters using
296  *
297  * \f[
298  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_norm}} =
299  * \frac{S_{\rm E}(E | t)}{{\tt m\_norm}}
300  * \f]
301  *
302  * \f[
303  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_index}} =
304  * S_{\rm E}(E | t) \, \ln(E/{\tt m_pivot})
305  * \f]
306  *
307  * \f[
308  * \frac{\delta S_{\rm E}(E | t)}{\delta {\tt m\_pivot}} =
309  * -S_{\rm E}(E | t) \,
310  * \left( \frac{{\tt m\_index}}{{\tt m\_pivot}} \right)
311  * \f]
312  *
313  * @todo The method expects that energy!=0. Otherwise Inf or NaN may result.
314  ***************************************************************************/
315 double GModelSpectralPlaw::eval(const GEnergy& srcEng,
316  const GTime& srcTime,
317  const bool& gradients) const
318 {
319  // Update the evaluation cache
320  update_eval_cache(srcEng);
321 
322  // Compute function value
323  double value = m_norm.value() * m_last_power;
324 
325  // Optionally compute gradients
326  if (gradients) {
327 
328  // Compute partial derivatives of the parameter values
329  double g_norm = (m_norm.is_free())
330  ? m_norm.scale() * m_last_power : 0.0;
331  double g_index = (m_index.is_free())
332  ? value * m_index.scale() * m_last_log_e_norm : 0.0;
333  double g_pivot = (m_pivot.is_free())
334  ? -value * m_last_index / m_pivot.factor_value() : 0.0;
335 
336  // Set gradients
337  m_norm.factor_gradient(g_norm);
338  m_index.factor_gradient(g_index);
339  m_pivot.factor_gradient(g_pivot);
340 
341  } // endif: gradient computation was requested
342 
343  // Compile option: Check for NaN/Inf
344  #if defined(G_NAN_CHECK)
345  if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
346  std::cout << "*** ERROR: GModelSpectralPlaw::eval";
347  std::cout << "(srcEng=" << srcEng;
348  std::cout << ", srcTime=" << srcTime << "):";
349  std::cout << " NaN/Inf encountered";
350  std::cout << " (value=" << value;
351  std::cout << ", m_norm=" << m_norm.value();
352  std::cout << ", m_index=" << m_index.value();
353  std::cout << ", m_pivot=" << m_pivot.value();
354  std::cout << ", m_last_power=" << m_last_power;
355  std::cout << ")" << std::endl;
356  }
357  #endif
358 
359  // Return
360  return value;
361 }
362 
363 
364 /***********************************************************************//**
365  * @brief Returns model photon flux between [emin, emax] (units: ph/cm2/s)
366  *
367  * @param[in] emin Minimum photon energy.
368  * @param[in] emax Maximum photon energy.
369  * @return Photon flux (ph/cm2/s).
370  *
371  * Computes
372  *
373  * \f[
374  * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) dE
375  * \f]
376  *
377  * where
378  * - [@p emin, @p emax] is an energy interval, and
379  * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
380  * The integration is done analytically.
381  ***************************************************************************/
383  const GEnergy& emax) const
384 {
385  // Initialise flux
386  double flux = 0.0;
387 
388  // Compute only if integration range is valid
389  if (emin < emax) {
390 
391  // Compute photon flux
392  flux = m_norm.value() *
394  emax.MeV(),
395  m_pivot.value(),
396  m_index.value());
397 
398  } // endif: integration range was valid
399 
400  // Return flux
401  return flux;
402 }
403 
404 
405 /***********************************************************************//**
406  * @brief Returns model energy flux between [emin, emax] (units: erg/cm2/s)
407  *
408  * @param[in] emin Minimum photon energy.
409  * @param[in] emax Maximum photon energy.
410  * @return Energy flux (erg/cm2/s).
411  *
412  * Computes
413  *
414  * \f[
415  * \int_{\tt emin}^{\tt emax} S_{\rm E}(E | t) E \, dE
416  * \f]
417  *
418  * where
419  * - [@p emin, @p emax] is an energy interval, and
420  * - \f$S_{\rm E}(E | t)\f$ is the spectral model (ph/cm2/s/MeV).
421  * The integration is done analytically.
422  ***************************************************************************/
424  const GEnergy& emax) const
425 {
426  // Initialise flux
427  double eflux = 0.0;
428 
429  // Compute only if integration range is valid
430  if (emin < emax) {
431 
432  // Compute photon flux
433  eflux = m_norm.value() *
435  emax.MeV(),
436  m_pivot.value(),
437  m_index.value());
438 
439  // Convert from MeV/cm2/s to erg/cm2/s
440  eflux *= gammalib::MeV2erg;
441 
442  } // endif: integration range was valid
443 
444  // Return flux
445  return eflux;
446 }
447 
448 
449 /***********************************************************************//**
450  * @brief Returns Monte Carlo energy between [emin, emax]
451  *
452  * @param[in] emin Minimum photon energy.
453  * @param[in] emax Maximum photon energy.
454  * @param[in] time True photon arrival time.
455  * @param[in,out] ran Random number generator.
456  * @return Energy.
457  *
458  * @exception GException::erange_invalid
459  * Energy range is invalid (emin < emax required).
460  *
461  * Returns Monte Carlo energy by randomly drawing from a power law.
462  ***************************************************************************/
464  const GEnergy& emax,
465  const GTime& time,
466  GRan& ran) const
467 {
468  // Throw an exception if energy range is invalid
469  if (emin >= emax) {
470  throw GException::erange_invalid(G_MC, emin.MeV(), emax.MeV(),
471  "Minimum energy < maximum energy required.");
472  }
473 
474  // Update cache
475  update_mc_cache(emin, emax);
476 
477  // Get uniform random number
478  double u = ran.uniform();
479 
480  // Initialise energy
481  double eng;
482 
483  // Case A: Index is not -1
484  if (index() != -1.0) {
485  if (u > 0.0) {
487  m_mc_exponent);
488  }
489  else {
490  eng = 0.0;
491  }
492  }
493 
494  // Case B: Index is -1
495  else {
497  }
498 
499  // Set energy
500  GEnergy energy;
501  energy.MeV(eng);
502 
503  // Return energy
504  return energy;
505 }
506 
507 
508 /***********************************************************************//**
509  * @brief Read model from XML element
510  *
511  * @param[in] xml XML element.
512  *
513  * Reads the spectral information from an XML element.
514  ***************************************************************************/
516 {
517  // Get parameter pointers
521 
522  // Read parameters
523  m_norm.read(*norm);
524  m_index.read(*index);
525  m_pivot.read(*pivot);
526 
527  // Return
528  return;
529 }
530 
531 
532 /***********************************************************************//**
533  * @brief Write model into XML element
534  *
535  * @param[in] xml XML element.
536  *
537  * @exception GException::model_invalid_spectral
538  * Existing XML element is not of the expected type.
539  *
540  * Writes the spectral information into an XML element.
541  ***************************************************************************/
543 {
544  // Set model type
545  if (xml.attribute("type") == "") {
546  xml.attribute("type", type());
547  }
548 
549  // Verify model type
550  if (xml.attribute("type") != type()) {
552  "Spectral model is not of type \""+type()+"\".");
553  }
554 
555  // Get XML parameters
559 
560  // Write parameters
561  m_norm.write(*norm);
562  m_index.write(*index);
563  m_pivot.write(*pivot);
564 
565  // Return
566  return;
567 }
568 
569 
570 /***********************************************************************//**
571  * @brief Print powerlaw information
572  *
573  * @param[in] chatter Chattiness (defaults to NORMAL).
574  * @return String containing model information.
575  ***************************************************************************/
576 std::string GModelSpectralPlaw::print(const GChatter& chatter) const
577 {
578  // Initialise result string
579  std::string result;
580 
581  // Continue only if chatter is not silent
582  if (chatter != SILENT) {
583 
584  // Append header
585  result.append("=== GModelSpectralPlaw ===");
586 
587  // Append information
588  result.append("\n"+gammalib::parformat("Number of parameters"));
589  result.append(gammalib::str(size()));
590  for (int i = 0; i < size(); ++i) {
591  result.append("\n"+m_pars[i]->print(chatter));
592  }
593 
594  } // endif: chatter was not silent
595 
596  // Return result
597  return result;
598 }
599 
600 
601 /*==========================================================================
602  = =
603  = Private methods =
604  = =
605  ==========================================================================*/
606 
607 /***********************************************************************//**
608  * @brief Initialise class members
609  ***************************************************************************/
611 {
612  // Initialise model type
613  m_type = "PowerLaw";
614 
615  // Initialise powerlaw normalisation
616  m_norm.clear();
617  m_norm.name("Prefactor");
618  m_norm.unit("ph/cm2/s/MeV");
619  m_norm.scale(1.0);
620  m_norm.value(1.0); // default: 1.0
621  m_norm.min(0.0); // min: 0.0
622  m_norm.free();
623  m_norm.gradient(0.0);
624  m_norm.has_grad(true);
625 
626  // Initialise powerlaw index
627  m_index.clear();
628  m_index.name("Index");
629  m_index.scale(1.0);
630  m_index.value(-2.0); // default: -2.0
631  m_index.range(-10.0,+10.0); // range: [-10,+10]
632  m_index.free();
633  m_index.gradient(0.0);
634  m_index.has_grad(true);
635 
636  // Initialise pivot energy
637  m_pivot.clear();
638  m_pivot.name("PivotEnergy");
639  m_pivot.unit("MeV");
640  m_pivot.scale(1.0);
641  m_pivot.value(100.0); // default: 100
642  m_pivot.fix();
643  m_pivot.gradient(0.0);
644  m_pivot.has_grad(true);
645 
646  // Set parameter pointer(s)
647  m_pars.clear();
648  m_pars.push_back(&m_norm);
649  m_pars.push_back(&m_index);
650  m_pars.push_back(&m_pivot);
651 
652  // Initialise eval cache
654  m_last_norm = 1.0e30;
655  m_last_index = 1.0e30;
656  m_last_pivot = 1.0e30;
657  m_last_e_norm = 0.0;
658  m_last_log_e_norm = 0.0;
659  m_last_power = 0.0;
660 
661  // Initialise MC cache
662  m_mc_emin = 0.0;
663  m_mc_emax = 0.0;
664  m_mc_exponent = 0.0;
665  m_mc_pow_emin = 0.0;
666  m_mc_pow_ewidth = 0.0;
667 
668  // Return
669  return;
670 }
671 
672 
673 /***********************************************************************//**
674  * @brief Copy class members
675  *
676  * @param[in] model GModelSpectralPlaw members which should be copied.
677  ***************************************************************************/
679 {
680  // Copy members
681  m_type = model.m_type;
682  m_norm = model.m_norm;
683  m_index = model.m_index;
684  m_pivot = model.m_pivot;
685 
686  // Set parameter pointer(s)
687  m_pars.clear();
688  m_pars.push_back(&m_norm);
689  m_pars.push_back(&m_index);
690  m_pars.push_back(&m_pivot);
691 
692  // Copy eval cache
694  m_last_norm = model.m_last_norm;
695  m_last_index = model.m_last_index;
696  m_last_pivot = model.m_last_pivot;
699  m_last_power = model.m_last_power;
700 
701  // Copy MC cache
702  m_mc_emin = model.m_mc_emin;
703  m_mc_emax = model.m_mc_emax;
707 
708  // Return
709  return;
710 }
711 
712 
713 /***********************************************************************//**
714  * @brief Delete class members
715  ***************************************************************************/
717 {
718  // Return
719  return;
720 }
721 
722 
723 /***********************************************************************//**
724  * @brief Update eval precomputation cache
725  *
726  * @param[in] energy Energy.
727  *
728  * Updates the precomputation cache for eval() method.
729  ***************************************************************************/
731 {
732  // Get parameter values (takes 2 multiplications which are difficult
733  // to avoid)
734  double index = m_index.value();
735  double pivot = m_pivot.value();
736 
737  // If the energy or one of the parameters index or pivot energy has
738  // changed then recompute the cache
739  if ((m_last_energy != energy) ||
740  (m_last_index != index) ||
741  (m_last_pivot != pivot)) {
742 
743  // Store actual energy and parameter values
744  m_last_energy = energy;
747 
748  // Compute and store value
749  double eng = energy.MeV();
750  m_last_e_norm = eng / m_last_pivot;
753 
754  } // endif: recomputation was required
755 
756  // Return
757  return;
758 }
759 
760 
761 /***********************************************************************//**
762  * @brief Update Monte Carlo pre computation cache
763  *
764  * @param[in] emin Minimum photon energy.
765  * @param[in] emax Maximum photon energy.
766  *
767  * Updates the precomputation cache for Monte Carlo simulations.
768  ***************************************************************************/
770  const GEnergy& emax) const
771 
772 {
773  // Case A: Index is not -1
774  if (index() != -1.0) {
775 
776  // Change in energy boundaries?
777  if (emin.MeV() != m_mc_emin || emax.MeV() != m_mc_emax) {
778  m_mc_emin = emin.MeV();
779  m_mc_emax = emax.MeV();
780  m_mc_exponent = index() + 1.0;
783  }
784 
785  }
786 
787  // Case B: Index is -1
788  else {
789 
790  // Change in energy boundaries?
791  if (emin.MeV() != m_mc_emin || emax.MeV() != m_mc_emax) {
792  m_mc_emin = emin.MeV();
793  m_mc_emax = emax.MeV();
794  m_mc_exponent = 0.0;
797  }
798 
799  }
800 
801  // Return
802  return;
803 }
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 gradient factor.
double norm(const GVector &vector)
Computes vector norm.
Definition: GVector.cpp:821
virtual ~GModelSpectralPlaw(void)
Destructor.
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
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:353
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:47
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:54
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:1127
bool is_free(void) const
Signal if parameter is free.
Power law spectral model class.
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:184
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:167
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.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual void read(const GXmlElement &xml)
Read model from XML element.
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:1513
double m_last_e_norm
Last E/Epivot value.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Definition: GVector.cpp:1184
double uniform(void)
Returns random double precision floating value in range 0 to 1.
Definition: GRan.cpp:242
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")
virtual GModelSpectralPlaw * clone(void) const
Clone spectral power law model.
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:1332
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:1142
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:1022
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:1562
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 value factor.
#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:1079
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:413
void copy_members(const GModelSpectralPlaw &model)
Copy class members.