42 const GModelRegistry g_cta_inst_sky_registry(&g_cta_inst_sky_seed);
45 #define G_EVAL "GCTAModelSkyCube::eval(GEvent&, GObservation&, bool&)"
46 #define G_NPRED "GCTAModelSkyCube::npred(GEnergy&, GTime&, GObservation&)"
47 #define G_MC "GCTAModelSkyCube::mc(GObservation&, GRan&)"
48 #define G_READ_XML_SPATIAL "GCTAModelSkyCube::read_xml_spatial(GXmlElement&)"
49 #define G_WRITE_XML_SPATIAL "GCTAModelSkyCube::write_xml_spatial("\
51 #define G_XML_SPECTRAL "GCTAModelSkyCube::xml_spectral(GXmlElement&)"
52 #define G_XML_TEMPORAL "GCTAModelSkyCube::xml_temporal(GXmlElement&)"
57 #define G_USE_NPRED_CACHE
293 #pragma omp critical(GCTAModelSkyCube_load)
296 GFits fits(filename);
397 const bool& gradients)
const
410 double spat_raw = 0.0;
413 if (
std::abs(wgt_left-1.0) < 1.0e-6) {
418 else if (
std::abs(wgt_right-1.0) < 1.0e-6) {
424 double spat_left =
m_cube(dir.
dir(), inx_left);
425 double spat_right =
m_cube(dir.
dir(), inx_right);
426 if (spat_left > 0.0 && spat_right > 0.0) {
441 if (event.
size() != 0.0) {
442 spat /=
event.size();
456 double value = spat * spec * temp;
464 double fact = spec * temp;
471 double fact = spat * temp;
474 (*
spectral())[i].factor_gradient((*
spectral())[i].factor_gradient() * fact);
480 double fact = spat * spec;
483 (*
temporal())[i].factor_gradient((*
temporal())[i].factor_gradient() * fact);
508 const GTime& obsTime,
513 bool has_npred =
false;
519 #if defined(G_USE_NPRED_CACHE)
528 #if defined(G_DEBUG_NPRED)
529 std::cout <<
"GCTAModelSkyCube::npred:";
530 std::cout <<
" cache=" << i;
531 std::cout <<
" npred=" << npred << std::endl;
557 double value = wgt_left *
m_cube(i, inx_left) +
558 wgt_right *
m_cube(i, inx_right);
561 npred += value * m_cube.solidangle(i);
566 #if defined(G_USE_NPRED_CACHE)
574 #if defined(G_NAN_CHECK)
576 std::string origin =
"GCTAModelSkyCube::npred";
577 std::string message =
" NaN/Inf encountered (npred=" +
617 "MC computation not implemented for binned analysis.");
734 for (
int k = 0; k < n; ++k) {
747 bool write_temporal = ((
m_temporal != NULL) &&
749 (*m_temporal)[0].value() != 1.0));
753 src = xml.
append(
"source");
756 if (write_temporal) {
772 if (write_temporal) {
773 if (dynamic_cast<GModelTemporalConst*>(
temporal()) == NULL) {
802 result.append(
"=== GCTAModelSkyCube ===");
813 if (n_spectral > 0) {
815 if (n_temporal > 0) {
816 result.append(
" * ");
819 if (n_temporal > 0) {
828 for (
int i = 0; i < n_spectral; ++i) {
833 for (
int i = 0; i < n_temporal; ++i) {
955 int n_pars = n_spectral + n_temporal;
961 for (
int i = 0; i < n_spectral; ++i) {
966 for (
int i = 0; i < n_temporal; ++i) {
1011 if (xml.
attribute(
"type") !=
"ModelCube") {
1012 std::string msg =
"Spatial model type \""+xml.
attribute(
"type")+
1013 "\" is not of type \"ModelCube\". Please verify "
1059 if (xml.
attribute(
"type") !=
"ModelCube") {
1060 std::string msg =
"Spatial model type \""+xml.
attribute(
"type")+
1061 "\" is not of type \"ModelCube\". Please verify "
virtual std::string type(void) const
Return data model type.
virtual void write(GXmlElement &xml) const =0
GModelTemporal * m_temporal
Temporal model.
Constant temporal model class interface definition.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
Abstract FITS image base class.
void init_members(void)
Initialise class members.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
const double & factor_gradient(void) const
Return parameter factor gradient.
double norm(const GVector &vector)
Computes vector norm.
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
CTA sky cube model class interface definition.
const std::string & name(void) const
Return parameter name.
std::string print_attributes(void) const
Print model attributes.
void warning(const std::string &origin, const std::string &message)
Emits warning.
Abstract spectral model base class.
Interface definition for the model registry class.
virtual std::string instrument(void) const =0
double gradient(void) const
Return parameter gradient.
Abstract temporal model base class.
int size(void) const
Return number of parameters.
GVector abs(const GVector &vector)
Computes absolute of vector elements.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
int size(void) const
Return number of energy boundaries.
const GFilename & filename(void) const
Return filename.
GModelSpectral * m_spectral
Spectral model.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
Abstract interface for the event classes.
void load(const GFilename &filename)
Load sky cube.
const double & wgt_left(void) const
Returns left node weight.
virtual ~GCTAModelSkyCube(void)
Destructor.
void free_members(void)
Delete class members.
virtual double size(void) const =0
Spectral model registry class definition.
void clear(void)
Clear node array.
virtual void write(GXmlElement &xml) const =0
double log10TeV(void) const
Return log10 of energy in TeV.
Random number generator class.
#define G_WRITE_XML_SPATIAL
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
virtual int elements(void) const
Return number of GXMLElement children of node.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
void set_pointers(void)
Set pointers.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
virtual const GTime & time(void) const =0
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
void read(const GFitsHDU &hdu)
Read skymap from FITS HDU.
void dir(const GSkyDir &dir)
Set sky direction.
bool is_free(void) const
Signal if parameter is free.
CTA sky cube model class.
void id(const std::string &id)
Set observation identifier.
GCTAModelSkyCube(void)
Void constructor.
bool is_notanumber(const double &x)
Signal if argument is not a number.
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
int size(void) const
Return number of parameters in model.
const double & scale(void) const
Return parameter scale.
bool is_infinite(const double &x)
Signal if argument is infinite.
virtual GCTAModelSkyCube * clone(void) const
Clone CTA sky cube model.
Definition of support function used by CTA classes.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
virtual void write(GXmlElement &xml) const
Write CTA cube background model into XML element.
virtual void clear(void)
Clear CTA sky cube model.
const double & wgt_right(void) const
Returns right node weight.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
void fix(void)
Fix a parameter.
int size(void) const
Return number of parameters.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
virtual const GEnergy & energy(void) const =0
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
const std::string extname_ebounds
void clear(void)
Clear parameter.
Abstract data model class.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
Abstract interface for FITS table.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
GEbounds m_ebounds
Energy boundaries of sky cube.
GModelPar m_norm
Normalisation parameter.
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
const int & inx_left(void) const
Returns left node index.
bool valid_model(void) const
Verifies if model has all components.
std::vector< double > m_npred_values
Model values.
void clear(void)
Clear instance.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
Abstract observation base class.
void clear(void)
Clear energy boundaries.
Abstract observation base class interface definition.
Interface definition for the spectral model registry class.
const int & inx_right(void) const
Returns right node index.
Interface definition for the temporal model registry class.
void write_attributes(GXmlElement &xml) const
Write model attributes.
virtual GModelSpectral * clone(void) const =0
Clones object.
void read_xml_spatial(const GXmlElement &xml)
Read spatial model from XML element.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA cube background model information.
std::vector< std::string > m_npred_names
Model names.
virtual void read(const GXmlElement &xml)
Read CTA sky cube model from XML element.
GFitsImage * image(const int &extno)
Get pointer to image HDU.
virtual std::string type(void) const =0
GFilename m_filename
Filename.
void free_members(void)
Delete class members.
void write_xml_spatial(GXmlElement &xml) const
Write spatial model into XML element.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
void clear(void)
Clear file name.
Temporal model registry class definition.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Return event rate in units of events MeV s sr .
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
double value(void) const
Return parameter value.
GNodeArray m_elogmeans
Mean log10(TeV) energies for the sky cube.
GModelSpectral * spectral(void) const
Return spectral model component.
void copy_members(const GCTAModelSkyCube &bgd)
Copy class members.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
GVector exp(const GVector &vector)
Computes exponential of vector elements.
virtual GModelTemporal * clone(void) const =0
Clones object.
void read_attributes(const GXmlElement &xml)
Read model attributes.
CTA instrument direction class.
#define G_READ_XML_SPATIAL
std::vector< GTime > m_npred_times
Model time.
GModelTemporal * temporal(void) const
Return temporal model component.
Model registry class definition.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void append(const double &node)
Append one node to array.
const int & npix(void) const
Returns number of pixels.
void close(void)
Close FITS file.
const GXmlElement * xml_get_par(const std::string &origin, const GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
virtual GCTAModelSkyCube & operator=(const GCTAModelSkyCube &model)
Assignment operator.
void init_members(void)
Initialise class members.
std::vector< GEnergy > m_npred_energies
Model energy.
Constant temporal model class.
const GCTAModelSkyCube g_cta_inst_sky_seed
Class that handles energies in a unit independent way.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated event rate in units of events MeV s .