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&, "\
148 if (
this != &model) {
226 const GTime& srcTime,
227 const bool& gradients)
const
236 value +=
m_spectral[i]->eval(srcEng, srcTime, gradients);
241 #if defined(G_NAN_CHECK)
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;
346 "Composite spectral model is empty. It is required to have at"\
347 " least one spectral model to run simulations");
385 int n_spectrals = xml.
elements(
"spectrum");
388 for (
int i = 0; i < n_spectrals; ++i) {
400 std::string component_name = spec->
attribute(
"component");
403 append(*ptr, component_name);
444 for (
int j = 0; j < cpy->
size(); ++j) {
448 std::string parname = par.
name();
491 const std::string& name)
500 std::string component_name = !name.empty() ? 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 "
519 for (
int ipar = 0; ipar < npars; ++ipar) {
525 par->
name(component_name+
":"+par->
name());
551 if (index >=
m_spectral.size() || index < 0) {
585 std::string msg =
"Model component \""+name+
"\" not found in composite "
611 result.append(
"=== GModelSpectralComposite ===");
620 for (
int i = 0; i <
size(); ++i) {
684 for (
int i = 0; i < model.
components(); ++i) {
693 for (
int ipar = 0; ipar < spec->
size(); ++ipar) {
749 if (par_changed ==
false) {
750 for (
int i = 0; i <
size(); ++i) {
769 for (
int i = 0; i <
size(); ++i) {
796 #if defined(G_DEBUG_UPDATE_MC_CACHE)
797 std::cout <<
"GModelSpectralComposite::update_mc_cache(";
798 std::cout << emin.
print() <<
"," << emax.
print() <<
"):";
801 std::cout <<
" prob[" << i <<
"]=" <<
m_mc_probs[i];
803 std::cout << std::endl;
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
bool contains(const std::string &str, const std::string &substring)
Checks if a substring is in a string.
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.
Spectral model registry class definition.
double sum(const GVector &vector)
Computes vector sum.
Random number generator class.
std::vector< std::string > split(const std::string &s, const std::string &sep)
Split string.
virtual int elements(void) const
Return number of GXMLElement children of node.
std::string m_type
Model type.
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.
virtual void read(const GXmlElement &xml)
Read model from XML element.
bool is_infinite(const double &x)
Signal if argument is infinite.
void append(const GModelSpectral &spec, const std::string &name="")
Append spectral component.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
double m_mc_flux
Flux cache.
const GModelSpectralComposite g_spectral_comp_seed
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
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.
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
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.
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.
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.
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.
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.
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.
GEnergy m_mc_emin
Last minimum energy.
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.