46 "InverseCutoffEnergy");
50 #define G_MC "GModelSpectralExpInvPlaw::mc(GEnergy&, GEnergy&, GTime&,"\
52 #define G_READ "GModelSpectralExpInvPlaw::read(GXmlElement&)"
53 #define G_WRITE "GModelSpectralExpInvPlaw::write(GXmlElement&)"
92 const std::string& prefactor,
93 const std::string& index,
94 const std::string& pivot,
95 const std::string& lambda) :
132 const double& lambda) :
259 if (
this != &model) {
367 const GTime& srcTime,
368 const bool& gradients)
const
404 #if defined(G_NAN_CHECK)
406 std::cout <<
"*** ERROR: GModelSpectralExpInvPlaw::eval";
407 std::cout <<
"(srcEng=" << srcEng;
408 std::cout <<
", srcTime=" << srcTime <<
"):";
409 std::cout <<
" NaN/Inf encountered";
410 std::cout <<
" (value=" << value;
412 std::cout <<
")" << std::endl;
454 double e_min = emin.
MeV();
455 double e_max = emax.
MeV();
458 flux = integral.romberg(e_min, e_max);
500 double e_min = emin.
MeV();
501 double e_max = emax.
MeV();
504 eflux = integral.romberg(e_min, e_max);
552 double acceptance_fraction;
560 double norm_emin =
std::exp(-emin.
MeV() * inv_ecut);
561 double norm_emax =
std::exp(-emax.
MeV() * inv_ecut);
562 double norm = (norm_emin > norm_emax) ? norm_emin : norm_emax;
565 #if defined(G_DEBUG_MC)
577 #if defined(G_DEBUG_MC)
585 if (
index() != -1.0) {
601 acceptance_fraction =
std::exp(-eng * inv_ecut);
603 }
while (ran.
uniform() * norm > acceptance_fraction);
609 #if defined(G_DEBUG_MC)
610 std::cout <<
"GModelSpectralExpInvPlaw::mc(";
611 std::cout << emin.
print() <<
"," << emax.
print() <<
"," << time.
print() <<
"):";
612 std::cout <<
" energy=" << energy.
print();
613 std::cout <<
" samples=" << samples << std::endl;
694 result.append(
"=== GModelSpectralExpInvPlaw ===");
699 for (
int i = 0; i <
size(); ++i) {
722 m_type =
"ExponentialCutoffPowerLaw";
876 double eng = energy.
MeV();
901 if (
index() != -1.0) {
944 double value =
m_norm * power;
959 double e_norm = energy * m_inv_pivot;
962 double value =
m_norm * power * energy;
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.
double m_norm
Normalization.
Abstract spectral model base class.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual GModelSpectralExpInvPlaw * clone(void) const
Clone exponentially cut off power law model.
double gradient(void) const
Return parameter gradient.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
int size(void) const
Return number of parameters.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
double m_last_power
Last power value.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
virtual void read(const GXmlElement &xml)
Read model from XML element.
std::vector< GModelPar * > m_pars
Parameter pointers.
Spectral model registry class definition.
double max(void) const
Return parameter maximum boundary.
double m_mc_pow_emin
Power of minimum energy.
Random number generator class.
double MeV(void) const
Return energy in MeV.
GEnergy m_last_energy
Last energy value.
GIntegral class interface definition.
double m_last_e_norm
Last E/Epivot value.
double min(void) const
Return parameter minimum boundary.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
bool is_free(void) const
Signal if parameter is free.
std::string m_type
Model type.
GModelPar m_index
Spectral index.
Exponential cut off power law spectral class.
double m_mc_pow_ewidth
Power of energy width.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
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 init_members(void)
Initialise class members.
double m_mc_exponent
Exponent (index+1)
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
GModelPar m_lambda
Cut-off parameter.
double m_last_pivot
Last pivot parameter.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
void free(void)
Free a parameter.
void fix(void)
Fix a parameter.
double m_mc_emax
Maximum energy.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
virtual void clear(void)
Clear exponentially cut off power law model.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Exponential cut off power law spectral class interface definition.
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_pivot
Pivot energy.
std::string print(const GChatter &chatter=NORMAL) const
Print time.
virtual std::string type(void) const
Return model type.
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.
double index(void) const
Return power law index.
void autoscale(void)
Autoscale parameters.
const GModelSpectralExpInvPlaw g_spectral_einvplaw_seed1("ExponentialCutoffPowerLaw","Prefactor","Index","PivotEnergy","InverseCutoffEnergy")
double m_inv_pivot
1 / Pivot energy
GModelSpectralExpInvPlaw(void)
Void constructor.
void init_members(void)
Initialise class members.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
GModelPar m_norm
Normalization factor.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
double m_last_lambda
Last cut-off parameter.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
const std::string & unit(void) const
Return parameter unit.
virtual ~GModelSpectralExpInvPlaw(void)
Destructor.
Exception handler interface definition.
virtual GModelSpectralExpInvPlaw & operator=(const GModelSpectralExpInvPlaw &model)
Assignment operator.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
double m_lambda
Cut-off parameter.
double m_last_index
Last index parameter.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void free_members(void)
Delete class members.
double eval(const double &eng)
Kernel for energy flux integration.
double m_last_e_lambda
Last E*lambda value.
double m_mc_emin
Minimum energy.
Integration class interface definition.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
GEnergy pivot(void) const
Return pivot energy.
double eval(const double &eng)
Kernel for photon flux integration.
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.
void clear(void)
Clear instance.
const double & factor_value(void) const
Return parameter factor value.
void copy_members(const GModelSpectralExpInvPlaw &model)
Copy class members.
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.