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
649 const GTime& obsTime,
662 #if defined(G_NAN_CHECK)
664 std::cout <<
"*** ERROR: GModelSky::npred:";
665 std::cout <<
" NaN/Inf encountered";
666 std::cout <<
" (npred=" <<
npred;
667 std::cout <<
", obsEng=" << obsEng;
668 std::cout <<
", obsTime=" << obsTime;
669 std::cout <<
")" << std::endl;
800 for (
int k = 0; k < n; ++k) {
812 if (cons->
norm() != 1.0) {
819 src = xml.
append(
"source");
839 if (
temporal() != NULL && cons == NULL) {
883 const GSkyDir& dir,
const double& radius,
898 bool use_model = (
norm > 0.0) ?
true :
false;
904 bool free_spectral =
false;
923 for (
int i = 0; i < nodes->
nodes(); ++i) {
931 free_spectral =
true;
939 if (nodes->
nodes() == 0) {
954 #if defined(G_DUMP_MC)
955 std::cout <<
"GModelSky::mc(\"" <<
name() <<
"\": ";
956 std::cout <<
"flux=" <<
flux <<
" ph/cm2/s, ";
957 std::cout <<
"rate=" << rate <<
" ph/s, ";
958 std::cout <<
"norm=" <<
norm <<
")" << std::endl;
968 #if defined(G_DUMP_MC_DETAIL)
969 std::cout <<
" Times=" << times.
size() << std::endl;
973 if (times.
size() > 0) {
978 for (
int i = 0; i < times.
size(); ++i) {
981 #if defined(G_DUMP_MC_DETAIL)
982 std::cout <<
" Photon=" << i << std::endl;
989 photon.
time(times[i]);
992 #if defined(G_DUMP_MC_DETAIL)
993 std::cout <<
" Time=" << times[i] << std::endl;
1008 #if defined(G_DUMP_MC_DETAIL)
1009 std::cout <<
" Energy=" << photon.
energy() << std::endl;
1025 #if defined(G_DUMP_MC_DETAIL)
1026 std::cout <<
" Direction=" << photon.
dir() << std::endl;
1039 if (free_spectral)
delete spectral;
1079 for (
int i = 0; i < nodes.
nodes(); ++i) {
1127 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1134 double mev_min = emin.
MeV();
1135 double mev_max = emax.
MeV();
1138 if (mev_max > mev_min) {
1145 flux = integral.
romberg(std::log(mev_min), std::log(mev_max));
1191 for (
int i = 0; i < nodes.
nodes(); ++i) {
1242 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1249 double mev_min = emin.
MeV();
1250 double mev_max = emax.
MeV();
1253 if (mev_max > mev_min) {
1260 eflux = integral.
romberg(std::log(mev_min), std::log(mev_max));
1305 for (
int ipar = 0; ipar <
size(); ++ipar) {
1323 const double step_size = 0.0002;
1324 double h = step_size;
1336 double derivative = 0.0;
1347 double fs1 =
flux(emin, emax);
1351 double fs2 =
flux(emin, emax);
1354 derivative = (fs1 - fs2) / h;
1364 double fs1 =
flux(emin, emax);
1368 double fs2 =
flux(emin, emax);
1371 derivative = (fs1 - fs2) / h;
1380 double fs1 =
flux(emin, emax);
1384 double fs2 =
flux(emin, emax);
1387 derivative = 0.5 * (fs1 - fs2) / h;
1394 if (derivative > 0.0) {
1445 for (
int ipar = 0; ipar <
size(); ++ipar) {
1463 const double step_size = 0.0002;
1464 double h = step_size;
1476 double derivative = 0.0;
1487 double fs1 =
flux(region, emin, emax);
1491 double fs2 =
flux(region, emin, emax);
1494 derivative = (fs1 - fs2) / h;
1504 double fs1 =
flux(region, emin, emax);
1508 double fs2 =
flux(region, emin, emax);
1511 derivative = (fs1 - fs2) / h;
1520 double fs1 =
flux(region, emin, emax);
1524 double fs2 =
flux(region, emin, emax);
1527 derivative = 0.5 * (fs1 - fs2) / h;
1534 if (derivative > 0.0) {
1581 for (
int ipar = 0; ipar <
size(); ++ipar) {
1599 const double step_size = 0.0002;
1600 double h = step_size;
1612 double derivative = 0.0;
1623 double fs1 =
eflux(emin, emax);
1627 double fs2 =
eflux(emin, emax);
1630 derivative = (fs1 - fs2) / h;
1640 double fs1 =
eflux(emin, emax);
1644 double fs2 =
eflux(emin, emax);
1647 derivative = (fs1 - fs2) / h;
1656 double fs1 =
eflux(emin, emax);
1660 double fs2 =
eflux(emin, emax);
1663 derivative = 0.5 * (fs1 - fs2) / h;
1670 if (derivative > 0.0) {
1721 for (
int ipar = 0; ipar <
size(); ++ipar) {
1739 const double step_size = 0.0002;
1740 double h = step_size;
1752 double derivative = 0.0;
1763 double fs1 =
eflux(region, emin, emax);
1767 double fs2 =
eflux(region, emin, emax);
1770 derivative = (fs1 - fs2) / h;
1780 double fs1 =
eflux(region, emin, emax);
1784 double fs2 =
eflux(region, emin, emax);
1787 derivative = (fs1 - fs2) / h;
1796 double fs1 =
eflux(region, emin, emax);
1800 double fs2 =
eflux(region, emin, emax);
1803 derivative = 0.5 * (fs1 - fs2) / h;
1810 if (derivative > 0.0) {
1846 result.append(
"=== GModelSky ===");
1861 if (n_spatial > 0) {
1863 if (n_spectral > 0 || n_temporal > 0) {
1864 result.append(
" * ");
1867 if (n_spectral > 0) {
1869 if (n_temporal > 0) {
1870 result.append(
" * ");
1873 if (n_temporal > 0) {
1882 for (
int i = 0; i < n_spatial; ++i) {
1883 result.append(
"\n"+(*
spatial())[i].print());
1887 for (
int i = 0; i < n_spectral; ++i) {
1888 result.append(
"\n"+(*
spectral())[i].print());
1892 for (
int i = 0; i < n_temporal; ++i) {
1893 result.append(
"\n"+(*
temporal())[i].print());
1897 for (
int i = 0; i <
scales(); ++i) {
1988 int n_pars = n_spatial + n_spectral + n_temporal;
1995 for (
int i = 0; i < n_spatial; ++i) {
2000 for (
int i = 0; i < n_spectral; ++i) {
2005 for (
int i = 0; i < n_temporal; ++i) {
2013 for (
int i = 0; i < n_scales; ++i) {
2047 m_type =
"ExtendedSource";
2052 m_type =
"ExtendedSource";
2057 m_type =
"CompositeSource";
2062 m_type =
"DiffuseSource";
2114 for (
int i = 0; i <
scales(); ++i) {
2216 double expx = std::exp(x);
2246 double expx = std::exp(x);
2250 double value = m_parent->spatial()->flux(*m_region, eng);
2253 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 integrated in circular 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.