47 #if defined(G_LEGACY_XML_FORMAT)
57 #define G_MC "GModelSpectralBrokenPlaw::mc(GEnergy&, GEnergy&, GTime&,"\
59 #define G_READ "GModelSpectralBrokenPlaw::read(GXmlElement&)"
60 #define G_WRITE "GModelSpectralBrokenPlaw::write(GXmlElement&)"
98 const std::string& prefactor,
99 const std::string& index1,
100 const std::string& breakenergy,
101 const std::string& index2) :
137 const double& index1,
139 const double& index2) :
229 if (
this != &model) {
349 const GTime& srcTime,
350 const bool& gradients)
const
392 #if defined(G_NAN_CHECK)
394 std::cout <<
"*** ERROR: GModelSpectralBrokenPlaw::eval";
395 std::cout <<
"(srcEng=" << srcEng;
396 std::cout <<
", srcTime=" << srcTime <<
"):";
397 std::cout <<
" NaN/Inf encountered";
398 std::cout <<
" (value=" << value;
404 std::cout <<
")" << std::endl;
575 for (inx =
m_mc_cum.size()-1; inx > 0; --inx) {
586 double eng = (u > 0.0)
595 double eng =
std::exp(u * (e_max - e_min) + e_min);
677 result.append(
"=== GModelSpectralBrokenPlaw ===");
682 for (
int i = 0; i <
size(); ++i) {
705 m_type =
"BrokenPowerLaw";
862 double eng = energy.
MeV();
904 double e_min = emin.
MeV();
905 double e_max = emax.
MeV();
919 if (inx_emin == inx_emax) {
959 for (
int i = 1; i <
m_mc_cum.size(); ++i) {
963 for (
int i = 0; i <
m_mc_cum.size(); ++i) {
968 for (
int i = 0; i <
m_mc_cum.size(); ++i) {
971 double exponent =
m_mc_exp[i] + 1.0;
GModelPar m_index2
Spectral index2.
void copy_members(const GModelSpectralBrokenPlaw &model)
Copy class members.
double m_last_index2
Last index1 parameter.
std::vector< double > m_mc_min
Lower boundary for MC.
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.
double index2(void) const
Return power law index2.
Random number generator class definition.
void update_mc_cache(const GEnergy &emin, const GEnergy &emax) const
Update Monte Carlo pre computation cache.
Abstract spectral model base class.
virtual void read(const GXmlElement &xml)
Read model from XML element.
double gradient(void) const
Return parameter gradient.
int size(void) const
Return number of parameters.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
virtual GModelSpectral & operator=(const GModelSpectral &model)
Assignment operator.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
virtual std::string type(void) const
Return model type.
std::vector< GModelPar * > m_pars
Parameter pointers.
Spectral model registry class definition.
void free_members(void)
Delete class members.
Random number generator class.
double m_last_log_e_norm
Last ln(E/Ebreakenergy) value.
std::vector< double > m_mc_exp
Exponent for MC.
double prefactor(void) const
Return pre factor.
double MeV(void) const
Return energy in MeV.
GModelPar m_index1
Spectral index1.
double m_last_power
Last power value.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const
Evaluate function.
double m_last_index1
Last index1 parameter.
virtual GModelSpectralBrokenPlaw * clone(void) const
Clone broken power law model.
void update_eval_cache(const GEnergy &energy) const
Update eval precomputation cache.
virtual void clear(void)
Clear broken power law model.
double min(void) const
Return parameter minimum boundary.
double m_mc_exponent1
Exponent (index1+1)
double plaw_energy_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute energy flux between two energies for a power law.
bool is_free(void) const
Signal if parameter is free.
std::vector< double > m_mc_cum
Cumulative distribution.
bool is_notanumber(const double &x)
Signal if argument is not a number.
const GModelSpectralBrokenPlaw g_spectral_blaw_seed1("BrokenPowerLaw","Prefactor","Index1","BreakEnergy","Index2")
GModelPar m_norm
Normalization factor.
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_mc_emin
Minimum energy.
GEnergy breakenergy(void) const
Return breakenergy energy.
GModelSpectralBrokenPlaw(void)
Void constructor.
std::vector< double > m_mc_max
Upper boundary for MC.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void free(void)
Free a parameter.
void fix(void)
Fix a parameter.
GModelPar m_breakenergy
Energy of spectral break.
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 GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const
Returns Monte Carlo energy between [emin, emax].
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.
double m_mc_pow_emin
Power of minimum energy.
Broken power law spectrum class definition.
double index1(void) const
Return power law index1.
Broken power law spectral model class.
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 double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
double m_last_breakenergy
Last breakenergy parameter.
std::string m_type
Model type.
virtual ~GModelSpectralBrokenPlaw(void)
Destructor.
virtual GModelSpectralBrokenPlaw & operator=(const GModelSpectralBrokenPlaw &model)
Assignment operator.
void init_members(void)
Initialise class members.
double m_mc_pow_ewidth
Power of energy width.
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.
GVector pow(const GVector &vector, const double &power)
Computes tanh of vector elements.
const std::string & unit(void) const
Return parameter unit.
double m_mc_exponent2
Exponent (index2+1)
Exception handler interface definition.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
GEnergy m_last_energy
Last energy value.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
double m_last_e_norm
Last E/Ebreakenergy value.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print brokenpowerlaw information.
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.
void init_members(void)
Initialise class members.
const double & factor_value(void) const
Return parameter factor value.
double m_mc_emax
Maximum energy.
Class that handles energies in a unit independent way.
double plaw_photon_flux(const double &emin, const double &emax, const double &epivot, const double &gamma)
Compute photon flux between two energies for a power law.
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.