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

Spatial composite model. More...

#include <GModelSpatialComposite.hpp>

Inheritance diagram for GModelSpatialComposite:
GModelSpatial GBase

Public Member Functions

 GModelSpatialComposite (void)
 Void constructor. More...
 
 GModelSpatialComposite (const bool &dummy, const std::string &type)
 Model type constructor. More...
 
 GModelSpatialComposite (const GXmlElement &xml)
 XML constructor. More...
 
 GModelSpatialComposite (const GModelSpatialComposite &model)
 Copy constructor. More...
 
virtual ~GModelSpatialComposite (void)
 Destructor. More...
 
virtual GModelSpatialCompositeoperator= (const GModelSpatialComposite &model)
 Assignment operator. More...
 
virtual void clear (void)
 Clear spatial composite model. More...
 
virtual GModelSpatialCompositeclone (void) const
 Clone spatial composite model. More...
 
virtual std::string classname (void) const
 Return class name. More...
 
virtual GClassCode code (void) const
 Return class code. More...
 
virtual double eval (const GPhoton &photon, const bool &gradients=false) const
 Evaluate function. More...
 
virtual GSkyDir mc (const GEnergy &energy, const GTime &time, GRan &ran) const
 Returns MC sky direction. More...
 
virtual double mc_norm (const GSkyDir &dir, const double &radius) const
 Return normalization of composite source for Monte Carlo simulations. More...
 
virtual bool contains (const GSkyDir &dir, const double &margin=0.0) const
 Checks where model contains specified sky direction. 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 composite spatial model information. More...
 
virtual double flux (const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
 Returns flux integrated in sky region. More...
 
int components (void) const
 Return number of model components. More...
 
void append (const GModelSpatial &component, const std::string &name="", const GModelPar &par=GModelPar("", 1.0))
 Append spatial component. More...
 
const GModelSpatialcomponent (const int &index) const
 Returns pointer to spatial component element. More...
 
const GModelSpatialcomponent (const std::string &name) const
 Returns pointer to specific spatial component. More...
 
double scale (const int &index) const
 Returns scale of spatial component. More...
 
double sum_of_scales (void) const
 Returns sum of all model scales. 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...
 
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 GModelSpatialComposite &model)
 Copy class members. More...
 
void free_members (void)
 Delete class members. More...
 
virtual void set_region (void) const
 Set boundary sky region. 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...
 

Protected Attributes

std::vector< GModelSpatial * > m_components
 Components. More...
 
std::vector< std::string > m_names
 Component names. More...
 
std::vector< GModelPar * > m_scales
 Component scales. 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

Spatial composite model.

This class implements the spatial model for a composition of spatial models.

Definition at line 47 of file GModelSpatialComposite.hpp.

Constructor & Destructor Documentation

GModelSpatialComposite::GModelSpatialComposite ( void  )

Void constructor.

Constructs empty spatial composite model.

Definition at line 70 of file GModelSpatialComposite.cpp.

References init_members().

Referenced by clone().

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

Model type constructor.

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

Constructs empty spatial composite model by specifying a model type.

Definition at line 88 of file GModelSpatialComposite.cpp.

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

GModelSpatialComposite::GModelSpatialComposite ( const GXmlElement xml)
explicit

XML constructor.

Parameters
[in]xmlXML element.

Construct a spatial composite 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 112 of file GModelSpatialComposite.cpp.

References init_members(), and read().

GModelSpatialComposite::GModelSpatialComposite ( const GModelSpatialComposite model)

Copy constructor.

Parameters
[in]modelSpatial composite model.

Definition at line 131 of file GModelSpatialComposite.cpp.

References copy_members(), and init_members().

GModelSpatialComposite::~GModelSpatialComposite ( void  )
virtual

Destructor.

Definition at line 148 of file GModelSpatialComposite.cpp.

References free_members().

Member Function Documentation

void GModelSpatialComposite::append ( const GModelSpatial component,
const std::string &  name = "",
const GModelPar par = GModelPar("", 1.0) 
)

