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)
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) {
427 spat_raw = std::exp(wgt_left * std::log(spat_left) +
428 wgt_right * std::log(spat_right));
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);
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) {
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) {
829 result.append(
"\n"+(*
spectral())[i].print());
833 for (
int i = 0; i < n_temporal; ++i) {
834 result.append(
"\n"+(*
temporal())[i].print());
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 "
const GCTAModelSkyCube g_cta_inst_sky_seed
#define G_READ_XML_SPATIAL
#define G_WRITE_XML_SPATIAL
CTA sky cube model class interface definition.
Definition of support function used by CTA classes.
Model registry class definition.
Spectral model registry class definition.
Constant temporal model class interface definition.
Temporal model registry class definition.
Abstract observation base class interface definition.
double norm(const GVector &vector)
Computes vector norm.
CTA instrument direction class.
void dir(const GSkyDir &dir)
Set sky direction.
CTA sky cube model class.
void init_members(void)
Initialise class members.
GModelSpectral * spectral(void) const
Return spectral model component.
std::vector< GTime > m_npred_times
Model time.
bool valid_model(void) const
Verifies if model has all components.
GNodeArray m_elogmeans
Mean log10(TeV) energies for the sky cube.
std::vector< GEnergy > m_npred_energies
Model energy.
void copy_members(const GCTAModelSkyCube &bgd)
Copy class members.
GModelTemporal * m_temporal
Temporal model.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print CTA cube background model information.
virtual void read(const GXmlElement &xml)
Read CTA sky cube model from XML element.
GModelTemporal * temporal(void) const
Return temporal model component.
void write_xml_spatial(GXmlElement &xml) const
Write spatial model into XML element.
virtual ~GCTAModelSkyCube(void)
Destructor.
virtual void write(GXmlElement &xml) const
Write CTA cube background model into XML element.
GFilename m_filename
Filename.
const GFilename & filename(void) const
Return filename.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
GEbounds m_ebounds
Energy boundaries of sky cube.
virtual GCTAEventList * mc(const GObservation &obs, GRan &ran) const
Return simulated list of events.
void free_members(void)
Delete class members.
virtual GCTAModelSkyCube & operator=(const GCTAModelSkyCube &model)
Assignment operator.
void read_xml_spatial(const GXmlElement &xml)
Read spatial model from XML element.
std::vector< std::string > m_npred_names
Model names.
virtual void clear(void)
Clear CTA sky cube model.
virtual GCTAModelSkyCube * clone(void) const
Clone CTA sky cube model.
GModelSpectral * m_spectral
Spectral model.
GModelPar m_norm
Normalisation parameter.
void load(const GFilename &filename)
Load sky cube.
GCTAModelSkyCube(void)
Void constructor.
std::vector< double > m_npred_values
Model values.
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 set_pointers(void)
Set pointers.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated event rate in units of events MeV s .
void read(const GFitsTable &table)
Read energy boundaries from FITS table.
int size(void) const
Return number of energy boundaries.
void clear(void)
Clear energy boundaries.
GEnergy elogmean(const int &index) const
Returns logarithmic mean energy for a given energy interval.
Class that handles energies in a unit independent way.
double log10TeV(void) const
Return log10 of energy in TeV.
Abstract interface for the event classes.
virtual const GEnergy & energy(void) const =0
virtual double size(void) const =0
virtual const GTime & time(void) const =0
void clear(void)
Clear file name.
Abstract FITS image base class.
Abstract interface for FITS table.
GFitsImage * image(const int &extno)
Get pointer to image HDU.
void close(void)
Close FITS file.
GFitsTable * table(const int &extno)
Get pointer to table HDU.
Abstract data model class.
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
virtual GModelData & operator=(const GModelData &model)
Assignment operator.
void write(GXmlElement &xml) const
Set or update parameter attributes in XML element.
void read(const GXmlElement &xml)
Extract parameter attributes from XML element.
Interface definition for the model registry class.
Interface definition for the spectral model registry class.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
Abstract spectral model base class.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual void write(GXmlElement &xml) const =0
virtual std::string type(void) const =0
int size(void) const
Return number of parameters.
Constant temporal model class.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
Interface definition for the temporal model registry class.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
Abstract temporal model base class.
virtual GModelTemporal * clone(void) const =0
Clones object.
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
int size(void) const
Return number of parameters.
virtual std::string type(void) const =0
virtual void write(GXmlElement &xml) const =0
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
void write_attributes(GXmlElement &xml) const
Write model attributes.
std::string print_attributes(void) const
Print model attributes.
int size(void) const
Return number of parameters in model.
void read_attributes(const GXmlElement &xml)
Read model attributes.
const std::string & name(void) const
Return parameter name.
void set_value(const double &value) const
Set indices and weighting factors for interpolation.
const int & inx_right(void) const
Returns right node index.
const int & inx_left(void) const
Returns left node index.
const double & wgt_right(void) const
Returns right node weight.
const double & wgt_left(void) const
Returns left node weight.
void clear(void)
Clear node array.
void append(const double &node)
Append one node to array.
Abstract observation base class.
virtual std::string instrument(void) const =0
void id(const std::string &id)
Set observation identifier.
bool is_free(void) const
Signal if parameter is free.
const double & scale(void) const
Return parameter scale.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
void range(const double &min, const double &max)
Set minimum and maximum parameter boundaries.
const double & factor_gradient(void) const
Return parameter factor gradient.
void fix(void)
Fix a parameter.
double gradient(void) const
Return parameter gradient.
void clear(void)
Clear parameter.
double value(void) const
Return parameter value.
const std::string & name(void) const
Return parameter name.
Random number generator class.
double solidangle(const int &index) const
Returns solid angle of pixel.
void clear(void)
Clear instance.
void read(const GFitsHDU &hdu)
Read skymap from FITS HDU.
const int & npix(void) const
Returns number of pixels.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
virtual GXmlNode * append(const GXmlNode &node)
Append XML child node.
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
virtual int elements(void) const
Return number of GXMLElement children of node.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
bool is_infinite(const double &x)
Signal if argument is infinite.
bool is_notanumber(const double &x)
Signal if argument is not a number.
const std::string extname_ebounds
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.
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.
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
void warning(const std::string &origin, const std::string &message)
Emits warning.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.