31 #include <lal/LALStdlib.h>
32 #include <lal/DetectorSite.h>
33 #include <lal/AVFactories.h>
34 #include <lal/LALError.h>
35 #include <lal/LALString.h>
36 #include <lal/StringInput.h>
37 #include <lal/UserInputParse.h>
38 #include <lal/Velocity.h>
39 #include <lal/TwoDMesh.h>
41 #include <lal/LogPrintf.h>
43 #include <lal/DopplerScan.h>
48 #define UNUSED __attribute__ ((unused))
56 #define INDEX_f0_f0 PMETRIC_INDEX(0,0)
57 #define INDEX_f0_A PMETRIC_INDEX(0,1)
58 #define INDEX_f0_D PMETRIC_INDEX(0,2)
59 #define INDEX_f0_f1 PMETRIC_INDEX(0,3)
61 #define INDEX_A_A PMETRIC_INDEX(1,1)
62 #define INDEX_D_D PMETRIC_INDEX(2,2)
63 #define INDEX_A_D PMETRIC_INDEX(1,2)
64 #define INDEX_A_f1 PMETRIC_INDEX(1,3)
66 #define INDEX_D_f1 PMETRIC_INDEX(2,3)
68 #define INDEX_f1_f1 PMETRIC_INDEX(3,3)
71 #define DELTA_0 "-1.570796"
72 #define DELTA_1 "1.570796"
73 #define ALPHA_0 "1e-6"
74 #define ALPHA_1 "6.283185"
76 #define SKYREGION_ALLSKY "(" ALPHA_0 ", " DELTA_0 "),(" ALPHA_1 ", " DELTA_0 "),(" ALPHA_1 ", " DELTA_1 "),(" ALPHA_0 ", " DELTA_1 ")"
118 const char *
va(
const char *format, ... );
131 if (
pos == NULL || skyScan == NULL ) {
136 switch ( skyScan->
state ) {
144 if ( skyScan->
skyNode == NULL ) {
251 gridpoint.fkdot[0] = init->
Freq;
255 XLALPrintInfo(
"'theoretical' spacings in frequency and spindown: \n" );
256 XLALPrintInfo(
"dFreq = %g, df1dot = %g, df2dot = %g, df3dot = %g\n",
257 gridSpacings.fkdot[0], gridSpacings.fkdot[1], gridSpacings.fkdot[2], gridSpacings.fkdot[3] );
296 if ( skyScan == NULL ) {
344 if ( skygrid == NULL ) {
425 metricpar.metricType =
par->metricType;
432 metricpar.spindown = NULL;
434 metricpar.epoch =
par->obsBegin;
435 metricpar.duration =
par->obsDuration;
436 metricpar.maxFreq =
par->Freq;
437 metricpar.site =
par->Detector;
438 metricpar.ephemeris =
par->ephemeris;
442 metricpar.position.longitude = skypos[0];
443 metricpar.position.latitude = skypos[1];
445 metricpar.position.longitude = skypos[1];
446 metricpar.position.latitude = skypos[0];
455 if (
par->projectMetric ) {
476 REAL8 det = g[0] * g[1] - g[2] * g[2];
477 if ( ( g[0] <= 0 ) || ( g[1] <= 0 ) || ( det <= 0 ) ) {
480 "metric = [ %16g, %16g ;\n"
483 metricpar.position.longitude, metricpar.position.latitude,
504 #define NUM_SPINDOWN 0
518 const CHAR *xmgrHeader =
520 "@title \"Sky-grid\"\n"
523 "@world ymin -1.58\n"
525 "@xaxis label \"Alpha\"\n"
526 "@yaxis label \"Delta\"\n";
532 fp = fopen(
"mesh_debug.agr",
"w" );
533 fp1 = fopen(
"mesh_debug.dat",
"w" );
545 fprintf(
fp,
"@target s%d\n@type xy\n", set );
559 fprintf(
fp,
"@s%d symbol 9\n@s%d symbol size 0.33\n", set, set );
560 fprintf(
fp,
"@s%d line type 0\n", set );
561 fprintf(
fp,
"@target s%d\n@type xy\n", set );
563 for ( node = skyGrid; node; node = node->
next ) {
619 fprintf(
fp,
"@target G0.S%d\n@type xy\n", set );
620 fprintf(
fp,
"@s%d color (0,0,0)\n", set );
629 r = sqrt(
x *
x +
y *
y );
632 Alpha +
r * cos( ellipse.
angle + b ), Delta +
r * sin( ellipse.
angle + b ) );
635 Alpha +
r * cos( ellipse.
angle + b ), Delta +
r * sin( ellipse.
angle + b ) );
684 UINT4 insideLeft, insideRight;
687 REAL8 xinter, v1x, v1y, v2x, v2y, px, py;
696 insideLeft = insideRight = 0;
701 for (
i = 0;
i <
N;
i++ ) {
704 v2x = vertex[(
i + 1 ) %
N].longitude;
705 v2y = vertex[(
i + 1 ) %
N].latitude;
708 if ( ( py <
fmin( v1y, v2y ) ) || ( py >=
fmax( v1y, v2y ) ) || ( v1y == v2y ) ) {
713 xinter = v1x + ( py - v1y ) * ( v2x - v1x ) / ( v2y - v1y );
725 inside = ( ( ( insideLeft % 2 ) == 1 ) || ( insideRight % 2 ) == 1 );
751 while ( meshpoint ) {
773 meshpoint = meshpoint->
next;
848 REAL8 step_Alpha, step_Delta, cos_Delta;
858 cos_Delta = fabs( cos( thisPoint.
latitude ) );
872 step_Alpha = dAlpha / cos_Delta;
878 cos_Delta = fabs( cos( thisPoint.
latitude ) );
935 meshpar.rangeParams = (
void * ) skyRegion;
946 meshpar.metricParams = (
void * )( &
params );
953 if ( metricpar.spindown ) {
957 metricpar.spindown = NULL;
996 for (
i = 0;
i <
data->lines->nTokens;
i++ ) {
998 &( thisPoint.longitude ), &( thisPoint.latitude ) ) ) {
1005 node->
Alpha = thisPoint.longitude;
1006 node->
Delta = thisPoint.latitude;
1036 if ( (
fp = fopen( fname,
"w" ) ) == NULL ) {
1063 const CHAR *fname =
"dFreq.pred";
1082 REAL8 V0[3], V1[3], V2[3];
1087 if ( (
fp = fopen( fname,
"w" ) ) == NULL ) {
1098 tinitE =
edat->ephemE[0].gps;
1099 dT =
edat->dtEtable;
1100 t0e = tgps[0] - tinitE;
1101 ientryE = floor( ( t0e / dT ) + 0.5e0 );
1104 tdiffE = t0e -
edat->dtEtable * ientryE + tgps[1] * 1.e-9;
1107 vel =
edat->ephemE[ientryE].vel;
1108 acc =
edat->ephemE[ientryE].acc;
1111 for (
j = 0;
j < 3;
j++ ) {
1112 accDot[
j] = (
edat->ephemE[ientryE + 1].acc[
j] -
edat->ephemE[ientryE].acc[
j] ) / dT;
1113 v[
j] = vel[
j] + acc[
j] * tdiffE + 0.5 * accDot[
j] * tdiffE * tdiffE;
1114 a[
j] = acc[
j] + accDot[
j] * tdiffE;
1119 for (
j = 0;
j < 3;
j++ ) {
1121 V1[
j] = v[
j] + 0.5 *
a[
j] * Tobs;
1122 V2[
j] = v[
j] + 0.5 *
a[
j] * Tobs + ( 2.0 / 5.0 ) * accDot[
j] * Tobs * Tobs;
1125 XLALPrintError(
"dT = %f, tdiffE = %f, Tobs = %f\n", dT, tdiffE, Tobs );
1126 XLALPrintError(
" vel = [ %g, %g, %g ]\n", vel[0], vel[1], vel[2] );
1127 XLALPrintError(
" acc = [ %g, %g, %g ]\n", acc[0], acc[1], acc[2] );
1128 XLALPrintError(
" accDot = [ %g, %g, %g ]\n\n", accDot[0], accDot[1], accDot[2] );
1133 XLALPrintError(
"\nVelocity-expression in circle-equation: \n" );
1141 np[0] = cos( node->
Delta ) * cos( node->
Alpha );
1142 np[1] = cos( node->
Delta ) * sin( node->
Alpha );
1143 np[2] = sin( node->
Delta );
1145 fact = 1.0 / ( 1.0 + np[0] * v[0] + np[1] * v[1] + np[2] * v[2] );
1169 #define mymax(a,b) ((a) > (b) ? (a) : (b))
1176 vel =
edat->ephemE[
i].vel;
1177 beta = sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
1178 maxvE =
mymax( maxvE, beta );
1183 vel =
edat->ephemS[
i].vel;
1184 beta = sqrt( vel[0] * vel[0] + vel[1] * vel[1] + vel[2] * vel[2] );
1185 maxvS =
mymax( maxvS, beta );
1188 XLALPrintError(
"Maximal Doppler-shift to be expected from ephemeris: %e", maxvE + maxvS );
1190 return ( maxvE + maxvS );
1208 const CHAR *skyRegion = NULL;
1210 if ( input == NULL ) {
1212 }
else if ( !strcmp( input,
"allsky" ) || !strcmp( input,
"ALLSKY" ) || !strcmp( input,
"Allsky" ) ) {
1221 while ( (
pos = strchr(
pos,
'(' ) ) != NULL ) {
1243 const char *startLong, *comma, *startLat, *
end;
1245 XLAL_CHECK( ( comma = strchr(
pos,
',' ) ) != NULL,
XLAL_EINVAL,
"Invalid skyregion format at '%s': no comma separator ','\n",
pos );
1249 startLat = comma + 1;
1251 while ( isspace( startLong[0] ) ) {
1254 while ( isspace( startLat[0] ) ) {
1258 size_t lenLong = comma - startLong;
1259 size_t lenLat =
end - startLat;
1261 XLAL_CHECK( lenLong <
sizeof( buf ),
XLAL_EINVAL,
"Element at '%s' exceeds buffer length %zd\n", startLong,
sizeof( buf ) );
1262 XLAL_CHECK( lenLat <
sizeof( buf ),
XLAL_EINVAL,
"Element at '%s' exceeds buffer length %zd\n", startLat,
sizeof( buf ) );
1265 memcpy( buf, startLong, lenLong );
1270 memcpy( buf, startLat, lenLat );
1281 pos = strchr(
pos + 1,
'(' );
1302 BOOLEAN onePoint = ( AlphaBand == 0 ) && ( DeltaBand == 0 );
1303 BOOLEAN region2D = ( AlphaBand != 0 ) && ( DeltaBand != 0 );
1307 REAL8 Da = AlphaBand;
1308 REAL8 Dd = DeltaBand;
1314 sprintf( buf,
"(%.16g, %.16g)", Alpha, Delta );
1317 "(%.16g, %.16g), (%.16g, %.16g), (%.16g, %.16g), (%.16g, %.16g)",
1320 Alpha + Da, Delta + Dd,
1321 Alpha, Delta + Dd );
1351 REAL8 g_f0_f0 = 0, gamma_f1_f1 = 0, gamma_a_a, gamma_d_d;
1358 metricpar.position.longitude = gridpoint.
Alpha;
1359 metricpar.position.latitude = gridpoint.
Delta;
1365 metricpar.spindown->data[0] = gridpoint.
fkdot[1] / gridpoint.
fkdot[0];
1367 metricpar.epoch =
params->obsBegin;
1369 metricpar.maxFreq = gridpoint.
fkdot[0];
1370 metricpar.site =
params->Detector;
1371 metricpar.ephemeris =
params->ephemeris;
1372 metricpar.metricType =
params->metricType;
1391 spacings->
fkdot[0] = 2.0 * sqrt(
params->metricMismatch / g_f0_f0 );
1393 if (
params->projectMetric ) {
1399 spacings->
fkdot[1] = 2.0 * gridpoint.
fkdot[0] * sqrt(
params->metricMismatch / gamma_f1_f1 );
1408 spacings->
Alpha = 2.0 * sqrt(
params->metricMismatch / gamma_a_a );
1409 spacings->
Delta = 2.0 * sqrt(
params->metricMismatch / gamma_d_d );
1415 REAL8 Tobs_s = Tobs;
1419 spacings->
fkdot[
s] = 1.0 / ( 2.0 * Tobs_s );
1441 REAL8 gaa, gad, gdd;
1442 REAL8 smin, smaj, angle;
1448 UINT4 dim = dim0 + 2;
1449 if ( !( metric->
length >= dim * ( dim + 1 ) / 2 ) ) {
1458 smin = gaa + gdd + sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
1459 smin = sqrt( 2.0 * mismatch / smin );
1462 smaj = gaa + gdd - sqrt( pow( gaa - gdd, 2 ) + pow( 2 * gad, 2 ) );
1463 smaj = sqrt( 2.0 * mismatch / smaj );
1466 angle = atan2( gad, mismatch / smaj / smaj - gdd );
1476 ellipse->
angle = angle;
1511 UINT4 iMin, numPoints;
1517 if ( !skygrid || ( numPartitions == 0 ) || ( partitionIndex >= numPartitions ) ) {
1525 while ( ( node = node->
next ) != NULL ) {
1529 if ( Nsky < numPartitions ) {
1534 Nt = Nsky / numPartitions;
1535 dp = Nsky - numPartitions * Nt;
1538 iMin =
fmin( partitionIndex, dp ) * ( Nt + 1 ) +
fmax( 0, ( (
INT4 )partitionIndex - (
INT4 )dp ) ) * Nt;
1539 numPoints = ( partitionIndex < dp ) ? ( Nt + 1 ) : Nt ;
1546 while ( counter -- ) {
1552 while ( numPoints -- ) {
1558 newNode = newNode->
next;
1568 return newGrid.next;
BOOLEAN pointInPolygon(const SkyPosition *point, const SkyRegion *polygon)
Function for checking if a given point lies inside or outside a given polygon, which is specified by ...
int fprintfDopplerParams(FILE *fp, const PulsarDopplerParams *params)
Debug-output of PulsarDopplerParams struct.
const char * va(const char *format,...)
CHAR * XLALSkySquare2String(REAL8 Alpha, REAL8 Delta, REAL8 AlphaBand, REAL8 DeltaBand)
parse a 'classical' sky-square (Alpha, Delta, AlphaBand, DeltaBand) into a "SkyRegion"-string of the ...
void InitDopplerSkyScan(LALStatus *status, DopplerSkyScanState *skyScan, const DopplerSkyScanInit *init)
DopplerSkyGrid * buildIsotropicSkyGrid(const SkyRegion *skyRegion, REAL8 dAlpha, REAL8 dDelta)
void FreeDopplerSkyScan(LALStatus *status, DopplerSkyScanState *skyScan)
REAL8 getDopplermax(EphemerisData *edat)
some temp test-code outputting the maximal possible dopper-shift |vE| + |vS| over the ephemeris
void printFrequencyShifts(LALStatus *, const DopplerSkyScanState *skyScan, const DopplerSkyScanInit *init)
void writeSkyGridFile(LALStatus *status, const DopplerSkyGrid *skyGrid, const CHAR *fname)
Write the given sky-grid to a file.
void getMetric(LALStatus *, meshREAL g[3], meshREAL skypos[2], void *params)
int XLALParseSkyRegionString(SkyRegion *region, const CHAR *input)
parse a skyRegion-string into a SkyRegion structure: the expected string-format is " (longitude1,...
DopplerSkyGrid * buildFlatSkyGrid(const SkyRegion *region, REAL8 dAlpha, REAL8 dDelta)
void freeSkyGrid(DopplerSkyGrid *skygrid)
void getMetricEllipse(LALStatus *status, MetricEllipse *ellipse, REAL8 mismatch, const REAL8Vector *metric, UINT4 dim0)
get "metric-ellipse" for given metric.
DopplerSkyGrid * buildMetricSkyGrid(SkyRegion *skyRegion, const DopplerSkyScanInit *init)
Build the skygrid using a specified metric.
TwoDMeshParamStruc meshPARAMS
DopplerSkyGrid * loadSkyGridFile(const CHAR *fname)
Load skygrid from file, clipped to searchRegion.
void getRange(LALStatus *, meshREAL y[2], meshREAL x, void *params)
void plotSkyGrid(LALStatus *, DopplerSkyGrid *skygrid, const SkyRegion *region, const DopplerSkyScanInit *init)
DopplerSkyGrid * ConvertTwoDMesh2SkyGrid(const meshNODE *mesh2d, const SkyRegion *region)
int XLALInitDopplerSkyScan(DopplerSkyScanState *skyScan, const DopplerSkyScanInit *init)
Initialize the Doppler sky-scanner.
int XLALNextDopplerSkyPos(PulsarDopplerParams *pos, DopplerSkyScanState *skyScan)
NextDopplerSkyPos(): step through sky-grid return 0 = OK, -1 = ERROR.
DopplerSkyGrid * XLALEquiPartitionSkygrid(const DopplerSkyGrid *skygrid, UINT4 partitionIndex, UINT4 numPartitions)
Equi-partition (approximately) a given skygrid into numPartitions, and return partition 0<= partition...
void gridFlipOrder(meshNODE *grid)
void XLALDestroyDopplerSkyScan(DopplerSkyScanState *skyScan)
Destroy the DopplerSkyScanState structure.
int getGridSpacings(PulsarDopplerParams *spacings, PulsarDopplerParams gridpoint, const DopplerSkyScanInit *params)
determine the 'canonical' stepsizes in all parameter-space directions, either from the metric (if –gr...
#define DOPPLERSCANH_MSGESYS
#define DOPPLERSCANH_ENEGMETRIC
#define DOPPLERSCANH_MSGENEGMETRIC
#define DOPPLERSCANH_ESYS
#define DOPPLERSCANH_MSGEXLAL
#define DOPPLERSCANH_EINPUT
#define DOPPLERSCANH_ENULL
#define DOPPLERSCANH_MSGENULL
#define DOPPLERSCANH_MSGEINPUT
#define DOPPLERSCANH_EXLAL
@ STATE_READY
initialized and ready
@ STATE_FINISHED
all templates have been read
@ STATE_IDLE
not initialized yet
@ GRID_METRIC
generate grid using a 2D sky-metric
@ GRID_FLAT
"flat" sky-grid: fixed step-size (dAlpha,dDelta)
@ GRID_FILE_SKYGRID
read skygrid from a file
@ GRID_METRIC_SKYFILE
'hybrid' grid-construction: use skygrid from file, metric for others
@ GRID_SKY_LAST
end-marker for factored grid types
@ GRID_ISOTROPIC
approximately isotropic sky-grid
#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)
int XLALParseDataFile(LALParsedDataFile **cfgdata, const CHAR *fname)
void XLALDestroyParsedDataFile(LALParsedDataFile *cfgdata)
#define XLAL_INIT_DECL(var,...)
void * XLALMalloc(size_t n)
char char * XLALStringDuplicate(const char *s)
void LogPrintf(LogLevel_t, const char *format,...) _LAL_GCC_PRINTF_FORMAT_(2
#define PMETRIC_INDEX(a, b)
Translate metrix matrix-indices (a,b) into vector-index l.
void LALProjectMetric(LALStatus *stat, REAL8Vector *metric, BOOLEAN errors)
Project out the zeroth dimension of a metric.
void LALPulsarMetric(LALStatus *stat, REAL8Vector **metric, PtoleMetricIn *input)
Unified "wrapper" to provide a uniform interface to LALPtoleMetric() and LALCoherentMetric().
REAL8 PulsarSpins[PULSAR_MAX_SPINS]
Typedef for fixed-size array holding GW frequency and derivatives fk = d^k Freq/dt^k|(tau_ref)
#define PULSAR_MAX_SPINS
maximal number of spin-parameters (Freq + spindowns) we can handle
void XLALNormalizeSkyPosition(double *restrict longitude, double *restrict latitude)
void LALNormalizeSkyPosition(LALStatus *stat, SkyPosition *posOut, const SkyPosition *posIn)
COORDINATESYSTEM_EQUATORIAL
void LALCreateTwoDMesh(LALStatus *stat, TwoDMeshNode **mesh, TwoDMeshParamStruc *params)
void LALDestroyTwoDMesh(LALStatus *stat, TwoDMeshNode **mesh, UINT4 *nFree)
void XLALDestroyREAL4Vector(REAL4Vector *vector)
REAL4Vector * XLALCreateREAL4Vector(UINT4 length)
void LALDDestroyVector(LALStatus *, REAL8Vector **)
void XLALDestroyREAL8Vector(REAL8Vector *vector)
#define XLAL_ERROR_NULL(...)
int int int XLALPrintInfo(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK(assertion,...)
int XLALPrintError(const char *fmt,...) _LAL_GCC_PRINTF_FORMAT_(1
#define XLAL_CHECK_NULL(assertion,...)
#define XLAL_PRINT_DEPRECATION_WARNING(replacement)
struct tagDopplerSkyGrid * next
initialization-structure passed to InitDopplerSkyScan()
const EphemerisData * ephemeris
ephemeris-data for "exact" metric
BOOLEAN projectMetric
project the metric orthogonal to Freq?
UINT4 numSkyPartitions
number of (roughly) equal partitions to split sky-grid into
UINT4 partitionIndex
index of requested sky-grid partition: in [0, numPartitions - 1]
const CHAR * skyGridFile
file containing a sky-grid (list of points) if GRID_FILE
LIGOTimeGPS obsBegin
GPS start-time of time-series.
REAL8 dDelta
sky step-sizes for GRID_FLAT and GRID_ISOTROPIC
REAL8 Freq
Frequency for which to build the skyGrid.
DopplerGridType gridType
which type of skygrid to generate
REAL8 obsDuration
length of time-series in seconds
REAL8 metricMismatch
for GRID_METRIC
LALPulsarMetricType metricType
which metric to use if GRID_METRIC
CHAR * skyRegionString
sky-region to search: format polygon '(a1,d1), (a2,d2), ..'
const LALDetector * Detector
Current detector.
this structure reflects the current state of a DopplerSkyScan
UINT4 numSkyGridPoints
how many skygrid-points
PulsarSpins dfkdot
fixed-size steps in spins
DopplerSkyGrid * skyNode
pointer to current grid-node in skygrid
scan_state_t state
idle, ready or finished
DopplerSkyGrid * skyGrid
head of linked list of skygrid nodes
SkyRegion skyRegion
polygon (and bounding square) defining sky-region
This structure contains all information about the center-of-mass positions of the Earth and Sun,...
a "sky-ellipse", described by the two major axes and it's angle wrt x-axis
This structure will likely be changed to match up better with those under StackMetric....
SkyPosition position
The equatorial coordinates at which the metric components are evaluated.
REAL4Vector * spindown
The (dimensionless) spindown parameters for which the metric components are evaluated.
REAL4 maxFreq
The maximum frequency to be searched, in Hz.
LALPulsarMetricType metricType
The type of metric to use: analytic, Ptolemaic or fully ephemeris-based.
const LALDetector * site
The detector site, used only for its latitude and longitude.
REAL4 duration
Duration of integration, in seconds.
const EphemerisData * ephemeris
Not used for the Ptolemaic approximation, this is for compatibility with other metrics.
LIGOTimeGPS epoch
When the coherent integration begins.
Type containing the 'Doppler-parameters' affecting the time-evolution of the phase.
PulsarSpins fkdot
Intrinsic spins: [Freq, f1dot, f2dot, ...
REAL8 Delta
Sky position: DEC (latitude) in equatorial coords and radians.
REAL8 Alpha
Sky position: RA (longitude) in equatorial coords and radians.
structure describing a polygon-region in the sky
UINT4 numVertices
number of polygon-vertices
SkyPosition lowerLeft
lower-left point of bounding square
SkyPosition * vertices
array of vertices
SkyPosition upperRight
upper-right point of bounding square
This structure represents a single node in a linked list of mesh points, specified in the coordinate ...
struct tagTwoDMeshNode * next
The next mesh point in the linked list; NULL if this is the tail.
REAL4 y
The coordinates of the mesh point.
This structure stores the parameters required by the two-dimensional mesh placement functions.