Append spatial component.

Parameters
[in]componentSpatial model component to append.
[in]nameName of spatial model.
[in]parModel scaling parameter.

Appends a spatial component to the composite model

Definition at line 535 of file GModelSpatialComposite.cpp.

References GModelSpatial::clone(), gammalib::contains(), G_APPEND, GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_components, m_names, GModelSpatial::m_pars, m_scales, GOptimizerPar::name(), scale(), GOptimizerPar::scale(), and gammalib::str().

Referenced by read().

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

Return class name.

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

Implements GModelSpatial.

Definition at line 114 of file GModelSpatialComposite.hpp.

void GModelSpatialComposite::clear ( void  )
virtual

Clear spatial composite model.

Implements GModelSpatial.

Definition at line 203 of file GModelSpatialComposite.cpp.

References free_members(), GModelSpatial::free_members(), init_members(), and GModelSpatial::init_members().

GModelSpatialComposite * GModelSpatialComposite::clone ( void  ) const
virtual

Clone spatial composite model.

Returns
Pointer to deep copy of spatial composite model.

Implements GModelSpatial.

Definition at line 223 of file GModelSpatialComposite.cpp.

References GModelSpatialComposite().

GClassCode GModelSpatialComposite::code ( void  ) const
inlinevirtual

Return class code.

Returns
GModelSpatialComposite.

Returns the code GModelSpatialComposite of the class.

Implements GModelSpatial.

Definition at line 128 of file GModelSpatialComposite.hpp.

References GMODEL_SPATIAL_COMPOSITE.

const GModelSpatial * GModelSpatialComposite::component ( const int &  index) const

Returns pointer to spatial component element.

Parameters
[in]indexIndex of spatial component [0,...,components()-1].
Returns
Spatial model.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns a spatial component to the composite model

Definition at line 607 of file GModelSpatialComposite.cpp.

References G_COMPONENT_INDEX, and m_components.

Referenced by GResponse::irf_composite(), GCTAResponseIrf::nroi_composite(), and write().

const GModelSpatial * GModelSpatialComposite::component ( const std::string &  name) const

Returns pointer to specific spatial component.

Parameters
[in]nameName of spatial component.
Returns
Spatial model.
Exceptions
GException::invalid_argumentSpatial model not found.

Returns a spatial component of the composite model

Definition at line 631 of file GModelSpatialComposite.cpp.

References G_COMPONENT_NAME, m_components, and m_names.

int GModelSpatialComposite::components ( void  ) const
inline

Return number of model components.

Returns
Number of model components.

Definition at line 158 of file GModelSpatialComposite.hpp.

References m_components.

Referenced by GResponse::irf_composite(), GCTAResponseIrf::nroi_composite(), and print().

bool GModelSpatialComposite::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 one of the model components.

Implements GModelSpatial.

Definition at line 315 of file GModelSpatialComposite.cpp.

References m_components, and m_scales.

void GModelSpatialComposite::copy_members ( const GModelSpatialComposite model)
protected

Copy class members.

Parameters
[in]modelSpatial composite model.

Definition at line 798 of file GModelSpatialComposite.cpp.

References m_components, m_names, GModelSpatial::m_pars, m_scales, GModelSpatial::m_type, and scale().

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

double GModelSpatialComposite::eval ( const GPhoton photon,
const bool &  gradients = false 
) const
virtual

Evaluate function.

Parameters
[in]photonIncident photon.
[in]gradientsCompute gradients?
Returns
Model value.

Evaluates the spatial composite model by summing all model components, weighting by their scale and dividing the sum of all scales.

Implements GModelSpatial.

Definition at line 240 of file GModelSpatialComposite.cpp.

References m_components, m_scales, and sum_of_scales().

double GModelSpatialComposite::flux ( const GSkyRegion region,
const GEnergy srcEng = GEnergy(),
const GTime srcTime = GTime() 
) const
virtual

Returns flux integrated in sky region.

Parameters
[in]regionSky region.
[in]srcEngEnergy.
[in]srcTimeTime.
Returns
Flux (adimensional or ph/cm2/s).

