Ejemplo n.º 1
0
int XLALHashTblFind(
  const LALHashTbl *ht,
  const void *x,
  const void **y
  )
{

  /* Check input */
  XLAL_CHECK( ht != NULL, XLAL_EFAULT );
  XLAL_CHECK( x != NULL && x != DEL, XLAL_EINVAL );
  XLAL_CHECK( y != NULL, XLAL_EFAULT );

  /* Try to find element matching 'x' in hash table, if found return in 'y' */
  if ( ht->data_len > 0 ) {
    int i = HASHIDX( ht, x );
    while ( ht->data[i] != NULL ) {
      *y = ht->data[i];
      if ( *y != DEL && EQUAL( ht, x, *y ) ) {
        return XLAL_SUCCESS;
      }
      INCRIDX( ht, i );
    }
  }

  /* No element matches 'x' */
  *y = NULL;
  return XLAL_SUCCESS;

}
Ejemplo n.º 2
0
/**
 * Time-shift the given SFT by an amount of 'shift' seconds,
 * using the frequency-domain expression
 * \f$\widetilde{y}(f) = \widetilde{x}(f) \, e^{i 2\pi\,f\,\tau}\f$,
 * which shifts \f$x(t)\f$ into \f$y(t) = x(t + \tau)\f$
 *
 * NOTE: this <b>modifies</b> the SFT in place
 */
int
XLALTimeShiftSFT ( SFTtype *sft,	/**< [in/out] SFT to time-shift */
		   REAL8 shift		/**< time-shift \f$\tau\f$ in seconds */
                   )
{
  XLAL_CHECK ( (sft != NULL) && (sft->data != NULL), XLAL_EINVAL );

  if ( shift == 0 ) {
    return XLAL_SUCCESS;
  }

  for ( UINT4 k=0; k < sft->data->length; k++ )
    {
      REAL8 fk = sft->f0 + k * sft->deltaF;	/* frequency of k-th bin */
      REAL8 shiftCyles = shift * fk;
      REAL4 fact_re, fact_im;			/* complex phase-shift factor e^(-2pi f tau) */
      XLAL_CHECK ( XLALSinCos2PiLUT ( &fact_im, &fact_re, shiftCyles ) == XLAL_SUCCESS, XLAL_EFUNC );

      COMPLEX8 fact = crectf(fact_re, fact_im);
      sft->data->data[k] *= fact;

    } /* for k < numBins */

  /* adjust SFTs epoch to the shift */
  XLALGPSAdd ( &sft->epoch, shift );

  return XLAL_SUCCESS;

} // XLALTimeShiftSFT()
Ejemplo n.º 3
0
/**
 * Has this user-variable been set by the user?
 * returns 1 (=TRUE) or 0 (=FALSE) on success, error-code otherwise
 */
int
XLALUserVarWasSet ( const void *cvar )
{
  XLAL_CHECK ( cvar != NULL, XLAL_EINVAL );
  XLAL_CHECK ( UVAR_vars.next != NULL, XLAL_EINVAL, "No UVAR memory allocated. Did you register any user-variables?" );

  // find this variable name in the list of registered user-variables
  LALUserVariable *ptr = &UVAR_vars;
  while ( (ptr = ptr->next) != NULL )
    {
      if ( ptr->varp == cvar) {
        break;
      }
    } // while ptr = ptr->next

  XLAL_CHECK ( ptr != NULL, XLAL_EINVAL, "Variable pointer passed UVARwasSet is not a registered User-variable\n" );

  // we found it: has it been set by user?
  if ( ptr->was_set ) {
    return 1;
  } else {
    return 0;
  }

} // XLALUserVarWasSet()
Ejemplo n.º 4
0
/**
 * Frequency and frequency derivative components of the metric, suitable for a directed
 * search with only one fixed sky position. The units are those expected by ComputeFstat.
 */
