GammaLib
2.1.0.dev
|
Background model class. More...
#include <GCTAModelBackground.hpp>
Public Member Functions | |
GCTAModelBackground (void) | |
Void constructor. More... | |
GCTAModelBackground (const GXmlElement &xml) | |
XML constructor. More... | |
GCTAModelBackground (const GCTAModelSpatial &spatial, const GModelSpectral &spectral) | |
Construct from spatial and spectral components. More... | |
GCTAModelBackground (const GCTAModelSpatial &spatial, const GModelSpectral &spectral, const GModelTemporal &temporal) | |
Construct from model components. More... | |
GCTAModelBackground (const GCTAModelBackground &model) | |
Copy constructor. More... | |
virtual | ~GCTAModelBackground (void) |
Destructor. More... | |
virtual GCTAModelBackground & | operator= (const GCTAModelBackground &model) |
Assignment operator. More... | |
virtual void | clear (void) |
Clear instance. More... | |
virtual GCTAModelBackground * | clone (void) const |
Clone instance. More... | |
virtual std::string | classname (void) const |
Return class name. More... | |
virtual std::string | type (void) const |
Return model type. More... | |
virtual bool | is_constant (void) const |
Signals if model is temporally constant. More... | |
virtual double | eval (const GEvent &event, const GObservation &obs, const bool &gradients=false) const |
Return background rate in units of events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\). More... | |
virtual double | npred (const GEnergy &energy, const GTime &time, const GObservation &obs) const |
Return spatially integrated background rate in units of events MeV \(^{-1}\) s \(^{-1}\). More... | |
virtual GCTAEventList * | mc (const GObservation &obs, GRan &ran) const |
Return simulated list of events. 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 model information. More... | |
GCTAModelSpatial * | spatial (void) const |
Return spatial model component. More... | |
GModelSpectral * | spectral (void) const |
Return spectral model component. More... | |
GModelTemporal * | temporal (void) const |
Return temporal model component. More... | |
void | spatial (const GCTAModelSpatial *spatial) |
Set spatial model component. More... | |
void | spectral (const GModelSpectral *spectral) |
Set spectral model component. More... | |
void | temporal (const GModelTemporal *temporal) |
Set temporal model component. More... | |
Public Member Functions inherited from GModelData | |
GModelData (void) | |
Void constructor. More... | |
GModelData (const GXmlElement &xml) | |
XML constructor. More... | |
GModelData (const GModelData &model) | |
Copy constructor. More... | |
virtual | ~GModelData (void) |
Destructor. More... | |
virtual GModelData & | operator= (const GModelData &model) |
Assignment operator. More... | |
virtual GVector | eval (const GObservation &obs, GMatrixSparse *gradients=NULL) const |
Return model values and gradients. More... | |
Public Member Functions inherited from GModel | |
GModel (void) | |
Void constructor. More... | |
GModel (const GXmlElement &xml) | |
XML constructor. More... | |
GModel (const GModel &model) | |
Copy constructor. More... | |
virtual | ~GModel (void) |
Destructor. More... | |
virtual GModel & | operator= (const GModel &model) |
Assignment operator. More... | |
virtual GModelPar & | operator[] (const int &index) |
Returns reference to model parameter by index. More... | |
virtual const GModelPar & | operator[] (const int &index) const |
Returns reference to model parameter by index (const version) More... | |
virtual GModelPar & | operator[] (const std::string &name) |
Returns reference to model parameter by name. More... | |
virtual const GModelPar & | operator[] (const std::string &name) const |
Returns reference to model parameter by name const version) More... | |
int | size (void) const |
Return number of parameters in model. More... | |
int | scales (void) const |
Return number of scale parameters in model. More... | |
GModelPar & | at (const int &index) |
Returns reference to model parameter by index. More... | |
const GModelPar & | at (const int &index) const |
Returns reference to model parameter by index (const version) More... | |
bool | has_par (const std::string &name) const |
Checks if parameter name exists. More... | |
bool | has_scales (void) const |
Signals that model has scales. More... | |
const std::string & | name (void) const |
Return parameter name. More... | |
void | name (const std::string &name) |
Set parameter name. More... | |
const double & | ts (void) const |
Return Test Statistic value. More... | |
void | ts (const double &ts) |
Set Test Statistic value. More... | |
const bool & | tscalc (void) const |
Return Test Statistic computation flag. More... | |
void | tscalc (const bool &tscalc) |
Set Test Statistic computation flag. More... | |
const bool & | has_ts (void) const |
Signals that model has Test Statistics value. More... | |
std::string | instruments (void) const |
Returns instruments to which model applies. More... | |
void | instruments (const std::string &instruments) |
Set instruments to which model applies. More... | |
GModelPar & | scale (const int &index) |
Returns reference to scale parameter by index. More... | |
const GModelPar & | scale (const int &index) const |
Returns reference to scale parameter by index (const version) More... | |
GModelPar | scale (const std::string &instrument) const |
Returns model scale factor for a given instrument. More... | |
void | scale (const GModelPar &par) |
Set model scale factor for a given instrument. More... | |
std::string | ids (void) const |
Returns observation identifiers to which model applies. More... | |
void | ids (const std::string &ids) |
Set observation identifiers to which model applies. More... | |
bool | is_valid (const std::string &instruments, const std::string &ids) const |
Verifies if model is valid for a given instrument and identifier. More... | |
const GModelAssociations & | associations (void) const |
Return model associations. More... | |
void | associations (const GModelAssociations &associations) |
Set model associations. More... | |
const bool & | has_eval_indices (void) const |
Signals that parameter indices updated by eval() method were set. More... | |
const std::vector< int > & | eval_indices (void) const |
Return vector of parameter indices updated by eval() method. 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 GCTAModelBackground &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | set_pointers (void) |
Set pointers. More... | |
GCTAModelSpatial * | xml_spatial (const GXmlElement &spatial) const |
Return pointer to spatial model from XML element. More... | |
GModelSpectral * | xml_spectral (const GXmlElement &spectral) const |
Return pointer to spectral model from XML element. More... | |
GModelTemporal * | xml_temporal (const GXmlElement &temporal) const |
Return pointer to temporal model from XML element. More... | |
bool | valid_model (void) const |
Verifies if model has all components. More... | |
Protected Member Functions inherited from GModelData | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GModelData &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
Protected Member Functions inherited from GModel | |
void | init_members (void) |
Initialise class members. More... | |
void | copy_members (const GModel &model) |
Copy class members. More... | |
void | free_members (void) |
Delete class members. More... | |
void | read_attributes (const GXmlElement &xml) |
Read model attributes. More... | |
void | write_attributes (GXmlElement &xml) const |
Write model attributes. More... | |
std::string | print_attributes (void) const |
Print model attributes. More... | |
void | read_scales (const GXmlElement &xml) |
Read instrument scales from XML element. More... | |
void | write_scales (GXmlElement &xml) const |
Write instrument scales into XML element. More... | |
Protected Attributes | |
GCTAModelSpatial * | m_spatial |
Spatial model. More... | |
GModelSpectral * | m_spectral |
Spectral model. More... | |
GModelTemporal * | m_temporal |
Temporal model. More... | |
Protected Attributes inherited from GModel | |
std::string | m_name |
Model name. More... | |
std::vector< std::string > | m_instruments |
Instruments to which model applies. More... | |
std::vector< GModelPar > | m_scales |
Model instrument scale factors. More... | |
std::vector< std::string > | m_ids |
Identifiers to which model applies. More... | |
std::vector< GModelPar * > | m_pars |
Pointers to all model parameters. More... | |
GModelAssociations | m_associations |
Model associations. More... | |
bool | m_has_ts |
Signals if TS is available. More... | |
bool | m_has_tscalc |
Signals if tscalc attribute is available. More... | |
bool | m_tscalc |
Signals if TS should be computed. More... | |
double | m_ts |
Test Statistic of the model. More... | |
bool | m_has_eval_inx |
std::vector< int > | m_eval_inx |
Background model class.
This class implements a background model for CTA.
Definition at line 54 of file GCTAModelBackground.hpp.
GCTAModelBackground::GCTAModelBackground | ( | void | ) |
Void constructor.
Constructs an empty background model.
Definition at line 79 of file GCTAModelBackground.cpp.
References init_members().
Referenced by clone().
|
explicit |
XML constructor.
[in] | xml | XML element. |
Constructs a background model from the information that is found in a XML element. Please refer to the read() method to learn about the expected structure of the XML element.
Definition at line 98 of file GCTAModelBackground.cpp.
References init_members(), read(), and set_pointers().
GCTAModelBackground::GCTAModelBackground | ( | const GCTAModelSpatial & | spatial, |
const GModelSpectral & | spectral | ||
) |
Construct from spatial and spectral components.
[in] | spatial | Spatial model component. |
[in] | spectral | Spectral model component. |
Constructs a background model from a spatial
and a spectral
model component. The temporal component is assumed to be constant.
Definition at line 124 of file GCTAModelBackground.cpp.
References GCTAModelSpatial::clone(), GModelTemporalConst::clone(), GModelSpectral::clone(), init_members(), m_spatial, m_spectral, m_temporal, set_pointers(), and temporal().
GCTAModelBackground::GCTAModelBackground | ( | const GCTAModelSpatial & | spatial, |
const GModelSpectral & | spectral, | ||
const GModelTemporal & | temporal | ||
) |
Construct from model components.
[in] | spatial | Spatial model component. |
[in] | spectral | Spectral model component. |
[in] | temporal | Temporal model component. |
Constructs a background model from a spatial
, a spectral
and a temporal
model component.
Definition at line 157 of file GCTAModelBackground.cpp.
References GModelTemporal::clone(), GCTAModelSpatial::clone(), GModelSpectral::clone(), init_members(), m_spatial, m_spectral, m_temporal, and set_pointers().
GCTAModelBackground::GCTAModelBackground | ( | const GCTAModelBackground & | model | ) |
Copy constructor.
[in] | model | Background model. |
Constructs a background model by copying information from an existing model. Note that the copy is a deep copy, so the original object can be destroyed after the copy without any loss of information.
Definition at line 187 of file GCTAModelBackground.cpp.
References copy_members(), init_members(), and set_pointers().
|
virtual |
Destructor.
Destroys a background model.
Definition at line 209 of file GCTAModelBackground.cpp.
References free_members().
|
inlinevirtual |
Return class name.
Implements GModelData.
Definition at line 120 of file GCTAModelBackground.hpp.
|
virtual |
Clear instance.
Resets the instance to a clean initial state. All information that resided in the object will be lost.
Implements GModelData.
Definition at line 270 of file GCTAModelBackground.cpp.
References GModelData::free_members(), free_members(), GModel::free_members(), GModelData::init_members(), init_members(), and GModel::init_members().
Referenced by read().
|
virtual |
Clone instance.
Implements GModelData.
Definition at line 292 of file GCTAModelBackground.cpp.
References GCTAModelBackground().
|
protected |
Copy class members.
[in] | model | Background model. |
Definition at line 891 of file GCTAModelBackground.cpp.
References GModelTemporal::clone(), GCTAModelSpatial::clone(), GModelSpectral::clone(), m_spatial, m_spectral, m_temporal, and set_pointers().
Referenced by GCTAModelBackground(), and operator=().
|
virtual |
Return background rate in units of events MeV \(^{-1}\) s \(^{-1}\) sr \(^{-1}\).
[in] | event | Observed event. |
[in] | obs | Observation. |
[in] | gradients | Compute gradients? |
Evaluates the background model which is a factorization of a spatial, spectral and temporal model component. The method returns a real rate, defined as the number of counts per MeV, steradian and ontime.
If the gradients
flag is true the method will also set the parameter gradients of the model parameters.
Add bookkeeping of last value and evaluate only if argument changed
Verify that CTA instrument direction pointer is valid, or better, add an offset method to GCTAPointing. Ideally, we should precompute all offset angles (for an event cube this may only be done easily if the pointing has been fixed; otherwise we need a structure similar to the Fermi/LAT livetime cube that provides the effective sky exposure as function of offset angle).
Implements GModelData.
Definition at line 404 of file GCTAModelBackground.cpp.
References gammalib::cta_dir(), GEvent::energy(), GModelTemporal::eval(), GCTAModelSpatial::eval(), GModelSpectral::eval(), G_EVAL, GModelTemporal::size(), GCTAModelSpatial::size(), GModelSpectral::size(), spatial(), spectral(), temporal(), and GEvent::time().
|
protected |
Delete class members.
Definition at line 909 of file GCTAModelBackground.cpp.
References m_spatial, m_spectral, and m_temporal.
Referenced by clear(), operator=(), and ~GCTAModelBackground().
|
protected |
Initialise class members.
Definition at line 874 of file GCTAModelBackground.cpp.
References m_spatial, m_spectral, and m_temporal.
Referenced by clear(), GCTAModelBackground(), and operator=().
|
inlinevirtual |
Signals if model is temporally constant.
Signals if the model is temporally constant. A temporally constant model is a model that has a temporal component of type "Constant".
Implements GModelData.
Definition at line 149 of file GCTAModelBackground.hpp.
References m_temporal, and GModelTemporal::type().
|
virtual |
Return simulated list of events.
[in] | obs | Observation. |
[in] | ran | Random number generator. |
Draws a sample of events from the background model using a Monte Carlo simulation. The region of interest, the energy boundaries and the good time interval for the sampling will be extracted from the observation argument that is passed to the method. The method also requires a random number generator of type GRan which is passed by reference, hence the state of the random number generator will be changed by the method.
For each event in the returned event list, the sky direction, the nominal coordinates (DETX and DETY), the energy and the time will be set.
Implements GModelData.
Definition at line 510 of file GCTAModelBackground.cpp.
References GCTAEventList::append(), gammalib::cta_event_list(), gammalib::cta_obs(), GCTAEventAtom::dir(), GEvents::ebounds(), GEbounds::emax(), GEbounds::emin(), GModelSpectral::flux(), G_MC, GEvents::gti(), m_spatial, m_spectral, m_temporal, GModelTemporal::mc(), GCTAModelSpatial::mc(), GModelSpectral::mc(), GModel::name(), GCTAModelSpatial::npred(), GCTAEventList::reserve(), GCTAEventList::roi(), GTimes::size(), GGti::size(), GEbounds::size(), spectral(), GGti::tstart(), GGti::tstop(), and valid_model().
|
virtual |
Return spatially integrated background rate in units of events MeV \(^{-1}\) s \(^{-1}\).
[in] | energy | Measured event energy. |
[in] | time | Measured event time. |
[in] | obs | Observation. |
Spatially integrates the background model for a given measured event energy and event time. The method returns a real rate, defined as the number of counts per MeV and ontime.
Implements GModelData.
Definition at line 474 of file GCTAModelBackground.cpp.
References GModelTemporal::eval(), GModelSpectral::eval(), GCTAModelSpatial::npred(), spatial(), spectral(), and temporal().
|
virtual |
Assignment operator.
[in] | model | Background model. |
Assigns the information from a background model to instance. Note that a deep copy of the information is performed, so the original instance can be destroyed after the assignment without any loss of information.
Definition at line 234 of file GCTAModelBackground.cpp.
References copy_members(), free_members(), init_members(), and GModelData::operator=().
Print model information.
[in] | chatter | Chattiness. |
Implements GModelData.
Definition at line 799 of file GCTAModelBackground.cpp.
References gammalib::parformat(), GModel::print_attributes(), SILENT, GModelTemporal::size(), GCTAModelSpatial::size(), GModelSpectral::size(), GModel::size(), spatial(), spectral(), gammalib::str(), temporal(), and type().
|
virtual |
Read model from XML element.
[in] | xml | XML element. |
Reads the sky model from an XML element. The XML element is expected to respect the following format:
<source name=".." type=".." instrument=".." id=".."> <spectrum type=".."> .. </spectrum> <spatialModel type=".."> .. </spatialModel> <temporal type=".."> .. </temporal> </source>
The temporal element is optional. In no temporal element is specified a constant component with unity normalization will be assumed.
Implements GModelData.
Definition at line 676 of file GCTAModelBackground.cpp.
References clear(), GModelTemporalConst::clone(), GXmlNode::element(), GXmlNode::elements(), m_spatial, m_spectral, m_temporal, GModel::read_attributes(), set_pointers(), temporal(), xml_spatial(), xml_spectral(), and xml_temporal().
Referenced by GCTAModelBackground().
|
protected |
Set pointers.
Set pointers to all model parameters. The pointers are stored in a vector that is member of the GModelData base class.
Definition at line 932 of file GCTAModelBackground.cpp.
References GModel::m_pars, GModelTemporal::size(), GCTAModelSpatial::size(), GModelSpectral::size(), spatial(), spectral(), and temporal().
Referenced by copy_members(), GCTAModelBackground(), read(), spatial(), spectral(), and temporal().
|
inline |
Return spatial model component.
Returns a pointer to the spatial model component of the model. The pointer is of type GCTAModelSpatial. Note that a NULL pointer may be returned if the model has no spatial model component.
Definition at line 165 of file GCTAModelBackground.hpp.
References m_spatial.
Referenced by eval(), npred(), print(), set_pointers(), valid_model(), and write().
void GCTAModelBackground::spatial | ( | const GCTAModelSpatial * | spatial | ) |
Set spatial model component.
[in] | spatial | Pointer to spatial model component. |
Sets the spatial model component of the model.
Definition at line 305 of file GCTAModelBackground.cpp.
References GCTAModelSpatial::clone(), m_spatial, and set_pointers().
|
inline |
Return spectral model component.
Returns a pointer to the spectral model component of the model. The pointer is of type GModelSpectral. Note that a NULL pointer may be returned if the model has no spectral model component.
Definition at line 181 of file GCTAModelBackground.hpp.
References m_spectral.
Referenced by gammalib::cta_model_spectral(), eval(), mc(), npred(), print(), set_pointers(), valid_model(), and write().
void GCTAModelBackground::spectral | ( | const GModelSpectral * | spectral | ) |
Set spectral model component.
[in] | spectral | Pointer to spectral model component. |
Sets the spectral model component of the model.
Definition at line 332 of file GCTAModelBackground.cpp.
References GModelSpectral::clone(), m_spectral, and set_pointers().
|
inline |
Return temporal model component.
Returns a pointer to the temporal model component of the model. The pointer is of type GModelTemporal. Note that a NULL pointer may be returned if the model has no temporal model component.
Definition at line 197 of file GCTAModelBackground.hpp.
References m_temporal.
Referenced by gammalib::cta_model_temporal(), eval(), GCTAModelBackground(), npred(), print(), read(), set_pointers(), valid_model(), and write().
void GCTAModelBackground::temporal | ( | const GModelTemporal * | temporal | ) |
Set temporal model component.
[in] | temporal | Pointer to temporal model component. |
Sets the temporal model component of the model.
Definition at line 359 of file GCTAModelBackground.cpp.
References GModelTemporal::clone(), m_temporal, and set_pointers().
|
inlinevirtual |
Return model type.
Returns "CTABackground" as the type of the model.
Implements GModelData.
Definition at line 134 of file GCTAModelBackground.hpp.
Referenced by print().
|
protected |
Verifies if model has all components.
Returns 'true' if models has a spatial, a spectral and a temporal component. Otherwise returns 'false'.
Definition at line 1031 of file GCTAModelBackground.cpp.
References spatial(), spectral(), and temporal().
Referenced by mc().
|
virtual |
Write model into XML element.
[in] | xml | XML element. |
Writes the sky model into an XML source library. The format written to the xml
element is as follows:
<source name=".." type=".." instrument=".." id=".."> <spectrum type=".."> .. </spectrum> <spatialModel type=".."> .. </spatialModel> <temporal type=".."> .. </temporal> </source>
For compatibility reasons the temporal element will only be written if it is a non-constant component or a constant component with a normalization that differs from unity.
Implements GModelData.
Definition at line 734 of file GCTAModelBackground.cpp.
References GXmlNode::append(), GXmlElement::attribute(), GXmlNode::element(), GXmlNode::elements(), GModel::name(), GModelTemporalConst::norm(), spatial(), spectral(), temporal(), GModelTemporal::write(), GCTAModelSpatial::write(), GModelSpectral::write(), and GModel::write_attributes().
|
protected |
Return pointer to spatial model from XML element.
[in] | spatial | XML element. |
Returns pointer to a spatial model that is defined in an XML element.
Definition at line 976 of file GCTAModelBackground.cpp.
References GCTAModelSpatialRegistry::alloc().
Referenced by read().
|
protected |
Return pointer to spectral model from XML element.
[in] | spectral | XML element. |
Returns pointer to spectral model that is defined in an XML element.
Definition at line 995 of file GCTAModelBackground.cpp.
References GModelSpectralRegistry::alloc().
Referenced by read().
|
protected |
Return pointer to temporal model from XML element.
[in] | temporal | XML element. |
Returns pointer to temporal model that is defined in an XML element.
Definition at line 1014 of file GCTAModelBackground.cpp.
References GModelTemporalRegistry::alloc().
Referenced by read().
|
protected |
Spatial model.
Definition at line 108 of file GCTAModelBackground.hpp.
Referenced by copy_members(), free_members(), GCTAModelBackground(), init_members(), mc(), read(), and spatial().
|
protected |
Spectral model.
Definition at line 109 of file GCTAModelBackground.hpp.
Referenced by copy_members(), free_members(), GCTAModelBackground(), init_members(), mc(), read(), and spectral().
|
protected |
Temporal model.
Definition at line 110 of file GCTAModelBackground.hpp.
Referenced by copy_members(), free_members(), GCTAModelBackground(), init_members(), is_constant(), mc(), read(), and temporal().