GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpectralMultiplicative.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * GModelSpectralMultiplicative.cpp - Multiplicative spectral model class *
3  * ----------------------------------------------------------------------- *
4  * copyright (C) 2016-2021 by Michael Mayer *
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 GModelSpectralMultiplicative.cpp
23  * @brief Multiplicative spectral model class implementation
24  * @author Michael Mayer
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 "GIntegral.hpp"
36 #include "GEnergies.hpp"
38 #include "GModelSpectralNodes.hpp"
40 
41 /* __ Constants __________________________________________________________ */
42 
43 /* __ Globals ____________________________________________________________ */
45 const GModelSpectralRegistry g_spectral_multi_registry(&g_spectral_multi_seed);
46 
47 /* __ Method name definitions ____________________________________________ */
48 #define G_MC "GModelSpectralMultiplicative::mc(GEnergy&, GEnergy&, GTime&, "\
49  "GRan&)"
50 #define G_WRITE "GModelSpectralMultiplicative::write(GXmlElement&)"
51 #define G_COMPONENT_INDEX "GModelSpectralMultiplicative::component(int&)"
52 #define G_COMPONENT_NAME "GModelSpectralMultiplicative::component"\
53  "(std::string&)"
54 #define G_APPEND "GModelSpectralMultiplicative::append(GModelSpectral&, "\
55  "std::string&)"
56 
57 /* __ Macros _____________________________________________________________ */
58 
59 /* __ Coding definitions _________________________________________________ */
60 
61 /* __ Debug definitions __________________________________________________ */
62 
63 
64 /*==========================================================================
65  = =
66  = Constructors/destructors =
67  = =
68  ==========================================================================*/
69 
70 /***********************************************************************//**
71  * @brief Void constructor
72  ***************************************************************************/
75 {
76  // Initialise private members for clean destruction
77  init_members();
78 
79  // Return
80  return;
81 }
82 
83 
84 /***********************************************************************//**
85  * @brief XML constructor
86  *
87  * @param[in] xml XML element containing spectral model information.
88  *
89  * Constructs a multiplicative spectral model by extracting information from
90  * an XML element. See the read() method for more information about the
91  * expected structure of the XML element.
92  ***************************************************************************/
95 {
96  // Initialise members
97  init_members();
98 
99  // Read information from XML element
100  read(xml);
101 
102  // Return
103  return;
104 }
105 
106 
107 /***********************************************************************//**
108  * @brief Copy constructor
109  *
110  * @param[in] model Multiplicative spectral model.
111  ***************************************************************************/
113  GModelSpectral(model)
114 {
115  // Initialise members
116  init_members();
117 
118  // Copy members
119  copy_members(model);
120 
121  // Return
122  return;
123 }
124 
125 
126 /***********************************************************************//**
127  * @brief Destructor
128  ***************************************************************************/
130 {
131  // Free members
132  free_members();
133 
134  // Return
135  return;
136 }
137 
138 
139 /*==========================================================================
140  = =
141  = Operators =
142  = =
143  ==========================================================================*/
144 
145 /***********************************************************************//**
146  * @brief Assignment operator
147  *
148  * @param[in] model Multiplicative spectral model.
149  * @return Multiplicative spectral model.
150  ***************************************************************************/
152 {
153  // Execute only if object is not identical
154  if (this != &model) {
155 
156  // Copy base class members
157  this->GModelSpectral::operator=(model);
158 
159  // Free members
160  free_members();
161 
162  // Initialise members
163  init_members();
164 
165  // Copy members
166  copy_members(model);
167 
168  } // endif: object was not identical
169 
170  // Return
171  return *this;
172 }
173 
174 
175 /*==========================================================================
176  = =
177  = Public methods =
178  = =
179  ==========================================================================*/
180 
181 /***********************************************************************//**
182  * @brief Clear multiplicative spectral model
183  ***************************************************************************/
185 {
186  // Free class members (base and derived classes, derived class first)
187  free_members();
189 
190  // Initialise members
192  init_members();
193 
194  // Return
195  return;
196 }
197 
198 
199 /***********************************************************************//**
200  * @brief Clone multiplicative spectral model model
201  *
202  * @return Pointer to deep copy of multiplicative spectral model.
203  ***************************************************************************/
205 {
206  // Clone spectral power law model
207  return new GModelSpectralMultiplicative(*this);
208 }
209 
210 
211 /***********************************************************************//**
212  * @brief Evaluate function
213  *
214  * @param[in] srcEng True photon energy.
215  * @param[in] srcTime True photon arrival time.
216  * @param[in] gradients Compute gradients?
217  * @return Model value (ph/cm2/s/MeV).
218  *
219  * Evaluates
220  *
221  * \f[
222  * \prod_{i=0}^{N} {M_{\rm i}}(\rm srcEng, srcTime)
223  * \f]
224  *
225  * where \f${M_{\rm i}}\f$ is the i-th model component.
226  *
227  * If the @p gradients flag is true the method will also compute the partial
228  * derivatives of each parameter of eachmodel component with respect to the
229  * parameters using
230  *
231  * \f[
232  * \frac{\delta S}{\delta P_{\rm ij}}\prod_{\rm k\neq \rm i}^{n} M_{\rm k}
233  * \f]
234  *
235  * where \f${P_{\rm ij}}\f$ is the j-th parameter of the i-th multiplicative
236  * component, while \f${M_{\rm k}}\f$ is the k-th model component and n the
237  * number of model components.
238  *
239  * @todo The method expects that energy!=0. Otherwise Inf or NaN may result.
240  ***************************************************************************/
242  const GTime& srcTime,
243  const bool& gradients) const
244 {
245  // Initialise result
246  double value = 0.0;
247 
248  // Check for available spectral components
249  if (m_spectral.size()) {
250 
251  // Set first spectral component
252  value = m_spectral[0]->eval(srcEng, srcTime, gradients);
253 
254  // Loop over model components
255  for (int i = 1; i < m_spectral.size(); ++i) {
256  value *= m_spectral[i]->eval(srcEng, srcTime, gradients);
257  }
258 
259  } // endfor: loop over model components
260 
261  // Modify gradients if requested
262  if (gradients) {
263 
264  // Loop over model components
265  for (int i = 0; i < m_spectral.size(); ++i) {
266 
267  // Initialise scaling factor
268  double factor = 1.0;
269 
270  // Loop over other model components and compute factor
271  for (int j = 0; j < m_spectral.size(); ++j) {
272  if (i != j) {
273  factor *= m_spectral[j]->eval(srcEng, srcTime, false);
274  }
275  }
276 
277  // Loop over model parameters
278  for (int ipar = 0; ipar < m_spectral[i]->size(); ++ipar) {
279 
280  // Get reference to model parameter
281  GModelPar& par = m_spectral[i]->operator[](ipar);
282 
283  // Scale parameter gradient
284  par.gradient(par.gradient()*factor);
285 
286  } // endfor: loop over model parameters
287 
288  } // endfor: loop over models
289 
290  } //endif: compute gradients
291 
292  // Compile option: Check for NaN/Inf
293  #if defined(G_NAN_CHECK)
294  if (gammalib::is_notanumber(value) || gammalib::is_infinite(value)) {
295  std::cout << "*** ERROR: GModelSpectralMultiplicative::eval";
296  std::cout << "(srcEng=" << srcEng;
297  std::cout << ", srcTime=" << srcTime << "):";
298  std::cout << " NaN/Inf encountered";
299  std::cout << " (value=" << value;
300  std::cout << ")" << std::endl;
301  }
302  #endif
303 
304  // Return
305  return value;
306 }
307 
308 
309 /***********************************************************************//**
310  * @brief Returns model photon flux between [emin, emax] (units: ph/cm2/s)
311  *
312  * @param[in] emin Minimum photon energy.
313  * @param[in] emax Maximum photon energy.
314  * @return Photon flux (ph/cm2/s).
315  *
316  * Computes the photon flux of multiplicative spectral model
317  ***************************************************************************/
319  const GEnergy& emax) const
320 {
321  // Initialise flux
322  double flux = 0.0;
323 
324  // Compute only if integration range is valid and components are available
325  if (emin < emax && m_spectral.size()) {
326 
327  // Initialise function to integrate
328  flux_kern kernel(m_spectral);
329 
330  // Initialise integral class with function
331  GIntegral integral(&kernel);
332 
333  // Set integration precision
334  integral.eps(1.0e-8);
335 
336  // Calculate integral between emin and emax
337  flux = integral.romberg(emin.MeV(), emax.MeV());
338 
339  } // endif: integration range was valid
340 
341  // Return flux
342  return flux;
343 }
344 
345 
346 /***********************************************************************//**
347  * @brief Returns model energy flux between [emin, emax] (units: erg/cm2/s)
348  *
349  * @param[in] emin Minimum photon energy.
350  * @param[in] emax Maximum photon energy.
351  * @return Energy flux (erg/cm2/s).
352  *
353  * Computes the energy flux of multiplicative spectral model
354  ***************************************************************************/
356  const GEnergy& emax) const
357 {
358  // Initialise eflux
359  double eflux = 0.0;
360 
361  // Compute only if integration range is valid and components are available
362  if (emin < emax && m_spectral.size()) {
363 
364  // Initialise function to integrate
365  eflux_kern kernel(m_spectral);
366 
367  // Initialise integral class with function
368  GIntegral integral(&kernel);
369 
370  // Set integration precision
371  integral.eps(1.0e-8);
372 
373  // Calculate integral between emin and emax
374  eflux = integral.romberg(emin.MeV(), emax.MeV());
375 
376  } // endif: integration range was valid
377 
378  // Return flux
379  return eflux;
380 }
381 
382 
383 /***********************************************************************//**
384  * @brief Returns Monte Carlo energy between [emin, emax]
385  *
386  * @param[in] emin Minimum photon energy.
387  * @param[in] emax Maximum photon energy.
388  * @param[in] time True photon arrival time.
389  * @param[in,out] ran Random number generator.
390  * @return Energy.
391  *
392  * Returns Monte Carlo energy by randomly drawing from a multiplicative
393  * spectral model.
394  ***************************************************************************/
396  const GEnergy& emax,
397  const GTime& time,
398  GRan& ran) const
399 {
400  // Check energy interval
402 
403  // Throw exception if model container is empty
404  if (m_spectral.size() == 0) {
405  std::string msg = "Multiplicative spectral model is empty. At least"
406  " one spectral model is required for simulations.";
407  throw GException::runtime_error(G_MC, msg);
408  }
409 
410  // Update MC cache
411  update_mc_cache(emin, emax);
412 
413  // Set energy
414  GEnergy energy = m_mc_spectrum.mc(emin, emax, time, ran);
415 
416  // Return energy
417  return energy;
418 }
419 
420 
421 /***********************************************************************//**
422  * @brief Read model from XML element
423  *
424  * @param[in] xml XML element.
425  *
426  * Reads the spectral information from an XML element.
427  ***************************************************************************/
429 {
430  // Get number of spectral components
431  int n_spectrals = xml.elements("spectrum");
432 
433  // Loop over spectral elements
434  for (int i = 0; i < n_spectrals; ++i) {
435 
436  // Get spectral XML element
437  const GXmlElement* spec = xml.element("spectrum", i);
438 
439  // Allocate a spectral registry object
440  GModelSpectralRegistry registry;
441 
442  // Read spectral model
443  GModelSpectral* ptr = registry.alloc(*spec);
444 
445  // Get component attribute from XML file
446  std::string component_name = spec->attribute("component");
447 
448  // Append spectral component to container
449  append(*ptr, component_name);
450 
451  // Free spectral model
452  delete ptr;
453 
454  } // endfor: loop over components
455 
456  // Return
457  return;
458 }
459 
460 
461 /***********************************************************************//**
462  * @brief Write model into XML element
463  *
464  * @param[in] xml XML element.
465  *
466  * Writes the spectral information into an XML element.
467  ***************************************************************************/
469 {
470  // Verify model type
472 
473  // Loop over model components
474  for (int i = 0; i < m_spectral.size(); i++) {
475 
476  // Write spectral model
477  if (m_spectral[i] != NULL) {
478 
479  // Create new spectrum node
480  xml.append(GXmlElement("spectrum"));
481 
482  // Get new spectrum node
483  GXmlElement* spec = xml.element("spectrum", xml.elements("spectrum")-1);
484 
485  // Create temporary copy of the spectral model. This is a kluge to
486  // write out the original parameters.
487  GModelSpectral* cpy = m_spectral[i]->clone();
488 
489  // Loop over parameters of model
490  for (int j = 0; j < cpy->size(); ++j) {
491 
492  // Get model parameter and name
493  GModelPar& par = (*cpy)[j];
494  std::string parname = par.name();
495 
496  // Check if name contains colon
497  if (gammalib::contains(parname, ":")) {
498 
499  // Split at the colon
500  std::vector<std::string> splits = gammalib::split(parname, ":");
501 
502  // Use second part of the string to recover original
503  // parameter name
504  par.name(splits[1]);
505  }
506 
507  } // endfor: loop over parameters
508 
509  // Write spectral component
510  cpy->write(*spec);
511 
512  // Add component name if previously available
513  if (m_components[i] != gammalib::str(i+1)) {
514  spec->attribute("component", m_components[i]);
515  }
516 
517  // Remove temporary copy
518  delete cpy;
519 
520  } // endif: spectral model was not NULL
521 
522  } // endfor: loop over model components
523 
524  // Return
525  return;
526 }
527 
528 
529 /***********************************************************************//**
530  * @brief Append spectral component
531  *
532  * @param[in] spec Spectral model component.
533  * @param[in] name Name of spectral component (can be empty).
534  *
535  * @exception GException::invalid_value
536  * Invalid component name specified
537  *
538  * Appends a spectral component to the Multiplicative model
539  ***************************************************************************/
541  const std::string& name)
542 {
543  // Append model container
544  m_spectral.push_back(spec.clone());
545 
546  // Get index of latest model
547  int index = m_spectral.size()-1;
548 
549  // Use model index as component name if component name is empty
550  std::string component_name = !name.empty() ? name
551  : gammalib::str(m_spectral.size());
552 
553  // Check if component name is unique, throw exception if not
554  if (gammalib::contains(m_components, component_name)) {
555  std::string msg = "Attempt to append component with name \""+
556  component_name+"\" to multiplicative spectral model "
557  "container, but a component with the same name exists "
558  "already. Every component in the container needs a "
559  "unique name. On default the system will increment "
560  "an integer if no component name is provided.";
562  }
563 
564  // Add component name (for now simple number)
565  m_components.push_back(component_name);
566 
567  // Get number of spectral parameters from model
568  int npars = m_spectral[index]->size();
569 
570  // Loop over model parameters
571  for (int ipar = 0; ipar < npars; ++ipar) {
572 
573  // Get model parameter
574  GModelPar* par = &(m_spectral[index]->operator[](ipar));
575 
576  // Prepend component name to parameter name
577  par->name(component_name+":"+par->name());
578 
579  // Append model parameter with new name to internal container
580  m_pars.push_back(par);
581 
582  } // endfor: loop over model parameters
583 
584  // Return
585  return;
586 }
587 
588 
589 /***********************************************************************//**
590  * @brief Return spectral model component by index
591  *
592  * @param[in] index Index of spectral component.
593  * @return Pointer to spectral model.
594  *
595  * Returns a component of the multiplicative spectral model by @p index.
596  ***************************************************************************/
598 {
599  // Check if index is in validity range
600  if (index >= m_spectral.size() || index < 0) {
601  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
602  index, m_spectral.size());
603  }
604 
605  // Return spectral component
606  return m_spectral[index];
607 }
608 
609 
610 /***********************************************************************//**
611  * @brief Return spectral model component by name
612  *
613  * @param[in] name Name of spectral component.
614  * @return Pointer to spectral model.
615  *
616  * @exception GException::invalid_argument
617  * Model component not found.
618  *
619  * Returns a component of the multiplicative spectral model by @p name.
620  ***************************************************************************/
621 const GModelSpectral* GModelSpectralMultiplicative::component(const std::string& name) const
622 {
623  // Check if model name is found
624  int index = -1;
625  for (int i = 0; i < m_components.size(); ++i) {
626  if (m_components[i] == name) {
627  index = i;
628  break;
629  }
630  }
631 
632  // Check if component name was found
633  if (index == -1) {
634  std::string msg = "Model component \""+name+"\" not found. Please "
635  "specify a valid model component name.";
637  }
638 
639  // Return spectral component
640  return m_spectral[index];
641 }
642 
643 
644 /***********************************************************************//**
645  * @brief Print multiplicative spectral model information
646  *
647  * @param[in] chatter Chattiness.
648  * @return String containing model information.
649  ***************************************************************************/
650 std::string GModelSpectralMultiplicative::print(const GChatter& chatter) const
651 {
652  // Initialise result string
653  std::string result;
654 
655  // Continue only if chatter is not silent
656  if (chatter != SILENT) {
657 
658  // Append header
659  result.append("=== GModelSpectralMultiplicative ===");
660 
661  // Append information
662  result.append("\n"+gammalib::parformat("Number of components"));
663  result.append(gammalib::str(components()));
664  result.append("\n"+gammalib::parformat("Number of parameters"));
665  result.append(gammalib::str(size()));
666 
667  // Print parameter information
668  for (int i = 0; i < size(); ++i) {
669  result.append("\n"+m_pars[i]->print(chatter));
670  }
671 
672  } // endif: chatter was not silent
673 
674  // Return result
675  return result;
676 }
677 
678 
679 /*==========================================================================
680  = =
681  = Private methods =
682  = =
683  ==========================================================================*/
684 
685 /***********************************************************************//**
686  * @brief Initialise class members
687  ***************************************************************************/
689 {
690  // Initialise model type
691  m_type = "Multiplicative";
692 
693  // Clear spectral models
694  m_spectral.clear();
695  m_components.clear();
696 
697  // Clear MC cache
699  m_mc_emin.clear();
700  m_mc_emax.clear();
701  m_mc_values.clear();
702 
703  // Return
704  return;
705 }
706 
707 
708 /***********************************************************************//**
709  * @brief Copy class members
710  *
711  * @param[in] model Multiplicative spectral model.
712  ***************************************************************************/
714 {
715  // Copy members
716  m_type = model.m_type;
717  m_components = model.m_components;
718 
719  // Copy MC cache
721  m_mc_emin = model.m_mc_emin;
722  m_mc_emax = model.m_mc_emax;
723  m_mc_values = model.m_mc_values;
724 
725  // Copy pointer(s) of spectral component
726  m_spectral.clear();
727  for (int i = 0; i < model.components(); ++i) {
728  m_spectral.push_back(model.m_spectral[i]->clone());
729  }
730 
731  // Store pointers to spectral parameters
732  m_pars.clear();
733  for (int i = 0; i < model.components(); ++i) {
734 
735  // Retrieve spectral model
736  GModelSpectral* spec = m_spectral[i];
737 
738  // Loop over parameters
739  for (int ipar = 0; ipar < spec->size(); ++ipar) {
740 
741  // Get model parameter reference
742  GModelPar& par = spec->operator[](ipar);
743 
744  // Append model parameter pointer to internal container
745  m_pars.push_back(&par);
746  }
747  }
748 
749  // Return
750  return;
751 }
752 
753 
754 /***********************************************************************//**
755  * @brief Delete class members
756  ***************************************************************************/
758 {
759  // Free memory
760  for (int i = 0; i < m_spectral.size(); ++i) {
761 
762  // Delete component i
763  if (m_spectral[i] != NULL) delete m_spectral[i];
764 
765  // Signal free pointer
766  m_spectral[i] = NULL;
767 
768  }
769 
770  // Return
771  return;
772 }
773 
774 
775 /***********************************************************************//**
776  * @brief Update Monte Carlo pre computation cache
777  *
778  * @param[in] emin Minimum photon energy.
779  * @param[in] emax Maximum photon energy.
780  *
781  * Updates the precomputation cache for Monte Carlo simulations. In case that
782  * the energy boundaries have changed or at least one of the model parameters
783  * has changed the method computes a spectral node function which has 100
784  * nodes per decade containing the multiplicative spectral model values and
785  * stores that into a Monte Carlo cache. This cache is then used by the mc()
786  * method for simulations.
787  ***************************************************************************/
789  const GEnergy& emax) const
790 
791 {
792  // Check if one of the parameters has changed. If the dimension of the
793  // parameter value cache differs from the number of parameters then notify
794  // a change. This will clear the cache and store the parameter values
795  // later
796  bool par_changed = (m_mc_values.size() != size());
797  if (par_changed == false) {
798  for (int i = 0; i < size(); ++i) {
799  if (m_pars[i]->value() != m_mc_values[i]) {
800  par_changed = true;
801  break;
802  }
803  }
804  }
805 
806  // Update cache if energy range or parameters have changed
807  if (par_changed || emin != m_mc_emin || emax != m_mc_emax) {
808 
809  // Store energy range
810  m_mc_emin = emin;
811  m_mc_emax = emax;
812 
813  // If parameters have changed then store the current parameter
814  // values for a comparison check for the next method call
815  if (par_changed) {
816  m_mc_values.clear();
817  for (int i = 0; i < size(); ++i) {
818  m_mc_values.push_back(m_pars[i]->value());
819  }
820  }
821 
822  // Clear spectral nodes
824 
825  // Compute number of nodes. We use here 100 nodes per log energy and
826  // assure that at least 100 nodes are used.
827  int nodes = int((emax.log10MeV() - emin.log10MeV()) * 100.0);
828  if (nodes < 100) {
829  nodes = 100;
830  }
831 
832  // Initialise energy array with fixed number of nodes
833  GEnergies energies = GEnergies(nodes, m_mc_emin, m_mc_emax, "LOG");
834 
835  // Append nodes to spectral function
836  for (int i = 0; i < energies.size(); ++i) {
837  m_mc_spectrum.append(energies[i], eval(energies[i]));
838  }
839 
840  } // endif: emin and emax have changed
841 
842  // Return
843  return;
844 }
virtual void write(GXmlElement &xml) const =0
virtual void read(const GXmlElement &xml)
Read model from XML element.
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
Definition: GTools.cpp:1342
std::vector< std::string > m_components
Names of components.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Definition: GIntegral.cpp:382
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
Abstract spectral model base class.
#define G_COMPONENT_INDEX
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
GModelSpectralMultiplicative(void)
Void constructor.
Multiplicative spectral model class.
std::vector< GModelPar * > m_pars
Parameter pointers.
XML element node class.
Definition: GXmlElement.hpp:48
Spectral model registry class definition.
std::vector< GModelSpectral * > m_spectral
Container of spectral models.
GEnergy m_mc_emin
Last minimum energy.
Random number generator class.
Definition: GRan.hpp:44
Spectral nodes model class definition.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
Definition: GTools.cpp:983
int components(void) const
Return number of spectral components.
double MeV(void) const
Return energy in MeV.
Definition: GEnergy.cpp:321
virtual GModelSpectralMultiplicative & operator=(const GModelSpectralMultiplicative &model)
Assignment operator.
virtual ~GModelSpectralMultiplicative(void)
Destructor.
virtual int elements(void) const
Return number of GXMLElement children of node.
Definition: GXmlNode.cpp:586
#define G_COMPONENT_NAME
Time class.
Definition: GTime.hpp:55
Gammalib tools definition.
const GModelSpectral * component(const int &index) const
Return spectral model component by index.
GIntegral class interface definition.
Definition: GIntegral.hpp:46
virtual GModelSpectralMultiplicative * clone(void) const
Clone multiplicative spectral model model.
std::vector< double > m_mc_values
Parameter values.
Energy container class.
Definition: GEnergies.hpp:60
double log10MeV(void) const
Return log10 of energy in MeV.
Definition: GEnergy.cpp:423
bool is_notanumber(const double &x)
Signal if argument is not a number.
Definition: GTools.hpp:201
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:184
void append(const GEnergy &energy, const double &intensity)
Append node.
Model parameter class.
Definition: GModelPar.hpp:87
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
void copy_members(const GModelSpectralMultiplicative &model)
Copy class members.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
Multiplicative spectral model class interface definition.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
Energy container class definition.
int size(void) const
Return number of energies in container.
Definition: GEnergies.hpp:170
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
Definition: GException.cpp:364
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
GChatter
Definition: GTypemaps.hpp:33
void append(const GModelSpectral &spec, const std::string &name="")
Append spectral component.
virtual std::string type(void) const
Return model type.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Interface definition for the spectral model registry class.
virtual void clear(void)
Clear multiplicative spectral model.
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print multiplicative spectral model information.
const GModelSpectralMultiplicative g_spectral_multi_seed
void eps(const double &eps)
Set relative precision.
Definition: GIntegral.hpp:214
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:640
virtual void clear(void)
Clear spectral nodes model.
void init_members(void)
Initialise class members.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
GEnergy m_mc_emax
Last maximum energy.
void free_members(void)
Delete class members.
Exception handler interface definition.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
Definition: GXmlNode.cpp:287
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1143
Integration class interface definition.
void free_members(void)
Delete class members.
GModelSpectralNodes m_mc_spectrum
MC spectrum cache.
void clear(void)
Clear instance.
Definition: GEnergy.cpp:261
void init_members(void)
Initialise class members.
Class that handles energies in a unit independent way.
Definition: GEnergy.hpp:48
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
Definition: GTools.cpp:489
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.
Definition: GTools.cpp:1819