int XLALSpindownMetric(
  gsl_matrix* metric,	/**< [in] Matrix containing the metric */
  double Tspan		/**< [in] Time span of the data set */
  )
{

  // Check input
  XLAL_CHECK(metric != NULL, XLAL_EFAULT);
  XLAL_CHECK(metric->size1 == metric->size2, XLAL_ESIZE);
  XLAL_CHECK(Tspan > 0, XLAL_EINVAL);

  // Calculate metric
  for (size_t i = 0; i < metric->size1; ++i) {
    for (size_t j = i; j < metric->size2; ++j) {
      gsl_matrix_set(metric, i, j, (
                       4.0 * LAL_PI * LAL_PI * pow(Tspan, i + j + 2) * (i + 1) * (j + 1)
                       ) / (
                         LAL_FACT[i + 1] * LAL_FACT[j + 1] * (i + 2) * (j + 2) * (i + j + 3)
                         ));
      gsl_matrix_set(metric, j, i, gsl_matrix_get(metric, i, j));
    }
  }

  return XLAL_SUCCESS;

} // XLALSpindownMetric
Ejemplo n.º 5
0
/// Parse a string into an INT8
/// This ignores initial whitespace, but throws an error on _any_ non-converted trailing characters (including whitespace)
int
XLALParseStringValueAsINT8 ( INT8 *valINT8,         ///< [out] return INT8 value
                             const char *valString  ///< [in]  input string value
                             )
{
  XLAL_CHECK ( (valINT8 != NULL) && (valString != NULL ), XLAL_EINVAL );

  errno = 0;
  char *endptr;
  int base10 = 10;
  long long valLLong = strtoll ( valString, &endptr, base10 );
  XLAL_CHECK ( errno == 0, XLAL_EFAILED, "strtoll() failed to convert '%s' into long long!\n", valString );
  XLAL_CHECK ( (*endptr) == '\0', XLAL_EFAILED, "strtoll(): trailing garbage '%s' found after int-conversion of '%s'\n", endptr, valString );

  //  check range and convert long-int into INT8
  if ( sizeof(valLLong) > sizeof(INT8) ) { // avoid warning about trivial check
    XLAL_CHECK ( (valLLong >= -LAL_sINT8_MAX) && (valLLong <= LAL_sINT8_MAX), XLAL_EDOM, "String-conversion '%s' --> '%lli' exceeds INT8 range of +-%"LAL_INT8_FORMAT"\n",
                 valString, valLLong, LAL_sINT8_MAX );
  }

  (*valINT8) = (INT8)valLLong;

  return XLAL_SUCCESS;

} // XLALParseStringValueAsINT8()
Ejemplo n.º 6
0
///
/// Parse a string representing a range of DECJ values into a REAL8Range. Possible formats
/// are <tt>start</tt>, <tt>start,end</tt>, <tt>start/band</tt>, or <tt>start~plusminus</tt>.
/// Output range is always <tt>low,high</tt> with <tt>range[0] = low; range[1] = high</tt>.
///
int XLALParseStringValueAsDECJRange(
  REAL8Range *decjRange,		///< [out] output range of DECJ values
  const char *valString			///< [in] input string
  )
{

  // Check input
  XLAL_CHECK(decjRange != NULL, XLAL_EFAULT);
  XLAL_CHECK(valString != NULL, XLAL_EFAULT);

  // Parse range
  char part[2][256];
  int T[2][2];
  split_string_into_range(valString, part, T);
  REAL8 val[2];
  XLAL_CHECK( XLALParseStringValueAsDECJ(&val[0], part[0]) == XLAL_SUCCESS, XLAL_EFUNC );
  XLAL_CHECK( XLALParseStringValueAsDECJ(&val[1], part[1]) == XLAL_SUCCESS, XLAL_EFUNC );
  (*decjRange)[0] = T[0][0] * val[0] + T[0][1] * val[1];
  (*decjRange)[1] = T[1][0] * val[0] + T[1][1] * val[1];

  // Check range ordering
  if ((*decjRange)[0] > (*decjRange)[1]) {
    const REAL8 tmp = (*decjRange)[0];
    (*decjRange)[0] = (*decjRange)[1];
    (*decjRange)[1] = tmp;
  }

  return XLAL_SUCCESS;

}
Ejemplo n.º 7
0
/// Parse a string into a BOOLEAN
/// Allowed string-values are (case-insensitive):
/// {"yes", "true", "1"} --> TRUE
/// {"no", "false", "0"} --> FALSE
///
/// NOTE: This throws an error on _any_ extraneous leading or trailing characters or whitespace
int
XLALParseStringValueAsBOOLEAN ( BOOLEAN *valBOOLEAN,     ///< [out] return BOOLEAN value
                                const char *valString    ///< [in]  input string value
                                )
{
  XLAL_CHECK ( (valBOOLEAN != NULL) && (valString != NULL ), XLAL_EINVAL );

  /* get rid of case ambiguities */
  char *valStringLower;
  XLAL_CHECK ( (valStringLower = XLALMalloc ( strlen(valString) + 1 )) != NULL, XLAL_ENOMEM );
  strcpy ( valStringLower, valString );
  XLALStringToLowerCase ( valStringLower );

  /* parse it as a bool */
  if ( !strcmp(valStringLower, "yes") || !strcmp(valStringLower, "true") || !strcmp(valStringLower, "1") )
    {
      (*valBOOLEAN) = 1;
    }
  else if ( !strcmp(valStringLower, "no") || !strcmp(valStringLower, "false") || !strcmp(valStringLower, "0") )
    {
      (*valBOOLEAN) = 0;
    }
  else
    {
      XLALFree ( valStringLower );
      XLAL_ERROR ( XLAL_EINVAL, "Illegal bool-string '%s', needs to be one of {'yes', 'true', '1'} or {'no', 'false', '0'} (case-insensitive)\n", valString );
    }

  XLALFree ( valStringLower );

  return XLAL_SUCCESS;

} // XLALParseStringValueAsBOOLEAN()
Ejemplo n.º 8
0
///
/// Parse a string representing a range of LIGOTimeGPS values into a LIGOTimeGPSRange. Possible formats
/// are <tt>start</tt>, <tt>start,end</tt>, <tt>start/band</tt>, or <tt>start~plusminus</tt>.
/// Output range is always <tt>low,high</tt> with <tt>range[0] = low; range[1] = high</tt>.
///
int XLALParseStringValueAsEPOCHRange(
  LIGOTimeGPSRange *gpsRange,		///< [out] output range of LIGOTimeGPS values
  const char *valString			///< [in] input string
  )
{

  // Check input
  XLAL_CHECK(gpsRange != NULL, XLAL_EFAULT);
  XLAL_CHECK(valString != NULL, XLAL_EFAULT);

  // Parse range
  char part[2][256];
  int T[2][2];
  split_string_into_range(valString, part, T);
  LIGOTimeGPS val[2];
  XLAL_CHECK( XLALParseStringValueAsEPOCH(&val[0], part[0]) == XLAL_SUCCESS, XLAL_EFUNC );
  XLAL_CHECK( XLALParseStringValueAsEPOCH(&val[1], part[1]) == XLAL_SUCCESS, XLAL_EFUNC );
  XLALINT8NSToGPS( &(*gpsRange)[0], T[0][0] * XLALGPSToINT8NS(&val[0]) + T[0][1] * XLALGPSToINT8NS(&val[1]) );
  XLALINT8NSToGPS( &(*gpsRange)[1], T[1][0] * XLALGPSToINT8NS(&val[0]) + T[1][1] * XLALGPSToINT8NS(&val[1]) );

  // Check range ordering
  if (XLALGPSCmp(&(*gpsRange)[0], &(*gpsRange)[1]) > 0) {
    const LIGOTimeGPS tmp = (*gpsRange)[0];
    (*gpsRange)[0] = (*gpsRange)[1];
    (*gpsRange)[1] = tmp;
  }

  return XLAL_SUCCESS;

}
Ejemplo n.º 9
0
static int _test_sum_of_squares(const double *correct, int length, double kaiser_beta, double creighton_beta, double tukey_beta, double gauss_beta)
{
	const double max_error = 1e-12;
	REAL4Window *windows1[NWINDOWS];
	REAL8Window *windows2[NWINDOWS];
	int i;

	XLAL_CHECK ( create_single_windows(windows1, length, kaiser_beta, creighton_beta, tukey_beta, gauss_beta) == XLAL_SUCCESS, XLAL_EFUNC );

	XLAL_CHECK ( create_double_windows(windows2, length, kaiser_beta, creighton_beta, tukey_beta, gauss_beta) == XLAL_SUCCESS, XLAL_EFUNC );

	for(i = 0; i < NWINDOWS; i++) {
		if(fractional_difference(windows1[i]->sumofsquares, correct[i]) > max_error) {
                  XLAL_ERROR (XLAL_EFAILED, "error: single-precision %d-sample %s window fails sum-of-squares test:  expected %.17g, got %.17g\n",
                              length, names[i], correct[i], windows1[i]->sumofsquares);
		}
		if(fractional_difference(windows2[i]->sumofsquares, correct[i]) > max_error) {
                  XLAL_ERROR (XLAL_EFAILED, "error: double-precision %d-sample %s window fails sum-of-squares test:  expected %.17g, got %.17g\n", length, names[i], correct[i], windows1[i]->sumofsquares);
		}
	}

	free_single_windows(windows1);
	free_double_windows(windows2);

	return XLAL_SUCCESS;

} // _test_sum_of_squares()
Ejemplo n.º 10
0
INT4 CompAntennaPatternWeights2(REAL4VectorAligned *output, const SkyPosition skypos, const LIGOTimeGPSVector *timestamps, const LALDetector det, const REAL8 *cosi, const REAL8 *psi)
{

   XLAL_CHECK( output != NULL, XLAL_EINVAL );

   REAL8 onePlusCosiSqOver2Sq = 1.0, cosiSq = 1.0;
   if (cosi!=NULL) {
      onePlusCosiSqOver2Sq = 0.25*(1.0 + (*cosi)*(*cosi))*(1.0 + (*cosi)*(*cosi));
      cosiSq = (*cosi)*(*cosi);
   }

   REAL8 fplus, fcross;
   for (UINT4 ii=0; ii<timestamps->length; ii++) {
      REAL8 gmst = XLALGreenwichMeanSiderealTime(&(timestamps->data[ii]));
      XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC );

      if (psi!=NULL) {
         XLALComputeDetAMResponse(&fplus, &fcross, det.response, skypos.longitude, skypos.latitude, *psi, gmst);
         XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC );
         output->data[ii] = fplus*fplus*onePlusCosiSqOver2Sq + fcross*fcross*cosiSq;
      } else {
         output->data[ii] = 0.0;
         for (UINT4 jj=0; jj<16; jj++) {
            XLALComputeDetAMResponse(&fplus, &fcross, det.response, skypos.longitude, skypos.latitude, 0.0625*LAL_PI*jj, gmst);
            XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC );
            output->data[ii] += fplus*fplus*onePlusCosiSqOver2Sq + fcross*fcross*cosiSq;
         }
         output->data[ii] *= 0.0625;
      }
   }

   return XLAL_SUCCESS;

} // CompAntennaPatternWeights()
Ejemplo n.º 11
0
/**
 * Compute the antenna velocity
 * \param [out] output     Pointer to REAL4Vector of antenna velocities
 * \param [in]  skypos     Sky position measured in RA and Dec in radians
 * \param [in]  t0         Start time (GPS seconds)
 * \param [in]  Tsft       Coherence length of the SFTs (in seconds)
 * \param [in]  SFToverlap Overlap of the SFTs (in seconds)
 * \param [in]  Tobs       Observation time (in seconds)
 * \param [in]  det        A LALDetector struct
 * \param [in]  edat       Pointer to EphemerisData
 * \return Status value
 */
