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) {
542 gradients[i] =
m_pars[i]->factor_gradient();
567 const bool& gradients)
const
570 double value = obs.
response()->convolve(*
this, event, obs, gradients);
649 const GTime& obsTime,
659 npred = obs.
response()->nroi(*
this, obsEng, obsTime, obs);
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) {
947 double flux = (use_model) ? spectral->
flux(emin, emax) : 0.0;
951 double rate = flux * area *
norm;
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) {
1094 flux = nodes.
flux(emin, emax);
1127 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1134 double mev_min = emin.
MeV();
1135 double mev_max = emax.
MeV();
1138 if (mev_max > mev_min) {
1191 for (
int i = 0; i < nodes.
nodes(); ++i) {
1206 eflux = nodes.
eflux(emin, emax);
1242 bool dependence = (
spatial()->
classname() ==
"GModelSpatialDiffuseCube") ||
1249 double mev_min = emin.
MeV();
1250 double mev_max = emax.
MeV();
1253 if (mev_max > mev_min) {
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) {
1396 flux_error += factor * factor;
1407 if (flux_error > 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) {
1536 flux_error += factor * factor;
1547 if (flux_error > 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) {
1672 eflux_error += factor * factor;
1683 if (eflux_error > 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) {
1812 eflux_error += factor * factor;
1823 if (eflux_error > 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) {
1887 for (
int i = 0; i < n_spectral; ++i) {
1892 for (
int i = 0; i < n_temporal; ++i) {
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) {
2041 if (dynamic_cast<const GModelSpatialPointSource*>(
m_spatial) != NULL) {
2046 else if (dynamic_cast<const GModelSpatialRadial*>(
m_spatial) != NULL) {
2047 m_type =
"ExtendedSource";
2051 else if (dynamic_cast<const GModelSpatialElliptical*>(
m_spatial) != NULL) {
2052 m_type =
"ExtendedSource";
2056 else if (dynamic_cast<const GModelSpatialComposite*>(
m_spatial) != NULL) {
2057 m_type =
"CompositeSource";
2062 m_type =
"DiffuseSource";
2114 for (
int i = 0; i <
scales(); ++i) {
2250 double value = m_parent->spatial()->flux(*m_region, eng);
2253 value *= m_parent->spectral()->eval(eng);
virtual void write(GXmlElement &xml) const =0
Constant temporal model class interface definition.
const double & factor_error(void) const
Return parameter factor error.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
void free_members(void)
Delete class members.
int scales(void) const
Return number of scale parameters in model.
void set_type(void)
Set model type based on spatial model component.
void computed_gradient(const GModel &model, const GModelPar &par) const
Signals that an analytical gradient was computed for a model parameter.
virtual GSkyDir mc(const GEnergy &energy, const GTime &time, GRan &ran) const =0
GModelTemporal * m_temporal
Temporal model.
virtual GTimes mc(const double &rate, const GTime &tmin, const GTime &tmax, GRan &ran) const =0
virtual GEnergy mc(const GEnergy &emin, const GEnergy &emax, const GTime &time, GRan &ran) const =0
double norm(const GVector &vector)
Computes vector norm.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Point source spatial model class interface definition.
int size(void) const
Return number of times.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const =0
const std::string & name(void) const
Return parameter name.
std::string print_attributes(void) const
Print model attributes.
Abstract spectral model base class.
Sparse matrix class interface definition.
void copy_members(const GModelSky &model)
Copy class members.
Interface definition for the model registry class.
virtual std::string instrument(void) const =0
GModelSpectral * spectral(void) const
Return spectral model component.
GModelTemporal * xml_temporal(const GXmlElement &temporal) const
Return pointer to temporal model from XML element.
double eflux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux error.
int size(void) const
Return number of parameters.
Abstract temporal model base class.
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.
int size(void) const
Return number of parameters.
virtual void clear(void)
Clear sky model.
virtual double eval(const GEnergy &srcEng, const GTime &srcTime=GTime(), const bool &gradients=false) const =0
GModelSpatial * xml_spatial(const GXmlElement &spatial) const
Return pointer to spatial model from XML element.
GModelTemporal * temporal(void) const
Return temporal model component.
Abstract radial spatial model base class interface definition.
void signal_analytical_gradients(const GObservation &obs) const
Signal all parameters that have analytical gradients for a given observation.
Abstract interface for the event classes.
void set_pointers(void)
Set parameter pointers.
Spectral model registry class definition.
virtual ~GModelSky(void)
Destructor.
virtual void write(GXmlElement &xml) const =0
Random number generator class.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const
Returns model photon flux between emin, emax
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const
Returns model energy flux between emin, emax
double MeV(void) const
Return energy in MeV.
bool valid_model(void) const
Verifies if model has all components.
virtual int elements(void) const
Return number of GXMLElement children of node.
GIntegral class interface definition.
virtual GModelTemporalConst * clone(void) const
Clone constant temporal model.
Interface for the circular sky region class.
Interface definition for the spatial model registry class.
const GModelSky * m_parent
Sky model.
bool is_free(void) const
Signal if parameter is free.
std::string m_type
Model type.
GModelSpectral * m_spectral
Spectral model.
std::vector< GModelPar > m_scales
Model instrument scale factors.
Spectral nodes model class.
double flux_error(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux error.
bool is_notanumber(const double &x)
Signal if argument is not a number.
std::vector< GModelPar * > m_pars
Pointers to all model parameters.
virtual void write(GXmlElement &xml) const
Write model into XML element.
int size(void) const
Return number of parameters in model.
Class that handles photons.
bool is_infinite(const double &x)
Signal if argument is infinite.
void init_members(void)
Initialise class members.
void mc_cone(const GSkyRegionCircle &cone) const
Set Monte Carlo simulation cone.
GVector sqrt(const GVector &vector)
Computes square root of vector elements.
const GModelSpectralNodes & spectrum(void) const
Get map cube spectrum.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
Abstract interface for the sky region class.
double eval(const double &x)
Integration kernel for flux_kern() class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
const std::string & name(void) const
Return parameter name.
const double & factor_max(void) const
Return parameter maximum factor boundary.
GVector gradients(const GPhoton &photon)
Return parameter gradients of sky model for a given photon.
double eflux(const GEnergy &emin, const GEnergy &emax) const
Return sky model energy flux.
Energy container class definition.
double eval(const double &x)
Integration kernel for eflux_kern() class.
int size(void) const
Return number of parameters.
virtual double npred(const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return spatially integrated sky model.
const GSkyRegion * m_region
Sky region.
GModelTemporal * alloc(const GXmlElement &xml) const
Allocate temporal model that is found in XML element.
void autoscale(void)
Autoscale parameter.
GVector log(const GVector &vector)
Computes natural logarithm of vector elements.
Spatial model registry class definition.
virtual void read(const GXmlElement &xml)
Read sky model from XML element.
GModelSpectral * alloc(const GXmlElement &xml) const
Allocate spectral model that is found in XML element.
const GTime & time(void) const
Return photon time.
GEnergy energy(const int &index) const
Return node energy.
GModelSpatial * alloc(const GXmlElement &xml) const
Allocate spatial model that is found in XML element.
virtual void response(const GResponse &rsp)=0
virtual double eval(const GTime &srcTime, const bool &gradients=false) const =0
bool has_max(void) const
Signal if parameter has maximum boundary.
Spatial composite model class interface definition.
Abstract observation base class.
virtual GModelSky * clone(void) const
Clone sky model.
bool has_scales(void) const
Signals that model has scales.
const GModelSky g_extendedsource_seed("ExtendedSource")
GModelPar & scale(const int &index)
Returns reference to scale parameter by index.
Interface definition for the spectral model registry class.
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.
virtual GModelSky & operator=(const GModelSky &model)
Assignment operator.
Abstract elliptical spatial model base class interface definition.
Abstract response base class definition.
double intensity(const int &index) const
Return node intensity.
const double & factor_min(void) const
Return parameter minimum factor boundary.
double value(const GPhoton &photon)
Return value of sky model for a given photon.
const GModelSky g_diffusesource_seed("DiffuseSource")
virtual GXmlElement * element(const int &index)
Return pointer to GXMLElement child.
void reserve(const int &num)
Reserve memory for photons in container.
Temporal model registry class definition.
Sky model class interface definition.
Spatial map cube model class interface definition.
int nodes(void) const
Return number of nodes.
bool has_min(void) const
Signal if parameter has minimum boundary.
void init_members(void)
Initialise class members.
virtual std::string classname(void) const =0
Return class name.
virtual double mc_norm(const GSkyDir &dir, const double &radius) const =0
void append(const GPhoton &photon)
Append photon to container.
virtual std::string type(void) const
Return sky model type.
virtual double flux(const GSkyRegion ®ion, const GEnergy &srcEng=GEnergy(), const GTime &srcTime=GTime()) const
Returns model flux within sky region.
GModelSpatial * m_spatial
Spatial model.
const GEnergy & energy(void) const
Return photon energy.
Exception handler interface definition.
GModelSpatial * spatial(void) const
Return spatial model component.
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.
Abstract spatial model base class.
virtual void write(GXmlElement &xml) const =0
GModelSky(void)
Void constructor.
double norm(void) const
Return normalization factor.
virtual GModel & operator=(const GModel &model)
Assignment operator.
virtual double flux(const GEnergy &emin, const GEnergy &emax) const =0
Model registry class definition.
virtual double eflux(const GEnergy &emin, const GEnergy &emax) const =0
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.
double flux(const GEnergy &emin, const GEnergy &emax) const
Return sky model photon flux.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print model information.
Integration class interface definition.
const GModelSky g_compositesource_seed("CompositeSource")
virtual GModelSpatial * clone(void) const =0
Clones object.
const GSkyDir & dir(void) const
Return photon sky direction.
virtual double eval(const GEvent &event, const GObservation &obs, const bool &gradients=false) const
Evaluate sky model for a given event of an observation.
const GModelSky g_pointsource_seed("PointSource")
Constant temporal model class.
void free_members(void)
Delete class members.
const double & factor_value(void) const
Return parameter factor value.
Class that handles energies in a unit independent way.
GModelSpectral * xml_spectral(const GXmlElement &spectral) const
Return pointer to spectral model from XML element.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.