48#if defined(G_LEGACY_XML_FORMAT)
58#define G_FLUX "GModelSpectralPlawPhotonFlux::flux(GEnergy&, GEnergy&)"
59#define G_EFLUX "GModelSpectralPlawPhotonFlux::eflux(GEnergy&, GEnergy&)"
60#define G_MC "GModelSpectralPlawPhotonFlux::mc(GEnergy&, GEnergy&, GTime&, "\
62#define G_READ "GModelSpectralPlawPhotonFlux::read(GXmlElement&)"
63#define G_WRITE "GModelSpectralPlawPhotonFlux::write(GXmlElement&)"
104 const std::string& flux,
105 const std::string& index,
106 const std::string& emin,
107 const std::string& emax) :
230 if (
this != &model) {
350 const GTime& srcTime,
351 const bool& gradients)
const
377 #if defined(G_NAN_CHECK)
379 std::cout <<
"*** ERROR: GModelSpectralPlawPhotonFlux::eval";
380 std::cout <<
"(srcEng=" << srcEng;
381 std::cout <<
", srcTime=" << srcTime <<
"):";
382 std::cout <<
" NaN/Inf encountered";
383 std::cout <<
" (value=" << value;
384 std::cout <<
", flux=" <<
flux();
385 std::cout <<
", m_norm=" <<
m_norm;
386 std::cout <<
", m_power=" <<
m_power;
387 std::cout <<
")" << std::endl;
423 if (
index() != -1.0) {
425 double pow_emin = std::pow(
emin.
MeV(), gamma);
426 double pow_emax = std::pow(
emax.
MeV(), gamma);
427 double pow_ref_emin = std::pow(this->
emin().MeV(), gamma);
428 double pow_ref_emax = std::pow(this->
emax().MeV(), gamma);
429 double factor = (pow_emax - pow_emin) /
430 (pow_ref_emax - pow_ref_emin);
436 double log_emin = std::log(
emin.
MeV());
437 double log_emax = std::log(
emax.
MeV());
438 double log_ref_emin = std::log(this->
emin().MeV());
439 double log_ref_emax = std::log(this->
emax().MeV());
440 double factor = (log_emax - log_emin) /
441 (log_ref_emax - log_ref_emin);
480 if (
index() != -1.0) {
482 double pow_ref_emin = std::pow(this->
emin().MeV(), gamma);
483 double pow_ref_emax = std::pow(this->
emax().MeV(), gamma);
487 double log_ref_emin = std::log(this->
emin().MeV());
488 double log_ref_emax = std::log(this->
emax().MeV());
493 if (
index() != -2.0) {
495 double pow_emin = std::pow(
emin.
MeV(), gamma);
496 double pow_emax = std::pow(
emax.
MeV(), gamma);
497 eflux =
norm / gamma * (pow_emax - pow_emin);
502 double log_emin = std::log(
emin.
MeV());
503 double log_emax = std::log(
emax.
MeV());
540 if (
index() != -1.0) {
541 double exponent =
index() + 1.0;
542 double e_max = std::pow(
emax.
MeV(), exponent);
543 double e_min = std::pow(
emin.
MeV(), exponent);
545 double eng = (u > 0.0)
546 ? std::exp(std::log(u * (e_max - e_min) + e_min) / exponent)
553 double e_max = std::log(
emax.
MeV());
554 double e_min = std::log(
emin.
MeV());
556 double eng = std::exp(u * (e_max - e_min) + e_min);
638 result.append(
"=== GModelSpectralPlawPhotonFlux ===");
643 for (
int i = 0; i <
size(); ++i) {
791 double gamma =
index() + 1.0;
Exception handler interface definition.
Mathematical function definitions.
const GModelSpectralPlawPhotonFlux g_spectral_plaw_phflux_seed1("PowerLaw", "PhotonFlux", "Index", "LowerLimit", "UpperLimit")
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.
Photon flux normalized power law spectral model class.
virtual std::string type(void) const
Return model type.
void update(const GEnergy &srcEng) const
Update precomputed values.
double m_power
Power-law factor.
virtual GModelSpectralPlawPhotonFlux * clone(void) const
Clone power law model.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
double m_pow_emin
emin^(index+1)
double m_log_emax
Log(emax)
double m_last_index
Last spectral index (MeV)
GModelPar m_emax
Upper energy limit (MeV)
GModelSpectralPlawPhotonFlux(void)
Void constructor.
virtual void read(const GXmlElement &xml)
Read model from XML element.
GEnergy emin(void) const
Return minimum energy.
void init_members(void)
Initialise class members.
GEnergy m_last_emin
Last lower energy limit.
GEnergy emax(void) const
Return maximum energy.
virtual void write(GXmlElement &xml) const
Write model into XML element.
std::string m_type
Model type.
GEnergy m_last_energy
Last source energy.
virtual GModelSpectralPlawPhotonFlux & operator=(const GModelSpectralPlawPhotonFlux &model)
Assignment operator.
void free_members(void)
Delete class members.
void copy_members(const GModelSpectralPlawPhotonFlux &model)
Copy class members.
GModelPar m_flux
Photon flux (ph/cm2/s)
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
GModelPar m_index
Spectral index.
double m_log_emin
Log(emin)
double flux(void) const
Return photon flux.
double m_norm
Power-law normalization (for pivot energy 1 MeV)
double index(void) const
Return power law index.
double m_g_norm
Power-law normalization gradient.
virtual void clear(void)
Clear power law model.
virtual ~GModelSpectralPlawPhotonFlux(void)
Destructor.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
GModelPar m_emin
Lower energy limit (MeV)
double m_pow_emax
emax^(index+1)
GEnergy m_last_emax
Last upper energy limit.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/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.