INT4 CompAntennaVelocity(REAL4VectorAligned *output, const SkyPosition skypos, const REAL8 t0, const REAL8 Tsft, const REAL8 SFToverlap, const REAL8 Tobs, const LALDetector det, EphemerisData *edat)
{

   XLAL_CHECK( output != NULL && edat != NULL, XLAL_EINVAL );

   INT4 numffts = (INT4)floor(Tobs/(Tsft-SFToverlap)-1);    //Number of FFTs
   LALStatus XLAL_INIT_DECL(status);

   REAL8 detvel[3];
   for (INT4 ii=0; ii<numffts; ii++) {

      LIGOTimeGPS gpstime = LIGOTIMEGPSZERO;
      gpstime.gpsSeconds = (INT4)floor(t0 + ii*(Tsft-SFToverlap) + 0.5*Tsft);
      gpstime.gpsNanoSeconds = (INT4)floor((t0+ii*(Tsft-SFToverlap)+0.5*Tsft - floor(t0+ii*(Tsft-SFToverlap)+0.5*Tsft))*1e9);

      LALDetectorVel(&status, detvel, &gpstime, det, edat);
      XLAL_CHECK( status.statusCode == 0, XLAL_EFUNC );

      output->data[ii] = (REAL4)(detvel[0]*cos(skypos.longitude)*cos(skypos.latitude) + detvel[1]*sin(skypos.longitude)*cos(skypos.latitude) + detvel[2]*sin(skypos.latitude));

   } /* for ii < numffts */

   return XLAL_SUCCESS;

} /* CompAntennaVelocity() */
Ejemplo n.º 12
0
/**
 * Freq-shift the given COMPLEX8Timeseries by an amount of 'shift' Hz,
 * using the time-domain expression y(t) = x(t) * e^(-i 2pi df t),
 * which shifts x(f) into y(f) = x(f + df)
 *
 * NOTE: this <b>modifies</b> the COMPLEX8TimeSeries in place
 */
int
XLALFrequencyShiftCOMPLEX8TimeSeries ( COMPLEX8TimeSeries *x,	        /**< [in/out] timeseries to time-shift */
				       const REAL8 shift	        /**< [in] freq-shift in Hz */
                                       )
{
  XLAL_CHECK ( (x != NULL) && ( x->data != NULL ), XLAL_EINVAL );

  if ( shift == 0 ) {
    return XLAL_SUCCESS;
  }

  /* get timeseries time-step */
  REAL8 deltat = x->deltaT;

  /* loop over COMPLEX8TimeSeries elements */
  for ( UINT4 k=0; k < x->data->length; k++)
    {
      REAL8 tk = k * deltat;	/* time of k-th bin */
      REAL8 shiftCycles = shift * tk;
      REAL4 fact_re, fact_im;			/* complex phase-shift factor e^(-2pi f tau) */

      /* use a sin/cos look-up-table for speed */
      XLAL_CHECK( XLALSinCos2PiLUT ( &fact_im, &fact_re, shiftCycles ) == XLAL_SUCCESS, XLAL_EFUNC );
      COMPLEX8 fact = crectf(fact_re, fact_im);

      x->data->data[k] *= fact;

    } /* for k < numBins */

  /* adjust timeseries heterodyne frequency to the shift */
  x->f0 -= shift;

  return XLAL_SUCCESS;

} /* XLALFrequencyShiftCOMPLEX8TimeSeries() */
Ejemplo n.º 13
0
/**
 * Change frequency-bin order from 'SFT' to fftw-convention
 * ie. from f[-(N-1)/2], ... f[-1], f[0], f[1], .... f[N/2]
 * to FFTW: f[0], f[1],...f[N/2], f[-(N-1)/2], ... f[-2], f[-1]
 */
int
XLALReorderSFTtoFFTW (COMPLEX8Vector *X)
{
  XLAL_CHECK ( (X != NULL) && (X->length > 0), XLAL_EINVAL );

  UINT4 N = X->length;
  UINT4 Npos_and_DC = NhalfPosDC ( N );
  UINT4 Nneg = NhalfNeg ( N );

  /* allocate temporary storage for swap */
  COMPLEX8 *tmp;
  XLAL_CHECK ( (tmp = XLALMalloc ( N * sizeof(*tmp) )) != NULL, XLAL_ENOMEM );

  memcpy ( tmp, X->data, N * sizeof(*tmp) );

  /* Copy second half of FFTW: 'negative' frequencies */
  memcpy ( X->data + Npos_and_DC, tmp, Nneg * sizeof(*tmp) );

  /* Copy first half of FFTW: 'DC + positive' frequencies */
  memcpy ( X->data, tmp + Nneg, Npos_and_DC * sizeof(*tmp) );

  XLALFree(tmp);

  return XLAL_SUCCESS;

}  // XLALReorderSFTtoFFTW()
Ejemplo n.º 14
0
/**
 * Extract multi detector-info from a given multi SFTCatalog view
*/
int
XLALMultiLALDetectorFromMultiSFTCatalogView ( MultiLALDetector *multiIFO,		//!< [out] list of detectors found in catalog
                                              const MultiSFTCatalogView *multiView	//!< [in] multi-IFO view of SFT catalog
                                              )
{
  // check input consistency
  XLAL_CHECK ( multiIFO != NULL, XLAL_EINVAL );
  XLAL_CHECK ( multiView != NULL, XLAL_EINVAL );
  UINT4 numIFOs = multiView->length;
  XLAL_CHECK ( (numIFOs > 0) && (numIFOs <= PULSAR_MAX_DETECTORS), XLAL_EINVAL );



  multiIFO->length = numIFOs;
  for ( UINT4 X=0; X < numIFOs; X ++ )
    {
      LALDetector *site;
      XLAL_CHECK ( (site = XLALGetSiteInfo ( multiView->data[X].data->header.name )) != NULL, XLAL_EFUNC );
      multiIFO->sites[X] = (*site);	 // struct-copy
      XLALFree ( site );
    } /* for X < numIFOs */

  return XLAL_SUCCESS;

} /* XLALMultiLALDetectorFromMultiSFTCatalogView() */
Ejemplo n.º 15
0
/**
 * Parse string-vectors (typically input by user) of N detector-names
 * for detectors \f$X=1\ldots N\f$, returns a MultiLALDetector struct
 *
 */
