24 #include <gsl/gsl_blas.h>
25 #include <gsl/gsl_linalg.h>
27 #include <lal/SynthesizeCWDraws.h>
29 #include <lal/FstatisticTools.h>
32 #define SQ(x) ((x)*(x))
63 if ( !
L || (
L->size1 != 4 ) || (
L->size2 != 4 ) ) {
75 n[0] = gsl_ran_gaussian( rng, 1.0 );
76 n[1] = gsl_ran_gaussian( rng, 1.0 );
77 n[2] = gsl_ran_gaussian( rng, 1.0 );
78 n[3] = gsl_ran_gaussian( rng, 1.0 );
83 gsl_vector_view n_view = gsl_vector_view_array(
n, 4 );
84 gsl_vector_view n_mu_view = gsl_vector_view_array( n_mu, 4 );
90 if ( ( gslstat = gsl_blas_dgemv( CblasNoTrans, 1.0,
L, &n_view.vector, 0.0, &n_mu_view.vector ) ) != 0 ) {
109 if ( !detStates || !detStates->
data ) {
113 if ( !amcoeffs || !amcoeffs->
a || !amcoeffs->
b ) {
114 XLALPrintError(
"%s: invalid NULL input in amcoeffs=%p or amcoeffs->a=%p, amcoeffs->b=%p\n",
__func__, amcoeffs, amcoeffs->
a, amcoeffs->
b );
118 if ( numAtoms != amcoeffs->
a->
length || numAtoms != amcoeffs->
b->
length ) {
161 if ( !multiDetStates || !multiDetStates->
data ) {
165 if ( !multiAM || !multiAM->
data || !multiAM->
data[0] ) {
178 if ( ( multiAtoms =
XLALCalloc( 1,
sizeof( *multiAtoms ) ) ) == NULL ) {
191 for ( X = 0; X <
numDet; X ++ ) {
214 if ( !atoms || !rng ) {
215 XLALPrintError(
"%s: invalid NULL input for 'atoms'=%p or random-number generator 'rng'=%p\n",
__func__, atoms, rng );
222 if ( ( Lcor = gsl_matrix_calloc( 4, 4 ) ) == NULL ) {
240 REAL8 a_by_2 = 0.5 * sqrt(
a2 );
241 REAL8 b_by_2 = 0.5 * sqrt(
b2 );
248 gsl_matrix_set( Lcor, 0, 0, a_by_2 );
249 gsl_matrix_set( Lcor, 0, 1, a_by_2 );
250 gsl_matrix_set( Lcor, 1, 0, b_by_2 );
251 gsl_matrix_set( Lcor, 1, 1, b_by_2 );
253 gsl_matrix_set( Lcor, 2, 2, a_by_2 );
254 gsl_matrix_set( Lcor, 2, 3, a_by_2 );
255 gsl_matrix_set( Lcor, 3, 2, b_by_2 );
256 gsl_matrix_set( Lcor, 3, 3, b_by_2 );
262 REAL8 x1, x2, x3, x4;
276 gsl_matrix_free( Lcor );
292 if ( !multiAtoms || !multiAtoms->
data ) {
334 if ( !atoms || !atoms->
data ) {
351 gsl_matrix *Mh_mu_nu;
352 if ( ( Mh_mu_nu = gsl_matrix_calloc( 4, 4 ) ) == NULL ) {
357 gsl_vector_const_view A_Mu_view = gsl_vector_const_view_array( A_Mu, 4 );
362 REAL8 Ap = 0, Bp = 0, Cp = 0;
388 gsl_matrix_set( Mh_mu_nu, 0, 0,
a2 );
389 gsl_matrix_set( Mh_mu_nu, 1, 1,
b2 );
390 gsl_matrix_set( Mh_mu_nu, 0, 1, ab );
391 gsl_matrix_set( Mh_mu_nu, 1, 0, ab );
393 gsl_matrix_set( Mh_mu_nu, 2, 2,
a2 );
394 gsl_matrix_set( Mh_mu_nu, 3, 3,
b2 );
395 gsl_matrix_set( Mh_mu_nu, 2, 3, ab );
396 gsl_matrix_set( Mh_mu_nu, 3, 2, ab );
400 gsl_vector_view sh_mu_view = gsl_vector_view_array( sh_mu, 4 );
408 REAL8 norm_s = sqrt( TAtom / 2.0 );
409 if ( ( gslstat = gsl_blas_dgemv( CblasNoTrans, norm_s, Mh_mu_nu, &A_Mu_view.vector, 0.0, &sh_mu_view.vector ) ) != 0 ) {
435 REAL8 rho2 = TAtom * ( Ap * (
SQ( A1 ) +
SQ( A3 ) ) + 2.0 * Cp * ( A1 * A2 + A3 * A4 ) + Bp * (
SQ( A2 ) +
SQ( A4 ) ) );
442 M_mu_nu->
Dd = Ap * Bp - Cp * Cp;
445 gsl_matrix_free( Mh_mu_nu );
469 if ( !multiAtoms || !multiAtoms->
data ) {
485 for ( X = 0; X <
numDet; X ++ ) {
490 if ( ( lineX >= 0 ) && ( (
UINT4 )lineX != X ) ) {
498 M_mu_nu->
Ad += M_mu_nu_X.
Ad;
499 M_mu_nu->
Bd += M_mu_nu_X.
Bd;
500 M_mu_nu->
Cd += M_mu_nu_X.
Cd;
507 M_mu_nu->
Dd = M_mu_nu->
Ad * M_mu_nu->
Bd -
SQ( M_mu_nu->
Cd );
545 if ( multiAMBuffer->
multiAM ) {
565 multiAMBuffer->
skypos = skypos;
578 }
else if ( AmpPrior.
fixedSNR == 0 ) {
599 injectWindow.type = transientInjectRange.
type;
601 injectWindow.t0 = (
UINT4 ) gsl_ran_flat( rng, transientInjectRange.
t0, transientInjectRange.
t0 + transientInjectRange.
t0Band );
602 injectWindow.tau = (
UINT4 ) gsl_ran_flat( rng, transientInjectRange.
tau, transientInjectRange.
tau + transientInjectRange.
tauBand );
629 rescale = 1.0 / detM1o8;
637 Amp.
aPlus *= rescale;
640 for (
i = 0;
i < 4;
i ++ ) {
656 if ( injParamsOut ) {
657 injParamsOut->
skypos = skypos;
660 for (
i = 0;
i < 4;
i ++ ) {
665 injParamsOut->
SNR = sqrt(
rho2 );
666 injParamsOut->
detM1o8 = detM1o8;
692 for ( X = 0; X <
numDet; X ++ ) {
696 for (
i = 0;
i < numAtoms;
i ++ ) {
719 const UINT4 dataStartGPS,
721 const UINT4 numDetectors
733 char M_mu_nu_X_header_string[256] =
"";
734 if ( outputMmunuX ) {
737 snprintf( buf0,
sizeof( buf0 ),
" AdX[%d] BdX[%d] CdX[%d] DdX[%d]", X, X, X, X );
738 strcat( M_mu_nu_X_header_string, buf0 );
741 ret =
fprintf(
fp,
"%%%%Alpha Delta SNR h0 cosi psi phi0 A1 A2 A3 A4 Ad Bd Cd Dd t0[d] tau[d] type (detMp)^(1/8)%s\n", M_mu_nu_X_header_string );
751 REAL8 t0_d = 1.0 * (
par->transientWindow.t0 - dataStartGPS ) /
DAY24;
754 char M_mu_nu_X_string[256] =
"";
755 if ( outputMmunuX ) {
760 strcat( M_mu_nu_X_string,
" " );
763 snprintf( buf0,
sizeof( buf0 ),
" %10.5g %10.5g %10.5g %10.5g",
par->multiAM.data[X]->A,
par->multiAM.data[X]->B,
par->multiAM.data[X]->C,
par->multiAM.data[X]->D );
764 strcat( M_mu_nu_X_string, buf0 );
772 h0 =
par->ampParams.aPlus + sqrt(
SQ(
par->ampParams.aPlus ) -
SQ(
par->ampParams.aCross ) );
780 ret =
fprintf(
fp,
" %5.3f %6.3f %6.3f %7.3g %6.3f %6.3f %6.3f % 9.3g % 9.3g % 9.3g % 9.3g %10.5g %10.5g %10.5g %10.5g %9.3f %9.3f %1d %9.3g%s\n",
781 par->skypos.longitude,
par->skypos.latitude,
784 par->ampVect[0],
par->ampVect[1],
par->ampVect[2],
par->ampVect[3],
785 par->multiAM.Mmunu.Ad,
par->multiAM.Mmunu.Bd,
par->multiAM.Mmunu.Cd,
par->multiAM.Mmunu.Dd,
786 t0_d, tau_d,
par->transientWindow.type,
#define __func__
log an I/O error, i.e.
REAL8 XLALDrawFromPDF1D(pdf1D_t *pdf, const gsl_rng *rng)
Function to generate random samples drawn from the given pdf(x) NOTE: if the 'sampling' field is NULL...
FstatAtomVector * XLALCreateFstatAtomVector(const UINT4 length)
Create a FstatAtomVector of the given length.
void XLALDestroyMultiFstatAtomVector(MultiFstatAtomVector *multiAtoms)
Free all memory associated with a MultiFstatAtomVector structure.
void XLALDestroyMultiAMCoeffs(MultiAMCoeffs *multiAMcoef)
Destroy a MultiAMCoeffs structure.
MultiAMCoeffs * XLALComputeMultiAMCoeffs(const MultiDetectorStateSeries *multiDetStates, const MultiNoiseWeights *multiWeights, SkyPosition skypos)
Multi-IFO version of XLALComputeAMCoeffs().
#define XLAL_INIT_DECL(var,...)
void * XLALCalloc(size_t m, size_t n)
REAL8 PulsarAmplitudeVect[4]
Struct for 'canonical' coordinates in amplitude-params space A^mu = {A1, A2, A3, A4}.
@ TRANSIENT_NONE
Note: in this case the window-parameters will be ignored, and treated as rect={data},...
COORDINATESYSTEM_EQUATORIAL
FstatAtomVector * XLALGenerateFstatAtomVector(const DetectorStateSeries *detStates, const AMCoeffs *amcoeffs)
Generate an FstatAtomVector for given antenna-pattern functions.
int XLALAddNoiseToMultiFstatAtomVector(MultiFstatAtomVector *multiAtoms, gsl_rng *rng)
Add Gaussian-noise components to given multi-FstatAtomVector.
REAL8 XLALAddSignalToMultiFstatAtomVector(MultiFstatAtomVector *multiAtoms, AntennaPatternMatrix *M_mu_nu, const PulsarAmplitudeVect A_Mu, transientWindow_t transientWindow, INT4 lineX)
Add given signal s_mu = M_mu_nu A^nu within the given transient-window to multi-IFO noise-atoms.
int write_InjParams_to_fp(FILE *fp, const InjParams_t *par, const UINT4 dataStartGPS, const BOOLEAN outputMmunuX, const UINT4 numDetectors)
Write an injection-parameters structure to the given file-pointer, adding one line with the injection...
MultiFstatAtomVector * XLALGenerateMultiFstatAtomVector(const MultiDetectorStateSeries *multiDetStates, const MultiAMCoeffs *multiAM)
Generate a multi-FstatAtomVector for given antenna-pattern functions.
MultiFstatAtomVector * XLALSynthesizeTransientAtoms(InjParams_t *injParamsOut, SkyPosition skypos, AmplitudePrior_t AmpPrior, transientWindowRange_t transientInjectRange, const MultiDetectorStateSeries *multiDetStates, BOOLEAN SignalOnly, multiAMBuffer_t *multiAMBuffer, gsl_rng *rng, INT4 lineX, const MultiNoiseWeights *multiNoiseWeights)
Generates a multi-Fstat atoms vector for given parameters, drawing random parameters wherever require...
int XLALRescaleMultiFstatAtomVector(MultiFstatAtomVector *multiAtoms, REAL8 rescale)
Rescale a given multi-Fstat atoms vector {Fa,Fb} by given scalar factor.
int XLALAddNoiseToFstatAtomVector(FstatAtomVector *atoms, gsl_rng *rng)
Add Gaussian-noise components to given FstatAtomVector.
int XLALDrawCorrelatedNoise(PulsarAmplitudeVect n_mu, const gsl_matrix *L, gsl_rng *rng)
Generate 4 random-noise draws n_mu = {n_1, n_2, n_3, n_4} with correlations according to the matrix M...
REAL8 XLALAddSignalToFstatAtomVector(FstatAtomVector *atoms, AntennaPatternMatrix *M_mu_nu, const PulsarAmplitudeVect A_Mu, transientWindow_t transientWindow)
Add signal s_mu = M_mu_nu A^nu within the given transient-window to given atoms.
int XLALGetTransientWindowTimespan(UINT4 *t0, UINT4 *t1, transientWindow_t transientWindow)
Helper-function to determine the total timespan of a transient CW window, ie.
#define DAY24
standard 24h day = 86400 seconds ==> this is what's used in the definition of 'tauDays'
static REAL8 XLALGetTransientWindowValue(UINT4 timestamp, UINT4 t0, UINT4 t1, UINT4 tau, transientWindowType_t type)
Function to compute the value of a given transient-window function at a given timestamp.
#define XLAL_ERROR_REAL8(...)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK_REAL8(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
This structure contains the per-SFT (weighted) antenna-pattern functions , with the SFT-index,...
REAL4Vector * b
(weighted) per-SFT antenna-pattern function
REAL4Vector * a
(weighted) per-SFT antenna-pattern function
Signal (amplitude) parameter ranges.
pdf1D_t * pdf_h0Nat
pdf for h0/sqrt{Sn}
REAL8 fixedSNR
alternative 1: adjust h0 to fix the optimal SNR of the signal
BOOLEAN fixRhohMax
alternative 2: draw h0 with fixed rhohMax = h0Max * (detM)^(1/8) <==> canonical Fstat prior
pdf1D_t * pdf_phi0
pdf(phi0)
pdf1D_t * pdf_cosi
pdf(cosi)
pdf1D_t * pdf_psi
pdf(psi)
Struct holding the "antenna-pattern" matrix , in terms of the multi-detector scalar product.
REAL8 Sinv_Tsft
normalization-factor (using single-sided PSD!)
REAL4 Dd
determinant factor , such that
LIGOTimeGPS tGPS
GPS timestamps corresponding to this entry.
Timeseries of DetectorState's, representing the detector-info at different timestamps.
REAL8 deltaT
timespan centered on each timestamp (e.g.
DetectorState * data
array of DetectorState entries
UINT4 length
total number of entries
An -statistic 'atom', i.e.
REAL4 b2_alpha
Antenna-pattern factor .
UINT4 timestamp
SFT GPS timestamp in seconds.
REAL4 ab_alpha
Antenna-pattern factor .
REAL4 a2_alpha
Antenna-pattern factor .
A vector of -statistic 'atoms', i.e.
UINT4 TAtom
Time-baseline of 'atoms', typically .
FstatAtom * data
Array of FstatAtom pointers of given length.
UINT4 length
Number of per-SFT 'atoms'.
Hold all (generally) randomly drawn injection parameters: skypos, amplitude-params,...
transientWindow_t transientWindow
PulsarAmplitudeParams ampParams
PulsarAmplitudeVect ampVect
Multi-IFO container for antenna-pattern coefficients and atenna-pattern matrix .
UINT4 length
number of IFOs
AMCoeffs ** data
noise-weighted AM-coeffs , and
Multi-IFO time-series of DetectorStates.
UINT4 length
number of detectors
DetectorStateSeries ** data
vector of pointers to DetectorStateSeries
A multi-detector vector of FstatAtomVector.
FstatAtomVector ** data
Array of FstatAtomVector pointers, one for each detector X.
UINT4 length
Number of detectors.
One noise-weight (number) per SFT (therefore indexed over IFOs and SFTs.
REAL8Vector ** data
weights-vector for each detector
Type containing the JKS 'amplitude parameters' {h0, cosi, phi0, psi}.
REAL8 aCross
Signal amplitude (cross)
REAL8 psi
polarization angle psi
REAL8 aPlus
Signal amplitude (plus)
REAL8 phi0
initial signal-phase (at some reference time)
struct for buffering of AM-coeffs, if signal for same sky-position is injected
SkyPosition skypos
sky-position for which we have AM-coeffs computed already
Struct defining one transient window instance.
UINT4 tau
transient timescale tau in seconds
transientWindowType_t type
window-type: none, rectangular, exponential, ....
Struct defining a range of transient windows.
UINT4 tauBand
range of transient timescales tau to search, in seconds
UINT4 tau
shortest transient timescale tau in seconds
UINT4 t0
earliest GPS start-time 't0' in seconds
transientWindowType_t type
window-type: none, rectangular, exponential, ....
UINT4 t0Band
range of start-times 't0' to search, in seconds