GammaLib 2.1.0.dev
Loading...
Searching...
No Matches
GModelSpatialComposite Class Reference

Spatial composite model. More...

#include <GModelSpatialComposite.hpp>

Inheritance diagram for GModelSpatialComposite:
GModelSpatial GBase

Public Member Functions

 GModelSpatialComposite (const bool &normalize=true)
 Void constructor.
 
 GModelSpatialComposite (const bool &dummy, const std::string &type)
 Model type constructor.
 
 GModelSpatialComposite (const GXmlElement &xml)
 XML constructor.
 
 GModelSpatialComposite (const GModelSpatialComposite &model)
 Copy constructor.
 
virtual ~GModelSpatialComposite (void)
 Destructor.
 
virtual GModelSpatialCompositeoperator= (const GModelSpatialComposite &model)
 Assignment operator.
 
virtual void clear (void)
 Clear spatial composite model.
 
virtual GModelSpatialCompositeclone (void) const
 Clone spatial composite model.
 
virtual std::string classname (void) const
 Return class name.
 
virtual GClassCode code (void) const
 Return class code.
 
virtual double eval (const GPhoton &photon, const bool &gradients=false) const
 Evaluate function.
 
virtual GSkyDir mc (const GEnergy &energy, const GTime &time, GRan &ran) const
 Returns MC sky direction.
 
virtual double mc_norm (const GSkyDir &dir, const double &radius) const
 Return normalization of composite source for Monte Carlo simulations.
 
virtual bool contains (const GSkyDir &dir, const double &margin=0.0) const
 Checks where model contains specified sky direction.
 
virtual void read (const GXmlElement &xml)
 Read model from XML element.
 
virtual void write (GXmlElement &xml) const
 Write model into XML element.
 
virtual std::string print (const GChatter &chatter=NORMAL) const
 Print composite spatial model information.
 