int
XLALParseMultiLALDetector ( MultiLALDetector *detInfo,        /**< [out] parsed detector-info struct */
                            const LALStringVector *detNames   /**< [in] list of detector names */
                            )
{
  XLAL_CHECK ( detInfo != NULL, XLAL_EINVAL );
  XLAL_CHECK ( detNames != NULL, XLAL_EINVAL );
  UINT4 numDet = detNames->length;
  XLAL_CHECK ( (numDet > 0) && (numDet <= PULSAR_MAX_DETECTORS), XLAL_EINVAL );

  detInfo->length = numDet;

  /* parse input strings and fill detInfo */
  for ( UINT4 X = 0; X < numDet; X ++ )
    {
      LALDetector *ifo;
      /* first parse detector name */
      XLAL_CHECK ( (ifo = XLALGetSiteInfo ( detNames->data[X] ) ) != NULL, XLAL_EINVAL, "Failed to parse detector-name '%s'\n", detNames->data[X] );
      detInfo->sites[X] = (*ifo);	// struct copy
      XLALFree ( ifo );

    } /* for X < numDet */

  return XLAL_SUCCESS;

} /* XLALParseMultiLALDetector() */
Ejemplo n.º 16
0
INT4 InitUserVars2(UserVariables_t *uvar, int argc, char *argv[])
{
   XLAL_CHECK ( uvar != NULL, XLAL_EINVAL, "Invalid NULL input 'uvar'\n");
   XLAL_CHECK ( argv != NULL, XLAL_EINVAL, "Invalid NULL input 'argv'\n");

   uvar->Tsft = 1800;
   uvar->SFToverlap = 900;

   XLALRegisterUvarMember(  help,             BOOLEAN, 'h', HELP    , "Print this help/usage message");
   XLALRegisterUvarMember(  Pmin,              REAL8, 0 , REQUIRED, "Minimum period");
   XLALRegisterUvarMember(  Pmax,              REAL8, 0 , REQUIRED, "Maximum period");
   XLALRegisterUvarMember(  dfmin,             REAL8, 0 , REQUIRED, "Minimum modulation depth");
   XLALRegisterUvarMember(  dfmax,             REAL8, 0 , REQUIRED, "Maximum modulation depth");
   XLALRegisterUvarMember(  Tsft,              REAL8, 0 , OPTIONAL, "SFT coherence length");
   XLALRegisterUvarMember(  SFToverlap,        REAL8, 0 , OPTIONAL, "SFT overlap in second");
   XLALRegisterUvarMember(  Tobs,              REAL8, 0 , REQUIRED, "Total observation time");
   XLALRegisterUvarMember(   minTemplateLength, INT4, 0 , REQUIRED, "Minimum number of pixels in templates");
   XLALRegisterUvarMember(   maxTemplateLength, INT4, 0 , REQUIRED, "Maximum number of pixels in tempaltes");
   XLALRegisterUvarMember(   maxVectorLength,   INT4, 0 , REQUIRED, "Maximum vector length");
   XLALRegisterUvarMember(   vectorMath,        INT4, 0 , OPTIONAL, "Vector math flag: 0 = no SSE/AVX, 1 = SSE, 2 = AVX");
   XLALRegisterUvarMember(  exactflag,         BOOLEAN, 0 , OPTIONAL, "Flag to specify using exact templates");
   XLALRegisterUvarMember(filename,          STRING, 0 , OPTIONAL, "Filename of output file (if not specified, the vector is destroyed upon exit)");

   XLAL_CHECK( XLALUserVarReadAllInput(argc, argv) == XLAL_SUCCESS, XLAL_EFUNC );

   if ( uvar->help ) exit (0);

   return XLAL_SUCCESS;
}
Ejemplo n.º 17
0
/**
 * Compute the antenna velocity
 * \param [out] output     Pointer to REAL4Vector of antenna velocities
 * \param [in]  ra         Right ascension value (radians)
 * \param [in]  dec        Declination value (radians)
 * \param [in]  t0         Start time (GPS seconds)
 * \param [in]  Tcoh       Coherence length of the SFTs (in seconds)
 * \param [in]  SFToverlap Overlap of the SFTs (in seconds)
 * \param [in]  Tobs       Observation time (in seconds)
 * \param [in]  det        A LALDetector struct
 * \param [in]  edat       Pointer to EphemerisData
 * \return Status value
 */
INT4 CompAntennaVelocity(REAL4Vector *output, REAL4 ra, REAL4 dec, REAL8 t0, REAL8 Tcoh, REAL8 SFToverlap, REAL8 Tobs, LALDetector det, EphemerisData *edat)
{

   XLAL_CHECK( output != NULL && edat != NULL, XLAL_EINVAL );

   INT4 ii;
   INT4 numffts = (INT4)floor(Tobs/(Tcoh-SFToverlap)-1);    //Number of FFTs
   LALStatus XLAL_INIT_DECL(status);

   REAL8 detvel[3];
   for (ii=0; ii<numffts; ii++) {

      LIGOTimeGPS gpstime = LIGOTIMEGPSZERO;
      gpstime.gpsSeconds = (INT4)floor(t0 + ii*(Tcoh-SFToverlap) + 0.5*Tcoh);
      gpstime.gpsNanoSeconds = (INT4)floor((t0+ii*(Tcoh-SFToverlap)+0.5*Tcoh - floor(t0+ii*(Tcoh-SFToverlap)+0.5*Tcoh))*1e9);

      LALDetectorVel(&status, detvel, &gpstime, det, edat);
      XLAL_CHECK( status.statusCode == 0, XLAL_EFUNC );

      output->data[ii] = (REAL4)(detvel[0]*cos(ra)*cos(dec) + detvel[1]*sin(ra)*cos(dec) + detvel[2]*sin(dec));

   } /* for ii < numffts */

   return XLAL_SUCCESS;

} /* CompAntennaVelocity() */
Ejemplo n.º 18
0
/**
 * \brief Compute the antenna pattern weights
 *
 * If linPolOn = 0, then the output weights are Fplus*Fplus + Fcross*Fcross,
 * or if linPolOn = 1, then the output weights are Fplus*Fplus for the given polarization angle
 * \param [out] output     Pointer to REAL4Vector of antenna pattern weights
 * \param [in]  ra         Right ascension value (radians)
 * \param [in]  dec        Declination value (radians)
 * \param [in]  t0         Start time (GPS seconds)
 * \param [in]  Tcoh       Coherence length of the SFTs (in seconds)
 * \param [in]  SFToverlap Overlap of the SFTs (in seconds)
 * \param [in]  Tobs       Observation time (in seconds)
 * \param [in]  linPolOn   Flag for linear polarizations (linPolOn = 0 is circular polarization weights, linPolOn = 1 is linear polarization weights)
 * \param [in]  polAngle   Only used for when linPolOn = 1. Polarization angle from which to compute the antenna pattern weights
 * \param [in]  det        A LALDetector struct
 * \return Status value
 */
INT4 CompAntennaPatternWeights(REAL4Vector *output, REAL4 ra, REAL4 dec, REAL8 t0, REAL8 Tcoh, REAL8 SFToverlap, REAL8 Tobs, INT4 linPolOn, REAL8 polAngle, LALDetector det)
{

   XLAL_CHECK( output != NULL, XLAL_EINVAL );

   INT4 numffts = (INT4)floor(Tobs/(Tcoh-SFToverlap)-1);    //Number of FFTs
   REAL8 fplus, fcross;

   for (INT4 ii=0; ii<numffts; ii++) {

      LIGOTimeGPS gpstime = LIGOTIMEGPSZERO;
      gpstime.gpsSeconds = (INT4)floor(t0 + ii*(Tcoh-SFToverlap) + 0.5*Tcoh);
      gpstime.gpsNanoSeconds = (INT4)floor((t0+ii*(Tcoh-SFToverlap)+0.5*Tcoh - floor(t0+ii*(Tcoh-SFToverlap)+0.5*Tcoh))*1e9);
      REAL8 gmst = XLALGreenwichMeanSiderealTime(&gpstime);
      XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC );

      XLALComputeDetAMResponse(&fplus, &fcross, (const REAL4(*)[3])det.response, ra, dec, polAngle, gmst);
      XLAL_CHECK( xlalErrno == 0, XLAL_EFUNC );

      if (!linPolOn) output->data[ii] = (REAL4)(fplus*fplus + fcross*fcross);
      else output->data[ii] = (REAL4)(fplus*fplus);

   } /* for ii < numffts */

   return XLAL_SUCCESS;

} /* CompAntennaPatternWeights() */
Ejemplo n.º 19
0
/**
 * Comparison function for two multiNoiseWeights vectors, return success or failure for given tolerance.
 * The fractional error is checked for the weights and normalization factors.
 *
 */
