21#include <gsl/gsl_roots.h>
43 for (
UINT4 ii = 0; ii < length; ii++ ) {
74 for (
UINT4 ii = oldlength; ii < length; ii++ ) {
117 ul->effSNRval = NULL;
133 if (
ul->moddepth ) {
139 if (
ul->effSNRval ) {
172 const gsl_root_fsolver_type *
T = gsl_root_fsolver_brent;
173 gsl_root_fsolver *
s = NULL;
176 switch (
params->ULsolver ) {
199 for (
INT4 ii = minrows; ii <= ihsmaxima->
rows; ii++ ) {
200 REAL8 loudestoutlier = 0.0, loudestoutlierminusnoise = 0.0, loudestoutliernoise = 0.0;
201 INT4 jjbinofloudestoutlier = 0, locationofloudestoutlier = -1;
202 INT4 startpositioninmaximavector = ( ii - 2 ) * ffdata->
numfbins - ( ( ii - 1 ) * ( ii - 1 ) - ( ii - 1 ) ) / 2;
203 REAL8 moddepth = 0.5 * ( ii - 1.0 ) /
params->Tsft;
206 for (
INT4 jj = 0; jj < ffdata->
numfbins - ( ii - 1 ); jj++ ) {
207 INT4 locationinmaximavector = startpositioninmaximavector + jj;
211 REAL8 totalnoise = 0.0;
212 for (
INT4 kk = 0; kk < ii; kk++ ) {
213 totalnoise += fbinavgs->
data[jj + kk];
215 totalnoise = noise * totalnoise;
217 REAL8 ihsminusnoise = ihsmaxima->
maxima->
data[locationinmaximavector] - totalnoise;
221 if ( ihsminusnoise > loudestoutlierminusnoise &&
222 ( fsig >=
params->ULfmin && fsig < params->ULfmin +
params->ULfspan ) &&
223 ( moddepth >=
params->ULminimumDeltaf && moddepth <=
params->ULmaximumDeltaf ) ) {
224 loudestoutlier = ihsmaxima->
maxima->
data[locationinmaximavector];
225 loudestoutliernoise = totalnoise;
226 loudestoutlierminusnoise = ihsminusnoise;
227 locationofloudestoutlier = ihsmaxima->
locations->
data[locationinmaximavector];
228 jjbinofloudestoutlier = jj;
232 if ( locationofloudestoutlier != -1 ) {
235 REAL8 initialguess =
ncx2inv_float( 0.95, 2.0 * loudestoutliernoise, 2.0 * loudestoutlierminusnoise );
238 REAL8 lo = 0.001 * initialguess, hi = 10.0 * initialguess;
239 pars.
val = 2.0 * loudestoutlier;
240 pars.
dof = 2.0 * loudestoutliernoise;
249 while (
status == GSL_CONTINUE && jj < max_iter ) {
251 status = gsl_root_fsolver_iterate(
s );
253 root = gsl_root_fsolver_root(
s );
254 lo = gsl_root_fsolver_x_lower(
s );
255 hi = gsl_root_fsolver_x_upper(
s );
256 status = gsl_root_test_interval( lo, hi, 0.0, 0.001 );
265 ul->fsig->data[ii - minrows] =
params->fmin -
params->dfmax + ( 0.5 * ( ii - 1.0 ) + jjbinofloudestoutlier - 6.0 ) /
params->Tsft;
266 ul->period->data[ii - minrows] =
params->Tobs / locationofloudestoutlier;
267 ul->moddepth->data[ii - minrows] = 0.5 * ( ii - 1.0 ) /
params->Tsft;
268 ul->ULval->data[ii - minrows] =
h0;
275 XLAL_CHECK( ULdetermined != 0,
XLAL_EFUNC,
"Failed to reach a louder outlier minus noise greater than 0\n" );
277 gsl_root_fsolver_free(
s );
292 return val - ( 1.0 -
params->ULpercent );
316 return val - ( 1.0 -
params->ULpercent );
340 return val - ( 1.0 -
params->ULpercent );
370 if (
stat( outputfile, &buf ) == -1 && errno == ENOENT ) {
371 XLAL_CHECK( ( ULFILE = fopen( outputfile,
"w" ) ) != NULL,
XLAL_EIO,
"Couldn't fopen file %s to output upper limits\n", outputfile );
372 fprintf( ULFILE,
"# TwoSpect upper limits output file\n" );
373 fprintf( ULFILE,
"# RA DEC Upper limit SNR_eff Freq Period Mod. depth UL normalization\n" );
375 XLAL_CHECK( ( ULFILE = fopen( outputfile,
"a" ) ) != NULL,
XLAL_EIO,
"Couldn't fopen file %s to output upper limits\n", outputfile );
378 REAL8 highesth0 = 0.0, snr = 0.0, fsig = 0.0, period = 0.0, moddepth = 0.0;
379 for (
UINT4 ii = 0; ii <
ul.moddepth->length; ii++ ) {
380 if ( printAllULvalues == 1 ) {
381 fprintf( ULFILE,
"%.6f %.6f %.6g %.6f %.6f %.6f %.6f %.6g\n",
ul.alpha,
ul.delta,
ul.ULval->data[ii],
ul.effSNRval->data[ii],
ul.fsig->data[ii],
ul.period->data[ii],
ul.moddepth->data[ii],
ul.normalization );
382 }
else if ( printAllULvalues == 0 &&
ul.ULval->data[ii] > highesth0 ) {
383 highesth0 =
ul.ULval->data[ii];
384 snr =
ul.effSNRval->data[ii];
385 fsig =
ul.fsig->data[ii];
386 period =
ul.period->data[ii];
387 moddepth =
ul.moddepth->data[ii];
390 if ( printAllULvalues == 0 ) {
391 fprintf( ULFILE,
"%.6f %.6f %.6g %.6f %.6f %.6f %.6f %.6g\n",
ul.alpha,
ul.delta, highesth0, snr, fsig, period, moddepth,
ul.normalization );
REAL8 ihs2h0(const REAL8 ihsval, const UserInput_t *params)
Convert the IHS statistic to an estimated h0, based on injections.
REAL8 unitGaussianSNR(REAL8 value, REAL8 dof)
REAL4 ncx2cdf_float(REAL4 x, REAL4 dof, REAL4 delta)
REAL4 ncx2inv_float(REAL8 p, REAL8 dof, REAL8 delta)
REAL8 ncx2cdf_withouttinyprob_withmatlabchi2cdf(REAL8 x, REAL8 dof, REAL8 delta)
REAL4 ncx2cdf_float_withouttinyprob_withmatlabchi2cdf(REAL4 x, REAL4 dof, REAL4 delta)
REAL8 ncx2cdf_withouttinyprob(REAL8 x, REAL8 dof, REAL8 delta)
REAL8 ncx2cdf(REAL8 x, REAL8 dof, REAL8 delta)
Matlab's version of the non-central chi-squared CDF with nu degrees of freedom and non-centrality del...
REAL4 ncx2cdf_float_withouttinyprob(REAL4 x, REAL4 dof, REAL4 delta)
#define XLAL_INIT_DECL(var,...)
void * XLALMalloc(size_t n)
void * XLALRealloc(void *p, size_t n)
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_VOID(...)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_REAL8(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
p
RUN ANALYSIS SCRIPT ###.
REAL4VectorAligned * maxima
REAL4VectorAligned * expectedIHSVector
void destroyUpperLimitStruct(UpperLimit *ul)
Free an UpperLimit structure.
REAL8 gsl_ncx2cdf_withouttinyprob_solver(const REAL8 x, void *p)
REAL8 ncx2cdf_float_withouttinyprob_withmatlabchi2cdf_solver(REAL8 x, void *p)
REAL8 gsl_ncx2cdf_solver(const REAL8 x, void *p)
void destroyUpperLimitVector(UpperLimitVector *vector)
Free an UpperLimitVector.
INT4 skypoint95UL(UpperLimit *ul, const UserInput_t *params, const ffdataStruct *ffdata, const ihsMaximaStruct *ihsmaxima, const ihsfarStruct *ihsfar, const REAL4VectorAligned *fbinavgs)
Determine the 95% confidence level upper limit at a particular sky location from the loudest IHS valu...
UpperLimitVector * resizeUpperLimitVector(UpperLimitVector *vector, const UINT4 length)
Resize an UpperLimitVector.
REAL8 ncx2cdf_withouttinyprob_withmatlabchi2cdf_solver(const REAL8 x, void *p)
UpperLimitVector * createUpperLimitVector(const UINT4 length)
Allocate a new UpperLimitVector.
REAL8 gsl_ncx2cdf_float_solver(const REAL8 x, void *p)
REAL8 gsl_ncx2cdf_float_withouttinyprob_solver(const REAL8 x, void *p)
void resetUpperLimitStruct(UpperLimit *ul)
Reset an UpperLimitStruct.
INT4 outputUpperLimitToFile(const CHAR *outputfile, const UpperLimit ul, const BOOLEAN printAllULvalues)
Output the highest upper limit to a file unless printAllULvalues==1 in which case,...