63 #define G_IRF "GCOMResponse::irf(GEvent&, GPhoton&, GObservation&)"
64 #define G_IRF_SPATIAL "GCOMResponse::irf_spatial(GEvent&, GSource&, "\
66 #define G_NROI "GCOMResponse::nroi(GModelSky&, GEnergy&, GTime&, "\
68 #define G_EBOUNDS "GCOMResponse::ebounds(GEnergy&)"
69 #define G_IRF_PTSRC "GCOMResponse::irf_ptsrc(GModelSky&, GObservation&, "\
71 #define G_IRF_RADIAL "GCOMResponse::irf_radial(GModelSky&, GObservation&, "\
73 #define G_IRF_ELLIPTICAL "GCOMResponse::irf_elliptical(GModelSky&, "\
74 " GObservation&, GMatrix*)"
75 #define G_IRF_DIFFUSE "GCOMResponse::irf_diffuse(GModelSky&, GObservation&, "\
136 const std::string& iaqname) :
GResponse()
292 if (observation == NULL) {
293 std::string cls = std::string(
typeid(&obs).name());
294 std::string msg =
"Observation of type \""+cls+
"\" is not a COMPTEL "
295 "observations. Please specify a COMPTEL observation "
303 std::string cls = std::string(
typeid(&cube).name());
304 std::string msg =
"Event cube of type \""+cls+
"\" is not a COMPTEL "
305 "event cube. Please specify a COMPTEL event cube "
313 std::string cls = std::string(
typeid(&event).name());
314 std::string msg =
"Event of type \""+cls+
"\" is not a COMPTEL event. "
315 "Please specify a COMPTEL event as argument.";
321 std::string msg =
"COMPTEL response is empty. Please initialise the "
322 "response with an \"IAQ\".";
326 std::string msg =
"COMPTEL response has a zero Phigeo bin size. "
327 "Please initialise the response with a valid "
353 int iphigeo = int(phirat);
354 double eps = phirat - iphigeo - 0.5;
359 iaq = (1.0 + eps) *
m_iaq[i] - eps *
m_iaq[i-1];
362 iaq = (1.0 - eps) *
m_iaq[i] + eps *
m_iaq[i+1];
367 iaq = (1.0 - eps) *
m_iaq[i] + eps *
m_iaq[i+1];
370 iaq = (1.0 + eps) *
m_iaq[i] - eps *
m_iaq[i-1];
380 double drg = observation->
drg().
map()(obsDir.
dir(), iphibar);
383 double drx = observation->
drx().
map()(srcDir);
386 double ontime = observation->
ontime();
395 irf = iaq * drg * drx / (ontime * tofcor) * phasecor;
398 irf *= obs.
deadc(srcTime);
406 #if defined(G_NAN_CHECK)
408 std::cout <<
"*** ERROR: GCOMResponse::irf:";
409 std::cout <<
" NaN/Inf encountered";
410 std::cout <<
" (irf=" <<
irf;
411 std::cout <<
", iaq=" << iaq;
412 std::cout <<
", drg=" << drg;
413 std::cout <<
", drx=" << drx;
415 std::cout << std::endl;
440 const GTime& obsTime,
444 std::string msg =
"Spatial integration of sky model over the data space "
445 "is not implemented.";
468 std::string msg =
"Energy dispersion not implemented.";
529 GFits fits(filename);
579 if (image.
naxis() == 2) {
604 m_iaq.assign(size, 0.0);
607 for (
int i = 0; i < size; ++i) {
621 double phigeo = iphigeo * phigeo_bin + phigeo_min;
622 double omega = omega0 *
std::sin(phigeo);
656 double omega = omega0 *
std::sin(phigeo * gammalib::deg2rad);
659 image(iphigeo, iphibar) =
m_iaq[i] * omega;
664 image.
card(
"CTYPE1",
"Phigeo",
"Geometrical scatter angle");
666 "[deg] Geometrical scatter angle for reference bin");
668 "[deg] Geometrical scatter angle bin size");
670 "Reference bin of geometrical scatter angle");
671 image.
card(
"CTYPE2",
"Phibar",
"Compton scatter angle");
673 "[deg] Compton scatter angle for reference bin");
676 "Reference bin of Compton scatter angle");
677 image.
card(
"BUNIT",
"Probability per bin",
"Unit of bins");
678 image.
card(
"TELESCOP",
"GRO",
"Name of telescope");
679 image.
card(
"INSTRUME",
"COMPTEL",
"Name of instrument");
680 image.
card(
"ORIGIN",
"GammaLib",
"Origin of FITS file");
681 image.
card(
"OBSERVER",
"Unknown",
"Observer that created FITS file");
739 result.append(
"=== GCOMResponse ===");
882 if (obs_ptr == NULL) {
883 std::string cls = std::string(
typeid(&obs).name());
884 std::string msg =
"Observation of type \""+cls+
"\" is not a COMPTEL "
885 "observations. Please specify a COMPTEL observation "
893 std::string msg =
"Observation \""+obs.
name()+
"\" ("+obs.
id()+
") does "
894 "not contain a COMPTEL event cube. Please specify "
895 "a COMPTEL observation containing and event cube.";
901 std::string msg =
"COMPTEL response is empty. Please initialise the "
902 "response with an \"IAQ\".";
906 std::string msg =
"COMPTEL response has a zero Phigeo bin size. "
907 "Please initialise the response with a valid "
914 int nphibar = cube->
naxis(2);
915 int nevents = cube->
size();
920 std::string msg =
"DRE has "+
gammalib::str(nphibar)+
" Phibar layers "
922 "bins. Please specify a compatible IAQ.";
934 double iaq_norm = obs_ptr->
drx().
map()(srcDir) * obs_ptr->
deadc() /
942 for (
int ipix = 0; ipix < npix; ++ipix) {
955 double phigeo = srcDir.
dist_deg(phigeoDir);
959 int iphigeo = int(phirat);
960 double eps = phirat - iphigeo - 0.5;
967 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
978 iaq = (1.0 + eps) *
m_iaq[i] - eps *
m_iaq[i-1];
981 iaq = (1.0 - eps) *
m_iaq[i] + eps *
m_iaq[i+1];
986 iaq = (1.0 - eps) *
m_iaq[i] + eps *
m_iaq[i+1];
989 iaq = (1.0 + eps) *
m_iaq[i] - eps *
m_iaq[i-1];
997 int idri = ipix + iphibar * npix;
1000 double irf = iaq * drg[idri] * iaq_norm;
1048 static const int iter_omega = 5;
1052 if (obs_ptr == NULL) {
1053 std::string cls = std::string(
typeid(&obs).name());
1054 std::string msg =
"Observation of type \""+cls+
"\" is not a COMPTEL "
1055 "observations. Please specify a COMPTEL observation "
1063 std::string msg =
"Observation \""+obs.
name()+
"\" ("+obs.
id()+
") does "
1064 "not contain a COMPTEL event cube. Please specify "
1065 "a COMPTEL observation containing and event cube.";
1070 if (
m_iaq.empty()) {
1071 std::string msg =
"COMPTEL response is empty. Please initialise the "
1072 "response with an \"IAQ\".";
1076 std::string msg =
"COMPTEL response has a zero Phigeo bin size. "
1077 "Please initialise the response with a valid "
1090 const double& theta_max = radial->
theta_max() - 1.0e-12;
1094 int nphibar = cube->
naxis(2);
1095 int nevents = cube->
size();
1100 std::string msg =
"DRE has "+
gammalib::str(nphibar)+
" Phibar layers "
1102 "bins. Please specify a compatible IAQ.";
1111 double phigeo_min =
m_phigeo_min * gammalib::deg2rad - 0.5 * phigeo_bin;
1112 double phigeo_max = phigeo_min + phigeo_bin *
m_phigeo_bins;
1117 double iaq_norm = obs_ptr->
deadc() /
1126 GMatrix rot = (ry * rz).transpose();
1129 for (
int ipix = 0; ipix < npix; ++ipix) {
1142 double zeta = phigeoDir.
dist(model_dir);
1145 double rho_min = (zeta > phigeo_max) ? zeta - phigeo_max : 0.0;
1146 double rho_max = zeta + phigeo_max;
1147 if (rho_min > theta_max) {
1148 rho_min = theta_max;
1150 if (rho_max > theta_max) {
1151 rho_max = theta_max;
1155 if (rho_max > rho_min) {
1177 irf = integral.
romberg(rho_min, rho_max, iter_rho);
1180 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1181 int idri = ipix + iphibar * npix;
1182 irfs[idri] = irf[iphibar] * drg[idri] * iaq_norm;
1219 static const int iter_omega = 5;
1223 if (obs_ptr == NULL) {
1224 std::string cls = std::string(
typeid(&obs).name());
1225 std::string msg =
"Observation of type \""+cls+
"\" is not a COMPTEL "
1226 "observations. Please specify a COMPTEL observation "
1234 std::string msg =
"Observation \""+obs.
name()+
"\" ("+obs.
id()+
") does "
1235 "not contain a COMPTEL event cube. Please specify "
1236 "a COMPTEL observation containing and event cube.";
1241 if (
m_iaq.empty()) {
1242 std::string msg =
"COMPTEL response is empty. Please initialise the "
1243 "response with an \"IAQ\".";
1247 std::string msg =
"COMPTEL response has a zero Phigeo bin size. "
1248 "Please initialise the response with a valid "
1258 const GSkyDir& model_dir = elliptical->
dir();
1259 const double& theta_max = elliptical->
theta_max();
1263 int nphibar = cube->
naxis(2);
1264 int nevents = cube->
size();
1269 std::string msg =
"DRE has "+
gammalib::str(nphibar)+
" Phibar layers "
1271 "bins. Please specify a compatible IAQ.";
1280 double phigeo_min =
m_phigeo_min * gammalib::deg2rad - 0.5 * phigeo_bin;
1281 double phigeo_max = phigeo_min + phigeo_bin *
m_phigeo_bins;
1286 double iaq_norm = obs_ptr->
deadc() /
1295 GMatrix rot = (ry * rz).transpose();
1298 for (
int ipix = 0; ipix < npix; ++ipix) {
1311 double zeta = phigeoDir.
dist(model_dir);
1314 double rho_min = (zeta > phigeo_max) ? zeta - phigeo_max : 0.0;
1315 double rho_max = zeta + phigeo_max;
1316 if (rho_min > theta_max) {
1317 rho_min = theta_max;
1319 if (rho_max > theta_max) {
1320 rho_max = theta_max;
1324 if (rho_max > rho_min) {
1346 irf = integral.
romberg(rho_min, rho_max, iter_rho);
1349 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1350 int idri = ipix + iphibar * npix;
1351 irfs[idri] = irf[iphibar] * drg[idri] * iaq_norm;
1400 if (obs_ptr == NULL) {
1401 std::string cls = std::string(
typeid(&obs).name());
1402 std::string msg =
"Observation of type \""+cls+
"\" is not a COMPTEL "
1403 "observations. Please specify a COMPTEL observation "
1411 std::string msg =
"Observation \""+obs.
name()+
"\" ("+obs.
id()+
") does "
1412 "not contain a COMPTEL event cube. Please specify "
1413 "a COMPTEL observation containing and event cube.";
1418 if (
m_iaq.empty()) {
1419 std::string msg =
"COMPTEL response is empty. Please initialise the "
1420 "response with an \"IAQ\".";
1424 std::string msg =
"COMPTEL response has a zero Phigeo bin size. "
1425 "Please initialise the response with a valid "
1432 int nphibar = cube->
naxis(2);
1433 int nevents = cube->
size();
1438 std::string msg =
"DRE has "+
gammalib::str(nphibar)+
" Phibar layers "
1440 "bins. Please specify a compatible IAQ.";
1450 double omega0 = 2.0 *
std::sin(0.5 * phigeo_bin);
1455 double iaq_norm = obs_ptr->
deadc() /
1460 for (
int ipix = 0; ipix < npix; ++ipix) {
1476 double phigeo = phigeo_min + double(iphigeo) * phigeo_bin;
1477 double sin_phigeo =
std::sin(phigeo);
1482 int naz = int(length / phigeo_bin + 0.5);
1489 double omega = omega0 * az_step * sin_phigeo;
1493 for (
int iaz = 0; iaz < naz; ++iaz, az += az_step) {
1497 skyDir.
rotate(az, phigeo);
1511 if (intensity == 0.0) {
1516 intensity *= drx(skyDir);
1522 for (
int iphibar = 0; iphibar < nphibar; ++iphibar) {
1525 int i = iphibar * m_phigeo_bins + iphigeo;
1528 double iaq =
m_iaq[i];
1536 int idri = ipix + iphibar * npix;
1539 double irf = iaq * drg[idri] * iaq_norm * intensity;
virtual GCOMResponse * clone(void) const
Clone instance.
void phibar(const double &phibar)
Set event Compton scatter angle.
virtual GVector irf_radial(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to radial source.
double m_phibar_ref_value
Phigeo reference value (deg)
void save(const GFilename &filename, const bool &clobber=false) const
Save the response vector cache into FITS file.
const std::string & rspname(void) const
Return response name.
GCaldb m_caldb
Calibration database.
double dist_deg(const GSkyDir &dir) const
Compute angular distance between sky directions in degrees.
Abstract FITS image base class.
const int & naxis(void) const
Return dimension of image.
virtual std::string print(const GChatter &chatter=NORMAL) const
Print COMPTEL response information.
virtual void clear(void)
Clear instance.
double dec_deg(void) const
Returns Declination in degrees.
Point source spatial model class interface definition.
double m_phigeo_bin_size
Phigeo binsize (deg)
Energy value class definition.
Abstract elliptical spatial model base class.
virtual double eval(const GPhoton &photon, const bool &gradients=false) const =0
int m_phibar_bins
Number of Phibar bins.
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.
std::string m_rspname
Response name.
std::vector< double > m_iaq
IAQ array.
Single precision FITS image class definition.
Generic matrix class definition.
const GCOMDri & drx(void) const
Return exposure.
double m_phibar_min
Phigeo value of first bin (deg)
Abstract radial spatial model base class interface definition.
void init_members(void)
Initialise class members.
virtual int size(void) const
Return number of bins in event cube.
virtual double ontime(void) const
Return ontime.
bool is_empty(void) const
Signal if filename is empty.
Kernel for rho angle integration of elliptical models.
COMPTEL observation class interface definition.
Abstract interface for the event classes.
GFilename filename(const std::string &detector, const std::string &filter, const std::string &codename, const std::string &date, const std::string &time, const std::string &expr)
Return calibration file name based on selection parameters.
void fixed_iter(const int &iter)
Set fixed number of iterations.
const double & tof_correction(void) const
Return ToF correction factor.
const GSkyDir & dir(void) const
Return position of elliptical spatial model.
virtual GVector irf_ptsrc(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to point source.
Interface for the COMPTEL instrument response function.
double m_phigeo_ref_value
Phigeo reference value (deg)
virtual const GTime & time(void) const
Return time of event bin.
FITS file class interface definition.
void init_members(void)
Initialise class members.
double m_phibar_ref_pixel
Phigeo reference pixel (starting from 1)
virtual double deadc(const GTime &time=GTime()) const
Return deadtime correction factor.
void eulery(const double &angle)
Set Euler rotation matrix around y axis.
virtual double theta_max(void) const =0
GResponseVectorCache m_irf_vector_cache
void id(const std::string &id)
Set observation identifier.
COMPTEL event bin class interface definition.
Abstract FITS image base class definition.
double m_phigeo_min
Phigeo value of first bin (deg)
bool is_notanumber(const double &x)
Signal if argument is not a number.
virtual GCOMResponse & operator=(const GCOMResponse &rsp)
Assignment operator.
Class that handles photons.
bool is_infinite(const double &x)
Signal if argument is infinite.
double real(const std::string &keyname) const
Return card value as double precision.
const double & phase_correction(void) const
Return pulsar phase correction factor.
const GCOMDri & drg(void) const
Return geometry factors.
Calibration database class.
const GSkyDir & dir(void) const
Return position of radial spatial model.
Energy boundaries container class.
COMPTEL instrument response function class interface definition.
void dir(const GSkyDir &dir)
Set event scatter direction.
void eulerz(const double &angle)
Set Euler rotation matrix around z axis.
Integration class for set of functions interface definition.
const GSkyMap & map(void) const
Return DRI sky map.
bool exists(void) const
Checks whether file exists.
Constant spectral model class interface definition.
virtual double pixel(const int &ix) const =0
void rotate(const double &phi, const double &theta)
Rotate sky direction by zenith and azimuth angle.
Abstract event base class definition.
void write(GFitsImageFloat &image) const
Write COMPTEL response into FITS image.
bool contains(const GSkyDir &dir) const
Checks if sky direction falls in map.
virtual double deadc(const GTime &time=GTime()) const =0
void load_cache(const GFilename &filename)
Load response cache.
double ra_deg(void) const
Returns Right Ascension in degrees.
virtual GVector irf_diffuse(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to diffuse source.
const GTime & time(void) const
Return photon time.
void save_cache(const GFilename &filename) const
Save response cache.
bool is_fits(void) const
Checks whether file is a FITS file.
Abstract observation base class.
Vector class interface definition.
Single precision FITS image class.
COMPTEL event bin container class.
Abstract observation base class interface definition.
virtual double irf(const GEvent &event, const GPhoton &photon, const GObservation &obs) const
Return value of instrument response function.
Calibration database class interface definition.
Point source spatial model.
void free_members(void)
Delete class members.
Defintion of COMPTEL helper classes for vector response.
Abstract elliptical spatial model base class interface definition.
int naxes(const int &axis) const
Return dimension of an image axis.
const GCOMDri & dre(void) const
Return reference to DRE data.
virtual GResponse & operator=(const GResponse &rsp)
Assignment operator.
void name(const std::string &name)
Set observation name.
GFitsImage * image(const int &extno)
Get pointer to image HDU.
const GCaldb & caldb(void) const
Return calibration database.
void free_members(void)
Delete class members.
double m_phigeo_ref_pixel
Phigeo reference pixel (starting from 1)
Sky model class interface definition.
virtual const GCOMInstDir & dir(void) const
Return instrument direction of event bin.
virtual GEbounds ebounds(const GEnergy &obsEnergy) const
Return true energy boundaries for a specific observed energy.
GCOMResponse(void)
Void constructor.
Interface class for COMPTEL observations.
Kernel for rho angle integration of radial models.
int m_phigeo_bins
Number of Phigeo bins.
double m_phibar_bin_size
Phigeo binsize (deg)
GVector sin(const GVector &vector)
Computes sine of vector elements.
virtual GEvents * events(void)
Return events.
std::string print(const GChatter &chatter=NORMAL) const
Print calibration database information.
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.
GModelSpatial * spatial(void) const
Return spatial model component.
Abstract radial spatial model base class.
Generic matrix class definition.
std::string filepath(const std::string &pathname, const std::string &filename)
Build file path from path name and file name.
virtual GVector irf_elliptical(const GModelSky &model, const GObservation &obs, GMatrix *gradients=NULL) const
Return instrument response to elliptical source.
void copy_members(const GCOMResponse &rsp)
Copy class members.
COMPTEL instrument direction class definition.
Integration class for set of functions.
Abstract instrument response base class.
std::string parformat(const std::string &s, const int &indent=0)
Convert string in parameter format.
COMPTEL event bin container class interface definition.
virtual ~GCOMResponse(void)
Destructor.
int iter_rho(const double &rho_max, const double &resolution, const int &iter_min, const int &iter_max)
Determine number of radial Romberg iterations.
GFitsHeaderCard & card(const int &cardno)
Return header card.
void load(const GFilename &filename)
Load response vector cache from FITS file.
void close(void)
Close FITS file.
virtual int naxis(const int &axis) const
Return number of bins in axis.
const GSkyDir & dir(void) const
Return photon sky direction.
Time class interface definition.
void clear(void)
Clear calibration database.
const double * pixels(void) const
Returns pointer to pixel data.
void read(const GFitsImage &hdu)
Read COMPTEL response from FITS image.
std::string rootdir(void) const
Return path to CALDB root directory.
Filename class interface definition.
Interface for the COMPTEL instrument direction class.
Mathematical function definitions.
Class that handles energies in a unit independent way.
void load(const std::string &rspname)
Load COMPTEL response.
virtual const GEnergy & energy(void) const
Return energy of event bin.
std::string str(const unsigned short int &value)
Convert unsigned short integer value into string.