int
XLALCompareMultiNoiseWeights ( MultiNoiseWeights *multiWeights1, MultiNoiseWeights *multiWeights2, REAL8 tolerance )
{

  XLALPrintInfo("Sinv_Tsft1 %.12e; Sinv_Tsft2 %.12e\n", multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft);
  XLAL_CHECK ( FRACERR( multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft ) <= tolerance, XLAL_EFAILED, "%s: Sinv_Tsft differs by more than tolerance %g multiWeights1 = %g, multiWeights2 = %g\n", __func__, tolerance, multiWeights1->Sinv_Tsft, multiWeights2->Sinv_Tsft );

  XLAL_CHECK( multiWeights1->length == multiWeights2->length, XLAL_EFAILED, "%s: numbers of detectors differ multiWeights1 = %d, multiWeights2 = %d\n", __func__, multiWeights1->length, multiWeights2->length );
  UINT4 numIFOs = multiWeights1->length;
  for ( UINT4 X = 0; X < numIFOs; X++)
    {
      REAL8Vector *weights1 = multiWeights1->data[X];
      REAL8Vector *weights2 = multiWeights2->data[X];

      XLAL_CHECK( weights1->length == weights2->length, XLAL_EFAILED, "%s: numbers of SFTs for detector %d differ multiWeights1 = %d, multiWeights2 = %d\n", __func__, X, weights1->length, weights2->length );
      UINT4 numSFTs = weights1->length;

      for ( UINT4 alpha = 0; alpha < numSFTs; alpha++)
	{
	  XLALPrintInfo("IFO %d; SFT %d; weight1 %.12e; weight2 %.12e\n", X, alpha, weights1->data[alpha], weights2->data[alpha]);
	  XLAL_CHECK ( FRACERR( weights1->data[alpha], weights2->data[alpha] ) <= tolerance, XLAL_EFAILED, "%s: weights for IFO %d, SFT %d differ by more than tolerance %g multiWeights1 = %g, multiWeights2 = %g\n", __func__, X, alpha, tolerance, weights1->data[alpha], weights2->data[alpha] );
	}
    }

  return XLAL_SUCCESS;

} /* XLALCompareMultiNoiseWeights() */
Ejemplo n.º 20
0
///
/// Add semicoherent results to output
///
int XLALWeaveOutputResultsAdd(
  WeaveOutputResults *out,
  const WeaveSemiResults *semi_res,
  const UINT4 semi_nfreqs
  )
{

  // Check input
  XLAL_CHECK( out != NULL, XLAL_EFAULT );
  XLAL_CHECK( semi_res != NULL, XLAL_EFAULT );

  // Store main-loop parameters relevant for completion-loop statistics calculation
  static BOOLEAN firstTime = 1;
  if ( firstTime ) {
    out->statistics_params->nsum2F = semi_res->nsum2F;
    memcpy( out->statistics_params->nsum2F_det, semi_res->nsum2F_det, sizeof( semi_res->nsum2F_det ) );
    firstTime = 0;
  }

  // Add results to toplists
  for ( size_t i = 0; i < out->ntoplists; ++i ) {
    XLAL_CHECK( XLALWeaveResultsToplistAdd( out->toplists[i], semi_res, semi_nfreqs ) == XLAL_SUCCESS, XLAL_EFUNC );
  }

  return XLAL_SUCCESS;

}
Ejemplo n.º 21
0
int XLALHashTblExtract(
  LALHashTbl *ht,
  const void *x,
  void **y
  )
{

  /* Check input */
  XLAL_CHECK( ht != NULL, XLAL_EFAULT );
  XLAL_CHECK( x != NULL && x != DEL, XLAL_EINVAL );
  XLAL_CHECK( y != NULL, XLAL_EFAULT );

  /* Try to find element matching 'x' in hash table, if found remove it from table and return in 'y' */
  if ( ht->data_len > 0 ) {
    int i = HASHIDX( ht, x );
    while ( ht->data[i] != NULL ) {
      *y = ht->data[i];
      if ( *y != DEL && EQUAL( ht, x, *y ) ) {
        ht->data[i] = DEL;
        --ht->n;
        if ( 8*ht->n < ht->data_len ) { /* Resize hash table to preserve minimum 50% occupancy */
          XLAL_CHECK( hashtbl_resize( ht ) == XLAL_SUCCESS, XLAL_EFUNC );
        }
        return XLAL_SUCCESS;
      }
      INCRIDX( ht, i );
    }
  }

  /* No element matches 'x' */
  *y = NULL;
  return XLAL_SUCCESS;

}
Ejemplo n.º 22
0
INT4 InitUserVars(UserVariables_t *uvar, int argc, char *argv[])
{
   XLAL_CHECK ( uvar != NULL, XLAL_EINVAL, "Invalid NULL input 'uvar'\n");
   XLAL_CHECK ( argv != NULL, XLAL_EINVAL, "Invalid NULL input 'argv'\n");

   uvar->ephemEarth = XLALStringDuplicate("earth00-19-DE405.dat.gz");
   uvar->ephemSun = XLALStringDuplicate("sun00-19-DE405.dat.gz");
   uvar->outfilename = XLALStringDuplicate("output.dat");
   uvar->Tsft = 1800;
   uvar->SFToverlap = 900;
   uvar->skylocations = 1;

   XLALregBOOLUserStruct(  help,        'h', UVAR_HELP     , "Print this help/usage message");
   XLALregREALUserStruct(  Tsft,         0 , UVAR_OPTIONAL , "SFT coherence time");
   XLALregREALUserStruct(  SFToverlap,   0 , UVAR_OPTIONAL , "SFT overlap in seconds, usually Tsft/2");
   XLALregREALUserStruct(  t0,           0 , UVAR_OPTIONAL , "GPS start time of the search");
   XLALregREALUserStruct(  Tobs,         0 , UVAR_OPTIONAL , "Duration of the search (in seconds)");
   XLALregREALUserStruct(  cosi,         0 , UVAR_OPTIONAL , "Cosine of NS inclinaiont angle");
   XLALregREALUserStruct(  psi,          0 , UVAR_OPTIONAL , "Polarization angle of GW");
   XLALregREALUserStruct(  alpha,        0 , UVAR_OPTIONAL , "Right ascension of source (in radians)");
   XLALregREALUserStruct(  delta,        0 , UVAR_OPTIONAL , "Declination of source (in radians)");
   XLALregINTUserStruct(   skylocations, 0 , UVAR_OPTIONAL , "Number of sky locations");
   XLALregLISTUserStruct(  IFO,          0 , UVAR_REQUIRED , "CSV list of detectors, eg. \"H1,H2,L1,G1, ...\" ");
   XLALregSTRINGUserStruct(outfilename,  0 , UVAR_OPTIONAL , "Output filename");
   XLALregSTRINGUserStruct(ephemEarth,   0 , UVAR_OPTIONAL , "Earth ephemeris file");
   XLALregSTRINGUserStruct(ephemSun,     0 , UVAR_OPTIONAL , "Sun ephemeris file");

   XLAL_CHECK( XLALUserVarReadAllInput(argc, argv) == XLAL_SUCCESS, XLAL_EFUNC );

   if ( uvar->help ) exit (0);

   return XLAL_SUCCESS;
}
Ejemplo n.º 23
0
/**
 * Write one line for given BSGL candidate into output file.
 *
 * NOTE: input stats and injParams can be NULL pointers, then writes header comment instead
 *
 */
