GCTASupport.cpp
5.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/***************************************************************************
* GCTASupport.cpp - CTA support functions *
* ----------------------------------------------------------------------- *
* copyright (C) 2011-2013 by Juergen Knoedlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* *
***************************************************************************/
/**
* @file GCTASupport.cpp
* @brief Implementation of support function used by CTA classes
* @author Juergen Knoedlseder
*/
/* __ Includes ___________________________________________________________ */
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <cmath>
#include <iostream>
#include "GCTASupport.hpp"
#include "GTools.hpp"
#include "GMath.hpp"
/* __ Coding definitions _________________________________________________ */
/* __ Debug definitions __________________________________________________ */
#define G_CHECK_FOR_NAN 0
/***********************************************************************//**
* @brief Returns length of circular arc within circular ROI
*
* @param[in] rad Circle radius in radians (<pi).
* @param[in] dist Circle centre distance to ROI centre (<pi).
* @param[in] cosdist Cosine of circle centre distance to ROI centre.
* @param[in] sindist Sinus of circle centre distance to ROI centre.
* @param[in] roi Radius of ROI in radians.
* @param[in] cosroi Cosine of ROI radius.
*
* This method returns the arclength in radians of a circle of radius 'rad'
* with a centre that is offset by 'dist' from the ROI centre, where the ROI
* radius is given by 'roi'. To speed-up computations, the cosines and sinus
* of 'roi' and 'psf' should be calculated by the client and be passed to
* the method.
***************************************************************************/
double gammalib::cta_roi_arclength(const double& rad, const double& dist,
const double& cosdist, const double& sindist,
const double& roi, const double& cosroi)
{
// Declare arclength
double arclength;
// Handle special case that circle centre matches ROI centre
if (dist == 0.0) {
if (rad > roi) arclength = 0.0; // Circle outside ROI
else arclength = gammalib::twopi; // Circle inside ROI
}
// ... otherwise circle and ROI centres are not identical
else {
// Handle special case that we evaluate exactly at the circle
// centre. In this case we have in fact a point, and if this point
// falls within the ROI it has a formal arclength of 2pi.
//
if (rad == 0.0) {
if (dist > roi) arclength = 0.0; // Circle centre outside ROI
else arclength = gammalib::twopi; // Circle centre inside ROI
}
// ... otherwise we have to handle the general case
else {
double d = roi - dist;
if (-rad >= d) {
arclength = 0.0;
}
else if (rad <= d) {
arclength = gammalib::twopi;
}
else {
double cosrad = std::cos(rad);
double sinrad = std::sin(rad);
double cosang = (cosroi - cosdist*cosrad) / (sindist*sinrad);
arclength = 2.0 * gammalib::acos(cosang);
#if G_CHECK_FOR_NAN
if (gammalib::is_infinite(arclength) ||
gammalib::is_notanumber(arclength)) {
std::cout << "cta_roi_arclength: NaN occured";
std::cout << " rad=" << rad;
std::cout << " sinrad=" << sinrad;
std::cout << " cosrad=" << cosrad;
std::cout << " sindist=" << sindist;
std::cout << " cosdist=" << cosdist;
std::cout << " cosang=" << cosang;
std::cout << std::endl;
}
#endif
}
}
} // endelse: Circle and ROI centres were not identical
// Return arclength
return arclength;
}