27 #if defined HAVE_LIBSUNMATH && defined ONLINE
33 #include <lal/LALStdio.h>
34 #include <lal/LALStdlib.h>
35 #include <lal/LALError.h>
36 #include <lal/DetectorSite.h>
37 #include <lal/DetResponse.h>
38 #include <lal/AVFactories.h>
40 #include <lal/Units.h>
41 #include <lal/TimeDelay.h>
42 #include <lal/VectorOps.h>
43 #include <lal/SimulateCoherentGW.h>
44 #include <lal/SkyCoordinates.h>
47 #define SIMULATECOHERENTGWH_ENUL 1
48 #define SIMULATECOHERENTGWH_EBAD 2
49 #define SIMULATECOHERENTGWH_ESIG 3
50 #define SIMULATECOHERENTGWH_EDIM 4
51 #define SIMULATECOHERENTGWH_EMEM 5
52 #define SIMULATECOHERENTGWH_EUNIT 6
54 #define SIMULATECOHERENTGWH_MSGENUL "Unexpected null pointer in arguments"
55 #define SIMULATECOHERENTGWH_MSGEBAD "A sampling interval is (effectively) zero"
56 #define SIMULATECOHERENTGWH_MSGESIG "Input signal must specify amplitude and phase functions"
57 #define SIMULATECOHERENTGWH_MSGEDIM "Amplitude must be a 2-dimensional vector"
58 #define SIMULATECOHERENTGWH_MSGEMEM "Memory allocation error"
59 #define SIMULATECOHERENTGWH_MSGEUNIT "Bad input units"
72 #define TCENTRE( time ) \
74 realIndex = delayOff + (time)*delayDt, \
75 intIndex = (INT4)floor( realIndex ), \
76 indexFrac = realIndex - intIndex, \
77 time + indexFrac*delayData[intIndex+1] \
78 + (1.0-indexFrac)*delayData[intIndex] \
219 INT4 shiftInit, shiftFinal;
223 REAL8 delayMin, delayMax;
243 REAL4 *aData, *fData, *shiftData, *plusData, *crossData;
244 REAL8 *phiData, *delayData;
245 REAL8 aOff, fOff, phiOff, shiftOff, polOff, delayOff;
246 REAL8 aDt, fDt, phiDt, shiftDt, polDt, delayDt;
254 REAL4 *aTransData = NULL, *phiTransData = NULL;
256 REAL8 phiFac = 1.0, fFac = 1.0;
261 REAL8 heteroFac, phi0;
272 ASSERT( CWsignal, stat, SIMULATECOHERENTGWH_ENUL,
273 SIMULATECOHERENTGWH_MSGENUL );
274 if ( !( CWsignal->
a ) ) {
275 ABORT( stat, SIMULATECOHERENTGWH_ESIG,
276 SIMULATECOHERENTGWH_MSGESIG );
279 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
281 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
282 if ( !( CWsignal->
phi ) ) {
283 ABORT( stat, SIMULATECOHERENTGWH_ESIG,
284 SIMULATECOHERENTGWH_MSGESIG );
287 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
289 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
292 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
294 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
296 if ( CWsignal->
shift ) {
298 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
300 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
303 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
304 if ( ( transfer = ( detector->
transfer != NULL ) ) ) {
306 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
308 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
311 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
313 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
315 SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
319 SIMULATECOHERENTGWH_EDIM, SIMULATECOHERENTGWH_MSGEDIM );
323 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
325 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
329 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
330 ASSERT( phiDt != 0.0, stat,
331 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
334 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
337 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
340 if ( CWsignal->
shift ) {
342 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
344 ASSERT( shiftDt != 0.0, stat,
345 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
350 SIMULATECOHERENTGWH_EBAD, SIMULATECOHERENTGWH_MSGEBAD );
358 phi0 += 0.000000001*(
REAL8)(
output->epoch.gpsNanoSeconds -
362 LALWarning( stat,
"REAL8 arithmetic is not sufficient to maintain"
363 " heterodyne phase to within a radian." );
370 if( CWsignal->
shift ) {
375 ABORT( stat, SIMULATECOHERENTGWH_EUNIT, SIMULATECOHERENTGWH_MSGEUNIT );
381 ABORT( stat, SIMULATECOHERENTGWH_ENUL, SIMULATECOHERENTGWH_MSGENUL );
388 outData =
output->data->data;
393 if ( CWsignal->
shift )
400 if ( detector->
site ) {
416 &source, ¶ms ), stat );
423 delayDt =
output->deltaT/( 2.0*dtDelayBy2 );
424 nMax = (
UINT4)(
output->data->length*delayDt ) + 3;
426 delayData = delay->
data;
429 if ( detector->
site ) {
439 for ( i = 0; i < nMax; i++ ) {
448 tDelay /= -
output->deltaT;
449 delayData[i] = tDelay;
450 if ( tDelay < delayMin )
452 if ( tDelay > delayMax )
460 LALInfo( stat,
"Detector site absent; simulating hplus with no"
461 " propagation delays" );
462 memset( delayData, 0, nMax*
sizeof(
REAL8) );
463 delayMin = delayMax = 0.0;
467 polDt =
output->deltaT/( 2.0*dtPolBy2 );
478 if ( polResponse.
pPlus )
485 ABORT( stat, SIMULATECOHERENTGWH_EMEM,
486 SIMULATECOHERENTGWH_MSGEMEM );
523 if ( detector->
site ) {
535 params.
deltaT = 2.0*dtPolBy2;
555 for ( i = 0; i < nMax; i++ ) {
639 phiTransData = phiTransfer->
data;
640 aTransData = aTransfer->
data;
645 aOff = (
output->epoch.gpsSeconds -
648 aOff += (
output->epoch.gpsNanoSeconds -
651 phiOff = (
output->epoch.gpsSeconds -
654 phiOff += (
output->epoch.gpsNanoSeconds -
658 fOff = (
output->epoch.gpsSeconds -
661 fOff += (
output->epoch.gpsNanoSeconds -
666 if ( CWsignal->
shift ) {
667 shiftOff = (
output->epoch.gpsSeconds -
670 shiftOff += (
output->epoch.gpsNanoSeconds -
681 if ( aOff + ( i + delayMin )*aDt < 0.0 ) {
682 INT4 j = (
INT4)floor( -aOff/aDt - delayMax );
685 while ( ( i < (
INT4)(
output->data->length ) ) &&
686 ( aOff + TCENTRE( i )*aDt < 0.0 ) )
689 if ( phiOff + ( i + delayMin )*phiDt < 0.0 ) {
690 INT4 j = (
INT4)( -phiOff/phiDt - delayMax );
693 while ( ( i < (
INT4)(
output->data->length ) ) &&
694 ( phiOff + TCENTRE( i )*phiDt < 0.0 ) )
698 LALWarning( stat,
"Signal starts after the end of the output"
705 n =
output->data->length - 1;
707 if ( aOff + ( n + delayMax )*aDt > nMax ) {
708 INT4 j = (
INT4)( ( nMax - aOff )/aDt - delayMin + 1.0 );
711 while ( ( n >= 0 ) &&
712 ( (
INT4)floor(aOff + TCENTRE( n )*aDt) > nMax ) )
716 if ( phiOff + ( n + delayMax )*phiDt > nMax ) {
717 INT4 j = (
INT4)( ( nMax - phiOff )/phiDt - delayMin + 1.0 );
720 while ( ( n >= 0 ) &&
721 ( (
INT4)floor(phiOff + TCENTRE( n )*phiDt) > nMax ) )
725 LALWarning( stat,
"CWsignal ends before the start of the output"
733 if ( fOff + ( fInit + delayMin )*fDt < 0.0 ) {
734 INT4 j = (
INT4)floor( -fOff/fDt - delayMax );
737 while ( ( fInit <= n ) &&
738 ( fOff + TCENTRE( fInit )*fDt < 0.0 ) )
743 if ( fOff + ( fFinal + delayMax )*fDt > nMax ) {
744 INT4 j = (
INT4)( ( nMax - fOff )/fDt - delayMin + 1.0 );
747 while ( ( fFinal >= i ) &&
748 ( (
INT4)floor(fOff + TCENTRE( fFinal )*fDt) > nMax ) )
757 if ( CWsignal->
shift ) {
759 if ( shiftOff + ( shiftInit + delayMin )*shiftDt < 0.0 ) {
760 INT4 j = (
INT4)floor( -shiftOff/shiftDt - delayMax );
763 while ( ( shiftInit <= n ) &&
764 ( shiftOff + TCENTRE( shiftInit )*shiftDt < 0.0 ) )
769 if ( shiftOff + ( shiftFinal + delayMax )*shiftDt > nMax ) {
770 INT4 j = (
INT4)( ( nMax - shiftOff )/shiftDt - delayMin + 1.0 );
771 if ( shiftFinal > j )
773 while ( ( shiftFinal >= i ) &&
774 ( (
INT4)floor(shiftOff + TCENTRE( shiftFinal )*shiftDt) > nMax ) )
785 if ( ( nMax =
output->data->length - n - 1 ) > 0 )
786 memset(
output->data->data + n + 1, 0, nMax*
sizeof(
REAL4) );
794 for ( ; i <= n; i++ ) {
795 REAL8 iCentre = TCENTRE( i );
803 REAL4 aTrans, phiTrans;
806 REAL8 sp, cp, ss, cs;
810 x = aOff + iCentre*aDt;
811 j = (
INT4)floor(
x );
822 a1 = frac*aData[j+2] + ( 1.0 - frac )*aData[j];
823 a2 = frac*aData[j+3] + ( 1.0 - frac )*aData[j+1];
827 if ( ( i < shiftInit ) || ( i > shiftFinal ) )
830 x = shiftOff + iCentre*shiftDt;
831 j = (
INT4)floor(
x );
833 if(i==n) shift=shiftData[j];
834 else shift = frac*shiftData[j+1] + ( 1.0 - frac )*shiftData[j];
838 x = phiOff + iCentre*phiDt;
839 j = (
INT4)floor(
x );
841 phi = frac*phiData[j+1] + ( 1.0 - frac )*phiData[j];
842 phi -= heteroFac*i + phi0;
846 if ( ( i < fInit ) || ( i > fFinal ) ) {
847 f = ( phiData[j+1] - phiData[j] )*phiFac;
850 x = fOff + iCentre*fDt;
851 j = (
INT4)floor(
x );
854 else f = frac*fData[j+1] + ( 1.0 - frac )*fData[j];
858 if ( (
x < 0.0 ) || (
x > nMax ) ) {
863 j = (
INT4)floor(
x );
867 aTrans=aTransData[j];
868 phiTrans=phiTransData[j];
871 aTrans = frac*aTransData[j+1] + ( 1.0 - frac )*aTransData[j];
872 phiTrans = frac*phiTransData[j+1] + ( 1.0 - frac )*phiTransData[j];
882 sincosp( shift, &ss, &cs );
883 sincosp( phi, &sp, &cp );
884 oPlus = a1*cs*cp - a2*ss*sp;
885 oCross = a1*ss*cp + a2*cs*sp;
887 oPlus = a1*cos( shift )*cos( phi ) - a2*sin( shift )*sin( phi );
888 oCross = a1*sin( shift )*cos( phi ) + a2*cos( shift )*sin( phi );
892 x = polOff + i*polDt;
893 j = (
INT4)floor(
x );
898 oCross*=crossData[j];
900 oPlus *= frac*plusData[j+1] + ( 1.0 - frac )*plusData[j];
901 oCross *= frac*crossData[j+1] + ( 1.0 - frac )*crossData[j];
904 outData[i] = oPlus + oCross;
910 LALWarning( stat,
"Signal passed outside of the frequency domain"
911 " of the transfer function (transfer function is"
912 " treated as zero outside its specified domain)" );
914 LALInfo( stat,
"Signal frequency was estimated by differencing"
915 " the signal phase" );
#define LALInfo(statusptr, info)
#define LALWarning(statusptr, warning)
#define ABORT(statusptr, code, mesg)
#define ENDFAIL(statusptr)
#define TRY(func, statusptr)
#define ATTATCHSTATUSPTR(statusptr)
#define ASSERT(assertion, statusptr, code, mesg)
#define DETATCHSTATUSPTR(statusptr)
#define INITSTATUS(statusptr)
#define RETURN(statusptr)
#define BEGINFAIL(statusptr)
void LALSimulateCoherentGW(LALStatus *status, REAL4TimeSeries *output, CoherentGW *input, DetectorResponse *detector)
static double f(double theta, double y, double xi)
void LALComputeDetAMResponseSeries(LALStatus *status, LALDetAMResponseSeries *pResponseSeries, const LALDetAndSource *pDetAndSource, const LALTimeIntervalAndNSample *pTimeInfo)
Computes REAL4TimeSeries containing time series of response amplitudes.
#define LAL_C_SI
Speed of light in vacuum, m s^-1.
#define LAL_REARTH_SI
Earth equatorial radius, m.
#define LAL_REAL8_EPS
Difference between 1 and the next resolvable REAL8 2^-52.
#define LAL_TWOPI
2*pi is circumference of a circle divided by its radius
unsigned char BOOLEAN
Boolean logical type, see Headers LAL(Atomic)Datatypes.h for more details.
double REAL8
Double precision real floating-point number (8 bytes).
uint32_t UINT4
Four-byte unsigned integer.
int32_t INT4
Four-byte signed integer.
float REAL4
Single precision real floating-point number (4 bytes).
void LALConvertSkyCoordinates(LALStatus *stat, SkyPosition *output, SkyPosition *input, ConvertSkyParams *params)
@ COORDINATESYSTEM_HORIZON
A horizon coordinate system.
@ COORDINATESYSTEM_EQUATORIAL
The sky-fixed equatorial coordinate system.
void LALGeocentricToGeodetic(LALStatus *, EarthPosition *location)
double XLALTimeDelayFromEarthCenter(const double detector_earthfixed_xyz_metres[3], double source_right_ascension_radians, double source_declination_radians, const LIGOTimeGPS *gpstime)
Compute difference in arrival time of the same signal at detector and at center of Earth-fixed frame.
int XLALUnitCompare(const LALUnit *unit1, const LALUnit *unit2)
Returns 0 if the the normal form of the two unit structures are the same or > 0 if they are different...
const LALUnit lalHertzUnit
Hertz [Hz].
const LALUnit lalDimensionlessUnit
dimensionless units
LALUnit * XLALUnitMultiply(LALUnit *output, const LALUnit *unit1, const LALUnit *unit2)
This function multiplies together the LALUnit structures *(input->unitOne) and *(input->unitTwo),...
void LALDCreateVector(LALStatus *, REAL8Vector **, UINT4)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void LALSDestroyVector(LALStatus *, REAL4Vector **)
void LALSCreateVector(LALStatus *, REAL4Vector **, UINT4)
void LALCVectorAngle(LALStatus *, REAL4Vector *, const COMPLEX8Vector *)
UNDOCUMENTED.
void LALCVectorAbs(LALStatus *, REAL4Vector *, const COMPLEX8Vector *)
UNDOCUMENTED.
void LALUnwrapREAL4Angle(LALStatus *, REAL4Vector *, const REAL4Vector *)
UNDOCUMENTED.
UINT4 length
Number of elements in array.
COMPLEX8 * data
Pointer to the data array.
REAL4TimeVectorSeries * a
This structure stores parameters for the function LALConvertSkyPosition().
CoordinateSystem system
The coordinate system to which one is transforming.
SkyPosition * zenith
The position of the zenith of the horizon coordinate system; may be NULL if one is neither converting...
LIGOTimeGPS * gpsTime
The GPS time for conversions between Earth-fixed and sky-fixed coordinates; may be NULL if no such co...
LIGOTimeGPS heterodyneEpoch
COMPLEX8FrequencySeries * transfer
This structure stores the location of a point on (or near) the surface of the Earth in both geodetic ...
REAL8 z
The Earth-fixed geocentric Cartesian coordinates of the point, in metres.
SkyPosition geodetic
The geographic coordinates of the upward vertical direction from the point; that is,...
This structure aggregates together three REAL4TimeSeries objects containing time series of detector A...
REAL4TimeSeries * pCross
timeseries of detector response to -polarized gravitational radiation
REAL4TimeSeries * pPlus
timeseries of detector response to -polarized gravitational radiation
REAL4TimeSeries * pScalar
timeseries of detector response to scalar gravitational radiation (NB: not yet implemented....
This structure aggregates a pointer to a LALDetector and a LALSource.
LALSource * pSource
Pointer to LALSource object containing information about the source.
const LALDetector * pDetector
Pointer to LALDetector object containing information about the detector.
REAL8 location[3]
The three components, in an Earth-fixed Cartesian coordinate system, of the position vector from the ...
This structure contains gravitational wave source position (in Equatorial coördinates),...
SkyPosition equatorialCoords
equatorial coordinates of source, in decimal RADIANS
REAL8 orientation
Orientation angle ( ) of source: counter-clockwise angle -axis makes with a line perpendicular to mer...
LAL status structure, see The LALStatus structure for more details.
struct tagLALStatus * statusPtr
Pointer to the next node in the list; NULL if this function is not reporting a subroutine error.
This structure encapsulates time and sampling information for computing a LALDetAMResponseSeries.
LIGOTimeGPS epoch
The start time of the time series.
UINT4 nSample
The total number of samples to be computed.
REAL8 deltaT
The sampling interval , in seconds.
Epoch relative to GPS epoch, see LIGOTimeGPS type for more details.
INT4 gpsSeconds
Seconds since 0h UTC 6 Jan 1980.
INT4 gpsNanoSeconds
Residual nanoseconds.
Time series of REAL4 data, see DATATYPE-TimeSeries types for more details.
REAL4Sequence * data
The sequence of sampled data.
LALUnit sampleUnits
The physical units of the quantity being sampled.
REAL8 deltaT
The time step between samples of the time series in seconds.
LIGOTimeGPS epoch
The start time of the time series.
CHAR name[LALNameLength]
The name of the time series of vectors.
REAL8 deltaT
The time step between samples of the time series of vectors in seconds.
LALUnit sampleUnits
The physical units of the quantity being sampled.
LIGOTimeGPS epoch
The start time of the time series of vectors.
REAL4VectorSequence * data
The sequence of sampled data vectors.
Vector of type REAL4, see DATATYPE-Vector types for more details.
REAL4 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
UINT4 vectorLength
The length n of each vector.
REAL4 * data
Pointer to the data array.
UINT4 length
The number l of vectors.
REAL8Sequence * data
The sequence of sampled data.
LALUnit sampleUnits
The physical units of the quantity being sampled.
REAL8 deltaT
The time step between samples of the time series in seconds.
LIGOTimeGPS epoch
The start time of the time series.
Vector of type REAL8, see DATATYPE-Vector types for more details.
REAL8 * data
Pointer to the data array.
UINT4 length
Number of elements in array.
This structure stores the two spherical coordinates of a sky position; ie a generic latitude and long...
REAL8 longitude
The longitudinal coordinate (in radians), as defined above.
REAL8 latitude
The latitudinal coordinate (in radians), as defined above.
CoordinateSystem system
The coordinate system in which latitude/longitude are expressed.
void output(int gps_sec, int output_type)