int
write_BSGL_candidate_to_fp ( FILE *fp, const BSGLComponents *stats, const LALStringVector *IFOs, const InjParams_t *injParams, const BOOLEAN haveBSGL )
{

  XLAL_CHECK ( fp, XLAL_EINVAL, "Invalid NULL filepointer input." );

  /* if requested, write header-comment line */
  if ( !stats && !injParams ) {

    char stat_header_string[256] = "";
    char buf0[256];
    snprintf ( stat_header_string, sizeof(stat_header_string), "2F   " );
    for ( UINT4 X = 0; X < IFOs->length ; X ++ ) {
      snprintf ( buf0, sizeof(buf0), "    2F_%s", IFOs->data[X] );
      UINT4 len1 = strlen ( stat_header_string ) + strlen ( buf0 ) + 1;
      XLAL_CHECK ( len1 <= sizeof ( stat_header_string ), XLAL_EBADLEN, "Assembled output string too long! (%d > %zu)", len1, sizeof(stat_header_string));
      strcat ( stat_header_string, buf0 );
    }
    if ( haveBSGL ) {
      snprintf ( buf0, sizeof(buf0), "     log10BSGL" );
      strcat ( stat_header_string, buf0 );
    }
    fprintf(fp, "%%%% freq  alpha    delta    f1dot    %s\n", stat_header_string);

    return XLAL_SUCCESS;	/* we're done here */

  } /* if par == NULL */

  /* sanity checks */
  XLAL_CHECK ( stats, XLAL_EFAULT, "Invalid stats pointer as input parameter!" );
  XLAL_CHECK ( injParams, XLAL_EFAULT, "Invalid injParams pointer as input parameter!" );

  /* add output-field containing twoF and per-detector sumTwoFX */
  char statString[256] = "";	/* defaults to empty */
  char buf0[256];
  snprintf ( statString, sizeof(statString), "%.6f", stats->TwoF );
  for ( UINT4 X = 0; X < IFOs->length ; X ++ ) {
    snprintf ( buf0, sizeof(buf0), " %.6f", stats->TwoFX[X] );
    UINT4 len1 = strlen ( statString ) + strlen ( buf0 ) + 1;
    XLAL_CHECK ( len1 <= sizeof ( statString ), XLAL_EBADLEN, "Assembled output string too long! (%d > %zu)", len1, sizeof(statString));
    strcat ( statString, buf0 );
  } /* for X < IFOs->length */
  if ( haveBSGL ) {
    snprintf ( buf0, sizeof(buf0), " %.6f", stats->log10BSGL );
    strcat ( statString, buf0 );
  }
  fprintf (fp, "%.6f %.6f %.6f %.6f %s\n",
		0.0, /* legacy field from synthesizeTransientStats: freq, not needed here */
		injParams->skypos.longitude,
		injParams->skypos.latitude,
		0.0,
		statString /* legacy field from synthesizeTransientStats: f1dot, not needed here */
	    );

  return XLAL_SUCCESS;

} /* write_BSGL_candidate_to_fp() */
Ejemplo n.º 24
0
// compare two SFTs, return XLAL_SUCCESS if OK, error otherwise
int
XLALCompareSFTs ( const SFTtype *sft1, const SFTtype *sft2, const VectorComparison *tol )
{
  // check input sanity
  XLAL_CHECK ( sft1 != NULL, XLAL_EINVAL );
  XLAL_CHECK ( sft2 != NULL, XLAL_EINVAL );
  XLAL_CHECK ( tol  != NULL, XLAL_EINVAL );

  XLAL_CHECK ( XLALGPSCmp ( &(sft1->epoch), &(sft2->epoch) ) == 0, XLAL_ETOL );
  REAL8 tolFreq = 10 * LAL_REAL8_EPS;
  REAL8 err_f0 = sft1->f0 - sft2->f0;
  XLAL_CHECK ( err_f0 < tolFreq, XLAL_ETOL, "f0_1 = %.16g, f0_2 = %.16g, relErr_f0 = %g (tol = %g)\n", sft1->f0, sft2->f0, err_f0, tolFreq );
  REAL8 relErr_df = RELERR ( sft1->deltaF, sft2->deltaF );
  XLAL_CHECK ( relErr_df < tolFreq, XLAL_ETOL, "dFreq1 = %g, dFreq2 = %g, relErr_df = %g (tol = %g)", sft1->deltaF, sft2->deltaF, relErr_df, tolFreq );

  XLAL_CHECK ( XLALUnitCompare( &(sft1->sampleUnits), &(sft2->sampleUnits) ) == 0, XLAL_ETOL );

  XLAL_CHECK ( sft1->data->length == sft2->data->length, XLAL_ETOL, "sft1->length = %d, sft2->length = %d\n", sft1->data->length, sft2->data->length  );

  VectorComparison XLAL_INIT_DECL(cmp);
  XLAL_CHECK ( XLALCompareCOMPLEX8Vectors ( &cmp, sft1->data, sft2->data, tol ) == XLAL_SUCCESS, XLAL_EFUNC );

  return XLAL_SUCCESS;

} // XLALCompareSFTs()
Ejemplo n.º 25
0
static int test_XLALPearsonHash(size_t hval_len, const int N, const int nc_ref)
{
  int n = 0, nc = 0;
  for (int i = 0; i < N; ++i) {
    UINT8 hi = 0;
    XLAL_CHECK(XLALPearsonHash(&hi, hval_len, &i, sizeof(i)) == XLAL_SUCCESS, XLAL_EFUNC);
    for (int j = 0; j <= i; ++j) {
      UINT8 hj = 0;
      XLAL_CHECK(XLALPearsonHash(&hj, hval_len, &j, sizeof(j)) == XLAL_SUCCESS, XLAL_EFUNC);
      XLAL_CHECK(i != j || hi == hj, XLAL_EFAILED);
      ++n;
      if (i != j && hi == hj) {
        ++nc;
      }
    }
  }
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j <= i; ++j) {
      UINT8 hij = 0, hji = 0;
      XLAL_CHECK(XLALPearsonHash(&hij, hval_len, &i, sizeof(i)) == XLAL_SUCCESS, XLAL_EFUNC);
      XLAL_CHECK(XLALPearsonHash(&hij, hval_len, &j, sizeof(j)) == XLAL_SUCCESS, XLAL_EFUNC);
      XLAL_CHECK(XLALPearsonHash(&hji, hval_len, &j, sizeof(j)) == XLAL_SUCCESS, XLAL_EFUNC);
      XLAL_CHECK(XLALPearsonHash(&hji, hval_len, &i, sizeof(i)) == XLAL_SUCCESS, XLAL_EFUNC);
      XLAL_CHECK(i != j || hij == hji, XLAL_EFAILED);
      ++n;
      if (i != j && hij == hji) {
        ++nc;
      }
    }
  }
  printf("XLALPearsonHash(hval=%zu) collisions in %i integer pairs: %i\n", hval_len, n, nc);
  XLAL_CHECK(nc == nc_ref, XLAL_EFAILED, "nc = %i != %i = nc_ref", nc, nc_ref);
  return XLAL_SUCCESS;
}
Ejemplo n.º 26
0
/**
 * Compare 2 SSBtimes vectors and return the maximal difference in
 * DeltaT in s, and in Tdot (dimensionless)
 */
