Loading [MathJax]/extensions/TeX/AMSmath.js
LALPulsar 7.1.1.1-b246709
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
XLALMultiNoiseWeightsTest.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2013 John T. Whelan
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#include <config.h>
21#include <math.h>
22#include <sys/times.h>
23
24#include <lal/NormalizeSFTRngMed.h>
25#include <lal/SFTfileIO.h>
26
27/**
28 * \author John T. Whelan
29 * \file
30 * \ingroup SFTfileIO_h
31 * \brief Tests for XLALComputeMultiNoiseWeights()
32 *
33 * PSDs are calculated using the test SFTs created for
34 * SFTfileIOTest.c
35 *
36 */
37
38/*---------- macros ---------- */
39#define FRACERR(x,y) (fabs((x)-(y))/(0.5*((x)+(y))))
40
41/* ----- internal prototypes ---------- */
42int XLALCompareMultiNoiseWeights( MultiNoiseWeights *multiWeights1, MultiNoiseWeights *multiWeights2, REAL8 tolerance );
43
44/* ----- function definitions ---------- */
45int
46main( void )
47{
49 SFTCatalog *catalog = NULL;
50 SFTConstraints XLAL_INIT_DECL( constraints );
52 MultiPSDVector *multiPSDs = NULL;
53 MultiNoiseWeights *multiWeightsXLAL = NULL;
54 MultiNoiseWeights *multiWeightsCorrect = NULL;
55 UINT4 rngmedBins = 11;
56 REAL8 tolerance = 2e-6; /* same algorithm, should be basically identical results */
57
58 /* Construct the "correct" weights, calculated using the old LAL routines */
59 UINT4 numIFOsCorrect = 2;
60 XLAL_CHECK( ( multiWeightsCorrect = XLALCalloc( 1, sizeof( *multiWeightsCorrect ) ) ) != NULL, XLAL_ENOMEM );
61 multiWeightsCorrect->length = numIFOsCorrect;
62 multiWeightsCorrect->Sinv_Tsft = 1.980867126449e+52;
63 XLAL_CHECK( ( multiWeightsCorrect->data = XLALCalloc( numIFOsCorrect, sizeof( *multiWeightsCorrect->data ) ) ) != NULL, XLAL_ENOMEM );
64 XLAL_CHECK( ( multiWeightsCorrect->data[0] = XLALCreateREAL8Vector( 4 ) ) != NULL, XLAL_ENOMEM );
65 multiWeightsCorrect->data[0]->data[0] = 6.425160659487e-05;
66 multiWeightsCorrect->data[0]->data[1] = 7.259453662367e-06;
67 multiWeightsCorrect->data[0]->data[2] = 9.838893684664e-04;
68 multiWeightsCorrect->data[0]->data[3] = 5.043766789923e-05;
69 XLAL_CHECK( ( multiWeightsCorrect->data[1] = XLALCreateREAL8Vector( 3 ) ) != NULL, XLAL_ENOMEM );
70 multiWeightsCorrect->data[1]->data[0] = 1.582309910283e-04;
71 multiWeightsCorrect->data[1]->data[1] = 5.345673753744e-04;
72 multiWeightsCorrect->data[1]->data[2] = 6.998201363537e+00;
73
74 /* Construct the catalog */
75 XLAL_CHECK( ( catalog = XLALSFTdataFind( TEST_DATA_DIR "MultiNoiseWeightsTest*.sft", &constraints ) ) != NULL, XLAL_EFUNC, " XLALSFTdataFind failed\n" );
76
77 /* Load the SFTs */
78 XLAL_CHECK( ( multiSFTs = XLALLoadMultiSFTs( catalog, -1, -1 ) ) != NULL, XLAL_EFUNC, " XLALLoadMultiSFTs failed\n" );
79
80 /* calculate the psd and normalize the SFTs */
81 XLAL_CHECK( ( multiPSDs = XLALNormalizeMultiSFTVect( multiSFTs, rngmedBins, NULL ) ) != NULL, XLAL_EFUNC, " XLALNormalizeMultiSFTVect failed\n" );
82
83 /* Get weights using XLAL function */
84 XLAL_CHECK( ( multiWeightsXLAL = XLALComputeMultiNoiseWeights( multiPSDs, rngmedBins, 0 ) ) != NULL, XLAL_EFUNC, " XLALComputeMultiNoiseWeights failed\n" );
85
86 /* Compare XLAL weights to reference */
87 XLAL_CHECK( XLALCompareMultiNoiseWeights( multiWeightsXLAL, multiWeightsCorrect, tolerance ) == XLAL_SUCCESS, XLAL_EFAILED, "Comparison between XLAL and reference MultiNoiseWeights failed\n" );
88
89 /* Also check copying some weights */
90 MultiNoiseWeights *copiedMultiWeights = NULL;
91 XLAL_CHECK( ( copiedMultiWeights = XLALCopyMultiNoiseWeights( multiWeightsCorrect ) ) != NULL, XLAL_EFUNC, "XLALCopyMultiNoiseWeights failed\n" );
92 XLAL_CHECK( XLALCompareMultiNoiseWeights( copiedMultiWeights, multiWeightsCorrect, tolerance ) == XLAL_SUCCESS, XLAL_EFAILED, "Comparison between reference MultiNoiseWeights and a copy failed\n" );
93
94 /* Clean up memory */
95 XLALDestroyMultiNoiseWeights( multiWeightsCorrect );
96 XLALDestroyMultiNoiseWeights( multiWeightsXLAL );
97 XLALDestroyMultiNoiseWeights( copiedMultiWeights );
98 XLALDestroyMultiPSDVector( multiPSDs );
100 XLALDestroySFTCatalog( catalog );
101 /* check for memory-leaks */
103
104 return XLAL_SUCCESS;
105
106} /* main() */
107
108/**
109 * Comparison function for two multiNoiseWeights vectors, return success or failure for given tolerance.
110 * The fractional error is checked for the weights and normalization factors.
111 *
112 */
113int
114XLALCompareMultiNoiseWeights( MultiNoiseWeights *multiWeights1, MultiNoiseWeights *multiWeights2, REAL8 tolerance )
115{
116
117 XLALPrintInfo( "Sinv_Tsft1 %.12e; Sinv_Tsft2 %.12e\n", multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft );
118 XLAL_CHECK( FRACERR( multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft ) <= tolerance, XLAL_EFAILED, "%s: Sinv_Tsft differs by more than tolerance %g multiWeights1 = %g, multiWeights2 = %g\n", __func__, tolerance, multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft );
119
120 XLAL_CHECK( multiWeights1->length == multiWeights2->length, XLAL_EFAILED, "%s: numbers of detectors differ multiWeights1 = %d, multiWeights2 = %d\n", __func__, multiWeights1->length, multiWeights2->length );
121 UINT4 numIFOs = multiWeights1->length;
122 for ( UINT4 X = 0; X < numIFOs; X++ ) {
123 REAL8Vector *weights1 = multiWeights1->data[X];
124 REAL8Vector *weights2 = multiWeights2->data[X];
125
126 XLAL_CHECK( weights1->length == weights2->length, XLAL_EFAILED, "%s: numbers of SFTs for detector %d differ multiWeights1 = %d, multiWeights2 = %d\n", __func__, X, weights1->length, weights2->length );
127 UINT4 numSFTs = weights1->length;
128
129 for ( UINT4 alpha = 0; alpha < numSFTs; alpha++ ) {
130 XLALPrintInfo( "IFO %d; SFT %d; weight1 %.12e; weight2 %.12e\n", X, alpha, weights1->data[alpha], weights2->data[alpha] );
131 XLAL_CHECK( FRACERR( weights1->data[alpha], weights2->data[alpha] ) <= tolerance, XLAL_EFAILED, "%s: weights for IFO %d, SFT %d differ by more than tolerance %g multiWeights1 = %g, multiWeights2 = %g\n", __func__, X, alpha, tolerance, weights1->data[alpha], weights2->data[alpha] );
132 }
133 }
134
135 return XLAL_SUCCESS;
136
137} /* XLALCompareMultiNoiseWeights() */
#define __func__
log an I/O error, i.e.
void LALCheckMemoryLeaks(void)
int main(void)
#define FRACERR(x, y)
int XLALCompareMultiNoiseWeights(MultiNoiseWeights *multiWeights1, MultiNoiseWeights *multiWeights2, REAL8 tolerance)
Comparison function for two multiNoiseWeights vectors, return success or failure for given tolerance.
double e
double REAL8
#define XLAL_INIT_DECL(var,...)
uint32_t UINT4
void * XLALCalloc(size_t m, size_t n)
MultiPSDVector * XLALNormalizeMultiSFTVect(MultiSFTVector *multsft, UINT4 blockSize, const MultiNoiseFloor *assumeSqrtSX)
Function for normalizing a multi vector of SFTs in a multi IFO search and returns the running-median ...
MultiNoiseWeights * XLALCopyMultiNoiseWeights(const MultiNoiseWeights *multiWeights)
Create a full copy of a MultiNoiseWeights object.
Definition: PSDutils.c:143
void XLALDestroyMultiPSDVector(MultiPSDVector *multvect)
Destroy a multi PSD-vector.
Definition: PSDutils.c:102
MultiNoiseWeights * XLALComputeMultiNoiseWeights(const MultiPSDVector *rngmed, UINT4 blocksRngMed, UINT4 excludePercentile)
Computes weight factors arising from MultiSFTs with different noise floors.
Definition: PSDutils.c:285
void XLALDestroyMultiNoiseWeights(MultiNoiseWeights *weights)
Destroy a MultiNoiseWeights object.
Definition: PSDutils.c:172
void XLALDestroySFTCatalog(SFTCatalog *catalog)
Free an 'SFT-catalogue'.
Definition: SFTcatalog.c:329
MultiSFTVector * XLALLoadMultiSFTs(const SFTCatalog *inputCatalog, REAL8 fMin, REAL8 fMax)
Function to load a catalog of SFTs from possibly different detectors.
Definition: SFTfileIO.c:416
void XLALDestroyMultiSFTVector(MultiSFTVector *multvect)
Destroy a multi SFT-vector.
Definition: SFTtypes.c:424
SFTCatalog * XLALSFTdataFind(const CHAR *file_pattern, const SFTConstraints *constraints)
Find the list of SFTs matching the file_pattern and satisfying the given constraints,...
Definition: SFTcatalog.c:71
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK(assertion,...)
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFUNC
XLAL_EFAILED
double alpha
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
Definition: PSDutils.h:71
REAL8 Sinv_Tsft
normalization factor used: (using single-sided PSD!)
Definition: PSDutils.h:77
UINT4 length
number of detectors
Definition: PSDutils.h:75
REAL8Vector ** data
weights-vector for each detector
Definition: PSDutils.h:76
A collection of PSD vectors – one for each IFO in a multi-IFO search.
Definition: PSDutils.h:62
A collection of SFT vectors – one for each IFO in a multi-IFO search.
Definition: SFTfileIO.h:179
REAL8 * data
An "SFT-catalogue": a vector of SFTdescriptors, as returned by XLALSFTdataFind()
Definition: SFTfileIO.h:238
'Constraints' for SFT-matching: which detector, within which time-stretch and which timestamps exactl...
Definition: SFTfileIO.h:212