Loading [MathJax]/extensions/TeX/AMSsymbols.js
LALInference 4.1.9.1-5e288d3
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
LALInferenceLikelihood.c
Go to the documentation of this file.
1/*
2 * LALInferenceLikelihood.c: Bayesian Followup likelihood functions
3 *
4 * Copyright (C) 2009 Ilya Mandel, Vivien Raymond, Christian Roever,
5 * Marc van der Sluys and John Veitch, Will M. Farr
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with with program; see the file COPYING. If not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 * MA 02110-1301 USA
22 */
23
24#include <complex.h>
25#include <lal/LALInferenceLikelihood.h>
26#include <lal/LALInferencePrior.h>
27#include <lal/LALInference.h>
28#include <lal/DetResponse.h>
29#include <lal/TimeDelay.h>
30#include <lal/TimeSeries.h>
31#include <lal/Units.h>
32#include <lal/Sequence.h>
33#include <lal/FrequencySeries.h>
34#include <lal/TimeFreqFFT.h>
35#include <lal/LALInferenceDistanceMarg.h>
36
37#include <gsl/gsl_sf_bessel.h>
38#include <gsl/gsl_sf_dawson.h>
39#include <gsl/gsl_sf_erf.h>
40#include <gsl/gsl_complex_math.h>
41#include <lal/LALInferenceTemplate.h>
42
43#include "logaddexp.h"
44
45#include <lal/distance_integrator.h>
46
47typedef enum
48{
54 MARGDIST = 32
56
57
58#ifdef __GNUC__
59#define UNUSED __attribute__ ((unused))
60#else
61#define UNUSED
62#endif
63
64#ifndef _OPENMP
65#define omp ignore
66#endif
67
70 LALInferenceModel *model,
71 LALInferenceLikelihoodFlags marginalisationflags);
72
73static double integrate_interpolated_log(double h, REAL8 *log_ys, size_t n, double *imean, size_t *imax);
74
75static int get_calib_spline(LALInferenceVariables *vars, const char *ifoname, REAL8Vector **logfreqs, REAL8Vector **amps, REAL8Vector **phases);
76static int get_calib_spline(LALInferenceVariables *vars, const char *ifoname, REAL8Vector **logfreqs, REAL8Vector **amps, REAL8Vector **phases)
77{
78 UINT4 npts = LALInferenceGetUINT4Variable(vars, "spcal_npts");
79 char ampname[VARNAME_MAX];
80 char phasename[VARNAME_MAX];
81 char freqname[VARNAME_MAX];
82 if(!*logfreqs) *logfreqs = XLALCreateREAL8Vector(npts);
83 if(!*amps) *amps = XLALCreateREAL8Vector(npts);
84 if(!*phases) *phases = XLALCreateREAL8Vector(npts);
85 XLAL_CHECK_ABORT((*logfreqs)->length==npts);
86 XLAL_CHECK_ABORT((*amps)->length==npts);
87 XLAL_CHECK_ABORT((*phases)->length==npts);
88
89 for(UINT4 i=0;i<npts;i++)
90 {
91 if((VARNAME_MAX <= snprintf(freqname, VARNAME_MAX, "%s_spcal_logfreq_%i", ifoname, i))) XLAL_ERROR(XLAL_EINVAL,"Variable name too long");
92 if((VARNAME_MAX <= snprintf(ampname, VARNAME_MAX, "%s_spcal_amp_%i", ifoname, i))) XLAL_ERROR(XLAL_EINVAL,"Variable name too long");
93 if((VARNAME_MAX <= snprintf(phasename, VARNAME_MAX, "%s_spcal_phase_%i", ifoname, i))) XLAL_ERROR(XLAL_EINVAL,"Variable name too long");
94
95 (*logfreqs)->data[i] = LALInferenceGetREAL8Variable(vars, freqname);
96 (*amps)->data[i] = LALInferenceGetREAL8Variable(vars, ampname);
97 (*phases)->data[i] = LALInferenceGetREAL8Variable(vars, phasename);
98 }
99 return(XLAL_SUCCESS);
100}
101
103{
104 char help[]="\
105 ----------------------------------------------\n\
106 --- Likelihood Arguments ---------------------\n\
107 ----------------------------------------------\n\
108 (--zeroLogLike) Use flat, null likelihood\n\
109 (--studentTLikelihood) Use the Student-T Likelihood that marginalizes over noise\n\
110 (--correlatedGaussianLikelihood) Use analytic, correlated Gaussian for Likelihood Z=-21.3\n\
111 (--bimodalGaussianLikelihood) Use analytic, bimodal correlated Gaussian for Likelihood Z=-25.9\n\
112 (--rosenbrockLikelihood) Use analytic, Rosenbrock banana for Likelihood\n\
113 (--noiseonly) Using noise-only likelihood\n\
114 (--margphi) Using marginalised phase likelihood\n\
115 (--margtime) Using marginalised time likelihood\n\
116 (--margtimephi) Using marginalised in time and phase likelihood\n\
117 (--margdist) Using marginalisation in distance with d^2 prior (compatible with --margphi and --margtimephi)\n\
118 (--margdist-comoving) Using marginalisation in distance with uniform-in-comoving-volume prior (compatible with --margphi and --margtimephi)\n\
119 \n";
120
121 /* Print command line arguments if help requested */
122 LALInferenceIFOData *ifo=NULL;
123 if(runState == NULL || LALInferenceGetProcParamVal(runState->commandLine,"--help"))
124 {
125 fprintf(stdout,"%s",help);
126 if (runState){
127 ifo=runState->data;
128 while(ifo) {
129 fprintf(stdout,"(--dof-%s DoF)\tDegrees of freedom for %s\n",ifo->name,ifo->name);
130 ifo=ifo->next;
131 }
132 }
133 return;
134 }
135
136 ProcessParamsTable *commandLine=runState->commandLine;
137 ifo=runState->data;
138
139 LALInferenceThreadState *thread = &(runState->threads[0]);
140
141 REAL8 nullLikelihood = 0.0; // Populated if such a thing exists
142
143 if (LALInferenceGetProcParamVal(commandLine, "--zeroLogLike")) {
144 /* Use zero log(L) */
146 } else if (LALInferenceGetProcParamVal(commandLine, "--correlatedGaussianLikelihood")) {
148 } else if (LALInferenceGetProcParamVal(commandLine, "--bimodalGaussianLikelihood")) {
150 } else if (LALInferenceGetProcParamVal(commandLine, "--rosenbrockLikelihood")) {
152 } else if (LALInferenceGetProcParamVal(commandLine, "--studentTLikelihood")) {
153 fprintf(stderr, "Using Student's T Likelihood.\n");
155
156 /* Set the noise model evidence to the student t model value */
160 REAL8 noiseZ = LALInferenceFreqDomainStudentTLogLikelihood(thread->currentParams, runState->data, thread->model);
161 thread->model->templt = temp;
163 fprintf(stdout,"Student-t Noise evidence %lf\n", noiseZ);
164
165 } else if (LALInferenceGetProcParamVal(commandLine, "--margphi")) {
166 fprintf(stderr, "Using marginalised phase likelihood.\n");
168 } else if (LALInferenceGetProcParamVal(commandLine, "--margtime")) {
169 fprintf(stderr, "Using marginalised time likelihood.\n");
171 } else if (LALInferenceGetProcParamVal(commandLine, "--margtimephi")) {
172 fprintf(stderr, "Using marginalised in time and phase likelihood.\n");
174 //LALInferenceAddVariable(runState->currentParams, "margtimephi", &margphi, LALINFERENCE_UINT4_t,LALINFERENCE_PARAM_FIXED);
175 }
176 else if (LALInferenceGetProcParamVal(commandLine, "--roqtime_steps")) {
177 fprintf(stderr, "Using ROQ in likelihood.\n");
179 }
180 else if (LALInferenceGetProcParamVal(commandLine, "--fastSineGaussianLikelihood")){
181 fprintf(stderr, "WARNING: Using Fast SineGaussian likelihood and WF for LIB.\n");
183 } else {
185 }
186
187 /* Try to determine a model-less likelihood, if such a thing makes sense */
189
190 nullLikelihood = LALInferenceNullLogLikelihood(runState->data);
191
192 }
196
197 void *oldtemplate = runState->threads[0].model->templt;
198 if (runState->threads[0].model->domain == LAL_SIM_DOMAIN_FREQUENCY) {
200 } else {
202 }
203 nullLikelihood = runState->likelihood(thread->currentParams, runState->data, thread->model);
204 runState->threads[0].model->templt = oldtemplate;
205
206 }
207
208 //null log likelihood logic doesn't work with noise parameters
209 if (LALInferenceGetProcParamVal(runState->commandLine,"--psdFit") ||
210 LALInferenceGetProcParamVal(runState->commandLine,"--psd-fit") ||
211 LALInferenceGetProcParamVal(runState->commandLine,"--glitchFit") ||
212 LALInferenceGetProcParamVal(runState->commandLine,"--glitch-fit")) {
213 nullLikelihood = 0.0;
214 ifo = runState->data;
215 while (ifo != NULL) {
216 ifo->nullloglikelihood = 0.0;
217 ifo = ifo->next;
218 }
219 }
220
221 INT4 t;
222 for(t=0; t < runState->nthreads; t++)
223 runState->threads[t].nullLikelihood = nullLikelihood;
224
225 LALInferenceAddVariable(runState->proposalArgs, "nullLikelihood", &nullLikelihood,
227
228 return;
229}
230
231
232const char *non_intrinsic_params[] = {"rightascension", "declination", "polarisation", "time",
233 "deltaLogL", "logL", "deltaloglH1", "deltaloglL1", "deltaloglV1",
234 "logw", "logPrior","hrss","loghrss", NULL};
235
237/***************************************************************/
238/* Return a variables structure containing only intrinsic */
239/* parameters. */
240/***************************************************************/
241{
242 // TODO: add pointer to template function here.
243 // (otherwise same parameters but different template will lead to no re-computation!!)
244 LALInferenceVariables intrinsicParams;
245 const char **non_intrinsic_param = non_intrinsic_params;
246
247 intrinsicParams.head = NULL;
248 intrinsicParams.dimension = 0;
249 LALInferenceCopyVariables(currentParams, &intrinsicParams);
250
251 while (*non_intrinsic_param) {
252 if (LALInferenceCheckVariable(&intrinsicParams, *non_intrinsic_param))
253 LALInferenceRemoveVariable(&intrinsicParams, *non_intrinsic_param);
254 non_intrinsic_param++;
255 }
256
257 return intrinsicParams;
258}
259
260/* Check to see if item is in the NULL-terminated array.
261 If so, return 1. Otherwise, add it to the array and return 0
262 */
263static int checkItemAndAdd(void *item, void **array);
264static int checkItemAndAdd(void *item, void **array)
265{
266 UINT4 i=0;
267 if(!array || !item) return 0;
268 while(array[i])
269 {
270 if(array[i++]==item) return 1;
271 }
272 array[i]=item;
273 return 0;
274}
275
276/* ============ Likelihood computations: ========== */
277
278/**
279 * For testing purposes (for instance sampling the prior), likelihood that returns 0.0 = log(1) every
280 * time. Activated with the --zeroLogLike command flag.
281 */
283 LALInferenceIFOData UNUSED *data,
284 LALInferenceModel UNUSED *model) {
285
286 INT4 SKY_FRAME=0;
287 REAL8 ra,dec,GPSdouble;
288
290 SKY_FRAME=*(INT4 *)LALInferenceGetVariable(currentParams,"SKY_FRAME");
291
292 if(SKY_FRAME==1)
293 {
295 REAL8 alph=acos(LALInferenceGetREAL8Variable(currentParams,"cosalpha"));
297 LALInferenceDetFrameToEquatorial(data->detector,data->next->detector,
298 t0,alph,theta,&GPSdouble,&ra,&dec);
302 }
303
304 REAL8 zero = 0.0;
307 return 0.0;
308}
309
310
311
312
315 LALInferenceModel *model)
316{
318 data,
319 model,
320 GAUSSIAN);
321}
322
323
326 LALInferenceModel *model,
327 LALInferenceLikelihoodFlags marginalisationflags)
328/***************************************************************/
329/* (log-) likelihood function. */
330/* Returns the non-normalised logarithmic likelihood. */
331/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
332/* Required (`currentParams') parameters are: */
333/* - "rightascension" (REAL8, radian, 0 <= RA <= 2pi) */
334/* - "declination" (REAL8, radian, -pi/2 <= dec <=pi/2) */
335/* - "polarisation" (REAL8, radian, 0 <= psi <= ?) */
336/* - "time" (REAL8, GPS sec.) */
337/***************************************************************/
338{
339 double Fplus, Fcross;
340 //double diffRe, diffIm;
341 //double dataReal, dataImag;
342 double glitchReal=0.0, glitchImag=0.0;
343 //REAL8 plainTemplateReal, plainTemplateImag;
344 //REAL8 templateReal=0.0, templateImag=0.0;
345 int i, j, lower, upper, ifo;
346 LALInferenceIFOData *dataPtr;
347 double ra=0.0, dec=0.0, psi=0.0, gmst=0.0;
348 double GPSdouble=0.0, t0=0.0;
349 LIGOTimeGPS GPSlal;
350 //double chisquared;
351 double timedelay; /* time delay b/w iterferometer & geocenter w.r.t. sky location */
352 double timeshift=0; /* time shift (not necessarily same as above) */
353 double deltaT, TwoDeltaToverN, deltaF, twopit=0.0, re, im, dre, dim, newRe, newIm;
354 double timeTmp;
355 double mc;
356 /* Burst templates are generated at hrss=1, thus need to rescale amplitude */
357 double amp_prefactor=1.0;
358
359 COMPLEX16FrequencySeries *calFactor = NULL;
360 COMPLEX16 calF = 0.0;
361
362 REAL8Vector *logfreqs = NULL;
363 REAL8Vector *amps = NULL;
364 REAL8Vector *phases = NULL;
365
366 UINT4 spcal_active = 0;
367 REAL8 calamp=0.0;
368 REAL8 calpha=0.0;
369 REAL8 cos_calpha=cos(calpha);
370 REAL8 sin_calpha=sin(calpha);
371 UINT4 constantcal_active=0;
372 INT4 errnum=0;
373
374 /* ROQ likelihood stuff */
375 REAL8 d_inner_h=0.0;
376 double dist_min, dist_max;
377 int cosmology=0;
378 UINT4 margdist = 0;
379 if(LALInferenceCheckVariable(model->params, "MARGDIST") && LALInferenceGetVariable(model->params, "MARGDIST"))
380 {
381 margdist = 1;
382 LALInferenceGetMinMaxPrior(model->params, "logdistance", &dist_min, &dist_max);
383 dist_max=exp(dist_max);
384 dist_min=exp(dist_min);
385 if(LALInferenceCheckVariable(model->params,"MARGDIST_COSMOLOGY"))
386 cosmology=LALInferenceGetINT4Variable(currentParams,"MARGDIST_COSMOLOGY");
387
388 }
389
390 if (LALInferenceCheckVariable(currentParams, "spcal_active") && (*(UINT4 *)LALInferenceGetVariable(currentParams, "spcal_active"))) {
391 spcal_active = 1;
392 }
393 if (LALInferenceCheckVariable(currentParams, "constantcal_active") && (*(UINT4 *)LALInferenceGetVariable(currentParams, "constantcal_active"))) {
394 constantcal_active = 1;
395 }
396 if (spcal_active && constantcal_active){
397 fprintf(stderr,"ERROR: cannot use spline and constant calibration error marginalization together. Exiting...\n");
398 exit(1);
399 }
400 if (model->roq_flag && constantcal_active){
401 fprintf(stderr,"ERROR: cannot use ROQ likelihood and constant calibration error marginalization together. Exiting...\n");
402 exit(1);
403 }
404
405 REAL8 degreesOfFreedom=2.0;
406 REAL8 chisq=0.0;
407 /* margphi params */
408 //REAL8 Rre=0.0,Rim=0.0;
409 REAL8 D=0.0,S=0.0;
410 COMPLEX16 Rcplx=0.0;
411 int margphi=0;
412 int margtime=0;
413 REAL8 desired_tc=0.0;
414 if (marginalisationflags==MARGPHI || marginalisationflags==MARGTIMEPHI)
415 margphi=1;
416 if (marginalisationflags==MARGTIME || marginalisationflags==MARGTIMEPHI)
417 margtime=1;
418
419 if(model->roq_flag && margtime) XLAL_ERROR_REAL8(XLAL_EINVAL,"ROQ does not support time marginalisation");
420
421
423 memset(&status,0,sizeof(status));
424
425 if(data==NULL) {XLAL_ERROR_REAL8(XLAL_EINVAL,"ERROR: Encountered NULL data pointer in likelihood\n");}
426
427 int Nifos=0;
428 for(dataPtr=data;dataPtr;dataPtr=dataPtr->next) Nifos++;
429 void *generatedFreqModels[1+Nifos];
430 for(i=0;i<=Nifos;i++) generatedFreqModels[i]=NULL;
431
432 //noise model meta parameters
433 gsl_matrix *nparams = NULL;//pointer to matrix holding noise parameters
434
435 gsl_matrix *psdBandsMin = NULL;//pointer to matrix holding min frequencies for psd model
436 gsl_matrix *psdBandsMax = NULL;//pointer to matrix holding max frequencies for psd model
437
438 //different formats for storing glitch model for DWT, FFT, and integration
439 gsl_matrix *glitchFD=NULL;
440
441 int Nblock = 1; //number of frequency blocks per IFO
442 int psdFlag = 0; //flag for including psd fitting
443 int glitchFlag = 0; //flag for including glitch model
444 int signalFlag = 1; //flag for including signal model
445
446 //check if psd parameters are included in the model
447 psdFlag = 0;
448 if(LALInferenceCheckVariable(currentParams, "psdScaleFlag"))
449 psdFlag = *((INT4 *)LALInferenceGetVariable(currentParams, "psdScaleFlag"));
450 if(psdFlag)
451 {
452 //if so, store current noise parameters in easily accessible matrix
453 nparams = *((gsl_matrix **)LALInferenceGetVariable(currentParams, "psdscale"));
454 Nblock = (int)nparams->size2;
455
456 psdBandsMin = *((gsl_matrix **)LALInferenceGetVariable(currentParams, "psdBandsMin"));
457 psdBandsMax = *((gsl_matrix **)LALInferenceGetVariable(currentParams, "psdBandsMax"));
458
459 }
460 double alpha[Nblock];
461 double lnalpha[Nblock];
462
463 double psdBandsMin_array[Nblock];
464 double psdBandsMax_array[Nblock];
465
466 //check if glitch model is being used
467 glitchFlag = 0;
468 if(LALInferenceCheckVariable(currentParams,"glitchFitFlag"))
469 glitchFlag = *((INT4 *)LALInferenceGetVariable(currentParams, "glitchFitFlag"));
470 if(glitchFlag)
471 glitchFD = *((gsl_matrix **)LALInferenceGetVariable(currentParams, "morlet_FD"));
472
473 //check if signal model is being used
474 signalFlag=1;
475 if(LALInferenceCheckVariable(currentParams, "signalModelFlag"))
476 signalFlag = *((INT4 *)LALInferenceGetVariable(currentParams, "signalModelFlag"));
477
478 int freq_length=0,time_length=0;
479 COMPLEX16Vector * dh_S_tilde=NULL;
480 COMPLEX16Vector * dh_S_phase_tilde = NULL;
481 REAL8Vector *dh_S=NULL;
482 REAL8Vector *dh_S_phase = NULL;
483 /* Setup times to integrate over */
484 freq_length = data->freqData->data->length;
485 time_length = 2*(freq_length-1);
486
487 /* Desired tc == 2 seconds before buffer end. Only used during
488 margtime{phi} to try to place the waveform in a reasonable
489 place before time-shifting */
490 deltaT = data->timeData->deltaT;
491 REAL8 epoch = XLALGPSGetREAL8(&(data->freqData->epoch));
492 desired_tc = epoch + (time_length-1)*deltaT - 2.0;
493
494 if(signalFlag)
495 {
499 }
501 amp_prefactor = exp(*(REAL8*)LALInferenceGetVariable(currentParams,"loghrss"));
502 }
503 else if (LALInferenceCheckVariable(currentParams, "hrss")){
504 amp_prefactor = (*(REAL8*)LALInferenceGetVariable(currentParams,"hrss"));
505 }
506
507 INT4 SKY_FRAME=0;
509 SKY_FRAME=*(INT4 *)LALInferenceGetVariable(currentParams,"SKY_FRAME");
510 if(SKY_FRAME==0){
511 /* determine source's sky location & orientation parameters: */
512 ra = *(REAL8*) LALInferenceGetVariable(currentParams, "rightascension"); /* radian */
513 dec = *(REAL8*) LALInferenceGetVariable(currentParams, "declination"); /* radian */
514 }
515 else
516 {
517 if(Nifos<2){
518 fprintf(stderr,"ERROR: Cannot use --detector-frame with less than 2 detectors!\n");
519 exit(1);
520 }
521 if(!margtime)
522 {
524 }
525 else /* Use the desired end time to compute the mapping to ra,dec */
526 {
527 t0=desired_tc;
528 }
529 REAL8 alph=acos(LALInferenceGetREAL8Variable(currentParams,"cosalpha"));
531 LALInferenceDetFrameToEquatorial(data->detector,data->next->detector,
532 t0,alph,theta,&GPSdouble,&ra,&dec);
536 }
537 psi = *(REAL8*) LALInferenceGetVariable(currentParams, "polarisation"); /* radian */
538 if(!margtime)
539 GPSdouble = *(REAL8*) LALInferenceGetVariable(currentParams, "time"); /* GPS seconds */
540 else
541 GPSdouble = XLALGPSGetREAL8(&(data->freqData->epoch));
542
543
544 // Add phase parameter set to 0 for calculation
545 if(margphi ){
546 REAL8 phi0=0.0;
549 }
550 }
551
552
553 if(margtime)
554 {
555 GPSdouble = desired_tc;
556 dh_S_tilde = XLALCreateCOMPLEX16Vector(freq_length);
557 dh_S = XLALCreateREAL8Vector(time_length);
558
559 if (dh_S_tilde ==NULL || dh_S == NULL)
560 XLAL_ERROR_REAL8(XLAL_ENOMEM, "Out of memory in LALInferenceMarginalisedTimeLogLikelihood.");
561
562 for (i = 0; i < freq_length; i++) {
563 dh_S_tilde->data[i] = 0.0;
564 }
565
566 if (margphi) {
567 dh_S_phase_tilde = XLALCreateCOMPLEX16Vector(freq_length);
568 dh_S_phase = XLALCreateREAL8Vector(time_length);
569
570 if (dh_S_phase_tilde == NULL || dh_S_phase == NULL) {
571 XLAL_ERROR_REAL8(XLAL_ENOMEM, "Out of memory in time-phase marginalised likelihood.");
572 }
573
574 for (i = 0; i < freq_length; i++) {
575 dh_S_phase_tilde->data[i] = 0.0;
576 }
577 }
578 }
579
580 /* figure out GMST: */
581 XLALGPSSetREAL8(&GPSlal, GPSdouble);
582 gmst=XLALGreenwichMeanSiderealTime(&GPSlal);
583
584 //chisquared = 0.0;
585 REAL8 loglikelihood = 0.0;
586
587 /* Reset SNR */
588 model->SNR = 0.0;
589
590 /* loop over data (different interferometers): */
591 for(dataPtr=data,ifo=0; dataPtr; dataPtr=dataPtr->next,ifo++) {
592 /* The parameters the Likelihood function can handle by itself */
593 /* (and which shouldn't affect the template function) are */
594 /* sky location (ra, dec), polarisation and signal arrival time. */
595 /* Note that the template function shifts the waveform to so that*/
596 /* t_c corresponds to the "time" parameter in */
597 /* model->params (set, e.g., from the trigger value). */
598
599 /* Reset log-likelihood */
600 model->ifo_loglikelihoods[ifo] = 0.0;
601 model->ifo_SNRs[ifo] = 0.0;
602 COMPLEX16 this_ifo_d_inner_h = 0.0;
603 REAL8 this_ifo_s = 0.0;
604 // Check if student-t likelihood is being used
605 if(marginalisationflags==STUDENTT)
606 {
607 /* extract the element from the "df" vector that carries the current Ifo's name: */
608 CHAR df_variable_name[320];
609 snprintf(df_variable_name,sizeof(df_variable_name),"df_%s",dataPtr->name);
610 if(LALInferenceCheckVariable(currentParams,df_variable_name)){
611 printf("Found variable %s\n",df_variable_name);
612 degreesOfFreedom = *(REAL8*) LALInferenceGetVariable(currentParams,df_variable_name);
613 }
614 else {
615 degreesOfFreedom = dataPtr->STDOF;
616 }
617 if (!(degreesOfFreedom>0)) {
618 XLALPrintError(" ERROR in StudentTLogLikelihood(): degrees-of-freedom parameter must be positive.\n");
620 }
621 }
622
623 if(signalFlag){
624
625 /* Check to see if this buffer has already been filled with the signal.
626 Different dataPtrs can share the same signal buffer to avoid repeated
627 calls to template */
628 if(!checkItemAndAdd((void *)(model->freqhPlus), generatedFreqModels))
629 {
630 /* Compare parameter values with parameter values corresponding */
631 /* to currently stored template; ignore "time" variable: */
632 if (LALInferenceCheckVariable(model->params, "time")) {
633 timeTmp = *(REAL8 *) LALInferenceGetVariable(model->params, "time");
634 LALInferenceRemoveVariable(model->params, "time");
635 }
636 else timeTmp = GPSdouble;
637
639 // Remove time variable so it can be over-written (if it was pinned)
640 if(LALInferenceCheckVariable(model->params,"time")) LALInferenceRemoveVariable(model->params,"time");
642
643 XLAL_TRY(model->templt(model),errnum);
644 errnum&=~XLAL_EFUNC;
645 if(errnum!=XLAL_SUCCESS)
646 {
647 switch(errnum)
648 {
649 case XLAL_EUSR0: /* Template generation failed in a known way, set -Inf likelihood */
650 /* Free up allocated vectors */
651 if(dh_S_tilde) XLALDestroyCOMPLEX16Vector(dh_S_tilde);
652 if(dh_S) XLALDestroyREAL8Vector(dh_S);
653 if(dh_S_phase_tilde) XLALDestroyCOMPLEX16Vector(dh_S_phase_tilde);
654 if(dh_S_phase) XLALDestroyREAL8Vector(dh_S_phase);
655 if(model->roq_flag)
656 {
657 if ( model->roq->hptildeLinear ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hptildeLinear);
658 if ( model->roq->hctildeLinear ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hctildeLinear);
659 if ( model->roq->hptildeQuadratic ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hptildeQuadratic);
660 if ( model->roq->hctildeQuadratic ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hctildeQuadratic);
661 }
662 return (-INFINITY);
663 break;
664 default: /* Panic! */
665 fprintf(stderr,"Unhandled error in template generation - exiting!\n");
666 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
667 exit(1);
668 break;
669 }
670
671 }
672
673 if (model->domain == LAL_SIM_DOMAIN_TIME) {
674 /* TD --> FD. */
676 }
677 }
678
679 /* Template is now in model->timeFreqhPlus and hCross */
680
681 /* Calibration stuff if necessary */
682 /*spline*/
683 if (spcal_active) {
684 logfreqs = NULL;
685 amps = NULL;
686 phases = NULL;
687 /* get_calib_spline creates and fills the logfreqs, amps, phases arrays */
688 get_calib_spline(currentParams, dataPtr->name, &logfreqs, &amps, &phases);
689 if (model->roq_flag) {
690
691 LALInferenceSplineCalibrationFactorROQ(logfreqs, amps, phases,
692 model->roq->frequencyNodesLinear,
693 &(model->roq->calFactorLinear),
694 model->roq->frequencyNodesQuadratic,
695 &(model->roq->calFactorQuadratic));
696 }
697
698 else{
699 if (calFactor == NULL) {
700 calFactor = XLALCreateCOMPLEX16FrequencySeries("calibration factors",
701 &(dataPtr->freqData->epoch),
702 0, dataPtr->freqData->deltaF,
704 dataPtr->freqData->data->length);
705 }
706 LALInferenceSplineCalibrationFactor(logfreqs, amps, phases, calFactor);
707 }
708 if(logfreqs) XLALDestroyREAL8Vector(logfreqs);
709 if(amps) XLALDestroyREAL8Vector(amps);
710 if(phases) XLALDestroyREAL8Vector(phases);
711
712 }
713 /*constant*/
714 if (constantcal_active){
715 char CA_A[320];
716 sprintf(CA_A,"%s_%s","calamp",dataPtr->name);
718 calamp=(*(REAL8*) LALInferenceGetVariable(currentParams, CA_A));
719 else
720 calamp=0.0;
721 char CP_A[320];
722 sprintf(CP_A,"%s_%s","calpha",dataPtr->name);
724 calpha=(*(REAL8*) LALInferenceGetVariable(currentParams, CP_A));
725 else
726 calpha=0.0;
727 cos_calpha=cos(calpha);
728 sin_calpha=-sin(calpha);
729 }
730 /* determine beam pattern response (F_plus and F_cross) for given Ifo: */
731 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])dataPtr->detector->response, ra, dec, psi, gmst);
732
733 /* signal arrival time (relative to geocenter); */
734 timedelay = XLALTimeDelayFromEarthCenter(dataPtr->detector->location, ra, dec, &GPSlal);
735 /* (negative timedelay means signal arrives earlier at Ifo than at geocenter, etc.) */
736 /* amount by which to time-shift template (not necessarily same as above "timedelay"): */
737 if (margtime)
738 /* If we are marginalising over time, we want the
739 freq-domain signal to have tC = epoch, so we shift it
740 from the model's "time" parameter to epoch */
741 timeshift = (epoch - (*(REAL8 *) LALInferenceGetVariable(model->params, "time"))) + timedelay;
742 else
743 timeshift = (GPSdouble - (*(REAL8*) LALInferenceGetVariable(model->params, "time"))) + timedelay;
744 twopit = LAL_TWOPI * timeshift;
745
746 /* For burst, add the right hrss in the amplitude. */
747 Fplus*=amp_prefactor;
748 Fcross*=amp_prefactor;
749
750 dataPtr->fPlus = Fplus;
751 dataPtr->fCross = Fcross;
752 dataPtr->timeshift = timeshift;
753 }//end signalFlag condition
754
755 /* determine frequency range & loop over frequency bins: */
756 deltaT = dataPtr->timeData->deltaT;
757 deltaF = 1.0 / (((double)dataPtr->timeData->data->length) * deltaT);
758 lower = (UINT4)ceil(dataPtr->fLow / deltaF);
759 upper = (UINT4)floor(dataPtr->fHigh / deltaF);
760 TwoDeltaToverN = 2.0 * deltaT / ((double) dataPtr->timeData->data->length);
761
762 /* Employ a trick here for avoiding cos(...) and sin(...) in time
763 shifting. We need to multiply each template frequency bin by
764 exp(-J*twopit*deltaF*i) = exp(-J*twopit*deltaF*(i-1)) +
765 exp(-J*twopit*deltaF*(i-1))*(exp(-J*twopit*deltaF) - 1) . This
766 recurrance relation has the advantage that the error growth is
767 O(sqrt(N)) for N repetitions. */
768
769 /* See, for example,
770
771 Press, Teukolsky, Vetteling & Flannery, 2007. Numerical
772 Recipes, Third Edition, Chapter 5.4.
773
774 Singleton, 1967. On computing the fast Fourier
775 transform. Comm. ACM, vol. 10, 647–654. */
776
777 /* Incremental values, using cos(theta) - 1 = -2*sin(theta/2)^2 */
778 dim = -sin(twopit*deltaF);
779 dre = -2.0*sin(0.5*twopit*deltaF)*sin(0.5*twopit*deltaF);
780
781 //Set up noise PSD meta parameters
782 for(i=0; i<Nblock; i++)
783 {
784 if(psdFlag)
785 {
786 alpha[i] = gsl_matrix_get(nparams,ifo,i);
787 lnalpha[i] = log(alpha[i]);
788
789 psdBandsMin_array[i] = gsl_matrix_get(psdBandsMin,ifo,i);
790 psdBandsMax_array[i] = gsl_matrix_get(psdBandsMax,ifo,i);
791 }
792 else
793 {
794 alpha[i]=1.0;
795 lnalpha[i]=0.0;
796 }
797 }
798
799 if (model->roq_flag) {
800
801 double complex weight_iii;
802
803 if (spcal_active){
804
805 for(unsigned int iii=0; iii < model->roq->frequencyNodesLinear->length; iii++){
806
807 complex double template_EI = model->roq->calFactorLinear->data[iii] * (dataPtr->fPlus*model->roq->hptildeLinear->data->data[iii] + dataPtr->fCross*model->roq->hctildeLinear->data->data[iii] );
808
809 weight_iii = gsl_spline_eval (dataPtr->roq->weights_linear[iii].spline_real_weight_linear, timeshift, dataPtr->roq->weights_linear[iii].acc_real_weight_linear) + I*gsl_spline_eval (dataPtr->roq->weights_linear[iii].spline_imag_weight_linear, timeshift, dataPtr->roq->weights_linear[iii].acc_imag_weight_linear);
810
811 this_ifo_d_inner_h += ( weight_iii * ( conj( template_EI ) ) );
812 }
813
814 for(unsigned int jjj=0; jjj < model->roq->frequencyNodesQuadratic->length; jjj++){
815
816 this_ifo_s += dataPtr->roq->weightsQuadratic[jjj] * creal( conj( model->roq->calFactorQuadratic->data[jjj] * (model->roq->hptildeQuadratic->data->data[jjj]*dataPtr->fPlus + model->roq->hctildeQuadratic->data->data[jjj]*dataPtr->fCross) ) * ( model->roq->calFactorQuadratic->data[jjj] * (model->roq->hptildeQuadratic->data->data[jjj]*dataPtr->fPlus + model->roq->hctildeQuadratic->data->data[jjj]*dataPtr->fCross) ) );
817 }
818 }
819
820 else{
821
822 for(unsigned int iii=0; iii < model->roq->frequencyNodesLinear->length; iii++){
823
824 complex double template_EI = dataPtr->fPlus*model->roq->hptildeLinear->data->data[iii] + dataPtr->fCross*model->roq->hctildeLinear->data->data[iii];
825
826 weight_iii = gsl_spline_eval (dataPtr->roq->weights_linear[iii].spline_real_weight_linear, timeshift, dataPtr->roq->weights_linear[iii].acc_real_weight_linear) + I*gsl_spline_eval (dataPtr->roq->weights_linear[iii].spline_imag_weight_linear, timeshift, dataPtr->roq->weights_linear[iii].acc_imag_weight_linear);
827
828 this_ifo_d_inner_h += weight_iii*conj(template_EI) ;
829
830 }
831
832 for(unsigned int jjj=0; jjj < model->roq->frequencyNodesQuadratic->length; jjj++){
833 complex double template_EI = model->roq->hptildeQuadratic->data->data[jjj]*Fplus + model->roq->hctildeQuadratic->data->data[jjj]*Fcross;
834
835 this_ifo_s += dataPtr->roq->weightsQuadratic[jjj] * creal( conj(template_EI) * (template_EI) );
836 }
837 }
838
839 d_inner_h += creal(this_ifo_d_inner_h);
840 // D gets the factor of 2 inside nullloglikelihood
841 // R gets a factor of 2 later, before entering the Bessel function
842 S += 0.5*this_ifo_s;
843 D += -dataPtr->nullloglikelihood;
844 Rcplx += 0.5*this_ifo_d_inner_h;
845
846 model->ifo_loglikelihoods[ifo] = creal(this_ifo_d_inner_h) - (0.5*this_ifo_s) + dataPtr->nullloglikelihood;
847
848 switch(marginalisationflags)
849 {
850 case GAUSSIAN:
851 case STUDENTT:
852 loglikelihood += model->ifo_loglikelihoods[ifo];
853 break;
854 case MARGTIME:
855 case MARGPHI:
856 case MARGTIMEPHI:
857 /* These are non-separable likelihoods, so single IFO log(L)
858 doesn't make sense. */
859 model->ifo_loglikelihoods[ifo] = 0.0;
860 break;
861 default:
862 break;
863 }
864
865 char varname[VARNAME_MAX];
866 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_optimal_snr",dataPtr->name)))
867 {
868 fprintf(stderr,"variable name too long\n"); exit(1);
869 }
870 REAL8 this_ifo_snr = sqrt(this_ifo_s);
871 model->ifo_SNRs[ifo] = this_ifo_snr;
873
874 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_cplx_snr_amp",dataPtr->name)))
875 {
876 fprintf(stderr,"variable name too long\n"); exit(1);
877 }
878 REAL8 cplx_snr_amp = cabs(this_ifo_d_inner_h)/this_ifo_snr;
880
881 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_cplx_snr_arg",dataPtr->name)))
882 {
883 fprintf(stderr,"variable name too long\n"); exit(1);
884 }
885 REAL8 cplx_snr_phase = carg(this_ifo_d_inner_h);
887
888 }
889 else{
890 REAL8 *psd=&(dataPtr->oneSidedNoisePowerSpectrum->data->data[lower]);
891 COMPLEX16 *dtilde=&(dataPtr->freqData->data->data[lower]);
892 COMPLEX16 *hptilde=&(model->freqhPlus->data->data[lower]);
893 COMPLEX16 *hctilde=&(model->freqhCross->data->data[lower]);
894 COMPLEX16 diff=0.0;
895 COMPLEX16 template=0.0;
896 REAL8 templatesq=0.0;
897 REAL8 this_ifo_S=0.0;
898 COMPLEX16 this_ifo_Rcplx=0.0;
899
900 for (i=lower,chisq=0.0,re = cos(twopit*deltaF*i),im = -sin(twopit*deltaF*i);
901 i<=upper;
902 i++, psd++, hptilde++, hctilde++, dtilde++,
903 newRe = re + re*dre - im*dim,
904 newIm = im + re*dim + im*dre,
905 re = newRe, im = newIm)
906 {
907
908 COMPLEX16 d=*dtilde;
909 /* Normalise PSD to our funny standard (see twoDeltaTOverN
910 below). */
911 REAL8 sigmasq=(*psd)*deltaT*deltaT;
912
913 if (constantcal_active) {
914 REAL8 dre_tmp= creal(d)*cos_calpha - cimag(d)*sin_calpha;
915 REAL8 dim_tmp = creal(d)*sin_calpha + cimag(d)*cos_calpha;
916 dre_tmp/=(1.0+calamp);
917 dim_tmp/=(1.0+calamp);
918
919 d=crect(dre_tmp,dim_tmp);
920 sigmasq/=((1.0+calamp)*(1.0+calamp));
921 }
922
923 REAL8 singleFreqBinTerm;
924
925
926 /* Add noise PSD parameters to the model */
927 if(psdFlag)
928 {
929 for(j=0; j<Nblock; j++)
930 {
931 if (i >= psdBandsMin_array[j] && i <= psdBandsMax_array[j])
932 {
933 sigmasq *= alpha[j];
934 loglikelihood -= lnalpha[j];
935 }
936 }
937 }
938
939 //subtract GW model from residual
940 diff = d;
941
942 if(signalFlag){
943 /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */
944 COMPLEX16 plainTemplate = Fplus*(*hptilde)+Fcross*(*hctilde);
945
946 /* Do time shifting */
947 template = plainTemplate * (re + I*im);
948
949 if (spcal_active) {
950 calF = calFactor->data->data[i];
951 template = template*calF;
952 }
953
954 diff -= template;
955
956 }//end signal subtraction
957
958 //subtract glitch model from residual
959 if(glitchFlag)
960 {
961 /* fourier amplitudes of glitches */
962 glitchReal = gsl_matrix_get(glitchFD,ifo,2*i);
963 glitchImag = gsl_matrix_get(glitchFD,ifo,2*i+1);
964 COMPLEX16 glitch = glitchReal + I*glitchImag;
965 diff -=glitch*deltaT;
966
967 }//end glitch subtraction
968
969 templatesq=creal(template)*creal(template) + cimag(template)*cimag(template);
970 REAL8 datasq = creal(d)*creal(d)+cimag(d)*cimag(d);
971 D+=TwoDeltaToverN*datasq/sigmasq;
972 this_ifo_S+=TwoDeltaToverN*templatesq/sigmasq;
973 COMPLEX16 dhstar = TwoDeltaToverN*d*conj(template)/sigmasq;
974 this_ifo_Rcplx+=dhstar;
975 Rcplx+=dhstar;
976
977 switch(marginalisationflags)
978 {
979 case GAUSSIAN:
980 {
981 REAL8 diffsq = creal(diff)*creal(diff)+cimag(diff)*cimag(diff);
982 chisq = TwoDeltaToverN*diffsq/sigmasq;
983 singleFreqBinTerm = chisq;
984 //chisquared += singleFreqBinTerm;
985 model->ifo_loglikelihoods[ifo] -= singleFreqBinTerm;
986 break;
987 }
988 case STUDENTT:
989 {
990 REAL8 diffsq = creal(diff)*creal(diff)+cimag(diff)*cimag(diff);
991 chisq = TwoDeltaToverN*diffsq/sigmasq;
992 singleFreqBinTerm = ((degreesOfFreedom+2.0)/2.0) * log(1.0 + chisq/degreesOfFreedom) ;
993 //chisquared += singleFreqBinTerm;
994 model->ifo_loglikelihoods[ifo] -= singleFreqBinTerm;
995 break;
996 }
997 case MARGTIME:
998 case MARGTIMEPHI:
999 {
1000 loglikelihood+=-TwoDeltaToverN*(templatesq+datasq)/sigmasq;
1001
1002 /* Note: No Factor of 2 here, since we are using the 2-sided
1003 COMPLEX16FFT. Also, we use d*conj(h) because we are
1004 using a complex->real *inverse* FFT to compute the
1005 time-series of likelihoods. */
1006 dh_S_tilde->data[i] += TwoDeltaToverN * d * conj(template) / sigmasq;
1007
1008 if (margphi) {
1009 /* This is the other phase quadrature */
1010 dh_S_phase_tilde->data[i] += TwoDeltaToverN * d * conj(I*template) / sigmasq;
1011 }
1012
1013 break;
1014 }
1015 case MARGPHI:
1016 {
1017 break;
1018 }
1019 default:
1020 break;
1021 }
1022
1023
1024
1025 } /* End loop over freq bins */
1026 switch(marginalisationflags)
1027 {
1028 case GAUSSIAN:
1029 case STUDENTT:
1030 loglikelihood += model->ifo_loglikelihoods[ifo];
1031 break;
1032 case MARGTIME:
1033 case MARGPHI:
1034 case MARGTIMEPHI:
1035 /* These are non-separable likelihoods, so single IFO log(L)
1036 doesn't make sense. */
1037 model->ifo_loglikelihoods[ifo] = 0.0;
1038 break;
1039 default:
1040 break;
1041 }
1042 S+=this_ifo_S;
1043 char varname[VARNAME_MAX];
1044 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_optimal_snr",dataPtr->name)))
1045 {
1046 fprintf(stderr,"variable name too long\n"); exit(1);
1047 }
1049
1050 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_cplx_snr_amp",dataPtr->name)))
1051 {
1052 fprintf(stderr,"variable name too long\n"); exit(1);
1053 }
1054 REAL8 cplx_snr_amp=0.0;
1055 REAL8 cplx_snr_phase=carg(this_ifo_Rcplx);
1056 if(this_ifo_S > 0) cplx_snr_amp=2.0*cabs(this_ifo_Rcplx)/sqrt(2.0*this_ifo_S);
1057
1059
1060 if((VARNAME_MAX <= snprintf(varname,VARNAME_MAX,"%s_cplx_snr_arg",dataPtr->name)))
1061 {
1062 fprintf(stderr,"variable name too long\n"); exit(1);
1063 }
1065 if(margdist )
1066 {
1067 if (margphi)
1068 {
1069 XLAL_TRY(model->ifo_loglikelihoods[ifo] = LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(this_ifo_S), 2.0*cabs(this_ifo_Rcplx), cosmology, margphi), errnum);
1070 }
1071 else
1072 {
1073 XLAL_TRY(model->ifo_loglikelihoods[ifo] = LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(this_ifo_S), 2.0*creal(this_ifo_Rcplx), cosmology, margphi), errnum);
1074 }
1075 errnum&=~XLAL_EFUNC;
1076 if(errnum!=XLAL_SUCCESS)
1077 {
1078 switch(errnum)
1079 {
1080 case XLAL_ERANGE: /* The SNR input was outside the interpolation range */
1081 if(calFactor) {XLALDestroyCOMPLEX16FrequencySeries(calFactor); calFactor=NULL;}
1082 return (-INFINITY);
1083 break;
1084 default: /* Panic! */
1085 fprintf(stderr,"Unhandled error in marginal distance likelihood - exiting!\n");
1086 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1087 exit(1);
1088 break;
1089 }
1090 }
1091 }
1092 /* Clean up calibration if necessary */
1093 if (!(calFactor == NULL)) {
1095 calFactor = NULL;
1096 }
1097 } /* end loop over detectors */
1098
1099 }
1100 if (model->roq_flag){
1101
1102
1103
1104 REAL8 OptimalSNR=sqrt(S);
1105 REAL8 MatchedFilterSNR = d_inner_h/OptimalSNR;
1106 /* fprintf(stderr, "%f\n", d_inner_h - 0.5*OptimalSNR); */
1109
1110 model->SNR = OptimalSNR;
1111
1112 if ( model->roq->hptildeLinear ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hptildeLinear);
1113 if ( model->roq->hctildeLinear ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hctildeLinear);
1114 if ( model->roq->hptildeQuadratic ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hptildeQuadratic);
1115 if ( model->roq->hctildeQuadratic ) XLALDestroyCOMPLEX16FrequencySeries(model->roq->hctildeQuadratic);
1116
1117 if(LALInferenceCheckVariable(model->params, "tilt_spin1")){
1118 mc = *(REAL8*) LALInferenceGetVariable(model->params, "chirpmass");
1119 REAL8 eta=0;
1120 REAL8 m1=0;
1121 REAL8 m2=0;
1122 if(LALInferenceCheckVariable(model->params,"q")) {
1123 REAL8 q = *(REAL8 *)LALInferenceGetVariable(model->params,"q");
1124 m1 = mc * pow(q, -3.0/5.0) * pow(q+1, 1.0/5.0);
1125 m2 = (m1) * q;
1126 eta = (m1*m2) / ((m1+m2)*(m1+m2));
1127 } else {
1128 eta = *(REAL8*) LALInferenceGetVariable(model->params, "eta");
1129 }
1130
1131 REAL8 tilt_spin1 = *(REAL8 *) LALInferenceGetVariable(model->params, "tilt_spin1");
1132 REAL8 a_spin1 = *(REAL8 *) LALInferenceGetVariable(model->params, "a_spin1");
1133 if( cos(tilt_spin1)*a_spin1 <= 0.4 - 7*eta){
1134 // the ROM breaks down for these parameter values so throw a large and negative likelihood to avoid
1135 // strange likelihood values
1136 loglikelihood = -1e15;
1137 //fprintf(stdout, "WARNING: sampling a bad region of parameter space; skipping\n");
1138 }
1139 }
1140
1141 }
1142
1143 // for models which are non-factorising
1144 switch(marginalisationflags)
1145 {
1146 case MARGPHI:
1147 {
1148 REAL8 R = 2.0*cabs(Rcplx);
1149 REAL8 phase_maxL = carg(Rcplx);
1150 if(phase_maxL<0.0) phase_maxL=LAL_TWOPI+phase_maxL;
1153 gsl_sf_result result;
1154 REAL8 I0x=0.0;
1155 if(GSL_SUCCESS==gsl_sf_bessel_I0_scaled_e(R, &result))
1156 {
1157 I0x=result.val;
1158 }
1159 else printf("ERROR: Cannot calculate I0(%lf)\n",R);
1160 /* This is marginalised over phase only for now */
1161 loglikelihood += -(S+D) + log(I0x) + R ;
1162 d_inner_h= 0.5*R;
1163
1164 if(margdist )
1165 {
1166 XLAL_TRY(loglikelihood = LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(S), R, cosmology, margphi), errnum);
1167 errnum&=~XLAL_EFUNC;
1168 if(errnum!=XLAL_SUCCESS)
1169 {
1170 switch(errnum)
1171 {
1172 case XLAL_ERANGE: /* The SNR input was outside the interpolation range */
1173 loglikelihood = -INFINITY;
1174 break;
1175 default: /* Panic! */
1176 fprintf(stderr,"Unhandled error in marginal distance likelihood - exiting!\n");
1177 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1178 exit(1);
1179 break;
1180 }
1181 }
1182 loglikelihood -= D ;
1183 REAL8 distance_maxl = 2.0*S/R;
1185
1186 }
1187 break;
1188 }
1189 case GAUSSIAN:
1190 {
1191 d_inner_h = creal(Rcplx);
1192 if(margdist )
1193 {
1194 XLAL_TRY(loglikelihood = LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(S), 2.0*d_inner_h, cosmology, margphi), errnum);
1195 errnum&=~XLAL_EFUNC;
1196 if(errnum!=XLAL_SUCCESS)
1197 {
1198 switch(errnum)
1199 {
1200 case XLAL_ERANGE: /* The SNR input was outside the interpolation range */
1201 loglikelihood = -INFINITY;
1202 break;
1203 default: /* Panic! */
1204 fprintf(stderr,"Unhandled error in marginal distance likelihood - exiting!\n");
1205 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1206 exit(1);
1207 break;
1208 }
1209 }
1210 loglikelihood -= D ;
1211 REAL8 distance_maxl = S/d_inner_h;
1213
1214 }
1215 break;
1216 }
1217 case MARGTIMEPHI:
1218 case MARGTIME:
1219 {
1220 /* LALSuite only performs complex->real reverse-FFTs. */
1221 dh_S_tilde->data[0] = crect( creal(dh_S_tilde->data[0]), 0. );
1222
1223 XLALREAL8ReverseFFT(dh_S, dh_S_tilde, data->margFFTPlan);
1224
1225 if (margphi) {
1226 dh_S_phase_tilde->data[0] = crect( creal(dh_S_phase_tilde->data[0]), 0.0);
1227 XLALREAL8ReverseFFT(dh_S_phase, dh_S_phase_tilde, data->margFFTPlan);
1228 }
1229
1230 REAL8 time_low,time_high;
1231 LALInferenceGetMinMaxPrior(currentParams,"time",&time_low,&time_high);
1232 t0 = XLALGPSGetREAL8(&(data->freqData->epoch));
1233 int istart = (UINT4)round((time_low - t0)/deltaT);
1234 int iend = (UINT4)round((time_high - t0)/deltaT);
1235 if(iend > (int) dh_S->length || istart < 0 ) {
1236 fprintf(stderr,"ERROR: integration over time extends past end of buffer! Is your time prior too wide?\n");
1237 exit(1);
1238 }
1239 UINT4 n = iend - istart;
1240 REAL8 xMax = -1.0;
1241 REAL8 angMax = 0.0;
1242 if (margphi) {
1243 /* We've got the real and imaginary parts of the FFT in the two
1244 arrays. Now combine them into one Bessel function. */
1245 for (i = istart; i < iend; i++) {
1246 /* Note: No factor of 2 for x because the 2-sided FFT above introduces that for us */
1247 double x = sqrt(dh_S->data[i]*dh_S->data[i] + dh_S_phase->data[i]*dh_S_phase->data[i]);
1248 if (x > xMax) { /* Store the phase angle at max L */
1249 angMax = atan2(dh_S_phase->data[i], dh_S->data[i]);
1250 xMax=x;
1251 }
1252
1253 if(margdist)
1254 {
1255 XLAL_TRY(dh_S->data[i]=LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(S), x, cosmology, margphi) + S, errnum);
1256 errnum&=~XLAL_EFUNC;
1257 if(errnum!=XLAL_SUCCESS)
1258 {
1259 switch(errnum)
1260 {
1261 case XLAL_ERANGE: /* The SNR input was outside the interpolation range */
1262 dh_S->data[i] = -INFINITY;
1263 break;
1264 default: /* Panic! */
1265 fprintf(stderr,"Unhandled error in marginal distance likelihood - exiting!\n");
1266 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1267 exit(1);
1268 break;
1269 }
1270 }
1271 }
1272 else
1273 {
1274 double I0=log(gsl_sf_bessel_I0_scaled(x)) + fabs(x);
1275 dh_S->data[i] = I0;
1276 }
1277 }
1278 }
1279 else
1280 {
1281 if(margdist)
1282 {
1283 for (i = istart; i < iend; i++)
1284 {
1285 XLAL_TRY(dh_S->data[i]=LALInferenceMarginalDistanceLogLikelihood(dist_min, dist_max, sqrt(S), dh_S->data[i], cosmology, margphi) + S, errnum);
1286 errnum&=~XLAL_EFUNC;
1287 if(errnum!=XLAL_SUCCESS)
1288 {
1289 switch(errnum)
1290 {
1291 case XLAL_ERANGE: /* The SNR input was outside the interpolation range */
1292 dh_S->data[i] = -INFINITY;
1293 break;
1294 default: /* Panic! */
1295 fprintf(stderr,"Unhandled error in marginal distance likelihood - exiting!\n");
1296 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1297 exit(1);
1298 break;
1299 }
1300 }
1301 }
1302 }
1303 }
1304 size_t imax;
1305 REAL8 imean;
1306 loglikelihood += integrate_interpolated_log(deltaT, dh_S->data + istart, n, &imean, &imax) - log(n*deltaT);
1307
1308 REAL8 max_time=t0+((REAL8) imax + istart)*deltaT;
1309 REAL8 mean_time=t0+(imean+(double)istart)*deltaT;
1310
1311 if(margphi){
1312 REAL8 phase_maxL=angMax;
1313 if(phase_maxL<0.0) phase_maxL=LAL_TWOPI+phase_maxL;
1316 d_inner_h= 0.5*xMax;
1317 REAL8 distance_maxl = 2.0*S/xMax;
1319 }
1320 else
1321 {
1322 d_inner_h=0.5*dh_S->data[imax+istart];
1323 }
1324 if(margdist)
1325 {
1326 REAL8 distance_maxl = 2.0*S/xMax;
1328 }
1331 XLALDestroyCOMPLEX16Vector(dh_S_tilde);
1333 if (margphi) {
1334 XLALDestroyCOMPLEX16Vector(dh_S_phase_tilde);
1335 XLALDestroyREAL8Vector(dh_S_phase);
1336 }
1337 break;
1338 }
1339 default:
1340 break;
1341
1342 }
1343 /* SNR variables */
1344 REAL8 OptimalSNR=sqrt(2.0*S);
1345 REAL8 MatchedFilterSNR = 0.;
1346
1347
1348 /* Avoid nan's, since noise-only model has OptimalSNR == 0. */
1349 if (OptimalSNR > 0.)
1350 MatchedFilterSNR = 2.0*d_inner_h/OptimalSNR;
1351
1352 if(margdist) /* If margdist enabled, scale snr to optimal distance */
1353 {
1354 OptimalSNR/=LALInferenceGetREAL8Variable(currentParams,"distance_maxl");
1355 /* Adjust the snrs in the IFOs */
1356 REAL8 coherence=loglikelihood + D;
1357 UINT4 ii;
1358 for(dataPtr=data,ii=0;dataPtr;dataPtr=dataPtr->next,ii++)
1359 {
1360 char varname[VARNAME_MAX];
1361 sprintf(varname,"%s_optimal_snr",dataPtr->name);
1363 if(s) *s/=LALInferenceGetREAL8Variable(currentParams,"distance_maxl");
1364 coherence -= model->ifo_loglikelihoods[ii];
1365 }
1367 }
1368
1371
1372 //loglikelihood = -1.0 * chisquared; // note (again): the log-likelihood is unnormalised!
1373
1374 if(LALInferenceCheckVariable(model->params, "lambdaS")){
1375
1376 REAL8 lambda1 = 0.0;
1377 REAL8 lambda2 = 0.0;
1378
1379 /*
1380 When using TimeMarginalised likelihood, the functions in LALInferenceTemplate.c appears not to be called
1381 for the first likelihood evaluation.
1382 This menas that the lambda1 and lambda2 parameters aren't added into model->params.
1383 So, we check if they are here, and if not run model->params through LALInferenceBinaryLove to fill them in!
1384 */
1385
1386 if (LALInferenceCheckVariable(model->params, "lambda1") && LALInferenceCheckVariable(model->params, "lambda2")){
1387 lambda1 = *(REAL8 *)LALInferenceGetVariable(model->params,"lambda1");
1388 lambda2 = *(REAL8 *)LALInferenceGetVariable(model->params,"lambda2");
1389 } else {
1391 }
1392
1395 // The BinaryLove model is only physically valid where lambda2 > lambda1 as it assumes m1 > m2
1396 // It also assumes both lambda1 and lambda2 to be positive
1397 // This is an explicit feature of the "raw" model fit, but since this implementation also incorporates
1398 // marginalisation over the fit uncertainty, there can be instances where those assumptions are randomly broken
1399 // for those cases, set logL = -inf.
1400 if( (lambda1 > lambda2) || (lambda1 < 0.0) || (lambda2 < 0.0)){
1401 loglikelihood = -INFINITY;
1402 }
1403 }
1404
1405 return(loglikelihood);
1406}
1407
1408double LALInferenceMarginalDistanceLogLikelihood(double dist_min, double dist_max, double OptimalSNR, double d_inner_h, int cosmology, int margphi)
1409{
1410 static const size_t default_log_radial_integrator_size = 400;
1411 double loglikelihood=0;
1412 static double log_norm = 0;
1413 static log_radial_integrator *integrator;
1414
1415 double pmax = 100000; /* CHECKME: Max SNR allowed ? */
1416 #pragma omp critical
1417 {
1418 if (integrator == NULL)
1419 {
1420 printf("Initialising distance integration lookup table\n");
1421 /* Initialise the integrator for the first time */
1422 integrator = log_radial_integrator_init(
1423 dist_min,
1424 dist_max,
1425 2, /* Power of distance in prior */
1426 cosmology,
1427 pmax,
1428 default_log_radial_integrator_size * 5, /* CHECKME: fudge factor of 5 compared to bayestar */
1429 !margphi);
1430 /* distance prior normalisation */
1431 log_norm = log_radial_integrator_eval(integrator, 0, 0, -INFINITY, -INFINITY);
1432 }
1433 }
1434 #pragma omp barrier
1435 if (!integrator) XLAL_ERROR(XLAL_EFUNC, "Unable to initialise distance marginalisation integrator");
1436
1437 if (isnan(OptimalSNR) || isnan(d_inner_h) || pmax<OptimalSNR)
1438 {
1439 loglikelihood=-INFINITY;
1440 XLAL_ERROR(XLAL_ERANGE,"warning: Optimal SNR %lf exceeded pmax %lf\n",OptimalSNR, pmax);
1441 }
1442 else
1443 {
1444 double marg_l = log_radial_integrator_eval(integrator, OptimalSNR , d_inner_h, log(OptimalSNR), log(d_inner_h));
1445 loglikelihood = marg_l - log_norm; /* Normalise prior */
1446 }
1447 return (loglikelihood);
1448}
1449
1450/***************************************************************/
1451/* Student-t (log-) likelihood function */
1452/* as described in Roever/Meyer/Christensen (2011): */
1453/* "Modelling coloured residual noise */
1454/* in gravitational-wave signal processing." */
1455/* Classical and Quantum Gravity, 28(1):015010. */
1456/* http://dx.doi.org/10.1088/0264-9381/28/1/015010 */
1457/* http://arxiv.org/abs/0804.3853 */
1458/* Returns the non-normalised logarithmic likelihood. */
1459/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1460/* Required (`currentParams') parameters are: */
1461/* - "rightascension" (REAL8, radian, 0 <= RA <= 2pi) */
1462/* - "declination" (REAL8, radian, -pi/2 <= dec <=pi/2) */
1463/* - "polarisation" (REAL8, radian, 0 <= psi <= ?) */
1464/* - "time" (REAL8, GPS sec.) */
1465/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1466/* This function is essentially the same as the */
1467/* "UndecomposedFreqDomainLogLikelihood()" function. */
1468/* The additional parameter to be supplied is the (REAL8) */
1469/* degrees-of-freedom parameter (nu) for each Ifo. */
1470/* The additional "df" argument gives the corresponding */
1471/* d.f. parameter for each element of the "*data" list. */
1472/* The names of "df" must match the "->name" slot of */
1473/* the elements of "data". */
1474/* */
1475/* (TODO: allow for d.f. parameter to vary with frequency, */
1476/* i.e., to be a set of vectors corresponding to */
1477/* frequencies) */
1478/***************************************************************/
1479
1481 LALInferenceIFOData *data,
1482 LALInferenceModel *model)
1483{
1484
1486
1487}
1488
1489
1491 COMPLEX16Vector * freqData1,
1492 COMPLEX16Vector * freqData2)
1493{
1494 if (dataPtr==NULL || freqData1 ==NULL || freqData2==NULL){
1496 }
1497
1498 int lower, upper, i;
1499 double deltaT, deltaF;
1500
1501 double overlap=0.0;
1502
1503 /* determine frequency range & loop over frequency bins: */
1504 deltaT = dataPtr->timeData->deltaT;
1505 deltaF = 1.0 / (((double)dataPtr->timeData->data->length) * deltaT);
1506 lower = ceil(dataPtr->fLow / deltaF);
1507 upper = floor(dataPtr->fHigh / deltaF);
1508
1509 for (i=lower; i<=upper; ++i){
1510 overlap += ((4.0*deltaF*(creal(freqData1->data[i])*creal(freqData2->data[i])+cimag(freqData1->data[i])*cimag(freqData2->data[i])))
1511 / dataPtr->oneSidedNoisePowerSpectrum->data->data[i]);
1512 }
1513
1514 return overlap;
1515}
1516
1518 COMPLEX16Vector * freqData1,
1519 COMPLEX16Vector * freqData2)
1520{
1521 if (dataPtr==NULL || freqData1 ==NULL || freqData2==NULL){
1523 }
1524
1525 int lower, upper, i;
1526 double deltaT, deltaF;
1527
1528 COMPLEX16 overlap=0.0;
1529
1530 /* determine frequency range & loop over frequency bins: */
1531 deltaT = dataPtr->timeData->deltaT;
1532 deltaF = 1.0 / (((double)dataPtr->timeData->data->length) * deltaT);
1533 lower = ceil(dataPtr->fLow / deltaF);
1534 upper = floor(dataPtr->fHigh / deltaF);
1535
1536 for (i=lower; i<=upper; ++i){
1537 overlap += 4.0*deltaF * freqData1->data[i] * conj(freqData2->data[i]) / dataPtr->oneSidedNoisePowerSpectrum->data->data[i];
1538 }
1539
1540 return overlap;
1541}
1542
1544/*Identical to FreqDomainNullLogLikelihood */
1545{
1546 REAL8 loglikelihood, totalChiSquared=0.0;
1547 LALInferenceIFOData *ifoPtr=data;
1548
1549 /* loop over data (different interferometers): */
1550 while (ifoPtr != NULL) {
1551 ifoPtr->nullloglikelihood = 0.0;
1553 totalChiSquared+=temp;
1554 ifoPtr->nullloglikelihood -= 0.5*temp;
1555 ifoPtr = ifoPtr->next;
1556 }
1557 loglikelihood = -0.5 * totalChiSquared; // note (again): the log-likelihood is unnormalised!
1558 return(loglikelihood);
1559}
1560
1562 LALInferenceIFOData *data,
1563 LALInferenceModel *model)
1564/***************************************************************/
1565/* (log-) likelihood function. */
1566/* Returns the non-normalised logarithmic likelihood. */
1567/* Analytically marginalised over phase and distance */
1568/* See LIGO-T1300326 for details */
1569/* At a distance of 1 Mpc for phi_0=0 */
1570/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1571/* Required (`currentParams') parameters are: */
1572/* - "rightascension" (REAL8, radian, 0 <= RA <= 2pi) */
1573/* - "declination" (REAL8, radian, -pi/2 <= dec <=pi/2) */
1574/* - "polarisation" (REAL8, radian, 0 <= psi <= ?) */
1575/* - "time" (REAL8, GPS sec.) */
1576/***************************************************************/
1577{
1579}
1580
1581/** Integrate interpolated log, returns the mean index in *imax if it
1582 * is not a NULL pointer. Stores the mean index in *imean (can be
1583 * fractional).
1584 *
1585 * The method used is the trapezoid method, which is quadratically
1586 * accurate.
1587 */
1588static double integrate_interpolated_log(double h, REAL8 *log_ys, size_t n, double *imean, size_t *imax) {
1589 size_t i;
1590 double log_integral = -INFINITY;
1591 double max=-INFINITY;
1592 size_t imax_l=0;
1593 double log_imean_l=-INFINITY;
1594 double log_h = log(h);
1595
1596 for (i = 1; i < n-1; i++) {
1597 log_integral = logaddexp(log_integral, log_ys[i]);
1598 log_imean_l = logaddexp(log_imean_l, log(i) + log_ys[i]);
1599
1600 if (log_ys[i] > max) {
1601 max = log_ys[i];
1602 imax_l = i;
1603 }
1604 }
1605
1606 log_integral = logaddexp(log_integral, log(0.5) + log_ys[0]);
1607 log_integral = logaddexp(log_integral, log(0.5) + log_ys[n-1]);
1608
1609 /* No contribution to mean index from i = 0 term! */
1610 log_imean_l = logaddexp(log_imean_l, log(0.5) + log(n-1) + log_ys[n-1]);
1611
1612 log_integral += log_h;
1613 log_imean_l += log_h;
1614
1615 if (creal(log_ys[0]) > max) {
1616 max = log_ys[0];
1617 imax_l = 0;
1618 }
1619
1620 if (log_ys[n-1] > max) {
1621 max = log_ys[n-1];
1622 imax_l = n-1;
1623 }
1624
1625 log_imean_l -= log_integral;
1626
1627 if(imean) *imean=exp(log_imean_l-log_integral);
1628 if(imax) *imax=imax_l;
1629
1630 return log_integral;
1631}
1632
1634 LALInferenceIFOData *data,
1635 LALInferenceModel *model)
1636{
1637
1639
1640
1641}
1642
1644 LALInferenceIFOData *data,
1645 LALInferenceModel *model)
1646{
1647
1649
1650
1651}
1652
1654 LALInferenceIFOData *data,
1655 LALInferenceModel *model)
1656/***************************************************************/
1657/* This is basically a loglikelihood for LIB that does not do */
1658/* any check for extra options (marginalization, calibration, */
1659/* As such, it is slighly faster. Don't use if you don't know */
1660/* what you are doing */
1661/* Returns the non-normalised logarithmic likelihood. */
1662/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1663/* Required (`currentParams') parameters are: */
1664/* - "rightascension" (REAL8, radian, 0 <= RA <= 2pi) */
1665/* - "declination" (REAL8, radian, -pi/2 <= dec <=pi/2) */
1666/* - "polarisation" (REAL8, radian, 0 <= psi <= ?) */
1667/* - "time" (REAL8, GPS sec.) */
1668/***************************************************************/
1669{
1670 double Fplus, Fcross;
1671 int i, lower, upper, ifo;
1672 LALInferenceIFOData *dataPtr;
1673 double ra=0.0, dec=0.0, psi=0.0, gmst=0.0;
1674 double GPSdouble=0.0;
1675 LIGOTimeGPS GPSlal;
1676 double timedelay; /* time delay b/w iterferometer & geocenter w.r.t. sky location */
1677 double timeshift=0; /* time shift (not necessarily same as above) */
1678 double deltaT, TwoDeltaToverN, deltaF, twopit=0.0, re, im, dre, dim, newRe, newIm;
1679 double timeTmp;
1680 /* Burst templates are generated at hrss=1, thus need to rescale amplitude */
1681 double amp_prefactor=1.0;
1682
1683 REAL8 chisq=0.0;
1685 memset(&status,0,sizeof(status));
1686
1687 if(data==NULL) {XLAL_ERROR_REAL8(XLAL_EINVAL,"ERROR: Encountered NULL data pointer in likelihood\n");}
1688
1689 int Nifos=0;
1690 for(dataPtr=data;dataPtr;dataPtr=dataPtr->next) Nifos++;
1691 void *generatedFreqModels[1+Nifos];
1692 for(i=0;i<=Nifos;i++) generatedFreqModels[i]=NULL;
1693
1695 amp_prefactor = exp(*(REAL8*)LALInferenceGetVariable(currentParams,"loghrss"));
1696 }
1697 else if (LALInferenceCheckVariable(currentParams, "hrss")){
1698 amp_prefactor = (*(REAL8*)LALInferenceGetVariable(currentParams,"hrss"));
1699 }
1700
1701 /* determine source's sky location & orientation parameters: */
1702 psi = *(REAL8*) LALInferenceGetVariable(currentParams, "polarisation"); /* radian */
1703 GPSdouble = *(REAL8*) LALInferenceGetVariable(currentParams, "time"); /* GPS seconds */
1704
1705 INT4 SKY_FRAME=0;
1707 SKY_FRAME=*(INT4 *)LALInferenceGetVariable(currentParams,"SKY_FRAME");
1708 if(SKY_FRAME==0){
1709 /* determine source's sky location & orientation parameters: */
1710 ra = *(REAL8*) LALInferenceGetVariable(currentParams, "rightascension"); /* radian */
1711 dec = *(REAL8*) LALInferenceGetVariable(currentParams, "declination"); /* radian */
1712 }
1713 else
1714 {
1715 if(Nifos<2){
1716 fprintf(stderr,"ERROR: Cannot use --detector-frame with less than 2 detectors!\n");
1717 exit(1);
1718 }
1720 REAL8 alph=acos(LALInferenceGetREAL8Variable(currentParams,"cosalpha"));
1722 LALInferenceDetFrameToEquatorial(data->detector,data->next->detector,
1723 t0,alph,theta,&GPSdouble,&ra,&dec);
1727 }
1728
1729 deltaT = data->timeData->deltaT;
1730 /* figure out GMST: */
1731 XLALGPSSetREAL8(&GPSlal, GPSdouble);
1732 gmst=XLALGreenwichMeanSiderealTime(&GPSlal);
1733
1734 REAL8 loglikelihood = 0.0;
1735
1736 /* Reset SNR */
1737 model->SNR = 0.0;
1738
1739 /* loop over data (different interferometers): */
1740 for(dataPtr=data,ifo=0; dataPtr; dataPtr=dataPtr->next,ifo++) {
1741 /* The parameters the Likelihood function can handle by itself */
1742 /* (and which shouldn't affect the template function) are */
1743 /* sky location (ra, dec), polarisation and signal arrival time. */
1744 /* Note that the template function shifts the waveform to so that*/
1745 /* t_c corresponds to the "time" parameter in */
1746 /* model->params (set, e.g., from the trigger value). */
1747
1748 /* Reset log-likelihood */
1749 model->ifo_loglikelihoods[ifo] = 0.0;
1750 model->ifo_SNRs[ifo] = 0.0;
1751
1752 /* Check to see if this buffer has already been filled with the signal.
1753 Different dataPtrs can share the same signal buffer to avoid repeated
1754 calls to template */
1755 if(!checkItemAndAdd((void *)(model->freqhPlus), generatedFreqModels))
1756 {
1757 /* Compare parameter values with parameter values corresponding */
1758 /* to currently stored template; ignore "time" variable: */
1759 if (LALInferenceCheckVariable(model->params, "time")) {
1760 timeTmp = *(REAL8 *) LALInferenceGetVariable(model->params, "time");
1761 LALInferenceRemoveVariable(model->params, "time");
1762 }
1763 else timeTmp = GPSdouble;
1764
1766 // Remove time variable so it can be over-written (if it was pinned)
1767 if(LALInferenceCheckVariable(model->params,"time")) LALInferenceRemoveVariable(model->params,"time");
1769
1770 INT4 errnum=0;
1771 XLAL_TRY(model->templt(model),errnum);
1772 errnum&=~XLAL_EFUNC;
1773 if(errnum!=XLAL_SUCCESS)
1774 {
1775 switch(errnum)
1776 {
1777 case XLAL_EUSR0: /* Template generation failed in a known way, set -Inf likelihood */
1778 return (-INFINITY);
1779 break;
1780 default: /* Panic! */
1781 fprintf(stderr,"Unhandled error in template generation - exiting!\n");
1782 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
1783 exit(1);
1784 break;
1785 }
1786
1787 }
1788
1789 }
1790 /* Template is now in model->timeFreqhPlus and hCross */
1791
1792 /* determine beam pattern response (F_plus and F_cross) for given Ifo: */
1793 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])dataPtr->detector->response, ra, dec, psi, gmst);
1794 /* signal arrival time (relative to geocenter); */
1795 timedelay = XLALTimeDelayFromEarthCenter(dataPtr->detector->location, ra, dec, &GPSlal);
1796 /* (negative timedelay means signal arrives earlier at Ifo than at geocenter, etc.) */
1797 /* amount by which to time-shift template (not necessarily same as above "timedelay"): */
1798 timeshift = (GPSdouble - (*(REAL8*) LALInferenceGetVariable(model->params, "time"))) + timedelay;
1799 twopit = LAL_TWOPI * timeshift;
1800
1801 /* For burst the effect of windowing in amplitude is important. Add it here. */
1802 Fplus*=amp_prefactor;
1803 Fcross*=amp_prefactor;
1804
1805 dataPtr->fPlus = Fplus;
1806 dataPtr->fCross = Fcross;
1807 dataPtr->timeshift = timeshift;
1808
1809
1810 /* determine frequency range & loop over frequency bins: */
1811 deltaF = 1.0 / (((double)dataPtr->timeData->data->length) * deltaT);
1812 lower = (UINT4)ceil(dataPtr->fLow / deltaF);
1813 upper = (UINT4)floor(dataPtr->fHigh / deltaF);
1814 TwoDeltaToverN = 2.0 * deltaT / ((double) dataPtr->timeData->data->length);
1815
1816 /* Employ a trick here for avoiding cos(...) and sin(...) in time
1817 shifting. We need to multiply each template frequency bin by
1818 exp(-J*twopit*deltaF*i) = exp(-J*twopit*deltaF*(i-1)) +
1819 exp(-J*twopit*deltaF*(i-1))*(exp(-J*twopit*deltaF) - 1) . This
1820 recurrance relation has the advantage that the error growth is
1821 O(sqrt(N)) for N repetitions. */
1822
1823 /* Incremental values, using cos(theta) - 1 = -2*sin(theta/2)^2*/
1824 dim = -sin(twopit*deltaF);
1825 dre = -2.0*sin(0.5*twopit*deltaF)*sin(0.5*twopit*deltaF);
1826
1827 REAL8 *psd=&(dataPtr->oneSidedNoisePowerSpectrum->data->data[lower]);
1828 COMPLEX16 *dtilde=&(dataPtr->freqData->data->data[lower]);
1829 COMPLEX16 *hptilde=&(model->freqhPlus->data->data[lower]);
1830 COMPLEX16 *hctilde=&(model->freqhCross->data->data[lower]);
1831 COMPLEX16 diff=0.0;
1832 COMPLEX16 template=0.0;
1833 INT4 upppone=upper+1;
1834 for (i=lower,chisq=0.0,re = cos(twopit*deltaF*i),im = -sin(twopit*deltaF*i);
1835 i<upppone;
1836 i++, psd++, hptilde++, hctilde++, dtilde++,
1837 newRe = re + re*dre - im*dim,
1838 newIm = im + re*dim + im*dre,
1839 re = newRe, im = newIm)
1840 {
1841
1842 COMPLEX16 d=*dtilde;
1843 /* Normalise PSD to our funny standard (see twoDeltaTOverN below). */
1844 REAL8 sigmasq=(*psd)*deltaT*deltaT;
1845 //subtract GW model from residual
1846 /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */
1847 COMPLEX16 plainTemplate = Fplus*(*hptilde)+Fcross*(*hctilde);
1848
1849 /* Do time shifting */
1850 template = plainTemplate * (re + I*im);
1851 diff = (d - template);
1852
1853 REAL8 diffsq = creal(diff)*creal(diff)+cimag(diff)*cimag(diff);
1854 chisq = TwoDeltaToverN*diffsq/sigmasq;
1855 model->ifo_loglikelihoods[ifo] -= chisq;
1856 } /* End loop over freq bins */
1857
1858 loglikelihood += model->ifo_loglikelihoods[ifo];
1859
1860 } /* end loop over detectors */
1861 // printf("%10.10e\n",loglikelihood);
1862 return(loglikelihood);
1863}
1864
1865
1867 LALInferenceIFOData *data,
1868 LALInferenceModel *model)
1869/***************************************************************/
1870/* Calculate the SNR across the network. */
1871/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1872/* Required (`currentParams') parameters are: */
1873/* - "rightascension" (REAL8, radian, 0 <= RA <= 2pi) */
1874/* - "declination" (REAL8, radian, -pi/2 <= dec <=pi/2) */
1875/* - "polarisation" (REAL8, radian, 0 <= psi <= ?) */
1876/* - "time" (REAL8, GPS sec.) */
1877/***************************************************************/
1878{
1879 double Fplus, Fcross;
1880 REAL8 plainTemplateReal, plainTemplateImag;
1881 int i, lower, upper, ifo;
1882 LALInferenceIFOData *dataPtr;
1883 double ra=0.0, dec=0.0, psi=0.0, gmst=0.0;
1884 double GPSdouble=0.0;
1885 LIGOTimeGPS GPSlal;
1886 double deltaT, TwoOverNDeltaT, deltaF;
1887 double timeTmp;
1888 double mc;
1890 memset(&status,0,sizeof(status));
1891 INT4 remove_time = 0;
1892
1893 int signalFlag = 1; //flag for including signal model
1894
1895 int Nifos=0;
1896 for(dataPtr=data;dataPtr;dataPtr=dataPtr->next) Nifos++;
1897 void *generatedFreqModels[1+Nifos];
1898 for(i=0;i<=Nifos;i++) generatedFreqModels[i]=NULL;
1899
1900 // If time isn't in current params, remove it at the end
1902 remove_time = 1;
1903
1904 //check if signal model is being used
1905 signalFlag=1;
1906 if(LALInferenceCheckVariable(currentParams, "signalModelFlag"))
1907 signalFlag = *((INT4 *)LALInferenceGetVariable(currentParams, "signalModelFlag"));
1908
1909 /* Reset SNRs in model struct */
1910 model->SNR = 0.0;
1911
1912 dataPtr = data;
1913 ifo = 0;
1914 while (dataPtr != NULL) {
1915 model->ifo_SNRs[ifo] = 0.0;
1916 ifo++;
1917 dataPtr = dataPtr->next;
1918 }
1919
1920 if (!signalFlag)
1921 return;
1922
1926 }
1927
1928
1929 INT4 SKY_FRAME=0;
1931 SKY_FRAME=*(INT4 *)LALInferenceGetVariable(currentParams,"SKY_FRAME");
1932 if(SKY_FRAME==0){
1933 /* determine source's sky location & orientation parameters: */
1934 ra = *(REAL8*) LALInferenceGetVariable(currentParams, "rightascension"); /* radian */
1935 dec = *(REAL8*) LALInferenceGetVariable(currentParams, "declination"); /* radian */
1936 }
1937 else
1938 {
1939 if(Nifos<2){
1940 fprintf(stderr,"ERROR: Cannot use --detector-frame with less than 2 detectors!\n");
1941 exit(1);
1942 }
1944 REAL8 alph=acos(LALInferenceGetREAL8Variable(currentParams,"cosalpha"));
1946 LALInferenceDetFrameToEquatorial(data->detector,data->next->detector,
1947 t0,alph,theta,&GPSdouble,&ra,&dec);
1951 }
1952
1953 /* determine source's sky location & orientation parameters: */
1954 ra = *(REAL8*) LALInferenceGetVariable(currentParams, "rightascension"); /* radian */
1955 dec = *(REAL8*) LALInferenceGetVariable(currentParams, "declination"); /* radian */
1956 psi = *(REAL8*) LALInferenceGetVariable(currentParams, "polarisation"); /* radian */
1957
1959 GPSdouble = *(REAL8*) LALInferenceGetVariable(currentParams, "time"); /* GPS seconds */
1960 else {
1961 UINT4 freq_length = data->freqData->data->length;
1962 UINT4 time_length = 2*(freq_length-1);
1963 REAL8 epoch = XLALGPSGetREAL8(&(data->freqData->epoch));
1964 GPSdouble = epoch + (time_length-1)*data->timeData->deltaT - 2.0;
1965 }
1966
1967 /* figure out GMST: */
1968 XLALGPSSetREAL8(&GPSlal, GPSdouble);
1969 gmst=XLALGreenwichMeanSiderealTime(&GPSlal);
1970
1971 ifo=0;
1972 dataPtr = data;
1973 while (dataPtr != NULL) {
1974 /* The parameters the Likelihood function can handle by itself */
1975 /* (and which shouldn't affect the template function) are */
1976 /* sky location (ra, dec), polarisation and signal arrival time. */
1977 /* Note that the template function shifts the waveform to so that*/
1978 /* t_c corresponds to the "time" parameter in */
1979 /* model->params (set, e.g., from the trigger value). */
1980
1981 /* Check to see if this buffer has already been filled with the signal.
1982 Different dataPtrs can share the same signal buffer to avoid repeated
1983 calls to template */
1984 if(!checkItemAndAdd((void *)(model->freqhPlus), generatedFreqModels))
1985 {
1986 /* to currently stored template; ignore "time" variable: */
1987 if (LALInferenceCheckVariable(model->params, "time")) {
1988 timeTmp = *(REAL8 *) LALInferenceGetVariable(model->params, "time");
1989 LALInferenceRemoveVariable(model->params, "time");
1990 }
1991 else timeTmp = GPSdouble;
1992
1994 // Remove time variable so it can be over-written (if it was pinned)
1995 if(LALInferenceCheckVariable(model->params,"time")) LALInferenceRemoveVariable(model->params,"time");
1997 if (!LALInferenceCheckVariable(model->params, "phase")) {
1998 double pi2 = M_PI / 2.0;
2000 }
2001 INT4 errnum=0;
2002 XLAL_TRY(model->templt(model),errnum);
2003 errnum&=~XLAL_EFUNC;
2004 if(errnum!=XLAL_SUCCESS)
2005 {
2006 switch(errnum)
2007 {
2008 case XLAL_EUSR0: /* Template generation failed in a known way, set -Inf likelihood */
2009 return;
2010 break;
2011 default: /* Panic! */
2012 fprintf(stderr,"Unhandled error in template generation - exiting!\n");
2013 fprintf(stderr,"XLALError: %d, %s\n",errnum,XLALErrorString(errnum));
2014 exit(1);
2015 break;
2016 }
2017
2018 }
2019
2020 if (model->domain == LAL_SIM_DOMAIN_TIME) {
2021 /* TD --> FD. */
2022 LALInferenceExecuteFT(model);
2023 }
2024 }
2025
2026 /* Template is now in dataPtr->timeFreqModelhPlus and hCross */
2027
2028 /* determine beam pattern response (F_plus and F_cross) for given Ifo: */
2029 XLALComputeDetAMResponse(&Fplus, &Fcross, (const REAL4(*)[3])dataPtr->detector->response, ra, dec, psi, gmst);
2030
2031 dataPtr->fPlus = Fplus;
2032 dataPtr->fCross = Fcross;
2033
2034 /* determine frequency range & loop over frequency bins: */
2035 deltaT = dataPtr->timeData->deltaT;
2036 deltaF = 1.0 / (((double)dataPtr->timeData->data->length) * deltaT);
2037 lower = (UINT4)ceil(dataPtr->fLow / deltaF);
2038 upper = (UINT4)floor(dataPtr->fHigh / deltaF);
2039 TwoOverNDeltaT = 2.0 / (deltaT * ((double) dataPtr->timeData->data->length));
2040
2041 for (i=lower; i<=upper; ++i){
2042 //subtract GW model from residual
2043 /* derive template (involving location/orientation parameters) from given plus/cross waveforms: */
2044 plainTemplateReal = Fplus * creal(model->freqhPlus->data->data[i])
2045 + Fcross * creal(model->freqhCross->data->data[i]);
2046 plainTemplateImag = Fplus * cimag(model->freqhPlus->data->data[i])
2047 + Fcross * cimag(model->freqhCross->data->data[i]);
2048
2049 /* un-do 1/deltaT scaling: */
2050 model->ifo_SNRs[ifo] += 2.0 * TwoOverNDeltaT * ( plainTemplateReal*plainTemplateReal + plainTemplateImag*plainTemplateImag ) / dataPtr->oneSidedNoisePowerSpectrum->data->data[i];
2051 }
2052
2053 model->SNR += model->ifo_SNRs[ifo];
2054 model->ifo_SNRs[ifo] = sqrt(model->ifo_SNRs[ifo]);
2055
2056 ifo++; //increment IFO counter for noise parameters
2057 dataPtr = dataPtr->next;
2058 }
2059
2060 if (remove_time && LALInferenceCheckVariable(currentParams, "time"))
2062
2063 model->SNR = sqrt(model->SNR);
2064}
static double integrate_interpolated_log(double h, REAL8 *log_ys, size_t n, double *imean, size_t *imax)
Integrate interpolated log, returns the mean index in *imax if it is not a NULL pointer.
static int checkItemAndAdd(void *item, void **array)
REAL8 LALInferenceZeroLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData UNUSED *data, LALInferenceModel UNUSED *model)
For testing purposes (for instance sampling the prior), likelihood that returns 0....
LALInferenceLikelihoodFlags
static int get_calib_spline(LALInferenceVariables *vars, const char *ifoname, REAL8Vector **logfreqs, REAL8Vector **amps, REAL8Vector **phases)
static REAL8 LALInferenceFusedFreqDomainLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model, LALInferenceLikelihoodFlags marginalisationflags)
const char * non_intrinsic_params[]
#define max(a, b)
LALInferenceVariables currentParams
int j
#define fprintf
int s
double theta
double log_radial_integrator_eval(const log_radial_integrator *integrator, double p, double b, double log_p, double log_b)
Evaluate the log distance integrator for given SNRs.
log_radial_integrator * log_radial_integrator_init(double r1, double r2, int k, int cosmology, double pmax, size_t size, int gaussian)
Distance integrator for marginalisation.
sigmaKerr data[0]
void XLALComputeDetAMResponse(double *fplus, double *fcross, const REAL4 D[3][3], const double ra, const double dec, const double psi, const double gmst)
COMPLEX16FrequencySeries * XLALCreateCOMPLEX16FrequencySeries(const CHAR *name, const LIGOTimeGPS *epoch, REAL8 f0, REAL8 deltaF, const LALUnit *sampleUnits, size_t length)
void XLALDestroyCOMPLEX16FrequencySeries(COMPLEX16FrequencySeries *series)
#define LAL_TWOPI
#define crect(re, im)
double complex COMPLEX16
double REAL8
char CHAR
uint32_t UINT4
int32_t INT4
float REAL4
#define VARNAME_MAX
Definition: LALInference.h:50
UINT4 LALInferenceGetUINT4Variable(LALInferenceVariables *vars, const char *name)
int LALInferenceSplineCalibrationFactorROQ(REAL8Vector *logfreqs, REAL8Vector *deltaAmps, REAL8Vector *deltaPhases, REAL8Sequence *freqNodesLin, COMPLEX16Sequence **calFactorROQLin, REAL8Sequence *freqNodesQuad, COMPLEX16Sequence **calFactorROQQuad)
Modified version of LALInferenceSplineCalibrationFactor to compute the calibration factors for the sp...
void LALInferenceAddVariable(LALInferenceVariables *vars, const char *name, const void *value, LALInferenceVariableType type, LALInferenceParamVaryType vary)
Add a variable named name to vars with initial value referenced by value.
Definition: LALInference.c:395
REAL8 LALInferenceGetREAL8Variable(LALInferenceVariables *vars, const char *name)
void LALInferenceExecuteFT(LALInferenceModel *model)
Execute FFT for data in IFOdata.
void LALInferenceRemoveVariable(LALInferenceVariables *vars, const char *name)
Remove name from vars Frees the memory for the name structure and its contents.
Definition: LALInference.c:450
void LALInferenceCopyVariables(LALInferenceVariables *origin, LALInferenceVariables *target)
Deep copy the variables from one to another LALInferenceVariables structure.
Definition: LALInference.c:558
void * LALInferenceGetVariable(const LALInferenceVariables *vars, const char *name)
Return a pointer to the memory the variable vars is stored in specified by name User must cast this p...
Definition: LALInference.c:238
void LALInferenceAddREAL8Variable(LALInferenceVariables *vars, const char *name, REAL8 value, LALInferenceParamVaryType vary)
INT4 LALInferenceGetINT4Variable(LALInferenceVariables *vars, const char *name)
ProcessParamsTable * LALInferenceGetProcParamVal(ProcessParamsTable *procparams, const char *name)
Returns the element of the process params table with "name".
void(* LALInferenceTemplateFunction)(struct tagLALInferenceModel *model)
Type declaration for template function, which operates on a LALInferenceIFOData structure *data.
Definition: LALInference.h:377
void LALInferenceBinaryLove(LALInferenceVariables *vars, REAL8 *lambda1, REAL8 *lambda2)
Compute Tidal deformabilities following BinaryLove Universal relations.
int LALInferenceSplineCalibrationFactor(REAL8Vector *logfreqs, REAL8Vector *deltaAmps, REAL8Vector *deltaPhases, COMPLEX16FrequencySeries *calFactor)
Computes the factor relating the physical waveform to a measured waveform for a spline-fit calibratio...
void LALInferenceDetFrameToEquatorial(LALDetector *det0, LALDetector *det1, REAL8 t0, REAL8 alpha, REAL8 theta, REAL8 *tg, REAL8 *ra, REAL8 *dec)
Conversion routines between Equatorial (RA,DEC) and detector-based coordinate systems,...
int LALInferenceCheckVariable(LALInferenceVariables *vars, const char *name)
Checks for name being present in vars returns 1(==true) or 0.
Definition: LALInference.c:525
@ LALINFERENCE_PARAM_OUTPUT
A parameter that never changes, functions should respect this.
Definition: LALInference.h:131
@ LALINFERENCE_PARAM_FIXED
A parameter that is cyclic, such as an angle between 0 and 2pi.
Definition: LALInference.h:130
@ LALINFERENCE_PARAM_LINEAR
Definition: LALInference.h:128
@ LALINFERENCE_REAL8_t
Definition: LALInference.h:109
REAL8 LALInferenceBimodalCorrelatedAnalyticLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
An analytic likeilhood that is two correlated Gaussians in 15 dimensions.
REAL8 LALInferenceCorrelatedAnalyticLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
An analytic likeilhood that is a correlated Gaussian in 15 dimensions.
REAL8 LALInferenceMarginalisedTimePhaseLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
void LALInferenceInitLikelihood(LALInferenceRunState *runState)
Initialisation function which reads runState->commaneLine and sets up the likelihood function accordi...
REAL8 LALInferenceNullLogLikelihood(LALInferenceIFOData *data)
Identical to LALInferenceFreqDomainNullLogLikelihood, but returns the likelihood of a null template.
double LALInferenceMarginalDistanceLogLikelihood(double dist_min, double dist_max, double OptimalSNR, double d_inner_h, int cosmology, int margphi)
Compute delta-log-likelihood for given distance min, max and OptimalSNR and d_inner_h when evaluated ...
REAL8 LALInferenceFreqDomainStudentTLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
Student-t (log-) likelihood function as described in Roever/Meyer/Christensen (2011): "Modelling colo...
COMPLEX16 LALInferenceComputeFrequencyDomainComplexOverlap(LALInferenceIFOData *dataPtr, COMPLEX16Vector *freqData1, COMPLEX16Vector *freqData2)
Computes the complex <x|y> overlap.
REAL8 LALInferenceFastSineGaussianLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
fast SineGaussian likelihood for LIB
REAL8 LALInferenceMarginalisedTimeLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
Returns the log-likelihood marginalised over the time dimension from the prior min to the prior max.
REAL8 LALInferenceComputeFrequencyDomainOverlap(LALInferenceIFOData *dataPtr, COMPLEX16Vector *freqData1, COMPLEX16Vector *freqData2)
Computes the <x|y> overlap in the Fourier domain.
REAL8 LALInferenceUndecomposedFreqDomainLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
(log-) likelihood function.
void LALInferenceNetworkSNR(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
Calculate the SNR across the network.
REAL8 LALInferenceMarginalisedPhaseLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
REAL8 LALInferenceRosenbrockLogLikelihood(LALInferenceVariables *currentParams, LALInferenceIFOData *data, LALInferenceModel *model)
15-D Rosenbrock log(L) function (see Eq (3) of http://en.wikipedia.org/wiki/Rosenbrock_function .
LALInferenceVariables LALInferenceGetInstrinsicParams(LALInferenceVariables *currentParams)
Get the intrinsic parameters from currentParams.
void LALInferenceGetMinMaxPrior(LALInferenceVariables *priorArgs, const char *name, REAL8 *min, REAL8 *max)
Get the minimum and maximum values of the uniform prior from the priorArgs list, given a name.
void LALInferenceTemplateNullFreqdomain(LALInferenceModel *model)
Returns a frequency-domain 'null' template (all zeroes, implying no signal present).
void LALInferenceTemplateNullTimedomain(LALInferenceModel *model)
Returns a time-domain 'null' template (all zeroes, implying no signal present).
LAL_SIM_DOMAIN_TIME
LAL_SIM_DOMAIN_FREQUENCY
static const INT4 q
int XLALREAL8ReverseFFT(REAL8Vector *output, const COMPLEX16Vector *input, const REAL8FFTPlan *plan)
REAL8 XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
const LALUnit lalDimensionlessUnit
REAL8Vector * XLALCreateREAL8Vector(UINT4 length)
COMPLEX16Vector * XLALCreateCOMPLEX16Vector(UINT4 length)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
void XLALDestroyCOMPLEX16Vector(COMPLEX16Vector *vector)
const char * XLALErrorString(int errnum)
#define XLAL_ERROR_REAL8(...)
#define XLAL_ERROR(...)
#define XLAL_CHECK_ABORT(assertion)
#define XLAL_TRY(statement, errnum)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
XLAL_ENOMEM
XLAL_SUCCESS
XLAL_EFAULT
XLAL_EUSR0
XLAL_ERANGE
XLAL_EFUNC
XLAL_EDOM
XLAL_EINVAL
REAL8 XLALGreenwichMeanSiderealTime(const LIGOTimeGPS *gpstime)
LIGOTimeGPS * XLALGPSSetREAL8(LIGOTimeGPS *epoch, REAL8 t)
REAL8 XLALGPSGetREAL8(const LIGOTimeGPS *epoch)
static double logaddexp(double x, double y)
Definition: logaddexp.h:37
help
double alpha
double t0
COMPLEX16Sequence * data
COMPLEX16 * data
REAL4 response[3][3]
REAL8 location[3]
Structure to contain IFO data.
Definition: LALInference.h:625
REAL8TimeSeries * timeData
Detector name.
Definition: LALInference.h:627
LALDetector * detector
integration limits for overlap integral in F-domain
Definition: LALInference.h:651
REAL8FrequencySeries * oneSidedNoisePowerSpectrum
Definition: LALInference.h:643
REAL8 timeshift
Detector responses.
Definition: LALInference.h:638
struct tagLALInferenceROQData * roq
counts how many time the template has been calculated
Definition: LALInference.h:657
char name[DETNAMELEN]
Definition: LALInference.h:626
COMPLEX16FrequencySeries * freqData
What is this?
Definition: LALInference.h:639
REAL8 nullloglikelihood
A time series of the data noise variance.
Definition: LALInference.h:636
struct tagLALInferenceIFOData * next
ROQ data.
Definition: LALInference.h:659
REAL8 fLow
FFT plan needed for time/time-and-phase marginalisation.
Definition: LALInference.h:650
REAL8 STDOF
IF INJECTION ONLY, E(SNR) of the injection in the detector.
Definition: LALInference.h:654
Structure to constain a model and its parameters.
Definition: LALInference.h:436
REAL8 * ifo_loglikelihoods
Network SNR at params
Definition: LALInference.h:445
REAL8 * ifo_SNRs
Array of single-IFO likelihoods at params
Definition: LALInference.h:446
COMPLEX16FrequencySeries * freqhPlus
Time series model buffers.
Definition: LALInference.h:454
REAL8 SNR
Likelihood value at params
Definition: LALInference.h:444
int roq_flag
ROQ data.
Definition: LALInference.h:464
LALInferenceVariables * params
Definition: LALInference.h:437
COMPLEX16FrequencySeries * freqhCross
Definition: LALInference.h:454
struct tagLALInferenceROQModel * roq
The padding of the above window.
Definition: LALInference.h:463
LALInferenceTemplateFunction templt
Domain of model.
Definition: LALInference.h:440
LALSimulationDomain domain
IFO-dependent parameters and buffers.
Definition: LALInference.h:439
Structure containing inference run state This includes pointers to the function types required to run...
Definition: LALInference.h:592
ProcessParamsTable * commandLine
Definition: LALInference.h:593
LALInferenceVariables * proposalArgs
The data from the interferometers.
Definition: LALInference.h:602
LALInferenceVariables * algorithmParams
Any special arguments for the prior function.
Definition: LALInference.h:604
INT4 nthreads
Array of live points for Nested Sampling.
Definition: LALInference.h:606
struct tagLALInferenceIFOData * data
Log sample, i.e.
Definition: LALInference.h:601
LALInferenceThreadState * threads
Definition: LALInference.h:612
LALInferenceLikelihoodFunction likelihood
MultiNest prior for the parameters.
Definition: LALInference.h:599
Structure containing chain-specific variables.
Definition: LALInference.h:541
LALInferenceVariables * currentParams
Prior boundaries, etc.
Definition: LALInference.h:556
LALInferenceModel * model
Cycle of proposals to call.
Definition: LALInference.h:548
REAL8 nullLikelihood
Array storing network SNR of current sample.
Definition: LALInference.h:571
The LALInferenceVariables structure to contain a set of parameters Implemented as a linked list of LA...
Definition: LALInference.h:170
LALInferenceVariableItem * head
Definition: LALInference.h:171
REAL8Sequence * data
REAL8Sequence * data
REAL8 * data
enum @1 epoch