int
XLALCompareSSBtimes ( REAL8 *err_DeltaT, REAL8 *err_Tdot, const SSBtimes *t1, const SSBtimes *t2 )
{
  XLAL_CHECK ( err_DeltaT != NULL, XLAL_EINVAL );
  XLAL_CHECK ( err_Tdot != NULL, XLAL_EINVAL );
  XLAL_CHECK ( t1 != NULL, XLAL_EINVAL );
  XLAL_CHECK ( t2 != NULL, XLAL_EINVAL );
  XLAL_CHECK ( (t1->DeltaT != NULL) && (t1->Tdot != NULL), XLAL_EINVAL );
  XLAL_CHECK ( XLALGPSDiff ( &(t1->refTime), &(t2->refTime) ) == 0, XLAL_ETOL,
               "Different reference-times: %f != %f\n", XLALGPSGetREAL8(&(t1->refTime)), XLALGPSGetREAL8(&(t2->refTime)));

  UINT4 numSteps = t1->DeltaT->length;
  XLAL_CHECK ( t1->Tdot->length == numSteps, XLAL_EINVAL );
  XLAL_CHECK ( t2->DeltaT->length == numSteps, XLAL_EINVAL );
  XLAL_CHECK ( t2->Tdot->length == numSteps, XLAL_EINVAL );

  REAL8 max_DeltaT = 0;
  REAL8 max_Tdot = 0;

  for ( UINT4 i = 0; i < numSteps; i ++ )
    {
      REAL8 DeltaT_i = fabs ( t1->DeltaT->data[i] - t2->DeltaT->data[i] );
      REAL8 Tdot_i   = fabs ( t1->Tdot->data[i]   - t2->Tdot->data[i] );

      max_DeltaT = fmax ( max_DeltaT, DeltaT_i );
      max_Tdot   = fmax ( max_Tdot,   Tdot_i );

    } // for i < numSteps

  (*err_DeltaT) = max_DeltaT;
  (*err_Tdot)   = max_Tdot;

  return XLAL_SUCCESS;

} // XLALCompareSSBtimes()
Ejemplo n.º 27
0
/** register all "user-variables" */
int
XLALInitUserVars ( UserVariables_t *uvar )
{
  XLAL_CHECK ( uvar != NULL, XLAL_EINVAL );

  /* set a few defaults */
  uvar->help = 0;

  XLAL_CHECK ( (uvar->IFOs = XLALCreateStringVector ( "H1", NULL )) != NULL, XLAL_ENOMEM, "Call to XLALCreateStringVector() failed." );

  uvar->ephemEarth = XLALStringDuplicate("earth00-19-DE405.dat.gz");
  uvar->ephemSun = XLALStringDuplicate("sun00-19-DE405.dat.gz");

  uvar->Alpha     = 0.0;
  uvar->Delta     = 0.0;
  uvar->skyGridFile = NULL;

  uvar->timeGPS = NULL;
  uvar->timeStampsFile = NULL;
  uvar->outab = 0;
  uvar->outABCD = 0;
  uvar->Tsft = 1800;

  uvar->noiseSqrtShX = NULL;

  /* register all user-variables */
  XLALregBOOLUserStruct(	help,		'h', UVAR_HELP,		"Print this help/usage message");
  XLALregLISTUserStruct( IFOs,                  'I', UVAR_OPTIONAL, "Comma-separated list of detectors, eg. \"H1,H2,L1,G1, ...\" [only 1 detector supported at the moment] ");

  XLALregREALUserStruct(	Alpha,		'a', UVAR_OPTIONAL,	"single skyposition Alpha in radians, equatorial coords.");
  XLALregREALUserStruct(	Delta, 		'd', UVAR_OPTIONAL,	"single skyposition Delta in radians, equatorial coords.");

  XLALregSTRINGUserStruct( skyGridFile,		's', UVAR_OPTIONAL,	"Alternatively: sky-grid file");

  XLALregLISTUserStruct( 	timeGPS,        't', UVAR_OPTIONAL, 	"GPS time at which to compute detector states (separate multiple timestamps by commata)");
  XLALregLISTUserStruct(	timeStampsFiles, 'T', UVAR_OPTIONAL,	"Alternative: time-stamps file(s) (comma-separated list per IFO, or one for all)");
  XLALregINTUserStruct(		Tsft,		 0, UVAR_OPTIONAL,	"Assumed length of one SFT in seconds; needed for timestamps offset consistency with F-stat based codes");

  XLALregLISTUserStruct ( noiseSqrtShX,		 0, UVAR_OPTIONAL, "Per-detector noise PSD sqrt(SX). Only ratios relevant to compute noise weights. Defaults to 1,1,...");

  XLALregSTRINGUserStruct (	ephemEarth,	 0,  UVAR_OPTIONAL,	"Earth ephemeris file to use");
  XLALregSTRINGUserStruct (	ephemSun,	 0,  UVAR_OPTIONAL,	"Sun ephemeris file to use");

  XLALregSTRINGUserStruct(	outab,		'o', UVAR_OPTIONAL,	"output file for antenna pattern functions a(t), b(t) at each timestamp");
  XLALregSTRINGUserStruct(	outABCD,	'O', UVAR_OPTIONAL,	"output file for antenna pattern matrix elements A, B, C, D averaged over timestamps");

  XLALregBOOLUserStruct(	version,        'V', UVAR_SPECIAL,      "Output code version");

  /* developer user variables */
  XLALregSTRINGUserStruct(	timeStampsFile,	  0, UVAR_OPTIONAL,	"Alternative: single time-stamps file (deprecated, use --timeStampsFiles instead");

  return XLAL_SUCCESS;

} /* XLALInitUserVars() */
Ejemplo n.º 28
0
/**
 * Determines a frequency band which covers the frequency evolution of a band of CW signals between two GPS times.
 * The calculation accounts for the spin evolution of the signals, and the maximum possible Dopper modulation
 * due to detector motion, and (for binary signals) binary orbital motion.
 */
int
XLALCWSignalCoveringBand ( REAL8 *minCoverFreq,                          /**< [out] Minimum frequency of the covering band */
                           REAL8 *maxCoverFreq,                          /**< [out] Maximum frequency of the covering band */
                           const LIGOTimeGPS *time1,                     /**< [in] One end of the GPS time range */
                           const LIGOTimeGPS *time2,                     /**< [in] The other end of the GPS time range */
                           const PulsarSpinRange *spinRange,             /**< [in] Frequency and spindown range of the CW signals */
                           const REAL8 binaryMaxAsini,                   /**< [in] Maximum projected semi-major axis a*sini/c (= 0 for isolated sources) */
                           const REAL8 binaryMinPeriod,                  /**< [in] Minimum orbital period (s); must be 0 for isolated signals */
                           const REAL8 binaryMaxEcc                      /**< [in] Maximal binary eccentricity: must be 0 for isolated signals */
                           )
{
  // Check input
  XLAL_CHECK( minCoverFreq != NULL, XLAL_EFAULT );
  XLAL_CHECK( maxCoverFreq != NULL, XLAL_EFAULT );
  XLAL_CHECK( time1 != NULL, XLAL_EFAULT );
  XLAL_CHECK( time2 != NULL, XLAL_EFAULT );
  XLAL_CHECK( spinRange != NULL, XLAL_EFAULT );
  XLAL_CHECK( binaryMaxAsini >= 0, XLAL_EINVAL );

  XLAL_CHECK( (binaryMaxAsini > 0)  || ((binaryMinPeriod == 0) && (binaryMaxEcc == 0)), XLAL_EINVAL );	// if isolated: required P=0 and e=0
  XLAL_CHECK( (binaryMaxAsini == 0) || ((binaryMinPeriod > 0) && (binaryMaxEcc >= 0) && (binaryMaxEcc<1)), XLAL_EINVAL );	// if binary: P>0, 0<=e<1

  // Extrapolate frequency and spindown range to each end of GPS time range
  PulsarSpinRange spin1, spin2;
  const REAL8 DeltaT1 = XLALGPSDiff(time1, &spinRange->refTime);
  const REAL8 DeltaT2 = XLALGPSDiff(time2, &spinRange->refTime);
  XLAL_CHECK( XLALExtrapolatePulsarSpinRange(&spin1, spinRange, DeltaT1) == XLAL_SUCCESS, XLAL_EFUNC );
  XLAL_CHECK( XLALExtrapolatePulsarSpinRange(&spin2, spinRange, DeltaT2) == XLAL_SUCCESS, XLAL_EFUNC );

  // Determine the minimum and maximum frequencies covered
  *minCoverFreq = MYMIN( spin1.fkdot[0], spin2.fkdot[0] );
  *maxCoverFreq = MYMAX( spin1.fkdot[0] + spin1.fkdotBand[0], spin2.fkdot[0] + spin2.fkdotBand[0] );

  // Extra frequency range needed due to detector motion, per unit frequency
  // * Maximum value of the time derivative of the diurnal and (Ptolemaic) orbital phase, plus 5% for luck
  REAL8 extraPerFreq = 1.05 * LAL_TWOPI / LAL_C_SI * ( (LAL_AU_SI/LAL_YRSID_SI) + (LAL_REARTH_SI/LAL_DAYSID_SI) );

  // Extra frequency range needed due to binary orbital motion, per unit frequency
  // Upper bound on maximum value, derived from time derivative of binary-CW phase,
  // see https://bugs.ligo.org/redmine/issues/1567
  if ( binaryMaxAsini > 0 )
    {
      REAL8 maxOmega = LAL_TWOPI / binaryMinPeriod;
      extraPerFreq += maxOmega * binaryMaxAsini / ( 1.0 - binaryMaxEcc );
  }

  // Expand frequency range
  (*minCoverFreq) *= 1.0 - extraPerFreq;
  (*maxCoverFreq) *= 1.0 + extraPerFreq;

  return XLAL_SUCCESS;

} /* XLALCWSignalCoveringBand() */
Ejemplo n.º 29
0
/**
 * Apply a spin-down correction to the complex8 timeseries
 * using the time-domain expression y(t) = x(t) * e^(-i 2pi sum f_k * (t-tref)^(k+1)),
 *
 * NOTE: this <b>modifies</b> the input COMPLEX8TimeSeries in place
 */
