00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171 #include <math.h>
00172 #include <string.h>
00173 #include <stdio.h>
00174 #include <lal/LALStdlib.h>
00175 #include <lal/LALConstants.h>
00176 #include <lal/StochasticCrossCorrelation.h>
00177 #include <lal/AVFactories.h>
00178 #include <lal/RealFFT.h>
00179 #include <lal/ComplexFFT.h>
00180 #include <lal/Units.h>
00181 #include <lal/Random.h>
00182 #include <lal/SimulateSB.h>
00183 #include <lal/DetectorSite.h>
00184
00185 NRCSID (SIMULATESBC, "$Id: SimulateSB.c,v 1.12 2007/06/08 14:41:47 bema Exp $");
00186
00187
00188 void
00189 LALSSSimStochBGTimeSeries( LALStatus *status,
00190 SSSimStochBGOutput *output,
00191 SSSimStochBGInput *input,
00192 SSSimStochBGParams *params
00193 )
00194
00195 {
00196
00197 UINT4 length;
00198 UINT4 freqlen;
00199 REAL8 deltaT;
00200 REAL8 f0;
00201
00202
00203 UINT4 i;
00204
00205
00206 REAL8 deltaF;
00207 RandomParams *randParams=NULL;
00208
00209
00210 REAL4Vector *gaussdevsX1=NULL;
00211 REAL4Vector *gaussdevsY1=NULL;
00212 REAL4Vector *gaussdevsX2=NULL;
00213 REAL4Vector *gaussdevsY2=NULL;
00214
00215
00216
00217 LALDetectorPair detectors;
00218 REAL4FrequencySeries overlap11,overlap12,overlap22;
00219 OverlapReductionFunctionParameters ORFparameters;
00220
00221
00222
00223 COMPLEX8Vector *ccounts[2]={NULL,NULL};
00224 COMPLEX8Vector *ccountsTmp[2]={NULL,NULL};
00225
00226
00227 RealFFTPlan *invPlan=NULL;
00228
00229
00230 INITSTATUS(status, "LALSSSimStochBGTimeSeries", SIMULATESBC);
00231 ATTATCHSTATUSPTR(status);
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243 ASSERT(output !=NULL, status,
00244 SIMULATESBH_ENULLP,
00245 SIMULATESBH_MSGENULLP);
00246 ASSERT(output->SSimStochBG1->data !=NULL, status,
00247 SIMULATESBH_ENULLP,
00248 SIMULATESBH_MSGENULLP);
00249 ASSERT(output->SSimStochBG2->data !=NULL, status,
00250 SIMULATESBH_ENULLP,
00251 SIMULATESBH_MSGENULLP);
00252 ASSERT(output->SSimStochBG1->data->data !=NULL, status,
00253 SIMULATESBH_ENULLP,
00254 SIMULATESBH_MSGENULLP);
00255 ASSERT(output->SSimStochBG2->data->data !=NULL, status,
00256 SIMULATESBH_ENULLP,
00257 SIMULATESBH_MSGENULLP);
00258
00259
00260 ASSERT(input != NULL, status,
00261 SIMULATESBH_ENULLP,
00262 SIMULATESBH_MSGENULLP);
00263
00264
00265 ASSERT(input->omegaGW != NULL, status,
00266 SIMULATESBH_ENULLP,
00267 SIMULATESBH_MSGENULLP);
00268
00269
00270 ASSERT(input->whiteningFilter1 != NULL, status,
00271 SIMULATESBH_ENULLP,
00272 SIMULATESBH_MSGENULLP);
00273
00274
00275 ASSERT(input->whiteningFilter2 != NULL, status,
00276 SIMULATESBH_ENULLP,
00277 SIMULATESBH_MSGENULLP);
00278
00279
00280 ASSERT(input->omegaGW->data != NULL, status,
00281 SIMULATESBH_ENULLP,
00282 SIMULATESBH_MSGENULLP);
00283
00284
00285 ASSERT(input->whiteningFilter1->data != NULL, status,
00286 SIMULATESBH_ENULLP,
00287 SIMULATESBH_MSGENULLP);
00288
00289
00290 ASSERT(input->whiteningFilter2->data != NULL, status,
00291 SIMULATESBH_ENULLP,
00292 SIMULATESBH_MSGENULLP);
00293
00294
00295 ASSERT(input->whiteningFilter1->data->data != NULL, status,
00296 SIMULATESBH_ENULLP,
00297 SIMULATESBH_MSGENULLP);
00298
00299
00300 ASSERT(input->whiteningFilter2->data->data != NULL, status,
00301 SIMULATESBH_ENULLP,
00302 SIMULATESBH_MSGENULLP);
00303
00304
00305
00306
00307 ASSERT(params->length > 0, status,
00308 SIMULATESBH_ENONPOSLEN,
00309 SIMULATESBH_MSGENONPOSLEN);
00310
00311
00312 ASSERT(params->deltaT > 0, status,
00313 SIMULATESBH_ENONPOSLEN,
00314 SIMULATESBH_MSGENONPOSLEN);
00315
00316
00317
00318
00319
00320
00321
00322 f0 = input->omegaGW->f0;
00323 if (f0 < 0)
00324 {
00325 ABORT( status,
00326 SIMULATESBH_ENEGFMIN,
00327 SIMULATESBH_MSGENEGFMIN );
00328 }
00329
00330
00331
00332
00333 length = params->length;
00334 freqlen = length/2 +1;
00335
00336 if (input->omegaGW->data->length != (length/2 +1))
00337 {
00338 ABORT(status,
00339 SIMULATESBH_EMMLEN,
00340 SIMULATESBH_MSGEMMLEN);
00341 }
00342 if (input->whiteningFilter1->data->length != (length/2 +1))
00343 {
00344 ABORT(status,
00345 SIMULATESBH_EMMLEN,
00346 SIMULATESBH_MSGEMMLEN);
00347 }
00348 if (input->whiteningFilter2->data->length != (length/2 +1))
00349 {
00350 ABORT(status,
00351 SIMULATESBH_EMMLEN,
00352 SIMULATESBH_MSGEMMLEN);
00353 }
00354 if (input->whiteningFilter1->f0 != f0)
00355 {
00356 ABORT(status,
00357 SIMULATESBH_EMMFMIN,
00358 SIMULATESBH_MSGEMMFMIN);
00359 }
00360 if (input->whiteningFilter2->f0 != f0)
00361 {
00362 ABORT(status,
00363 SIMULATESBH_EMMFMIN,
00364 SIMULATESBH_MSGEMMFMIN);
00365 }
00366
00367
00368 deltaT = params->deltaT;
00369 deltaF = 1/(deltaT*length);
00370 if (input->whiteningFilter1->deltaF != deltaF)
00371 {
00372 ABORT(status,
00373 SIMULATESBH_EMMDELTAF,
00374 SIMULATESBH_MSGEMMDELTAF);
00375 }
00376 if (input->whiteningFilter2->deltaF != deltaF)
00377 {
00378 ABORT(status,
00379 SIMULATESBH_EMMDELTAF,
00380 SIMULATESBH_MSGEMMDELTAF);
00381 }
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393 LALCreateReverseRealFFTPlan(status->statusPtr,&invPlan,length,0);
00394 CHECKSTATUSPTR( status );
00395
00396 LALSCreateVector( status->statusPtr,
00397 &gaussdevsX1, freqlen );
00398 BEGINFAIL( status )
00399 {
00400 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00401 &invPlan ), status );
00402 }
00403 ENDFAIL( status );
00404
00405
00406 LALSCreateVector( status->statusPtr,
00407 &gaussdevsY1, freqlen );
00408 BEGINFAIL( status )
00409 {
00410 TRY( LALSDestroyVector( status->statusPtr,
00411 &gaussdevsX1), status );
00412 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00413 &invPlan ), status );
00414 }
00415 ENDFAIL( status );
00416
00417 LALSCreateVector( status->statusPtr,
00418 &gaussdevsX2, freqlen );
00419 BEGINFAIL( status )
00420 {
00421 TRY( LALSDestroyVector( status->statusPtr,
00422 &gaussdevsY1), status );
00423 TRY( LALSDestroyVector( status->statusPtr,
00424 &gaussdevsX1), status );
00425 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00426 &invPlan ), status );
00427 }
00428 ENDFAIL( status );
00429
00430 LALSCreateVector( status->statusPtr,
00431 &gaussdevsY2, freqlen );
00432 BEGINFAIL( status )
00433 {
00434 TRY( LALSDestroyVector( status->statusPtr,
00435 &gaussdevsX2), status );
00436 TRY( LALSDestroyVector( status->statusPtr,
00437 &gaussdevsY1), status );
00438 TRY( LALSDestroyVector( status->statusPtr,
00439 &gaussdevsX1), status );
00440 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00441 &invPlan ), status );
00442 }
00443 ENDFAIL( status );
00444
00445
00446 LALCreateRandomParams( status->statusPtr,
00447 &randParams, params->seed );
00448 BEGINFAIL( status )
00449 {
00450 TRY( LALSDestroyVector( status->statusPtr,
00451 &gaussdevsY2), status );
00452 TRY( LALSDestroyVector( status->statusPtr,
00453 &gaussdevsX2), status );
00454 TRY( LALSDestroyVector( status->statusPtr,
00455 &gaussdevsY1), status );
00456 TRY( LALSDestroyVector( status->statusPtr,
00457 &gaussdevsX1), status );
00458 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00459 &invPlan ), status );
00460 }
00461 ENDFAIL( status );
00462
00463 LALCCreateVector(status->statusPtr, &ccounts[0],freqlen);
00464 BEGINFAIL( status )
00465 {
00466 TRY( LALDestroyRandomParams( status->statusPtr,
00467 &randParams), status );
00468 TRY( LALSDestroyVector( status->statusPtr,
00469 &gaussdevsY2), status );
00470 TRY( LALSDestroyVector( status->statusPtr,
00471 &gaussdevsX2), status );
00472 TRY( LALSDestroyVector( status->statusPtr,
00473 &gaussdevsY1), status );
00474 TRY( LALSDestroyVector( status->statusPtr,
00475 &gaussdevsX1), status );
00476 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00477 &invPlan ), status );
00478 }
00479 ENDFAIL( status );
00480
00481 LALCCreateVector(status->statusPtr, &ccounts[1],freqlen);
00482 BEGINFAIL( status )
00483 {
00484 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00485 TRY( LALDestroyRandomParams( status->statusPtr,
00486 &randParams), status );
00487 TRY( LALSDestroyVector( status->statusPtr,
00488 &gaussdevsY2), status );
00489 TRY( LALSDestroyVector( status->statusPtr,
00490 &gaussdevsX2), status );
00491 TRY( LALSDestroyVector( status->statusPtr,
00492 &gaussdevsY1), status );
00493 TRY( LALSDestroyVector( status->statusPtr,
00494 &gaussdevsX1), status );
00495 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00496 &invPlan ), status );
00497 }
00498 ENDFAIL( status );
00499
00500 LALCCreateVector(status->statusPtr, &ccountsTmp[0],freqlen);
00501 BEGINFAIL( status )
00502 {
00503 TRY( LALCDestroyVector(status->statusPtr, &ccounts[1]), status);
00504 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00505 TRY( LALDestroyRandomParams( status->statusPtr,
00506 &randParams), status );
00507 TRY( LALSDestroyVector( status->statusPtr,
00508 &gaussdevsY2), status );
00509 TRY( LALSDestroyVector( status->statusPtr,
00510 &gaussdevsX2), status );
00511 TRY( LALSDestroyVector( status->statusPtr,
00512 &gaussdevsY1), status );
00513 TRY( LALSDestroyVector( status->statusPtr,
00514 &gaussdevsX1), status );
00515 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00516 &invPlan ), status );
00517 }
00518 ENDFAIL( status );
00519
00520 LALCCreateVector(status->statusPtr, &ccountsTmp[1],freqlen);
00521 BEGINFAIL( status )
00522 {
00523 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[0]), status);
00524 TRY( LALCDestroyVector(status->statusPtr, &ccounts[1]), status);
00525 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00526 TRY( LALDestroyRandomParams( status->statusPtr,
00527 &randParams), status );
00528 TRY( LALSDestroyVector( status->statusPtr,
00529 &gaussdevsY2), status );
00530 TRY( LALSDestroyVector( status->statusPtr,
00531 &gaussdevsX2), status );
00532 TRY( LALSDestroyVector( status->statusPtr,
00533 &gaussdevsY1), status );
00534 TRY( LALSDestroyVector( status->statusPtr,
00535 &gaussdevsX1), status );
00536 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00537 &invPlan ), status );
00538 }
00539 ENDFAIL( status );
00540
00541 overlap11.data = NULL;
00542 LALSCreateVector(status->statusPtr, &(overlap11.data),freqlen);
00543 BEGINFAIL( status )
00544 {
00545 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[1]), status);
00546 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[0]), status);
00547 TRY( LALCDestroyVector(status->statusPtr, &ccounts[1]), status);
00548 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00549 TRY( LALDestroyRandomParams( status->statusPtr,
00550 &randParams), status );
00551 TRY( LALSDestroyVector( status->statusPtr,
00552 &gaussdevsY2), status );
00553 TRY( LALSDestroyVector( status->statusPtr,
00554 &gaussdevsX2), status );
00555 TRY( LALSDestroyVector( status->statusPtr,
00556 &gaussdevsY1), status );
00557 TRY( LALSDestroyVector( status->statusPtr,
00558 &gaussdevsX1), status );
00559 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00560 &invPlan ), status );
00561 }
00562 ENDFAIL( status );
00563
00564 overlap12.data = NULL;
00565 LALSCreateVector(status->statusPtr, &(overlap12.data),freqlen);
00566 BEGINFAIL( status )
00567 {
00568 TRY( LALSDestroyVector(status->statusPtr, &(overlap11.data)), status);
00569 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[1]), status);
00570 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[0]), status);
00571 TRY( LALCDestroyVector(status->statusPtr, &ccounts[1]), status);
00572 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00573 TRY( LALDestroyRandomParams( status->statusPtr,
00574 &randParams), status );
00575 TRY( LALSDestroyVector( status->statusPtr,
00576 &gaussdevsY2), status );
00577 TRY( LALSDestroyVector( status->statusPtr,
00578 &gaussdevsX2), status );
00579 TRY( LALSDestroyVector( status->statusPtr,
00580 &gaussdevsY1), status );
00581 TRY( LALSDestroyVector( status->statusPtr,
00582 &gaussdevsX1), status );
00583 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00584 &invPlan ), status );
00585 }
00586 ENDFAIL( status );
00587
00588 overlap22.data = NULL;
00589 LALSCreateVector(status->statusPtr, &(overlap22.data),freqlen);
00590 BEGINFAIL( status )
00591 {
00592 TRY( LALSDestroyVector(status->statusPtr, &(overlap12.data)), status);
00593 TRY( LALSDestroyVector(status->statusPtr, &(overlap11.data)), status);
00594 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[1]), status);
00595 TRY( LALCDestroyVector(status->statusPtr, &ccountsTmp[0]), status);
00596 TRY( LALCDestroyVector(status->statusPtr, &ccounts[1]), status);
00597 TRY( LALCDestroyVector(status->statusPtr, &ccounts[0]), status);
00598 TRY( LALDestroyRandomParams( status->statusPtr,
00599 &randParams), status );
00600 TRY( LALSDestroyVector( status->statusPtr,
00601 &gaussdevsY2), status );
00602 TRY( LALSDestroyVector( status->statusPtr,
00603 &gaussdevsX2), status );
00604 TRY( LALSDestroyVector( status->statusPtr,
00605 &gaussdevsY1), status );
00606 TRY( LALSDestroyVector( status->statusPtr,
00607 &gaussdevsX1), status );
00608 TRY( LALDestroyRealFFTPlan( status->statusPtr,
00609 &invPlan ), status );
00610 }
00611 ENDFAIL( status );
00612
00613
00614 LALNormalDeviates( status->statusPtr,
00615 gaussdevsX1, randParams );
00616 CHECKSTATUSPTR( status);
00617
00618 LALDestroyRandomParams(status->statusPtr,&randParams);
00619
00620 LALCreateRandomParams(status->statusPtr,&randParams, params->seed +1);
00621
00622 LALNormalDeviates( status->statusPtr,
00623 gaussdevsY1, randParams );
00624 CHECKSTATUSPTR( status);
00625
00626 LALDestroyRandomParams(status->statusPtr,&randParams);
00627
00628 LALCreateRandomParams(status->statusPtr,&randParams, params->seed +2);
00629
00630 LALNormalDeviates( status->statusPtr,
00631 gaussdevsX2, randParams );
00632 CHECKSTATUSPTR( status);
00633
00634 LALDestroyRandomParams(status->statusPtr,&randParams);
00635
00636 LALCreateRandomParams(status->statusPtr,&randParams, params->seed +3);
00637
00638 LALNormalDeviates( status->statusPtr,
00639 gaussdevsY2, randParams );
00640 CHECKSTATUSPTR( status);
00641
00642 LALDestroyRandomParams(status->statusPtr,&randParams);
00643
00644 ORFparameters.length = length/2 + 1;
00645 ORFparameters.f0 = f0;
00646 ORFparameters.deltaF = deltaF;
00647 detectors.detectorOne = params->detectorOne;
00648 detectors.detectorTwo = params->detectorOne;
00649
00650 LALOverlapReductionFunction( status->statusPtr, &overlap11,
00651 &detectors, &ORFparameters);
00652 CHECKSTATUSPTR( status);
00653
00654 detectors.detectorOne = params->detectorOne;
00655 detectors.detectorTwo = params->detectorTwo;
00656
00657 LALOverlapReductionFunction( status->statusPtr, &overlap12,
00658 &detectors, &ORFparameters);
00659 CHECKSTATUSPTR( status);
00660
00661 detectors.detectorOne = params->detectorTwo;
00662 detectors.detectorTwo = params->detectorTwo;
00663
00664 LALOverlapReductionFunction( status->statusPtr, &overlap22,
00665 &detectors, &ORFparameters);
00666 CHECKSTATUSPTR( status);
00667
00668 if (f0 == 0)
00669 {
00670 REAL4 gamma11,gamma12,gamma22;
00671 REAL4 omega;
00672 REAL8 freq;
00673 REAL8 factor;
00674 REAL8 factor2,factor3;
00675 COMPLEX8 wFilter1;
00676 COMPLEX8 wFilter2;
00677
00678
00679 for (i = 1; i < freqlen; ++i)
00680 {
00681 freq = i*deltaF;
00682
00683 gamma11 = overlap11.data->data[i];
00684 gamma12 = overlap12.data->data[i];
00685 gamma22 = overlap22.data->data[i];
00686
00687 omega = input->omegaGW->data->data[i];
00688
00689 factor = deltaF * sqrt(3.0L * length * deltaT * omega /
00690 (40.0L *freq*freq*freq)
00691 )* LAL_H0FAC_SI / LAL_PI;
00692 factor2 = sqrt(gamma22-gamma12*gamma12/gamma11)*factor;
00693 factor3 = sqrt(gamma11)*factor;
00694
00695 wFilter1 = input->whiteningFilter1->data->data[i];
00696 wFilter2 = input->whiteningFilter2->data->data[i];
00697
00698 ccountsTmp[0]->data[i].re=factor3*gaussdevsX1->data[i];
00699 ccountsTmp[0]->data[i].im=factor3*gaussdevsY1->data[i];
00700 ccountsTmp[1]->data[i].re=ccountsTmp[0]->data[i].re*gamma12/gamma11+factor2*gaussdevsX2->data[i];
00701 ccountsTmp[1]->data[i].im=ccountsTmp[0]->data[i].im*gamma12/gamma11+factor2*gaussdevsY2->data[i];
00702
00703 ccounts[0]->data[i].re = wFilter1.re * ccountsTmp[0]->data[i].re -
00704 wFilter1.im * ccountsTmp[0]->data[i].im;
00705 ccounts[0]->data[i].im = wFilter1.re * ccountsTmp[0]->data[i].im +
00706 wFilter1.im * ccountsTmp[0]->data[i].re;
00707 ccounts[1]->data[i].re = wFilter2.re * ccountsTmp[1]->data[i].re -
00708 wFilter2.im * ccountsTmp[1]->data[i].im;
00709 ccounts[1]->data[i].im = wFilter2.re * ccountsTmp[1]->data[i].im +
00710 wFilter2.im * ccountsTmp[1]->data[i].re;
00711 }
00712
00713
00714 for (i=0;i<2;++i)
00715 {
00716 ccounts[i]->data[0].re=0.0;
00717 ccounts[i]->data[0].im=0.0;
00718 ccountsTmp[i]->data[length/2].im=0.0;
00719 }
00720
00721
00722 gamma11 = overlap11.data->data[length/2];
00723 gamma12 = overlap12.data->data[length/2];
00724 gamma22 = overlap22.data->data[length/2];
00725
00726 omega = input->omegaGW->data->data[length/2];
00727 freq = deltaF*length/2;
00728
00729 wFilter1 = input->whiteningFilter1->data->data[length/2];
00730 wFilter2 = input->whiteningFilter2->data->data[length/2];
00731
00732
00733 if (wFilter1.im != 0)
00734 {
00735 ABORT(status,
00736 SIMULATESBH_ECOMPTIME,
00737 SIMULATESBH_MSGECOMPTIME);
00738 };
00739 if (wFilter2.im != 0)
00740 {
00741 ABORT(status,
00742 SIMULATESBH_ECOMPTIME,
00743 SIMULATESBH_MSGECOMPTIME);
00744 };
00745
00746 factor = deltaF * sqrt(3.0L * length * deltaT * omega /
00747 (40.0L *freq<