GammaLib
2.1.0.dev
|
Spatial map model. More...
#include <GModelSpatialDiffuseMap.hpp>
Public Member Functions | |
GModelSpatialDiffuseMap (void) | |
Void constructor. More... | |
GModelSpatialDiffuseMap (const bool &dummy, const std::string &type) | |
Model type constructor. More... | |
GModelSpatialDiffuseMap (const GXmlElement &xml) | |
XML constructor. More... | |
GModelSpatialDiffuseMap (const GFilename &filename, const double &value=1.0, const bool &normalize=true) | |
File name constructor. More... | |
GModelSpatialDiffuseMap (const GSkyMap &map, const double &value=1.0, const bool &normalize=true) | |
Sky map constructor. More... | |
GModelSpatialDiffuseMap (const GModelSpatialDiffuseMap &model) | |
Copy constructor. More... | |
virtual | ~GModelSpatialDiffuseMap (void) |
Destructor. More... | |
virtual GModelSpatialDiffuseMap & | operator= (const GModelSpatialDiffuseMap &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear spatial map model. More... | |
virtual GModelSpatialDiffuseMap * | clone (void) const |
Clone spatial map model. More... | |
virtual std::string | classname (void) const |
Return class name. More... | |
virtual double | eval (const GPhoton &photon, const bool &gradients=false) const |
Return intensity of sky map. 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 diffuse map for Monte Carlo simulations. More... | |
virtual bool | contains (const GSkyDir &dir, const double &margin=0.0) const |
Signals whether model contains 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 map information. More... | |
virtual double | flux (const GSkyRegion ®ion, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const |
Returns diffuse map flux integrated in sky region. More... | |
double | value (void) const |
Get model value. More... | |
void | value (const double &value) |
Set model value. More... | |
const GFilename & | filename (void) const |
Get file name. More... | |
void | load (const GFilename &filename) |
Load skymap into the model class. More... | |
const GSkyMap & | map (void) const |
Get map. More... | |
void | map (const GSkyMap &map) |
Set map cube. More... | |
bool | normalize (void) const |
Return normalization flag. More... | |
void | mc_cone (const GSkyRegionCircle &cone) const |
Set Monte Carlo simulation cone. More... | |
const GSkyRegionCircle & | mc_cone (void) const |
Get Monte Carlo simulation cone. More... | |
Public Member Functions inherited from GModelSpatialDiffuse | |
GModelSpatialDiffuse (void) | |
Void constructor. More... | |
GModelSpatialDiffuse (const GModelSpatialDiffuse &model) | |
Copy constructor. More... | |
virtual | ~GModelSpatialDiffuse (void) |
Destructor. More... | |
virtual GModelSpatialDiffuse & | operator= (const GModelSpatialDiffuse &model) |
Assignment operator. More... | |
virtual GClassCode | code (void) const |
Return class code. 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 GModelSpatial & | operator= (const GModelSpatial &model) |
Assignment operator. More... | |
virtual GModelPar & | operator[] (const int &index) |
Returns model parameter. More... | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns model parameter (const version) More... | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns model parameter. More... | |
virtual const GModelPar & | operator[] (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... | |
GModelPar & | at (const int &index) |
Returns model parameter. More... | |
const GModelPar & | at (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 GSkyRegion * | region (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 GModelSpatialDiffuseMap &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | prepare_map (void) |
Prepare sky map after loading. More... | |
virtual void | set_region (void) const |
Set boundary sky region. More... | |
Protected Member Functions inherited from GModelSpatialDiffuse | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GModelSpatialDiffuse &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... | |
Protected Attributes | |
GModelPar | m_value |
Value. More... | |
GSkyMap | m_map |
Skymap. More... | |
GFilename | m_filename |
Name of skymap. More... | |
bool | m_normalize |
Normalize map (default: true) More... | |
bool | m_has_normalize |
XML has normalize attribute. More... | |
GSkyRegionCircle | m_mc_cone |
MC cone. More... | |
double | m_mc_one_minus_cosrad |
1-cosine of radius More... | |
double | m_mc_norm |
Map normalization. More... | |
double | m_mc_max |
Map maximum for MC. 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... | |
Spatial map model.
This class implements the spatial component of the factorised source model for a skymap.
Definition at line 50 of file GModelSpatialDiffuseMap.hpp.
GModelSpatialDiffuseMap::GModelSpatialDiffuseMap | ( | void | ) |
Void constructor.
Constructs empty spatial map model.
Definition at line 73 of file GModelSpatialDiffuseMap.cpp.
References init_members().
Referenced by clone().
GModelSpatialDiffuseMap::GModelSpatialDiffuseMap | ( | const bool & | dummy, |
const std::string & | type | ||
) |
Model type constructor.
[in] | dummy | Dummy flag. |
[in] | type | Model type. |
Constructs empty spatial map model by specifying a model type
.
Definition at line 92 of file GModelSpatialDiffuseMap.cpp.
References init_members(), GModelSpatial::m_type, and GModelSpatial::type().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs spatial map 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 116 of file GModelSpatialDiffuseMap.cpp.
References init_members(), and read().
GModelSpatialDiffuseMap::GModelSpatialDiffuseMap | ( | const GFilename & | filename, |
const double & | value = 1.0 , |
||
const bool & | normalize = true |
||
) |
File name constructor.
[in] | filename | File name. |
[in] | value | Normalization factor. |
[in] | normalize | Normalize map? |
Constructs spatial map model by loading a sky map from the file specified by filename
and by setting the value
by which the map will be multiplied (or normalized).
Definition at line 141 of file GModelSpatialDiffuseMap.cpp.
References init_members(), load(), m_normalize, m_value, normalize(), and GOptimizerPar::value().
GModelSpatialDiffuseMap::GModelSpatialDiffuseMap | ( | const GSkyMap & | map, |
const double & | value = 1.0 , |
||
const bool & | normalize = true |
||
) |
Sky map constructor.
[in] | map | Sky map. |
[in] | value | Normalization factor. |
[in] | normalize | Normalize map. |
Constructs spatial map model by setting the sky map
and by setting the value
by which the map will be multiplied (or normalized).
Definition at line 173 of file GModelSpatialDiffuseMap.cpp.
References init_members(), m_map, m_normalize, m_value, map(), normalize(), prepare_map(), and GOptimizerPar::value().
GModelSpatialDiffuseMap::GModelSpatialDiffuseMap | ( | const GModelSpatialDiffuseMap & | model | ) |
Copy constructor.
[in] | model | Spatial map model. |
Construct a spatial map model by copying another spatial map model.
Definition at line 205 of file GModelSpatialDiffuseMap.cpp.
References copy_members(), and init_members().
|
virtual |
|
inlinevirtual |
Return class name.
Implements GModelSpatialDiffuse.
Definition at line 131 of file GModelSpatialDiffuseMap.hpp.
|
virtual |
Clear spatial map model.
Implements GModelSpatialDiffuse.
Definition at line 279 of file GModelSpatialDiffuseMap.cpp.
References GModelSpatialDiffuse::free_members(), free_members(), GModelSpatial::free_members(), GModelSpatialDiffuse::init_members(), init_members(), and GModelSpatial::init_members().
|
virtual |
Clone spatial map model.
Implements GModelSpatialDiffuse.
Definition at line 301 of file GModelSpatialDiffuseMap.cpp.
References GModelSpatialDiffuseMap().
|
virtual |
Signals whether model contains sky direction.
[in] | dir | Sky direction. |
[in] | margin | Margin to be added to sky direction (degrees) |
Signals whether a sky direction falls within the bounding circle of the diffuse map.
Implements GModelSpatialDiffuse.
Definition at line 471 of file GModelSpatialDiffuseMap.cpp.
References GSkyRegionCircle::centre(), GSkyDir::dist_deg(), GModelSpatial::m_region, and GSkyRegionCircle::radius().
|
protected |
Copy class members.
[in] | model | Spatial map cube model. |
Definition at line 874 of file GModelSpatialDiffuseMap.cpp.
References m_filename, m_has_normalize, m_map, m_mc_cone, m_mc_max, m_mc_norm, m_mc_one_minus_cosrad, m_normalize, GModelSpatial::m_pars, GModelSpatial::m_type, and m_value.
Referenced by GModelSpatialDiffuseMap(), and operator=().
|
virtual |
Return intensity of sky map.
[in] | photon | Incident photon. |
[in] | gradients | Compute gradients? |
Returns the intensity of the sky map at the specified sky direction multiplied by the normalization factor. If the sky direction falls outside the sky map, an intensity of 0 is returned.
If the gradients
flag is true the method will also evaluate the partial derivatives of the model.
Implements GModelSpatialDiffuse.
Definition at line 322 of file GModelSpatialDiffuseMap.cpp.
References GPhoton::dir(), GOptimizerPar::factor_gradient(), GOptimizerPar::is_free(), m_map, m_value, GOptimizerPar::scale(), and GOptimizerPar::value().
|
inline |
Get file name.
Returns the file name of the spatial map model.
Definition at line 174 of file GModelSpatialDiffuseMap.hpp.
References m_filename.
Referenced by load().
|
virtual |
Returns diffuse map flux integrated in sky region.
[in] | region | Sky region. |
[in] | srcEng | Energy. |
[in] | srcTime | Time. |
Returns diffuse map flux within a sky region. The flux is defined as the sum of the flux in all diffuse map pixels that are contained within the sky region multiplied by the diffuse map normalisation factor.
Reimplemented from GModelSpatial.
Definition at line 733 of file GModelSpatialDiffuseMap.cpp.
References GSkyMap::flux(), m_map, m_value, and GOptimizerPar::value().
Referenced by mc_cone(), and prepare_map().
|
protected |
Delete class members.
Definition at line 902 of file GModelSpatialDiffuseMap.cpp.
Referenced by clear(), operator=(), and ~GModelSpatialDiffuseMap().
|
protected |
Initialise class members.
Definition at line 833 of file GModelSpatialDiffuseMap.cpp.
References GSkyRegionCircle::clear(), GFilename::clear(), GSkyMap::clear(), GOptimizerPar::clear(), GOptimizerPar::fix(), GOptimizerPar::gradient(), GOptimizerPar::has_grad(), m_filename, m_has_normalize, m_map, m_mc_cone, m_mc_max, m_mc_norm, m_mc_one_minus_cosrad, m_normalize, GModelSpatial::m_pars, GModelSpatial::m_type, m_value, GOptimizerPar::name(), GOptimizerPar::range(), GOptimizerPar::scale(), and GOptimizerPar::value().
Referenced by clear(), GModelSpatialDiffuseMap(), and operator=().
void GModelSpatialDiffuseMap::load | ( | const GFilename & | filename | ) |
Load skymap into the model class.
[in] | filename | Sky map file. |
Loads skymap into the model class. The method calls the protected method prepare_map() that prepares the map for usage by the class.
If the filename
is empty, no map will be loaded.
Definition at line 797 of file GModelSpatialDiffuseMap.cpp.
References GSkyMap::clear(), filename(), GFilename::is_empty(), GSkyMap::load(), m_filename, m_map, and prepare_map().
Referenced by GModelSpatialDiffuseMap(), and read().
|
inline |
Get map.
Returns the sky map.
Definition at line 188 of file GModelSpatialDiffuseMap.hpp.
References m_map.
Referenced by GModelSpatialDiffuseMap(), GResponse::irf_diffuse(), map(), and gammalib::resolution().
|
inline |
Set map cube.
[in] | map | Sky map. |
Set the sky map.
Definition at line 202 of file GModelSpatialDiffuseMap.hpp.
References m_map, map(), and prepare_map().
|
virtual |
Returns MC sky direction.
[in] | energy | Photon energy (ignored). |
[in] | time | Photon arrival time (ignored). |
[in,out] | ran | Random number generator. |
GException::invalid_value | No sky map defined. |
GException::invalid_return_value | Simulation cone not defined, does not overlap with map or map is empty. |
Returns a random sky direction according to the intensity distribution of the model sky map. The method uses a rejection method to determine the sky direction. If no sky direction could be determined, the method throws an GException::invalid_return_value exception.
Implements GModelSpatialDiffuse.
Definition at line 363 of file GModelSpatialDiffuseMap.cpp.
References gammalib::acos(), GSkyRegionCircle::centre(), G_MC, m_map, m_mc_cone, m_mc_max, m_mc_one_minus_cosrad, GSkyMap::npix(), gammalib::rad2deg, GSkyDir::rotate_deg(), GRan::uniform(), and value().
void GModelSpatialDiffuseMap::mc_cone | ( | const GSkyRegionCircle & | cone | ) | const |
Set Monte Carlo simulation cone.
[in] | cone | Monte Carlo simulation cone. |
Sets the simulation cone that defines the directions that will be simulated using the mc() method and pre-computes the maximum intensity and the spatially integrated flux of the map within the simulation cone region.
Definition at line 639 of file GModelSpatialDiffuseMap.cpp.
References GSkyRegionCircle::centre(), cos(), gammalib::deg2rad, GSkyDir::dist_deg(), flux(), GSkyMap::flux(), m_map, m_mc_cone, m_mc_max, m_mc_norm, m_mc_one_minus_cosrad, m_normalize, GSkyMap::npix(), GSkyMap::pix2dir(), GSkyRegionCircle::radius(), and sum().
|
inline |
Get Monte Carlo simulation cone.
Returns the sky region circle used for Monte Carlo simulations.
Definition at line 232 of file GModelSpatialDiffuseMap.hpp.
References m_mc_cone.
Referenced by mc_norm(), and prepare_map().
|
virtual |
Return normalization of diffuse map for Monte Carlo simulations.
[in] | dir | Centre of simulation cone. |
[in] | radius | Radius of simulation cone (degrees). |
Returns the normalization of a diffuse map. The normalization is given by the model value times the integrated flux in the sky map over a circular region.
Implements GModelSpatialDiffuse.
Definition at line 447 of file GModelSpatialDiffuseMap.cpp.
|
inline |
Return normalization flag.
Signals whether a map has been normalized or not.
Definition at line 218 of file GModelSpatialDiffuseMap.hpp.
References m_normalize.
Referenced by GModelSpatialDiffuseMap(), prepare_map(), and print().
|
virtual |
Assignment operator.
[in] | model | Spatial map model. |
Assigns a spatial map model to another spatial map model.
Definition at line 246 of file GModelSpatialDiffuseMap.cpp.
References copy_members(), free_members(), init_members(), and GModelSpatialDiffuse::operator=().
|
protected |
Prepare sky map after loading.
Prepares a sky map after loading. Negative, infinite or undefined skymap pixels are set to zero intensity. The method also determine the centre and radius of a circle enclosing the map, and the Monte Carlo simulation cone is set to this circle.
If normalize() is true, the map is furthermore normalised so that the total flux in the map amounts to 1 ph/cm2/s. Negative skymap pixels are set to zero intensity.
Definition at line 921 of file GModelSpatialDiffuseMap.cpp.
References GSkyRegionCircle::clear(), flux(), GSkyMap::flux(), gammalib::is_infinite(), gammalib::is_notanumber(), m_map, GModelSpatial::m_region, mc_cone(), normalize(), GSkyMap::npix(), GSkyMap::region_circle(), and sum().
Referenced by GModelSpatialDiffuseMap(), load(), and map().
Print map information.
[in] | chatter | Chattiness. |
Implements GModelSpatialDiffuse.
Definition at line 751 of file GModelSpatialDiffuseMap.cpp.
References GSkyRegionCircle::centre(), m_filename, m_mc_norm, GModelSpatial::m_pars, GModelSpatial::m_region, normalize(), gammalib::parformat(), GSkyDir::print(), GSkyRegionCircle::radius(), SILENT, GModelSpatial::size(), and gammalib::str().
|
virtual |
Read model from XML element.
[in] | xml | XML element. |
GException::invalid_value | Model parameters not found in XML element. |
Reads the spatial information for a diffuse map from an XML element. The expected format of the XML element is
<spatialModel type="DiffuseMap" file="myfile.fits" normalize="1"> <parameter name="Normalization" ../> </spatialModel>
The file
attribute provides the filename of the diffuse map FITS file. The filename may be either an absolute filename (starting with '/') or a relative filename. If no access path is given, the file is expected to reside in the same location as the XML file.
The normalize
attribute specifies whether the sky map should be normalized to unity flux or not. If the attribute is not given, the map will be automatically normalized. To prevent normalization, normalize="0"
needs to be specified.
Implements GModelSpatialDiffuse.
Definition at line 521 of file GModelSpatialDiffuseMap.cpp.
References GXmlElement::attribute(), G_READ, GXmlElement::has_attribute(), load(), m_has_normalize, m_normalize, m_value, GModelPar::read(), gammalib::tolower(), gammalib::xml_check_parnum(), gammalib::xml_file_expand(), gammalib::xml_get_par(), and gammalib::xml_has_par().
Referenced by GModelSpatialDiffuseMap().
|
protectedvirtual |
Set boundary sky region.
Implements GModelSpatialDiffuse.
Definition at line 973 of file GModelSpatialDiffuseMap.cpp.
|
inline |
Get model value.
Returns the value of the spatial map model.
Definition at line 145 of file GModelSpatialDiffuseMap.hpp.
References m_value, and GOptimizerPar::value().
|
inline |
Set model value.
[in] | value | Model value. |
Set the value of the spatial map model.
Definition at line 159 of file GModelSpatialDiffuseMap.hpp.
References m_value, and GOptimizerPar::value().
|
virtual |
Write model into XML element.
[in] | xml | XML element. |
GException::model_invalid_spatial | Existing XML element is not of type "SpatialMap" |
GException::model_invalid_parnum | Invalid number of model parameters found in XML element. |
GException::model_invalid_parnames | Invalid model parameter names found in XML element. |
Writes the spatial information for a diffuse map into an XML element. The format of the XML element is
<spatialModel type="DiffuseMap" file="myfile.fits" normalize="1"> <parameter name="Prefactor" value="1" min="0.1" max="10" scale="1" free="0"/> </spatialModel>
The file
attribute provides the filename of the diffuse map FITS file. The filename may be either an absolute filename (starting with '/') or a relative filename. If no access path is given, the file is expected to reside in the same location as the XML file.
The normalize
attribute specifies whether the sky map should be normalized to unity flux or not. The attribute will only be written if the normalization is disabled.
Implements GModelSpatialDiffuse.
Definition at line 600 of file GModelSpatialDiffuseMap.cpp.
References GXmlElement::attribute(), G_WRITE, m_filename, m_has_normalize, m_normalize, m_value, GOptimizerPar::name(), GModelSpatial::type(), value(), GModelPar::write(), gammalib::xml_check_type(), gammalib::xml_file_reduce(), and gammalib::xml_need_par().
|
protected |
Name of skymap.
Definition at line 113 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), filename(), init_members(), load(), print(), and write().
|
protected |
XML has normalize attribute.
Definition at line 115 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), init_members(), read(), and write().
|
protected |
Skymap.
Definition at line 112 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), eval(), flux(), GModelSpatialDiffuseMap(), init_members(), load(), map(), mc(), mc_cone(), and prepare_map().
|
mutableprotected |
MC cone.
Definition at line 118 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), init_members(), mc(), and mc_cone().
|
mutableprotected |
Map maximum for MC.
Definition at line 121 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), init_members(), mc(), and mc_cone().
|
mutableprotected |
Map normalization.
Definition at line 120 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), init_members(), mc_cone(), mc_norm(), and print().
|
mutableprotected |
1-cosine of radius
Definition at line 119 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), init_members(), mc(), and mc_cone().
|
protected |
Normalize map (default: true)
Definition at line 114 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), GModelSpatialDiffuseMap(), init_members(), mc_cone(), normalize(), read(), and write().
|
protected |
Value.
Definition at line 111 of file GModelSpatialDiffuseMap.hpp.
Referenced by copy_members(), eval(), flux(), GModelSpatialDiffuseMap(), init_members(), read(), value(), and write().