21#include <lal/UserInput.h>
39 vector->numofcandidates = 0;
47 vector->data[ii].prob = 0.0;
74 if ( length >
vector->length )
for (
UINT4 ii =
vector->length; ii < length; ii++ ) {
75 vector->data[ii].prob = 0.0;
122void loadCandidateData(
candidate *
output,
const REAL8 fsig,
const REAL8 period,
const REAL8 moddepth,
const REAL4 ra,
const REAL4 dec,
const REAL8 statval,
const REAL8 h0,
const REAL8 prob,
const INT4 proberrcode,
const REAL8 normalization,
const INT4 templateVectorIndex,
const BOOLEAN lineContamination )
127 output->moddepth = moddepth;
133 output->proberrcode = proberrcode;
134 output->normalization = normalization;
135 output->templateVectorIndex = templateVectorIndex;
136 output->lineContamination = lineContamination;
156 XLAL_CHECK(
output != NULL && input != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL &&
params != NULL && plan != NULL && rng != NULL,
XLAL_EINVAL );
158 INT4 proberrcode = 0;
175 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
184 loadCandidateData(
output, input->
fsig, input->
period, input->
moddepth, input->
ra, input->
dec, R,
h0, prob, proberrcode, 1.0, -1, 0 );
200 INT4 proberrcode = 0;
211 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
220 if ( prob < output->
data[
output->length - 1].prob ) {
222 while ( insertionPoint > 0 && prob < output->
data[insertionPoint - 1].prob ) {
226 loadCandidateData( &(
output->data[kk + 1] ),
output->data[kk].fsig,
output->data[kk].period,
output->data[kk].moddepth,
output->data[kk].ra,
output->data[kk].dec,
output->data[kk].stat,
output->data[kk].h0,
output->data[kk].prob,
output->data[kk].proberrcode,
output->data[kk].normalization,
output->data[kk].templateVectorIndex, 0 );
228 loadCandidateData( &(
output->data[insertionPoint] ), template->f0, template->period, template->moddepth, input->
data[ii].
ra, input->
data[ii].
dec, R,
h0, prob, proberrcode, ffdata->
tfnormalization, input->
data[ii].
templateVectorIndex, 0 );
230 output->numofcandidates++;
259 fprintf( stderr,
"Performing brute force template search... " );
262 REAL8 fstepsize, dfstepsize;
264 REAL4 alpha0 = 45.0 * (
params->Tsft / 1800.0 ) + 30.0;
280 trialb->
data[ii] = search.
dfmin + dfstepsize * ii;
308 INT4 bestproberrcode = 0;
309 REAL8 bestf = 0.0, bestp = 0.0, bestdf = 0.0, bestR = 0.0, besth0 = 0.0, bestProb = 0.0;
314 if (
params->calcRthreshold ) {
330 trialp->
data[startposition - ( kk + 1 )] = trialp->
data[startposition - kk] - nnp;
334 trialp->
data[startposition + ( kk + 1 )] = trialp->
data[startposition + kk] + nnp;
351 loadCandidateData( &cand, trialf->
data[ii], trialp->
data[kk], trialb->
data[jj], input.
ra, input.
dec, 0, 0, 0.0, 0, 0.0, -1, 0 );
355 if ( useExactTemplates ) {
361 if (
params->calcRthreshold && bestProb == 0.0 ) {
365 REAL8 R =
calculateR( ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
367 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
376 if ( ( bestProb != 0.0 && prob < bestProb ) || ( bestProb == 0.0 && !
params->calcRthreshold && prob < log10templatefar ) || ( bestProb == 0.0 &&
params->calcRthreshold && R > farval->
far ) ) {
377 bestf = trialf->
data[ii];
378 bestp = trialp->
data[kk];
379 bestdf = trialb->
data[jj];
383 bestproberrcode = proberrcode;
392 if (
params->calcRthreshold ) {
403 if ( bestProb == 0.0 ) {
404 loadCandidateData(
output, input.
fsig, input.
period, input.
moddepth, input.
ra, input.
dec, input.
stat, input.
h0, input.
prob, input.
proberrcode, input.
normalization, input.
templateVectorIndex, input.
lineContamination );
406 loadCandidateData(
output, bestf, bestp, bestdf, input.
ra, input.
dec, bestR, besth0, bestProb, bestproberrcode, input.
normalization, input.
templateVectorIndex, input.
lineContamination );
432 XLAL_CHECK( *
output != NULL && paramspace != NULL &&
params != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL && secondFFTplan != NULL && rng != NULL,
XLAL_EINVAL );
435 REAL8 fstepsize, dfstepsize;
451 trialb->
data[ii] = search.
dfmin + dfstepsize * ii;
494 trialp->
data[startposition - ( kk + 1 )] = trialp->
data[startposition - kk] - nnp;
498 trialp->
data[startposition + ( kk + 1 )] = trialp->
data[startposition + kk] + nnp;
515 loadCandidateData( &cand, trialf->
data[ii], trialp->
data[kk], trialb->
data[jj], input.
ra, input.
dec, 0, 0, 0.0, 0, 0.0, -1, 0 );
519 if ( useExactTemplates ) {
525 REAL8 R =
calculateR( ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
527 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
535 if ( ( *output )->numofcandidates == ( *output )->length - 1 ) {
539 loadCandidateData( &( ( *output )->data[( *output )->numofcandidates] ), trialf->
data[ii], trialp->
data[kk], trialb->
data[jj], input.
ra, input.
dec, R,
h0, prob, proberrcode, input.
normalization, input.
templateVectorIndex, input.
lineContamination );
540 ( *output )->numofcandidates++;
575INT4 templateSearch_scox1Style(
candidateVector **
output,
const REAL8 fminimum,
const REAL8 fspan,
const REAL8 period,
const REAL8 asini,
const REAL8 asinisigma,
const SkyPosition skypos,
const UserInput_t *
params,
const REAL4VectorAligned *ffdata,
const REAL4VectorAligned *aveNoise,
const REAL4VectorAligned *aveTFnoisePerFbinRatio,
const REAL4VectorSequence *trackedlines,
const REAL4FFTPlan *secondFFTplan,
const gsl_rng *rng,
BOOLEAN useExactTemplates )
578 XLAL_CHECK( *
output != NULL &&
params != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL && secondFFTplan != NULL && rng != NULL,
XLAL_EINVAL );
588 fstepsize = fspan / (
REAL8 )( numfsteps - 1 );
589 for (
INT4 ii = 0; ii < numfsteps; ii++ ) {
590 trialf->
data[ii] = fminimum + fstepsize * ii;
594 INT4 proberrcode = 0;
616 REAL8 moddepth = 0.8727 * ( trialf->
data[ii] / 1000.0 ) * ( 7200.0 / period ) * asini;
619 REAL8 moddepthspan = 0.8727 * ( trialf->
data[numfsteps - 1] / 1000.0 ) * ( 7200.0 / period ) * 6 * asinisigma;
622 REAL8 moddepthmin = moddepth - 0.5 * moddepthspan;
624 INT4 numdfsteps = (
INT4 )round( 4.0 * moddepthspan *
params->Tsft ) + 1;
628 if ( numdfsteps > 1 ) {
629 dfstepsize = moddepthspan / (
REAL8 )( numdfsteps - 1 );
633 for (
INT4 jj = 0; jj < numdfsteps; jj++ ) {
634 trialdf->
data[jj] = moddepthmin + dfstepsize * jj;
643 loadCandidateData( &cand, trialf->
data[ii], period, trialdf->
data[jj], skypos.
longitude, skypos.
latitude, 0, 0, 0.0, 0, 0.0, -1, 0 );
647 if ( useExactTemplates != 0 ) {
653 REAL8 R =
calculateR( ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
655 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
664 if ( trackedlines != NULL ) {
666 while ( kk < trackedlines->length && lineContamination == 0 ) {
667 if ( 2.0 * trialdf->
data[jj] >= ( trackedlines->
data[kk * 3 + 2] - trackedlines->
data[kk * 3 + 1] ) ) {
668 if ( ( trackedlines->
data[kk * 3 + 2] >= (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) && trackedlines->
data[kk * 3 + 2] <= (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) ) ||
669 ( trackedlines->
data[kk * 3 + 1] >= (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) && trackedlines->
data[kk * 3 + 1] <= (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) ) ) {
670 lineContamination = 1;
674 if ( ( (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) >= trackedlines->
data[kk * 3 + 1] && (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) <= trackedlines->
data[kk * 3 + 2] ) ||
675 ( (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) >= trackedlines->
data[kk * 3 + 1] && (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) <= trackedlines->
data[kk * 3 + 2] ) ) {
676 lineContamination = 1;
684 if ( ( *output )->numofcandidates == ( *output )->length - 1 ) {
689 loadCandidateData( &( ( *output )->data[( *output )->numofcandidates] ), trialf->
data[ii], period, trialdf->
data[jj], skypos.
longitude, skypos.
latitude, R,
h0, prob, proberrcode, 0.0, -1, lineContamination );
690 ( *output )->numofcandidates++;
724INT4 templateSearch_fixedDf(
candidateVector **
output,
const LALStringVector *dffixed,
const REAL8 fminimum,
const REAL8 fspan,
const REAL8 period,
const SkyPosition skypos,
const UserInput_t *
params,
const REAL4VectorAligned *ffdata,
const REAL4VectorAligned *aveNoise,
const REAL4VectorAligned *aveTFnoisePerFbinRatio,
const REAL4VectorSequence *trackedlines,
const REAL4FFTPlan *secondFFTplan,
const gsl_rng *rng,
BOOLEAN useExactTemplates )
727 XLAL_CHECK( *
output != NULL && dffixed != NULL &&
params != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL && secondFFTplan != NULL && rng != NULL,
XLAL_EINVAL );
745 fstepsize = fspan / (
REAL8 )( numfsteps - 1 );
746 for (
INT4 ii = 0; ii < numfsteps; ii++ ) {
747 trialf->
data[ii] = fminimum + fstepsize * ii;
751 INT4 proberrcode = 0;
762 loadCandidateData( &cand, trialf->
data[ii], period, trialdf->
data[jj], skypos.
longitude, skypos.
latitude, 0, 0, 0.0, 0, 0.0, -1, 0 );
766 if ( useExactTemplates != 0 ) {
772 REAL8 R =
calculateR( ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
774 REAL8 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
783 if ( trackedlines != NULL ) {
785 while ( kk < trackedlines->length && lineContamination == 0 ) {
786 if ( 2.0 * trialdf->
data[jj] >= ( trackedlines->
data[kk * 3 + 2] - trackedlines->
data[kk * 3 + 1] ) ) {
787 if ( ( trackedlines->
data[kk * 3 + 2] >= (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) && trackedlines->
data[kk * 3 + 2] <= (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) ) ||
788 ( trackedlines->
data[kk * 3 + 1] >= (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) && trackedlines->
data[kk * 3 + 1] <= (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) ) ) {
789 lineContamination = 1;
793 if ( ( (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) >= trackedlines->
data[kk * 3 + 1] && (
REAL4 )( trialf->
data[ii] + trialdf->
data[jj] ) <= trackedlines->
data[kk * 3 + 2] ) ||
794 ( (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) >= trackedlines->
data[kk * 3 + 1] && (
REAL4 )( trialf->
data[ii] - trialdf->
data[jj] ) <= trackedlines->
data[kk * 3 + 2] ) ) {
795 lineContamination = 1;
803 if ( ( *output )->numofcandidates == ( *output )->length - 1 ) {
808 loadCandidateData( &( ( *output )->data[( *output )->numofcandidates] ), trialf->
data[ii], period, trialdf->
data[jj], skypos.
longitude, skypos.
latitude, R,
h0, prob, proberrcode, 0.0, -1, lineContamination );
809 ( *output )->numofcandidates++;
843 REAL8 avefsig, aveperiod, mindf, maxdf;
846 INT4Vector *locs = NULL, *locs2 = NULL, *usedcandidate = NULL;
854 locs2->data[ii] = -1;
855 usedcandidate->data[ii] = 0;
859 REAL4FFTPlan *plan = NULL;
860 if ( exactflag == 1 ) {
877 if ( foundany == 0 ) {
883 while ( foundany == 1 ) {
890 if ( foundany == 0 ) {
899 while ( foundany == 1 ) {
906 if ( foundany == 0 ) {
915 UINT4 subsetloc = 0, nextsubsetloc = 0, subsetlocset = 0;
917 for (
UINT4 jj = subsetloc; jj <
loc; jj++ ) {
919 locs2->data[loc2] = locs->
data[jj];
921 }
else if ( usedcandidate->data[locs->
data[jj]] == 0 && subsetlocset == 0 ) {
926 if ( jj + 1 ==
loc ) {
927 if ( subsetlocset == 1 ) {
928 subsetloc = nextsubsetloc;
934 fprintf( stderr,
"Finding best modulation depth with number to try %d\n", loc2 );
935 avefsig = 0.0, aveperiod = 0.0, mindf = 0.0, maxdf = 0.0;
936 REAL8 weight = 0.0, bestmoddepth = 0.0, bestR = 0.0, besth0 = 0.0, bestProb = 0.0;
937 INT4 bestproberrcode = 0;
938 for (
UINT4 kk = 0; kk < loc2; kk++ ) {
939 avefsig += input->
data[locs2->data[kk]].
fsig * ( input->
data[locs2->data[kk]].
prob * input->
data[locs2->data[kk]].
prob );
941 weight += input->
data[locs2->data[kk]].
prob * input->
data[locs2->data[kk]].
prob;
942 if ( mindf > input->
data[locs2->data[kk]].
moddepth || mindf == 0.0 ) {
945 if ( maxdf < input->
data[locs2->data[kk]].moddepth ) {
950 besth0 = input->
data[locs2->data[kk]].
h0;
952 bestR = input->
data[locs2->data[kk]].
stat;
953 bestProb = input->
data[locs2->data[kk]].
prob;
957 usedcandidate->data[locs2->data[kk]] = 1;
959 avefsig = avefsig / weight;
960 aveperiod = aveperiod / weight;
962 INT4 proberrcode = 0;
964 if ( loc2 > 1 && aveperiod >=
params->Pmin - 1.0 && aveperiod <= params->Pmax + 1.0 ) {
965 UINT4 numofmoddepths = (
UINT4 )floorf( 2 * ( maxdf - mindf ) *
params->Tsft ) + 1;
970 for (
UINT4 kk = 0; kk < numofmoddepths; kk++ ) {
971 if ( ( mindf + kk * 0.5 /
params->Tsft ) >=
params->dfmin && ( mindf + kk * 0.5 /
params->Tsft ) <=
params->dfmax ) {
973 loadCandidateData( &cand, avefsig, aveperiod, mindf + kk * 0.5 /
params->Tsft, input->
data[0].
ra, input->
data[0].
dec, 0, 0, 0.0, 0, 0.0, -1, 0 );
975 if ( exactflag == 1 ) {
983 REAL8 prob =
probR(
template, ffplanenoise, fbinaveratios, R,
params, rng, &proberrcode );
986 if ( prob < bestProb ) {
987 bestmoddepth = mindf + kk * 0.5 /
params->Tsft;
990 bestproberrcode = proberrcode;
999 if ( bestProb != 0.0 ) {
1000 if ( bestR > 0.0 ) {
1001 besth0 = 2.7426 * pow( bestR / (
params->Tsft *
params->Tobs ), 0.25 );
1006 if ( ( *output )->numofcandidates == ( *output )->length - 1 ) {
1009 loadCandidateData( &( ( *output )->data[( *output )->numofcandidates] ), avefsig, aveperiod, bestmoddepth, input->
data[0].
ra, input->
data[0].
dec, bestR, besth0, bestProb, bestproberrcode, input->
data[0].
normalization, -1, 0 );
1010 ( *output )->numofcandidates++;
1019 if ( usedcandidate->data[jj] == 0 ) {
1029 locs->
data[jj] = -1;
1030 locs2->data[jj] = -1;
1038 if ( exactflag == 1 ) {
1042 fprintf( stderr,
"Clustering done with candidates = %d\n", ( *output )->numofcandidates );
1043 fprintf(
LOG,
"Clustering done with candidates = %d\n", ( *output )->numofcandidates );
1065 XLAL_CHECK( *
output != NULL && ihsCandidates != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL &&
params != NULL && rng != NULL,
XLAL_EINVAL );
1068 INT4 proberrcode = 0;
1078 INT4 candidatesoutsideofmainULrange = 0;
1079 REAL8 log10templatefar = log10(
params->tmplfar );
1088 REAL8 R, prob, bestPeriod = 0.0, bestR = 0.0, bestProb = 0.0;
1089 INT4 bestproberrcode = 0;
1096 if (
params->calcRthreshold ) {
1101 R =
calculateR( ffdata->
ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
1103 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
1108 if ( ( !
params->calcRthreshold && prob < log10templatefar ) || (
params->calcRthreshold && R > farval->
far ) ) {
1116 REAL8 periodfact = 0.0;
1117 for (
UINT4 jj = 0; jj <= 1; jj++ ) {
1119 for (
INT4 kk = 2; kk <=
params->periodHarmToCheck; kk++ ) {
1121 periodfact = 1.0 / (
REAL8 )kk;
1123 periodfact = (
REAL8 )kk;
1126 ihsCandidates->
data[ii].
period *= periodfact;
1128 R =
calculateR( ffdata->
ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
1130 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
1132 if (
params->calcRthreshold && bestProb == 0.0 ) {
1135 if ( ( bestProb != 0.0 && prob < bestProb ) || ( bestProb == 0.0 && !
params->calcRthreshold && prob < log10templatefar ) || ( bestProb == 0.0 &&
params->calcRthreshold && R > farval->
far ) ) {
1139 bestproberrcode = proberrcode;
1141 ihsCandidates->
data[ii].
period /= periodfact;
1146 for (
INT4 kk = 1; kk <=
params->periodFracToCheck; kk++ ) {
1148 periodfact = ( kk + 1.0 ) / ( kk + 2.0 );
1150 periodfact = ( kk + 2.0 ) / ( kk + 1.0 );
1153 ihsCandidates->
data[ii].
period *= periodfact;
1155 R =
calculateR( ffdata->
ffdata,
template, aveNoise, aveTFnoisePerFbinRatio );
1157 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
1159 if (
params->calcRthreshold && bestProb == 0.0 ) {
1162 if ( ( bestProb != 0.0 && prob < bestProb ) || ( bestProb == 0.0 && !
params->calcRthreshold && prob < log10templatefar ) || ( bestProb == 0.0 &&
params->calcRthreshold && R > farval->
far ) ) {
1166 bestproberrcode = proberrcode;
1168 ihsCandidates->
data[ii].
period /= periodfact;
1173 if ( bestProb != 0.0 ) {
1175 if ( bestR > 0.0 ) {
1176 h0 = 2.7426 * sqrt( sqrt( bestR / (
params->Tsft *
params->Tobs ) ) );
1179 if ( ( *output )->numofcandidates == ( *output )->length - 1 ) {
1182 loadCandidateData( &( ( *output )->data[( *output )->numofcandidates] ), ihsCandidates->
data[ii].
fsig, bestPeriod, ihsCandidates->
data[ii].
moddepth,
pos.longitude,
pos.latitude, bestR,
h0, bestProb, bestproberrcode, ihsCandidates->
data[ii].
normalization, -1, ihsCandidates->
data[ii].
lineContamination );
1183 ( *output )->numofcandidates++;
1188 candidatesoutsideofmainULrange++;
1199 fprintf( stderr,
"%d remaining candidate(s) inside UL range.\n", ihsCandidates->
numofcandidates - candidatesoutsideofmainULrange );
1200 fprintf( stderr,
"Initial stage done with candidates = %d\n", ( *output )->numofcandidates );
1201 fprintf(
LOG,
"Initial stage done with candidates = %d\n", ( *output )->numofcandidates );
1225 XLAL_CHECK(
output != NULL && templateVec != NULL && ffdata != NULL && aveNoise != NULL && aveTFnoisePerFbinRatio != NULL &&
params != NULL && rng != NULL,
XLAL_EINVAL );
1227 fprintf( stderr,
"Testing TwoSpectTemplateVector... " );
1232 INT4 proberrcode = 0;
1240 for (
UINT4 ii = 0; ii < numfbins; ii++ ) {
1242 for (
UINT4 jj = 0; jj < templateVec->
length; jj++ ) {
1253 prob =
probR(
template, aveNoise, aveTFnoisePerFbinRatio, R,
params, rng, &proberrcode );
1262 if ( prob < output->
data[
output->length - 1].prob ) {
1264 while ( insertionPoint > 0 && prob < output->
data[insertionPoint - 1].prob ) {
1268 loadCandidateData( &(
output->data[kk + 1] ),
output->data[kk].fsig,
output->data[kk].period,
output->data[kk].moddepth,
output->data[kk].ra,
output->data[kk].dec,
output->data[kk].stat,
output->data[kk].h0,
output->data[kk].prob,
output->data[kk].proberrcode,
output->data[kk].normalization,
output->data[kk].templateVectorIndex,
output->data[kk].lineContamination );
1270 loadCandidateData( &(
output->data[insertionPoint] ), template->f0, template->period, template->moddepth, skypos.
longitude, skypos.
latitude, R,
h0, prob, proberrcode, ffdata->
tfnormalization, jj, 0 );
1272 output->numofcandidates++;
1313 loadCandidateData( &(
output->data[ii] ), input->
data[ii].
fsig, input->
data[ii].
period, input->
data[ii].
moddepth, input->
data[ii].
ra, input->
data[ii].
dec, input->
data[ii].
stat, input->
data[ii].
h0, input->
data[ii].
prob, input->
data[ii].
proberrcode, input->
data[ii].
normalization, input->
data[ii].
templateVectorIndex, input->
data[ii].
lineContamination );
1323 REAL8 highestsignificance = 0.0;
1324 INT4 candidateWithHighestSignificance = 0;
1326 if ( input->
data[jj].
prob > highestsignificance ) {
1327 highestsignificance = input->
data[jj].
prob;
1328 candidateWithHighestSignificance = jj;
1332 loadCandidateData( &(
output->data[ii] ), input->
data[candidateWithHighestSignificance].
fsig, input->
data[candidateWithHighestSignificance].
period, input->
data[candidateWithHighestSignificance].
moddepth, input->
data[candidateWithHighestSignificance].
ra, input->
data[candidateWithHighestSignificance].
dec, input->
data[candidateWithHighestSignificance].
stat, input->
data[candidateWithHighestSignificance].
h0, input->
data[candidateWithHighestSignificance].
prob, input->
data[candidateWithHighestSignificance].
proberrcode, input->
data[candidateWithHighestSignificance].
normalization, input->
data[candidateWithHighestSignificance].
templateVectorIndex, input->
data[candidateWithHighestSignificance].
lineContamination );
1334 input->
data[candidateWithHighestSignificance].
prob = 0.0;
1341 fprintf( stderr,
"%s: keepOnlyTopNumIHS given (%d) is not greater than 0, but it should be to use this function.\n",
__func__,
params->keepOnlyTopNumIHS );
1363 REAL8 sumofsqweights = 0.0;
1364 for (
UINT4 ii = 0; ii <
template->templatedata->length; ii++ )
if ( template->templatedata->data[ii] != 0.0 ) {
1365 sumofsqweights += (
template->templatedata->data[ii] *
template->templatedata->data[ii] );
1368 REAL8 sumofsqweightsinv = 1.0 / sumofsqweights;
1373 for (
UINT4 ii = 0; ii <
template->templatedata->length; ii++ ) {
1374 if ( template->templatedata->data[ii] != 0.0 ) {
1375 UINT4 firstfreqbin =
template->pixellocations->data[ii] / numfprbins;
1376 UINT4 secfreqbin =
template->pixellocations->data[ii] - firstfreqbin * numfprbins;
1377 R += ( ffdata->
data[
template->pixellocations->data[ii] ] - noise->
data[secfreqbin] * fbinaveratios->
data[firstfreqbin] ) * template->templatedata->data[ii] * sumofsqweightsinv;
1389 FILE *CANDFILE = NULL;
1391 if (
stat( outputfile, &buf ) == -1 && errno == ENOENT ) {
1392 XLAL_CHECK( ( CANDFILE = fopen( outputfile,
"w" ) ) != NULL,
XLAL_EIO,
"Couldn't fopen file %s to output candidates\n", outputfile );
1393 fprintf( CANDFILE,
"# TwoSpect candidates output file\n" );
1394 fprintf( CANDFILE,
"# Freq Period Mod. depth RA DEC Statistic val. Est. h0 False alarm prob. TF normalization Template vec. num. Line contam.\n" );
1396 XLAL_CHECK( ( CANDFILE = fopen( outputfile,
"a" ) ) != NULL,
XLAL_EIO,
"Couldn't fopen file %s to output candidates\n", outputfile );
1400 fprintf( CANDFILE,
"%.6f %.6f %.7f %.4f %.4f %.4f %g %.4f %g %d %d\n", input->
data[ii].
fsig, input->
data[ii].
period, input->
data[ii].
moddepth, input->
data[ii].
ra, input->
data[ii].
dec, input->
data[ii].
stat, input->
data[ii].
h0, input->
data[ii].
prob, input->
data[ii].
normalization, input->
data[ii].
templateVectorIndex, input->
data[ii].
lineContamination );
1416 REAL8 maxB = 0.5 * period / ( cohtime * cohtime );
1429 REAL8 minP = 2.0 * moddepth * cohtime * cohtime;
#define __func__
log an I/O error, i.e.
INT4 templateSearch_scox1Style(candidateVector **output, const REAL8 fminimum, const REAL8 fspan, const REAL8 period, const REAL8 asini, const REAL8 asinisigma, const SkyPosition skypos, const UserInput_t *params, const REAL4VectorAligned *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const REAL4VectorSequence *trackedlines, const REAL4FFTPlan *secondFFTplan, const gsl_rng *rng, BOOLEAN useExactTemplates)
A brute force template search to find the most significant template around a putative source whose pa...
REAL8 minPeriod(const REAL8 moddepth, const REAL8 cohtime)
Calculates minimum period allowed, equation 6 of E.
candidateVector * keepMostSignificantCandidates(const candidateVector *input, const UserInput_t *params)
Keep the most significant candidates, potentially reducing the number of candidates if there are more...
candidateVector * createcandidateVector(const UINT4 length)
Allocate a candidateVector.
INT4 testIHScandidates(candidateVector **output, const candidateVector *ihsCandidates, const ffdataStruct *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const SkyPosition pos, const UserInput_t *params, const gsl_rng *rng)
Function to test the IHS candidates against Gaussian templates.
INT4 analyzeCandidatesTemplateFromVector(candidateVector *output, const candidateVector *input, const TwoSpectTemplateVector *vector, const ffdataStruct *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const UserInput_t *params, const gsl_rng *rng, const UINT4 templateLen)
REAL8 calculateR(const REAL4VectorAligned *ffdata, const TwoSpectTemplate *template, const REAL4VectorAligned *noise, const REAL4VectorAligned *fbinaveratios)
Calculate the R statistic from equation 13 of E.
candidateVector * resizecandidateVector(candidateVector *vector, const UINT4 length)
Resize a candidateVector.
INT4 writeCandidateVector2File(const CHAR *outputfile, const candidateVector *input)
INT4 bruteForceTemplateSearch(candidate *output, const candidate input, const TwoSpectParamSpaceSearchVals *paramspace, const UserInput_t *params, const REAL4VectorAligned *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const REAL4FFTPlan *secondFFTplan, const gsl_rng *rng, const BOOLEAN useExactTemplates)
A brute force template search to find the most significant template around a candidate.
REAL8 maxModDepth(const REAL8 period, const REAL8 cohtime)
Calculates maximum modulation depth allowed, equation 6 of E.
INT4 bruteForceTemplateTest(candidateVector **output, const candidate input, const TwoSpectParamSpaceSearchVals *paramspace, const UserInput_t *params, const REAL4VectorAligned *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const REAL4FFTPlan *secondFFTplan, const gsl_rng *rng, const BOOLEAN useExactTemplates)
A brute force template search to test templates around a candidate.
INT4 testTwoSpectTemplateVector(candidateVector *output, const TwoSpectTemplateVector *templateVec, const ffdataStruct *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const SkyPosition skypos, const UserInput_t *params, const gsl_rng *rng, const UINT4 templateLen)
Test each of the templates in a TwoSpectTemplateVector and keep the top 10 This will not check the fa...
INT4 clusterCandidates(candidateVector **output, const candidateVector *input, const ffdataStruct *ffdata, const UserInput_t *params, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const gsl_rng *rng, const BOOLEAN exactflag)
Cluster candidates by frequency, period, and modulation depth using templates.
INT4 analyzeOneTemplate(candidate *output, const candidate *input, const ffdataStruct *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const UserInput_t *params, const REAL4FFTPlan *plan, const gsl_rng *rng, const BOOLEAN exactflag)
Analyze a single template.
void destroycandidateVector(candidateVector *vector)
Free a candidateVector.
void loadCandidateData(candidate *output, const REAL8 fsig, const REAL8 period, const REAL8 moddepth, const REAL4 ra, const REAL4 dec, const REAL8 statval, const REAL8 h0, const REAL8 prob, const INT4 proberrcode, const REAL8 normalization, const INT4 templateVectorIndex, const BOOLEAN lineContamination)
Load candidate data.
INT4 templateSearch_fixedDf(candidateVector **output, const LALStringVector *dffixed, const REAL8 fminimum, const REAL8 fspan, const REAL8 period, const SkyPosition skypos, const UserInput_t *params, const REAL4VectorAligned *ffdata, const REAL4VectorAligned *aveNoise, const REAL4VectorAligned *aveTFnoisePerFbinRatio, const REAL4VectorSequence *trackedlines, const REAL4FFTPlan *secondFFTplan, const gsl_rng *rng, BOOLEAN useExactTemplates)
A brute force template search to find the most significant template at a fixed modulation depth aroun...
farStruct * createfarStruct(void)
Allocate memory for farStruct.
REAL8 probR(const TwoSpectTemplate *template, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const REAL8 R, const UserInput_t *params, const gsl_rng *rng, INT4 *errcode)
Analytically calculate the probability of a true signal using the Davies' method.
INT4 numericFAR(farStruct *output, const TwoSpectTemplate *template, const REAL8 thresh, const REAL4VectorAligned *ffplanenoise, const REAL4VectorAligned *fbinaveratios, const UserInput_t *inputParams, const gsl_rng *rng, const INT4 method)
Numerically solve for the FAR of the R statistic from the weights using the Davies algorithm and a ro...
void destroyfarStruct(farStruct *farstruct)
Destroy an farStruct.
#define XLAL_INIT_DECL(var,...)
void * XLALMalloc(size_t n)
void * XLALRealloc(void *p, size_t n)
REAL4FFTPlan * XLALCreateForwardREAL4FFTPlan(UINT4 size, int measurelvl)
void XLALDestroyREAL4FFTPlan(REAL4FFTPlan *plan)
INT4Vector * XLALCreateINT4Vector(UINT4 length)
void XLALDestroyINT4Vector(INT4Vector *vector)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_VOID(...)
#define XLAL_ERROR_NULL(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_VOID(assertion,...)
#define XLAL_CHECK_REAL8(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
REAL4 periodSpacingFactor
REAL4VectorAligned * templatedata
BOOLEAN lineContamination
REAL4VectorAligned * ffdata
INT4 makeTemplate(TwoSpectTemplate *output, const candidate input, const UserInput_t *params, const REAL4FFTPlan *plan)
Make an template based on FFT of sinc squared functions.
void resetTwoSpectTemplate(TwoSpectTemplate *template)
Reset the values in a TwoSpectTemplate.
TwoSpectTemplate * createTwoSpectTemplate(const UINT4 length)
Allocate a new TwoSpectTemplate.
void destroyTwoSpectTemplate(TwoSpectTemplate *template)
Free a TwoSpectTemplate.
INT4 convertTemplateForSpecificFbin(TwoSpectTemplate *output, const TwoSpectTemplate *input, const REAL8 freq, const UserInput_t *params)
Convert an arbitrary frequency bin template into a template for a specific frequency bin.
INT4 makeTemplateGaussians(TwoSpectTemplate *output, const candidate input, const UserInput_t *params)
Make an estimated template based on FFT of train of Gaussians.