/** * MAIN function * Generates samples of B-stat and F-stat according to their pdfs for given signal-params. */ int main(int argc,char *argv[]) { UserInput_t XLAL_INIT_DECL(uvar); ConfigVariables XLAL_INIT_DECL(cfg); vrbflg = 1; /* verbose error-messages */ /* turn off default GSL error handler */ gsl_set_error_handler_off (); /* ----- register and read all user-variables ----- */ if ( XLALInitUserVars( &uvar ) != XLAL_SUCCESS ) { LogPrintf ( LOG_CRITICAL, "%s: XLALInitUserVars() failed with errno=%d\n", __func__, xlalErrno ); return 1; } /* do ALL cmdline and cfgfile handling */ BOOLEAN should_exit = 0; if ( XLALUserVarReadAllInput ( &should_exit, argc, argv ) != XLAL_SUCCESS ) { LogPrintf ( LOG_CRITICAL, "%s: XLALUserVarReadAllInput() failed with errno=%d\n", __func__, xlalErrno ); return 1; } if ( should_exit ) return EXIT_FAILURE; if ( uvar.version ) { /* output verbose VCS version string if requested */ CHAR *vcs; if ( (vcs = XLALGetVersionString (lalDebugLevel)) == NULL ) { LogPrintf ( LOG_CRITICAL, "%s:XLALGetVersionString(%d) failed with errno=%d.\n", __func__, lalDebugLevel, xlalErrno ); return 1; } printf ( "%s\n", vcs ); XLALFree ( vcs ); return 0; } /* ---------- Initialize code-setup ---------- */ if ( XLALInitCode( &cfg, &uvar ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: XLALInitCode() failed with error = %d\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } /* compare IFO name for line injection with IFO list, find the corresponding index, or throw an error if not found */ UINT4 numDetectors = cfg.multiDetStates->length; INT4 lineX = -1; if ( uvar.lineIFO ) { for ( UINT4 X=0; X < numDetectors; X++ ) { if ( strcmp( uvar.lineIFO, uvar.IFOs->data[X] ) == 0 ) lineX = X; } if ( lineX == -1 ) { XLALPrintError ("\nError in function %s, line %d : Could not match detector ID \"%s\" for line injection to any detector.\n\n", __func__, __LINE__, uvar.lineIFO); XLAL_ERROR ( XLAL_EFAILED ); } } /* ----- prepare stats output ----- */ FILE *fpStats = NULL; if ( uvar.outputStats ) { if ( (fpStats = fopen (uvar.outputStats, "wb")) == NULL) { LogPrintf (LOG_CRITICAL, "Error opening file '%s' for writing..\n\n", uvar.outputStats ); XLAL_ERROR ( XLAL_EIO ); } fprintf (fpStats, "%s", cfg.logString ); /* write search log comment */ if ( write_BSGL_candidate_to_fp ( fpStats, NULL, uvar.IFOs, NULL, uvar.computeBSGL ) != XLAL_SUCCESS ) { /* write header-line comment */ XLAL_ERROR ( XLAL_EFUNC ); } } /* if outputStats */ /* ----- prepare injection params output ----- */ FILE *fpInjParams = NULL; if ( uvar.outputInjParams ) { if ( (fpInjParams = fopen (uvar.outputInjParams, "wb")) == NULL) { LogPrintf (LOG_CRITICAL, "Error opening file '%s' for writing..\n\n", uvar.outputInjParams ); XLAL_ERROR ( XLAL_EIO ); } fprintf (fpInjParams, "%s", cfg.logString ); /* write search log comment */ if ( write_InjParams_to_fp ( fpInjParams, NULL, 0, uvar.outputMmunuX, numDetectors ) != XLAL_SUCCESS ) { /* write header-line comment */ XLAL_ERROR ( XLAL_EFUNC ); } } /* if outputInjParams */ multiAMBuffer_t XLAL_INIT_DECL(multiAMBuffer); /* prepare AM-buffer */ /* ----- prepare BSGL computation */ BSGLSetup *BSGLsetup = NULL; if ( uvar.computeBSGL ) { BOOLEAN useLogCorrection = TRUE; REAL4 *oLGX_p = NULL; REAL4 oLGX[PULSAR_MAX_DETECTORS]; if ( uvar.oLGX != NULL ) { XLAL_CHECK ( uvar.oLGX->length == numDetectors, XLAL_EINVAL, "Invalid input: length(oLGX) = %d differs from number of detectors (%d)'\n", uvar.oLGX->length, numDetectors ); XLAL_CHECK ( XLALParseLinePriors ( &oLGX[0], uvar.oLGX ) == XLAL_SUCCESS, XLAL_EFUNC ); oLGX_p = &oLGX[0]; } XLAL_CHECK ( ( BSGLsetup = XLALCreateBSGLSetup ( numDetectors, uvar.Fstar0, oLGX_p, useLogCorrection ) ) != NULL, XLAL_EFUNC ); } // if computeBSGL /* ----- main MC loop over numDraws trials ---------- */ INT4 i; for ( i=0; i < uvar.numDraws; i ++ ) { InjParams_t XLAL_INIT_DECL(injParamsDrawn); /* ----- generate signal random draws from ranges and generate Fstat atoms */ MultiFstatAtomVector *multiAtoms; multiAtoms = XLALSynthesizeTransientAtoms ( &injParamsDrawn, cfg.skypos, cfg.AmpPrior, cfg.transientInjectRange, cfg.multiDetStates, cfg.SignalOnly, &multiAMBuffer, cfg.rng, lineX, cfg.multiNoiseWeights ); XLAL_CHECK ( multiAtoms != NULL, XLAL_EFUNC ); /* ----- if requested, output signal injection parameters into file */ if ( fpInjParams && (write_InjParams_to_fp ( fpInjParams, &injParamsDrawn, uvar.dataStartGPS, uvar.outputMmunuX, numDetectors ) != XLAL_SUCCESS ) ) { XLAL_ERROR ( XLAL_EFUNC ); } /* if fpInjParams & failure*/ /* initialise BSGLComponents structure and allocate memory */ BSGLComponents XLAL_INIT_DECL(synthStats); /* struct containing multi-detector Fstat, single-detector Fstats, line-robust stat */ synthStats.numDetectors = numDetectors; /* compute F- and BSGListics from atoms */ UINT4 X; for ( X=0; X < numDetectors; X++ ) { synthStats.TwoFX[X] = XLALComputeFstatFromAtoms ( multiAtoms, X ); if ( xlalErrno != 0 ) { XLALPrintError ("\nError in function %s, line %d : Failed call to XLALComputeFstatFromAtoms().\n\n", __func__, __LINE__); XLAL_ERROR ( XLAL_EFUNC ); } } synthStats.TwoF = XLALComputeFstatFromAtoms ( multiAtoms, -1 ); if ( xlalErrno != 0 ) { XLALPrintError ("\nError in function %s, line %d : Failed call to XLALComputeFstatFromAtoms().\n\n", __func__, __LINE__); XLAL_ERROR ( XLAL_EFUNC ); } if ( uvar.computeBSGL ) { synthStats.log10BSGL = XLALComputeBSGL ( synthStats.TwoF, synthStats.TwoFX, BSGLsetup ); XLAL_CHECK ( xlalErrno == 0, XLAL_EFUNC, "XLALComputeBSGL() failed with xlalErrno = %d\n", xlalErrno ); } /* ----- if requested, output atoms-vector into file */ if ( uvar.outputAtoms ) { FILE *fpAtoms; char *fnameAtoms; UINT4 len = strlen ( uvar.outputAtoms ) + 20; if ( (fnameAtoms = XLALCalloc ( 1, len )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, len ); XLAL_ERROR ( XLAL_EFUNC ); } sprintf ( fnameAtoms, "%s_%04d_of_%04d.dat", uvar.outputAtoms, i + 1, uvar.numDraws ); if ( ( fpAtoms = fopen ( fnameAtoms, "wb" )) == NULL ) { XLALPrintError ("%s: failed to open atoms-output file '%s' for writing.\n", __func__, fnameAtoms ); XLAL_ERROR ( XLAL_EFUNC ); } fprintf ( fpAtoms, "%s", cfg.logString ); /* output header info */ if ( write_MultiFstatAtoms_to_fp ( fpAtoms, multiAtoms ) != XLAL_SUCCESS ) { XLALPrintError ("%s: failed to write atoms to output file '%s'. xlalErrno = %d\n", __func__, fnameAtoms, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } XLALFree ( fnameAtoms ); fclose (fpAtoms); } /* if outputAtoms */ /* ----- if requested, output transient-cand statistics */ if ( fpStats && write_BSGL_candidate_to_fp ( fpStats, &synthStats, uvar.IFOs, &injParamsDrawn, uvar.computeBSGL ) != XLAL_SUCCESS ) { XLALPrintError ( "%s: write_transientCandidate_to_fp() failed.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } /* ----- free Memory */ XLALDestroyMultiFstatAtomVector ( multiAtoms ); } /* for i < numDraws */ /* ----- close files ----- */ if ( fpStats ) fclose ( fpStats ); if ( fpInjParams ) fclose ( fpInjParams ); /* ----- free memory ---------- */ XLALDestroyMultiDetectorStateSeries ( cfg.multiDetStates ); XLALDestroyMultiNoiseWeights ( cfg.multiNoiseWeights ); XLALDestroyExpLUT(); XLALDestroyMultiAMCoeffs ( multiAMBuffer.multiAM ); /* ----- free amplitude prior pdfs ----- */ XLALDestroyPDF1D ( cfg.AmpPrior.pdf_h0Nat ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_cosi ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_psi ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_phi0 ); XLALFree ( BSGLsetup ); BSGLsetup = NULL; if ( cfg.logString ) { XLALFree ( cfg.logString ); } gsl_rng_free ( cfg.rng ); XLALDestroyUserVars(); /* did we forget anything ? (doesn't cover gsl-memory!) */ LALCheckMemoryLeaks(); return 0; } /* main() */
/** * MAIN function * Generates samples of B-stat and F-stat according to their pdfs for given signal-params. */ int main(int argc,char *argv[]) { UserInput_t XLAL_INIT_DECL(uvar); ConfigVariables XLAL_INIT_DECL(cfg); /**< various derived configuration settings */ vrbflg = 1; /* verbose error-messages */ LogSetLevel(lalDebugLevel); /* turn off default GSL error handler */ gsl_set_error_handler_off (); /* ----- register and read all user-variables ----- */ LogSetLevel(lalDebugLevel); if ( XLALInitUserVars( &uvar ) != XLAL_SUCCESS ) { LogPrintf ( LOG_CRITICAL, "%s: XLALInitUserVars() failed with errno=%d\n", __func__, xlalErrno ); return 1; } /* do ALL cmdline and cfgfile handling */ if ( XLALUserVarReadAllInput ( argc, argv ) != XLAL_SUCCESS ) { LogPrintf ( LOG_CRITICAL, "%s: XLALUserVarReadAllInput() failed with errno=%d\n", __func__, xlalErrno ); return 1; } if (uvar.help) /* if help was requested, we're done here */ return 0; if ( uvar.version ) { /* output verbose VCS version string if requested */ CHAR *vcs; if ( (vcs = XLALGetVersionString (lalDebugLevel)) == NULL ) { LogPrintf ( LOG_CRITICAL, "%s:XLALGetVersionString(%d) failed with errno=%d.\n", __func__, lalDebugLevel, xlalErrno ); return 1; } printf ( "%s\n", vcs ); XLALFree ( vcs ); return 0; } /* ---------- Initialize code-setup ---------- */ if ( XLALInitCode( &cfg, &uvar ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: XLALInitCode() failed with error = %d\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } /* ----- prepare stats output ----- */ FILE *fpTransientStats = NULL; if ( uvar.outputStats ) { if ( (fpTransientStats = fopen (uvar.outputStats, "wb")) == NULL) { LogPrintf (LOG_CRITICAL, "Error opening file '%s' for writing..\n\n", uvar.outputStats ); XLAL_ERROR ( XLAL_EIO ); } fprintf (fpTransientStats, "%s", cfg.logString ); /* write search log comment */ if ( write_transientCandidate_to_fp ( fpTransientStats, NULL ) != XLAL_SUCCESS ) { /* write header-line comment */ XLAL_ERROR ( XLAL_EFUNC ); } } /* if outputStats */ /* ----- prepare injection params output ----- */ FILE *fpInjParams = NULL; if ( uvar.outputInjParams ) { if ( (fpInjParams = fopen (uvar.outputInjParams, "wb")) == NULL) { LogPrintf (LOG_CRITICAL, "Error opening file '%s' for writing..\n\n", uvar.outputInjParams ); XLAL_ERROR ( XLAL_EIO ); } fprintf (fpInjParams, "%s", cfg.logString ); /* write search log comment */ if ( write_InjParams_to_fp ( fpInjParams, NULL, 0, 0, 0 ) != XLAL_SUCCESS ) { /* write header-line comment - options outputMmunuX and numDetectors not supported here, so pass defaults to deactivate them */ XLAL_ERROR ( XLAL_EFUNC ); } } /* if outputInjParams */ /* ----- main MC loop over numDraws trials ---------- */ multiAMBuffer_t XLAL_INIT_DECL(multiAMBuffer); /* prepare AM-buffer */ INT4 i; for ( i=0; i < uvar.numDraws; i ++ ) { InjParams_t XLAL_INIT_DECL(injParamsDrawn); /* ----- generate signal random draws from ranges and generate Fstat atoms */ MultiFstatAtomVector *multiAtoms; multiAtoms = XLALSynthesizeTransientAtoms ( &injParamsDrawn, cfg.skypos, cfg.AmpPrior, cfg.transientInjectRange, cfg.multiDetStates, cfg.SignalOnly, &multiAMBuffer, cfg.rng, -1, NULL ); // options lineX and noise_weights not supported here, so pass defaults to deactivate them if ( multiAtoms ==NULL ) { LogPrintf ( LOG_CRITICAL, "%s: XLALSynthesizeTransientAtoms() failed with xlalErrno = %d\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } /* ----- if requested, output signal injection parameters into file */ if ( fpInjParams && (write_InjParams_to_fp ( fpInjParams, &injParamsDrawn, uvar.dataStartGPS, 0, 0 ) ) != XLAL_SUCCESS ) { // options outputMmunuX and numDetectors not supported here, so pass defaults to deactivate them XLAL_ERROR ( XLAL_EFUNC ); } /* if fpInjParams & failure*/ /* ----- add meta-info on current transient-CW candidate */ transientCandidate_t XLAL_INIT_DECL(cand); cand.doppler.Alpha = multiAMBuffer.skypos.longitude; cand.doppler.Delta = multiAMBuffer.skypos.latitude; cand.windowRange = cfg.transientSearchRange; /* ----- if needed: compute transient-Bstat search statistic on these atoms */ if ( fpTransientStats || uvar.outputFstatMap || uvar.outputPosteriors ) { /* compute Fstat map F_mn over {t0, tau} */ if ( (cand.FstatMap = XLALComputeTransientFstatMap ( multiAtoms, cand.windowRange, uvar.useFReg)) == NULL ) { XLALPrintError ("%s: XLALComputeTransientFstatMap() failed with xlalErrno = %d.\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } } /* if we'll need the Fstat-map F_mn */ /* ----- if requested compute marginalized Bayes factor */ if ( fpTransientStats ) { cand.logBstat = XLALComputeTransientBstat ( cand.windowRange, cand.FstatMap ); UINT4 err = xlalErrno; if ( err ) { XLALPrintError ("%s: XLALComputeTransientBstat() failed with xlalErrno = %d\n", __func__, err ); XLAL_ERROR ( XLAL_EFUNC ); } if ( uvar.SignalOnly ) { cand.FstatMap->maxF += 2; cand.logBstat += 2; } } /* if Bstat requested */ /* ----- if requested, compute parameter posteriors for {t0, tau} */ pdf1D_t *pdf_t0 = NULL; pdf1D_t *pdf_tau = NULL; if ( fpTransientStats || uvar.outputPosteriors ) { if ( (pdf_t0 = XLALComputeTransientPosterior_t0 ( cand.windowRange, cand.FstatMap )) == NULL ) { XLALPrintError ("%s: failed to compute t0-posterior\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } if ( (pdf_tau = XLALComputeTransientPosterior_tau ( cand.windowRange, cand.FstatMap )) == NULL ) { XLALPrintError ("%s: failed to compute tau-posterior\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } /* get maximum-posterior estimate (MP) from the modes of these pdfs */ cand.t0_MP = XLALFindModeOfPDF1D ( pdf_t0 ); if ( xlalErrno ) { XLALPrintError ("%s: mode-estimation failed for pdf_t0. xlalErrno = %d\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } cand.tau_MP = XLALFindModeOfPDF1D ( pdf_tau ); if ( xlalErrno ) { XLALPrintError ("%s: mode-estimation failed for pdf_tau. xlalErrno = %d\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } } // if posteriors required /* ----- if requested, compute Ftotal over full data-span */ if ( uvar.computeFtotal ) { transientFstatMap_t *FtotalMap; /* prepare special window to cover all the data with one F-stat calculation == Ftotal */ transientWindowRange_t XLAL_INIT_DECL(winRangeAll); winRangeAll.type = TRANSIENT_NONE; BOOLEAN useFReg = false; if ( (FtotalMap = XLALComputeTransientFstatMap ( multiAtoms, winRangeAll, useFReg)) == NULL ) { XLALPrintError ("%s: XLALComputeTransientFstatMap() failed with xlalErrno = %d.\n", __func__, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } /* we only use twoFtotal = 2 * maxF from this single-Fstat calculation */ REAL8 twoFtotal = 2.0 * FtotalMap->maxF; if ( uvar.SignalOnly ) twoFtotal += 4; /* ugly hack: lacking a good container for twoFtotal, we borrow fkdot[3] for this here ;) [only used for paper-MCs] */ cand.doppler.fkdot[3] = twoFtotal; /* good riddance .. */ XLALDestroyTransientFstatMap ( FtotalMap ); } /* if computeFtotal */ /* ----- if requested, output atoms-vector into file */ if ( uvar.outputAtoms ) { FILE *fpAtoms; char *fnameAtoms; UINT4 len = strlen ( uvar.outputAtoms ) + 20; if ( (fnameAtoms = XLALCalloc ( 1, len )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, len ); XLAL_ERROR ( XLAL_EFUNC ); } sprintf ( fnameAtoms, "%s_%04d_of_%04d.dat", uvar.outputAtoms, i + 1, uvar.numDraws ); if ( ( fpAtoms = fopen ( fnameAtoms, "wb" )) == NULL ) { XLALPrintError ("%s: failed to open atoms-output file '%s' for writing.\n", __func__, fnameAtoms ); XLAL_ERROR ( XLAL_EFUNC ); } fprintf ( fpAtoms, "%s", cfg.logString ); /* output header info */ if ( write_MultiFstatAtoms_to_fp ( fpAtoms, multiAtoms ) != XLAL_SUCCESS ) { XLALPrintError ("%s: failed to write atoms to output file '%s'. xlalErrno = %d\n", __func__, fnameAtoms, xlalErrno ); XLAL_ERROR ( XLAL_EFUNC ); } XLALFree ( fnameAtoms ); fclose (fpAtoms); } /* if outputAtoms */ /* ----- if requested, output Fstat-map over {t0, tau} */ if ( uvar.outputFstatMap ) { FILE *fpFstatMap; char *fnameFstatMap; UINT4 len = strlen ( uvar.outputFstatMap ) + 20; if ( (fnameFstatMap = XLALCalloc ( 1, len )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, len ); XLAL_ERROR ( XLAL_EFUNC ); } sprintf ( fnameFstatMap, "%s_%04d_of_%04d.dat", uvar.outputFstatMap, i + 1, uvar.numDraws ); if ( ( fpFstatMap = fopen ( fnameFstatMap, "wb" )) == NULL ) { XLALPrintError ("%s: failed to open Fstat-map output file '%s' for writing.\n", __func__, fnameFstatMap ); XLAL_ERROR ( XLAL_EFUNC ); } fprintf ( fpFstatMap, "%s", cfg.logString ); /* output header info */ fprintf (fpFstatMap, "\nFstat_mn = \\\n" ); if ( XLALfprintfGSLmatrix ( fpFstatMap, "%.9g", cand.FstatMap->F_mn ) != XLAL_SUCCESS ) { XLALPrintError ("%s: XLALfprintfGSLmatrix() failed.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } XLALFree ( fnameFstatMap ); fclose (fpFstatMap); } /* if outputFstatMap */ /* ----- if requested, output posterior pdfs on transient params {t0, tau} into a file */ if ( uvar.outputPosteriors ) { FILE *fpPosteriors; char *fnamePosteriors; UINT4 len = strlen ( uvar.outputPosteriors ) + 20; if ( (fnamePosteriors = XLALCalloc ( 1, len )) == NULL ) { XLALPrintError ("%s: failed to XLALCalloc ( 1, %d )\n", __func__, len ); XLAL_ERROR ( XLAL_EFUNC ); } sprintf ( fnamePosteriors, "%s_%04d_of_%04d.dat", uvar.outputPosteriors, i + 1, uvar.numDraws ); if ( ( fpPosteriors = fopen ( fnamePosteriors, "wb" )) == NULL ) { XLALPrintError ("%s: failed to open posteriors-output file '%s' for writing.\n", __func__, fnamePosteriors ); XLAL_ERROR ( XLAL_EFUNC ); } fprintf ( fpPosteriors, "%s", cfg.logString ); /* output header info */ /* write them to file, using pdf-method */ if ( XLALOutputPDF1D_to_fp ( fpPosteriors, pdf_t0, "pdf_t0" ) != XLAL_SUCCESS ) { XLALPrintError ("%s: failed to output t0-posterior to file '%s'.\n", __func__, fnamePosteriors ); XLAL_ERROR ( XLAL_EFUNC ); } if ( XLALOutputPDF1D_to_fp ( fpPosteriors, pdf_tau, "pdf_tau" ) != XLAL_SUCCESS ) { XLALPrintError ("%s: failed to output tau-posterior to file '%s'.\n", __func__, fnamePosteriors ); XLAL_ERROR ( XLAL_EFUNC ); } /* free mem, close file */ XLALFree ( fnamePosteriors ); fclose (fpPosteriors); } /* if outputPosteriors */ /* ----- if requested, output transient-cand statistics */ if ( fpTransientStats && write_transientCandidate_to_fp ( fpTransientStats, &cand ) != XLAL_SUCCESS ) { XLALPrintError ( "%s: write_transientCandidate_to_fp() failed.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } /* ----- free Memory */ XLALDestroyTransientFstatMap ( cand.FstatMap ); XLALDestroyMultiFstatAtomVector ( multiAtoms ); XLALDestroyPDF1D ( pdf_t0 ); XLALDestroyPDF1D ( pdf_tau ); } /* for i < numDraws */ /* ----- close files ----- */ if ( fpTransientStats) fclose ( fpTransientStats ); if ( fpInjParams ) fclose ( fpInjParams ); /* ----- free memory ---------- */ XLALDestroyMultiDetectorStateSeries ( cfg.multiDetStates ); XLALDestroyMultiAMCoeffs ( multiAMBuffer.multiAM ); XLALDestroyExpLUT(); /* ----- free amplitude prior pdfs ----- */ XLALDestroyPDF1D ( cfg.AmpPrior.pdf_h0Nat ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_cosi ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_psi ); XLALDestroyPDF1D ( cfg.AmpPrior.pdf_phi0 ); if ( cfg.logString ) XLALFree ( cfg.logString ); gsl_rng_free ( cfg.rng ); XLALDestroyUserVars(); /* did we forget anything ? (doesn't cover gsl-memory!) */ LALCheckMemoryLeaks(); return 0; } /* main() */
int main(int argc, char *argv[]) { LALStatus status = blank_status; ConfigVariables XLAL_INIT_DECL(config); UserVariables_t XLAL_INIT_DECL(uvar); /* register user-variables */ XLAL_CHECK ( XLALInitUserVars ( &uvar ) == XLAL_SUCCESS, XLAL_EFUNC ); /* read cmdline & cfgfile */ BOOLEAN should_exit = 0; XLAL_CHECK( XLALUserVarReadAllInput( &should_exit, argc, argv ) == XLAL_SUCCESS, XLAL_EFUNC ); if ( should_exit ) { exit(1); } if ( uvar.version ) { XLALOutputVersionString ( stdout, lalDebugLevel ); exit(0); } /* basic setup and initializations */ XLAL_CHECK ( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC ); /* ----- allocate memory for AM-coeffs ----- */ AMCoeffs AMold, AMnew1, AMnew2; /**< containers holding AM-coefs computed by 3 different AM functions */ AMold.a = XLALCreateREAL4Vector ( 1 ); AMold.b = XLALCreateREAL4Vector ( 1 ); AMnew1.a = XLALCreateREAL4Vector ( 1 ); AMnew1.b = XLALCreateREAL4Vector ( 1 ); AMnew2.a = XLALCreateREAL4Vector ( 1 ); AMnew2.b = XLALCreateREAL4Vector ( 1 ); XLAL_CHECK ( AMold.a && AMold.b && AMnew1.a && AMnew1.b && AMnew2.a && AMnew2.a, XLAL_ENOMEM, "Failed to XLALCreateREAL4Vector ( 1 )\n" ); /* ----- get detector-state series ----- */ DetectorStateSeries *detStates = NULL; XLAL_CHECK ( (detStates = XLALGetDetectorStates ( config.timestamps, config.det, config.edat, 0 )) != NULL, XLAL_EFUNC ); /* ----- compute associated SSB timing info ----- */ SSBtimes *tSSB = XLALGetSSBtimes ( detStates, config.skypos, config.timeGPS, SSBPREC_RELATIVISTIC ); XLAL_CHECK ( tSSB != NULL, XLAL_EFUNC, "XLALGetSSBtimes() failed with xlalErrno = %d\n", xlalErrno ); /* ===== 1) compute AM-coeffs the 'old way': [used in CFSv1] ===== */ BarycenterInput XLAL_INIT_DECL(baryinput); AMCoeffsParams XLAL_INIT_DECL(amParams); EarthState earth; baryinput.site.location[0] = config.det->location[0]/LAL_C_SI; baryinput.site.location[1] = config.det->location[1]/LAL_C_SI; baryinput.site.location[2] = config.det->location[2]/LAL_C_SI; baryinput.alpha = config.skypos.longitude; baryinput.delta = config.skypos.latitude; baryinput.dInv = 0.e0; /* amParams structure to compute a(t) and b(t) */ amParams.das = XLALMalloc(sizeof(*amParams.das)); amParams.das->pSource = XLALMalloc(sizeof(*amParams.das->pSource)); amParams.baryinput = &baryinput; amParams.earth = &earth; amParams.edat = config.edat; amParams.das->pDetector = config.det; amParams.das->pSource->equatorialCoords.longitude = config.skypos.longitude; amParams.das->pSource->equatorialCoords.latitude = config.skypos.latitude; amParams.das->pSource->orientation = 0.0; amParams.das->pSource->equatorialCoords.system = COORDINATESYSTEM_EQUATORIAL; amParams.polAngle = 0; LAL_CALL ( LALComputeAM ( &status, &AMold, config.timestamps->data, &amParams), &status); XLALFree ( amParams.das->pSource ); XLALFree ( amParams.das ); /* ===== 2) compute AM-coeffs the 'new way' using LALNewGetAMCoeffs() */ LALGetAMCoeffs ( &status, &AMnew1, detStates, config.skypos ); if ( status.statusCode ) { XLALPrintError ("%s: call to LALGetAMCoeffs() failed, status = %d\n\n", __func__, status.statusCode ); XLAL_ERROR ( status.statusCode & XLAL_EFUNC ); } /* ===== 3) compute AM-coeffs the 'newer way' using LALNewGetAMCoeffs() [used in CFSv2] */ LALNewGetAMCoeffs ( &status, &AMnew2, detStates, config.skypos ); if ( status.statusCode ) { XLALPrintError ("%s: call to LALNewGetAMCoeffs() failed, status = %d\n\n", __func__, status.statusCode ); XLAL_ERROR ( status.statusCode & XLAL_EFUNC ); } /* ===== 4) use standalone version of the above [used in FstatMetric_v2] */ REAL8 a0,b0; if ( XLALComputeAntennaPatternCoeffs ( &a0, &b0, &config.skypos, &config.timeGPS, config.det, config.edat ) != XLAL_SUCCESS ) { XLALPrintError ("%s: XLALComputeAntennaPatternCoeffs() failed.\n", __func__ ); XLAL_ERROR ( XLAL_EFUNC ); } /* ==================== output the results ==================== */ printf ("\n"); printf ("----- Input parameters:\n"); printf ("tGPS = { %d, %d }\n", config.timeGPS.gpsSeconds, config.timeGPS.gpsNanoSeconds ); printf ("Detector = %s\n", config.det->frDetector.name ); printf ("Sky position: longitude = %g rad, latitude = %g rad [equatorial coordinates]\n", config.skypos.longitude, config.skypos.latitude ); printf ("\n"); printf ("----- Antenna pattern functions (a,b):\n"); printf ("LALComputeAM: ( %-12.8g, %-12.8g) [REAL4]\n", AMold.a->data[0], AMold.b->data[0] ); printf ("LALGetAMCoeffs: ( %-12.8g, %-12.8g) [REAL4]\n", AMnew1.a->data[0], AMnew1.b->data[0] ); printf ("LALNewGetAMCoeffs: ( %-12.8g, %-12.8g) [REAL4]\n", AMnew2.a->data[0]/config.sinzeta, AMnew2.b->data[0]/config.sinzeta ); printf ("XLALComputeAntennaPatternCoeffs: ( %-12.8g, %-12.8g) [REAL8]\n", a0/config.sinzeta, b0/config.sinzeta ); printf ("\n"); printf ("----- Detector & Earth state:\n"); REAL8 *pos = detStates->data[0].rDetector; printf ("Detector position [ICRS J2000. Units=sec]: rDet = {%g, %g, %g}\n", pos[0], pos[1], pos[2] ); REAL8 *vel = detStates->data[0].vDetector; printf ("Detector velocity [ICRS J2000. Units=c]: vDet = {%g, %g, %g}\n", vel[0], vel[1], vel[2] ); printf ("Local mean sideral time: LMST = %g rad\n", detStates->data[0].LMST); printf ("\n"); printf ("----- SSB timing data:\n"); printf ("TOA difference tSSB - tDet = %g s\n", tSSB->DeltaT->data[0] ); printf ("TOA rate of change dtSSB/dtDet - 1 = %g\n", tSSB->Tdot->data[0] - 1.0 ); printf ("\n\n"); /* ----- done: free all memory */ XLAL_CHECK ( XLALDestroyConfig( &config ) == XLAL_SUCCESS, XLAL_EFUNC ); XLALDestroyDetectorStateSeries ( detStates ); XLALDestroyREAL4Vector ( AMold.a ); XLALDestroyREAL4Vector ( AMold.b ); XLALDestroyREAL4Vector ( AMnew1.a ); XLALDestroyREAL4Vector ( AMnew1.b ); XLALDestroyREAL4Vector ( AMnew2.a ); XLALDestroyREAL4Vector ( AMnew2.b ); XLALDestroyREAL8Vector ( tSSB->DeltaT ); XLALDestroyREAL8Vector ( tSSB->Tdot ); XLALFree (tSSB); LALCheckMemoryLeaks(); return 0; } /* main */
int main(int argc, char *argv[]) { ConfigVariables XLAL_INIT_DECL(config); UserVariables_t XLAL_INIT_DECL(uvar); DopplerMetricParams XLAL_INIT_DECL(metricParams); vrbflg = 1; /* verbose error-messages */ /* set LAL error-handler */ lal_errhandler = LAL_ERR_EXIT; /* register user-variables */ if ( initUserVars(&uvar) != XLAL_SUCCESS ) { XLALPrintError( "%s(): initUserVars() failed\n", __func__ ); return EXIT_FAILURE; } /* read cmdline & cfgfile */ if ( XLALUserVarReadAllInput(argc,argv) != XLAL_SUCCESS ) { XLALPrintError( "%s(): XLALUserVarReadAllInput() failed\n", __func__ ); return EXIT_FAILURE; } if (uvar.help) /* help requested: we're done */ return 0; CHAR *VCSInfoString; if ( (VCSInfoString = XLALGetVersionString(0)) == NULL ) { XLALPrintError("XLALGetVersionString(0) failed.\n"); exit(1); } if ( uvar.version ) { printf ( "%s\n", VCSInfoString ); return 0; } if ( uvar.coordsHelp ) { CHAR *helpstr; if ( (helpstr = XLALDopplerCoordinateHelpAll()) == NULL ) { LogPrintf ( LOG_CRITICAL, "XLALDopplerCoordinateHelpAll() failed!\n\n"); return -1; } printf ( "\n%s\n", helpstr ); XLALFree ( helpstr ); return 0; } /* if coordsHelp */ /* basic setup and initializations */ XLAL_CHECK ( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC, "XLALInitCode() failed with xlalErrno = %d\n\n", xlalErrno ); config.history->VCSInfoString = VCSInfoString; /* parse detector motion string */ int detMotionType = XLALParseDetectorMotionString( uvar.detMotionStr ); XLAL_CHECK ( detMotionType != XLAL_FAILURE, XLAL_EFUNC, "Failed to pass detector motion string '%s'", uvar.detMotionStr ); metricParams.detMotionType = detMotionType; metricParams.segmentList = config.segmentList; metricParams.coordSys = config.coordSys; metricParams.multiIFO = config.multiIFO; metricParams.multiNoiseFloor = config.multiNoiseFloor; metricParams.signalParams = config.signalParams; metricParams.projectCoord = uvar.projection - 1; /* user-input counts from 1, but interally we count 0=1st coord. (-1==no projection) */ metricParams.approxPhase = uvar.approxPhase; /* ----- compute metric full metric + Fisher matrix ---------- */ DopplerPhaseMetric *Pmetric = NULL; if ( uvar.metricType == 0 || uvar.metricType == 2 ) { if ( (Pmetric = XLALComputeDopplerPhaseMetric ( &metricParams, config.edat )) == NULL ) { LogPrintf (LOG_CRITICAL, "Something failed in XLALComputeDopplerPhaseMetric(). xlalErrno = %d\n\n", xlalErrno); return -1; } } DopplerFstatMetric *Fmetric = NULL; if ( uvar.metricType == 1 || uvar.metricType == 2 ) { if ( (Fmetric = XLALComputeDopplerFstatMetric ( &metricParams, config.edat )) == NULL ) { LogPrintf (LOG_CRITICAL, "Something failed in XLALComputeDopplerFstatMetric(). xlalErrno = %d\n\n", xlalErrno); return -1; } } /* ---------- output results ---------- */ if ( uvar.outputMetric ) { FILE *fpMetric; if ( (fpMetric = fopen ( uvar.outputMetric, "wb" )) == NULL ) { LogPrintf (LOG_CRITICAL, "%s: failed to open '%s' for writing. error = '%s'\n", __func__, uvar.outputMetric, strerror(errno)); return FSTATMETRIC_EFILE; } if ( XLALOutputDopplerMetric ( fpMetric, Pmetric, Fmetric, config.history ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: failed to write Doppler metric into output-file '%s'. xlalErrno = %d\n\n", __func__, uvar.outputMetric, xlalErrno ); return FSTATMETRIC_EFILE; } fclose ( fpMetric ); } /* if outputMetric */ /* ----- done: free all memory */ XLALDestroyDopplerPhaseMetric ( Pmetric ); XLALDestroyDopplerFstatMetric ( Fmetric ); if ( XLALDestroyConfig( &config ) != XLAL_SUCCESS ) { LogPrintf (LOG_CRITICAL, "%s: XLADestroyConfig() failed, xlalErrno = %d.\n\n", __func__, xlalErrno ); return FSTATMETRIC_EXLAL; } LALCheckMemoryLeaks(); return 0; } /* main */
int main(int argc, char *argv[]) { ConfigVariables config = empty_ConfigVariables; UserVariables_t uvar = empty_UserVariables; /* register user-variables */ XLAL_CHECK ( XLALInitUserVars ( &uvar ) == XLAL_SUCCESS, XLAL_EFUNC ); /* read cmdline & cfgfile */ XLAL_CHECK ( XLALUserVarReadAllInput ( argc,argv ) == XLAL_SUCCESS, XLAL_EFUNC ); if (uvar.help) { /* help requested: we're done */ exit(0); } if ( uvar.version ) { XLALOutputVersionString ( stdout, lalDebugLevel ); exit(0); } /* basic setup and initializations */ XLAL_CHECK ( XLALInitCode( &config, &uvar, argv[0] ) == XLAL_SUCCESS, XLAL_EFUNC ); /* prepare output files */ FILE *fpOutab = NULL; if ( uvar.outab ) { XLAL_CHECK ( (fpOutab = fopen (uvar.outab, "wb")) != NULL, XLAL_EIO, "Error opening file '%s' for writing...", uvar.outab ); /* write header info in comments */ XLAL_CHECK ( XLAL_SUCCESS == XLALOutputVersionString ( fpOutab, 0 ), XLAL_EFUNC ); /* write the command-line */ for (int a = 0; a < argc; a++) { fprintf(fpOutab,"%%%% argv[%d]: '%s'\n", a, argv[a]); } /* write column headings */ fprintf(fpOutab, "%%%% columns:\n%%%% Alpha Delta tGPS "); if ( config.numDetectors == 1 ) { fprintf(fpOutab, " a(t) b(t)"); } else { for ( UINT4 X=0; X < config.numDetectors; X++ ) { fprintf(fpOutab, " a[%d](t) b[%d](t)", X, X); } } fprintf(fpOutab, "\n"); } FILE *fpOutABCD = NULL; if ( uvar.outABCD ) { XLAL_CHECK ( (fpOutABCD = fopen (uvar.outABCD, "wb")) != NULL, XLAL_EIO, "Error opening file '%s' for writing...", uvar.outABCD ); /* write header info in comments */ XLAL_CHECK ( XLAL_SUCCESS == XLALOutputVersionString ( fpOutABCD, 0 ), XLAL_EFUNC ); /* write the command-line */ for (int a = 0; a < argc; a++) { fprintf(fpOutABCD,"%%%% argv[%d]: '%s'\n", a, argv[a]); } /* write column headings */ fprintf(fpOutABCD, "%%%% columns:\n%%%% Alpha Delta"); fprintf(fpOutABCD, " A B C D"); if ( config.numDetectors > 1 ) { fprintf(fpOutABCD, " "); for ( UINT4 X=0; X < config.numDetectors; X++ ) { fprintf(fpOutABCD, " A[%d] B[%d] C[%d] D[%d]", X, X, X, X); } } fprintf(fpOutABCD, "\n"); } /* loop over sky positions (outer loop, could allow for buffering if necessary) */ for (UINT4 n = 0; n < config.numSkyPoints; n++) { SkyPosition skypos; skypos.system = COORDINATESYSTEM_EQUATORIAL; skypos.longitude = config.Alpha->data[n]; skypos.latitude = config.Delta->data[n]; /* do the actual computation of the antenna pattern functions */ MultiAMCoeffs *multiAM; XLAL_CHECK ( ( multiAM = XLALComputeMultiAMCoeffs ( config.multiDetStates, config.multiNoiseWeights, skypos ) ) != NULL, XLAL_EFUNC, "XLALComputeAMCoeffs() failed." ); /* for multi-IFO run with weights, do it again, without weights, to get single-IFO quantities consistent with single-IFO runs * FIXME: remove this temporary hack when MultiAmCoeffs have been changed to include non-weighted single-IFO quantities */ MultiAMCoeffs *multiAMforSingle = NULL; MultiAMCoeffs *multiAMunweighted = NULL; if ( ( config.numDetectors > 1 ) && ( config.multiNoiseWeights != NULL ) ) { XLAL_CHECK ( ( multiAMunweighted = XLALComputeMultiAMCoeffs ( config.multiDetStates, NULL, skypos ) ) != NULL, XLAL_EFUNC, "XLALComputeAMCoeffs() failed." ); multiAMforSingle = multiAMunweighted; } else { multiAMforSingle = multiAM; } /* write out the data for this sky point */ if ( uvar.outab ) { // output a(t), b(t) at each timestamp for (UINT4 t = 0; t < config.numTimeStamps; t++) { // FIXME: does not work for different multi-IFO numTimeStampsX fprintf (fpOutab, "%.7f %.7f %d", config.Alpha->data[n], config.Delta->data[n], config.multiTimestamps->data[0]->data[t].gpsSeconds ); for ( UINT4 X=0; X < config.numDetectors; X++ ) { fprintf(fpOutab, " %12.8f %12.8f", multiAMforSingle->data[X]->a->data[t], multiAMforSingle->data[X]->b->data[t]); } // for ( UINT4 X=0; X < config.numDetectors; X++ ) fprintf(fpOutab, "\n"); } // for (UINT4 t = 0; t < config.numTimeStamps; t++) } // if ( uvar.outab ) if ( uvar.outABCD ) { // output ABCD averaged over all timestamps // FIXME: stop doing average manually when AMCoeffs is changed to contain averaged values REAL8 A = multiAM->Mmunu.Ad/config.numTimeStamps; REAL8 B = multiAM->Mmunu.Bd/config.numTimeStamps; REAL8 C = multiAM->Mmunu.Cd/config.numTimeStamps; REAL8 D = A*B-SQ(C); fprintf (fpOutABCD, "%.7f %.7f %12.8f %12.8f %12.8f %12.8f", config.Alpha->data[n], config.Delta->data[n], A, B, C, D ); if ( config.numDetectors > 1 ) { for ( UINT4 X=0; X < config.numDetectors; X++ ) { REAL4 AX = multiAMforSingle->data[X]->A/config.numTimeStampsX->data[X]; REAL4 BX = multiAMforSingle->data[X]->B/config.numTimeStampsX->data[X]; REAL4 CX = multiAMforSingle->data[X]->C/config.numTimeStampsX->data[X]; REAL4 DX = AX*BX-SQ(CX); fprintf(fpOutABCD, " %12.8f %12.8f %12.8f %12.8f", AX, BX, CX, DX); } } fprintf(fpOutABCD, "\n"); } // if ( uvar.outABCD ) XLALDestroyMultiAMCoeffs ( multiAM ); if ( multiAMunweighted ) { XLALDestroyMultiAMCoeffs ( multiAMunweighted ); } } // for (UINT4 n = 0; n < config.numSkyPoints; n++) /* ----- close output files ----- */ if ( fpOutab ) { fprintf (fpOutab, "\n"); fclose ( fpOutab ); } if ( fpOutABCD ) { fprintf (fpOutABCD, "\n"); fclose ( fpOutABCD ); } /* ----- done: free all memory */ XLAL_CHECK ( XLALDestroyConfig( &config ) == XLAL_SUCCESS, XLAL_EFUNC ); LALCheckMemoryLeaks(); return 0; } /* main */