48 #if defined(G_LEGACY_XML_FORMAT)
58 #define G_MC "GModelSpectralExpPlaw::mc(GEnergy&, GEnergy&, GTime&, GRan&)"
59 #define G_READ "GModelSpectralExpPlaw::read(GXmlElement&)"
60 #define G_WRITE "GModelSpectralExpPlaw::write(GXmlElement&)"
99 const std::string& prefactor,
100 const std::string& index,
101 const std::string& pivot,
102 const std::string& cutoff) :
229 if (
this != &model) {
337 const GTime& srcTime,
338 const bool& gradients)
const
374 #if defined(G_NAN_CHECK)
376 std::cout <<
"*** ERROR: GModelSpectralExpPlaw::eval";
377 std::cout <<
"(srcEng=" << srcEng;
378 std::cout <<
", srcTime=" << srcTime <<
"):";
379 std::cout <<
" NaN/Inf encountered";
380 std::cout <<
" (value=" << value;
382 std::cout <<
")" << std::endl;
424 double e_min = emin.
MeV();
425 double e_max = emax.
MeV();
428 flux = integral.romberg(e_min, e_max);
470 double e_min = emin.
MeV();
471 double e_max = emax.
MeV();
474 eflux = integral.romberg(e_min, e_max);
519 double acceptance_fraction;
527 double norm_emin =
std::exp(-emin.
MeV() * inv_ecut);
528 double norm_emax =
std::exp(-emax.
MeV() * inv_ecut);
529 double norm = (norm_emin > norm_emax) ? norm_emin : norm_emax;
532 #if defined(G_DEBUG_MC)
544 #if defined(G_DEBUG_MC)
552 if (
index() != -1.0) {
568 acceptance_fraction =
std::exp(-eng * inv_ecut);
570 }
while (ran.
uniform() * norm > acceptance_fraction);
576 #if defined(G_DEBUG_MC)
577 std::cout <<
"GModelSpectralExpPlaw::mc(";
578 std::cout << emin.
print() <<
"," << emax.
print() <<
"," << time.
print() <<
"):";
579 std::cout <<
" energy=" << energy.
print();
580 std::cout <<
" samples=" << samples << std::endl;
661 result.append(
"=== GModelSpectralExpPlaw ===");
666 for (
int i = 0; i <
size(); ++i) {
689 m_type =
"ExponentialCutoffPowerLaw";
842 double eng = energy.
MeV();
867 if (
index() != -1.0) {
910 double value =
m_norm * power;
925 double e_norm = energy * m_inv_pivot;
926 double e_cut = energy * m_inv_ecut;
928 double value =
m_norm * power * energy;
const double & factor_gradient(void) const
Return parameter factor gradient.
double m_last_e_norm
Last E/Epivot value.
double norm(const GVector &vector)
Computes vector norm.
double m_mc_emax
Maximum energy.
const std::string & name(void) const
Return parameter name.
Random number generator class definition.
Abstract spectral model base class.
double m_last_index
Last index parameter.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
virtual std::string type(void) const
Return model type.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
virtual void write(GXmlElement &xml) const
Write model into XML element.
void copy_members(const GModelSpectralExpPlaw &model)
Copy class members.
std::vector< GModelPar * > m_pars
Parameter pointers.
double m_mc_exponent
Exponent (index+1)
GEnergy pivot(void) const
Return pivot energy.
Spectral model registry class definition.
double eval(const double &eng)
Kernel for photon flux integration.
Random number generator class.
double MeV(void) const
Return energy in MeV.
double m_inv_pivot
1 / Pivot energy
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
GIntegral class interface definition.
void free_members(void)
Delete class members.
double min(void) const
Return parameter minimum boundary.
double m_norm
Normalization.
bool is_free(void) const
Signal if parameter is free.
GModelPar m_ecut
Exponential cut off energy.
bool is_notanumber(const double &x)
Signal if argument is not a number.
const GModelSpectralExpPlaw g_spectral_eplaw_seed1("ExponentialCutoffPowerLaw","Prefactor","Index","PivotEnergy","CutoffEnergy")
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
virtual ~GModelSpectralExpPlaw(void)
Destructor.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
GModelPar m_norm
Normalization factor.
virtual void read(const GXmlElement &xml)
Read model from XML element.
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns MC energy between [emin, emax].
std::string print(const GChatter &chatter=NORMAL) const
Print energy.
virtual void clear(void)
Clear exponentially cut off power law model.
void free(void)
Free a parameter.
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 m_last_ecut
Last energy cut-off parameter.
double uniform(void)
Returns random double precision floating value in range 0 to 1.
double m_mc_emin
Minimum energy.
void check_energy_interval(const std::string &origin, const GEnergy &emin, const GEnergy &emax)
Checks energy interval.
void clear(void)
Clear parameter.
GModelSpectralExpPlaw(void)
Void constructor.
double index(void) const
Return power law index.
std::string print(const GChatter &chatter=NORMAL) const
Print time.
GEnergy m_last_energy
Last energy value.
std::string m_type
Model type.
double m_last_pivot
Last pivot parameter.
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.
void autoscale(void)
Autoscale parameters.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
double m_last_power
Last power value.
void init_members(void)
Initialise class members.
double m_inv_ecut
1 / Cut off energy
double m_mc_pow_emin
Power of minimum energy.
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.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
const std::string & unit(void) const
Return parameter unit.
Exception handler interface definition.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
Exponential cut off power law spectral class.
double eval(const double &eng)
Kernel for energy flux integration.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
GModelPar m_pivot
Pivot energy.
virtual GModelSpectralExpPlaw & operator=(const GModelSpectralExpPlaw &model)
Assignment operator.
void init_members(void)
Initialise class members.
Exponential cut off power law spectral class interface definition.
virtual GModelSpectralExpPlaw * clone(void) const
Clone exponentially cut off power law model.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
GModelPar m_index
Spectral index.
Integration class interface definition.
double m_last_e_cut
Last E/Ecut value.
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.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
double m_mc_pow_ewidth
Power of energy width.
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.