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) {
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.
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.
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.
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.
Spectral nodes model class definition.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
int components(void) const
Return number of spectral components.
double MeV(void) const
Return energy in MeV.
virtual GModelSpectralMultiplicative & operator=(const GModelSpectralMultiplicative &model)
Assignment operator.
virtual ~GModelSpectralMultiplicative(void)
Destructor.
virtual int elements(void) const
Return number of GXMLElement children of node.
const GModelSpectral * component(const int &index) const
Return spectral model component by index.
GIntegral class interface definition.
virtual GModelSpectralMultiplicative * clone(void) const
Clone multiplicative spectral model model.
std::vector< double > m_mc_values
Parameter values.
double log10MeV(void) const
Return log10 of energy in MeV.
bool is_notanumber(const double &x)
Signal if argument is not a number.
bool is_infinite(const double &x)
Signal if argument is infinite.
void append(const GEnergy &energy, const double &intensity)
Append node.
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.
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.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
std::string m_type
Model type.
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.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
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.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
Integration class interface definition.
void free_members(void)
Delete class members.
GModelSpectralNodes m_mc_spectrum
MC spectrum cache.
void clear(void)
Clear instance.
void init_members(void)
Initialise class members.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.