int
XLALSpinDownCorrectionMultiTS ( MultiCOMPLEX8TimeSeries *multiTimeSeries,       /**< [in/out] timeseries to time-shift */
                                const PulsarDopplerParams *doppler		/**< parameter-space point to correct for */
                                )
{
  // check input sanity
  XLAL_CHECK ( (multiTimeSeries != NULL) &&  (multiTimeSeries->data != NULL) && (multiTimeSeries->length > 0), XLAL_EINVAL );
  XLAL_CHECK ( doppler != NULL, XLAL_EINVAL );

  UINT4 numDetectors = multiTimeSeries->length;

  LIGOTimeGPS *epoch = &(multiTimeSeries->data[0]->epoch);
  UINT4 numSamples = multiTimeSeries->data[0]->data->length;

  REAL8 dt = multiTimeSeries->data[0]->deltaT;

  /* determine number of spin down's and check if sensible */
  UINT4 nspins = PULSAR_MAX_SPINS - 1;
  while ( (nspins > 0) && (doppler->fkdot[nspins] == 0) ) {
    nspins--;
  }

  /* apply spin derivitive correction to resampled timeseries */
  REAL8 tk = XLALGPSDiff ( epoch, &(doppler->refTime) );
  for ( UINT4 k=0; k < numSamples; k++ )
    {
      REAL8 tk_pow_jp1 = tk;
      REAL8 cycles_k = 0;
      for ( UINT4 j=1; j <= nspins; j++ )
        {
          tk_pow_jp1 *= tk;
          /* compute fractional number of cycles the spin-derivitive has added since the reftime */
          cycles_k += LAL_FACT_INV[j+1] * doppler->fkdot[j] * tk_pow_jp1;
        } // for j < nspins

      REAL4 cosphase, sinphase;
      XLAL_CHECK( XLALSinCos2PiLUT ( &sinphase, &cosphase, -cycles_k ) == XLAL_SUCCESS, XLAL_EFUNC );
      COMPLEX8 em2piphase = crectf ( cosphase, sinphase );

      /* loop over detectors */
      for ( UINT4 X=0; X < numDetectors; X++ )
        {
          multiTimeSeries->data[X]->data->data[k] *= em2piphase;
        } // for X < numDetectors

      tk += dt;

    } // for k < numSamples

  return XLAL_SUCCESS;

} // XLALSpinDownCorrectionMultiTS()
/* ----- function definitions ---------- */
int
main (  void )
{
  LALStatus XLAL_INIT_DECL(status);
  SFTCatalog *catalog = NULL;
  SFTConstraints XLAL_INIT_DECL(constraints);
  MultiSFTVector *multiSFTs = NULL;
  MultiPSDVector *multiPSDs = NULL;
  MultiNoiseWeights *multiWeightsXLAL = NULL;
  MultiNoiseWeights *multiWeightsCorrect = NULL;
  UINT4 rngmedBins = 11;
  REAL8 tolerance = 2e-6;	/* same algorithm, should be basically identical results */

  /* Construct the "correct" weights, calculated using the old LAL routines */
  UINT4 numIFOsCorrect = 2;
  XLAL_CHECK ( ( multiWeightsCorrect = XLALCalloc ( 1, sizeof(*multiWeightsCorrect ) ) ) != NULL, XLAL_ENOMEM );
  multiWeightsCorrect->length = numIFOsCorrect;
  multiWeightsCorrect->Sinv_Tsft = 1.980867126449e+52;
  XLAL_CHECK ( ( multiWeightsCorrect->data = XLALCalloc ( numIFOsCorrect, sizeof(*multiWeightsCorrect->data ) ) ) != NULL, XLAL_ENOMEM );
  XLAL_CHECK ( ( multiWeightsCorrect->data[0] = XLALCreateREAL8Vector(4) ) != NULL, XLAL_ENOMEM );
  multiWeightsCorrect->data[0]->data[0] = 6.425160659487e-05;
  multiWeightsCorrect->data[0]->data[1] = 7.259453662367e-06;
  multiWeightsCorrect->data[0]->data[2] = 9.838893684664e-04;
  multiWeightsCorrect->data[0]->data[3] = 5.043766789923e-05;
  XLAL_CHECK ( ( multiWeightsCorrect->data[1] = XLALCreateREAL8Vector(3) ) != NULL, XLAL_ENOMEM );
  multiWeightsCorrect->data[1]->data[0] = 1.582309910283e-04;
  multiWeightsCorrect->data[1]->data[1] = 5.345673753744e-04;
  multiWeightsCorrect->data[1]->data[2] = 6.998201363537e+00;

  /* Construct the catalog */
  XLAL_CHECK ( ( catalog = XLALSFTdataFind ( TEST_DATA_DIR "MultiNoiseWeightsTest*.sft", &constraints ) ) != NULL, XLAL_EFUNC, " XLALSFTdataFind failed\n" );

  /* Load the SFTs */
  XLAL_CHECK ( ( multiSFTs = XLALLoadMultiSFTs ( catalog, -1, -1 ) ) != NULL, XLAL_EFUNC, " XLALLoadMultiSFTs failed\n" );

  /* calculate the psd and normalize the SFTs */
  XLAL_CHECK ( ( multiPSDs = XLALNormalizeMultiSFTVect ( multiSFTs, rngmedBins, NULL ) ) != NULL, XLAL_EFUNC, " XLALNormalizeMultiSFTVect failed\n" );

  /* Get weights using XLAL function */
  XLAL_CHECK ( ( multiWeightsXLAL = XLALComputeMultiNoiseWeights ( multiPSDs, rngmedBins, 0 ) ) != NULL, XLAL_EFUNC, " XLALComputeMultiNoiseWeights failed\n" );

  /* Compare XLAL weights to reference */
  XLAL_CHECK ( XLALCompareMultiNoiseWeights ( multiWeightsXLAL, multiWeightsCorrect, tolerance ) == XLAL_SUCCESS, XLAL_EFAILED, "Comparison between XLAL and reference MultiNoiseWeights failed\n" );

  /* Clean up memory */
  XLALDestroyMultiNoiseWeights ( multiWeightsCorrect );
  XLALDestroyMultiNoiseWeights ( multiWeightsXLAL );
  XLALDestroyMultiPSDVector ( multiPSDs );
  XLALDestroyMultiSFTVector ( multiSFTs );
  XLALDestroySFTCatalog ( catalog );
  /* check for memory-leaks */
  LALCheckMemoryLeaks();

  return XLAL_SUCCESS;

} /* main() */