GammaLib 2.1.0.dev
|
Spatial composite model. More...
#include <GModelSpatialComposite.hpp>
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 GModelSpatialComposite & | operator= (const GModelSpatialComposite &model) |
Assignment operator. | |
virtual void | clear (void) |
Clear spatial composite model. | |
virtual GModelSpatialComposite * | clone (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 ®ion, 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 GModelSpatial * | component (const int &index) const |
Returns pointer to spatial component element. | |
const GModelSpatial * | component (const std::string &name) const |
Returns pointer to specific spatial component. | |
std::string | name (const int &index) const |
Returns names of spatial component. | |
const GModelPar * | scale (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 GModelSpatial & | operator= (const GModelSpatial &model) |
Assignment operator. | |
virtual GModelPar & | operator[] (const int &index) |
Returns model parameter. | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns model parameter (const version) | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns model parameter. | |
virtual const GModelPar & | operator[] (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. | |
GModelPar & | at (const int &index) |
Returns model parameter. | |
const GModelPar & | at (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 GSkyRegion * | region (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. | |
Spatial composite model.
This class implements the spatial model for a composition of spatial models.
Definition at line 47 of file GModelSpatialComposite.hpp.
GModelSpatialComposite::GModelSpatialComposite | ( | const bool & | normalize = true | ) |
Void constructor.
[in] | normalize | Normalize 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::GModelSpatialComposite | ( | const bool & | dummy, |
const std::string & | type ) |
Model type constructor.
[in] | dummy | Dummy flag. |
[in] | type | Model 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().
|
explicit |
XML constructor.
[in] | xml | XML 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::GModelSpatialComposite | ( | const GModelSpatialComposite & | model | ) |
Copy constructor.
[in] | model | Spatial composite model. |
Definition at line 141 of file GModelSpatialComposite.cpp.
References copy_members(), and init_members().
|
virtual |
void GModelSpatialComposite::append | ( | const GModelSpatial & | component, |
const std::string & | name = "", | ||
const GModelPar & | par = GModelPar("", 1.0) ) |
Append spatial component.
[in] | component | Spatial model component to append. |
[in] | name | Name of spatial model. |
[in] | par | Model 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().
|
inlinevirtual |
Return class name.
Implements GModelSpatial.
Definition at line 117 of file GModelSpatialComposite.hpp.
|
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().
|
virtual |
Clone spatial composite model.
Implements GModelSpatial.
Definition at line 233 of file GModelSpatialComposite.cpp.
References GModelSpatialComposite().
|
inlinevirtual |
Return class code.
Returns the code GModelSpatialComposite of the class.
Implements GModelSpatial.
Definition at line 131 of file GModelSpatialComposite.hpp.
References GMODEL_SPATIAL_COMPOSITE.
const GModelSpatial * GModelSpatialComposite::component | ( | const int & | index | ) | const |
Returns pointer to spatial component element.
[in] | index | Index of spatial component [0,...,components()-1]. |
GException::out_of_range | Index 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().
const GModelSpatial * GModelSpatialComposite::component | ( | const std::string & | name | ) | const |
Returns pointer to specific spatial component.
[in] | name | Name of spatial component. |
GException::invalid_argument | Spatial 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().
|
inline |
Return 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().
|
virtual |
Checks where model contains specified sky direction.
[in] | dir | Sky direction. |
[in] | margin | Margin to be added to sky direction (degrees) |
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().
|
protected |
Copy class members.
[in] | model | Spatial 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=().
|
virtual |
Evaluate function.
[in] | photon | Incident photon. |
[in] | gradients | Compute gradients? |
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().
|
virtual |
Returns flux integrated in sky region.
[in] | region | Sky region. |
[in] | srcEng | Energy. |
[in] | srcTime | Time. |
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().
|
protected |
Delete class members.
Definition at line 945 of file GModelSpatialComposite.cpp.
References m_components, and m_scales.
Referenced by clear(), operator=(), and ~GModelSpatialComposite().
|
protected |
Initialise class members.
Definition at line 870 of file GModelSpatialComposite.cpp.
References m_components, m_has_normalize, m_names, m_normalize, GModelSpatial::m_pars, m_scales, and GModelSpatial::m_type.
Referenced by clear(), GModelSpatialComposite(), GModelSpatialComposite(), GModelSpatialComposite(), GModelSpatialComposite(), and operator=().
|
virtual |
Returns MC sky direction.
[in] | energy | Photon energy. |
[in] | time | Photon arrival time. |
[in,out] | ran | Random number generator. |
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().
|
inlinevirtual |
Return normalization of composite source for Monte Carlo simulations.
[in] | dir | Centre of simulation cone. |
[in] | radius | Radius of simulation cone (degrees). |
Returns unity.
Implements GModelSpatial.
Definition at line 148 of file GModelSpatialComposite.hpp.
std::string GModelSpatialComposite::name | ( | const int & | index | ) | const |
Returns names of spatial component.
[in] | index | Index of spatial component [0,...,components()-1]. |
GException::out_of_range | Index 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().
|
inline |
Return normalisation flag.
Definition at line 173 of file GModelSpatialComposite.hpp.
References m_normalize.
Referenced by GModelSpatialComposite(), and GResponse::irf_composite().
|
virtual |
Assignment operator.
[in] | model | Spatial composite model. |
Definition at line 180 of file GModelSpatialComposite.cpp.
References copy_members(), free_members(), init_members(), and GModelSpatial::operator=().
Print composite spatial model information.
[in] | chatter | Chattiness. |
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().
|
virtual |
Read model from XML element.
[in] | xml | XML element. |
Reads the spatial information from an XML element.
Implements GModelSpatial.
Definition at line 377 of file GModelSpatialComposite.cpp.
References GModelSpatialRegistry::alloc(), append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GOptimizerPar::fix(), GOptimizerPar::free(), GXmlElement::has_attribute(), m_has_normalize, m_normalize, GOptimizerPar::max(), GOptimizerPar::min(), name(), GOptimizerPar::range(), GOptimizerPar::remove_max(), GOptimizerPar::remove_min(), scale(), gammalib::todouble(), gammalib::toint(), gammalib::tolower(), and GOptimizerPar::value().
Referenced by GModelSpatialComposite().
const GModelPar * GModelSpatialComposite::scale | ( | const int & | index | ) | const |
Returns scale parameter of spatial component.
[in] | index | Index of spatial component [0,...,components()-1]. |
GException::out_of_range | Index 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().
|
protectedvirtual |
Set boundary sky region.
Implements GModelSpatial.
Definition at line 983 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 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().
|
virtual |
Write model into XML element.
[in] | xml | XML element into which model information is written. |
Write the spatial information into an XML element.
Implements GModelSpatial.
Definition at line 470 of file GModelSpatialComposite.cpp.
References GXmlNode::append(), GXmlElement::attribute(), GModelSpatial::clone(), component(), GXmlNode::element(), GXmlNode::elements(), G_WRITE, GXmlElement::has_attribute(), m_components, m_has_normalize, m_names, m_normalize, m_scales, max(), min(), name(), GOptimizerPar::name(), GModelSpatial::size(), gammalib::str(), GModelSpatial::type(), GModelSpatial::write(), and gammalib::xml_check_type().
|
protected |
Components.
Definition at line 105 of file GModelSpatialComposite.hpp.
Referenced by append(), component(), component(), components(), contains(), copy_members(), eval(), flux(), free_members(), init_members(), mc(), and write().
|
protected |
XML has normalize attribute.
Definition at line 104 of file GModelSpatialComposite.hpp.
Referenced by copy_members(), init_members(), read(), and write().
|
protected |
Component names.
Definition at line 106 of file GModelSpatialComposite.hpp.
Referenced by append(), component(), copy_members(), init_members(), name(), and write().
|
protected |
Normalize component.
Definition at line 103 of file GModelSpatialComposite.hpp.
Referenced by copy_members(), eval(), flux(), GModelSpatialComposite(), init_members(), normalize(), print(), read(), sum_of_scales(), and write().
|
protected |
Component scales.
Definition at line 107 of file GModelSpatialComposite.hpp.
Referenced by append(), contains(), copy_members(), eval(), flux(), free_members(), init_members(), mc(), name(), scale(), sum_of_scales(), and write().