40 const double c_theta_max = 3.0;
41 const double c_max_exponent = 0.5 * c_theta_max * c_theta_max;
42 const double c_fraction = 1.0 -
std::exp(-c_max_exponent);
48 #if defined(G_LEGACY_XML_FORMAT)
54 #define G_CONSTRUCTOR "GModelSpatialEllipticalGauss::"\
55 "GModelSpatialEllipticalGauss(GSkyDir&, double&, double&, "\
56 "double&, std::string&)"
57 #define G_READ "GModelSpatialEllipticalGauss::read(GXmlElement&)"
58 #define G_WRITE "GModelSpatialEllipticalGauss::write(GXmlElement&)"
63 #define G_SMALL_ANGLE_APPROXIMATION
97 const std::string& type) :
130 const double& semimajor,
131 const double& semiminor,
132 const double& posangle,
133 const std::string& coordsys) :
137 if ((coordsys !=
"CEL") && (coordsys !=
"GAL")) {
138 std::string msg =
"Invalid coordinate system \""+coordsys+
"\" "
139 "specified. Please specify either \"CEL\" or "
148 if (coordsys ==
"CEL") {
238 if (
this != &model) {
357 const double& posangle,
360 const bool& gradients)
const
372 #if defined(G_SMALL_ANGLE_APPROXIMATION)
374 double cosinus =
std::cos(rel_posangle);
375 double sinus =
std::sin(rel_posangle);
380 double r_relative = theta/r_ellipse;
381 double exponent = 0.5*r_relative*r_relative;
388 double term1 =
m_term1 * cosphi * cosphi;
389 double term2 =
m_term2 * sinphi * sinphi;
390 double term3 =
m_term3 * sinphi * cosphi;
393 double exponent = theta * theta * (term1 + term2 + term3);
397 if (exponent <= c_max_exponent) {
402 #if defined(G_NAN_CHECK)
404 std::cout <<
"*** ERROR: GModelSpatialEllipticalGauss::eval";
405 std::cout <<
"(theta=" << theta <<
"): NaN/Inf encountered";
406 std::cout <<
"(posangle=" << posangle <<
"): NaN/Inf encountered";
407 std::cout <<
" (value=" << value;
408 std::cout <<
", MinorAxis^2=" <<
m_minor2;
409 std::cout <<
", MaxjorAxis^2=" <<
m_major2;
410 std::cout <<
", m_norm=" <<
m_norm;
411 std::cout <<
")" << std::endl;
454 }
while (ran_major > c_theta_max);
457 }
while (ran_minor > c_theta_max);
462 double theta =
std::sqrt(theta1 * theta1 + theta2 * theta2);
475 return (photon.
dir());
492 const double& margin)
const
495 double distance = dir.
dist(this->
dir());
627 result.append(
"=== GModelSpatialEllipticalGauss ===");
632 for (
int i = 0; i <
size(); ++i) {
655 m_type =
"EllipticalGaussian";
738 bool changed =
false;
762 m_norm = (denom > 0.0) ? 1.0 / denom : 0.0;
767 #if !defined(G_SMALL_ANGLE_APPROXIMATION)
780 double cospos =
std::cos(posangle_rad);
781 double sinpos =
std::sin(posangle_rad);
GModelPar m_semimajor
Semi-major axis of ellipse (deg)
double m_last_major
Last semi-major axis.
virtual void write(GXmlElement &xml) const
Write model into XML element.
double m_sinpos2
squared sine of position angle
void free_members(void)
Delete class members.
virtual GModelSpatialEllipticalGauss * clone(void) const
Clone elliptical Gaussian model.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const
Checks whether model contains specified sky direction.
virtual void write(GXmlElement &xml) const
Write model into XML element.
Abstract elliptical spatial model base class.
const std::string & name(void) const
Return parameter name.
GModelSpatialEllipticalGauss(void)
Void constructor.
virtual GModelSpatialEllipticalGauss & operator=(const GModelSpatialEllipticalGauss &model)
Assignment operator.
GModelPar m_lon
Right Ascension or Galactic longitude (deg)
virtual void clear(void)
Clear elliptical Gaussian model.
int size(void) const
Return number of parameters.
double m_minor2
square of minor axis
virtual double eval(const double &theta, const double &posangle, const GEnergy &energy, const GTime &time, const bool &gradients=false) const
Evaluate function (in units of sr^-1)
virtual void read(const GXmlElement &xml)
Read model from XML element.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
GVector cos(const GVector &vector)
Computes cosine of vector elements.
double m_minor_rad
Minor axis in radians.
virtual GModelSpatialElliptical & operator=(const GModelSpatialElliptical &model)
Assignment operator.
const GSkyDir & dir(void) const
Return position of elliptical spatial model.
Random number generator class.
Interface for the circular sky region class.
Interface definition for the spatial model registry class.
double m_cospos2
squared cosine of position angle
void init_members(void)
Initialise class members.
double m_major2
square of major axis
GSkyRegionCircle m_region
Bounding circle.
virtual void set_region(void) const
Set boundary sky region.
bool is_notanumber(const double &x)
Signal if argument is not a number.
double m_term2
Help term 2.
Class that handles photons.
bool is_infinite(const double &x)
Signal if argument is infinite.
void update(void) const
Update precomputation cache.
double semiminor(void) const
Return semi-minor axis of ellipse.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
double m_norm
Normalization.
double m_last_minor
Last semi-minor axis.
Radial disk model class interface definition.
std::vector< GModelPar * > m_pars
Parameter pointers.
void rotate_deg(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
double m_sin2pos
sine of twice the position angle
Spatial model registry class definition.
double m_term3
Help term 3.
const GTime & time(void) const
Return photon time.
void init_members(void)
Initialise class members.
virtual void read(const GXmlElement &xml)
Read model from XML element.
GModelPar m_semiminor
Semi-minor axis of ellipse (deg)
std::string type(void) const
Return model type.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const
Returns MC sky direction.
void xml_check_parnum(const std::string &origin, const GXmlElement &xml, const int &number)
Checks number of parameters.
const GModelSpatialEllipticalGauss g_elliptical_gauss_seed
double normal(void)
Returns normal deviates.
const GSkyRegion * region(void) const
Return boundary sky region.
void free_members(void)
Delete class members.
double atan2d(const double &y, const double &x)
Compute arc tangens in degrees.
std::string m_type
Spatial model type.
double posangle(void) const
Return Position Angle of model.
double m_term1
Help term 1.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double m_last_posangle
Last position angle.
GModelPar m_lat
Declination or Galactic latitude (deg)
virtual std::string print(const GChatter &chatter=NORMAL) const
Print information.
void copy_members(const GModelSpatialEllipticalGauss &model)
Copy class members.
GVector sin(const GVector &vector)
Computes sine of vector elements.
const GEnergy & energy(void) const
Return photon energy.
Exception handler interface definition.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
Elliptical gauss model class interface definition.
void init_members(void)
Initialise class members.
virtual ~GModelSpatialEllipticalGauss(void)
Destructor.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void free_members(void)
Delete class members.
double m_major_rad
Major axis in radians.
double semimajor(void) const
Return semi-major axis of ellipse.
const GSkyDir & dir(void) const
Return photon sky direction.
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.
Mathematical function definitions.
Class that handles energies in a unit independent way.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
virtual double theta_max(void) const
Return maximum model radius (in radians)
void xml_check_type(const std::string &origin, GXmlElement &xml, const std::string &type)
Checks the model type.