virtual double flux (const GSkyRegion &region, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
 Returns flux integrated in sky region.
 
int components (void) const
 Return number of model components.
 
void append (const GModelSpatial &component, const std::string &name="", const GModelPar &par=GModelPar("", 1.0))
 Append spatial component.
 
const GModelSpatialcomponent (const int &index) const
 Returns pointer to spatial component element.
 
const GModelSpatialcomponent (const std::string &name) const
 Returns pointer to specific spatial component.
 
std::string name (const int &index) const
 Returns names of spatial component.
 
const GModelParscale (const int &index) const
 Returns scale parameter of spatial component.
 
double sum_of_scales (void) const
 Returns sum of all model scales.
 
const bool & normalize (void) const
 Return normalisation flag.
 
- Public Member Functions inherited from GModelSpatial
 GModelSpatial (void)
 Void constructor.
 
 GModelSpatial (const GModelSpatial &model)
 Copy constructor.
 
virtual ~GModelSpatial (void)
 Destructor.
 
virtual GModelSpatialoperator= (const GModelSpatial &model)
 Assignment operator.
 
virtual GModelParoperator[] (const int &index)
 Returns model parameter.
 
virtual const GModelParoperator[] (const int &index) const
 Returns model parameter (const version)
 
virtual GModelParoperator[] (const std::string &name)
 Returns model parameter.
 
virtual const GModelParoperator[] (const std::string &name) const
 Returns model parameter (const version)
 
std::string type (void) const
 Return model type.
 
void type (const std::string &type)
 Set model type.
 
GModelParat (const int &index)
 Returns model parameter.
 
const GModelParat (const int &index) const
 Returns model parameter (const version)
 
bool has_par (const std::string &name) const
 Checks if parameter name exists.
 
bool has_free_pars (void) const
 Checks if the spatial model has free parameters.
 
int size (void) const
 Return number of parameters.
 
void autoscale (void)
 Autoscale parameters.
 
const GSkyRegionregion (void) const
 Return boundary sky region.
 
- Public Member Functions inherited from GBase
virtual ~GBase (void)
 Destructor.
 

Protected Member Functions

void init_members (void)
 Initialise class members.
 
void copy_members (const GModelSpatialComposite &model)
 Copy class members.
 
void free_members (void)
 Delete class members.
 
virtual void set_region (void) const
 Set boundary sky region.
 
- Protected Member Functions inherited from GModelSpatial
void init_members (void)
 Initialise class members.
 
void copy_members (const GModelSpatial &model)
 Copy class members.
 
void free_members (void)
 Delete class members.
 

Protected Attributes

bool m_normalize
 Normalize component.
 
bool m_has_normalize
 XML has normalize attribute.
 
std::vector< GModelSpatial * > m_components
 Components.
 
std::vector< std::string > m_names
 Component names.
 
std::vector< GModelPar * > m_scales
 Component scales.
 
- Protected Attributes inherited from GModelSpatial
std::string m_type
 Spatial model type.
 
GSkyRegionCircle m_region
 Bounding circle.
 
std::vector< GModelPar * > m_pars
 Parameter pointers.
 

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() [1/4]

GModelSpatialComposite::GModelSpatialComposite ( const bool & normalize = true)

Void constructor.

Parameters
[in]normalizeNormalize model components

Constructs empty spatial composite model. If the normalize argument is true the composite spatial model is normalised to unit, while if false, no normalisation is performed and the sum_of_scales() method returns unity.

Definition at line 77 of file GModelSpatialComposite.cpp.

References init_members(), m_normalize, and normalize().

Referenced by clone().

◆ GModelSpatialComposite() [2/4]

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 98 of file GModelSpatialComposite.cpp.

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

◆ GModelSpatialComposite() [3/4]

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 122 of file GModelSpatialComposite.cpp.

References init_members(), and read().

◆ GModelSpatialComposite() [4/4]

GModelSpatialComposite::GModelSpatialComposite ( const GModelSpatialComposite & model)

Copy constructor.

Parameters
[in]modelSpatial composite model.

Definition at line 141 of file GModelSpatialComposite.cpp.

References copy_members(), and init_members().

◆ ~GModelSpatialComposite()

GModelSpatialComposite::~GModelSpatialComposite ( void )
virtual

Destructor.

Definition at line 158 of file GModelSpatialComposite.cpp.

References free_members().

Member Function Documentation

◆ append()

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 591 of file GModelSpatialComposite.cpp.

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

Referenced by read().

◆ classname()

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

Return class name.

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

Implements GModelSpatial.

Definition at line 117 of file GModelSpatialComposite.hpp.

◆ clear()

void GModelSpatialComposite::clear ( void )
virtual

Clear spatial composite model.

Implements GModelSpatial.

Definition at line 213 of file GModelSpatialComposite.cpp.

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

◆ clone()

GModelSpatialComposite * GModelSpatialComposite::clone ( void ) const
virtual

Clone spatial composite model.

Returns
Pointer to deep copy of spatial composite model.

Implements GModelSpatial.

Definition at line 233 of file GModelSpatialComposite.cpp.

References GModelSpatialComposite().

◆ code()

GClassCode GModelSpatialComposite::code ( void ) const
inlinevirtual

Return class code.

Returns
GModelSpatialComposite.

Returns the code GModelSpatialComposite of the class.

Implements GModelSpatial.

Definition at line 131 of file GModelSpatialComposite.hpp.

References GMODEL_SPATIAL_COMPOSITE.

◆ component() [1/2]

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 663 of file GModelSpatialComposite.cpp.

References G_COMPONENT_INDEX, and m_components.

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

◆ component() [2/2]

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 687 of file GModelSpatialComposite.cpp.

References G_COMPONENT_NAME, m_components, m_names, and name().

◆ components()

int GModelSpatialComposite::components ( void ) const
inline

Return number of model components.

Returns
Number of model components.

Definition at line 161 of file GModelSpatialComposite.hpp.

References m_components.

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

◆ contains()

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 350 of file GModelSpatialComposite.cpp.

References contains(), m_components, and m_scales.

Referenced by contains().

◆ copy_members()

void GModelSpatialComposite::copy_members ( const GModelSpatialComposite & model)
protected

Copy class members.

Parameters
[in]modelSpatial composite model.

Definition at line 893 of file GModelSpatialComposite.cpp.

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

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

◆ eval()

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. If normalisation is requested the method divides the result by the sum of all scales.

Implements GModelSpatial.

Definition at line 251 of file GModelSpatialComposite.cpp.

References component(), m_components, m_normalize, m_scales, scale(), sum(), and sum_of_scales().

◆ flux()

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 798 of file GModelSpatialComposite.cpp.

References flux(), m_components, m_normalize, m_scales, GModelSpatial::region(), sum(), and sum_of_scales().

Referenced by flux().

◆ free_members()

void GModelSpatialComposite::free_members ( void )
protected

Delete class members.

Definition at line 945 of file GModelSpatialComposite.cpp.

References m_components, and m_scales.

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

◆ init_members()

void GModelSpatialComposite::init_members ( void )
protected

◆ mc()

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 308 of file GModelSpatialComposite.cpp.

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

◆ mc_norm()

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 148 of file GModelSpatialComposite.hpp.

◆ name()

std::string GModelSpatialComposite::name ( const int & index) const

Returns names of spatial component.

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

Returns the name of a spatial component to the composite model

Definition at line 721 of file GModelSpatialComposite.cpp.

References G_NAME, m_names, and m_scales.

Referenced by append(), component(), GResponse::irf_composite(), GResponse::irf_composite(), read(), and write().

◆ normalize()

const bool & GModelSpatialComposite::normalize ( void ) const
inline

Return normalisation flag.

Returns
True if composite model is normalised.

Definition at line 173 of file GModelSpatialComposite.hpp.

References m_normalize.

Referenced by GModelSpatialComposite(), and GResponse::irf_composite().

◆ operator=()

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

Assignment operator.

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

Definition at line 180 of file GModelSpatialComposite.cpp.

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

◆ print()

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 830 of file GModelSpatialComposite.cpp.

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

Referenced by print().

◆ read()

◆ scale()

const GModelPar * GModelSpatialComposite::scale ( const int & index) const

Returns scale parameter of spatial component.

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

Returns the scale parameter of a spatial component to the composite model

Definition at line 745 of file GModelSpatialComposite.cpp.

References G_SCALE, and m_scales.

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

◆ set_region()

void GModelSpatialComposite::set_region ( void ) const
protectedvirtual

Set boundary sky region.

Todo
Implement computation of sky boundary region

Implements GModelSpatial.

Definition at line 983 of file GModelSpatialComposite.cpp.

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

◆ sum_of_scales()

double GModelSpatialComposite::sum_of_scales ( void ) const

Returns sum of all model scales.

Returns
Sum of all model scales

Returns the sum of all model scales if model normalisation was requested, otherwise returns 1.0.

Definition at line 766 of file GModelSpatialComposite.cpp.

References m_normalize, m_scales, and sum().

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

◆ write()

void GModelSpatialComposite::write ( GXmlElement & xml) const
virtual

Member Data Documentation

◆ m_components

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

◆ m_has_normalize

bool GModelSpatialComposite::m_has_normalize
protected

XML has normalize attribute.

Definition at line 104 of file GModelSpatialComposite.hpp.

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

◆ m_names

std::vector<std::string> GModelSpatialComposite::m_names
protected

Component names.

Definition at line 106 of file GModelSpatialComposite.hpp.

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

◆ m_normalize

bool GModelSpatialComposite::m_normalize
protected

◆ m_scales

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

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