23 #include <lal/UserInputParse.h>
25 #include <lal/LineRobustStats.h>
52 const BSGLSetup *setup
78 const UINT4 numSegments
91 setup->Fstar0sc = Fstar0sc;
97 setup->oLGX[X] = ( oLGX != NULL ) ? oLGX[X] : oLGX_default;
98 oLG += setup->oLGX[X];
102 REAL4 ln_1_plus_oLG = logf( 1.0 + oLG );
103 setup->C = Fstar0sc - ln_1_plus_oLG;
107 if ( setup->oLGX[X] > 0 ) {
108 setup->ln_pLtL_X[X] = logf( setup->oLGX[X] ) - ln_1_plus_oLG;
112 setup->perSegTerm = Fstar0sc * ( numSegments - 1 ) / numSegments - logf( numSegments );
114 setup->useLogCorrection = useLogCorrection;
178 const BSGLSetup *setup
181 XLAL_CHECK( ( outBSGL != NULL ) && ( twoF != NULL ) && ( twoFPerDet != NULL ) && ( setup != NULL ) && ( len >= 1 ),
XLAL_EINVAL );
183 for (
UINT4 i = 0;
i < len;
i ++ ) {
185 REAL4 FpMax = setup->C;
189 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
190 Xterm[X] = 0.5f * twoFPerDet[X][
i] + setup->ln_pLtL_X[X];
191 FpMax = fmaxf( FpMax, Xterm[X] );
194 outBSGL[
i] = 0.5f * twoF[
i] - FpMax;
196 if ( setup->useLogCorrection ) {
198 REAL4 extraSum = expf( setup->C - FpMax );
201 for (
UINT4 X = 0; X < setup->numDetectors; X++ ) {
202 extraSum += expf( Xterm[X] - FpMax );
204 outBSGL[
i] -= logf( extraSum );
220 const BSGLSetup *setup
225 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
226 twoFPerDet[X] = &( twoFX[X] );
245 const BSGLSetup *setup
248 XLAL_CHECK( ( outDenom != NULL ) && ( twoFPerDet != NULL ) && ( maxTwoFSegPerDet != NULL ) && ( setup != NULL ),
XLAL_EINVAL );
251 for (
UINT4 i = 0;
i < len;
i ++ ) {
252 REAL4 FpMax = setup->C;
257 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
259 Xterm[X] = 0.5f * twoFPerDet[X][
i] + ln_pLX;
260 FpMax = fmaxf( FpMax, Xterm[X] );
261 Xlterm[X] = 0.5f * maxTwoFSegPerDet[X][
i] + setup->perSegTerm + ln_pLX;
262 FpMax = fmaxf( FpMax, Xlterm[X] );
324 const BSGLSetup *setup
327 XLAL_CHECK( ( outBSGLtL != NULL ) && ( twoF != NULL ) && ( twoFPerDet != NULL ) && ( maxTwoFSegPerDet != NULL ) && ( setup != NULL ),
XLAL_EFUNC );
332 for (
UINT4 i = 0;
i < len;
i ++ ) {
333 outBSGLtL[
i] -= 0.5f * twoF[
i];
346 const BSGLSetup *setup
352 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
353 twoFPerDet[X] = &( twoFX[X] );
354 maxTwoFSegPerDet[X] = &( maxtwoFlX[X] );
391 const REAL4 *maxTwoFSeg,
395 const BSGLSetup *setup
398 XLAL_CHECK( ( outBtSGLtL != NULL ) && ( maxTwoFSeg != NULL ) && ( twoFPerDet != NULL ) && ( maxTwoFSegPerDet != NULL ) && ( setup != NULL ),
XLAL_EFUNC );
402 for (
UINT4 i = 0;
i < len;
i ++ ) {
403 outBtSGLtL[
i] -= 0.5f * maxTwoFSeg[
i] + setup->perSegTerm;
416 const BSGLSetup *setup
422 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
423 twoFPerDet[X] = &( twoFX[X] );
424 maxTwoFSegPerDet[X] = &( maxtwoFXl[X] );
467 const REAL4 maxtwoFl,
470 const BSGLSetup *setup
475 REAL4 GLtLDenominator;
478 for (
UINT4 X = 0; X < setup->numDetectors; X ++ ) {
479 twoFPerDet[X] = &( twoFX[X] );
480 maxTwoFSegPerDet[X] = &( maxtwoFXl[X] );
485 REAL4 multiF = 0.5f * twoF + ln_pS;
486 REAL4 tsTerm = 0.5f * maxtwoFl + setup->perSegTerm + ln_pS;
487 REAL4 maxNumerator = fmaxf( multiF, tsTerm );
488 REAL4 minNumerator = fminf( multiF, tsTerm );
490 REAL4 ln_BStSGLtL = maxNumerator + logf( 1 + expf( minNumerator - maxNumerator ) ) - GLtLDenominator;
void * XLALCalloc(size_t m, size_t n)
int XLALVectorComputeBSGLtL(REAL4 *outBSGLtL, const REAL4 *twoF, const REAL4 *twoFPerDet[PULSAR_MAX_DETECTORS], const REAL4 *maxTwoFSegPerDet[PULSAR_MAX_DETECTORS], const UINT4 len, const BSGLSetup *setup)
REAL4 XLALComputeBSGLtL(const REAL4 twoF, const REAL4 twoFX[PULSAR_MAX_DETECTORS], const REAL4 maxtwoFlX[PULSAR_MAX_DETECTORS], const BSGLSetup *setup)
Single-bin wrapper of XLALVectorComputeBSGLtL(), provided for backwards compatibility.
REAL4 XLALComputeBtSGLtL(const REAL4 maxtwoFl, const REAL4 twoFX[PULSAR_MAX_DETECTORS], const REAL4 maxtwoFXl[PULSAR_MAX_DETECTORS], const BSGLSetup *setup)
Single-bin wrapper of XLALVectorComputeBtSGLtL(), provided for backwards compatibility.
void XLALDestroyBSGLSetup(BSGLSetup *setup)
int XLALVectorComputeBSGL(REAL4 *outBSGL, const REAL4 *twoF, const REAL4 *twoFPerDet[PULSAR_MAX_DETECTORS], const UINT4 len, const BSGLSetup *setup)
REAL4 XLALComputeBStSGLtL(const REAL4 twoF, const REAL4 maxtwoFl, const REAL4 twoFX[PULSAR_MAX_DETECTORS], const REAL4 maxtwoFXl[PULSAR_MAX_DETECTORS], const BSGLSetup *setup)
BSGLSetup * XLALCreateBSGLSetup(const UINT4 numDetectors, const REAL4 Fstar0sc, const REAL4 oLGX[PULSAR_MAX_DETECTORS], const BOOLEAN useLogCorrection, const UINT4 numSegments)
REAL4 XLALComputeBSGL(const REAL4 twoF, const REAL4 twoFX[PULSAR_MAX_DETECTORS], const BSGLSetup *setup)
Single-bin wrapper of XLALVectorComputeBSGL(), provided for backwards compatibility.
int XLALVectorComputeGLtLDenominator(REAL4 *outDenom, const REAL4 *twoFPerDet[PULSAR_MAX_DETECTORS], const REAL4 *maxTwoFSegPerDet[PULSAR_MAX_DETECTORS], const UINT4 len, const BSGLSetup *setup)
int XLALParseLinePriors(REAL4 oLGX[PULSAR_MAX_DETECTORS], const LALStringVector *oLGX_string)
Parse string-vectors (typically input by user) of N per-detector line-to-Gaussian prior ratios to a ...
int XLALVectorComputeBtSGLtL(REAL4 *outBtSGLtL, const REAL4 *maxTwoFSeg, const REAL4 *twoFPerDet[PULSAR_MAX_DETECTORS], const REAL4 *maxTwoFSegPerDet[PULSAR_MAX_DETECTORS], const UINT4 len, const BSGLSetup *setup)
#define PULSAR_MAX_DETECTORS
maximal number of detectors we can handle (for static arrays of detector quantities)
#define XLAL_CHECK(assertion,...)
#define XLAL_CHECK_REAL4(assertion,...)
#define XLAL_CHECK_NULL(assertion,...)
internal storage for setup and pre-computed BSGL quantities
REAL4 oLGX[PULSAR_MAX_DETECTORS]
REAL4 ln_pLtL_X[PULSAR_MAX_DETECTORS]