50#define G_FLUX "GModelSpectralPlawEnergyFlux::flux(GEnergy&, GEnergy&)"
51#define G_EFLUX "GModelSpectralPlawEnergyFlux::eflux(GEnergy&, GEnergy&)"
52#define G_MC "GModelSpectralPlawEnergyFlux::mc(GEnergy&, GEnergy&, GTime&, "\
54#define G_READ "GModelSpectralPlawEnergyFlux::read(GXmlElement&)"
55#define G_WRITE "GModelSpectralPlawEnergyFlux::write(GXmlElement&)"
94 const std::string& eflux,
95 const std::string& index,
96 const std::string& emin,
97 const std::string& emax) :
220 if (
this != &model) {
342 const GTime& srcTime,
343 const bool& gradients)
const
370 #if defined(G_NAN_CHECK)
372 std::cout <<
"*** ERROR: GModelSpectralPlawEnergyFlux::eval";
373 std::cout <<
"(srcEng=" << srcEng;
374 std::cout <<
", srcTime=" << srcTime <<
"):";
375 std::cout <<
" NaN/Inf encountered";
376 std::cout <<
" (value=" << value;
377 std::cout <<
", eflux=" <<
eflux();
378 std::cout <<
", m_norm=" <<
m_norm;
379 std::cout <<
", m_power=" <<
m_power;
380 std::cout <<
")" << std::endl;
417 if (
index() != -2.0) {
419 double pow_ref_emin = std::pow(this->
emin().MeV(), gamma);
420 double pow_ref_emax = std::pow(this->
emax().MeV(), gamma);
422 (pow_ref_emax - pow_ref_emin);
425 double log_ref_emin = std::log(this->
emin().MeV());
426 double log_ref_emax = std::log(this->
emax().MeV());
428 (log_ref_emax - log_ref_emin);
432 if (
index() != -1.0) {
434 double pow_emin = std::pow(
emin.
MeV(), gamma);
435 double pow_emax = std::pow(
emax.
MeV(), gamma);
436 flux =
norm / gamma * (pow_emax - pow_emin);
441 double log_emin = std::log(
emin.
MeV());
442 double log_emax = std::log(
emax.
MeV());
443 flux =
norm * (log_emax - log_emin);
480 if (
index() != -2.0) {
482 double pow_ref_emin = std::pow(this->
emin().MeV(), gamma);
483 double pow_ref_emax = std::pow(this->
emax().MeV(), gamma);
484 double pow_emin = std::pow(
emin.
MeV(), gamma);
485 double pow_emax = std::pow(
emax.
MeV(), gamma);
486 double factor = (pow_emax - pow_emin) /
487 (pow_ref_emax - pow_ref_emin);
491 double log_emin = std::log(
emin.
MeV());
492 double log_emax = std::log(
emax.
MeV());
493 double log_ref_emin = std::log(this->
emin().MeV());
494 double log_ref_emax = std::log(this->
emax().MeV());
495 double factor = (log_emax - log_emin) /
496 (log_ref_emax - log_ref_emin);
530 if (
index() != -1.0) {
531 double exponent =
index() + 1.0;
532 double e_max = std::pow(
emax.
MeV(), exponent);
533 double e_min = std::pow(
emin.
MeV(), exponent);
535 double eng = (u > 0.0)
536 ? std::exp(std::log(u * (e_max - e_min) + e_min) / exponent)
543 double e_max = std::log(
emax.
MeV());
544 double e_min = std::log(
emin.
MeV());
546 double eng = std::exp(u * (e_max - e_min) + e_min);
628 result.append(
"=== GModelSpectralPlawEnergyFlux ===");
633 for (
int i = 0; i <
size(); ++i) {
781 double gamma =
index() + 2.0;
Exception handler interface definition.
Mathematical function definitions.
const GModelSpectralPlawEnergyFlux g_spectral_plaw_eflux_seed("PowerLaw", "EnergyFlux", "Index", "LowerLimit", "UpperLimit")
Energy flux normalized power law spectral model class interface definition.
Spectral model registry class definition.
Random number generator class definition.
double norm(const GVector &vector)
Computes vector norm.
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 write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Energy flux normalized power law spectral model class.
GModelSpectralPlawEnergyFlux(void)
Void constructor.
std::string m_type
Model type.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
double m_log_emax
Log(emax)
virtual GModelSpectralPlawEnergyFlux * clone(void) const
Clone power law model.
GModelPar m_index
Spectral index.
GEnergy m_last_energy
Last source energy.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual std::string type(void) const
Return model type.
virtual ~GModelSpectralPlawEnergyFlux(void)
Destructor.
double m_power
Power-law factor.
void free_members(void)
Delete class members.
double eflux(void) const
Return energy flux.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
void update(const GEnergy &srcEng) const
Update precomputed values.
double m_log_emin
Log(emin)
void copy_members(const GModelSpectralPlawEnergyFlux &model)
Copy class members.
double m_pow_emin
emin^(index+1)
GModelPar m_eflux
Energy flux (erg/cm2/s)
GEnergy emax(void) const
Return maximum energy.
GEnergy emin(void) const
Return minimum energy.
GModelPar m_emin
Lower energy limit (MeV)
double m_last_index
Last spectral index (MeV)
GEnergy m_last_emax
Last upper energy limit.
double index(void) const
Return power law index.
void init_members(void)
Initialise class members.
GEnergy m_last_emin
Last lower energy limit.
virtual void clear(void)
Clear power law model.
GModelPar m_emax
Upper energy limit (MeV)
double m_norm
Power-law normalization (for pivot energy 1 MeV)
double m_pow_emax
emax^(index+1)
double m_g_norm
Power-law normalization gradient.
virtual GModelSpectralPlawEnergyFlux & operator=(const GModelSpectralPlawEnergyFlux &model)
Assignment operator.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
Interface definition for the spectral model registry class.
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.
int size(void) const
Return number of parameters.
void init_members(void)
Initialise class members.
const double & factor_value(void) const
Return parameter factor value.
bool is_free(void) const
Signal if parameter is free.
void free(void)
Free a parameter.
const double & scale(void) const
Return parameter scale.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
const std::string & unit(void) const
Return parameter unit.
const double & factor_gradient(void) const
Return parameter factor gradient.
void fix(void)
Fix a parameter.
double gradient(void) const
Return parameter gradient.
void clear(void)
Clear parameter.
double value(void) const
Return parameter value.
const std::string & name(void) const
Return parameter name.
Random number generator class.
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.
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.
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.