Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALPulsar 7.1.1.1-8a6b96f
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LatticeTilingTest.c
Go to the documentation of this file.
1//
2// Copyright (C) 2014, 2015, 2016 Karl Wette
3//
4// This program is free software; you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation; either version 2 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with with program; see the file COPYING. If not, write to the
16// Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17// MA 02110-1301 USA
18//
19
20// Tests of the lattice-based template generation code in LatticeTiling.[ch].
21
22#include <config.h>
23#include <stdio.h>
24
25#include <lal/LatticeTiling.h>
26#include <lal/LALStdlib.h>
27#include <lal/Factorial.h>
28#include <lal/DopplerFullScan.h>
29#include <lal/SuperskyMetrics.h>
30#include <lal/LALInitBarycenter.h>
31
32#include <lal/GSLHelpers.h>
33
34#if defined(__GNUC__)
35#define UNUSED __attribute__ ((unused))
36#else
37#define UNUSED
38#endif
39
40#define MISM_HIST_BINS 20
41
42// Safely compute absolute different between two unsigned integers
43#define ABSDIFF(x, y) (int)((x) > (y) ? ((x) - (y)) : ((y) - (x)))
44
45// The reference mismatch histograms were generated in Octave
46// using the LatticeMismatchHist() function available in OctApps.
47
49 4.531107, 1.870257, 1.430467, 1.202537, 1.057047, 0.953084, 0.875050, 0.813050, 0.762368, 0.719968,
50 0.683877, 0.652659, 0.625394, 0.601300, 0.579724, 0.560515, 0.542944, 0.527142, 0.512487, 0.499022
51};
52
54 1.570963, 1.571131, 1.571074, 1.571102, 1.570808, 1.570789, 1.570617, 1.570716, 1.570671, 1.570867,
55 1.157132, 0.835785, 0.645424, 0.503305, 0.389690, 0.295014, 0.214022, 0.143584, 0.081427, 0.025878
56};
57
59 0.608404, 1.112392, 1.440652, 1.705502, 1.934785, 2.139464, 2.296868, 2.071379, 1.748278, 1.443955,
60 1.155064, 0.879719, 0.616210, 0.375368, 0.223752, 0.131196, 0.071216, 0.033130, 0.011178, 0.001489
61};
62
63#define A1s_mism_hist Z1_mism_hist
64
66 1.210152, 1.210142, 1.209837, 1.209697, 1.209368, 1.209214, 1.209399, 1.209170, 1.208805, 1.208681,
67 1.208631, 1.208914, 1.208775, 1.209021, 1.208797, 0.816672, 0.505394, 0.315665, 0.170942, 0.052727
68};
69
71 0.327328, 0.598545, 0.774909, 0.917710, 1.040699, 1.150991, 1.250963, 1.344026, 1.431020, 1.512883,
72 1.590473, 1.664510, 1.595423, 1.391209, 1.194340, 1.004085, 0.729054, 0.371869, 0.098727, 0.011236
73};
74
76 0.088295, 0.264916, 0.441209, 0.617937, 0.794537, 0.971005, 1.147715, 1.324035, 1.500356, 1.677569,
77 1.806866, 1.816272, 1.757854, 1.653638, 1.513900, 1.268203, 0.833153, 0.417934, 0.100320, 0.004287
78};
79
81 const LatticeTiling UNUSED *tiling,
82 const UINT8 UNUSED total_ref,
83 const int UNUSED total_tol,
84 const UINT8 UNUSED total_ckpt_0,
85 const UINT8 UNUSED total_ckpt_1,
86 const UINT8 UNUSED total_ckpt_2,
87 const UINT8 UNUSED total_ckpt_3
88)
89{
90
91#if !defined(HAVE_LIBCFITSIO)
92 printf( "Skipping serialisation test (CFITSIO library is not available)\n" );
93#else // defined(HAVE_LIBCFITSIO)
94 printf( "Performing serialisation test ..." );
95
97
98 const UINT8 total_ckpt[4] = {total_ckpt_0, total_ckpt_1, total_ckpt_2, total_ckpt_3};
99
100 // Create lattice tiling iterator
101 LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator( tiling, n );
102 XLAL_CHECK( itr != NULL, XLAL_EFUNC );
104
105 // Count number of points
108 XLAL_CHECK( ABSDIFF( total, total_ref ) <= total_tol, XLAL_EFUNC, "|total - total_ref| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > %i", total, total_ref, total_tol );
109
110 // Get all points
111 gsl_matrix *GAMAT( points, n, total );
115
116 // Iterate over all points again, this time with checkpointing
117 gsl_vector *GAVEC( point, n );
118 size_t k_ckpt = 0;
119 for ( UINT8 k = 0; k < total; ++k ) {
120
121 // Check next point for consistency
122 XLAL_CHECK( XLALNextLatticeTilingPoint( itr, point ) >= 0, XLAL_EFUNC );
123 gsl_vector_const_view points_k_view = gsl_matrix_const_column( points, k );
124 gsl_vector_sub( point, &points_k_view.vector );
125 double err = gsl_blas_dasum( point ) / n;
126 XLAL_CHECK( err < 1e-6, XLAL_EFAILED, "err = %e < 1e-6", err );
127
128 // Checkpoint iterator at certain intervals
129 if ( k_ckpt < XLAL_NUM_ELEM( total_ckpt ) && k + 1 >= total_ckpt[k_ckpt] ) {
130
131 // Save iterator to a FITS file
132 {
133 FITSFile *file = XLALFITSFileOpenWrite( "LatticeTilingTest.fits" );
134 XLAL_CHECK( file != NULL, XLAL_EFUNC );
137 }
138
139 // Destroy and recreate lattice tiling iterator
142 XLAL_CHECK( itr != NULL, XLAL_EFUNC );
144
145 // Restore iterator to a FITS file
146 {
147 FITSFile *file = XLALFITSFileOpenRead( "LatticeTilingTest.fits" );
148 XLAL_CHECK( file != NULL, XLAL_EFUNC );
151 }
152
153 printf( " checkpoint at %" LAL_UINT8_FORMAT "/%" LAL_UINT8_FORMAT " ...", k + 1, total );
154 ++k_ckpt;
155
156 }
157
158 }
160
161 printf( " done\n" );
162
163 // Cleanup
165 GFVEC( point );
166 GFMAT( points );
167
168#endif // !defined(HAVE_LIBCFITSIO)
169
170 return XLAL_SUCCESS;
171
172}
173
174static int BasicTest(
175 const size_t n,
176 const int bound_on_0,
177 const int bound_on_1,
178 const int bound_on_2,
179 const int bound_on_3,
180 const TilingLattice lattice,
181 const UINT8 total_ref_0,
182 const UINT8 total_ref_1,
183 const UINT8 total_ref_2,
184 const UINT8 total_ref_3
185)
186{
187
188 const int total_tol = 1;
189 const double value_tol = 1000 * LAL_REAL8_EPS;
190
191 const int bound_on[4] = {bound_on_0, bound_on_1, bound_on_2, bound_on_3};
192 const UINT8 total_ref[4] = {total_ref_0, total_ref_1, total_ref_2, total_ref_3};
193
194 // Create lattice tiling
195 LatticeTiling *tiling = XLALCreateLatticeTiling( n );
196 XLAL_CHECK( tiling != NULL, XLAL_EFUNC );
197
198 // Add bounds
199 for ( size_t i = 0; i < n; ++i ) {
200 XLAL_CHECK( bound_on[i] == 0 || bound_on[i] == 1, XLAL_EFAILED );
201 XLAL_CHECK( XLALSetLatticeTilingConstantBound( tiling, i, 0.0, bound_on[i] * pow( 100.0, 1.0 / n ) ) == XLAL_SUCCESS, XLAL_EFUNC );
202 }
203
204 // Set metric to the Lehmer matrix
205 const double max_mismatch = 0.3;
206 {
207 gsl_matrix *GAMAT( metric, n, n );
208 for ( size_t i = 0; i < n; ++i ) {
209 for ( size_t j = 0; j < n; ++j ) {
210 const double ii = i + 1, jj = j + 1;
211 gsl_matrix_set( metric, i, j, jj >= ii ? ii / jj : jj / ii );
212 }
213 }
215 GFMAT( metric );
216 printf( "Number of (tiled) dimensions: %zu (%zu)\n", XLALTotalLatticeTilingDimensions( tiling ), XLALTiledLatticeTilingDimensions( tiling ) );
217 printf( " Bounds: %i %i %i %i\n", bound_on_0, bound_on_1, bound_on_2, bound_on_3 );
218 printf( " Lattice type: %i\n", lattice );
219 }
220
221 // Check bounds
222 for ( size_t i = 0; i < n; ++i ) {
223 gsl_vector *GAVEC( point, n ); // Unused for this parameter space, but still needed as input
224 double lower, upper;
225 XLAL_CHECK( XLALGetLatticeTilingBound( tiling, i, point, false, &lower, &upper ) == XLAL_SUCCESS, XLAL_EFUNC );
226 XLAL_CHECK( lower == 0.0, XLAL_EFUNC );
227 XLAL_CHECK( upper == bound_on[i] * pow( 100.0, 1.0 / n ), XLAL_EFUNC );
228 GFVEC( point );
229 }
230
231 // Check tiled status of lattce tiling dimensions
232 for ( size_t i = 0, ti = 0; i < n; ++i ) {
233 const int is_tiled_i = XLALIsTiledLatticeTilingDimension( tiling, i );
234 XLAL_CHECK( is_tiled_i >= 0, XLAL_EFUNC );
235 XLAL_CHECK( !is_tiled_i == !bound_on[i], XLAL_EFAILED, "XLALIsTiledLatticeTilingDimension(tiling, %zu) = %i, should be %i", i, is_tiled_i, bound_on[i] );
236 if ( is_tiled_i ) {
237 const size_t j = XLALLatticeTilingTiledDimension( tiling, ti );
239 XLAL_CHECK( i == j, XLAL_EFAILED, "XLALLatticeTilingTiledDimension( tiling, %zu ) = %zu, should be %zu", ti, j, i );
240 ++ti;
241 }
242 }
243
244 // Create lattice tiling locator
245 LatticeTilingLocator *loc = XLALCreateLatticeTilingLocator( tiling );
246 XLAL_CHECK( loc != NULL, XLAL_EFUNC );
247 if ( lalDebugLevel & LALINFOBIT ) {
248 printf( " Index trie:\n" );
250 }
251
252 for ( size_t i = 0; i < n; ++i ) {
253
254 // Create lattice tiling iterator over 'i+1' dimensions
255 LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator( tiling, i + 1 );
256 XLAL_CHECK( itr != NULL, XLAL_EFUNC );
257
258 // Count number of points
261 printf( "Number of lattice points in %zu dimensions: %" LAL_UINT8_FORMAT " (vs %" LAL_UINT8_FORMAT ", tolerance = %i)\n", i + 1, total, total_ref[i], total_tol );
262 XLAL_CHECK( ABSDIFF( total, total_ref[i] ) <= total_tol, XLAL_EFUNC, "|total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > %i", i, total, total_ref[i], total_tol );
263 for ( UINT8 k = 0; XLALNextLatticeTilingPoint( itr, NULL ) > 0; ++k ) {
264 const UINT8 itr_index = XLALCurrentLatticeTilingIndex( itr );
265 XLAL_CHECK( k == itr_index, XLAL_EFUNC, "k = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT " = itr_index", k, itr_index );
266 }
268
269 // Check tiling statistics
270 printf( " Check tiling statistics ..." );
271 for ( size_t j = 0; j < n; ++j ) {
273 XLAL_CHECK( stats != NULL, XLAL_EFUNC );
274 XLAL_CHECK( stats->name != NULL, XLAL_EFUNC );
275 XLAL_CHECK( ABSDIFF( stats->total_points, total_ref[j] ) <= total_tol, XLAL_EFAILED, "|total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > %i", j, stats->total_points, total_ref[j], total_tol );
276 XLAL_CHECK( stats->min_points <= stats->max_points, XLAL_EFAILED, "min_points = %" LAL_INT4_FORMAT " > %" LAL_INT4_FORMAT " = max_points", stats->min_points, stats->max_points );
277 XLAL_CHECK( stats->min_value <= stats->max_value, XLAL_EFAILED, "min_value = %g > %g = max_value", stats->min_value, stats->max_value );
278 printf( " %s ...", stats->name );
279 }
280 printf( " done\n" );
281
282 // Get all points
283 gsl_matrix *GAMAT( points, n, total );
286 for ( UINT8 k = 0; k < total; ++k ) {
287 gsl_vector_const_view point_view = gsl_matrix_const_column( points, k );
288 const gsl_vector *point = &point_view.vector;
289 for ( size_t j = 0; j < n; ++j ) {
290 const double point_j = gsl_vector_get( point, j );
292 XLAL_CHECK( point_j >= stats->min_value - value_tol, XLAL_EFAILED, "point_j = %.10g < %.10g = stats[%zu]->min_value", point_j, stats->min_value, j );
293 XLAL_CHECK( point_j <= stats->max_value + value_tol, XLAL_EFAILED, "point_j = %.10g > %.10g = stats[%zu]->max_value", point_j, stats->max_value, j );
294 }
295 }
296
297 // Get nearest points to each template, check for consistency
298 printf( " Testing XLALNearestLatticeTiling{Point|Block}() ..." );
299 gsl_vector *GAVEC( nearest, n );
300 UINT8Vector *nearest_indexes = XLALCreateUINT8Vector( n );
301 XLAL_CHECK( nearest_indexes != NULL, XLAL_ENOMEM );
302 for ( UINT8 k = 0; k < total; ++k ) {
303 gsl_vector_const_view point_view = gsl_matrix_const_column( points, k );
304 const gsl_vector *point = &point_view.vector;
305 XLAL_CHECK( XLALNearestLatticeTilingPoint( loc, point, nearest, nearest_indexes ) == XLAL_SUCCESS, XLAL_EFUNC );
306 for ( size_t j = 0; j < n; ++j ) {
307 const double nearest_j = gsl_vector_get( nearest, j );
309 XLAL_CHECK( nearest_j >= stats->min_value - value_tol, XLAL_EFAILED, "nearest_j = %.10g < %.10g = stats[%zu]->min_value", nearest_j, stats->min_value, j );
310 XLAL_CHECK( nearest_j <= stats->max_value + value_tol, XLAL_EFAILED, "nearest_j = %.10g > %.10g = stats[%zu]->max_value", nearest_j, stats->max_value, j );
311 }
312 gsl_vector_sub( nearest, point );
313 double err = gsl_blas_dasum( nearest ) / n;
314 XLAL_CHECK( err < 1e-6, XLAL_EFAILED, "err = %e < 1e-6", err );
315 XLAL_CHECK( nearest_indexes->data[i] == k, XLAL_EFAILED, "nearest_indexes[%zu] = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", i, nearest_indexes->data[i], k );
316 if ( 0 < i ) {
319 INT4 nearest_left = 0, nearest_right = 0;
320 XLAL_CHECK( XLALNearestLatticeTilingBlock( loc, point, i, nearest, &nearest_index, &nearest_left, &nearest_right ) == XLAL_SUCCESS, XLAL_EFUNC );
321 XLAL_CHECK( nearest_index == nearest_indexes->data[i - 1], XLAL_EFAILED, "nearest_index = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", nearest_index, nearest_indexes->data[i - 1] );
322 XLAL_CHECK( nearest_left <= nearest_right, XLAL_EFAILED, "invalid [nearest_left, nearest_right] = [%i, %i]\n", nearest_left, nearest_right );
323 UINT4 nearest_len = nearest_right - nearest_left + 1;
324 XLAL_CHECK( nearest_len <= stats->max_points, XLAL_EFAILED, "nearest_len = %i > %i = stats[%zu]->max_points\n", nearest_len, stats->max_points, i );
325 }
326 if ( i + 1 < n ) {
329 INT4 nearest_left = 0, nearest_right = 0;
330 XLAL_CHECK( XLALNearestLatticeTilingBlock( loc, point, i + 1, nearest, &nearest_index, &nearest_left, &nearest_right ) == XLAL_SUCCESS, XLAL_EFUNC );
331 XLAL_CHECK( nearest_index == nearest_indexes->data[i], XLAL_EFAILED, "nearest_index = %" LAL_UINT8_FORMAT " != %" LAL_UINT8_FORMAT "\n", nearest_index, nearest_indexes->data[i] );
332 XLAL_CHECK( nearest_left <= nearest_right, XLAL_EFAILED, "invalid [nearest_left, nearest_right] = [%i, %i]\n", nearest_left, nearest_right );
333 UINT4 nearest_len = nearest_right - nearest_left + 1;
334 XLAL_CHECK( nearest_len <= stats->max_points, XLAL_EFAILED, "nearest_len = %i > %i = stats[%zu]->max_points\n", nearest_len, stats->max_points, i + 1 );
335 }
336 }
337 printf( " done\n" );
338
339 // Cleanup
341 GFMAT( points );
342 GFVEC( nearest );
343 XLALDestroyUINT8Vector( nearest_indexes );
344
345 // Create alternating lattice tiling iterator over 'i+1' dimensions
346 printf( " Testing XLALSetLatticeTilingAlternatingIterator() ..." );
347 LatticeTilingIterator *itr_alt = XLALCreateLatticeTilingIterator( tiling, i + 1 );
348 XLAL_CHECK( itr_alt != NULL, XLAL_EFUNC );
350
351 // Count number of points, check for consistency with non-alternating count
352 UINT8 total_alt = 0;
353 while ( XLALNextLatticeTilingPoint( itr_alt, NULL ) > 0 ) {
354 ++total_alt;
355 }
356 XLAL_CHECK( ABSDIFF( total_alt, total_ref[i] ) <= total_tol, XLAL_EFUNC, "alternating |total - total_ref[%zu]| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > %i", i, total_alt, total_ref[i], total_tol );
357 printf( " done\n" );
358
359 // Cleanup
361
362 }
363
364 // Perform serialisation test
365 XLAL_CHECK( SerialisationTest( tiling, total_ref[n - 1], total_tol, total_ref_0, total_ref_1, total_ref_2, total_ref_3 ) == XLAL_SUCCESS, XLAL_EFUNC );
366
367 // Cleanup
371 printf( "\n" );
372
373 return XLAL_SUCCESS;
374
375}
376
377static int MismatchTest(
378 const LatticeTiling *tiling,
379 const gsl_matrix *metric,
380 const double max_mismatch,
381 const double injs_per_point,
382 const double mism_hist_error_tol,
383 const double mism_out_of_range_tol,
384 const UINT8 total_ref,
385 const int total_tol,
386 const double mism_hist_ref[MISM_HIST_BINS]
387)
388{
389
390 const size_t n = XLALTotalLatticeTilingDimensions( tiling );
391
392 // Create lattice tiling iterator and locator
393 LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator( tiling, n );
394 XLAL_CHECK( itr != NULL, XLAL_EFUNC );
395 LatticeTilingLocator *loc = XLALCreateLatticeTilingLocator( tiling );
396 XLAL_CHECK( loc != NULL, XLAL_EFUNC );
397
398 // Count number of points
401 printf( "Number of lattice points: %" LAL_UINT8_FORMAT " (vs %" LAL_UINT8_FORMAT ", tolerance = %i)\n", total, total_ref, total_tol );
402 XLAL_CHECK( ABSDIFF( total, total_ref ) <= total_tol, XLAL_EFUNC, "|total - total_ref| = |%" LAL_UINT8_FORMAT " - %" LAL_UINT8_FORMAT "| > %i", total, total_ref, total_tol );
403
404 // Initialise mismatch histogram counts
405 double mism_hist[MISM_HIST_BINS] = {0};
406 double mism_hist_total = 0, mism_hist_out_of_range = 0;
407
408 // Perform 'injs_per_point' injections for every template
409 printf( "Injections per point: %g\n", injs_per_point );
410 {
411 UINT8 total_injs = llround( total * injs_per_point );
412 const size_t max_injs_per_batch = 100000;
413
414 // Allocate memory
415 gsl_matrix *GAMAT( max_injections, n, max_injs_per_batch );
416 gsl_matrix *max_nearest = NULL;
417 gsl_matrix *GAMAT( max_temp, n, max_injs_per_batch );
418
419 // Allocate random number generator
421 XLAL_CHECK( rng != NULL, XLAL_EFUNC );
422
423 while ( total_injs > 0 ) {
424 const size_t injs_per_batch = GSL_MIN( max_injs_per_batch, total_injs );
425 total_injs -= injs_per_batch;
426 printf( " Injections remaining: %" LAL_UINT8_FORMAT "...\n", total_injs );
427
428 // Create matrix views
429 gsl_matrix_view injections_view = gsl_matrix_submatrix( max_injections, 0, 0, n, injs_per_batch );
430 gsl_matrix *const injections = &injections_view.matrix;
431 gsl_matrix_view temp_view = gsl_matrix_submatrix( max_temp, 0, 0, n, injs_per_batch );
432 gsl_matrix *const temp = &temp_view.matrix;
433
434 // Generate random injection points
436
437 // Find nearest lattice template points
439 gsl_matrix_view nearest_view = gsl_matrix_submatrix( max_nearest, 0, 0, n, injs_per_batch );
440 gsl_matrix *const nearest = &nearest_view.matrix;
441
442 // Compute mismatch between injections
443 gsl_matrix_sub( nearest, injections );
444 gsl_blas_dsymm( CblasLeft, CblasUpper, 1.0, metric, nearest, 0.0, temp );
445 for ( size_t j = 0; j < temp->size2; ++j ) {
446 gsl_vector_view temp_j = gsl_matrix_column( temp, j );
447 gsl_vector_view nearest_j = gsl_matrix_column( nearest, j );
448 double mismatch = 0.0;
449 gsl_blas_ddot( &nearest_j.vector, &temp_j.vector, &mismatch );
450 mismatch /= max_mismatch;
451
452 // Increment mismatch histogram counts
453 ++mism_hist_total;
454 if ( mismatch < 0.0 || mismatch > 1.0 ) {
455 ++mism_hist_out_of_range;
456 } else {
457 ++mism_hist[lround( floor( mismatch * MISM_HIST_BINS ) )];
458 }
459
460 }
461
462 }
463
464 // Cleanup
466 GFMAT( max_injections, max_nearest, max_temp );
467
468 }
469
470 // Normalise histogram
471 for ( size_t i = 0; i < MISM_HIST_BINS; ++i ) {
472 mism_hist[i] *= MISM_HIST_BINS / mism_hist_total;
473 }
474
475 // Print mismatch histogram and its reference
476 printf( "Mismatch histogram: " );
477 for ( size_t i = 0; i < MISM_HIST_BINS; ++i ) {
478 printf( " %0.3f", mism_hist[i] );
479 }
480 printf( "\n" );
481 printf( "Reference histogram:" );
482 for ( size_t i = 0; i < MISM_HIST_BINS; ++i ) {
483 printf( " %0.3f", mism_hist_ref[i] );
484 }
485 printf( "\n" );
486
487 // Determine error between mismatch histogram and its reference
488 double mism_hist_error = 0.0;
489 for ( size_t i = 0; i < MISM_HIST_BINS; ++i ) {
490 mism_hist_error += fabs( mism_hist[i] - mism_hist_ref[i] );
491 }
492 mism_hist_error /= MISM_HIST_BINS;
493 printf( "Mismatch histogram error: %0.3e (tolerance %0.3e)\n", mism_hist_error, mism_hist_error_tol );
494 if ( mism_hist_error >= mism_hist_error_tol ) {
495 XLAL_ERROR( XLAL_EFAILED, "mismatch histogram error exceeds tolerance\n" );
496 }
497
498 // Check fraction of injections out of histogram range
499 const double mism_out_of_range = mism_hist_out_of_range / mism_hist_total;
500 printf( "Fraction of points out of histogram range: %0.3e (tolerance %0.3e)\n", mism_out_of_range, mism_out_of_range_tol );
501 if ( mism_out_of_range > mism_out_of_range_tol ) {
502 XLAL_ERROR( XLAL_EFAILED, "fraction of points out of histogram range exceeds tolerance\n" );
503 }
504
505 // Perform 10 injections outside parameter space
506 {
507 gsl_matrix *GAMAT( injections, n, 10 );
508 gsl_matrix *GAMAT( nearest, n, 10 );
510 XLAL_CHECK( rng != NULL, XLAL_EFUNC );
511
512 // Generate random injection points outside parameter space
514
515 // Find nearest lattice template points
517
518 // Cleanup
519 GFMAT( injections, nearest );
521 }
522
523 // Cleanup
526
527 return XLAL_SUCCESS;
528
529}
530
532 const TilingLattice lattice,
533 const double freqband,
534 const double f1dotband,
535 const double f2dotband,
536 const UINT8 total_ref,
537 const double mism_hist_ref[MISM_HIST_BINS]
538)
539{
540
541 const int total_tol = 1;
542
543 // Create lattice tiling
544 LatticeTiling *tiling = XLALCreateLatticeTiling( 3 );
545 XLAL_CHECK( tiling != NULL, XLAL_EFUNC );
546
547 // Add bounds
548 const double fndot[3] = {100, 0, 0};
549 const double fndotband[3] = {freqband, f1dotband, f2dotband};
550 for ( size_t i = 0; i < 3; ++i ) {
551 printf( "Bounds: f%zudot=%0.3g, f%zudotband=%0.3g\n", i, fndot[i], i, fndotband[i] );
552 XLAL_CHECK( XLALSetLatticeTilingConstantBound( tiling, i, fndot[i], fndot[i] + fndotband[i] ) == XLAL_SUCCESS, XLAL_EFUNC );
553 }
554
555 // Set metric to the spindown metric
556 const double max_mismatch = 0.3;
557 gsl_matrix *GAMAT( metric, 3, 3 );
558 for ( size_t i = 0; i < metric->size1; ++i ) {
559 for ( size_t j = i; j < metric->size2; ++j ) {
560 const double Tspan = 432000;
561 const double metric_i_j_num = 4.0 * LAL_PI * LAL_PI * pow( Tspan, i + j + 2 ) * ( i + 1 ) * ( j + 1 );
562 const double metric_i_j_denom = LAL_FACT[i + 1] * LAL_FACT[j + 1] * ( i + 2 ) * ( j + 2 ) * ( i + j + 3 );
563 gsl_matrix_set( metric, i, j, metric_i_j_num / metric_i_j_denom );
564 gsl_matrix_set( metric, j, i, gsl_matrix_get( metric, i, j ) );
565 }
566 }
567 printf( "Lattice type: %i\n", lattice );
569
570 // Perform mismatch test
571 XLAL_CHECK( MismatchTest( tiling, metric, max_mismatch, 10, 5e-2, 2e-3, total_ref, total_tol, mism_hist_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
572
573 // Perform serialisation test
574 XLAL_CHECK( SerialisationTest( tiling, total_ref, total_tol, 1, 0.2 * total_ref, 0.6 * total_ref, 0.9 * total_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
575
576 // Cleanup
578 GFMAT( metric );
580 printf( "\n" );
581
582 return XLAL_SUCCESS;
583
584}
585
587 const TilingLattice lattice,
588 const double freq,
589 const double freqband,
590 const UINT8 total_ref,
591 const double mism_hist_ref[MISM_HIST_BINS]
592)
593{
594
595 const int total_tol = 1;
596
597 // Create lattice tiling
598 LatticeTiling *tiling = XLALCreateLatticeTiling( 3 );
599 XLAL_CHECK( tiling != NULL, XLAL_EFUNC );
600
601 // Add bounds
602 printf( "Bounds: freq=%0.3g, freqband=%0.3g\n", freq, freqband );
606
607 // Set metric to the spindown metric
608 const double max_mismatch = 0.3;
609 gsl_matrix *GAMAT( metric, 3, 3 );
610 for ( size_t i = 0; i < metric->size1; ++i ) {
611 for ( size_t j = i; j < metric->size2; ++j ) {
612 const double Tspan = 1036800;
613 const double metric_i_j_num = 4.0 * LAL_PI * LAL_PI * pow( Tspan, i + j + 2 ) * ( i + 1 ) * ( j + 1 );
614 const double metric_i_j_denom = LAL_FACT[i + 1] * LAL_FACT[j + 1] * ( i + 2 ) * ( j + 2 ) * ( i + j + 3 );
615 gsl_matrix_set( metric, i, j, metric_i_j_num / metric_i_j_denom );
616 gsl_matrix_set( metric, j, i, gsl_matrix_get( metric, i, j ) );
617 }
618 }
619 printf( "Lattice type: %i\n", lattice );
621
622 // Perform mismatch test
623 XLAL_CHECK( MismatchTest( tiling, metric, max_mismatch, 10, 5e-2, 2e-3, total_ref, total_tol, mism_hist_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
624
625 // Perform serialisation test
626 XLAL_CHECK( SerialisationTest( tiling, total_ref, total_tol, 1, 0.2 * total_ref, 0.6 * total_ref, 0.9 * total_ref ) == XLAL_SUCCESS, XLAL_EFUNC );
627
628 // Cleanup
630 GFMAT( metric );
632 printf( "\n" );
633
634 return XLAL_SUCCESS;
635
636}
637
638static int SuperskyTests(
639 const UINT8 coh_total_ref_0,
640 const UINT8 coh_total_ref_1,
641 const UINT8 coh_total_ref_2,
642 const UINT8 semi_total_ref
643)
644{
645
646 const UINT8 coh_total_ref[3] = {coh_total_ref_0, coh_total_ref_1, coh_total_ref_2};
647
648 printf( "Performing super-sky metric tests ...\n\n" );
649
650 // Compute reduced supersky metrics
651 const double Tspan = 90000;
652 LIGOTimeGPS ref_time;
653 XLALGPSSetREAL8( &ref_time, 900100100 );
654 LALSegList segments;
655 {
657 LALSeg segment;
658 {
659 LIGOTimeGPS start_time = ref_time, end_time = ref_time;
660 XLALGPSAdd( &start_time, -100 * Tspan );
661 XLALGPSAdd( &end_time, -98 * Tspan );
662 XLAL_CHECK( XLALSegSet( &segment, &start_time, &end_time, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
663 XLAL_CHECK( XLALSegListAppend( &segments, &segment ) == XLAL_SUCCESS, XLAL_EFUNC );
664 }
665 {
666 LIGOTimeGPS start_time = ref_time, end_time = ref_time;
667 XLALGPSAdd( &start_time, -0.5 * Tspan );
668 XLALGPSAdd( &end_time, 0.5 * Tspan );
669 XLAL_CHECK( XLALSegSet( &segment, &start_time, &end_time, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
670 XLAL_CHECK( XLALSegListAppend( &segments, &segment ) == XLAL_SUCCESS, XLAL_EFUNC );
671 }
672 {
673 LIGOTimeGPS start_time = ref_time, end_time = ref_time;
674 XLALGPSAdd( &start_time, 92.5 * Tspan );
675 XLALGPSAdd( &end_time, 93.5 * Tspan );
676 XLAL_CHECK( XLALSegSet( &segment, &start_time, &end_time, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
677 XLAL_CHECK( XLALSegListAppend( &segments, &segment ) == XLAL_SUCCESS, XLAL_EFUNC );
678 }
679 XLAL_CHECK( segments.length == XLAL_NUM_ELEM( coh_total_ref ), XLAL_EFAILED );
680 }
682 .length = 1,
684 };
685 EphemerisData *edat = XLALInitBarycenter( TEST_PKG_DATA_DIR "earth00-40-DE405.dat.gz",
686 TEST_PKG_DATA_DIR "sun00-40-DE405.dat.gz" );
687 XLAL_CHECK( edat != NULL, XLAL_EFUNC );
688 const double freq_max = 40.0;
690 XLAL_CHECK( metrics != NULL, XLAL_EFUNC );
691 XLAL_CHECK( metrics->num_segments == segments.length, XLAL_EFAILED );
692
693 // Project and rescale semicoherent metric to give equal frequency spacings
694 const double coh_max_mismatch = 1.4, semi_max_mismatch = 4.9;
695 XLAL_CHECK( XLALEqualizeReducedSuperskyMetricsFreqSpacing( metrics, coh_max_mismatch, semi_max_mismatch ) == XLAL_SUCCESS, XLAL_EFUNC );
696
697 // Create lattice tilings
698 LatticeTiling *coh_tiling[metrics->num_segments];
699 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
700 coh_tiling[n] = XLALCreateLatticeTiling( 4 );
701 XLAL_CHECK( coh_tiling[n] != NULL, XLAL_EFUNC );
702 }
703 LatticeTiling *semi_tiling = XLALCreateLatticeTiling( 4 );
704 XLAL_CHECK( semi_tiling != NULL, XLAL_EFUNC );
705
706 // Add bounds
707 const double alpha1 = 0, alpha2 = LAL_PI, delta1 = -LAL_PI_2, delta2 = LAL_PI_2;
708 const double freq_min = freq_max - 0.05, f1dot = -3e-9;
709 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
710 XLAL_CHECK( XLALSetSuperskyPhysicalSkyBounds( coh_tiling[n], metrics->coh_rssky_metric[n], metrics->coh_rssky_transf[n], alpha1, alpha2, delta1, delta2 ) == XLAL_SUCCESS, XLAL_EFUNC );
713 }
714 XLAL_CHECK( XLALSetSuperskyPhysicalSkyBounds( semi_tiling, metrics->semi_rssky_metric, metrics->semi_rssky_transf, alpha1, alpha2, delta1, delta2 ) == XLAL_SUCCESS, XLAL_EFUNC );
717
718 // Set metric
719 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
721 }
723
724 // Check lattice step sizes in frequency
725 const size_t ifreq = 3;
726 const double semi_dfreq = XLALLatticeTilingStepSize( semi_tiling, ifreq );
727 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
728 const double coh_dfreq = XLALLatticeTilingStepSize( coh_tiling[n], ifreq );
729 const double tol = 1e-8;
730 XLAL_CHECK( fabs( coh_dfreq - semi_dfreq ) < tol * semi_dfreq, XLAL_EFAILED, "semi_dfreq=%0.15e, coh_dfreq[%zu]=%0.15e, |coh_dfreq - semi_dfreq| >= %0.5g * semi_dfreq", semi_dfreq, n, coh_dfreq, tol );
731 }
732
733 // Print information on bounds
734 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
735 for ( size_t i = 0; i < XLALTotalLatticeTilingDimensions( coh_tiling[n] ); ++i ) {
736 const LatticeTilingStats *stats = XLALLatticeTilingStatistics( coh_tiling[n], i );
737 XLAL_CHECK( stats != NULL, XLAL_EFUNC );
738 XLAL_CHECK( stats->name != NULL, XLAL_EFUNC );
739 const int j = XLALLatticeTilingDimensionByName( coh_tiling[n], stats->name );
740 XLAL_CHECK( j == ( int )i, XLAL_EFUNC, "XLALLatticeTilingDimensionByName(..., \"%s\") = %i != %zu", stats->name, j, i );
741 printf( "Coherent #%zu bound #%zu: name=%6s, points=[%4u,%4u]\n", n, i, stats->name, stats->min_points, stats->max_points );
742 }
743 }
744 for ( size_t i = 0; i < XLALTotalLatticeTilingDimensions( semi_tiling ); ++i ) {
745 const LatticeTilingStats *stats = XLALLatticeTilingStatistics( semi_tiling, i );
746 XLAL_CHECK( stats != NULL, XLAL_EFUNC );
747 XLAL_CHECK( stats->name != NULL, XLAL_EFUNC );
748 const int j = XLALLatticeTilingDimensionByName( semi_tiling, stats->name );
749 XLAL_CHECK( j == ( int )i, XLAL_EFUNC, "XLALLatticeTilingDimensionByName(..., \"%s\") = %i != %zu", stats->name, j, i );
750 printf( "Semicoherent bound #%zu: name=%6s, points=[%4u,%4u]\n", i, stats->name, stats->min_points, stats->max_points );
751 }
752 printf( "\n" );
753
754 // Perform mismatch test of coherent and semicoherent tilings
755 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
756 printf( "Coherent #%zu mismatch tests:\n", n );
757 XLAL_CHECK( MismatchTest( coh_tiling[n], metrics->coh_rssky_metric[n], coh_max_mismatch, 0.1, 5e-2, 5e-2, coh_total_ref[n], lround( 1e-5 * coh_total_ref[n] ), A4s_mism_hist ) == XLAL_SUCCESS, XLAL_EFUNC );
758 printf( "\n" );
759 }
760 printf( "Semicoherent mismatch tests:\n" );
761 XLAL_CHECK( MismatchTest( semi_tiling, metrics->semi_rssky_metric, semi_max_mismatch, 0.0001, 5e-2, 5e-2, semi_total_ref, lround( 1e-6 * semi_total_ref ), A4s_mism_hist ) == XLAL_SUCCESS, XLAL_EFUNC );
762 printf( "\n" );
763
764 // Cleanup
765 for ( size_t n = 0; n < metrics->num_segments; ++n ) {
766 XLALDestroyLatticeTiling( coh_tiling[n] );
767 }
768 XLALDestroyLatticeTiling( semi_tiling );
770 XLALSegListClear( &segments );
773
774 printf( "Finished super-sky metric tests\n\n" );
775
776 return XLAL_SUCCESS;
777
778}
779
780static double LinearBound(
781 const void *data,
782 const size_t dim,
783 const gsl_matrix *cache UNUSED,
784 const gsl_vector *point
785)
786{
787
788 // Get bounds data
789 const double *c_m = ( const double * ) data;
790 const double c = c_m[0];
791 const double m = c_m[1];
792
793 // Return bound
794 const double x = gsl_vector_get( point, dim - 1 );
795 return m * x + c;
796
797}
798
800 const double y_range
801)
802{
803
804 // Create lattice tiling
805 LatticeTiling *tiling = XLALCreateLatticeTiling( 2 );
806 XLAL_CHECK( tiling != NULL, XLAL_EFUNC );
807
808 // Add bounds with strict padding
811 {
812 const double c_m_lower[] = { -y_range, 5.0 };
813 const double c_m_upper[] = { +y_range, 5.0 };
814 XLAL_CHECK( XLALSetLatticeTilingBound( tiling, 1, LinearBound, sizeof( c_m_lower ), c_m_lower, c_m_upper ) == XLAL_SUCCESS, XLAL_EFUNC );
816 }
817
818 // Set metric to the Lehmer matrix
819 const double max_mismatch = 0.3;
820 {
821 gsl_matrix *GAMAT( metric, 2, 2 );
822 for ( size_t i = 0; i < 2; ++i ) {
823 for ( size_t j = 0; j < 2; ++j ) {
824 const double ii = i + 1, jj = j + 1;
825 gsl_matrix_set( metric, i, j, jj >= ii ? ii / jj : jj / ii );
826 }
827 }
829 GFMAT( metric );
830 }
831
832 // Create lattice tiling iterator
833 LatticeTilingIterator *itr = XLALCreateLatticeTilingIterator( tiling, 2 );
834
835 // Check that all points are strictly within boundaries
836 {
837 gsl_vector *GAVEC( point, 2 );
838 while ( XLALNextLatticeTilingPoint( itr, point ) > 0 ) {
839 const double x = gsl_vector_get( point, 0 );
840 const double y = gsl_vector_get( point, 1 );
841 XLAL_CHECK( -1.0 <= x && x <= 1.0, XLAL_EFAILED, "x=%0.5g is not in strict boundaries [-1, 1]", x );
842 const double y_min = 5.0 * x - y_range;
843 const double y_max = 5.0 * x + y_range;
844 XLAL_CHECK( y_min <= y && y <= y_max, XLAL_EFAILED, "y=%0.5g is not within strict boundaries [%0.5g, %0.5g]", y, y_min, y_max );
845 }
846 GFVEC( point );
847 }
848
849 // Cleanup
852
853 return XLAL_SUCCESS;
854
855}
856
857int main( void )
858{
859
860 // Turn off buffering to sync standard output and error printing
861 setvbuf( stdout, NULL, _IONBF, 0 );
862 setvbuf( stderr, NULL, _IONBF, 0 );
863
864 // Perform basic tests
865 XLAL_CHECK_MAIN( BasicTest( 1, 0, 0, 0, 0, TILING_LATTICE_CUBIC, 1, 1, 1, 1 ) == XLAL_SUCCESS, XLAL_EFUNC );
866 XLAL_CHECK_MAIN( BasicTest( 1, 1, 1, 1, 1, TILING_LATTICE_ANSTAR, 93, 0, 0, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
867 XLAL_CHECK_MAIN( BasicTest( 1, 1, 1, 1, 1, TILING_LATTICE_CUBIC, 93, 0, 0, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
868 XLAL_CHECK_MAIN( BasicTest( 2, 0, 0, 0, 0, TILING_LATTICE_ANSTAR, 1, 1, 1, 1 ) == XLAL_SUCCESS, XLAL_EFUNC );
869 XLAL_CHECK_MAIN( BasicTest( 2, 1, 1, 1, 1, TILING_LATTICE_ANSTAR, 12, 144, 0, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
870 XLAL_CHECK_MAIN( BasicTest( 2, 1, 1, 1, 1, TILING_LATTICE_CUBIC, 13, 190, 0, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
871 XLAL_CHECK_MAIN( BasicTest( 3, 0, 0, 0, 0, TILING_LATTICE_CUBIC, 1, 1, 1, 1 ) == XLAL_SUCCESS, XLAL_EFUNC );
872 XLAL_CHECK_MAIN( BasicTest( 3, 1, 1, 1, 1, TILING_LATTICE_ANSTAR, 8, 46, 332, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
873 XLAL_CHECK_MAIN( BasicTest( 3, 1, 1, 1, 1, TILING_LATTICE_CUBIC, 8, 60, 583, 0 ) == XLAL_SUCCESS, XLAL_EFUNC );
874 XLAL_CHECK_MAIN( BasicTest( 4, 0, 0, 0, 0, TILING_LATTICE_ANSTAR, 1, 1, 1, 1 ) == XLAL_SUCCESS, XLAL_EFUNC );
875 XLAL_CHECK_MAIN( BasicTest( 4, 0, 0, 0, 1, TILING_LATTICE_ANSTAR, 1, 1, 1, 4 ) == XLAL_SUCCESS, XLAL_EFUNC );
876 XLAL_CHECK_MAIN( BasicTest( 4, 0, 0, 1, 0, TILING_LATTICE_ANSTAR, 1, 1, 4, 4 ) == XLAL_SUCCESS, XLAL_EFUNC );
877 XLAL_CHECK_MAIN( BasicTest( 4, 0, 0, 1, 1, TILING_LATTICE_ANSTAR, 1, 1, 4, 20 ) == XLAL_SUCCESS, XLAL_EFUNC );
878 XLAL_CHECK_MAIN( BasicTest( 4, 0, 1, 0, 0, TILING_LATTICE_ANSTAR, 1, 4, 4, 4 ) == XLAL_SUCCESS, XLAL_EFUNC );
879 XLAL_CHECK_MAIN( BasicTest( 4, 0, 1, 0, 1, TILING_LATTICE_ANSTAR, 1, 5, 5, 25 ) == XLAL_SUCCESS, XLAL_EFUNC );
880 XLAL_CHECK_MAIN( BasicTest( 4, 0, 1, 1, 0, TILING_LATTICE_ANSTAR, 1, 5, 24, 24 ) == XLAL_SUCCESS, XLAL_EFUNC );
881 XLAL_CHECK_MAIN( BasicTest( 4, 0, 1, 1, 1, TILING_LATTICE_ANSTAR, 1, 5, 20, 115 ) == XLAL_SUCCESS, XLAL_EFUNC );
882 XLAL_CHECK_MAIN( BasicTest( 4, 1, 0, 0, 0, TILING_LATTICE_ANSTAR, 4, 4, 4, 4 ) == XLAL_SUCCESS, XLAL_EFUNC );
883 XLAL_CHECK_MAIN( BasicTest( 4, 1, 0, 0, 1, TILING_LATTICE_ANSTAR, 5, 5, 5, 23 ) == XLAL_SUCCESS, XLAL_EFUNC );
884 XLAL_CHECK_MAIN( BasicTest( 4, 1, 0, 1, 0, TILING_LATTICE_ANSTAR, 5, 5, 23, 23 ) == XLAL_SUCCESS, XLAL_EFUNC );
885 XLAL_CHECK_MAIN( BasicTest( 4, 1, 0, 1, 1, TILING_LATTICE_ANSTAR, 6, 6, 24, 139 ) == XLAL_SUCCESS, XLAL_EFUNC );
886 XLAL_CHECK_MAIN( BasicTest( 4, 1, 1, 0, 0, TILING_LATTICE_ANSTAR, 5, 25, 25, 25 ) == XLAL_SUCCESS, XLAL_EFUNC );
887 XLAL_CHECK_MAIN( BasicTest( 4, 1, 1, 0, 1, TILING_LATTICE_ANSTAR, 6, 30, 30, 162 ) == XLAL_SUCCESS, XLAL_EFUNC );
888 XLAL_CHECK_MAIN( BasicTest( 4, 1, 1, 1, 0, TILING_LATTICE_ANSTAR, 6, 27, 151, 151 ) == XLAL_SUCCESS, XLAL_EFUNC );
889 XLAL_CHECK_MAIN( BasicTest( 4, 1, 1, 1, 1, TILING_LATTICE_ANSTAR, 6, 30, 145, 897 ) == XLAL_SUCCESS, XLAL_EFUNC );
890 XLAL_CHECK_MAIN( BasicTest( 4, 1, 1, 1, 1, TILING_LATTICE_CUBIC, 7, 46, 287, 2543 ) == XLAL_SUCCESS, XLAL_EFUNC );
891
892 // Perform mismatch tests with a square parameter space
899
900 // Perform mismatch tests with an age--braking index parameter space
904
905 // Perform a variety of tests with the reduced supersky parameter space and metric
906 XLAL_CHECK_MAIN( SuperskyTests( 6886488, 1050134, 932765, 26063227993 ) == XLAL_SUCCESS, XLAL_EFUNC );
907
908 // Perform test to check latting tiling with strict boundary flags
909 for ( double y_range = 0.5; y_range < 2.005; y_range += 0.1 ) {
910 printf( "Strict boundary tests, y_range=%g\n", y_range );
912 }
913 printf( "\n" );
914
915 return EXIT_SUCCESS;
916
917}
918
919// Local Variables:
920// c-file-style: "linux"
921// c-basic-offset: 2
922// End:
int XLALSetLatticeTilingF2DotBrakingBound(LatticeTiling *tiling, const size_t freq_dimension, const size_t f1dot_dimension, const size_t f2dot_dimension, const double min_braking, const double max_braking)
Set a second spindown bound derived from braking indices.
int XLALSetLatticeTilingF1DotAgeBrakingBound(LatticeTiling *tiling, const size_t freq_dimension, const size_t f1dot_dimension, const double age, const double min_braking, const double max_braking)
Set a first spindown bound derived from spindown age and braking indices.
FITSFile * XLALFITSFileOpenWrite(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:263
FITSFile * XLALFITSFileOpenRead(const CHAR UNUSED *file_name)
Definition: FITSFileIO.c:320
void XLALFITSFileClose(FITSFile UNUSED *file)
Definition: FITSFileIO.c:245
REAL8 freq_min
REAL8 freq_max
int j
int k
void LALCheckMemoryLeaks(void)
#define c
static int MismatchSquareTest(const TilingLattice lattice, const double freqband, const double f1dotband, const double f2dotband, const UINT8 total_ref, const double mism_hist_ref[MISM_HIST_BINS])
static int MismatchTest(const LatticeTiling *tiling, const gsl_matrix *metric, const double max_mismatch, const double injs_per_point, const double mism_hist_error_tol, const double mism_out_of_range_tol, const UINT8 total_ref, const int total_tol, const double mism_hist_ref[MISM_HIST_BINS])
const double Z2_mism_hist[MISM_HIST_BINS]
const double Z3_mism_hist[MISM_HIST_BINS]
static double LinearBound(const void *data, const size_t dim, const gsl_matrix *cache UNUSED, const gsl_vector *point)
static int SerialisationTest(const LatticeTiling UNUSED *tiling, const UINT8 UNUSED total_ref, const int UNUSED total_tol, const UINT8 UNUSED total_ckpt_0, const UINT8 UNUSED total_ckpt_1, const UINT8 UNUSED total_ckpt_2, const UINT8 UNUSED total_ckpt_3)
const double A2s_mism_hist[MISM_HIST_BINS]
#define MISM_HIST_BINS
const double A4s_mism_hist[MISM_HIST_BINS]
const double Z1_mism_hist[MISM_HIST_BINS]
int main(void)
static int SuperskyTests(const UINT8 coh_total_ref_0, const UINT8 coh_total_ref_1, const UINT8 coh_total_ref_2, const UINT8 semi_total_ref)
static int MismatchAgeBrakeTest(const TilingLattice lattice, const double freq, const double freqband, const UINT8 total_ref, const double mism_hist_ref[MISM_HIST_BINS])
#define A1s_mism_hist
static int StrictBoundaryTest(const double y_range)
const double A3s_mism_hist[MISM_HIST_BINS]
static int BasicTest(const size_t n, const int bound_on_0, const int bound_on_1, const int bound_on_2, const int bound_on_3, const TilingLattice lattice, const UINT8 total_ref_0, const UINT8 total_ref_1, const UINT8 total_ref_2, const UINT8 total_ref_3)
#define ABSDIFF(x, y)
REAL8 tol
double e
const LALDetector lalCachedDetectors[LAL_NUM_DETECTORS]
struct tagFITSFile FITSFile
Representation of a FITS file.
Definition: FITSFileIO.h:54
static const UINT8 LAL_FACT[]
EphemerisData * XLALInitBarycenter(const CHAR *earthEphemerisFile, const CHAR *sunEphemerisFile)
XLAL interface to reading ephemeris files 'earth' and 'sun', and return ephemeris-data in old backwar...
void XLALDestroyEphemerisData(EphemerisData *edat)
Destructor for EphemerisData struct, NULL robust.
#define LAL_PI_2
#define LAL_REAL8_EPS
#define LAL_PI
#define XLAL_NUM_ELEM(x)
uint64_t UINT8
uint32_t UINT4
int32_t INT4
#define lalDebugLevel
LALINFOBIT
LAL_LLO_4K_DETECTOR
#define LAL_INT4_FORMAT
#define LAL_UINT8_FORMAT
int XLALIsTiledLatticeTilingDimension(const LatticeTiling *tiling, const size_t dim)
Return >0 if a lattice tiling dimension is tiled (i.e.
int XLALSetLatticeTilingBound(LatticeTiling *tiling, const size_t dim, const LatticeTilingBound func, const size_t data_len, const void *data_lower, const void *data_upper)
Set a parameter-space bound on a dimension of the lattice tiling.
size_t XLALTotalLatticeTilingDimensions(const LatticeTiling *tiling)
Return the total number of dimensions of the lattice tiling.
int XLALNearestLatticeTilingPoint(const LatticeTilingLocator *loc, const gsl_vector *point, gsl_vector *nearest_point, UINT8Vector *nearest_index)
Locate the nearest point in a lattice tiling to a given point.
UINT8 XLALTotalLatticeTilingPoints(const LatticeTilingIterator *itr)
Return the total number of points covered by the lattice tiling iterator.
int XLALSetLatticeTilingConstantBound(LatticeTiling *tiling, const size_t dim, const double bound1, const double bound2)
Set a constant lattice tiling parameter-space bound, given by the minimum and maximum of the two supp...
int XLALSaveLatticeTilingIterator(const LatticeTilingIterator *itr, FITSFile *file, const char *name)
Save the state of a lattice tiling iterator to a FITS file.
REAL8 XLALLatticeTilingStepSize(const LatticeTiling *tiling, const size_t dim)
Return the step size of the lattice tiling in a given dimension, or 0 for non-tiled dimensions.
int XLALGetLatticeTilingBound(const LatticeTiling *tiling, const size_t dim, const gsl_vector *point, const bool padding, double *lower, double *upper)
Get a parameter-space bound on a dimension of the lattice tiling.
int XLALLatticeTilingDimensionByName(const LatticeTiling *tiling, const char *bound_name)
Return the index of the lattice tiling dimension which has the given name.
int XLALSetTilingLatticeAndMetric(LatticeTiling *tiling, const TilingLattice lattice, const gsl_matrix *metric, const double max_mismatch)
Set the tiling lattice, parameter-space metric, and maximum prescribed mismatch.
int XLALNearestLatticeTilingBlock(const LatticeTilingLocator *loc, const gsl_vector *point, const size_t dim, gsl_vector *nearest_point, UINT8 *nearest_index, INT4 *nearest_left, INT4 *nearest_right)
Locate the nearest block in a lattice tiling to a given point.
void XLALDestroyLatticeTilingLocator(LatticeTilingLocator *loc)
Destroy a lattice tiling locator.
UINT8 XLALCurrentLatticeTilingIndex(const LatticeTilingIterator *itr)
Return the index of the current point in the lattice tiling iterator.
size_t XLALTiledLatticeTilingDimensions(const LatticeTiling *tiling)
Return the number of tiled dimensions of the lattice tiling.
size_t XLALLatticeTilingTiledDimension(const LatticeTiling *tiling, const size_t tiled_dim)
Return the dimension of the tiled lattice tiling dimension indexed by 'tiled_dim'.
int XLALRestoreLatticeTilingIterator(LatticeTilingIterator *itr, FITSFile *file, const char *name)
Restore the state of a lattice tiling iterator from a FITS file.
LatticeTilingIterator * XLALCreateLatticeTilingIterator(const LatticeTiling *tiling, const size_t itr_ndim)
Create a new lattice tiling iterator.
void XLALDestroyLatticeTilingIterator(LatticeTilingIterator *itr)
Destroy a lattice tiling iterator.
void XLALDestroyLatticeTiling(LatticeTiling *tiling)
Destroy a lattice tiling.
int XLALNextLatticeTilingPoint(LatticeTilingIterator *itr, gsl_vector *point)
Advance lattice tiling iterator, and optionally return the next point in point.
int XLALSetLatticeTilingAlternatingIterator(LatticeTilingIterator *itr, const bool alternating)
Set whether the lattice tiling iterator should alternate its iteration direction (i....
int XLALNearestLatticeTilingPoints(const LatticeTilingLocator *loc, const gsl_matrix *points, gsl_matrix **nearest_points, UINT8VectorSequence **nearest_indexes)
Locate the nearest points in a lattice tiling to a given set of points.
LatticeTiling * XLALCreateLatticeTiling(const size_t ndim)
Create a new lattice tiling.
const LatticeTilingStats * XLALLatticeTilingStatistics(const LatticeTiling *tiling, const size_t dim)
Return statistics related to the number/value of lattice tiling points in a dimension.
int XLALPrintLatticeTilingIndexTrie(const LatticeTilingLocator *loc, FILE *file)
Print the internal index trie of a lattice tiling locator to the given file pointer.
LatticeTilingLocator * XLALCreateLatticeTilingLocator(const LatticeTiling *tiling)
Create a new lattice tiling locator.
int XLALResetLatticeTilingIterator(LatticeTilingIterator *itr)
Reset an iterator to the beginning of a lattice tiling.
TilingLattice
Type of lattice to generate tiling with.
Definition: LatticeTiling.h:63
int XLALSetLatticeTilingPadding(LatticeTiling *tiling, const size_t dim, const double lower_bbox_pad, const double upper_bbox_pad, const int lower_intp_pad, const int upper_intp_pad, const int find_bound_extrema)
Control the padding of lattice tiling parameter-space bounds in the given dimension.
int XLALNextLatticeTilingPoints(LatticeTilingIterator *itr, gsl_matrix **points)
Advance lattice tiling iterator, and optionally return the next set of points in points.
int XLALRandomLatticeTilingPoints(const LatticeTiling *tiling, const double scale, RandomParams *rng, gsl_matrix *random_points)
Generate random points within the parameter space of the lattice tiling.
@ TILING_LATTICE_ANSTAR
An-star ( ) lattice.
Definition: LatticeTiling.h:65
@ TILING_LATTICE_CUBIC
Cubic ( ) lattice.
Definition: LatticeTiling.h:64
static const INT4 m
RandomParams * XLALCreateRandomParams(INT4 seed)
void XLALDestroyRandomParams(RandomParams *params)
int XLALSegListInit(LALSegList *seglist)
int XLALSegListClear(LALSegList *seglist)
int XLALSegListAppend(LALSegList *seglist, const LALSeg *seg)
int XLALSegSet(LALSeg *seg, const LIGOTimeGPS *start, const LIGOTimeGPS *end, const INT4 id)
int XLALSetSuperskyPhysicalSkyBounds(LatticeTiling *tiling, gsl_matrix *rssky_metric, SuperskyTransformData *rssky_transf, const double alpha1, const double alpha2, const double delta1, const double delta2)
Set parameter-space bounds on the physical sky position for a lattice tiling using the reduced super...
void XLALDestroySuperskyMetrics(SuperskyMetrics *metrics)
Destroy a SuperskyMetrics struct.
SuperskyMetrics * XLALComputeSuperskyMetrics(const SuperskyMetricType type, const size_t spindowns, const LIGOTimeGPS *ref_time, const LALSegList *segments, const double fiducial_freq, const MultiLALDetector *detectors, const MultiNoiseFloor *detector_weights, const DetectorMotionType detector_motion, const EphemerisData *ephemerides)
Compute the supersky metrics, which are returned in a SuperskyMetrics struct.
int XLALEqualizeReducedSuperskyMetricsFreqSpacing(SuperskyMetrics *metrics, const double coh_max_mismatch, const double semi_max_mismatch)
Project and rescale the reduced supersky metrics in the frequency dimension, such that all reduced su...
int XLALSetSuperskyPhysicalSpinBound(LatticeTiling *tiling, const SuperskyTransformData *rssky_transf, const size_t s, const double bound1, const double bound2)
Set parameter-space bounds on the physical frequency/spindowns for a lattice tiling using the reduce...
@ SUPERSKY_METRIC_TYPE
Metric for all-sky searches.
@ DETMOTION_SPIN
Full spin motion.
@ DETMOTION_PTOLEORBIT
Ptolemaic (circular) orbital motion.
void XLALDestroyUINT8Vector(UINT8Vector *vector)
UINT8Vector * XLALCreateUINT8Vector(UINT4 length)
#define xlalErrno
#define XLAL_ERROR(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_MAIN(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EFAILED
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
LIGOTimeGPS * XLALGPSAdd(LIGOTimeGPS *epoch, REAL8 dt)
float data[BLOCKSIZE]
Definition: hwinject.c:360
float total[BLOCKSIZE]
Definition: hwinject.c:361
list y
temp
injections
start_time
n
LALDetector detectors[LAL_NUM_DETECTORS]
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
UINT4 length
Statistics related to the number/value of lattice tiling points in a dimension.
array of detectors definitions 'LALDetector'
Computed supersky metrics, returned by XLALComputeSuperskyMetrics().
gsl_matrix * semi_rssky_metric
Semicoherent reduced supersky metric (2-dimensional sky)
gsl_matrix ** coh_rssky_metric
Coherent reduced supersky metric (2-dimensional sky) for each segment.
size_t num_segments
Number of segments.
SuperskyTransformData * semi_rssky_transf
Semicoherent reduced supersky metric coordinate transform data.
SuperskyTransformData ** coh_rssky_transf
Coherent reduced supersky metric coordinate transform data for each segment.
UINT8 * data