GammaLib  2.1.0.dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GModelSpatialRadialShell Class Reference

#include <GModelSpatialRadialShell.hpp>

Inheritance diagram for GModelSpatialRadialShell:
GModelSpatialRadial GModelSpatial GBase

Public Member Functions

 GModelSpatialRadialShell (void)
 Void constructor. More...
 
 GModelSpatialRadialShell (const bool &dummy, const std::string &type)
 Model type constructor. More...
 
 GModelSpatialRadialShell (const GSkyDir &dir, const double &radius, const double &width, const std::string &coordsys="CEL")
 Shell constructor. More...
 
 GModelSpatialRadialShell (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpatialRadialShell (const GModelSpatialRadialShell &model)
 Copy constructor. More...
 
virtual ~GModelSpatialRadialShell (void)
 Destructor. More...
 
virtual GModelSpatialRadialShelloperator= (const GModelSpatialRadialShell &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear radial shell model. More...
 
virtual GModelSpatialRadialShellclone (void) const
 Clone radial shell model. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual double eval (const double &theta, const GEnergy &energy, const GTime &time, const bool &gradients=false) const
 Evaluate function (in units of sr^-1) More...
 
virtual GSkyDir mc (const GEnergy &energy, const GTime &time, GRan &ran) const
 Returns MC sky direction. More...
 
virtual bool contains (const GSkyDir &dir, const double &margin=0.0) const
 Checks where model contains specified sky direction. More...
 
virtual double theta_max (void) const
 Return maximum model radius (in radians) More...
 
virtual void read (const GXmlElement &xml)
 Read model from XML element. More...
 
virtual void write (GXmlElement &xml) const
 Write model into XML element. More...
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print information. More...
 
double radius (void) const
 Return shell radius. More...
 
double width (void) const
 Return shell width. More...
 
void radius (const double &radius)
 Set shell radius. More...
 
void width (const double &width)
 Set width radius. More...
 
- Public Member Functions inherited from GModelSpatialRadial
 GModelSpatialRadial (void)
 Void constructor. More...
 
 GModelSpatialRadial (const GModelSpatialRadial &model)
 Copy constructor. More...
 
 GModelSpatialRadial (const GXmlElement &xml)
 XML constructor. More...
 
virtual ~GModelSpatialRadial (void)
 Destructor. More...
 
virtual GModelSpatialRadialoperator= (const GModelSpatialRadial &model)
 Assignment operator. More...
 
virtual GClassCode code (void) const
 Return class code. More...
 
virtual bool is_energy_dependent (void) const
 Signals whether radial model is energy dependent. More...
 
virtual bool is_time_dependent (void) const
 Signals whether radial model is time dependent. More...
 
virtual double eval (const GPhoton &photon, const bool &gradients=false) const
 Return model value. More...
 
virtual double mc_norm (const GSkyDir &dir, const double &radius) const
 Return normalization of radial source for Monte Carlo simulations. More...
 
std::string coordsys (void) const
 Return coordinate system. More...
 
const GSkyDirdir (void) const
 Return position of radial spatial model. More...
 
void dir (const GSkyDir &dir)
 Set position of radial spatial model. More...
 
- Public Member Functions inherited from GModelSpatial
 GModelSpatial (void)
 Void constructor. More...
 
 GModelSpatial (const GModelSpatial &model)
 Copy constructor. More...
 
virtual ~GModelSpatial (void)
 Destructor. More...
 
virtual GModelSpatialoperator= (const GModelSpatial &model)
 Assignment operator. More...
 
virtual GModelParoperator[] (const int &index)
 Returns model parameter. More...
 
virtual const GModelParoperator[] (const int &index) const
 Returns model parameter (const version) More...
 
virtual GModelParoperator[] (const std::string &name)
 Returns model parameter. More...
 
virtual const GModelParoperator[] (const std::string &name) const
 Returns model parameter (const version) More...
 
virtual double flux (const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
 Returns model flux within sky region. More...
 
std::string type (void) const
 Return model type. More...
 
void type (const std::string &type)
 Set model type. More...
 
GModelParat (const int &index)
 Returns model parameter. More...
 
const GModelParat (const int &index) const
 Returns model parameter (const version) More...
 
bool has_par (const std::string &name) const
 Checks if parameter name exists. More...
 
bool has_free_pars (void) const
 Checks if the spatial model has free parameters. More...
 
int size (void) const
 Return number of parameters. More...
 
void autoscale (void)
 Autoscale parameters. More...
 
const GSkyRegionregion (void) const
 Return boundary sky region. More...
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor. More...
 

Protected Member Functions

void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelSpatialRadialShell &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
void update (void) const
 Update precomputation cache. More...
 
virtual void set_region (void) const
 Set boundary sky region. More...
 
- Protected Member Functions inherited from GModelSpatialRadial
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelSpatialRadial &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
bool is_celestial (void) const
 Check if model holds celestial coordinates. More...
 
- Protected Member Functions inherited from GModelSpatial
void init_members (void)
 Initialise class members. More...
 
void copy_members (const GModelSpatial &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 

Static Protected Member Functions

static double f1 (double x)
 Return function 1 value needed for precomputation. More...
 
static double f2 (double x)
 Return function 2 value needed for precomputation. More...
 

Protected Attributes

GModelPar m_radius
 Inner shell radius (deg) More...
 
GModelPar m_width
 Shell thickness (deg) More...
 
double m_last_radius
 Last shell radius (deg) More...
 
double m_last_width
 Last shell width (deg) More...
 
double m_theta_in
 Inner shell radius (rad) More...
 
double m_x_in
 sin(m_theta_in)^2 More...
 
double m_theta_out
 Outer shell radius (rad) More...
 
double m_x_out
 sin(m_theta_out)^2 More...
 
double m_norm
 Shell normalization. More...
 
- Protected Attributes inherited from GModelSpatialRadial
GModelPar m_lon
 Right Ascension or Galactic longitude (deg) More...
 
GModelPar m_lat
 Declination or Galactic latitude (deg) More...
 
GSkyDir m_dir
 Sky direction representing parameters. More...
 
double m_last_lon
 Last longitude. More...
 
double m_last_lat
 Last latitude. More...
 
- Protected Attributes inherited from GModelSpatial
std::string m_type
 Spatial model type. More...
 
GSkyRegionCircle m_region
 Bounding circle. More...
 
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Definition at line 64 of file GModelSpatialRadialShell.hpp.

Constructor & Destructor Documentation

GModelSpatialRadialShell::GModelSpatialRadialShell ( void  )

Void constructor.

Constructs empty radial shell model.

Definition at line 73 of file GModelSpatialRadialShell.cpp.

References init_members().

Referenced by clone().

GModelSpatialRadialShell::GModelSpatialRadialShell ( const bool &  dummy,
const std::string &  type 
)

Model type constructor.

Parameters
[in]dummyDummy flag.
[in]typeModel type.

Constructs empty radial shell model by specifying a model type.

Definition at line 91 of file GModelSpatialRadialShell.cpp.

References init_members(), GModelSpatial::m_type, and GModelSpatial::type().

GModelSpatialRadialShell::GModelSpatialRadialShell ( const GSkyDir dir,
const double &  radius,
const double &  width,
const std::string &  coordsys = "CEL" 
)

Shell constructor.

Parameters
[in]dirSky position of shell centre.
[in]radiusInner shell radius (degrees).
[in]widthShell width (degrees).
[in]coordsysCoordinate system (either "CEL" or "GAL")
Exceptions
GException::invalid_argumentInvalid coordsys argument specified.

Constructs the shell model from the shell centre (dir), the inner shell radius, and the shell width. The coordsys parameter specifies whether the sky direction should be interpreted in the celestial or Galactic coordinate system.

Definition at line 122 of file GModelSpatialRadialShell.cpp.

References GModelSpatialRadial::dir(), G_CONSTRUCTOR, init_members(), GModelSpatialRadial::m_lat, GModelSpatialRadial::m_lon, GOptimizerPar::name(), radius(), and width().

GModelSpatialRadialShell::GModelSpatialRadialShell ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Constructs shell spatial model by extracting information from an XML element. See the read() method for more information about the expected structure of the XML element.

Definition at line 168 of file GModelSpatialRadialShell.cpp.

References init_members(), and read().

GModelSpatialRadialShell::GModelSpatialRadialShell ( const GModelSpatialRadialShell model)

Copy constructor.

Parameters
[in]modelRadial shell source model.

Definition at line 187 of file GModelSpatialRadialShell.cpp.

References copy_members(), and init_members().

GModelSpatialRadialShell::~GModelSpatialRadialShell ( void  )
virtual

Destructor.

Definition at line 204 of file GModelSpatialRadialShell.cpp.

References free_members().

Member Function Documentation

std::string GModelSpatialRadialShell::classname ( void  ) const
inlinevirtual

Return class name.

Returns
String containing the class name ("GModelSpatialRadialShell").

Implements GModelSpatialRadial.

Definition at line 136 of file GModelSpatialRadialShell.hpp.

void GModelSpatialRadialShell::clear ( void  )
virtual
GModelSpatialRadialShell * GModelSpatialRadialShell::clone ( void  ) const
virtual

Clone radial shell model.

Returns
Pointer to deep copy of radial shell model.

Implements GModelSpatialRadial.

Definition at line 281 of file GModelSpatialRadialShell.cpp.

References GModelSpatialRadialShell().

bool GModelSpatialRadialShell::contains ( const GSkyDir dir,
const double &  margin = 0.0 
) const
virtual

Checks where model contains specified sky direction.

Parameters
[in]dirSky direction.
[in]marginMargin to be added to sky direction (degrees)
Returns
True if the model contains the sky direction.

Signals whether a sky direction is contained in the radial shell model.

Implements GModelSpatialRadial.

Definition at line 437 of file GModelSpatialRadialShell.cpp.

References gammalib::deg2rad, GModelSpatialRadial::dir(), GSkyDir::dist(), and theta_max().

void GModelSpatialRadialShell::copy_members ( const GModelSpatialRadialShell model)
protected

Copy class members.

Parameters
[in]modelRadial shell source model.

We do not have to push back the members on the parameter stack as this should have been done by init_members() that was called before. Otherwise we would have the radius and width twice on the stack.

Definition at line 641 of file GModelSpatialRadialShell.cpp.

References m_last_radius, m_last_width, m_norm, m_radius, m_theta_in, m_theta_out, GModelSpatial::m_type, m_width, m_x_in, and m_x_out.

Referenced by GModelSpatialRadialShell(), and operator=().

double GModelSpatialRadialShell::eval ( const double &  theta,
const GEnergy energy,
const GTime time,
const bool &  gradients = false 
) const
virtual

Evaluate function (in units of sr^-1)

Parameters
[in]thetaAngular distance from shell centre (radians).
[in]energyPhoton energy.
[in]timePhoton arrival time.
[in]gradientsCompute gradients?
Returns
Model value.

Evaluates the spatial part for a shell source model. The shell source model is a radial function \(f(\theta)\), where \(\theta\) is the angular separation between shell centre and the actual location.

The function is given by

\[ S_{\rm p}(\vec{p} | E, t) = {\tt m\_norm} \left \{ \begin{array}{l l} \displaystyle \sqrt{ \sin^2 \theta_{\rm out} - \sin^2 \theta } - \sqrt{ \sin^2 \theta_{\rm in} - \sin^2 \theta } & \mbox{if $\theta \le \theta_{\rm in}$} \\ \\ \displaystyle \sqrt{ \sin^2 \theta_{\rm out} - \sin^2 \theta } & \mbox{if $\theta_{\rm in} < \theta \le \theta_{\rm out}$} \\ \\ \displaystyle 0 & \mbox{if $\theta > \theta_{\rm out}$} \end{array} \right . \]

Here, \(\theta_{\rm in}\) and \(\theta_{\rm out}\) are the shell inner and outer radius.

The method will not compute analytical parameter gradients, even if the gradients argument is set to true. Radial disk parameter gradients need to be computed numerically.

Implements GModelSpatialRadial.

Definition at line 327 of file GModelSpatialRadialShell.cpp.

References gammalib::is_infinite(), gammalib::is_notanumber(), m_norm, m_x_in, m_x_out, sin(), sqrt(), and update().

Referenced by mc().

double GModelSpatialRadialShell::f1 ( double  x)
staticprotected

Return function 1 value needed for precomputation.

Computes \(f1(x) = \sqrt{1 - \cos 2 x}\).

Definition at line 750 of file GModelSpatialRadialShell.cpp.

References cos(), and sqrt().

Referenced by f2(), and update().

double GModelSpatialRadialShell::f2 ( double  x)
staticprotected

Return function 2 value needed for precomputation.

Compute

\[f2(x) = \frac{1+\cos 2x}{4} \ln \left( \frac{\sqrt{2} \cos x}{\sqrt{2} + \sqrt{ 1 - \cos 2 x}} \right)\]

.

Definition at line 768 of file GModelSpatialRadialShell.cpp.

References cos(), f1(), log(), and gammalib::sqrt_two.

Referenced by update().

void GModelSpatialRadialShell::free_members ( void  )
protected

Delete class members.

Definition at line 665 of file GModelSpatialRadialShell.cpp.

Referenced by clear(), operator=(), and ~GModelSpatialRadialShell().

GSkyDir GModelSpatialRadialShell::mc ( const GEnergy energy,
const GTime time,
GRan ran 
) const
virtual

Returns MC sky direction.

Parameters
[in]energyPhoton energy.
[in]timePhoton arrival time.
[in,out]ranRandom number generator.
Returns
Sky direction.
Exceptions
GException::invalid_return_valueInvalid u_max value

Draws an arbitrary sky position from the 2D shell distribution.

Implements GModelSpatialRadial.

Definition at line 381 of file GModelSpatialRadialShell.cpp.

References GModelSpatialRadial::dir(), eval(), G_MC, m_norm, m_theta_out, m_x_out, gammalib::rad2deg, GSkyDir::rotate_deg(), sin(), GRan::uniform(), and update().

GModelSpatialRadialShell & GModelSpatialRadialShell::operator= ( const GModelSpatialRadialShell model)
virtual

Assignment operator.

Parameters
[in]modelRadial shell source model.
Returns
Radial shell source model.

Definition at line 226 of file GModelSpatialRadialShell.cpp.

References copy_members(), free_members(), init_members(), and GModelSpatialRadial::operator=().

std::string GModelSpatialRadialShell::print ( const GChatter chatter = NORMAL) const
virtual

Print information.

Parameters
[in]chatterChattiness.
Returns
String containing model information.

Implements GModelSpatialRadial.

Definition at line 552 of file GModelSpatialRadialShell.cpp.

References GModelSpatial::m_pars, gammalib::parformat(), SILENT, GModelSpatial::size(), and gammalib::str().

double GModelSpatialRadialShell::radius ( void  ) const
inline

Return shell radius.

Returns
Shell radius (degrees).

Returns the shell radius in degrees.

Definition at line 150 of file GModelSpatialRadialShell.hpp.

References m_radius, and GOptimizerPar::value().

Referenced by GModelSpatialRadialShell(), GCTAResponseIrf::irf_radial(), GCTAResponseIrf::nroi_radial(), read(), theta_max(), update(), and write().

void GModelSpatialRadialShell::radius ( const double &  radius)
inline

Set shell radius.

Parameters
[in]radiusShell radius (degrees).

Sets the shell radius in degrees.

Definition at line 164 of file GModelSpatialRadialShell.hpp.

References m_radius, and GOptimizerPar::value().

void GModelSpatialRadialShell::read ( const GXmlElement xml)
virtual

Read model from XML element.

Parameters
[in]xmlXML element.

Reads the radial shell model information from an XML element. The XML element shall have either the format

<spatialModel type="RadialShell">
  <parameter name="RA"     scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
  <parameter name="DEC"    scale="1.0" value="22.0145" min="-90"  max="90"  free="1"/>
  <parameter name="Radius" scale="1.0" value="0.30"    min="0.01" max="10"  free="1"/>
  <parameter name="Width"  scale="1.0" value="0.10"    min="0.01" max="10"  free="1"/>
</spatialModel>

or

<spatialModel type="RadialShell">
  <parameter name="GLON"   scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
  <parameter name="GLAT"   scale="1.0" value="22.0145" min="-90"  max="90"  free="1"/>
  <parameter name="Radius" scale="1.0" value="0.30"    min="0.01" max="10"  free="1"/>
  <parameter name="Width"  scale="1.0" value="0.10"    min="0.01" max="10"  free="1"/>
</spatialModel>
Todo:
Implement tests of the radius and radius boundary and the width and width boundary. The radius and radius boundary should be >=0, the width and width boundary should be >0.

Reimplemented from GModelSpatialRadial.

Definition at line 488 of file GModelSpatialRadialShell.cpp.

References G_READ, m_radius, m_width, GOptimizerPar::name(), radius(), GModelSpatialRadial::read(), GModelPar::read(), width(), gammalib::xml_check_parnum(), and gammalib::xml_get_par().

Referenced by GModelSpatialRadialShell().

void GModelSpatialRadialShell::set_region ( void  ) const
protectedvirtual
double GModelSpatialRadialShell::theta_max ( void  ) const
virtual

Return maximum model radius (in radians)

Returns
Maximum model radius (in radians).

Implements GModelSpatialRadial.

Definition at line 453 of file GModelSpatialRadialShell.cpp.

References gammalib::deg2rad, radius(), and width().

Referenced by contains().

void GModelSpatialRadialShell::update ( void  ) const
protected

Update precomputation cache.

Performs precomputations that are valid for a given pair of radius and width values. The following members are set by this method: m_last_radius, m_last_width, m_theta_in, m_theta_out, m_x_in, m_x_out and m_norm.

m_theta_in contains the inner shell radius in radians, while m_theta_out contains the outer shell radius in radians.

\({\tt m\_x\_in} = \sin^2 {\tt m\_theta\_in}\), \({\tt m\_x\_out} = \sin^2 {\tt m\_theta\_out}\), and

\[{\tt m\_norm} = \frac{1}{2 \pi} \frac{\sqrt{1-\cos 2 {\tt m\_theta\_out}} - \sqrt{1-\cos 2 {\tt m\_theta\_in}}}{2 \sqrt{2}} + \frac{1+\cos 2 {\tt m\_theta\_out}}{4} \ln \left( \frac{\sqrt{2} \cos {\tt m\_theta\_out}} {\sqrt{2} + \sqrt{1 - \cos 2 {\tt m\_theta\_out}}} \right) - \frac{1+\cos 2 {\tt m\_theta\_in}}{4} \ln \left( \frac{\sqrt{2} \cos {\tt m\_theta\_in}} {\sqrt{2} + \sqrt{1 - \cos 2 {\tt m\_theta\_in}}} \right)\]

Definition at line 695 of file GModelSpatialRadialShell.cpp.

References gammalib::deg2rad, f1(), f2(), gammalib::is_infinite(), gammalib::is_notanumber(), m_last_radius, m_last_width, m_norm, m_theta_in, m_theta_out, m_x_in, m_x_out, radius(), sin(), gammalib::sqrt_two, gammalib::twopi, and width().

Referenced by eval(), and mc().

double GModelSpatialRadialShell::width ( void  ) const
inline

Return shell width.

Returns
Shell width (degrees).

Returns the shell width in degrees.

Definition at line 179 of file GModelSpatialRadialShell.hpp.

References m_width, and GOptimizerPar::value().

Referenced by GModelSpatialRadialShell(), read(), theta_max(), update(), and write().

void GModelSpatialRadialShell::width ( const double &  width)
inline

Set width radius.

Parameters
[in]widthShell width (degrees).

Sets the shell width in degrees.

Definition at line 193 of file GModelSpatialRadialShell.hpp.

References m_width, and GOptimizerPar::value().

void GModelSpatialRadialShell::write ( GXmlElement xml) const
virtual

Write model into XML element.

Parameters
[in]xmlXML element into which model information is written.

Writes the radial shell model information into an XML element. The XML element will have the format

<spatialModel type="RadialShell">
  <parameter name="RA"     scale="1.0" value="83.6331" min="-360" max="360" free="1"/>
  <parameter name="DEC"    scale="1.0" value="22.0145" min="-90"  max="90"  free="1"/>
  <parameter name="Radius" scale="1.0" value="0.30"    min="0.01" max="10"  free="1"/>
  <parameter name="Width"  scale="1.0" value="0.10"    min="0.01" max="10"  free="1"/>
</spatialModel>

Reimplemented from GModelSpatialRadial.

Definition at line 525 of file GModelSpatialRadialShell.cpp.

References G_WRITE, m_radius, m_width, GOptimizerPar::name(), radius(), GModelSpatial::type(), width(), GModelSpatialRadial::write(), GModelPar::write(), gammalib::xml_check_type(), and gammalib::xml_need_par().

Member Data Documentation

double GModelSpatialRadialShell::m_last_radius
mutableprotected

Last shell radius (deg)

Definition at line 120 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), and update().

double GModelSpatialRadialShell::m_last_width
mutableprotected

Last shell width (deg)

Definition at line 121 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), and update().

double GModelSpatialRadialShell::m_norm
mutableprotected

Shell normalization.

Definition at line 126 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), eval(), init_members(), mc(), and update().

GModelPar GModelSpatialRadialShell::m_radius
protected

Inner shell radius (deg)

Definition at line 116 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), radius(), read(), set_region(), and write().

double GModelSpatialRadialShell::m_theta_in
mutableprotected

Inner shell radius (rad)

Definition at line 122 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), and update().

double GModelSpatialRadialShell::m_theta_out
mutableprotected

Outer shell radius (rad)

Definition at line 124 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), mc(), and update().

GModelPar GModelSpatialRadialShell::m_width
protected

Shell thickness (deg)

Definition at line 117 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), read(), set_region(), width(), and write().

double GModelSpatialRadialShell::m_x_in
mutableprotected

sin(m_theta_in)^2

Definition at line 123 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), eval(), init_members(), and update().

double GModelSpatialRadialShell::m_x_out
mutableprotected

sin(m_theta_out)^2

Definition at line 125 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), eval(), init_members(), mc(), and update().


The documentation for this class was generated from the following files: