60#define G_NPRED "GModelSky::npred(GEnergy&, GTime&, GObservation&)"
61#define G_XML_SPATIAL "GModelSky::xml_spatial(GXmlElement&)"
62#define G_XML_SPECTRAL "GModelSky::xml_spectral(GXmlElement&)"
63#define G_XML_TEMPORAL "GModelSky::xml_temporal(GXmlElement&)"
64#define G_INTEGRATE_TIME "GModelSky::integrate_time(GEvent&, GObservation&,"\
66#define G_INTEGRATE_ENERGY "GModelSky::integrate_energy(GEvent&, GTime&," \
67 " GObservation&, bool)"
68#define G_INTEGRATE_DIR "GModelSky::integrate_dir(GEvent&, GEnergy&, GTime&,"\
69 " GObservation, bool)"
347 if (
this != &model) {
541 for (
int i = 0; i <
size(); ++i) {
567 const bool& gradients)
const
599 const int& offset)
const
651 const GTime& obsTime,
664 #if defined(G_NAN_CHECK)
666 std::cout <<
"*** ERROR: GModelSky::npred:";
667 std::cout <<
" NaN/Inf encountered";
668 std::cout <<
" (npred=" <<
npred;
669 std::cout <<
", obsEng=" << obsEng;
670 std::cout <<
", obsTime=" << obsTime;
671 std::cout <<
")" << std::endl;
802 for (
int k = 0; k < n; ++k) {
814 if (cons->
norm() != 1.0) {
821 src = xml.
append(
"source");
841 if (
temporal() != NULL && cons == NULL) {
885 const GSkyDir& dir,
const double& radius,
900 bool use_model = (
norm > 0.0) ?
true :
false;
906 bool free_spectral =
false;
925 for (
int i = 0; i < nodes->
nodes(); ++i) {
933 free_spectral =
true;
941 if (nodes->
nodes() == 0) {
956 #if defined(G_DUMP_MC)
957 std::cout <<
"GModelSky::mc(\"" <<
name() <<
"\": ";
958 std::cout <<
"flux=" <<
flux <<
" ph/cm2/s, ";
959 std::cout <<
"rate=" << rate <<
" ph/s, ";
960 std::cout <<
"norm=" <<
norm <<
")" << std::endl;
970 #if defined(G_DUMP_MC_DETAIL)
971 std::cout <<
" Times=" << times.
size() << std::endl;
975 if (times.
size() > 0) {
980 for (
int i = 0; i < times.
size(); ++i) {
983 #if defined(G_DUMP_MC_DETAIL)
984 std::cout <<
" Photon=" << i << std::endl;
991 photon.
time(times[i]);
994 #if defined(G_DUMP_MC_DETAIL)
995 std::cout <<
" Time=" << times[i] << std::endl;
1010 #if defined(G_DUMP_MC_DETAIL)
1011 std::cout <<
" Energy=" << photon.
energy() << std::endl;
1027 #if defined(G_DUMP_MC_DETAIL)
1028 std::cout <<
" Direction=" << photon.
dir() << std::endl;
1041 if (free_spectral)
delete spectral;
1081 for (
int i = 0; i < nodes.
nodes(); ++i) {
1129 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1136 double mev_min = emin.
MeV();
1137 double mev_max = emax.
MeV();
1140 if (mev_max > mev_min) {
1147 flux = integral.
romberg(std::log(mev_min), std::log(mev_max));
1193 for (
int i = 0; i < nodes.
nodes(); ++i) {
1244 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1251 double mev_min = emin.
MeV();
1252 double mev_max = emax.
MeV();
1255 if (mev_max > mev_min) {
1262 eflux = integral.
romberg(std::log(mev_min), std::log(mev_max));
1307 for (
int ipar = 0; ipar <
size(); ++ipar) {
1325 const double step_size = 0.0002;
1326 double h = step_size;
1338 double derivative = 0.0;
1349 double fs1 =
flux(emin, emax);
1353 double fs2 =
flux(emin, emax);
1356 derivative = (fs1 - fs2) / h;
1366 double fs1 =
flux(emin, emax);
1370 double fs2 =
flux(emin, emax);
1373 derivative = (fs1 - fs2) / h;
1382 double fs1 =
flux(emin, emax);
1386 double fs2 =
flux(emin, emax);
1389 derivative = 0.5 * (fs1 - fs2) / h;
1396 if (derivative > 0.0) {
1447 for (
int ipar = 0; ipar <
size(); ++ipar) {
1465 const double step_size = 0.0002;
1466 double h = step_size;
1478 double derivative = 0.0;
1489 double fs1 =
flux(region, emin, emax);
1493 double fs2 =
flux(region, emin, emax);
1496 derivative = (fs1 - fs2) / h;
1506 double fs1 =
flux(region, emin, emax);
1510 double fs2 =
flux(region, emin, emax);
1513 derivative = (fs1 - fs2) / h;
1522 double fs1 =
flux(region, emin, emax);
1526 double fs2 =
flux(region, emin, emax);
1529 derivative = 0.5 * (fs1 - fs2) / h;
1536 if (derivative > 0.0) {
1583 for (
int ipar = 0; ipar <
size(); ++ipar) {
1601 const double step_size = 0.0002;
1602 double h = step_size;
1614 double derivative = 0.0;
1625 double fs1 =
eflux(emin, emax);
1629 double fs2 =
eflux(emin, emax);
1632 derivative = (fs1 - fs2) / h;
1642 double fs1 =
eflux(emin, emax);
1646 double fs2 =
eflux(emin, emax);
1649 derivative = (fs1 - fs2) / h;
1658 double fs1 =
eflux(emin, emax);
1662 double fs2 =
eflux(emin, emax);
1665 derivative = 0.5 * (fs1 - fs2) / h;
1672 if (derivative > 0.0) {
1723 for (
int ipar = 0; ipar <
size(); ++ipar) {
1741 const double step_size = 0.0002;
1742 double h = step_size;
1754 double derivative = 0.0;
1765 double fs1 =
eflux(region, emin, emax);
1769 double fs2 =
eflux(region, emin, emax);
1772 derivative = (fs1 - fs2) / h;
1782 double fs1 =
eflux(region, emin, emax);
1786 double fs2 =
eflux(region, emin, emax);
1789 derivative = (fs1 - fs2) / h;
1798 double fs1 =
eflux(region, emin, emax);
1802 double fs2 =
eflux(region, emin, emax);
1805 derivative = 0.5 * (fs1 - fs2) / h;
1812 if (derivative > 0.0) {
1848 result.append(
"=== GModelSky ===");
1863 if (n_spatial > 0) {
1865 if (n_spectral > 0 || n_temporal > 0) {
1866 result.append(
" * ");
1869 if (n_spectral > 0) {
1871 if (n_temporal > 0) {
1872 result.append(
" * ");
1875 if (n_temporal > 0) {
1884 for (
int i = 0; i < n_spatial; ++i) {
1885 result.append(
"\n"+(*
spatial())[i].print());
1889 for (
int i = 0; i < n_spectral; ++i) {
1890 result.append(
"\n"+(*
spectral())[i].print());
1894 for (
int i = 0; i < n_temporal; ++i) {
1895 result.append(
"\n"+(*
temporal())[i].print());
1899 for (
int i = 0; i <
scales(); ++i) {
1990 int n_pars = n_spatial + n_spectral + n_temporal;
1997 for (
int i = 0; i < n_spatial; ++i) {
2002 for (
int i = 0; i < n_spectral; ++i) {
2007 for (
int i = 0; i < n_temporal; ++i) {
2015 for (
int i = 0; i < n_scales; ++i) {
2049 m_type =
"ExtendedSource";
2054 m_type =
"ExtendedSource";
2059 m_type =
"CompositeSource";
2064 m_type =
"DiffuseSource";
2098 if ((par.
name() !=
"GLON") &&
2099 (par.
name() !=
"GLAT") &&
2100 (par.
name() !=
"RA") &&
2101 (par.
name() !=
"DEC") &&
2102 (par.
name() !=
"Sigma")) {
2135 for (
int i = 0; i <
scales(); ++i) {
2237 double expx = std::exp(x);
2267 double expx = std::exp(x);
2271 double value = m_parent->spatial()->flux(*m_region, eng);
2274 value *= m_parent->spectral()->eval(eng);
Energy container class definition.
Exception handler interface definition.
Integration class interface definition.
Model registry class definition.
const GModelSky g_diffusesource_seed("DiffuseSource")
const GModelSky g_compositesource_seed("CompositeSource")
const GModelSky g_extendedsource_seed("ExtendedSource")
const GModelSky g_pointsource_seed("PointSource")
Sky model class interface definition.
Spatial composite model class interface definition.
Spatial map cube model class interface definition.
Abstract elliptical spatial model base class interface definition.
Point source spatial model class interface definition.
Abstract radial spatial model base class interface definition.
Spatial model registry class definition.
Spectral model registry class definition.
Constant temporal model class interface definition.
Temporal model registry class definition.
Abstract response base class definition.
double norm(const GVector &vector)
Computes vector norm.
Class that handles energies in a unit independent way.
double MeV(void) const
Return energy in MeV.
Abstract interface for the event classes.
GIntegral class interface definition.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Sparse matrix class interface definition.
Interface definition for the model registry class.
double eval(const double &x)
Integration kernel for eflux_kern() class.
const GModelSky * m_parent
Sky model.
double eval(const double &x)
Integration kernel for flux_kern() class.
const GSkyRegion * m_region
Sky region.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
virtual GModelSky & operator=(const GModelSky &model)
Assignment operator.
double eflux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux error.
void init_members(void)
Initialise class members.
GModelTemporal * m_temporal
Temporal model.
double value(const GPhoton &photon)
Return value of sky model for a given photon.
void set_pointers(void)
Set parameter pointers.
GModelSpatial * xml_spatial(const GXmlElement &spatial) const
Return pointer to spatial model from XML element.
bool valid_model(void) const
Verifies if model has all components.
GModelSpectral * m_spectral
Spectral model.
GModelSpatial * m_spatial
Spatial model.
double flux(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux.
virtual void read(const GXmlElement &xml)
Read sky model from XML element.
std::string m_type
Model type.
virtual GModelSky * clone(void) const
Clone sky model.
void set_type(void)
Set model type based on spatial model component.
double flux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux error.
GModelSpectral * spectral(void) const
Return spectral model component.
GPhotons mc(const double &area, const GSkyDir &dir, const double &radius, const GEnergy &emin, const GEnergy &emax, const GTime &tmin, const GTime &tmax, GRan &ran) const
Return simulated list of photons.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated sky model.
GVector gradients(const GPhoton &photon)
Return parameter gradients of sky model for a given photon.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
GModelSky(void)
Void constructor.
void signal_analytical_gradients(const GObservation &obs) const
Signal all parameters that have analytical gradients for a given observation.
virtual void write(GXmlElement &xml) const
Write model into XML element.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Evaluate sky model for a given event of an observation.
virtual void clear(void)
Clear sky model.
void free_members(void)
Delete class members.
double eflux(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux.
GModelTemporal * temporal(void) const
Return temporal model component.
void copy_members(const GModelSky &model)
Copy class members.
GModelSpatial * spatial(void) const
Return spatial model component.
virtual std::string type(void) const
Return sky model type.
virtual ~GModelSky(void)
Destructor.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
const GModelSpectralNodes & spectrum(void) const
Get map cube spectrum.
void mc_cone(const GSkyRegionCircle &cone) const
Set Monte Carlo simulation cone.
Abstract elliptical spatial model base class.
Point source spatial model.
Abstract radial spatial model base class.
Interface definition for the spatial model registry class.
GModelSpatial * alloc(const GXmlElement &xml) const
Allocate spatial model that is found in XML element.
Abstract spatial model base class.
std::string type(void) const
Return model type.
virtual void write(GXmlElement &xml) const =0
virtual std::string classname(void) const =0
Return class name.
virtual GModelSpatial * clone(void) const =0
Clones object.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
virtual double flux(const GSkyRegion ®ion, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns model flux within sky region.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const =0
virtual double mc_norm(const GSkyDir &dir, const double &radius) const =0
int size(void) const
Return number of parameters.
Spectral nodes model class.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between [emin, emax] (units: ph/cm2/s)
int nodes(void) const
Return number of nodes.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between [emin, emax] (units: erg/cm2/s)
double intensity(const int &index) const
Return node intensity.
GEnergy energy(const int &index) const
Return node energy.
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 GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const =0
virtual double flux(const GEnergy &emin, const GEnergy &emax) const =0
virtual GModelSpectral * clone(void) const =0
Clones object.
virtual void write(GXmlElement &xml) const =0
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const =0
virtual std::string type(void) const =0
int size(void) const
Return number of parameters.
Constant temporal model class.
double norm(void) const
Return normalization factor.
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 GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const =0
virtual void write(GXmlElement &xml) const =0
GModelPar & scale(const int &index)
Returns reference to scale parameter by index.
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
bool has_scales(void) const
Signals that model has scales.
void write_attributes(GXmlElement &xml) const
Write model attributes.
void free_members(void)
Delete class members.
void init_members(void)
Initialise class members.
std::string print_attributes(void) const
Print model attributes.
int size(void) const
Return number of parameters in model.
virtual GModel & operator=(const GModel &model)
Assignment operator.
void read_attributes(const GXmlElement &xml)
Read model attributes.
const std::string & name(void) const
Return parameter name.
int scales(void) const
Return number of scale parameters in model.
std::vector< GModelPar > m_scales
Model instrument scale factors.
Abstract observation base class.
void computed_gradient(const GModel &model, const GModelPar &par) const
Signals that an analytical gradient was computed for a model parameter.
virtual std::string instrument(void) const =0
virtual void response(const GResponse &rsp)=0
const double & factor_max(void) const
Return parameter maximum factor boundary.
const double & factor_value(void) const
Return parameter factor value.
bool is_free(void) const
Signal if parameter is free.
const double & factor_error(void) const
Return parameter factor error.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
bool has_min(void) const
Signal if parameter has minimum boundary.
std::string print(const GChatter &chatter=NORMAL) const
Print parameter information.
void autoscale(void)
Autoscale parameter.
bool has_max(void) const
Signal if parameter has maximum boundary.
const double & factor_min(void) const
Return parameter minimum factor boundary.
const std::string & name(void) const
Return parameter name.
Class that handles photons.
const GTime & time(void) const
Return photon time.
const GSkyDir & dir(void) const
Return photon sky direction.
const GEnergy & energy(void) const
Return photon energy.
void reserve(const int &num)
Reserve memory for photons in container.
void append(const GPhoton &photon)
Append photon to container.
Random number generator class.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Interface for the circular sky region class.
Abstract interface for the sky region class.
int size(void) const
Return number of times.
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.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.