25#include <gsl/gsl_linalg.h>
27#include <lal/LALConstants.h>
28#include <lal/LALMalloc.h>
29#include <lal/XLALError.h>
30#include <lal/DetResponse.h>
31#include <lal/Skymap.h>
37static double dot3(
double a[3],
double b[3])
39 return a[0] * b[0] +
a[1] * b[1] +
a[2] * b[2];
44static void inv22(
double a[2][2],
double b[2][2])
46 double c = b[0][0] * b[1][1] - b[0][1] * b[1][0];
47 a[0][0] = b[1][1] / c;
48 a[0][1] = -b[0][1] / c;
49 a[1][0] = -b[1][0] / c;
50 a[1][1] = b[0][0] / c;
57 return a[0][0] *
a[1][1] -
a[0][1] *
a[1][0];
64 a[0] = sin(b[0]) * cos(b[1]);
65 a[1] = sin(b[0]) * sin(b[1]);
74 a[1] = atan2(b[1], b[0]);
127 (b + log1p(exp(
a - b))) :
128 ((b <
a) ? (
a + log1p(exp(b -
a))) : (
a + log(2)));
138 for (
p = begin;
p !=
end; ++
p)
157 for (
p = begin;
p !=
end; ++
p)
182 int whole = floor(t);
189 h[0] = (1. + 2. * t) * (1. - t) * (1. - t);
190 h[1] = t * (1. - t) * (1. - t);
191 h[2] = t * t * (3. - 2. * t);
192 h[3] = t * t * (t - 1.);
197 w[1] = h[0] - 0.5 * h[3];
198 w[2] = h[2] + 0.5 * h[1];
204 for (i = 0; i != 4; ++i)
206 y +=
x[whole + i - 1] * w[i];
226 for (i = 0; i != plan->
n; ++i)
240 double directions[2],
250 for (j = 0; j != plan->
n; ++j)
288 for (i = 0; i != 2; ++i)
290 for (j = 0; j != 2; ++j)
292 a[i][j] = ((i == j) ? 1.0 : 0.0);
293 for (k = 0; k != plan->
n; ++k)
295 a[i][j] += properties->
f[k][i] * wSw[k] * properties->
f[k][j];
306 for (i = 0; i != plan->
n; ++i)
308 for (j = 0; j != plan->
n; ++j)
310 kernel->
k[i][j] = 0.0;
311 for (k = 0; k != 2; ++k)
313 for (l = 0; l != 2; ++l)
315 kernel->
k[i][j] += properties->
f[i][k] * b[k][l] * properties->
f[j][l];
347 for (i = 0; i != plan->
n; ++i)
349 for (j = 0; j != plan->
n; ++j)
352 for (k = 0; k != 2; ++k)
354 a[i][j] += properties->
f[i][k] * properties->
f[j][k];
356 a[i][j] *= wSw[i] * wSw[j];
364 gsl_matrix_view
m = gsl_matrix_view_array_with_tda(
a[0], plan->
n, plan->
n,
XLALSKYMAP_N);
365 gsl_permutation*
p = gsl_permutation_alloc(plan->
n);
368 gsl_linalg_LU_decomp(&
m.matrix,
p, &s);
370 gsl_matrix_view inverse = gsl_matrix_view_array_with_tda(kernel->
k[0], plan->
n, plan->
n,
XLALSKYMAP_N);
372 gsl_linalg_LU_invert(&
m.matrix,
p, &inverse.matrix);
374 gsl_permutation_free(
p);
378 for (i = 0; i != plan->
n; ++i)
380 for (j = 0; j != plan->
n; ++j)
382 kernel->
k[i][j] = -kernel->
k[i][j];
384 kernel->
k[i][i] += 1. / wSw[i];
390 for (i = 0; i != plan->
n; ++i)
424 for (i = 0; i != plan->
n; ++i)
435 for (i = 0; i != plan->
n; ++i)
437 for (j = 0; j != plan->
n; ++j)
439 a +=
x[i] * kernel->
k[i][j] *
x[j];
static double site_time(LALDetector *site, double direction[3])
void XLALSkymapDirectionPropertiesConstruct(XLALSkymapPlanType *plan, double directions[2], XLALSkymapDirectionPropertiesType *properties)
static void site_response(double f[2], const LALDetector *site, double direction[3])
static double * findmax(double *begin, double *end)
static double det22(double a[2][2])
void XLALSkymapSphericalFromCartesian(double a[2], double b[3])
void XLALSkymapUncertainKernelConstruct(XLALSkymapPlanType *plan, XLALSkymapDirectionPropertiesType *properties, double *wSw, double *error, XLALSkymapKernelType *kernel)
double XLALSkymapLogTotalExp(double *begin, double *end)
double XLALSkymapLogSumExp(double a, double b)
static void inv22(double a[2][2], double b[2][2])
double XLALSkymapInterpolate(double t, double *x)
void XLALSkymapApply(XLALSkymapPlanType *plan, XLALSkymapDirectionPropertiesType *properties, XLALSkymapKernelType *kernel, double **xSw, double tau, double *posterior)
static double logtotalexpwithmax(double *begin, double *end, double m)
static double dot3(double a[3], double b[3])
void XLALSkymapPlanConstruct(int sampleFrequency, int n, int *detectors, XLALSkymapPlanType *plan)
void XLALSkymapKernelConstruct(XLALSkymapPlanType *plan, XLALSkymapDirectionPropertiesType *properties, double *wSw, XLALSkymapKernelType *kernel)
void XLALSkymapCartesianFromSpherical(double a[3], double b[2])
static REAL8TimeSeries * error(const REAL8TimeSeries *s1, const REAL8TimeSeries *s0)
static double f(double theta, double y, double xi)
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
Pre-existing detectors.
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
An implementation of the detector response formulae in Anderson et al PRD 63 042003 (2001) .
#define LAL_C_SI
Speed of light in vacuum, m s^-1.
double f[XLALSKYMAP_N][2]
double delay[XLALSKYMAP_N]
double k[XLALSKYMAP_N][XLALSKYMAP_N]
LALDetector site[XLALSKYMAP_N]