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);
428 (log_ref_emax - log_ref_emin);
432 if (
index() != -1.0) {
436 flux = norm / gamma * (pow_emax - pow_emin);
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);
486 double factor = (pow_emax - pow_emin) /
487 (pow_ref_emax - pow_ref_emin);
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;
535 double eng = (u > 0.0)
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;
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_last_index
Last spectral index (MeV)
const double & factor_gradient(void) const
Return parameter factor gradient.
double norm(const GVector &vector)
Computes vector norm.
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
Abstract spectral model base class.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
std::vector< GModelPar * > m_pars
Parameter pointers.
Spectral model registry class definition.
GEnergy emin(void) const
Return minimum energy.
Random number generator class.
double MeV(void) const
Return energy in MeV.
void init_members(void)
Initialise class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
Energy flux normalized power law spectral model class interface definition.
virtual ~GModelSpectralPlawEnergyFlux(void)
Destructor.
bool is_free(void) const
Signal if parameter is free.
virtual GModelSpectralPlawEnergyFlux & operator=(const GModelSpectralPlawEnergyFlux &model)
Assignment operator.
virtual GModelSpectralPlawEnergyFlux * clone(void) const
Clone power law model.
double log10MeV(void) const
Return log10 of energy in MeV.
GModelPar m_emin
Lower energy limit (MeV)
void update(const GEnergy &srcEng) const
Update precomputed values.
std::string m_type
Model type.
bool is_notanumber(const double &x)
Signal if argument is not a number.
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
double m_power
Power-law factor.
GModelPar m_eflux
Energy flux (erg/cm2/s)
GEnergy m_last_emax
Last upper energy limit.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
GEnergy m_last_emin
Last lower energy limit.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual std::string type(void) const
Return model type.
double m_g_norm
Power-law normalization gradient.
void free(void)
Free a parameter.
GModelPar m_index
Spectral index.
void fix(void)
Fix a parameter.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
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.
void clear(void)
Clear parameter.
GModelPar m_emax
Upper energy limit (MeV)
GModelSpectralPlawEnergyFlux(void)
Void constructor.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
Interface definition for the spectral model registry class.
GEnergy m_last_energy
Last source energy.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
double m_pow_emin
emin^(index+1)
void init_members(void)
Initialise class members.
void copy_members(const GModelSpectralPlawEnergyFlux &model)
Copy class members.
double m_norm
Power-law normalization (for pivot energy 1 MeV)
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
double index(void) const
Return power law index.
double m_log_emax
Log(emax)
const std::string & unit(void) const
Return parameter unit.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
void free_members(void)
Delete class members.
const GModelSpectralPlawEnergyFlux g_spectral_plaw_eflux_seed("PowerLaw","EnergyFlux","Index","LowerLimit","UpperLimit")
Exception handler interface definition.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
double eflux(void) const
Return energy flux.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
double m_pow_emax
emax^(index+1)
Energy flux normalized power law spectral model class.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
GEnergy emax(void) const
Return maximum energy.
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.
void free_members(void)
Delete class members.
virtual void clear(void)
Clear power law model.
double m_log_emin
Log(emin)
const double & factor_value(void) const
Return parameter factor value.
Mathematical function definitions.
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.