Returns flux within a sky region.

Reimplemented from GModelSpatial.

Definition at line 710 of file GModelSpatialComposite.cpp.

References m_components, m_scales, and sum_of_scales().

void GModelSpatialComposite::free_members ( void  )
protected

Delete class members.

Definition at line 848 of file GModelSpatialComposite.cpp.

References m_components, and m_scales.

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

void GModelSpatialComposite::init_members ( void  )
protected

Initialise class members.

Definition at line 777 of file GModelSpatialComposite.cpp.

References m_components, m_names, GModelSpatial::m_pars, m_scales, and GModelSpatial::m_type.

Referenced by clear(), GModelSpatialComposite(), and operator=().

GSkyDir GModelSpatialComposite::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.

Draws an arbitrary model component and an arbitrary direction from that component.

Implements GModelSpatial.

Definition at line 273 of file GModelSpatialComposite.cpp.

References m_components, m_scales, sum(), sum_of_scales(), and GRan::uniform().

double GModelSpatialComposite::mc_norm ( const GSkyDir dir,
const double &  radius 
) const
inlinevirtual

Return normalization of composite source for Monte Carlo simulations.

Parameters
[in]dirCentre of simulation cone.
[in]radiusRadius of simulation cone (degrees).
Returns
Normalization.

Returns unity.

Implements GModelSpatial.

Definition at line 145 of file GModelSpatialComposite.hpp.

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

Assignment operator.

Parameters
[in]modelSpatial composite model.
Returns
Spatial composite model.

Definition at line 170 of file GModelSpatialComposite.cpp.

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

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

Print composite spatial model information.

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

Implements GModelSpatial.

Definition at line 739 of file GModelSpatialComposite.cpp.

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

double GModelSpatialComposite::scale ( const int &  index) const

Returns scale of spatial component.

Parameters
[in]indexIndex of spatial component [0,...,components()-1].
Returns
Scale.
Exceptions
GException::out_of_rangeIndex is out of range.

Returns the scale of a spatial component to the composite model

Definition at line 665 of file GModelSpatialComposite.cpp.

References G_COMPONENT_INDEX, and m_scales.

Referenced by append(), copy_members(), GResponse::irf_composite(), GCTAResponseIrf::nroi_composite(), and read().

void GModelSpatialComposite::set_region ( void  ) const
protectedvirtual

Set boundary sky region.

Todo:
Implement computation of sky boundary region

Implements GModelSpatial.

Definition at line 886 of file GModelSpatialComposite.cpp.

References GModelSpatial::m_region, and GModelSpatial::region().

double GModelSpatialComposite::sum_of_scales ( void  ) const

Returns sum of all model scales.

Returns
Sum of all model scales

Definition at line 683 of file GModelSpatialComposite.cpp.

References m_scales, and sum().

Referenced by eval(), flux(), GResponse::irf_composite(), mc(), and GCTAResponseIrf::nroi_composite().

void GModelSpatialComposite::write ( GXmlElement xml) const
virtual

Write model into XML element.

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

Write the spatial information into an XML element.

Implements GModelSpatial.

Definition at line 424 of file GModelSpatialComposite.cpp.

References GXmlNode::append(), GXmlElement::attribute(), GModelSpatial::clone(), component(), GXmlNode::element(), GXmlNode::elements(), G_WRITE, GXmlElement::has_attribute(), m_components, m_names, m_scales, max(), min(), GOptimizerPar::name(), GModelSpatial::size(), gammalib::str(), GModelSpatial::type(), GModelSpatial::write(), and gammalib::xml_check_type().

Member Data Documentation

std::vector<GModelSpatial*> GModelSpatialComposite::m_components
protected
std::vector<std::string> GModelSpatialComposite::m_names
protected

Component names.

Definition at line 103 of file GModelSpatialComposite.hpp.

Referenced by append(), component(), copy_members(), init_members(), and write().

std::vector<GModelPar*> GModelSpatialComposite::m_scales
protected

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