62#define G_IRF "GCTAResponseCube::irf(GEvent&, GPhoton& GObservation&)"
63#define G_IRF_PTSRC "GCTAResponseCube::irf_ptsrc(GEvent&, GSource&,"\
65#define G_IRF_RADIAL "GCTAResponseCube::irf_radial(GEvent&, GSource&,"\
67#define G_IRF_DIFFUSE "GCTAResponseCube::irf_diffuse(GEvent&, GSource&,"\
69#define G_NROI "GCTAResponseCube::nroi(GModelSky&, GEnergy&, GTime&, "\
71#define G_EBOUNDS "GCTAResponseCube::ebounds(GEnergy&)"
72#define G_READ "GCTAResponseCube::read(GXmlElement&)"
73#define G_WRITE "GCTAResponseCube::write(GXmlElement&)"
74#define G_IRF_RADIAL2 "GCTAResponseCube::irf_radial(GModelSky&, "\
75 "GObservation&, GMatrixSparse*)"
329 const GEnergy& obsEng =
event.energy();
338 double delta = obsDir.
dist(srcDir);
351 if ((livetime > 0.0) && (delta <= delta_max)) {
360 irf *=
psf()(srcDir, delta, srcEng);
364 irf *=
edisp()(obsEng, srcEng, srcDir);
378 #if defined(G_NAN_CHECK)
380 std::cout <<
"*** ERROR: GCTAResponseCube::irf:";
381 std::cout <<
" NaN/Inf encountered";
382 std::cout <<
" irf=" <<
irf;
383 std::cout << std::endl;
424 const GTime& obsTime,
428 std::string msg =
"Spatial integration of sky model over the data space "
429 "is not implemented.";
504 std::string name = obs.
id() +
"::" + source.
name();
506 const GEnergy& ereco =
event.energy();
517 std::string name = obs.
id() +
"::" + source.
name();
539 for (
int i = 0; i < cache.
size(); ++i) {
714 if (!(filename.empty())) {
721 if (!(filename.empty())) {
729 if (!(filename.empty())) {
737 if (!(filename.empty())) {
762 result.append(
"=== GCTAResponseCube ===");
767 result.append(
"Used");
771 result.append(
"Not available");
774 result.append(
"Not used");
788 result.append(
"\n"+
m_psf.
print(reduced_chatter));
902 const double& delta_mod,
905 const GTime& srcTime)
const
910 static const int iter_delta = 5;
911 static const int iter_phi = 6;
923 double delta_min = (delta_mod > theta_max) ? delta_mod - theta_max : 0.0;
924 double delta_max = delta_mod + theta_max;
925 if (delta_max > psf_max) {
946 std::vector<double> bounds;
947 bounds.push_back(delta_min);
948 bounds.push_back(delta_max);
953 double transition_point = theta_max - delta_mod;
954 if (transition_point > delta_min && transition_point < delta_max) {
955 bounds.push_back(transition_point);
959 value = integral.
romberg(bounds, iter_delta);
962 #if defined(G_NAN_CHECK)
964 std::cout <<
"*** ERROR: GCTAResponseCube::psf_radial:";
965 std::cout <<
" NaN/Inf encountered";
966 std::cout <<
" (value=" << value;
967 std::cout <<
", delta_min=" << delta_min;
968 std::cout <<
", delta_max=" << delta_max <<
")";
969 std::cout << std::endl;
1010 const double& rho_obs,
1011 const double& posangle_obs,
1014 const GTime& srcTime)
const
1019 static const int iter_rho = 5;
1020 static const int iter_phi = 5;
1036 double aspect_ratio;
1038 aspect_ratio = (model->
semimajor() > 0.0) ?
1043 aspect_ratio = (model->
semiminor() > 0.0) ?
1048 semiminor = semimajor * aspect_ratio;
1051 double rho_min = (rho_obs > delta_max) ? rho_obs - delta_max : 0.0;
1052 double rho_max = rho_obs + delta_max;
1053 if (rho_max > semimajor) {
1054 rho_max = semimajor;
1058 if (rho_max > rho_min) {
1081 std::vector<double> bounds;
1082 bounds.push_back(rho_min);
1083 bounds.push_back(rho_max);
1090 double transition_point = delta_max - rho_obs;
1091 if (transition_point > rho_min && transition_point < rho_max) {
1092 bounds.push_back(transition_point);
1097 if (semiminor > rho_min && semiminor < rho_max) {
1098 bounds.push_back(semiminor);
1105 #if defined(G_NAN_CHECK)
1107 std::cout <<
"*** ERROR: GCTAResponseCube::psf_elliptical:";
1108 std::cout <<
" NaN/Inf encountered";
1109 std::cout <<
" (irf=" <<
irf;
1110 std::cout <<
", rho_min=" << rho_min;
1111 std::cout <<
", rho_max=" << rho_max <<
")";
1112 std::cout << std::endl;
1150 const GTime& srcTime)
const
1155 static const int min_iter_delta = 5;
1156 static const int min_iter_phi = 5;
1157 static const int max_iter_delta = 8;
1158 static const int max_iter_phi = 8;
1167 GMatrix rot = (ry * rz).transpose();
1170 double delta_min = 0.0;
1181 obsDir, srcEng, srcTime,
1182 min_iter_phi, max_iter_phi,
1187 min_iter_delta, max_iter_delta);
1196 double psf = integral.
romberg(delta_min, delta_max);
1232 std::string msg =
"The current event is not a CTA event bin. "
1233 "This method only works on binned CTA data. Please "
1234 "make sure that a CTA observation containing binned "
1235 "CTA data is provided.";
1242 double delta = bin->
dir().
dir().dist(srcDir);
1252 if ((livetime > 0.0) && (delta <= delta_max)) {
1264 irf *=
psf()(srcDir, delta, srcEng);
1279 #if defined(G_NAN_CHECK)
1281 std::cout <<
"*** ERROR: GCTAResponseCube::irf_ptsrc:";
1282 std::cout <<
" NaN/Inf encountered";
1283 std::cout <<
" irf=" <<
irf;
1284 std::cout << std::endl;
1315 std::string msg =
"The current event is not a CTA event bin. "
1316 "This method only works on binned CTA data. Please "
1317 "make sure that a CTA observation containing binned "
1318 "CTA data is provided.";
1337 double rho_obs = model->
dir().
dist(obsDir);
1344 if ((livetime > 0.0) && (rho_obs <= model->theta_max()+
psf().delta_max())) {
1381 #if defined(G_NAN_CHECK)
1383 std::cout <<
"*** ERROR: GCTAResponseCube::irf_radial:";
1384 std::cout <<
" NaN/Inf encountered";
1385 std::cout <<
" irf=" <<
irf;
1386 std::cout << std::endl;
1417 std::string msg =
"The current event is not a CTA event bin. "
1418 "This method only works on binned CTA data. Please "
1419 "make sure that a CTA observation containing binned "
1420 "CTA data is provided.";
1439 double rho_obs = model->
dir().
dist(obsDir);
1440 double posangle_obs = model->
dir().
posang(obsDir);
1447 if ((livetime > 0.0) && (rho_obs <= model->theta_max()+
psf().delta_max())) {
1484 #if defined(G_NAN_CHECK)
1486 std::cout <<
"*** ERROR: GCTAResponseCube::irf_elliptical:";
1487 std::cout <<
" NaN/Inf encountered";
1488 std::cout <<
" irf=" <<
irf;
1489 std::cout << std::endl;
1523 std::string msg =
"The current event is not a CTA event bin. "
1524 "This method only works on binned CTA data. Please "
1525 "make sure that a CTA observation containing binned "
1526 "CTA data is provided.";
1552 if (livetime > 0.0 && model->
contains(obsDir, delta_max)) {
1591 #if defined(G_NAN_CHECK)
1593 std::cout <<
"*** ERROR: GCTAResponseCube::irf_diffuse:";
1594 std::cout <<
" NaN/Inf encountered";
1595 std::cout <<
" irf=" <<
irf;
1596 std::cout << std::endl;
1639 if (livetime > 0.0) {
1642 bool grad = (gradients != NULL);
1652 int npars = radial->
size();
1653 int ndirs = cube.
npix();
1654 int nengs = cube.
ebins();
1658 if (gradients->
rows() != nevents) {
1660 " rows in gradient matrix differs from number "
1662 "observation. Please provide a compatible "
1666 if (gradients->
columns() != npars) {
1668 " columns in gradient matrix differs from number "
1670 "model. Please provide a compatible "
1678 for (
int ieng = 0; ieng < nengs; ++ieng) {
1687 gradient =
new GVector[npars];
1688 for (
int ipar = 0; ipar < npars; ++ipar) {
1689 gradient[ipar] =
GVector(nevents);
1695 for (
int ipar = 0; ipar < npars; ++ipar) {
1711 for (
int idir = 0; idir < ndirs; ++idir) {
1718 double zeta = radial->
dir().
dist(obsDir);
1722 if (zeta <= radial->theta_max()+
psf().delta_max()) {
1728 for (
int ieng = 0, index = idir; ieng < nengs; ++ieng, index += ndirs) {
1735 double aeff =
norm *
exposure()(obsDir, srcEngs[ieng]);
1738 irfs[index] = aeff *
psf[ieng];
1742 for (
int ipar = 0, ipsf = ieng+nengs; ipar < npars;
1743 ++ipar, ipsf += nengs) {
1744 gradient[ipar][index] = aeff *
psf[ipsf];
1757 for (
int ipar = 0; ipar < npars; ++ipar) {
1758 gradients->
column(ipar, gradient[ipar]);
1763 if (gradient != NULL) {
1788 const GTime& srcTime,
1789 const bool& grad)
const
1794 static const int iter_delta = 5;
1795 static const int iter_phi = 6;
1804 double delta_min = (zeta > theta_max) ? zeta - theta_max : 0.0;
1805 double delta_max = zeta + theta_max;
1806 if (delta_max > psf_max) {
1807 delta_max = psf_max;
1827 std::vector<double> bounds;
1828 bounds.push_back(delta_min);
1829 bounds.push_back(delta_max);
1834 double transition_point = theta_max - zeta;
1835 if (transition_point > delta_min && transition_point < delta_max) {
1836 bounds.push_back(transition_point);
1843 #if defined(G_NAN_CHECK)
1844 for (
int i = 0; i < srcEngs.
size(); ++i) {
1847 std::cout <<
"*** ERROR: GCTAResponseCube::psf_radial:";
1848 std::cout <<
" NaN/Inf encountered";
1849 std::cout <<
" (value=" << values[i];
1850 std::cout <<
", delta_min=" << delta_min;
1851 std::cout <<
", delta_max=" << delta_max <<
")";
1852 std::cout << std::endl;
CTA event bin class interface definition.
CTA event bin container class interface definition.
CTA instrument direction class interface definition.
CTA cube-style response function class definition.
CTA response helper classes definition.
Definition of support function used by CTA classes.
Energy container class definition.
Energy value class definition.
Abstract event base class definition.
Integration class interface definition.
Integration class for set of functions interface definition.
Sparse matrix class definition.
Spatial composite model class interface definition.
Abstract diffuse spatial model base class interface definition.
Abstract elliptical spatial model base class interface definition.
Point source spatial model class interface definition.
Radial shell model class interface definition.
Abstract radial spatial model base class interface definition.
N-dimensional array class interface definition.
Abstract observation base class interface definition.
Sky direction class interface definition.
Time class interface definition.
@ GMODEL_SPATIAL_ELLIPTICAL
@ GMODEL_SPATIAL_COMPOSITE
@ GMODEL_SPATIAL_POINT_SOURCE
double norm(const GVector &vector)
Computes vector norm.
CTA cube background class.
void load(const GFilename &filename)
Load background cube from FITS file.
void clear(void)
Clear background.
const GFilename & filename(void) const
Return background cube filename.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
CTA energy dispersion for stacked analysis.
std::string print(const GChatter &chatter=NORMAL) const
Print energy dispersion cube information.
const GFilename & filename(void) const
Return edisp cube filename.
void clear(void)
Clear energy dispersion cube.
GEbounds ebounds(const GEnergy &obsEng) const
Return boundaries in true energy.
void load(const GFilename &filename)
Load energy dispersion cube from FITS file.
std::string print(const GChatter &chatter=NORMAL) const
Print exposure cube information.
void clear(void)
Clear instance.
void load(const GFilename &filename)
Load exposure cube from FITS file.
const GFilename & filename(void) const
Return exposure cube filename.
double deadc(void) const
Return deadtime correction.
const double & livetime(void) const
Return livetime.
CTA point spread function for cube analysis.
double delta_max(void) const
Return maximum delta value in radians.
std::string print(const GChatter &chatter=NORMAL) const
Print PSF cube information.
void load(const GFilename &filename)
Load PSF cube from FITS file.
const GFilename & filename(void) const
Return exposure cube filename.
void clear(void)
Clear instance.
GCTAEventBin class interface definition.
const int & ipix(void) const
Return the spatial pixel index.
const int & ieng(void) const
Return the energy layer index.
virtual const GTime & time(void) const
Return time of event bin.
virtual const GCTAInstDir & dir(void) const
Return instrument direction of event bin.
virtual const GEnergy & energy(void) const
Return energy of event bin.
CTA event bin container class.
const GEnergy & energy(const int &index) const
Return energy of cube layer.
const GTime & time(void) const
Return event cube mean time.
int npix(void) const
Return number of pixels in one energy bins of the event cube.
int nx(void) const
Return number of bins in X direction.
void counts(const GSkyMap &counts)
Set event cube counts from sky map.
int ebins(void) const
Return number of energy bins in the event cube.
int ny(void) const
Return number of bins in Y direction.
CTA instrument direction class.
void dir(const GSkyDir &dir)
Set sky direction.
CTA cube-style response function class.
virtual GCTAResponseCube * clone(void) const
Clone instance.
GCTAResponseCube(void)
Void constructor.
const GCTACubeExposure & exposure(void) const
Return exposure cube.
GCTACubeBackground m_background
Background cube.
virtual void clear(void)
Clear instance.
std::vector< GNdarray > m_cache_values
Cached values.
virtual double nroi(const GModelSky &model, const GEnergy &obsEng, const GTime &obsTime, const GObservation &obs) const
Return integral of event probability for a given sky model over ROI.
double psf_diffuse(const GModelSpatial *model, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate PSF over diffuse model.
virtual bool apply_edisp(void) const
Signal if energy dispersion should be applied.
double irf_diffuse(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to diffuse source.
virtual GCTAResponseCube & operator=(const GCTAResponseCube &rsp)
Assignment operator.
double psf_radial(const GModelSpatialRadial *model, const double &rho_obs, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate Psf over radial model.
virtual bool use_edisp(void) const
Signal if response uses energy dispersion.
virtual ~GCTAResponseCube(void)
Destructor.
double psf_elliptical(const GModelSpatialElliptical *model, const double &rho_obs, const double &posangle_obs, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate Psf over elliptical model.
void copy_members(const GCTAResponseCube &rsp)
Copy class members.
virtual GEbounds ebounds(const GEnergy &obsEng) const
Return true energy boundaries for a specific observed energy.
virtual void read(const GXmlElement &xml)
Read response information from XML element.
double irf_elliptical(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to elliptical source.
const GCTACubePsf & psf(void) const
Return cube analysis point spread function.
const GCTACubeEdisp & edisp(void) const
Return cube analysis energy dispersion cube.
std::vector< std::string > m_cache_names
Model names.
GCTACubeEdisp m_edisp
Energy dispersion cube.
double irf_ptsrc(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to point source.
virtual void write(GXmlElement &xml) const
Write response information into XML element.
GCTACubePsf m_psf
Mean point spread function.
bool m_apply_edisp
Apply energy dispersion.
const GCTACubeBackground & background(void) const
Return cube analysis background cube.
double irf_radial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to radial source.
GCTACubeExposure m_exposure
Exposure cube.
virtual double irf_spatial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response integrated over the spatial model.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return instrument response.
void init_members(void)
Initialise class members.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print response information.
bool m_has_edisp
Flag to indicate if energy.
void free_members(void)
Delete class members.
CTA instrument response function class.
void init_members(void)
Initialise class members.
virtual GCTAResponse & operator=(const GCTAResponse &rsp)
Assignment operator.
void free_members(void)
Delete class members.
Energy boundaries container class.
int size(void) const
Return number of energies in container.
GEnergy & append(const GEnergy &energy)
Append energy to container.
Class that handles energies in a unit independent way.
Abstract interface for the event classes.
virtual bool is_bin(void) const =0
virtual int size(void) const =0
Abstract instrument direction base class.
GIntegral class interface definition.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void fixed_iter(const int &iter)
Set fixed number of iterations.
Integration class for set of functions.
GVector romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
void fixed_iter(const int &iter)
Set fixed number of iterations.
const int & rows(void) const
Return number of matrix rows.
const int & columns(void) const
Return number of matrix columns.
Generic matrix class definition.
void eulerz(const double &angle)
Set Euler rotation matrix around z axis.
void eulery(const double &angle)
Set Euler rotation matrix around y axis.
virtual GVector column(const int &column) const
Extract column as vector from matrix.
GModelSpatial * spatial(void) const
Return spatial model component.
Abstract diffuse spatial model base class.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
Abstract elliptical spatial model base class.
double semimajor(void) const
Return semi-major axis of ellipse.
double posangle(void) const
Return Position Angle of model.
const GSkyDir & dir(void) const
Return position of elliptical spatial model.
double semiminor(void) const
Return semi-minor axis of ellipse.
virtual double theta_max(void) const =0
Point source spatial model.
const GSkyDir & dir(void) const
Return position of point source.
Abstract radial spatial model base class.
virtual double theta_max(void) const =0
const GSkyDir & dir(void) const
Return position of radial spatial model.
Abstract spatial model base class.
bool has_free_pars(void) const
Checks if the spatial model has free parameters.
virtual GClassCode code(void) const =0
int size(void) const
Return number of parameters.
N-dimensional array class.
int size(void) const
Return number of elements in array.
Abstract observation base class.
virtual GEvents * events(void)
Return events.
void computed_gradient(const GModel &model, const GModelPar &par) const
Signals that an analytical gradient was computed for a model parameter.
void id(const std::string &id)
Set observation identifier.
bool is_free(void) const
Signal if parameter is free.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
Class that handles photons.
const GSkyDir & dir(void) const
Return photon sky direction.
const GEnergy & energy(void) const
Return photon energy.
bool contains(const std::string &name, const GEnergy &ereco, const GEnergy &etrue, double *value=NULL) const
Check if cache contains a value for specific parameters.
std::string print(const GChatter &chatter=NORMAL) const
Print response cache.
void set(const std::string &name, const GEnergy &ereco, const GEnergy &etrue, const double &value)
Set cache value.
GResponseCache m_irf_cache
void init_members(void)
Initialise class members.
void free_members(void)
Delete class members.
bool m_use_irf_cache
Control usage of irf cache.
virtual double irf_composite(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to composite source.
double dec_deg(void) const
Returns Declination in degrees.
double ra_deg(void) const
Returns Right Ascension in degrees.
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
double posang(const GSkyDir &dir, const std::string &coordsys="CEL") const
Compute position angle between sky directions in radians.
Class that handles gamma-ray sources.
const GEnergy & energy(void) const
Return photon energy.
const std::string & name(void) const
Return model name.
const GModelSpatial * model(void) const
Return spatial model component.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
Kernel for Psf delta angle integration used for stacked analysis.
Kernel for Psf delta angle integration used for stacked analysis.
Kernel for radial spatial model PSF delta angle integration.
Implementation of CTA helper classes for stacked vector response.
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.
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.
double resolution(const GModelSpatial *model)
Determine resolution of spatial model.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
int iter_rho(const double &rho_max, const double &resolution, const int &iter_min, const int &iter_max)
Determine number of radial Romberg iterations.
const GCTAEventCube & cta_event_cube(const std::string &origin, const GObservation &obs)
Retrieve CTA event cube from generic observation.
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.