48#define G_MC "GModelSpectralMultiplicative::mc(GEnergy&, GEnergy&, GTime&, "\
50#define G_WRITE "GModelSpectralMultiplicative::write(GXmlElement&)"
51#define G_COMPONENT_INDEX "GModelSpectralMultiplicative::component(int&)"
52#define G_COMPONENT_NAME "GModelSpectralMultiplicative::component"\
54#define G_APPEND "GModelSpectralMultiplicative::append(GModelSpectral&, "\
154 if (
this != &model) {
242 const GTime& srcTime,
243 const bool& gradients)
const
252 value =
m_spectral[0]->eval(srcEng, srcTime, gradients);
256 value *=
m_spectral[i]->eval(srcEng, srcTime, gradients);
273 factor *=
m_spectral[j]->eval(srcEng, srcTime,
false);
278 for (
int ipar = 0; ipar <
m_spectral[i]->size(); ++ipar) {
293 #if defined(G_NAN_CHECK)
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;
334 integral.
eps(1.0e-8);
371 integral.
eps(1.0e-8);
405 std::string msg =
"Multiplicative spectral model is empty. At least"
406 " one spectral model is required for simulations.";
431 int n_spectrals = xml.
elements(
"spectrum");
434 for (
int i = 0; i < n_spectrals; ++i) {
446 std::string component_name = spec->
attribute(
"component");
449 append(*ptr, component_name);
490 for (
int j = 0; j < cpy->
size(); ++j) {
494 std::string parname = par.
name();
541 const std::string& name)
550 std::string component_name = !name.empty() ? 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.";
571 for (
int ipar = 0; ipar < npars; ++ipar) {
577 par->
name(component_name+
":"+par->
name());
600 if (index >=
m_spectral.size() || index < 0) {
634 std::string msg =
"Model component \""+name+
"\" not found. Please "
635 "specify a valid model component name.";
659 result.append(
"=== GModelSpectralMultiplicative ===");
668 for (
int i = 0; i <
size(); ++i) {
691 m_type =
"Multiplicative";
727 for (
int i = 0; i < model.
components(); ++i) {
733 for (
int i = 0; i < model.
components(); ++i) {
739 for (
int ipar = 0; ipar < spec->
size(); ++ipar) {
797 if (par_changed ==
false) {
798 for (
int i = 0; i <
size(); ++i) {
817 for (
int i = 0; i <
size(); ++i) {
836 for (
int i = 0; i < energies.
size(); ++i) {
Energy container class definition.
Exception handler interface definition.
Integration class interface definition.
#define G_COMPONENT_INDEX
const GModelSpectralMultiplicative g_spectral_multi_seed
Multiplicative spectral model class interface definition.
Spectral nodes model class definition.
Spectral model registry class definition.
Random number generator class definition.
int size(void) const
Return number of energies in container.
Class that handles energies in a unit independent way.
double MeV(void) const
Return energy in MeV.
double log10MeV(void) const
Return log10 of energy in MeV.
void clear(void)
Clear instance.
GIntegral class interface definition.
void eps(const double &eps)
Set relative precision.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Multiplicative spectral model class.
void copy_members(const GModelSpectralMultiplicative &model)
Copy class members.
std::vector< GModelSpectral * > m_spectral
Container of spectral models.
virtual std::string type(void) const
Return model type.
virtual GModelSpectralMultiplicative & operator=(const GModelSpectralMultiplicative &model)
Assignment operator.
GModelSpectralMultiplicative(void)
Void constructor.
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.
const GModelSpectral * component(const int &index) const
Return spectral model component by index.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual void clear(void)
Clear multiplicative spectral model.
void append(const GModelSpectral &spec, const std::string &name="")
Append spectral component.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
std::vector< double > m_mc_values
Parameter values.
virtual ~GModelSpectralMultiplicative(void)
Destructor.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
virtual GModelSpectralMultiplicative * clone(void) const
Clone multiplicative spectral model model.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print multiplicative spectral model information.
GEnergy m_mc_emin
Last minimum energy.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
virtual void read(const GXmlElement &xml)
Read model from XML element.
GModelSpectralNodes m_mc_spectrum
MC spectrum cache.
std::string m_type
Model type.
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 Monte Carlo energy between [emin, emax].
GEnergy m_mc_emax
Last maximum energy.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual void clear(void)
Clear spectral nodes model.
void append(const GEnergy &energy, const double &intensity)
Append node.
Interface definition for the spectral model registry class.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
Abstract spectral model base class.
void free_members(void)
Delete class members.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
std::vector< GModelPar * > m_pars
Parameter pointers.
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual void write(GXmlElement &xml) const =0
int size(void) const
Return number of parameters.
void init_members(void)
Initialise class members.
double gradient(void) const
Return parameter gradient.
const std::string & name(void) const
Return parameter name.
Random number generator class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual int elements(void) const
Return number of GXMLElement children of node.
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
bool is_infinite(const double &x)
Signal if argument is infinite.
bool is_notanumber(const double &x)
Signal if argument is not a number.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.