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();
500 double e_min = emin.
MeV();
501 double e_max = emax.
MeV();
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) {
943 double power = std::pow(e_norm,
m_index) * std::exp(-e_cut);
944 double value =
m_norm * power;
959 double e_norm = energy * m_inv_pivot;
961 double power = std::pow(e_norm,
m_index) * std::exp(-e_cut);
962 double value =
m_norm * power * energy;
Exception handler interface definition.
Integration class interface definition.
const GModelSpectralExpInvPlaw g_spectral_einvplaw_seed1("ExponentialCutoffPowerLaw", "Prefactor", "Index", "PivotEnergy", "InverseCutoffEnergy")
Exponential cut off power law spectral 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.
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
void clear(void)
Clear instance.
GIntegral class interface definition.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double eval(const double &eng)
Kernel for energy flux integration.
double eval(const double &eng)
Kernel for photon flux integration.
double m_norm
Normalization.
double m_inv_pivot
1 / Pivot energy
double m_lambda
Cut-off parameter.
Exponential cut off power law spectral class.
void init_members(void)
Initialise class members.
GModelSpectralExpInvPlaw(void)
Void constructor.
GModelPar m_pivot
Pivot energy.
double m_last_e_lambda
Last E*lambda value.
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_last_e_norm
Last E/Epivot value.
GEnergy m_last_energy
Last energy value.
GModelPar m_norm
Normalization factor.
GEnergy pivot(void) const
Return pivot energy.
virtual std::string type(void) const
Return model type.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
void free_members(void)
Delete class members.
double m_mc_emin
Minimum energy.
double m_last_index
Last index parameter.
double m_last_pivot
Last pivot parameter.
void copy_members(const GModelSpectralExpInvPlaw &model)
Copy class members.
GModelPar m_lambda
Cut-off parameter.
double m_mc_pow_emin
Power of minimum energy.
virtual ~GModelSpectralExpInvPlaw(void)
Destructor.
GEnergy cutoff(void) const
Return cut-off energy.
virtual GModelSpectralExpInvPlaw & operator=(const GModelSpectralExpInvPlaw &model)
Assignment operator.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
virtual GModelSpectralExpInvPlaw * clone(void) const
Clone exponentially cut off power law model.
double m_last_power
Last power value.
double index(void) const
Return power law index.
double prefactor(void) const
Return pre factor.
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] (units: erg/cm2/s)
double m_mc_exponent
Exponent (index+1)
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual void clear(void)
Clear exponentially cut off power law model.
double m_last_lambda
Last cut-off parameter.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
GModelPar m_index
Spectral index.
std::string m_type
Model type.
double m_mc_emax
Maximum energy.
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.
void autoscale(void)
Autoscale parameters.
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.
double max(void) const
Return parameter maximum boundary.
double min(void) const
Return parameter minimum boundary.
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.
std::string print(const GChatter &chatter=NORMAL) const
Print time.
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.