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