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) {
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);
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);
484 norm =
m_flux.
value() * gamma / (pow_ref_emax - pow_ref_emin);
489 norm =
m_flux.
value() / (log_ref_emax - log_ref_emin);
493 if (
index() != -2.0) {
497 eflux = norm / gamma * (pow_emax - pow_emin);
504 eflux = norm * (log_emax - log_emin);
540 if (
index() != -1.0) {
541 double exponent =
index() + 1.0;
545 double eng = (u > 0.0)
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;
Photon flux normalized power law spectral model class.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
const double & factor_gradient(void) const
Return parameter factor gradient.
GEnergy m_last_emax
Last upper energy limit.
double norm(const GVector &vector)
Computes vector norm.
GEnergy m_last_energy
Last source energy.
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
Abstract spectral model base class.
virtual GModelSpectralPlawPhotonFlux * clone(void) const
Clone power law model.
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.
double index(void) const
Return power law index.
std::vector< GModelPar * > m_pars
Parameter pointers.
Spectral model registry class definition.
GModelSpectralPlawPhotonFlux(void)
Void constructor.
Random number generator class.
double MeV(void) const
Return energy in MeV.
const GModelSpectralPlawPhotonFlux g_spectral_plaw_phflux_seed1("PowerLaw","PhotonFlux","Index","LowerLimit","UpperLimit")
GModelPar m_emin
Lower energy limit (MeV)
bool is_free(void) const
Signal if parameter is free.
double log10MeV(void) const
Return log10 of energy in MeV.
GEnergy emax(void) const
Return maximum energy.
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.
void update(const GEnergy &srcEng) const
Update precomputed values.
GModelPar m_emax
Upper energy limit (MeV)
double m_log_emin
Log(emin)
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
virtual GModelSpectralPlawPhotonFlux & operator=(const GModelSpectralPlawPhotonFlux &model)
Assignment operator.
void free(void)
Free a parameter.
void free_members(void)
Delete class members.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
void fix(void)
Fix a parameter.
double m_last_index
Last spectral index (MeV)
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_index
Spectral index.
void copy_members(const GModelSpectralPlawPhotonFlux &model)
Copy class members.
double flux(void) const
Return photon flux.
double m_norm
Power-law normalization (for pivot energy 1 MeV)
Flux normalized power law spectral model class interface definition.
void init_members(void)
Initialise class members.
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.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print power law information.
double m_log_emax
Log(emax)
void init_members(void)
Initialise class members.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
GEnergy m_last_emin
Last lower energy limit.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
double m_power
Power-law factor.
double m_g_norm
Power-law normalization gradient.
const std::string & unit(void) const
Return parameter unit.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
Exception handler interface definition.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
double m_pow_emax
emax^(index+1)
virtual void read(const GXmlElement &xml)
Read model from XML element.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GEnergy emin(void) const
Return minimum energy.
virtual std::string type(void) const
Return model type.
GModelPar m_flux
Photon flux (ph/cm2/s)
virtual ~GModelSpectralPlawPhotonFlux(void)
Destructor.
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_pow_emin
emin^(index+1)
const double & factor_value(void) const
Return parameter factor value.
Mathematical function definitions.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
std::string m_type
Model type.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.