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;
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
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);
1102 irf = integral.
romberg(bounds, iter_rho);
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())) {
1361 irf *=
psf_radial(model, rho_obs, obsDir, srcEng, obsTime);
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())) {
1464 irf *=
psf_elliptical(model, rho_obs, posangle_obs, obsDir, srcEng, obsTime);
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)) {
1571 irf *=
psf_diffuse(model, obsDir, srcEng, obsTime);
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;
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;
const GFilename & filename(void) const
Return edisp cube filename.
void copy_members(const GCTAResponseCube &rsp)
Copy class members.
const int & ieng(void) const
Return the energy layer index.
std::string print(const GChatter &chatter=NORMAL) const
Print energy dispersion cube information.
CTA response helper classes definition.
bool m_use_irf_cache
Control usage of irf cache.
double irf_radial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to radial source.
void computed_gradient(const GModel &model, const GModelPar &par) const
Signals that an analytical gradient was computed for a model parameter.
double norm(const GVector &vector)
Computes vector norm.
double dec_deg(void) const
Returns Declination in degrees.
double romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
Point source spatial model class interface definition.
GCTACubePsf m_psf
Mean point spread function.
virtual bool use_edisp(void) const
Signal if response uses energy dispersion.
Radial shell model class interface definition.
const GCTAInstDir & cta_dir(const std::string &origin, const GEvent &event)
Retrieve CTA instrument direction from generic event.
CTA cube-style response function class definition.
Energy value class definition.
Abstract elliptical spatial model base class.
GCTACubeExposure m_exposure
Exposure cube.
virtual const GCTAInstDir & dir(void) const
Return instrument direction of event bin.
void load(const GFilename &filename)
Load PSF cube from FITS file.
const GSkyDir & dir(void) const
Return position of point source.
int size(void) const
Return number of parameters.
void clear(void)
Clear instance.
const GTime & time(void) const
Return event cube mean time.
bool has_free_pars(void) const
Checks if the spatial model has free parameters.
Sky direction class interface definition.
const GFilename & filename(void) const
Return background cube filename.
GCTAEventBin class interface definition.
const GCTACubeBackground & background(void) const
Return cube analysis background cube.
CTA cube background class.
Abstract radial spatial model base class interface definition.
CTA event bin class interface definition.
CTA cube-style response function class.
void clear(void)
Clear instance.
Abstract interface for the event classes.
void fixed_iter(const int &iter)
Set fixed number of iterations.
std::vector< std::string > m_cache_names
Model names.
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.
const GCTAEventCube & cta_event_cube(const std::string &origin, const GObservation &obs)
Retrieve CTA event cube from generic observation.
const GSkyDir & dir(void) const
Return position of elliptical spatial model.
virtual double irf_composite(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to composite source.
void counts(const GSkyMap &counts)
Set event cube counts from sky map.
virtual GVector column(const int &column) const
Extract column as vector from matrix.
std::string print(const GChatter &chatter=NORMAL) const
Print background information.
virtual GCTAResponseCube & operator=(const GCTAResponseCube &rsp)
Assignment operator.
void load(const GFilename &filename)
Load energy dispersion cube from FITS file.
virtual double irf_spatial(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response integrated over the spatial model.
GIntegral class interface definition.
virtual const GEnergy & energy(void) const
Return energy of event bin.
double irf_diffuse(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to diffuse source.
virtual void write(GXmlElement &xml) const
Write response information into XML element.
const std::string & name(void) const
Return model name.
void init_members(void)
Initialise class members.
GFilename xml_file_reduce(const GXmlElement &xml, const std::string &filename)
Reduce file name provided for writing as XML attribute.
virtual GClassCode code(void) const =0
void dir(const GSkyDir &dir)
Set sky direction.
void init_members(void)
Initialise class members.
bool is_free(void) const
Signal if parameter is free.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print response information.
void eulery(const double &angle)
Set Euler rotation matrix around y axis.
virtual double theta_max(void) const =0
std::string print(const GChatter &chatter=NORMAL) const
Print exposure cube information.
void id(const std::string &id)
Set observation identifier.
int ny(void) const
Return number of bins in Y direction.
Abstract instrument direction base class.
bool is_notanumber(const double &x)
Signal if argument is not a number.
void load(const GFilename &filename)
Load exposure cube from FITS file.
void init_members(void)
Initialise class members.
Class that handles photons.
bool is_infinite(const double &x)
Signal if argument is infinite.
virtual GCTAResponse & operator=(const GCTAResponse &rsp)
Assignment operator.
Definition of support function used by CTA classes.
std::vector< GNdarray > m_cache_values
Cached values.
Kernel for radial spatial model PSF delta angle integration.
const GCTACubeExposure & exposure(void) const
Return exposure cube.
double semiminor(void) const
Return semi-minor axis of ellipse.
virtual bool is_bin(void) const =0
CTA event bin container class.
void clear(void)
Clear background.
bool has_grad(void) const
Signal if parameter gradient is computed analytically.
int npix(void) const
Return number of pixels in one energy bins of the event cube.
const GSkyDir & dir(void) const
Return position of radial spatial model.
Energy boundaries container class.
const GXmlAttribute * attribute(const int &index) const
Return attribute.
GEbounds ebounds(const GEnergy &obsEng) const
Return boundaries in true energy.
virtual ~GCTAResponseCube(void)
Destructor.
const GCTACubePsf & psf(void) const
Return cube analysis point spread function.
const int & rows(void) const
Return number of matrix rows.
N-dimensional array class interface definition.
Energy container class definition.
Kernel for Psf delta angle integration used for stacked analysis.
GCTACubeBackground m_background
Background cube.
void eulerz(const double &angle)
Set Euler rotation matrix around z axis.
Integration class for set of functions interface definition.
virtual const GTime & time(void) const
Return time of event bin.
int nx(void) const
Return number of bins in X direction.
int size(void) const
Return number of energies in container.
bool m_has_edisp
Flag to indicate if energy.
GXmlElement * xml_need_par(const std::string &origin, GXmlElement &xml, const std::string &name)
Return pointer to parameter with given name in XML element.
Implementation of CTA helper classes for stacked vector response.
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.
const GFilename & filename(void) const
Return exposure cube filename.
Abstract event base class definition.
void free_members(void)
Delete class members.
const GCTACubeEdisp & edisp(void) const
Return cube analysis energy dispersion cube.
void free_members(void)
Delete class members.
virtual GCTAResponseCube * clone(void) const
Clone instance.
CTA instrument direction class interface definition.
double ra_deg(void) const
Returns Right Ascension in degrees.
virtual GEbounds ebounds(const GEnergy &obsEng) const
Return true energy boundaries for a specific observed energy.
double resolution(const GModelSpatial *model)
Determine resolution of spatial model.
CTA energy dispersion for stacked analysis.
double deadc(void) const
Return deadtime correction.
const GEnergy & energy(const int &index) const
Return energy of cube layer.
virtual void clear(void)
Clear instance.
Spatial composite model class interface definition.
const GModelSpatial * model(void) const
Return spatial model component.
Abstract observation base class.
const GEnergy & energy(void) const
Return photon energy.
N-dimensional array class.
double psf_diffuse(const GModelSpatial *model, const GSkyDir &obsDir, const GEnergy &srcEng, const GTime &srcTime) const
Integrate PSF over diffuse model.
virtual bool contains(const GSkyDir &dir, const double &margin=0.0) const =0
Abstract observation base class interface definition.
double irf_ptsrc(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to point source.
Point source spatial model.
void load(const GFilename &filename)
Load background cube from FITS file.
bool xml_has_par(const GXmlElement &xml, const std::string &name)
Checks if parameter with given name in XML element exists.
Kernel for Psf delta angle integration used for stacked analysis.
CTA instrument response function class.
void free_members(void)
Delete class members.
Abstract elliptical spatial model base class interface definition.
Abstract diffuse spatial model base class interface definition.
double posang(const GSkyDir &dir, const std::string &coordsys="CEL") const
Compute position angle between sky directions in radians.
int iter_phi(const double &rho, const double &resolution, const int &iter_min, const int &iter_max)
Determine number of azimuthal Romberg iterations.
CTA point spread function for cube analysis.
std::string print(const GChatter &chatter=NORMAL) const
Print PSF cube information.
double posangle(void) const
Return Position Angle of model.
bool m_apply_edisp
Apply energy dispersion.
GCTACubeEdisp m_edisp
Energy dispersion cube.
GChatter reduce(const GChatter &chatter)
Reduce chattiness by one level.
Sparse matrix class definition.
double delta_max(void) const
Return maximum delta value in radians.
CTA event bin container class interface definition.
const double & livetime(void) const
Return livetime.
virtual GEvents * events(void)
Return events.
virtual void read(const GXmlElement &xml)
Read response information from XML element.
const GEnergy & energy(void) const
Return photon energy.
GEnergy & append(const GEnergy &energy)
Append energy to container.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return instrument response.
GVector romberg(std::vector< double > bounds, const int &order=5)
Perform Romberg integration.
virtual double theta_max(void) const =0
double dist(const GSkyDir &dir) const
Compute angular distance between sky directions in radians.
void fixed_iter(const int &iter)
Set fixed number of iterations.
GModelSpatial * spatial(void) const
Return spatial model component.
CTA instrument direction class.
Abstract spatial model base class.
GResponseCache m_irf_cache
Abstract radial spatial model base class.
GCTAResponseCube(void)
Void constructor.
Generic matrix class definition.
Abstract diffuse spatial model base class.
double irf_elliptical(const GEvent &event, const GSource &source, const GObservation &obs) const
Return instrument response to elliptical source.
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.
Integration class for set of functions.
virtual bool apply_edisp(void) const
Signal if energy dispersion should be applied.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
void clear(void)
Clear energy dispersion cube.
Class that handles gamma-ray sources.
void set(const std::string &name, const GEnergy &ereco, const GEnergy &etrue, const double &value)
Set cache value.
int ebins(void) const
Return number of energy bins in the event cube.
Integration class interface definition.
const GFilename & filename(void) const
Return exposure cube filename.
const int & ipix(void) const
Return the spatial pixel index.
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 int & columns(void) const
Return number of matrix columns.
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 semimajor(void) const
Return semi-major axis of ellipse.
const GSkyDir & dir(void) const
Return photon sky direction.
Time class interface definition.
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.
std::string print(const GChatter &chatter=NORMAL) const
Print response cache.
Class that handles energies in a unit independent way.
virtual int size(void) const =0
GFilename xml_file_expand(const GXmlElement &xml, const std::string &filename)
Expand file name provided as XML attribute for loading.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.