GammaLib  1.7.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-2017 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  * @exception GException::erange_invalid
393  * Energy range is invalid (emin < emax required).
394  *
395  * Returns Monte Carlo energy by randomly drawing from a multiplicative
396  * spectral model.
397  ***************************************************************************/
399  const GEnergy& emax,
400  const GTime& time,
401  GRan& ran) const
402 {
403  // Throw an exception if energy range is invalid
404  if (emin >= emax) {
405  throw GException::erange_invalid(G_MC, emin.MeV(), emax.MeV(),
406  "Minimum energy < maximum energy required.");
407  }
408 
409  // Throw exception if model container is empty
410  if (m_spectral.size() == 0) {
411  std::string msg = "Multiplicative spectral model is empty. At least"
412  " one spectral model is required for simulations.";
413  throw GException::runtime_error(G_MC, msg);
414  }
415 
416  // Update MC cache
417  update_mc_cache(emin, emax);
418 
419  // Set energy
420  GEnergy energy = m_mc_spectrum.mc(emin, emax, time, ran);
421 
422  // Return energy
423  return energy;
424 }
425 
426 
427 /***********************************************************************//**
428  * @brief Read model from XML element
429  *
430  * @param[in] xml XML element.
431  *
432  * Reads the spectral information from an XML element.
433  ***************************************************************************/
435 {
436  // Get number of spectral components
437  int n_spectrals = xml.elements("spectrum");
438 
439  // Loop over spectral elements
440  for (int i = 0; i < n_spectrals; ++i) {
441 
442  // Get spectral XML element
443  const GXmlElement* spec = xml.element("spectrum", i);
444 
445  // Allocate a spectral registry object
446  GModelSpectralRegistry registry;
447 
448  // Read spectral model
449  GModelSpectral* ptr = registry.alloc(*spec);
450 
451  // Get component attribute from XML file
452  std::string component_name = spec->attribute("component");
453 
454  // Append spectral component to container
455  append(*ptr, component_name);
456 
457  // Free spectral model
458  delete ptr;
459 
460  } // endfor: loop over components
461 
462  // Return
463  return;
464 }
465 
466 
467 /***********************************************************************//**
468  * @brief Write model into XML element
469  *
470  * @param[in] xml XML element.
471  *
472  * @exception GException::model_invalid_spectral
473  * Existing XML element is not of the expected type.
474  *
475  * Writes the spectral information into an XML element.
476  ***************************************************************************/
478 {
479  // Set model type
480  if (xml.attribute("type") == "") {
481  xml.attribute("type", type());
482  }
483 
484  // Verify model type
485  if (xml.attribute("type") != type()) {
487  "Spectral model is not of type \""+type()+"\".");
488  }
489 
490  // Loop over model components
491  for (int i = 0; i < m_spectral.size(); i++) {
492 
493  // Write spectral model
494  if (m_spectral[i] != NULL) {
495 
496  // Create new spectrum node
497  xml.append(GXmlElement("spectrum"));
498 
499  // Get new spectrum node
500  GXmlElement* spec = xml.element("spectrum", xml.elements("spectrum")-1);
501 
502  // Create temporary copy of the spectral model. This is a kluge to
503  // write out the original parameters.
504  GModelSpectral* cpy = m_spectral[i]->clone();
505 
506  // Loop over parameters of model
507  for (int j = 0; j < cpy->size(); ++j) {
508 
509  // Get model parameter and name
510  GModelPar& par = (*cpy)[j];
511  std::string parname = par.name();
512 
513  // Check if name contains colon
514  if (gammalib::contains(parname, ":")) {
515 
516  // Split at the colon
517  std::vector<std::string> splits = gammalib::split(parname, ":");
518 
519  // Use second part of the string to recover original
520  // parameter name
521  par.name(splits[1]);
522  }
523 
524  } // endfor: loop over parameters
525 
526  // Write spectral component
527  cpy->write(*spec);
528 
529  // Add component name if previously available
530  if (m_components[i] != gammalib::str(i+1)) {
531  spec->attribute("component", m_components[i]);
532  }
533 
534  // Remove temporary copy
535  delete cpy;
536 
537  } // endif: spectral model was not NULL
538 
539  } // endfor: loop over model components
540 
541  // Return
542  return;
543 }
544 
545 
546 /***********************************************************************//**
547  * @brief Append spectral component
548  *
549  * @param[in] spec Spectral model component.
550  * @param[in] name Name of spectral component (can be empty).
551  *
552  * @exception GException::invalid_value
553  * Invalid component name specified
554  *
555  * Appends a spectral component to the Multiplicative model
556  ***************************************************************************/
558  const std::string& name)
559 {
560  // Append model container
561  m_spectral.push_back(spec.clone());
562 
563  // Get index of latest model
564  int index = m_spectral.size()-1;
565 
566  // Use model index as component name if component name is empty
567  std::string component_name = !name.empty() ? name
568  : gammalib::str(m_spectral.size());
569 
570  // Check if component name is unique, throw exception if not
571  if (gammalib::contains(m_components, component_name)) {
572  std::string msg = "Attempt to append component with name \""+
573  component_name+"\" to multiplicative spectral model "
574  "container, but a component with the same name exists "
575  "already. Every component in the container needs a "
576  "unique name. On default the system will increment "
577  "an integer if no component name is provided.";
579  }
580 
581  // Add component name (for now simple number)
582  m_components.push_back(component_name);
583 
584  // Get number of spectral parameters from model
585  int npars = m_spectral[index]->size();
586 
587  // Loop over model parameters
588  for (int ipar = 0; ipar < npars; ++ipar) {
589 
590  // Get model parameter
591  GModelPar* par = &(m_spectral[index]->operator[](ipar));
592 
593  // Prepend component name to parameter name
594  par->name(component_name+":"+par->name());
595 
596  // Append model parameter with new name to internal container
597  m_pars.push_back(par);
598 
599  } // endfor: loop over model parameters
600 
601  // Return
602  return;
603 }
604 
605 
606 /***********************************************************************//**
607  * @brief Return spectral model component by index
608  *
609  * @param[in] index Index of spectral component.
610  * @return Pointer to spectral model.
611  *
612  * Returns a component of the multiplicative spectral model by @p index.
613  ***************************************************************************/
615 {
616  // Check if index is in validity range
617  if (index >= m_spectral.size() || index < 0) {
618  throw GException::out_of_range(G_COMPONENT_INDEX, "Component Index",
619  index, m_spectral.size());
620  }
621 
622  // Return spectral component
623  return m_spectral[index];
624 }
625 
626 
627 /***********************************************************************//**
628  * @brief Return spectral model component by name
629  *
630  * @param[in] name Name of spectral component.
631  * @return Pointer to spectral model.
632  *
633  * Returns a component of the multiplicative spectral model by @p name.
634  ***************************************************************************/
635 const GModelSpectral* GModelSpectralMultiplicative::component(const std::string& name) const
636 {
637  // Check if model name is found
638  int index = -1;
639  for (int i = 0; i < m_components.size(); ++i) {
640  if (m_components[i] == name) {
641  index = i;
642  break;
643  }
644  }
645 
646  // Check if component name was found
647  if (index == -1) {
649  }
650 
651  // Return spectral component
652  return m_spectral[index];
653 }
654 
655 
656 /***********************************************************************//**
657  * @brief Print multiplicative spectral model information
658  *
659  * @param[in] chatter Chattiness.
660  * @return String containing model information.
661  ***************************************************************************/
662 std::string GModelSpectralMultiplicative::print(const GChatter& chatter) const
663 {
664  // Initialise result string
665  std::string result;
666 
667  // Continue only if chatter is not silent
668  if (chatter != SILENT) {
669 
670  // Append header
671  result.append("=== GModelSpectralMultiplicative ===");
672 
673  // Append information
674  result.append("\n"+gammalib::parformat("Number of components"));
675  result.append(gammalib::str(components()));
676  result.append("\n"+gammalib::parformat("Number of parameters"));
677  result.append(gammalib::str(size()));
678 
679  // Print parameter information
680  for (int i = 0; i < size(); ++i) {
681  result.append("\n"+m_pars[i]->print(chatter));
682  }
683 
684  } // endif: chatter was not silent
685 
686  // Return result
687  return result;
688 }
689 
690 
691 /*==========================================================================
692  = =
693  = Private methods =
694  = =
695  ==========================================================================*/
696 
697 /***********************************************************************//**
698  * @brief Initialise class members
699  ***************************************************************************/
701 {
702  // Initialise model type
703  m_type = "Multiplicative";
704 
705  // Clear spectral models
706  m_spectral.clear();
707  m_components.clear();
708 
709  // Clear MC cache
711  m_mc_emin.clear();
712  m_mc_emax.clear();
713  m_mc_values.clear();
714 
715  // Return
716  return;
717 }
718 
719 
720 /***********************************************************************//**
721  * @brief Copy class members
722  *
723  * @param[in] model Multiplicative spectral model.
724  ***************************************************************************/
726 {
727  // Copy members
728  m_type = model.m_type;
729  m_components = model.m_components;
730 
731  // Copy MC cache
733  m_mc_emin = model.m_mc_emin;
734  m_mc_emax = model.m_mc_emax;
735  m_mc_values = model.m_mc_values;
736 
737  // Copy pointer(s) of spectral component
738  m_spectral.clear();
739  for (int i = 0; i < model.components(); ++i) {
740  m_spectral.push_back(model.m_spectral[i]->clone());
741  }
742 
743  // Store pointers to spectral parameters
744  m_pars.clear();
745  for (int i = 0; i < model.components(); ++i) {
746 
747  // Retrieve spectral model
748  GModelSpectral* spec = m_spectral[i];
749 
750  // Loop over parameters
751  for (int ipar = 0; ipar < spec->size(); ++ipar) {
752 
753  // Get model parameter reference
754  GModelPar& par = spec->operator[](ipar);
755 
756  // Append model parameter pointer to internal container
757  m_pars.push_back(&par);
758  }
759  }
760 
761  // Return
762  return;
763 }
764 
765 
766 /***********************************************************************//**
767  * @brief Delete class members
768  ***************************************************************************/
770 {
771  // Free memory
772  for (int i = 0; i < m_spectral.size(); ++i) {
773 
774  // Delete component i
775  if (m_spectral[i] != NULL) delete m_spectral[i];
776 
777  // Signal free pointer
778  m_spectral[i] = NULL;
779 
780  }
781 
782  // Return
783  return;
784 }
785 
786 
787 /***********************************************************************//**
788  * @brief Update Monte Carlo pre computation cache
789  *
790  * @param[in] emin Minimum photon energy.
791  * @param[in] emax Maximum photon energy.
792  *
793  * Updates the precomputation cache for Monte Carlo simulations. In case that
794  * the energy boundaries have changed or at least one of the model parameters
795  * has changed the method computes a spectral node function which has 100
796  * nodes per decade containing the multiplicative spectral model values and
797  * stores that into a Monte Carlo cache. This cache is then used by the mc()
798  * method for simulations.
799  ***************************************************************************/
801  const GEnergy& emax) const
802 
803 {
804  // Check if one of the parameters has changed. If the dimension of the
805  // parameter value cache differs from the number of parameters then notify
806  // a change. This will clear the cache and store the parameter values
807  // later
808  bool par_changed = (m_mc_values.size() != size());
809  if (par_changed == false) {
810  for (int i = 0; i < size(); ++i) {
811  if (m_pars[i]->value() != m_mc_values[i]) {
812  par_changed = true;
813  break;
814  }
815  }
816  }
817 
818  // Update cache if energy range or parameters have changed
819  if (par_changed || emin != m_mc_emin || emax != m_mc_emax) {
820 
821  // Store energy range
822  m_mc_emin = emin;
823  m_mc_emax = emax;
824 
825  // If parameters have changed then store the current parameter
826  // values for a comparison check for the next method call
827  if (par_changed) {
828  m_mc_values.clear();
829  for (int i = 0; i < size(); ++i) {
830  m_mc_values.push_back(m_pars[i]->value());
831  }
832  }
833 
834  // Clear spectral nodes
836 
837  // Compute number of nodes. We use here 100 nodes per log energy and
838  // assure that at least 100 nodes are used.
839  int nodes = int((emax.log10MeV() - emin.log10MeV()) * 100.0);
840  if (nodes < 100) {
841  nodes = 100;
842  }
843 
844  // Initialise energy array with fixed number of nodes
845  GEnergies energies = GEnergies(nodes, m_mc_emin, m_mc_emax, true);
846 
847  // Append nodes to spectral function
848  for (int i = 0; i < energies.size(); ++i) {
849  m_mc_spectrum.append(energies[i], eval(energies[i]));
850  }
851 
852  } // endif: emin and emax have changed
853 
854  // Return
855  return;
856 }
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:1221
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:380
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:47
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:862
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:580
#define G_COMPONENT_NAME
Time class.
Definition: GTime.hpp:54
Gammalib tools definition.
const GModelSpectral * component(const int &index) const
Return spectral model component by index.
GIntegral class interface definition.
Definition: GIntegral.hpp:45
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:184
bool is_infinite(const double &x)
Signal if argument is infinite.
Definition: GTools.hpp:167
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:162
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
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:206
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
Definition: GXmlNode.cpp:634
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:284
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Definition: GTools.cpp:1022
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:413