GammaLib  1.7.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)
 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 std::string type (void) const
 Return model type. 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 GSkyRegionregion (void) const
 Return boundary sky region. 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 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...
 
double ra (void) const
 Return Right Ascencion of model centre. More...
 
double dec (void) const
 Return Declination of model centre. More...
 
void ra (const double &ra)
 Set Right Ascencion of model centre. More...
 
void dec (const double &dec)
 Set Declination of model centre. More...
 
GSkyDir dir (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...
 
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...
 
double flux (const GSkyRegion *reg, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
 Returns model flux integrated in circular 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...
 
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...
 
- 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

std::string m_type
 Model type. More...
 
GModelPar m_radius
 Inner shell radius (deg) More...
 
GModelPar m_width
 Shell thickness (deg) More...
 
GSkyRegionCircle m_region
 Bounding circle. 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_ra
 Right Ascension (deg) More...
 
GModelPar m_dec
 Declination (deg) More...
 
- Protected Attributes inherited from GModelSpatial
std::vector< GModelPar * > m_pars
 Parameter pointers. More...
 

Detailed Description

Definition at line 58 of file GModelSpatialRadialShell.hpp.

Constructor & Destructor Documentation

GModelSpatialRadialShell::GModelSpatialRadialShell ( void  )

Void constructor.

Constructs empty radial shell model.

Definition at line 71 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 89 of file GModelSpatialRadialShell.cpp.

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

GModelSpatialRadialShell::GModelSpatialRadialShell ( const GSkyDir dir,
const double &  radius,
const double &  width 
)

Shell constructor.

Parameters
[in]dirSky position of shell centre.
[in]radiusInner shell radius (degrees).
[in]widthShell width (degrees).

Constructs the shell model from the shell centre (dir), the inner shell radius, and the shell width.

Definition at line 114 of file GModelSpatialRadialShell.cpp.

References GModelSpatialRadial::dir(), init_members(), 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 141 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 160 of file GModelSpatialRadialShell.cpp.

References copy_members(), and init_members().

GModelSpatialRadialShell::~GModelSpatialRadialShell ( void  )
virtual

Destructor.

Definition at line 177 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 133 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 254 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 410 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 632 of file GModelSpatialRadialShell.cpp.

References m_last_radius, m_last_width, m_norm, m_radius, m_region, m_theta_in, m_theta_out, 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 300 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 742 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 760 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 657 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 354 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 199 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 (defaults to NORMAL).
Returns
String containing model information.

Implements GModelSpatialRadial.

Definition at line 540 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 161 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 175 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.
Exceptions
GException::model_invalid_parnumInvalid number of model parameters found in XML element.
GException::model_invalid_parnamesInvalid model parameter names found in XML 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 466 of file GModelSpatialRadialShell.cpp.

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

Referenced by GModelSpatialRadialShell().

GSkyRegion * GModelSpatialRadialShell::region ( void  ) const
inlinevirtual

Return boundary sky region.

Returns
Boundary sky region.

Returns a sky region that fully encloses the spatial model component.

Implements GModelSpatialRadial.

Definition at line 219 of file GModelSpatialRadialShell.hpp.

References m_region, and set_region().

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

Return maximum model radius (in radians)

Returns
Maximum model radius (in radians).

Implements GModelSpatialRadial.

Definition at line 426 of file GModelSpatialRadialShell.cpp.

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

Referenced by contains().

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

Return model type.

Returns
Model type.

Returns the type of the radial shell model.

Implements GModelSpatialRadial.

Definition at line 147 of file GModelSpatialRadialShell.hpp.

References m_type.

Referenced by GModelSpatialRadialShell().

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 687 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 190 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 204 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.
Exceptions
GException::model_invalid_spatialExisting XML element is not of type 'GaussFunction'
GException::model_invalid_parnumInvalid number of model parameters found in XML element.
GException::model_invalid_parnamesInvalid model parameter names found in XML element.

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 516 of file GModelSpatialRadialShell.cpp.

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

Member Data Documentation

double GModelSpatialRadialShell::m_last_radius
mutableprotected

Last shell radius (deg)

Definition at line 117 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 118 of file GModelSpatialRadialShell.hpp.

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

double GModelSpatialRadialShell::m_norm
mutableprotected

Shell normalization.

Definition at line 123 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 112 of file GModelSpatialRadialShell.hpp.

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

GSkyRegionCircle GModelSpatialRadialShell::m_region
mutableprotected

Bounding circle.

Definition at line 114 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), init_members(), region(), and set_region().

double GModelSpatialRadialShell::m_theta_in
mutableprotected

Inner shell radius (rad)

Definition at line 119 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 121 of file GModelSpatialRadialShell.hpp.

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

std::string GModelSpatialRadialShell::m_type
protected

Model type.

Definition at line 111 of file GModelSpatialRadialShell.hpp.

Referenced by copy_members(), GModelSpatialRadialShell(), init_members(), and type().

GModelPar GModelSpatialRadialShell::m_width
protected

Shell thickness (deg)

Definition at line 113 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 120 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 122 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: